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 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(); } }
@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(); } }
private void checkSubmodules() throws IOException { ObjectDatabase odb = db.getObjectDatabase(); if (objectChecker == null) { return; } for (GitmoduleEntry entry : objectChecker.getGitsubmodules()) { AnyObjectId blobId = entry.getBlobId(); ObjectLoader blob = odb.open(blobId, Constants.OBJ_BLOB); try { SubmoduleValidator.assertValidGitModulesFile( new String(blob.getBytes(), UTF_8)); } catch (LargeObjectException | SubmoduleValidationException e) { throw new IOException(e); } } }
private void checkGitModules(ProgressMonitor pm, FsckError errors) throws IOException { pm.beginTask(JGitText.get().validatingGitModules, objChecker.getGitsubmodules().size()); for (GitmoduleEntry entry : objChecker.getGitsubmodules()) { AnyObjectId blobId = entry.getBlobId(); ObjectLoader blob = objdb.open(blobId, Constants.OBJ_BLOB); try { SubmoduleValidator.assertValidGitModulesFile( new String(blob.getBytes(), UTF_8)); } catch (SubmoduleValidationException e) { CorruptObject co = new FsckError.CorruptObject( blobId.toObjectId(), Constants.OBJ_BLOB, e.getFsckMessageId()); errors.getCorruptObjects().add(co); } pm.update(1); } pm.endTask(); }
if (entry.getFileMode() == FileMode.SYMLINK && opt.getSymLinks() == SymLinks.TRUE) { byte[] bytes = ol.getBytes(); String target = RawParseUtils.decode(bytes); if (deleteRecursive && f.isDirectory()) {
@Nonnull public static byte[] readObject(@Nonnull AnyObjectId id, @Nonnull ObjectReader reader) throws IOException { return reader.open(id).getBytes(); }
private boolean isLfsPointer(@NotNull ObjectLoader loader) { return loader.getSize() <= ru.bozaro.gitlfs.pointer.Constants.POINTER_MAX_SIZE && Pointer.parsePointer(loader.getBytes()) != null; }
@Nonnull public static BlobSnapshot load(ObjectId id, ObjectReader reader) throws IOException { return new BlobSnapshot(reader.open(id).getBytes(), id); }
ObjectId blobId = getObjectId( 0 ); ObjectReader objectReader = repository.newObjectReader(); ObjectLoader objectLoader = objectReader.open( blobId ); byte[] bytes = objectLoader.getBytes(); objectReader.close(); booloean binary = RawText.isBinary( bytes );
private <C> C getFileContents(final Class<C> c, final ObjectId blobId) throws IOException { final ObjectLoader loader = git.getRepository().open(blobId); final ObjectMapper mapper = Serializers.lenient(); return mapper.readValue(loader.getBytes(), c); }
private <C> C getFileContents(final Class<C> c, final ObjectId blobId) throws IOException { final ObjectLoader loader = git.getRepository().open(blobId); final ObjectMapper mapper = Serializers.lenient(); return mapper.readValue(loader.getBytes(), c); }
private Map<String, RevTag> getAnnotatedTagPerTagName( final Optional<String> ignoreTagsIfNameMatches, final List<Ref> tagList) { final Map<String, RevTag> tagPerCommit = newHashMap(); for (final Ref tag : tagList) { if (ignoreTagsIfNameMatches.isPresent()) { if (compile(ignoreTagsIfNameMatches.get()).matcher(tag.getName()).matches()) { continue; } } final Ref peeledTag = this.repository.peel(tag); if (peeledTag.getPeeledObjectId() != null) { try { final RevTag revTag = RevTag.parse(this.repository.open(tag.getObjectId()).getBytes()); tagPerCommit.put(tag.getName(), revTag); } catch (final IOException e) { LOG.error(e.getMessage(), e); } } } return tagPerCommit; }
public RevCommit execute() throws IOException { try (final ObjectReader reader = repo.newObjectReader()) { return RevCommit.parse(reader.open(objectId).getBytes()); } } }
byte[] getContent(String objectId) throws IOException { final ObjectId flowSnapshotObjectId = gitRepo.resolve(objectId); return gitRepo.newObjectReader().open(flowSnapshotObjectId).getBytes(); }
private void checkSubmodules() throws IOException { ObjectDatabase odb = db.getObjectDatabase(); if (objectChecker == null) { return; } for (GitmoduleEntry entry : objectChecker.getGitsubmodules()) { AnyObjectId blobId = entry.getBlobId(); ObjectLoader blob = odb.open(blobId, Constants.OBJ_BLOB); try { SubmoduleValidator.assertValidGitModulesFile( new String(blob.getBytes(), UTF_8)); } catch (LargeObjectException | SubmoduleValidationException e) { throw new IOException(e); } } }
private String getSourceCode(Repository repo, DiffEntry diff) throws IOException { if(!collectConfig.isCollectingSourceCode()) return ""; try { ObjectReader reader = repo.newObjectReader(); byte[] bytes = reader.open(diff.getNewId().toObjectId()).getBytes(); return new String(bytes, "utf-8"); } catch (Throwable e) { return ""; } }
private IdentifiableResource readBlob (Repository aRepo, String aPath, String aBlobId) throws Exception { try (ObjectReader reader = aRepo.newObjectReader()) { if(aBlobId.equals(LATEST)) { List<IdentifiableResource> headFiles = getHeadFiles(aRepo, aPath); Assert.notEmpty(headFiles,"could not find: " + aPath + ":" + aBlobId); return headFiles.get(0); } ObjectId objectId = aRepo.resolve(aBlobId); Assert.notNull(objectId,"could not find: " + aPath + ":" + aBlobId); byte[] data = reader.open(objectId).getBytes(); AbbreviatedObjectId abbreviated = reader.abbreviate(objectId); return new IdentifiableResource(aPath+":"+abbreviated.name(), new ByteArrayResource(data)); } }
/** * Returns the file as a String form the repository indexed by its ObjectId. * * @param id - ObjectID of the file. * @return - File returned as String. * @throws IOException - failed. */ @SuppressWarnings("DefaultCharset") public String readObject(final ObjectId id) throws IOException { try (val reader = git.getRepository().newObjectReader()) { if (reader.has(id)) { return new String(reader.open(id).getBytes()); } else { return readFormWorkingTree(id); } } }
/** * Returns the RawText of file specified by ObjectId. * * @param id - ObjectId of a file. * @return - RawText. * @throws IOException - failed. */ @SuppressWarnings("DefaultCharset") public RawText rawText(final ObjectId id) throws IOException { val objectReader = objectReader(); if (objectReader.has(id)) { return new RawText(objectReader.open(id).getBytes()); } else { return new RawText(readFormWorkingTree(id).getBytes()); } }