From patchwork Mon Aug 15 15:11:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12943680 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 607F0C25B0E for ; Mon, 15 Aug 2022 15:11:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232975AbiHOPLa (ORCPT ); Mon, 15 Aug 2022 11:11:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230262AbiHOPL2 (ORCPT ); Mon, 15 Aug 2022 11:11:28 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E5DF13E88 for ; Mon, 15 Aug 2022 08:11:27 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id bv3so9416902wrb.5 for ; Mon, 15 Aug 2022 08:11:27 -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; bh=gaLOdNNG0v0n0byAu9u0dJwUUSbbltut6YVDnKvnRxo=; b=pxPr4+lBiqfbGEGtCzXDy3ONPdtAZLkYZa3JOTS+sH9vquWCHTKwj6l9zSy6/mgtw/ 8FAxv/e/RYu6glw3vDTUW8AhaGD92uIm3pQdZw0Junx7ZY6a6QSGQKUky3R42lq6/gzd Crc3A9rdRm/Se/+Ueqbm3AX8MhCsKGCCsHIjNshbRF/UVfd7gtXKELKtF6G7dlb6xS4P Bpcd+fu3E4BuPmAy8tOo9eqhRwG3qx+ytZRoPXHaVAJuWwoRgIu+bo1ZPAi2oX/oGjQH DVWtFwGmAEtvBwjwoPqsJLfq7Eg1Qw0PhDN7ma7dnrYcQK00td4clmPT86H/UBYk7BIO r9EQ== 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; bh=gaLOdNNG0v0n0byAu9u0dJwUUSbbltut6YVDnKvnRxo=; b=d3D/+8lEqLA9FVcMSaYjE9XjKiNnX3//1uHJ0+qQsffb7dwPu7mv7vauQ1e6awTEc0 6Vs7CPUiHEJmwpXSkKDf/faS6CrMkHK3YltVeGWicNydRrtWuWXPK2FEM52y4G9msKA4 Py74kpN5bc822Lbrf62yeyZ6kMnqRYdCMHPqX0tx+q61oXn45wWT5cd+MoIMOqsiU7AT bdsQlRNrPbvbvbnboxuqaSc218Pjc3fpjpk17g4wkAFBAZQuO6pMxHTzRjEd5kIFOGk8 x4G9DmwqYNBUZW0d6S1miUlHmOF1pPuCr/sz45uDiNnwxq8LzbTcY2ui37y51PqalZa9 MABw== X-Gm-Message-State: ACgBeo0zTeX7E5RTJtbajdVcu+HT5gwFJjzNPm9SapiCrna/wT3lFGLU L6+BbAtLitjMhW77ixWQXPwUJw8HUJA= X-Google-Smtp-Source: AA6agR5HCdO3L/xXnMOnv3J1YvWquZvKugTXkiN05iYuJcUSUMLQe//J+ZV/sZROHCAC4MUOCqYpOQ== X-Received: by 2002:a5d:5311:0:b0:224:f76e:ad6f with SMTP id e17-20020a5d5311000000b00224f76ead6fmr5446783wrv.54.1660576285842; Mon, 15 Aug 2022 08:11:25 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c7-20020a05600c0a4700b003a5de95b105sm10571376wmq.41.2022.08.15.08.11.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 08:11:25 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 15 Aug 2022 15:11:19 +0000 Subject: [PATCH 1/5] 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 , 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 and remove a couple of unnecessary call to set_fake_editor. 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 3e04802cb00..e1fc2dbd48e 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 -i --onto main...side' ' git checkout side && git reset --hard K && - set_fake_editor && test_must_fail git rebase -i --onto main...side J ' @@ -156,8 +159,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 && @@ -171,8 +176,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 && @@ -187,8 +194,12 @@ test_expect_success 'rebase -i --keep-base main from side' ' git checkout side && git reset --hard K && - set_fake_editor && test_must_fail git rebase -i --keep-base main ' +# This must be the last test in this file +test_expect_success '$EDITOR and friends are unchanged' ' + test_editor_unchanged +' + test_done From patchwork Mon Aug 15 15:11:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12943681 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 91788C00140 for ; Mon, 15 Aug 2022 15:11:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232984AbiHOPLd (ORCPT ); Mon, 15 Aug 2022 11:11:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232968AbiHOPLa (ORCPT ); Mon, 15 Aug 2022 11:11:30 -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 C032E13E38 for ; Mon, 15 Aug 2022 08:11:28 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id bu15so898305wrb.7 for ; Mon, 15 Aug 2022 08:11:28 -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; bh=jB0FOfuAXaKYQyFPcsSGVjETFzfznjfHJicUtnnXHDc=; b=N3dxUIivUwiObhqw9S7T45OFKnu8kVcRskh4d5wv7agjnIc6maxo+r+5zJOXa+8SE3 1IGYEEXEW9MV0PMqrVfRPo0sbVi4QW9gjjwOZNmLQ5KdcmitVInbhJvPx6/h+3F2WWvd ZX/kpqzw8EJVQggnZGRCD6omA4RjLADU/rGg1m9mWcTy1T0FPNkKs1Mn7b2TBqO30EDj rU6y0Agxnz2u3dI2XpUn+V1LG4PBedvMjZFPLsFEpEOgJMG6I6UR9TWB2kA1UqqFDZBp Dl6b7BV8MxLIdtPFlwl9wlK90XX4hdkQTTiwdo6YVLUYDZ/IK6rDN/RaQLyNQNO5Xi0H hl/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc; bh=jB0FOfuAXaKYQyFPcsSGVjETFzfznjfHJicUtnnXHDc=; b=eyQ6BVlO6ZUGilzmINS3evLdG+dCI0p0Q4afziOxAI8EmbB7BjeQRJ3EH16k2M0ws1 PtCFkfcKxdOsFj4PQ4rCakRVzgQulAvuhAj7Qv9oNxMWxfbaGf7eP/E8yDjTPeGP6O+9 LeyWa+2qeb0nPh0QKe7bUFdZjAbW+0dnwQtw9WXT1FY07acLI3lLieioOLoEDFMF2DYI 6yjZFElYbQogYF060lCyh37iLJ8hcLsl4dcuCP4Qp4lPG8CXmJRYUgS7XxTZAsBXGV7p AIy6XemXUGHglTaqHMeFR0MRTh7tPIB5bySb9poPjTX/zczmzCGXVV9b3bLYIpFawXk9 PrYg== X-Gm-Message-State: ACgBeo33jz8c2Gn4H6+yoOr2l+wduPLRYP0TF1vQKnJk0V3MkDNKD0BR 4R6FPaYceylTQcOKjWwgk5mKP4n3pjY= X-Google-Smtp-Source: AA6agR4+l10W5u9K2RqKh8BTmKL2NlEnZX0k4C2wEGD9Q8IERjhWBT/9CmabB2N7ZYDg+fjN/7V4nA== X-Received: by 2002:a5d:4983:0:b0:220:5fee:1d79 with SMTP id r3-20020a5d4983000000b002205fee1d79mr9278555wrq.62.1660576287041; Mon, 15 Aug 2022 08:11:27 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n4-20020a05600c464400b003a331c6bffdsm9499304wmo.47.2022.08.15.08.11.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 08:11:26 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 15 Aug 2022 15:11:20 +0000 Subject: [PATCH 2/5] 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 , 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 branch being rebased does not point to a commit. It also simplifies the code than handles finding the merge base and fork point as it not longer has to convert from an oid to a commit. Signed-off-by: Phillip Wood --- builtin/rebase.c | 62 ++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 56e4214b441..6cf9c95f4e1 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,10 @@ 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 +1702,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 +1779,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 +1793,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 +1814,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) (options.restrict_revision ? oid_to_hex(&options.restrict_revision->object.oid) : oid_to_hex(&options.upstream->object.oid)), - oid_to_hex(&options.orig_head)); + oid_to_hex(&options.orig_head->object.oid)); options.revisions = revisions.buf; From patchwork Mon Aug 15 15:11:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12943682 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 17CDEC00140 for ; Mon, 15 Aug 2022 15:11:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231502AbiHOPLe (ORCPT ); Mon, 15 Aug 2022 11:11:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229994AbiHOPLa (ORCPT ); Mon, 15 Aug 2022 11:11:30 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0BA51CB1A for ; Mon, 15 Aug 2022 08:11:29 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id ay39-20020a05600c1e2700b003a5503a80cfso4046918wmb.2 for ; Mon, 15 Aug 2022 08:11:29 -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; bh=O3IhWz1TTOveOMKTPthuFBz/G5/QPbB/RzNIjdz2Jsk=; b=V/KwWJkCsGBAjEG/Gc72AgAO3+h6u8jw+6TenP41+xaN0LjhBp+/FOC+QarEK8Ioi3 GGojKnQYb9mOBdxX73KTRD7T1EnWCzft36k4V5dqymSmwZkTKa6SIjwFzEVtvDWN6dQu 8fbodYTkDbhA/hoDwt+rOh2z1lXVHfAQ6VfZfWia44XoofOnq6NIW1SVDO6pFvr/oucS 9kf+cUph5yeqToGabEdCGR5+WxfzkYkV64qkS74ar1xCSQ36uQjhv1QWwFWjHh3jDkgr yXHKBkcDnC2MlAnnhtCCkwYVUdyOILHWBgCUph0CC+9kfgIruqEkyY4nfBs0VU0ZvKVt kMCw== 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; bh=O3IhWz1TTOveOMKTPthuFBz/G5/QPbB/RzNIjdz2Jsk=; b=q1s2FO3oClGWOd/tkDRoLOBX1xbTYB6knN0HFxUVepiKsp0kSox21/oOBChm28ai8a bXCLFRNBmRQ1GqsECCefJrK5kt3bubArZQSOS2L7MwCw5qj4VRGwH4CsJRfow9dmJ+p+ 7M/YT/izSWPvKVb2QkEAsWZi+BLuvhWVLu2zOBfe2ct8hHf1pzmeddaSrvd90o19Iv14 crcGkPq+H8D+gxCGTpHGkKekUvdDUfoOZ6rcxlopn6vbeGNoCmaM/HWtykEnZn6dh0vf JX+qk3PYO2q8loK3uG7Y24IlvIQvz2KLwYyP1Rsu+dePqyZX52m18lBfWKJf1DG+oxvw hoQw== X-Gm-Message-State: ACgBeo0wlhl62XKfqd7DFlKmJUDD+KWaN9/HshVddM28xcvsV6Ky8rvB e5d/ICRsjmy4RWf83w1rmiEbVgak9+E= X-Google-Smtp-Source: AA6agR6y66u0LyxGiX+z3T5qxr+7V5x27dJ7Z4EvtacW+5stPUzyCkwZSMPbh4vYVdGlTp65FnawIg== X-Received: by 2002:a05:600c:a03:b0:39e:4f0c:938c with SMTP id z3-20020a05600c0a0300b0039e4f0c938cmr10431722wmp.145.1660576288210; Mon, 15 Aug 2022 08:11:28 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b6-20020a05600c4e0600b003a5f4fccd4asm4310067wmq.35.2022.08.15.08.11.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 08:11:27 -0700 (PDT) Message-Id: <019158db9d2dbb371705ba79a96a907e4a17cdb1.1660576283.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 15 Aug 2022 15:11:21 +0000 Subject: [PATCH 3/5] rebase: factor out merge_base calculation Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Philippe Blain , Denton Liu , Johannes Schindelin , 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 twice when --keep-base is given. Signed-off-by: Phillip Wood --- Note the unnecessary braces around "if (keep_base)" are added here reduce the churn on the next commit. --- builtin/rebase.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 6cf9c95f4e1..86ea731ca3a 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(merge_base, null_oid()); + if (is_null_oid(merge_base)) goto done; - } - oidcpy(merge_base, &merge_bases->item->object.oid); if (!oideq(merge_base, &onto->object.oid)) goto done; @@ -902,6 +898,20 @@ done: return res && is_linear_history(onto, head); } +static void fill_merge_base(struct rebase_options *options, + struct object_id *merge_base) +{ + struct commit_list *merge_bases = NULL; + + merge_bases = get_merge_bases(options->onto, options->orig_head); + if (!merge_bases || merge_bases->next) + oidcpy(merge_base, null_oid()); + else + oidcpy(merge_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; @@ -1668,7 +1678,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) die(_("Does not point to a valid commit '%s'"), options.onto_name); } - + if (keep_base) { + oidcpy(&merge_base, &options.onto->object.oid); + } else { + fill_merge_base(&options, &merge_base); + } if (options.fork_point > 0) options.restrict_revision = get_fork_point(options.upstream_name, options.orig_head); @@ -1697,13 +1711,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 merge_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) && - allow_preemptive_ff) { + if (allow_preemptive_ff && + can_fast_forward(options.onto, options.upstream, options.restrict_revision, + options.orig_head, &merge_base)) { int flag; if (!(options.flags & REBASE_FORCE)) { From patchwork Mon Aug 15 15:11:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12943683 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 CCB14C25B06 for ; Mon, 15 Aug 2022 15:11:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240520AbiHOPLh (ORCPT ); Mon, 15 Aug 2022 11:11:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232388AbiHOPLc (ORCPT ); Mon, 15 Aug 2022 11:11:32 -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 EB4992019B for ; Mon, 15 Aug 2022 08:11:30 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id ay12so3979042wmb.1 for ; Mon, 15 Aug 2022 08:11:30 -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; bh=yDcfO/3KwB+tt7IYfPSzNWG2EwOg9CJOS9nc2eiK7Dw=; b=S1oSsyRjB4xXaQIeRrlipYVoro75zMY+cPTUgYrqwPdJpIfObupjXgwu7nAUdPs4QB Os9Z7eNJtalprXkQg6eoGz65PbnOQvkQc/uJf+QoOx5l242xbxRoKPwuFgWHd/onbOiw AUVmMTzwUeg3llLYdurP3JoQyGBh8yFmBxmv+2mIQ4Ox91/gjrD5VS6zYFZgDV8ZZy7c aMqm5mMHG2Gme9mgqdGWoSZbfzfoTbgpw2LI01/nthWYvDOVZDBY2wwnkejpNHts1QkU aRpnoQcImMbem7JECKUY7W2J4C1s9EwKwpvKVT8qIuArvAnmF061G2idFH/1fBwoEygm 7C6w== 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; bh=yDcfO/3KwB+tt7IYfPSzNWG2EwOg9CJOS9nc2eiK7Dw=; b=UwLkAt05Iiy9uHnQ+jm4vTY87fXV9S9ahqcL4dvzFNk6aK71mwTx1Sxgo+huHXvN47 iGSjWpdaRp+3gy3JtE65IcRBLow+9S9X4qX1oWhyWtiAz7ii5L68TYwNG4RTlZBwWcYn F+BrX5keEL4fWpuMgtb6LSmoiKlYPiIaYqK/hWdUrskVjodJDKf/z2UhKH3MXBr6X0F/ hA5eIiuTSw2l94cJ1ozV6NVWUVGDrDGiLKbNP3PuyCSWHfCebNERwT7Ccr08viA2asyp IPYrGl9EztsEbCBWoExPFF2CHpyePrRn/Il7AVsmIjn9Tt2M0PJE6TPyRDjR393nv5// OF6Q== X-Gm-Message-State: ACgBeo0CsN5in1S+rZ1eDRzSZS0ogMQ28d6B7xAa9avtqsSOrf2Cx3Va ioSb872kk90jU5WlKHh80+/4W55bVjQ= X-Google-Smtp-Source: AA6agR6W4WJjtPH6CxWihsN9YCRtFpCx4VprB9tvhbaozPsRQPHT0S6I9Kgjx5SPjUX7a9KMrXgHPg== X-Received: by 2002:a1c:7512:0:b0:3a4:f09d:1cf7 with SMTP id o18-20020a1c7512000000b003a4f09d1cf7mr16568168wmc.67.1660576289198; Mon, 15 Aug 2022 08:11:29 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n128-20020a1ca486000000b003a540fef440sm9842117wme.1.2022.08.15.08.11.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 08:11:28 -0700 (PDT) Message-Id: <9cd4c372ee4b3e5ba45c66a43ad0edaf52f0eed9.1660576283.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 15 Aug 2022 15:11:22 +0000 Subject: [PATCH 4/5] 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 , 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 | 2 +- builtin/rebase.c | 15 ++++++++++++++- t/t3416-rebase-onto-threedots.sh | 21 +++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index 080658c8710..dc0c6c54e27 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 --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 diff --git a/builtin/rebase.c b/builtin/rebase.c index 86ea731ca3a..b6b3e00e3b1 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1181,6 +1181,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 */ @@ -1240,6 +1241,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 as it is confusing if + * commits disappear 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"); @@ -1416,7 +1423,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,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } if (keep_base) { oidcpy(&merge_base, &options.onto->object.oid); + if (options.reapply_cherry_picks) + options.upstream = options.onto; } else { fill_merge_base(&options, &merge_base); } diff --git a/t/t3416-rebase-onto-threedots.sh b/t/t3416-rebase-onto-threedots.sh index e1fc2dbd48e..e0410bfc2a8 100755 --- a/t/t3416-rebase-onto-threedots.sh +++ b/t/t3416-rebase-onto-threedots.sh @@ -197,6 +197,27 @@ test_expect_success 'rebase -i --keep-base main from side' ' test_must_fail git rebase -i --keep-base main ' +test_expect_success 'rebase --keep-base keeps cherry picks' ' + git checkout -f -B main E && + git cherry-pick F && + ( + set_fake_editor && + EXPECT_COUNT=2 git rebase -i --keep-base HEAD G + ) && + test_cmp_rev HEAD G +' + +test_expect_success 'rebase --keep-base --no-reapply-cherry-picks' ' + git checkout -f -B main E && + git cherry-pick F && + ( + set_fake_editor && + EXPECT_COUNT=1 git rebase -i --keep-base \ + --no-reapply-cherry-picks HEAD G + ) && + test_cmp_rev HEAD^ C +' + # This must be the last test in this file test_expect_success '$EDITOR and friends are unchanged' ' test_editor_unchanged From patchwork Mon Aug 15 15:11:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12943684 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 B3149C00140 for ; Mon, 15 Aug 2022 15:11:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240874AbiHOPLj (ORCPT ); Mon, 15 Aug 2022 11:11:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232986AbiHOPLd (ORCPT ); Mon, 15 Aug 2022 11:11:33 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 309E61DA4B for ; Mon, 15 Aug 2022 08:11:32 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id z16so9385130wrh.12 for ; Mon, 15 Aug 2022 08:11:32 -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; bh=QzzhX+Qt9+q/IBHtNlNduzoXOL4/Xbi0jMiIcERhYDI=; b=WF1sgftFHUsdPdzuAOgEghG6OdZQ1CE2gNQ/nkJNVOMWWvw82n+z8HSe9SBUu/scAO qVIqz2DxQg+KNKSjrUTpLRSR7QlN8jbt0y4QTMo7heufFkt8CFpmnZelTbOn7prd7f9T r4HJEEHfQEGovw3xrdBKx0/lLAbyCpNXbbrCwLu1pqC18E6SS9PVEWWlqMvv31IjD6cb Go30XKKOGPm2mwMGdb1L6hxJVp3lce0EwVxR281x6l/uDKtIe6oreACyez4jBdADwtGK XTO4JWPffBuUWgQnkAgxRce6hsNEusUnqwxbz+L0iedloJUJhGNRoEEf7+I/F1GH84nC P9Bw== 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; bh=QzzhX+Qt9+q/IBHtNlNduzoXOL4/Xbi0jMiIcERhYDI=; b=BBhsfj6usAxr6O449zVWTsZT0Z2365BYSmtuHhhlZiu3TUB3MPkysvLQzHLrydGrMm F/Qh6AnXt4Vo9K+XmPm6aHXK2jk/OEujXaNM7fjTkeYBD+XR+Vg0Ff/o8geLxRgaCgY9 rd5NFYO6nmt33oysr0+huYfU2j/1+hK7aP4NdLvGLoLFCV6dTaZWHMqCmYyWEwoUe8f2 K2fzOQfllXRLLLUN9s3HJnuByturP28CHk1q+q9rdG3Idn3i+x7tciozgz9KCNPOP3m4 smputdMHWDRzZkIuEYk3zjJGaNF/g49sabgvYg/3tCyj0UGjyVFA6EfeopjOwggZlLeS jICw== X-Gm-Message-State: ACgBeo0xsmTHshozDcJjBiDhZE3HzVIxuRkchFYCpEJLwJ+DXCQFANjt G1icMjOkCi785kHtnkwyNV9hJcgAw1s= X-Google-Smtp-Source: AA6agR7pzav9w9tHMTfUFCk4BJSY40KCcEFD3ix/PXWDTL7/MufF68P8P7AAV43FrDV9oewkqtbwYA== X-Received: by 2002:adf:fd4f:0:b0:220:60bc:3fc9 with SMTP id h15-20020adffd4f000000b0022060bc3fc9mr9070397wrs.398.1660576290593; Mon, 15 Aug 2022 08:11:30 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e2-20020a5d5942000000b0021e13efa17esm7636019wri.70.2022.08.15.08.11.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 08:11:29 -0700 (PDT) Message-Id: <68bcd10949ec7767d1e0ee8e2f0730ca36bad1c5.1660576283.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 15 Aug 2022 15:11:23 +0000 Subject: [PATCH 5/5] 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 , 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. Signed-off-by: Phillip Wood --- Documentation/git-rebase.txt | 2 +- builtin/rebase.c | 6 ++++++ t/t3431-rebase-fork-point.sh | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index dc0c6c54e27..6d62e404268 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 diff --git a/builtin/rebase.c b/builtin/rebase.c index b6b3e00e3b1..1a8344b890e 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1240,6 +1240,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 ignores config.forkPoint as it is confusing if + * the branch base changes when using this option. + */ + if (options.fork_point < 0) + options.fork_point = 0; } /* * --keep-base defaults to --reapply-cherry-picks as it is confusing if 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