Package org.eclipse.jgit.revwalk

Examples of org.eclipse.jgit.revwalk.RevWalk


    TreeWalk treeWalk = new TreeWalk(repo);
    int dcIdx = treeWalk.addTree(new DirCacheIterator(index));
    int fIdx = treeWalk.addTree(new FileTreeIterator(repo));
    int hIdx = -1;
    if (headId != null)
      hIdx = treeWalk.addTree(new RevWalk(repo).parseTree(headId));
    treeWalk.setRecursive(true);

    while (treeWalk.next()) {
      String path = treeWalk.getPathString();
      // check if current entry's path matches a specified path
View Full Code Here


      revPool.release();

    if (reverse)
      revPool = new ReverseWalk(getRepository());
    else
      revPool = new RevWalk(getRepository());

    revPool.setRetainBody(true);
    SEEN = revPool.newFlag("SEEN");
    reader = revPool.getObjectReader();
    treeWalk = new TreeWalk(reader);
View Full Code Here

      ObjectId branch = repo.resolve(name);
      if (branch == null)
        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 {
View Full Code Here

   * @throws IOException
   * @throws RefNotFoundException
   */
  protected CheckoutCommand checkoutPaths() throws IOException,
      RefNotFoundException {
    RevWalk revWalk = new RevWalk(repo);
    DirCache dc = repo.lockDirCache();
    try {
      DirCacheEditor editor = dc.editor();
      TreeWalk startWalk = new TreeWalk(revWalk.getObjectReader());
      startWalk.setRecursive(true);
      startWalk.setFilter(PathFilterGroup.createFromStrings(paths));
      boolean checkoutIndex = startCommit == null && startPoint == null;
      if (!checkoutIndex)
        startWalk.addTree(revWalk.parseCommit(getStartPoint())
            .getTree());
      else
        startWalk.addTree(new DirCacheIterator(dc));

      final File workTree = repo.getWorkTree();
      final ObjectReader r = repo.getObjectDatabase().newReader();
      try {
        while (startWalk.next()) {
          final ObjectId blobId = startWalk.getObjectId(0);
          final FileMode mode = startWalk.getFileMode(0);
          editor.add(new PathEdit(startWalk.getPathString()) {
            public void apply(DirCacheEntry ent) {
              ent.setObjectId(blobId);
              ent.setFileMode(mode);
              try {
                DirCacheCheckout.checkoutEntry(repo, new File(
                    workTree, ent.getPathString()), ent, r);
              } catch (IOException e) {
                throw new JGitInternalException(
                    MessageFormat.format(
                        JGitText.get().checkoutConflictWithFile,
                        ent.getPathString()), e);
              }
            }
          });
        }
        editor.commit();
      } finally {
        startWalk.release();
        r.release();
      }
    } finally {
      dc.unlock();
      revWalk.release();
    }
    return this;
  }
View Full Code Here

          if (monitor != null)
            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);
View Full Code Here

      }
    } finally {
      closeConnection(result);
    }

    final RevWalk walk = new RevWalk(transport.local);
    try {
      if (monitor instanceof BatchingProgressMonitor) {
        ((BatchingProgressMonitor) monitor).setDelayStart(
            250, TimeUnit.MILLISECONDS);
      }
      monitor.beginTask(JGitText.get().updatingReferences, localUpdates.size());
      if (transport.isRemoveDeletedRefs())
        deleteStaleTrackingRefs(result, walk);
      for (TrackingRefUpdate u : localUpdates) {
        try {
          monitor.update(1);
          u.update(walk);
          result.add(u);
        } catch (IOException err) {
          throw new TransportException(MessageFormat.format(JGitText
              .get().failureUpdatingTrackingRef,
              u.getLocalName(), err.getMessage()), err);
        }
      }
      monitor.endTask();
    } finally {
      walk.release();
    }

    if (!fetchHeadUpdates.isEmpty()) {
      try {
        updateFETCH_HEAD(result);
View Full Code Here

   *            the repository this merger will read and write data on.
   */
  protected Merger(final Repository local) {
    db = local;
    reader = db.newObjectReader();
    walk = new RevWalk(reader);
  }
View Full Code Here

   * @throws IOException
   *             on serious errors
   */
  public ObjectId resolve(final String revstr)
      throws AmbiguousObjectException, IOException {
    RevWalk rw = new RevWalk(this);
    try {
      return resolve(rw, revstr);
    } finally {
      rw.release();
    }
  }
View Full Code Here

    if (stashEntries.isEmpty())
      return Collections.emptyList();

    final List<RevCommit> stashCommits = new ArrayList<RevCommit>(
        stashEntries.size());
    final RevWalk walk = new RevWalk(repo);
    walk.setRetainBody(true);
    try {
      for (ReflogEntry entry : stashEntries)
        try {
          stashCommits.add(walk.parseCommit(entry.getNewId()));
        } catch (IOException e) {
          throw new JGitInternalException(MessageFormat.format(
              JGitText.get().cannotReadCommit, entry.getNewId()),
              e);
        }
    } finally {
      walk.dispose();
    }
    return stashCommits;
  }
View Full Code Here

  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,
              headCommit.getTree(), repo.lockDirCache(),
              merger.getResultTreeId());
          dco.setFailOnConflict(true);
          dco.checkout();
          newHead = new Git(getRepository()).commit()
              .setMessage(srcCommit.getFullMessage())
              .setReflogComment(
                  "cherry-pick: "
                      + srcCommit.getShortMessage())
              .setAuthor(srcCommit.getAuthorIdent()).call();
          cherryPickedRefs.add(src);
        } else {
          if (merger.failed())
            return new CherryPickResult(merger.getFailingPaths());

          // there are merge conflicts

          String message = new MergeMessageFormatter()
              .formatWithConflicts(srcCommit.getFullMessage(),
                  merger.getUnmergedPaths());

          repo.writeCherryPickHead(srcCommit.getId());
          repo.writeMergeCommitMsg(message);

          return CherryPickResult.CONFLICT;
        }
      }
    } catch (IOException e) {
      throw new JGitInternalException(
          MessageFormat.format(
              JGitText.get().exceptionCaughtDuringExecutionOfCherryPickCommand,
              e), e);
    } finally {
      revWalk.release();
    }
    return new CherryPickResult(newHead, cherryPickedRefs);
  }
View Full Code Here

TOP

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

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.