Don't aggressively coalesce across lines
Don't bother trying to coalesce over line boundaries when the
common region that contains the LF is less than 5 characters.
Its likely that the common region is actually a trailing "*/" or
"}" to close out the current statement. We are usually better off
reporting this as common to the user.
Bug: issue 473
Change-Id: I93762d07d34eb71269ea6758ac3466a5351f8dbf
Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListCacheImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListCacheImpl.java
index be4eaab..341873e 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListCacheImpl.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/patch/PatchListCacheImpl.java
@@ -246,9 +246,12 @@
int bb = c.getBeginB();
int be = n.getEndB();
- wordEdits.set(j, new Edit(ab, ae, bb, be));
- wordEdits.remove(j + 1);
- continue;
+ if (canCoalesce(a, c.getEndA(), n.getBeginA())
+ && canCoalesce(b, c.getEndB(), n.getBeginB())) {
+ wordEdits.set(j, new Edit(ab, ae, bb, be));
+ wordEdits.remove(j + 1);
+ continue;
+ }
}
j++;
@@ -367,6 +370,15 @@
return new PatchListEntry(fileHeader, edits);
}
+ private static boolean canCoalesce(CharText a, int b, int e) {
+ while (b < e) {
+ if (a.charAt(b++) == '\n') {
+ return false;
+ }
+ }
+ return true;
+ }
+
private static int findLF(List<Edit> edits, int j, CharText t, int b) {
int lf = b;
int limit = 0 < j ? edits.get(j - 1).getEndB() : 0;