Skip to content

Instantly share code, notes, and snippets.

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',
parsed = parser.parse_args()
c ='svn log -v --xml --stop-on-copy {}'.format(parsed.svn_path))
tree = etree.XML(c.std_out)
except etree.XMLSyntaxError:
print "couldn't parse output from svn"
# 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)
print "{}@{}".format(stem, rev)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment