@Override public void putEntry(ZipOutputStream out, ObjectId tree, String path, FileMode mode, ObjectLoader loader) throws IOException { // loader is null for directories... if (loader != null) { ZipEntry entry = new ZipEntry(path); if (tree instanceof RevCommit) { long t = ((RevCommit) tree).getCommitTime() * 1000L; entry.setTime(t); } out.putNextEntry(entry); out.write(loader.getBytes()); out.closeEntry(); } }
/** * Gets the loader for a file from a specified commit and its path * * @param commit * - the commit from which to get the loader * @param path * - the path to the file * @return the loader * @throws MissingObjectException * @throws IncorrectObjectTypeException * @throws CorruptObjectException * @throws IOException */ public ObjectLoader getLoaderFrom(ObjectId commit, String path) throws IOException { Repository repository = git.getRepository(); RevWalk revWalk = new RevWalk(repository); RevCommit revCommit = revWalk.parseCommit(commit); // and using commit's tree find the path RevTree tree = revCommit.getTree(); TreeWalk treeWalk = new TreeWalk(repository); treeWalk.addTree(tree); treeWalk.setRecursive(true); treeWalk.setFilter(PathFilter.create(path)); ObjectLoader loader = null; if (treeWalk.next()) { ObjectId objectId = treeWalk.getObjectId(0); loader = repository.open(objectId); } treeWalk.close(); revWalk.close(); return loader; }
public List<String> getProjectList(String projectName){ FileRepositoryBuilder builder = new FileRepositoryBuilder(); List list= new ArrayList(); try { log.debug("errororororoor123 "+ "\n"); Repository repository = builder .readEnvironment() // scan environment GIT_* variables .setGitDir(new File("C:/test0101/" + projectName +"/.git")) // scan up the file system tree .build(); DirCache index = DirCache.read(repository); ObjectLoader loader = null; log.debug("DirCache has " + index.getEntryCount() + " items"); for (int i = 0; i < index.getEntryCount(); i++) { log.debug(index.getEntry(i).getPathString()+ "\n"); list.add(index.getEntry(i).getPathString()); } } catch (IOException e) { log.debug("errororororoor "+ "\n"); // TODO Auto-generated catch block e.printStackTrace(); } return list; }
/** * Storing revisions in Git Notes causes object hash computation, which is expensive. */ public AssetRevision getRevisionGitNotes(File file) throws IOException { AssetRevision rev = file2rev.get(file); if (rev == null) { ObjectId workingId = getObjectId(file); try (RevWalk walk = new RevWalk(localRepo)) { Ref ref = localRepo.findRef(NOTES_REF); if (ref != null) { RevCommit notesCommit = walk.parseCommit(ref.getObjectId()); NoteMap notes = NoteMap.read(walk.getObjectReader(), notesCommit); Note note = notes.getNote(workingId); if (note != null) { ObjectLoader loader = localRepo.open(note.getData()); String noteStr = new String(loader.getBytes()).trim(); rev = parseAssetRevision(noteStr); file2rev.put(file, rev); return rev; } } } } return rev; }
public byte[] readFromCommit(String commitId, String path) throws Exception { try (RevWalk revWalk = new RevWalk(localRepo)) { RevCommit commit = revWalk.parseCommit(ObjectId.fromString(commitId)); // use commit's tree find the path RevTree tree = commit.getTree(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (TreeWalk treeWalk = new TreeWalk(localRepo)) { treeWalk.addTree(tree); treeWalk.setRecursive(true); treeWalk.setFilter(PathFilter.create(path)); if (!treeWalk.next()) { return null; } ObjectId objectId = treeWalk.getObjectId(0); ObjectLoader loader = localRepo.open(objectId); loader.copyTo(baos); } revWalk.dispose(); return baos.toByteArray(); } }
public static boolean getFileFromCommit(final OutputStream os, final String file, final Repository repo, final RevTree tree) throws IOException, GitAPIException { final TreeWalk treeWalk = new TreeWalk(repo); treeWalk.addTree(tree); treeWalk.setRecursive(true); treeWalk.setFilter(PathFilter.create(file)); if (!treeWalk.next()) { logger.info("Did not find expected file '" + file + "'"); return false; } final ObjectId objectId = treeWalk.getObjectId(0); final ObjectLoader loader = repo.open(objectId); // and then one can the loader to read the file loader.copyTo(os); return true; }
@Override public Note merge(Note base, Note ours, Note theirs, ObjectReader reader, ObjectInserter inserter) throws IOException { if (ours == null) { return theirs; } if (theirs == null) { return ours; } if (ours.getData().equals(theirs.getData())) { return ours; } ObjectLoader lo = reader.open(ours.getData()); byte[] sep = new byte[] {'\n'}; ObjectLoader lt = reader.open(theirs.getData()); try (ObjectStream os = lo.openStream(); ByteArrayInputStream b = new ByteArrayInputStream(sep); ObjectStream ts = lt.openStream(); UnionInputStream union = new UnionInputStream(os, b, ts)) { ObjectId noteData = inserter.insert(Constants.OBJ_BLOB, lo.getSize() + sep.length + lt.getSize(), union); return new Note(ours, noteData); } }
@SuppressWarnings("resource") private BinaryResult zipBlob( final String path, ObjectLoader obj, RevCommit commit, @Nullable final String suffix) { final String commitName = commit.getName(); final long when = commit.getCommitTime() * 1000L; return new BinaryResult() { @Override public void writeTo(OutputStream os) throws IOException { try (ZipOutputStream zipOut = new ZipOutputStream(os)) { String decoration = randSuffix(); if (!Strings.isNullOrEmpty(suffix)) { decoration = suffix + '-' + decoration; } ZipEntry e = new ZipEntry(safeFileName(path, decoration)); e.setComment(commitName + ":" + path); e.setSize(obj.getSize()); e.setTime(when); zipOut.putNextEntry(e); obj.copyTo(zipOut); zipOut.closeEntry(); } } }.setContentType(ZIP_TYPE).setAttachmentName(safeFileName(path, suffix) + ".zip").disableGzip(); }
public Ref execute() { try { final Ref value = repo.getRefDatabase().getRef(name); if (value != null) { return value; } final ObjectId treeRef = repo.resolve(name + "^{tree}"); if (treeRef != null) { final ObjectLoader loader = repo.getObjectDatabase().newReader().open(treeRef); if (loader.getType() == OBJ_TREE) { return new ObjectIdRef.PeeledTag(Ref.Storage.NEW, name, ObjectId.fromString(name), treeRef); } } } catch (final Exception ignored) { } return null; }
private void parseBlobs(String repositoryPath, String syntaxTreeDirPath) { File repoDir = new File(repositoryPath); try { Repository repo = new FileRepository(repoDir); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; while ( (line = br.readLine()) != null) { root = new Tree(""); ObjectId obj = ObjectId.fromString(line); ObjectLoader loader = repo.open(obj); char[] src = IOUtils.toCharArray(loader.openStream()); File outputFile = new File(syntaxTreeDirPath, line); parseSourcecodeAndWriteSyntaxTree(src, outputFile); } } catch (IOException e) { e.printStackTrace(); } }
private byte[] open(ObjectReader reader, FileMode mode, AbbreviatedObjectId id) throws IOException { if (mode == FileMode.MISSING) return new byte[] { }; if (mode.getObjectType() != Constants.OBJ_BLOB) return new byte[] { }; if (!id.isComplete()) { Collection<ObjectId> ids = reader.resolve(id); if (ids.size() == 1) id = AbbreviatedObjectId.fromObjectId(ids.iterator().next()); else if (ids.size() == 0) throw new MissingObjectException(id, Constants.OBJ_BLOB); else throw new AmbiguousObjectException(id, ids); } ObjectLoader ldr = reader.open(id.toObjectId()); return ldr.getCachedBytes(bigFileThreshold); }
private void extractPackage(Repository _repo) throws MissingObjectException, IOException{ ObjectLoader newFile = _repo.open(this.newObjId); String newData = readStream(newFile.openStream()); ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(newData.toCharArray()); parser.setKind(ASTParser.K_COMPILATION_UNIT); Hashtable<String, String> options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.DISABLED); parser.setCompilerOptions(options); final CompilationUnit cu = (CompilationUnit) parser.createAST(null); cu.accept(new ASTVisitor() { public boolean visit(PackageDeclaration _package){ packageName = _package.getName().getFullyQualifiedName(); return false; } }); }
/** * Retrieves the raw byte content of a file in the specified tree. * * @param repository * @param tree * if null, the RevTree from HEAD is assumed. * @param path * @return content as a byte [] */ public static byte[] getByteContent(Repository repository, RevTree tree, final String path, boolean throwError) { RevWalk rw = new RevWalk(repository); byte[] content = null; try (TreeWalk tw = new TreeWalk(repository)) { tw.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path))); if (tree == null) { ObjectId object = getDefaultBranch(repository); if (object == null) { return null; } RevCommit commit = rw.parseCommit(object); tree = commit.getTree(); } tw.reset(tree); while (tw.next()) { if (tw.isSubtree() && !path.equals(tw.getPathString())) { tw.enterSubtree(); continue; } ObjectId entid = tw.getObjectId(0); FileMode entmode = tw.getFileMode(0); if (entmode != FileMode.GITLINK) { ObjectLoader ldr = repository.open(entid, Constants.OBJ_BLOB); content = ldr.getCachedBytes(); } } } catch (Throwable t) { if (throwError) { error(t, repository, "{0} can't find {1} in tree {2}", path, tree.name()); } } finally { rw.close(); rw.dispose(); } return content; }
/** * Gets the raw byte content of the specified blob object. * * @param repository * @param objectId * @return byte [] blob content */ public static byte[] getByteContent(Repository repository, String objectId) { RevWalk rw = new RevWalk(repository); byte[] content = null; try { RevBlob blob = rw.lookupBlob(ObjectId.fromString(objectId)); ObjectLoader ldr = repository.open(blob.getId(), Constants.OBJ_BLOB); content = ldr.getCachedBytes(); } catch (Throwable t) { error(t, repository, "{0} can't find blob {1}", objectId); } finally { rw.close(); rw.dispose(); } return content; }
@NotNull @Override public String getMd5(@NotNull GitObject<? extends ObjectId> objectId) throws IOException, SVNException { final ObjectLoader loader = objectId.openObject(); final ObjectStream stream = loader.openStream(); final byte[] header = new byte[Constants.POINTER_MAX_SIZE]; int length = ByteStreams.read(stream, header, 0, header.length); if (length < header.length) { final Map<String, String> pointer = Pointer.parsePointer(header, 0, length); if (pointer != null) { String md5 = getReader(pointer).getMd5(); if (md5 != null) { return md5; } } } return GitFilterHelper.getMd5(this, cacheMd5, null, objectId); }
/** * Gets the raw byte content of the specified blob object. * * @param repository * @param objectId * @return byte [] blob content */ public static byte[] getByteContent(Repository repository, String objectId) { RevWalk rw = new RevWalk(repository); byte[] content = null; try { RevBlob blob = rw.lookupBlob(ObjectId.fromString(objectId)); rw.parseBody(blob); ByteArrayOutputStream os = new ByteArrayOutputStream(); ObjectLoader ldr = repository.open(blob.getId(), Constants.OBJ_BLOB); byte[] tmp = new byte[4096]; InputStream in = ldr.openStream(); int n; while ((n = in.read(tmp)) > 0) { os.write(tmp, 0, n); } in.close(); content = os.toByteArray(); } catch (Throwable t) { error(t, repository, "{0} can't find blob {1}", objectId); } finally { rw.dispose(); } return content; }
/** {@inheritDoc} */ public void appendNote(String note, String namespace) throws GitException { try (Repository repo = getRepository()) { ObjectId head = repo.resolve(HEAD); // commit to put a note on ShowNoteCommand cmd = git(repo).notesShow(); cmd.setNotesRef(qualifyNotesNamespace(namespace)); try (ObjectReader or = repo.newObjectReader(); RevWalk walk = new RevWalk(or)) { cmd.setObjectId(walk.parseAny(head)); Note n = cmd.call(); if (n==null) { addNote(note,namespace); } else { ObjectLoader ol = or.open(n.getData()); StringWriter sw = new StringWriter(); IOUtils.copy(new InputStreamReader(ol.openStream(),CHARSET),sw); sw.write("\n"); addNote(sw.toString() + normalizeNote(note), namespace); } } } catch (GitAPIException | IOException e) { throw new GitException(e); } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { // a RevWalk allows to retrieve information from the repository try (RevWalk walk = new RevWalk(repository)) { // a simple tag that is not annotated Ref simpleTag = repository.findRef("initialtag"); RevObject any = walk.parseAny(simpleTag.getObjectId()); System.out.println("Commit: " + any); // an annotated tag Ref annotatedTag = repository.findRef("secondtag"); any = walk.parseAny(annotatedTag.getObjectId()); System.out.println("Tag: " + any); // finally try to print out the tag-content System.out.println("\nTag-Content: \n"); ObjectLoader loader = repository.open(annotatedTag.getObjectId()); 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(); } } }
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()); } } } } }
@Test public void testRevWalkDisposeClosesReader() throws IOException { try (Repository repo = CookbookHelper.openJGitCookbookRepository()) { try (ObjectReader reader = repo.newObjectReader()) { try (RevWalk walk = new RevWalk(reader)) { walk.dispose(); Ref head = repo.exactRef("refs/heads/master"); System.out.println("Found head: " + head); ObjectLoader loader = reader.open(head.getObjectId()); assertNotNull(loader); } } } }
/** 커밋에 붙어있는 GIT 노트를 가져옴 * @param commit * @return */ public String getNote(String commit){ String str = new String(); try{ Note note = git.notesShow().setObjectId(CommitUtils.getCommit(git.getRepository(), commit)).call(); ObjectLoader loader = this.localRepo.open(note.getData()); str = new String(loader.getBytes()); }finally{ return str; } }
private RevObject parseNew(AnyObjectId id, ObjectLoader ldr) throws LargeObjectException, CorruptObjectException, MissingObjectException, IOException { RevObject r; int type = ldr.getType(); switch (type) { case Constants.OBJ_COMMIT: { final RevCommit c = createCommit(id); c.parseCanonical(this, getCachedBytes(c, ldr)); r = c; break; } case Constants.OBJ_TREE: { r = new RevTree(id); r.flags |= PARSED; break; } case Constants.OBJ_BLOB: { r = new RevBlob(id); r.flags |= PARSED; break; } case Constants.OBJ_TAG: { final RevTag t = new RevTag(id); t.parseCanonical(this, getCachedBytes(t, ldr)); r = t; break; } default: throw new IllegalArgumentException(MessageFormat.format( JGitText.get().badObjectType, Integer.valueOf(type))); } objects.add(r); return r; }
byte[] getCachedBytes(RevObject obj, ObjectLoader ldr) throws LargeObjectException, MissingObjectException, IOException { try { return ldr.getCachedBytes(5 * MB); } catch (LargeObjectException tooBig) { tooBig.setObjectId(obj); throw tooBig; } }
public InputStream getInputStream(BlobIdent ident) { try (RevWalk revWalk = new RevWalk(getRepository())) { ObjectId commitId = getObjectId(ident.revision); RevTree revTree = revWalk.parseCommit(commitId).getTree(); TreeWalk treeWalk = TreeWalk.forPath(getRepository(), ident.path, revTree); if (treeWalk != null) { ObjectLoader objectLoader = treeWalk.getObjectReader().open(treeWalk.getObjectId(0)); return objectLoader.openStream(); } else { throw new ObjectNotFoundException("Unable to find blob path '" + ident.path + "' in revision '" + ident.revision + "'"); } } catch (IOException e) { throw new RuntimeException(e); } }
/** * Gets the InputStream for the file that is found in the given commit at the * given path * * @param commitID * - the commit in which the file exists * @param path * - the path to the file * * @return the InputStream for the file * * @throws IOException */ public InputStream getInputStream(ObjectId commitID) throws IOException { InputStream toReturn = null; if (commitID != null) { ObjectLoader loader = git.getRepository().open(commitID); if (loader == null) { throw new IOException("Cannot obtain an object loader for the commit ID: " + commitID); } else { toReturn = loader.openStream(); } } else { throw new IOException("The commit ID can't be null"); } return toReturn; }
public static ObjectJson buildObject(TreeWalk tree, FileMode fileMode, ObjectLoader loader) throws LargeObjectException { ObjectJson objectJson = new ObjectJson(); objectJson.addDoc(FILE_MODE_NAME, getFileMode(fileMode)); objectJson.addDoc(FILE_MODE_NAME, fileMode); objectJson.addDoc(FILE_TYPE, fileMode.getObjectType()); objectJson.addDoc(OBJECT_ID, tree.getObjectId(0).getName()); objectJson.addDoc(OBJECT_SIZE, loader.getSize()); objectJson.addDoc(OBJECT_JSON, new String(loader.getBytes())); return objectJson; }
/** * * @param repo * @param lastCommitId * @return * @throws LargeObjectException * @throws IOException */ public static ObjectId getLastCommitTreeId(Repository repo, ObjectId lastCommitId) throws LargeObjectException, IOException { if (lastCommitId == null) { return null; } else { ObjectReader objectReader = repo.newObjectReader(); ObjectLoader objectLoader = objectReader.open(lastCommitId); RevCommit oldCommit = RevCommit.parse(objectLoader.getBytes()); return oldCommit.getTree().getId(); } }
/** * * @param repo * @param blobId * @return * @throws LargeObjectException * @throws IOException */ public static byte[] getObjectFromRepo(Repository repo, ObjectId blobId) throws LargeObjectException, IOException { ObjectReader objectReader = repo.newObjectReader(); ObjectLoader objectLoader = objectReader.open(blobId); // int type = objectLoader.getType(); // Constants.OBJ_BLOB byte[] bytes = objectLoader.getBytes(); return bytes; }
public static void getLastRevision(Git git, String base, String name, String rev, OutputStream out, String ext) throws WsSrvException, IOException { checkFile(base, name, ext); String fp = getLocalPath(name); // find the HEAD ObjectId lastCommitId = git.getRepository().resolve(Constants.HEAD); // a RevWalk allows to walk over commits based on // some filtering that is defined RevWalk revWalk = new RevWalk(git.getRepository()); RevCommit commit = revWalk.parseCommit(lastCommitId); // and using commit's tree find the path RevTree tree = commit.getTree(); System.out.println("Having tree: " + tree); // now try to find a specific file TreeWalk treeWalk = new TreeWalk(git.getRepository()); treeWalk.addTree(tree); treeWalk.setRecursive(true); treeWalk.setFilter(PathFilter.create(fp)); if (!treeWalk.next()) { throw new IllegalStateException( "Did not find expected file 'README.md'"); } ObjectId objectId = treeWalk.getObjectId(0); System.out.println("ObjectId: " + objectId.toString()); ObjectLoader loader = git.getRepository().open(objectId); // and then one can the loader to read the file loader.copyTo(System.out); revWalk.dispose(); }
/** * Function used to treat pack object, it load the data from each object of * the pack to create the original object when the object is recreate it * store the object into the git object index * * @author Sylvain * * @param pathPack * the path of the pack file * @throws IOException * @throws DataFormatException */ public static void makePack(String pathPack) throws IOException, DataFormatException { String[] path = pathPack.split(osBarre + ".git" + osBarre); RepositoryBuilder builder = new RepositoryBuilder(); builder.setMustExist(true); builder.setGitDir(new File(path[0] + osBarre + ".git" + osBarre)); Repository repository = builder.build(); for (MutableEntry mutableEntry : new PackFile(new File(pathPack), 0)) { GitObject obj = null; String sha1 = mutableEntry.toObjectId().name(); ObjectId id = repository.resolve(sha1); ObjectLoader loader = repository.open(id); switch (loader.getType()) { case Constants.OBJ_BLOB: obj = new GitBlob(loader.getSize(), sha1, "", loader.getCachedBytes()); break; case Constants.OBJ_COMMIT: obj = new GitCommit(loader.getSize(), sha1, new String(loader.getCachedBytes())); break; case Constants.OBJ_TREE: obj = new GitTree(loader.getSize(), sha1, loader.getBytes()); break; case Constants.OBJ_TAG: obj = new GitTag(loader.getSize(), sha1, new String(loader.getCachedBytes())); break; default: break; } GitObjectsIndex.getInstance().put(mutableEntry.toObjectId().name(), obj); } }
@Override public ObjectLoader open(AnyObjectId objectId, int typeHint) throws MissingObjectException, IncorrectObjectTypeException, IOException { ObjectLoader objectLoader = objectLoaderCache.get(objectId); if (objectLoader == null) { objectLoader = delegate.open(objectId, Constants.OBJ_TREE); objectLoaderCache.put(objectId.copy(), objectLoader); } return objectLoader; }
private String getContent(final ObjectId id) { try { final ObjectLoader loader = repository.open(id); return new String(loader.getBytes()); } catch (final IOException e) { return EMPTY; } }
@Override public ShowFileContentResponse showFileContent(String file, String version) throws GitException { String content; ObjectId revision; try { revision = getRepository().resolve(version); try (RevWalk revWalk = new RevWalk(getRepository())) { RevCommit revCommit = revWalk.parseCommit(revision); RevTree tree = revCommit.getTree(); try (TreeWalk treeWalk = new TreeWalk(getRepository())) { treeWalk.addTree(tree); treeWalk.setRecursive(true); treeWalk.setFilter(PathFilter.create(file)); if (!treeWalk.next()) { throw new GitException( "fatal: Path '" + file + "' does not exist in '" + version + "'" + lineSeparator()); } ObjectId objectId = treeWalk.getObjectId(0); ObjectLoader loader = repository.open(objectId); content = new String(loader.getBytes()); } } } catch (IOException exception) { throw new GitException(exception.getMessage()); } return newDto(ShowFileContentResponse.class).withContent(content); }
/** * Utility method that converts a note to a string (assuming it's UTF-8). */ private String noteToString(Repository repo, Note note) throws MissingObjectException, IOException, UnsupportedEncodingException { ObjectLoader loader = repo.open(note.getData()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); loader.copyTo(baos); return new String(baos.toByteArray(), "UTF-8"); }
public static StarRef readLabels(Repository repo, String refName) throws IOException { Ref ref = repo.exactRef(refName); if (ref == null) { return StarRef.MISSING; } try (ObjectReader reader = repo.newObjectReader()) { ObjectLoader obj = reader.open(ref.getObjectId(), Constants.OBJ_BLOB); return StarRef.create( ref, Splitter.on(CharMatcher.whitespace()) .omitEmptyStrings() .split(new String(obj.getCachedBytes(Integer.MAX_VALUE), UTF_8))); } }
protected byte[] readFile(String fileName) throws IOException { if (revision == null) { return new byte[] {}; } TreeWalk tw = TreeWalk.forPath(reader, fileName, revision.getTree()); if (tw != null) { ObjectLoader obj = reader.open(tw.getObjectId(0), Constants.OBJ_BLOB); return obj.getCachedBytes(Integer.MAX_VALUE); } return new byte[] {}; }