Created
September 7, 2011 23:12
-
-
Save techtonik/1202091 to your computer and use it in GitHub Desktop.
VCS - Subversion - Get revision number for a given path in local copy
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
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