[PATCH] patchbomb: reduce number of opts.get calls

Christian Ebert blacktrash at gmx.net
Tue Jun 15 15:05:15 CDT 2010


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1276632298 -7200
# Node ID a950a574ca283d71510b8927a8a96d06db698ece
# Parent  938fefb57db50cfdb4576fba0a4135def2b0abf0
patchbomb: reduce number of opts.get calls

diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -234,6 +234,13 @@
     '''
 
     _charsets = mail._charsets(ui)
+    _bundle = opts.get('bundle')
+    _date = opts.get('date')
+    _mbox = opts.get('mbox')
+    _outgoing = opts.get('outgoing')
+    _rev = opts.get('rev')
+    # internal option used by pbranches
+    _patches = opts.get('patches')
 
     def outgoing(dest, revs):
         '''Return the revisions present locally but not in dest'''
@@ -271,38 +278,36 @@
                 pass
             os.rmdir(tmpdir)
 
-    if not (opts.get('test') or opts.get('mbox')):
+    if not (opts.get('test') or _mbox):
         # really sending
         mail.validateconfig(ui)
 
-    if not (revs or opts.get('rev')
-            or opts.get('outgoing') or opts.get('bundle')
-            or opts.get('patches')):
+    if not (revs or _rev or _outgoing or _bundle or _patches):
         raise util.Abort(_('specify at least one changeset with -r or -o'))
 
-    if opts.get('outgoing') and opts.get('bundle'):
+    if _outgoing and _bundle:
         raise util.Abort(_("--outgoing mode always on with --bundle;"
                            " do not re-specify --outgoing"))
 
-    if opts.get('outgoing') or opts.get('bundle'):
+    if _outgoing or _bundle:
         if len(revs) > 1:
             raise util.Abort(_("too many destinations"))
         dest = revs and revs[0] or None
         revs = []
 
-    if opts.get('rev'):
+    if _rev:
         if revs:
             raise util.Abort(_('use only one form to specify the revision'))
-        revs = opts.get('rev')
+        revs = _rev
 
-    if opts.get('outgoing'):
-        revs = outgoing(dest, opts.get('rev'))
-    if opts.get('bundle'):
+    if _outgoing:
+        revs = outgoing(dest, _rev)
+    if _bundle:
         opts['revs'] = revs
 
     # start
-    if opts.get('date'):
-        start_time = util.parsedate(opts.get('date'))
+    if _date:
+        start_time = util.parsedate(_date)
     else:
         start_time = util.makedate()
 
@@ -381,11 +386,9 @@
               ui.config('patchbomb', 'from') or
               prompt(ui, 'From', ui.username()))
 
-    # internal option used by pbranches
-    patches = opts.get('patches')
-    if patches:
-        msgs = getpatchmsgs(patches, opts.get('patchnames'))
-    elif opts.get('bundle'):
+    if _patches:
+        msgs = getpatchmsgs(_patches, opts.get('patchnames'))
+    elif _bundle:
         msgs = getbundlemsgs(getbundle(dest))
     else:
         msgs = getpatchmsgs(list(getpatches(revs)))
@@ -463,9 +466,9 @@
                     raise
             if fp is not ui:
                 fp.close()
-        elif opts.get('mbox'):
+        elif _mbox:
             ui.status(_('Writing '), subj, ' ...\n')
-            fp = open(opts.get('mbox'), 'In-Reply-To' in m and 'ab+' or 'wb+')
+            fp = open(_mbox, 'In-Reply-To' in m and 'ab+' or 'wb+')
             generator = email.Generator.Generator(fp, mangle_from_=True)
             # Should be time.asctime(), but Windows prints 2-characters day
             # of month instead of one. Make them print the same thing.


More information about the Mercurial-devel mailing list