Search in sources :

Example 6 with RevBlob

use of org.eclipse.jgit.revwalk.RevBlob in project gitblit by gitblit.

the class JGitUtils method getByteContent.

/**
	 * Gets the raw byte content of the specified blob object.
	 *
	 * @param repository
	 * @param objectId
	 * @return byte [] blob content
	 */
public static byte[] getByteContent(Repository repository, String objectId) {
    RevWalk rw = new RevWalk(repository);
    byte[] content = null;
    try {
        RevBlob blob = rw.lookupBlob(ObjectId.fromString(objectId));
        ObjectLoader ldr = repository.open(blob.getId(), Constants.OBJ_BLOB);
        content = ldr.getCachedBytes();
    } catch (Throwable t) {
        error(t, repository, "{0} can't find blob {1}", objectId);
    } finally {
        rw.dispose();
    }
    return content;
}
Also used : RevBlob(org.eclipse.jgit.revwalk.RevBlob) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader) RevWalk(org.eclipse.jgit.revwalk.RevWalk)

Example 7 with RevBlob

use of org.eclipse.jgit.revwalk.RevBlob in project gitiles by GerritCodeReview.

the class PathServletTest method treeTextEscaped.

@Test
public void treeTextEscaped() throws Exception {
    RevBlob blob = repo.blob("contents");
    repo.branch("master").commit().add("foo\nbar\rbaz", blob).create();
    assertThat(buildBlob("/repo/+/master/", "040000")).isEqualTo("100644 blob " + blob.name() + "\t\"foo\\nbar\\rbaz\"\n");
}
Also used : RevBlob(org.eclipse.jgit.revwalk.RevBlob) Test(org.junit.Test)

Example 8 with RevBlob

use of org.eclipse.jgit.revwalk.RevBlob in project gitiles by GerritCodeReview.

the class RevisionParserTest method parseUnsupportedRevisionExpressions.

@Test
public void parseUnsupportedRevisionExpressions() throws Exception {
    RevBlob blob = repo.blob("blob contents");
    RevCommit master = repo.branch("master").commit().add("blob", blob).create();
    assertThat(repo.getRepository().resolve("master^{}")).isEqualTo(master);
    assertThat(parser.parse("master^{}")).isNull();
    assertThat(repo.getRepository().resolve("master^{commit}")).isEqualTo(master);
    assertThat(parser.parse("master^{commit}")).isNull();
    assertThat(repo.getRepository().resolve("master:blob")).isEqualTo(blob);
    assertThat(parser.parse("master:blob")).isNull();
    // TestRepository has no simple way of setting the reflog.
    //assertThat(repo.getRepository().resolve("master@{0}")).isEqualTo(null);
    assertThat(parser.parse("master@{0}")).isNull();
}
Also used : RevBlob(org.eclipse.jgit.revwalk.RevBlob) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 9 with RevBlob

use of org.eclipse.jgit.revwalk.RevBlob in project gitiles by GerritCodeReview.

the class TimeCacheTest method taggedTreeAndBlobTime.

@Test
public void taggedTreeAndBlobTime() throws Exception {
    RevBlob blob = repo.blob("contents");
    RevTree tree = repo.tree(repo.file("foo", blob));
    repo.tick(1);
    RevTag blobTag = repo.tag("blob", blob);
    repo.tick(1);
    RevTag treeTag = repo.tag("tree", tree);
    assertThat(getTime(blobTag)).isEqualTo(start + 1);
    assertThat(getTime(treeTag)).isEqualTo(start + 2);
}
Also used : RevTag(org.eclipse.jgit.revwalk.RevTag) RevBlob(org.eclipse.jgit.revwalk.RevBlob) RevTree(org.eclipse.jgit.revwalk.RevTree) Test(org.junit.Test)

Example 10 with RevBlob

use of org.eclipse.jgit.revwalk.RevBlob in project gitiles by GerritCodeReview.

the class TimeCacheTest method treeAndBlobTime.

@Test
public void treeAndBlobTime() throws Exception {
    RevBlob blob = repo.blob("contents");
    RevTree tree = repo.tree(repo.file("foo", blob));
    assertThat(getTime(blob)).isEqualTo(Long.MIN_VALUE);
    assertThat(getTime(tree)).isEqualTo(Long.MIN_VALUE);
}
Also used : RevBlob(org.eclipse.jgit.revwalk.RevBlob) RevTree(org.eclipse.jgit.revwalk.RevTree) Test(org.junit.Test)

Aggregations

RevBlob (org.eclipse.jgit.revwalk.RevBlob)10 Test (org.junit.Test)9 RevTree (org.eclipse.jgit.revwalk.RevTree)3 PathEdit (org.eclipse.jgit.dircache.DirCacheEditor.PathEdit)2 DirCacheEntry (org.eclipse.jgit.dircache.DirCacheEntry)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 RevTag (org.eclipse.jgit.revwalk.RevTag)2 File (com.google.gitiles.FileJsonData.File)1 Result (com.google.gitiles.RevisionParser.Result)1 ObjectLoader (org.eclipse.jgit.lib.ObjectLoader)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1