On Wed, Dec 22, 2010 at 01:09:24PM -0000, Echlin, Jamie wrote: > Afternoon, > > For some client-side Tortoise hooks (which are for the purpose of > preventing people shoot themselves in the head in all the myriad ways > Subversion allows), I need to get the ancestor-branch, ie where the > current branch/tag was copied from. > > My current strategy for doing this is svn log -q --stop-on-copy, get the > last rev, then svn log -vr thatRev on it, and look for the copied from. > I have to do it in two shots because svn log -v for the whole branch is > too slow. > > I'm wondering though if there is a better/faster way of doing this, like > something undiscovered in the API. Server-side I could use > svn.fs.closest_copy() but I only have the working copy to work with.
Try this: svn log --stop-on-copy -r1:HEAD --limit 1 ^/branches/mybranch This gives you a log entry of the revision in which the branch was created. The trick is to stop on copy, reverse the range of the log (default is HEAD:1), and then limit the output to one entry. If you want to parse the copyfrom info, I'd suggest adding two additional options: -v --xml Then you'll get some XML like this: <?xml version="1.0"?> <log> <logentry revision="2"> <author>stsp</author> <date>2010-12-22T18:51:44.476391Z</date> <paths> <path prop-mods="false" text-mods="false" kind="dir" copyfrom-path="/trunk" copyfrom-rev="1" action="A">/branch</path> </paths> <msg>creating branch</msg> </logentry> </log> > Furthermore I'm having problems with branches that weren't created > "cleanly", eg users will create a new directory, then svn copy stuff in, > or create a branch from a working copy containing modified files. (Both > bad practices that I'm trying to prevent, but nevertheless these exist > in the wild). The best approach is probably to educate your users. And try to write a pre-commit hook script that attemps to catches commits like this, e.g. by looking for empty directories being added beneath the /branches directory. The hook could reject the commit and write a message to stderr telling users how to create the branch properly. Or you'll have to parse the log of subdirectories in the branch. This can be done as above, but will probably be quite tedious. HTH, Stefan