From patchwork Mon Oct 17 13:17:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13008862 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74D21C433FE for ; Mon, 17 Oct 2022 13:17:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230230AbiJQNRw (ORCPT ); Mon, 17 Oct 2022 09:17:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229974AbiJQNRu (ORCPT ); Mon, 17 Oct 2022 09:17:50 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 113FD5F7E9 for ; Mon, 17 Oct 2022 06:17:49 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id bk15so18379450wrb.13 for ; Mon, 17 Oct 2022 06:17:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=oXEoc6/5lUfAgWQpoF3mlId0HIU3GZEyBxBCSN9AC7I=; b=GTDwGcRuXzKQPikPRZFvNgULJhKwapc/VqxrLPza9PMEMOpOnZMxHc8d1MruGIO559 c6UKiygT//HtBRgqLMgWZKluTFQtHd1yhtz3nJV8d3+h5GxIHRXLIyX/nR2EOO51UpsM U+hH0rukhh0P59supCiFcJopHwEQuBo5E/5avUlBCrbSWnZufLkOVAlNaWZJ0g4tX4Uw Onyn1K32FxQrmrIeHT6X1e0IydENOxrKXCdBFoAfLtzs7tVGpyvW6BRjHMCNH0wD04uC p5AwthyFc9Gpjug8/DGm2ai6WjGp6a4g10dD9x4kaxJwdZ1wLZoMgu/pEQBI7kTTXinc TEgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=oXEoc6/5lUfAgWQpoF3mlId0HIU3GZEyBxBCSN9AC7I=; b=tzeYl36wHADrLZW4qVFqNABC5RkgnuYWnh/MgDL2oWQC1ZDz5LQFkx1vdfEDS+qhjU NFpHrBExrX2Reuh+gM8cRilfco+sba8YTMqi9Kgc/0xsSIgluDc76cIK8tcMgxtaYASE GY6/LS9ELLHdQ0IM8aZfxh3JjGlizeVP3lLx6LdEou3DBB5nBWxmLoiAdCkDyzEHmN0U lGx2KzbORgOZYFVMqsQRqGU7Hf4hERSHWkNZP61puuNFNFyXRWvWZRQRaFnYZ/OR2+qM fjV/dTxSoTpQDdPs+Z5zHBAlCliNFZvWR5gaeFw77ZF4aBN388MyN8iE8Aoskr82hzcY D25g== X-Gm-Message-State: ACrzQf3RV2E7hHyAMqD0pxIVsM6F4rvqHygl3zCCRDmjLqt1xWTO+2vR hnw/lRbsP4rFPptBo7nlJWflENbrbzc= X-Google-Smtp-Source: AMsMyM7stMAy/bF8BlVxqrYf2eJWy3FtLP7pOadf2KFse59klzLNcKb4QrXFsS4Pej6f/vuinVjewA== X-Received: by 2002:a5d:408e:0:b0:22e:650a:ec4b with SMTP id o14-20020a5d408e000000b0022e650aec4bmr6439055wrp.212.1666012667357; Mon, 17 Oct 2022 06:17:47 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u7-20020adfed47000000b002286670bafasm8565550wro.48.2022.10.17.06.17.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 06:17:46 -0700 (PDT) Message-Id: <12fb0ac6d5d932f9a8685d803ed017c357182768.1666012665.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 17 Oct 2022 13:17:38 +0000 Subject: [PATCH v4 1/8] t3416: tighten two tests Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Denton Liu , Johannes Schindelin , Phillip Wood , Elijah Newren , Junio C Hamano , Jonathan Tan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood Add a check for the correct error message to the tests that check we require a single merge base so we can be sure the rebase failed for the correct reason. Also rename the tests to reflect what they are testing. Signed-off-by: Phillip Wood --- t/t3416-rebase-onto-threedots.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/t/t3416-rebase-onto-threedots.sh b/t/t3416-rebase-onto-threedots.sh index 3e04802cb00..dc67d2308f3 100755 --- a/t/t3416-rebase-onto-threedots.sh +++ b/t/t3416-rebase-onto-threedots.sh @@ -97,13 +97,14 @@ test_expect_success 'rebase -i --onto main...' ' test_cmp expect actual ' -test_expect_success 'rebase -i --onto main...side' ' +test_expect_success 'rebase --onto main...side requires a single merge-base' ' git reset --hard && git checkout side && git reset --hard K && set_fake_editor && - test_must_fail git rebase -i --onto main...side J + test_must_fail git rebase -i --onto main...side J 2>err && + grep "need exactly one merge base" err ' test_expect_success 'rebase --keep-base --onto incompatible' ' @@ -182,13 +183,14 @@ test_expect_success 'rebase -i --keep-base main topic from main' ' test_cmp expect actual ' -test_expect_success 'rebase -i --keep-base main from side' ' +test_expect_success 'rebase --keep-base requires a single merge base' ' git reset --hard && git checkout side && git reset --hard K && set_fake_editor && - test_must_fail git rebase -i --keep-base main + test_must_fail git rebase -i --keep-base main 2>err && + grep "need exactly one merge base with branch" err ' test_done From patchwork Mon Oct 17 13:17:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13008863 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B549C4332F for ; Mon, 17 Oct 2022 13:17:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230350AbiJQNRz (ORCPT ); Mon, 17 Oct 2022 09:17:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229909AbiJQNRv (ORCPT ); Mon, 17 Oct 2022 09:17:51 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F18A65FF50 for ; Mon, 17 Oct 2022 06:17:49 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id w18so18419904wro.7 for ; Mon, 17 Oct 2022 06:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=7faw4EUCXSCyKuXe8/STylGCsukVPYq05BacxCx1390=; b=l5y0tLV3LKuosmrl57TF5KuQmdf3m/IZMlEFqHj/YuPsILEMzXvquzg83pFrNg34kr XmzpBkPV3GUBba5SbPHmxtzgiD93qVMwAUGN1NMGdSDUOkknm2inWEOeothpSGyEfHOB xdAIVmCHARDUiugzHk6gYV7mus/a5If996jnbpEf/ibkkmZvrZHvROQ6AIzSas5F0A+m nNySWEdSfyT66X0SdhsWaGtFZkZO8s1t0rdWjZ3J9nMw0rQz08aFmhH7vUSliuw2ogi7 Lo3ULkzQD3CuTY3x+M8hh1L1RNylAXaqJ7TPdXhTmQ1P+jbUg0hJUN+e6zZsn3pISwQw ZSwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=7faw4EUCXSCyKuXe8/STylGCsukVPYq05BacxCx1390=; b=f1Xp1YtAJ8r8yLwGZyeRmetBUOJXVJxf7W1vkLf9eFqjvYQbOOk/AVB9VqzFb/ORcG SWWyyAQIzRThd875E6A0RWNBpTfn4k3XS9GkadJ/L0HXBXMw64T7YzQi80TfjZ28e27H 9SvMbmbXerkyqVuWj1z3ZuDgwtSJol376uwHi3DUa+rZLaJgdCI0FyrrnNGeNW+J739p spgKiJHmcj/MlFDfJbCxyISDJb6LoJN6scyVaB+k7EFXCgeN79+CwSXFtl+CRuWy0wRB AbXhafc395Af6p0MX7SWgXAksGwzzgSrzGJPtd1Uod5ALnCI0bEdlDJP7MHM4uEqM9uL j2hw== X-Gm-Message-State: ACrzQf16DTpXGyEBCX9l9a/YyBhS9bhsVYpFnIdIlg6/1RjO8O04MrRD 7hSle1aPoZ1hy6fmK28zdmpzf/az5u0= X-Google-Smtp-Source: AMsMyM6arQf2xdQ79PBKiAyVDD56WRVEYmIiwb+sm3Cei7gZl4UlKJj604sqEEJizErHxbxtkchAmg== X-Received: by 2002:a5d:4c8e:0:b0:22e:3979:7dc9 with SMTP id z14-20020a5d4c8e000000b0022e39797dc9mr6030714wrs.41.1666012668339; Mon, 17 Oct 2022 06:17:48 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v16-20020a5d43d0000000b00228d67db06esm8519319wrr.21.2022.10.17.06.17.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 06:17:47 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 17 Oct 2022 13:17:39 +0000 Subject: [PATCH v4 2/8] t3416: set $EDITOR in subshell Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Denton Liu , Johannes Schindelin , Phillip Wood , Elijah Newren , Junio C Hamano , Jonathan Tan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood As $EDITOR is exported, setting it in one test affects all subsequent tests. Avoid this by always setting it in a subshell. Also remove a couple of unnecessary call to set_fake_editor where the editor does not change the todo list. Signed-off-by: Phillip Wood --- t/t3416-rebase-onto-threedots.sh | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/t/t3416-rebase-onto-threedots.sh b/t/t3416-rebase-onto-threedots.sh index dc67d2308f3..01eb9513d6c 100755 --- a/t/t3416-rebase-onto-threedots.sh +++ b/t/t3416-rebase-onto-threedots.sh @@ -79,8 +79,10 @@ test_expect_success 'rebase -i --onto main...topic' ' git reset --hard && git checkout topic && git reset --hard G && - set_fake_editor && - EXPECT_COUNT=1 git rebase -i --onto main...topic F && + ( + set_fake_editor && + EXPECT_COUNT=1 git rebase -i --onto main...topic F + ) && git rev-parse HEAD^1 >actual && git rev-parse C^0 >expect && test_cmp expect actual @@ -90,8 +92,10 @@ test_expect_success 'rebase -i --onto main...' ' git reset --hard && git checkout topic && git reset --hard G && - set_fake_editor && - EXPECT_COUNT=1 git rebase -i --onto main... F && + ( + set_fake_editor && + EXPECT_COUNT=1 git rebase -i --onto main... F + ) && git rev-parse HEAD^1 >actual && git rev-parse C^0 >expect && test_cmp expect actual @@ -102,7 +106,6 @@ test_expect_success 'rebase --onto main...side requires a single merge-base' ' git checkout side && git reset --hard K && - set_fake_editor && test_must_fail git rebase -i --onto main...side J 2>err && grep "need exactly one merge base" err ' @@ -157,8 +160,10 @@ test_expect_success 'rebase -i --keep-base main from topic' ' git checkout topic && git reset --hard G && - set_fake_editor && - EXPECT_COUNT=2 git rebase -i --keep-base main && + ( + set_fake_editor && + EXPECT_COUNT=2 git rebase -i --keep-base main + ) && git rev-parse C >base.expect && git merge-base main HEAD >base.actual && test_cmp base.expect base.actual && @@ -172,8 +177,10 @@ test_expect_success 'rebase -i --keep-base main topic from main' ' git checkout main && git branch -f topic G && - set_fake_editor && - EXPECT_COUNT=2 git rebase -i --keep-base main topic && + ( + set_fake_editor && + EXPECT_COUNT=2 git rebase -i --keep-base main topic + ) && git rev-parse C >base.expect && git merge-base main HEAD >base.actual && test_cmp base.expect base.actual && @@ -188,9 +195,13 @@ test_expect_success 'rebase --keep-base requires a single merge base' ' git checkout side && git reset --hard K && - set_fake_editor && test_must_fail git rebase -i --keep-base main 2>err && grep "need exactly one merge base with branch" err ' +# This must be the last test in this file +test_expect_success '$EDITOR and friends are unchanged' ' + test_editor_unchanged +' + test_done From patchwork Mon Oct 17 13:17:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13008864 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D38AC433FE for ; Mon, 17 Oct 2022 13:18:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230436AbiJQNR6 (ORCPT ); Mon, 17 Oct 2022 09:17:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230258AbiJQNRw (ORCPT ); Mon, 17 Oct 2022 09:17:52 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B7274D25B for ; Mon, 17 Oct 2022 06:17:51 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id iv17so8618943wmb.4 for ; Mon, 17 Oct 2022 06:17:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=t4XqjxzKj5QYArEQIi/wuOmUM5Rr9PThx002U33744k=; b=FBVxU/j5YGzJqLv36blL3U2iJMxevvbeNvdBvpir+7by20PFEs0RVY/7KwER+oIMQx B62XC0y6HdGdizj+2Wq5bM16iE/fAkvCpk+bfUkOdIX+dicW48m/7tCE70pGrURH3DzV 02P2qIizugSiDCxSaw+Q9bWs6slOwAf+ddMXHtvQuO2LGX+JDJGh+5Z0CEFI1paaHyrj RUVZsjsDDmFuftAI//FDI5Z4NzcnzOJQgD0AzqUlcZKIgwrw03YAVZGRsJkQjmdpHVNF VCH7h/zcz8ylr9VGDaamfBJwkrvR0o1XLysUIpCPmeJUPx6OHjlDGWd+X9Mp0WGtDhHP eE/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=t4XqjxzKj5QYArEQIi/wuOmUM5Rr9PThx002U33744k=; b=zXvHLAsrrPblcxODOaXF8dOYe/wczmvgoG3mbX7Aqr4RtW/0AHpkb2mzNYq36UBrFI u4MkMN3C4/bfWuRfPl0fKzkTiEkWlPFKjoF3RXBXbzdV2OSuf41Rzg+Ph6RPmlbmU0Uj jLNlV8lvhCvWInHRWR4wgN9jJg8ml0aalGGtYfNfOXSVW7UdhfTYF/6ckpLGhb8vuI6o qJhZgo4bHyKTez3TyG/RK7/K4cht/gXPvf3n73ObUukGtFW4ycXEkFpQ5dIW92N8S4Hw oIbINAsygA5IZE9SDLHxqawO2ieHD7hKE4TiBcdSwy7bANtuCLD/GE9XF+bWG8sfvlhY hcYg== X-Gm-Message-State: ACrzQf2JrMkk+U0xDu0Ikh5A/xLv9C8FnmUS4BGK3k8eKlOEdFI0F4Bm c/TeJVGeb5nu2Xre3SPlocdLXODlH14= X-Google-Smtp-Source: AMsMyM5LgEVcqgdAvnAM+6hhe7MbmSLIxEWx46pCzRpvAK9RpGvC+CIyyVuWxIQZvYUvSravLUYtNw== X-Received: by 2002:a05:600c:220a:b0:3c5:df6:2f3b with SMTP id z10-20020a05600c220a00b003c50df62f3bmr18716317wml.63.1666012669284; Mon, 17 Oct 2022 06:17:49 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m6-20020a1c2606000000b003c452678025sm15539087wmm.4.2022.10.17.06.17.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 06:17:48 -0700 (PDT) Message-Id: <1d5e0419c45087c474f33d5ea6b3bcdacd072fa5.1666012665.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 17 Oct 2022 13:17:40 +0000 Subject: [PATCH v4 3/8] rebase: be stricter when reading state files containing oids Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Denton Liu , Johannes Schindelin , Phillip Wood , Elijah Newren , Junio C Hamano , Jonathan Tan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood The state files for 'onto' and 'orig_head' should contain a full hex oid, change the reading functions from get_oid() to get_oid_hex() to reflect this. They should also name commits and not tags so add and use a function that looks up a commit from an oid like lookup_commit_reference() but without dereferencing tags. Suggested-by: Junio C Hamano Signed-off-by: Phillip Wood --- builtin/rebase.c | 8 ++++---- commit.c | 8 ++++++++ commit.h | 13 +++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 56e4214b441..06903eb6d4d 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -431,9 +431,9 @@ static int read_basic_state(struct rebase_options *opts) opts->head_name = starts_with(head_name.buf, "refs/") ? xstrdup(head_name.buf) : NULL; strbuf_release(&head_name); - if (get_oid(buf.buf, &oid)) - return error(_("could not get 'onto': '%s'"), buf.buf); - opts->onto = lookup_commit_or_die(&oid, buf.buf); + if (get_oid_hex(buf.buf, &oid) || + !(opts->onto = lookup_commit_object(the_repository, &oid))) + return error(_("invalid onto: '%s'"), buf.buf); /* * We always write to orig-head, but interactive rebase used to write to @@ -448,7 +448,7 @@ static int read_basic_state(struct rebase_options *opts) } else if (!read_oneliner(&buf, state_dir_path("head", opts), READ_ONELINER_WARN_MISSING)) return -1; - if (get_oid(buf.buf, &opts->orig_head)) + if (get_oid_hex(buf.buf, &opts->orig_head)) return error(_("invalid orig-head: '%s'"), buf.buf); if (file_exists(state_dir_path("quiet", opts))) diff --git a/commit.c b/commit.c index 0db461f9735..de30b098dd3 100644 --- a/commit.c +++ b/commit.c @@ -59,6 +59,14 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref return c; } +struct commit *lookup_commit_object (struct repository *r, + const struct object_id *oid) +{ + struct object *obj = parse_object(r, oid); + return obj ? object_as_type(obj, OBJ_COMMIT, 0) : NULL; + +} + struct commit *lookup_commit(struct repository *r, const struct object_id *oid) { struct object *obj = lookup_object(r, oid); diff --git a/commit.h b/commit.h index 21e4d25ce78..fa39202fa6b 100644 --- a/commit.h +++ b/commit.h @@ -64,6 +64,19 @@ enum decoration_type { void add_name_decoration(enum decoration_type type, const char *name, struct object *obj); const struct name_decoration *get_name_decoration(const struct object *obj); +/* + * Look up commit named by "oid" respecting replacement objects. + * Returns NULL if "oid" is not a commit or does not exist. + */ +struct commit *lookup_commit_object(struct repository *r, const struct object_id *oid); + +/* + * Look up commit named by "oid" without replacement objects or + * checking for object existence. Returns the requested commit if it + * is found in the object cache, NULL if "oid" is in the object cache + * but is not a commit and a newly allocated unparsed commit object if + * "oid" is not in the object cache. + */ struct commit *lookup_commit(struct repository *r, const struct object_id *oid); struct commit *lookup_commit_reference(struct repository *r, const struct object_id *oid); From patchwork Mon Oct 17 13:17:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13008865 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F32ADC433FE for ; Mon, 17 Oct 2022 13:18:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230444AbiJQNSA (ORCPT ); Mon, 17 Oct 2022 09:18:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230291AbiJQNRy (ORCPT ); Mon, 17 Oct 2022 09:17:54 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14EBD5F7E9 for ; Mon, 17 Oct 2022 06:17:52 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id f11so18408906wrm.6 for ; Mon, 17 Oct 2022 06:17:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=xzkAdR/cmhQWP52wBCVOyaeBNaay//gaD99aQbZf56w=; b=GfnyYSDTT5W0PA+AdeF6Tzg7e5cVAA/nFQU6PMT212h68H7z7xft47dXk7PSniHkac 94v28it+Sz3IgyAGlsfwrhyDXzGlI7FUzhE2AsIkZZW3zg+OxAAcznFVle4YMDb4nj58 PEAeX6RI5oWvsmtq/PuvJUfOVWaiNOB1GAN765T3kImyS3e4Pa1F9W6kN2PJKfwQC7x5 yL7kILlUpenfG9bqP61hBvWRU+qQnPfmAqBTKuPqJlDJa583dbB9tX+bkgnL4CXDLx3G rkZfRRY5PU/q/RURLVjmYUylH7vyJGqSC4RpNkwv5kPn2/ifrXr2eut6550eJPSTW9Xc BWXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=xzkAdR/cmhQWP52wBCVOyaeBNaay//gaD99aQbZf56w=; b=3vyd6sRkP9F/+nMbFXV3ot72RU1LsyyjzdgCy+UNIipIVC9PGksJQCPzUN1PHp7W/s QS3UlLzCgRgUBswuoLOlNdTmO5fj9wFIinPLz2R5oLdccukI1BLGM47jH98gpeA+XCT9 1iNn5rEh7+O6vB4UqjtgcPg3F7P09Eh9wDHQBus4om9mjzbctQfx/HAfX2RGi7jVYkHk qrVHXy/6AQgc1GqyhDRTJqcv2kyGoGb+zFkM1ck8oj61WeeEz7wKLk9Kjeg2w67voLkU PH0qyfd1xt7bRUMNsuyv4GK54CLvwNnW77dCzQ6DVbJIo56+Lsdq4KWMJwz0tCtZ0phF 2ccg== X-Gm-Message-State: ACrzQf3gwOIcAfMU76x3zQI/bGzWnJhlfvGnhaJjAcl9zyGavtKGLVeT GqD+qwGmNkHZvSJQo/P32WoupnQPPQk= X-Google-Smtp-Source: AMsMyM5HCVaVxtOdRacs6KPZhXBcBB2BoST9eAS2S+V128vYp9ntzVcgv1QYr0typfw8ybuZcUM2mA== X-Received: by 2002:a5d:5988:0:b0:22e:5a65:1e21 with SMTP id n8-20020a5d5988000000b0022e5a651e21mr6357887wri.338.1666012670249; Mon, 17 Oct 2022 06:17:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t8-20020a5d6a48000000b0022b11a27e39sm8382397wrw.1.2022.10.17.06.17.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 06:17:49 -0700 (PDT) Message-Id: <22f3d265b57a7148d503a9eeddd19614f441824d.1666012665.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 17 Oct 2022 13:17:41 +0000 Subject: [PATCH v4 4/8] rebase: store orig_head as a commit Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Denton Liu , Johannes Schindelin , Phillip Wood , Elijah Newren , Junio C Hamano , Jonathan Tan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood Using a struct commit rather than a struct oid to hold orig_head means that we error out straight away if the branch being rebased does not point to a commit. It also simplifies the code that handles finding the merge base and fork point as it no longer has to convert from an oid to a commit. To avoid changing the behavior of "git rebase " we keep the existing call to read_ref() and use lookup_commit_object() on the oid returned by that rather than calling lookup_commit_reference_by_name() which applies the ref dwim rules to its argument. Helped-by: Junio C Hamano Signed-off-by: Phillip Wood --- builtin/rebase.c | 67 ++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 06903eb6d4d..211e9139f2e 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -68,7 +68,7 @@ struct rebase_options { const char *upstream_name; const char *upstream_arg; char *head_name; - struct object_id orig_head; + struct commit *orig_head; struct commit *onto; const char *onto_name; const char *revisions; @@ -261,13 +261,13 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags) struct replay_opts replay = get_replay_opts(opts); struct string_list commands = STRING_LIST_INIT_DUP; - if (get_revision_ranges(opts->upstream, opts->onto, &opts->orig_head, + if (get_revision_ranges(opts->upstream, opts->onto, &opts->orig_head->object.oid, &revisions, &shortrevisions)) return -1; if (init_basic_state(&replay, opts->head_name ? opts->head_name : "detached HEAD", - opts->onto, &opts->orig_head)) { + opts->onto, &opts->orig_head->object.oid)) { free(revisions); free(shortrevisions); @@ -298,9 +298,8 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags) split_exec_commands(opts->cmd, &commands); ret = complete_action(the_repository, &replay, flags, shortrevisions, opts->onto_name, opts->onto, - &opts->orig_head, &commands, opts->autosquash, - opts->update_refs, - &todo_list); + &opts->orig_head->object.oid, &commands, + opts->autosquash, opts->update_refs, &todo_list); } string_list_clear(&commands, 0); @@ -448,7 +447,8 @@ static int read_basic_state(struct rebase_options *opts) } else if (!read_oneliner(&buf, state_dir_path("head", opts), READ_ONELINER_WARN_MISSING)) return -1; - if (get_oid_hex(buf.buf, &opts->orig_head)) + if (get_oid_hex(buf.buf, &oid) || + !(opts->orig_head = lookup_commit_object(the_repository, &oid))) return error(_("invalid orig-head: '%s'"), buf.buf); if (file_exists(state_dir_path("quiet", opts))) @@ -517,7 +517,7 @@ static int rebase_write_basic_state(struct rebase_options *opts) write_file(state_dir_path("onto", opts), "%s", opts->onto ? oid_to_hex(&opts->onto->object.oid) : ""); write_file(state_dir_path("orig-head", opts), "%s", - oid_to_hex(&opts->orig_head)); + oid_to_hex(&opts->orig_head->object.oid)); if (!(opts->flags & REBASE_NO_QUIET)) write_file(state_dir_path("quiet", opts), "%s", ""); if (opts->flags & REBASE_VERBOSE) @@ -646,7 +646,7 @@ static int run_am(struct rebase_options *opts) /* this is now equivalent to !opts->upstream */ &opts->onto->object.oid : &opts->upstream->object.oid), - oid_to_hex(&opts->orig_head)); + oid_to_hex(&opts->orig_head->object.oid)); rebased_patches = xstrdup(git_path("rebased-patches")); format_patch.out = open(rebased_patches, @@ -680,7 +680,7 @@ static int run_am(struct rebase_options *opts) free(rebased_patches); strvec_clear(&am.args); - ropts.oid = &opts->orig_head; + ropts.oid = &opts->orig_head->object.oid; ropts.branch = opts->head_name; ropts.default_reflog_action = DEFAULT_REFLOG_ACTION; reset_head(the_repository, &ropts); @@ -833,7 +833,7 @@ static int checkout_up_to_date(struct rebase_options *options) strbuf_addf(&buf, "%s: checkout %s", getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options->switch_to); - ropts.oid = &options->orig_head; + ropts.oid = &options->orig_head->object.oid; ropts.branch = options->head_name; ropts.flags = RESET_HEAD_RUN_POST_CHECKOUT_HOOK; if (!ropts.branch) @@ -866,15 +866,11 @@ static int is_linear_history(struct commit *from, struct commit *to) static int can_fast_forward(struct commit *onto, struct commit *upstream, struct commit *restrict_revision, - struct object_id *head_oid, struct object_id *merge_base) + struct commit *head, struct object_id *merge_base) { - struct commit *head = lookup_commit(the_repository, head_oid); struct commit_list *merge_bases = NULL; int res = 0; - if (!head) - goto done; - merge_bases = get_merge_bases(onto, head); if (!merge_bases || merge_bases->next) { oidcpy(merge_base, null_oid()); @@ -1312,13 +1308,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) if (read_basic_state(&options)) exit(1); - ropts.oid = &options.orig_head; + ropts.oid = &options.orig_head->object.oid; ropts.branch = options.head_name; ropts.flags = RESET_HEAD_HARD; ropts.default_reflog_action = DEFAULT_REFLOG_ACTION; if (reset_head(the_repository, &ropts) < 0) die(_("could not move back to %s"), - oid_to_hex(&options.orig_head)); + oid_to_hex(&options.orig_head->object.oid)); remove_branch_state(the_repository, 0); ret = finish_rebase(&options); goto cleanup; @@ -1604,25 +1600,27 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) */ if (argc == 1) { /* Is it "rebase other branchname" or "rebase other commit"? */ + struct object_id branch_oid; branch_name = argv[0]; options.switch_to = argv[0]; /* Is it a local branch? */ strbuf_reset(&buf); strbuf_addf(&buf, "refs/heads/%s", branch_name); - if (!read_ref(buf.buf, &options.orig_head)) { + if (!read_ref(buf.buf, &branch_oid)) { die_if_checked_out(buf.buf, 1); options.head_name = xstrdup(buf.buf); + options.orig_head = + lookup_commit_object(the_repository, + &branch_oid); /* If not is it a valid ref (branch or commit)? */ } else { - struct commit *commit = + options.orig_head = lookup_commit_reference_by_name(branch_name); - if (!commit) - die(_("no such branch/commit '%s'"), - branch_name); - oidcpy(&options.orig_head, &commit->object.oid); options.head_name = NULL; } + if (!options.orig_head) + die(_("no such branch/commit '%s'"), branch_name); } else if (argc == 0) { /* Do not need to switch branches, we are already on it. */ options.head_name = @@ -1639,8 +1637,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) FREE_AND_NULL(options.head_name); branch_name = "HEAD"; } - if (get_oid("HEAD", &options.orig_head)) - die(_("Could not resolve HEAD to a revision")); + options.orig_head = lookup_commit_reference_by_name("HEAD"); + if (!options.orig_head) + die(_("Could not resolve HEAD to a commit")); } else BUG("unexpected number of arguments left to parse"); @@ -1672,13 +1671,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.onto_name); } - if (options.fork_point > 0) { - struct commit *head = - lookup_commit_reference(the_repository, - &options.orig_head); + if (options.fork_point > 0) options.restrict_revision = - get_fork_point(options.upstream_name, head); - } + get_fork_point(options.upstream_name, options.orig_head); if (repo_read_index(the_repository) < 0) die(_("could not read index")); @@ -1708,7 +1703,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) * call it before checking allow_preemptive_ff. */ if (can_fast_forward(options.onto, options.upstream, options.restrict_revision, - &options.orig_head, &merge_base) && + options.orig_head, &merge_base) && allow_preemptive_ff) { int flag; @@ -1785,7 +1780,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) strbuf_addf(&msg, "%s: checkout %s", getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name); ropts.oid = &options.onto->object.oid; - ropts.orig_head = &options.orig_head, + ropts.orig_head = &options.orig_head->object.oid, ropts.flags = RESET_HEAD_DETACH | RESET_ORIG_HEAD | RESET_HEAD_RUN_POST_CHECKOUT_HOOK; ropts.head_msg = msg.buf; @@ -1799,7 +1794,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) * we just fast-forwarded. */ strbuf_reset(&msg); - if (oideq(&merge_base, &options.orig_head)) { + if (oideq(&merge_base, &options.orig_head->object.oid)) { printf(_("Fast-forwarded %s to %s.\n"), branch_name, options.onto_name); strbuf_addf(&msg, "rebase finished: %s onto %s", @@ -1820,7 +1815,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) (options.restrict_revision ? oid_to_hex(&options.restrict_revision->object.oid) : oid_to_hex(&options.upstream->object.oid)), - oid_to_hex(&options.orig_head)); + oid_to_hex(&options.orig_head->object.oid)); options.revisions = revisions.buf; From patchwork Mon Oct 17 13:17:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13008867 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA903C433FE for ; Mon, 17 Oct 2022 13:18:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230503AbiJQNSO (ORCPT ); Mon, 17 Oct 2022 09:18:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229909AbiJQNR4 (ORCPT ); Mon, 17 Oct 2022 09:17:56 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E900B61116 for ; Mon, 17 Oct 2022 06:17:53 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id r8-20020a1c4408000000b003c47d5fd475so12675771wma.3 for ; Mon, 17 Oct 2022 06:17:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=qzQeiEYJNz8/AgY3Nwo7MkE5MHdlACypJs6itrpRQN4=; b=npQ5mieuf/oEtUc/HqRg9iA814VaOXw9M/ju3/ZdnUN6QDYayM02xowJJyOz757ViB z+5bINGVsJ9t6qoCwo506gZGBs4Wq3jSWDdC4QiNXBHw1LPxkA0iaqlzIK77w3Q00l6T i4qtmy2brSvLHJm5Ljwzcqut203rAGUSzAKqLYTezQV/QkxldRbqiaSvkYloheh5JBsK FG0+NPyM0i9enpfWn8KgWbPs8tABVshFWLIKfPwpza9aDhfNc7n87OPq8vvq06jjCcvR L+R1oVpaLmx9856q/VmsPEzJG38kX40TanNSwNJbSb+q4hIkTKzL0XVEjYhUV+xJigmE sC2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=qzQeiEYJNz8/AgY3Nwo7MkE5MHdlACypJs6itrpRQN4=; b=Va91cWukInu0P/kFJaHG0NPhXVuAv8wM8Ve8qS//D4g6+IBvVZEaaTp+vTJ1x9vAuV hZrw/Fmr9PwESvE4ktmKCnG3mAMhhyb60GAJn/af3HEb6/N06cK2AUaQenNh/B846MYk mYlESS1XyFZ3iKt75TL14J2K75wMwbEbzvFkVin7mCQhHnpxGTQjLWT6GN1FnDd12STp L0eNMFLstMoD9vl2iGWGXmIVeH2ax6xT09MZRro1cDeFfYz7DfeSApD21qbfzpTVTry+ U6NOKtOrz8cvOaG8xdP0AJ8Xt8VRBmFCzG0Af6MmDEo094zKl8L/TfC/L3mlwzVK57yj CKgw== X-Gm-Message-State: ACrzQf06FdXL+eupLTGmaPe+bGOCQZiO22tIy+QLQ3aylNaxy8qDqIml 1GK/Z0EYj+Ykrwha/IoEB/1GrY1BMv8= X-Google-Smtp-Source: AMsMyM5RCCvSkfpqazo2CkL06s9RDJ3D4RV2uKI14wnrWzgMePbq2/FUmhPgpm+gUsv2qknBaKh8kg== X-Received: by 2002:a05:600c:34cc:b0:3c6:fb65:24cc with SMTP id d12-20020a05600c34cc00b003c6fb6524ccmr952700wmq.1.1666012671332; Mon, 17 Oct 2022 06:17:51 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n14-20020a5d400e000000b0022ae401e9e0sm8409542wrp.78.2022.10.17.06.17.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 06:17:50 -0700 (PDT) Message-Id: <79a8c0fe28434b4eb3e53cbb76a25024b1b43cb5.1666012665.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 17 Oct 2022 13:17:42 +0000 Subject: [PATCH v4 5/8] rebase: rename merge_base to branch_base Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Denton Liu , Johannes Schindelin , Phillip Wood , Elijah Newren , Junio C Hamano , Jonathan Tan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood merge_base is not a very descriptive name, the variable always holds the merge-base of 'branch' and 'onto' which is commit at the base of the branch being rebased so rename it to branch_base. Signed-off-by: Phillip Wood --- builtin/rebase.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 211e9139f2e..d70b9b248fa 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -866,22 +866,22 @@ static int is_linear_history(struct commit *from, struct commit *to) static int can_fast_forward(struct commit *onto, struct commit *upstream, struct commit *restrict_revision, - struct commit *head, struct object_id *merge_base) + struct commit *head, struct object_id *branch_base) { struct commit_list *merge_bases = NULL; int res = 0; merge_bases = get_merge_bases(onto, head); if (!merge_bases || merge_bases->next) { - oidcpy(merge_base, null_oid()); + oidcpy(branch_base, null_oid()); goto done; } - oidcpy(merge_base, &merge_bases->item->object.oid); - if (!oideq(merge_base, &onto->object.oid)) + oidcpy(branch_base, &merge_bases->item->object.oid); + if (!oideq(branch_base, &onto->object.oid)) goto done; - if (restrict_revision && !oideq(&restrict_revision->object.oid, merge_base)) + if (restrict_revision && !oideq(&restrict_revision->object.oid, branch_base)) goto done; if (!upstream) @@ -1035,7 +1035,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) struct strbuf msg = STRBUF_INIT; struct strbuf revisions = STRBUF_INIT; struct strbuf buf = STRBUF_INIT; - struct object_id merge_base; + struct object_id branch_base; int ignore_whitespace = 0; enum action action = ACTION_NONE; const char *gpg_sign = NULL; @@ -1653,7 +1653,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } else if (!options.onto_name) options.onto_name = options.upstream_name; if (strstr(options.onto_name, "...")) { - if (get_oid_mb(options.onto_name, &merge_base) < 0) { + if (get_oid_mb(options.onto_name, &branch_base) < 0) { if (keep_base) die(_("'%s': need exactly one merge base with branch"), options.upstream_name); @@ -1661,7 +1661,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) die(_("'%s': need exactly one merge base"), options.onto_name); } - options.onto = lookup_commit_or_die(&merge_base, + options.onto = lookup_commit_or_die(&branch_base, options.onto_name); } else { options.onto = @@ -1699,11 +1699,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) * in which case we could fast-forward without replacing the commits * with new commits recreated by replaying their changes. * - * Note that can_fast_forward() initializes merge_base, so we have to + * Note that can_fast_forward() initializes branch_base, so we have to * call it before checking allow_preemptive_ff. */ if (can_fast_forward(options.onto, options.upstream, options.restrict_revision, - options.orig_head, &merge_base) && + options.orig_head, &branch_base) && allow_preemptive_ff) { int flag; @@ -1745,12 +1745,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) struct diff_options opts; if (options.flags & REBASE_VERBOSE) { - if (is_null_oid(&merge_base)) + if (is_null_oid(&branch_base)) printf(_("Changes to %s:\n"), oid_to_hex(&options.onto->object.oid)); else printf(_("Changes from %s to %s:\n"), - oid_to_hex(&merge_base), + oid_to_hex(&branch_base), oid_to_hex(&options.onto->object.oid)); } @@ -1762,8 +1762,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT; opts.detect_rename = DIFF_DETECT_RENAME; diff_setup_done(&opts); - diff_tree_oid(is_null_oid(&merge_base) ? - the_hash_algo->empty_tree : &merge_base, + diff_tree_oid(is_null_oid(&branch_base) ? + the_hash_algo->empty_tree : &branch_base, &options.onto->object.oid, "", &opts); diffcore_std(&opts); diff_flush(&opts); @@ -1794,7 +1794,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) * we just fast-forwarded. */ strbuf_reset(&msg); - if (oideq(&merge_base, &options.orig_head->object.oid)) { + if (oideq(&branch_base, &options.orig_head->object.oid)) { printf(_("Fast-forwarded %s to %s.\n"), branch_name, options.onto_name); strbuf_addf(&msg, "rebase finished: %s onto %s", From patchwork Mon Oct 17 13:17:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13008866 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1235CC4332F for ; Mon, 17 Oct 2022 13:18:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229905AbiJQNSN (ORCPT ); Mon, 17 Oct 2022 09:18:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbiJQNR4 (ORCPT ); Mon, 17 Oct 2022 09:17:56 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F4B95C9E8 for ; Mon, 17 Oct 2022 06:17:54 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id m29-20020a05600c3b1d00b003c6bf423c71so12260733wms.0 for ; Mon, 17 Oct 2022 06:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=LF+NGj9dormuMpuEtDjpx1ozsfBQtYr1oEqnz9zZelw=; b=Ku5lrJ7STgAAAB5sH41bLS4mM1QOevLYPpF/+p1uVMZZGA7LMk18+oOUE6nB6WGKIp oGwTORmy5s7W5Mdsfp80OLYYvJf3L/1wnu/zVxdFD8DSkk9eKbz4c7185WoXjSN6E9Sl 3hiZECW2Co2c7Up2ipJekqOY4fpKXB3qL8K/6zllL9dsCw/iJFOdYlR9rICadBLCxK4b NTym/fsKoMot5Db+io3pqiD9In2C6nOQz/OTDau8uDk7elpTYiacbfFZdQ3jIPXDTZ64 zlrXu3AYOUbPkGoCapyTZD7dBK5vTENKZ6+k5bjxYoxL8GnfQGkv+XqOvaiN1S0xKkXP 6cNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=LF+NGj9dormuMpuEtDjpx1ozsfBQtYr1oEqnz9zZelw=; b=O4V+Ha9WTyu5Iu/mKxHY5/26RaOHPrEo+GLzJeSw/fITjqCiSu0G68hHQrsRBC+Tu0 lzu7gf6TVVx9KWoOPlaKImhjWuxevS2JFBl7zXCG49HC0fkB2UkoqSHjdfiaz0cLeCQ0 RSHJmNukJtv9jrznBPlcmn7qTC/LD5666YmI+RDkv3rWRfyqxcyzlReYsTCvq6exMLEb Y+lb+4my5VeMDXQ/CpY6MuBfnnsuDrglG5D2Q66VAToQ936S2k0GaTwdQDOywzoEpM5s UL3KWHNitarf6YoM7ihkwnLqP0pAm6y/uGfYzZK2upKEq0kzD07JOPGqtVp2iDSJlD+g 8JRw== X-Gm-Message-State: ACrzQf16UvOLuUMJV3m7xmYvEf/HsRRZ60Bb0QIkj6BqzL3LTzPCaDZY ZT6peiAd0qu3Y5+7i0mmv5Ct1gEbPLQ= X-Google-Smtp-Source: AMsMyM4fsj6QVvhhfoS0siczhpgq3pPNPOb5wkxXxXwKLWVL43kTUDEc8vyZSFxzyywGAx7tnfW4mw== X-Received: by 2002:a05:600c:46ce:b0:3c6:f243:8d74 with SMTP id q14-20020a05600c46ce00b003c6f2438d74mr6861889wmo.166.1666012672370; Mon, 17 Oct 2022 06:17:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l1-20020a5d4bc1000000b0022afe4fb459sm3624747wrt.51.2022.10.17.06.17.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 06:17:51 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 17 Oct 2022 13:17:43 +0000 Subject: [PATCH v4 6/8] rebase: factor out branch_base calculation Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Denton Liu , Johannes Schindelin , Phillip Wood , Elijah Newren , Junio C Hamano , Jonathan Tan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood Separate out calculating the merge base between 'onto' and 'HEAD' from the check for whether we can fast-forward or not. This means we can skip the fast-forward checks when the rebase is forced and avoid calculating the merge-base between 'HEAD' and 'onto' when --keep-base is given. Signed-off-by: Phillip Wood --- builtin/rebase.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index d70b9b248fa..90ae8fd8de7 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -871,13 +871,9 @@ static int can_fast_forward(struct commit *onto, struct commit *upstream, struct commit_list *merge_bases = NULL; int res = 0; - merge_bases = get_merge_bases(onto, head); - if (!merge_bases || merge_bases->next) { - oidcpy(branch_base, null_oid()); - goto done; - } + if (is_null_oid(branch_base)) + goto done; /* fill_branch_base() found multiple merge bases */ - oidcpy(branch_base, &merge_bases->item->object.oid); if (!oideq(branch_base, &onto->object.oid)) goto done; @@ -887,7 +883,6 @@ static int can_fast_forward(struct commit *onto, struct commit *upstream, if (!upstream) goto done; - free_commit_list(merge_bases); merge_bases = get_merge_bases(upstream, head); if (!merge_bases || merge_bases->next) goto done; @@ -902,6 +897,20 @@ done: return res && is_linear_history(onto, head); } +static void fill_branch_base(struct rebase_options *options, + struct object_id *branch_base) +{ + struct commit_list *merge_bases = NULL; + + merge_bases = get_merge_bases(options->onto, options->orig_head); + if (!merge_bases || merge_bases->next) + oidcpy(branch_base, null_oid()); + else + oidcpy(branch_base, &merge_bases->item->object.oid); + + free_commit_list(merge_bases); +} + static int parse_opt_am(const struct option *opt, const char *arg, int unset) { struct rebase_options *opts = opt->value; @@ -1669,6 +1678,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) if (!options.onto) die(_("Does not point to a valid commit '%s'"), options.onto_name); + fill_branch_base(&options, &branch_base); } if (options.fork_point > 0) @@ -1698,13 +1708,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) * Check if we are already based on onto with linear history, * in which case we could fast-forward without replacing the commits * with new commits recreated by replaying their changes. - * - * Note that can_fast_forward() initializes branch_base, so we have to - * call it before checking allow_preemptive_ff. */ - if (can_fast_forward(options.onto, options.upstream, options.restrict_revision, - options.orig_head, &branch_base) && - allow_preemptive_ff) { + if (allow_preemptive_ff && + can_fast_forward(options.onto, options.upstream, options.restrict_revision, + options.orig_head, &branch_base)) { int flag; if (!(options.flags & REBASE_FORCE)) { From patchwork Mon Oct 17 13:17:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13008868 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3653C4332F for ; Mon, 17 Oct 2022 13:18:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230396AbiJQNSQ (ORCPT ); Mon, 17 Oct 2022 09:18:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230440AbiJQNR7 (ORCPT ); Mon, 17 Oct 2022 09:17:59 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C689961D71 for ; Mon, 17 Oct 2022 06:17:55 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id l32so8629665wms.2 for ; Mon, 17 Oct 2022 06:17:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=f3Omp7XenVN67hPeqLMKSf3k2o/8oFmfRIUuQR1BZGY=; b=aOMhPNVnh/I+4Ao9Wc4woJa2GBf7whNj4WRw+QnT/6QIbX+1TDe/yO3CaMjp1xuXed EqmtGVU9rTZp8aRvf8LFBRgSt2sosMvuUxTAeDDg/zLuXJHHW4OCwMeh/MPSIq4bgSEk N8B2K6xBmTxupRYcCBhe8GosA52ZCCUOawRKZRsZrFRWHkjoEjWwAmpZygBeBs6G7HlI ErzxGFuLO84nvYhSn0DqNP4h4nNHShRbK68WNvFtnPJWfnp2ope6WB1oy41LZ0odZiaA WpJ5y+Udt9Gqcpo3L/YdAdyMrwcS2H5en/KMRo4FkplT6W2aUWS6pv7opW9Jyd9UIHY/ FjVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=f3Omp7XenVN67hPeqLMKSf3k2o/8oFmfRIUuQR1BZGY=; b=2s6z8LOnna0Ce3HWKPAEpH8m+Vyn1k8IrgfhrX7k54bZiF3VJw1HkcyU7bMb9oAD1O wiChN86Mgyw8S9nhVHnBoK3bzIeD1DMHps11lypHuL8Xp+9fR1V9oxG3xsJ+L2TytK8m FjTTF8ABIrm9UfWvrqhM3f3yZU8Kto7Ztyld6oNZm8dV4de0I20EWm4Iwp+4w/XIw39J j5Y8KhI0ve+TSoSZE+mG1ctIOGxotSafib2KhDKfTJbd0KyKtvtJmJ7dzHSzOYhiUtPC DpCIbpZnvx1PrBY0gPeX1B8Q0k2jUTL9Q+oAcjD3gABlZ9gWhy6JSpV5YkeJL1SZpr2Q jC3w== X-Gm-Message-State: ACrzQf0rw8wchHVAgk0zR7+Xqa4qFHt2jcHfosYY89CaZgb/hqiALo74 +HTeMSlPC96qEq5qC+RE5t/VesHdjjM= X-Google-Smtp-Source: AMsMyM5vGxasnbaBD922oxm1UC3Fh+OelHAqreIGux7VrdPxTITw1zYLpZMoiDVgb8Vqnde+Lmomxg== X-Received: by 2002:a05:600c:219a:b0:3c6:f259:7e30 with SMTP id e26-20020a05600c219a00b003c6f2597e30mr6524966wme.111.1666012673450; Mon, 17 Oct 2022 06:17:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u5-20020a5d5145000000b00232251d71c7sm8346266wrt.68.2022.10.17.06.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 06:17:52 -0700 (PDT) Message-Id: <367e44c6928a5f1f9dc31b2068cba1c91229c9eb.1666012665.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 17 Oct 2022 13:17:44 +0000 Subject: [PATCH v4 7/8] rebase --keep-base: imply --reapply-cherry-picks Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Denton Liu , Johannes Schindelin , Phillip Wood , Elijah Newren , Junio C Hamano , Jonathan Tan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood As --keep-base does not rebase the branch it is confusing if it removes commits that have been cherry-picked to the upstream branch. As --reapply-cherry-picks is not supported by the "apply" backend this commit ensures that cherry-picks are reapplied by forcing the upstream commit to match the onto commit unless --no-reapply-cherry-picks is given. Reported-by: Philippe Blain Signed-off-by: Phillip Wood --- Documentation/git-rebase.txt | 26 ++++++++++++++++---------- builtin/rebase.c | 16 +++++++++++++++- t/t3416-rebase-onto-threedots.sh | 21 +++++++++++++++++++++ 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index 080658c8710..ee6cdd56949 100644 --- a/Documentation/git-rebase.txt +++ b/Documentation/git-rebase.txt @@ -218,12 +218,14 @@ leave out at most one of A and B, in which case it defaults to HEAD. merge base of `` and ``. Running `git rebase --keep-base ` is equivalent to running - `git rebase --onto ... `. + `git rebase --reapply-cherry-picks --onto ... `. + This option is useful in the case where one is developing a feature on top of an upstream branch. While the feature is being worked on, the upstream branch may advance and it may not be the best idea to keep -rebasing on top of the upstream but to keep the base commit as-is. +rebasing on top of the upstream but to keep the base commit as-is. As +the base commit is unchanged this option implies `--reapply-cherry-picks` +to avoid losing commits. + Although both this option and `--fork-point` find the merge base between `` and ``, this option uses the merge base as the _starting @@ -278,7 +280,8 @@ See also INCOMPATIBLE OPTIONS below. Note that commits which start empty are kept (unless `--no-keep-empty` is specified), and commits which are clean cherry-picks (as determined by `git log --cherry-mark ...`) are detected and dropped as a -preliminary step (unless `--reapply-cherry-picks` is passed). +preliminary step (unless `--reapply-cherry-picks` or `--keep-base` is +passed). + See also INCOMPATIBLE OPTIONS below. @@ -311,13 +314,16 @@ See also INCOMPATIBLE OPTIONS below. upstream changes, the behavior towards them is controlled by the `--empty` flag.) + -By default (or if `--no-reapply-cherry-picks` is given), these commits -will be automatically dropped. Because this necessitates reading all -upstream commits, this can be expensive in repos with a large number -of upstream commits that need to be read. When using the 'merge' -backend, warnings will be issued for each dropped commit (unless -`--quiet` is given). Advice will also be issued unless -`advice.skippedCherryPicks` is set to false (see linkgit:git-config[1]). + +In the absence of `--keep-base` (or if `--no-reapply-cherry-picks` is +given), these commits will be automatically dropped. Because this +necessitates reading all upstream commits, this can be expensive in +repositories with a large number of upstream commits that need to be +read. When using the 'merge' backend, warnings will be issued for each +dropped commit (unless `--quiet` is given). Advice will also be issued +unless `advice.skippedCherryPicks` is set to false (see +linkgit:git-config[1]). + + `--reapply-cherry-picks` allows rebase to forgo reading all upstream commits, potentially improving performance. diff --git a/builtin/rebase.c b/builtin/rebase.c index 90ae8fd8de7..d718b7fe888 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1180,6 +1180,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0; + options.reapply_cherry_picks = -1; options.allow_empty_message = 1; git_config(rebase_config, &options); /* options.gpg_sign_opt will be either "-S" or NULL */ @@ -1239,6 +1240,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) if (options.root) die(_("options '%s' and '%s' cannot be used together"), "--keep-base", "--root"); } + /* + * --keep-base defaults to --reapply-cherry-picks to avoid losing + * commits when using this option. + */ + if (options.reapply_cherry_picks < 0) + options.reapply_cherry_picks = keep_base; if (options.root && options.fork_point > 0) die(_("options '%s' and '%s' cannot be used together"), "--root", "--fork-point"); @@ -1415,7 +1422,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) if (options.empty != EMPTY_UNSPECIFIED) imply_merge(&options, "--empty"); - if (options.reapply_cherry_picks) + /* + * --keep-base implements --reapply-cherry-picks by altering upstream so + * it works with both backends. + */ + if (options.reapply_cherry_picks && !keep_base) imply_merge(&options, "--reapply-cherry-picks"); if (gpg_sign) @@ -1681,6 +1692,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) fill_branch_base(&options, &branch_base); } + if (keep_base && options.reapply_cherry_picks) + options.upstream = options.onto; + if (options.fork_point > 0) options.restrict_revision = get_fork_point(options.upstream_name, options.orig_head); diff --git a/t/t3416-rebase-onto-threedots.sh b/t/t3416-rebase-onto-threedots.sh index 01eb9513d6c..ea501f2b42b 100755 --- a/t/t3416-rebase-onto-threedots.sh +++ b/t/t3416-rebase-onto-threedots.sh @@ -199,6 +199,27 @@ test_expect_success 'rebase --keep-base requires a single merge base' ' grep "need exactly one merge base with branch" err ' +test_expect_success 'rebase --keep-base keeps cherry picks' ' + git checkout -f -B main E && + git cherry-pick F && + ( + set_fake_editor && + EXPECT_COUNT=2 git rebase -i --keep-base HEAD G + ) && + test_cmp_rev HEAD G +' + +test_expect_success 'rebase --keep-base --no-reapply-cherry-picks' ' + git checkout -f -B main E && + git cherry-pick F && + ( + set_fake_editor && + EXPECT_COUNT=1 git rebase -i --keep-base \ + --no-reapply-cherry-picks HEAD G + ) && + test_cmp_rev HEAD^ C +' + # This must be the last test in this file test_expect_success '$EDITOR and friends are unchanged' ' test_editor_unchanged From patchwork Mon Oct 17 13:17:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13008869 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4E1DC433FE for ; Mon, 17 Oct 2022 13:18:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230241AbiJQNSS (ORCPT ); Mon, 17 Oct 2022 09:18:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230107AbiJQNSK (ORCPT ); Mon, 17 Oct 2022 09:18:10 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AF7B4D25B for ; Mon, 17 Oct 2022 06:17:56 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id bv10so18432204wrb.4 for ; Mon, 17 Oct 2022 06:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=TaHfzcKiw4cPzg+w4ZMcI22KFEYgkOy3WEfS5eM/jPw=; b=dFij8rOShyMEn/JKDVhUFGiHdjgAfNAexs3mZYlhZUXyvCmOIQFsNijKW48JJDKax5 Y9JdZdtNvA/L+O3VDpGJqsHJo6v5dczYFOCyzv9VDin6osQh8hlXqG/pEwjP3GuxSwmK 1HiM2aZW9BVTHHtLQwZzTIuPnNq4Za1I3wwtAyMEWezS7eJinDEBkkQpwXU+nmjFVvbb B6MfVeiPhbzYJxc1y2jXxZemneKfvoygAaIo2+pD+H6gBOFZcUshaX2SJUr/QfRPFPCT IcjPhTqUfYdCqbM/Vi50CJYi81onMz4i2MvrN8SBURLItVnXqdSmsLAJvskuiPm/tokZ O4Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=TaHfzcKiw4cPzg+w4ZMcI22KFEYgkOy3WEfS5eM/jPw=; b=aDw++ZxYeY8B+oaEYvdei0IzCpBrmsIGFrlajXYgcrSGBoH3D2DSjVcxWiXps4BJYJ oMCGu0u4/qAKjy7P+vy6SddIlltNMxcKMQH3he6DuHYf2lM3f48e8D+X3Y4q50n1qaCY aduPhc5CN5ymOiqlpq0jO8oRzLGveZB7NuWtZidrQ9Oa2rGtkHpgvPl3/X//NzKH43Vs TAMMZFeapGfmanLmir8q1djQV3oms9Qz2/+Fjgg0n5X6z9Rn4gUD9hgEPpYeGEmbzaix LNzLjzOxx0Tk5RU4W6glVYFR91VFvPBoHLMXNFHNh9HpWtPyd/tFxfcj2tmSlFBQ3mbl FSHQ== X-Gm-Message-State: ACrzQf063wPqm8+dgrR2gLf7q++U2nm84LPiPbvpdh/xww1Lu5JcIrWv PrS0c10lU82MLny91dMA8s/Qk6266H8= X-Google-Smtp-Source: AMsMyM7LvLrokXJjj0ggBmYiZG9PJ/WJFZA6QCkR6LOVUhk3d1j2SBhAWH8sABJguTLRxuHWww5vVg== X-Received: by 2002:a05:6000:1541:b0:231:115e:9bb8 with SMTP id 1-20020a056000154100b00231115e9bb8mr6615914wry.51.1666012674369; Mon, 17 Oct 2022 06:17:54 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h12-20020a05600c314c00b003c3d8a4e47asm10686262wmo.2.2022.10.17.06.17.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 06:17:53 -0700 (PDT) Message-Id: <656b9c9dab6f091f02008137f2da0f843882746b.1666012665.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 17 Oct 2022 13:17:45 +0000 Subject: [PATCH v4 8/8] rebase --keep-base: imply --no-fork-point Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Denton Liu , Johannes Schindelin , Phillip Wood , Elijah Newren , Junio C Hamano , Jonathan Tan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood Given the name of the option it is confusing if --keep-base actually changes the base of the branch without --fork-point being explicitly given on the command line. The combination of --keep-base with an explicit --fork-point is still supported even though --fork-point means we do not keep the same base if the upstream branch has been rewound. We do this in case anyone is relying on this behavior which is tested in t3431[1] [1] https://lore.kernel.org/git/20200715032014.GA10818@generichostname/ Signed-off-by: Phillip Wood --- Documentation/git-rebase.txt | 8 ++++---- builtin/rebase.c | 6 ++++++ t/t3431-rebase-fork-point.sh | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index ee6cdd56949..1e2d543ced9 100644 --- a/Documentation/git-rebase.txt +++ b/Documentation/git-rebase.txt @@ -218,7 +218,7 @@ leave out at most one of A and B, in which case it defaults to HEAD. merge base of `` and ``. Running `git rebase --keep-base ` is equivalent to running - `git rebase --reapply-cherry-picks --onto ... `. + `git rebase --reapply-cherry-picks --no-fork-point --onto ... `. + This option is useful in the case where one is developing a feature on top of an upstream branch. While the feature is being worked on, the @@ -452,9 +452,9 @@ When `--fork-point` is active, 'fork_point' will be used instead of ` command (see linkgit:git-merge-base[1]). If 'fork_point' ends up being empty, the `` will be used as a fallback. + -If `` is given on the command line, then the default is -`--no-fork-point`, otherwise the default is `--fork-point`. See also -`rebase.forkpoint` in linkgit:git-config[1]. +If `` or `--keep-base` is given on the command line, then +the default is `--no-fork-point`, otherwise the default is +`--fork-point`. See also `rebase.forkpoint` in linkgit:git-config[1]. + If your branch was based on `` but `` was rewound and your branch contains commits which were dropped, this option can be used diff --git a/builtin/rebase.c b/builtin/rebase.c index d718b7fe888..b9164a30bff 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1239,6 +1239,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) die(_("options '%s' and '%s' cannot be used together"), "--keep-base", "--onto"); if (options.root) die(_("options '%s' and '%s' cannot be used together"), "--keep-base", "--root"); + /* + * --keep-base defaults to --no-fork-point to keep the + * base the same. + */ + if (options.fork_point < 0) + options.fork_point = 0; } /* * --keep-base defaults to --reapply-cherry-picks to avoid losing diff --git a/t/t3431-rebase-fork-point.sh b/t/t3431-rebase-fork-point.sh index 1d0b15380ed..70e81363569 100755 --- a/t/t3431-rebase-fork-point.sh +++ b/t/t3431-rebase-fork-point.sh @@ -50,7 +50,7 @@ test_rebase () { test_rebase 'G F E D B A' test_rebase 'G F D B A' --onto D -test_rebase 'G F B A' --keep-base +test_rebase 'G F C B A' --keep-base test_rebase 'G F C E D B A' --no-fork-point test_rebase 'G F C D B A' --no-fork-point --onto D test_rebase 'G F C B A' --no-fork-point --keep-base