當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。