From 2424a8a9d595c87106db51da5867ed417eb8a2f5 Mon Sep 17 00:00:00 2001 From: Gustaf Lundh Date: Fri, 5 Oct 2012 18:10:12 +0200 Subject: [PATCH] File indentation is sometimes wrong in Side-By-Side To reproduce: 1. Change file indendation in a patch and push. 2. Set "Ignore Whitespace" to "All" in the Prefs. 3. Empty the diff_intraline cache. 4. View the patch using Side-By-Side. 5. Change Ignore Whitespace to "None" and update the page. 6. The lines with changed indentation are now fetched from the base, leading gerrit to display the wrong indentation on the right handed side. Issue due to diff_intraline cache does not account for changed whitespace settings, which will trick SparseFileContent.apply() to grab lines from left-side hunk when the line is not within the range of the right sided hunk. Bug: issue 816 Change-Id: I3b8c8a7aaf5d18696846d757722b3aaa4d04243e --- .../gerrit/httpd/rpc/patch/PatchScriptBuilder.java | 3 ++- .../gerrit/server/patch/IntraLineDiffKey.java | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptBuilder.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptBuilder.java index ad7746f619..816bbef6eb 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptBuilder.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchScriptBuilder.java @@ -147,7 +147,8 @@ class PatchScriptBuilder { } else if (diffPrefs.isIntralineDifference()) { IntraLineDiff d = patchListCache.getIntraLineDiff(new IntraLineDiffKey(a.id, a.src, - b.id, b.src, edits, projectKey, bId, b.path)); + b.id, b.src, edits, projectKey, bId, b.path, + diffPrefs.getIgnoreWhitespace() != Whitespace.IGNORE_NONE)); if (d != null) { switch (d.getStatus()) { case EDIT_LIST: diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/patch/IntraLineDiffKey.java b/gerrit-server/src/main/java/com/google/gerrit/server/patch/IntraLineDiffKey.java index 08af5e72e7..62ed5e4c14 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/patch/IntraLineDiffKey.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/patch/IntraLineDiffKey.java @@ -29,8 +29,9 @@ import java.io.Serializable; import java.util.List; public class IntraLineDiffKey implements Serializable { - static final long serialVersionUID = 3L; + static final long serialVersionUID = 4L; + private transient boolean ignoreWhitespace; private transient ObjectId aId; private transient ObjectId bId; @@ -45,7 +46,8 @@ public class IntraLineDiffKey implements Serializable { private transient String path; public IntraLineDiffKey(ObjectId aId, Text aText, ObjectId bId, Text bText, - List edits, Project.NameKey projectKey, ObjectId commit, String path) { + List edits, Project.NameKey projectKey, ObjectId commit, String path, + boolean ignoreWhitespace) { this.aId = aId; this.bId = bId; @@ -56,6 +58,8 @@ public class IntraLineDiffKey implements Serializable { this.projectKey = projectKey; this.commit = commit; this.path = path; + + this.ignoreWhitespace = ignoreWhitespace; } Text getTextA() { @@ -96,6 +100,7 @@ public class IntraLineDiffKey implements Serializable { h = h * 31 + aId.hashCode(); h = h * 31 + bId.hashCode(); + h = h * 31 + (ignoreWhitespace ? 1 : 0); return h; } @@ -105,7 +110,8 @@ public class IntraLineDiffKey implements Serializable { if (o instanceof IntraLineDiffKey) { final IntraLineDiffKey k = (IntraLineDiffKey) o; return aId.equals(k.aId) // - && bId.equals(k.bId); + && bId.equals(k.bId) // + && ignoreWhitespace == k.ignoreWhitespace; } return false; } @@ -127,10 +133,12 @@ public class IntraLineDiffKey implements Serializable { private void writeObject(final ObjectOutputStream out) throws IOException { writeNotNull(out, aId); writeNotNull(out, bId); + out.writeBoolean(ignoreWhitespace); } private void readObject(final ObjectInputStream in) throws IOException { aId = readNotNull(in); bId = readNotNull(in); + ignoreWhitespace = in.readBoolean(); } }