示例#1
0
 def _commit_modified(self,
                      commit,
                      input_work_dir,
                      output_work_dir,
                      last_failure_shortlog,
                      tree_id=None,
                      parents=None,
                      add_id=True):
     if commit.revert or last_failure_shortlog:
         env = {
             'GIT_COMMITTER_NAME': self.git_name,
             'GIT_COMMITTER_EMAIL': self.git_email,
             'GIT_AUTHOR_NAME': self.git_name,
             'GIT_AUTHOR_EMAIL': self.git_email,
         }
     else:
         env = git.commit_env_vars(commit.tree_id, tree=input_work_dir)
         env.update({
             'GIT_COMMITTER_NAME': self.git_name,
             'GIT_COMMITTER_EMAIL': self.git_email,
         })
     if commit.revert:
         msg = git.commit_message(commit.msg_id, tree=input_work_dir)
         subj = msg.split('\n')[0]
         msg = 'Revert "%s"\n\n' % subj
         msg += 'This commit was rebased out so revert it here.'
     elif last_failure_shortlog:
         msg = 'mirror: multi-input commit\n\n'
         msg += 'Some commits failed to generate and were skipped. This commit\n'
         msg += 'is a combination of them, with the following original commits:\n\n'
         msg += last_failure_shortlog
     else:
         msg = git.commit_message(commit.msg_id, tree=input_work_dir)
     if msg[-1] != '\n':
         msg += '\n'
     self._commit(commit, msg, env, output_work_dir, tree_id, parents,
                  add_id)
示例#2
0
    def _find_commits(self, branch, start_commit, input_work_dir,
                      output_work_dir):
        # If somebody manually modified the output tree without pointing to an
        # input tree commit (which really should happen only in the case of
        # ChromeOS where we may merge upstream) then search for the original
        # commit pointer also in the parent, etc. of the top-most output commit.
        last_commit = None

        for back in range(self.max_parents):
            last_commit = git.get_note(self.notes_branch,
                                       '%s~%d' % (start_commit, back),
                                       tree=output_work_dir)
            if last_commit is not None:
                last_commit = last_commit.strip()
                self.debug(
                    'Found note on %s~%d indicating last checked commit is %s'
                    % (start_commit, back, last_commit))
                break

            try:
                msg = git.commit_message('%s~%d' % (start_commit, back),
                                         tree=output_work_dir)
            except git.GitError:
                msg = ''
            match = self._id_re.search(msg)
            if match:
                last_commit = match.group(1)
                break

        if last_commit:
            return self._log_commits(last_commit, 'origin/' + branch,
                                     input_work_dir)

        # Note that this is also important if working on a new branch, where
        # we get here through self._need_to_mirror() with start_commit being
        # just the branch name - so above we'll have tried something like
        # new_branch~0, new_branch~1 etc. none of which can exists. So now
        # this will give up and tell us to create just the single commit,
        # which at least is some work to do so we can sort it out later in
        # self._prepare_output_git() which detects and bases a new branch
        # properly.
        commit_id = git.rev_parse('origin/' + branch, tree=input_work_dir)
        return [Commit(commit_id, input_work_dir)]
示例#3
0
 def __repr__(self):
     subj = git.commit_message(self._tree_id,
                               tree=self._tree).split('\n')[0]
     return '<Commit(tree=%s,id=%s,subj=%s)>' % (self._tree, self._tree_id,
                                                 subj)