Re: [PATCH 3/4] add: introduce '--resolved' option

Junio C Hamano <[email protected]> Wed, 29 Jul 2026 08:01:33 -0700
Newsgroups org.kernel.vger.git
Message-ID <[email protected]>
Junio C Hamano <[email protected]> writes:

> +
> +int has_conflict_markers(struct index_state *istate, const char *path)
> +{
> +	FILE *f;
> +	struct strbuf sb = STRBUF_INIT;
> +	int marker_size = ll_merge_marker_size(istate, path);
> +	int has_markers = 0;
> +
> +	f = fopen(path, "r");
> +	if (!f)
> +		return 0;
> +
> +	while (strbuf_getwholeline(&sb, f, '\n') != EOF) {
> +		if (is_conflict_marker_line(sb.buf, sb.len, marker_size)) {
> +			has_markers = 1;
> +			break;
> +		}
> +	}
> +	fclose(f);
> +	strbuf_release(&sb);
> +	return has_markers;
> +}

Left unchecked, this loop may end up scanning a large binary file to
the end in vain.  We may squeeze in something like this to punt
early.

 merge-ll.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/merge-ll.c b/merge-ll.c
index 5e5044b9e3..ef5287dee8 100644
--- a/merge-ll.c
+++ b/merge-ll.c
@@ -516,6 +516,9 @@ int has_conflict_markers(struct index_state *istate, const char *path)
 			has_markers = 1;
 			break;
 		}
+		if (buffer_is_binary(sb.buf,
+				     ULONG_MAX <= sb.len ? ULONG_MAX : sb.len))
+			break;
 	}
 	fclose(f);
 	strbuf_release(&sb);
-- 
2.55.0-609-g9a17695db7