# HG changeset patch # User Pierre-Yves David # Date 1433890154 25200 # Node ID a6bcd70cd9c277d090fdeb3e595ce578366603ae # Parent 262e6ad93885428682e886e377d03d1630b12bb4 revsetbenchmarks: extract call to mercurial into a function This is a gratuitous change to make the code easier to look at. diff -r 262e6ad93885 -r a6bcd70cd9c2 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 + + is the list of command + argument, + 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: