本文整理匯總了Java中org.eclipse.jgit.treewalk.TreeWalk.isSubtree方法的典型用法代碼示例。如果您正苦於以下問題:Java TreeWalk.isSubtree方法的具體用法?Java TreeWalk.isSubtree怎麽用?Java TreeWalk.isSubtree使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jgit.treewalk.TreeWalk
的用法示例。
在下文中一共展示了TreeWalk.isSubtree方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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());
}
示例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());
}
示例3: 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;
}
示例4: getFileSHA1Checksum
import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
@Override
public String getFileSHA1Checksum() throws SVNException {
String path = getCreatedPath();
long revision = getTextRepresentation().getRevision();
Repository gitRepository = myGitFS.getGitRepository();
try {
RevTree tree = new RevWalk(gitRepository).parseTree(gitRepository.resolve("refs/svn/" + revision));
TreeWalk treeWalk = TreeWalk.forPath(gitRepository, path, tree);
if (treeWalk.isSubtree()) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.FS_NOT_FILE, "Attempted to get checksum of a *non*-file node");
SVNErrorManager.error(err, SVNLogType.FSFS);
}
return treeWalk.getObjectId(0).getName();
} catch (IOException e) {
SVNDebugLog.getDefaultLog().logError(SVNLogType.DEFAULT, e.getMessage());
return "";
}
}
示例5: getFileAsDiffFormat
import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public List<DiffInfo> getFileAsDiffFormat(RepositoryPK repositoryPK, String ref) {
try (RepositoryReader reader = new RepositoryReader(repositoryPK)) {
Git git = reader.getGit();
Repository repository = reader.getRepository();
ObjectId objectId = repository.resolve(ref);
List<RevCommit> commits = getFirstCommits(git, objectId, null, 2);
TreeWalk treeWalk = new TreeWalk(repository);
List<DiffInfo> diffInfos = new ArrayList<>();
treeWalk.addTree(commits.get(0).getTree());
treeWalk.setRecursive(true);
while (treeWalk.next()) {
ObjectId fileId = treeWalk.getObjectId(0);
if (!treeWalk.isSubtree()) {
FileContent fileContent = getFileContent(git, treeWalk.getPathString(), fileId);
diffInfos.add(DiffInfo.ofNewCommit(fileContent));
}
}
return diffInfos;
} catch (IOException | GitAPIException e) {
throw new RuntimeException(e);
}
}
示例6: 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;
}
};
}
示例7: include
import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
@Override
public boolean include(TreeWalk walker) {
if (walker.isSubtree()) {
return true;
}
return matches(walker);
}
示例8: 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();
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: findMatchingIdentity
import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
/**
* Find the tree that contains the required identity.
*
* @return The ObjectId of the tree (directory) that contains the matching
* identity within the supplied hierarchy.
*/
private ObjectId findMatchingIdentity(
IdentityValidator identityValidator,
ObjectId tree) throws IOException {
TreeWalk treeWalk = new TreeWalk(repo.getRepository());
try {
treeWalk.setRecursive(false);
treeWalk.addTree(tree);
while (treeWalk.next()) {
if (treeWalk.isSubtree()) {
ObjectId candidateId = findMatchingIdentity(
identityValidator, treeWalk.getObjectId(0));
if (ObjectId.zeroId().equals(candidateId)) {
// Keep searching
} else {
return candidateId;
}
} else if (identityValidator.getIdentityFilename().equals(treeWalk.getNameString())) {
// Read the identity file
ObjectLoader loader = repo.getRepository().open(
treeWalk.getObjectId(0));
ObjectStream stream = loader.openStream();
InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8);
if (identityValidator.isIdentityMatched(new BufferedReader(reader))) {
// We found it
return tree;
}
}
}
return ObjectId.zeroId();
} finally {
treeWalk.release();
}
}
示例14: 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;
}
示例15: 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();
}
}