# HG changeset patch # User Pierre-Yves David # Date 1415136537 0 # Node ID 79f7444520bf7d33f9012e0d4503b1622d5cba57 # Parent 49ed71f9a7c02598ded3d4a125cd25e0a535a2a9 patchbomb: extract 'getpatches' closure in its own function Keep marching toward the promised land of simplification! diff -r 49ed71f9a7c0 -r 79f7444520bf hgext/patchbomb.py --- 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 = []