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>
This commit is contained in:
Shawn O. Pearce
2010-03-01 11:49:21 -08:00
parent c2f7f3e58a
commit 7bfcf9ac59

View File

@@ -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<Edit> edits, int j, CharText t, int b) {
int lf = b;
int limit = 0 < j ? edits.get(j - 1).getEndB() : 0;