[PATCH] dispatch: simplify _earlygetopt slightly

Henri Wiechers hwiechers at gmail.com
Sat Jun 20 09:54:51 CDT 2009


# HG changeset patch
# User Henri Wiechers <hwiechers at gmail.com>
# Date 1245508665 -7200
# Node ID 2c8a6932de4e3c42d07bbf734798870147d92a03
# Parent  7951f385fcb71f9b684ceb467d37aa43ddecefda
dispatch: simplify _earlygetopt slightly

diff -r 7951f385fcb7 -r 2c8a6932de4e mercurial/dispatch.py
--- a/mercurial/dispatch.py	Sat Jun 20 10:58:57 2009 +0200
+++ b/mercurial/dispatch.py	Sat Jun 20 16:37:45 2009 +0200
@@ -292,21 +292,17 @@
         argcount = len(args)
     shortopts = [opt for opt in aliases if len(opt) == 2]
     values = []
-    pos = 0
-    while pos < argcount:
-        if args[pos] in aliases:
-            if pos + 1 >= argcount:
+    for pos in xrange(argcount - 1, -1, -1):
+        arg = args[pos]
+        if arg in aliases:
+            if pos == argcount - 1:    
                 # ignore and let getopt report an error if there is no value
                 break
             del args[pos]
-            values.append(args.pop(pos))
-            argcount -= 2
-        elif args[pos][:2] in shortopts:
+            values.insert(0, args.pop(pos))
+        elif arg[:2] in shortopts:
             # short option can have no following space, e.g. hg log -Rfoo
-            values.append(args.pop(pos)[2:])
-            argcount -= 1
-        else:
-            pos += 1
+            values.insert(0, args.pop(pos)[2:])
     return values
 
 def runcommand(lui, repo, cmd, fullargs, ui, options, d):


More information about the Mercurial-devel mailing list