Show More
@@ -10,41 +10,32 b'' | |||
|
10 | 10 | |
|
11 | 11 | from __future__ import absolute_import, print_function |
|
12 | 12 | import math |
|
13 | import optparse # cannot use argparse, python 2.7 only | |
|
13 | 14 | import os |
|
14 | 15 | import re |
|
16 | import subprocess | |
|
15 | 17 | import sys |
|
16 | from subprocess import ( | |
|
17 | CalledProcessError, | |
|
18 | check_call, | |
|
19 | PIPE, | |
|
20 | Popen, | |
|
21 | STDOUT, | |
|
22 | ) | |
|
23 | # cannot use argparse, python 2.7 only | |
|
24 | from optparse import ( | |
|
25 | OptionParser, | |
|
26 | ) | |
|
27 | 18 | |
|
28 | 19 | DEFAULTVARIANTS = ['plain', 'min', 'max', 'first', 'last', |
|
29 | 20 | 'reverse', 'reverse+first', 'reverse+last', |
|
30 | 21 | 'sort', 'sort+first', 'sort+last'] |
|
31 | 22 | |
|
32 | 23 | def check_output(*args, **kwargs): |
|
33 | kwargs.setdefault('stderr', PIPE) | |
|
34 | kwargs.setdefault('stdout', PIPE) | |
|
35 | proc = Popen(*args, **kwargs) | |
|
24 | kwargs.setdefault('stderr', subprocess.PIPE) | |
|
25 | kwargs.setdefault('stdout', subprocess.PIPE) | |
|
26 | proc = subprocess.Popen(*args, **kwargs) | |
|
36 | 27 | output, error = proc.communicate() |
|
37 | 28 | if proc.returncode != 0: |
|
38 | raise CalledProcessError(proc.returncode, ' '.join(args[0])) | |
|
29 | raise subprocess.CalledProcessError(proc.returncode, ' '.join(args[0])) | |
|
39 | 30 | return output |
|
40 | 31 | |
|
41 | 32 | def update(rev): |
|
42 | 33 | """update the repo to a revision""" |
|
43 | 34 | try: |
|
44 | check_call(['hg', 'update', '--quiet', '--check', str(rev)]) | |
|
35 | subprocess.check_call(['hg', 'update', '--quiet', '--check', str(rev)]) | |
|
45 | 36 | check_output(['make', 'local'], |
|
46 | 37 | stderr=None) # suppress output except for error/warning |
|
47 | except CalledProcessError as exc: | |
|
38 | except subprocess.CalledProcessError as exc: | |
|
48 | 39 | print('update to revision %s failed, aborting'%rev, file=sys.stderr) |
|
49 | 40 | sys.exit(exc.returncode) |
|
50 | 41 | |
@@ -60,7 +51,7 b' def hg(cmd, repo=None):' | |||
|
60 | 51 | fullcmd += ['--config', |
|
61 | 52 | 'extensions.perf=' + os.path.join(contribdir, 'perf.py')] |
|
62 | 53 | fullcmd += cmd |
|
63 | return check_output(fullcmd, stderr=STDOUT) | |
|
54 | return check_output(fullcmd, stderr=subprocess.STDOUT) | |
|
64 | 55 | |
|
65 | 56 | def perf(revset, target=None, contexts=False): |
|
66 | 57 | """run benchmark for this very revset""" |
@@ -70,7 +61,7 b' def perf(revset, target=None, contexts=F' | |||
|
70 | 61 | args.append('--contexts') |
|
71 | 62 | output = hg(args, repo=target) |
|
72 | 63 | return parseoutput(output) |
|
73 | except CalledProcessError as exc: | |
|
64 | except subprocess.CalledProcessError as exc: | |
|
74 | 65 | print('abort: cannot run revset benchmark: %s'%exc.cmd, file=sys.stderr) |
|
75 | 66 | if getattr(exc, 'output', None) is None: # no output before 2.7 |
|
76 | 67 | print('(no output)', file=sys.stderr) |
@@ -103,9 +94,9 b' def printrevision(rev):' | |||
|
103 | 94 | """print data about a revision""" |
|
104 | 95 | sys.stdout.write("Revision ") |
|
105 | 96 | sys.stdout.flush() |
|
106 | check_call(['hg', 'log', '--rev', str(rev), '--template', | |
|
107 | '{if(tags, " ({tags})")} ' | |
|
108 | '{rev}:{node|short}: {desc|firstline}\n']) | |
|
97 | subprocess.check_call(['hg', 'log', '--rev', str(rev), '--template', | |
|
98 | '{if(tags, " ({tags})")} ' | |
|
99 | '{rev}:{node|short}: {desc|firstline}\n']) | |
|
109 | 100 | |
|
110 | 101 | def idxwidth(nbidx): |
|
111 | 102 | """return the max width of number used for index |
@@ -215,7 +206,7 b' def getrevs(spec):' | |||
|
215 | 206 | """get the list of rev matched by a revset""" |
|
216 | 207 | try: |
|
217 | 208 | out = check_output(['hg', 'log', '--template={rev}\n', '--rev', spec]) |
|
218 | except CalledProcessError as exc: | |
|
209 | except subprocess.CalledProcessError as exc: | |
|
219 | 210 | print("abort, can't get revision from %s"%spec, file=sys.stderr) |
|
220 | 211 | sys.exit(exc.returncode) |
|
221 | 212 | return [r for r in out.split() if r] |
@@ -234,8 +225,8 b' summary output is provided. Use it to de' | |||
|
234 | 225 | point regressions. Revsets to run are specified in a file (or from stdin), one |
|
235 | 226 | revsets per line. Line starting with '#' will be ignored, allowing insertion of |
|
236 | 227 | comments.""" |
|
237 | parser = OptionParser(usage="usage: %prog [options] <revs>", | |
|
238 | description=helptext) | |
|
228 | parser = optparse.OptionParser(usage="usage: %prog [options] <revs>", | |
|
229 | description=helptext) | |
|
239 | 230 | parser.add_option("-f", "--file", |
|
240 | 231 | help="read revset from FILE (stdin if omitted)", |
|
241 | 232 | metavar="FILE") |
General Comments 0
You need to be logged in to leave comments.
Login now