Exemple #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
Exemple #2
0
def auto_edit_patch(repo, cd, msg, author, sign_str):
    """Edit the patch noninteractively in a couple of ways:

         - If C{msg} is not C{None}, parse it to find a replacement
           message, and possibly also replacement author and timestamp.

         - C{author} is a function that takes the original
           L{Person<stgit.lib.git.Person>} value as argument, and
           return the new one.

         - C{sign_str}, if not C{None}, is a sign string to append to
           the message.

    Return a pair: the new L{CommitData<stgit.lib.git.CommitData>};
    and the diff text if it didn't apply, or C{None} otherwise."""
    if msg is not None:
        cd, failed_diff = update_patch_description(repo,
                                                   cd,
                                                   msg,
                                                   contains_diff=False)
        assert not failed_diff
    a = author(cd.author)
    if a != cd.author:
        cd = cd.set_author(a)
    if sign_str is not None:
        cd = cd.set_message(
            utils.add_trailer(
                cd.message_str,
                sign_str,
                Person.committer().name,
                Person.committer().email,
            ))
    return cd
Exemple #3
0
def auto_edit_patch(repo, cd, msg, author, sign_str):
    """Edit the patch noninteractively in a couple of ways:

    * If ``msg`` is not None, parse it to find a replacement message, and possibly also
      replacement author and timestamp.

    * ``author`` is a function that takes the original :class:`stgit.lib.git.Person`
      value as argument, and returns the new one.

    * ``sign_str, if not None, is a trailer string to append to the message.

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

    """
    if msg is not None:
        cd, failed_diff = update_patch_description(repo,
                                                   cd,
                                                   msg,
                                                   contains_diff=False)
        assert not failed_diff
    a = author(cd.author)
    if a != cd.author:
        cd = cd.set_author(a)
    if sign_str is not None:
        cd = cd.set_message(
            utils.add_trailer(
                cd.message_str,
                sign_str,
                Person.committer().name,
                Person.committer().email,
            ))
    return cd
Exemple #4
0
def update_commit_data(cd,
                       message=None,
                       author=None,
                       sign_str=None,
                       edit=False,
                       verbose=False):
    """Create updated CommitData 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:
        message_str = cd.message_str
        tmpl = templates.get_template('patchdescr.tmpl')
        if tmpl:
            message_str += tmpl

        status = '\n# '.join(_git_status())
        message_str += COMMIT_MESSAGE_INSTRUCTIONS + status
        if verbose:
            # include a diff
            message_str += (COMMIT_MESSAGE_DEMARCATION_LINE +
                            COMMIT_MESSAGE_INSTRUCTIONS_2)
            message_str += '\n'.join(_git_diff())
        new_message = edit_string(message_str, '.stgit-new.txt')
        new_message = new_message.split(COMMIT_MESSAGE_DEMARCATION_LINE)[0]
        new_message = '\n'.join(line for line in new_message.splitlines()
                                if not line.startswith('#'))
        cd = cd.set_message(new_message)

    return cd