hgext/patchbomb.py
changeset 12199 17d604e522b4
parent 12197 540693065d40
child 12200 aebb39d45500
equal deleted inserted replaced
12198:0c67a58f0580 12199:17d604e522b4
   106 
   106 
   107 def introneeded(opts, number):
   107 def introneeded(opts, number):
   108     '''is an introductory message required?'''
   108     '''is an introductory message required?'''
   109     return number > 1 or opts.get('intro') or opts.get('desc')
   109     return number > 1 or opts.get('intro') or opts.get('desc')
   110 
   110 
   111 def makepatch(ui, repo, patch, opts, _charsets, idx, total, patchname=None):
   111 def makepatch(ui, repo, patchlines, opts, _charsets, idx, total,
       
   112               patchname=None):
   112 
   113 
   113     desc = []
   114     desc = []
   114     node = None
   115     node = None
   115     body = ''
   116     body = ''
   116 
   117 
   117     for line in patch:
   118     for line in patchlines:
   118         if line.startswith('#'):
   119         if line.startswith('#'):
   119             if line.startswith('# Node ID'):
   120             if line.startswith('# Node ID'):
   120                 node = line.split()[-1]
   121                 node = line.split()[-1]
   121             continue
   122             continue
   122         if line.startswith('diff -r') or line.startswith('diff --git'):
   123         if line.startswith('diff -r') or line.startswith('diff --git'):
   130         body = ('\n'.join(desc[1:]).strip() or
   131         body = ('\n'.join(desc[1:]).strip() or
   131                 'Patch subject is complete summary.')
   132                 'Patch subject is complete summary.')
   132         body += '\n\n\n'
   133         body += '\n\n\n'
   133 
   134 
   134     if opts.get('plain'):
   135     if opts.get('plain'):
   135         while patch and patch[0].startswith('# '):
   136         while patchlines and patchlines[0].startswith('# '):
   136             patch.pop(0)
   137             patchlines.pop(0)
   137         if patch:
   138         if patchlines:
   138             patch.pop(0)
   139             patchlines.pop(0)
   139         while patch and not patch[0].strip():
   140         while patchlines and not patchlines[0].strip():
   140             patch.pop(0)
   141             patchlines.pop(0)
   141 
   142 
   142     if opts.get('diffstat'):
   143     if opts.get('diffstat'):
   143         body += cdiffstat(ui, '\n'.join(desc), patch) + '\n\n'
   144         body += cdiffstat(ui, '\n'.join(desc), patchlines) + '\n\n'
   144 
   145 
   145     if opts.get('attach') or opts.get('inline'):
   146     if opts.get('attach') or opts.get('inline'):
   146         msg = email.MIMEMultipart.MIMEMultipart()
   147         msg = email.MIMEMultipart.MIMEMultipart()
   147         if body:
   148         if body:
   148             msg.attach(mail.mimeencode(ui, body, _charsets, opts.get('test')))
   149             msg.attach(mail.mimeencode(ui, body, _charsets, opts.get('test')))
   149         p = mail.mimetextpatch('\n'.join(patch), 'x-patch', opts.get('test'))
   150         p = mail.mimetextpatch('\n'.join(patchlines), 'x-patch', opts.get('test'))
   150         binnode = bin(node)
   151         binnode = bin(node)
   151         # if node is mq patch, it will have the patch file's name as a tag
   152         # if node is mq patch, it will have the patch file's name as a tag
   152         if not patchname:
   153         if not patchname:
   153             patchtags = [t for t in repo.nodetags(binnode)
   154             patchtags = [t for t in repo.nodetags(binnode)
   154                          if t.endswith('.patch') or t.endswith('.diff')]
   155                          if t.endswith('.patch') or t.endswith('.diff')]
   163         if opts.get('attach'):
   164         if opts.get('attach'):
   164             disposition = 'attachment'
   165             disposition = 'attachment'
   165         p['Content-Disposition'] = disposition + '; filename=' + patchname
   166         p['Content-Disposition'] = disposition + '; filename=' + patchname
   166         msg.attach(p)
   167         msg.attach(p)
   167     else:
   168     else:
   168         body += '\n'.join(patch)
   169         body += '\n'.join(patchlines)
   169         msg = mail.mimetextpatch(body, display=opts.get('test'))
   170         msg = mail.mimetextpatch(body, display=opts.get('test'))
   170 
   171 
   171     flag = ' '.join(opts.get('flag'))
   172     flag = ' '.join(opts.get('flag'))
   172     if flag:
   173     if flag:
   173         flag = ' ' + flag
   174         flag = ' ' + flag