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


Java TreeWalk.enterSubtree方法代碼示例

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


在下文中一共展示了TreeWalk.enterSubtree方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: newMerger

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
@Override
public ThreeWayMerger newMerger (Repository db, boolean inCore) {
    return new RecursiveMerger(db, inCore) {
        protected boolean mergeTreeWalk (TreeWalk treeWalk, boolean ignoreConflicts)
                throws IOException {
            boolean ok = true;
            boolean hasWorkingTreeIterator = tw.getTreeCount() > T_FILE;
            while (treeWalk.next()) {
                if (!processEntry(
                        treeWalk.getTree(T_BASE, CanonicalTreeParser.class),
                        treeWalk.getTree(T_OURS, CanonicalTreeParser.class),
                        treeWalk.getTree(T_THEIRS, CanonicalTreeParser.class),
                        treeWalk.getTree(T_INDEX, DirCacheBuildIterator.class),
                        hasWorkingTreeIterator ? treeWalk.getTree(T_FILE,
                                        WorkingTreeIterator.class) : null, ignoreConflicts)) {
                    ok = false;
                }
                if (treeWalk.isSubtree() && enterSubtree) {
                    treeWalk.enterSubtree();
                }
            }
            if (!ok) {
                cleanUp();
            }
            return ok;
        }
    };
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:29,代碼來源:CherryPickCommand.java

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

示例4: listRepositoryContents

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
private List<String> listRepositoryContents() throws IOException, NLBVCSException {
    List<String> result = new ArrayList<>();
    Ref head = m_localRepo.getRef(Constants.HEAD);
    // head can be null if repo is broken (for example, .git directory was deleted)
    if (head == null) {
        throw new NLBVCSException("Your Git repository is broken.\nPlease either properly clone it (using 'git clone' command) or use 'runlight' command to run the program.");
    }

    // head.getObjectId() can be null, for example, if repository was never committed.
    final ObjectId objectId = head.getObjectId();
    if (objectId != null) {
        // a RevWalk allows to walk over commits based on some filtering that is defined
        RevWalk walk = new RevWalk(m_localRepo);

        RevCommit commit = walk.parseCommit(objectId);
        RevTree tree = commit.getTree();

        // now use a TreeWalk to iterate over all files in the Tree recursively
        // you can set Filters to narrow down the results if needed
        TreeWalk treeWalk = new TreeWalk(m_localRepo);
        treeWalk.addTree(tree);
        treeWalk.setRecursive(false);
        while (treeWalk.next()) {
            if (treeWalk.isSubtree()) {
                //System.out.println("dir: " + treeWalk.getPathString());
                treeWalk.enterSubtree();
            } else {
                //System.out.println("file: " + treeWalk.getPathString());
                result.add(treeWalk.getPathString());
            }
        }
    }

    return result;
}
 
開發者ID:Antokolos,項目名稱:NLB,代碼行數:36,代碼來源:GitAdapter.java

示例5: getAllMetadata

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
/**
 * Replicates ls-tree for the current commit.
 *
 * @return Map containing the full path and the data for all items in the repository.
 * @throws IOException
 */
public Map<String, byte[]> getAllMetadata() throws Exception
{
    Map<String, byte[]> contents = new HashMap<String, byte[]>();
    ObjectReader reader = repository.newObjectReader();
    ObjectId commitId = repository.resolve(curCommit);
    RevWalk revWalk = new RevWalk(reader);
    RevCommit commit = revWalk.parseCommit(commitId);
    RevTree tree = commit.getTree();
    TreeWalk treeWalk = new TreeWalk(reader);
    treeWalk.addTree(tree);
    treeWalk.setRecursive(false);

    while (treeWalk.next())
    {
        if (treeWalk.isSubtree())
        {
            treeWalk.enterSubtree();
        }
        else
        {
            String member = treeWalk.getPathString();
            if (member.contains(SOURCEDIR))
            {
                byte[] data = getBlob(member, curCommit);
                contents.put(member, data);
            }
        }
    }

    reader.release();

    return contents;
}
 
開發者ID:aesanch2,項目名稱:salesforce-migration-assistant,代碼行數:40,代碼來源:SMAGit.java

示例6: walkToPath

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
private List<Boolean> walkToPath(TreeWalk tw, String pathString) throws IOException {
  AutoDiveFilter f = new AutoDiveFilter(pathString);
  tw.setFilter(f);
  while (tw.next()) {
    if (f.isDone(tw)) {
      return f.hasSingleTree;
    } else if (tw.isSubtree()) {
      tw.enterSubtree();
    }
  }
  return null;
}
 
開發者ID:afrojer,項目名稱:gitiles,代碼行數:13,代碼來源:PathServlet.java

示例7: getByteContent

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

示例8: getFilesInPath

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
/**
 * Returns the list of files in the specified folder at the specified
 * commit. If the repository does not exist or is empty, an empty list is
 * returned.
 * 
 * @param repository
 * @param path
 *            if unspecified, root folder is assumed.
 * @param commit
 *            if null, HEAD is assumed.
 * @return list of files in specified path
 */
public static List<PathModel> getFilesInPath(Repository repository, String path,
		RevCommit commit) {
	List<PathModel> list = new ArrayList<PathModel>();
	if (!hasCommits(repository)) {
		return list;
	}
	if (commit == null) {
		commit = getCommit(repository, null);
	}
	final TreeWalk tw = new TreeWalk(repository);
	try {
		tw.addTree(commit.getTree());
		if (!StringUtils.isEmpty(path)) {
			PathFilter f = PathFilter.create(path);
			tw.setFilter(f);
			tw.setRecursive(false);
			boolean foundFolder = false;
			while (tw.next()) {
				if (!foundFolder && tw.isSubtree()) {
					tw.enterSubtree();
				}
				if (tw.getPathString().equals(path)) {
					foundFolder = true;
					continue;
				}
				if (foundFolder) {
					list.add(getPathModel(tw, path, commit));
				}
			}
		} else {
			tw.setRecursive(false);
			while (tw.next()) {
				list.add(getPathModel(tw, null, commit));
			}
		}
	} catch (IOException e) {
		error(e, repository, "{0} failed to get files for commit {1}", commit.getName());
	} finally {
		tw.release();
	}
	Collections.sort(list);
	return list;
}
 
開發者ID:warpfork,項目名稱:gitblit,代碼行數:56,代碼來源:JGitUtils.java

示例9: cloneCommit

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
private void cloneCommit() throws Exception {
	ObjectReader objectReader = m_headRepository.newObjectReader();
	try {
		File mineDir = new File(m_target, this.m_name);
		
		if (!mineDir.exists()) {
			mineDir.mkdir();
			mineDir.setWritable(true);
			mineDir.setExecutable(true);
		}
		
		TreeWalk treeWalk = new TreeWalk(objectReader);
		treeWalk.addTree(m_current.getTree());
		
		while (treeWalk.next()) {
			String path = treeWalk.getPathString();
			File file = new File(mineDir, path);
			if (treeWalk.isSubtree()) {
				file.mkdir();
				treeWalk.enterSubtree();
			} else {
				FileOutputStream outputStream = new FileOutputStream(file);
				ObjectId objectId = treeWalk.getObjectId(0);
				ObjectLoader objectLoader = objectReader.open(objectId);
				try {
					objectLoader.copyTo(outputStream);
				} finally {
					outputStream.close();
				}

				if (FileMode.EXECUTABLE_FILE.equals(treeWalk.getRawMode(0))) {
					file.setExecutable(true);
				}
			}
		}
		
		GlobalMessages.commitPulled(this.m_i, this.m_current.getName());
		
		m_runningThreads--;
		
	} catch (Exception e) {
		errorHandlingMining(e, this.m_current);
	} finally {
		// Release resources
		objectReader.release();
	}
}
 
開發者ID:gingerswede,項目名稱:doris,代碼行數:48,代碼來源:GitRepository.java


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