From patchwork Thu Aug 24 20:54:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13364691 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0A1BEE49A0 for ; Thu, 24 Aug 2023 20:56:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243618AbjHXUzc (ORCPT ); Thu, 24 Aug 2023 16:55:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243600AbjHXUzD (ORCPT ); Thu, 24 Aug 2023 16:55:03 -0400 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DA93199F for ; Thu, 24 Aug 2023 13:55:01 -0700 (PDT) Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 63A0D1A0E6C; Thu, 24 Aug 2023 16:54:59 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=VcpTRbsLL8LxA6piqJv/JztIS RoLkFjv7IPzC/QLXSs=; b=AAZc1PMFbhcPNOxCIKRG1m6ewOt/3VDKl0gBXG4Py 13pw+g0LLzZllFQ4dC3UwwT2n7sIcC2dI9ZgtIqyG8ulqvfD+uaFSZZ9w+DrU4ZB vwzK0TnhZXFTmGrNML5aXCyQSoxiXXLSNrAeiuFqls2HZJ+2rPs3hLeaDZXh9zVp x0= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 5C3951A0E6B; Thu, 24 Aug 2023 16:54:59 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [35.185.212.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id BA4AD1A0E6A; Thu, 24 Aug 2023 16:54:58 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano 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 Message-ID: <20230824205456.1231371-2-gitster@pobox.com> X-Mailer: git-send-email 2.42.0-29-gcd9da15a85 In-Reply-To: <20230824205456.1231371-1-gitster@pobox.com> References: <20230824205456.1231371-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 7CAB08E6-42C0-11EE-BF88-25B3960A682E-77302942!pb-smtp2.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- 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; } From patchwork Thu Aug 24 20:54:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13364693 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F046EE49A6 for ; Thu, 24 Aug 2023 20:56:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243624AbjHXUzd (ORCPT ); Thu, 24 Aug 2023 16:55:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243601AbjHXUzE (ORCPT ); Thu, 24 Aug 2023 16:55:04 -0400 Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D34DC1993 for ; Thu, 24 Aug 2023 13:55:02 -0700 (PDT) Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id DDA061AB4F1; Thu, 24 Aug 2023 16:55:01 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=20eAVldOeq8tMGTOgnR9vhish saUKZGgjFLPb9RIl6s=; b=qIlmTr05FtLbqnQpMGriyuWZVTS2gL6qkrRtKaqvu EbbiucdBwAFRaKh/jFhQrMq2RS+qFcuHSNx2sqhOmslwksjYhEmJw6U6kpzY5Iyv pUjHAt9IvouFlMYD0d73ubO1JsPmAfvN5VX8OqsWf1G38xiCnBhz9gMY412dgwAJ ME= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 91FE41AB4EF; Thu, 24 Aug 2023 16:55:01 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [35.185.212.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 4E8AA1AB4EE; Thu, 24 Aug 2023 16:55:00 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Cc: Thomas Gummerer Subject: [PATCH 2/4] rerere: fix comment on handle_file() helper Date: Thu, 24 Aug 2023 13:54:54 -0700 Message-ID: <20230824205456.1231371-3-gitster@pobox.com> X-Mailer: git-send-email 2.42.0-29-gcd9da15a85 In-Reply-To: <20230824205456.1231371-1-gitster@pobox.com> References: <20230824205456.1231371-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 7D99244A-42C0-11EE-A72E-78DCEB2EC81B-77302942!pb-smtp1.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The return value from handle_path() is returned to the caller of handle_file() in the normal cases, and it is not the number of hunks. It is just a normal C Boolean, "do we (!=0) or do we not (0) have conflict?" plus "a negative return value signals an error". And all the callers of handle_file() understands its return value as such. Update the comment to match the reality after 221444f5 (rerere: only return whether a path has conflicts or not, 2018-08-05), which apparently forgot to update this comment when it turned the returned value of this function from the number of conflict hunks to a boolean plus error. Signed-off-by: Junio C Hamano --- cc: Thomas Gummerer --- rerere.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rerere.c b/rerere.c index 73cdc8392f..4ce1270a94 100644 --- a/rerere.c +++ b/rerere.c @@ -454,7 +454,7 @@ static int handle_path(unsigned char *hash, struct rerere_io *io, int marker_siz /* * Scan the path for conflicts, do the "handle_path()" thing above, and - * return the number of conflict hunks found. + * return true iff conflict hunks were found. */ static int handle_file(struct index_state *istate, const char *path, unsigned char *hash, const char *output) From patchwork Thu Aug 24 20:54:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13364690 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3809EE49AB for ; Thu, 24 Aug 2023 20:56:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243626AbjHXUze (ORCPT ); Thu, 24 Aug 2023 16:55:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243606AbjHXUzI (ORCPT ); Thu, 24 Aug 2023 16:55:08 -0400 Received: from pb-smtp20.pobox.com (pb-smtp20.pobox.com [173.228.157.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4709A1993 for ; Thu, 24 Aug 2023 13:55:06 -0700 (PDT) Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id D152031529; Thu, 24 Aug 2023 16:55:05 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=yCruabo+UPctXf4ahL2oJ5XQX eQxw8aF3LVd7MXaA4g=; b=CgEeZ7rgCbmbxriBu9dXWrL2z2hKRxUKnhLUtMjAe kv/y8uT/UvJtkeGMekRfjCzuW3wbzTawnRQbDm+kaN39iBlv9FFgU+KhsF7jrA7A 24A5wfgxCnLXJGh26pvW38ilVBRMpM8mZQJqoi/Zb5/0jYYD3RiSmNjR0pwTeDtH As= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id C94CB31528; Thu, 24 Aug 2023 16:55:05 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [35.185.212.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 3DA8C31526; Thu, 24 Aug 2023 16:55:02 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 3/4] rerere: try_merge() should use LL_MERGE_ERROR when it means an error Date: Thu, 24 Aug 2023 13:54:55 -0700 Message-ID: <20230824205456.1231371-4-gitster@pobox.com> X-Mailer: git-send-email 2.42.0-29-gcd9da15a85 In-Reply-To: <20230824205456.1231371-1-gitster@pobox.com> References: <20230824205456.1231371-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 7EBF9C14-42C0-11EE-BB53-F515D2CDFF5E-77302942!pb-smtp20.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When the preimage or the postimage files cannot be read, the try_merge() helper function returns LL_MERGE_CONFLICT. To all of its callers, this does not make them do wrong things per-se, as they are only checking if the result is 0 and LL_MERGE_CONFLICT is not 0. But it is an error if we fail to read the input we expect to be able to read; return LL_MERGE_ERROR instead. This does not change any behaviour---it just makes the code use the "correct" constant to signal an error. Signed-off-by: Junio C Hamano --- rerere.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rerere.c b/rerere.c index 4ce1270a94..6bc3c54d3b 100644 --- a/rerere.c +++ b/rerere.c @@ -617,7 +617,7 @@ static int try_merge(struct index_state *istate, if (read_mmfile(&base, rerere_path(id, "preimage")) || read_mmfile(&other, rerere_path(id, "postimage"))) { - ret = LL_MERGE_CONFLICT; + ret = LL_MERGE_ERROR; } else { /* * A three-way merge. Note that this honors user-customizable From patchwork Thu Aug 24 20:54:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13364692 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40B94EE49AD for ; Thu, 24 Aug 2023 20:56:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243628AbjHXUze (ORCPT ); Thu, 24 Aug 2023 16:55:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243593AbjHXUzL (ORCPT ); Thu, 24 Aug 2023 16:55:11 -0400 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE49D1993 for ; Thu, 24 Aug 2023 13:55:09 -0700 (PDT) Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 429F22417C; Thu, 24 Aug 2023 16:55:09 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=Ad2bjH9uiJyr45Ow8nRPtmckC N5Il0G4IL6oemKB8Ws=; b=w81Ds/FyYt+3UUE+Bz8tV9t95zIkHRlSICR8xlO1d A7hIR6B2IoFIv1VMU9i3Fs1RWbU4Tc+Dqs7PvdetKlWIVMjVrjVQmqBtCUbTIEIk +D+d5cVow0GvD6DJomPeI0zRFO9nZJHo9t5d8Khg1XZLVisyHd9n68F5MSdqou0m Oo= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 3AE392417B; Thu, 24 Aug 2023 16:55:09 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [35.185.212.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id BA9F02417A; Thu, 24 Aug 2023 16:55:05 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 4/4] rerere: modernize use of empty strbuf Date: Thu, 24 Aug 2023 13:54:56 -0700 Message-ID: <20230824205456.1231371-5-gitster@pobox.com> X-Mailer: git-send-email 2.42.0-29-gcd9da15a85 In-Reply-To: <20230824205456.1231371-1-gitster@pobox.com> References: <20230824205456.1231371-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 80D6F074-42C0-11EE-B79A-A19503B9AAD1-77302942!pb-smtp21.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Back when the code in the handle_conflict() helper function that hashes the contents stored in the strbuf "one" and "two", including its terminating NUL, was written, a freshly initialized strbuf had NULL in its .buf member, so it was an error to say update(one.buf, one.len + 1) which was corrected by b4833a2c (rerere: Fix use of an empty strbuf.buf, 2007-09-26). But soon after that, b315c5c0 (strbuf change: be sure ->buf is never ever NULL., 2007-09-27) introduced strbuf_slopbuf mechanism that ensures that .buf member of a strbuf is *never* NULL. A freshly initialized and empty strbuf uses a static piece of memory that has NUL in it, with its .len member set to 0, so we can always safely use from offset 0 of .buf[] array for (one.len + 1) bytes. Simplify the code by essentially reverting the b4833a2c, whose fix is no longer necessary in the modern world order. Signed-off-by: Junio C Hamano --- rerere.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/rerere.c b/rerere.c index 6bc3c54d3b..69a61aac93 100644 --- a/rerere.c +++ b/rerere.c @@ -390,12 +390,8 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io, strbuf_addbuf(out, &two); rerere_strbuf_putconflict(out, '>', marker_size); if (ctx) { - the_hash_algo->update_fn(ctx, one.buf ? - one.buf : "", - one.len + 1); - the_hash_algo->update_fn(ctx, two.buf ? - two.buf : "", - two.len + 1); + the_hash_algo->update_fn(ctx, one.buf, one.len + 1); + the_hash_algo->update_fn(ctx, two.buf, two.len + 1); } break; } else if (hunk == RR_SIDE_1)