private byte[] contentFromTree(RevTree tree) { try { final ObjectReader reader = gitRepo.newObjectReader(); CanonicalTreeParser parser = new CanonicalTreeParser(); parser.reset(reader, tree); String lastPath = null; while (true) { final String path = parser.getEntryPathString(); parser = parser.next(); if (path.equals(lastPath)) { break; } lastPath = path; if (path.equals(CRUISE_CONFIG_XML)) { final ObjectId id = parser.getEntryObjectId(); final ObjectLoader loader = reader.open(id); return loader.getBytes(); } } return null; } catch (IOException e) { LOGGER.error("Could not fetch content from the config repository found at path '{}'", workingDir.getAbsolutePath(), e); throw new RuntimeException("Error while fetching content from the config repository.", e); } }
@Override public ObjectLoader open(String path, ObjectId id) throws IOException { return reader.open(id, Constants.OBJ_BLOB); } }
@Override public ObjectLoader open() throws IOException { return ObjectReader.this.open(cur, OBJ_ANY); }
@Override public ObjectLoader open(AnyObjectId objectId) throws MissingObjectException, IOException { return delegate().open(objectId); }
@Override public ObjectLoader open(AnyObjectId objectId, int typeHint) throws MissingObjectException, IncorrectObjectTypeException, IOException { return delegate().open(objectId, typeHint); }
private static byte[] read(ObjectReader or, AnyObjectId blobId) throws MissingObjectException, IncorrectObjectTypeException, IOException { ObjectLoader loader = or.open(blobId, Constants.OBJ_BLOB); return loader.getCachedBytes(Integer.MAX_VALUE); }
@Override public <T extends ObjectId> AsyncObjectLoaderQueue<T> open( Iterable<T> objectIds, boolean reportMissing) { return delegate().open(objectIds, reportMissing); }
private void checkObjectCollision(AnyObjectId obj, int type, byte[] data) throws IOException { try { final ObjectLoader ldr = readCurs.open(obj, type); final byte[] existingData = ldr.getCachedBytes(data.length); if (!Arrays.equals(data, existingData)) { throw new IOException(MessageFormat.format( JGitText.get().collisionOn, obj.name())); } } catch (MissingObjectException notLocal) { // This is OK, we don't have a copy of the object locally // but the API throws when we try to read it as usually its // an error to read something that doesn't exist. } }
byte[] getCachedBytes(RevObject obj) throws LargeObjectException, MissingObjectException, IncorrectObjectTypeException, IOException { return getCachedBytes(obj, reader.open(obj, obj.getType())); }
private TreeVisit newTreeVisit(RevObject obj) throws LargeObjectException, MissingObjectException, IncorrectObjectTypeException, IOException { TreeVisit tv = freeVisit; if (tv != null) { freeVisit = tv.parent; tv.ptr = 0; tv.namePtr = 0; tv.nameEnd = 0; tv.pathLen = 0; } else { tv = new TreeVisit(); } tv.obj = obj; tv.buf = reader.open(obj, OBJ_TREE).getCachedBytes(); return tv; }
static PushCertificate read(TreeWalk tw) throws IOException { if (tw == null || (tw.getRawMode(0) & TYPE_FILE) != TYPE_FILE) { return null; } ObjectLoader loader = tw.getObjectReader().open(tw.getObjectId(0), OBJ_BLOB); try (InputStream in = loader.openStream(); Reader r = new BufferedReader( new InputStreamReader(in, UTF_8))) { return PushCertificateParser.fromReader(r); } }
static byte[] buffer(PackConfig config, ObjectReader or, AnyObjectId objId) throws IOException { // PackWriter should have already pruned objects that // are above the big file threshold, so our chances of // the object being below it are very good. We really // shouldn't be here, unless the implementation is odd. return or.open(objId).getCachedBytes(config.getBigFileThreshold()); }
AttributesNode load(ObjectReader reader) throws IOException { AttributesNode r = new AttributesNode(); ObjectLoader loader = reader.open(objectId); if (loader != null) { try (InputStream in = loader.openStream()) { r.parse(in); } } return r.getRules().isEmpty() ? null : r; } }
private static AttributesNode loadAttributes(ObjectReader reader, AnyObjectId id) throws IOException { AttributesNode r = new AttributesNode(); try (InputStream in = reader.open(id, OBJ_BLOB).openStream()) { r.parse(in); } return r.getRules().isEmpty() ? noAttributes() : r; }
private void writeWholeObjectDeflate(PackOutputStream out, final ObjectToPack otp) throws IOException { final Deflater deflater = deflater(); final ObjectLoader ldr = reader.open(otp, otp.getType()); crc32.reset(); otp.setOffset(out.length()); out.writeHeader(otp, ldr.getSize()); deflater.reset(); DeflaterOutputStream dst = new DeflaterOutputStream(out, deflater); ldr.copyTo(dst); dst.finish(); }
private byte[] readTree(AnyObjectId id) throws MissingObjectException, IncorrectObjectTypeException, IOException { TreeWithData tree = treeCache.get(id); if (tree != null) return tree.buf; ObjectLoader ldr = reader.open(id, OBJ_TREE); byte[] buf = ldr.getCachedBytes(Integer.MAX_VALUE); treeCache.add(new TreeWithData(id, buf)); return buf; }
private static String readContentAsNormalizedString(DirCacheEntry entry, ObjectReader reader) throws MissingObjectException, IOException { ObjectLoader open = reader.open(entry.getObjectId()); byte[] cachedBytes = open.getCachedBytes(); return FS.detect().normalize(RawParseUtils.decode(cachedBytes)); }
void loadText(ObjectReader reader) throws IOException { ObjectLoader ldr = LfsFactory.getInstance().applySmudgeFilter(sourceRepository, reader.open(sourceBlob, Constants.OBJ_BLOB), LfsFactory.getAttributesForPath(sourceRepository, sourcePath.getPath(), sourceCommit) .get(Constants.ATTR_DIFF)); sourceText = new RawText(ldr.getCachedBytes(Integer.MAX_VALUE)); }
private RawText getRawText(ObjectId id, Attributes attributes) throws IOException, BinaryBlobException { if (id.equals(ObjectId.zeroId())) return new RawText(new byte[] {}); ObjectLoader loader = LfsFactory.getInstance().applySmudgeFilter( getRepository(), reader.open(id, OBJ_BLOB), attributes.get(Constants.ATTR_MERGE)); int threshold = PackConfig.DEFAULT_BIG_FILE_THRESHOLD; return RawText.load(loader, threshold); }
@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); } } } } }