本文整理匯總了Java中org.eclipse.jgit.treewalk.CanonicalTreeParser類的典型用法代碼示例。如果您正苦於以下問題:Java CanonicalTreeParser類的具體用法?Java CanonicalTreeParser怎麽用?Java CanonicalTreeParser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CanonicalTreeParser類屬於org.eclipse.jgit.treewalk包,在下文中一共展示了CanonicalTreeParser類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPaths
import org.eclipse.jgit.treewalk.CanonicalTreeParser; //導入依賴的package包/類
private List<DiffEntry> getPaths(Repository repository, RevCommit rev)
throws MissingObjectException, IncorrectObjectTypeException,
IOException {
RevCommit parent = null;
List<DiffEntry> diffs = null;
RevWalk rw = new RevWalk(repository);
DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
df.setRepository(repository);
df.setDiffComparator(RawTextComparator.DEFAULT);
df.setDetectRenames(true);
if (rev.getParentCount() > 0 && rev.getParent(0) != null) {
parent = rw.parseCommit(rev.getParent(0).getId());
diffs = df.scan(parent.getTree(), rev.getTree());
} else {
diffs = df.scan(new EmptyTreeIterator(), new CanonicalTreeParser(
null, rw.getObjectReader(), rev.getTree()));
}
return diffs;
}
示例2: getIterator
import org.eclipse.jgit.treewalk.CanonicalTreeParser; //導入依賴的package包/類
private AbstractTreeIterator getIterator (String commit, ObjectReader or) throws IOException, GitException {
Repository repository = getRepository();
switch (commit) {
case Constants.HEAD:
return getHeadIterator(or);
case GitClient.INDEX:
return new DirCacheIterator(repository.readDirCache());
case GitClient.WORKING_TREE:
return new FileTreeIterator(repository);
default:
CanonicalTreeParser p = new CanonicalTreeParser();
p.reset(or, Utils.findCommit(repository, commit).getTree());
return p;
}
}
示例3: blockingPreviewDiff
import org.eclipse.jgit.treewalk.CanonicalTreeParser; //導入依賴的package包/類
private Map<String, Change<?>> blockingPreviewDiff(Revision baseRevision, Iterable<Change<?>> changes) {
requireNonNull(baseRevision, "baseRevision");
requireNonNull(changes, "changes");
baseRevision = blockingNormalize(baseRevision);
try (ObjectReader reader = jGitRepository.newObjectReader();
RevWalk revWalk = new RevWalk(reader);
DiffFormatter diffFormatter = new DiffFormatter(NullOutputStream.INSTANCE)) {
final ObjectId baseTreeId = toTreeId(revWalk, baseRevision);
final DirCache dirCache = DirCache.newInCore();
final int numEdits = applyChanges(baseRevision, baseTreeId, dirCache, changes);
if (numEdits == 0) {
return Collections.emptyMap();
}
CanonicalTreeParser p = new CanonicalTreeParser();
p.reset(reader, baseTreeId);
diffFormatter.setRepository(jGitRepository);
List<DiffEntry> result = diffFormatter.scan(p, new DirCacheIterator(dirCache));
return toChangeMap(result);
} catch (IOException e) {
throw new StorageException("failed to perform a dry-run diff", e);
}
}
示例4: getTreeIterator
import org.eclipse.jgit.treewalk.CanonicalTreeParser; //導入依賴的package包/類
private AbstractTreeIterator getTreeIterator( String commitId ) throws Exception {
if ( commitId == null ) {
return new EmptyTreeIterator();
}
if ( commitId.equals( WORKINGTREE ) ) {
return new FileTreeIterator( git.getRepository() );
} else if ( commitId.equals( INDEX ) ) {
return new DirCacheIterator( git.getRepository().readDirCache() );
} else {
ObjectId id = git.getRepository().resolve( commitId );
if ( id == null ) { // commitId does not exist
return new EmptyTreeIterator();
} else {
CanonicalTreeParser treeIterator = new CanonicalTreeParser();
try ( RevWalk rw = new RevWalk( git.getRepository() ) ) {
RevTree tree = rw.parseTree( id );
try ( ObjectReader reader = git.getRepository().newObjectReader() ) {
treeIterator.reset( reader, tree.getId() );
}
}
return treeIterator;
}
}
}
示例5: prepareTreeParser
import org.eclipse.jgit.treewalk.CanonicalTreeParser; //導入依賴的package包/類
private AbstractTreeIterator prepareTreeParser(Repository repository, String ref) throws IOException {
if ("~~staged~~".equals(ref)) {
return new DirCacheIterator(DirCache.read(repository));
} else if ("~~unstaged~~".equals(ref)) {
return new FileTreeIterator(repository);
}
try (RevWalk walk = new RevWalk(repository)) {
ObjectId commitObjectId = repository.resolve(ref);
if (commitObjectId == null) {
throw new GitInvalidRefException(format("invalid git ref %s", ref));
}
log.debug("ref: {}, commit id: {}", ref, commitObjectId.toString());
RevCommit commit = walk.parseCommit(commitObjectId);
RevTree tree = walk.parseTree(commit.getTree().getId());
CanonicalTreeParser treeParser = new CanonicalTreeParser();
try (ObjectReader objectReader = repository.newObjectReader()) {
treeParser.reset(objectReader, tree.getId());
}
return treeParser;
}
}
示例6: prepareTreeParser
import org.eclipse.jgit.treewalk.CanonicalTreeParser; //導入依賴的package包/類
private AbstractTreeIterator prepareTreeParser(Repository repository, String objectId) throws IOException {
// from the commit we can build the tree which allows us to construct the TreeParser
//noinspection Duplicates
try (RevWalk walk = new RevWalk(repository)) {
RevCommit commit = walk.parseCommit(ObjectId.fromString(objectId));
RevTree tree = walk.parseTree(commit.getTree().getId());
CanonicalTreeParser oldTreeParser = new CanonicalTreeParser();
try (ObjectReader oldReader = repository.newObjectReader()) {
oldTreeParser.reset(oldReader, tree.getId());
}
walk.dispose();
return oldTreeParser;
}
}
示例7: name
import org.eclipse.jgit.treewalk.CanonicalTreeParser; //導入依賴的package包/類
@Test public void name() throws IOException, GitAPIException {
ObjectId head = repo.resolve("HEAD^{tree}");
ObjectId oldHead = repo.resolve("HEAD^^{tree}");
ObjectReader reader = repo.newObjectReader();
CanonicalTreeParser prevParser = new CanonicalTreeParser();
prevParser.reset(reader, oldHead);
CanonicalTreeParser headParser = new CanonicalTreeParser();
headParser.reset(reader, head);
List<DiffEntry> diffs = new Git(repo).diff()
.setNewTree(headParser)
.setOldTree(prevParser)
.call();
for (DiffEntry entry : diffs)
System.out.println(entry);
}
示例8: processTreeParser
import org.eclipse.jgit.treewalk.CanonicalTreeParser; //導入依賴的package包/類
private void processTreeParser(CanonicalTreeParser treeParser)
throws IOException {
TreeParserTreeEntry treeParserEntry = new TreeParserTreeEntry(
treeParser, objectReader);
List<CanonicalTreeParser> subTrees = new ArrayList<CanonicalTreeParser>();
while (!treeParser.eof()) {
FileMode entryFileMode = treeParser.getEntryFileMode();
if (FileMode.TREE.equals(entryFileMode)) {
CanonicalTreeParser canonicalTreeParser = new CanonicalTreeParser();
canonicalTreeParser.reset(objectReader,
treeParser.getEntryObjectId());
subTrees.add(canonicalTreeParser);
} else {
if (!filterPredicate.evaluate(treeParserEntry)) {
treeEntryWalk.walk(treeParserEntry);
}
}
treeParser.next();
}
for (CanonicalTreeParser subTreeParser : subTrees) {
processTreeParser(subTreeParser);
}
}
示例9: prepareTreeParser
import org.eclipse.jgit.treewalk.CanonicalTreeParser; //導入依賴的package包/類
private AbstractTreeIterator prepareTreeParser(Repository repo, Ref targetRef) throws IOException {
try (RevWalk walk = newRevWalk(repo)) {
walk.markStart(walk.parseCommit(targetRef.getObjectId()));
walk.markStart(walk.parseCommit(repo.exactRef("HEAD").getObjectId()));
walk.setRevFilter(RevFilter.MERGE_BASE);
RevCommit base = walk.parseCommit(walk.next());
CanonicalTreeParser treeParser = new CanonicalTreeParser();
try (ObjectReader objectReader = repo.newObjectReader()) {
treeParser.reset(objectReader, base.getTree());
}
walk.dispose();
return treeParser;
}
}
示例10: emptyToCommit
import org.eclipse.jgit.treewalk.CanonicalTreeParser; //導入依賴的package包/類
/**
* Show changes between specified revision and empty tree.
*
* @param commitId id of commit
* @param formatter diff formatter
* @return list of diff entries
* @throws IOException if any i/o errors occurs
*/
private List<DiffEntry> emptyToCommit(String commitId, DiffFormatter formatter)
throws IOException {
ObjectId commit = repository.resolve(commitId);
checkArgument(commit != null, "Invalid commit id " + commitId);
RevTree tree;
try (RevWalk revWalkA = new RevWalk(repository)) {
tree = revWalkA.parseTree(commit);
}
List<DiffEntry> diff;
try (ObjectReader reader = repository.newObjectReader()) {
CanonicalTreeParser iterator = new CanonicalTreeParser();
iterator.reset(reader, tree);
diff = formatter.scan(new EmptyTreeIterator(), iterator);
}
return diff;
}
示例11: execute
import org.eclipse.jgit.treewalk.CanonicalTreeParser; //導入依賴的package包/類
public List<DiffEntry> execute() {
if (newRef == null || git.getRepository() == null) {
return emptyList();
}
try (final ObjectReader reader = git.getRepository().newObjectReader()) {
CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
if (oldRef != null) {
oldTreeIter.reset(reader,
oldRef);
}
CanonicalTreeParser newTreeIter = new CanonicalTreeParser();
newTreeIter.reset(reader,
newRef);
return new CustomDiffCommand(git).setNewTree(newTreeIter).setOldTree(oldTreeIter).setShowNameAndStatusOnly(true).call();
} catch (final Exception ex) {
throw new RuntimeException(ex);
}
}
示例12: iterateOverTreeWalk
import org.eclipse.jgit.treewalk.CanonicalTreeParser; //導入依賴的package包/類
void iterateOverTreeWalk(final Git git,
final ObjectId headId,
final BiConsumer<String, CanonicalTreeParser> consumer) {
if (headId != null) {
try (final TreeWalk treeWalk = new TreeWalk(git.getRepository())) {
final int hIdx = treeWalk.addTree(new RevWalk(git.getRepository()).parseTree(headId));
treeWalk.setRecursive(true);
while (treeWalk.next()) {
final String walkPath = treeWalk.getPathString();
final CanonicalTreeParser hTree = treeWalk.getTree(hIdx,
CanonicalTreeParser.class);
consumer.accept(walkPath,
hTree);
}
} catch (final Exception ex) {
throw new RuntimeException(ex);
}
}
}
示例13: populateDiff
import org.eclipse.jgit.treewalk.CanonicalTreeParser; //導入依賴的package包/類
/**
* Populate all the files to update, if the system should update.
*/
private void populateDiff() {
try {
git.fetch().call();
Repository repo = git.getRepository();
ObjectId fetchHead = repo.resolve("FETCH_HEAD^{tree}");
ObjectId head = repo.resolve("HEAD^{tree}");
ObjectReader reader = repo.newObjectReader();
CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
oldTreeIter.reset(reader, head);
CanonicalTreeParser newTreeIter = new CanonicalTreeParser();
newTreeIter.reset(reader, fetchHead);
List<DiffEntry> diffs = git.diff().setShowNameAndStatusOnly(true)
.setNewTree(newTreeIter)
.setOldTree(oldTreeIter)
.call();
pluginsToUpdate = new ArrayList<PluginToUpdate>();
checkDiffEmpty(diffs);
} catch (GitAPIException | IOException ex) {
Logger.getLogger(UpdaterGenerator.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例14: createTreeParser
import org.eclipse.jgit.treewalk.CanonicalTreeParser; //導入依賴的package包/類
protected CanonicalTreeParser createTreeParser(String ref) throws IOException, GitAPIException {
assert ref != null && !ref.isEmpty() : "Ref should not be empty or null";
RevCommit commit;
try(RevWalk walk = new RevWalk(repo)) {
commit = walk.parseCommit(repo.resolve(ref));
RevTree commitTree = commit.getTree();
RevTree tree = walk.parseTree(commitTree.getId());
CanonicalTreeParser oldTreeParser = new CanonicalTreeParser();
try(ObjectReader oldReader = repo.newObjectReader()) {
oldTreeParser.reset(oldReader, tree.getId());
}
return oldTreeParser;
}
catch (MissingObjectException e) {
throw new NotFoundException(e.getMessage(), e);
}
}
示例15: loadTree
import org.eclipse.jgit.treewalk.CanonicalTreeParser; //導入依賴的package包/類
@NotNull
public Iterable<GitTreeEntry> loadTree(@Nullable GitTreeEntry tree) throws IOException {
final GitObject<ObjectId> treeId = getTreeObject(tree);
// Loading tree.
if (treeId == null) {
return Collections.emptyList();
}
final List<GitTreeEntry> result = new ArrayList<>();
final Repository repo = treeId.getRepo();
final CanonicalTreeParser treeParser = new CanonicalTreeParser(GitRepository.emptyBytes, repo.newObjectReader(), treeId.getObject());
while (!treeParser.eof()) {
result.add(new GitTreeEntry(
treeParser.getEntryFileMode(),
new GitObject<>(repo, treeParser.getEntryObjectId()),
treeParser.getEntryPathString()
));
treeParser.next();
}
return result;
}