From patchwork Thu Sep 14 09:39:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 13384932 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 3B5D7EDE99C for ; Thu, 14 Sep 2023 09:42:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237585AbjINJmX (ORCPT ); Thu, 14 Sep 2023 05:42:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237181AbjINJmJ (ORCPT ); Thu, 14 Sep 2023 05:42:09 -0400 Received: from cloud.peff.net (cloud.peff.net [104.130.231.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2A3C59E2 for ; Thu, 14 Sep 2023 02:39:49 -0700 (PDT) Received: (qmail 27321 invoked by uid 109); 14 Sep 2023 09:39:49 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Thu, 14 Sep 2023 09:39:49 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 21299 invoked by uid 111); 14 Sep 2023 09:39:51 -0000 Received: from coredump.intra.peff.net (HELO coredump.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Thu, 14 Sep 2023 05:39:51 -0400 Authentication-Results: peff.net; auth=none Date: Thu, 14 Sep 2023 05:39:48 -0400 From: Jeff King To: git@vger.kernel.org Cc: Elijah Newren Subject: [PATCH 1/4] merge-ort: drop custom err() function Message-ID: <20230914093948.GA2254894@coredump.intra.peff.net> References: <20230914093409.GA2254811@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230914093409.GA2254811@coredump.intra.peff.net> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The merge-ort code has an err() function, but it's really just error() in disguise. It differs in two ways: 1. It takes a "struct merge_options" argument. But the function completely ignores it! We can simply remove it. 2. It formats the error string into a strbuf, prepending "error: ", and then feeds the result into error(). But this is wrong! The error() function already adds the prefix, so we end up with: error: error: Failed to execute internal merge So let's just drop this function entirely and call error() directly, as the functions are otherwise identical (note that they both always return -1). Presumably nobody noticed the bogus messages because they are quite hard to trigger (they are mostly internal errors reading and writing objects). However, one easy trigger is a custom merge driver which dies by signal; we have a test already here, but we were not checking the contents of stderr. Signed-off-by: Jeff King --- A few of these messages starts with capital letters, which is unlike our usual error message style. I didn't clean that up here. We could do so on top, but I actually wonder if some of these ought to be using path_msg() and continuing instead, to give output closer to other conflict or error cases (e.g., conflicts caused by missing submodule objects). But I dunno. I guess these are all more clearly "woah, something is totally wrong" that we do not expect to happen, so it probably isn't a big deal to just abort. merge-ort.c | 28 +++++----------------------- t/t6406-merge-attr.sh | 3 ++- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 8631c99700..027ecc7f78 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -721,23 +721,6 @@ static void clear_or_reinit_internal_opts(struct merge_options_internal *opti, renames->callback_data_nr = renames->callback_data_alloc = 0; } -__attribute__((format (printf, 2, 3))) -static int err(struct merge_options *opt, const char *err, ...) -{ - va_list params; - struct strbuf sb = STRBUF_INIT; - - strbuf_addstr(&sb, "error: "); - va_start(params, err); - strbuf_vaddf(&sb, err, params); - va_end(params); - - error("%s", sb.buf); - strbuf_release(&sb); - - return -1; -} - static void format_commit(struct strbuf *sb, int indent, struct repository *repo, @@ -2122,13 +2105,12 @@ static int handle_content_merge(struct merge_options *opt, &result_buf); if ((merge_status < 0) || !result_buf.ptr) - ret = err(opt, _("Failed to execute internal merge")); + ret = error(_("Failed to execute internal merge")); if (!ret && write_object_file(result_buf.ptr, result_buf.size, OBJ_BLOB, &result->oid)) - ret = err(opt, _("Unable to add %s to database"), - path); + ret = error(_("Unable to add %s to database"), path); free(result_buf.ptr); if (ret) @@ -3518,10 +3500,10 @@ static int read_oid_strbuf(struct merge_options *opt, unsigned long size; buf = repo_read_object_file(the_repository, oid, &type, &size); if (!buf) - return err(opt, _("cannot read object %s"), oid_to_hex(oid)); + return error(_("cannot read object %s"), oid_to_hex(oid)); if (type != OBJ_BLOB) { free(buf); - return err(opt, _("object %s is not a blob"), oid_to_hex(oid)); + return error(_("object %s is not a blob"), oid_to_hex(oid)); } strbuf_attach(dst, buf, size, size + 1); return 0; @@ -4973,7 +4955,7 @@ static void merge_ort_nonrecursive_internal(struct merge_options *opt, * TRANSLATORS: The %s arguments are: 1) tree hash of a merge * base, and 2-3) the trees for the two trees we're merging. */ - err(opt, _("collecting merge info failed for trees %s, %s, %s"), + error(_("collecting merge info failed for trees %s, %s, %s"), oid_to_hex(&merge_base->object.oid), oid_to_hex(&side1->object.oid), oid_to_hex(&side2->object.oid)); diff --git a/t/t6406-merge-attr.sh b/t/t6406-merge-attr.sh index 9677180a5b..05ad13b23e 100755 --- a/t/t6406-merge-attr.sh +++ b/t/t6406-merge-attr.sh @@ -179,7 +179,8 @@ test_expect_success !WINDOWS 'custom merge driver that is killed with a signal' >./please-abort && echo "* merge=custom" >.gitattributes && - test_must_fail git merge main && + test_must_fail git merge main 2>err && + grep "^error: Failed to execute internal merge" err && git ls-files -u >output && git diff --name-only HEAD >>output && test_must_be_empty output From patchwork Thu Sep 14 09:39:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 13384933 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 289B5EDE99C for ; Thu, 14 Sep 2023 09:42:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237725AbjINJms (ORCPT ); Thu, 14 Sep 2023 05:42:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237761AbjINJme (ORCPT ); Thu, 14 Sep 2023 05:42:34 -0400 Received: from cloud.peff.net (cloud.peff.net [104.130.231.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33E7661AE for ; Thu, 14 Sep 2023 02:39:54 -0700 (PDT) Received: (qmail 27327 invoked by uid 109); 14 Sep 2023 09:39:53 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Thu, 14 Sep 2023 09:39:53 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 21307 invoked by uid 111); 14 Sep 2023 09:39:56 -0000 Received: from coredump.intra.peff.net (HELO coredump.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Thu, 14 Sep 2023 05:39:56 -0400 Authentication-Results: peff.net; auth=none Date: Thu, 14 Sep 2023 05:39:53 -0400 From: Jeff King To: git@vger.kernel.org Cc: Elijah Newren Subject: [PATCH 2/4] merge-ort: stop passing "opt" to read_oid_strbuf() Message-ID: <20230914093953.GB2254894@coredump.intra.peff.net> References: <20230914093409.GA2254811@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230914093409.GA2254811@coredump.intra.peff.net> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This function doesn't look at its merge_options parameter. It used to pass it down to err(), but that function no longer exists (and didn't look at "opt" anyway). We can drop it here. Signed-off-by: Jeff King --- merge-ort.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 027ecc7f78..31c663b297 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -3491,8 +3491,7 @@ static int sort_dirs_next_to_their_children(const char *one, const char *two) return c1 - c2; } -static int read_oid_strbuf(struct merge_options *opt, - const struct object_id *oid, +static int read_oid_strbuf(const struct object_id *oid, struct strbuf *dst) { void *buf; @@ -3527,8 +3526,8 @@ static int blob_unchanged(struct merge_options *opt, if (oideq(&base->oid, &side->oid)) return 1; - if (read_oid_strbuf(opt, &base->oid, &basebuf) || - read_oid_strbuf(opt, &side->oid, &sidebuf)) + if (read_oid_strbuf(&base->oid, &basebuf) || + read_oid_strbuf(&side->oid, &sidebuf)) goto error_return; /* * Note: binary | is used so that both renormalizations are From patchwork Thu Sep 14 09:39:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 13384934 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 78DFAEDE9A0 for ; Thu, 14 Sep 2023 09:43:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237922AbjINJnE (ORCPT ); Thu, 14 Sep 2023 05:43:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237855AbjINJms (ORCPT ); Thu, 14 Sep 2023 05:42:48 -0400 Received: from cloud.peff.net (cloud.peff.net [104.130.231.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CC7726B2 for ; Thu, 14 Sep 2023 02:40:00 -0700 (PDT) Received: (qmail 27333 invoked by uid 109); 14 Sep 2023 09:39:59 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Thu, 14 Sep 2023 09:39:59 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 21330 invoked by uid 111); 14 Sep 2023 09:40:01 -0000 Received: from coredump.intra.peff.net (HELO coredump.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Thu, 14 Sep 2023 05:40:01 -0400 Authentication-Results: peff.net; auth=none Date: Thu, 14 Sep 2023 05:39:58 -0400 From: Jeff King To: git@vger.kernel.org Cc: Elijah Newren Subject: [PATCH 3/4] merge-ort: drop unused parameters from detect_and_process_renames() Message-ID: <20230914093958.GC2254894@coredump.intra.peff.net> References: <20230914093409.GA2254811@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230914093409.GA2254811@coredump.intra.peff.net> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This function takes three trees representing the merge base and both sides of the merge, but never looks at any of them. This is due to f78cf97617 (merge-ort: call diffcore_rename() directly, 2021-02-14). Prior to that commit, we passed pairs of trees to diff_tree_oid(). But after that commit, we collect a custom diff_queue for each pair in the merge_options struct, and just run diffcore_rename() on the result. So the function does not need to know about the original trees at all anymore. Signed-off-by: Jeff King --- merge-ort.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 31c663b297..20eefd9b5e 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -3324,10 +3324,7 @@ static int collect_renames(struct merge_options *opt, return clean; } -static int detect_and_process_renames(struct merge_options *opt, - struct tree *merge_base, - struct tree *side1, - struct tree *side2) +static int detect_and_process_renames(struct merge_options *opt) { struct diff_queue_struct combined = { 0 }; struct rename_info *renames = &opt->priv->renames; @@ -4964,8 +4961,7 @@ static void merge_ort_nonrecursive_internal(struct merge_options *opt, trace2_region_leave("merge", "collect_merge_info", opt->repo); trace2_region_enter("merge", "renames", opt->repo); - result->clean = detect_and_process_renames(opt, merge_base, - side1, side2); + result->clean = detect_and_process_renames(opt); trace2_region_leave("merge", "renames", opt->repo); if (opt->priv->renames.redo_after_renames == 2) { trace2_region_enter("merge", "reset_maps", opt->repo); From patchwork Thu Sep 14 09:40:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 13384935 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 4D158EDE99E for ; Thu, 14 Sep 2023 09:43:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237847AbjINJnU (ORCPT ); Thu, 14 Sep 2023 05:43:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237853AbjINJnB (ORCPT ); Thu, 14 Sep 2023 05:43:01 -0400 Received: from cloud.peff.net (cloud.peff.net [104.130.231.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DFAF2712 for ; Thu, 14 Sep 2023 02:40:05 -0700 (PDT) Received: (qmail 27339 invoked by uid 109); 14 Sep 2023 09:40:05 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Thu, 14 Sep 2023 09:40:05 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 21334 invoked by uid 111); 14 Sep 2023 09:40:07 -0000 Received: from coredump.intra.peff.net (HELO coredump.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Thu, 14 Sep 2023 05:40:07 -0400 Authentication-Results: peff.net; auth=none Date: Thu, 14 Sep 2023 05:40:04 -0400 From: Jeff King To: git@vger.kernel.org Cc: Elijah Newren Subject: [PATCH 4/4] merge-ort: drop unused "opt" parameter from merge_check_renames_reusable() Message-ID: <20230914094004.GD2254894@coredump.intra.peff.net> References: <20230914093409.GA2254811@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230914093409.GA2254811@coredump.intra.peff.net> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The merge_options parameter has never been used since the function was introduced in 64aceb6d73 (merge-ort: add code to check for whether cached renames can be reused, 2021-05-20). In theory some merge options might impact our decisions here, but that has never been the case so far. Let's drop it to appease -Wunused-parameter; it would be easy to add back later if we need to (there is only one caller). Signed-off-by: Jeff King --- merge-ort.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 20eefd9b5e..3953c9f745 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -4880,8 +4880,7 @@ static void merge_start(struct merge_options *opt, struct merge_result *result) trace2_region_leave("merge", "allocate/init", opt->repo); } -static void merge_check_renames_reusable(struct merge_options *opt, - struct merge_result *result, +static void merge_check_renames_reusable(struct merge_result *result, struct tree *merge_base, struct tree *side1, struct tree *side2) @@ -5083,7 +5082,7 @@ void merge_incore_nonrecursive(struct merge_options *opt, trace2_region_enter("merge", "merge_start", opt->repo); assert(opt->ancestor != NULL); - merge_check_renames_reusable(opt, result, merge_base, side1, side2); + merge_check_renames_reusable(result, merge_base, side1, side2); merge_start(opt, result); /* * Record the trees used in this merge, so if there's a next merge in From patchwork Sat Sep 16 06:00:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 13388129 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 6ADEECD37B5 for ; Sat, 16 Sep 2023 06:01:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238357AbjIPGBY (ORCPT ); Sat, 16 Sep 2023 02:01:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238744AbjIPGBK (ORCPT ); Sat, 16 Sep 2023 02:01:10 -0400 Received: from cloud.peff.net (cloud.peff.net [104.130.231.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B04A1BEE for ; Fri, 15 Sep 2023 23:01:01 -0700 (PDT) Received: (qmail 1598 invoked by uid 109); 16 Sep 2023 06:01:00 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Sat, 16 Sep 2023 06:01:00 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 9142 invoked by uid 111); 16 Sep 2023 06:01:02 -0000 Received: from coredump.intra.peff.net (HELO coredump.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Sat, 16 Sep 2023 02:01:02 -0400 Authentication-Results: peff.net; auth=none Date: Sat, 16 Sep 2023 02:00:59 -0400 From: Jeff King To: git@vger.kernel.org Cc: Elijah Newren , Junio C Hamano Subject: [PATCH 5/4] merge-ort: lowercase a few error messages Message-ID: <20230916060059.GA498798@coredump.intra.peff.net> References: <20230914093409.GA2254811@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230914093409.GA2254811@coredump.intra.peff.net> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Thu, Sep 14, 2023 at 05:34:09AM -0400, Jeff King wrote: > A few small cleanups for merge-ort collected from playing with > -Wunused-parameter. The first one actually fixes a user-visible bug, and > the rest are just cleanups. > > [1/4]: merge-ort: drop custom err() function > [2/4]: merge-ort: stop passing "opt" to read_oid_strbuf() > [3/4]: merge-ort: drop unused parameters from detect_and_process_renames() > [4/4]: merge-ort: drop unused "opt" parameter from merge_check_renames_reusable() Here's one more clean-up on top. I hesitated on this for the initial send just because I didn't know if we might want to switch these error messages to path_msg(), which does capitalize sometimes. But Elijah's response convinced me that we should just leave them in place, in which case it makes sense to do a minimal style fixup. Junio, this is on top of what you've queued in jk/ort-unused-parameter-cleanups. -- >8 -- Subject: [PATCH] merge-ort: lowercase a few error messages As noted in CodingGuidelines, error messages should not be capitalized. Fix up a few of these that were copied verbatim from merge-recursive to match our modern style. Signed-off-by: Jeff King Signed-off-by: Jeff King --- merge-ort.c | 4 ++-- t/t6406-merge-attr.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 3953c9f745..7857ce9fbd 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -2105,12 +2105,12 @@ static int handle_content_merge(struct merge_options *opt, &result_buf); if ((merge_status < 0) || !result_buf.ptr) - ret = error(_("Failed to execute internal merge")); + ret = error(_("failed to execute internal merge")); if (!ret && write_object_file(result_buf.ptr, result_buf.size, OBJ_BLOB, &result->oid)) - ret = error(_("Unable to add %s to database"), path); + ret = error(_("unable to add %s to database"), path); free(result_buf.ptr); if (ret) diff --git a/t/t6406-merge-attr.sh b/t/t6406-merge-attr.sh index 05ad13b23e..72f8c1722f 100755 --- a/t/t6406-merge-attr.sh +++ b/t/t6406-merge-attr.sh @@ -180,7 +180,7 @@ test_expect_success !WINDOWS 'custom merge driver that is killed with a signal' >./please-abort && echo "* merge=custom" >.gitattributes && test_must_fail git merge main 2>err && - grep "^error: Failed to execute internal merge" err && + grep "^error: failed to execute internal merge" err && git ls-files -u >output && git diff --name-only HEAD >>output && test_must_be_empty output