All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: Re: [PATCH 3/4] add: introduce '--resolved' option
Date: Wed, 29 Jul 2026 08:01:33 -0700	[thread overview]
Message-ID: <xmqqse51algy.fsf@gitster.g> (raw)
In-Reply-To: <20260728215219.753678-4-gitster@pobox.com> (Junio C. Hamano's message of "Tue, 28 Jul 2026 14:52:18 -0700")

Junio C Hamano <gitster@pobox.com> 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


  parent reply	other threads:[~2026-07-29 15:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28 21:52 [PATCH 0/4] git add --resolved Junio C Hamano
2026-07-28 21:52 ` [PATCH 1/4] merge-ll: consolidate conflict marker scanning logic Junio C Hamano
2026-07-28 21:52 ` [PATCH 2/4] read-cache: add remove_file_from_index_with_flags() Junio C Hamano
2026-07-28 21:52 ` [PATCH 3/4] add: introduce '--resolved' option Junio C Hamano
2026-07-29  3:28   ` Michael Montalbo
2026-07-29 13:43     ` Junio C Hamano
2026-07-29 13:49       ` Junio C Hamano
2026-07-29 15:01   ` Junio C Hamano [this message]
2026-07-28 21:52 ` [PATCH 4/4] read-cache: reindent Junio C Hamano
2026-07-29 17:25 ` [PATCH v2 0/4] git add --resolved Junio C Hamano
2026-07-29 17:25   ` [PATCH v2 1/4] read-cache: reindent Junio C Hamano
2026-07-29 17:25   ` [PATCH v2 2/4] merge-ll: consolidate conflict marker scanning logic Junio C Hamano
2026-07-29 17:25   ` [PATCH v2 3/4] read-cache: add remove_file_from_index_with_flags() Junio C Hamano
2026-07-29 17:25   ` [PATCH v2 4/4] add: introduce '--resolved' option Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqse51algy.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.