Package org.eclipse.jgit.revwalk

Examples of org.eclipse.jgit.revwalk.RevCommit


   * invocation of the command. Don't call this method twice on an instance.
   *
   * @return the result of the cherry-pick
   */
  public CherryPickResult call() throws GitAPIException {
    RevCommit newHead = null;
    List<Ref> cherryPickedRefs = new LinkedList<Ref>();
    checkCallable();

    RevWalk revWalk = new RevWalk(repo);
    try {

      // get the head commit
      Ref headRef = repo.getRef(Constants.HEAD);
      if (headRef == null)
        throw new NoHeadException(
            JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
      RevCommit headCommit = revWalk.parseCommit(headRef.getObjectId());

      newHead = headCommit;

      // loop through all refs to be cherry-picked
      for (Ref src : commits) {
        // get the commit to be cherry-picked
        // handle annotated tags
        ObjectId srcObjectId = src.getPeeledObjectId();
        if (srcObjectId == null)
          srcObjectId = src.getObjectId();
        RevCommit srcCommit = revWalk.parseCommit(srcObjectId);

        // get the parent of the commit to cherry-pick
        if (srcCommit.getParentCount() != 1)
          throw new MultipleParentsNotAllowedException(
              MessageFormat.format(
                  JGitText.get().canOnlyCherryPickCommitsWithOneParent,
                  srcCommit.name(),
                  Integer.valueOf(srcCommit.getParentCount())));

        RevCommit srcParent = srcCommit.getParent(0);
        revWalk.parseHeaders(srcParent);

        ResolveMerger merger = (ResolveMerger) MergeStrategy.RESOLVE
            .newMerger(repo);
        merger.setWorkingTreeIterator(new FileTreeIterator(repo));
        merger.setBase(srcParent.getTree());
        if (merger.merge(headCommit, srcCommit)) {
          if (AnyObjectId.equals(headCommit.getTree().getId(), merger
              .getResultTreeId()))
            continue;
          DirCacheCheckout dco = new DirCacheCheckout(repo,
View Full Code Here


      remaining = c.sourceText.size();
      push(c);
      return this;
    }

    RevCommit commit = revPool.parseCommit(id);
    if (!find(commit, resultPath))
      return this;

    Candidate c = new Candidate(commit, resultPath);
    c.sourceBlob = idBuf.toObjectId();
View Full Code Here

      }
    }
  }

  private boolean processOne(Candidate n) throws IOException {
    RevCommit parent = n.getParent(0);
    if (parent == null)
      return split(n.getNextCandidate(0), n);
    if (parent.has(SEEN))
      return false;
    revPool.parseHeaders(parent);

    if (find(parent, n.sourcePath)) {
      if (idBuf.equals(n.sourceBlob)) {
View Full Code Here

  private boolean processMerge(Candidate n) throws IOException {
    int pCnt = n.getParentCount();

    for (int pIdx = 0; pIdx < pCnt; pIdx++) {
      RevCommit parent = n.getParent(pIdx);
      if (parent.has(SEEN))
        continue;
      revPool.parseHeaders(parent);
    }

    // If any single parent exactly matches the merge, follow only
    // that one parent through history.
    ObjectId[] ids = null;
    for (int pIdx = 0; pIdx < pCnt; pIdx++) {
      RevCommit parent = n.getParent(pIdx);
      if (parent.has(SEEN))
        continue;
      if (!find(parent, n.sourcePath))
        continue;
      if (!(n instanceof ReverseCandidate) && idBuf.equals(n.sourceBlob)) {
        n.sourceCommit = parent;
        push(n);
        return false;
      }
      if (ids == null)
        ids = new ObjectId[pCnt];
      ids[pIdx] = idBuf.toObjectId();
    }

    // If rename detection is enabled, search for any relevant names.
    DiffEntry[] renames = null;
    if (renameDetector != null) {
      renames = new DiffEntry[pCnt];
      for (int pIdx = 0; pIdx < pCnt; pIdx++) {
        RevCommit parent = n.getParent(pIdx);
        if (parent.has(SEEN))
          continue;
        if (ids != null && ids[pIdx] != null)
          continue;

        DiffEntry r = findRename(parent, n.sourceCommit, n.sourcePath);
        if (r == null)
          continue;

        if (n instanceof ReverseCandidate) {
          if (ids == null)
            ids = new ObjectId[pCnt];
          ids[pCnt] = r.getOldId().toObjectId();
        } else if (0 == r.getOldId().prefixCompare(n.sourceBlob)) {
          // A 100% rename without any content change can also
          // skip directly to the parent. Note this bypasses an
          // earlier parent that had the path (above) but did not
          // have an exact content match. For performance reasons
          // we choose to follow the one parent over trying to do
          // possibly both parents.
          n.sourceCommit = parent;
          n.sourcePath = PathFilter.create(r.getOldPath());
          push(n);
          return false;
        }

        renames[pIdx] = r;
      }
    }

    // Construct the candidate for each parent.
    Candidate[] parents = new Candidate[pCnt];
    for (int pIdx = 0; pIdx < pCnt; pIdx++) {
      RevCommit parent = n.getParent(pIdx);
      if (parent.has(SEEN))
        continue;

      Candidate p;
      if (renames != null && renames[pIdx] != null) {
        p = n.create(parent,
View Full Code Here

   *         returned. If a failure occurred during revert <code>null</code>
   *         is returned. The list of successfully reverted {@link Ref}'s can
   *         be obtained by calling {@link #getRevertedRefs()}
   */
  public RevCommit call() throws GitAPIException {
    RevCommit newHead = null;
    checkCallable();

    RevWalk revWalk = new RevWalk(repo);
    try {

      // get the head commit
      Ref headRef = repo.getRef(Constants.HEAD);
      if (headRef == null)
        throw new NoHeadException(
            JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
      RevCommit headCommit = revWalk.parseCommit(headRef.getObjectId());

      newHead = headCommit;

      // loop through all refs to be reverted
      for (Ref src : commits) {
        // get the commit to be reverted
        // handle annotated tags
        ObjectId srcObjectId = src.getPeeledObjectId();
        if (srcObjectId == null)
          srcObjectId = src.getObjectId();
        RevCommit srcCommit = revWalk.parseCommit(srcObjectId);

        // get the parent of the commit to revert
        if (srcCommit.getParentCount() != 1) {
          throw new MultipleParentsNotAllowedException(
              JGitText.get().canOnlyRevertCommitsWithOneParent);
        }
        RevCommit srcParent = srcCommit.getParent(0);
        revWalk.parseHeaders(srcParent);

        ResolveMerger merger = (ResolveMerger) MergeStrategy.RESOLVE
            .newMerger(repo);
        merger.setWorkingTreeIterator(new FileTreeIterator(repo));
        merger.setBase(srcCommit.getTree());

        if (merger.merge(headCommit, srcParent)) {
          if (AnyObjectId.equals(headCommit.getTree().getId(), merger
              .getResultTreeId()))
            continue;
          DirCacheCheckout dco = new DirCacheCheckout(repo,
              headCommit.getTree(), repo.lockDirCache(),
              merger.getResultTreeId());
          dco.setFailOnConflict(true);
          dco.checkout();
          String shortMessage = "Revert \"" + srcCommit.getShortMessage() + "\"";
          String newMessage = shortMessage + "\n\n"
              + "This reverts commit "
              + srcCommit.getId().getName() + ".\n";
          newHead = new Git(getRepository()).commit()
              .setMessage(newMessage)
              .setReflogComment("revert: " + shortMessage).call();
          revertedRefs.add(src);
        } else {
          unmergedPaths = merger.getUnmergedPaths();
          Map<String, MergeFailureReason> failingPaths = merger
              .getFailingPaths();
          if (failingPaths != null)
            failingResult = new MergeResult(null,
                merger.getBaseCommit(0, 1),
                new ObjectId[] { headCommit.getId(),
                    srcParent.getId() },
                MergeStatus.FAILED, MergeStrategy.RESOLVE,
                merger.getMergeResults(), failingPaths, null);
          return null;
        }
      }
View Full Code Here

   *
   * @return an object describing the result of this command
   */
  public RebaseResult call() throws NoHeadException, RefNotFoundException,
      JGitInternalException, GitAPIException {
    RevCommit newHead = null;
    boolean lastStepWasForward = false;
    checkCallable();
    checkParameters();
    try {
      switch (operation) {
      case ABORT:
        try {
          return abort(RebaseResult.ABORTED_RESULT);
        } catch (IOException ioe) {
          throw new JGitInternalException(ioe.getMessage(), ioe);
        }
      case SKIP:
        // fall through
      case CONTINUE:
        String upstreamCommitName = readFile(rebaseDir, ONTO);
        this.upstreamCommit = walk.parseCommit(repo
            .resolve(upstreamCommitName));
        break;
      case BEGIN:
        RebaseResult res = initFilesAndRewind();
        if (res != null)
          return res;
      }

      if (monitor.isCancelled())
        return abort(RebaseResult.ABORTED_RESULT);

      if (operation == Operation.CONTINUE)
        newHead = continueRebase();

      if (operation == Operation.SKIP)
        newHead = checkoutCurrentHead();

      ObjectReader or = repo.newObjectReader();

      List<Step> steps = loadSteps();
      for (Step step : steps) {
        popSteps(1);
        Collection<ObjectId> ids = or.resolve(step.commit);
        if (ids.size() != 1)
          throw new JGitInternalException(
              "Could not resolve uniquely the abbreviated object ID");
        RevCommit commitToPick = walk
            .parseCommit(ids.iterator().next());
        if (monitor.isCancelled())
          return new RebaseResult(commitToPick);
        try {
          monitor.beginTask(MessageFormat.format(
              JGitText.get().applyingCommit,
              commitToPick.getShortMessage()),
              ProgressMonitor.UNKNOWN);
          // if the first parent of commitToPick is the current HEAD,
          // we do a fast-forward instead of cherry-pick to avoid
          // unnecessary object rewriting
          newHead = tryFastForward(commitToPick);
View Full Code Here

      }
    } finally {
      dc.unlock();
    }
    RevWalk rw = new RevWalk(repo);
    RevCommit commit = rw.parseCommit(repo.resolve(Constants.HEAD));
    rw.release();
    return commit;
  }
View Full Code Here

      headName = "detached HEAD";
    ObjectId headId = head.getObjectId();
    if (headId == null)
      throw new RefNotFoundException(MessageFormat.format(
          JGitText.get().refNotResolved, Constants.HEAD));
    RevCommit headCommit = walk.lookupCommit(headId);
    RevCommit upstream = walk.lookupCommit(upstreamCommit.getId());

    if (walk.isMergedInto(upstream, headCommit))
      return RebaseResult.UP_TO_DATE_RESULT;
    else if (walk.isMergedInto(headCommit, upstream)) {
      // head is already merged into upstream, fast-foward
View Full Code Here

    ObjectId headId = head.getObjectId();
    if (headId == null)
      throw new RefNotFoundException(MessageFormat.format(
          JGitText.get().refNotResolved, Constants.HEAD));
    RevCommit headCommit = walk.lookupCommit(headId);
    if (walk.isMergedInto(newCommit, headCommit))
      return newCommit;

    String headName;
    if (head.isSymbolic())
View Full Code Here

      monitor.beginTask(MessageFormat.format(
          JGitText.get().abortingRebase, commitId),
          ProgressMonitor.UNKNOWN);

      DirCacheCheckout dco;
      RevCommit commit = walk.parseCommit(repo.resolve(commitId));
      if (result.getStatus().equals(Status.FAILED)) {
        RevCommit head = walk.parseCommit(repo.resolve(Constants.HEAD));
        dco = new DirCacheCheckout(repo, head.getTree(),
            repo.lockDirCache(), commit.getTree());
      } else {
        dco = new DirCacheCheckout(repo, repo.lockDirCache(),
            commit.getTree());
      }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.revwalk.RevCommit

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.