Example usage for org.eclipse.jgit.lib Repository open

List of usage examples for org.eclipse.jgit.lib Repository open

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Repository open.

Prototype

@NonNull
public ObjectLoader open(AnyObjectId objectId, int typeHint)
        throws MissingObjectException, IncorrectObjectTypeException, IOException 

Source Link

Document

Open an object from this repository.

Usage

From source file:org.gitective.core.BlobUtils.java

License:Open Source License

/**
 * Open a stream to the contents of the blob at the path in the commit that
 * the given revision references.//from   w w  w.j  a v a2 s .  c om
 *
 * @param repository
 * @param revision
 * @param path
 * @return stream
 */
public static ObjectStream getStream(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));
    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);
    }
}