git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
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	[thread overview]
Message-ID: <20210312030107.1849942-2-gitster@pobox.com> (raw)
In-Reply-To: <20210312030107.1849942-1-gitster@pobox.com>

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 <gitster@pobox.com>
---
 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, &current_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, &current_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,
-- 
2.31.0-rc2-175-g3820f1c72e


  reply	other threads:[~2021-03-12  3:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-11 20:11 [BUG] cmd given to "rebase -x cmd" cannot see the original HEAD? Junio C Hamano
2021-03-12  3:01 ` [PATCH 0/2] "rebase -x cmd" loses notes Junio C Hamano
2021-03-12  3:01   ` Junio C Hamano [this message]
2021-03-12  3:01   ` [PATCH 2/2] [WIP] sequencer.c: carry forward notes on HEAD across "rebase -x" Junio C Hamano
2021-03-12 11:12     ` Phillip Wood
2021-03-12 12:26     ` Ævar Arnfjörð Bjarmason
2021-03-12 11:09 ` [BUG] cmd given to "rebase -x cmd" cannot see the original HEAD? Phillip Wood
2021-03-12 11:26 ` [WIP][PATCH] rebase: update the list of rewritten commits when amending pick Phillip Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210312030107.1849942-2-gitster@pobox.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).