comparison hgext/patchbomb.py @ 31186:83fa357edbd5

patchbomb: pass around ui and revs that are needed for flag template See the next patch for why.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 25 Feb 2017 18:35:34 +0900
parents bbb5d2aa0bf0
children 6b8e1a08ef1d
comparison
equal deleted inserted replaced
31185:bbb5d2aa0bf0 31186:83fa357edbd5
133 % introconfig) 133 % introconfig)
134 ui.write_err(_('(should be one of always, never, auto)\n')) 134 ui.write_err(_('(should be one of always, never, auto)\n'))
135 intro = 1 < number 135 intro = 1 < number
136 return intro 136 return intro
137 137
138 def _formatprefix(flags, idx, total, numbered): 138 def _formatprefix(ui, repo, rev, flags, idx, total, numbered):
139 """build prefix to patch subject""" 139 """build prefix to patch subject"""
140 flag = ' '.join(flags) 140 flag = ' '.join(flags)
141 if flag: 141 if flag:
142 flag = ' ' + flag 142 flag = ' ' + flag
143 143
145 return '[PATCH%s]' % flag 145 return '[PATCH%s]' % flag
146 else: 146 else:
147 tlen = len(str(total)) 147 tlen = len(str(total))
148 return '[PATCH %0*d of %d%s]' % (tlen, idx, total, flag) 148 return '[PATCH %0*d of %d%s]' % (tlen, idx, total, flag)
149 149
150 def makepatch(ui, repo, patchlines, opts, _charsets, idx, total, numbered, 150 def makepatch(ui, repo, rev, patchlines, opts, _charsets, idx, total, numbered,
151 patchname=None): 151 patchname=None):
152 152
153 desc = [] 153 desc = []
154 node = None 154 node = None
155 body = '' 155 body = ''
212 p['Content-Disposition'] = disposition + '; filename=' + patchname 212 p['Content-Disposition'] = disposition + '; filename=' + patchname
213 msg.attach(p) 213 msg.attach(p)
214 else: 214 else:
215 msg = mail.mimetextpatch(body, display=opts.get('test')) 215 msg = mail.mimetextpatch(body, display=opts.get('test'))
216 216
217 prefix = _formatprefix(opts.get('flag'), idx, total, numbered) 217 prefix = _formatprefix(ui, repo, rev, opts.get('flag'), idx, total,
218 numbered)
218 subj = desc[0].strip().rstrip('. ') 219 subj = desc[0].strip().rstrip('. ')
219 if not numbered: 220 if not numbered:
220 subj = ' '.join([prefix, opts.get('subject') or subj]) 221 subj = ' '.join([prefix, opts.get('subject') or subj])
221 else: 222 else:
222 subj = ' '.join([prefix, subj]) 223 subj = ' '.join([prefix, subj])
309 emailmod.Encoders.encode_base64(datapart) 310 emailmod.Encoders.encode_base64(datapart)
310 msg.attach(datapart) 311 msg.attach(datapart)
311 msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test')) 312 msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test'))
312 return [(msg, subj, None)] 313 return [(msg, subj, None)]
313 314
314 def _makeintro(repo, sender, patches, **opts): 315 def _makeintro(repo, sender, revs, patches, **opts):
315 """make an introduction email, asking the user for content if needed 316 """make an introduction email, asking the user for content if needed
316 317
317 email is returned as (subject, body, cumulative-diffstat)""" 318 email is returned as (subject, body, cumulative-diffstat)"""
318 ui = repo.ui 319 ui = repo.ui
319 _charsets = mail._charsets(ui) 320 _charsets = mail._charsets(ui)
320 321
321 prefix = _formatprefix(opts.get('flag'), 0, len(patches), numbered=True) 322 # use the last revision which is likely to be a bookmarked head
323 prefix = _formatprefix(ui, repo, revs.last(), opts.get('flag'),
324 0, len(patches), numbered=True)
322 subj = (opts.get('subject') or 325 subj = (opts.get('subject') or
323 prompt(ui, '(optional) Subject: ', rest=prefix, default='')) 326 prompt(ui, '(optional) Subject: ', rest=prefix, default=''))
324 if not subj: 327 if not subj:
325 return None # skip intro if the user doesn't bother 328 return None # skip intro if the user doesn't bother
326 329
355 ui.write(_('this patch series consists of %d patches.\n\n') 358 ui.write(_('this patch series consists of %d patches.\n\n')
356 % len(patches)) 359 % len(patches))
357 360
358 # build the intro message, or skip it if the user declines 361 # build the intro message, or skip it if the user declines
359 if introwanted(ui, opts, len(patches)): 362 if introwanted(ui, opts, len(patches)):
360 msg = _makeintro(repo, sender, patches, **opts) 363 msg = _makeintro(repo, sender, revs, patches, **opts)
361 if msg: 364 if msg:
362 msgs.append(msg) 365 msgs.append(msg)
363 366
364 # are we going to send more than one message? 367 # are we going to send more than one message?
365 numbered = len(msgs) + len(patches) > 1 368 numbered = len(msgs) + len(patches) > 1
366 369
367 # now generate the actual patch messages 370 # now generate the actual patch messages
368 name = None 371 name = None
369 for i, p in enumerate(patches): 372 assert len(revs) == len(patches)
373 for i, (r, p) in enumerate(zip(revs, patches)):
370 if patchnames: 374 if patchnames:
371 name = patchnames[i] 375 name = patchnames[i]
372 msg = makepatch(ui, repo, p, opts, _charsets, i + 1, 376 msg = makepatch(ui, repo, r, p, opts, _charsets, i + 1,
373 len(patches), numbered, name) 377 len(patches), numbered, name)
374 msgs.append(msg) 378 msgs.append(msg)
375 379
376 return msgs 380 return msgs
377 381