Skip to content

Commit cb0eded

Browse files
mhaggergitster
authored andcommitted
xdl_change_compact(): only use heuristic if group can't be matched
If the changed group of lines can be matched to a group in the other file, then that positioning should take precedence over the compaction heuristic. The old code tried the heuristic unconditionally, which cost redundant effort and also was broken if the matching code had already shifted the group higher than the blank line. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent a8fd78c commit cb0eded

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

xdiff/xdiffi.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -504,25 +504,25 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
504504
}
505505
} while (grpsiz != ix - ixs);
506506

507-
/*
508-
* Try to move back the possibly merged group of changes, to match
509-
* the recorded position in the other file.
510-
*/
511-
while (ixref < ix) {
512-
rchg[--ixs] = 1;
513-
rchg[--ix] = 0;
514-
while (rchgo[--ixo]);
515-
}
516-
517-
/*
518-
* If a group can be moved back and forth, see if there is a
519-
* blank line in the moving space. If there is a blank line,
520-
* make sure the last blank line is the end of the group.
521-
*
522-
* As we already shifted the group forward as far as possible
523-
* in the earlier loop, we need to shift it back only if at all.
524-
*/
525-
if ((flags & XDF_COMPACTION_HEURISTIC) && blank_lines) {
507+
if (ixref < ix) {
508+
/*
509+
* Try to move back the possibly merged group of changes, to match
510+
* the recorded position in the other file.
511+
*/
512+
while (ixref < ix) {
513+
rchg[--ixs] = 1;
514+
rchg[--ix] = 0;
515+
while (rchgo[--ixo]);
516+
}
517+
} else if ((flags & XDF_COMPACTION_HEURISTIC) && blank_lines) {
518+
/*
519+
* The group can be slid up to make its last line a
520+
* blank line. Do so.
521+
*
522+
* As we already shifted the group forward as far as
523+
* possible in the earlier loop, we need to shift it
524+
* back only if at all.
525+
*/
526526
while (ixs > 0 &&
527527
!is_blank_line(recs, ix - 1, flags) &&
528528
recs_match(recs, ixs - 1, ix - 1, flags)) {

0 commit comments

Comments
 (0)