changeset 23210:79f7444520bf

patchbomb: extract 'getpatches' closure in its own function Keep marching toward the promised land of simplification!
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 04 Nov 2014 21:28:57 +0000
parents 49ed71f9a7c0
children 6993282e5362
files hgext/patchbomb.py
diffstat 1 files changed, 16 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/patchbomb.py	Tue Nov 04 21:22:59 2014 +0000
+++ b/hgext/patchbomb.py	Tue Nov 04 21:28:57 2014 +0000
@@ -153,6 +153,21 @@
     msg['X-Mercurial-Series-Total'] = '%i' % total
     return msg, subj, ds
 
+def _getpatches(repo, revs, **opts):
+    """return a list of patches for a list of revisions
+
+    Each patch in the list is itself a list of lines.
+    """
+    ui = repo.ui
+    prev = repo['.'].rev()
+    for r in scmutil.revrange(repo, revs):
+        if r == prev and (repo[None].files() or repo[None].deleted()):
+            ui.warn(_('warning: working directory has '
+                      'uncommitted changes\n'))
+        output = cStringIO.StringIO()
+        cmdutil.export(repo, [r], fp=output,
+                     opts=patch.diffopts(ui, opts))
+        yield output.getvalue().split('\n')
 emailopts = [
     ('', 'body', None, _('send patches as inline message text (default)')),
     ('a', 'attach', None, _('send patches as attachments')),
@@ -292,17 +307,6 @@
             return []
         return [str(r) for r in revs]
 
-    def getpatches(revs):
-        prev = repo['.'].rev()
-        for r in scmutil.revrange(repo, revs):
-            if r == prev and (repo[None].files() or repo[None].deleted()):
-                ui.warn(_('warning: working directory has '
-                          'uncommitted changes\n'))
-            output = cStringIO.StringIO()
-            cmdutil.export(repo, [r], fp=output,
-                         opts=patch.diffopts(ui, opts))
-            yield output.getvalue().split('\n')
-
     def getbundle(dest):
         tmpdir = tempfile.mkdtemp(prefix='hg-email-bundle-')
         tmpfn = os.path.join(tmpdir, 'bundle')
@@ -450,7 +454,7 @@
     elif bundle:
         msgs = getbundlemsgs(getbundle(dest))
     else:
-        msgs = getpatchmsgs(list(getpatches(revs)))
+        msgs = getpatchmsgs(list(_getpatches(repo, revs, **opts)))
 
     showaddrs = []