From patchwork Wed Sep 7 14:37: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: 12969057 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 8501AC6FA86 for ; Wed, 7 Sep 2022 14:38:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229671AbiIGOh7 (ORCPT ); Wed, 7 Sep 2022 10:37:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbiIGOh4 (ORCPT ); Wed, 7 Sep 2022 10:37:56 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A0807755C for ; Wed, 7 Sep 2022 07:37:55 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id bq9so7809282wrb.4 for ; Wed, 07 Sep 2022 07:37: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; bh=oXEoc6/5lUfAgWQpoF3mlId0HIU3GZEyBxBCSN9AC7I=; b=nvToeB2U2YA9UuO/YrxK72C4OourEmNtgNOQDtmHItpaPejKgLHaFiTWKEnqabRqt/ Pok29Pq+zsT4HVY/jJ67MqGDIFWpz9khVU2gtVm4O0AAvrMoeDesYspgAKm5vWMW1iT9 pMKWrddRFgmFie4IO/Uqy/Yd2TUAIXdR0zkvoPLBAS0oLDML/aiqiFXW9JX+PZp/dsvH t0Uh6jR+19k2SRV06ESG0ikIa4hIsvyqaesOAWNlwn5W7XqLqJmh9TBFHivaBZnBxNor PwwnMJo8ncfPW+rE8/j6IT/V8LysauX/g+rNmCBk8UGxIeDcypcev2eteQNlBny/Jq7b W3ZA== 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; bh=oXEoc6/5lUfAgWQpoF3mlId0HIU3GZEyBxBCSN9AC7I=; b=ROEtm31DfR8C80l0nBZ0zZbGdaY3wei/0o3RvLOCdcqcZ60FXO3VRoHwny9wjWdre+ E3vy5+3cO2MEomz0kb1OOBU9MO6EksFVFa1S6v0S9EKhmuCOtsDvDrzsAfE4pEs3x7UP qeJrZuXf/CDQ5XFEpKgaShwhFRrFAgYnVknaSqd7c2LPfFHAOOAlpj+mlw/aUIt5sRGK fOuE/mRDX7Yo14r+0IwZoDx1Z9d4zdmCQIaVpE5jCvctrSaBInni0jPpz8Mm1XASqiIf cpLSe2KBssWTLpDPkkBtYCok5bWaJQe6j6/Gfxn5o4rgYV1RDFBh0JPAKT+nyYcBJPpx bFYg== X-Gm-Message-State: ACgBeo0gKInuZB+AlD1QscOLYkHj3RctkjJqBnFIek3IZcnfTTzQyzY4 R00gVkhqgctMYf23BqF7krkzULt34Zs= X-Google-Smtp-Source: AA6agR52Z4NCeHvSGVUFgFwiR9gkalr+QsRo0ceZ2gMihQ3cwJ862nWvwbhNG5RzTLpdreuRjGC2rg== X-Received: by 2002:a5d:6388:0:b0:228:c792:aabe with SMTP id p8-20020a5d6388000000b00228c792aabemr2268863wru.689.1662561473606; Wed, 07 Sep 2022 07:37:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id bt24-20020a056000081800b0022377df817fsm18059192wrb.58.2022.09.07.07.37.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 07:37:52 -0700 (PDT) Message-Id: <12fb0ac6d5d932f9a8685d803ed017c357182768.1662561470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 07 Sep 2022 14:37:44 +0000 Subject: [PATCH v2 1/7] 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 Wed Sep 7 14:37: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: 12969058 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 0A8A1C54EE9 for ; Wed, 7 Sep 2022 14:38:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229603AbiIGOiD (ORCPT ); Wed, 7 Sep 2022 10:38:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229637AbiIGOh6 (ORCPT ); Wed, 7 Sep 2022 10:37:58 -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 D11F57697E for ; Wed, 7 Sep 2022 07:37:56 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id e20so20687038wri.13 for ; Wed, 07 Sep 2022 07:37: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; bh=7faw4EUCXSCyKuXe8/STylGCsukVPYq05BacxCx1390=; b=G3OLmWDCfCxJlg0OWgG2Cy81Hz+/s9c27v9c9GZ5qyfeXPqJDzKhyabACXgppMV6Ow 0DI0MIyte8tZkiJ25C2+G0s1ApJ2VVJfWtmOZIqEyHJFD5olr/31srxeeZMCGKLDs7l1 NRVJU7WDRbMAveRHRfX0WZpCZ2TTummtcIpXim+XFiP/UuHTVwB7nKHdQG+NIzF1bnph xCMPmZd6pnqr+dKHQ54SB95SWaB4lWXrqwDrnCvVuKBkw///zmQHnwl/ZJ3PlXkRzBpk naKw8X7SQteqV7xtA2/eGX0SKVugqTw9ZbQvNYgDU1SrC8tjnrrCUomORN5v8VA9yfWf bOvg== 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; bh=7faw4EUCXSCyKuXe8/STylGCsukVPYq05BacxCx1390=; b=AvfvMKPO/EYkSLbNnB0AHkRvURkOzv+qqzmg4tQNhn3JZRPFoLmLh3P3VGgxJxhaH1 QchMRsviiqigecZSloRs4pGIDW42UYXOsFVf15mH2kBFliNUcZhIc0tMp5IJmvODutzn hbKnSF8ovx5PfLgqhvi0/k6TuMHgTBmYnSsWWkqgd6G8VIduJQjB3lSwo7AwDbIy7pOD ZJWC6OZeRFzAIcA9liz/n9QEtuzaDxaMVHEXfmBSCHiRDYFskkQL+vzU/YPXOBj6810J VLr5Ggv15No2b8qOdBnIjQuM1C1YiH4vKEaBm4uvdEDero7b7ltPTX5dJo5I8rjhsuJ/ BL1Q== X-Gm-Message-State: ACgBeo3ibflprG+9+Og/6H7+O7A0wrGErhLX3rAcE1e6l9CMqfn/wqEE QmZrerk9BfCL3OsHRJE8OAkdgk6tThE= X-Google-Smtp-Source: AA6agR4uxz2U6frj6TDNZDyw5SHNfN5IhT/FERgAoXkK+nla1UsrA23ZBOVWH3eD+2Zg9lEugbyBbw== X-Received: by 2002:adf:d088:0:b0:228:a789:ce1f with SMTP id y8-20020adfd088000000b00228a789ce1fmr2245625wrh.461.1662561475134; Wed, 07 Sep 2022 07:37:55 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d13-20020a05600c3acd00b003a643ac2b08sm18388607wms.8.2022.09.07.07.37.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 07:37:54 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 07 Sep 2022 14:37:45 +0000 Subject: [PATCH v2 2/7] 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 Wed Sep 7 14:37:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12969059 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 40CAFC6FA89 for ; Wed, 7 Sep 2022 14:38:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229876AbiIGOiK (ORCPT ); Wed, 7 Sep 2022 10:38:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229677AbiIGOh7 (ORCPT ); Wed, 7 Sep 2022 10:37:59 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4043E7755C for ; Wed, 7 Sep 2022 07:37:58 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id d12-20020a05600c34cc00b003a83d20812fso9666258wmq.1 for ; Wed, 07 Sep 2022 07:37: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; bh=l85nBnlGEJZ7I0Tetme70BjmV9LBB9ZHP/7uw8NOMII=; b=YnFBaTlCYlL/hb9d56G+qZIW3T3kzs3FidcsYkFZZs2ZXfiJ02kAoUVmM+h8Y4tDXm Jf71Kr11TQBtI/1ZrpTIQ+mbDSxxU9XC+ntdl7tLBCpbVBM+F2JsyiKdtiOB0KuQ1Gt0 U4Lih0q2cugIHmBj75t+Ygxlkl+gRSiVXDNoOkNUYnbEVlPvyoi1lNd8V6pY7CCLFdsI 8fxs+O4T/OLvV9cHWXQzSA8cVD50W7Cl0cPumUU4Ta1jR8DIiDdaS10phpx46HKVk3Rv /SQC+c7oSR0FG0BXhSXDJKIClT2vmRDn8ZomYQXaWM+h534j38N9DJnKcCuaFge44FBu CE6Q== 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; bh=l85nBnlGEJZ7I0Tetme70BjmV9LBB9ZHP/7uw8NOMII=; b=aqbTDMBUtjv17RtLgcEQGXisKj0sgWFSu0cgQXt8aL2nRnHwGfGcod5UPXNfG9Wq1w Mi89nr1Ah0VtQm2li9nr/fim8Ve9iePiC1QNUBxfRSyKVzbLcXCQPf9w9wqaxRZf3ivs Kfhh/D9PeZ0jF6o2uK9V93+gee3WUcCQKyhynVVbTjdLyLIGc1QwY4LKIqTiV+VR4cZq gF5mQsPKP5dVjhcdpF8Oz6P9Y/oWHx60RkXALdwAiuJIAL5jceyF/+oOMXozYojxodNY rDFbw+BrWnnqmWv94i9xr+8Mh2Tow50tYCSBe4Q/Rs0FjhyuIQc9Iw8QcADR15iUDe7o jGkQ== X-Gm-Message-State: ACgBeo3qMj/MauFWhcUhyRJ2zaNHa+1rVz8/t/g1PSVKGzriI8xU39Xf b/2x+zD59hOhhRM160ReKUeivF6SzIM= X-Google-Smtp-Source: AA6agR4L9G9eRWF8K1flh+qihde/FSRmoKTJhC6cJkgytk0Tg0usaKf+FA1NH429qCj0RZcqawFSsA== X-Received: by 2002:a05:600c:582:b0:3a5:4f7b:3146 with SMTP id o2-20020a05600c058200b003a54f7b3146mr2267162wmd.152.1662561476523; Wed, 07 Sep 2022 07:37:56 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n30-20020a05600c501e00b003a61306d79dsm22555320wmr.41.2022.09.07.07.37.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 07:37:55 -0700 (PDT) Message-Id: <9daee95d434155742dbb19271eea8c0bc05eb365.1662561470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 07 Sep 2022 14:37:46 +0000 Subject: [PATCH v2 3/7] 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. Signed-off-by: Phillip Wood --- builtin/rebase.c | 61 +++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 56e4214b441..a3cf1ef5923 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(buf.buf, &opts->orig_head)) + opts->orig_head = lookup_commit_reference_by_name(buf.buf); + if (!opts->orig_head) 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; @@ -1610,17 +1606,17 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) /* Is it a local branch? */ strbuf_reset(&buf); strbuf_addf(&buf, "refs/heads/%s", branch_name); - if (!read_ref(buf.buf, &options.orig_head)) { + options.orig_head = lookup_commit_reference_by_name(buf.buf); + if (options.orig_head) { die_if_checked_out(buf.buf, 1); options.head_name = xstrdup(buf.buf); /* 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) + if (!options.orig_head) die(_("no such branch/commit '%s'"), branch_name); - oidcpy(&options.orig_head, &commit->object.oid); options.head_name = NULL; } } else if (argc == 0) { @@ -1639,8 +1635,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 +1669,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 +1701,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 +1778,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 +1792,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 +1813,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 Wed Sep 7 14:37:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12969061 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 46AE1C38145 for ; Wed, 7 Sep 2022 14:38:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229697AbiIGOiP (ORCPT ); Wed, 7 Sep 2022 10:38:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229736AbiIGOiC (ORCPT ); Wed, 7 Sep 2022 10:38:02 -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 C93BC796BA for ; Wed, 7 Sep 2022 07:37:59 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id bp20so20235379wrb.9 for ; Wed, 07 Sep 2022 07:37:59 -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; bh=Q6ItcPI6xHP71TlY+fYKLbGe9zwtY+Rr4iUmMfLEpzg=; b=XP/IBG9CLkxbTV+VIvBxKkxQ7iejv7IID4FAy0j2EbtpHq5cOACYcp0NC3b2i1IAkY EGALY3/T2d4lixVItGeg6YII8ZHMeF2UFd1Fv6HcB5s4L9IVlD+TKVXu4kqkf6bj1uLU Aia7zrpssHrm8MBQ9ouz8g0rL2bCm7GoJSm2NvM+jjYtraCf8XQOfEJ0UROeDXfXdLI/ Pwel77h/r3UPVu8mATtKeAPqqtzY5DLgLEdK0bgycqdu9sJIGf9g4g6Q2NO+C7gqrTyu UVEK6DHkVhFhA/FFR7X7VKKiXC3xYBt0lVQ5/YI5jh6mb2Rm7tb3SoE/YynRN4co68l2 YNxQ== 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; bh=Q6ItcPI6xHP71TlY+fYKLbGe9zwtY+Rr4iUmMfLEpzg=; b=49Iy/31siDtlgwbWBlKC0Z9/jRY+5lrV7wJjRmECRDfBRm3sLbI5i4kF0JBTw3eziT d1HC7A1jqw3wO7fL7fPKUkBt8v/bBOSP9KuC9EyVyI6r2iU8SGHFrcL/Y4K/W21+KBt5 RqtdCxx8ySBTxj+U8UoPVHQkHUK8tfO4QMMbQDvNrsVMXTvfpJoBUVhuci9ocqcdxQ2a qGruWnAqR0qghFVUDpgh50BlqwQ3UsENxzRfuxv4Ki3rDqqgPaVKwzSaWWgerVSeLx/b 4eJivofJlRm6cGewBsqw9eweGY7hCJd8xoO2TFyUho41DuU66/K8xSlwCfr1jbZtoh4o algQ== X-Gm-Message-State: ACgBeo2R0vk4Yep+dMdfZ0px3ORvTYMcsKjk1m+9EOsL2vkYpKJRWoNL BA492dscgZckhzKNghhxoM//s0q7Nrg= X-Google-Smtp-Source: AA6agR4IElyOoTgTulJUGqT5Yp7YNCJGBAsTUwwWsiHhBJOeNhOzBfICtNCWh+oEH0h0JkIH+mVV1w== X-Received: by 2002:a5d:65ce:0:b0:228:d8b6:d1 with SMTP id e14-20020a5d65ce000000b00228d8b600d1mr2314484wrw.486.1662561478022; Wed, 07 Sep 2022 07:37:58 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l10-20020a1ced0a000000b003a8436e2a94sm18903022wmh.16.2022.09.07.07.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 07:37:57 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 07 Sep 2022 14:37:47 +0000 Subject: [PATCH v2 4/7] 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 a3cf1ef5923..dd5e0e1feb6 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; @@ -1651,7 +1651,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); @@ -1659,7 +1659,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 = @@ -1697,11 +1697,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; @@ -1743,12 +1743,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)); } @@ -1760,8 +1760,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); @@ -1792,7 +1792,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 Wed Sep 7 14:37:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12969060 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 B6F7EC6FA86 for ; Wed, 7 Sep 2022 14:38:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229754AbiIGOiL (ORCPT ); Wed, 7 Sep 2022 10:38:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229697AbiIGOiC (ORCPT ); Wed, 7 Sep 2022 10:38:02 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C836C72B61 for ; Wed, 7 Sep 2022 07:38:00 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id m17-20020a7bce11000000b003a5bedec07bso11996724wmc.0 for ; Wed, 07 Sep 2022 07:38:00 -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; bh=2yzHLcjtuvUxrHTA/UZk5taVZwKLdxBxKR7daGtKpEY=; b=qE6z14NORsLGmfSohxfZ+tBHzWG0n4noKudk8UunLQGnRuDC9g8yb5mCynFyN+DOsW LlgXVx58gmT+nM4P3hAwt+YzRyXyicB9pJpFuWD9RAHB0abNMe05pNcFJzfkpiLI8G3y kj/tk5FmI5dZGMUGRWtnEWcuUlSqytUODkgqB+dlA7fW9EiwMI4BV92/p60twvksfrUk mheUanjyiT5ygyjoQLKzMj1VCQzWwmUblYglk9Ii9F51yYk+P66K1kKCG6gGCrdnBvbw L6fQ019z022nBim20hjxkPK54GdoFAMcrSHsW8lNDFkFex6xPrO2/iMEt4d6gW89tvv1 k0/w== 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; bh=2yzHLcjtuvUxrHTA/UZk5taVZwKLdxBxKR7daGtKpEY=; b=Xsqr1l9JZWY5WlFQifw4DlkFrLDwkxU7WjB76xBCm0gksMcOvg8tqDrbMsLs1gxCPH WnS54sAAWE7fARfbH4eRwvFQFkC9uEYdgv8mIz5SxHWu6eXqK7ZItCvQZ9+tWmLHV66K 8q+SyKMG9BaDQw+Z2pIAhl1oWTQ1dcexIPwC12/utSoZ7WZcbF+XxM6IGkdgd2YcAveB nQ+B+rCzYXN4Fo41swySovy7qkpPl9yKxI13RQpiKci39TfjmxCov26dKfJalGDR0f4W FKIBwbmReKMqthEWSZQJ/6ZSztjzfD0uyxIV3I4PDyjWNWLTLOchDtmifGK/L2PGTPZn DRtg== X-Gm-Message-State: ACgBeo1sY5WuYZ0+7bYwZn1skHZE5srUDTyM0VEFhZdSi/bFGoyO9IG+ DICeVYzzz/rcbGp53+C5E5SD72Ez214= X-Google-Smtp-Source: AA6agR4dy1EdqwqJMB6Jv2oeYQ5AhONsqYsknJ4MykajKxIIb+SmIArxYfejJEmY5Rpq0PRAoQgReQ== X-Received: by 2002:a05:600c:348f:b0:3a5:e28c:a1d5 with SMTP id a15-20020a05600c348f00b003a5e28ca1d5mr2189127wmq.33.1662561479150; Wed, 07 Sep 2022 07:37:59 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y8-20020adfe6c8000000b00228de58ae2bsm5055422wrm.12.2022.09.07.07.37.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 07:37:58 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 07 Sep 2022 14:37:48 +0000 Subject: [PATCH v2 5/7] 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 | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index dd5e0e1feb6..b5c78ce1fb0 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()); + if (is_null_oid(branch_base)) goto done; - } - 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; @@ -1667,8 +1676,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); @@ -1696,13 +1705,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 Wed Sep 7 14:37:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12969062 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 D2A0EC54EE9 for ; Wed, 7 Sep 2022 14:38:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229783AbiIGOiQ (ORCPT ); Wed, 7 Sep 2022 10:38:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229786AbiIGOiI (ORCPT ); Wed, 7 Sep 2022 10:38:08 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E7707B1C4 for ; Wed, 7 Sep 2022 07:38:02 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id b5so20724361wrr.5 for ; Wed, 07 Sep 2022 07:38:02 -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; bh=nU05la8118E5qqcSfvjH2ePUu/UsC7r6OQ3Uqsd6xQg=; b=TtHqdHPPT0nl/13bmAkMPu2NtX57PuuB2VSvwbmGCQpKsqQS02v6hodY/DTahQJNpQ FWhwY6UcIERoI5RKYihhJBwXQzf4YOknzXG5zmb8yhX4con+fPsV2QS9m0bGY7MVRKCP m29UY40a+a12u46Qm/pZAw2epDPSvkiFREEdFnp/wPrPzbTfaimHZ23K4jQBh0Wa9wV9 r82OygJtx6uJwSPUWgcswvP1K4xwEvSA3j7zlbusNiavjChf0FV6LsZDJG+96dB65XuT VyTVFu7v1CLREw8HS4KCeajtaZuAceoitmGtnCGodE1SgdpKwlIKq/meGPr1rZMhvCqN MPTQ== 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; bh=nU05la8118E5qqcSfvjH2ePUu/UsC7r6OQ3Uqsd6xQg=; b=3VmqIxKmLYfQvxqCh3NfQet64Ar3N4mykNMjkgohqh5J12Qz3Pqy9rx2FJZ9Q63saM hGUIFQ+dKLP0lG1Ilf+Sd8iwnMm+Qwmdj/eZwGoqrlpfs/9avkrPhTxzrM5oTzEOfmf7 hCR0543RY92GvHwIJ6b23Or/kNDYwYXlqj6yD38Z2BMkUKzaZ8JGp8pyhbANpBQwL2de QeGBx4EZ4IPyD2gXHZpEqmNay8erfJ3f2uPgzD2VqsnbEuEzHQh4GybwN0d/WdjR6MpV arFNILwMThEqXnyi5TYCswzXlvjZT1YmywpXT3ttoQTBLRD5yNbONhumLT29u8P2gHK5 MwCw== X-Gm-Message-State: ACgBeo0a9Q58/AQ6HXYlMNjGHHAwAu92nJ240Z4ChxzxVZZxKhRlh/Cl ALMwwvnwHxOrqLBJEbYx5cFsOLOq3b8= X-Google-Smtp-Source: AA6agR4Ys5q1Sk1cUODithQRON0+IyIde1eLOHha+H+yPDw/lGeKMNBpDy8RBS0OpLDAMYJx1xhNIQ== X-Received: by 2002:a5d:6f19:0:b0:228:d8e8:3ac8 with SMTP id ay25-20020a5d6f19000000b00228d8e83ac8mr2229895wrb.101.1662561480231; Wed, 07 Sep 2022 07:38:00 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l20-20020a05600c089400b003a30fbde91dsm24671210wmp.20.2022.09.07.07.37.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 07:37:59 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 07 Sep 2022 14:37:49 +0000 Subject: [PATCH v2 6/7] 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 b5c78ce1fb0..204155bb25b 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) @@ -1678,6 +1689,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 Wed Sep 7 14:37:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12969063 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 134CCC54EE9 for ; Wed, 7 Sep 2022 14:38:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229557AbiIGOiT (ORCPT ); Wed, 7 Sep 2022 10:38:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229765AbiIGOiJ (ORCPT ); Wed, 7 Sep 2022 10:38:09 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EC0F78595 for ; Wed, 7 Sep 2022 07:38:03 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id k9so20750101wri.0 for ; Wed, 07 Sep 2022 07:38: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; bh=gz8Q6j9kb9vhYj1GfcqE2ha6v900eQwAd3kfKvvXRpw=; b=LXx73Bn/ExKPjWQZJVPRW/HdPF8XQ7EeFrpLeKbYJBP5pF8gyqxqnvNpWoRAaGJQ96 Ka/KnXuYyP1usjrMFj1nnAPFz1kpW7BKsDxLaln9nvc5MaufDdHiXcaZG5zjecM5k9F9 xPSgJ5nz+Fk5XFUQtX1k5Leh6WRf46X8BrJiImmjlVS748OOm94WcLuNJ/OW6Ge1V6Kn hxvtdnTPFQ3e4X6u+4lW/8v9XEmpIphk3CfTfHcATrFsnmsI2TC4Wv/yf5Ro6vlnH8EX 9WblLPi8rmUfDaNAyzAipVgZIlHxDsJYKfOcPqM8svR8Djp9rand/Ja3bN0mVHahM4me BbJA== 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; bh=gz8Q6j9kb9vhYj1GfcqE2ha6v900eQwAd3kfKvvXRpw=; b=QYCATfxcBujXqZ6vN/1sHD8nlmUesMDfVkgq0blDg4Vbi6bKvm93fdWAkL43Uwb2xP LmBmiOvBH4Q1TMCxA5f1mM97Gdbotod1DkV6QoTWakegUrObIOK+P5FWTkTJwx2dLo/I WepI/0stIumKVZ3u6gtF6LKM4yA8DLHTkPA624o4TfGtvd/2lyEuj2prNk6E7WBJy7QY mryqocoNOx9+DFy9SSVi/EEs+l3d10wwOe6S4rtq4u4BvANhSZlN+1+5lzMboFqcyoy3 cjjJrOAE0x9Dd+YU2Zv4ICVuWwSerC6s6d+uNvUNRjHCfMI3CVC949hOHuFDMiDGa/3m zMFg== X-Gm-Message-State: ACgBeo3dkTz1UKKjOzCVcZjTJfia/i1OeCN9UWEFcG1S3Iu/oVVhQkoA sir5hIdHQLLjrNGG/hIWhYq7E+GKCyI= X-Google-Smtp-Source: AA6agR7bECvPH3rYEohsWG0tAjzu/5PLJCVjCuNHdmECidEf+tWoeu6E2BpCL8/fE8wRFexWGs5vaQ== X-Received: by 2002:a05:6000:912:b0:229:9bc1:27ed with SMTP id bz18-20020a056000091200b002299bc127edmr1501927wrb.546.1662561481462; Wed, 07 Sep 2022 07:38:01 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n19-20020a05600c3b9300b003a846a014c1sm27798621wms.23.2022.09.07.07.38.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 07:38:00 -0700 (PDT) Message-Id: <6410b101d7f4ad97f87faec93703370a0493aa4a.1662561470.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 07 Sep 2022 14:37:50 +0000 Subject: [PATCH v2 7/7] 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 204155bb25b..3065e6f082b 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