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

The following examples show how to use org.eclipse.jgit.treewalk.TreeWalk#getTreeCount() . 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: CommitGit.java    From coming with MIT License 6 votes vote down vote up
@Override
public boolean include(TreeWalk walker) throws MissingObjectException, IncorrectObjectTypeException, IOException {
	int n = walker.getTreeCount();
	if (n == 1) {
		return true;
	}

	int m = walker.getRawMode(0);
	int i = 1;

	while (i < n) {
		if (walker.getRawMode(i) == m && walker.idEqual(i, 0)) {
			return false;
		}
		i++;
	}
	return true;
}
 
Example 2
Source File: SubtreeMerger.java    From git-merge-repos with Apache License 2.0 6 votes vote down vote up
private AbstractTreeIterator getSingleTreeIterator(TreeWalk treeWalk, String commitMessage) {
	AbstractTreeIterator result = null;
	int treeCount = treeWalk.getTreeCount();
	for (int i = 0; i < treeCount; i++) {
		AbstractTreeIterator it = treeWalk.getTree(i, AbstractTreeIterator.class);
		if (it != null) {
			if (result != null) {
				String msg = "Trees of repositories overlap in path '"
						+ it.getEntryPathString()
						+ "'. "
						+ "We can only merge non-overlapping trees, "
						+ "so make sure the repositories have been prepared for that. "
						+ "One possible way is to process each repository to move the root to a subdirectory first.\n"
						+ "Current commit:\n" + commitMessage;
				throw new IllegalStateException(msg);
			} else {
				result = it;
			}
		}
	}
	return result;
}