From patchwork Thu Feb 22 13:21: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: 13567325 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.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 A79DE132483 for ; Thu, 22 Feb 2024 13:21:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608117; cv=none; b=pnyDpdxl+wJ0fpitHyF3g9XRkN4ZoBZxFu6AuZdn3lDRzmrliI3R5+qlbzlmGBwUj+sTIGfosQxanziv7SdmP0izeGbMcL3HRFZ3rL3wILqUOD6lV7cGb8+PGBl6BvRA0A6CScU/0VHQQFIm+fxKgb5BFiRWew9BgnCi7pc5vzY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608117; c=relaxed/simple; bh=CIKQ8Bb1sUrqihQ5MJIFUcbno3QB/yb6ILzqtp+yaVo=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=IuXjSxhrLvfxa8nUxv98/kN7p3hbiO0DSDxGJC4s8c3iED91hzEPtiDmSzpxhI9kXFBo8fRdjLw+9++JYPprqHQMQOtjFWrMbVIHmfofjRI/yWFMdjLDH6q8PtRu/i5YWSTCtirPZdkA7XUFpYxLMBuIokGGAsFZewL1pWu58GE= 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=apHELFcy; arc=none smtp.client-ip=209.85.221.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="apHELFcy" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-33d153254b7so4113678f8f.0 for ; Thu, 22 Feb 2024 05:21:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708608113; x=1709212913; 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=qTSR9XKJE4GOW6G6lNSpqCjAzTbfFv8qkdL27MvMrxQ=; b=apHELFcySwK2/APY5kr+S/8yLVWO29VXq4aQ3CVeOF2TjuamVk2TeqqC0Q9zH8A1QY J9haCAAcfIVUW91O6gpeOaYdjj/qzHIIu72sAZBgv4/PMSz/q8zEN/buRctjG6ULfTVZ 2tlpsgoeu9zJ48VKG5aN/rPGzMC9uY7YktHmR4ErOLllMh+IRAQVTKG8zseXRyCe3T2s G97ISARj8xsmeuRSfNFinYFpX7ZNH0X9BHjfdMIv8/9fAFMZ0otDtlUYphXMBGv5nKgj r895C+4egr6tBtJhs6/TstCTtdgHwW5TEmUhFlrL6h9qZOkwNH63kBaeXHj50GJIk8GZ Ovzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708608113; x=1709212913; 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=qTSR9XKJE4GOW6G6lNSpqCjAzTbfFv8qkdL27MvMrxQ=; b=Mwfli+YVVNNZ7iNBzl/5j8XwK7BOSROzwhF6bp7a/WUMHSwMYNw3HDITTH3XmquyFB IGy9Ar+B3PPiIOXXskj9fyO0aMsF8e7ZBjHbDxocu6BML0xijnmQs3jS2Dnuc9CN5yIh zNKHi8QcDdfPMn64zPCPm6VrzpjUQ7Zj1Xo6qvtrnnec50XK33JC77119Usom4l1vHPk QWvyFwv10Wa1KsvY+Q7ElwLawG23uzdCxT0/zo7evjObnliYNMUucNnt5G6bn6WQhqb3 0gZZPeqz+nhgnJTS4xoomtBDNf9QeDMEy1HsXUemM1EY5+5ZJ4KHPdKvkRceoaqby1vu fEMQ== X-Gm-Message-State: AOJu0YyCmo1JRDaavFINywmbxH7GGL/o9gV8cSbHIlJuS21Rv4Xasx1I EozDGVXzl+PylXFva6/iyctMlNmR8jhyxdCOEMGoLaLlMbeV6EG1Wq4p1pC9 X-Google-Smtp-Source: AGHT+IF0CnRNdi2SmkJaGJv4oHy9lxl3Ap/+TYr61aZCZc3TMQ9UmK6/VN4GATv7EWXPnLvkAm5P4w== X-Received: by 2002:adf:e2c2:0:b0:33d:73de:ca3b with SMTP id d2-20020adfe2c2000000b0033d73deca3bmr4469263wrj.52.1708608113249; Thu, 22 Feb 2024 05:21:53 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b14-20020a05600010ce00b0033d06dfcf84sm20227058wrx.100.2024.02.22.05.21.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:21:53 -0800 (PST) Message-ID: <6e4e409cd43bcf445f811e171958ef4a169a0163.1708608110.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 22 Feb 2024 13:21:40 +0000 Subject: [PATCH v2 01/11] paint_down_to_common: plug two memory leaks 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: Patrick Steinhardt , 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. The priority queue has a similar issue: There might still be a commit in that queue. Let's release both, to address the potential memory leaks. Signed-off-by: Johannes Schindelin --- commit-reach.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/commit-reach.c b/commit-reach.c index a868a575ea1..7ea916f9ebd 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -105,8 +105,11 @@ 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)) { + clear_prio_queue(&queue); + free_commit_list(result); return NULL; + } p->object.flags |= flags; prio_queue_put(&queue, p); } From patchwork Thu Feb 22 13:21: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: 13567327 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 125511332B7 for ; Thu, 22 Feb 2024 13:21:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608118; cv=none; b=GAjUjrb44Q+Pt4v2EchmJkmec5mMr0ofwuxdi5zB1vhd1eKEIHv+9YEX9AwZfv/vHx652KLplSzWwv84ZwDYp4smWUJ1jt6P2oIeYyrw9kBME1/WC7ffwlo7IRZZbZVWtHMRtmTy/qbYWLbJssDfxEtW02OxeQCv4oVHmkuF/oY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608118; c=relaxed/simple; bh=24cqd6BppGjFm/VaiCvgn/CeewR+GmS1eJySW1bPu8w=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=I5c9Sangyj/Ef2XBN02/EE+P0deMFvTjSKfS5SFo/UecFsx36wuc0aoWEBwwblVac5OATNOtlk7GDrJ/AyDffOObXaDn7+hcknru7wGQRpo9kwS6B/EPyau08ypaFlkp2XgH/FVMwn3LhdnCAjVsmznbl6T34DL2i/0v9bvlN8o= 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=Cf2kexHj; arc=none smtp.client-ip=209.85.128.52 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="Cf2kexHj" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-412730e5b95so17654915e9.3 for ; Thu, 22 Feb 2024 05:21:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708608115; x=1709212915; 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=kPWe61qAdoPZyXs9YiS8hEi6k2qk0jViNhPiNFV+RYk=; b=Cf2kexHj9XZ+MptC1msil1ol2M9NPxLdoMt/YSXL/Qsr1KDmZPYGnAvBSWE1UVB9+V mzjuIphCsBd4y3KXnvsePdNnVxn8FTMCYfWu6oM8qu34P9yCmDynp3yiYp1ip8Zi+iBD y44ADeRGIizy9X5Mfm1l5FnaBshcwQxNtVVbETjCMLQukKzgCSkabgtDDWFxuMf96EO1 oh4Ty0q4qKZD1IPunWXMJrYzJv3EK3+mzGnD4sMhH7AvQJNu34uk61C07MAUpoAndIGG E2dYmwHYmfoUaDTEV6ZEz6NN7Na55j0Z8U1G1OBYGeCgUZkEgqS+VOdOQss3yj8W00zH sVAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708608115; x=1709212915; 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=kPWe61qAdoPZyXs9YiS8hEi6k2qk0jViNhPiNFV+RYk=; b=Rheo3Bp2NVQ3n8wgxg+Oe16IUeO4oMZ4sZHVQhOLQXKYK1VKwWe64ZlKQrEGtzUWje kEfllsSCB2bavDlxlpA8/5kxeQVRPp0mgNTWlI5woWVUSZrnf9pD5xW1OkH3zVanZE3X N0p4esUg4job/b8FJdZKberdOz9hscLcf9ZdY8bLtiMjY04Pd03wGobyem08NSiCGpZ/ C5NfGZgL0Q75HCYKyTa52wlaIYMttfOBogxqkjkQkyLIci4fmSWF73043TUCcuIUWxGl 7L3KTQYjjhnh+MBGIVAPggeCV2iwltBWbN5L6UvYby/ZHeZXAO0XyR+K9K30FRu5PEoZ NdDw== X-Gm-Message-State: AOJu0Yw5/N/7LXPManjqE2lG1Tcrnyu8XeUPR8YqIHsFahaqETC44q7d fFEPwMZEHBi7yt7wA6gAa9XaOP74ROCW0zq13H0c0ydciEOOKareKOSkaA7g X-Google-Smtp-Source: AGHT+IGss+bhPGNpuzOS5KJ+ilYWfJGebLvfLm8SDwokArd39ehBBNcC0xk870Ch3S7tvLjYNZM6xQ== X-Received: by 2002:a05:600c:5107:b0:410:78ca:f756 with SMTP id o7-20020a05600c510700b0041078caf756mr14758768wms.32.1708608114600; Thu, 22 Feb 2024 05:21:54 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g16-20020a05600c311000b004127942bcd6sm4403496wmo.7.2024.02.22.05.21.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:21:53 -0800 (PST) Message-ID: <5c16becfb9b4741a1c91f1c560ad270b74048baa.1708608110.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 22 Feb 2024 13:21:41 +0000 Subject: [PATCH v2 02/11] 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: Patrick Steinhardt , 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 | 5 +++-- commit-reach.h | 3 ++- remote.c | 2 +- shallow.c | 5 +++-- t/helper/test-reach.c | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/commit-reach.c b/commit-reach.c index 7ea916f9ebd..ba2df8b8f3a 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; - if (repo_in_merge_bases_many(r, other, 1, &commit)) + if (repo_in_merge_bases_many(r, other, 1, &commit, 0)) return 1; } return 0; @@ -478,7 +478,8 @@ 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; 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 ac728cdd778..dfcc1f86a7f 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 */ - !repo_in_merge_bases_many(the_repository, c, ca.nr, ca.commits)) { + !repo_in_merge_bases_many(the_repository, c, ca.nr, ca.commits, 1)) { update_refstatus(ref_status, info->ref->nr, *bitmap); dst++; break; @@ -828,7 +828,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); si->need_reachability_test[c] = 0; } return si->reachable[c]; 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 Thu Feb 22 13:21: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: 13567329 Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 CD9A6131E5C for ; Thu, 22 Feb 2024 13:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608121; cv=none; b=DfLLpcPod93jDH4BHB+n9Pdt3ps+pzUvFlkoQVXMd3G6Z00q/fZICtU564PPOt7Oi99lsH9jNlUO0ceF2iHss6E5bhsyTNpqiL1xq+cUa8uQ7Ls1ae/7n0rNYR7yJ5bIPVMOFUtpwX14P3s/KVj9f31N0ev6ASJ2HuZ38vz6VVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608121; c=relaxed/simple; bh=Syx4NjPcIpNtyrjzl3x0GGXEW0EPGqr71KjFZHHPZP8=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=toSWsU+9qxneTYWQ6mGYn2PVUhZvxoLvho4K1hUTQ944ctwDrTGxK5aDFfgOhqdJIbpmeTdakRDMtYynxpiH1+OzYRlgnuS6fhAlDbsgl43KDZcNoRZBYXD8dLHhgZzVDrj3lQ0V3b5jzoGT4U6VNyOOrsjPqXT6aR/lQnNrNEE= 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=gTeh5vkt; arc=none smtp.client-ip=209.85.208.181 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="gTeh5vkt" Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2d244b28b95so40861111fa.0 for ; Thu, 22 Feb 2024 05:21:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708608116; x=1709212916; 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=ZH6ulL8Wd+r38HjTcw8+LwpCJD151OMvzfTEdbsLwa4=; b=gTeh5vktLZbMrEaEyQij1xQ3nHNDtVLeYHssuY/KzeAdWY+I/ohkD5RT5j6uKrj2Wz sXYGWv5yef0O1i3IGI7/I2ObP5lfT3KdrYe41jhTJeAR971VQxu+MODnWgABCT4oEi1E t1TN5k2wtGcntSWZr/l95taT9e37MiPKbKZALKdgBEd6/aIDsR4jBXmeUPqfUsJJoTos melF1QI3zYI2JDUhQhQ+Q6oKBVdVPjtFQ/bfBZXVTAYP6nhQhHD9wvohVOdKYkbxebI/ okyuP9Wo2j8dbGcnITOMD7QVtbaYHYcea43owwFLQbeb/eFK3Uq5gGhTkqgL91TpQs6h HNFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708608116; x=1709212916; 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=ZH6ulL8Wd+r38HjTcw8+LwpCJD151OMvzfTEdbsLwa4=; b=H1a757u61TQIl76zGXfVOKFCkF+tYnaoIuJLSrs8VKnqA9ekZw7YOj03H+uwV3f6qh vKA++37sXmSfPDQMixPWd5yJT9FrYhT2mD4HLNO6zVgZyGecb+AqgcdmUFY41aLhiQV4 vDuaKY1H7RhVAKsPlSe0t7d2xFSghB064x3KQecvw8ExHmRghQd7ef9a7CrOaUGYNEhQ oBcFszFg2ZObmE2+amUnjoVSAeamc939xj9QgejeOgbdhmQ0sdsVZlliGr2O5V3Czfjh a7zUOExu0L0tfyXwExuWmja+CS0AbTBbStCFjZlSOndkxID6pYxiGlebjr684bAua2Jy Ty/g== X-Gm-Message-State: AOJu0YzBcx1fWHxCrt3ju8NlswnsIiP0cTjBeJGWbKb1gsBS3h/sHsny LXIosc2eoefvwXeejhGGtJtTYwHgv1yvkeuVOcW4bXWnZf2mUxNM/tRDkBwj X-Google-Smtp-Source: AGHT+IGSWu0KQbour8rqQvT1yHrPsTFaYFNTBSPG+/FZHmJaWpjcT5MVZ8bJ+Mu1VPgD4zb7vF+sdg== X-Received: by 2002:a2e:9d87:0:b0:2d2:32ac:21f6 with SMTP id c7-20020a2e9d87000000b002d232ac21f6mr8573694ljj.16.1708608115841; Thu, 22 Feb 2024 05:21:55 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s7-20020a7bc387000000b004107dfa6aebsm6002764wmj.28.2024.02.22.05.21.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:21:55 -0800 (PST) Message-ID: <4dd214f91d4783f29b03908cc0034156253889a7.1708608110.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 22 Feb 2024 13:21:42 +0000 Subject: [PATCH v2 03/11] Start reporting missing commits in `repo_in_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: Patrick Steinhardt , 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. Note: As of this patch, errors are returned only if any of the specified merge heads is missing. Over the course of the next patches, missing commits will also be reported by the `paint_down_to_common()` function, which is called by `repo_in_merge_bases_many()`, and those errors will be properly propagated back to the caller at that stage. 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 | 81 ++++++++++++++++++++++++++++++++++++------ merge-recursive.c | 54 +++++++++++++++++++++++----- shallow.c | 18 ++++++---- 12 files changed, 175 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 ba2df8b8f3a..5ff71d72d51 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -464,11 +464,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, 0)) - return 1; + ret = repo_in_merge_bases_many(r, other, 1, &commit, 0); + if (ret) + return ret; } return 0; } @@ -486,10 +488,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 ignore_missing_commits ? 0 : -1; for (i = 0; i < nr_reference; i++) { if (repo_parse_commit(r, reference[i])) - return ret; + return ignore_missing_commits ? 0 : -1; generation = commit_graph_generation(reference[i]); if (generation > max_generation) @@ -598,6 +600,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..24c16a4f5ff 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 ret = repo_in_merge_bases(the_repository, branch, head); - return repo_in_merge_bases(the_repository, branch, head); + if (ret < 0) + exit(128); + return ret; } static int delete_remote_branch(const char *pattern, int force) diff --git a/merge-ort.c b/merge-ort.c index 6491070d965..9f3af46333a 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,14 @@ 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) { + object_array_clear(&merges); + release_revisions(&revs); + return ret; + } + if (ret > 0) add_object_array(o, NULL, &merges); } reset_revision_walk(); @@ -1725,9 +1735,17 @@ 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) { + object_array_clear(&merges); + release_revisions(&revs); + return ret; + } + if (ret > 0) { + contains_another = 1; + break; + } } } @@ -1749,7 +1767,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 +1814,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 < 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) + ret2 = repo_in_merge_bases(&subrepo, commit_o, 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) { path_msg(opt, CONFLICT_SUBMODULE_MAY_HAVE_REWINDS, 0, path, NULL, NULL, NULL, _("Failed to merge submodule %s " @@ -1807,7 +1843,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 +1861,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 +1895,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..0d931cc14ad 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1144,7 +1144,13 @@ 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) { + object_array_clear(&merges); + release_revisions(&revs); + return ret; + } + if (ret) add_object_array(o, NULL, &merges); } reset_revision_walk(); @@ -1159,9 +1165,17 @@ 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) { + object_array_clear(&merges); + release_revisions(&revs); + return ret; + } + if (ret > 0) { + contains_another = 1; + break; + } } } @@ -1197,7 +1211,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 +1248,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 > 0) + 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 +1283,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 +1436,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 dfcc1f86a7f..f71496f35c3 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, 1)) { - 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, 1); + if (ret < 0) + exit(128); + if (!ret) { + update_refstatus(ref_status, info->ref->nr, *bitmap); + dst++; + break; + } } } info->nr_ours = dst; @@ -830,6 +834,8 @@ int delayed_reachability_test(struct shallow_info *si, int c) si->nr_commits, si->commits, 1); + if (si->reachable[c] < 0) + exit(128); si->need_reachability_test[c] = 0; } return si->reachable[c]; From patchwork Thu Feb 22 13:21: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: 13567328 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 4DD05134CCE for ; Thu, 22 Feb 2024 13:21:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608121; cv=none; b=AOQjAiFDLQptS47iAAHI20XzdYeGm6mmndzu+C9C65eInQUxjVmS8DkKNECHhyiovlHwmnesRC6hqQ0UjbjKzUp7emzMU0Uucn1v5dIXU0GMmITuZoUaZ4b5QD5c3+Kube9iDW3FQe10lPxhmpxZlMvee9UHgoGPP0t4DTQzq2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608121; c=relaxed/simple; bh=XK+Coh5PwwNEzPwXMw8DdCAp0qD9ozktfiVc/5uk2rQ=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=WZHl0bAzFecRfRdpg2ea0HfR0w0hbX8RRe0Fml16GgpItlspSvrzzViqqnCyUhjvluVqU/C39Vf4lUUfxaVkekjkGQbjtxTmeztoSuTNeyKkclTANq03gbujw2aB3ID91bnRY60i6W7EXD83JeHrtaC+NiLpvkQHi3Dj0mUVOxs= 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=fR0RK/ar; arc=none smtp.client-ip=209.85.128.52 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="fR0RK/ar" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-412700a7207so13154285e9.2 for ; Thu, 22 Feb 2024 05:21:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708608117; x=1709212917; 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=FH5F4ez2NmzNeSHSGewWiOcbU5KriPIckDGLw8M93Tw=; b=fR0RK/arZKrxceqaLPO2Colm0eJBVkocBBJ0RbkpXvHq3Iow4Nb64AeEBNGorsbnEq yc1oiR/eryuyCUjTer/qjNhhApjaz2ibCzt08tpVUdmlEIhm/0yj+ZrgpNRxmcdHkJXL YsBMcVfwHY0GLpdjvce2+8H5suW2RVQmN0JPn1jd/wyTUkXzwp+4lVEJmEC+R61wAyqz wNXo0n/35FSjOwQWHew8m+8cwnm3UlOamuFex8+IXzMQbqeL0UBMmt9QEYtImtx0Fzom PTrLO1eVFQWU81D4xqs4nRDSyBJdQdtEE6ipBvOtZMPOyLcHGM8p7+hXpcbn3Px26vuv QIrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708608117; x=1709212917; 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=FH5F4ez2NmzNeSHSGewWiOcbU5KriPIckDGLw8M93Tw=; b=SxVaxWry87sXI3JBcCTKTf+QjRta2qfilVz2rMJxBUNt0ClZmU9KS5RZesoUEX+ALS 0s4yjpBP7mtWcXWFK7sDYt3NhNtNpY3HOicTc5hvVZXAob21+PEh4V1Td4xkncL5uK3r aIFOJcWci7b27Xv4+oSqx7wlrV9Tu+lElJlOA2y/ML5qxIgOrIwo0WWfInw9FgUIhkWs 0pA91Ee6jkff4pNgmdvjDkLl7cupJsydwTqDuXMnnqjvVpA2ow4p6cHUkPaWLtAAcl4D 7GbHmXaF4AFuZksqmzwFq9zsk1/TizU5kRmTelqvCR/dXG0wkt0D5GIvrgH0XkK+u86G nyPA== X-Gm-Message-State: AOJu0YwIcUJHSdxUY++sE6YHQRPYYug1IjTRaVh64mVjO8a7QlrovtRB DM4FzQ9BROP0FxidXqUKnyeVQzkB3zpsBfRlL3uC7B13Ai+taHDSonJFm38r X-Google-Smtp-Source: AGHT+IGvX+qhRxWSRoVFjX0852iGMzj9joWSEYRNUtk2WJC0tLSvviu3Sjtef+w5HNTaN2EBfESHDg== X-Received: by 2002:a5d:4104:0:b0:33b:5f1d:5ef4 with SMTP id l4-20020a5d4104000000b0033b5f1d5ef4mr13168462wrp.1.1708608116538; Thu, 22 Feb 2024 05:21:56 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d2-20020adfef82000000b0033b75b39aebsm20363506wro.11.2024.02.22.05.21.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:21:56 -0800 (PST) Message-ID: <53bdeddb4cb0293b2d7f896b5a8943ab10b57037.1708608110.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 22 Feb 2024 13:21:43 +0000 Subject: [PATCH v2 04/11] 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: Patrick Steinhardt , 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 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"). Note: shallow commits' parents are set to `NULL` internally already, therefore there is no need to special-case shallow repositories here, as the merge-base logic will not try to access parent commits of shallow commits. Likewise, partial clones aren't an issue either: If a commit is missing during the revision walk in the merge-base logic, it is fetched via `promisor_remote_get_direct()`. And not only the single missing commit object: Due to the way the "promised" objects are fetched (in `fetch_objects()` in `promisor-remote.c`, using `fetch --filter=blob:none`), there is no actual way to fetch a single commit object, as the remote side will pass that commit OID to `pack-objects --revs [...]` which in turn passes it to `rev-list` which interprets this as a commit _range_ instead of a single object. Therefore, in partial clones (unless they are shallow in addition), all commits reachable from a commit that is in the local object database are also present in that local database. 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 5ff71d72d51..7112b10eeea 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; @@ -108,6 +109,13 @@ static struct commit_list *paint_down_to_common(struct repository *r, if (repo_parse_commit(r, p)) { clear_prio_queue(&queue); free_commit_list(result); + /* + * 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()`. + */ return NULL; } p->object.flags |= flags; @@ -143,7 +151,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); @@ -214,7 +222,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++) @@ -504,7 +512,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 Thu Feb 22 13:21: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: 13567330 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (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 8D3241332B7 for ; Thu, 22 Feb 2024 13:22:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608122; cv=none; b=Z+LnwpqR9FfBzYVvx823EIc2PC8/h63zZwAOIE3TDjbORuxYMNqHosv6Yqr5Feqq5fgR9PBWauBjSr5jpzv493/j+f20C1zAxylXU8Wf/x/tg4R3gLjJrwW6AaEdGrXXEwZwSDuFhvmGarMHSVg7aAt9pXfm+S4cu5kWMyNXoow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608122; c=relaxed/simple; bh=+pZqO4z9dzPxkYeO95GzM11oRgZZU6Hu7Qf1EyX5XlA=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=uupsG7qyn0qhq00CYVZu24HHCC+TQFPqSpzaeFA6x8Y6FsASpFKr474h16plAJUavFQ8ndM1fWfDgLe9zl6WKmZzvnDkSiFN+eEJYVU98aNZ3fPFlS+Si3t2OEMOR7XIPZwIywbOoOMAaUKAUZ9qVtEmsV14X9B//VRSHqx+KTc= 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=jm8IIQXD; arc=none smtp.client-ip=209.85.208.174 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="jm8IIQXD" Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2d25a7b02d6so19688551fa.2 for ; Thu, 22 Feb 2024 05:22:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708608118; x=1709212918; 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=mN1V+1j8c+E3JD8Ld0NDPVa4IYGtQUvIiMGNp6/rDak=; b=jm8IIQXDD2a0hOiCjaXjQQCf6eQJQr3uHPAUQhy+J10jgAXE3WoKXtiYq+ajyckWLg TAyZA/cuND1evi2yQNwUORgAhYCmTHA5n1mQ2zdNi2sal5wNNQ/SNrFxBOyzHRBM/LcW RhgPPBTogGTj3wnEWHOTBt2LufZXmAllMbJTDdwdRbieaxU5fvYa3gG88WrxejOyTfCm m5eLDKEF16uLa9pwINAHAaH0Mn2hm8YEj3PtR8Xlk2pXJ6bIDxoClIqUMpcWQStCXJ4e lyCilkPZO7edY6bxNOZVt62AWtDiuxAOX2l467sISm4fiT3Ad8+gVz3N3Qw3nQNauwfo QK5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708608118; x=1709212918; 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=mN1V+1j8c+E3JD8Ld0NDPVa4IYGtQUvIiMGNp6/rDak=; b=DVpckh93uzpPeV8hv6KZySAn/USor2TaCtqO26PSFAdlIgdKcRwlQGEGwrr35KVlDy CWHOZ+nouSeFgrOFCSB9+rld279xpHHgOv1CY982CjUdvZgv+w8R+CmAIshiE54gZcqr yc++1RYC2AuiTx9GEC0MvHTMGO0e9UvQ23IuLl0nDvUD8gOhJczxaLs5sIrwulVf+zTv 68k21jEmElCoqrnO5TSYMT1Flna+a5FWfglfwjtRaD2HQkGpo9Ppb8IuaVzt5hAoVFBe 9+ldmJ+iuZgN8GCh9jqIX/VAZsmt6rtpn3nSmtLXwLehveqFLVMn5wUequ4YVAbQUErh Ormg== X-Gm-Message-State: AOJu0YwtfliJc9+dWyK7CKgUoaeWlKAlSFGJpU5J0DPVrDeeXFEyKHok 46L0cQ1B4wJgsSw18aY/zv4xvgE60/EWH6/KE37sMDhgOZIqZtkdWWteYd6c X-Google-Smtp-Source: AGHT+IGyXVMMk8BGtYydzQeOSqua8wiG+GoVUN1KOo+fflWBJjwBuGCMw0o/CWCac1hCNRn6kB2mLg== X-Received: by 2002:a2e:87da:0:b0:2d2:4c4d:e208 with SMTP id v26-20020a2e87da000000b002d24c4de208mr4666057ljj.30.1708608118060; Thu, 22 Feb 2024 05:21:58 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id jv15-20020a05600c570f00b004125f34fd7csm6127408wmb.31.2024.02.22.05.21.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:21:56 -0800 (PST) Message-ID: In-Reply-To: References: Date: Thu, 22 Feb 2024 13:21:44 +0000 Subject: [PATCH v2 05/11] 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: Patrick Steinhardt , 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 | 66 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/commit-reach.c b/commit-reach.c index 7112b10eeea..9148a7dcbc0 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; @@ -108,7 +108,8 @@ static struct commit_list *paint_down_to_common(struct repository *r, continue; if (repo_parse_commit(r, p)) { clear_prio_queue(&queue); - free_commit_list(result); + free_commit_list(*result); + *result = NULL; /* * At this stage, we know that the commit is * missing: `repo_parse_commit()` uses @@ -116,7 +117,10 @@ static struct commit_list *paint_down_to_common(struct repository *r, * corrupt commits would already have been * dispatched with a `die()`. */ - return NULL; + 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); @@ -124,7 +128,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, @@ -151,7 +155,10 @@ 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) { + free_commit_list(list); + return NULL; + } while (list) { struct commit *commit = pop_commit(&list); @@ -205,7 +212,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]) @@ -221,8 +228,16 @@ 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)) { + clear_commit_marks(array[i], all_flags); + clear_commit_marks_many(filled, work, all_flags); + free_commit_list(common); + free(work); + free(redundant); + free(filled_index); + return -1; + } if (array[i]->object.flags & PARENT2) redundant[i] = 1; for (j = 0; j < filled; j++) @@ -422,6 +437,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); @@ -491,7 +510,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; @@ -510,10 +529,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); @@ -566,6 +586,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 Thu Feb 22 13:21: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: 13567331 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 8230B146905 for ; Thu, 22 Feb 2024 13:22:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608123; cv=none; b=jmIDXUAgh4ZG46O6zlRYBNEIsEI93OjoUguEwUuqntiBOSfaHLl7dfkMlVn3t8ZjFrY3b5axC4nRcSL6vEqNX5y5B6JQfTdwTcnyfuq99gp2jMR3wYC1LaCxuQv3dHXJvCYmKWkbx73aAKVhFxcCRYaNe3CDj6DH4/Qqaogg448= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608123; c=relaxed/simple; bh=PUvI8mflEWOq2BwZiRa/nQDGYx9iFMV5Pd34ga33pGg=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=dyOqGSJW7Chmsqo15DAnUUEsKuHK4Fp+mjcsAhVVJoA0DNDbVwmEIobNju7XOQlCYkomrcaYEqacFTPZHd3pha5zsES1ugouObV/y5Hc/IrUiTmmJIZGWf+mtpMUufwWiIqc3H2bUVYOAbFk/ZCp19tmNPORzW0SO0tD57RJlWU= 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=RpyxXjkn; arc=none smtp.client-ip=209.85.128.48 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="RpyxXjkn" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-41276a43dc3so12213875e9.0 for ; Thu, 22 Feb 2024 05:22:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708608119; x=1709212919; 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=ls2gfG7/KzRPf3br5sgCg2MiCtFeXyjXvkeYAyegKIQ=; b=RpyxXjkn3etrz6uixp1luorDXxJYmXVaOAMnuwmd3+kgKygoJPQd5nTZ9Q2ahZuyCR wIRhT3eulBZNLA0THp4wZHpTV5r4v4HubnkovKEj/AkO1daaDE96N9lTMKLyIFZS9MlS l7BRy9jjlb/u/w2V9Aiqgrj+UDOhm9pV5f2K5zD/ErD8R3mCpZ5ll9ztyvcT5LeUjOyN kOA5CXlJGb9I2IxFJEJMj+ZHTHFVhf7S/HI96KD60NYk0iTwfEALAHdjiJ9kyzbl83K2 K5dmBMa0Hgr5Zs0t3/cHgQJHVpIIr389Zics+yzTCg0HAozCBw5yhUI0zvmi/KQLjnvU 4EIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708608119; x=1709212919; 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=ls2gfG7/KzRPf3br5sgCg2MiCtFeXyjXvkeYAyegKIQ=; b=Y703NIUHC8fvO9LMoGIl793gHZt1+1kdlCdOdlJ88UVpZguyaM4vVSVFGdJZN4Yukp PveLnGmxCp+g1W/DDW2A+8Kkn3Y+UOVx140fEIWvAEM6166NCdkRKhckEhrCe6UXzcU+ 6tZjgTYeUG81KuMD8fBkYkE3NglXgAz2JHm2N9Im/q7AGCln4R6/6xB8B9VneyEfwMwD 4bDQrqWtMm3pQsjDEWMMWaqhUxXZAUnMRz4ZjxNo6T5gVzPlhzLuCnL14s+MUorEnYKR tC9cp6LEV57qfF0V+YmYt8MibUhO5rPDMftj9+5JBX+x45X9W2AQPEq74WUa5bXu7EBW jCVA== X-Gm-Message-State: AOJu0YzNUoW9XcGWKHhWqbJ+Qqhs5WSyhchEj7UyGtzVtsnJxG6EJjVA a+nRKx/wUgwTVGTx57jCfgOyAEXuXgmIjnZwlg5VQ0a83m6SUI6XA4M78JTT X-Google-Smtp-Source: AGHT+IGvonwbV5y48Uty4lVdTlXQFQUr3+H+Zt8Cm8vZcKGYwoxFsJmqcsEErp41lZ0YAOZozMELDw== X-Received: by 2002:a05:600c:1387:b0:40f:e284:d785 with SMTP id u7-20020a05600c138700b0040fe284d785mr17633763wmf.23.1708608119279; Thu, 22 Feb 2024 05:21:59 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u7-20020a7bc047000000b0040fe4b733f4sm6041221wmc.26.2024.02.22.05.21.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:21:58 -0800 (PST) Message-ID: <05756fbf71a2ff4932fb2c140659d07a87db25ee.1708608110.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 22 Feb 2024 13:21:45 +0000 Subject: [PATCH v2 06/11] 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: Patrick Steinhardt , 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 9148a7dcbc0..2c74583c8e0 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -131,41 +131,49 @@ 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) { free_commit_list(list); - 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) @@ -410,10 +418,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 Thu Feb 22 13:21: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: 13567332 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 9C8D51474AB for ; Thu, 22 Feb 2024 13:22:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608124; cv=none; b=AcH9h+JF0BXgIwbeFUNH+ZDR7YgcExd558IbS5hgwcHqM+C7jv5KYROQuB5avvh1Mpc3KH3jZ2OIHiLCLJxLKoVGD21uKAjTE4NDMcb6UfFo4Asvqk9aTE2tZ/cRNaRyv4vWCx2RyMXhrjkGQPaqFvZ7hUbCytsWcPAVE7z5ibA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608124; c=relaxed/simple; bh=GMisT3c0UH8nvhHSntvgDda4WOaTeQgKFgBvq9WNG3s=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=hQJ7Tf/os43uGPhVHdnW0UNYQZR6dUoZkMbVdmgiWmDrbS6X5w/iDSToHxoTiKBYFCbR0UQ67m58jaHor+vMONEmstERHmAq56kWkBpNZb7FBP8gILpQ/DV7COum9DSxGBFhcTAZbQ9ShEkUDQJwa9LoVGL0ZpUWEzTHdNLMdxg= 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=NhhT3BZE; arc=none smtp.client-ip=209.85.221.48 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="NhhT3BZE" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-33d18931a94so1466427f8f.1 for ; Thu, 22 Feb 2024 05:22:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708608120; x=1709212920; 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=NZYTa7/iq5fGG8lMxU083J6LdnIvDMjkHZYAAFHn/9g=; b=NhhT3BZE+g78YPQFz8bLI4SIjrJT3Ws65XDE49BCKqZDcg3OJeE6EThkGXkZ/kn9OC v26+yXHpsv04718QxzcQRb08lUW9vtWTASziJvhh8ftwX4Z8rdZ+NqQs3Dn70TqLPNKB /fsgaXn15bCoZFOCmAZGTsRwinnVO2R/HPgjcCsIEBwYqwMLmrlslDm0hYsuaubtadXJ HApHiuT+cthhay2r04yhtfculAesa2e1jBA6WzGg8HaYXs24mYD8yZT0ZDoqP28Symvh yK0hUCWErGWp3Ss8jdQ3XIzxoANmH1anPRJ7BOMqS+N8PSUKaQaBWvC7Y5YuFEXPE+b+ kXxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708608120; x=1709212920; 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=NZYTa7/iq5fGG8lMxU083J6LdnIvDMjkHZYAAFHn/9g=; b=IgWAx8CjAzVg0Qgs4rr0vU8xuQLZZmBs9ejrQvcnCIcfbQVzpH+DBPRdv/IDOjfilD UdIR5etrzv/qjksdHxYJfFp9J6mHdOQq0mtcNjb49YJX3LlOu0uFJgCEdTsQsThV3MRw hLVRwvbBsCINb3WjgWa5Izp2z5+Y3p1dordV4ZpiT2BN6gaMmnsFbm+c+TigiSukv5aG kzkltPikyyjYsEERCBUS/VAMXtb5uL3Nozeii5srUBI6qimoZ8mUwV1rG39SY9jrzavj NloTQuc8Cowf+ssXETSTdScojfYv+hBPI3lqAxvMsJw7sD4ajEhIggpR32WDMCaDRlcz +WMw== X-Gm-Message-State: AOJu0Ywff2L6wNn4KkLF7OfcYEkesDxuQabwPZ0ZggqVAecBKdYfCciy Au61sisc87QT3xVaPbPxgswJksGvzx5nda7CmBoABH/a1XHNxLVleyKtXz7o X-Google-Smtp-Source: AGHT+IG9S8OcUcn3FxS+6UB3kBgOvK8gjYHUwkJT6LUjhW67o4NJdPuReF5PshjMXvH1O7EqJ9XhyA== X-Received: by 2002:a5d:5182:0:b0:33d:1eea:4346 with SMTP id k2-20020a5d5182000000b0033d1eea4346mr11226238wrv.37.1708608120459; Thu, 22 Feb 2024 05:22:00 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id cc18-20020a5d5c12000000b0033d67791dc0sm9518205wrb.43.2024.02.22.05.21.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:21:59 -0800 (PST) Message-ID: In-Reply-To: References: Date: Thu, 22 Feb 2024 13:21:46 +0000 Subject: [PATCH v2 07/11] 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: Patrick Steinhardt , 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 2c74583c8e0..5fa0abc7d1e 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -410,37 +410,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); @@ -448,13 +449,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, @@ -462,7 +462,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, @@ -470,14 +475,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 Thu Feb 22 13:21: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: 13567333 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 4072E1332B7 for ; Thu, 22 Feb 2024 13:22:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608126; cv=none; b=jZ5tvg2Lw67+KD/2F0Ic32LD6x6bzN+guadV8UXhZoGnJMLhr25KQSjK1BC+CX6SAiS3JeqC8Nz7DFt5YihswwtD+1eRsRVPTJC2kKi3GuYiJomO+v2I9zzuLpHhZi5dQJIYfe5C9Buya0iE/xaLX0X6xVOSqjlozQFiD6tpfdo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608126; c=relaxed/simple; bh=k82XXytIOf1iUdIbwqVKYDEdc+wyvr0BoBxa3J3j5h0=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=j7bVDiV5lLc17I+QPQ4h+KG1UsMRmrc3yZKR7DFSpWsJoxbGbZflQrw5Xc34rq39fuScsgjQEtTzh4xS7DfgzxOBb2XHVUieF/izSzcHHw66b9uExcsi8lbQldoLdNDqVJocL+Qqpd0i/tn7Q5Rl/HVlOhlNTirOyYx8PQmyTfM= 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=JeJvBRl1; arc=none smtp.client-ip=209.85.208.177 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="JeJvBRl1" Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2d094bc2244so107267761fa.1 for ; Thu, 22 Feb 2024 05:22:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708608122; x=1709212922; 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=f1P9ivwVvGfGXy67eLQ3BFxWbwUzX4jOeNotuFovadI=; b=JeJvBRl1DmWocjEgrx2LLfJAQW1LZiGTlJ62RvF6kFkV1DUehJyVMxHwLExGp9P3Bu IiqPy07+0j7ka03RTBlJxc3wTD5r9NJvNUPADho+moy5BlfZRAd1qHYLy+KReQudpUbN keQY76V4Be2k4ggf8VQ4ELYcEY+BnrOL1D82lpoQmOklHnI1BsM1gr9dYm6MZIp1HJb9 dI7vjEhV35+l3ds0VHsWk/8+2Sat9EAPLiR5mc6REHwzL7acPb7uIGg2BN1sZj0ElwVD kbJbkEpJDF3jlS0PkqtLaP0zqt2MMeOuiVb5UBBJjqxNgeP4Ye0sS065z3h/dahMuNG4 rrqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708608122; x=1709212922; 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=f1P9ivwVvGfGXy67eLQ3BFxWbwUzX4jOeNotuFovadI=; b=YcV4t2t6QXeD4cRPrzXayy64JEDWoWohVl4D4s4i5xjx7YrDHSXo5+MHteUiICIb5g 6JBhZQcO3BOVhCdRQHNdhFo/GOzPY8rN342ADB8GP0FaadrtRI2++ujproI5pt2pI9Li rA3RCoOQZS3xj1hBmimKZ6VhPHR01+KaxSlCeLEAsN2brxj2P1HXi2J51OJzX7t4XQM8 QypB5Wpq/SuNuawoSqc4p2w8JGpTYQv5d9AJOMCRgFFO1L6KKhQVun8BihbLIpM7QUbu tq1SKNKfoX8FyXpuKnEEYVsYgj6MIJbkhLHFWyL4HwnS9+vh2p8Y934gqYCakcURG+fB UUeA== X-Gm-Message-State: AOJu0YxUVr1xi3sUmTIb7kV+NZRdNBvYz7ap09+fwP1vXZpTk37Cx9pL h9r2U5o93JZ8+s/u+JhjoB3D5Yy3WOXWtJBcyIZgiGok6p4DaHoE5EYKxZ2S X-Google-Smtp-Source: AGHT+IH8fVWY7okieSKGDhGI7kyZ+qGjWabC++hN775zgZR/hk56SCJqYPSnS7jjjbIaYXb/6uFNcQ== X-Received: by 2002:a2e:8057:0:b0:2d2:3891:b43 with SMTP id p23-20020a2e8057000000b002d238910b43mr8036384ljg.27.1708608121569; Thu, 22 Feb 2024 05:22:01 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w16-20020a05600c475000b004128c73beffsm1415835wmo.34.2024.02.22.05.22.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:22:00 -0800 (PST) Message-ID: <9ca504525b96fdeb20adb41ef02626b8ed12bff8.1708608110.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 22 Feb 2024 13:21:47 +0000 Subject: [PATCH v2 08/11] 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: Patrick Steinhardt , 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 | 7 +++++-- revision.c | 12 ++++++++---- sequencer.c | 8 ++++++-- submodule.c | 7 ++++++- t/t4301-merge-tree-write-tree.sh | 12 ++++++++++++ 17 files changed, 96 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 5fa0abc7d1e..10e625ff51b 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -189,9 +189,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 @@ -483,16 +486,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 9f3af46333a..90d8495ca1f 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -5066,7 +5066,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 0d931cc14ad..d609373d960 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3638,7 +3638,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..63bec6d9a2b 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,10 @@ 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) { + free_commit_list(mbs); + return -1; + } if (!mbs || mbs->next) st = -1; else { diff --git a/revision.c b/revision.c index 00d5c29bfce..eb0d550842f 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,17 @@ 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) { + free_commit_list(exclude); + 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 Thu Feb 22 13:21: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: 13567335 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (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 B3A6E1474D4 for ; Thu, 22 Feb 2024 13:22:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608127; cv=none; b=Tw5dF5r6VsRBw+nLQb3xloWtsopE0SPibL0W7EiOlHBdUnkP+++nmdI5IGehWwDpY0jVG+EFQiGfn/R58zo2ZghlhheGGHlSlKBnd2SMHwkKLjHz+aAJpEeHKNbTwIdqoWDwFg3DmA2338RA+2qgy2wU5byt+J+VLwHsT1i9tTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608127; c=relaxed/simple; bh=hzRxdBrl2ByI5HBj9L44tIXXHO2fkT2SNobbwjCZPCg=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=eYF4a3XZBJpk3cWTvfvArCUZ5tf24qkdU3OYw4lrCWAmH48uaJLFNldgNRlUpSVks4YUvlYtFmYAzPwRcyOo6evQsLuMPq/4JeAX2EiAwDk/Qxi9097cLRT04kRK6+/OOSpOwx4RTctSp5ep7uOSYxZEY12VmAxATE5mSaUn8gI= 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=N0THHLty; arc=none smtp.client-ip=209.85.208.169 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="N0THHLty" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2d0e520362cso79211431fa.2 for ; Thu, 22 Feb 2024 05:22:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708608122; x=1709212922; 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=KjZk1iDVFshalJ84DkUa03UuxpWms0aWmK5IcaENZJk=; b=N0THHLtyfMdQ7GHovQgFMS7LbzOG4gVaqQzOexn046OomtKHZvjwoNq4KirghICYF9 M5+P1G62wBBrsTDwj+lfF7xybivSJ2EHI8MGfK4jS1JA1iZc5hxK2883BoHHP8U68TKA 5Fg8RjFqVxN0dZCCC2fJOY1FGXZViBaplZF9jlA31uAZjW1rrvt9vNCU1Z5hOlvwenBv T1QSNBDSewfT/VlLOxJX6mu+i+LLoChxrEY4ZOzZ66jfbCtyDFsGqHGvopIQPAJKSVs7 uihIPtUW/PBmuoS9E6zcepDnUXN9UzXK29Nd6TNZ1DLhj90tOXXeQQ00Ka9ntZIDt9XN udyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708608122; x=1709212922; 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=KjZk1iDVFshalJ84DkUa03UuxpWms0aWmK5IcaENZJk=; b=Zrq+mg48Xm+GxaZ00Z5WP2Nnq8H9J/wXAVhYhtGltgtOWtpX0D5SD1vRV4uawG04ZF qtYkY7VkJHOcVgfEHlNd7U1oNQWW3H1USNuq5gOvN3UdQIPKeWE3ZxJ9w6FeiqgEIlM2 05fi1cCPdTPX8Oy1/vA+Xq4djZ6/zBNNU4bcqz0GaT+dIVX+HNjGpl+Ooc6I8OnfyRRK LxcMswyhlw38ddKir7L+PyY+BxXRwkP3e2Y7oJ8iFEeJRLTl+Lyg0xNYn5L6ZL5+Pyki n6WGVPlD321UD/e/KjsJNrP35GXg1a3CUR7EUhP7iIZfYvVuM1AD4ytxmFjzRHGnqq+V 96Gw== X-Gm-Message-State: AOJu0YzDBLcJJ3UVlndqXkUq71pMOo2E2SlDHPqEpnUa7AYlcYxTlU1b 5+jgNeywQcug3zUEJpa/Y0SNKsCjLlDWhU+syt6+2hpeGmAUKW53uPpSFfvJ X-Google-Smtp-Source: AGHT+IH0EHNRZO7GhN9Ia88yxNRVMEWatHWRkW2b0DFeKQONlR+AlxJ4y87bygjQyu0j0tegtjS2SQ== X-Received: by 2002:a2e:8552:0:b0:2d2:4465:1146 with SMTP id u18-20020a2e8552000000b002d244651146mr6211952ljj.53.1708608122444; Thu, 22 Feb 2024 05:22:02 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p24-20020a05600c1d9800b0041273e84fe1sm6624004wms.25.2024.02.22.05.22.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:22:01 -0800 (PST) Message-ID: In-Reply-To: References: Date: Thu, 22 Feb 2024 13:21:48 +0000 Subject: [PATCH v2 09/11] 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: Patrick Steinhardt , 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 | 8 ++++++-- builtin/merge.c | 6 +++++- builtin/pull.c | 5 +++-- commit-reach.c | 20 +++++++++++--------- commit-reach.h | 2 +- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/builtin/merge-base.c b/builtin/merge-base.c index 0308fd73289..2edffc5487e 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -77,13 +77,17 @@ 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) { + free_commit_list(revs); + free_commit_list(result); + 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 10e625ff51b..fa21a8f2f6b 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -176,24 +176,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; @@ -202,10 +204,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 Thu Feb 22 13:21:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13567334 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 B832F1474DA for ; Thu, 22 Feb 2024 13:22:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608126; cv=none; b=m47S6fGHFx9wjZFaYFqkbpSO15D2h4GieyHRfalUGdYz3tAG+59yuCLgRv7dcg1xfkMA0ey1tpOpUb4W93Y3J4ihRxkPsebjJnBC43tvev7fAVG3B9UFu0bT4Euso3XO41KdDJPiofIcOd55/mJwycmI92FV7STmAs7NVBA6sqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608126; c=relaxed/simple; bh=CLpj2eQfppOLJzGwC3VItCwf3+h1DC58UrsmbIL/P+U=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=WSbIbfZAnn23UAn4XZKSL7A8irSskW7L5pe27gMqrmUPH2q6yonuHcLkh2SFr0yAVqWBEwtT5P0H8rksyNftwZ7seyzNPpnvJDAHuBoJz31vhArF+xLU0K4tVbaN0t2+4N1lvBPDRKcmlDgp0sAJvnGsFyY5foDhCpWBvxWtblI= 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=QPB6s5TM; arc=none smtp.client-ip=209.85.128.48 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="QPB6s5TM" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-41282be73e7so5134215e9.3 for ; Thu, 22 Feb 2024 05:22:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708608123; x=1709212923; 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=IpB/h3lwfLFrLf+CGh0DZz5bM0QyAjW0iXQElsRCUNk=; b=QPB6s5TM2Mh2BDQGu4jtYyqzhrmdd8H2n3cU5DuT4wBwVdQEGqoSA+1OXmntw/SXrw Q/o78O2H1AYmfGx5eHmLWwAqLReyL7zXMqHNP4KSAdS4DCxxd5HHzJzo1Dva/EZk7wmj J8WGT7DtqNMqqim8zRSnWhZoazpG+C+y7ko/Gpbw88JMd+tJRb/EORaIFSkJ4xGAZkI1 DD2Td2AZ6z9IC/G5IH6L5h9X+896UdHHqjOEHse9BpudfZuqY4MWKDYPz3TFIVgJ/3uq tjdA0cFXaA6nLklNSTSFNR9J3eTxonQcrbI557j/LzooroyC72kQUxx/bom+EXCGpy91 hWSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708608123; x=1709212923; 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=IpB/h3lwfLFrLf+CGh0DZz5bM0QyAjW0iXQElsRCUNk=; b=IVmpzELnJnrRlJ6Fyfkl984YVEBQRqsidfZrXV6UlGHXPdyDZAxbuWXTv2Yr0zsYeR qKk4dHMAwIHKdfKFoh4ly3vcfMUdk8Uk84uHqLNkitugupXr766SBCypEFLWjg8c3e0F +buWNAd4TTL9vcZkUSZZ6e6s4n6n7517yHYFy3SdzFc7hR0OZBRprYo29CzAj17vuZP6 Ij4Gf5y85XDSZByvTTp0qc12x0HX9EdrWGIni78nxlLuDuL2D0LCnUnxLwfGH8eKgZBf ndr0/IW6Az5wTovakhunv105XWOpXQSd7a/zwklEmuYQKLdpQZPO4ywrsCBOIYP59iSi ibkQ== X-Gm-Message-State: AOJu0Yxbem/7mlDyzVxjzOZKEC2uhdT/p/CW0hsgG5nyWYqvPRwLdgTN VNSyqDy8qVXO578PQxMae4uEAc3Aslm3z45dN85mFHZz+2P6sEe4B3MELRsU X-Google-Smtp-Source: AGHT+IG2XHZ/f0IN25CndpCZpIOklwiyinTglCBJpkB6euIG1lDmsHx2+4VLvIGWDczr/HopIMqO8Q== X-Received: by 2002:a05:600c:458d:b0:412:60f9:3fec with SMTP id r13-20020a05600c458d00b0041260f93fecmr8910598wmo.15.1708608122925; Thu, 22 Feb 2024 05:22:02 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p18-20020a05600c359200b0041256523bf8sm19332455wmq.31.2024.02.22.05.22.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:22:02 -0800 (PST) Message-ID: <602a7383f726c14bf7941653c2825b4c345247c8.1708608110.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 22 Feb 2024 13:21:49 +0000 Subject: [PATCH v2 10/11] 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: Patrick Steinhardt , 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 fa21a8f2f6b..954a05399f1 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -462,17 +462,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 Thu Feb 22 13:21:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13567336 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 DC6A51482E8 for ; Thu, 22 Feb 2024 13:22:05 +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=1708608127; cv=none; b=D2zu13SOAiN3KuumkukYrCgXFLGu8EBsGJAapxuAwAKDQssSnXqUTaaWjK3bZZjnnV0ZPqoMAjHo5uSHEDXZBt8hJuXGLB7GU5YE0ThyBvsMJjXkKadB2n6JXFMwF6h6O4UxxDzXh3moGJxXRe0Ta3Iyngl0eV06rpjXpYuiw/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708608127; c=relaxed/simple; bh=ycRcJNh4RBH0q+Ha2b1dfdCgivn8LOTTSA25a7ks9Io=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=W9zYBO97/jEiTBQKzyNZcMN4BWI/Eq9ZrueIkkbG9k8d0W/BgsvrFHWBY3g7zuAQ2By/5juAoA5e6BeiNz4Gx4H1v/gScyUCtq35qprlEeZ0CAFNBL2jNToZeBx3D5zmcQTtilNEYDWQORBpy4gp6i3mH9hn5XksbW+U8YmNg+Y= 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=C3hOOYFy; 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="C3hOOYFy" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-33d90dfe73cso367528f8f.0 for ; Thu, 22 Feb 2024 05:22:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708608123; x=1709212923; 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=8ATFgjL2j9vsAkuTtdOxufbw4oIBU/BIZVTdpWAvcts=; b=C3hOOYFyEIBxyWv5hKlilJTSwjIRF77Qy7NBzhS8UuA2mpvgoXCPevUzEOF5GUiS5L rxSjbyTgxYKZOiZU8JQt9Rs/GjEzRKn85QnG8sNUNiKTOwLDzEtVAWH/+9DLXj5jSxJk LDlBfJyOJzssmIVF+VoSBgLX01mhAZ9tZgxiDvYDqbbWWxTnb4z5nEqMzPXhT8EFPMsB aEl7i6BsBtBWbWEua4Vyt+yaNLHe6/Rn/FNI8j8YAvfmbRsE41sPzRIAusCdhU3936OY zZfWXb4dtf6wvzReiKw8cCKtaXUcXwJDrbBx2WQmiB2TwnqMrRE12VUO4QpOUSnpVVco XXbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708608123; x=1709212923; 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=8ATFgjL2j9vsAkuTtdOxufbw4oIBU/BIZVTdpWAvcts=; b=OCbiSPiSD0uUL8jm8iyEc0Uatn8wqTNzWdyTx+EMHKdHfHKKZTE7RYOkAXPPMYi/FX DUevRkL+ZbXSM0V6EF9zv1zMW8SQTMY08GYqfbEz7fiIjwIgUerkgOEfEHNilBN0bUj3 jF13FzGjf4qiOFYPv3C8gbZDNv71lpVM7NxchxVsVwxwrc5hWhCFCHY58shcOvITcwvp t4QqLR4Vze5OKUzoOv5gkoJB5cNdk626A+pkUb1FIMPoELqAFHpA4f/aw+ZygbxX8VaN peVl9z/M4xoaeWXTLRSuVTHXfeEZ6Ud8cfBnjW1C76verx2trUtCzJSfXpAmnLtw2twB Mnpg== X-Gm-Message-State: AOJu0YzCH4MzEiUsEnrKkarZ7cYnywYlI1ke8NamiYDtoVzK0M+6xuXa MVTRbfnZETupfdpy83KHZN31IUefn1aF+3zUz++rY1V0z2Usrk2gI9OxWhMl X-Google-Smtp-Source: AGHT+IEHm1U9EtinAxNiLunt0Gx6yguege/XHVaumx10QCbxXRjf7kNIu9ZGn1B8yrqdGIMjZccUIw== X-Received: by 2002:a5d:5141:0:b0:33d:3f23:eea7 with SMTP id u1-20020a5d5141000000b0033d3f23eea7mr2220595wrt.35.1708608123666; Thu, 22 Feb 2024 05:22:03 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r3-20020adfce83000000b0033d2541b3e1sm18774213wrn.72.2024.02.22.05.22.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:22:03 -0800 (PST) Message-ID: <96850ed2d690adc58dd7866f984a04480e49fec0.1708608110.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 22 Feb 2024 13:21:50 +0000 Subject: [PATCH v2 11/11] 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: Patrick Steinhardt , 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 | 9 ++++++--- commit-reach.c | 16 ++++++---------- commit-reach.h | 7 ++++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/builtin/merge-base.c b/builtin/merge-base.c index 2edffc5487e..a8a1ca53968 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -13,10 +13,13 @@ 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) { + free_commit_list(result); + return -1; + } if (!result) return 1; diff --git a/commit-reach.c b/commit-reach.c index 954a05399f1..2c69cb83d6f 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -471,17 +471,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);