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():