revsetbenchmarks: extract call to mercurial into a function
authorPierre-Yves David <pierre-yves.david@fb.com>
Tue, 09 Jun 2015 15:49:14 -0700
changeset 25528 a6bcd70cd9c2
parent 25527 262e6ad93885
child 25529 3e80691d0dfe
revsetbenchmarks: extract call to mercurial into a function This is a gratuitous change to make the code easier to look at.
contrib/revsetbenchmarks.py
--- a/contrib/revsetbenchmarks.py	Wed Jun 10 19:26:16 2015 -0700
+++ b/contrib/revsetbenchmarks.py	Tue Jun 09 15:49:14 2015 -0700
@@ -36,19 +36,24 @@
         print >> sys.stderr, 'update to revision %s failed, aborting' % rev
         sys.exit(exc.returncode)
 
+
+def hg(cmd, repo=None):
+    """run a mercurial command
+
+    <cmd> is the list of command + argument,
+    <repo> is an optional repository path to run this command in."""
+    fullcmd = ['./hg']
+    if repo is not None:
+        fullcmd += ['-R', repo]
+    fullcmd += ['--config',
+                'extensions.perf=' + os.path.join(contribdir, 'perf.py')]
+    fullcmd += cmd
+    return check_output(fullcmd, stderr=STDOUT)
+
 def perf(revset, target=None):
     """run benchmark for this very revset"""
     try:
-        cmd = ['./hg',
-               '--config',
-               'extensions.perf='
-               + os.path.join(contribdir, 'perf.py'),
-               'perfrevset',
-               revset]
-        if target is not None:
-            cmd.append('-R')
-            cmd.append(target)
-        output = check_output(cmd, stderr=STDOUT)
+        output = hg(['perfrevset', revset], repo=target)
         output = output.lstrip('!') # remove useless ! in this context
         return output.strip()
     except CalledProcessError, exc: