git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rebase -i: stop setting GIT_CHERRY_PICK_HELP
@ 2024-02-27 14:06 Phillip Wood via GitGitGadget
  2024-02-27 18:38 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Phillip Wood via GitGitGadget @ 2024-02-27 14:06 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin, Phillip Wood, Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

Setting this environment variable causes the sequencer to display a
custom message when it stops for the user to resolve conflicts and
remove CHERRY_PICK_HEAD. Setting it in "git rebase" is a vestige of
the scripted implementation, now that it is a builtin command we do
not need to communicate with the sequencer machinery via environment
variables.

Move the conflicts advice to use when rebasing into
sequencer.c so we do not need to pass it via the environment.

Note that we retain the changes in e4301f73fff (sequencer: unset
GIT_CHERRY_PICK_HELP for 'exec' commands, 2024-02-02) just in case
GIT_CHERRY_PICK_HELP is set in the environment when "git rebase" is
run.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
    rebase -i: stop setting GIT_CHERRY_PICK_HELP

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1678%2Fphillipwood%2Frebase-stop-setting-GIT_CHERRY_PICK_HELP-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1678/phillipwood/rebase-stop-setting-GIT_CHERRY_PICK_HELP-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1678

 builtin/rebase.c | 14 +++-----------
 sequencer.c      | 14 +++++++++++++-
 sequencer.h      |  2 ++
 3 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index 5b086f651a6..d0cc518c931 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -567,13 +567,6 @@ static int move_to_original_branch(struct rebase_options *opts)
 	return ret;
 }
 
-static const char *resolvemsg =
-N_("Resolve all conflicts manually, mark them as resolved with\n"
-"\"git add/rm <conflicted_files>\", then run \"git rebase --continue\".\n"
-"You can instead skip this commit: run \"git rebase --skip\".\n"
-"To abort and get back to the state before \"git rebase\", run "
-"\"git rebase --abort\".");
-
 static int run_am(struct rebase_options *opts)
 {
 	struct child_process am = CHILD_PROCESS_INIT;
@@ -587,7 +580,7 @@ static int run_am(struct rebase_options *opts)
 		     opts->reflog_action);
 	if (opts->action == ACTION_CONTINUE) {
 		strvec_push(&am.args, "--resolved");
-		strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
+		strvec_pushf(&am.args, "--resolvemsg=%s", rebase_resolvemsg);
 		if (opts->gpg_sign_opt)
 			strvec_push(&am.args, opts->gpg_sign_opt);
 		status = run_command(&am);
@@ -598,7 +591,7 @@ static int run_am(struct rebase_options *opts)
 	}
 	if (opts->action == ACTION_SKIP) {
 		strvec_push(&am.args, "--skip");
-		strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
+		strvec_pushf(&am.args, "--resolvemsg=%s", rebase_resolvemsg);
 		status = run_command(&am);
 		if (status)
 			return status;
@@ -672,7 +665,7 @@ static int run_am(struct rebase_options *opts)
 
 	strvec_pushv(&am.args, opts->git_am_opts.v);
 	strvec_push(&am.args, "--rebasing");
-	strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
+	strvec_pushf(&am.args, "--resolvemsg=%s", rebase_resolvemsg);
 	strvec_push(&am.args, "--patch-format=mboxrd");
 	if (opts->allow_rerere_autoupdate == RERERE_AUTOUPDATE)
 		strvec_push(&am.args, "--rerere-autoupdate");
@@ -700,7 +693,6 @@ static int run_specific_rebase(struct rebase_options *opts)
 
 	if (opts->type == REBASE_MERGE) {
 		/* Run sequencer-based rebase */
-		setenv("GIT_CHERRY_PICK_HELP", resolvemsg, 1);
 		if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT))
 			setenv("GIT_SEQUENCE_EDITOR", ":", 1);
 		if (opts->gpg_sign_opt) {
diff --git a/sequencer.c b/sequencer.c
index f49a871ac06..76027ad5f5c 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -461,10 +461,22 @@ static void free_message(struct commit *commit, struct commit_message *msg)
 	repo_unuse_commit_buffer(the_repository, commit, msg->message);
 }
 
+const char *rebase_resolvemsg =
+N_("Resolve all conflicts manually, mark them as resolved with\n"
+"\"git add/rm <conflicted_files>\", then run \"git rebase --continue\".\n"
+"You can instead skip this commit: run \"git rebase --skip\".\n"
+"To abort and get back to the state before \"git rebase\", run "
+"\"git rebase --abort\".");
+
 static void print_advice(struct repository *r, int show_hint,
 			 struct replay_opts *opts)
 {
-	char *msg = getenv("GIT_CHERRY_PICK_HELP");
+	const char *msg;
+
+	if (is_rebase_i(opts))
+		msg = rebase_resolvemsg;
+	else
+		msg = getenv("GIT_CHERRY_PICK_HELP");
 
 	if (msg) {
 		advise("%s\n", msg);
diff --git a/sequencer.h b/sequencer.h
index dcef7bb99c0..437eabd38af 100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -14,6 +14,8 @@ const char *rebase_path_todo(void);
 const char *rebase_path_todo_backup(void);
 const char *rebase_path_dropped(void);
 
+extern const char *rebase_resolvemsg;
+
 #define APPEND_SIGNOFF_DEDUP (1u << 0)
 
 enum replay_action {

base-commit: 3c2a3fdc388747b9eaf4a4a4f2035c1c9ddb26d0
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rebase -i: stop setting GIT_CHERRY_PICK_HELP
  2024-02-27 14:06 [PATCH] rebase -i: stop setting GIT_CHERRY_PICK_HELP Phillip Wood via GitGitGadget
@ 2024-02-27 18:38 ` Junio C Hamano
  2024-02-28 14:45   ` phillip.wood123
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2024-02-27 18:38 UTC (permalink / raw)
  To: Phillip Wood via GitGitGadget; +Cc: git, Johannes Schindelin, Phillip Wood

"Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com> writes:

> Note that we retain the changes in e4301f73fff (sequencer: unset
> GIT_CHERRY_PICK_HELP for 'exec' commands, 2024-02-02) just in case
> GIT_CHERRY_PICK_HELP is set in the environment when "git rebase" is
> run.

Is this comment about this part of the code?

> +	const char *msg;
> +
> +	if (is_rebase_i(opts))
> +		msg = rebase_resolvemsg;
> +	else
> +		msg = getenv("GIT_CHERRY_PICK_HELP");

Testing is_rebase_i() first means we ignore the environment
unconditionally and use our own message always in "rebase -i", no?

Not that I think we should honor the environment variable and let it
override our message.  I just found the description a bit confusing.

> diff --git a/sequencer.h b/sequencer.h
> index dcef7bb99c0..437eabd38af 100644
> --- a/sequencer.h
> +++ b/sequencer.h
> @@ -14,6 +14,8 @@ const char *rebase_path_todo(void);
>  const char *rebase_path_todo_backup(void);
>  const char *rebase_path_dropped(void);
>  
> +extern const char *rebase_resolvemsg;

This is more library-ish part of the system than a random file in
the builtin/ directory.  This place as the final location for the
string makes sense to me.

Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rebase -i: stop setting GIT_CHERRY_PICK_HELP
  2024-02-27 18:38 ` Junio C Hamano
@ 2024-02-28 14:45   ` phillip.wood123
  0 siblings, 0 replies; 3+ messages in thread
From: phillip.wood123 @ 2024-02-28 14:45 UTC (permalink / raw)
  To: Junio C Hamano, Phillip Wood via GitGitGadget
  Cc: git, Johannes Schindelin, Phillip Wood

On 27/02/2024 18:38, Junio C Hamano wrote:
> "Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 
>> Note that we retain the changes in e4301f73fff (sequencer: unset
>> GIT_CHERRY_PICK_HELP for 'exec' commands, 2024-02-02) just in case
>> GIT_CHERRY_PICK_HELP is set in the environment when "git rebase" is
>> run.
> 
> Is this comment about this part of the code?

No, it is about

         strvec_push(&cmd.env, "GIT_CHERRY_PICK_HELP");

in do_exec() which clears GIT_CHERRY_PICK_HELP in the child environment 
when running an exec command so that "exec git cherry-pick ..." retains 
the correct author information.

>> +	const char *msg;
>> +
>> +	if (is_rebase_i(opts))
>> +		msg = rebase_resolvemsg;
>> +	else
>> +		msg = getenv("GIT_CHERRY_PICK_HELP");
> 
> Testing is_rebase_i() first means we ignore the environment
> unconditionally and use our own message always in "rebase -i", no?

Yes, this matches the existing behavior in builtin/rebase.c where we call

	setenv("GIT_CHERRY_PICK_HELP", resolvemsg, 1);

to set GIT_CHERRY_PICK_HELP even if it is already set in the environment.

> Not that I think we should honor the environment variable and let it
> override our message.  I just found the description a bit confusing.

I should have been clearer what that it was talking about - i.e. it is 
still worth clearing GIT_CHERRY_PICK_HELP in the environment when 
running exec commands.

Best Wishes

Phillip


>> diff --git a/sequencer.h b/sequencer.h
>> index dcef7bb99c0..437eabd38af 100644
>> --- a/sequencer.h
>> +++ b/sequencer.h
>> @@ -14,6 +14,8 @@ const char *rebase_path_todo(void);
>>   const char *rebase_path_todo_backup(void);
>>   const char *rebase_path_dropped(void);
>>   
>> +extern const char *rebase_resolvemsg;
> 
> This is more library-ish part of the system than a random file in
> the builtin/ directory.  This place as the final location for the
> string makes sense to me.
> 
> Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-28 14:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-27 14:06 [PATCH] rebase -i: stop setting GIT_CHERRY_PICK_HELP Phillip Wood via GitGitGadget
2024-02-27 18:38 ` Junio C Hamano
2024-02-28 14:45   ` phillip.wood123

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).