patchbomb: extract 'getpatches' closure in its own function
Keep marching toward the promised land of simplification!
--- 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 = []