Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java18
1 files changed, 14 insertions, 4 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java
index 3858b3dd0e..e38cb468d9 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java
@@ -218,7 +218,8 @@ class Blame extends TextBuiltin {
dateWidth = Math.max(dateWidth, date(line).length());
pathWidth = Math.max(pathWidth, path(line).length());
}
- while (line + 1 < end && blame.getSourceCommit(line + 1) == c) {
+ while (line + 1 < end
+ && sameCommit(blame.getSourceCommit(line + 1), c)) {
line++;
}
maxSourceLine = Math.max(maxSourceLine, blame.getSourceLine(line));
@@ -257,13 +258,22 @@ class Blame extends TextBuiltin {
blame.getResultContents().writeLine(outs, line);
outs.flush();
outw.print('\n');
- } while (++line < end && blame.getSourceCommit(line) == c);
+ } while (++line < end
+ && sameCommit(blame.getSourceCommit(line), c));
}
} catch (NoWorkTreeException | IOException e) {
throw die(e.getMessage(), e);
}
}
+ @SuppressWarnings("ReferenceEquality")
+ private static boolean sameCommit(RevCommit a, RevCommit b) {
+ // Reference comparison is intentional; BlameGenerator uses a single
+ // RevWalk which caches the RevCommit objects, and if a given commit
+ // is cached the RevWalk returns the same instance.
+ return a == b;
+ }
+
private int uniqueAbbrevLen(ObjectReader reader, RevCommit commit)
throws IOException {
return reader.abbreviate(commit, abbrev).length();
@@ -295,14 +305,14 @@ class Blame extends TextBuiltin {
}
}
- if (beginStr.equals("")) //$NON-NLS-1$
+ if (beginStr.isEmpty())
begin = 0;
else if (beginStr.startsWith("/")) //$NON-NLS-1$
begin = findLine(0, beginStr);
else
begin = Math.max(0, Integer.parseInt(beginStr) - 1);
- if (endStr.equals("")) //$NON-NLS-1$
+ if (endStr.isEmpty())
end = blame.getResultContents().size();
else if (endStr.startsWith("/")) //$NON-NLS-1$
end = findLine(begin, endStr);

Back to the top