You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by "Echlin, Jamie" <ja...@credit-suisse.com> on 2010/12/22 13:09:24 UTC

How to get the parent branch...

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.

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).

Any help appreciated as always...
jamie

=============================================================================== 
Please access the attached hyperlink for an important electronic communications disclaimer: 
http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html 
=============================================================================== 


Re: How to get the parent branch...

Posted by Stefan Sperling <st...@elego.de>.
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

Re: How to get the parent branch...

Posted by Daniel Shahaf <d....@daniel.shahaf.name>.
Echlin, Jamie wrote on Wed, Dec 22, 2010 at 13:09:24 -0000:
> 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.

'svn info' also displays copyfrom.

> 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.
> 

You could use the RA API (svn_ra.h) directly; that ought to be the most
efficient solution.

> 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).
> 
> Any help appreciated as always...
> jamie
> 
> =============================================================================== 
> Please access the attached hyperlink for an important electronic communications disclaimer: 
> http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html 
> =============================================================================== 
> 

Re: How to get the parent branch...

Posted by Daniel Shahaf <d....@daniel.shahaf.name>.
Chris Tashjian wrote on Wed, Dec 22, 2010 at 11:34:03 -0500:
> >
> > 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.
> >
> 
> When I create a new branch I add an svn:property, such as "base-tag", to the
> new branch with a reference to the old branch.  Then all you need to do on a
> given branch is "svn propget base-tag <BRANCH_URL>"
> 
> It's a manual process to add it, but I find it saves a lot of time (and
> question answering) later.

Plus, since creating a tag is typically a URL-to-URL (or WC-to-URL) copy
operation, the usual warning against modifying transactions from the
pre-commit hook does not apply...

IOW, the pre-commit hook could add that (versioned) property.

Re: How to get the parent branch...

Posted by Chris Tashjian <ct...@thepond.com>.
>
> 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.
>

When I create a new branch I add an svn:property, such as "base-tag", to the
new branch with a reference to the old branch.  Then all you need to do on a
given branch is "svn propget base-tag <BRANCH_URL>"

It's a manual process to add it, but I find it saves a lot of time (and
question answering) later.