Index: build/util/lastchange.py |
diff --git a/build/util/lastchange.py b/build/util/lastchange.py |
index 07e2a69545ae2f62653b036811c7a472e0536081..4b39a0a2df8325d2be9fd70ff0525f98886416ba 100755 |
--- a/build/util/lastchange.py |
+++ b/build/util/lastchange.py |
@@ -19,6 +19,19 @@ class VersionInfo(object): |
self.revision = revision |
+def IsGitSVN(directory): |
+ """Return true if the directory is managed by git-svn.""" |
+ |
+ # To test whether git-svn has been set up, query the config for any |
+ # svn-related configuration. This command exits with an error code |
+ # if there aren't any matches, so ignore its output. |
+ status = subprocess.call(['git', 'config', '--get-regexp', '^svn'], |
+ stdout=subprocess.PIPE, |
+ stderr=subprocess.PIPE, |
+ cwd=directory) |
+ return status == 0 |
+ |
+ |
def FetchSVNRevision(command, directory): |
""" |
Fetch the Subversion branch and revision for the a given directory |
@@ -35,7 +48,7 @@ def FetchSVNRevision(command, directory): |
# We can't just pass shell=True to Popen, as under win32 this will |
# cause CMD to be used, while we explicitly want a cygwin shell. |
if sys.platform in ('cygwin', 'win32'): |
- command = [ 'sh', '-c', ' '.join(command) ]; |
+ command = ['sh', '-c', ' '.join(command)] |
try: |
proc = subprocess.Popen(command, |
stdout=subprocess.PIPE, |
@@ -72,13 +85,16 @@ def FetchVersionInfo(default_lastchange, directory=None): |
""" |
version_info = FetchSVNRevision(['svn', 'info'], directory) |
if not version_info: |
- version_info = FetchSVNRevision(['git', 'svn', 'info'], directory) |
+ # Check that this is a git-svn repo before running 'git svn info', |
+ # as that will hang if not. |
+ if IsGitSVN(directory): |
tony
2011/01/24 17:57:44
Nit: Maybe merge this condition with the 'not vers
|
+ version_info = FetchSVNRevision(['git', 'svn', 'info'], directory) |
if not version_info: |
if default_lastchange and os.path.exists(default_lastchange): |
revision = open(default_lastchange, 'r').read().strip() |
version_info = VersionInfo(None, None, revision) |
else: |
- version_info = VersionInfo('', '', '0') |
+ version_info = VersionInfo('unknown', '', '0') |
return version_info |