bzexport: prefer using non-MQ export mechanism; r?glob draft
authorGregory Szorc <gps@mozilla.com>
Tue, 01 Aug 2017 17:38:34 -0700
changeset 11433 9711a456f30d0bc063f97845efa0a2554c05129c
parent 11432 b4dc9917bf041e4b354a4e6089f2d86b3af1a79f
child 11434 457dc1557900e7f6ffbc8f09b282b591f18baeb2
push id1746
push userbmo:gps@mozilla.com
push dateThu, 03 Aug 2017 02:22:07 +0000
reviewersglob
bzexport: prefer using non-MQ export mechanism; r?glob ce9d0ea7995e changed the code to use MQ's mechanisms for exporting a revision. This broke tests. Specifically, the User field was dropped from the attachment output. This feels like an undesirable change. We refactor the code to prefer the built-in changeset exporting machanism. We still preserve the ability to query a revset. MozReview-Commit-ID: 7GT8vorOWqo
hgext/bzexport/__init__.py
--- a/hgext/bzexport/__init__.py
+++ b/hgext/bzexport/__init__.py
@@ -995,35 +995,38 @@ def bzexport(ui, repo, *args, **opts):
                 ui.write("Warning: ignoring --%s option when not creating a bug\n" % o)
 
     contents = StringIO()
     diffopts = patch.diffopts(ui, opts)
     context = ui.config("bzexport", "unified", ui.config("diff", "unified", None))
     if context:
         diffopts.context = int(context)
     description_from_patch = None
-    if hasattr(repo, 'mq'):
+
+    revs = scmutil.revrange(repo, [rev])
+    if revs:
+        ctx = repo[revs.last()]
+        description_from_patch = encoding.tolocal(ctx.description())
+        if hasattr(cmdutil, "export"):
+            cmdutil.export(repo, [ctx.hex()], fp=contents, opts=diffopts)
+        else:
+            # Support older hg versions
+            patch.export(repo, [ctx.hex()], fp=contents, opts=diffopts)
+    elif util.safehasattr(repo, 'mq'):
         q = repo.mq
         try:
             contents = q.opener(q.lookup(rev), "r")
             description_from_patch = '\n'.join(mq.patchheader(q.join(rev), q.plainmode).message)
         except error.Abort:
             # mq failed to find a patch named rev. Fall through and do a normal
             # lookup instead.
             pass
 
     if description_from_patch is None:
-        ctx = scmutil.revsingle(repo, rev)
-        rev = node.hex(ctx.node())
-        description_from_patch = encoding.tolocal(ctx.description())
-        if hasattr(cmdutil, "export"):
-            cmdutil.export(repo, [rev], fp=contents, opts=diffopts)
-        else:
-            # Support older hg versions
-            patch.export(repo, [rev], fp=contents, opts=diffopts)
+        raise error.Abort(_('unable to find %s') % rev)
 
     filename = opts['patch_id'] or patch_id(ui, repo, rev)
 
     if opts['ignore_all_space']:
         filename += "_ws"
 
     patch_comment = None
     reviewers = []