comparison contrib/revsetbenchmarks.py @ 25528:a6bcd70cd9c2

revsetbenchmarks: extract call to mercurial into a function This is a gratuitous change to make the code easier to look at.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 09 Jun 2015 15:49:14 -0700
parents e53f6b72a0e4
children 3e80691d0dfe
comparison
equal deleted inserted replaced
25527:262e6ad93885 25528:a6bcd70cd9c2
34 check_call(['hg', 'update', '--quiet', '--check', str(rev)]) 34 check_call(['hg', 'update', '--quiet', '--check', str(rev)])
35 except CalledProcessError, exc: 35 except CalledProcessError, exc:
36 print >> sys.stderr, 'update to revision %s failed, aborting' % rev 36 print >> sys.stderr, 'update to revision %s failed, aborting' % rev
37 sys.exit(exc.returncode) 37 sys.exit(exc.returncode)
38 38
39
40 def hg(cmd, repo=None):
41 """run a mercurial command
42
43 <cmd> is the list of command + argument,
44 <repo> is an optional repository path to run this command in."""
45 fullcmd = ['./hg']
46 if repo is not None:
47 fullcmd += ['-R', repo]
48 fullcmd += ['--config',
49 'extensions.perf=' + os.path.join(contribdir, 'perf.py')]
50 fullcmd += cmd
51 return check_output(fullcmd, stderr=STDOUT)
52
39 def perf(revset, target=None): 53 def perf(revset, target=None):
40 """run benchmark for this very revset""" 54 """run benchmark for this very revset"""
41 try: 55 try:
42 cmd = ['./hg', 56 output = hg(['perfrevset', revset], repo=target)
43 '--config',
44 'extensions.perf='
45 + os.path.join(contribdir, 'perf.py'),
46 'perfrevset',
47 revset]
48 if target is not None:
49 cmd.append('-R')
50 cmd.append(target)
51 output = check_output(cmd, stderr=STDOUT)
52 output = output.lstrip('!') # remove useless ! in this context 57 output = output.lstrip('!') # remove useless ! in this context
53 return output.strip() 58 return output.strip()
54 except CalledProcessError, exc: 59 except CalledProcessError, exc:
55 print >> sys.stderr, 'abort: cannot run revset benchmark' 60 print >> sys.stderr, 'abort: cannot run revset benchmark'
56 sys.exit(exc.returncode) 61 sys.exit(exc.returncode)