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
This commit is contained in:
Gustaf Lundh
2012-10-05 18:10:12 +02:00
parent 6bb9d0e90d
commit 2424a8a9d5
2 changed files with 13 additions and 4 deletions

View File

@@ -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:

View File

@@ -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<Edit> edits, Project.NameKey projectKey, ObjectId commit, String path) {
List<Edit> 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();
}
}