/** * Get the contents of the blob at the given path in the commit that HEAD * references. * * @param repository * @param path * @return content or null if no blob with path at HEAD commit */ public static String getHeadContent(final Repository repository, final String path) { return getContent(repository, HEAD, path); }
/** * Diff the blobs at the given object ids using the * {@link RawTextComparator#DEFAULT} comparator. * * @see #diff(Repository, ObjectId, ObjectId, RawTextComparator) * @param repository * @param blob1 * @param blob2 * @return list of edits */ public static Collection<Edit> diff(final Repository repository, final ObjectId blob1, final ObjectId blob2) { return diff(repository, blob1, blob2, DEFAULT); }
/** * Get the contents of the the blob in the commit located at the given path * as a byte array. * * @param repository * @param commit * @param path * @return raw content */ protected static byte[] getBytes(final Repository repository, final RevCommit commit, final String path) { final ObjectId id = lookupId(repository, commit, path); return id != null ? getBytes(repository, id) : null; }
/** * Get the contents of the blob in the commit located at the given path. * * @param repository * @param commitId * @param path * @return contents or null if no blob with path at given commit */ public static String getContent(final Repository repository, final ObjectId commitId, final String path) { return toString(repository, getRawContent(repository, commitId, path)); }
/** * Get the contents of the the blob with the given id as a UTF-8 * {@link String}. * * @param repository * @param id * @return content of blob as UTF-8 string */ public static String getContent(final Repository repository, final ObjectId id) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (id == null) throw new IllegalArgumentException( Assert.formatNotNull("Object id")); return toString(repository, getBytes(repository, id)); }
/** * Get the raw contents of the blob in the commit located at the given path. * * @param repository * @param commitId * @param path * @return raw content or null if no blob with path at given commit */ public static byte[] getRawContent(final Repository repository, final ObjectId commitId, final String path) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (commitId == null) throw new IllegalArgumentException( Assert.formatNotNull("Commit id")); if (path == null) throw new IllegalArgumentException(Assert.formatNotNull("Path")); if (path.length() == 0) throw new IllegalArgumentException(Assert.formatNotEmpty("Path")); final RevCommit commit = CommitUtils.parse(repository, commitId); return getBytes(repository, commit, path); }
/** * Get the id of the blob at the path in the commit that the given revision * references. * * @param repository * @param commitId * @param path * @return blob id */ public static ObjectId getId(final Repository repository, final ObjectId commitId, final String path) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (commitId == null) throw new IllegalArgumentException( Assert.formatNotNull("Commit id")); if (path == null) throw new IllegalArgumentException(Assert.formatNotNull("Path")); if (path.length() == 0) throw new IllegalArgumentException(Assert.formatNotEmpty("Path")); final RevCommit commit = CommitUtils.parse(repository, commitId); return lookupId(repository, commit, path); }
/** * Get the id of the blob at the path in the commit that HEAD currently * references. * * @param repository * @param path * @return blob id */ public static ObjectId getHeadId(final Repository repository, final String path) { return getId(repository, HEAD, path); }
/** * Get the raw contents of the blob at the given path in the commit that * HEAD references. * * @param repository * @param path * @return content or null if no blob with path at HEAD commit */ public static byte[] getRawHeadContent(final Repository repository, final String path) { return getRawContent(repository, HEAD, path); }
/** * Open a stream to the contents of the blob at the path in the commit that * HEAD currently references. * * @param repository * @param path * @return stream */ public static ObjectStream getHeadStream(final Repository repository, final String path) { return getStream(repository, HEAD, path); }
/** * Get the contents of the blob at the given path in the commit that the * revision references. * * @param repository * @param revision * @param path * @return contents or null if no blob with path at given revision */ public static String getContent(final Repository repository, final String revision, final String path) { return toString(repository, getRawContent(repository, revision, path)); }
/** * Get raw contents of the blob at the given path in the commit that the * revision references. * * @param repository * @param revision * @param path * @return raw content or null if no blob with path at given revision */ public static byte[] getRawContent(final Repository repository, final String revision, final String path) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (revision == null) throw new IllegalArgumentException(Assert.formatNotNull("Revision")); if (revision.length() == 0) throw new IllegalArgumentException( Assert.formatNotEmpty("Revision")); if (path == null) throw new IllegalArgumentException(Assert.formatNotNull("Path")); if (path.length() == 0) throw new IllegalArgumentException(Assert.formatNotEmpty("Path")); final RevCommit commit = CommitUtils.parse(repository, CommitUtils.strictResolve(repository, revision)); return getBytes(repository, commit, path); }
/** * Get the id of the blob at the path in the commit that the given revision * references. * * @param repository * @param revision * @param path * @return blob id */ public static ObjectId getId(final Repository repository, final String revision, final String path) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (revision == null) throw new IllegalArgumentException(Assert.formatNotNull("Revision")); if (revision.length() == 0) throw new IllegalArgumentException( Assert.formatNotEmpty("Revision")); if (path == null) throw new IllegalArgumentException(Assert.formatNotNull("Path")); if (path.length() == 0) throw new IllegalArgumentException(Assert.formatNotEmpty("Path")); final RevCommit commit = CommitUtils.parse(repository, CommitUtils.strictResolve(repository, revision)); return lookupId(repository, commit, path); }
/** * Get content of note as string * * @param note * @return string */ protected String getContent(final Note note) { return BlobUtils.getContent(repository, note.getData()); }
/** * Diff the blobs at the given object ids using the * {@link RawTextComparator#DEFAULT} comparator. * * @see #diff(ObjectReader, ObjectId, ObjectId, RawTextComparator) * @param reader * @param blob1 * @param blob2 * @return list of edits */ public static Collection<Edit> diff(final ObjectReader reader, final ObjectId blob1, final ObjectId blob2) { return diff(reader, blob1, blob2, DEFAULT); }
/** * Open a stream to the contents of the blob at the path in the given commit * * @param repository * @param commitId * @param path * @return stream, null if no blob at given path */ public static ObjectStream getStream(final Repository repository, final ObjectId commitId, final String path) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); if (commitId == null) throw new IllegalArgumentException( Assert.formatNotNull("Commit id")); if (path == null) throw new IllegalArgumentException(Assert.formatNotNull("Path")); if (path.length() == 0) throw new IllegalArgumentException(Assert.formatNotEmpty("Path")); final RevCommit commit = CommitUtils.parse(repository, commitId); final ObjectId blobId = lookupId(repository, commit, path); if (blobId == null) return null; try { return repository.open(blobId, OBJ_BLOB).openStream(); } catch (IOException e) { throw new GitException(e, repository); } }
protected String doGetContent(Git git, String objectId, String pathOrBlobPath) { objectId = defaultObjectId(git, objectId); Repository r = git.getRepository(); String blobPath = trimLeadingSlash(pathOrBlobPath); return BlobUtils.getContent(r, objectId, blobPath); }
@Override public boolean include(RevWalk walker, RevCommit commit, Collection<DiffEntry> diffs) { count = 0; final ObjectReader reader = walker.getObjectReader(); for (DiffEntry diff : diffs) { if (!isFileDiff(diff)) continue; final AbbreviatedObjectId oldId = diff.getOldId(); if (oldId == null) continue; include(commit, diff, BlobUtils.diff(reader, oldId.toObjectId(), diff.getNewId().toObjectId())); if (count >= total) break; } return count >= total ? true : include(false); }