Fix slightly broken loop logic in insert_optional_args() by converting it to
authorZac Medico <zmedico@gentoo.org>
Tue, 29 Jul 2008 13:01:38 +0000 (13:01 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 29 Jul 2008 13:01:38 +0000 (13:01 -0000)
pop args off of a stack.

svn path=/main/trunk/; revision=11262

pym/_emerge/__init__.py

index 205111999d2048cfd9962519f1af18b4def20670..a9f28a79d4146b75e2b01087c04670a5a2c26d35 100644 (file)
@@ -12737,7 +12737,10 @@ def insert_optional_args(args):
 
        new_args = []
        jobs_opts = ("-j", "--jobs")
-       for i, arg in enumerate(args):
+       arg_stack = args[:]
+       arg_stack.reverse()
+       while arg_stack:
+               arg = arg_stack.pop()
 
                short_job_opt = bool("j" in arg and arg[:1] == "-" and arg[:2] != "--")
                if not (short_job_opt or arg in jobs_opts):
@@ -12760,16 +12763,15 @@ def insert_optional_args(args):
                                job_count = "True"
                                saved_opts = arg[1:].replace("j", "")
 
-               if job_count is None and \
-                       i < len(args) - 1:
+               if job_count is None and arg_stack:
                        try:
-                               job_count = int(args[i+1])
+                               job_count = int(arg_stack[-1])
                        except ValueError:
                                pass
                        else:
-                               # The next loop iteration will append
-                               # the validated job count to new_args.
-                               continue
+                               # Discard the job count from the stack
+                               # since we're consuming it here.
+                               arg_stack.pop()
 
                if job_count is None:
                        # unlimited number of jobs