示例#1
0
def update_commit_data(cd,
                       message=None,
                       author=None,
                       sign_str=None,
                       edit=False):
    """Return a new CommitData object updated according to the command line
    options."""
    # Set the commit message from commandline.
    if message is not None:
        cd = cd.set_message(message)

    # Modify author data.
    if author is not None:
        cd = cd.set_author(author)

    # Add Signed-off-by: or similar.
    if sign_str is None:
        sign_str = config.get("stgit.autosign")
    if sign_str:
        cd = cd.set_message(
            add_trailer(cd.message_str, sign_str, cd.committer.name,
                        cd.committer.email))

    if edit:
        tmpl = templates.get_template('patchdescr.tmpl')
        if tmpl:
            cd = cd.set_message(cd.message + tmpl)
        cd = cd.set_message(edit_bytes(cd.message, '.stgit-new.txt'))

    return cd
示例#2
0
def interactive_edit_patch(repo, cd, edit_diff, diff_flags, replacement_diff):
    """Edit the patch interactively. If C{edit_diff} is true, edit the
    diff as well. If C{replacement_diff} is not C{None}, it contains a
    diff to edit instead of the patch's real diff.

    Return a pair: the new L{CommitData<stgit.lib.git.CommitData>};
    and the diff text if it didn't apply, or C{None} otherwise."""
    return update_patch_description(
        repo, cd, utils.edit_bytes(
            patch_desc(repo, cd, edit_diff, diff_flags, replacement_diff),
            '.stgit-edit.' + ['txt', 'patch'][bool(edit_diff)]),
        edit_diff)
示例#3
0
文件: edit.py 项目: xcode2010/stgit
def interactive_edit_patch(repo, cd, edit_diff, diff_flags):
    """Edit the patch interactively.

    If ``edit_diff`` is true, edit the diff as well. If ``replacement_diff`` is not
    None, it contains a diff to edit instead of the patch's real diff.

    :returns: tuple with the new :class:`stgit.lib.git.CommitData` and the diff text if
              it did not apply, or None otherwise

    """
    return update_patch_description(
        repo,
        cd,
        utils.edit_bytes(
            patch_desc(repo, cd, edit_diff, diff_flags, replacement_diff=None),
            '.stgit-edit.' + ['txt', 'patch'][bool(edit_diff)],
        ),
        edit_diff,
    )
示例#4
0
def interactive_edit_patch(repo, cd, patch_name, edit_diff, diff_flags):
    """Edit the patch interactively.

    If ``edit_diff`` is true, edit the diff as well.

    :returns: 3-tuple:
        - the new :class:`commitdata<stgit.lib.git.commitdata>`
        - the patch name if given or none otherwise
        - the diff text if it did not apply or none otherwise
    """
    patch_desc = get_patch_description(repo, cd, patch_name, edit_diff,
                                       diff_flags)
    cd, patch_name, failed_diff = _update_patch_description(
        repo,
        cd,
        utils.edit_bytes(patch_desc,
                         '.stgit-edit.' + ['txt', 'patch'][bool(edit_diff)]),
        edit_diff,
    )

    if failed_diff:
        note_patch_application_failure(patch_desc)

    return cd, patch_name, failed_diff
示例#5
0
文件: mail.py 项目: hasturkun/stgit
def __build_message(tmpl, msg_id, options, patch, patch_nr, total_nr, ref_id):
    """Build the message to be sent via SMTP
    """
    repository = directory.repository
    stack = repository.current_stack

    p = stack.patches.get(patch)

    if p.commit.data.message:
        descr = p.commit.data.message.strip()
    else:
        # provide a place holder and force the edit message option on
        descr = '<empty message>'
        options.edit_patches = True

    descr_lines = descr.split('\n')
    short_descr = descr_lines[0].strip()
    long_descr = '\n'.join(l.rstrip() for l in descr_lines[1:]).lstrip('\n')

    author = p.commit.data.author
    committer = p.commit.data.committer

    sender = __get_sender()

    if author.name_email != sender:
        fromauth = 'From: %s\n\n' % author.name_email
    else:
        fromauth = ''

    if options.version:
        version_str = '%s' % options.version
        version_space = ' '
    else:
        version_str = ''
        version_space = ''

    if options.prefix:
        prefix_str = options.prefix
    else:
        prefix_str = config.get('stgit.mail.prefix')
    if prefix_str:
        prefix_space = ' '
    else:
        prefix_str = ''
        prefix_space = ''

    total_nr_str = text(total_nr)
    patch_nr_str = text(patch_nr).zfill(len(total_nr_str))
    if not options.unrelated and total_nr > 1:
        number_str = '%s/%s' % (patch_nr_str, total_nr_str)
        number_space = ' '
    else:
        number_str = ''
        number_space = ''

    diff = repository.diff_tree(
        p.commit.data.parent.data.tree,
        p.commit.data.tree,
        diff_opts=options.diff_flags,
    )
    tmpl_dict = {
        'patch': patch,
        'sender': sender,
        'maintainer': sender,  # for backward template compatibility
        'shortdescr': short_descr,
        'longdescr': long_descr,
        'endofheaders': '',  # for backward template compatibility
        'diff': diff,
        'diffstat': diffstat(diff),
        'date': '',  # for backward template compatibility
        'version': version_str,
        'vspace': version_space,
        'prefix': prefix_str,
        'pspace': prefix_space,
        'patchnr': patch_nr_str,
        'totalnr': total_nr_str,
        'number': number_str,
        'nspace': number_space,
        'snumber': number_str.strip(),
        'fromauth': fromauth,
        'authname': author.name,
        'authemail': author.email,
        'authdate': author.date.rfc2822_format(),
        'commname': committer.name,
        'commemail': committer.email,
    }

    try:
        msg_bytes = templates.specialize_template(tmpl, tmpl_dict)
    except KeyError as err:
        raise CmdException('Unknown patch template variable: %s' % err)
    except TypeError:
        raise CmdException('Only "%(name)s" variables are '
                           'supported in the patch template')

    if options.edit_patches:
        msg_bytes = edit_bytes(msg_bytes, '.stgitmail.txt')

    # The Python email message
    try:
        msg = message_from_bytes(msg_bytes)
    except Exception as ex:
        raise CmdException('template parsing error: %s' % str(ex))

    if options.auto:
        extra_cc = __get_signers_list(descr)
    else:
        extra_cc = []

    if not options.git:
        __build_address_headers(msg, options, extra_cc)
    __build_extra_headers(msg, msg_id, ref_id)
    __encode_message(msg)

    return msg
示例#6
0
文件: mail.py 项目: hasturkun/stgit
def __build_cover(tmpl, msg_id, options, patches):
    """Build the cover message (series description) to be sent via SMTP
    """
    sender = __get_sender()

    if options.version:
        version_str = '%s' % options.version
        version_space = ' '
    else:
        version_str = ''
        version_space = ''

    if options.prefix:
        prefix_str = options.prefix
    else:
        prefix_str = config.get('stgit.mail.prefix')
    if prefix_str:
        prefix_space = ' '
    else:
        prefix_str = ''
        prefix_space = ''

    total_nr_str = text(len(patches))
    patch_nr_str = '0'.zfill(len(total_nr_str))
    if len(patches) > 1:
        number_str = '%s/%s' % (patch_nr_str, total_nr_str)
        number_space = ' '
    else:
        number_str = ''
        number_space = ''

    repository = directory.repository
    stack = repository.current_stack

    tmpl_dict = {
        'sender':
        sender,  # for backward template compatibility
        'maintainer':
        sender,  # for backward template compatibility
        'endofheaders':
        '',  # for backward template compatibility
        'date':
        '',
        'version':
        version_str,
        'vspace':
        version_space,
        'prefix':
        prefix_str,
        'pspace':
        prefix_space,
        'patchnr':
        patch_nr_str,
        'totalnr':
        total_nr_str,
        'number':
        number_str,
        'nspace':
        number_space,
        'snumber':
        number_str.strip(),
        'shortlog':
        __shortlog(stack, patches),
        'diffstat':
        repository.diff_tree(
            stack.base.data.tree,
            stack.top.data.tree,
            diff_opts=options.diff_flags,
            stat=True,
        ),
    }

    try:
        msg_bytes = templates.specialize_template(tmpl, tmpl_dict)
    except KeyError as err:
        raise CmdException('Unknown patch template variable: %s' % err)
    except TypeError:
        raise CmdException('Only "%(name)s" variables are '
                           'supported in the patch template')

    if options.edit_cover:
        msg_bytes = edit_bytes(msg_bytes, '.stgitmail.txt')

    # The Python email message
    try:
        msg = message_from_bytes(msg_bytes)
    except Exception as ex:
        raise CmdException('template parsing error: %s' % str(ex))

    extra_cc = []
    if options.auto:
        for pn in patches:
            p = stack.patches.get(pn)
            if p.commit.data.message:
                descr = p.commit.data.message.strip()
                extra_cc.extend(__get_signers_list(descr))
        extra_cc = list(set(extra_cc))

    if not options.git:
        __build_address_headers(msg, options, extra_cc)
    __build_extra_headers(msg, msg_id, options.in_reply_to)
    __encode_message(msg)

    return msg
示例#7
0
def __build_cover(tmpl, msg_id, options, patches):
    """Build the cover message (series description) to be sent via SMTP
    """
    sender = __get_sender()

    if options.version:
        version_str = '%s' % options.version
        version_space = ' '
    else:
        version_str = ''
        version_space = ''

    if options.prefix:
        prefix_str = options.prefix
    else:
        prefix_str = config.get('stgit.mail.prefix')
    if prefix_str:
        prefix_space = ' '
    else:
        prefix_str = ''
        prefix_space = ''

    total_nr_str = text(len(patches))
    patch_nr_str = '0'.zfill(len(total_nr_str))
    if len(patches) > 1:
        number_str = '%s/%s' % (patch_nr_str, total_nr_str)
        number_space = ' '
    else:
        number_str = ''
        number_space = ''

    tmpl_dict = {
        'sender':
        sender,  # for backward template compatibility
        'maintainer':
        sender,  # for backward template compatibility
        'endofheaders':
        '',  # for backward template compatibility
        'date':
        '',
        'version':
        version_str,
        'vspace':
        version_space,
        'prefix':
        prefix_str,
        'pspace':
        prefix_space,
        'patchnr':
        patch_nr_str,
        'totalnr':
        total_nr_str,
        'number':
        number_str,
        'nspace':
        number_space,
        'snumber':
        number_str.strip(),
        'shortlog':
        stack.shortlog(crt_series.get_patch(p) for p in reversed(patches)),
        'diffstat':
        gitlib.diffstat(
            git.diff(
                rev1=git_id(crt_series, '%s^' % patches[0]),
                rev2=git_id(crt_series, '%s' % patches[-1]),
                diff_flags=options.diff_flags,
            )),
    }

    try:
        msg_bytes = templates.specialize_template(tmpl, tmpl_dict)
    except KeyError as err:
        raise CmdException('Unknown patch template variable: %s' % err)
    except TypeError:
        raise CmdException('Only "%(name)s" variables are '
                           'supported in the patch template')

    if options.edit_cover:
        msg_bytes = edit_bytes(msg_bytes, '.stgitmail.txt')

    # The Python email message
    try:
        msg = message_from_bytes(msg_bytes)
    except Exception as ex:
        raise CmdException('template parsing error: %s' % str(ex))

    extra_cc = []
    if options.auto:
        for patch in patches:
            p = crt_series.get_patch(patch)
            if p.get_description():
                descr = p.get_description().strip()
                extra_cc.extend(__get_signers_list(descr))
        extra_cc = list(set(extra_cc))

    if not options.git:
        __build_address_headers(msg, options, extra_cc)
    __build_extra_headers(msg, msg_id, options.in_reply_to)
    __encode_message(msg)

    return msg
示例#8
0
文件: mail.py 项目: aboyett/stgit
def __build_message(tmpl, msg_id, options, patch, patch_nr, total_nr, ref_id):
    """Build the message to be sent via SMTP
    """
    p = crt_series.get_patch(patch)

    if p.get_description():
        descr = p.get_description().strip()
    else:
        # provide a place holder and force the edit message option on
        descr = '<empty message>'
        options.edit_patches = True

    descr_lines = descr.split('\n')
    short_descr = descr_lines[0].strip()
    long_descr = '\n'.join(l.rstrip() for l in descr_lines[1:]).lstrip('\n')

    authname = p.get_authname()
    authemail = p.get_authemail()
    commname = p.get_commname()
    commemail = p.get_commemail()

    sender = __get_sender()

    fromauth = '%s <%s>' % (authname, authemail)
    if fromauth != sender:
        fromauth = 'From: %s\n\n' % fromauth
    else:
        fromauth = ''

    if options.version:
        version_str = '%s' % options.version
        version_space = ' '
    else:
        version_str = ''
        version_space = ''

    if options.prefix:
        prefix_str = options.prefix
    else:
        prefix_str = config.get('stgit.mail.prefix')
    if prefix_str:
        prefix_space = ' '
    else:
        prefix_str = ''
        prefix_space = ''

    total_nr_str = text(total_nr)
    patch_nr_str = text(patch_nr).zfill(len(total_nr_str))
    if not options.unrelated and total_nr > 1:
        number_str = '%s/%s' % (patch_nr_str, total_nr_str)
        number_space = ' '
    else:
        number_str = ''
        number_space = ''

    diff = git.diff(rev1=git_id(crt_series, '%s^' % patch),
                    rev2=git_id(crt_series, '%s' % patch),
                    diff_flags=options.diff_flags)
    tmpl_dict = {
        'patch': patch,
        'sender': sender,
        # for backward template compatibility
        'maintainer': sender,
        'shortdescr': short_descr,
        'longdescr': long_descr,
        # for backward template compatibility
        'endofheaders': '',
        'diff': diff,
        'diffstat': gitlib.diffstat(diff),
        # for backward template compatibility
        'date': '',
        'version': version_str,
        'vspace': version_space,
        'prefix': prefix_str,
        'pspace': prefix_space,
        'patchnr': patch_nr_str,
        'totalnr': total_nr_str,
        'number': number_str,
        'nspace': number_space,
        'snumber': number_str.strip(),
        'fromauth': fromauth,
        'authname': authname,
        'authemail': authemail,
        'authdate': p.get_authdate(),
        'commname': commname,
        'commemail': commemail
    }

    try:
        msg_bytes = templates.specialize_template(tmpl, tmpl_dict)
    except KeyError as err:
        raise CmdException('Unknown patch template variable: %s' % err)
    except TypeError:
        raise CmdException('Only "%(name)s" variables are '
                           'supported in the patch template')

    if options.edit_patches:
        msg_bytes = edit_bytes(msg_bytes, '.stgitmail.txt')

    # The Python email message
    try:
        msg = message_from_bytes(msg_bytes)
    except Exception as ex:
        raise CmdException('template parsing error: %s' % str(ex))

    if options.auto:
        extra_cc = __get_signers_list(descr)
    else:
        extra_cc = []

    if not options.git:
        __build_address_headers(msg, options, extra_cc)
    __build_extra_headers(msg, msg_id, ref_id)
    __encode_message(msg)

    return msg