Created
June 7, 2012 23:00
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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