Pavel P
Pavel P

Reputation: 16940

how to get correct svn version number on UNIX?

I've tried all kinds of stuff, and there is only one tool that does it right: SubWCRev.exe from TortoiseSVN.

svn info, svnversion are all jokes and don't provide good results (so, please don't post replies involving these unless you are sure that they can do that).

I work on a huge project and I maintain buildserver for our project. The buildserver does sparse checkout (e.g. only some of the folders are checked out that are actually used by our project). My goal is simple: i don't want my version number to bump up if somebody modifies files in other branches or folders that aren't part my sparse checkout. Basically, my goal is to ensure that identical input files will generate identical build results (e.g. embedded svn number should be the same). SubWCRev from tortoise does exactly this job and reports last committed revision of all the files that are checked out. svnversion -cn for example is a close try, but it doesn't work properly.

Imagine I have this structure:

trunk
  |
  +-src
  +-include
  +-lib
    |
    +-Win32
    +-Linux
    +-WinRT

lib folder contains libraries for different OS'es and platforms. For example, Win32 is over a gig in size and on linux box we do sparse checkout e.g. svn update --set-depth=exclude trunk/lib/Win32 this way on my linux buildserver I don't even see trunk/lib/Win32. The problem with svnversion -c is that it reports last committed rev even in sub-folders that are excluded. So, is there a tool that behaves like SubWCRev from tortoise svn (I don't care for it's capability to substitute tags in files, all I need is the last commited version number that it extracts properly).

Upvotes: 2

Views: 1581

Answers (1)

Ben Reser
Ben Reser

Reputation: 5765

I wouldn't say that svn info or svnversion are jokes they just are including the version of directories. The reason including the version of the directories creates a problem is due to the way Subversion bubbles up the revision of a changed node to the parent and their parents and so on. SubWCRev can behave the same way if you pass it the -f option.

There happens to be a *nix version of SubWCRev called svnwcrev. It took a bit of mucking with the Makefile to get it to build for me since I was building on OS X. I had to provide it -lapr-1 -lsvn_subr-1 -lsvn_wc-1 on the LIBRARIES line of the config.mk file. But it worked as advertised. While it is very old the versioning rules of the Subversion API means that it'll work against even the newest libraries (I happened to build it against 1.7). If you go this route and run into problems building, make a comment here and I'll do my best to help you get it built.

There also happens to be a Java tool called SvnRev which is similar to SubWCRev (haven't tried it but I assume it does what it promises). The only concern I have with this suggestion is that it appears to directly read the working copy database, which means it may stop working in the future as we change the format of the database.

Another alternatively would be to essentially roll your own by doing svn info --xml -R $WC, ignore all the nodes with kind="dir" and calculating the largest revision in the commit entity. If I hadn't found the above I'd probably have done this but writing XPath code is a pain and I think the max function isn't available from xsltproc (which makes it even more annoying to write).

If you'd like to see this integrated into svnversion then I'd suggest that you ask for an option to make it ignore directories on the [email protected] mailing list. Given that there are several utilities that can do this and they seem to be on the rather old and not terribly well maintained side, I don't think there will be too much objection to adding such an option to svnversion.

Upvotes: 2

Related Questions