本文整理汇总了Java中org.eclipse.jgit.treewalk.TreeWalk.getPathString方法的典型用法代码示例。如果您正苦于以下问题:Java TreeWalk.getPathString方法的具体用法?Java TreeWalk.getPathString怎么用?Java TreeWalk.getPathString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.treewalk.TreeWalk
的用法示例。
在下文中一共展示了TreeWalk.getPathString方法的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: 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;
}
}
示例4: 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();
}
}
示例5: getChange
import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
private BlobChange getChange(TreeWalk treeWalk, RevCommit oldCommit, RevCommit newCommit) {
DiffEntry.ChangeType changeType = DiffEntry.ChangeType.MODIFY;
BlobIdent oldBlobIdent;
if (!treeWalk.getObjectId(0).equals(ObjectId.zeroId())) {
oldBlobIdent = new BlobIdent(oldCommit.name(), treeWalk.getPathString(), treeWalk.getRawMode(0));
} else {
oldBlobIdent = new BlobIdent(oldCommit.name(), null, FileMode.TREE.getBits());
changeType = DiffEntry.ChangeType.ADD;
}
BlobIdent newBlobIdent;
if (!treeWalk.getObjectId(1).equals(ObjectId.zeroId())) {
newBlobIdent = new BlobIdent(newCommit.name(), treeWalk.getPathString(), treeWalk.getRawMode(1));
} else {
newBlobIdent = new BlobIdent(newCommit.name(), null, FileMode.TREE.getBits());
changeType = DiffEntry.ChangeType.DELETE;
}
return new BlobChange(changeType, oldBlobIdent, newBlobIdent, WhitespaceOption.DEFAULT) {
@Override
public Blob getBlob(BlobIdent blobIdent) {
return context.getProject().getBlob(blobIdent);
}
};
}
示例6: collect
import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
@Override
public void collect(IndexSearcher searcher, TreeWalk treeWalk, List<QueryHit> hits) {
String blobPath = treeWalk.getPathString();
Range range = PathUtils.matchSegments(blobPath, match, true);
if (range != null) {
hits.add(new PathHit(blobPath, range));
}
}
示例7: 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;
}
示例8: zip
import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
/**
* Zips the contents of the tree at the (optionally) specified revision and the (optionally) specified basepath to the supplied outputstream.
*
* @param repository
* @param basePath
* if unspecified, entire repository is assumed.
* @param objectId
* if unspecified, HEAD is assumed.
* @param os
* @return true if repository was successfully zipped to supplied output stream
*/
public static boolean zip(Repository repository, String basePath, String objectId, OutputStream os) {
RevCommit commit = JGitUtils.getCommit(repository, objectId);
if (commit == null) {
return false;
}
boolean success = false;
RevWalk rw = new RevWalk(repository);
TreeWalk tw = new TreeWalk(repository);
try {
tw.reset();
tw.addTree(commit.getTree());
ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);
zos.setComment("Generated by Gitblit");
if (!StringUtils.isEmpty(basePath)) {
PathFilter f = PathFilter.create(basePath);
tw.setFilter(f);
}
tw.setRecursive(true);
MutableObjectId id = new MutableObjectId();
ObjectReader reader = tw.getObjectReader();
long modified = commit.getAuthorIdent().getWhen().getTime();
while (tw.next()) {
FileMode mode = tw.getFileMode(0);
if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
continue;
}
tw.getObjectId(id, 0);
ZipArchiveEntry entry = new ZipArchiveEntry(tw.getPathString());
entry.setSize(reader.getObjectSize(id, Constants.OBJ_BLOB));
entry.setComment(commit.getName());
entry.setUnixMode(mode.getBits());
entry.setTime(modified);
zos.putArchiveEntry(entry);
ObjectLoader ldr = repository.open(id);
ldr.copyTo(zos);
zos.closeArchiveEntry();
}
zos.finish();
success = true;
} catch (IOException e) {
error(e, repository, "{0} failed to zip files from commit {1}", commit.getName());
} finally {
tw.close();
rw.close();
rw.dispose();
}
return success;
}
示例9: getFilesInVersion
import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
/**
* Returns a list containing the paths to all files in the specified
* version.
*
* @param c version identifier (commit)
* @return a list containing the paths to all files in the specified version
* @throws IllegalStateException if this file is currently not open
*/
private Collection<String> getFilesInVersion(RevCommit c) {
Collection<String> result = new ArrayList<String>();
// file has to be opened
if (!isOpened()) {
throw new IllegalStateException(
"File\"" + getFile().getPath() + "\" not opened!");
}
Git git = null;
try {
git = Git.open(tmpFolder);
// create a tree walk to search for files
TreeWalk walk = new TreeWalk(git.getRepository());
if (walk != null) {
// recursively search fo files
walk.setRecursive(true);
// add the tree the specified commit belongs to
walk.addTree(c.getTree());
// walk through the tree
while (walk.next()) {
// TODO: is it a problem if mode is treemode?
final FileMode mode = walk.getFileMode(0);
if (mode == FileMode.TREE) {
System.out.print(
"VersionedFile."
+ "getFilesInVersion(): FileMode unexpected!");
}
// retrieve the path name of the current element
String fileName = walk.getPathString();
// we do not want to commit/checkout this file
if (!fileName.equals(FILE_INFO_NAME)) {
result.add(walk.getPathString());
}
}
}
} catch (IOException ex) {
closeGit(git);
Logger.getLogger(VersionedFile.class.getName()).
log(Level.SEVERE, null, ex);
}
closeGit(git);
return result;
}
示例10: zip
import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
/**
* Zips the contents of the tree at the (optionally) specified revision and
* the (optionally) specified basepath to the supplied outputstream.
*
* @param repository
* @param basePath
* if unspecified, entire repository is assumed.
* @param objectId
* if unspecified, HEAD is assumed.
* @param os
* @return true if repository was successfully zipped to supplied output
* stream
*/
public static boolean zip(Repository repository, String basePath, String objectId,
OutputStream os) {
RevCommit commit = JGitUtils.getCommit(repository, objectId);
if (commit == null) {
return false;
}
boolean success = false;
RevWalk rw = new RevWalk(repository);
TreeWalk tw = new TreeWalk(repository);
try {
tw.reset();
tw.addTree(commit.getTree());
ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);
zos.setComment("Generated by Gitblit");
if (!StringUtils.isEmpty(basePath)) {
PathFilter f = PathFilter.create(basePath);
tw.setFilter(f);
}
tw.setRecursive(true);
MutableObjectId id = new MutableObjectId();
ObjectReader reader = tw.getObjectReader();
long modified = commit.getAuthorIdent().getWhen().getTime();
while (tw.next()) {
FileMode mode = tw.getFileMode(0);
if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
continue;
}
tw.getObjectId(id, 0);
ZipArchiveEntry entry = new ZipArchiveEntry(tw.getPathString());
entry.setSize(reader.getObjectSize(id, Constants.OBJ_BLOB));
entry.setComment(commit.getName());
entry.setUnixMode(mode.getBits());
entry.setTime(modified);
zos.putArchiveEntry(entry);
ObjectLoader ldr = repository.open(id);
ldr.copyTo(zos);
zos.closeArchiveEntry();
}
zos.finish();
success = true;
} catch (IOException e) {
error(e, repository, "{0} failed to zip files from commit {1}", commit.getName());
} finally {
tw.release();
rw.dispose();
}
return success;
}
示例11: toIndexFile
import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
private IndexFile toIndexFile(Context context, TreeWalk treeWalk, RevCommit revCommit, ObjectId objectId) throws IOException {
File file = new File(treeWalk.getPathString());
String id = String.format("%s|%s|%s|%s", FILE.name().toLowerCase(), context.getName(), revCommit.name(), file.getPath());
logger.debug("Indexing file with id {}", id);
return IndexFile.indexFile()
.id(id)
.commit(revCommit.name())
.project(context.getName())
.path(file.getPath())
.name(file.getName())
.extension(Files.getFileExtension(file.getAbsolutePath()))
.content(safeContent(context, objectId))
.build();
}
示例12: getRepoMetadata
import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
/**
* Fetch all commit metadata from the repo
* @param repoDir repository directory
* @return list of commit metadata
* @throws IOException
* @throws GitAPIException
*/
public static List<CommitMetadata> getRepoMetadata(String repoDir) throws IOException, GitAPIException {
List<CommitMetadata> metadataList = new ArrayList<>();
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File(repoDir, ".git")).readEnvironment().findGitDir().build();
// Current branch may not be master. Instead of hard coding determine the current branch
String currentBranch = repository.getBranch();
Ref head = repository.getRef("refs/heads/" + currentBranch); // current branch may not be "master"
if (head == null) {
return metadataList;
}
Git git = new Git(repository);
RevWalk walk = new RevWalk(repository);
RevCommit commit = walk.parseCommit(head.getObjectId());
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(commit.getTree());
treeWalk.setRecursive(true);
while (treeWalk.next()) {
String filePath = treeWalk.getPathString();
Iterable<RevCommit> commitLog = git.log().add(repository.resolve(Constants.HEAD)).addPath(filePath).call();
for (RevCommit r : commitLog) {
CommitMetadata metadata = new CommitMetadata(r.getName());
metadata.setFilePath(filePath);
metadata.setFileName(FilenameUtils.getName(filePath));
metadata.setMessage(r.getShortMessage().trim());
// Difference between committer and author
// refer to: http://git-scm.com/book/ch2-3.html
PersonIdent committer = r.getCommitterIdent();
PersonIdent author = r.getAuthorIdent();
metadata.setAuthor(author.getName());
metadata.setAuthorEmail(author.getEmailAddress());
metadata.setCommitter(committer.getName());
metadata.setCommitterEmail(committer.getEmailAddress());
metadata.setCommitTime(committer.getWhen());
metadataList.add(metadata);
}
}
git.close();
return metadataList;
}
示例13: testAddMixedLineEndings
import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
public void testAddMixedLineEndings () throws Exception {
File f = new File(workDir, "f");
String content = "";
for (int i = 0; i < 10000; ++i) {
content += i + "\r\n";
}
write(f, content);
File[] files = new File[] { f };
GitClient client = getClient(workDir);
client.add(files, NULL_PROGRESS_MONITOR);
client.commit(files, "commit", null, null, NULL_PROGRESS_MONITOR);
Map<File, GitStatus> statuses = client.getStatus(files, NULL_PROGRESS_MONITOR);
assertEquals(1, statuses.size());
assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false);
// lets turn autocrlf on
StoredConfig cfg = repository.getConfig();
cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "true");
cfg.save();
// when this starts failing, remove the work around
ObjectInserter inserter = repository.newObjectInserter();
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.setFilter(PathFilterGroup.createFromStrings("f"));
treeWalk.setRecursive(true);
treeWalk.reset();
treeWalk.addTree(new FileTreeIterator(repository));
while (treeWalk.next()) {
String path = treeWalk.getPathString();
assertEquals("f", path);
WorkingTreeIterator fit = treeWalk.getTree(0, WorkingTreeIterator.class);
InputStream in = fit.openEntryStream();
try {
inserter.insert(Constants.OBJ_BLOB, fit.getEntryLength(), in);
fail("this should fail, remove the work around");
} catch (EOFException ex) {
assertEquals("Input did not match supplied length. 10000 bytes are missing.", ex.getMessage());
} finally {
in.close();
inserter.release();
}
break;
}
// no err should occur
write(f, content + "hello");
statuses = client.getStatus(files, NULL_PROGRESS_MONITOR);
assertEquals(1, statuses.size());
assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false);
client.add(files, NULL_PROGRESS_MONITOR);
statuses = client.getStatus(files, NULL_PROGRESS_MONITOR);
assertEquals(1, statuses.size());
assertStatus(statuses, workDir, f, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false);
client.commit(files, "message", null, null, NULL_PROGRESS_MONITOR);
statuses = client.getStatus(files, NULL_PROGRESS_MONITOR);
assertEquals(1, statuses.size());
assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false);
}
示例14: collect
import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
@Override
public void collect(IndexSearcher searcher, TreeWalk treeWalk, List<QueryHit> hits) {
String blobPath = treeWalk.getPathString();
ObjectId blobId = treeWalk.getObjectId(0);
List<Symbol> symbols = GitPlex.getInstance(SearchManager.class).getSymbols(searcher, blobId, blobPath);
if (symbols != null) {
for (Symbol symbol: symbols) {
if (hits.size() < getCount()) {
if ((primary==null || primary.booleanValue() == symbol.isPrimary())
&& symbol.getName() != null
&& symbol.isSearchable()
&& (local == null || local.booleanValue() == symbol.isLocalInHierarchy())) {
String normalizedTerm;
if (!caseSensitive)
normalizedTerm = term.toLowerCase();
else
normalizedTerm = term;
String normalizedSymbolName;
if (!caseSensitive)
normalizedSymbolName = symbol.getName().toLowerCase();
else
normalizedSymbolName = symbol.getName();
String normalizedExcludeTerm;
if (excludeTerm != null) {
if (!caseSensitive)
normalizedExcludeTerm = excludeTerm.toLowerCase();
else
normalizedExcludeTerm = excludeTerm;
} else {
normalizedExcludeTerm = null;
}
if (WildcardUtils.matchString(normalizedTerm, normalizedSymbolName)
&& (normalizedExcludeTerm == null || !normalizedSymbolName.equals(normalizedExcludeTerm))
&& (excludeBlobPath == null || !excludeBlobPath.equals(blobPath))) {
Range matchRange = WildcardUtils.rangeOfMatch(normalizedTerm, normalizedSymbolName);
hits.add(new SymbolHit(blobPath, symbol, matchRange));
}
}
} else {
break;
}
}
}
}
示例15: PathInfo
import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
protected PathInfo(TreeWalk tw) {
fileMode = tw.getFileMode(0);
path = tw.getPathString();
objectId = tw.getObjectId(0);
}