Skip to content

Instantly share code, notes, and snippets.

@techtonik
Created September 7, 2011 23:12
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 techtonik/1202091 to your computer and use it in GitHub Desktop.
Save techtonik/1202091 to your computer and use it in GitHub Desktop.
VCS - Subversion - Get revision number for a given path in local copy
def get_svn_path_revision(path):
"""return latest modification revision of a path inside svn
:raise: EnvironmentError if SVN working copy format is unknown
:return: int
"""
from os.path import basename, dirname, join, isdir
if isdir(path):
entries_path = join(path, ".svn", "entries")
else:
entries_path = join(dirname(path), ".svn", "entries")
with open(entries_path) as f:
entries = [l.strip() for l in f.readlines()]
# check known working copy version
# it seems to be entries[0]
if entries[0] != '10':
raise EnvironmentError(10, "Unknown SVN working copy format")
# check entry modification revision
if isdir(path):
return int(entries[10])
else:
idx = entries.index(basename(path))
entry = entries[idx:idx+33]
return int(entry[9])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment