Package org.eclipse.jgit.revwalk

Examples of org.eclipse.jgit.revwalk.RevCommit


              throw new RevisionSyntaxException(
                  JGitText.get().invalidCommitParentNumber,
                  revstr);
            }
            if (pnum != 0) {
              RevCommit commit = (RevCommit) ref;
              if (pnum > commit.getParentCount())
                ref = null;
              else
                ref = commit.getParent(pnum - 1);
            }
            i = j - 1;
            break;
          case '{':
            int k;
            String item = null;
            for (k = i + 2; k < rev.length; ++k) {
              if (rev[k] == '}') {
                item = new String(rev, i + 2, k - i - 2);
                break;
              }
            }
            i = k;
            if (item != null)
              if (item.equals("tree")) {
                ref = rw.parseTree(ref);
              } else if (item.equals("commit")) {
                ref = rw.parseCommit(ref);
              } else if (item.equals("blob")) {
                ref = rw.peel(ref);
                if (!(ref instanceof RevBlob))
                  throw new IncorrectObjectTypeException(ref,
                      Constants.TYPE_BLOB);
              } else if (item.equals("")) {
                ref = rw.peel(ref);
              } else
                throw new RevisionSyntaxException(revstr);
            else
              throw new RevisionSyntaxException(revstr);
            break;
          default:
            ref = rw.parseAny(ref);
            if (ref instanceof RevCommit) {
              RevCommit commit = ((RevCommit) ref);
              if (commit.getParentCount() == 0)
                ref = null;
              else
                ref = commit.getParent(0);
            } else
              throw new IncorrectObjectTypeException(ref,
                  Constants.TYPE_COMMIT);

          }
        } else {
          ref = rw.peel(ref);
          if (ref instanceof RevCommit) {
            RevCommit commit = ((RevCommit) ref);
            if (commit.getParentCount() == 0)
              ref = null;
            else
              ref = commit.getParent(0);
          } else
            throw new IncorrectObjectTypeException(ref,
                Constants.TYPE_COMMIT);
        }
        break;
      case '~':
        if (ref == null) {
          ref = parseSimple(rw, new String(rev, 0, i));
          if (ref == null)
            return null;
        }
        ref = rw.peel(ref);
        if (!(ref instanceof RevCommit))
          throw new IncorrectObjectTypeException(ref,
              Constants.TYPE_COMMIT);
        int l;
        for (l = i + 1; l < rev.length; ++l) {
          if (!Character.isDigit(rev[l]))
            break;
        }
        String distnum = new String(rev, i + 1, l - i - 1);
        int dist;
        try {
          dist = Integer.parseInt(distnum);
        } catch (NumberFormatException e) {
          throw new RevisionSyntaxException(
              JGitText.get().invalidAncestryLength, revstr);
        }
        while (dist > 0) {
          RevCommit commit = (RevCommit) ref;
          if (commit.getParentCount() == 0) {
            ref = null;
            break;
          }
          commit = commit.getParent(0);
          rw.parseHeaders(commit);
          ref = commit;
          --dist;
        }
        i = l - 1;
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

    return RawParseUtils.decode(content, 0, end);
  }

  private boolean checkoutCommit(RevCommit commit) throws IOException {
    try {
      RevCommit head = walk.parseCommit(repo.resolve(Constants.HEAD));
      DirCacheCheckout dco = new DirCacheCheckout(repo, head.getTree(),
          repo.lockDirCache(), commit.getTree());
      dco.setFailOnConflict(true);
      dco.checkout();
      // update the HEAD
      RefUpdate refUpdate = repo.updateRef(Constants.HEAD, true);
View Full Code Here

    NoteMap map = NoteMap.newEmptyMap();
    try {
      Ref ref = repo.getRef(notesRef);
      // if we have a notes ref, use it
      if (ref != null) {
        RevCommit notesCommit = walk.parseCommit(ref.getObjectId());
        map = NoteMap.read(walk.getObjectReader(), notesCommit);
      }

      Iterator<Note> i = map.iterator();
      while (i.hasNext())
View Full Code Here

        last = obj;
        haveCnt++;

        if (obj instanceof RevCommit) {
          RevCommit c = (RevCommit) obj;
          if (oldestTime == 0 || c.getCommitTime() < oldestTime)
            oldestTime = c.getCommitTime();
        }

        if (obj.has(PEER_HAS))
          continue;
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));
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.