implement --no-attachment
authorSteve Fink <sfink@mozilla.com>
Wed, 11 Jan 2012 15:29:27 -0800
changeset 46 f2eb962c631415a417c9ef3c6d7e5ad5bdb23244
parent 45 a9feea42470383eb1b115873c401ea7dd7546bb5
child 47 d4ed4ed03e03e49a47a2538963501f085eae2712
push id33
push usersfink@mozilla.com
push dateWed, 01 Feb 2012 20:22:14 +0000
implement --no-attachment
bzexport.py
--- a/bzexport.py
+++ b/bzexport.py
@@ -680,34 +680,19 @@ def bugzilla_info(ui):
         if userid is None or cookie is None:
             ui.write_err("Error: couldn't find bugzilla login cookies.\n")
             return
 
     auth = bzAuth(userid, cookie, username, password)
 
     return (auth, api_server, bugzilla)
 
-def bzexport(ui, repo, *args, **opts):
-    """
-    Export changesets to bugzilla attachments.
-
-    When the --new option is used, a menu will be displayed for the product and
-    component unless a default has been set in the [bzexport] of the config
-    file (keys are 'product' and 'component'), or if something has been
-    specified on the command line.
-
-    Also, the -e option may be used to bring up an editor that will allow
-    editing all fields of the attachment and bug (if creating one).
-    """
-    auth, api_server, bugzilla = bugzilla_info(ui)
-
-    if opts['no_attachment'] and not opts['new']:
-        raise util.Abort(_("--no-attachment requires --new"))
-    if opts['no_attachment'] and opts['review']:
-        raise util.Abort(_("--reviewers not allowed with --no-attachment"))
+def infer_arguments(ui, repo, args, opts):
+    if opts['no_attachment']:
+        return (None, None)
 
     rev = None
     bug = None
     if len(args) < 2:
         # We need to guess at some args.
         if len(args) == 1:
             # Just one arg. Could be a revision or a bug number.
             # Check this first, because a series of digits
@@ -720,18 +705,17 @@ def bzexport(ui, repo, *args, **opts):
                 # Don't do any validation here, to allow
                 # users to use bug aliases. The BzAPI call
                 # will fail with bad bug numbers.
                 bug = args[0]
 
         # With zero args we'll guess at both, and if we fail we'll
         # fail later.
     elif len(args) > 2:
-        ui.write_err("Too many arguments to bzexport!\n")
-        return
+        raise util.Abort(_("Too many arguments!"))
     else:
         # Just right.
         rev, bug = args
 
     if rev is None:
         # Default to 'tip'
         rev = 'tip'
 
@@ -741,28 +725,50 @@ def bzexport(ui, repo, *args, **opts):
             ui.write_err("Local changes found; refresh first!\n");
             return
 
     if rev in ["tip", "qtip"]:
         # Look for a nicer name in the MQ.
         if hasattr(repo, 'mq') and repo.mq.applied:
             rev = repo.mq.applied[-1].name
 
+    return (rev, bug)
+
+def bzexport(ui, repo, *args, **opts):
+    """
+    Export changesets to bugzilla attachments.
+
+    When the --new option is used, a menu will be displayed for the product and
+    component unless a default has been set in the [bzexport] of the config
+    file (keys are 'product' and 'component'), or if something has been
+    specified on the command line.
+
+    Also, the -e option may be used to bring up an editor that will allow
+    editing all fields of the attachment and bug (if creating one).
+    """
+    auth, api_server, bugzilla = bugzilla_info(ui)
+
+    if opts['no_attachment'] and not opts['new']:
+        raise util.Abort(_("--no-attachment requires --new"))
+    if opts['no_attachment'] and opts['review']:
+        raise util.Abort(_("--reviewers not allowed with --no-attachment"))
+
+    rev, bug = infer_arguments(ui, repo, args, opts)
+
     contents = StringIO()
     diffopts = patch.diffopts(ui, opts)
     context = ui.config("bzexport", "unified", None)
     if context:
         diffopts.context = int(context)
-    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)
+    if not opts['no_attachment']:
+        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)
 
     # Just always use the rev name as the patch name. Doesn't matter much,
     # unless you want to avoid obsoleting existing patches when uploading a
     # version that doesn't include whitespace changes.
     filename = rev
     if opts['ignore_all_space']:
         filename += "_ws"
 
@@ -811,24 +817,21 @@ def bzexport(ui, repo, *args, **opts):
             desc = m.group(1)
             patch_comment = m.group(2)
 
     attachment_comment = opts['comment']
     bug_comment = opts['bug_description']
 
     if not attachment_comment:
         # New bugs get first shot at the patch comment
-        if not opts['new']:
-            attachment_comment = patch_comment
-        elif bug_comment:
+        if not opts['new'] or bug_comment:
             attachment_comment = patch_comment
 
-    if not bug_comment:
-        if opts['new']:
-            bug_comment = patch_comment
+    if not bug_comment and opts['new']:
+        bug_comment = patch_comment
 
     if opts["review"]:
         search_strings = opts["review"].split(",")
         reviewers = validate_reviewers(ui, api_server, auth, search_strings, multi_reviewer_prompt)
     elif len(reviewers) > 0:
         # Pulled reviewers out of commit message
         reviewers = validate_reviewers(ui, api_server, auth, reviewers, multi_reviewer_prompt)
 
@@ -879,16 +882,18 @@ def bzexport(ui, repo, *args, **opts):
 
         if values['PRODUCT'] in [None, '<choose-from-menu>']:
             values['PRODUCT'] = product_menu(ui, api_server)
         if values['COMPONENT'] in [None, '<choose-from-menu>']:
             values['COMPONENT'] = component_menu(ui, api_server, values['PRODUCT'])
         if values['PRODVERSION'] in [None, '<default>']:
             values['PRODVERSION'] = get_default_version(ui, api_server, values['PRODUCT'])
             ui.write("Using default version %s of product %s\n" % (values['PRODVERSION'], values['PRODUCT']))
+        if values['BUGTITLE'] in [None, '<required>']:
+            values['BUGTITLE'] = ui.prompt(_("Bug title:"))
 
         try:
             response = create_bug(ui, api_server, auth,
                                   product = values['PRODUCT'],
                                   component = values['COMPONENT'],
                                   version = values['PRODVERSION'],
                                   title = values['BUGTITLE'],
                                   description = values['BUGCOMMENT0'])