Skip to content

Instantly share code, notes, and snippets.

@x110dc
Created June 7, 2012 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x110dc/2892216 to your computer and use it in GitHub Desktop.
Save x110dc/2892216 to your computer and use it in GitHub Desktop.
short python script to print the origin (branch and rev) of an SVN branch
#!/usr/bin/env python
# show the revision and stem from which a branch originates
# requires the 'lxml' and 'envoy' libraries
import sys
from lxml import etree
import envoy
import argparse
parser = argparse.ArgumentParser(
description='Show origin (stem and revision) of a SVN branch')
parser.add_argument('svn_path', action='store', default='.', nargs='?')
parser.add_argument('--pretty', action="store_true", dest='pretty',
default=False)
parsed = parser.parse_args()
c = envoy.run('svn log -v --xml --stop-on-copy {}'.format(parsed.svn_path))
try:
tree = etree.XML(c.std_out)
except etree.XMLSyntaxError:
print "couldn't parse output from svn"
sys.exit(1)
# get the last log entry
r = tree.xpath('/log/logentry[last()]/paths/path')[0]
stem = r.get("copyfrom-path")
rev = r.get("copyfrom-rev")
if parsed.pretty:
print "stemmed from '{}' at r{}".format(stem, rev)
else:
print "{}@{}".format(stem, rev)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment