• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java PathFilterGroup类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.jgit.treewalk.filter.PathFilterGroup的典型用法代码示例。如果您正苦于以下问题:Java PathFilterGroup类的具体用法?Java PathFilterGroup怎么用?Java PathFilterGroup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PathFilterGroup类属于org.eclipse.jgit.treewalk.filter包,在下文中一共展示了PathFilterGroup类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getSubmoduleCommitId

import org.eclipse.jgit.treewalk.filter.PathFilterGroup; //导入依赖的package包/类
public static String getSubmoduleCommitId(Repository repository, String path, RevCommit commit) {
	String commitId = null;
	try (TreeWalk tw = new TreeWalk(repository)) {
		tw.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path)));
		tw.reset(commit.getTree());
		while (tw.next()) {
			if (tw.isSubtree() && !path.equals(tw.getPathString())) {
				tw.enterSubtree();
				continue;
			}
			if (FileMode.GITLINK == tw.getFileMode(0)) {
				commitId = tw.getObjectId(0).getName();
				break;
			}
		}
	} catch (Throwable t) {
		error(t, repository, "{0} can't find {1} in commit {2}", path, commit.name());
	}
	return commitId;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:21,代码来源:JGitUtils.java


示例2: getSubmoduleCommitId

import org.eclipse.jgit.treewalk.filter.PathFilterGroup; //导入依赖的package包/类
public static String getSubmoduleCommitId(Repository repository, String path, RevCommit commit) {
	String commitId = null;
	RevWalk rw = new RevWalk(repository);
	TreeWalk tw = new TreeWalk(repository);
	tw.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path)));
	try {
		tw.reset(commit.getTree());
		while (tw.next()) {
			if (tw.isSubtree() && !path.equals(tw.getPathString())) {
				tw.enterSubtree();
				continue;
			}
			if (FileMode.GITLINK == tw.getFileMode(0)) {
				commitId = tw.getObjectId(0).getName();
				break;
			}
		}
	} catch (Throwable t) {
		error(t, repository, "{0} can't find {1} in commit {2}", path, commit.name());
	} finally {
		rw.dispose();
		tw.release();
	}
	return commitId;
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:26,代码来源:JGitUtils.java


示例3: getByteContent

import org.eclipse.jgit.treewalk.filter.PathFilterGroup; //导入依赖的package包/类
/**
 * Retrieves the raw byte content of a file in the specified tree.
 * 
 * @param repository
 * @param tree
 *            if null, the RevTree from HEAD is assumed.
 * @param path
 * @return content as a byte []
 */
public static byte[] getByteContent(Repository repository, RevTree tree, final String path, boolean throwError) {
	RevWalk rw = new RevWalk(repository);
	byte[] content = null;
	try (TreeWalk tw = new TreeWalk(repository)) {
		tw.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path)));
		if (tree == null) {
			ObjectId object = getDefaultBranch(repository);
			if (object == null) {
				return null;
			}
			RevCommit commit = rw.parseCommit(object);
			tree = commit.getTree();
		}
		tw.reset(tree);
		while (tw.next()) {
			if (tw.isSubtree() && !path.equals(tw.getPathString())) {
				tw.enterSubtree();
				continue;
			}
			ObjectId entid = tw.getObjectId(0);
			FileMode entmode = tw.getFileMode(0);
			if (entmode != FileMode.GITLINK) {
				ObjectLoader ldr = repository.open(entid, Constants.OBJ_BLOB);
				content = ldr.getCachedBytes();
			}
		}
	} catch (Throwable t) {
		if (throwError) {
			error(t, repository, "{0} can't find {1} in tree {2}", path, tree.name());
		}
	} finally {
		rw.close();
		rw.dispose();
	}
	return content;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:46,代码来源:JGitUtils.java


示例4: run

import org.eclipse.jgit.treewalk.filter.PathFilterGroup; //导入依赖的package包/类
@Override
protected void run () throws GitException {
    Repository repository = getRepository();
    TreeWalk walk = new TreeWalk(repository);
    try {
        walk.reset();
        walk.setRecursive(true);
        walk.addTree(Utils.findCommit(repository, revisionFirst).getTree());
        walk.addTree(Utils.findCommit(repository, revisionSecond).getTree());
        Collection<PathFilter> pathFilters = Utils.getPathFilters(repository.getWorkTree(), roots);
        if (pathFilters.isEmpty()) {
            walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, PathFilter.ANY_DIFF));
        } else {
            walk.setFilter(AndTreeFilter.create(new TreeFilter[] { 
                TreeFilter.ANY_DIFF,
                PathFilter.ANY_DIFF,
                PathFilterGroup.create(pathFilters)
            }));
        }
        List<GitRevisionInfo.GitFileInfo> infos = Utils.getDiffEntries(repository, walk, getClassFactory());
        for (GitRevisionInfo.GitFileInfo info : infos) {
            statuses.put(info.getFile(), info);
        }
    } catch (IOException ex) {
        throw new GitException(ex);
    } finally {
        walk.release();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:CompareCommand.java


示例5: applyCriteria

import org.eclipse.jgit.treewalk.filter.PathFilterGroup; //导入依赖的package包/类
private void applyCriteria (RevWalk walk, SearchCriteria criteria,
        final RevFlag partOfResultFlag, DiffConfig diffConfig) {
    File[] files = criteria.getFiles();
    if (files.length > 0) {
        Collection<PathFilter> pathFilters = Utils.getPathFilters(getRepository().getWorkTree(), files);
        if (!pathFilters.isEmpty()) {
            if (criteria.isFollow() && pathFilters.size() == 1) {
                walk.setTreeFilter(FollowFilter.create(pathFilters.iterator().next().getPath(), diffConfig));
            } else {
                walk.setTreeFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, PathFilterGroup.create(pathFilters)));
            }
        }
    }
    RevFilter filter;
    if (criteria.isIncludeMerges()) {
        filter = RevFilter.ALL;
    } else {
        filter = RevFilter.NO_MERGES;
    }
    filter = AndRevFilter.create(filter, new CancelRevFilter(monitor));
    filter = AndRevFilter.create(filter, new RevFilter() {

        @Override
        public boolean include (RevWalk walker, RevCommit cmit) {
            return cmit.has(partOfResultFlag);
        }

        @Override
        public RevFilter clone () {
            return this;
        }

        @Override
        public boolean requiresCommitBody () {
            return false;
        }            
        
    });
    
    String username = criteria.getUsername();
    if (username != null && !(username = username.trim()).isEmpty()) {
        filter = AndRevFilter.create(filter, OrRevFilter.create(CommitterRevFilter.create(username), AuthorRevFilter.create(username)));
    }
    String message = criteria.getMessage();
    if (message != null && !(message = message.trim()).isEmpty()) {
        filter = AndRevFilter.create(filter, MessageRevFilter.create(message));
    }
    Date from  = criteria.getFrom();
    Date to  = criteria.getTo();
    if (from != null && to != null) {
        filter = AndRevFilter.create(filter, CommitTimeRevFilter.between(from, to));
    } else if (from != null) {
        filter = AndRevFilter.create(filter, CommitTimeRevFilter.after(from));
    } else if (to != null) {
        filter = AndRevFilter.create(filter, CommitTimeRevFilter.before(to));
    }
    // this must be at the end, limit filter must apply as the last
    if (criteria.getLimit() != -1) {
        filter = AndRevFilter.create(filter, MaxCountRevFilter.create(criteria.getLimit()));
    }
    walk.setRevFilter(filter);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:63,代码来源:LogCommand.java


示例6: checkout

import org.eclipse.jgit.treewalk.filter.PathFilterGroup; //导入依赖的package包/类
public void checkout () throws IOException, GitException {
    TreeWalk treeWalk = new TreeWalk(repository);
    Collection<String> relativePaths = Utils.getRelativePaths(repository.getWorkTree(), roots);
    if (!relativePaths.isEmpty()) {
        treeWalk.setFilter(PathFilterGroup.createFromStrings(relativePaths));
    }
    treeWalk.setRecursive(true);
    treeWalk.reset();
    treeWalk.addTree(new DirCacheIterator(cache));
    treeWalk.addTree(new FileTreeIterator(repository));
    String lastAddedPath = null;
    ObjectReader od = repository.newObjectReader();
    try {
    while (treeWalk.next() && !monitor.isCanceled()) {
        File path = new File(repository.getWorkTree(), treeWalk.getPathString());
        if (treeWalk.getPathString().equals(lastAddedPath)) {
            // skip conflicts
            continue;
        } else {
            lastAddedPath = treeWalk.getPathString();
        }
        DirCacheIterator dit = treeWalk.getTree(0, DirCacheIterator.class);
        FileTreeIterator fit = treeWalk.getTree(1, FileTreeIterator.class);
        if (dit != null && (recursively || directChild(roots, repository.getWorkTree(), path)) && (fit == null || fit.isModified(dit.getDirCacheEntry(), checkContent, od))) {
            // update entry
            listener.notifyFile(path, treeWalk.getPathString());
            checkoutEntry(repository, path, dit.getDirCacheEntry(), od);
        }
    }
    } finally {
        od.release();
        treeWalk.release();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:CheckoutIndex.java


示例7: isTracked

import org.eclipse.jgit.treewalk.filter.PathFilterGroup; //导入依赖的package包/类
public boolean isTracked(String path) throws IOException {
    ObjectId objectId = localRepo.resolve(Constants.HEAD);
    RevTree tree;
    RevWalk walk = null;
    if (objectId != null) {
      walk = new RevWalk(localRepo);
      tree = walk.parseTree(objectId);
    }
    else {
      tree = null;
    }

    try (TreeWalk treeWalk = new TreeWalk(localRepo)) {
        treeWalk.setRecursive(true);
        if (tree != null)
          treeWalk.addTree(tree);
        else
          treeWalk.addTree(new EmptyTreeIterator());

        treeWalk.addTree(new DirCacheIterator(localRepo.readDirCache()));
        treeWalk.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path)));
        return treeWalk.next();
    }
    finally {
        if (walk != null)
            walk.close();
    }
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:29,代码来源:VersionControlGit.java


示例8: getBaseConfig

import org.eclipse.jgit.treewalk.filter.PathFilterGroup; //导入依赖的package包/类
@Nullable
private static Config getBaseConfig(@NotNull Repository repository, @NotNull String configFileName) throws IOException, ConfigInvalidException {
	final Config baseConfig;
	if (repository.isBare()) {
		// read bugtraq config directly from the repository
		String content = null;
		RevWalk rw = new RevWalk(repository);
		try (TreeWalk tw = new TreeWalk(repository)) {
			tw.setFilter(PathFilterGroup.createFromStrings(configFileName));
			Ref head = repository.getRef(Constants.HEAD);
			if (head == null) {
				return null;
			}
			head = head.getTarget();
			if (head == null) {
				return null;
			}
			ObjectId headId = head.getObjectId();
			if (headId == null) {
				return null;
			}
			RevCommit commit = rw.parseCommit(headId);
			RevTree tree = commit.getTree();
			tw.reset(tree);
			while (tw.next()) {
				ObjectId entid = tw.getObjectId(0);
				FileMode entmode = tw.getFileMode(0);
				if (FileMode.REGULAR_FILE == entmode) {
					ObjectLoader ldr = repository.open(entid, Constants.OBJ_BLOB);
					content = new String(ldr.getCachedBytes(), commit.getEncoding());
					break;
				}
			}
		} finally {
			rw.close();
			rw.dispose();
		}

		if (content == null) {
			// config not found
			baseConfig = null;
		} else {
			// parse the config
			Config config = new Config();
			config.fromText(content);
			baseConfig = config;
		}
	} else {
		// read bugtraq config from work tree
		final File baseFile = new File(repository.getWorkTree(), configFileName);
		if (baseFile.isFile()) {
			FileBasedConfig fileConfig = new FileBasedConfig(baseFile, repository.getFS());
			fileConfig.load();
			baseConfig = fileConfig;
		} else {
			baseConfig = null;
		}
	}
	return baseConfig;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:61,代码来源:BugtraqConfig.java


示例9: getByteContent

import org.eclipse.jgit.treewalk.filter.PathFilterGroup; //导入依赖的package包/类
/**
 * Retrieves the raw byte content of a file in the specified tree.
 * 
 * @param repository
 * @param tree
 *            if null, the RevTree from HEAD is assumed.
 * @param path
 * @return content as a byte []
 */
public static byte[] getByteContent(Repository repository, RevTree tree, final String path, boolean throwError) {
	RevWalk rw = new RevWalk(repository);
	TreeWalk tw = new TreeWalk(repository);
	tw.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path)));
	byte[] content = null;
	try {
		if (tree == null) {
			ObjectId object = getDefaultBranch(repository);
			RevCommit commit = rw.parseCommit(object);
			tree = commit.getTree();
		}
		tw.reset(tree);
		while (tw.next()) {
			if (tw.isSubtree() && !path.equals(tw.getPathString())) {
				tw.enterSubtree();
				continue;
			}
			ObjectId entid = tw.getObjectId(0);
			FileMode entmode = tw.getFileMode(0);
			if (entmode != FileMode.GITLINK) {
				RevObject ro = rw.lookupAny(entid, entmode.getObjectType());
				rw.parseBody(ro);
				ByteArrayOutputStream os = new ByteArrayOutputStream();
				ObjectLoader ldr = repository.open(ro.getId(), Constants.OBJ_BLOB);
				byte[] tmp = new byte[4096];
				InputStream in = ldr.openStream();
				int n;
				while ((n = in.read(tmp)) > 0) {
					os.write(tmp, 0, n);
				}
				in.close();
				content = os.toByteArray();
			}
		}
	} catch (Throwable t) {
		if (throwError) {
			error(t, repository, "{0} can't find {1} in tree {2}", path, tree.name());
		}
	} finally {
		rw.dispose();
		tw.release();
	}
	return content;
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:54,代码来源:JGitUtils.java


示例10: run

import org.eclipse.jgit.treewalk.filter.PathFilterGroup; //导入依赖的package包/类
@Override
  protected void run() throws GitException {
      Repository repository = getRepository();
      DiffFormatter formatter = new DiffFormatter(out);
      formatter.setRepository(repository);
      ObjectReader or = null;
      String workTreePath = repository.getWorkTree().getAbsolutePath();
      try {
          Collection<PathFilter> pathFilters = Utils.getPathFilters(repository.getWorkTree(), roots);
          if (!pathFilters.isEmpty()) {
              formatter.setPathFilter(PathFilterGroup.create(pathFilters));
          }
          if (repository.getConfig().get(WorkingTreeOptions.KEY).getAutoCRLF() != CoreConfig.AutoCRLF.FALSE) {
              // work-around for autocrlf
              formatter.setDiffComparator(new AutoCRLFComparator());
          }
          or = repository.newObjectReader();
          AbstractTreeIterator firstTree = getIterator(firstCommit, or);
          AbstractTreeIterator secondTree = getIterator(secondCommit, or);
          List<DiffEntry> diffEntries;
          if (secondTree instanceof WorkingTreeIterator) {
              // remote when fixed in JGit, see ExportDiffTest.testDiffRenameDetectionProblem
              formatter.setDetectRenames(false);
              diffEntries = formatter.scan(firstTree, secondTree);
              formatter.setDetectRenames(true);
              RenameDetector detector = formatter.getRenameDetector();
              detector.reset();
              detector.addAll(diffEntries);
diffEntries = detector.compute(new ContentSource.Pair(ContentSource.create(or), ContentSource.create((WorkingTreeIterator) secondTree)), NullProgressMonitor.INSTANCE);
          } else {
              formatter.setDetectRenames(true);
              diffEntries = formatter.scan(firstTree, secondTree);
          }
          for (DiffEntry ent : diffEntries) {
              if (monitor.isCanceled()) {
                  break;
              }
              listener.notifyFile(new File(workTreePath + File.separator + ent.getNewPath()), ent.getNewPath());
              formatter.format(ent);
          }
          formatter.flush();
      } catch (IOException ex) {
          throw new GitException(ex);
      } finally {
          if (or != null) {
              or.release();
          }
          formatter.release();
      }
  }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:51,代码来源:ExportDiffCommand.java


示例11: mergeConflicts

import org.eclipse.jgit.treewalk.filter.PathFilterGroup; //导入依赖的package包/类
private void mergeConflicts (List<String> conflicts, DirCache cache) throws GitException {
    DirCacheBuilder builder = cache.builder();
    DirCacheBuildIterator dci = new DirCacheBuildIterator(builder);
    TreeWalk walk = new TreeWalk(getRepository());
    ObjectDatabase od = null;
    DiffAlgorithm.SupportedAlgorithm diffAlg = getRepository().getConfig().getEnum(
                    ConfigConstants.CONFIG_DIFF_SECTION, null,
                    ConfigConstants.CONFIG_KEY_ALGORITHM,
                    DiffAlgorithm.SupportedAlgorithm.HISTOGRAM);
    MergeAlgorithm merger = new MergeAlgorithm(DiffAlgorithm.getAlgorithm(diffAlg));
    try {
        od = getRepository().getObjectDatabase();
        walk.addTree(dci);
        walk.setFilter(PathFilterGroup.create(Utils.getPathFilters(conflicts)));
        String lastPath = null;
        DirCacheEntry[] entries = new DirCacheEntry[3];
        walk.setRecursive(true);
        while (walk.next()) {
            DirCacheEntry e = walk.getTree(0, DirCacheIterator.class).getDirCacheEntry();
            String path = e.getPathString();
            if (lastPath != null && !lastPath.equals(path)) {
                resolveEntries(merger, lastPath, entries, od, builder);
            }
            if (e.getStage() == 0) {
                DirCacheIterator c = walk.getTree(0, DirCacheIterator.class);
                builder.add(c.getDirCacheEntry());
            } else {
                entries[e.getStage() - 1] = e;
                lastPath = path;
            }
        }
        resolveEntries(merger, lastPath, entries, od, builder);
        builder.commit();
    } catch (IOException ex) {
        throw new GitException(ex);
    } finally {
        walk.release();
        if (od != null) {
            od.close();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:43,代码来源:CheckoutRevisionCommand.java


示例12: testAddMixedLineEndings

import org.eclipse.jgit.treewalk.filter.PathFilterGroup; //导入依赖的package包/类
public void testAddMixedLineEndings () throws Exception {
    File f = new File(workDir, "f");
    String content = "";
    for (int i = 0; i < 10000; ++i) {
        content += i + "\r\n";
    }
    write(f, content);
    File[] files = new File[] { f };
    GitClient client = getClient(workDir);
    client.add(files, NULL_PROGRESS_MONITOR);
    client.commit(files, "commit", null, null, NULL_PROGRESS_MONITOR);
    
    Map<File, GitStatus> statuses = client.getStatus(files, NULL_PROGRESS_MONITOR);
    assertEquals(1, statuses.size());
    assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false);
    
    // lets turn autocrlf on
    StoredConfig cfg = repository.getConfig();
    cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "true");
    cfg.save();
    
    // when this starts failing, remove the work around
    ObjectInserter inserter = repository.newObjectInserter();
    TreeWalk treeWalk = new TreeWalk(repository);
    treeWalk.setFilter(PathFilterGroup.createFromStrings("f"));
    treeWalk.setRecursive(true);
    treeWalk.reset();
    treeWalk.addTree(new FileTreeIterator(repository));
    while (treeWalk.next()) {
        String path = treeWalk.getPathString();
        assertEquals("f", path);
        WorkingTreeIterator fit = treeWalk.getTree(0, WorkingTreeIterator.class);
        InputStream in = fit.openEntryStream();
        try {
            inserter.insert(Constants.OBJ_BLOB, fit.getEntryLength(), in);
            fail("this should fail, remove the work around");
        } catch (EOFException ex) {
            assertEquals("Input did not match supplied length. 10000 bytes are missing.", ex.getMessage());
        } finally {
            in.close();
            inserter.release();
        }
        break;
    }
    
    // no err should occur
    write(f, content + "hello");
    statuses = client.getStatus(files, NULL_PROGRESS_MONITOR);
    assertEquals(1, statuses.size());
    assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false);
    client.add(files, NULL_PROGRESS_MONITOR);
    statuses = client.getStatus(files, NULL_PROGRESS_MONITOR);
    assertEquals(1, statuses.size());
    assertStatus(statuses, workDir, f, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false);
    client.commit(files, "message", null, null, NULL_PROGRESS_MONITOR);
    statuses = client.getStatus(files, NULL_PROGRESS_MONITOR);
    assertEquals(1, statuses.size());
    assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:60,代码来源:AddTest.java


示例13: getFileRevisions

import org.eclipse.jgit.treewalk.filter.PathFilterGroup; //导入依赖的package包/类
@Nonnull
public static List<RevCommit> getFileRevisions(String path, AnyObjectId start, int skip, int limit, ObjectReader reader) throws IOException {
  path = normalizeNodePath(path);
  TreeFilter filter = AndTreeFilter.create(PathFilterGroup.createFromStrings(path), ANY_DIFF);
  return getHistory(start, skip, limit, filter, reader);
}
 
开发者ID:beijunyi,项目名称:ParallelGit,代码行数:7,代码来源:CommitUtils.java


示例14: getCommitDiffFiles

import org.eclipse.jgit.treewalk.filter.PathFilterGroup; //导入依赖的package包/类
private List<DiffCommitFile> getCommitDiffFiles(RevCommit revCommit, String pattern)
    throws IOException {
  List<DiffEntry> diffs;
  TreeFilter filter = null;
  if (!isNullOrEmpty(pattern)) {
    filter =
        AndTreeFilter.create(
            PathFilterGroup.createFromStrings(Collections.singleton(pattern)),
            TreeFilter.ANY_DIFF);
  }
  List<DiffCommitFile> commitFilesList = new ArrayList<>();
  try (TreeWalk tw = new TreeWalk(repository)) {
    tw.setRecursive(true);
    // get the current commit parent in order to compare it with the current commit
    // and to get the list of DiffEntry.
    if (revCommit.getParentCount() > 0) {
      RevCommit parent = parseCommit(revCommit.getParent(0));
      tw.reset(parent.getTree(), revCommit.getTree());
      if (filter != null) {
        tw.setFilter(filter);
      } else {
        tw.setFilter(TreeFilter.ANY_DIFF);
      }
      diffs = DiffEntry.scan(tw);
    } else {
      // If the current commit has no parents (which means it is the initial commit),
      // then create an empty tree and compare it to the current commit to get the
      // list of DiffEntry.
      try (RevWalk rw = new RevWalk(repository);
          DiffFormatter diffFormat = new DiffFormatter(NullOutputStream.INSTANCE)) {
        diffFormat.setRepository(repository);
        if (filter != null) {
          diffFormat.setPathFilter(filter);
        }
        diffs =
            diffFormat.scan(
                new EmptyTreeIterator(),
                new CanonicalTreeParser(null, rw.getObjectReader(), revCommit.getTree()));
      }
    }
  }
  if (diffs != null) {
    commitFilesList.addAll(
        diffs
            .stream()
            .map(
                diff ->
                    newDto(DiffCommitFile.class)
                        .withOldPath(diff.getOldPath())
                        .withNewPath(diff.getNewPath())
                        .withChangeType(diff.getChangeType().name()))
            .collect(toList()));
  }
  return commitFilesList;
}
 
开发者ID:eclipse,项目名称:che,代码行数:56,代码来源:JGitConnection.java


示例15: writeTo

import org.eclipse.jgit.treewalk.filter.PathFilterGroup; //导入依赖的package包/类
@Override
public final void writeTo(OutputStream out) throws IOException {
  DiffFormatter formatter = new DiffFormatter(new BufferedOutputStream(out));
  formatter.setRepository(repository);
  List<String> rawFileFilter = params.getFileFilter();
  TreeFilter pathFilter =
      (rawFileFilter != null && rawFileFilter.size() > 0)
          ? PathFilterGroup.createFromStrings(rawFileFilter)
          : TreeFilter.ALL;
  formatter.setPathFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, pathFilter));

  try {
    String commitA = params.getCommitA();
    String commitB = params.getCommitB();
    boolean cached = params.isCached();

    List<DiffEntry> diff;
    if (commitA == null && commitB == null && !cached) {
      diff = indexToWorkingTree(formatter);
    } else if (commitA != null && commitB == null && !cached) {
      diff = commitToWorkingTree(commitA, formatter);
    } else if (commitA == null && commitB != null) {
      diff = emptyToCommit(commitB, formatter);
    } else if (commitB == null) {
      diff = commitToIndex(commitA, formatter);
    } else {
      diff = commitToCommit(commitA, commitB, formatter);
    }

    DiffType type = params.getType();
    if (type == DiffType.NAME_ONLY) {
      writeNames(diff, out);
    } else if (type == DiffType.NAME_STATUS) {
      writeNamesAndStatus(diff, out);
    } else {
      writeRawDiff(diff, formatter);
    }
  } catch (GitException e) {
    LOG.error(e.getMessage());
  } finally {
    formatter.close();
    repository.close();
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:45,代码来源:JGitDiffPage.java


示例16: copy

import org.eclipse.jgit.treewalk.filter.PathFilterGroup; //导入依赖的package包/类
private List<String> copy(
    Set<String> paths, PatchSet.Id old, RevisionResource resource, Account.Id userId)
    throws IOException, PatchListNotAvailableException, OrmException {
  Project.NameKey project = resource.getChange().getProject();
  try (Repository git = gitManager.openRepository(project);
      ObjectReader reader = git.newObjectReader();
      RevWalk rw = new RevWalk(reader);
      TreeWalk tw = new TreeWalk(reader)) {
    Change change = resource.getChange();
    PatchSet patchSet = psUtil.get(db.get(), resource.getNotes(), old);
    if (patchSet == null) {
      throw new PatchListNotAvailableException(
          String.format(
              "patch set %s of change %s not found", old.get(), change.getId().get()));
    }

    PatchList oldList = patchListCache.get(change, patchSet);

    PatchList curList = patchListCache.get(change, resource.getPatchSet());

    int sz = paths.size();
    List<String> pathList = Lists.newArrayListWithCapacity(sz);

    tw.setFilter(PathFilterGroup.createFromStrings(paths));
    tw.setRecursive(true);
    int o = tw.addTree(rw.parseCommit(oldList.getNewId()).getTree());
    int c = tw.addTree(rw.parseCommit(curList.getNewId()).getTree());

    int op = -1;
    if (oldList.getOldId() != null) {
      op = tw.addTree(rw.parseTree(oldList.getOldId()));
    }

    int cp = -1;
    if (curList.getOldId() != null) {
      cp = tw.addTree(rw.parseTree(curList.getOldId()));
    }

    while (tw.next()) {
      String path = tw.getPathString();
      if (tw.getRawMode(o) != 0
          && tw.getRawMode(c) != 0
          && tw.idEqual(o, c)
          && paths.contains(path)) {
        // File exists in previously reviewed oldList and in curList.
        // File content is identical.
        pathList.add(path);
      } else if (op >= 0
          && cp >= 0
          && tw.getRawMode(o) == 0
          && tw.getRawMode(c) == 0
          && tw.getRawMode(op) != 0
          && tw.getRawMode(cp) != 0
          && tw.idEqual(op, cp)
          && paths.contains(path)) {
        // File was deleted in previously reviewed oldList and curList.
        // File exists in ancestor of oldList and curList.
        // File content is identical in ancestors.
        pathList.add(path);
      }
    }
    accountPatchReviewStore
        .get()
        .markReviewed(resource.getPatchSet().getId(), userId, pathList);
    return pathList;
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:68,代码来源:Files.java



注:本文中的org.eclipse.jgit.treewalk.filter.PathFilterGroup类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java InternalCompassOrientationProvider类代码示例发布时间:2022-05-22
下一篇:
Java XMLStreamWriter类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap