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()) { // 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(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(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; } } }
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(); } } } }
if (headId != null && rw.parseCommit(headId).getTree().getId().equals(treeId)) {
public ObjectId execute() { final RevCommit commit = git.getLastCommit(treeRefName); if (commit == null) { return null; } return commit.getTree().getId(); } }
+ ".\n"; //$NON-NLS-1$ if (merger.merge(headCommit, srcParent)) { if (AnyObjectId.equals(headCommit.getTree().getId(), merger .getResultTreeId())) continue;
cherryPickName }); if (merger.merge(newHead, srcCommit)) { if (AnyObjectId.equals(newHead.getTree().getId(), merger .getResultTreeId())) continue;
private ObjectId toTreeId(RevWalk revWalk, Revision revision) { final ObjectId commitId = commitIdDatabase.get(revision); try { return revWalk.parseCommit(commitId).getTree().getId(); } catch (IOException e) { throw new StorageException("failed to parse a commit: " + commitId, e); } }
private ObjectId toTreeId(RevWalk revWalk, Revision revision) { final ObjectId commitId = commitIdDatabase.get(revision); try { return revWalk.parseCommit(commitId).getTree().getId(); } catch (IOException e) { throw new StorageException("failed to parse a commit: " + commitId, e); } }
private boolean isDifferentFromParent(final RevWalk revWalk, final CommitBuilder commitBuilder) throws MissingObjectException, IncorrectObjectTypeException, IOException { final ObjectId parentId = commitBuilder.getParentIds()[0]; final RevCommit parentCommit = revWalk.parseCommit(parentId); final ObjectId parentTreeId = parentCommit.getTree().getId(); final ObjectId commitTreeId = commitBuilder.getTreeId(); // A commit with the same tree as its parent has no changes. return !commitTreeId.equals(parentTreeId); }