From 7bfcf9ac59fa4895bf622382b7afc383a41e644f Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 1 Mar 2010 11:49:21 -0800 Subject: [PATCH] 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 --- .../server/patch/PatchListCacheImpl.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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 be4eaab5ce..341873ed28 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 @@ public class PatchListCacheImpl implements PatchListCache { 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 @@ public class PatchListCacheImpl implements PatchListCache { 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 edits, int j, CharText t, int b) { int lf = b; int limit = 0 < j ? edits.get(j - 1).getEndB() : 0;