Search in sources :

Example 6 with BlameInfo

use of com.google.gerrit.extensions.common.BlameInfo in project gerrit by GerritCodeReview.

the class GetBlameIT method forRecreatedFile.

@Test
public void forRecreatedFile() throws Exception {
    // Create change that adds 'foo.txt'.
    createChange("Change 1", "foo.txt", "FOO");
    // Create change that deletes 'foo.txt'.
    pushFactory.create(admin.newIdent(), testRepo, "Change 2", "foo.txt", "FOO").rm("refs/for/master");
    // Create change that recreates 'foo.txt'.
    PushOneCommit.Result r = createChange("Change 3", "foo.txt", "FOO");
    List<BlameInfo> blameInfos = gApi.changes().id(r.getChangeId()).current().file("foo.txt").blameRequest().get();
    assertThat(blameInfos).hasSize(1);
    BlameInfo blameInfo = blameInfos.get(0);
    assertThat(blameInfo.author).isEqualTo(admin.fullName());
    assertThat(blameInfo.id).isEqualTo(r.getCommit().getId().name());
    assertThat(blameInfo.commitMsg).isEqualTo(r.getCommit().getFullMessage());
    assertThat(blameInfo.time).isEqualTo(r.getCommit().getCommitTime());
    assertThat(blameInfo.ranges).hasSize(1);
    RangeInfo rangeInfo = blameInfo.ranges.get(0);
    assertThat(rangeInfo.start).isEqualTo(1);
    assertThat(rangeInfo.end).isEqualTo(1);
}
Also used : RangeInfo(com.google.gerrit.extensions.common.RangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) BlameInfo(com.google.gerrit.extensions.common.BlameInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 7 with BlameInfo

use of com.google.gerrit.extensions.common.BlameInfo in project gerrit by GerritCodeReview.

the class GetBlameIT method forNewlyAddedFile.

@Test
public void forNewlyAddedFile() throws Exception {
    PushOneCommit.Result r = createChange("Test Change", "foo.txt", "FOO");
    List<BlameInfo> blameInfos = gApi.changes().id(r.getChangeId()).current().file("foo.txt").blameRequest().get();
    assertThat(blameInfos).hasSize(1);
    BlameInfo blameInfo = blameInfos.get(0);
    assertThat(blameInfo.author).isEqualTo(admin.fullName());
    assertThat(blameInfo.id).isEqualTo(r.getCommit().getId().name());
    assertThat(blameInfo.commitMsg).isEqualTo(r.getCommit().getFullMessage());
    assertThat(blameInfo.time).isEqualTo(r.getCommit().getCommitTime());
    assertThat(blameInfo.ranges).hasSize(1);
    RangeInfo rangeInfo = blameInfo.ranges.get(0);
    assertThat(rangeInfo.start).isEqualTo(1);
    assertThat(rangeInfo.end).isEqualTo(1);
}
Also used : RangeInfo(com.google.gerrit.extensions.common.RangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) BlameInfo(com.google.gerrit.extensions.common.BlameInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 8 with BlameInfo

use of com.google.gerrit.extensions.common.BlameInfo in project gerrit by GerritCodeReview.

the class GetBlame method blame.

private List<BlameInfo> blame(ObjectId id, String path, Repository repository, RevWalk revWalk) throws IOException {
    ListMultimap<BlameInfo, RangeInfo> ranges = MultimapBuilder.hashKeys().arrayListValues().build();
    List<BlameInfo> result = new ArrayList<>();
    if (blameCache.findLastCommit(repository, id, path) == null) {
        return result;
    }
    List<Region> blameRegions = blameCache.get(repository, id, path);
    int from = 1;
    for (Region region : blameRegions) {
        RevCommit commit = revWalk.parseCommit(region.getSourceCommit());
        BlameInfo blameInfo = toBlameInfo(commit, region.getSourceAuthor());
        ranges.put(blameInfo, new RangeInfo(from, from + region.getCount() - 1));
        from += region.getCount();
    }
    for (BlameInfo key : ranges.keySet()) {
        key.ranges = ranges.get(key);
        result.add(key);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Region(com.google.gitiles.blame.cache.Region) RangeInfo(com.google.gerrit.extensions.common.RangeInfo) BlameInfo(com.google.gerrit.extensions.common.BlameInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

BlameInfo (com.google.gerrit.extensions.common.BlameInfo)8 RangeInfo (com.google.gerrit.extensions.common.RangeInfo)4 ArrayList (java.util.ArrayList)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 List (java.util.List)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 ObjectReader (org.eclipse.jgit.lib.ObjectReader)2 Ref (org.eclipse.jgit.lib.Ref)2 Repository (org.eclipse.jgit.lib.Repository)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 Test (org.junit.Test)2 Project (com.google.gerrit.entities.Project)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 Project (com.google.gerrit.reviewdb.client.Project)1 InMemoryInserter (com.google.gerrit.server.git.InMemoryInserter)1 Region (com.google.gitiles.blame.Region)1 Region (com.google.gitiles.blame.cache.Region)1