- Fix hg version compatibility (hg 1.9 renamed some things)
authorSteve Fink <sfink@mozilla.com>
Wed, 23 Nov 2011 10:25:55 -0800
changeset 66 b86343ae2917
parent 65 12e11daf441e
child 67 f302ad097f33
push id48
push usersfink@mozilla.com
push dateWed, 23 Nov 2011 18:28:26 +0000
- Fix hg version compatibility (hg 1.9 renamed some things) - Use insertion position to fix invalid oldpatchname - Report renames to counteract confusing message
__init__.py
--- a/__init__.py
+++ b/__init__.py
@@ -149,35 +149,53 @@ def extsetup(ui=None):
     # and that's OK.
     if opts['preview']:
       extensions.wrapfunction(url, "open", previewopen)
 
     # mercurial's url.search_re includes the // and that doesn't match what we
     # want which is bz:dddddd(/ddddd)?
     files = map(fixuppath, files)
 
+    # Remember where the next patch will be inserted into the series
+    try:
+      # hg 1.9+
+      insert = q.fullseriesend()
+    except:
+      insert = q.full_series_end()
+
     # Do the import as normal. The first patch of any bug is actually imported
     # and the rest are stored in the global delayed_imports. The imported
     # patches have dumb filenames because there's no way to tell mq to pick the
     # patch name *after* download.
     orig(ui, repo, *files, **opts)
 
     # 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
+      # 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):
-        oldpatchname = patch.id or patch.bug.num
+        # Find where qimport will have inserted the initial patch
+        try:
+          # hg 1.9+
+          oldpatchname = q.fullseries[insert]
+        except:
+          oldpatchname = q.full_series[insert]
+        insert += 1
         newpatchname = checkpatchname(patch)
         if newpatchname != oldpatchname:
           qrename(ui, repo, oldpatchname, newpatchname)
-          if ui.verbose:
-            ui.write("Renamed %s -> %s\n" % (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