comparison hgext/patchbomb.py @ 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 122f5c3f3308
children 6993282e5362
comparison
equal deleted inserted replaced
23209:49ed71f9a7c0 23210:79f7444520bf
151 msg['X-Mercurial-Node'] = node 151 msg['X-Mercurial-Node'] = node
152 msg['X-Mercurial-Series-Index'] = '%i' % idx 152 msg['X-Mercurial-Series-Index'] = '%i' % idx
153 msg['X-Mercurial-Series-Total'] = '%i' % total 153 msg['X-Mercurial-Series-Total'] = '%i' % total
154 return msg, subj, ds 154 return msg, subj, ds
155 155
156 def _getpatches(repo, revs, **opts):
157 """return a list of patches for a list of revisions
158
159 Each patch in the list is itself a list of lines.
160 """
161 ui = repo.ui
162 prev = repo['.'].rev()
163 for r in scmutil.revrange(repo, revs):
164 if r == prev and (repo[None].files() or repo[None].deleted()):
165 ui.warn(_('warning: working directory has '
166 'uncommitted changes\n'))
167 output = cStringIO.StringIO()
168 cmdutil.export(repo, [r], fp=output,
169 opts=patch.diffopts(ui, opts))
170 yield output.getvalue().split('\n')
156 emailopts = [ 171 emailopts = [
157 ('', 'body', None, _('send patches as inline message text (default)')), 172 ('', 'body', None, _('send patches as inline message text (default)')),
158 ('a', 'attach', None, _('send patches as attachments')), 173 ('a', 'attach', None, _('send patches as attachments')),
159 ('i', 'inline', None, _('send patches as inline attachments')), 174 ('i', 'inline', None, _('send patches as inline attachments')),
160 ('', 'bcc', [], _('email addresses of blind carbon copy recipients')), 175 ('', 'bcc', [], _('email addresses of blind carbon copy recipients')),
290 if not revs: 305 if not revs:
291 ui.status(_("no changes found\n")) 306 ui.status(_("no changes found\n"))
292 return [] 307 return []
293 return [str(r) for r in revs] 308 return [str(r) for r in revs]
294 309
295 def getpatches(revs):
296 prev = repo['.'].rev()
297 for r in scmutil.revrange(repo, revs):
298 if r == prev and (repo[None].files() or repo[None].deleted()):
299 ui.warn(_('warning: working directory has '
300 'uncommitted changes\n'))
301 output = cStringIO.StringIO()
302 cmdutil.export(repo, [r], fp=output,
303 opts=patch.diffopts(ui, opts))
304 yield output.getvalue().split('\n')
305
306 def getbundle(dest): 310 def getbundle(dest):
307 tmpdir = tempfile.mkdtemp(prefix='hg-email-bundle-') 311 tmpdir = tempfile.mkdtemp(prefix='hg-email-bundle-')
308 tmpfn = os.path.join(tmpdir, 'bundle') 312 tmpfn = os.path.join(tmpdir, 'bundle')
309 try: 313 try:
310 commands.bundle(ui, repo, tmpfn, dest, **opts) 314 commands.bundle(ui, repo, tmpfn, dest, **opts)
448 if patches: 452 if patches:
449 msgs = getpatchmsgs(patches, opts.get('patchnames')) 453 msgs = getpatchmsgs(patches, opts.get('patchnames'))
450 elif bundle: 454 elif bundle:
451 msgs = getbundlemsgs(getbundle(dest)) 455 msgs = getbundlemsgs(getbundle(dest))
452 else: 456 else:
453 msgs = getpatchmsgs(list(getpatches(revs))) 457 msgs = getpatchmsgs(list(_getpatches(repo, revs, **opts)))
454 458
455 showaddrs = [] 459 showaddrs = []
456 460
457 def getaddrs(header, ask=False, default=None): 461 def getaddrs(header, ask=False, default=None):
458 configkey = header.lower() 462 configkey = header.lower()