Java Code Examples for org.eclipse.jgit.treewalk.filter.PathFilter#create()

The following examples show how to use org.eclipse.jgit.treewalk.filter.PathFilter#create() . 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: DiffCalculator.java    From diff-check with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Map<String, BlobWrapper> getRevFileContentMap(
        Git git, RevCommit commit, Set<String> filePathSet, ObjectReader reader) throws Exception {
    if (filePathSet == null || filePathSet.isEmpty()) {
        return Collections.emptyMap();
    }
    TreeFilter filter = filePathSet.size() > 1
            ? OrTreeFilter.create(filePathSet.stream()
                    .map(PathFilter::create)
                    .collect(Collectors.toList()))
            : PathFilter.create(filePathSet.iterator().next());
     return getContentMapByTreeAndFilter(git, new CanonicalTreeParser(null, reader, commit.getTree()), filter);
}
 
Example 2
Source File: DiffCalculator.java    From diff-check with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Map<String, BlobWrapper> getIndexedFileContentMap(Git git, Set<String> filePathSet) throws Exception {
    if (filePathSet == null || filePathSet.isEmpty()) {
        return Collections.emptyMap();
    }
    DirCache index = git.getRepository().readDirCache();
    TreeFilter filter = filePathSet.size() > 1
            ? OrTreeFilter.create(filePathSet.stream()
                    .map(PathFilter::create)
                    .collect(Collectors.toList()))
            : PathFilter.create(filePathSet.iterator().next());
    return getContentMapByTreeAndFilter(git, new DirCacheIterator(index), filter);
}
 
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: FollowFilter.java    From onedev with MIT License 2 votes vote down vote up
/**
 * Create a new tree filter for a user supplied path.
 * <p>
 * Path strings are relative to the root of the repository. If the user's
 * input should be assumed relative to a subdirectory of the repository the
 * caller must prepend the subdirectory's path prior to creating the filter.
 * <p>
 * Path strings use '/' to delimit directories on all platforms.
 *
 * @param path
 *            the path to filter on. Must not be the empty string. All
 *            trailing '/' characters will be trimmed before string's length
 *            is checked or is used as part of the constructed filter.
 * @param cfg
 *            diff config specifying rename detection options.
 * @return a new filter for the requested path.
 * @throws java.lang.IllegalArgumentException
 *             the path supplied was the empty string.
 * @since 3.0
 */
public static FollowFilter create(String path, DiffConfig cfg) {
	return new FollowFilter(PathFilter.create(path), cfg);
}