Bug 913083 - Use an accessor for the "main" imported patch, r=jdm
authorSteve Fink <sfink@mozilla.com>
Thu, 05 Sep 2013 10:41:19 -0700
changeset 78 9c5006e8d531
parent 77 9fec7d31e8d5
child 79 e1be488e64f4
push id58
push usersfink@mozilla.com
push date2013-09-05 17:41 +0000
reviewersjdm
bugs913083
Bug 913083 - Use an accessor for the "main" imported patch, r=jdm
__init__.py
bzhandler.py
--- a/__init__.py
+++ b/__init__.py
@@ -162,33 +162,32 @@ def extsetup(ui=None):
     if ret:
       return ret
 
     # If the user passed a name, then mq used that so we don't need to rename
     if not opts['name']:
       # cache the lookup of the name. findcmd is not fast.
       qrename = cmdutil.findcmd("qrename", commands.table)[1][0]
 
-      # For all the already imported patches, rename them. Except there will
-      # only be one, since if the url resolves to multiple patches then
-      # everything but the first will go into bzhandler.delayed_imports.
-      for (patch, path) in list(bzhandler.imported_patches):
-        try:
-          # hg 1.9+
-          oldpatchname = q.fullseries[q.fullseriesend()]
-        except:
-          oldpatchname = q.full_series[q.full_series_end()]
-        newpatchname = checkpatchname(patch)
-        if newpatchname != oldpatchname:
-          qrename(ui, repo, oldpatchname, newpatchname)
-          # mq always reports the original name, which is confusing so we'll
-          # report the rename. But if ui.verbose is on, qrename will have
-          # already reported it.
-          if not ui.verbose:
-            ui.write("renamed %s -> %s\n" % (oldpatchname, newpatchname))
+      # Rename the already imported patch. If there are multiple patches, the
+      # rest will be in bzhandler.delayed_imports, which we'll name correctly
+      # in the first place.
+      try:
+        # hg 1.9+
+        oldpatchname = q.fullseries[q.fullseriesend()]
+      except:
+        oldpatchname = q.full_series[q.full_series_end()]
+      newpatchname = checkpatchname(bzhandler.last_imported_patch())
+      if newpatchname != oldpatchname:
+        qrename(ui, repo, oldpatchname, newpatchname)
+        # mq always reports the original name, which is confusing so we'll
+        # report the rename. But if ui.verbose is on, qrename will have already
+        # reported it.
+        if not ui.verbose:
+          ui.write("renamed %s -> %s\n" % (oldpatchname, newpatchname))
 
     # now process the delayed imports
 
     # these opts are invariant for all patches
     newopts = {}
     newopts.update(opts)
     newopts['force'] = True
 
--- a/bzhandler.py
+++ b/bzhandler.py
@@ -8,18 +8,21 @@ import os
 import re
 
 # qimportbz modules
 import bz
 
 # Patch list
 delayed_imports = []
 
-# (Patch * path) list
-imported_patches = []
+# The patch that got imported
+imported_patch = None
+
+def last_imported_patch():
+  return imported_patch
 
 class ObjectResponse(object):
   def __init__(self, obj):
     self.obj = obj
 
   def read(self):
     return self.obj
 
@@ -108,17 +111,18 @@ class Handler(urllib2.BaseHandler):
           except (ValueError, IndexError):
             self.ui.warn("Invalid patch number = '%s'\n" % choice)
             continue
         if not patch and len(delayed_imports) > 0:
           patch = delayed_imports.pop()
 
     # and finally return the response
     if patch:
-      imported_patches.append((patch, req.get_full_url()))
+      global imported_patch
+      imported_patch = patch
       return PatchResponse(patch)
 
 # interface reverse engineered from urllib.addbase
 class PatchResponse(object):
   def __init__(self, p):
     self.patch = p
     # utf-8: convert from internal (16/32-bit) Unicode to 8-bit encoding.
     # NB: Easier output to deal with, as most (code) patches are ASCII only.