Package org.eclipse.jgit.revwalk

Examples of org.eclipse.jgit.revwalk.RevCommit


        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


      } catch (IncorrectObjectTypeException notCommit) {
        continue;
      }
    }

    RevCommit bad = walk.next();
    if (bad != null) {
      throw new PackProtocolException(MessageFormat.format(
          JGitText.get().wantNotValid,
          bad.name()));
    }
    walk.reset();
  }
View Full Code Here

    walk.resetRetain(SAVE);
    walk.markStart((RevCommit) want);
    if (oldestTime != 0)
      walk.setRevFilter(CommitTimeRevFilter.after(oldestTime * 1000L));
    for (;;) {
      final RevCommit c = walk.next();
      if (c == null)
        break;
      if (c.has(PEER_HAS)) {
        addCommonBase(c);
        want.add(SATISFIED);
        return true;
      }
    }
View Full Code Here

      // determine the current HEAD and the commit it is referring to
      ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}");
      if (headId != null)
        if (amend) {
          RevCommit previousCommit = new RevWalk(repo)
              .parseCommit(headId);
          RevCommit[] p = previousCommit.getParents();
          for (int i = 0; i < p.length; i++)
            parents.add(0, p[i].getId());
        } else {
          parents.add(0, headId);
        }

      // lock the index
      DirCache index = repo.lockDirCache();
      try {
        if (!only.isEmpty())
          index = createTemporaryIndex(headId, index);

        ObjectInserter odi = repo.newObjectInserter();
        try {
          // Write the index as tree to the object database. This may
          // fail for example when the index contains unmerged paths
          // (unresolved conflicts)
          ObjectId indexTreeId = index.writeTree(odi);

          if (insertChangeId)
            insertChangeId(indexTreeId);

          // Create a Commit object, populate it and write it
          CommitBuilder commit = new CommitBuilder();
          commit.setCommitter(committer);
          commit.setAuthor(author);
          commit.setMessage(message);

          commit.setParentIds(parents);
          commit.setTreeId(indexTreeId);
          ObjectId commitId = odi.insert(commit);
          odi.flush();

          RevWalk revWalk = new RevWalk(repo);
          try {
            RevCommit revCommit = revWalk.parseCommit(commitId);
            RefUpdate ru = repo.updateRef(Constants.HEAD);
            ru.setNewObjectId(commitId);
            if (reflogComment != null) {
              ru.setRefLogMessage(reflogComment, false);
            } else {
              String prefix = amend ? "commit (amend): "
                  : "commit: ";
              ru.setRefLogMessage(
                  prefix + revCommit.getShortMessage(), false);
            }
            if (headId != null)
              ru.setExpectedOldObjectId(headId);
            else
              ru.setExpectedOldObjectId(ObjectId.zeroId());
View Full Code Here

    return currentSource.getAuthor();
  }

  /** @return current committer being blamed. */
  public PersonIdent getSourceCommitter() {
    RevCommit c = getSourceCommit();
    return c != null ? c.getCommitterIdent() : null;
  }
View Full Code Here

        throw new RefNotFoundException(MessageFormat.format(JGitText
            .get().refNotResolved, name));

      RevWalk revWalk = new RevWalk(repo);
      AnyObjectId headId = headRef.getObjectId();
      RevCommit headCommit = headId == null ? null : revWalk
          .parseCommit(headId);
      RevCommit newCommit = revWalk.parseCommit(branch);
      RevTree headTree = headCommit == null ? null : headCommit.getTree();
      DirCacheCheckout dco = new DirCacheCheckout(repo, headTree,
          repo.lockDirCache(), newCommit.getTree());
      dco.setFailOnConflict(true);
      try {
        dco.checkout();
      } catch (CheckoutConflictException e) {
        status = new CheckoutResult(Status.CONFLICTS, dco
View Full Code Here

            clone.setProgressMonitor(monitor);
          submoduleRepo = clone.call().getRepository();
        }

        RevWalk walk = new RevWalk(submoduleRepo);
        RevCommit commit = walk.parseCommit(generator.getObjectId());

        String update = generator.getConfigUpdate();
        if (ConfigConstants.CONFIG_KEY_MERGE.equals(update)) {
          MergeCommand merge = new MergeCommand(submoduleRepo);
          merge.include(commit);
          merge.call();
        } else if (ConfigConstants.CONFIG_KEY_REBASE.equals(update)) {
          RebaseCommand rebase = new RebaseCommand(submoduleRepo);
          rebase.setUpstream(commit);
          rebase.call();
        } else {
          // Checkout commit referenced in parent repository's index
          // as a detached HEAD
          DirCacheCheckout co = new DirCacheCheckout(submoduleRepo,
              submoduleRepo.lockDirCache(), commit.getTree());
          co.setFailOnConflict(true);
          co.checkout();
          RefUpdate refUpdate = submoduleRepo.updateRef(
              Constants.HEAD, true);
          refUpdate.setNewObjectId(commit);
View Full Code Here

   * @throws IOException
   *             objects are missing or multiple merge bases were found.
   */
  protected AbstractTreeIterator mergeBase(final int aIdx, final int bIdx)
      throws IOException {
    RevCommit base = getBaseCommit(aIdx, bIdx);
    return (base == null) ? new EmptyTreeIterator() : openTree(base.getTree());
  }
View Full Code Here

          Constants.TYPE_COMMIT);
    walk.reset();
    walk.setRevFilter(RevFilter.MERGE_BASE);
    walk.markStart(sourceCommits[aIdx]);
    walk.markStart(sourceCommits[bIdx]);
    final RevCommit base = walk.next();
    if (base == null)
      return null;
    final RevCommit base2 = walk.next();
    if (base2 != null) {
      throw new IOException(MessageFormat.format(JGitText.get().multipleMergeBasesFor
          , sourceCommits[aIdx].name(), sourceCommits[bIdx].name()
          , base.name(), base2.name()));
    }
    return base;
  }
View Full Code Here

              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;
        }
        int dist;
        if (l - i > 1) {
          String distnum = new String(rev, i + 1, l - i - 1);
          try {
            dist = Integer.parseInt(distnum);
          } catch (NumberFormatException e) {
            throw new RevisionSyntaxException(
                JGitText.get().invalidAncestryLength, revstr);
          }
        } else
          dist = 1;
        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

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.