contrib/revsetbenchmarks.py
changeset 21287 2d93b74335a2
parent 21286 f0f810096842
child 21548 651d7548a744
equal deleted inserted replaced
21286:f0f810096842 21287:2d93b74335a2
    13 # This script also does one run of the current version of mercurial installed
    13 # This script also does one run of the current version of mercurial installed
    14 # to compare performance.
    14 # to compare performance.
    15 
    15 
    16 import sys
    16 import sys
    17 from subprocess import check_call, Popen, CalledProcessError, STDOUT, PIPE
    17 from subprocess import check_call, Popen, CalledProcessError, STDOUT, PIPE
       
    18 # cannot use argparse, python 2.7 only
       
    19 from optparse import OptionParser
       
    20 
       
    21 
    18 
    22 
    19 def check_output(*args, **kwargs):
    23 def check_output(*args, **kwargs):
    20     kwargs.setdefault('stderr', PIPE)
    24     kwargs.setdefault('stderr', PIPE)
    21     kwargs.setdefault('stdout', PIPE)
    25     kwargs.setdefault('stdout', PIPE)
    22     proc = Popen(*args, **kwargs)
    26     proc = Popen(*args, **kwargs)
    63         print >> sys.stderr, "abort, can't get revision from %s" % spec
    67         print >> sys.stderr, "abort, can't get revision from %s" % spec
    64         sys.exit(exc.returncode)
    68         sys.exit(exc.returncode)
    65     return [r for r in out.split() if r]
    69     return [r for r in out.split() if r]
    66 
    70 
    67 
    71 
       
    72 parser = OptionParser(usage="usage: %prog [options] <revs>")
       
    73 parser.add_option("-f", "--file",
       
    74                   help="read revset from FILE", metavar="FILE")
       
    75 
       
    76 (options, args) = parser.parse_args()
    68 
    77 
    69 if len(sys.argv) < 2:
    78 if len(sys.argv) < 2:
    70     print >> sys.stderr, 'usage: %s <revs> [file]' % sys.argv[0]
    79     parser.print_help()
    71     sys.exit(255)
    80     sys.exit(255)
    72 
    81 
    73 target_rev = sys.argv[1]
    82 
       
    83 target_rev = args[0]
    74 
    84 
    75 revsetsfile = sys.stdin
    85 revsetsfile = sys.stdin
    76 if len(sys.argv) > 2:
    86 if options.file:
    77     revsetsfile = open(sys.argv[2])
    87     revsetsfile = open(options.file)
    78 
    88 
    79 revsets = [l.strip() for l in revsetsfile]
    89 revsets = [l.strip() for l in revsetsfile]
    80 
    90 
    81 print "Revsets to benchmark"
    91 print "Revsets to benchmark"
    82 print "----------------------------"
    92 print "----------------------------"