From patchwork Thu Oct 13 08:42:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13005745 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 AD978C433FE for ; Thu, 13 Oct 2022 08:42:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229734AbiJMImy (ORCPT ); Thu, 13 Oct 2022 04:42:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229569AbiJMImv (ORCPT ); Thu, 13 Oct 2022 04:42:51 -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 6E45F11C265 for ; Thu, 13 Oct 2022 01:42:50 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id j16so1715934wrh.5 for ; Thu, 13 Oct 2022 01:42: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=oXEoc6/5lUfAgWQpoF3mlId0HIU3GZEyBxBCSN9AC7I=; b=NVdrzN8aTu1iRuFM6kvuZ8GuIEcOe+d0abMW0on+riOVoeMPchsMy5UKmRWm1+az0N zs20O0HnGb8oFlAf4dPoRUxMqoZqsGYBwUk4eLqJPrP0Fpbi/iQ1VXIYxZn7aw3Yj39q tPzT0FmEUZTG+QZSTzrf1yONVqj5zHY/9LvJGIQljqv5eDPZuhxj70l6EH6VnAESokDI GT0IBimV2VLhl9t/inQ/J5RbD/TLwt1ZyOnRtPEVy7QF7BRSDPNil0KNe5PgJc72kKAW tgRABcdij6reatN6pVVFu1bThsb5xdCkT/4IT23DlEtoKtUlPl2BAzS4VNI2zBblyTfO wfqg== 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=Dc2CayvhLkfQv67eGHtrKBEJ+qhMLBry7ElmSBkLm3BmYLUIZEGNOiII8+Yj8JmYrN 2X0cbyz/Bnq/NfR3aFDs27hg5o4DYEX7fooeN3vUSoWeA5VjxKTW6l6K++dHoAVCmCqc MYhl2pRhJlvto2wiAmwyzYwawk3LeA7C/UFGtUAaNoTsbQS6Wf9wnIsEuIWtb26vdatu KetaH5ck+9pRHmpK9He9M9SarlmAZuyU6W3Sx36ByptZr2wG+HrUaO9hYu4HizbJLGl6 Ccx3pjIBtrqKOMU+WqhcdoL45Rjx31ghFrsdsZFHsaRNwfyzH0cYhnXi9tj9QvHtwS5i +nsw== X-Gm-Message-State: ACrzQf3k/lUVqINePZD0oNyt7eGhcCQs1KRNlRIZplPHNchnaf7jwI6v O3ZncHZflF6eWsV1INOMPpI7bmJqIbo= X-Google-Smtp-Source: AMsMyM6vyRYt+HjWWwauPX0UNXHzdF4C7eyDtqVkfxJtZpuxdfz9qrh4xy+QLWD/uePJC0r4lavc6g== X-Received: by 2002:a5d:55d0:0:b0:231:2304:3a6a with SMTP id i16-20020a5d55d0000000b0023123043a6amr9830030wrw.94.1665650568540; Thu, 13 Oct 2022 01:42:48 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g10-20020a5d488a000000b0022e6178bd84sm1550659wrq.8.2022.10.13.01.42.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 01:42:47 -0700 (PDT) Message-Id: <12fb0ac6d5d932f9a8685d803ed017c357182768.1665650564.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 13 Oct 2022 08:42:37 +0000 Subject: [PATCH v3 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 , 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 Thu Oct 13 08:42: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: 13005746 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 E9CDDC43219 for ; Thu, 13 Oct 2022 08:42:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229783AbiJMImz (ORCPT ); Thu, 13 Oct 2022 04:42:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229533AbiJMImx (ORCPT ); Thu, 13 Oct 2022 04:42:53 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4348411C245 for ; Thu, 13 Oct 2022 01:42:52 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id a3so1798004wrt.0 for ; Thu, 13 Oct 2022 01:42: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=7faw4EUCXSCyKuXe8/STylGCsukVPYq05BacxCx1390=; b=Gc9kemrMPSvLKJEIAOSqqREPI4ZdTB2IlRTDMgZKjIxzMXrNexO+qLbhyrVbT378WB +cpaUwFtWDLAS84cHMrWXIhksYkZA+RbPW22B2EOZBGbvLe+DvAvrEdjPRfmUvIR/sBE 7u4JV60aoRR0AqAXsW57Du44en4xR54zNGF+OYuzTKKE5qREySqWQKYWw12ZHzf6UQCS /DcAMq67zoUPjlfmHnR4S/Lfhjk4mDZsKiZ2o8+8RhJHLDGY+/Rv+EHj2OsNJH4Tb+ih 8NbHWMXcDogyo1HSXGbGY9wfZ50gugB+QY6Z6jHqhXGCv1yBe2gcZy7vaI2EsodPd2zs nWVg== 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=F8UCrHlNUrcNuJQ8VFhYZlZj9Rkbd+r8U2lRvGpxizyG5HZTOQoiOhEMhklMq7IYJN lGjcYTm6A+/xqMnQM/oQcK5cwYsrLUitGIOsGSh2ND+DIl/pOz8cZ2EjllMIJuEtCJDf nxh7KcG2zG70CZalMVFENF5V0GdDENAII9mNZVh5XTS5Lh+2hKEae8BK0M1Y1P1q1KYj p2KHliFQmdOMEwjwXlZFW9o+Gj3meKc8uyoo/Q1o5c6+XRwOGQbz8FzIeeer2n4E1AfJ ZPcn9X+w13ypz140W4dyJWGvSq4mUO4LiW+FFJ+tj7fMNNrNbkOlqSgSn8cFeE1Bm5F3 l37w== X-Gm-Message-State: ACrzQf1/WEma7CbIxtJQvPg97aJfPeqmIdpP8fEg/enBlTv6ZoB+Mfh9 wVpcRF8dLaY5kjGFdU1rcqnmgokiAwI= X-Google-Smtp-Source: AMsMyM532BCFBiS6z8EFqYSNzOoc09a2wLmAysKE/8U92UAAyR4ZQ0iRZ7VizZdBIw+dvoiSbz1AQw== X-Received: by 2002:adf:f00b:0:b0:22e:3439:cff2 with SMTP id j11-20020adff00b000000b0022e3439cff2mr21339826wro.719.1665650570643; Thu, 13 Oct 2022 01:42:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m16-20020a5d6250000000b0022da3977ec5sm1449533wrv.113.2022.10.13.01.42.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 01:42:49 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 13 Oct 2022 08:42:38 +0000 Subject: [PATCH v3 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 , 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 Thu Oct 13 08:42: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: 13005747 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 9027AC4332F for ; Thu, 13 Oct 2022 08:43:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229831AbiJMInE (ORCPT ); Thu, 13 Oct 2022 04:43:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbiJMImz (ORCPT ); Thu, 13 Oct 2022 04:42:55 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB04E11C265 for ; Thu, 13 Oct 2022 01:42:53 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id bp11so1691638wrb.9 for ; Thu, 13 Oct 2022 01:42:53 -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=DA638DpmCNs4fVsqrnUKB6t0csSxWofyQYcTp0QOw0s=; b=mm+ctdKOrji+s+aDnUBg7kyG6wk+yePOnyUP1g95mgq1I4TyKGftkPihkOHSM0Q5ht fFeGlibZGa6BJwzEPuSICDbaLxxfxjhSq0g0JA/ppL7g8uTiSxVGVMRlg4OJsEpHL98z PogkoRbjF3HWwwSb6OPjRY1ZR0ISxdosGi4WDEiIS7CbF/g6ARNW2Ski3XaidH330O7f vpDHCvFC9wj9QcSw4k79yiyLgW3lLRa1vQ/3CP8bpkkOJJRJVq6elXVIrIYCwUiLH8Hj /bj5CMaJD3+8+AeLuyp1bpx5FdT68hNlV6nWIXYOKfqdeXvacz4IUepy5IgHN5/jkfy8 6MYw== 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=DA638DpmCNs4fVsqrnUKB6t0csSxWofyQYcTp0QOw0s=; b=5gfpat4jiB20pfH+5gXYrenUdbPl/GAX4uplqrJw7HTJYgPCq1rylfpidNXLLd93ul +QaI/FciFP3yieRjPn8qvalKhTA6EMr63Lq0caI7jIfe4nmNhF1SDpF3Lbq2Q21RG75p FmJ0ekLNtpEmOrIpJ2BLj3jH2ADdaxT3U30nPwE1Pmmr8vXKsGet9tRBlyj8UtiwMRpt fYIK/ecWTTwyS3+vCur79Ll1auSfygzUOE5zvH6QWTXbYUKcs0XtfObxgsHL0G5NVO6J YnRY9OwuDdiJJCHLKPeWf/h+yKkMzh4ce9vlIlgFDIN3uxqCRTj7kDbssy619m/SZxX+ gPEw== X-Gm-Message-State: ACrzQf3719sTPjkt7s1puhR9Qq4yM5p+SVah01JbRmwK58OkucZjumBH zAX3KCydL8Ifi4oFjqB5Olugl5i1GR0= X-Google-Smtp-Source: AMsMyM4sQJxldR5ly6sDRctFroNmCcNK3zaEKjY5LByTszxKSOiC1GiC6efWQmsos+TvhsYV62tLSQ== X-Received: by 2002:a5d:59af:0:b0:22e:32be:60f1 with SMTP id p15-20020a5d59af000000b0022e32be60f1mr19877224wrr.81.1665650572056; Thu, 13 Oct 2022 01:42:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a14-20020a5d456e000000b0022ccae2fa62sm1554477wrc.22.2022.10.13.01.42.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 01:42:51 -0700 (PDT) Message-Id: <1fd58520253420fbe870a8528540dbc9e2178e3f.1665650564.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 13 Oct 2022 08:42:39 +0000 Subject: [PATCH v3 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 , 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. Suggested-by: Junio C Hamano Signed-off-by: Phillip Wood --- builtin/rebase.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 56e4214b441..76f83a42f49 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -431,7 +431,7 @@ 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)) + if (get_oid_hex(buf.buf, &oid)) return error(_("could not get 'onto': '%s'"), buf.buf); opts->onto = lookup_commit_or_die(&oid, buf.buf); @@ -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))) From patchwork Thu Oct 13 08:42: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: 13005748 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 7BCFEC4332F for ; Thu, 13 Oct 2022 08:43:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229861AbiJMInH (ORCPT ); Thu, 13 Oct 2022 04:43:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229533AbiJMIm5 (ORCPT ); Thu, 13 Oct 2022 04:42:57 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D78C14BB79 for ; Thu, 13 Oct 2022 01:42:55 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id c3-20020a1c3503000000b003bd21e3dd7aso2752185wma.1 for ; Thu, 13 Oct 2022 01:42: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=pA+ksGgWHi9wkjUhFVrYzCvmnDpHFT71ffrPZEbDo/8=; b=R9CspTBJSetxDmVA4ED+lDSpft4+ol96ut+hPvCJYcfXee8GpT8ru2OUPnYMU1YBBv QtU28lMYgx8osQigJqsctV8mEg+87aziKl/egAJD79VolXAQXXOVv7Yo57MsNR6O/Z6m qig8Es/sF/qmlOEqmA1Cmlhbx3sNdQA5jYUY2WHNLfbQKzRRJJ4KHRI4uETzAzbBzISR u4W2+xWQRxXoc2u7B9tHI7RGIEpa2/3gS82MbLnS1xSBrit+f9/6ONF9LceAe5nVasmi 0KBppatsFu0r5dImHeD8x7k2q/QP/ranj7zWlTlr/w49JqO69hov5DHiNNjaouLqHJxT aX4Q== 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=pA+ksGgWHi9wkjUhFVrYzCvmnDpHFT71ffrPZEbDo/8=; b=AAJiD5gRh3fJnE8p92EpCMSVJJ81iNG//X9REyRE5hDZj9oxNFE0tQwgvY980VZgjw 419tXZ8sCSjqWDTFBFgajNRbUAWnCqNDsfZgRIWvZQE4Vr6R3iJjl8GqQkgOTSr4tJE9 CJ5s+4NpMEVQNxUM6DxlQmoJ41MubfrDIp+E+cPZ0VmBMQez2lmGveBWDA4FBfMIyZcu vtef/FIvVjgZwpKZLAQfbdzEX5KPY+DizZr/JMftpYzCxai8xUBQCnnw6koNdgUrqwxa aXTPFiDgyJlYQlPRd11uipTetrgWN68+ho43wkO46qZW3qypK0sMeB7gYhkuZIuyqIaG RA1Q== X-Gm-Message-State: ACrzQf0N0fZaub6eC0FBzP1bnFdtR6vUJjEeMCesSsUJA3Fz/tdT4CGT WR6vW0TOBINm78shS1MTsK40urSzuNk= X-Google-Smtp-Source: AMsMyM5KruYXsxLedXkM+ydfXcF/B3q0BRPAUGp0oezIYF3Nsiwb2g7kErmNlkzBcHHLCdZYHwjp7w== X-Received: by 2002:a05:600c:4194:b0:3c3:d0ed:2d44 with SMTP id p20-20020a05600c419400b003c3d0ed2d44mr5770535wmh.151.1665650573296; Thu, 13 Oct 2022 01:42:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g17-20020a05600c001100b003c6bbe910fdsm4581653wmc.9.2022.10.13.01.42.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 01:42:52 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 13 Oct 2022 08:42:40 +0000 Subject: [PATCH v3 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 , 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_reference() on the oid returned by that rather than calling lookup_commit_reference_by_name() which applies the ref dwim rules to its argument. lookup_commit_reference() will dereference tag objects but we do not expect the branch being rebased to be pointing to a tag object. 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 76f83a42f49..7e6ce374c59 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_reference(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_reference(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 Thu Oct 13 08:42: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: 13005750 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 E2F82C433FE for ; Thu, 13 Oct 2022 08:43:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229863AbiJMInQ (ORCPT ); Thu, 13 Oct 2022 04:43:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbiJMInF (ORCPT ); Thu, 13 Oct 2022 04:43:05 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9224415DB0C for ; Thu, 13 Oct 2022 01:42:57 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id bv10so1722140wrb.4 for ; Thu, 13 Oct 2022 01:42:57 -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=cXRpK3Gmha71w1nQdeXTUYi8vteYdTPfLiPwPdRDtkY=; b=RxtjCYJa1n+RSsvF8YjNigJg6Bgce2tUip94+jbXAzNHq4fBChrV501zsqN3+oep5M 2lV8FJp+tzfwpuOKdbbxiHrcHkzbyj3UAo8+fr8zSwEgVuAxmiI7YlFh1ZD1h70/xcN/ N3wLxNa3f20UGZwJis9F4A0F0gz9zyVHxstk8dd45CADEHIA7Dkv2CqyuLGGJfYRW7fT NM3yVo5Tr9FVSwXNBhEsj/VDggxcLN78oSrQyDF2nlOdzAdjWb6S4mC41jmvYo5sAn/S 0y3LNNtSpeRhfxgXMlBZ5ESYREgLhLXMAG28817NLwrDrvwwnqb/Ho0MScmDqL07fuEY c83g== 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=cXRpK3Gmha71w1nQdeXTUYi8vteYdTPfLiPwPdRDtkY=; b=1OIiiEjfwPZZ8vttC1QIdZuihi3azPDdw+R8wMnPkd2hFa4ScjeOZb6BwnRh4n1fCX 4/FtF7sYExq437ohC+h5nvCR2I7FDGScIZMzF4G55mvJYGjIXm6YHsqNa+tu4X09VjdO OhfbhVJ2GX5J8QEucJjd//4S+1ZfSfC1/7Ny+9x+FVo7sBx9WHSCUTOW/0xoijGY1PpO IIH0HIA6Z6jV4+lJsA4xQyz6zPY9nscTlHn9HK3+7rLs9OMhOHH/1aE7YTL0zXQ3VQvI b98jSeH8r/A6LCFu3UTobeKHOXEr6UK9flBXUkTvAgc31pH+kzQFQykoYOX3QQWF2lNp alTA== X-Gm-Message-State: ACrzQf1lGEFSIAQ91SdZ3KTlzFVc1coSbHOVIC9dSWXW0Z/a7XK6cVeM aTUcJdSSFfQOsfSerk7gH0QiFK9A0R4= X-Google-Smtp-Source: AMsMyM5h1KZLeJcklU6e2VKc4TmXGqb/F55ZZzz0wpatkmA5QRiz8eVgNmIcTvZKDhCueBpCVELV/A== X-Received: by 2002:adf:ea08:0:b0:22e:46e9:2a8a with SMTP id q8-20020adfea08000000b0022e46e92a8amr21182876wrm.636.1665650575087; Thu, 13 Oct 2022 01:42:55 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l15-20020a05600c4f0f00b003c6cc57566fsm2616169wmq.14.2022.10.13.01.42.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 01:42:54 -0700 (PDT) Message-Id: <00f70c9034452bd87c82fb3aea9658aec32f2ec1.1665650564.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 13 Oct 2022 08:42:41 +0000 Subject: [PATCH v3 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 , 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 7e6ce374c59..cbafcc41e75 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 Thu Oct 13 08:42: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: 13005749 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 56658C4332F for ; Thu, 13 Oct 2022 08:43:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229891AbiJMInP (ORCPT ); Thu, 13 Oct 2022 04:43:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229833AbiJMInG (ORCPT ); Thu, 13 Oct 2022 04:43:06 -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 1E9CF11C6ED for ; Thu, 13 Oct 2022 01:42:58 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id n12so1688454wrp.10 for ; Thu, 13 Oct 2022 01:42:58 -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=CFDOCyxyF67ldTK6/Jhw0peKx3GN9J1CiKuwn/CaeXk=; b=ECCvJqZaF0PKNEcPstjmbc7qTs654TNxwYIqHiR0RhNWD+UhO0+risk0XwDhjbNMo8 ODoi8Nmz22Rucjsc/jXBlQO0tFjVnavudK/HS12vs+9RAoKkoSI5caMK7q2aWQ88O6PF yKuqsWkXXSwGKF7NB+SkM8MO/bwsbZK/Ff9Gmk0KY2F6AfxFSWD3BZ9U5Lm6JvtjN6Bj xtvS1fdxN2Fc5VnvlqizXmmdZ+ZqXjrlcGhu1zjUu4v73NmYTAx6fo9nW/T3HRi5cpA7 TTqKCJz1qczRPUs2/iMFdEwaZ/o1Xor9a0VIzVJDLAt04l7t3r7kGZ2iOrDb2EqDMYOL hayQ== 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=CFDOCyxyF67ldTK6/Jhw0peKx3GN9J1CiKuwn/CaeXk=; b=kbB4RWuBgkXkHmy2xjUB0uSiXrNratx+hTc1DobWpZqlnD4B+rCkj5qvdj5jdFil8r x7Mwa7nWRHkeBWm3/1LB+vDxrj6BDkYhGc9bX5Wg798ubsnZ8dOfazQsMb/ZRyE6TTbd ZpvGB0msHr9nFejq3NHGLGAd7IMZznW3XgR8xqVLKgI62WYoMAQNPpMBS73CYyphwhm+ PCMWKhGsxnLF1VlOMH14Sv3tRjsxbibaQBlHwoyW7O3cYEoFC+JQ22eK36Ic72N35rUn e/lS7xldQlC9UU+dsREeAKOWGZu8/oIUCMQJOnMamqUKV51r7mBQFZFynWJvekAAtxls OYgw== X-Gm-Message-State: ACrzQf2QP+UTBNe4zNv3hVCCU+XhBoyDtZzdunwofATNET1AV+VMLMK5 f29F4aN4EmamD+mlTNSo2774SAp8rp8= X-Google-Smtp-Source: AMsMyM55KfVDIUnVfFYWgkHpo9rYRK6bW/BJVjPWDjiSg1u2E9YZ0E17QjHxh7Z9tpdRuXcaOxwCmA== X-Received: by 2002:a5d:5149:0:b0:22e:8b85:3d7d with SMTP id u9-20020a5d5149000000b0022e8b853d7dmr19954122wrt.55.1665650577143; Thu, 13 Oct 2022 01:42:57 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x16-20020a5d4450000000b0021e51c039c5sm1494573wrr.80.2022.10.13.01.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 01:42:55 -0700 (PDT) Message-Id: <2efbfc94187d9f0968e5b670c9152651cd8f1a5b.1665650564.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 13 Oct 2022 08:42:42 +0000 Subject: [PATCH v3 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 , 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 | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index cbafcc41e75..40619a0fb2d 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,8 +1678,8 @@ 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) options.restrict_revision = get_fork_point(options.upstream_name, options.orig_head); @@ -1698,13 +1707,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 Thu Oct 13 08:42: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: 13005751 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 99BA3C4332F for ; Thu, 13 Oct 2022 08:43:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229827AbiJMInS (ORCPT ); Thu, 13 Oct 2022 04:43:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbiJMInM (ORCPT ); Thu, 13 Oct 2022 04:43:12 -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 0FE6515DB09 for ; Thu, 13 Oct 2022 01:43:01 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id c7-20020a05600c0ac700b003c6cad86f38so2753366wmr.2 for ; Thu, 13 Oct 2022 01:43:01 -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=8tvwW88syw1NkbCQIQuKP34ysRi4o+mgY6z7gc+Y9Yk=; b=TC2SsN146LKbu2BOr/ugMbC7LVYQ2W1aJoUtQL7kb9+yKn2pX7ZiGXGb9YSiEdsB7G kMq42WPm9v/UDDImMDwTicDfQgebFi/s+0JrAYL4EvCMhYAwYws57XqHPIkMiNLDHpM+ AcXGR1zecgBbefx46DMHmhKDOkTtzhMHyaJyRvXnXjkSOaUKIX/Rdcm1M2zpW9R/0POG 2Q0gW4I/ZGTfjYPpcBLkrjUddYM56XrBtsd1M+HvRWyuQB98oVH60Z/hLul7E3BLbjmc YLRMZljtiHgS10grAIH82FhU0QO5VWuYpQ3j7zWtLITqs7dClwummlsVHLtSCV+wYSla CJZg== 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=8tvwW88syw1NkbCQIQuKP34ysRi4o+mgY6z7gc+Y9Yk=; b=uMu9JnkPbjCS8yBE0Wif/KO7OZNd8AmktZLL8MqkXugL9nsn0cHUEA2kxahvIHO0Te SR6GLpgFA4kY9nWzHO4YCgHRf/1FtGH7vHi0A2aErFRkLLFrEyDg2xPx7AJI6JEideQg MapnJca8y4Px8UDqRKggMFDw7VtDTk39HIAhVz+DtJpsGcq7D4YnOtzkoEUPModkUJZJ 1JCx7LcVWlgJRg7piSB0+tUcDm0MHNsLv4kZDmDNs2sErgXrF/yLyL+/IYahOW40gReE /i56qvxvWaRHYagZa0JphLocf5Y3v01CbR0FXY1qkZZojZRVwCpV89yTj53ScYYAc+a4 Zjjw== X-Gm-Message-State: ACrzQf3ObpKCVmKvR0iPq7woXbUhBw2hpsb6/6/sv1j+ndBpm/gusN/y PVzb+enNV4ucpshPQIW5+7N9OV+E/2k= X-Google-Smtp-Source: AMsMyM4fYuEYOmYcnNtBI2t/PihWbxc1gS87ASTXNg2UFgdubix9qBV4P8rwI2WF15iTgonpKJWvcg== X-Received: by 2002:a05:600c:4f8d:b0:3b4:9f2f:4311 with SMTP id n13-20020a05600c4f8d00b003b49f2f4311mr5471758wmq.17.1665650579662; Thu, 13 Oct 2022 01:42:59 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n37-20020a05600c502500b003b3307fb98fsm4056232wmr.24.2022.10.13.01.42.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 01:42:58 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 13 Oct 2022 08:42:43 +0000 Subject: [PATCH v3 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 , 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 40619a0fb2d..ecc965c8586 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) @@ -1680,6 +1691,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.onto_name); 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 Thu Oct 13 08:42: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: 13005752 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 814DAC43217 for ; Thu, 13 Oct 2022 08:43:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229873AbiJMInU (ORCPT ); Thu, 13 Oct 2022 04:43:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229875AbiJMInN (ORCPT ); Thu, 13 Oct 2022 04:43:13 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80F0D15DB37 for ; Thu, 13 Oct 2022 01:43:03 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id r13so1679073wrj.11 for ; Thu, 13 Oct 2022 01:43:03 -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=8c9p6wva0W7FqIhQJnIwqTZ3rUpQZJ2jSX0hmUXze58=; b=AkGYFCN8LCNDs5Hio/zMKVeMlxzq5TnUvByqASPrQGlrGdXHuKZbr6cLTjkrDM7DMg UbA2jh7yx8O8p3qe794+nTE/vqmQPRrYYyRboHOA7Hd9F4Ik3tmEuZXV0AmkohYX06gt 49morilJs7ao4rzw0MUS7zm1p21zaXXcu0gRrTkoZ7m+fumdyBdbyfibSZi8Dpe6hi0s oL7vJtdSi//4yiy/H/vC/2u+6Su+59sfaz4BQWR5OMwzB4K6xxRg0CLgLVMeNOLJhE62 5ikmy33EJFBOIwTNA6QjMKp244f9iqZkWWkOLVhV0sbTfwrkwoSrgPH3sokcgEzgKD67 qEgQ== 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=8c9p6wva0W7FqIhQJnIwqTZ3rUpQZJ2jSX0hmUXze58=; b=36hPA515YFaXqqD5zTYMWLUeSS87eK7rqCL+hUUSef8RwowhCABBXWvgCozmW/6gfa 6oXkvmex5+dglyKPFBe0Ya10zgfZpIF/8ZX3DK7ZQ1wHpoZTh2fPk3GbdrnKLd8wlU4c j3nXQqTvmrDjwAfmz2rHOuzrzU1tYimN0Wq/fQJn4Trjp9UbgxI05Ax6DZEt4Wt7jr3N mnqM/B6rPUw+Rdy3X8CXF4WJxc3vo/AHcs//uYhwcr8qb+uOSZVWvTjIDwluCt80OORC trfIkZOkg0WKQ46WU38nbx0DsRWzkH7e5kn95nhG0FQp9RTx5Bq+D/+NcBlWuevli7nE KrWA== X-Gm-Message-State: ACrzQf3wO5sp/9XO5+bsDFXluidc1vgjvoCLPNjl8DLUXoVSUfL+Ktrt mwWrWwqEUnRDF7pquRB87mXoflIanTQ= X-Google-Smtp-Source: AMsMyM7PVjbu4fe/zvliqQOZwddSAqLXlibyl7P+Fb2bEOddsyBKvZ4Wrmlpakxoth83/lGqmNGm7Q== X-Received: by 2002:a05:6000:1845:b0:22f:bfca:6439 with SMTP id c5-20020a056000184500b0022fbfca6439mr15066383wri.298.1665650581152; Thu, 13 Oct 2022 01:43:01 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i16-20020adffc10000000b0022ed6ff3a96sm1477722wrr.39.2022.10.13.01.43.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 01:43:00 -0700 (PDT) Message-Id: <4d0226e1dcc778ce310f956546e6c18c7d3f4d4b.1665650564.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 13 Oct 2022 08:42:44 +0000 Subject: [PATCH v3 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 , 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 ecc965c8586..df8f7a8a5db 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