From patchwork Fri Mar 12 03:01:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 12133629 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E43BCC433E0 for ; Fri, 12 Mar 2021 03:02:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A78D064F78 for ; Fri, 12 Mar 2021 03:02:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231512AbhCLDBq (ORCPT ); Thu, 11 Mar 2021 22:01:46 -0500 Received: from pb-smtp1.pobox.com ([64.147.108.70]:58464 "EHLO pb-smtp1.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229664AbhCLDBM (ORCPT ); Thu, 11 Mar 2021 22:01:12 -0500 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 4532EBF768; Thu, 11 Mar 2021 22:01:12 -0500 (EST) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=yKP64XlU704jsFPEPY9LhjxfN z0=; b=VmjX744vi9qSgxw04Gh2G4HEhzhp88CaJkRL6OceUStV64cfBt3q9oqqY c7eh3KyG6fgQ+358xaX8OpWgnRwPV55EOKNUdWFr4oQ/vbTiM8pkijkDIsZmeibV N40pJxKPb1JhH2jLtq9qUFpUDFIvR/ATLDkoyVx8nXZtTqQyG4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=sasl; b=ORpfNJETDT0QBy+9vx2 LzwbdXQdBJdSBhgQPB41sqthaa9qJTh5ccbAA53uaS8e8Q6tCs2U+qOz8YxDdA5S ZxN+mj7eO0MaNfRTBmv4BfOWl87E1nB378JjUJChTMLgQCEV4q4PQ4MtVmFei2Qv Hrsa5QbyCH71pogOqjIfBjM4= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 3D8A4BF767; Thu, 11 Mar 2021 22:01:12 -0500 (EST) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.74.119.39]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id C5A2BBF766; Thu, 11 Mar 2021 22:01:11 -0500 (EST) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 1/2] sequencer.c: make commit_post_rewrite() take two object names Date: Thu, 11 Mar 2021 19:01:06 -0800 Message-Id: <20210312030107.1849942-2-gitster@pobox.com> X-Mailer: git-send-email 2.31.0-rc2-175-g3820f1c72e In-Reply-To: <20210312030107.1849942-1-gitster@pobox.com> References: <20210312030107.1849942-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 337F3CD0-82DF-11EB-8DD0-D152C8D8090B-77302942!pb-smtp1.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The helper function is to copy notes between two commits by taking the original one and a new one that is supposed to be a rewrite of the original one. It somehow takes "struct commit *" for the former but "struct object_id *" for the latter, but what it does does not need access to the in-core commit object. Change the function to take two "struct object_id *" instead. As we require "struct object_id *" for the original commit now, the comment on the old "struct commit *" that must be non-NULL which made taking the address of its object.oid member safe no longer is relevant to this function (it is the caller's concern now), so remove it. Two callers we have are of course safe, and there is no reason to call this "as we rewrote A to B, please copy notes on A to B, too" helper if the caller knows A is NULL, so the comment would have very little value even if it were kept. Signed-off-by: Junio C Hamano --- builtin/commit.c | 6 +++--- sequencer.c | 9 ++++----- sequencer.h | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 739110c5a7..f2fbef053e 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1702,9 +1702,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix) repo_rerere(the_repository, 0); run_auto_maintenance(quiet); run_commit_hook(use_editor, get_index_file(), "post-commit", NULL); - if (amend && !no_post_rewrite) { - commit_post_rewrite(the_repository, current_head, &oid); - } + if (amend && !no_post_rewrite) + commit_post_rewrite(the_repository, ¤t_head->object.oid, &oid); + if (!quiet) { unsigned int flags = 0; diff --git a/sequencer.c b/sequencer.c index d2332d3e17..92a4871997 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1175,18 +1175,17 @@ static int run_rewrite_hook(const struct object_id *oldoid, } void commit_post_rewrite(struct repository *r, - const struct commit *old_head, + const struct object_id *old_head, const struct object_id *new_head) { struct notes_rewrite_cfg *cfg; cfg = init_copy_notes_for_rewrite("amend"); if (cfg) { - /* we are amending, so old_head is not NULL */ - copy_note_for_rewrite(cfg, &old_head->object.oid, new_head); + copy_note_for_rewrite(cfg, old_head, new_head); finish_copy_notes_for_rewrite(r, cfg, "Notes added by 'git commit --amend'"); } - run_rewrite_hook(&old_head->object.oid, new_head); + run_rewrite_hook(old_head, new_head); } static int run_prepare_commit_msg_hook(struct repository *r, @@ -1538,7 +1537,7 @@ static int try_to_commit(struct repository *r, run_commit_hook(0, r->index_file, "post-commit", NULL); if (flags & AMEND_MSG) - commit_post_rewrite(r, current_head, oid); + commit_post_rewrite(r, ¤t_head->object.oid, oid); out: free_commit_extra_headers(extra); diff --git a/sequencer.h b/sequencer.h index f8b2e4ab85..79eed55c4b 100644 --- a/sequencer.h +++ b/sequencer.h @@ -192,7 +192,7 @@ int update_head_with_reflog(const struct commit *old_head, const char *action, const struct strbuf *msg, struct strbuf *err); void commit_post_rewrite(struct repository *r, - const struct commit *current_head, + const struct object_id *old_head, const struct object_id *new_head); void create_autostash(struct repository *r, const char *path, From patchwork Fri Mar 12 03:01:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 12133631 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18484C433DB for ; Fri, 12 Mar 2021 03:02:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB08364F90 for ; Fri, 12 Mar 2021 03:02:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231531AbhCLDBq (ORCPT ); Thu, 11 Mar 2021 22:01:46 -0500 Received: from pb-smtp20.pobox.com ([173.228.157.52]:54996 "EHLO pb-smtp20.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231351AbhCLDBQ (ORCPT ); Thu, 11 Mar 2021 22:01:16 -0500 Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 69B18124F59; Thu, 11 Mar 2021 22:01:16 -0500 (EST) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=8yD478ONw1UaQ6yg4t4xnjUba 1Y=; b=axIB0ydC5I0Bq5vEZECKQNt6fjRCzp0DE98kfy9jXqVv6BenFbu+lsMU0 V8rGTGpb6E6m1LgV6/9Hy2jcx/d/S9tCLzhmF0A5LtYHiQstEu1J8SPghAq1eMqy oIOYDYTw7WcJ6gcb2QiLTiap8Il2vgDVgJ889+n2yaXGyeL0qI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=sasl; b=DKH4BY3d0UGc+ATwO0t uRD5M1J6d5v3DNWkI00v9uU+c15QEt3N55CKNtQ4dj5/XiI2j4ebP9JN792FTPEs 4OyRkj8gHb7vdwRYgsBEg7CfCClxWCfGJT6MLu8aMw+bzZEmWSzlovXMS8o6akQ8 vRoeWN/wryTP4la+yidkvAso= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 61CFD124F58; Thu, 11 Mar 2021 22:01:16 -0500 (EST) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.74.119.39]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id ABBE4124F57; Thu, 11 Mar 2021 22:01:13 -0500 (EST) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 2/2] [WIP] sequencer.c: carry forward notes on HEAD across "rebase -x" Date: Thu, 11 Mar 2021 19:01:07 -0800 Message-Id: <20210312030107.1849942-3-gitster@pobox.com> X-Mailer: git-send-email 2.31.0-rc2-175-g3820f1c72e In-Reply-To: <20210312030107.1849942-1-gitster@pobox.com> References: <20210312030107.1849942-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 34A06760-82DF-11EB-B74A-E43E2BB96649-77302942!pb-smtp20.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When the external command invoked by "rebase -x" replaces the HEAD, we seem to lose the notes attached to the original HEAD, which is why we have been losing the amlog mappings in the git core project. Here is a half-successful attempt to fix it. For whatever reason, when the external command is "git commit --amend --no-edit", the updated code carries notes forward correctly, but when the command is changed to "git commit --amend -m tweak", it fails to do so, and I do not have more time to work on this, so I'd stop here with an expected failure in the test. Help is appreciated. Signed-off-by: Junio C Hamano --- sequencer.c | 10 +++++++++- t/t3404-rebase-interactive.sh | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/sequencer.c b/sequencer.c index 92a4871997..e0bdc39e4d 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3276,7 +3276,10 @@ static int do_exec(struct repository *r, const char *command_line) { struct strvec child_env = STRVEC_INIT; const char *child_argv[] = { NULL, NULL }; - int dirty, status; + int dirty, status, bad_head; + struct object_id old_head_oid, new_head_oid; + + bad_head = get_oid("HEAD", &old_head_oid); fprintf(stderr, _("Executing: %s\n"), command_line); child_argv[0] = command_line; @@ -3286,6 +3289,11 @@ static int do_exec(struct repository *r, const char *command_line) status = run_command_v_opt_cd_env(child_argv, RUN_USING_SHELL, NULL, child_env.v); + bad_head |= get_oid("HEAD", &new_head_oid); + + if (!bad_head && !oideq(&old_head_oid, &new_head_oid)) + commit_post_rewrite(r, &old_head_oid, &new_head_oid); + /* force re-reading of the cache */ if (discard_index(r->index) < 0 || repo_read_index(r) < 0) return error(_("could not read index")); diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 66bcbbf952..3222c594ab 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -155,6 +155,8 @@ test_expect_success 'rebase -i with the exec command checks tree cleanness' ' git rebase --continue ' +# NEEDSWORK: Fix c762aada1ab3a2c428c with s/@/HEAD/; + test_expect_success 'rebase -x with empty command fails' ' test_when_finished "git rebase --abort ||:" && test_must_fail env git rebase -x "" @ 2>actual && @@ -867,6 +869,22 @@ test_expect_success 'rebase -i can copy notes over a fixup' ' test_cmp expect output ' +test_expect_success 'notes are copied even rebase -x changes HEAD' ' + git reset --hard n3 && + git rebase -x "git commit --amend --no-edit" n1^1 && + git log --format="%s <%N>" n1^1..n3 >expect && + git log --format="%s <%N>" n1^1..HEAD >actual && + test_cmp expect actual +' + +test_expect_failure 'notes are copied even rebase -x changes HEAD' ' + git reset --hard n3 && + git rebase -x "git commit --amend -m tweak" n1^1 && + git log --format="tweak <%N>" n1^1..n3 >expect && + git log --format="%s <%N>" n1^1..HEAD >actual && + test_cmp expect actual +' + test_expect_success 'rebase while detaching HEAD' ' git symbolic-ref HEAD && grandparent=$(git rev-parse HEAD~2) &&