當前位置: 首頁>>代碼示例>>Java>>正文


Java TreeWalk.setFilter方法代碼示例

本文整理匯總了Java中org.eclipse.jgit.treewalk.TreeWalk.setFilter方法的典型用法代碼示例。如果您正苦於以下問題:Java TreeWalk.setFilter方法的具體用法?Java TreeWalk.setFilter怎麽用?Java TreeWalk.setFilter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jgit.treewalk.TreeWalk的用法示例。


在下文中一共展示了TreeWalk.setFilter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: getLoaderFrom

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
/**
 * Gets the loader for a file from a specified commit and its path
 * 
 * @param commit
 *          - the commit from which to get the loader
 * @param path
 *          - the path to the file
 * @return the loader
 * @throws MissingObjectException
 * @throws IncorrectObjectTypeException
 * @throws CorruptObjectException
 * @throws IOException
 */
public ObjectLoader getLoaderFrom(ObjectId commit, String path)
		throws IOException {
	Repository repository = git.getRepository();
	RevWalk revWalk = new RevWalk(repository);
	RevCommit revCommit = revWalk.parseCommit(commit);
	// and using commit's tree find the path
	RevTree tree = revCommit.getTree();
	TreeWalk treeWalk = new TreeWalk(repository);
	treeWalk.addTree(tree);
	treeWalk.setRecursive(true);
	treeWalk.setFilter(PathFilter.create(path));

	ObjectLoader loader = null;
	if (treeWalk.next()) {
		ObjectId objectId = treeWalk.getObjectId(0);
		loader = repository.open(objectId);
	}

	treeWalk.close();
	revWalk.close();
	return loader;
}
 
開發者ID:oxygenxml,項目名稱:oxygen-git-plugin,代碼行數:36,代碼來源:GitAccess.java

示例3: getFileFromCommit

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public static boolean getFileFromCommit(final OutputStream os, final String file, final Repository repo, final RevTree tree) throws IOException, GitAPIException {
    final TreeWalk treeWalk = new TreeWalk(repo);
    treeWalk.addTree(tree);
    treeWalk.setRecursive(true);
    treeWalk.setFilter(PathFilter.create(file));
    if (!treeWalk.next()) {
        logger.info("Did not find expected file '" + file + "'");
        return false;
    }

    final ObjectId objectId = treeWalk.getObjectId(0);
    final ObjectLoader loader = repo.open(objectId);

    // and then one can the loader to read the file
    loader.copyTo(os);
    return true;
}
 
開發者ID:cobr123,項目名稱:VirtaMarketAnalyzer,代碼行數:18,代碼來源:GitHubPublisher.java

示例4: getBlob

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
private Optional<String[]> getBlob(Git git, String fileName, CodeRevision revision)
		throws IOException {
	TreeWalk treeWalk = new TreeWalk(git.getRepository());
	treeWalk.addTree(getTreeIterator(git, revision));
	treeWalk.setFilter(PathFilter.create(fileName));
	treeWalk.setRecursive(true);
	if (!treeWalk.next()) {
		return Optional.empty();
	}
	ObjectId blobId = treeWalk.getObjectId(0);
	String content = new String(git.getRepository().getObjectDatabase().open(blobId).getBytes(),
			Charset.forName("UTF-8"));

	String[] lines = content.split("\n");
	return Optional.of(lines);
}
 
開發者ID:bugminer,項目名稱:bugminer,代碼行數:17,代碼來源:GitStrategy.java

示例5: gitRepoContainsFile

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public static boolean gitRepoContainsFile(Repository repository, String file) throws IllegalStateException, IOException {
	ObjectId lastCommitId = repository.resolve(Constants.HEAD);

       // a RevWalk allows to walk over commits based on some filtering
       RevWalk revWalk = new RevWalk(repository);
       RevCommit commit = revWalk.parseCommit(lastCommitId);

       // and using commit's tree find the path
       RevTree tree = commit.getTree();
       
       TreeWalk treeWalk = new TreeWalk(repository);
       treeWalk.addTree(tree);
       treeWalk.setRecursive(true);
       treeWalk.setFilter(PathFilter.create(file));
       return treeWalk.next(); 
}
 
開發者ID:jenkinsci,項目名稱:openshift-deployer-plugin,代碼行數:17,代碼來源:TestUtils.java

示例6: listFiles

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
private void listFiles() throws GitException {
    RevWalk revWalk = new RevWalk(repository);
    TreeWalk walk = new TreeWalk(repository);
    try {
        List<GitFileInfo> result;
        walk.reset();
        walk.setRecursive(true);
        RevCommit parentCommit = null;
        if (revCommit.getParentCount() > 0) {
            for (RevCommit commit : revCommit.getParents()) {
                revWalk.markStart(revWalk.lookupCommit(commit));
            }
            revWalk.setRevFilter(RevFilter.MERGE_BASE);
            Iterator<RevCommit> it = revWalk.iterator();
            if (it.hasNext()) {
                parentCommit = it.next();
            }
            if (parentCommit != null) {
                walk.addTree(parentCommit.getTree().getId());
            }
        }
        walk.addTree(revCommit.getTree().getId());
        walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, PathFilter.ANY_DIFF));
        if (parentCommit != null) {
            result = Utils.getDiffEntries(repository, walk, GitClassFactoryImpl.getInstance());
        } else {
            result = new ArrayList<GitFileInfo>();
            while (walk.next()) {
                result.add(new GitFileInfo(new File(repository.getWorkTree(), walk.getPathString()), walk.getPathString(), GitFileInfo.Status.ADDED, null, null));
            }
        }
        this.modifiedFiles = result.toArray(new GitFileInfo[result.size()]);
    } catch (IOException ex) {
        throw new GitException(ex);
    } finally {
        revWalk.release();
        walk.release();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:40,代碼來源:GitRevisionInfo.java

示例7: checkout

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的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

示例8: updateFollowFilter

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
private void updateFollowFilter(ObjectId[] trees, DiffConfig cfg)
		throws MissingObjectException, IncorrectObjectTypeException,
		CorruptObjectException, IOException {
	TreeWalk tw = pathFilter;
	FollowFilter oldFilter = (FollowFilter) tw.getFilter();
	tw.setFilter(TreeFilter.ANY_DIFF);
	tw.reset(trees);

	List<DiffEntry> files = DiffEntry.scan(tw);
	RenameDetector rd = new RenameDetector(tw.getObjectReader(), cfg);
	rd.addAll(files);
	files = rd.compute();

	TreeFilter newFilter = oldFilter;
	for (DiffEntry ent : files) {
		if (isRename(ent) && ent.getNewPath().equals(oldFilter.getPath())) {
			newFilter = FollowFilter.create(ent.getOldPath(), cfg);
			RenameCallback callback = oldFilter.getRenameCallback();
			if (callback != null) {
				callback.renamed(ent);
				// forward the callback to the new follow filter
				((FollowFilter) newFilter).setRenameCallback(callback);
			}
			break;
		}
	}
	tw.setFilter(newFilter);
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:29,代碼來源:TreeRevFilter.java

示例9: getLastRevision

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public static void getLastRevision(Git git, String base, String name, 
     String rev, OutputStream out, String ext) 
                         throws WsSrvException, IOException {

  checkFile(base, name, ext);
   String fp = getLocalPath(name);
   
   // find the HEAD
   ObjectId lastCommitId = git.getRepository().resolve(Constants.HEAD);

   // a RevWalk allows to walk over commits based on 
   // 									some filtering that is defined
   RevWalk revWalk = new RevWalk(git.getRepository());
   RevCommit commit = revWalk.parseCommit(lastCommitId);
   // and using commit's tree find the path
   RevTree tree = commit.getTree();
   System.out.println("Having tree: " + tree);

   // now try to find a specific file
   TreeWalk treeWalk = new TreeWalk(git.getRepository());
   treeWalk.addTree(tree);
   treeWalk.setRecursive(true);
   treeWalk.setFilter(PathFilter.create(fp));
   
   if (!treeWalk.next()) {
       throw new IllegalStateException(
       		"Did not find expected file 'README.md'");
   }

   ObjectId objectId = treeWalk.getObjectId(0);
   System.out.println("ObjectId: " + objectId.toString());
   ObjectLoader loader = git.getRepository().open(objectId);

   // and then one can the loader to read the file
   loader.copyTo(System.out);

   revWalk.dispose();
  
}
 
開發者ID:osbitools,項目名稱:OsBiToolsWs,代碼行數:40,代碼來源:GitUtils.java

示例10: forPath

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
@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();
}
 
開發者ID:beijunyi,項目名稱:ParallelGit,代碼行數:15,代碼來源:GfsTreeWalkTest.java

示例11: listIgnored

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
private String[] listIgnored(Repository rep, RevWalk rw, TreeWalk tw, int cutPrefixLen) throws Exception {
	addTree(GitModeMenuMgr.MODE_STAGING, null, rep, rw, tw);
	int workingTreeIndex = addTree(GitModeMenuMgr.MODE_WORKING_AREA, null, rep, rw, tw);
	IndexDiffFilter filter = new IndexDiffFilter(0, workingTreeIndex, true);
	tw.setFilter(filter);
	tw.setRecursive(true);
	while (tw.next()) {
		//just loop it...
	}
	Set<String> s = filter.getIgnoredPaths();
	return s.toArray(new String[s.size()]);
}
 
開發者ID:BeckYang,項目名稱:TeamFileList,代碼行數:13,代碼來源:GitListBuilder.java

示例12: getFileContentOfLastCommit

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public static File getFileContentOfLastCommit(String filePath,Repository repository) throws RevisionSyntaxException, AmbiguousObjectException, IncorrectObjectTypeException, IOException {
	// find the HEAD
	ObjectId lastCommitId = repository.resolve(Constants.HEAD);

	// a RevWalk allows to walk over commits based on some filtering that is
	// defined
	RevWalk revWalk = new RevWalk(repository);
	RevCommit commit = revWalk.parseCommit(lastCommitId);
	// and using commit's tree find the path
	RevTree tree = commit.getTree();
	System.out.println("Having tree: " + tree);

	// now try to find a specific file
	TreeWalk treeWalk = new TreeWalk(repository);
	treeWalk.addTree(tree);
	treeWalk.setRecursive(true);
	treeWalk.setPostOrderTraversal(true);
	treeWalk.setFilter(PathFilter.create(filePath));
	if (!treeWalk.next()) {
		//TODO the file is added to project
		throw new IllegalStateException(
				"CHANGECOMMIT -- Did not find expected file '" + filePath + "'");
	}

	ObjectId objectId = treeWalk.getObjectId(0);
	ObjectLoader loader = repository.open(objectId);

	return Utils.inputStreamToFile(loader.openStream());
}
 
開發者ID:SEMERU-WM,項目名稱:ChangeScribe,代碼行數:30,代碼來源:Utils.java

示例13: getStringContentOfLastCommit

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public static String getStringContentOfLastCommit(String filePath,Repository repository) throws RevisionSyntaxException, AmbiguousObjectException, IncorrectObjectTypeException, IOException {
	// find the HEAD
	ObjectId lastCommitId = repository.resolve(Constants.HEAD);
	// a RevWalk allows to walk over commits based on some filtering that is
	// defined
	RevWalk revWalk = new RevWalk(repository);
	RevCommit commit = revWalk.parseCommit(lastCommitId);
	// and using commit's tree find the path
	RevTree tree = commit.getTree();
	System.out.println("Having tree: " + tree);
	// now try to find a specific file
	TreeWalk treeWalk = new TreeWalk(repository);
	treeWalk.addTree(tree);
	treeWalk.setRecursive(true);
	treeWalk.setPostOrderTraversal(true);
	treeWalk.setFilter(PathFilter.create(filePath));
	if (!treeWalk.next()) {
		//TODO the file is added to project
		throw new IllegalStateException(
				"CHANGECOMMIT -- Did not find expected file '" + filePath + "'");
	}

	ObjectId objectId = treeWalk.getObjectId(0);
	ObjectLoader loader = repository.open(objectId);
	
	return IOUtils.stringFromFile(Utils.inputStreamToFile(loader.openStream()).getAbsolutePath(), "utf-8");
}
 
開發者ID:SEMERU-WM,項目名稱:ChangeScribe,代碼行數:28,代碼來源:Utils.java

示例14: getStringContentOfCommitID

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public static String getStringContentOfCommitID(String filePath,Repository repository, String commitID) throws RevisionSyntaxException, AmbiguousObjectException, IncorrectObjectTypeException, IOException {
	// find the HEAD
	ObjectId lastCommitId = repository.resolve(commitID);

	// a RevWalk allows to walk over commits based on some filtering that is
	// defined
	RevWalk revWalk = new RevWalk(repository);
	RevCommit commit = revWalk.parseCommit(lastCommitId);
	// and using commit's tree find the path
	RevTree tree = commit.getTree();
	System.out.println("Having tree: " + tree);

	// now try to find a specific file
	TreeWalk treeWalk = new TreeWalk(repository);
	treeWalk.addTree(tree);
	treeWalk.setRecursive(true);
	treeWalk.setPostOrderTraversal(true);
	treeWalk.setFilter(PathFilter.create(filePath.substring(filePath.indexOf("/") + 1)));
	if (!treeWalk.next()) {
		
		//TODO the file is added to project
		throw new IllegalStateException(
				"CHANGECOMMIT -- Did not find expected file '" + filePath + "'");
	}
	ObjectId objectId = treeWalk.getObjectId(0);
	ObjectLoader loader = repository.open(objectId);
	return IOUtils.stringFromFile(Utils.inputStreamToFile(loader.openStream()).getAbsolutePath(), "utf-8");
}
 
開發者ID:SEMERU-WM,項目名稱:ChangeScribe,代碼行數:29,代碼來源:Utils.java

示例15: streamFromRepo

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
protected boolean streamFromRepo(HttpServletRequest request, HttpServletResponse response, Repository repository, RevCommit commit,
		String requestedPath) throws IOException {

	boolean served = false;
	RevWalk rw = new RevWalk(repository);
	TreeWalk tw = new TreeWalk(repository);
	try {
		tw.reset();
		tw.addTree(commit.getTree());
		PathFilter f = PathFilter.create(requestedPath);
		tw.setFilter(f);
		tw.setRecursive(true);
		MutableObjectId id = new MutableObjectId();
		ObjectReader reader = tw.getObjectReader();
		while (tw.next()) {
			FileMode mode = tw.getFileMode(0);
			if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
				continue;
			}
			tw.getObjectId(id, 0);

			String filename = StringUtils.getLastPathElement(requestedPath);
			try {
				String userAgent = request.getHeader("User-Agent");
				if (userAgent != null && userAgent.indexOf("MSIE 5.5") > -1) {
					response.setHeader("Content-Disposition", "filename=\"" + URLEncoder.encode(filename, Constants.ENCODING) + "\"");
				} else if (userAgent != null && userAgent.indexOf("MSIE") > -1) {
					response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(filename, Constants.ENCODING) + "\"");
				} else {
					response.setHeader("Content-Disposition", "attachment; filename=\""
							+ new String(filename.getBytes(Constants.ENCODING), "latin1") + "\"");
				}
			} catch (UnsupportedEncodingException e) {
				response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
			}

			long len = reader.getObjectSize(id, org.eclipse.jgit.lib.Constants.OBJ_BLOB);
			setContentType(response, "application/octet-stream");
			response.setIntHeader("Content-Length", (int) len);
			ObjectLoader ldr = repository.open(id);
			ldr.copyTo(response.getOutputStream());
			served = true;
		}
	} finally {
		tw.close();
		rw.dispose();
	}

	response.flushBuffer();
	return served;
}
 
開發者ID:tomaswolf,項目名稱:gerrit-gitblit-plugin,代碼行數:52,代碼來源:RawServlet.java


注:本文中的org.eclipse.jgit.treewalk.TreeWalk.setFilter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。