revsetbenchmark: get revision to benchmark in a function
authorPierre-Yves David <pierre-yves.david@fb.com>
Wed, 26 Mar 2014 18:36:19 -0700
changeset 20853 95293cf67871
parent 20852 b2353501d6dc
child 20854 bad5399c5d5f
revsetbenchmark: get revision to benchmark in a function And move it to proper subprocess call.
contrib/revsetbenchmarks.py
--- a/contrib/revsetbenchmarks.py	Wed Mar 26 18:27:17 2014 -0700
+++ b/contrib/revsetbenchmarks.py	Wed Mar 26 18:36:19 2014 -0700
@@ -41,6 +41,16 @@
     check_call(['hg', 'log', '--rev', str(rev), '--template',
                '{desc|firstline}\n'])
 
+def getrevs(spec):
+    """get the list of rev matched by a revset"""
+    try:
+        out = check_output(['hg', 'log', '--template={rev}\n', '--rev', spec])
+    except CalledProcessError, exc:
+        print >> sys.stderr, "abort, can't get revision from %s" % spec
+        sys.exit(exc.returncode)
+    return [r for r in out.split() if r]
+
+
 
 target_rev = sys.argv[1]
 
@@ -59,12 +69,9 @@
 print "----------------------------"
 print
 
-revs = check_output("hg log --template='{rev}\n' --rev " + target_rev,
-                    shell=True)
 
-revs = [r for r in revs.split() if r]
+revs = getrevs(target_rev)
 
-# Benchmark revisions
 for r in revs:
     print "----------------------------"
     printrevision(r)