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
--- 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 = []