Java Code Examples for org.eclipse.jgit.treewalk.TreeWalk#enterSubtree()

The following examples show how to use org.eclipse.jgit.treewalk.TreeWalk#enterSubtree() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResolveMerger.java    From onedev with MIT License 6 votes vote down vote up
/**
 * Process the given TreeWalk's entries.
 *
 * @param treeWalk
 *            The walk to iterate over.
 * @param ignoreConflicts
 *            see
 *            {@link org.eclipse.jgit.merge.ResolveMerger#mergeTrees(AbstractTreeIterator, RevTree, RevTree, boolean)}
 * @return Whether the trees merged cleanly.
 * @throws java.io.IOException
 * @since 3.5
 */
protected boolean mergeTreeWalk(TreeWalk treeWalk, boolean ignoreConflicts)
		throws IOException {
	boolean hasWorkingTreeIterator = tw.getTreeCount() > T_FILE;
	boolean hasAttributeNodeProvider = treeWalk
			.getAttributesNodeProvider() != null;
	while (treeWalk.next()) {
		if (!processEntry(
				treeWalk.getTree(T_BASE, CanonicalTreeParser.class),
				treeWalk.getTree(T_OURS, CanonicalTreeParser.class),
				treeWalk.getTree(T_THEIRS, CanonicalTreeParser.class),
				treeWalk.getTree(T_INDEX, DirCacheBuildIterator.class),
				hasWorkingTreeIterator ? treeWalk.getTree(T_FILE,
						WorkingTreeIterator.class) : null,
				ignoreConflicts, hasAttributeNodeProvider
						? treeWalk.getAttributes()
						: NO_ATTRIBUTES)) {
			cleanUp();
			return false;
		}
		if (treeWalk.isSubtree() && enterSubtree)
			treeWalk.enterSubtree();
	}
	return true;
}
 
Example 2
Source File: CherryPickCommand.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public ThreeWayMerger newMerger (Repository db, boolean inCore) {
    return new RecursiveMerger(db, inCore) {
        protected boolean mergeTreeWalk (TreeWalk treeWalk, boolean ignoreConflicts)
                throws IOException {
            boolean ok = true;
            boolean hasWorkingTreeIterator = tw.getTreeCount() > T_FILE;
            boolean hasAttributeNodeProvider = treeWalk.getAttributesNodeProvider() != null;
            while (treeWalk.next()) {
                if (!processEntry(
                        treeWalk.getTree(T_BASE, CanonicalTreeParser.class),
                        treeWalk.getTree(T_OURS, CanonicalTreeParser.class),
                        treeWalk.getTree(T_THEIRS, CanonicalTreeParser.class),
                        treeWalk.getTree(T_INDEX, DirCacheBuildIterator.class),
                        hasWorkingTreeIterator ? treeWalk.getTree(T_FILE, WorkingTreeIterator.class) : null,
                        ignoreConflicts,
                        hasAttributeNodeProvider ? treeWalk.getAttributes() : NO_ATTRIBUTES
                )) {
                    ok = false;
                }
                if (treeWalk.isSubtree() && enterSubtree) {
                    treeWalk.enterSubtree();
                }
            }
            if (!ok) {
                cleanUp();
            }
            return ok;
        }
    };
}
 
Example 3
Source File: GfsTreeWalkTest.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@Nonnull
private TreeWalk forPath(String path) throws IOException {
  TreeWalk tw = prepareTreeWalk(false);
  PathFilter filter = PathFilter.create(path.charAt(0) == '/' ? path.substring(1) : path);
  tw.setFilter(filter);
  tw.setRecursive(false);
  while(tw.next()) {
    if(filter.isDone(tw))
      return tw;
    if(tw.isSubtree())
      tw.enterSubtree();
  }
  throw new IllegalStateException();
}
 
Example 4
Source File: GfsTreeWalkTest.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@Nonnull
private TreeWalk forPath(String path) throws IOException {
  TreeWalk tw = prepareTreeWalk(false);
  PathFilter filter = PathFilter.create(path.charAt(0) == '/' ? path.substring(1) : path);
  tw.setFilter(filter);
  tw.setRecursive(false);
  while(tw.next()) {
    if(filter.isDone(tw))
      return tw;
    if(tw.isSubtree())
      tw.enterSubtree();
  }
  throw new IllegalStateException();
}
 
Example 5
Source File: SMAGit.java    From salesforce-migration-assistant with MIT License 5 votes vote down vote up
/**
 * Replicates ls-tree for the current commit.
 *
 * @return Map containing the full path and the data for all items in the repository.
 * @throws IOException
 */
public Map<String, byte[]> getAllMetadata() throws Exception
{
    Map<String, byte[]> contents = new HashMap<String, byte[]>();
    ObjectReader reader = repository.newObjectReader();
    ObjectId commitId = repository.resolve(curCommit);
    RevWalk revWalk = new RevWalk(reader);
    RevCommit commit = revWalk.parseCommit(commitId);
    RevTree tree = commit.getTree();
    TreeWalk treeWalk = new TreeWalk(reader);
    treeWalk.addTree(tree);
    treeWalk.setRecursive(false);

    while (treeWalk.next())
    {
        if (treeWalk.isSubtree())
        {
            treeWalk.enterSubtree();
        }
        else
        {
            String member = treeWalk.getPathString();
            if (member.contains(SOURCEDIR))
            {
                byte[] data = getBlob(member, curCommit);
                contents.put(member, data);
            }
        }
    }

    reader.release();

    return contents;
}