コード例 #1
0
def auto_edit_patch(repo, cd, msg, contains_diff, author, committer, 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. If C{contains_diff} is true, also look for a
           replacement diff.

         - C{author} and C{committer} are two functions that take 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 None:
        failed_diff = None
    else:
        cd, failed_diff = update_patch_description(repo, cd, msg,
                                                   contains_diff)
    a, c = author(cd.author), committer(cd.committer)
    if (a, c) != (cd.author, cd.committer):
        cd = cd.set_author(a).set_committer(c)
    if sign_str is not None:
        cd = cd.set_message(
            utils.add_sign_line(
                cd.message,
                sign_str,
                Person.committer().name,
                Person.committer().email,
            ))
    return cd, failed_diff
コード例 #2
0
def update_commit_data(cd, options):
    """Return a new CommitData object updated according to the command line
    options."""
    # Set the commit message from commandline.
    if options.message is not None:
        cd = cd.set_message(options.message)

    # Modify author data.
    cd = cd.set_author(options.author(cd.author))

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

    # Let user edit the commit message manually, unless
    # --save-template or --message was specified.
    if not getattr(options, 'save_template', None) and options.message is None:
        tmpl = templates.get_template('patchdescr.tmpl')
        if tmpl:
            cd = cd.set_message(cd.message + tmpl)
        cd = cd.set_message(edit_string(cd.message, '.stgit-new.txt'))

    return cd
コード例 #3
0
ファイル: common.py プロジェクト: hasturkun/stgit
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_sign_line(
                cd.message, 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_string(cd.message, '.stgit-new.txt'))

    return cd
コード例 #4
0
ファイル: edit.py プロジェクト: samv/stgit
def auto_edit_patch(repo, cd, msg, contains_diff, author, committer, 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. If C{contains_diff} is true, also look for a
           replacement diff.

         - C{author} and C{committer} are two functions that take 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 == None:
        failed_diff = None
    else:
        cd, failed_diff = update_patch_description(repo, cd, msg, contains_diff)
    a, c = author(cd.author), committer(cd.committer)
    if (a, c) != (cd.author, cd.committer):
        cd = cd.set_author(a).set_committer(c)
    if sign_str != None:
        cd = cd.set_message(utils.add_sign_line(
                cd.message, sign_str, git.Person.committer().name,
                git.Person.committer().email))
    return cd, failed_diff
コード例 #5
0
ファイル: common.py プロジェクト: snits/stgit
def update_commit_data(cd, options):
    """Return a new CommitData object updated according to the command line
    options."""
    # Set the commit message from commandline.
    if options.message is not None:
        cd = cd.set_message(options.message)

    # Modify author data.
    cd = cd.set_author(options.author(cd.author))

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

    # Let user edit the commit message manually, unless
    # --save-template or --message was specified.
    if not getattr(options, 'save_template', None) and options.message is None:
        cd = cd.set_message(edit_string(cd.message, '.stgit-new.txt'))

    return cd
コード例 #6
0
ファイル: stack.py プロジェクト: snits/stgit
 def sign(msg):
     return add_sign_line(msg, sign_str,
                          committer_name or git.committer().name,
                          committer_email or git.committer().email)
コード例 #7
0
ファイル: stack.py プロジェクト: snits/stgit
    def refresh_patch(self, files = None, message = None, edit = False,
                      empty = False,
                      show_patch = False,
                      cache_update = True,
                      author_name = None, author_email = None,
                      author_date = None,
                      committer_name = None, committer_email = None,
                      backup = True, sign_str = None, log = 'refresh',
                      notes = None, bottom = None):
        """Generates a new commit for the topmost patch
        """
        patch = self.get_current_patch()
        if not patch:
            raise StackException('No patches applied')

        descr = patch.get_description()
        if not (message or descr):
            edit = True
            descr = ''
        elif message:
            descr = message

        # TODO: move this out of the stgit.stack module, it is really
        # for higher level commands to handle the user interaction
        if not message and edit:
            descr = edit_file(self, descr.rstrip(), \
                              'Please edit the description for patch "%s" ' \
                              'above.' % patch.get_name(), show_patch)

        if not author_name:
            author_name = patch.get_authname()
        if not author_email:
            author_email = patch.get_authemail()
        if not committer_name:
            committer_name = patch.get_commname()
        if not committer_email:
            committer_email = patch.get_commemail()

        descr = add_sign_line(descr, sign_str, committer_name, committer_email)

        if not bottom:
            bottom = patch.get_bottom()

        if empty:
            tree_id = git.get_commit(bottom).get_tree()
        else:
            tree_id = None

        commit_id = git.commit(files = files,
                               message = descr, parents = [bottom],
                               cache_update = cache_update,
                               tree_id = tree_id,
                               set_head = True,
                               allowempty = True,
                               author_name = author_name,
                               author_email = author_email,
                               author_date = author_date,
                               committer_name = committer_name,
                               committer_email = committer_email)

        patch.set_top(commit_id, backup = backup)
        patch.set_description(descr)
        patch.set_authname(author_name)
        patch.set_authemail(author_email)
        patch.set_authdate(author_date)
        patch.set_commname(committer_name)
        patch.set_commemail(committer_email)

        if log:
            self.log_patch(patch, log, notes)

        return commit_id
コード例 #8
0
 def sign(msg):
     return add_sign_line(msg, sign_str,
                          committer_name or git.committer().name,
                          committer_email or git.committer().email)
コード例 #9
0
    def refresh_patch(
        self,
        files=None,
        message=None,
        edit=False,
        empty=False,
        show_patch=False,
        cache_update=True,
        author_name=None,
        author_email=None,
        author_date=None,
        committer_name=None,
        committer_email=None,
        backup=True,
        sign_str=None,
        log='refresh',
        notes=None,
        bottom=None
    ):
        """Generates a new commit for the topmost patch
        """
        patch = self.get_current_patch()
        if not patch:
            raise StackException('No patches applied')

        descr = patch.get_description()
        if not (message or descr):
            edit = True
            descr = ''
        elif message:
            descr = message

        # TODO: move this out of the stgit.stack module, it is really
        # for higher level commands to handle the user interaction
        if not message and edit:
            descr = edit_file(
                self,
                descr.rstrip(),
                'Please edit the description for patch "%s" above.' % (
                    patch.get_name(),
                    show_patch,
                )
            )

        if not author_name:
            author_name = patch.get_authname()
        if not author_email:
            author_email = patch.get_authemail()
        if not committer_name:
            committer_name = patch.get_commname()
        if not committer_email:
            committer_email = patch.get_commemail()

        descr = add_sign_line(descr, sign_str, committer_name, committer_email)

        if not bottom:
            bottom = patch.get_bottom()

        if empty:
            tree_id = git.get_commit(bottom).get_tree()
        else:
            tree_id = None

        commit_id = git.commit(
            files=files,
            message=descr,
            parents=[bottom],
            cache_update=cache_update,
            tree_id=tree_id,
            set_head=True,
            allowempty=True,
            author_name=author_name,
            author_email=author_email,
            author_date=author_date,
            committer_name=committer_name,
            committer_email=committer_email
        )

        patch.set_top(commit_id, backup=backup)
        patch.set_description(descr)
        patch.set_authname(author_name)
        patch.set_authemail(author_email)
        patch.set_authdate(author_date)
        patch.set_commname(committer_name)
        patch.set_commemail(committer_email)

        if log:
            self.log_patch(patch, log, notes)

        return commit_id