Refine search
private static void runBuiltinFilterCommand(Repository repo, CheckoutMetadata checkoutMetadata, ObjectLoader ol, OutputStream channel) throws MissingObjectException, IOException { boolean isMandatory = repo.getConfig().getBoolean( ConfigConstants.CONFIG_FILTER_SECTION, ConfigConstants.CONFIG_SECTION_LFS, ConfigConstants.CONFIG_KEY_REQUIRED, false); FilterCommand command = null; try { command = FilterCommandRegistry.createFilterCommand( checkoutMetadata.smudgeFilterCommand, repo, ol.openStream(), channel); } catch (IOException e) { LOG.error(JGitText.get().failedToDetermineFilterDefinition, e); if (!isMandatory) { // In case an IOException occurred during creating of the // command then proceed as if there would not have been a // builtin filter (only if the filter is not mandatory). ol.copyTo(channel); } else { throw e; } } if (command != null) { while (command.run() != -1) { // loop as long as command.run() tells there is work to do } } }
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); } }
/** * Create the stream from an existing loader's cached bytes. * * @param loader * the loader. */ public SmallStream(ObjectLoader loader) { this(loader.getType(), loader.getCachedBytes()); }
/** * Obtain a copy of the bytes of this object. * <p> * Unlike {@link #getCachedBytes()} this method returns an array that might * be modified by the caller. * * @return the bytes of this object. * @throws org.eclipse.jgit.errors.LargeObjectException * if the object won't fit into a byte array, because * {@link #isLarge()} returns true. Callers should use * {@link #openStream()} instead to access the contents. */ public final byte[] getBytes() throws LargeObjectException { return cloneArray(getCachedBytes()); }
void hash(ObjectLoader obj) throws MissingObjectException, IOException, TableFullException { if (obj.isLarge()) { hashLargeObject(obj); } else { byte[] raw = obj.getCachedBytes(); hash(raw, 0, raw.length); } }
byte[] getContent(String objectId) throws IOException { final ObjectId flowSnapshotObjectId = gitRepo.resolve(objectId); return gitRepo.newObjectReader().open(flowSnapshotObjectId).getBytes(); }
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()); } } } } } }
checkoutMetadata = CheckoutMetadata.EMPTY; ObjectLoader ol = or.open(entry.getObjectId()); File f = new File(repo.getWorkTree(), entry.getPathString()); File parentDir = f.getParentFile(); FileUtils.mkdirs(parentDir, true); FS fs = repo.getFS(); WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY); if (entry.getFileMode() == FileMode.SYMLINK && opt.getSymLinks() == SymLinks.TRUE) { byte[] bytes = ol.getBytes(); String target = RawParseUtils.decode(bytes); if (deleteRecursive && f.isDirectory()) { ol.copyTo(channel); entry.setLength(ol.getSize()); } else { entry.setLength(tmpFile.length());
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(); } } } }
ProcessBuilder filterProcessBuilder = fs.runInShell( checkoutMetadata.smudgeFilterCommand, new String[0]); filterProcessBuilder.directory(repo.getWorkTree()); filterProcessBuilder.environment().put(Constants.GIT_DIR_KEY, repo.getDirectory().getAbsolutePath()); ExecutionResult result; int rc; try { result = fs.execute(filterProcessBuilder, ol.openStream()); rc = result.getRc(); if (rc == 0) {
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (Git git = new Git(repository)) { List<Note> call = git.notesList().call(); System.out.println("Listing " + call.size() + " notes"); for (Note note : call) { System.out.println("Note: " + note + " " + note.getName() + " " + note.getData().getName() + "\nContent: "); // displaying the contents of the note is done via a simple blob-read ObjectLoader loader = repository.open(note.getData()); loader.copyTo(System.out); } } } } }
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(); } } } }
/** {@inheritDoc} */ @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()); ObjectLoader lt = reader.open(theirs.getData()); try (UnionInputStream union = new UnionInputStream(lo.openStream(), lt.openStream())) { ObjectId noteData = inserter.insert(Constants.OBJ_BLOB, lo.getSize() + lt.getSize(), union); return new Note(ours, noteData); } } }
@Override public ObjectStream openStream() throws IOException { return delegate().openStream(); } }
/** * Loosen objects in a pack file which are not also in the newly-created * pack files. * * @param inserter * @param reader * @param pack * @param existing * @throws IOException */ private void loosen(ObjectDirectoryInserter inserter, ObjectReader reader, PackFile pack, HashSet<ObjectId> existing) throws IOException { for (PackIndex.MutableEntry entry : pack) { ObjectId oid = entry.toObjectId(); if (existing.contains(oid)) { continue; } existing.add(oid); ObjectLoader loader = reader.open(oid); inserter.insert(loader.getType(), loader.getSize(), loader.openStream(), true /* create this object even though it's a duplicate */); } }
private static void printFile(Repository repository, RevTree tree) throws IOException { // now try to find a specific file try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); treeWalk.setRecursive(false); treeWalk.setFilter(PathFilter.create("README.md")); if (!treeWalk.next()) { throw new IllegalStateException("Did not find expected file 'README.md'"); } // FileMode specifies the type of file, FileMode.REGULAR_FILE for normal file, FileMode.EXECUTABLE_FILE for executable bit // set FileMode fileMode = treeWalk.getFileMode(0); ObjectLoader loader = repository.open(treeWalk.getObjectId(0)); System.out.println("README.md: " + getFileMode(fileMode) + ", type: " + fileMode.getObjectType() + ", mode: " + fileMode + " size: " + loader.getSize()); } }
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; }
/** * Whether this object is too large to obtain as a byte array. * * @return true if this object is too large to obtain as a byte array. * Objects over a certain threshold should be accessed only by their * {@link #openStream()} to prevent overflowing the JVM heap. */ public boolean isLarge() { try { getCachedBytes(); return false; } catch (LargeObjectException tooBig) { return true; } }