/** * Set the common ancestor tree. * * @param id * common base treeish; null to automatically compute the common * base from the input commits during * {@link #merge(AnyObjectId...)}. * @throws org.eclipse.jgit.errors.IncorrectObjectTypeException * the object is not a treeish. * @throws org.eclipse.jgit.errors.MissingObjectException * the object does not exist. * @throws java.io.IOException * the object could not be read. */ public void setBase(AnyObjectId id) throws MissingObjectException, IncorrectObjectTypeException, IOException { if (id != null) { baseTree = walk.parseTree(id); } else { baseTree = null; } }
@SuppressWarnings("resource") private static RevTree toTree(ObjectReader reader, AnyObjectId id) throws IOException { return new RevWalk(reader).parseTree(id); }
/** * Construct an Indexdiff * * @param repository * a {@link org.eclipse.jgit.lib.Repository} object. * @param objectId * tree id. If null, an EmptyTreeIterator is used. * @param workingTreeIterator * iterator for working directory * @throws java.io.IOException */ public IndexDiff(Repository repository, ObjectId objectId, WorkingTreeIterator workingTreeIterator) throws IOException { this.repository = repository; if (objectId != null) { try (RevWalk rw = new RevWalk(repository)) { tree = rw.parseTree(objectId); } } else { tree = null; } this.initialWorkingTreeIterator = workingTreeIterator; }
/** * Determine the differences between two trees. * * No output is created, instead only the file paths that are different are * returned. Callers may choose to format these paths themselves, or convert * them into {@link org.eclipse.jgit.patch.FileHeader} instances with a * complete edit list by calling {@link #toFileHeader(DiffEntry)}. * <p> * Either side may be null to indicate that the tree has beed added or * removed. The diff will be computed against nothing. * * @param a * the old (or previous) side or null * @param b * the new (or updated) side or null * @return the paths that are different. * @throws java.io.IOException * trees cannot be read or file contents cannot be read. */ public List<DiffEntry> scan(AnyObjectId a, AnyObjectId b) throws IOException { assertHaveReader(); try (RevWalk rw = new RevWalk(reader)) { RevTree aTree = a != null ? rw.parseTree(a) : null; RevTree bTree = b != null ? rw.parseTree(b) : null; return scan(aTree, bTree); } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { ObjectId revId = repository.resolve(Constants.HEAD); try (TreeWalk treeWalk = new TreeWalk(repository)) { try (RevWalk revWalk = new RevWalk(repository)) { treeWalk.addTree(revWalk.parseTree(revId)); while (treeWalk.next()) { System.out.println("---------------------------"); System.out.append("name: ").println(treeWalk.getNameString()); System.out.append("path: ").println(treeWalk.getPathString()); ObjectLoader loader = repository.open(treeWalk.getObjectId(0)); System.out.append("directory: ").println(loader.getType() == Constants.OBJ_TREE); System.out.append("size: ").println(loader.getSize()); } } } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { ObjectId revId = repository.resolve(Constants.HEAD); try (TreeWalk treeWalk = new TreeWalk(repository)) { try (RevWalk revWalk = new RevWalk(repository)) { treeWalk.addTree(revWalk.parseTree(revId)); while (treeWalk.next()) { System.out.println("---------------------------"); System.out.append("name: ").println(treeWalk.getNameString()); System.out.append("path: ").println(treeWalk.getPathString()); ObjectLoader loader = repository.open(treeWalk.getObjectId(0)); System.out.append("directory: ").println(loader.getType() == Constants.OBJ_TREE); System.out.append("size: ").println(loader.getSize()); } } } } } }
private static AnyObjectId asTree(ObjectReader or, AnyObjectId treeish) throws MissingObjectException, IncorrectObjectTypeException, IOException { if (treeish instanceof RevTree) return treeish; if (treeish instanceof RevCommit && ((RevCommit) treeish).getTree() != null) return ((RevCommit) treeish).getTree(); try (RevWalk rw = new RevWalk(or)) { return rw.parseTree(treeish).getId(); } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { // See e.g. GetRevCommitFromObjectId for how to use a SHA-1 directly Ref head = repository.findRef("HEAD"); System.out.println("Ref of HEAD: " + head + ": " + head.getName() + " - " + head.getObjectId().getName()); // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); System.out.println("Commit: " + commit); // a commit points to a tree RevTree tree = walk.parseTree(commit.getTree().getId()); System.out.println("Found Tree: " + tree); walk.dispose(); } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { // See e.g. GetRevCommitFromObjectId for how to use a SHA-1 directly Ref head = repository.findRef("HEAD"); System.out.println("Ref of HEAD: " + head + ": " + head.getName() + " - " + head.getObjectId().getName()); // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); System.out.println("Commit: " + commit); // a commit points to a tree RevTree tree = walk.parseTree(commit.getTree().getId()); System.out.println("Found Tree: " + tree); walk.dispose(); } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { // the Ref holds an ObjectId for any type of object (tree, commit, blob, tree) Ref head = repository.exactRef("refs/heads/master"); System.out.println("Ref of refs/heads/master: " + head); System.out.println("\nPrint contents of head of master branch, i.e. the latest commit information"); ObjectLoader loader = repository.open(head.getObjectId()); loader.copyTo(System.out); System.out.println("\nPrint contents of tree of head of master branch, i.e. the latest binary tree information"); // a commit points to a tree try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); RevTree tree = walk.parseTree(commit.getTree().getId()); System.out.println("Found Tree: " + tree); loader = repository.open(tree.getId()); loader.copyTo(System.out); walk.dispose(); } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { // the Ref holds an ObjectId for any type of object (tree, commit, blob, tree) Ref head = repository.exactRef("refs/heads/master"); System.out.println("Ref of refs/heads/master: " + head); System.out.println("\nPrint contents of head of master branch, i.e. the latest commit information"); ObjectLoader loader = repository.open(head.getObjectId()); loader.copyTo(System.out); System.out.println("\nPrint contents of tree of head of master branch, i.e. the latest binary tree information"); // a commit points to a tree try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); RevTree tree = walk.parseTree(commit.getTree().getId()); System.out.println("Found Tree: " + tree); loader = repository.open(tree.getId()); loader.copyTo(System.out); walk.dispose(); } } } }
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; } }
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; } } }
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; } }
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; } } }
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; } } }
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; } } }
private static AbstractTreeIterator prepareTreeParser(Repository repository, String ref) throws IOException { // from the commit we can build the tree which allows us to construct the TreeParser Ref head = repository.exactRef(ref); try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); 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; } } }
private static AbstractTreeIterator prepareTreeParser(Repository repository, String ref) throws IOException { // from the commit we can build the tree which allows us to construct the TreeParser Ref head = repository.exactRef(ref); try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); 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; } } }
ObjectReader reader = walk.getObjectReader(); walk.reset(rw.parseTree(tree)); if (!paths.isEmpty()) walk.setFilter(PathFilterGroup.createFromStrings(paths));