[PATCH 6 of 8] revsetbenchmark: use optparse to retrieve argument
pierre-yves.david at ens-lyon.org
pierre-yves.david at ens-lyon.org
Thu May 1 20:45:27 CDT 2014
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1398796842 25200
# Tue Apr 29 11:40:42 2014 -0700
# Node ID 5aa9fb32c6eb67357a7bdada00d1d7b0725bbf47
# Parent 3bb87edcae46d4362641d7a57c48a73e3ee076d4
revsetbenchmark: use optparse to retrieve argument
We need more flexibility. For example we'll want to run the benchmark on other
repository.
diff --git a/contrib/revsetbenchmarks.py b/contrib/revsetbenchmarks.py
--- a/contrib/revsetbenchmarks.py
+++ b/contrib/revsetbenchmarks.py
@@ -13,10 +13,14 @@
# This script also does one run of the current version of mercurial installed
# to compare performance.
import sys
from subprocess import check_call, Popen, CalledProcessError, STDOUT, PIPE
+# cannot use argparse, python 2.7 only
+from optparse import OptionParser
+
+
def check_output(*args, **kwargs):
kwargs.setdefault('stderr', PIPE)
kwargs.setdefault('stdout', PIPE)
proc = Popen(*args, **kwargs)
@@ -63,20 +67,26 @@ def getrevs(spec):
print >> sys.stderr, "abort, can't get revision from %s" % spec
sys.exit(exc.returncode)
return [r for r in out.split() if r]
+parser = OptionParser(usage="usage: %prog [options] <revs>")
+parser.add_option("-f", "--file",
+ help="read revset from FILE", metavar="FILE")
+
+(options, args) = parser.parse_args()
if len(sys.argv) < 2:
- print >> sys.stderr, 'usage: %s <revs> [file]' % sys.argv[0]
+ parser.print_help()
sys.exit(255)
-target_rev = sys.argv[1]
+
+target_rev = args[0]
revsetsfile = sys.stdin
-if len(sys.argv) > 2:
- revsetsfile = open(sys.argv[2])
+if options.file:
+ revsetsfile = open(options.file)
revsets = [l.strip() for l in revsetsfile]
print "Revsets to benchmark"
print "----------------------------"
More information about the Mercurial-devel
mailing list