0

I have a PHP script that automatically generates project release history by examining directories under SVN, specifically those matching the pattern ^/*/tags/*.

e.g.

^/myproject/tags/v1-00
^/myproject/tags/v1-01
^/myproject/tags/v1-02

…and so forth.

Among other things, the script parses the output of svn info:

[tomalak@cat ~]$ svn info https://localhost/svn/myproject/tags/v8-11/
Path: v8-11
URL: https://localhost/svn/myproject/tags/v8-11
Repository Root: https://localhost/svn
Repository UUID: ***
Revision: 15198
Node Kind: directory
Last Changed Author: ***
Last Changed Rev: 15192
Last Changed Date: 2013-06-17 12:31:52 +0100 (Mon, 17 Jun 2013)

in order to obtain the SVN revision and Date of the tag's creation.

This works really well… until somebody commits onto the tag. It happens. Newer versions of TortoiseSVN warn you, and you can create pre-commit hooks to try to physically prohibit committing onto tags1, but I want to handle this case regardless.

We're told the "Last Changed Rev" and "Last Changed Date"; can we, without too much more work (and ideally without a second svn invocation), ask for the "First Changed Rev" and "First Changed Date" instead?


Related: "SVN: How to get the first revision of a file?" comes close, but I specifically want to do this with the single svn info call if at all possible. ("How to get the earliest checkout-able revision info from subversion?" is also close, but ultimately useless.)

1 Actually, I've had trouble doing this without prohibiting initial tag creation, though that's a story for another day…

Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055

1 Answers1

0

ideally without a second svn invocation

One approach, which violates this "constraint" but otherwise meets your needs and is quite simple, is to perform an initial pre-processing step to explicitly retrieve that revision number:

[tomalak@cat ~]$ svn log https://localhost/svn/myproject/tags/v8-11/ \
  --stop-on-copy --quiet | grep ^r | tail -n 1 | sed -r -e 's/^r|\s.*//g'
15000

Your automated svn info invocation could then use this revision number to provide the detail you want:

[tomalak@cat ~]$ svn info https://localhost/svn/myproject/tags/v8-11/ -r 15000
Path: v8-11
URL: https://localhost/svn/myproject/tags/v8-11
Repository Root: https://localhost/svn
Repository UUID: ***
Revision: 15000
Node Kind: directory
Last Changed Author: ***
Last Changed Rev: 15000
Last Changed Date: 2013-04-30 12:01:30 +0100 (Tue, 30 Apr 2013)

If you really want only a single command then you can always do svn log inline in the svn info call using backticks:

[tomalak@cat ~]$ svn info https://localhost/svn/myproject/tags/v8-11/ \
    -r `svn log https://localhost/svn/myproject/tags/v8-11/ \
    --stop-on-copy --quiet | grep ^r | tail -n 1 | sed -r -e 's/^r|\s.*//g'`

though, of course, in actual fact this is still performing two invocations of svn.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055