本文整理汇总了Java中org.eclipse.jgit.treewalk.AbstractTreeIterator类的典型用法代码示例。如果您正苦于以下问题:Java AbstractTreeIterator类的具体用法?Java AbstractTreeIterator怎么用?Java AbstractTreeIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AbstractTreeIterator类属于org.eclipse.jgit.treewalk包,在下文中一共展示了AbstractTreeIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIterator
import org.eclipse.jgit.treewalk.AbstractTreeIterator; //导入依赖的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;
}
}
示例2: getTreeIterator
import org.eclipse.jgit.treewalk.AbstractTreeIterator; //导入依赖的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;
}
}
}
示例3: diff
import org.eclipse.jgit.treewalk.AbstractTreeIterator; //导入依赖的package包/类
@Override
public String diff(Workspace ws, String path, String oldRef, String newRef) throws IOException, GitAPIException {
Repository repository = getRepository(ws.getSpaceKey());
AbstractTreeIterator oldTreeParser = prepareTreeParser(repository, oldRef);
AbstractTreeIterator newTreeParser = prepareTreeParser(repository, newRef);
Config config = new Config();
config.setBoolean("diff", null, "renames", true);
DiffConfig diffConfig = config.get(DiffConfig.KEY);
String relativePath = ws.getRelativePath(path).toString();
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
Git git = Git.wrap(repository)) {
git.diff()
.setOldTree(oldTreeParser)
.setNewTree(newTreeParser)
.setPathFilter(FollowFilter.create(relativePath, diffConfig))
.setOutputStream(baos)
.call();
return baos.toString();
}
}
示例4: prepareTreeParser
import org.eclipse.jgit.treewalk.AbstractTreeIterator; //导入依赖的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;
}
}
示例5: prepareTreeParser
import org.eclipse.jgit.treewalk.AbstractTreeIterator; //导入依赖的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;
}
}
示例6: buildDirCache
import org.eclipse.jgit.treewalk.AbstractTreeIterator; //导入依赖的package包/类
private void buildDirCache(TreeWalk walk, DirCacheBuilder builder)
throws MissingObjectException, IncorrectObjectTypeException,
CorruptObjectException, IOException {
while (walk.next()) {
AbstractTreeIterator cIter = walk.getTree(0,
AbstractTreeIterator.class);
if (cIter == null) {
// Not in commit, don't add to new index
continue;
}
final DirCacheEntry entry = new DirCacheEntry(walk.getRawPath());
entry.setFileMode(cIter.getEntryFileMode());
entry.setObjectIdFromRaw(cIter.idBuffer(), cIter.idOffset());
DirCacheIterator dcIter = walk.getTree(1, DirCacheIterator.class);
if (dcIter != null && dcIter.idEqual(cIter)) {
DirCacheEntry indexEntry = dcIter.getDirCacheEntry();
entry.setLastModified(indexEntry.getLastModified());
entry.setLength(indexEntry.getLength());
}
builder.add(entry);
}
}
示例7: prepareTreeParser
import org.eclipse.jgit.treewalk.AbstractTreeIterator; //导入依赖的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;
}
}
示例8: getDiffBetweenCommits
import org.eclipse.jgit.treewalk.AbstractTreeIterator; //导入依赖的package包/类
public String getDiffBetweenCommits(int commitIndex) throws IOException,GitAPIException{
if(commitIndex+1==commitCount)
return "Nothing to Diff. This is first commit";
AbstractTreeIterator current = prepareTreeParser(repository,commitSHA.get(commitIndex));
AbstractTreeIterator parent = prepareTreeParser(repository,commitSHA.get(++commitIndex));
ObjectReader reader = repository.newObjectReader();
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
// finally get the list of changed files
Git git = new Git(repository) ;
List<DiffEntry> diff = git.diff().
setOldTree(parent).
setNewTree(current).
//TODO Set the path filter to filter out the selected file
//setPathFilter(PathFilter.create("README.md")).
call();
for (DiffEntry entry : diff) {
System.out.println("Entry: " + entry + ", from: " + entry.getOldId() + ", to: " + entry.getNewId());
DiffFormatter formatter = new DiffFormatter(byteStream) ;
formatter.setRepository(repository);
formatter.format(entry);
}
// System.out.println(byteStream.toString());
String diffContent = byteStream.toString();
return byteStream.toString();
}
示例9: getDiffString
import org.eclipse.jgit.treewalk.AbstractTreeIterator; //导入依赖的package包/类
private String getDiffString() throws GitAPIException, IOException {
ObjectId head = this.repo.resolve("HEAD");
if(head == null) return "";
// The following code is largely written by Tk421 on StackOverflow
// (http://stackoverflow.com/q/23486483)
// Thanks! NOTE: comments are mine.
ByteArrayOutputStream diffOutputStream = new ByteArrayOutputStream();
DiffFormatter formatter = new DiffFormatter(diffOutputStream);
formatter.setRepository(this.repo);
formatter.setPathFilter(PathFilter.create(this.pathFilter.replaceAll("\\\\","/")));
AbstractTreeIterator commitTreeIterator = prepareTreeParser(this.repo, head.getName());
FileTreeIterator workTreeIterator = new FileTreeIterator(this.repo);
// Scan gets difference between the two iterators.
formatter.format(commitTreeIterator, workTreeIterator);
return diffOutputStream.toString();
}
示例10: prepareTreeParser
import org.eclipse.jgit.treewalk.AbstractTreeIterator; //导入依赖的package包/类
private static AbstractTreeIterator prepareTreeParser(
Repository repository, RevCommit commit) throws IOException,
MissingObjectException, IncorrectObjectTypeException {
// from the commit we can build the tree which allows us to construct
// the TreeParser
RevWalk walk = new RevWalk(repository);
RevTree tree = walk.parseTree(commit.getTree().getId());
CanonicalTreeParser result = new CanonicalTreeParser();
ObjectReader reader = repository.newObjectReader();
try {
result.reset(reader, tree.getId());
} finally {
reader.release();
}
walk.dispose();
return result;
}
示例11: formatHtmlDiff
import org.eclipse.jgit.treewalk.AbstractTreeIterator; //导入依赖的package包/类
private void formatHtmlDiff(OutputStream out,
Repository repo, RevWalk walk,
AbstractTreeIterator oldTree, AbstractTreeIterator newTree,
String path)
throws IOException {
DiffFormatter diff = new HtmlDiffFormatter(renderer, out);
try {
if (!path.equals("")) {
diff.setPathFilter(PathFilter.create(path));
}
diff.setRepository(repo);
diff.setDetectRenames(true);
diff.format(oldTree, newTree);
} finally {
diff.release();
}
}
示例12: prepareTreeParser
import org.eclipse.jgit.treewalk.AbstractTreeIterator; //导入依赖的package包/类
private static 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(repository.resolve(objectId));
RevTree tree = walk.parseTree(commit.getTree().getId());
CanonicalTreeParser treeParser = new CanonicalTreeParser();
try (ObjectReader reader = repository.newObjectReader()) {
treeParser.reset(reader, tree.getId());
}
walk.dispose();
return treeParser;
}
}
示例13: main
import org.eclipse.jgit.treewalk.AbstractTreeIterator; //导入依赖的package包/类
public static void main(String[] args) throws IOException, GitAPIException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
// the diff works on TreeIterators, we prepare two for the two branches
AbstractTreeIterator oldTreeParser = prepareTreeParser(repository, "b97b184b0ce11c0b6a4dcc2b57768ff155cb696b");
AbstractTreeIterator newTreeParser = prepareTreeParser(repository, "9e0719d7d773b41b49ebf04e6fd7b5c637e96063");
// then the porcelain diff-command returns a list of diff entries
try (Git git = new Git(repository)) {
List<DiffEntry> diff = git.diff().
setOldTree(oldTreeParser).
setNewTree(newTreeParser).
setPathFilter(PathFilter.create("README.md")).
// to filter on Suffix use the following instead
//setPathFilter(PathSuffixFilter.create(".java")).
call();
for (DiffEntry entry : diff) {
System.out.println("Entry: " + entry + ", from: " + entry.getOldId() + ", to: " + entry.getNewId());
try (DiffFormatter formatter = new DiffFormatter(System.out)) {
formatter.setRepository(repository);
formatter.format(entry);
}
}
}
}
}
示例14: prepareTreeParser
import org.eclipse.jgit.treewalk.AbstractTreeIterator; //导入依赖的package包/类
private static 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 treeParser = new CanonicalTreeParser();
try (ObjectReader reader = repository.newObjectReader()) {
treeParser.reset(reader, tree.getId());
}
walk.dispose();
return treeParser;
}
}
示例15: main
import org.eclipse.jgit.treewalk.AbstractTreeIterator; //导入依赖的package包/类
public static void main(String[] args) throws IOException, GitAPIException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
try (Git git = new Git(repository)) {
if(repository.exactRef("refs/heads/testbranch") == null) {
// first we need to ensure that the remote branch is visible locally
Ref ref = git.branchCreate().setName("testbranch").setStartPoint("origin/testbranch").call();
System.out.println("Created local testbranch with ref: " + ref);
}
// the diff works on TreeIterators, we prepare two for the two branches
AbstractTreeIterator oldTreeParser = prepareTreeParser(repository, "refs/heads/testbranch");
AbstractTreeIterator newTreeParser = prepareTreeParser(repository, "refs/heads/master");
// then the procelain diff-command returns a list of diff entries
List<DiffEntry> diff = git.diff().setOldTree(oldTreeParser).setNewTree(newTreeParser).call();
for (DiffEntry entry : diff) {
System.out.println("Entry: " + entry);
}
}
}
}