diff options
author | Edwin Kempin <ekempin@google.com> | 2016-09-12 16:05:40 +0200 |
---|---|---|
committer | Edwin Kempin <ekempin@google.com> | 2016-09-13 09:36:37 +0000 |
commit | ef353fedd20069b79844e2d2122b926a80685a46 (patch) | |
tree | 36b3e69a945ee4da688aa3f54699f89182e40b28 | |
parent | f6fd4558fcd3faf10fdf335e1d7465fab558a298 (diff) |
PatchListLoader: Fix againstParent computation
When a commit is compared against its parent, we want to show the
complete commit message as new in the diff screen (diffing the commit
message of the viewed commit with the commit message of the parent
commit does not make sense). To detect this case PatchListLoader sets
the againstParent flag.
Until recently we only supported comparing commits against the first
parent and hence the againstParent flag was only set if a comparison
against the first parent was done. Consider all parents now.
Change-Id: I29f2cae6f302cc173aa4bb6b3081f4f894007780
Signed-off-by: Edwin Kempin <ekempin@google.com>
-rw-r--r-- | gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListKey.java | 2 | ||||
-rw-r--r-- | gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListLoader.java | 13 |
2 files changed, 12 insertions, 3 deletions
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListKey.java b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListKey.java index 961ed5c423..43e3dcec09 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListKey.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListKey.java @@ -35,7 +35,7 @@ import java.io.Serializable; import java.util.Objects; public class PatchListKey implements Serializable { - public static final long serialVersionUID = 21L; + public static final long serialVersionUID = 22L; public static final BiMap<Whitespace, Character> WHITESPACE_TYPES = ImmutableBiMap.of( Whitespace.IGNORE_NONE, 'N', diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListLoader.java b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListLoader.java index faeaaf22d1..2fa43bb0fd 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListLoader.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListLoader.java @@ -162,8 +162,7 @@ public class PatchListLoader implements Callable<PatchList> { return new PatchList(a, b, true, entries); } - boolean againstParent = - b.getParentCount() > 0 && b.getParent(0).equals(a); + boolean againstParent = isAgainstParent(a, b); RevCommit aCommit = a instanceof RevCommit ? (RevCommit) a : null; RevTree aTree = rw.parseTree(a); @@ -214,6 +213,16 @@ public class PatchListLoader implements Callable<PatchList> { } } + private boolean isAgainstParent(RevObject a, RevCommit b) { + for (int i = 0; i < b.getParentCount(); i++) { + if (b.getParent(i).equals(a)) { + return true; + } + } + + return false; + } + private static long getFileSize(ObjectReader reader, FileMode mode, String path, RevTree t) throws IOException { if (!isBlob(mode)) { |