git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 1/4] rerere: simplify check_one_conflict() helper function
Date: Thu, 24 Aug 2023 13:54:53 -0700	[thread overview]
Message-ID: <20230824205456.1231371-2-gitster@pobox.com> (raw)
In-Reply-To: <20230824205456.1231371-1-gitster@pobox.com>

The helper function is responsible for inspecting the index and
deciding if the path is merged, is conflicted in a way that we would
want to handle, or is conflicted in a way that we cannot handle.

Currently, only conflicts with both stage #2 and stage #3 are
handled, but eventually we would want to be able to deal with
delete-modify conflicts (i.e. only one of stages #2 and #3 exist).
Streamline the implementation of the function to make it easier to
extend.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 rerere.c | 34 +++++++++++++++-------------------
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/rerere.c b/rerere.c
index b525dd9230..73cdc8392f 100644
--- a/rerere.c
+++ b/rerere.c
@@ -499,9 +499,11 @@ static int handle_file(struct index_state *istate,
 }
 
 /*
- * Look at a cache entry at "i" and see if it is not conflicting,
- * conflicting and we are willing to handle, or conflicting and
- * we are unable to handle, and return the determination in *type.
+ * Look at a cache entry at "i" and see if it is not conflicting
+ * (RESOLVED), conflicting and we are willing to handle (THREE_STAGED),
+ * or conflicting and we are unable to handle (PUNTED), and return the
+ * determination in *type.
+ *
  * Return the cache index to be looked at next, by skipping the
  * stages we have already looked at in this invocation of this
  * function.
@@ -509,6 +511,7 @@ static int handle_file(struct index_state *istate,
 static int check_one_conflict(struct index_state *istate, int i, int *type)
 {
 	const struct cache_entry *e = istate->cache[i];
+	unsigned int seen_stages = 0;
 
 	if (!ce_stage(e)) {
 		*type = RESOLVED;
@@ -516,24 +519,17 @@ static int check_one_conflict(struct index_state *istate, int i, int *type)
 	}
 
 	*type = PUNTED;
-	while (i < istate->cache_nr && ce_stage(istate->cache[i]) == 1)
-		i++;
-
-	/* Only handle regular files with both stages #2 and #3 */
-	if (i + 1 < istate->cache_nr) {
-		const struct cache_entry *e2 = istate->cache[i];
-		const struct cache_entry *e3 = istate->cache[i + 1];
-		if (ce_stage(e2) == 2 &&
-		    ce_stage(e3) == 3 &&
-		    ce_same_name(e, e3) &&
-		    S_ISREG(e2->ce_mode) &&
-		    S_ISREG(e3->ce_mode))
-			*type = THREE_STAGED;
+	for (; i < istate->cache_nr; i++) {
+		const struct cache_entry *n = istate->cache[i];
+		if (!ce_same_name(n, e))
+			break;
+		if (S_ISREG(n->ce_mode))
+			seen_stages |= 1u << (ce_stage(n) - 1);
 	}
 
-	/* Skip the entries with the same name */
-	while (i < istate->cache_nr && ce_same_name(e, istate->cache[i]))
-		i++;
+	if ((seen_stages & 6) == 6)
+		*type = THREE_STAGED; /* has both stages #2 and #3 */
+
 	return i;
 }
 
-- 
2.42.0-29-gcd9da15a85


  reply	other threads:[~2023-08-24 20:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-24 20:54 [PATCH 0/4] code clean-up for rerere Junio C Hamano
2023-08-24 20:54 ` Junio C Hamano [this message]
2023-08-24 20:54 ` [PATCH 2/4] rerere: fix comment on handle_file() helper Junio C Hamano
2023-08-24 20:54 ` [PATCH 3/4] rerere: try_merge() should use LL_MERGE_ERROR when it means an error Junio C Hamano
2023-08-24 20:54 ` [PATCH 4/4] rerere: modernize use of empty strbuf 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=20230824205456.1231371-2-gitster@pobox.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).