Esempio n. 1
0
def makepatch(ui,
              repo,
              patchlines,
              opts,
              _charsets,
              idx,
              total,
              patchname=None):

    desc = []
    node = None
    body = ''

    for line in patchlines:
        if line.startswith('#'):
            if line.startswith('# Node ID'):
                node = line.split()[-1]
            continue
        if line.startswith('diff -r') or line.startswith('diff --git'):
            break
        desc.append(line)

    if not patchname and not node:
        raise ValueError

    if opts.get('attach'):
        body = ('\n'.join(desc[1:]).strip()
                or 'Patch subject is complete summary.')
        body += '\n\n\n'

    if opts.get('plain'):
        while patchlines and patchlines[0].startswith('# '):
            patchlines.pop(0)
        if patchlines:
            patchlines.pop(0)
        while patchlines and not patchlines[0].strip():
            patchlines.pop(0)

    ds = patch.diffstat(patchlines)
    if opts.get('diffstat'):
        body += ds + '\n\n'

    if opts.get('attach') or opts.get('inline'):
        msg = email.MIMEMultipart.MIMEMultipart()
        if body:
            msg.attach(mail.mimeencode(ui, body, _charsets, opts.get('test')))
        p = mail.mimetextpatch('\n'.join(patchlines), 'x-patch',
                               opts.get('test'))
        binnode = bin(node)
        # if node is mq patch, it will have the patch file's name as a tag
        if not patchname:
            patchtags = [
                t for t in repo.nodetags(binnode)
                if t.endswith('.patch') or t.endswith('.diff')
            ]
            if patchtags:
                patchname = patchtags[0]
            elif total > 1:
                patchname = cmdutil.make_filename(repo,
                                                  '%b-%n.patch',
                                                  binnode,
                                                  seqno=idx,
                                                  total=total)
            else:
                patchname = cmdutil.make_filename(repo, '%b.patch', binnode)
        disposition = 'inline'
        if opts.get('attach'):
            disposition = 'attachment'
        p['Content-Disposition'] = disposition + '; filename=' + patchname
        msg.attach(p)
    else:
        body += '\n'.join(patchlines)
        msg = mail.mimetextpatch(body, display=opts.get('test'))

    flag = ' '.join(opts.get('flag'))
    if flag:
        flag = ' ' + flag

    subj = desc[0].strip().rstrip('. ')
    if not introneeded(opts, total):
        subj = '[PATCH%s] %s' % (flag, opts.get('subject') or subj)
    else:
        tlen = len(str(total))
        subj = '[PATCH %0*d of %d%s] %s' % (tlen, idx, total, flag, subj)
    msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test'))
    msg['X-Mercurial-Node'] = node
    return msg, subj, ds
Esempio n. 2
0
    def makepatch(patch, idx, total):
        desc = []
        node = None
        body = ''
        for line in patch:
            if line.startswith('#'):
                if line.startswith('# Node ID'):
                    node = line.split()[-1]
                continue
            if line.startswith('diff -r') or line.startswith('diff --git'):
                break
            desc.append(line)
        if not node:
            raise ValueError

        if opts['attach']:
             body = ('\n'.join(desc[1:]).strip() or
                   'Patch subject is complete summary.')
             body += '\n\n\n'

        if opts.get('plain'):
            while patch and patch[0].startswith('# '):
                patch.pop(0)
            if patch:
                patch.pop(0)
            while patch and not patch[0].strip():
                patch.pop(0)
        if opts.get('diffstat'):
            body += cdiffstat('\n'.join(desc), patch) + '\n\n'
        if opts.get('attach') or opts.get('inline'):
            msg = email.MIMEMultipart.MIMEMultipart()
            if body:
                msg.attach(email.MIMEText.MIMEText(body, 'plain'))
            p = email.MIMEText.MIMEText('\n'.join(patch), 'x-patch')
            binnode = bin(node)
            # if node is mq patch, it will have patch file name as tag
            patchname = [t for t in repo.nodetags(binnode)
                         if t.endswith('.patch') or t.endswith('.diff')]
            if patchname:
                patchname = patchname[0]
            elif total > 1:
                patchname = cmdutil.make_filename(repo, '%b-%n.patch',
                                                  binnode, idx, total)
            else:
                patchname = cmdutil.make_filename(repo, '%b.patch', binnode)
            disposition = 'inline'
            if opts['attach']:
                disposition = 'attachment'
            p['Content-Disposition'] = disposition + '; filename=' + patchname
            msg.attach(p)
        else:
            body += '\n'.join(patch)
            msg = email.MIMEText.MIMEText(body)

        subj = desc[0].strip().rstrip('. ')
        if total == 1:
            subj = '[PATCH] ' + (opts.get('subject') or subj)
        else:
            tlen = len(str(total))
            subj = '[PATCH %0*d of %d] %s' % (tlen, idx, total, subj)
        msg['Subject'] = subj
        msg['X-Mercurial-Node'] = node
        return msg
Esempio n. 3
0
def makepatch(ui, repo, patch, opts, _charsets, idx, total, patchname=None):

    desc = []
    node = None
    body = ''

    for line in patch:
        if line.startswith('#'):
            if line.startswith('# Node ID'):
                node = line.split()[-1]
            continue
        if line.startswith('diff -r') or line.startswith('diff --git'):
            break
        desc.append(line)

    if not patchname and not node:
        raise ValueError

    if opts.get('attach'):
        body = ('\n'.join(desc[1:]).strip() or
                'Patch subject is complete summary.')
        body += '\n\n\n'

    if opts.get('plain'):
        while patch and patch[0].startswith('# '):
            patch.pop(0)
        if patch:
            patch.pop(0)
        while patch and not patch[0].strip():
            patch.pop(0)

    if opts.get('diffstat'):
        body += cdiffstat(ui, '\n'.join(desc), patch) + '\n\n'

    if opts.get('attach') or opts.get('inline'):
        msg = email.MIMEMultipart.MIMEMultipart()
        if body:
            msg.attach(mail.mimeencode(ui, body, _charsets, opts.get('test')))
        p = mail.mimetextpatch('\n'.join(patch), 'x-patch', opts.get('test'))
        binnode = bin(node)
        # if node is mq patch, it will have the patch file's name as a tag
        if not patchname:
            patchtags = [t for t in repo.nodetags(binnode)
                         if t.endswith('.patch') or t.endswith('.diff')]
            if patchtags:
                patchname = patchtags[0]
            elif total > 1:
                patchname = cmdutil.make_filename(repo, '%b-%n.patch',
                                                  binnode, seqno=idx, total=total)
            else:
                patchname = cmdutil.make_filename(repo, '%b.patch', binnode)
        disposition = 'inline'
        if opts.get('attach'):
            disposition = 'attachment'
        p['Content-Disposition'] = disposition + '; filename=' + patchname
        msg.attach(p)
    else:
        body += '\n'.join(patch)
        msg = mail.mimetextpatch(body, display=opts.get('test'))

    flag = ' '.join(opts.get('flag'))
    if flag:
        flag = ' ' + flag

    subj = desc[0].strip().rstrip('. ')
    if total == 1 and not opts.get('intro'):
        subj = '[PATCH%s] %s' % (flag, opts.get('subject') or subj)
    else:
        tlen = len(str(total))
        subj = '[PATCH %0*d of %d%s] %s' % (tlen, idx, total, flag, subj)
    msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test'))
    msg['X-Mercurial-Node'] = node
    return msg, subj
Esempio n. 4
0
    def makepatch(patch, idx, total):
        desc = []
        node = None
        body = ''
        for line in patch:
            if line.startswith('#'):
                if line.startswith('# Node ID'):
                    node = line.split()[-1]
                continue
            if line.startswith('diff -r') or line.startswith('diff --git'):
                break
            desc.append(line)
        if not node:
            raise ValueError

        if opts['attach']:
            body = ('\n'.join(desc[1:]).strip()
                    or 'Patch subject is complete summary.')
            body += '\n\n\n'

        if opts.get('plain'):
            while patch and patch[0].startswith('# '):
                patch.pop(0)
            if patch:
                patch.pop(0)
            while patch and not patch[0].strip():
                patch.pop(0)
        if opts.get('diffstat'):
            body += cdiffstat('\n'.join(desc), patch) + '\n\n'
        if opts.get('attach') or opts.get('inline'):
            msg = email.MIMEMultipart.MIMEMultipart()
            if body:
                msg.attach(email.MIMEText.MIMEText(body, 'plain'))
            p = email.MIMEText.MIMEText('\n'.join(patch), 'x-patch')
            binnode = bin(node)
            # if node is mq patch, it will have patch file name as tag
            patchname = [
                t for t in repo.nodetags(binnode)
                if t.endswith('.patch') or t.endswith('.diff')
            ]
            if patchname:
                patchname = patchname[0]
            elif total > 1:
                patchname = cmdutil.make_filename(repo, '%b-%n.patch', binnode,
                                                  idx, total)
            else:
                patchname = cmdutil.make_filename(repo, '%b.patch', binnode)
            disposition = 'inline'
            if opts['attach']:
                disposition = 'attachment'
            p['Content-Disposition'] = disposition + '; filename=' + patchname
            msg.attach(p)
        else:
            body += '\n'.join(patch)
            msg = email.MIMEText.MIMEText(body)

        subj = desc[0].strip().rstrip('. ')
        if total == 1:
            subj = '[PATCH] ' + (opts.get('subject') or subj)
        else:
            tlen = len(str(total))
            subj = '[PATCH %0*d of %d] %s' % (tlen, idx, total, subj)
        msg['Subject'] = subj
        msg['X-Mercurial-Node'] = node
        return msg