当前位置: 首页>>代码示例>>Java>>正文


Java TreeWalk类代码示例

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


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

示例1: getHeadFiles

import org.eclipse.jgit.treewalk.TreeWalk; //导入依赖的package包/类
private List<IdentifiableResource> getHeadFiles (Repository aRepository, String... aSearchPaths) {
  List<String> searchPaths = Arrays.asList(aSearchPaths);
  List<IdentifiableResource> resources = new ArrayList<>();
  try (ObjectReader reader = aRepository.newObjectReader(); RevWalk walk = new RevWalk(reader); TreeWalk treeWalk = new TreeWalk(aRepository,reader);) {
    final ObjectId id = aRepository.resolve(Constants.HEAD);
    RevCommit commit = walk.parseCommit(id);
    RevTree tree = commit.getTree();
    treeWalk.addTree(tree);
    treeWalk.setRecursive(true);
    while (treeWalk.next()) {
      String path = treeWalk.getPathString();        
      if(searchPaths.stream().anyMatch((sp)->path.startsWith(sp))) {
        ObjectId objectId = treeWalk.getObjectId(0);
        logger.debug("Loading {} [{}]",path,objectId.name());
        resources.add(readBlob(aRepository, path.substring(0, path.indexOf('.')), objectId.name()));
      }
    }
    return resources;
  }
  catch (Exception e) {
    throw Throwables.propagate(e);
  } 
}
 
开发者ID:creactiviti,项目名称:piper,代码行数:24,代码来源:JGitTemplate.java

示例2: getPathModel

import org.eclipse.jgit.treewalk.TreeWalk; //导入依赖的package包/类
/**
 * Returns a path model of the current file in the treewalk.
 * 
 * @param tw
 * @param basePath
 * @param commit
 * @return a path model of the current file in the treewalk
 */
private static PathModel getPathModel(TreeWalk tw, String basePath, RevCommit commit) {
	String name;
	long size = 0;
	if (StringUtils.isEmpty(basePath)) {
		name = tw.getPathString();
	} else {
		name = tw.getPathString().substring(basePath.length() + 1);
	}
	ObjectId objectId = tw.getObjectId(0);
	try {
		if (!tw.isSubtree() && (tw.getFileMode(0) != FileMode.GITLINK)) {
			size = tw.getObjectReader().getObjectSize(objectId, Constants.OBJ_BLOB);
		}
	} catch (Throwable t) {
		error(t, null, "failed to retrieve blob size for " + tw.getPathString());
	}
	return new PathModel(name, tw.getPathString(), size, tw.getFileMode(0).getBits(), objectId.getName(), commit.getName());
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:27,代码来源:JGitUtils.java

示例3: getSubmoduleCommitId

import org.eclipse.jgit.treewalk.TreeWalk; //导入依赖的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

示例4: getPathModel

import org.eclipse.jgit.treewalk.TreeWalk; //导入依赖的package包/类
/**
 * Returns a path model of the current file in the treewalk.
 * 
 * @param tw
 * @param basePath
 * @param commit
 * @return a path model of the current file in the treewalk
 */
private static PathModel getPathModel(TreeWalk tw, String basePath, RevCommit commit) {
	String name;
	long size = 0;
	if (StringUtils.isEmpty(basePath)) {
		name = tw.getPathString();
	} else {
		name = tw.getPathString().substring(basePath.length() + 1);
	}
	ObjectId objectId = tw.getObjectId(0);
	try {
		if (!tw.isSubtree() && (tw.getFileMode(0) != FileMode.GITLINK)) {
			size = tw.getObjectReader().getObjectSize(objectId, Constants.OBJ_BLOB);
		}
	} catch (Throwable t) {
		error(t, null, "failed to retrieve blob size for " + tw.getPathString());
	}
	return new PathModel(name, tw.getPathString(), size, tw.getFileMode(0).getBits(),
			objectId.getName(), commit.getName());
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:28,代码来源:JGitUtils.java

示例5: getSubmoduleCommitId

import org.eclipse.jgit.treewalk.TreeWalk; //导入依赖的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

示例6: isDirectory

import org.eclipse.jgit.treewalk.TreeWalk; //导入依赖的package包/类
/** 파일주소와 커밋아이디를 바탕으로 디렉토리인지 검사함.
 * @param commitID
 * @param filePath
 * @return
 */
public boolean isDirectory(String commitID, String filePath){
	if(filePath.length() == 0)
		return true;
	try{
		ObjectId revId = this.localRepo.resolve(commitID);
		TreeWalk treeWalk = new TreeWalk(this.localRepo);
		treeWalk.addTree(new RevWalk(this.localRepo).parseTree(revId));
		treeWalk.setRecursive(true);
		while (treeWalk.next()) {
			if(treeWalk.getPathString().equals(filePath)){
				return false;
			}
		}
		treeWalk.reset(new RevWalk(this.localRepo).parseTree(revId));
		while (treeWalk.next()) {
			if(treeWalk.getPathString().startsWith(filePath)){
				return true;
			}
		}
	}catch(Exception e){
		return false;
	}
	return false;
}
 
开发者ID:forweaver,项目名称:forweaver2.0,代码行数:30,代码来源:GitUtil.java

示例7: getGitFileList

import org.eclipse.jgit.treewalk.TreeWalk; //导入依赖的package包/类
/** 저장소의 파일 목록을 커밋 아이디를 가지고 가져옴.
 * @param commitID
 * @return
 */
public List<String> getGitFileList(String commitID) {
	List<String> fileList = new ArrayList<String>();
	try{
		ObjectId revId = this.localRepo.resolve(commitID);
		TreeWalk treeWalk = new TreeWalk(this.localRepo);
		treeWalk.addTree(new RevWalk(this.localRepo).parseTree(revId));
		treeWalk.setRecursive(true);

		while (treeWalk.next()) {
			fileList.add("/"+treeWalk.getPathString());
		}

	}catch(Exception e){
		System.out.println(e.getMessage());
	}
	return fileList;
}
 
开发者ID:forweaver,项目名称:forweaver2.0,代码行数:22,代码来源:GitUtil.java

示例8: simpleFileBrowser

import org.eclipse.jgit.treewalk.TreeWalk; //导入依赖的package包/类
/** 단순하게 커밋을 트리워크를 이용하여 당시 파일 내역을 출력.
 * @param commit
 * @return
 */
private String simpleFileBrowser(RevCommit commit){
	String out = new String();
	try
	{
		TreeWalk treeWalk = new TreeWalk(this.localRepo);
		treeWalk.addTree(new RevWalk(this.localRepo).parseTree(	commit));

		while (treeWalk.next())
		{
			out+="--- /dev/null\n";
			out+="+++ b/"+treeWalk.getPathString()+"\n";
			out+= "+"+BlobUtils.getContent(this.localRepo, commit,treeWalk.getPathString().replace("\n", "\n+"));
			out+="\n";
		}
	}finally{
		return out;
	}
}
 
开发者ID:forweaver,项目名称:forweaver2.0,代码行数:23,代码来源:GitUtil.java

示例9: deleteIfUnversioned

import org.eclipse.jgit.treewalk.TreeWalk; //导入依赖的package包/类
private void deleteIfUnversioned(DirCache cache, String path, WorkingTreeIterator f, Repository repository, TreeWalk treeWalk) throws IOException, NoWorkTreeException {
    if (cache.getEntry(path) == null &&  // not in index 
        !f.isEntryIgnored() &&             // not ignored
        !Utils.isFromNested(f.getEntryFileMode().getBits()))
    {            
        File file = new File(repository.getWorkTree().getAbsolutePath() + File.separator + path);                        
        if(file.isDirectory()) {
            String[] s = file.list();
            if(s != null && s.length > 0) { // XXX is there no better way to find out if empty?
                // not empty
                return; 
            }
        }
        file.delete();
        listener.notifyFile(file, treeWalk.getPathString());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:CleanCommand.java

示例10: QuickSearchPanel

import org.eclipse.jgit.treewalk.TreeWalk; //导入依赖的package包/类
public QuickSearchPanel(String id, IModel<Project> projectModel, IModel<String> revisionModel) {
	super(id);
	
	this.projectModel = projectModel;
	this.revisionModel = revisionModel;
	
	Project project = projectModel.getObject();
	for (String blobPath: getRecentOpened()) {
		try {
			RevTree revTree = project.getRevCommit(revisionModel.getObject()).getTree();
			TreeWalk treeWalk = TreeWalk.forPath(project.getRepository(), blobPath, revTree);
			if (treeWalk != null && treeWalk.getRawMode(0) != FileMode.TREE.getBits()) {
				symbolHits.add(new FileHit(blobPath, null));
			}
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:20,代码来源:QuickSearchPanel.java

示例11: getChangedFiles

import org.eclipse.jgit.treewalk.TreeWalk; //导入依赖的package包/类
private Set<String> getChangedFiles(Project project, ObjectId oldObjectId, ObjectId newObjectId) {
	Set<String> changedFiles = new HashSet<>();
	try (TreeWalk treeWalk = new TreeWalk(project.getRepository())) {
		treeWalk.setFilter(TreeFilter.ANY_DIFF);
		treeWalk.setRecursive(true);
		RevCommit oldCommit = project.getRevCommit(oldObjectId);
		RevCommit newCommit = project.getRevCommit(newObjectId);
		treeWalk.addTree(oldCommit.getTree());
		treeWalk.addTree(newCommit.getTree());
		while (treeWalk.next()) {
			changedFiles.add(treeWalk.getPathString());
		}
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
	return changedFiles;
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:18,代码来源:DefaultProjectManager.java

示例12: getMode

import org.eclipse.jgit.treewalk.TreeWalk; //导入依赖的package包/类
public int getMode(String revision, @Nullable String path) {
	if (path != null) {
		RevCommit commit = getRevCommit(revision);
		try {
			TreeWalk treeWalk = TreeWalk.forPath(getRepository(), path, commit.getTree());
			if (treeWalk != null) {
				return treeWalk.getRawMode(0);
			} else {
				throw new ObjectNotFoundException("Unable to find blob path '" + path
						+ "' in revision '" + revision + "'");
			}
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	} else {
		return FileMode.TREE.getBits();
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:19,代码来源:Project.java

示例13: testRemoveFile

import org.eclipse.jgit.treewalk.TreeWalk; //导入依赖的package包/类
@Test
public void testRemoveFile() throws IOException {
	createDir("client");
	addFileAndCommit("client/a.java", "a", "add a");
	addFileAndCommit("client/b.java", "b", "add b");
	
	createDir("server/src/com/example/a");
	createDir("server/src/com/example/b");
	addFileAndCommit("server/src/com/example/a/a.java", "a", "add a");
	addFileAndCommit("server/src/com/example/b/b.java", "b", "add b");
	
	String refName = "refs/heads/master";
	ObjectId oldCommitId = git.getRepository().resolve(refName);
	
	BlobEdits edits = new BlobEdits(Sets.newHashSet("/server/src/com/example/a//a.java"), Maps.newHashMap());
	ObjectId newCommitId = edits.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user, "test delete");
	
	try (RevWalk revWalk = new RevWalk(git.getRepository())) {
		RevTree revTree = revWalk.parseCommit(newCommitId).getTree();
		assertNull(TreeWalk.forPath(git.getRepository(), "server/src/com/example/a", revTree));
		assertNotNull(TreeWalk.forPath(git.getRepository(), "server/src/com/example/b/b.java", revTree));
		assertNotNull(TreeWalk.forPath(git.getRepository(), "client/a.java", revTree));
		assertNotNull(TreeWalk.forPath(git.getRepository(), "client/b.java", revTree));
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:26,代码来源:BlobEditsTest.java

示例14: shouldFailIfOldPathIsTreeWhenRename

import org.eclipse.jgit.treewalk.TreeWalk; //导入依赖的package包/类
@Test
public void shouldFailIfOldPathIsTreeWhenRename() throws IOException {
	createDir("client");
	addFileAndCommit("client/a.java", "a", "add a");
	addFileAndCommit("client/b.java", "b", "add b");
	
	createDir("server/src/com/example/a");
	createDir("server/src/com/example/b");
	addFileAndCommit("server/src/com/example/a/a.java", "a", "add a");
	addFileAndCommit("server/src/com/example/b/b.java", "b", "add b");
	
	String refName = "refs/heads/master";
	ObjectId oldCommitId = git.getRepository().resolve(refName);
	
	Map<String, BlobContent> newBlobs = new HashMap<>();
	newBlobs.put("client/c.java", new BlobContent.Immutable("a".getBytes(), FileMode.REGULAR_FILE));
	BlobEdits edits = new BlobEdits(Sets.newHashSet("server/src/com/example/a"), newBlobs);
	ObjectId newCommitId = edits.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user, 
			"test rename");
	try (RevWalk revWalk = new RevWalk(git.getRepository())) {
		RevTree revTree = revWalk.parseCommit(newCommitId).getTree();
		assertNotNull(TreeWalk.forPath(git.getRepository(), "client/c.java", revTree));
		assertNull(TreeWalk.forPath(git.getRepository(), "server/src/com/example/a", revTree));
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:26,代码来源:BlobEditsTest.java

示例15: testMergeWithoutConflicts

import org.eclipse.jgit.treewalk.TreeWalk; //导入依赖的package包/类
@Test
public void testMergeWithoutConflicts() throws Exception {
	addFileAndCommit("initial", "", "initial");
	git.checkout().setCreateBranch(true).setName("dev").call();
	addFileAndCommit("dev1", "", "dev1");
	addFileAndCommit("dev2", "", "dev2");
	git.checkout().setName("master").call();
	addFileAndCommit("master1", "", "master1");
	addFileAndCommit("master2", "", "master2");
	ObjectId masterId = git.getRepository().resolve("master");
	ObjectId devId = git.getRepository().resolve("dev");
	ObjectId mergeCommitId = GitUtils.merge(git.getRepository(), devId, masterId, false, user, "merge commit");
	try (	RevWalk revWalk = new RevWalk(git.getRepository());
			TreeWalk treeWalk = new TreeWalk(git.getRepository())) {
		RevCommit mergeCommit = revWalk.parseCommit(mergeCommitId);
		treeWalk.addTree(mergeCommit.getTree());
		Set<String> files = new HashSet<>();
		while (treeWalk.next()) {
			files.add(treeWalk.getPathString());
		}
		assertEquals(Sets.newHashSet("initial", "dev1", "dev2", "master1", "master2"), files);
		assertEquals(2, mergeCommit.getParentCount());
		assertEquals(masterId, mergeCommit.getParent(0));
		assertEquals(devId, mergeCommit.getParent(1));
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:27,代码来源:GitUtilsTest.java


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