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);
}
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);
}
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;
}
Aggregations