Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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