From: Eric S. Raymond Date: Thu, 26 Sep 2013 10:28:16 +0000 (-0400) Subject: Refactor the repository probe code. X-Git-Tag: 1.11~5 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=74ff6d514fd5723c3b038179f63f7741efaa1096;p=coverity-submit.git Refactor the repository probe code. --- diff --git a/coverity-submit b/coverity-submit index 1296eca..0ae94be 100755 --- a/coverity-submit +++ b/coverity-submit @@ -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():