Package org.eclipse.jgit.revwalk

Examples of org.eclipse.jgit.revwalk.RevCommit


    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


   {
      // Does the same as the original git-cherryPick
      // except commiting after running merger
      Repository repo = git.getRepository();

      RevCommit newHead = null;
      List<Ref> cherryPickedRefs = new LinkedList<Ref>();

      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;

         // 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() == 0)
            throw new CantMergeCommitWithZeroParentsException("Commit with zero parents cannot be merged");

         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))
         {
            DirCacheCheckout dco = new DirCacheCheckout(repo,
                     headCommit.getTree(), repo.lockDirCache(),
                     merger.getResultTreeId());
View Full Code Here

         RefUpdate u = db.updateRef(Constants.HEAD);
         u.disableRefLog();
         u.link(branch.getName());
      }

      final RevCommit commit = parseCommit(branch);
      final RefUpdate u = db.updateRef(Constants.HEAD);
      u.setNewObjectId(commit);
      u.forceUpdate();

      DirCache dc = db.lockDirCache();
      DirCacheCheckout co = new DirCacheCheckout(db, dc, commit.getTree());
      co.checkout();
   }
View Full Code Here

   private RevCommit parseCommit(final Ref branch)
            throws MissingObjectException, IncorrectObjectTypeException,
            IOException
   {
      final RevWalk rw = new RevWalk(db);
      final RevCommit commit;
      try
      {
         commit = rw.parseCommit(branch.getObjectId());
      }
      finally
View Full Code Here

      walker.markUninteresting(obj);

    final int maxBases = config.getDeltaSearchWindowSize();
    Set<RevTree> baseTrees = new HashSet<RevTree>();
    BlockList<RevCommit> commits = new BlockList<RevCommit>();
    RevCommit c;
    while ((c = walker.next()) != null) {
      if (exclude(c))
        continue;
      if (c.has(inCachedPack)) {
        CachedPack pack = tipToPack.get(c);
        if (includesAllTips(pack, include, walker)) {
          useCachedPack(walker, keepOnRestart, //
              wantObjs, haveObjs, pack);
          commits = new BlockList<RevCommit>();

          endPhase(countingMonitor);
          beginPhase(PackingPhase.COUNTING, countingMonitor,
              ProgressMonitor.UNKNOWN);
          continue;
        }
      }

      if (c.has(RevFlag.UNINTERESTING)) {
        if (baseTrees.size() <= maxBases)
          baseTrees.add(c.getTree());
        continue;
      }

      commits.add(c);
      countingMonitor.update(1);
    }

    if (shallowPack) {
      for (RevCommit cmit : commits) {
        addObject(cmit, 0);
      }
    } else {
      int commitCnt = 0;
      boolean putTagTargets = false;
      for (RevCommit cmit : commits) {
        if (!cmit.has(added)) {
          cmit.add(added);
          addObject(cmit, 0);
          commitCnt++;
        }

        for (int i = 0; i < cmit.getParentCount(); i++) {
          RevCommit p = cmit.getParent(i);
          if (!p.has(added) && !p.has(RevFlag.UNINTERESTING)) {
            p.add(added);
            addObject(p, 0);
            commitCnt++;
          }
        }
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);
            String prefix = amend ? "commit (amend): " : "commit: ";
            ru.setRefLogMessage(
                prefix + revCommit.getShortMessage(), false);

            ru.setExpectedOldObjectId(headId);
            Result rc = ru.forceUpdate();
            switch (rc) {
            case NEW:
View Full Code Here

  public Note call() throws JGitInternalException {
    checkCallable();
    RevWalk walk = new RevWalk(repo);
    ObjectInserter inserter = repo.newObjectInserter();
    NoteMap map = NoteMap.newEmptyMap();
    RevCommit notesCommit = null;
    try {
      Ref ref = repo.getRef(notesRef);
      // if we have a notes ref, use it
      if (ref != null) {
        notesCommit = walk.parseCommit(ref.getObjectId());
View Full Code Here

      final Date maxWhen = new Date(maxTime * 1000L);
      walk.sort(RevSort.COMMIT_TIME_DESC);
      walk.markStart(reachableCommits);
      walk.setRevFilter(CommitTimeRevFilter.after(maxWhen));
      for (;;) {
        final RevCommit c = walk.next();
        if (c == null)
          break;
        if (c.has(ADVERTISED) && !c.has(COMMON)) {
          // This is actually going to be a common commit, but
          // our peer doesn't know that fact yet.
          //
          c.add(COMMON);
          c.carry(COMMON);
          reachableCommits.add(c);
        }
      }
    }
  }
View Full Code Here

      newHead.disableRefLog();
      newHead.link(head.getName());
      addMergeConfig(repo, head);
    }

    final RevCommit commit = parseCommit(repo, head);

    boolean detached = !head.getName().startsWith(Constants.R_HEADS);
    RefUpdate u = repo.updateRef(Constants.HEAD, detached);
    u.setNewObjectId(commit.getId());
    u.forceUpdate();

    if (!bare) {
      DirCache dc = repo.lockDirCache();
      DirCacheCheckout co = new DirCacheCheckout(repo, dc,
          commit.getTree());
      co.checkout();
    }
  }
View Full Code Here

    }
  }

  private void parseReachable(ObjectId id) {
    try {
      RevCommit o = walk.parseCommit(id);
      if (!o.has(REACHABLE)) {
        o.add(REACHABLE);
        reachableCommits.add(o);
      }
    } catch (IOException readError) {
      // If we cannot read the value of the ref skip it.
    }
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.