Package org.eclipse.jgit.merge

Examples of org.eclipse.jgit.merge.ThreeWayMerger


        String mergeMessage = new MergeMessageFormatter().format(
            commits, head);
        repo.writeMergeCommitMsg(mergeMessage);
        repo.writeMergeHeads(Arrays.asList(ref.getObjectId()));
        ThreeWayMerger merger = (ThreeWayMerger) mergeStrategy
            .newMerger(repo);
        boolean noProblems;
        Map<String, org.eclipse.jgit.merge.MergeResult<?>> lowLevelResults = null;
        Map<String, MergeFailureReason> failingPaths = null;
        List<String> unmergedPaths = null;
        if (merger instanceof ResolveMerger) {
          ResolveMerger resolveMerger = (ResolveMerger) merger;
          resolveMerger.setCommitNames(new String[] {
              "BASE", "HEAD", ref.getName() });
          resolveMerger.setWorkingTreeIterator(new FileTreeIterator(repo));
          noProblems = merger.merge(headCommit, srcCommit);
          lowLevelResults = resolveMerger
              .getMergeResults();
          failingPaths = resolveMerger.getFailingPaths();
          unmergedPaths = resolveMerger.getUnmergedPaths();
        } else
          noProblems = merger.merge(headCommit, srcCommit);

        if (noProblems) {
          DirCacheCheckout dco = new DirCacheCheckout(repo,
              headCommit.getTree(), repo.lockDirCache(),
              merger.getResultTreeId());
          dco.setFailOnConflict(true);
          dco.checkout();
          RevCommit newHead = new Git(getRepository()).commit().call();
          return new MergeResult(newHead.getId(),
              null, new ObjectId[] {
                  headCommit.getId(), srcCommit.getId() },
              MergeStatus.MERGED, mergeStrategy, null, null);
        } else {
          if (failingPaths != null) {
            repo.writeMergeCommitMsg(null);
            repo.writeMergeHeads(null);
            return new MergeResult(null,
                merger.getBaseCommit(0, 1),
                new ObjectId[] {
                    headCommit.getId(), srcCommit.getId() },
                MergeStatus.FAILED, mergeStrategy,
                lowLevelResults, failingPaths, null);
          } else {
            String mergeMessageWithConflicts = new MergeMessageFormatter()
                .formatWithConflicts(mergeMessage,
                    unmergedPaths);
            repo.writeMergeCommitMsg(mergeMessageWithConflicts);
            return new MergeResult(null,
                merger.getBaseCommit(0, 1),
                new ObjectId[] { headCommit.getId(),
                    srcCommit.getId() },
                MergeStatus.CONFLICTING, mergeStrategy,
                lowLevelResults, null);
          }
View Full Code Here


      }
    }
  }

  private void mergeOneCommit(final CodeReviewCommit n) throws MergeException {
    final ThreeWayMerger m = newThreeWayMerger();
    try {
      if (m.merge(new AnyObjectId[] {mergeTip, n})) {
        writeMergeCommit(m.getResultTreeId(), n);

      } else {
        failed(n, CommitMergeStatus.PATH_CONFLICT);
      }
    } catch (IOException e) {
View Full Code Here

      }
    }
  }

  private ThreeWayMerger newThreeWayMerger() {
    ThreeWayMerger m;
    if (destProject.isUseContentMerge()) {
      // Settings for this project allow us to try and
      // automatically resolve conflicts within files if needed.
      // Use ResolveMerge and instruct to operate in core.
      m = MergeStrategy.RESOLVE.newMerger(repo, true);
    } else {
      // No auto conflict resolving allowed. If any of the
      // affected files was modified, merge will fail.
      m = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(repo);
    }
    m.setObjectInserter(new ObjectInserter.Filter() {
      @Override
      protected ObjectInserter delegate() {
        return inserter;
      }
View Full Code Here

  }

  private void cherryPickChanges() throws MergeException, OrmException {
    while (!toMerge.isEmpty()) {
      final CodeReviewCommit n = toMerge.remove(0);
      final ThreeWayMerger m = newThreeWayMerger();
      try {
        if (mergeTip == null) {
          // The branch is unborn. Take a fast-forward resolution to
          // create the branch.
          //
          mergeTip = n;
          n.statusCode = CommitMergeStatus.CLEAN_MERGE;

        } else if (n.getParentCount() == 0) {
          // Refuse to merge a root commit into an existing branch,
          // we cannot obtain a delta for the cherry-pick to apply.
          //
          n.statusCode = CommitMergeStatus.CANNOT_CHERRY_PICK_ROOT;

        } else if (n.getParentCount() == 1) {
          // If there is only one parent, a cherry-pick can be done by
          // taking the delta relative to that one parent and redoing
          // that on the current merge tip.
          //
          m.setBase(n.getParent(0));
          if (m.merge(mergeTip, n)) {
            writeCherryPickCommit(m, n);

          } else {
            n.statusCode = CommitMergeStatus.PATH_CONFLICT;
          }
View Full Code Here

    if (base.equals(parentCommit)) {
      throw new IOException("Change is already up to date.");
    }

    final ThreeWayMerger merger = MergeStrategy.RESOLVE.newMerger(git, true);
    merger.setBase(parentCommit);
    merger.merge(original, base);

    if (merger.getResultTreeId() == null) {
      throw new IOException(
          "The rebase failed since conflicts occured during the merge.");
    }

    final CommitBuilder rebasedCommitBuilder = new CommitBuilder();

    rebasedCommitBuilder.setTreeId(merger.getResultTreeId());
    rebasedCommitBuilder.setParentId(base);
    rebasedCommitBuilder.setAuthor(original.getAuthorIdent());
    rebasedCommitBuilder.setMessage(original.getFullMessage());
    rebasedCommitBuilder.setCommitter(committerIdent);
View Full Code Here

      } else {

        repo.writeMergeCommitMsg(new MergeMessageFormatter().format(
            commits, head));
        repo.writeMergeHeads(Arrays.asList(ref.getObjectId()));
        ThreeWayMerger merger = (ThreeWayMerger) mergeStrategy
            .newMerger(repo);
        boolean noProblems;
        Map<String, org.eclipse.jgit.merge.MergeResult<?>> lowLevelResults = null;
        Map<String, MergeFailureReason> failingPaths = null;
        if (merger instanceof ResolveMerger) {
          ResolveMerger resolveMerger = (ResolveMerger) merger;
          resolveMerger.setCommitNames(new String[] {
              "BASE", "HEAD", ref.getName() });
          resolveMerger.setWorkingTreeIterator(new FileTreeIterator(repo));
          noProblems = merger.merge(headCommit, srcCommit);
          lowLevelResults = resolveMerger
              .getMergeResults();
          failingPaths = resolveMerger.getFailingPaths();
        } else
          noProblems = merger.merge(headCommit, srcCommit);

        if (noProblems) {
          DirCacheCheckout dco = new DirCacheCheckout(repo,
              headCommit.getTree(), repo.lockDirCache(),
              merger.getResultTreeId());
          dco.setFailOnConflict(true);
          dco.checkout();
          RevCommit newHead = new Git(getRepository()).commit().call();
          return new MergeResult(newHead.getId(),
              null, new ObjectId[] {
                  headCommit.getId(), srcCommit.getId() },
              MergeStatus.MERGED, mergeStrategy, null, null);
        } else {
          if (failingPaths != null) {
            repo.writeMergeCommitMsg(null);
            repo.writeMergeHeads(null);
            return new MergeResult(null,
                merger.getBaseCommit(0, 1),
                new ObjectId[] {
                    headCommit.getId(), srcCommit.getId() },
                MergeStatus.FAILED, mergeStrategy,
                lowLevelResults, null);
          } else
            return new MergeResult(null,
                merger.getBaseCommit(0, 1),
                new ObjectId[] { headCommit.getId(),
                    srcCommit.getId() },
                MergeStatus.CONFLICTING, mergeStrategy,
                lowLevelResults, null);
        }
View Full Code Here

    ObjectId theirsId = write(theirsList);
    inserter.flush();

    ObjectId resultTreeId;
    if (nonNotesMergeStrategy instanceof ThreeWayMergeStrategy) {
      ThreeWayMerger m = ((ThreeWayMergeStrategy) nonNotesMergeStrategy)
          .newMerger(db, true);
      m.setBase(baseId);
      if (!m.merge(oursId, theirsId))
        throw new NotesMergeConflictException(baseList, oursList,
            theirsList);

      resultTreeId = m.getResultTreeId();
    } else {
      Merger m = nonNotesMergeStrategy.newMerger(db, true);
      if (!m.merge(new AnyObjectId[] { oursId, theirsId }))
        throw new NotesMergeConflictException(baseList, oursList,
            theirsList);
      resultTreeId = m.getResultTreeId();
    }
    AbbreviatedObjectId none = AbbreviatedObjectId.fromString("");
    return NoteParser.parse(none, resultTreeId, reader).nonNotes;
  }
View Full Code Here

    if (scope.contains("..")) { //$NON-NLS-1$
      String[] commits = scope.split("\\.\\."); //$NON-NLS-1$
      if (commits.length != 2) {
        throw new IllegalArgumentException(NLS.bind("Illegal scope format, expected {old}..{new}, was {0}", scope));
      }
      ThreeWayMerger merger = new ResolveMerger(db) {
        @Override
        protected boolean mergeImpl() throws IOException {
          // do nothing
          return false;
        }
      };
      // use #merge to set sourceObjects
      String tip0 = GitUtils.decode(commits[0]);
      String tip1 = GitUtils.decode(commits[1]);
      merger.merge(new ObjectId[] { db.resolve(tip0), db.resolve(tip1) });
      RevCommit baseCommit = merger.getBaseCommit(0, 1);

      IPath p = new Path(GitServlet.GIT_URI + '/' + Commit.RESOURCE).append(baseCommit.getId().getName()).append(path.removeFirstSegments(1));
      return new URI(location.getScheme(), location.getUserInfo(), location.getHost(), location.getPort(), p.toString(), "parts=body", null); //$NON-NLS-1$
    } else if (scope.equals(GitConstants.KEY_DIFF_CACHED)) {
      // HEAD is the base
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.merge.ThreeWayMerger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.