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(); } } }
private void markTreeComplete(RevTree tree) throws IOException { if (tree.has(COMPLETE)) return; tree.add(COMPLETE); treeWalk.reset(tree); while (treeWalk.next()) { treeWalk.getObjectId(idBuffer, 0); throw new CorruptObjectException(MessageFormat.format(JGitText.get().corruptObjectInvalidMode3 , mode, idBuffer.name(), treeWalk.getPathString(), tree.name()));
private static TreeWalk buildTreeWalk(Repository repository, RevTree tree, final String path) throws IOException { TreeWalk treeWalk = TreeWalk.forPath(repository, path, tree); if(treeWalk == null) { throw new FileNotFoundException("Did not find expected file '" + path + "' in tree '" + tree.getName() + "'"); } return treeWalk; } }
public boolean matches(Pattern pattern, RevCommit commit) { RevTree tree = commit.getTree(); return tree != null ? matches(pattern, tree.name()) : false; } }
/** * Locate a reference to a tree without loading it. * <p> * The tree may or may not exist in the repository. It is impossible to tell * from this method's return value. * * @param id * name of the tree object. * @return reference to the tree object. Never null. */ @NonNull public RevTree lookupTree(AnyObjectId id) { RevTree c = (RevTree) objects.get(id); if (c == null) { c = new RevTree(id); objects.add(c); } return c; }
if (treeId.equals(lastTree)) { if (GitTraceLocation.QUICKDIFF.isActive()) GitTraceLocation.getTrace().trace( String msg = NLS .bind(UIText.GitDocument_errorLoadTree, new Object[] { treeId.getName(), baseline, resource, repository }); Activator.logError(msg, new Throwable()); setResolved(null, null, null, ""); //$NON-NLS-1$
@Override void parseHeaders(RevWalk walk) throws MissingObjectException, IncorrectObjectTypeException, IOException { if (walk.reader.has(this)) flags |= PARSED; else throw new MissingObjectException(this, getType()); }
@Override void parseBody(RevWalk walk) throws MissingObjectException, IncorrectObjectTypeException, IOException { if ((flags & PARSED) == 0) parseHeaders(walk); } }
/** * Lookup an entry stored in a tree, failing if not present. * * @param tree * the tree to search. * @param path * the path to find the entry of. * @return the parsed object entry at this path, never null. * @throws Exception */ public RevObject get(final RevTree tree, final String path) throws Exception { final TreeWalk tw = new TreeWalk(pool.getObjectReader()); tw.setFilter(PathFilterGroup.createFromStrings(Collections .singleton(path))); tw.reset(tree); while (tw.next()) { if (tw.isSubtree() && !path.equals(tw.getPathString())) { tw.enterSubtree(); continue; } final ObjectId entid = tw.getObjectId(0); final FileMode entmode = tw.getFileMode(0); return pool.lookupAny(entid, entmode.getObjectType()); } fail("Can't find " + path + " in tree " + tree.name()); return null; // never reached. }
break; case Constants.OBJ_TREE: r = new RevTree(id); break; case Constants.OBJ_BLOB:
@Override void parseHeaders(RevWalk walk) throws MissingObjectException, IncorrectObjectTypeException, IOException { if (walk.reader.has(this)) flags |= PARSED; else throw new MissingObjectException(this, getType()); }
@Override void parseBody(RevWalk walk) throws MissingObjectException, IncorrectObjectTypeException, IOException { if ((flags & PARSED) == 0) parseHeaders(walk); } }
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 void markTreeComplete(final RevTree tree) throws IOException { if (tree.has(COMPLETE)) return; tree.add(COMPLETE); treeWalk.reset(tree); while (treeWalk.next()) { treeWalk.getObjectId(idBuffer, 0); throw new CorruptObjectException(MessageFormat.format(JGitText.get().corruptObjectInvalidMode3 , mode, idBuffer.name(), treeWalk.getPathString(), tree.name()));
/** * Lookup an entry stored in a tree, failing if not present. * * @param tree * the tree to search. * @param path * the path to find the entry of. * @return the parsed object entry at this path, never null. * @throws Exception */ public RevObject get(RevTree tree, String path) throws Exception { try (TreeWalk tw = new TreeWalk(pool.getObjectReader())) { tw.setFilter(PathFilterGroup.createFromStrings(Collections .singleton(path))); tw.reset(tree); while (tw.next()) { if (tw.isSubtree() && !path.equals(tw.getPathString())) { tw.enterSubtree(); continue; } final ObjectId entid = tw.getObjectId(0); final FileMode entmode = tw.getFileMode(0); return pool.lookupAny(entid, entmode.getObjectType()); } } fail("Can't find " + path + " in tree " + tree.name()); return null; // never reached. }
r = new RevTree(id); r.flags |= PARSED; break;
private static TreeWalk buildTreeWalk(Repository repository, RevTree tree, final String path) throws IOException { TreeWalk treeWalk = TreeWalk.forPath(repository, path, tree); if(treeWalk == null) { throw new FileNotFoundException("Did not find expected file '" + path + "' in tree '" + tree.getName() + "'"); } return treeWalk; } }
@Override void parseHeaders(RevWalk walk) throws MissingObjectException, IncorrectObjectTypeException, IOException { if (walk.reader.has(this)) flags |= PARSED; else throw new MissingObjectException(this, getType()); }
@Override void parseBody(RevWalk walk) throws MissingObjectException, IncorrectObjectTypeException, IOException { if ((flags & PARSED) == 0) parseHeaders(walk); } }
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(); } } } }