本文整理匯總了Java中org.eclipse.jgit.treewalk.TreeWalk.forPath方法的典型用法代碼示例。如果您正苦於以下問題:Java TreeWalk.forPath方法的具體用法?Java TreeWalk.forPath怎麽用?Java TreeWalk.forPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jgit.treewalk.TreeWalk
的用法示例。
在下文中一共展示了TreeWalk.forPath方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPathModel
import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
/**
* Returns a path model by path string
*
* @param repo
* @param path
* @param filter
* @param commit
* @return a path model of the specified object
*/
private static PathModel getPathModel(Repository repo, String path, String filter, RevCommit commit) throws IOException {
long size = 0;
try (TreeWalk tw = TreeWalk.forPath(repo, path, commit.getTree())) {
String pathString = path;
if (!tw.isSubtree() && (tw.getFileMode(0) != FileMode.GITLINK)) {
size = tw.getObjectReader().getObjectSize(tw.getObjectId(0), Constants.OBJ_BLOB);
pathString = PathUtils.getLastPathComponent(pathString);
} else if (tw.isSubtree()) {
// do not display dirs that are behind in the path
if (!Strings.isNullOrEmpty(filter)) {
pathString = path.replaceFirst(filter + "/", "");
}
// remove the last slash from path in displayed link
if (pathString != null && pathString.charAt(pathString.length() - 1) == '/') {
pathString = pathString.substring(0, pathString.length() - 1);
}
}
return new PathModel(pathString, tw.getPathString(), size, tw.getFileMode(0).getBits(), tw.getObjectId(0).getName(), commit.getName());
}
}
示例2: 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);
}
}
}
示例3: 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();
}
}
示例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: load
import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
private Text load(ObjectId tree, String path)
throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException,
IOException {
if (path == null) {
return Text.EMPTY;
}
final TreeWalk tw = TreeWalk.forPath(repo, path, tree);
if (tw == null) {
return Text.EMPTY;
}
if (tw.getFileMode(0).getObjectType() == Constants.OBJ_BLOB) {
return new Text(repo.open(tw.getObjectId(0), Constants.OBJ_BLOB));
} else if (tw.getFileMode(0).getObjectType() == Constants.OBJ_COMMIT) {
String str = "Subproject commit " + ObjectId.toString(tw.getObjectId(0));
return new Text(str.getBytes(UTF_8));
} else {
return Text.EMPTY;
}
}
示例6: getPathEdits
import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
@Override
public List<DirCacheEditor.PathEdit> getPathEdits(Repository repository, RevCommit baseCommit)
throws IOException {
try (RevWalk revWalk = new RevWalk(repository)) {
revWalk.parseHeaders(baseCommit);
try (TreeWalk treeWalk =
TreeWalk.forPath(revWalk.getObjectReader(), currentFilePath, baseCommit.getTree())) {
if (treeWalk == null) {
return Collections.emptyList();
}
DirCacheEditor.DeletePath deletePathEdit = new DirCacheEditor.DeletePath(currentFilePath);
AddPath addPathEdit =
new AddPath(newFilePath, treeWalk.getFileMode(0), treeWalk.getObjectId(0));
return Arrays.asList(deletePathEdit, addPathEdit);
}
}
}
示例7: getAccountConfig
import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
private Config getAccountConfig(TestRepository<?> allUsersRepo) throws Exception {
Config ac = new Config();
try (TreeWalk tw =
TreeWalk.forPath(
allUsersRepo.getRepository(),
AccountConfig.ACCOUNT_CONFIG,
getHead(allUsersRepo.getRepository()).getTree())) {
assertThat(tw).isNotNull();
ac.fromText(
new String(
allUsersRepo
.getRevWalk()
.getObjectReader()
.open(tw.getObjectId(0), OBJ_BLOB)
.getBytes(),
UTF_8));
}
return ac;
}
示例8: getBlob
import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
/**
* Read blob content and cache result in repository in case the same blob
* content is requested again.
*
* We made this method thread-safe as we are using ForkJoinPool to calculate
* diffs of multiple blob changes concurrently, and this method will be
* accessed concurrently in that special case.
*
* @param blobIdent
* ident of the blob
* @return
* blob of specified blob ident
* @throws
* ObjectNotFoundException if blob of specified ident can not be found in repository
*
*/
public Blob getBlob(BlobIdent blobIdent) {
Preconditions.checkArgument(blobIdent.revision!=null && blobIdent.path!=null && blobIdent.mode!=null,
"Revision, path and mode of ident param should be specified");
Blob blob = getBlobCache().get(blobIdent);
if (blob == null) {
try (RevWalk revWalk = new RevWalk(getRepository())) {
ObjectId revId = getObjectId(blobIdent.revision);
RevTree revTree = revWalk.parseCommit(revId).getTree();
TreeWalk treeWalk = TreeWalk.forPath(getRepository(), blobIdent.path, revTree);
if (treeWalk != null) {
ObjectId blobId = treeWalk.getObjectId(0);
if (blobIdent.isGitLink()) {
String url = getSubmodules(blobIdent.revision).get(blobIdent.path);
if (url == null)
throw new ObjectNotFoundException("Unable to find submodule '" + blobIdent.path + "' in .gitmodules");
String hash = blobId.name();
blob = new Blob(blobIdent, blobId, new Submodule(url, hash).toString().getBytes());
} else if (blobIdent.isTree()) {
throw new NotFileException("Path '" + blobIdent.path + "' is a tree");
} else {
blob = new Blob(blobIdent, blobId, treeWalk.getObjectReader());
}
getBlobCache().put(blobIdent, blob);
} else {
throw new ObjectNotFoundException("Unable to find blob path '" + blobIdent.path + "' in revision '" + blobIdent.revision + "'");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return blob;
}
示例9: getInputStream
import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public InputStream getInputStream(BlobIdent ident) {
try (RevWalk revWalk = new RevWalk(getRepository())) {
ObjectId commitId = getObjectId(ident.revision);
RevTree revTree = revWalk.parseCommit(commitId).getTree();
TreeWalk treeWalk = TreeWalk.forPath(getRepository(), ident.path, revTree);
if (treeWalk != null) {
ObjectLoader objectLoader = treeWalk.getObjectReader().open(treeWalk.getObjectId(0));
return objectLoader.openStream();
} else {
throw new ObjectNotFoundException("Unable to find blob path '" + ident.path + "' in revision '" + ident.revision + "'");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例10: getRemoteContentStream
import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public ObjectStream getRemoteContentStream(String branch, String path) throws Exception {
ObjectId id = localRepo.resolve("refs/remotes/origin/" + branch);
try (ObjectReader reader = localRepo.newObjectReader();
RevWalk walk = new RevWalk(reader)) {
RevCommit commit = walk.parseCommit(id);
RevTree tree = commit.getTree();
TreeWalk treewalk = TreeWalk.forPath(reader, path, tree);
if (treewalk != null) {
return reader.open(treewalk.getObjectId(0)).openStream();
}
else {
return null;
}
}
}
示例11: getFileStreamForPath
import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
@Override
public InputStream getFileStreamForPath(SVNDeltaCombiner combiner, String path) throws SVNException {
Repository repository = ((GitFS)getOwner()).getGitRepository();
try {
path = DAVPathUtil.dropLeadingSlash(path);
RevCommit commit = SVNGitUtil.getCommitFromRevision(repository, getRevision());
TreeWalk treeWalk = TreeWalk.forPath(repository, path, commit.getTree());
SVNDebugLog.getDefaultLog().logFine(SVNLogType.DEFAULT, "stream path: " + path);
return repository.open(treeWalk.getObjectId(0)).openStream();
} catch (IOException e) {
throw new SVNException(SVNErrorMessage.create(SVNErrorCode.FS_GENERAL, "Failed to stream a file"), e);
}
}
示例12: getRepositoryContent
import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
private byte[] getRepositoryContent(Repository repository, RevCommit revCommit, String fileName) throws IOException {
TreeWalk treewalk = TreeWalk.forPath(repository, fileName, revCommit.getTree());
if(treewalk != null) {
return repository.open(treewalk.getObjectId(0)).getBytes();
} else {
return null;
}
}
示例13: load
import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
private Text load(ObjectId tree, String path, ObjectReader reader)
throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException,
IOException {
if (path == null) {
return Text.EMPTY;
}
final TreeWalk tw = TreeWalk.forPath(reader, path, tree);
if (tw == null) {
return Text.EMPTY;
}
if (tw.getFileMode(0).getObjectType() != Constants.OBJ_BLOB) {
return Text.EMPTY;
}
return new Text(reader.open(tw.getObjectId(0), Constants.OBJ_BLOB));
}
示例14: create
import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public static FileResource create(
GitRepositoryManager repoManager, ProjectState projectState, ObjectId rev, String path)
throws ResourceNotFoundException, IOException {
try (Repository repo = repoManager.openRepository(projectState.getNameKey());
RevWalk rw = new RevWalk(repo)) {
RevTree tree = rw.parseTree(rev);
if (TreeWalk.forPath(repo, path, tree) != null) {
return new FileResource(projectState, rev, path);
}
}
throw new ResourceNotFoundException(IdString.fromDecoded(path));
}
示例15: find
import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
private TreeWalk find(ObjectId within)
throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException,
IOException {
if (path == null || within == null) {
return null;
}
try (RevWalk rw = new RevWalk(reader)) {
final RevTree tree = rw.parseTree(within);
return TreeWalk.forPath(reader, path, tree);
}
}