Пример #1
0
  public CodeReviewCommit createCherryPickFromCommit(
      Repository repo,
      ObjectInserter inserter,
      RevCommit mergeTip,
      RevCommit originalCommit,
      PersonIdent cherryPickCommitterIdent,
      String commitMsg,
      CodeReviewRevWalk rw)
      throws MissingObjectException, IncorrectObjectTypeException, IOException,
          MergeIdenticalTreeException, MergeConflictException {

    final ThreeWayMerger m = newThreeWayMerger(repo, inserter);

    m.setBase(originalCommit.getParent(0));
    if (m.merge(mergeTip, originalCommit)) {
      ObjectId tree = m.getResultTreeId();
      if (tree.equals(mergeTip.getTree())) {
        throw new MergeIdenticalTreeException("identical tree");
      }

      CommitBuilder mergeCommit = new CommitBuilder();
      mergeCommit.setTreeId(tree);
      mergeCommit.setParentId(mergeTip);
      mergeCommit.setAuthor(originalCommit.getAuthorIdent());
      mergeCommit.setCommitter(cherryPickCommitterIdent);
      mergeCommit.setMessage(commitMsg);
      return rw.parseCommit(commit(inserter, mergeCommit));
    } else {
      throw new MergeConflictException("merge conflict");
    }
  }
    @Override
    public ChangeKind load(Key key) throws IOException {
      if (Objects.equal(key.prior, key.next)) {
        return ChangeKind.NO_CODE_CHANGE;
      }

      RevWalk walk = new RevWalk(key.repo);
      try {
        RevCommit prior = walk.parseCommit(key.prior);
        walk.parseBody(prior);
        RevCommit next = walk.parseCommit(key.next);
        walk.parseBody(next);

        if (!next.getFullMessage().equals(prior.getFullMessage())) {
          if (next.getTree() == prior.getTree() && isSameParents(prior, next)) {
            return ChangeKind.NO_CODE_CHANGE;
          } else {
            return ChangeKind.REWORK;
          }
        }

        if (prior.getParentCount() != 1 || next.getParentCount() != 1) {
          // Trivial rebases done by machine only work well on 1 parent.
          return ChangeKind.REWORK;
        }

        if (next.getTree() == prior.getTree() && isSameParents(prior, next)) {
          return ChangeKind.TRIVIAL_REBASE;
        }

        // A trivial rebase can be detected by looking for the next commit
        // having the same tree as would exist when the prior commit is
        // cherry-picked onto the next commit's new first parent.
        ThreeWayMerger merger =
            MergeUtil.newThreeWayMerger(
                key.repo, MergeUtil.createDryRunInserter(), key.strategyName);
        merger.setBase(prior.getParent(0));
        if (merger.merge(next.getParent(0), prior)
            && merger.getResultTreeId().equals(next.getTree())) {
          return ChangeKind.TRIVIAL_REBASE;
        } else {
          return ChangeKind.REWORK;
        }
      } finally {
        key.repo = null;
        walk.release();
      }
    }
Пример #3
0
 public CodeReviewCommit mergeOneCommit(
     PersonIdent author,
     PersonIdent committer,
     Repository repo,
     CodeReviewRevWalk rw,
     ObjectInserter inserter,
     RevFlag canMergeFlag,
     Branch.NameKey destBranch,
     CodeReviewCommit mergeTip,
     CodeReviewCommit n)
     throws IntegrationException {
   final ThreeWayMerger m = newThreeWayMerger(repo, inserter);
   try {
     if (m.merge(new AnyObjectId[] {mergeTip, n})) {
       return writeMergeCommit(
           author,
           committer,
           rw,
           inserter,
           canMergeFlag,
           destBranch,
           mergeTip,
           m.getResultTreeId(),
           n);
     } else {
       failed(rw, canMergeFlag, mergeTip, n, CommitMergeStatus.PATH_CONFLICT);
     }
   } catch (NoMergeBaseException e) {
     try {
       failed(rw, canMergeFlag, mergeTip, n, getCommitMergeStatus(e.getReason()));
     } catch (IOException e2) {
       throw new IntegrationException("Cannot merge " + n.name(), e);
     }
   } catch (IOException e) {
     throw new IntegrationException("Cannot merge " + n.name(), e);
   }
   return mergeTip;
 }