diff options
author | David Pursehouse <david.pursehouse@gmail.com> | 2019-06-12 13:02:07 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2019-06-17 08:18:12 +0900 |
commit | 215a2dcf0f63cb53209353f17b08e78c9b85233c (patch) | |
tree | 2d87cd66a21eab27ab5b414baf23f23da48f7b2d | |
parent | 76b3781f4b9d9bce83ce81886851b90e486c34fb (diff) | |
download | jgit-215a2dcf0f63cb53209353f17b08e78c9b85233c.tar.gz jgit-215a2dcf0f63cb53209353f17b08e78c9b85233c.zip |
Blame: Suppress ReferenceEquality warning for RevCommit instances
Reference comparison of the RevCommit objects is OK; BlameGenerator uses
a single RevWalk which caches the RevCommits, so if a given commit is
cached the RevWalk will always return the same instance.
Factor the comparison out to a method, and suppress the warning with an
explanatory comment.
Change-Id: I5a148001dba7749ac15119aed388adb12b6f51ad
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java | 14 |
1 files changed, 12 insertions, 2 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 8794ca6cbe..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(); |