Patchwork [7,of,9] revsetbenchmark: get revision to benchmark in a function

login
register
mail settings
Submitter Pierre-Yves David
Date March 27, 2014, 2:49 a.m.
Message ID <84e82f401d6024eff76d.1395888548@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4086/
State Accepted
Commit 95293cf67871aa7689acaa9d03250071184eff27
Headers show

Comments

Pierre-Yves David - March 27, 2014, 2:49 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1395884179 25200
#      Wed Mar 26 18:36:19 2014 -0700
# Node ID 84e82f401d6024eff76dbb07e8f6c793b89ae035
# Parent  88331f2ede08e631c3926d58375a1b84021ca16e
revsetbenchmark: get revision to benchmark in a function

And move it to proper subprocess call.

Patch

diff --git a/contrib/revsetbenchmarks.py b/contrib/revsetbenchmarks.py
--- a/contrib/revsetbenchmarks.py
+++ b/contrib/revsetbenchmarks.py
@@ -39,10 +39,20 @@  def printrevision(rev):
     sys.stdout.write("Revision: ")
     sys.stdout.flush()
     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]
 
 revsetsfile = sys.stdin
 if len(sys.argv) > 2:
@@ -57,16 +67,13 @@  for idx, rset in enumerate(revsets):
     print "%i) %s" % (idx, rset)
 
 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)
     print "----------------------------"
     update(r)