Ejemplo n.º 1
0
 def write_commit(self):
     metadata = self.__metadata_string()
     tree = self.__tree(metadata)
     self.__simplified = self.__repo.commit(
         git.CommitData(tree=tree,
                        message=self.message,
                        parents=[
                            prev.simplified for prev in [self.prev]
                            if prev is not None
                        ]))
     parents = list(self.__parents())
     while len(parents) >= self.__max_parents:
         g = self.__repo.commit(
             git.CommitData(
                 tree=tree,
                 parents=parents[-self.__max_parents:],
                 message='Stack log parent grouping',
             ))
         parents[-self.__max_parents:] = [g]
     self.commit = self.__repo.commit(
         git.CommitData(
             tree=tree,
             message=self.message,
             parents=[self.simplified] + parents,
         ))
Ejemplo n.º 2
0
def _squash_patches(trans, patches, msg, save_template, no_verify=False):
    cd = trans.patches[patches[0]].data
    cd = git.CommitData(tree=cd.tree, parents=cd.parents)
    for pn in patches[1:]:
        c = trans.patches[pn]
        tree = trans.stack.repository.simple_merge(
            base=c.data.parent.data.tree, ours=cd.tree, theirs=c.data.tree)
        if not tree:
            return None
        cd = cd.set_tree(tree)
    if msg is None:
        msg = utils.append_comment(
            trans.patches[patches[0]].data.message,
            '\n\n'.join('%s\n\n%s' %
                        (pn.ljust(70, '-'), trans.patches[pn].data.message)
                        for pn in patches[1:]))
        if save_template:
            save_template(msg)
            raise SaveTemplateDone()
        else:
            msg = utils.edit_string(msg, '.stgit-squash.txt')
    msg = utils.strip_comment(msg).strip()
    cd = cd.set_message(msg)

    if not no_verify:
        cd = common.run_commit_msg_hook(trans.stack.repository, cd)

    return cd
Ejemplo n.º 3
0
def __create_commit(repository, tree, parents, options, message=''):
    """Return a new Commit object."""
    cd = git.CommitData(tree=tree,
                        parents=parents,
                        message=message,
                        author=git.Person.author(),
                        committer=git.Person.committer())
    cd = common.update_commit_data(cd, options)

    return repository.commit(cd)
Ejemplo n.º 4
0
 def write_patchlog():
     try:
         old_log = [self.__stack.repository.refs.get(self.__log_ref)]
     except KeyError:
         old_log = []
     cd = git.CommitData(tree=new_commit.data.tree,
                         parents=old_log,
                         message='%s\t%s' % (msg, new_commit.sha1))
     c = self.__stack.repository.commit(cd)
     self.__stack.repository.refs.set(self.__log_ref, c, msg)
     return c
Ejemplo n.º 5
0
def make_temp_patch(stack, patch_name, paths, temp_index):
    """Commit index to temp patch, in a complete transaction. If any path
    limiting is in effect, use a temp index."""
    tree = write_tree(stack, paths, temp_index)
    commit = stack.repository.commit(git.CommitData(
            tree = tree, parents = [stack.head],
            message = 'Refresh of %s' % patch_name))
    temp_name = utils.make_patch_name('refresh-temp', stack.patches.exists)
    trans = transaction.StackTransaction(stack,
                                         'refresh (create temporary patch)')
    trans.patches[temp_name] = commit
    trans.applied.append(temp_name)
    return trans.run(stack.repository.default_iw,
                     print_current_patch = False), temp_name
Ejemplo n.º 6
0
def func(parser, options, args):
    """Create a new patch."""
    stack = directory.repository.current_stack
    if stack.repository.default_index.conflicts():
        raise common.CmdException(
            'Cannot create a new patch -- resolve conflicts first')

    # Choose a name for the new patch -- or None, which means make one
    # up later when we've gotten hold of the commit message.
    if len(args) == 0:
        name = None
    elif len(args) == 1:
        name = args[0]
        if stack.patches.exists(name):
            raise common.CmdException('%s: patch already exists' % name)
    else:
        parser.error('incorrect number of arguments')

    cd = gitlib.CommitData(
        tree=stack.head.data.tree,
        parents=[stack.head],
        message='',
        author=gitlib.Person.author(),
        committer=gitlib.Person.committer(),
    )
    cd = common.update_commit_data(cd, options)

    if options.save_template:
        options.save_template(cd.message.encode('utf-8'))
        return utils.STGIT_SUCCESS

    if not options.no_verify:
        cd = common.run_commit_msg_hook(stack.repository, cd)

    if name is None:
        name = utils.make_patch_name(cd.message,
                                     lambda name: stack.patches.exists(name))

    # Write the new patch.
    stack.repository.default_iw
    trans = transaction.StackTransaction(stack, 'new')
    trans.patches[name] = stack.repository.commit(cd)
    trans.applied.append(name)
    return trans.run()