]> thyrsus.com Git - coverity-submit.git/commitdiff
Refactor the repository probe code.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 26 Sep 2013 10:28:16 +0000 (06:28 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 26 Sep 2013 10:28:16 +0000 (06:28 -0400)
coverity-submit

index 1296ecacf967ca9a8c73f1d17b732a2cf0b02cc6..0ae94beb56950235268c4a522f62cfc9c27f0088 100755 (executable)
@@ -10,16 +10,17 @@ version = "1.10"
 
 def commit_id():
     "If we're in a repository directory, try to extract a commit description."
-    if os.system("git rev-parse HEAD >/dev/null 2>&1") == 0:
-        (status, output) = commands.getstatusoutput("git describe HEAD")
-    elif os.system("hg root >/dev/null 2>&1") == 0:
-        (status, output) = commands.getstatusoutput("hg --id")
-    elif os.system("bzr root >/dev/null 2>&1") == 0:
-        (status, output) = commands.getstatusoutput("bzr version-info --custom --template='{revision_id}\n'")
-    elif os.system("svn info >/dev/null 2>&1") == 0:
-        (status, output) = commands.getstatusoutput("svnversion")
-    if status == 0:
-        return output
+    methods = (
+        ("git rev-parse HEAD", "git describe HEAD"),
+        ("hg root", "hg --id"),
+        ("bzr root", "bzr version-info --custom --template='{revision_id}\n'"),
+        ("svn info", "svnversion")
+        )
+    for (probe, extract) in methods:
+        if os.system(probe + " >/dev/null 2>&1") == 0:
+            (status, output) = commands.getstatusoutput(extract)
+            if status == 0:
+                return output
     return None
 
 def deduce_name():