commit 450d9f6b216b7cdde9e4079e0db459d3bd2caa0d from: Mark Jamsek via: Thomas Adam date: Mon Feb 20 16:18:17 2023 UTC use chunk offset to efficiently detect conflict markers Rather than skip lines, use the new diff APIs to directly seek to each chunk with newly added lines for more efficient conflict marker detection. ok stsp@ commit - db9ae6560f9f90548b4e4d4d69f372b51f869792 commit + 450d9f6b216b7cdde9e4079e0db459d3bd2caa0d blob - 89e894cb419ae5b35cd91c980ca7cc01cdc1f048 blob + 8bba5c9f9469a7fe3ccbd275bbcb22c0ad909f0b --- lib/worktree.c +++ lib/worktree.c @@ -1555,16 +1555,12 @@ get_modified_file_content_status(unsigned char *status if (err) goto done; - if (fseek(ondisk_file, 0L, SEEK_SET) == -1) { - err = got_ferror(ondisk_file, GOT_ERR_IO); - goto done; - } - r = diffreg_result->result; for (n = 0; n < r->chunks.len; n += nchunks_parsed) { struct diff_chunk *c; struct diff_chunk_context cc = {}; + off_t pos; int clc, crc; /* @@ -1575,20 +1571,20 @@ get_modified_file_content_status(unsigned char *status clc = diff_chunk_get_left_count(c); crc = diff_chunk_get_right_count(c); - if (!crc && clc) { + if (!crc || crc == clc) { nchunks_parsed = 1; - continue; /* removed lines */ + continue; /* removed or unchanged lines */ } - diff_chunk_context_load_change(&cc, &nchunks_parsed, r, n, 0); - - while (ln < cc.right.start) { - err = skip_one_line(ondisk_file); - if (err) - goto done; - ++ln; + pos = diff_chunk_get_right_start_pos(c); + if (fseek(ondisk_file, pos, SEEK_SET) == -1) { + err = got_ferror(ondisk_file, GOT_ERR_IO); + goto done; } + diff_chunk_context_load_change(&cc, &nchunks_parsed, r, n, 0); + ln = cc.right.start; + while (ln < cc.right.end) { linelen = getline(&line, &linesize, ondisk_file); if (linelen == -1) {