From patchwork Tue Feb 13 08:41:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13554702 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2C5421A06 for ; Tue, 13 Feb 2024 08:41:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813714; cv=none; b=l9Sj3HJN060YS7VU2evCE4BsOwXovQNn2eBzWZqVU0ea1qkQPdvy82YaAk0wmLkSs/2PfuJQk38omeYMMbC93w8Lfho2o7ILJZgpTvjbsNzSzy+Zh0nvVGbSFOc8lw1T3y3dVWrRqf8YFfpbZYyk2wI0wM0iBosJGQ23IL5I5DU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813714; c=relaxed/simple; bh=maRSH6CdZ0quV4tjfMdY3X/x0x6ekaCEyHdN+5gSPNQ=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=i6vJ+jw7TehyNWkWY5NvYqQAUqXYZQLFrbcSEiCjQTuEAxi5NEgnPrFzR6pwNOimPqX2o1SfOuCCW4+p4GZk8X38iWGGt4BY85pkW5orOElB7DyQOJKekXiPv+gVQLAB7k/XC3VGEoaB4JUX/H4z3kRZPIo7tnVwvAtTU0KQj3g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KUFE6btg; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KUFE6btg" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-33b8807b55aso774647f8f.3 for ; Tue, 13 Feb 2024 00:41:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707813711; x=1708418511; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=G7TKBKP3jIBTZf2WQYt+2Te9xx/3veTpIXxjz+O2OTo=; b=KUFE6btgykpYUoQTG9Zg8f4kVYRwOovQ4ABC3JKSSkSGc6m5I5f+O960eRY1rji5M8 +SYOexlkpNf90cSwGkpKrvLO3yW2DodaJ/yZ3R6dXWbMVmJfAMwlJhk+n+vhBzLul/E+ bEx2mZsV4MC3EdgvoAMV76l6O4yTyyd7+EfNWn5ExO/djjBSsvbLQAAsLNGTlP0lTWrU qGrjcW0QbzeFBe2Gb8kOaeAEbx0oPyTcSU5BXCIShuXloah9rz2fv/3jaXJpViBFUvso ZbnsCB5VQz98GnyFsPi3L4yFn/d/Poy2X/cUv0/hWZsR9bl6kx7LHlIrSsqjYYENmnAs Nimw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707813711; x=1708418511; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G7TKBKP3jIBTZf2WQYt+2Te9xx/3veTpIXxjz+O2OTo=; b=nYmVG4e4/UJBjGYnuqrzWxIktbPpSctHGFaykMXOEj0SaItfhIpx+TwufgLBhbijef sy+Q7mtuI9ifzHVtmvYTwVzhU/O4+UKa9prAb/lCzd+WMEzpZuVEh/2ef5gr3zyRwMT/ M/pXDTgtQxdkaS4llggWNc/A1OBh0SToWTsvpjrRnHuk9pi3mMMQDNdqbKygJ7sgf3A/ 8WRzOOCbZxOC+CdsR1eIKbpEjHFL7GXx2JF4YQGJFq0sJAOEqTHvKV5VCWQnBSTPLUdV FnDkzcRlmgF2cqhDukEI4S5CtCkqdTWCgEkmwe7ATHA1L7JVZ0wxlR8l2x6dQJLGFUQ9 lJHg== X-Gm-Message-State: AOJu0YyxnZ3xnWTcTwqOxNO74rFWiRftVS59wTXv2mGcWuZ9NescVfml AGc1H0Uy0ORDVao1e380K5v3btNQXWc1yCVzMgFzc2DGf2Ab3Yk/tnatais9 X-Google-Smtp-Source: AGHT+IE2u3hc6hFfpbkwdmbBGTqONZMHcrJ73GPS/zy0C7+/sc7uEcarh4Y/0HMDN46jZpahpHePnQ== X-Received: by 2002:a05:6000:4027:b0:33b:4e58:7a8d with SMTP id cp39-20020a056000402700b0033b4e587a8dmr8219779wrb.63.1707813711164; Tue, 13 Feb 2024 00:41:51 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k6-20020a5d66c6000000b00337d5cd0d8asm8879209wrw.90.2024.02.13.00.41.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 00:41:50 -0800 (PST) Message-ID: <818eef0a64443e42c288ea3b294bf52e7411914b.1707813709.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 08:41:37 +0000 Subject: [PATCH 01/12] paint_down_to_common: plug a memory leak Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin When a commit is missing, we return early (currently pretending that no merge basis could be found in that case). At that stage, it is possible that a merge base could have been found already, and added to the `result`, which is now leaked. Let's release it, to address that memory leak. Signed-off-by: Johannes Schindelin --- commit-reach.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/commit-reach.c b/commit-reach.c index a868a575ea1..b2b102926c9 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -105,8 +105,10 @@ static struct commit_list *paint_down_to_common(struct repository *r, parents = parents->next; if ((p->object.flags & flags) == flags) continue; - if (repo_parse_commit(r, p)) + if (repo_parse_commit(r, p)) { + free_commit_list(result); return NULL; + } p->object.flags |= flags; prio_queue_put(&queue, p); } From patchwork Tue Feb 13 08:41:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13554705 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28E1F21A0C for ; Tue, 13 Feb 2024 08:41:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813716; cv=none; b=Jgb5D5Kr2BHEQ2E28uiSfMFaE2FfXKYPYCb0Fq0Ei3eh6NZ9WefcWTTVqVQ0PM6e2W//z7nttVeqQbMUHcxIPs99Os25beYzBqSVQRQ/OupYdGsy2q7HnFpb55SnhWvk/r1msTxyzmCST7SuMdMjD8NlkcLyEmPUbzmOOZHan18= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813716; c=relaxed/simple; bh=pc8sD8DJdmRrLVfEXtTSt78zBumqbB2PyU0f4hVl9h0=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=jdJbiGyvHEELqIxbAdyhJzB2H5G4z8y66CBHpv/gKRVFKs9ysmXN713n3+XpWmzIs54DGIKdZSicpbZtYqWC27PSmrKBxPI+RjyWkFvl++AZm5v3P/mPa7yCULAl2IeNhuI9ZUOoOBnaXpTaZ0gGYxwhbzK3R/xxVLwhPrVBWXY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hCq/6ZXd; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hCq/6ZXd" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-33b66a7f859so1475632f8f.3 for ; Tue, 13 Feb 2024 00:41:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707813712; x=1708418512; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=lAonqMO/1n1mv8zhF/oze9LH0aHCF5e3SDtK15aH4dM=; b=hCq/6ZXd5RtnusQWKxBj6t2XunsSJSJiTxUMfo83RoEG+lpJAmkl7emUvqLXzOq1Pc r9EBaZtXJhgnnWyiSjnXi/QbPjT61c/fhTAmWgvFkUzwt0hDcC0/IXiD0RqyiSx+Hi6n nMALdyY0ArUMIciXtdWfTsp+L1fVttxYzRxCvGZzJADeAHLnyz2+hXwXpF5g2x44jRN6 fxm9t0wIPxJdBIB+MkChhuV/soDV1p+PqbA/nDq5YWpVut4E9qaUsvsxmg9crERI/Fja 9Oac06ejlCXh2Za4ctwukDOnBVXN9KW0TKwjQey4neSGZyJH0rYMjWwkKVxWC29X+XCw CV4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707813712; x=1708418512; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lAonqMO/1n1mv8zhF/oze9LH0aHCF5e3SDtK15aH4dM=; b=O516RY61HZjeYiHc82WEKzGhVzk7AlO65k6ykJYe6HOHQ2B2x9g9LNAht5QE46BE5/ bw17u28hL3qTzbsrPCtlH26MOUJBFZcLu0YCA8rcYHtOpDodu8LPPjrq1FoMkVbHEOqm 7aYLqejq2309RGsGMPeOKx59UOS/c1tfFhIJ/WhYJDHw5vHrN7dIHvEENXDDWHVxkwWO x7oVSRhQjSjYroFBtMdnAdUGk9VnK2nZZkWlpMsY5snE4SQ+OXmZjCixUTdJDQhwHANj a+rhzUcHVIfRkecHF/u/tqYZRGylmwJQmNAYqY+OGTONhkLXTqJwOoOwQxjm+7G6o5Ey V7lQ== X-Gm-Message-State: AOJu0YyYrtd7pOkANZe37bC6N6zPnuQgGadnwi9cyedhqu7i4g5TAUbe Y4Hm/MzkcjZnTmiSiig6kn5iNll/cggTSheaG6r7iGKKqrMFCFCbp21w6enY X-Google-Smtp-Source: AGHT+IGGljDohstDou2doNFaklr8IM1LB0YG1bU+IYSoRdgd6/TM4gf3OPwWPTGV5EZkEB4J3dmR+Q== X-Received: by 2002:a5d:61c4:0:b0:33b:179d:d9aa with SMTP id q4-20020a5d61c4000000b0033b179dd9aamr5988208wrv.26.1707813711931; Tue, 13 Feb 2024 00:41:51 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id bj8-20020a0560001e0800b0033b3ca3a255sm8920934wrb.19.2024.02.13.00.41.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 00:41:51 -0800 (PST) Message-ID: <5f0af7fc0b95f9539ba7f740cb805ff1638d14cc.1707813709.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 08:41:38 +0000 Subject: [PATCH 02/12] Let `repo_in_merge_bases()` report missing commits Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin Some functions in Git's source code follow the convention that returning a negative value indicates a fatal error, e.g. repository corruption. Let's use this convention in `repo_in_merge_bases()` to report when one of the specified commits is missing (i.e. when `repo_parse_commit()` reports an error). Also adjust the callers of `repo_in_merge_bases()` to handle such negative return values. Signed-off-by: Johannes Schindelin --- builtin/branch.c | 12 +++++-- builtin/fast-import.c | 6 +++- builtin/fetch.c | 2 ++ builtin/log.c | 7 ++-- builtin/merge-base.c | 6 +++- builtin/pull.c | 4 +++ builtin/receive-pack.c | 6 +++- commit-reach.c | 12 ++++--- http-push.c | 5 ++- merge-ort.c | 75 ++++++++++++++++++++++++++++++++++++------ merge-recursive.c | 48 ++++++++++++++++++++++----- shallow.c | 18 ++++++---- 12 files changed, 163 insertions(+), 38 deletions(-) diff --git a/builtin/branch.c b/builtin/branch.c index e7ee9bd0f15..7f9e79237f3 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -161,6 +161,8 @@ static int branch_merged(int kind, const char *name, merged = reference_rev ? repo_in_merge_bases(the_repository, rev, reference_rev) : 0; + if (merged < 0) + exit(128); /* * After the safety valve is fully redefined to "check with @@ -169,9 +171,13 @@ static int branch_merged(int kind, const char *name, * any of the following code, but during the transition period, * a gentle reminder is in order. */ - if ((head_rev != reference_rev) && - (head_rev ? repo_in_merge_bases(the_repository, rev, head_rev) : 0) != merged) { - if (merged) + if (head_rev != reference_rev) { + int expect = head_rev ? repo_in_merge_bases(the_repository, rev, head_rev) : 0; + if (expect < 0) + exit(128); + if (expect == merged) + ; /* okay */ + else if (merged) warning(_("deleting branch '%s' that has been merged to\n" " '%s', but not yet merged to HEAD"), name, reference_name); diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 444f41cf8ca..14c2efa88fc 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -1625,6 +1625,7 @@ static int update_branch(struct branch *b) oidclr(&old_oid); if (!force_update && !is_null_oid(&old_oid)) { struct commit *old_cmit, *new_cmit; + int ret; old_cmit = lookup_commit_reference_gently(the_repository, &old_oid, 0); @@ -1633,7 +1634,10 @@ static int update_branch(struct branch *b) if (!old_cmit || !new_cmit) return error("Branch %s is missing commits.", b->name); - if (!repo_in_merge_bases(the_repository, old_cmit, new_cmit)) { + ret = repo_in_merge_bases(the_repository, old_cmit, new_cmit); + if (ret < 0) + exit(128); + if (!ret) { warning("Not updating %s" " (new tip %s does not contain %s)", b->name, oid_to_hex(&b->oid), diff --git a/builtin/fetch.c b/builtin/fetch.c index fd134ba74d9..0584a1f8b64 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -978,6 +978,8 @@ static int update_local_ref(struct ref *ref, uint64_t t_before = getnanotime(); fast_forward = repo_in_merge_bases(the_repository, current, updated); + if (fast_forward < 0) + exit(128); forced_updates_ms += (getnanotime() - t_before) / 1000000; } else { fast_forward = 1; diff --git a/builtin/log.c b/builtin/log.c index ba775d7b5cf..1705da71aca 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1623,7 +1623,7 @@ static struct commit *get_base_commit(const char *base_commit, { struct commit *base = NULL; struct commit **rev; - int i = 0, rev_nr = 0, auto_select, die_on_failure; + int i = 0, rev_nr = 0, auto_select, die_on_failure, ret; switch (auto_base) { case AUTO_BASE_NEVER: @@ -1723,7 +1723,10 @@ static struct commit *get_base_commit(const char *base_commit, rev_nr = DIV_ROUND_UP(rev_nr, 2); } - if (!repo_in_merge_bases(the_repository, base, rev[0])) { + ret = repo_in_merge_bases(the_repository, base, rev[0]); + if (ret < 0) + exit(128); + if (!ret) { if (die_on_failure) { die(_("base commit should be the ancestor of revision list")); } else { diff --git a/builtin/merge-base.c b/builtin/merge-base.c index e68b7fe45d7..0308fd73289 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -103,12 +103,16 @@ static int handle_octopus(int count, const char **args, int show_all) static int handle_is_ancestor(int argc, const char **argv) { struct commit *one, *two; + int ret; if (argc != 2) die("--is-ancestor takes exactly two commits"); one = get_commit_reference(argv[0]); two = get_commit_reference(argv[1]); - if (repo_in_merge_bases(the_repository, one, two)) + ret = repo_in_merge_bases(the_repository, one, two); + if (ret < 0) + exit(128); + if (ret) return 0; else return 1; diff --git a/builtin/pull.c b/builtin/pull.c index be2b2c9ebc9..e6f2942c0c5 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -931,6 +931,8 @@ static int get_can_ff(struct object_id *orig_head, merge_head = lookup_commit_reference(the_repository, orig_merge_head); ret = repo_is_descendant_of(the_repository, merge_head, list); free_commit_list(list); + if (ret < 0) + exit(128); return ret; } @@ -955,6 +957,8 @@ static int already_up_to_date(struct object_id *orig_head, commit_list_insert(theirs, &list); ok = repo_is_descendant_of(the_repository, ours, list); free_commit_list(list); + if (ok < 0) + exit(128); if (!ok) return 0; } diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 8c4f0cb90a9..956fea6293e 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1546,6 +1546,7 @@ static const char *update(struct command *cmd, struct shallow_info *si) starts_with(name, "refs/heads/")) { struct object *old_object, *new_object; struct commit *old_commit, *new_commit; + int ret2; old_object = parse_object(the_repository, old_oid); new_object = parse_object(the_repository, new_oid); @@ -1559,7 +1560,10 @@ static const char *update(struct command *cmd, struct shallow_info *si) } old_commit = (struct commit *)old_object; new_commit = (struct commit *)new_object; - if (!repo_in_merge_bases(the_repository, old_commit, new_commit)) { + ret2 = repo_in_merge_bases(the_repository, old_commit, new_commit); + if (ret2 < 0) + exit(128); + if (!ret2) { rp_error("denying non-fast-forward %s" " (you should pull first)", name); ret = "non-fast-forward"; diff --git a/commit-reach.c b/commit-reach.c index b2b102926c9..dab32eb470d 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -463,11 +463,13 @@ int repo_is_descendant_of(struct repository *r, } else { while (with_commit) { struct commit *other; + int ret; other = with_commit->item; with_commit = with_commit->next; - if (repo_in_merge_bases_many(r, other, 1, &commit)) - return 1; + ret = repo_in_merge_bases_many(r, other, 1, &commit); + if (ret) + return ret; } return 0; } @@ -484,10 +486,10 @@ int repo_in_merge_bases_many(struct repository *r, struct commit *commit, timestamp_t generation, max_generation = GENERATION_NUMBER_ZERO; if (repo_parse_commit(r, commit)) - return ret; + return -1; for (i = 0; i < nr_reference; i++) { if (repo_parse_commit(r, reference[i])) - return ret; + return -1; generation = commit_graph_generation(reference[i]); if (generation > max_generation) @@ -596,6 +598,8 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid) commit_list_insert(old_commit, &old_commit_list); ret = repo_is_descendant_of(the_repository, new_commit, old_commit_list); + if (ret < 0) + exit(128); free_commit_list(old_commit_list); return ret; } diff --git a/http-push.c b/http-push.c index a704f490fdb..85fa2f457d4 100644 --- a/http-push.c +++ b/http-push.c @@ -1576,8 +1576,11 @@ static int verify_merge_base(struct object_id *head_oid, struct ref *remote) struct commit *head = lookup_commit_or_die(head_oid, "HEAD"); struct commit *branch = lookup_commit_or_die(&remote->old_oid, remote->name); + int i = repo_in_merge_bases(the_repository, branch, head); - return repo_in_merge_bases(the_repository, branch, head); + if (i < 0) + exit(128); + return i; } static int delete_remote_branch(const char *pattern, int force) diff --git a/merge-ort.c b/merge-ort.c index 6491070d965..64e76afe89f 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -544,6 +544,7 @@ enum conflict_and_info_types { CONFLICT_SUBMODULE_HISTORY_NOT_AVAILABLE, CONFLICT_SUBMODULE_MAY_HAVE_REWINDS, CONFLICT_SUBMODULE_NULL_MERGE_BASE, + CONFLICT_SUBMODULE_CORRUPT, /* Keep this entry _last_ in the list */ NB_CONFLICT_TYPES, @@ -596,7 +597,9 @@ static const char *type_short_descriptions[] = { [CONFLICT_SUBMODULE_MAY_HAVE_REWINDS] = "CONFLICT (submodule may have rewinds)", [CONFLICT_SUBMODULE_NULL_MERGE_BASE] = - "CONFLICT (submodule lacks merge base)" + "CONFLICT (submodule lacks merge base)", + [CONFLICT_SUBMODULE_CORRUPT] = + "CONFLICT (submodule corrupt)" }; struct logical_conflict_info { @@ -1710,7 +1713,11 @@ static int find_first_merges(struct repository *repo, die("revision walk setup failed"); while ((commit = get_revision(&revs)) != NULL) { struct object *o = &(commit->object); - if (repo_in_merge_bases(repo, b, commit)) + int ret = repo_in_merge_bases(repo, b, commit); + + if (ret < 0) + return ret; + if (ret > 0) add_object_array(o, NULL, &merges); } reset_revision_walk(); @@ -1725,9 +1732,14 @@ static int find_first_merges(struct repository *repo, contains_another = 0; for (j = 0; j < merges.nr; j++) { struct commit *m2 = (struct commit *) merges.objects[j].item; - if (i != j && repo_in_merge_bases(repo, m2, m1)) { - contains_another = 1; - break; + if (i != j) { + int ret = repo_in_merge_bases(repo, m2, m1); + if (ret < 0) + return ret; + if (ret > 0) { + contains_another = 1; + break; + } } } @@ -1749,7 +1761,7 @@ static int merge_submodule(struct merge_options *opt, { struct repository subrepo; struct strbuf sb = STRBUF_INIT; - int ret = 0; + int ret = 0, ret2; struct commit *commit_o, *commit_a, *commit_b; int parent_count; struct object_array merges; @@ -1796,8 +1808,26 @@ static int merge_submodule(struct merge_options *opt, } /* check whether both changes are forward */ - if (!repo_in_merge_bases(&subrepo, commit_o, commit_a) || - !repo_in_merge_bases(&subrepo, commit_o, commit_b)) { + ret2 = repo_in_merge_bases(&subrepo, commit_o, commit_a); + if (ret2 < 1) { + path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0, + path, NULL, NULL, NULL, + _("Failed to merge submodule %s " + "(repository corrupt)"), + path); + goto cleanup; + } + if (!ret2) + ret2 = repo_in_merge_bases(&subrepo, commit_o, commit_b); + if (ret2 < 1) { + path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0, + path, NULL, NULL, NULL, + _("Failed to merge submodule %s " + "(repository corrupt)"), + path); + goto cleanup; + } + if (!ret2) { path_msg(opt, CONFLICT_SUBMODULE_MAY_HAVE_REWINDS, 0, path, NULL, NULL, NULL, _("Failed to merge submodule %s " @@ -1807,7 +1837,16 @@ static int merge_submodule(struct merge_options *opt, } /* Case #1: a is contained in b or vice versa */ - if (repo_in_merge_bases(&subrepo, commit_a, commit_b)) { + ret2 = repo_in_merge_bases(&subrepo, commit_a, commit_b); + if (ret2 < 0) { + path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0, + path, NULL, NULL, NULL, + _("Failed to merge submodule %s " + "(repository corrupt)"), + path); + goto cleanup; + } + if (ret2 > 0) { oidcpy(result, b); path_msg(opt, INFO_SUBMODULE_FAST_FORWARDING, 1, path, NULL, NULL, NULL, @@ -1816,7 +1855,16 @@ static int merge_submodule(struct merge_options *opt, ret = 1; goto cleanup; } - if (repo_in_merge_bases(&subrepo, commit_b, commit_a)) { + ret2 = repo_in_merge_bases(&subrepo, commit_b, commit_a); + if (ret2 < 0) { + path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0, + path, NULL, NULL, NULL, + _("Failed to merge submodule %s " + "(repository corrupt)"), + path); + goto cleanup; + } + if (ret2 > 0) { oidcpy(result, a); path_msg(opt, INFO_SUBMODULE_FAST_FORWARDING, 1, path, NULL, NULL, NULL, @@ -1841,6 +1889,13 @@ static int merge_submodule(struct merge_options *opt, parent_count = find_first_merges(&subrepo, path, commit_a, commit_b, &merges); switch (parent_count) { + case -1: + path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0, + path, NULL, NULL, NULL, + _("Failed to merge submodule %s " + "(repository corrupt)"), + path); + break; case 0: path_msg(opt, CONFLICT_SUBMODULE_FAILED_TO_MERGE, 0, path, NULL, NULL, NULL, diff --git a/merge-recursive.c b/merge-recursive.c index e3beb0801b1..e3fe7803cbe 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1144,7 +1144,10 @@ static int find_first_merges(struct repository *repo, die("revision walk setup failed"); while ((commit = get_revision(&revs)) != NULL) { struct object *o = &(commit->object); - if (repo_in_merge_bases(repo, b, commit)) + int ret = repo_in_merge_bases(repo, b, commit); + if (ret < 0) + return ret; + if (ret) add_object_array(o, NULL, &merges); } reset_revision_walk(); @@ -1159,9 +1162,14 @@ static int find_first_merges(struct repository *repo, contains_another = 0; for (j = 0; j < merges.nr; j++) { struct commit *m2 = (struct commit *) merges.objects[j].item; - if (i != j && repo_in_merge_bases(repo, m2, m1)) { - contains_another = 1; - break; + if (i != j) { + int ret = repo_in_merge_bases(repo, m2, m1); + if (ret < 0) + return ret; + if (ret > 0) { + contains_another = 1; + break; + } } } @@ -1197,7 +1205,7 @@ static int merge_submodule(struct merge_options *opt, const struct object_id *b) { struct repository subrepo; - int ret = 0; + int ret = 0, ret2; struct commit *commit_base, *commit_a, *commit_b; int parent_count; struct object_array merges; @@ -1234,14 +1242,29 @@ static int merge_submodule(struct merge_options *opt, } /* check whether both changes are forward */ - if (!repo_in_merge_bases(&subrepo, commit_base, commit_a) || - !repo_in_merge_bases(&subrepo, commit_base, commit_b)) { + ret2 = repo_in_merge_bases(&subrepo, commit_base, commit_a); + if (ret2 < 0) { + output(opt, 1, _("Failed to merge submodule %s (repository corrupt)"), path); + goto cleanup; + } + if (ret2) + ret2 = repo_in_merge_bases(&subrepo, commit_base, commit_b); + if (ret2 < 0) { + output(opt, 1, _("Failed to merge submodule %s (repository corrupt)"), path); + goto cleanup; + } + if (!ret2) { output(opt, 1, _("Failed to merge submodule %s (commits don't follow merge-base)"), path); goto cleanup; } /* Case #1: a is contained in b or vice versa */ - if (repo_in_merge_bases(&subrepo, commit_a, commit_b)) { + ret2 = repo_in_merge_bases(&subrepo, commit_a, commit_b); + if (ret2 < 0) { + output(opt, 1, _("Failed to merge submodule %s (repository corrupt)"), path); + goto cleanup; + } + if (ret2) { oidcpy(result, b); if (show(opt, 3)) { output(opt, 3, _("Fast-forwarding submodule %s to the following commit:"), path); @@ -1254,7 +1277,12 @@ static int merge_submodule(struct merge_options *opt, ret = 1; goto cleanup; } - if (repo_in_merge_bases(&subrepo, commit_b, commit_a)) { + ret2 = repo_in_merge_bases(&subrepo, commit_b, commit_a); + if (ret2 < 0) { + output(opt, 1, _("Failed to merge submodule %s (repository corrupt)"), path); + goto cleanup; + } + if (ret2) { oidcpy(result, a); if (show(opt, 3)) { output(opt, 3, _("Fast-forwarding submodule %s to the following commit:"), path); @@ -1402,6 +1430,8 @@ static int merge_mode_and_contents(struct merge_options *opt, &o->oid, &a->oid, &b->oid); + if (result->clean < 0) + return -1; } else if (S_ISLNK(a->mode)) { switch (opt->recursive_variant) { case MERGE_VARIANT_NORMAL: diff --git a/shallow.c b/shallow.c index ac728cdd778..cf4b95114b7 100644 --- a/shallow.c +++ b/shallow.c @@ -795,12 +795,16 @@ static void post_assign_shallow(struct shallow_info *info, if (!*bitmap) continue; for (j = 0; j < bitmap_nr; j++) - if (bitmap[0][j] && - /* Step 7, reachability test at commit level */ - !repo_in_merge_bases_many(the_repository, c, ca.nr, ca.commits)) { - update_refstatus(ref_status, info->ref->nr, *bitmap); - dst++; - break; + if (bitmap[0][j]) { + /* Step 7, reachability test at commit level */ + int ret = repo_in_merge_bases_many(the_repository, c, ca.nr, ca.commits); + if (ret < 0) + exit(128); + if (!ret) { + update_refstatus(ref_status, info->ref->nr, *bitmap); + dst++; + break; + } } } info->nr_ours = dst; @@ -829,6 +833,8 @@ int delayed_reachability_test(struct shallow_info *si, int c) commit, si->nr_commits, si->commits); + if (si->reachable[c] < 0) + exit(128); si->need_reachability_test[c] = 0; } return si->reachable[c]; From patchwork Tue Feb 13 08:41:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13554704 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF37522071 for ; Tue, 13 Feb 2024 08:41:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813716; cv=none; b=suKQkSjMiHO6l1ZXPhVQ+QeJe+CM2ZnQmw4QRBEUdikd8KHhXd9b1bzBko9UmSAN8p5RQxDICqi/LcSeItW1z+2BXBBTMyh70nAjH2YeX+hiA4EGe3BBm/ZnZAscWWbJTob0CxTqkecIXa9Vczsq33tB+9v9Iwkx2sDEd0I0R/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813716; c=relaxed/simple; bh=1KMvi2u+wtKRUxMi6ylYlRTHEtPQKJNb/eUNynG1EH4=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=o+A0+8FWazOgbWJ1a2hT1+lKwX8Y5awq0fiEa3JkdN7eg8vWY3AzAHV8FybVjLTHG+OFImBm8k063ksMP2Xb7SMKXFZ9YDZRcXXif+zDzz8HcZU8jNRWA0nCeCwF4WiwFpFZp2ewFL3rfgKHaVz8nN4Gy6W9NnJiuUzehRDsWp0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fG70TKsl; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fG70TKsl" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-33cda3dfa06so167214f8f.3 for ; Tue, 13 Feb 2024 00:41:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707813712; x=1708418512; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=+crd7Yhc5AhyCTc0OphfUGDRElIJF2+ZsCa/m/BWkmI=; b=fG70TKslfhgijKw82nwf1NQl+RvPVnzTVq508t+dWYzBNKU5PMsVn2mT+gjoviBjHw /PJYc5xHrGZnJb2A6dlUees/L2iqHnSKw+RaHwkYnqEwg5vgEF/bqN1tEuNJCWKtKoBg RBIAam9FEcKj0+CWfGlT4et1bkHy4OzGjnQTvkPlLM8Qtc83CtT8aRt3Cpi0fd9/gl4V R+5Y3hnJpMJeaeBnTt9wMCgWJRys/6N4pNEVaDhQ0HKv29C1gBPmCMcU7Q2YsSOL6cLP aZFEfBBt6Yd4WEwyBFQyJLydzOHFxC0MH0W1p7kUoLHJCl/S0PSmW36a171Q3uM6SWoh KZJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707813712; x=1708418512; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+crd7Yhc5AhyCTc0OphfUGDRElIJF2+ZsCa/m/BWkmI=; b=d+ng6jj56H1zODddazzXUT/Mq8+3ttwBzVMrQ/V1N+g5X0kyiSMsclFbVmBInMLTIs 87vkF5ukOHSAv1lhsbuNm+Fy2QhvGrB0CHVfViY5H5DgOdPM9CK4EH075aFuw9GfFIrL EijipjnSYGzbmWMVFV48g1d9xWohy5Og7WeFHwYZK8uKWwVM0L2t0I0cjAVigRjm/hPf 7BMi+HeOWIFi86AmDRpB0pv+3C7EsKxHrtMCbQj1gMHKOlLj1H5ydwebPMc7m8nJR2Bu nDDko0Nr03RpcLD3ZbLvkOOTcTxoUjXwlkhgfUrKTKmRJbkaSsuD7N8pCnC8IaRN43uN buEA== X-Gm-Message-State: AOJu0YyauBHYTr2n58vCAv/cVUboV4iFL53lL0a8aKi2+1niBGHe8b2H lJKXEQRYi9wwEyCta+NtOw1CtSGSTfPhuxNmZTduW/CLBzV2/sMcpyp2JKU6 X-Google-Smtp-Source: AGHT+IE2GnC+nhBPZPYOXL2S8XWM2zSQ2YzlhgVmyHDeq1J9oTr2g/6PVRY45RgqOchg/TblwXuIVA== X-Received: by 2002:a5d:47ce:0:b0:33b:684f:4926 with SMTP id o14-20020a5d47ce000000b0033b684f4926mr8011968wrc.63.1707813712426; Tue, 13 Feb 2024 00:41:52 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i9-20020a5d5229000000b0033ae7d768b2sm8913173wra.117.2024.02.13.00.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 00:41:52 -0800 (PST) Message-ID: <8395c3efbc3c34d732347f743a0263707ec454bf.1707813709.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 08:41:39 +0000 Subject: [PATCH 03/12] Prepare `repo_in_merge_bases_many()` to optionally expect missing commits Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin Currently this function treats unrelated commit histories the same way as commit histories with missing commit objects. Typically, missing commit objects constitute a corrupt repository, though, and should be reported as such. The next commits will make it so, but there is one exception: In `git fetch --update-shallow` we _expect_ commit objects to be missing, and we do want to treat the now-incomplete commit histories as unrelated. To allow for that, let's introduce an additional parameter that is passed to `repo_in_merge_bases_many()` to trigger this behavior, and use it in the two callers in `shallow.c`. This does not change behavior in this commit, but prepares in an easy-to-review way for the upcoming changes that will make the merge base logic more stringent with regards to missing commit objects. Signed-off-by: Johannes Schindelin --- commit-reach.c | 9 +++++---- commit-reach.h | 3 ++- remote.c | 2 +- shallow.c | 5 +++-- t/helper/test-reach.c | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/commit-reach.c b/commit-reach.c index dab32eb470d..248a0f2b39d 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -467,7 +467,7 @@ int repo_is_descendant_of(struct repository *r, other = with_commit->item; with_commit = with_commit->next; - ret = repo_in_merge_bases_many(r, other, 1, &commit); + ret = repo_in_merge_bases_many(r, other, 1, &commit, 0); if (ret) return ret; } @@ -479,17 +479,18 @@ int repo_is_descendant_of(struct repository *r, * Is "commit" an ancestor of one of the "references"? */ int repo_in_merge_bases_many(struct repository *r, struct commit *commit, - int nr_reference, struct commit **reference) + int nr_reference, struct commit **reference, + int ignore_missing_commits) { struct commit_list *bases; int ret = 0, i; timestamp_t generation, max_generation = GENERATION_NUMBER_ZERO; if (repo_parse_commit(r, commit)) - return -1; + return ignore_missing_commits ? 0 : -1; for (i = 0; i < nr_reference; i++) { if (repo_parse_commit(r, reference[i])) - return -1; + return ignore_missing_commits ? 0 : -1; generation = commit_graph_generation(reference[i]); if (generation > max_generation) diff --git a/commit-reach.h b/commit-reach.h index 35c4da49481..68f81549a44 100644 --- a/commit-reach.h +++ b/commit-reach.h @@ -30,7 +30,8 @@ int repo_in_merge_bases(struct repository *r, struct commit *reference); int repo_in_merge_bases_many(struct repository *r, struct commit *commit, - int nr_reference, struct commit **reference); + int nr_reference, struct commit **reference, + int ignore_missing_commits); /* * Takes a list of commits and returns a new list where those diff --git a/remote.c b/remote.c index abb24822beb..763c80f4a7d 100644 --- a/remote.c +++ b/remote.c @@ -2675,7 +2675,7 @@ static int is_reachable_in_reflog(const char *local, const struct ref *remote) if (MERGE_BASES_BATCH_SIZE < size) size = MERGE_BASES_BATCH_SIZE; - if ((ret = repo_in_merge_bases_many(the_repository, commit, size, chunk))) + if ((ret = repo_in_merge_bases_many(the_repository, commit, size, chunk, 0))) break; } diff --git a/shallow.c b/shallow.c index cf4b95114b7..f71496f35c3 100644 --- a/shallow.c +++ b/shallow.c @@ -797,7 +797,7 @@ static void post_assign_shallow(struct shallow_info *info, for (j = 0; j < bitmap_nr; j++) if (bitmap[0][j]) { /* Step 7, reachability test at commit level */ - int ret = repo_in_merge_bases_many(the_repository, c, ca.nr, ca.commits); + int ret = repo_in_merge_bases_many(the_repository, c, ca.nr, ca.commits, 1); if (ret < 0) exit(128); if (!ret) { @@ -832,7 +832,8 @@ int delayed_reachability_test(struct shallow_info *si, int c) si->reachable[c] = repo_in_merge_bases_many(the_repository, commit, si->nr_commits, - si->commits); + si->commits, + 1); if (si->reachable[c] < 0) exit(128); si->need_reachability_test[c] = 0; diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c index 3e173399a00..aa816e168ea 100644 --- a/t/helper/test-reach.c +++ b/t/helper/test-reach.c @@ -113,7 +113,7 @@ int cmd__reach(int ac, const char **av) repo_in_merge_bases(the_repository, A, B)); else if (!strcmp(av[1], "in_merge_bases_many")) printf("%s(A,X):%d\n", av[1], - repo_in_merge_bases_many(the_repository, A, X_nr, X_array)); + repo_in_merge_bases_many(the_repository, A, X_nr, X_array, 0)); else if (!strcmp(av[1], "is_descendant_of")) printf("%s(A,X):%d\n", av[1], repo_is_descendant_of(r, A, X)); else if (!strcmp(av[1], "get_merge_bases_many")) { From patchwork Tue Feb 13 08:41:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13554707 Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D4281B7FE for ; Tue, 13 Feb 2024 08:41:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813717; cv=none; b=TEasSFO+t8Vhfw8HYElQAqqIjj0S4VFNcXu8lGIG0Rh8j4YneGxZ9QqDwwexLTZIt0lIbbp+7Nyqe5XXcNwUr2EQDJlmSZ4maST8HoxlhmIBY4aMS/OmsArAfFYyNAjBLRtC5HL/dDsofPEdq3ubDGk6smWGfPQL0woTM06icsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813717; c=relaxed/simple; bh=GrslJf7zwznCr+lViYLeubzBI8nd61LlCqp9zotvxW4=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=T5TnYmSrenzZqRTU4OQMHv/J+UfhRTxmx0c0AjBTQmzqUmLCYUkD6Rk4lZsysxS0eBhBAlQZmhNUCkRmpJQSY/9JMe5MbnmSnOPODURwsND5iHIerRGfY7MuCAamiqNX1tv0FpzufI4VSRd38+dXNoWn04hOhQILPU5D2XQTpbs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hxjKCWpo; arc=none smtp.client-ip=209.85.208.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hxjKCWpo" Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2d1094b5568so3728971fa.1 for ; Tue, 13 Feb 2024 00:41:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707813714; x=1708418514; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=EHXU9fzIVpwa+u3LyYtpp8MZzdGNheEGwQSj8lXLfYg=; b=hxjKCWpoWx3y6QSjHENc8fL2gCnpU/QW52SHM8KkZKlhwfXKdkUMHK5X/KfqeihrSN I8QyaiUBnS82bu47IOLngWZ33JE/GrCYnkOeHkZsj5dTPyN2ihslJQ8PfTaMU/cf0MDD kYdZsHmRsKk6CKq0FVwFEuW75AwDgRjNr979/2srHol1fUNEhZrTxGeLIhsj8kisR0OS IBHn0PyTReekb+wMswitjYqDQefCUc9+wDexUgbdfJ6FxKv/imrQm262iHgGGhwP29P2 fUn4fPJZZ4WBcC1fiiTpyHZnVlCFIdojRatWsb/ikNpOvt6Nr7eOk79f1s6/o72U4eBx 4/pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707813714; x=1708418514; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EHXU9fzIVpwa+u3LyYtpp8MZzdGNheEGwQSj8lXLfYg=; b=v2vepoWktEQ30UZPediWSL0KOHD+41+QQdFy5S6j3vVkauZjO53dbNKcA3zicRbAMH 7E/reLcHxxvH0PpVsh6E7mN2DpeprWjLdXRxeTqyOUhzA/Fqxx0CI0uQdRbgSoWsQQTz QZbtFAKaUdByyFnDVeJ+v+KK3Cd0n0xLUgq2cnrgcjbUCzjTzZ3jlPS6MY8PsmlKqGlG g80JcJK5E+j/INpOjb7FUleCwPPed5niFkZhfRS4Ry21JhFCxO5MvB5jYMVbcp0nFIVh z0NtT5HSTswExr3Nb+gwNJusK1WoBToTuwOS56dP4esNBFEU7YLpVlYcV/MKd4Zzg/ot 3fuA== X-Gm-Message-State: AOJu0YwuqZQ2zKsbkNLRd3s/3msnCCFy+wPAWmj1XgvcqlogFpWG0MQB NbPrfUruzOzhxE+CpfIRA3c6uexHxPtXSbqSq/0xLM7jAJt54fCoFLqmrnOq X-Google-Smtp-Source: AGHT+IElKY0oVsHmLZRxTd1HPRX77xFUobasrBz7JB+Y0RhFUy+ImEFa6ry0Fpv4TptVC+y+xegfuA== X-Received: by 2002:a2e:a0c3:0:b0:2d0:5f2e:5b35 with SMTP id f3-20020a2ea0c3000000b002d05f2e5b35mr6475207ljm.30.1707813713588; Tue, 13 Feb 2024 00:41:53 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id bj8-20020a0560001e0800b0033b3ca3a255sm8920997wrb.19.2024.02.13.00.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 00:41:52 -0800 (PST) Message-ID: <7477b18adebe4eca721a0f2fa73ec5bdec389d36.1707813709.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 08:41:40 +0000 Subject: [PATCH 04/12] Prepare `paint_down_to_common()` for handling shallow commits Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin When `git fetch --update-shallow` needs to test for commit ancestry, it can naturally run into a missing object (e.g. if it is a parent of a shallow commit). To accommodate, the merge base logic will need to be able to handle this situation gracefully. Currently, that logic pretends that a missing parent commit is equivalent to a a missing parent commit, and for the purpose of `--update-shallow` that is exactly what we need it to do. Therefore, let's introduce a flag to indicate when that is precisely the logic we want. We need a flag, and cannot rely on `is_repository_shallow()` to indicate that situation, because that function would return 0: There may not actually be a `shallow` file, as demonstrated e.g. by t5537.10 ("add new shallow root with receive.updateshallow on") and t5538.4 ("add new shallow root with receive.updateshallow on"). Signed-off-by: Johannes Schindelin --- commit-reach.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/commit-reach.c b/commit-reach.c index 248a0f2b39d..1d1d8c989de 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -53,7 +53,8 @@ static int queue_has_nonstale(struct prio_queue *queue) static struct commit_list *paint_down_to_common(struct repository *r, struct commit *one, int n, struct commit **twos, - timestamp_t min_generation) + timestamp_t min_generation, + int ignore_missing_commits) { struct prio_queue queue = { compare_commits_by_gen_then_commit_date }; struct commit_list *result = NULL; @@ -106,6 +107,13 @@ static struct commit_list *paint_down_to_common(struct repository *r, if ((p->object.flags & flags) == flags) continue; if (repo_parse_commit(r, p)) { + /* + * At this stage, we know that the commit is + * missing: `repo_parse_commit()` uses + * `OBJECT_INFO_DIE_IF_CORRUPT` and therefore + * corrupt commits would already have been + * dispatched with a `die()`. + */ free_commit_list(result); return NULL; } @@ -142,7 +150,7 @@ static struct commit_list *merge_bases_many(struct repository *r, return NULL; } - list = paint_down_to_common(r, one, n, twos, 0); + list = paint_down_to_common(r, one, n, twos, 0, 0); while (list) { struct commit *commit = pop_commit(&list); @@ -213,7 +221,7 @@ static int remove_redundant_no_gen(struct repository *r, min_generation = curr_generation; } common = paint_down_to_common(r, array[i], filled, - work, min_generation); + work, min_generation, 0); if (array[i]->object.flags & PARENT2) redundant[i] = 1; for (j = 0; j < filled; j++) @@ -503,7 +511,7 @@ int repo_in_merge_bases_many(struct repository *r, struct commit *commit, bases = paint_down_to_common(r, commit, nr_reference, reference, - generation); + generation, ignore_missing_commits); if (commit->object.flags & PARENT2) ret = 1; clear_commit_marks(commit, all_flags); From patchwork Tue Feb 13 08:41:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13554706 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 312191B971 for ; Tue, 13 Feb 2024 08:41:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813717; cv=none; b=DIG/kcopUwQ0R+pHXgxqamt1tzJg/xoKWxaqq33pO1uh7rpe0pTgPAGZHgufbXvrfh/PpmhI0H1ksxmAw+wdtrMMxs1Onx+olheXY4C2KJ+nyTkeZTD3nsey3kdEJvgt6UXNdij03w80crnYymMBwZpsqkWav6clMFh8MI8zYFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813717; c=relaxed/simple; bh=T4wW6Y17tbP4C1Ce/RItUq+t2VELXKk1LuDe+jotUkw=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=C+5PiBioAMCQND7Tz5SL5XG4eQwTrUD1tP/0TX4N46dzFaqjyQsJgvfNvDx7wT+sOFStN+Ue4rF6wFOohkwestoJRWDaylsUcG2dwtVPIgUu4LGqIxyxPGPHXyyC+4BJy99vp3PVMFLTqLJKr2DTBSEAmZmMM/zhtIOcifozLbc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KTwvghYi; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KTwvghYi" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-33b2960ff60so2885025f8f.1 for ; Tue, 13 Feb 2024 00:41:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707813714; x=1708418514; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=8T6cpIjJ3ZlgRyQ8CNL6hcHKBuljhhivRQn7Yl+KJwk=; b=KTwvghYiujryK8DBu+pxYWuTVUm3v+7NZjPgDhKJ254hmW4NLxYgCkQbPNrmHH2Pwv Tu/rQmV91iEUf1mAmVU1OvI8hE+ZtqaKv82qST7n6LwgOKaFMXJ96Ww2opcCTL7YGtrZ QrojiE9T47M5SRNq9E4XEhat7z29QVYRRm5+AvW19wIjbWu4eYrft2WqGK1tBCLwOwiu BmcA0RafS587rjMtStfxOc+rJ6/HPlHG/A/W0o6XMNNUok3ztr3mfD0EJ8z6KEmexi1P t4rAv+PLUjxWG7AsnC/jg/HDc7yroGCOR8PU4F6Ca9ZyCJRQ+4bSGiQ7pbzh2vrFyOW1 wcOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707813714; x=1708418514; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8T6cpIjJ3ZlgRyQ8CNL6hcHKBuljhhivRQn7Yl+KJwk=; b=WTUM23fCvOrPpBOa1q1xFbhDW2wjZLn0NZbS3vhVYosI9Lt6KPJnz3GwcrH3Kqx4zz RkCWuLfXyxXzxyEFHi8o7rjdl0MnMJ2GZPhmegKz2pnq2EHsv+YEZCpirk8vmrmT4b3C HTZ+CDvbfHjda3lQyo1sauYmd5GRBVI62lRA7zN689qovCzHyJqvytzc9caoDWp6Zvdn X6mEd+X4HV20tRB875mMiF1WhDcUYNzujg89hu/F2mJM+UV2eUmztzXHnymJAW0JMndw 0q9oiKaz2AoCrRTHGStuxVvEXf3uzFs9ilk3MZa0FHhPluYjEcQH23DEPGTrSnDFwvp8 BsLw== X-Gm-Message-State: AOJu0YzDjbBvlSUsYK92kR18ZzE5aKPjRqclHERr0cFrLN370azJlZ+Y uAStz82FZQy94uNkPgD/rBe0xUMaq7/PJb7FBaabHB6A+B7/DIohYb5/uiRn X-Google-Smtp-Source: AGHT+IE4zTvpJ20u8eH24HvS1hzPR0ylcmwx3Cl5yenFL/dX3q8ZNp/5w0kULSDmUisy6LI/uqrRYw== X-Received: by 2002:a05:6000:114a:b0:33a:f503:30b3 with SMTP id d10-20020a056000114a00b0033af50330b3mr1293850wrx.24.1707813714121; Tue, 13 Feb 2024 00:41:54 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q17-20020a5d61d1000000b0033940016d6esm8858362wrv.93.2024.02.13.00.41.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 00:41:53 -0800 (PST) Message-ID: In-Reply-To: References: Date: Tue, 13 Feb 2024 08:41:41 +0000 Subject: [PATCH 05/12] commit-reach: start reporting errors in `paint_down_to_common()` Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin If a commit cannot be parsed, it is currently ignored when looking for merge bases. That's undesirable as the operation can pretend success in a corrupt repository, even though the command should fail with an error message. Let's start at the bottom of the stack by teaching the `paint_down_to_common()` function to return an `int`: if negative, it indicates fatal error, if 0 success. This requires a couple of callers to be adjusted accordingly. Signed-off-by: Johannes Schindelin --- commit-reach.c | 56 +++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/commit-reach.c b/commit-reach.c index 1d1d8c989de..dafe117036b 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -50,14 +50,14 @@ static int queue_has_nonstale(struct prio_queue *queue) } /* all input commits in one and twos[] must have been parsed! */ -static struct commit_list *paint_down_to_common(struct repository *r, - struct commit *one, int n, - struct commit **twos, - timestamp_t min_generation, - int ignore_missing_commits) +static int paint_down_to_common(struct repository *r, + struct commit *one, int n, + struct commit **twos, + timestamp_t min_generation, + int ignore_missing_commits, + struct commit_list **result) { struct prio_queue queue = { compare_commits_by_gen_then_commit_date }; - struct commit_list *result = NULL; int i; timestamp_t last_gen = GENERATION_NUMBER_INFINITY; @@ -66,8 +66,8 @@ static struct commit_list *paint_down_to_common(struct repository *r, one->object.flags |= PARENT1; if (!n) { - commit_list_append(one, &result); - return result; + commit_list_append(one, result); + return 0; } prio_queue_put(&queue, one); @@ -95,7 +95,7 @@ static struct commit_list *paint_down_to_common(struct repository *r, if (flags == (PARENT1 | PARENT2)) { if (!(commit->object.flags & RESULT)) { commit->object.flags |= RESULT; - commit_list_insert_by_date(commit, &result); + commit_list_insert_by_date(commit, result); } /* Mark parents of a found merge stale */ flags |= STALE; @@ -114,8 +114,11 @@ static struct commit_list *paint_down_to_common(struct repository *r, * corrupt commits would already have been * dispatched with a `die()`. */ - free_commit_list(result); - return NULL; + free_commit_list(*result); + if (ignore_missing_commits) + return 0; + return error(_("could not parse commit %s"), + oid_to_hex(&p->object.oid)); } p->object.flags |= flags; prio_queue_put(&queue, p); @@ -123,7 +126,7 @@ static struct commit_list *paint_down_to_common(struct repository *r, } clear_prio_queue(&queue); - return result; + return 0; } static struct commit_list *merge_bases_many(struct repository *r, @@ -150,7 +153,8 @@ static struct commit_list *merge_bases_many(struct repository *r, return NULL; } - list = paint_down_to_common(r, one, n, twos, 0, 0); + if (paint_down_to_common(r, one, n, twos, 0, 0, &list) < 0) + return NULL; while (list) { struct commit *commit = pop_commit(&list); @@ -204,7 +208,7 @@ static int remove_redundant_no_gen(struct repository *r, for (i = 0; i < cnt; i++) repo_parse_commit(r, array[i]); for (i = 0; i < cnt; i++) { - struct commit_list *common; + struct commit_list *common = NULL; timestamp_t min_generation = commit_graph_generation(array[i]); if (redundant[i]) @@ -220,8 +224,9 @@ static int remove_redundant_no_gen(struct repository *r, if (curr_generation < min_generation) min_generation = curr_generation; } - common = paint_down_to_common(r, array[i], filled, - work, min_generation, 0); + if (paint_down_to_common(r, array[i], filled, + work, min_generation, 0, &common)) + return -1; if (array[i]->object.flags & PARENT2) redundant[i] = 1; for (j = 0; j < filled; j++) @@ -421,6 +426,10 @@ static struct commit_list *get_merge_bases_many_0(struct repository *r, clear_commit_marks_many(n, twos, all_flags); cnt = remove_redundant(r, rslt, cnt); + if (cnt < 0) { + free(rslt); + return NULL; + } result = NULL; for (i = 0; i < cnt; i++) commit_list_insert_by_date(rslt[i], &result); @@ -490,7 +499,7 @@ int repo_in_merge_bases_many(struct repository *r, struct commit *commit, int nr_reference, struct commit **reference, int ignore_missing_commits) { - struct commit_list *bases; + struct commit_list *bases = NULL; int ret = 0, i; timestamp_t generation, max_generation = GENERATION_NUMBER_ZERO; @@ -509,10 +518,11 @@ int repo_in_merge_bases_many(struct repository *r, struct commit *commit, if (generation > max_generation) return ret; - bases = paint_down_to_common(r, commit, - nr_reference, reference, - generation, ignore_missing_commits); - if (commit->object.flags & PARENT2) + if (paint_down_to_common(r, commit, + nr_reference, reference, + generation, ignore_missing_commits, &bases)) + ret = -1; + else if (commit->object.flags & PARENT2) ret = 1; clear_commit_marks(commit, all_flags); clear_commit_marks_many(nr_reference, reference, all_flags); @@ -565,6 +575,10 @@ struct commit_list *reduce_heads(struct commit_list *heads) } } num_head = remove_redundant(the_repository, array, num_head); + if (num_head < 0) { + free(array); + return NULL; + } for (i = 0; i < num_head; i++) tail = &commit_list_insert(array[i], tail)->next; free(array); From patchwork Tue Feb 13 08:41:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13554708 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E86D224C6 for ; Tue, 13 Feb 2024 08:41:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813719; cv=none; b=Im5T/HJf8tjz3FbAsYqx16/MlnMgERkqewz2MPqo3yWOd75IIDy2W+mDfiADtpgT5v2SrwKC9juVeq/XTMysn9rIR2Ycx1Buuk38+NLAmtVgz/5aGqCodf1Yyt/PuYmdddnrpahXKaY9osEdIJfXgkm2m74fmWG6kLuZVovegR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813719; c=relaxed/simple; bh=JGK/3U+YVHbi42/87+8D4qb5BXiukQmXCkiwmW06+L0=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=Y3Z3FyGZuyYODiCF8BSEkKCzxVUw4MfwXYSYdOkxp0pSGc7WGH8oMGOrX0rqVlQWjOv1S5/u0wX4WAcLI2KwkZ/+BIJe7Xqnootr/yn2fvpFv/MVgSrqGXRqCT0dXaQ5+l4pfWdlCG0zgq65pwgegw+hpMvRlZPLlfZ+/1qt5L8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hypQ5M9c; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hypQ5M9c" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-411a6ceada8so8477985e9.3 for ; Tue, 13 Feb 2024 00:41:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707813715; x=1708418515; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=rAXaQat3fAdnCzzf/SoTPVQfaVFuwFz0Zd8u1TmWe1M=; b=hypQ5M9cv8AonhkgJJ65Pj20D9N9F2CI6kD/LF3OSkWNgSUXSB/nBCK3Xu6JLz5DpZ N1o7hCSDcWu1+Zxvj59qJx1E8w6w5X7ulZxWc0Wh84yeXYvPWd4edeyLVbjCjrXJqGa2 5gEIi1wNVApu2s1zFw/G5alpQZADN4zDIYQ2u8HBB86QdeZyBQ9/jX3ZbaWdFbIToJ7k J9zLCivTV7AU665cQqUe06ozRkXRA8zgcMawlBAs831NBJIkCIaKuyR5mtkRPf6bxHz8 psz1ZRmnm910bpRicbL1BgLF7vzYlf1yKG3Hk+ObwCuJZyKGLE+ZKAGBKZ6vj/qd+4S/ gXaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707813715; x=1708418515; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rAXaQat3fAdnCzzf/SoTPVQfaVFuwFz0Zd8u1TmWe1M=; b=SxB2C1q+vvJ/ZTYzB6lZRke5A57ZhPe3T4k6W/Pghu10k/IcKBhv7WLpGyoglcDREt xTtU7lBNVHmtBV4KxsLBdC+g6hheYAVu8JZN1yh6MQ3rXMbt53m2rQZ298/wkXg11pok 0vvIsUX6EzV6mhx5OCzSWoSu7a1IvS/JHRm9uQy3qIwB1OYBx0AyEjKPuF9OKsJTG7GY JILR3SwuuDMVSPYxY+0YS8KniTYEdyzooEp2jUbip4KbR9PW/tKNvV7d8lvoXncen1W0 iTPPuUJ5pBRzhT3C25dcR9bFu3CPG9/7BI3sNUiwrz7KIZiwGKYpuRhw22lZ0WN5IYKB qacA== X-Gm-Message-State: AOJu0YyPVXfbtagDed86RwID/I3JocRkv+r2V+32L2dDJvd5Q+lVsLg/ fMjGiMKAWZiO90FucAqU5JVVAtdqw5jJ1eSIiWLaQiFldudorPN6NwEmLwAL X-Google-Smtp-Source: AGHT+IE71+mhXCmkFw5LD6aTVtL57RGkXyKtMqGig7sWIwDHjhxcI8SOfK9NJHfStzS2etHg4nwDtw== X-Received: by 2002:a05:600c:474d:b0:40f:e40:b53d with SMTP id w13-20020a05600c474d00b0040f0e40b53dmr6611887wmo.1.1707813714970; Tue, 13 Feb 2024 00:41:54 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m18-20020a5d56d2000000b0033b60bad2fcsm8837068wrw.113.2024.02.13.00.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 00:41:54 -0800 (PST) Message-ID: <0aca08a2cb5d679dc4d5dd9401f989d026c80b5b.1707813709.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 08:41:42 +0000 Subject: [PATCH 06/12] merge_bases_many(): pass on errors from `paint_down_to_common()` Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin The `paint_down_to_common()` function was just taught to indicate parsing errors, and now the `merge_bases_many()` function is aware of that, too. One tricky aspect is that `merge_bases_many()` parses commits of its own, but wants to gracefully handle the scenario where NULL is passed as a merge head, returning the empty list of merge bases. The way this was handled involved calling `repo_parse_commit(NULL)` and relying on it to return an error. This has to be done differently now so that we can handle missing commits correctly by producing a fatal error. Next step: adjust the caller of `merge_bases_many()`: `get_merge_bases_many_0()`. Signed-off-by: Johannes Schindelin --- commit-reach.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/commit-reach.c b/commit-reach.c index dafe117036b..c9969da8c6c 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -129,39 +129,47 @@ static int paint_down_to_common(struct repository *r, return 0; } -static struct commit_list *merge_bases_many(struct repository *r, - struct commit *one, int n, - struct commit **twos) +static int merge_bases_many(struct repository *r, + struct commit *one, int n, + struct commit **twos, + struct commit_list **result) { struct commit_list *list = NULL; - struct commit_list *result = NULL; int i; for (i = 0; i < n; i++) { - if (one == twos[i]) + if (one == twos[i]) { /* * We do not mark this even with RESULT so we do not * have to clean it up. */ - return commit_list_insert(one, &result); + *result = commit_list_insert(one, result); + return 0; + } } + if (!one) + return 0; if (repo_parse_commit(r, one)) - return NULL; + return error(_("could not parse commit %s"), + oid_to_hex(&one->object.oid)); for (i = 0; i < n; i++) { + if (!twos[i]) + return 0; if (repo_parse_commit(r, twos[i])) - return NULL; + return error(_("could not parse commit %s"), + oid_to_hex(&twos[i]->object.oid)); } if (paint_down_to_common(r, one, n, twos, 0, 0, &list) < 0) - return NULL; + return -1; while (list) { struct commit *commit = pop_commit(&list); if (!(commit->object.flags & STALE)) - commit_list_insert_by_date(commit, &result); + commit_list_insert_by_date(commit, result); } - return result; + return 0; } struct commit_list *get_octopus_merge_bases(struct commit_list *in) @@ -399,10 +407,11 @@ static struct commit_list *get_merge_bases_many_0(struct repository *r, { struct commit_list *list; struct commit **rslt; - struct commit_list *result; + struct commit_list *result = NULL; int cnt, i; - result = merge_bases_many(r, one, n, twos); + if (merge_bases_many(r, one, n, twos, &result) < 0) + return NULL; for (i = 0; i < n; i++) { if (one == twos[i]) return result; From patchwork Tue Feb 13 08:41:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13554709 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC8C0225AF for ; Tue, 13 Feb 2024 08:41:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813720; cv=none; b=kio7HFiQdbe/neMzSveyWa+ASLfYb1IILapZUKnZmmGOtJbjTKnCi0efF5+yojou0NJCUa6RTY2Y1FFQFq+LZo77QYUMc1E5Wyw1s6bFYb4wW7IImXrIO0gTOZu3hzRhB7Fwf6ZyHNYn/0qrGup5vntdspgTkLFP+9OhyEhwDlM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813720; c=relaxed/simple; bh=38f4SvXMAXAAp49D4JyECLnhScsTxR8aI+Ev4bA03UE=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=k1pNEsNp9Si+tQ8Q3Dafnoae6TgCvIWYWpPf0IGOJBecAFJYFCNftr3vyI+mpP9gdKqXMJNluo8p+gVWGwEvvftsYgzBghf++9cQPx3YEGzqJEzhSqqgXuzYWu5qzm7Q4jyfWEyepsaDFICFEcf+qruvSxIX3jSkeoc+EIjZKKI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XtzJ5WtI; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XtzJ5WtI" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-51182ece518so2900034e87.3 for ; Tue, 13 Feb 2024 00:41:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707813716; x=1708418516; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=+DxeN9rSU8m3tFIc0CnmTjy51tks/aFaDfRedgvv/R0=; b=XtzJ5WtIk/ItVQQQrYO6NNcIbJ/mzwt46y9ynotiE9yF3Geaa6oCLV5ix2/iFJect8 O9QgiDD6aGSmSAqdpPyCPUhbiq2CpWTVrgq3fw0hWJPrQcAhSQjSQSpDkr+KHumUYk5A khli/Fd7Xd1kKaEpp+h8yAYK+0VyG/8mlxPCG7iBknYRSNBgkQR9A+DOB5MVqFcdeESb D+BhKslqsc0ZS1g5d3U1oznZfL+Zt4RSXz9xajmcnvIom67U2LGHTMk/E3mEvOk6kIDY Ej7oKOcxY9xSWt2KNYF2yI5BSdPBjNISVUmdL21gCeluvY9V5W8Tw0bZwrEnxsjI7RMt 53Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707813716; x=1708418516; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+DxeN9rSU8m3tFIc0CnmTjy51tks/aFaDfRedgvv/R0=; b=UVNF4MyXZVIIM6LB+NEP60v/DWxL9Dgm5Jo7SnzYtEuPcGeQlXAL40S087Tzml88Tj o1hXWI85o6C6gv+Gpg2uFKQSJsndPlhOa5DeUj3FEa8vSNOIORooK1xG5R8dceOoUmue hC5cqBDXOI8tlX50qmh1MtLYD2G4ImhaTMsduZ4QB5xirZPGljD+kKeapk7vggfHUM9m NzGgbCQ993IJkAiEnkS+lWQ8umBOib6FJPoHzN619aJuvEZ+aAzr1HUAPiMqen7tKAGC Z+X+hNXiose68Am716kuOer5++afFCVWcc8ibdF1JAjeQoVC6dr26a9gtcQ/4F7EcEku AqTw== X-Gm-Message-State: AOJu0YzJNMiGy3H/T2XhrMRjX0Lawe51H0PrciCiIBuSH6Ss9RjoOoKS aJ8y2xPi3H2RCGfr3zHu2vnDCs5Asby0bB9r6AdqrldZMryEApRUhFzUjtRQ X-Google-Smtp-Source: AGHT+IFjP9vB8VfT8vTTHMFblHLXK9UXiOicB2dZ3Mz7U4Y/VHMwV/uEPzyBqGosFWouYegfIX1Ryg== X-Received: by 2002:ac2:5b0d:0:b0:510:526:182b with SMTP id v13-20020ac25b0d000000b005100526182bmr6330757lfn.67.1707813716121; Tue, 13 Feb 2024 00:41:56 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r11-20020a05600c458b00b00410504b582csm11060142wmo.11.2024.02.13.00.41.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 00:41:55 -0800 (PST) Message-ID: <03734cc09dab415f05c5524b2a1e3492fefad8c2.1707813709.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 08:41:43 +0000 Subject: [PATCH 07/12] get_merge_bases_many_0(): pass on errors from `merge_bases_many()` Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin The `merge_bases_many()` function was just taught to indicate parsing errors, and now the `get_merge_bases_many_0()` function is aware of that, too. Next step: adjust the callers of `get_merge_bases_many_0()`. Signed-off-by: Johannes Schindelin --- commit-reach.c | 57 +++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/commit-reach.c b/commit-reach.c index c9969da8c6c..359853275a9 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -399,37 +399,38 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt return remove_redundant_no_gen(r, array, cnt); } -static struct commit_list *get_merge_bases_many_0(struct repository *r, - struct commit *one, - int n, - struct commit **twos, - int cleanup) +static int get_merge_bases_many_0(struct repository *r, + struct commit *one, + int n, + struct commit **twos, + int cleanup, + struct commit_list **result) { struct commit_list *list; struct commit **rslt; - struct commit_list *result = NULL; int cnt, i; - if (merge_bases_many(r, one, n, twos, &result) < 0) - return NULL; + if (merge_bases_many(r, one, n, twos, result) < 0) + return -1; for (i = 0; i < n; i++) { if (one == twos[i]) - return result; + return 0; } - if (!result || !result->next) { + if (!*result || !(*result)->next) { if (cleanup) { clear_commit_marks(one, all_flags); clear_commit_marks_many(n, twos, all_flags); } - return result; + return 0; } /* There are more than one */ - cnt = commit_list_count(result); + cnt = commit_list_count(*result); CALLOC_ARRAY(rslt, cnt); - for (list = result, i = 0; list; list = list->next) + for (list = *result, i = 0; list; list = list->next) rslt[i++] = list->item; - free_commit_list(result); + free_commit_list(*result); + *result = NULL; clear_commit_marks(one, all_flags); clear_commit_marks_many(n, twos, all_flags); @@ -437,13 +438,12 @@ static struct commit_list *get_merge_bases_many_0(struct repository *r, cnt = remove_redundant(r, rslt, cnt); if (cnt < 0) { free(rslt); - return NULL; + return -1; } - result = NULL; for (i = 0; i < cnt; i++) - commit_list_insert_by_date(rslt[i], &result); + commit_list_insert_by_date(rslt[i], result); free(rslt); - return result; + return 0; } struct commit_list *repo_get_merge_bases_many(struct repository *r, @@ -451,7 +451,12 @@ struct commit_list *repo_get_merge_bases_many(struct repository *r, int n, struct commit **twos) { - return get_merge_bases_many_0(r, one, n, twos, 1); + struct commit_list *result = NULL; + if (get_merge_bases_many_0(r, one, n, twos, 1, &result) < 0) { + free_commit_list(result); + return NULL; + } + return result; } struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r, @@ -459,14 +464,24 @@ struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r, int n, struct commit **twos) { - return get_merge_bases_many_0(r, one, n, twos, 0); + struct commit_list *result = NULL; + if (get_merge_bases_many_0(r, one, n, twos, 0, &result) < 0) { + free_commit_list(result); + return NULL; + } + return result; } struct commit_list *repo_get_merge_bases(struct repository *r, struct commit *one, struct commit *two) { - return get_merge_bases_many_0(r, one, 1, &two, 1); + struct commit_list *result = NULL; + if (get_merge_bases_many_0(r, one, 1, &two, 1, &result) < 0) { + free_commit_list(result); + return NULL; + } + return result; } /* From patchwork Tue Feb 13 08:41:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13554710 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F50F225DA for ; Tue, 13 Feb 2024 08:41:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813721; cv=none; b=T4CU87qEoccFkP4N7XXG6aurWmQdwqFdvWrZTQw/cStTDM4P08iJuE/2EU2rrndEqQRKnPzAPTm1SitXYn17lRDeZFIB3TqA/KY53qPVMV6sLK9Zm8i9kHD8a7Ih2h3Paei3XHMb3Qux1mYk3EwzSM4MTWu6YMVULd/LYEuOdBI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813721; c=relaxed/simple; bh=O6WbFAlBEad2plwIzBn2HkrOpyOVgRH7tgVtFnIUY8g=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=XtEhFwOfNjKvxq+uhjdprug7lo/soxuD5m/uoysUF5u/lqBCcs3fiay19xwcvjt3cYf7KGcOi1VIo24c0Lklyq3NA6B6g3ZyPQQlUEq1a/TpLmnwvzF1+Yur0Nlk+328b8ObpdNHBxDGaPpW1repcCFYkYNoliJyobMnBFadCIg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NXyJsP4h; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NXyJsP4h" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-33b29b5ea96so1919738f8f.0 for ; Tue, 13 Feb 2024 00:41:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707813717; x=1708418517; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=D0YPV023e17Vg3xNyIe0N/Q6qOxZ7eBWuxiV2ENQ/YQ=; b=NXyJsP4hFo/W+/gRhUohH2mATgSG2g5BGx9wvUbRP2R8rYvPDTvhxp0Fr1Av5K+pBz 42Uq/8V+Kz1cRREojUNtzyg1BrJpjGsTxdpJ1/cWdzWpIQKlSb4NmQqviZ61f2P4Qeji 2cbGHEwl0cpmhC3ClNRsilEd9Icxdb9misjWpEYiVe7qFe6ry7Z4sPM93qkP8fy2spFW vTaHbyqFuFRdsUXHOhE3vV8wB5CJJNIKcRFY8PxS64L88gEOeCNyQFX81RqBi9tYi09F RVWyefgdvuFzux62GhoH1nlP8MyeNprW8+5slYQR1qF1VMcSD05bNL2uynQfvvhdaM9y /yLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707813717; x=1708418517; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D0YPV023e17Vg3xNyIe0N/Q6qOxZ7eBWuxiV2ENQ/YQ=; b=wDJbrA6Tc68rzj3ub7UGwt4CbDMVndFZW/MiE1jiuKfBonlVMMg9Kknmj8kgQXmZR3 yDJ83pud+IHHml3rLcjZR5hCRIEuCB+3AiyIbw9ov1ENvlxua5uxw7ci/Rmp5xXa6kQv Ymn67DmrHjRyBeiKEnQyDOKS9Fpw+k6hKML9HGmw5/wxa9ySmI7P/e5eQP0Yw/wZdP8y ut1tQCBY0Hlp5Rm0U2rKrTLfgu3ow73bGav8pB4vhXRugm8XLCKKhVl6ON9qorccWrqG p+ETP9vJef1NHEw4//hsT6Rd0xPWrWre01jENY37/OF9G2HlTZ65SIxdw/DePx82ve+n JsTA== X-Gm-Message-State: AOJu0YzM2vC7m625vQR2LzZVz1lZAt1bE+qGyC261CtuRpeQi/V8sI6c /VHYub3zRhNh+BWe1FQkhyaaqtqR+cm8C8v9ut2t7hXfOSqza+CYx7tgRQgg X-Google-Smtp-Source: AGHT+IGsi3LdykkaOUMMmlRsDCtq7rWz5UnSz+0ayyFjG+KgA1tsJSgMVJHYkXIKP+FbKPY+9sKrhg== X-Received: by 2002:a05:6000:8b:b0:33a:ead3:6438 with SMTP id m11-20020a056000008b00b0033aead36438mr1726665wrx.33.1707813716833; Tue, 13 Feb 2024 00:41:56 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c14-20020adfe70e000000b0033afe6968bfsm8880523wrm.64.2024.02.13.00.41.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 00:41:56 -0800 (PST) Message-ID: <43c33e2eac4e5addc039ede6e3943de4cab4faee.1707813709.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 08:41:44 +0000 Subject: [PATCH 08/12] repo_get_merge_bases(): pass on errors from `merge_bases_many()` Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin The `merge_bases_many()` function was just taught to indicate parsing errors, and now the `repo_get_merge_bases()` function (which is also surfaced via the `repo_get_merge_bases()` macro) is aware of that, too. Naturally, there are a lot of callers that need to be adjusted now, too. Next step: adjust the callers of `get_octopus_merge_bases()`. Signed-off-by: Johannes Schindelin --- builtin/log.c | 10 +++++----- builtin/merge-tree.c | 5 +++-- builtin/merge.c | 20 ++++++++++++-------- builtin/rebase.c | 8 +++++--- builtin/rev-parse.c | 5 +++-- commit-reach.c | 23 +++++++++++------------ commit-reach.h | 7 ++++--- diff-lib.c | 5 +++-- log-tree.c | 5 +++-- merge-ort.c | 6 +++++- merge-recursive.c | 4 +++- notes-merge.c | 3 ++- object-name.c | 5 +++-- revision.c | 10 ++++++---- sequencer.c | 8 ++++++-- submodule.c | 7 ++++++- t/t4301-merge-tree-write-tree.sh | 12 ++++++++++++ 17 files changed, 92 insertions(+), 51 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index 1705da71aca..befafd6ae04 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1702,11 +1702,11 @@ static struct commit *get_base_commit(const char *base_commit, */ while (rev_nr > 1) { for (i = 0; i < rev_nr / 2; i++) { - struct commit_list *merge_base; - merge_base = repo_get_merge_bases(the_repository, - rev[2 * i], - rev[2 * i + 1]); - if (!merge_base || merge_base->next) { + struct commit_list *merge_base = NULL; + if (repo_get_merge_bases(the_repository, + rev[2 * i], + rev[2 * i + 1], &merge_base) < 0 || + !merge_base || merge_base->next) { if (die_on_failure) { die(_("failed to find exact merge base")); } else { diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index a35e0452d66..76200250629 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -463,8 +463,9 @@ static int real_merge(struct merge_tree_options *o, * Get the merge bases, in reverse order; see comment above * merge_incore_recursive in merge-ort.h */ - merge_bases = repo_get_merge_bases(the_repository, parent1, - parent2); + if (repo_get_merge_bases(the_repository, parent1, + parent2, &merge_bases) < 0) + exit(128); if (!merge_bases && !o->allow_unrelated_histories) die(_("refusing to merge unrelated histories")); merge_bases = reverse_commit_list(merge_bases); diff --git a/builtin/merge.c b/builtin/merge.c index d748d46e135..ac9d58adc29 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1517,10 +1517,13 @@ int cmd_merge(int argc, const char **argv, const char *prefix) if (!remoteheads) ; /* already up-to-date */ - else if (!remoteheads->next) - common = repo_get_merge_bases(the_repository, head_commit, - remoteheads->item); - else { + else if (!remoteheads->next) { + if (repo_get_merge_bases(the_repository, head_commit, + remoteheads->item, &common) < 0) { + ret = 2; + goto done; + } + } else { struct commit_list *list = remoteheads; commit_list_insert(head_commit, &list); common = get_octopus_merge_bases(list); @@ -1631,7 +1634,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) struct commit_list *j; for (j = remoteheads; j; j = j->next) { - struct commit_list *common_one; + struct commit_list *common_one = NULL; struct commit *common_item; /* @@ -1639,9 +1642,10 @@ int cmd_merge(int argc, const char **argv, const char *prefix) * merge_bases again, otherwise "git merge HEAD^ * HEAD^^" would be missed. */ - common_one = repo_get_merge_bases(the_repository, - head_commit, - j->item); + if (repo_get_merge_bases(the_repository, head_commit, + j->item, &common_one) < 0) + exit(128); + common_item = common_one->item; free_commit_list(common_one); if (!oideq(&common_item->object.oid, &j->item->object.oid)) { diff --git a/builtin/rebase.c b/builtin/rebase.c index 043c65dccd9..06a55fc7325 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -879,7 +879,8 @@ static int can_fast_forward(struct commit *onto, struct commit *upstream, if (!upstream) goto done; - merge_bases = repo_get_merge_bases(the_repository, upstream, head); + if (repo_get_merge_bases(the_repository, upstream, head, &merge_bases) < 0) + exit(128); if (!merge_bases || merge_bases->next) goto done; @@ -898,8 +899,9 @@ static void fill_branch_base(struct rebase_options *options, { struct commit_list *merge_bases = NULL; - merge_bases = repo_get_merge_bases(the_repository, options->onto, - options->orig_head); + if (repo_get_merge_bases(the_repository, options->onto, + options->orig_head, &merge_bases) < 0) + exit(128); if (!merge_bases || merge_bases->next) oidcpy(branch_base, null_oid()); else diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index fde8861ca4e..c97d0f6144c 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -297,7 +297,7 @@ static int try_difference(const char *arg) show_rev(NORMAL, &end_oid, end); show_rev(symmetric ? NORMAL : REVERSED, &start_oid, start); if (symmetric) { - struct commit_list *exclude; + struct commit_list *exclude = NULL; struct commit *a, *b; a = lookup_commit_reference(the_repository, &start_oid); b = lookup_commit_reference(the_repository, &end_oid); @@ -305,7 +305,8 @@ static int try_difference(const char *arg) *dotdot = '.'; return 0; } - exclude = repo_get_merge_bases(the_repository, a, b); + if (repo_get_merge_bases(the_repository, a, b, &exclude) < 0) + exit(128); while (exclude) { struct commit *commit = pop_commit(&exclude); show_rev(REVERSED, &commit->object.oid, NULL); diff --git a/commit-reach.c b/commit-reach.c index 359853275a9..3471c933f6c 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -185,9 +185,12 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in) struct commit_list *new_commits = NULL, *end = NULL; for (j = ret; j; j = j->next) { - struct commit_list *bases; - bases = repo_get_merge_bases(the_repository, i->item, - j->item); + struct commit_list *bases = NULL; + if (repo_get_merge_bases(the_repository, i->item, + j->item, &bases) < 0) { + free_commit_list(bases); + return NULL; + } if (!new_commits) new_commits = bases; else @@ -472,16 +475,12 @@ struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r, return result; } -struct commit_list *repo_get_merge_bases(struct repository *r, - struct commit *one, - struct commit *two) +int repo_get_merge_bases(struct repository *r, + struct commit *one, + struct commit *two, + struct commit_list **result) { - struct commit_list *result = NULL; - if (get_merge_bases_many_0(r, one, 1, &two, 1, &result) < 0) { - free_commit_list(result); - return NULL; - } - return result; + return get_merge_bases_many_0(r, one, 1, &two, 1, result); } /* diff --git a/commit-reach.h b/commit-reach.h index 68f81549a44..2c6fcdd34f6 100644 --- a/commit-reach.h +++ b/commit-reach.h @@ -9,9 +9,10 @@ struct ref_filter; struct object_id; struct object_array; -struct commit_list *repo_get_merge_bases(struct repository *r, - struct commit *rev1, - struct commit *rev2); +int repo_get_merge_bases(struct repository *r, + struct commit *rev1, + struct commit *rev2, + struct commit_list **result); struct commit_list *repo_get_merge_bases_many(struct repository *r, struct commit *one, int n, struct commit **twos); diff --git a/diff-lib.c b/diff-lib.c index 0e9ec4f68af..498224ccce2 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -565,7 +565,7 @@ void diff_get_merge_base(const struct rev_info *revs, struct object_id *mb) { int i; struct commit *mb_child[2] = {0}; - struct commit_list *merge_bases; + struct commit_list *merge_bases = NULL; for (i = 0; i < revs->pending.nr; i++) { struct object *obj = revs->pending.objects[i].item; @@ -592,7 +592,8 @@ void diff_get_merge_base(const struct rev_info *revs, struct object_id *mb) mb_child[1] = lookup_commit_reference(the_repository, &oid); } - merge_bases = repo_get_merge_bases(the_repository, mb_child[0], mb_child[1]); + if (repo_get_merge_bases(the_repository, mb_child[0], mb_child[1], &merge_bases) < 0) + exit(128); if (!merge_bases) die(_("no merge base found")); if (merge_bases->next) diff --git a/log-tree.c b/log-tree.c index 504da6b519e..4f337766a39 100644 --- a/log-tree.c +++ b/log-tree.c @@ -1010,7 +1010,7 @@ static int do_remerge_diff(struct rev_info *opt, struct object_id *oid) { struct merge_options o; - struct commit_list *bases; + struct commit_list *bases = NULL; struct merge_result res = {0}; struct pretty_print_context ctx = {0}; struct commit *parent1 = parents->item; @@ -1035,7 +1035,8 @@ static int do_remerge_diff(struct rev_info *opt, /* Parse the relevant commits and get the merge bases */ parse_commit_or_die(parent1); parse_commit_or_die(parent2); - bases = repo_get_merge_bases(the_repository, parent1, parent2); + if (repo_get_merge_bases(the_repository, parent1, parent2, &bases) < 0) + exit(128); /* Re-merge the parents */ merge_incore_recursive(&o, bases, parent1, parent2, &res); diff --git a/merge-ort.c b/merge-ort.c index 64e76afe89f..88f23a37f5a 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -5060,7 +5060,11 @@ static void merge_ort_internal(struct merge_options *opt, struct strbuf merge_base_abbrev = STRBUF_INIT; if (!merge_bases) { - merge_bases = repo_get_merge_bases(the_repository, h1, h2); + if (repo_get_merge_bases(the_repository, h1, h2, + &merge_bases) < 0) { + result->clean = -1; + return; + } /* See merge-ort.h:merge_incore_recursive() declaration NOTE */ merge_bases = reverse_commit_list(merge_bases); } diff --git a/merge-recursive.c b/merge-recursive.c index e3fe7803cbe..0bed0b97424 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3632,7 +3632,9 @@ static int merge_recursive_internal(struct merge_options *opt, } if (!merge_bases) { - merge_bases = repo_get_merge_bases(the_repository, h1, h2); + if (repo_get_merge_bases(the_repository, h1, h2, + &merge_bases) < 0) + return -1; merge_bases = reverse_commit_list(merge_bases); } diff --git a/notes-merge.c b/notes-merge.c index 8799b522a55..51282934ae6 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -607,7 +607,8 @@ int notes_merge(struct notes_merge_options *o, assert(local && remote); /* Find merge bases */ - bases = repo_get_merge_bases(the_repository, local, remote); + if (repo_get_merge_bases(the_repository, local, remote, &bases) < 0) + exit(128); if (!bases) { base_oid = null_oid(); base_tree_oid = the_hash_algo->empty_tree; diff --git a/object-name.c b/object-name.c index 0bfa29dbbfe..89c34f9b49e 100644 --- a/object-name.c +++ b/object-name.c @@ -1481,7 +1481,7 @@ int repo_get_oid_mb(struct repository *r, struct object_id *oid) { struct commit *one, *two; - struct commit_list *mbs; + struct commit_list *mbs = NULL; struct object_id oid_tmp; const char *dots; int st; @@ -1509,7 +1509,8 @@ int repo_get_oid_mb(struct repository *r, two = lookup_commit_reference_gently(r, &oid_tmp, 0); if (!two) return -1; - mbs = repo_get_merge_bases(r, one, two); + if (repo_get_merge_bases(r, one, two, &mbs) < 0) + return -1; if (!mbs || mbs->next) st = -1; else { diff --git a/revision.c b/revision.c index 00d5c29bfce..3492cc95159 100644 --- a/revision.c +++ b/revision.c @@ -1965,7 +1965,7 @@ static void add_pending_commit_list(struct rev_info *revs, static void prepare_show_merge(struct rev_info *revs) { - struct commit_list *bases; + struct commit_list *bases = NULL; struct commit *head, *other; struct object_id oid; const char **prune = NULL; @@ -1980,7 +1980,8 @@ static void prepare_show_merge(struct rev_info *revs) other = lookup_commit_or_die(&oid, "MERGE_HEAD"); add_pending_object(revs, &head->object, "HEAD"); add_pending_object(revs, &other->object, "MERGE_HEAD"); - bases = repo_get_merge_bases(the_repository, head, other); + if (repo_get_merge_bases(the_repository, head, other, &bases) < 0) + exit(128); add_rev_cmdline_list(revs, bases, REV_CMD_MERGE_BASE, UNINTERESTING | BOTTOM); add_pending_commit_list(revs, bases, UNINTERESTING | BOTTOM); free_commit_list(bases); @@ -2068,14 +2069,15 @@ static int handle_dotdot_1(const char *arg, char *dotdot, } else { /* A...B -- find merge bases between the two */ struct commit *a, *b; - struct commit_list *exclude; + struct commit_list *exclude = NULL; a = lookup_commit_reference(revs->repo, &a_obj->oid); b = lookup_commit_reference(revs->repo, &b_obj->oid); if (!a || !b) return dotdot_missing(arg, dotdot, revs, symmetric); - exclude = repo_get_merge_bases(the_repository, a, b); + if (repo_get_merge_bases(the_repository, a, b, &exclude) < 0) + return -1; add_rev_cmdline_list(revs, exclude, REV_CMD_MERGE_BASE, flags_exclude); add_pending_commit_list(revs, exclude, flags_exclude); diff --git a/sequencer.c b/sequencer.c index d584cac8ed9..4417f2f1956 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3913,7 +3913,7 @@ static int do_merge(struct repository *r, int run_commit_flags = 0; struct strbuf ref_name = STRBUF_INIT; struct commit *head_commit, *merge_commit, *i; - struct commit_list *bases, *j; + struct commit_list *bases = NULL, *j; struct commit_list *to_merge = NULL, **tail = &to_merge; const char *strategy = !opts->xopts.nr && (!opts->strategy || @@ -4139,7 +4139,11 @@ static int do_merge(struct repository *r, } merge_commit = to_merge->item; - bases = repo_get_merge_bases(r, head_commit, merge_commit); + if (repo_get_merge_bases(r, head_commit, merge_commit, &bases) < 0) { + ret = -1; + goto leave_merge; + } + if (bases && oideq(&merge_commit->object.oid, &bases->item->object.oid)) { ret = 0; diff --git a/submodule.c b/submodule.c index e603a19a876..04931a5474b 100644 --- a/submodule.c +++ b/submodule.c @@ -595,7 +595,12 @@ static void show_submodule_header(struct diff_options *o, (!is_null_oid(two) && !*right)) message = "(commits not present)"; - *merge_bases = repo_get_merge_bases(sub, *left, *right); + *merge_bases = NULL; + if (repo_get_merge_bases(sub, *left, *right, merge_bases) < 0) { + message = "(corrupt repository)"; + goto output_header; + } + if (*merge_bases) { if ((*merge_bases)->item == *left) fast_forward = 1; diff --git a/t/t4301-merge-tree-write-tree.sh b/t/t4301-merge-tree-write-tree.sh index b2c8a43fce3..5d1e7aca4c8 100755 --- a/t/t4301-merge-tree-write-tree.sh +++ b/t/t4301-merge-tree-write-tree.sh @@ -945,4 +945,16 @@ test_expect_success 'check the input format when --stdin is passed' ' test_cmp expect actual ' +test_expect_success 'error out on missing commits as well' ' + git init --bare missing-commit.git && + git rev-list --objects side1 side3 >list-including-initial && + grep -v ^$(git rev-parse side1^) list && + git pack-objects missing-commit.git/objects/pack/missing-initial actual && + test_must_be_empty actual +' + test_done From patchwork Tue Feb 13 08:41:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13554711 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 843F722630 for ; Tue, 13 Feb 2024 08:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813722; cv=none; b=fJ/3YSzklMQU48GC5XnB8meDjhd7PIEeb+AE6HjIbYgX6DZ3FHpLh/oQBKj2AgNi14Ic3vDHH9yELfphLiELrk8tRyUqzLNnHozen2L5ddG6E63JaYv/BLPzBkkW3CnvBDY8X0EnkhUSnUHkuML1Kr93rPwPeBbLBCoKYtNuRPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813722; c=relaxed/simple; bh=RhPaQ9InCTyM16u1KIe3bU05+wmkCgkLhP5S3cx0sSM=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=b6gSQ7d6tDDkvvejix8//pwsYmx3aD4n2nxDCDwvHslCpEw351ZkjKSPyyfP0b8aoSmRUTNvdcYHQ3eYKIt2zmMZr5nI7ZipYbbaLtGAeGDouNSAFklUte4lWPs6hPmIrHrP5IpyYEj/CIzVrcZICMlqLJNynCKrpWDhnhrrgI8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VSVtPpib; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VSVtPpib" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-337cc8e72f5so2913306f8f.1 for ; Tue, 13 Feb 2024 00:42:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707813718; x=1708418518; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=zpWtaL7xg4+HRBnHxJRTgSdwPDTJo7o4ScowL/W2lcI=; b=VSVtPpibe99K8wRckxh5NlMwvtWCFqqPfhDMQFc5jOxeCmqGvMaMcCuBEhMEsc7W04 BKYM3Z8BfbMzBXKVM3fYTx4+jNNl8rMZKUBGH0QlKX0iqS+UAa76BX4HvJo3WTLQu8rk jXpPnFfXUQddPX3xcjgLQjA6Hu6woLH5MS7BIMRw91H2uiC9kNJFJSTHy6FE4yfMJ7uB zdR6r2MYciqaJQV0QUR1/wUmSua0X/PymUgKdpo6ueXko1uN+NY60+UtQ0hD+7u8521i U/ZPAwfUgmc9slXv+8npsAeW1z8rHpauWW1aXyatbrD5raKi3WC40ohakK5gJeppGXSu 1N1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707813718; x=1708418518; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zpWtaL7xg4+HRBnHxJRTgSdwPDTJo7o4ScowL/W2lcI=; b=BK0CdWlpjX0CFTeUXNhsHv0ZEoRTu31fQ9k5Icr1NJ/jJUFgGOcGUNG/LAszvb/J4Y G7Mv1S6wQBUs7p8AyTsy4LCABzidOZaXaHPL4ZhsJl344zl5988Z/TXknIrexKawsiR/ zx6Rw7Zx8qM0z//DvOOav+NgJbwijhVrf3CQAwQaVvyTlqFFEjcBxGhiYmNTIi4DAdbS XzmJU2C5q3nFspw8mfWbya5T37nqc9pS1DINrJwVYQf/LMNh1BvaB4ysROrr2OIMzqh9 dW6Aj1VZFrp6Zkx7UByfgitOhnqKiElC7vMBCTnvyAXespFx0MbnIQVpVB4DCLq7zLp5 wIOA== X-Gm-Message-State: AOJu0Yy7FBAKluWjF5XGzg3NmFKuv8TBM4xynlNkHYjiwcxeXQ+Jnkmt IC6S4BZ68/BpRaHHMIzTOGJwdgbCWWAfM78fIzfUJitpWavVYEWLxod2ZPJL X-Google-Smtp-Source: AGHT+IF8fJzasbPGYpmojb3Hy22nkvzpq8QQls+rBrWfk2T0DfaKFyAhUT5b3RSx08Gw0Fe0l3bxNQ== X-Received: by 2002:a5d:554e:0:b0:33a:ee4d:98c8 with SMTP id g14-20020a5d554e000000b0033aee4d98c8mr6445913wrw.61.1707813718135; Tue, 13 Feb 2024 00:41:58 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ay20-20020a5d6f14000000b0033b495b1d10sm9154883wrb.8.2024.02.13.00.41.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 00:41:57 -0800 (PST) Message-ID: <7fbf660e371454b309d962624d5121c87aed1e85.1707813709.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 08:41:45 +0000 Subject: [PATCH 09/12] get_octopus_merge_bases(): pass on errors from `merge_bases_many()` Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin The `merge_bases_many()` function was just taught to indicate parsing errors, and now the `repo_get_merge_bases()` function (which is also surfaced via the `get_merge_bases()` macro) is aware of that, too. Naturally, the callers need to be adjusted now, too. Next step: adjust `repo_get_merge_bases_many()`. Signed-off-by: Johannes Schindelin --- builtin/merge-base.c | 5 +++-- builtin/merge.c | 6 +++++- builtin/pull.c | 5 +++-- commit-reach.c | 20 +++++++++++--------- commit-reach.h | 2 +- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/builtin/merge-base.c b/builtin/merge-base.c index 0308fd73289..6faabfb6698 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -77,13 +77,14 @@ static int handle_independent(int count, const char **args) static int handle_octopus(int count, const char **args, int show_all) { struct commit_list *revs = NULL; - struct commit_list *result, *rev; + struct commit_list *result = NULL, *rev; int i; for (i = count - 1; i >= 0; i--) commit_list_insert(get_commit_reference(args[i]), &revs); - result = get_octopus_merge_bases(revs); + if (get_octopus_merge_bases(revs, &result) < 0) + return 128; free_commit_list(revs); reduce_heads_replace(&result); diff --git a/builtin/merge.c b/builtin/merge.c index ac9d58adc29..94c5b693972 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1526,7 +1526,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix) } else { struct commit_list *list = remoteheads; commit_list_insert(head_commit, &list); - common = get_octopus_merge_bases(list); + if (get_octopus_merge_bases(list, &common) < 0) { + free(list); + ret = 2; + goto done; + } free(list); } diff --git a/builtin/pull.c b/builtin/pull.c index e6f2942c0c5..0c5a55f2f4d 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -820,7 +820,7 @@ static int get_octopus_merge_base(struct object_id *merge_base, const struct object_id *merge_head, const struct object_id *fork_point) { - struct commit_list *revs = NULL, *result; + struct commit_list *revs = NULL, *result = NULL; commit_list_insert(lookup_commit_reference(the_repository, curr_head), &revs); @@ -830,7 +830,8 @@ static int get_octopus_merge_base(struct object_id *merge_base, commit_list_insert(lookup_commit_reference(the_repository, fork_point), &revs); - result = get_octopus_merge_bases(revs); + if (get_octopus_merge_bases(revs, &result) < 0) + exit(128); free_commit_list(revs); reduce_heads_replace(&result); diff --git a/commit-reach.c b/commit-reach.c index 3471c933f6c..1b618eb9cd1 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -172,24 +172,26 @@ static int merge_bases_many(struct repository *r, return 0; } -struct commit_list *get_octopus_merge_bases(struct commit_list *in) +int get_octopus_merge_bases(struct commit_list *in, struct commit_list **result) { - struct commit_list *i, *j, *k, *ret = NULL; + struct commit_list *i, *j, *k; if (!in) - return ret; + return 0; - commit_list_insert(in->item, &ret); + commit_list_insert(in->item, result); for (i = in->next; i; i = i->next) { struct commit_list *new_commits = NULL, *end = NULL; - for (j = ret; j; j = j->next) { + for (j = *result; j; j = j->next) { struct commit_list *bases = NULL; if (repo_get_merge_bases(the_repository, i->item, j->item, &bases) < 0) { free_commit_list(bases); - return NULL; + free_commit_list(*result); + *result = NULL; + return -1; } if (!new_commits) new_commits = bases; @@ -198,10 +200,10 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in) for (k = bases; k; k = k->next) end = k; } - free_commit_list(ret); - ret = new_commits; + free_commit_list(*result); + *result = new_commits; } - return ret; + return 0; } static int remove_redundant_no_gen(struct repository *r, diff --git a/commit-reach.h b/commit-reach.h index 2c6fcdd34f6..4690b6ecd0c 100644 --- a/commit-reach.h +++ b/commit-reach.h @@ -21,7 +21,7 @@ struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r, struct commit *one, int n, struct commit **twos); -struct commit_list *get_octopus_merge_bases(struct commit_list *in); +int get_octopus_merge_bases(struct commit_list *in, struct commit_list **result); int repo_is_descendant_of(struct repository *r, struct commit *commit, From patchwork Tue Feb 13 08:41:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13554712 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E01B23747 for ; Tue, 13 Feb 2024 08:42:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813724; cv=none; b=iGwEW6RcTz8NmGs7MufIkI07nzP7G4Hx1IuXxoubzirBP9ZaKL+bOhGAiKOAcyTRYnXfYexkMm5RIRhZGdPR06ZLoReZtiobPkgWJUj9WtyNhtO+7Okpj6T1Nb5XS6QdyP/gAqqNs5XfwHCdNsHQK9Zdqz/GOdnWxfzvBdvZ0qo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813724; c=relaxed/simple; bh=D4ngLwOzAbYmiCqMYRi4ETGueghrqBs77BO+RgXN7Lw=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=pyUvooLb5tXwBenWVkjqzP7te9h97CULhWYGzPK7eWtOWB6UhM3vbdG8F4Upayq6hm8J0haWk1rJq3vaWdC5BddV9mG9pbE1OUIB7xx4Bo7zDv2R96kqzN+vcq/OnF937aKyxCRbCyuDqcLcEEzCJfm/CWSkxsw16FI6odcBU/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ldThvLpj; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ldThvLpj" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-511972043c3so737463e87.1 for ; Tue, 13 Feb 2024 00:42:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707813719; x=1708418519; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=lLtERfHWGfDVQgYN0hsMKkK4fu+29ltz7NypP7JpjbA=; b=ldThvLpjErNjXUECV5Nuxap/hrCw5fT/lOXzl4PyfbYyL5w1/bFpV1mmr/yDk4saVp 7LmLqxA5JAbcOBnVIoUcEbwB2GlHY9su3XOWD2ckRMp01uJgQ0sGG+ZSZTeFBtRDIXMf Kbve1gZEAPBWjoru0ANs8bDOIKcfZq316QwynxXI74CTFb5bL2rK/GWDb2Abw0Ey/zwt jo2ibnfGMHrX3RrorJVxmCdItsMuW/EFGnIntAL3VRjsiArz4FJT3VDcUaCI2zqcVBI5 II6Q652cDR4yFY14ebbVe7Knp94itHWmnw9XMWUqciEEx00pWMSRK/QgT2OJWDeHyKM4 Oodg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707813719; x=1708418519; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lLtERfHWGfDVQgYN0hsMKkK4fu+29ltz7NypP7JpjbA=; b=InJdHWrRfv8LmuPBkrxjnSIsxg9Gk/FcGc4m5x3kNMpQLOvch4ZDWOZCM6Hd+AvDvf /ALPyss3pXO6UO2B/Kh8BTcqQuSymzvgLA0eEJYzamoYPY4PdrIuzT0pGREF8nm7uluw 1U4n1VPxWa/d8y/ADBMrDDNKnMUc5oa9EpIfKu1esWLWRGx1+smeQfiBRvG/g4zPu003 MJ08I0LdaObG7F9H4To6LQb/A/01tF3BCYvG1ls1kt9gUR2fL7iSZsqAfUst/Nv5EKSH W1uHDoYB9aCe2mAknb1Gj9A+lAxQUjdn4/njWuFRDOrp6GeH7SSfZlqyZW7r17I7mIaF YN6g== X-Gm-Message-State: AOJu0Yx0kQDERN4EGbeRETmGn9Q5A+UdOzGMbVvq/oDHs2Lyco3wSNsX n08Y59jDIgyOeWKPRC6NisI1PbQuT24UWb3Z4NdD2TnznbZlv5tcCNKxzluH X-Google-Smtp-Source: AGHT+IHDpbX9za/QhZIidbous859UTeUF2vE9zrSvSbgYAqiU++40rmVq8r9DNzHt0zTsEhsaJ6RRA== X-Received: by 2002:a05:6512:31d4:b0:510:ee2c:e9c4 with SMTP id j20-20020a05651231d400b00510ee2ce9c4mr8253747lfe.17.1707813719367; Tue, 13 Feb 2024 00:41:59 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r11-20020a05600c458b00b00410504b582csm11060312wmo.11.2024.02.13.00.41.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 00:41:58 -0800 (PST) Message-ID: <55757c3a35d73c7fd81ec7fb19bb4ba6093e325b.1707813709.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 08:41:46 +0000 Subject: [PATCH 10/12] repo_get_merge_bases_many(): pass on errors from `merge_bases_many()` Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin The `merge_bases_many()` function was just taught to indicate parsing errors, and now the `repo_get_merge_bases_many()` function is aware of that, too. Naturally, there are a lot of callers that need to be adjusted now, too. Next stop: `repo_get_merge_bases_dirty()`. Signed-off-by: Johannes Schindelin --- bisect.c | 7 ++++--- builtin/log.c | 13 +++++++------ commit-reach.c | 16 ++++++---------- commit-reach.h | 7 ++++--- commit.c | 7 ++++--- t/helper/test-reach.c | 9 ++++++--- 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/bisect.c b/bisect.c index 1be8e0a2711..2018466d69f 100644 --- a/bisect.c +++ b/bisect.c @@ -851,10 +851,11 @@ static void handle_skipped_merge_base(const struct object_id *mb) static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int no_checkout) { enum bisect_error res = BISECT_OK; - struct commit_list *result; + struct commit_list *result = NULL; - result = repo_get_merge_bases_many(the_repository, rev[0], rev_nr - 1, - rev + 1); + if (repo_get_merge_bases_many(the_repository, rev[0], rev_nr - 1, + rev + 1, &result) < 0) + exit(128); for (; result; result = result->next) { const struct object_id *mb = &result->item->object.oid; diff --git a/builtin/log.c b/builtin/log.c index befafd6ae04..c75790a7cec 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1656,7 +1656,7 @@ static struct commit *get_base_commit(const char *base_commit, struct branch *curr_branch = branch_get(NULL); const char *upstream = branch_get_upstream(curr_branch, NULL); if (upstream) { - struct commit_list *base_list; + struct commit_list *base_list = NULL; struct commit *commit; struct object_id oid; @@ -1667,11 +1667,12 @@ static struct commit *get_base_commit(const char *base_commit, return NULL; } commit = lookup_commit_or_die(&oid, "upstream base"); - base_list = repo_get_merge_bases_many(the_repository, - commit, total, - list); - /* There should be one and only one merge base. */ - if (!base_list || base_list->next) { + if (repo_get_merge_bases_many(the_repository, + commit, total, + list, + &base_list) < 0 || + /* There should be one and only one merge base. */ + !base_list || base_list->next) { if (die_on_failure) { die(_("could not find exact merge base")); } else { diff --git a/commit-reach.c b/commit-reach.c index 1b618eb9cd1..f0006ab6422 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -451,17 +451,13 @@ static int get_merge_bases_many_0(struct repository *r, return 0; } -struct commit_list *repo_get_merge_bases_many(struct repository *r, - struct commit *one, - int n, - struct commit **twos) +int repo_get_merge_bases_many(struct repository *r, + struct commit *one, + int n, + struct commit **twos, + struct commit_list **result) { - struct commit_list *result = NULL; - if (get_merge_bases_many_0(r, one, n, twos, 1, &result) < 0) { - free_commit_list(result); - return NULL; - } - return result; + return get_merge_bases_many_0(r, one, n, twos, 1, result); } struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r, diff --git a/commit-reach.h b/commit-reach.h index 4690b6ecd0c..458043f4d58 100644 --- a/commit-reach.h +++ b/commit-reach.h @@ -13,9 +13,10 @@ int repo_get_merge_bases(struct repository *r, struct commit *rev1, struct commit *rev2, struct commit_list **result); -struct commit_list *repo_get_merge_bases_many(struct repository *r, - struct commit *one, int n, - struct commit **twos); +int repo_get_merge_bases_many(struct repository *r, + struct commit *one, int n, + struct commit **twos, + struct commit_list **result); /* To be used only when object flags after this call no longer matter */ struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r, struct commit *one, int n, diff --git a/commit.c b/commit.c index 8405d7c3fce..00add5d81c6 100644 --- a/commit.c +++ b/commit.c @@ -1054,7 +1054,7 @@ struct commit *get_fork_point(const char *refname, struct commit *commit) { struct object_id oid; struct rev_collect revs; - struct commit_list *bases; + struct commit_list *bases = NULL; int i; struct commit *ret = NULL; char *full_refname; @@ -1079,8 +1079,9 @@ struct commit *get_fork_point(const char *refname, struct commit *commit) for (i = 0; i < revs.nr; i++) revs.commit[i]->object.flags &= ~TMP_MARK; - bases = repo_get_merge_bases_many(the_repository, commit, revs.nr, - revs.commit); + if (repo_get_merge_bases_many(the_repository, commit, revs.nr, + revs.commit, &bases) < 0) + exit(128); /* * There should be one and only one merge base, when we found diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c index aa816e168ea..84ee9da8681 100644 --- a/t/helper/test-reach.c +++ b/t/helper/test-reach.c @@ -117,9 +117,12 @@ int cmd__reach(int ac, const char **av) else if (!strcmp(av[1], "is_descendant_of")) printf("%s(A,X):%d\n", av[1], repo_is_descendant_of(r, A, X)); else if (!strcmp(av[1], "get_merge_bases_many")) { - struct commit_list *list = repo_get_merge_bases_many(the_repository, - A, X_nr, - X_array); + struct commit_list *list = NULL; + if (repo_get_merge_bases_many(the_repository, + A, X_nr, + X_array, + &list) < 0) + exit(128); printf("%s(A,X):\n", av[1]); print_sorted_commit_ids(list); } else if (!strcmp(av[1], "reduce_heads")) { From patchwork Tue Feb 13 08:41:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13554713 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7ED0241E0 for ; Tue, 13 Feb 2024 08:42:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813724; cv=none; b=jjnC0PPMkD3GN5t/C8OLXYVXpjYnZwt9vLdS333h9Mba7cBawa1X8aSXltWN2dQgIRTI2qh7hh4XPqRyp+HkjiFaijUTX9/Nfbt6FVm6+ucooZBo7u7yFoD/aIjyG+SkeNug0Ej6fqdVYQxRIsEQ0KCoSHQdNZqi4fBb3y6j0T0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813724; c=relaxed/simple; bh=RxoT3URQxzSKtRB5NWpYXhSDr6yLg79ox/MyvN4ui3g=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=Rs1coIY2dOMx8bSd7pEJuilxTHeC9IwhIVx1pajwyL2Hjj9kHmEROfn1OdXiUD/ZcqjQ1fY37caAMWiDaZUB6oop/unbeVZ0ONOABvZc5pqFACuPLm6+8PgKY5AhC0BEkgONq+RYiSCHwXIHKKqWCXIg05vSAbPagMhfvhFhqRo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=B2P88BjN; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="B2P88BjN" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-33b86bc4bbaso786578f8f.0 for ; Tue, 13 Feb 2024 00:42:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707813721; x=1708418521; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=qZKwi/ctzH3R8FrIFeuzQhRnkbkMXS7fqsSPnlKaOtA=; b=B2P88BjNdPa2AfUohqo//3R9Ni1gVXPGX8S36KEOD1y6CsJZaPiix14vwYuzk1q9lC 3IaiQDd6eqqAfizGYboNK5NgJq9dGUMmmYbUHGxSooBRMS6zJfVT0kufZJXvB6zL13PA BFysf+OunP+EiFD+ujneQ6Bx53IF6OCC2pcu3Sw11ZwDfHZau/JG/p/BfmbYIBWikiV8 vJ31LCgK3qJlQkJymRRWhb8g45q4SI5Yn7lslRIRaXq65M5inaqrhG2yzA5tNzmJuHKl VyzMG/pxXlHyipTy/2RF5hJ1C9DHlFcBEdmhJcUmzegPi1EfqBtQMe/e+TCebHtPq7bB 71wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707813721; x=1708418521; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qZKwi/ctzH3R8FrIFeuzQhRnkbkMXS7fqsSPnlKaOtA=; b=qXsWmcUoO4yIbUnspDIm3K5Jh1obmE5+mu2AG5wOT/WWk/MmIaMTeaAUQMX6YcnLNr zoxIWqHDgTjcKwkpa5tnelQzcpRxgu9kk/SSvRKKIIdsQL2DtMf0DHTVashK1fk1bQh1 J7jr6iGhT9MHt2RCs2Aj+r2un+JJAbTJ7MPNFHY/ECC6MJoq2MArTrNki/NvEa43+zZx YQGuhLPlBGr2zZLfiAHLaUz94ZAXyN7Opw7UwH87NsEUZTcZNPSwJZYv0/pN+sRyH/fc 9QmOH1B+s9vouAAZrB+XCpACfsR9N/ytYiUhYvR4m80fDmsidAGqcWfWT5ptH/eQO5cf JdXg== X-Gm-Message-State: AOJu0YzMOhSHIN6Q8/OMwoL2LKoVH+7IMNP28TtaOWKkDw/zbthCLWJ3 S+FQN+PeseKrfn9F5koMdlVIXNZZjIypPXZdcG3ppNqzlFy4K0oRWezLKIfX X-Google-Smtp-Source: AGHT+IEhgtZtd2+Ruuj2UluqAnvBtxpJe9J7GAKSNKR15fjgg4a36KVAcERAvfXpbncMqg1ooT30Tg== X-Received: by 2002:adf:f04b:0:b0:33a:e808:31a4 with SMTP id t11-20020adff04b000000b0033ae80831a4mr7109503wro.55.1707813720615; Tue, 13 Feb 2024 00:42:00 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k23-20020a5d5257000000b0033b444a39a9sm8863005wrc.54.2024.02.13.00.41.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 00:41:59 -0800 (PST) Message-ID: In-Reply-To: References: Date: Tue, 13 Feb 2024 08:41:47 +0000 Subject: [PATCH 11/12] repo_get_merge_bases_many_dirty(): pass on errors from `merge_bases_many()` Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin The `merge_bases_many()` function was just taught to indicate parsing errors, and now the `repo_get_merge_bases_many_dirty()` function is aware of that, too. Signed-off-by: Johannes Schindelin --- builtin/merge-base.c | 7 ++++--- commit-reach.c | 16 ++++++---------- commit-reach.h | 7 ++++--- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/builtin/merge-base.c b/builtin/merge-base.c index 6faabfb6698..2b6af1bc35b 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -13,10 +13,11 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all) { - struct commit_list *result, *r; + struct commit_list *result = NULL, *r; - result = repo_get_merge_bases_many_dirty(the_repository, rev[0], - rev_nr - 1, rev + 1); + if (repo_get_merge_bases_many_dirty(the_repository, rev[0], + rev_nr - 1, rev + 1, &result) < 0) + return -1; if (!result) return 1; diff --git a/commit-reach.c b/commit-reach.c index f0006ab6422..25b39c302a8 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -460,17 +460,13 @@ int repo_get_merge_bases_many(struct repository *r, return get_merge_bases_many_0(r, one, n, twos, 1, result); } -struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r, - struct commit *one, - int n, - struct commit **twos) +int repo_get_merge_bases_many_dirty(struct repository *r, + struct commit *one, + int n, + struct commit **twos, + struct commit_list **result) { - struct commit_list *result = NULL; - if (get_merge_bases_many_0(r, one, n, twos, 0, &result) < 0) { - free_commit_list(result); - return NULL; - } - return result; + return get_merge_bases_many_0(r, one, n, twos, 0, result); } int repo_get_merge_bases(struct repository *r, diff --git a/commit-reach.h b/commit-reach.h index 458043f4d58..bf63cc468fd 100644 --- a/commit-reach.h +++ b/commit-reach.h @@ -18,9 +18,10 @@ int repo_get_merge_bases_many(struct repository *r, struct commit **twos, struct commit_list **result); /* To be used only when object flags after this call no longer matter */ -struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r, - struct commit *one, int n, - struct commit **twos); +int repo_get_merge_bases_many_dirty(struct repository *r, + struct commit *one, int n, + struct commit **twos, + struct commit_list **result); int get_octopus_merge_bases(struct commit_list *in, struct commit_list **result); From patchwork Tue Feb 13 08:41:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13554714 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3567C24211 for ; Tue, 13 Feb 2024 08:42:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813724; cv=none; b=gzPuGsTfDkg4rRYGSTiw6Dgn9w+okV4qOEj4OQPYnBM586O/QngOo6MVEySLUwXN0+KHi1PLP0Q8mC6Ggff8L+Cp5vFgN0cvfgjLX7p6Tn9+46J/JCV75dKPuXUaOJhll9d2tDoI2pbebY+X+KNe+b7Iq/dKXau6fqpuKQEHJhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707813724; c=relaxed/simple; bh=4tXWpJHmXJ81JORgGGgPuPoD0yIYiVuZcz0S4p1MMlo=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=FyLq8pvbPsbM61ADxzQYk1LMnMpYqAIe4JLvT2lUqb8dq6NyKSi0dtd1TEu3VUvcAkmIYkHSYPr59zR93VwH4Yoh19W51pWMNnNVN2UJqB5aPGpCRrRAFwk9oqS8t4TzwLQGClS3355IxOijuC45UD04vYXbsmtkZCsipuo8Pv8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MGGNWFTU; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MGGNWFTU" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-410db155e57so12086075e9.1 for ; Tue, 13 Feb 2024 00:42:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707813721; x=1708418521; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=dayC9VH7FeXOIUaYFGKaD/5B9RiZ/xqRFScCbcT5yN4=; b=MGGNWFTUGvi/eKrEiIpVqE15kbl22irhTa5otXEHjoeRjZRaYaNdxoG7SxvaD+xaCG VtKvoYQsmc26BLp4uTkTcNrE0V0fq491byPsypRPCEG6M4WEelb+560WGDdMpPcLTnCj QX7kE1XP5Es5nzlkBTL2WNAtR0U4bqr+oniT2iS6RSmnbnOer3CcmXZ862Qo+7BB1TS6 SwGMyklzAkBUMuJZlRYq/2Y+BTl+VC2kUKEAZe58lpIx2MwFjNYAxy5tmfrw/YW0sZps GDiBwOogXLzMYubITZpUDthDU5YwnhakPkYtyw7/g8nRVloAZH5R9UC/teQwo1dkvryn /Axg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707813721; x=1708418521; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dayC9VH7FeXOIUaYFGKaD/5B9RiZ/xqRFScCbcT5yN4=; b=VCAEzIJFhOmHeaer4BwmhB4oLI5Sw6FMWqeD81eGzc6FZRw9KTAcddlaCDY2cs+O5K jYYSwpUUaJa7poJHWGfyviVd4Hyv24RccqoUP+ZKD8ZEuMzJpmBLfsgxdeOwjuLpYIjd 58ruUV9sDtSQmOqfhMPhwQbvn9VG8hrMv53syZqedo2Ao4iaOFjpDK9YgI46qYgw1Zpi e7wv7o3KD7mgiUyzgp4h9sSlopREzMnxxIKPjjui+telP6GFkD1pBrc61porl4bCOEI9 RtWVl7NtW7EQNQnKvIQrgq7FGZJ2r4Dipiu71IM3pLOwPaeMJYD0TEdGQVN+2HZc9jY5 KVmQ== X-Gm-Message-State: AOJu0YxQoDSPwrOodaiH5Jml5i0KOGrFnUy8b6MtkOPLmgLkzLa/DVfN W8yLT8gtIuDjj8cDjV5Mslb5iBQmjLDabXFhRgn+HEzUWk2duADM3lLS+0mV X-Google-Smtp-Source: AGHT+IGTiBoubDh9u4yqHY68BJ1qtmo+1yuL/ZoY6rN7xGBjg1S0KPch1Y2GDmhFewGHFzKXXQPA3Q== X-Received: by 2002:a5d:47ab:0:b0:33b:523f:2aa7 with SMTP id 11-20020a5d47ab000000b0033b523f2aa7mr8468513wrb.45.1707813721173; Tue, 13 Feb 2024 00:42:01 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ba24-20020a0560001c1800b0033cdf4bea19sm323515wrb.9.2024.02.13.00.42.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 00:42:00 -0800 (PST) Message-ID: <33894600ae77156ba022ebba6cec4f2b24c77cd2.1707813709.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 13 Feb 2024 08:41:48 +0000 Subject: [PATCH 12/12] paint_down_to_common(): special-case shallow/partial clones Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin In shallow/partial clones, we _expect_ commits to be missing. Let's teach the merge-base logic to ignore those and simply go ahead and treat the involved commit histories as cut off at that point. Signed-off-by: Johannes Schindelin --- commit-reach.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/commit-reach.c b/commit-reach.c index 25b39c302a8..4af60c2501d 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -10,6 +10,8 @@ #include "tag.h" #include "commit-reach.h" #include "ewah/ewok.h" +#include "shallow.h" +#include "promisor-remote.h" /* Remember to update object flag allocation in object.h */ #define PARENT1 (1u<<16) @@ -115,7 +117,9 @@ static int paint_down_to_common(struct repository *r, * dispatched with a `die()`. */ free_commit_list(*result); - if (ignore_missing_commits) + if (ignore_missing_commits || + is_repository_shallow(r) || + repo_has_promisor_remote(r)) return 0; return error(_("could not parse commit %s"), oid_to_hex(&p->object.oid));