Provide a support to blame on a given commit. This is done by passing in
RevCommit as a start to blame.
The underlying jgit commit 87efbcb adds a support to accept a start
commit. Passing in a FilteredRevCommit that overrides parents would save
a lot of time walking/finding commits to be blamed on.
Change-Id: Ia2b45fe540b70ca940f247baf16b2e15d6aef599
diff --git a/java/com/google/gitiles/blame/cache/BlameCacheImpl.java b/java/com/google/gitiles/blame/cache/BlameCacheImpl.java
index 75ab09b..2fa80f5 100644
--- a/java/com/google/gitiles/blame/cache/BlameCacheImpl.java
+++ b/java/com/google/gitiles/blame/cache/BlameCacheImpl.java
@@ -32,6 +32,7 @@
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import org.eclipse.jgit.blame.BlameGenerator;
+import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
@@ -133,9 +134,14 @@
}
}
- public static List<Region> loadBlame(Key key, Repository repo) throws IOException {
+ public static List<Region> loadBlame(Key key, AnyObjectId blameCommit, Repository repo)
+ throws IOException {
+ if (blameCommit == null) {
+ return loadBlame(key, repo);
+ }
+
try (BlameGenerator gen = new BlameGenerator(repo, key.path)) {
- gen.push(null, key.commitId);
+ gen.push(null, blameCommit);
if (gen.getResultContents() == null) {
return ImmutableList.of();
}
@@ -143,6 +149,10 @@
}
}
+ public static List<Region> loadBlame(Key key, Repository repo) throws IOException {
+ return loadBlame(key, key.commitId, repo);
+ }
+
private static class PooledCommit {
final ObjectId commit;
final PersonIdent author;
@@ -192,7 +202,8 @@
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(
+ new Region(null, null, null, /* start= */ last.getEnd(), /* end= */ r.getStart()));
}
}
result.add(r);