/** * 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 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 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); }
/** * 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); } }
final ObjectId blobId = lookupId(repository, commit, path); if (blobId == null) return null;