Example usage for org.eclipse.jgit.blame BlameGenerator getSourceCommit

List of usage examples for org.eclipse.jgit.blame BlameGenerator getSourceCommit

Introduction

In this page you can find the example usage for org.eclipse.jgit.blame BlameGenerator getSourceCommit.

Prototype

public RevCommit getSourceCommit() 

Source Link

Document

Get the revision blamed for the current region.

Usage

From source file:com.google.gitiles.blame.BlameCacheImpl.java

License:Open Source License

private static List<Region> loadRegions(BlameGenerator gen) throws IOException {
    Map<ObjectId, PooledCommit> commits = Maps.newHashMap();
    Interner<String> strings = Interners.newStrongInterner();
    int lineCount = gen.getResultContents().size();

    List<Region> regions = Lists.newArrayList();
    while (gen.next()) {
        String path = gen.getSourcePath();
        PersonIdent author = gen.getSourceAuthor();
        ObjectId commit = gen.getSourceCommit();
        checkState(path != null && author != null && commit != null);

        PooledCommit pc = commits.get(commit);
        if (pc == null) {
            pc = new PooledCommit(commit.copy(), new PersonIdent(strings.intern(author.getName()),
                    strings.intern(author.getEmailAddress()), author.getWhen(), author.getTimeZone()));
            commits.put(pc.commit, pc);/*from  ww w  .  ja  v a 2s.  c  o m*/
        }
        path = strings.intern(path);
        commit = pc.commit;
        author = pc.author;
        regions.add(new Region(path, commit, author, gen.getResultStart(), gen.getResultEnd()));
    }
    Collections.sort(regions);

    // Fill in any gaps left by bugs in JGit, since rendering code assumes the
    // full set of contiguous regions.
    List<Region> result = Lists.newArrayListWithExpectedSize(regions.size());
    Region last = null;
    for (Region r : regions) {
        if (last != null) {
            checkState(last.getEnd() <= r.getStart());
            if (last.getEnd() < r.getStart()) {
                result.add(new Region(null, null, null, last.getEnd(), r.getStart()));
            }
        }
        result.add(r);
        last = r;
    }
    if (last != null && last.getEnd() != lineCount) {
        result.add(new Region(null, null, null, last.getEnd(), lineCount));
    }

    return ImmutableList.copyOf(result);
}