git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] sequencer: honor GIT_REFLOG_ACTION
@ 2020-04-01 20:31 Elijah Newren via GitGitGadget
  2020-04-01 20:46 ` Junio C Hamano
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Elijah Newren via GitGitGadget @ 2020-04-01 20:31 UTC (permalink / raw)
  To: git
  Cc: jrnieder, elbrus, ijackson, phillip.wood, alban.gruin,
	Johannes.Schindelin, Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

There is a lot of code to honor GIT_REFLOG_ACTION throughout git,
including some in sequencer.c; unfortunately, reflog_message() and its
callers ignored it.  Instruct reflog_message() to check the existing
environment variable, and use it when present as an override to
action_name().

Also restructure pick_commits() to only temporarily modify
GIT_REFLOG_ACTION for a short duration and then restore the old value,
so that when we do this setting within a loop we do not keep adding "
(pick)" substrings and end up with a reflog message of the form
    rebase (pick) (pick) (pick) (finish): returning to refs/heads/master

Signed-off-by: Elijah Newren <newren@gmail.com>
---
    sequencer: honor GIT_REFLOG_ACTION
    
    I'm not the best with getenv/setenv. The xstrdup() wrapping is
    apparently necessary on mac and bsd. The xstrdup seems like it leaves us
    with a memory leak, but since setenv(3) says to not alter or free it, I
    think it's right. Anyone have any alternative suggestions?

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-746%2Fnewren%2Fhonor-reflog-action-in-sequencer-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-746/newren/honor-reflog-action-in-sequencer-v1
Pull-Request: https://github.com/git/git/pull/746

 sequencer.c               |  9 +++++++--
 t/t3406-rebase-message.sh | 16 ++++++++--------
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index e528225e787..5837fdaabbe 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -3708,10 +3708,11 @@ static const char *reflog_message(struct replay_opts *opts,
 {
 	va_list ap;
 	static struct strbuf buf = STRBUF_INIT;
+	char *reflog_action = getenv("GIT_REFLOG_ACTION");
 
 	va_start(ap, fmt);
 	strbuf_reset(&buf);
-	strbuf_addstr(&buf, action_name(opts));
+	strbuf_addstr(&buf, reflog_action ? reflog_action : action_name(opts));
 	if (sub_action)
 		strbuf_addf(&buf, " (%s)", sub_action);
 	if (fmt) {
@@ -3799,8 +3800,10 @@ static int pick_commits(struct repository *r,
 			struct replay_opts *opts)
 {
 	int res = 0, reschedule = 0;
+	char *prev_reflog_action;
 
 	setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
+	prev_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
 	if (opts->allow_ff)
 		assert(!(opts->signoff || opts->no_commit ||
 				opts->record_origin || opts->edit));
@@ -3845,12 +3848,14 @@ static int pick_commits(struct repository *r,
 		}
 		if (item->command <= TODO_SQUASH) {
 			if (is_rebase_i(opts))
-				setenv("GIT_REFLOG_ACTION", reflog_message(opts,
+				setenv(GIT_REFLOG_ACTION, reflog_message(opts,
 					command_to_string(item->command), NULL),
 					1);
 			res = do_pick_commit(r, item->command, item->commit,
 					     opts, is_final_fixup(todo_list),
 					     &check_todo);
+			if (is_rebase_i(opts))
+				setenv(GIT_REFLOG_ACTION, prev_reflog_action, 1);
 			if (is_rebase_i(opts) && res < 0) {
 				/* Reschedule */
 				advise(_(rescheduled_advice),
diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh
index 61b76f33019..927a4f4a4e4 100755
--- a/t/t3406-rebase-message.sh
+++ b/t/t3406-rebase-message.sh
@@ -89,22 +89,22 @@ test_expect_success 'GIT_REFLOG_ACTION' '
 	git checkout -b reflog-topic start &&
 	test_commit reflog-to-rebase &&
 
-	git rebase --apply reflog-onto &&
+	git rebase reflog-onto &&
 	git log -g --format=%gs -3 >actual &&
 	cat >expect <<-\EOF &&
-	rebase finished: returning to refs/heads/reflog-topic
-	rebase: reflog-to-rebase
-	rebase: checkout reflog-onto
+	rebase (finish): returning to refs/heads/reflog-topic
+	rebase (pick): reflog-to-rebase
+	rebase (start): checkout reflog-onto
 	EOF
 	test_cmp expect actual &&
 
 	git checkout -b reflog-prefix reflog-to-rebase &&
-	GIT_REFLOG_ACTION=change-the-reflog git rebase --apply reflog-onto &&
+	GIT_REFLOG_ACTION=change-the-reflog git rebase reflog-onto &&
 	git log -g --format=%gs -3 >actual &&
 	cat >expect <<-\EOF &&
-	rebase finished: returning to refs/heads/reflog-prefix
-	change-the-reflog: reflog-to-rebase
-	change-the-reflog: checkout reflog-onto
+	change-the-reflog (finish): returning to refs/heads/reflog-prefix
+	change-the-reflog (pick): reflog-to-rebase
+	change-the-reflog (start): checkout reflog-onto
 	EOF
 	test_cmp expect actual
 '

base-commit: 274b9cc25322d9ee79aa8e6d4e86f0ffe5ced925
-- 
gitgitgadget

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

* Re: [PATCH] sequencer: honor GIT_REFLOG_ACTION
  2020-04-01 20:31 [PATCH] sequencer: honor GIT_REFLOG_ACTION Elijah Newren via GitGitGadget
@ 2020-04-01 20:46 ` Junio C Hamano
  2020-04-01 23:29 ` Ian Jackson
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 14+ messages in thread
From: Junio C Hamano @ 2020-04-01 20:46 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget
  Cc: git, jrnieder, elbrus, ijackson, phillip.wood, alban.gruin,
	Johannes.Schindelin, Elijah Newren

"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Elijah Newren <newren@gmail.com>
>
> There is a lot of code to honor GIT_REFLOG_ACTION throughout git,
> including some in sequencer.c; unfortunately, reflog_message() and its
> callers ignored it.  Instruct reflog_message() to check the existing
> environment variable, and use it when present as an override to
> action_name().
>
> Also restructure pick_commits() to only temporarily modify
> GIT_REFLOG_ACTION for a short duration and then restore the old value,

Yeah, I was wondering what you'd be doing about that setenv().  The
code around there looks good.  I briefly wondered what would happen
when the environment variable is totally unset upon entry, but then
we'd have the fallback value of action_name(opts) in there, so we
won't have a risk of running xstrdup(NULL).


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

* Re: [PATCH] sequencer: honor GIT_REFLOG_ACTION
  2020-04-01 20:31 [PATCH] sequencer: honor GIT_REFLOG_ACTION Elijah Newren via GitGitGadget
  2020-04-01 20:46 ` Junio C Hamano
@ 2020-04-01 23:29 ` Ian Jackson
  2020-04-02  5:15   ` Elijah Newren
  2020-04-02  9:25 ` Phillip Wood
  2020-04-07 16:59 ` [PATCH v2] " Elijah Newren via GitGitGadget
  3 siblings, 1 reply; 14+ messages in thread
From: Ian Jackson @ 2020-04-01 23:29 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget
  Cc: git, jrnieder, elbrus, phillip.wood, alban.gruin,
	Johannes.Schindelin, Elijah Newren

Hi.  Thanks for looking at this.

Elijah Newren via GitGitGadget writes ("[PATCH] sequencer: honor GIT_REFLOG_ACTION"):
>     I'm not the best with getenv/setenv. The xstrdup() wrapping is
>     apparently necessary on mac and bsd. The xstrdup seems like it leaves us
>     with a memory leak, but since setenv(3) says to not alter or free it, I
>     think it's right. Anyone have any alternative suggestions?

I can try to help.  It's not entirely trivial.

The setenv interface is a wrapper around putenv.  putenv has had a
variety of different semantics.  Some of these sets of semantics
cannot be used to re-set the same environment variable without a
memory leak - and even figuring out what semantics you have would be
complex and tend to produce code which would fail in bad ways.
There's a short summary of the situation in Linux's putenv(3).

Would it be possible for git to arrange to set GIT_REFLOG_ACTION only
when it is invoking subprocesses ?  Otherwise it would update, and
look at, a global variable of its own.  (Or a parameter to relevant
functions if one doesn't like the action-at-a-distance effect of a
global.)

And, it seems to me that the reflog handling should be centralised.

> +	char *reflog_action = getenv("GIT_REFLOG_ACTION");
>  
>  	va_start(ap, fmt);
>  	strbuf_reset(&buf);
> -	strbuf_addstr(&buf, action_name(opts));
> +	strbuf_addstr(&buf, reflog_action ? reflog_action : action_name(opts));

Open coding this kind of thing at every site which needs to think
about the reflog actions will surely result in some of the instances
having bugs.

Writing a single function that contans this (or most of it) would
happily decouple all of its call sites from literally asking about
getenv("GIT_REFLOG_ACTION") thereby making it easier to do the
indirection-through-program-variables I suggest.

Having said that,

> diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh
> index 61b76f33019..927a4f4a4e4 100755
> --- a/t/t3406-rebase-message.sh
> +++ b/t/t3406-rebase-message.sh

This test case convinces me that the patch has the right behaviour for
at least the case I care about :-).

Thanks,
Ian.

-- 
Ian Jackson <ijackson@chiark.greenend.org.uk>   These opinions are my own.

If I emailed you from an address @fyvzl.net or @evade.org.uk, that is
a private address which bypasses my fierce spamfilter.

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

* Re: [PATCH] sequencer: honor GIT_REFLOG_ACTION
  2020-04-01 23:29 ` Ian Jackson
@ 2020-04-02  5:15   ` Elijah Newren
  2020-04-02  9:39     ` Phillip Wood
  0 siblings, 1 reply; 14+ messages in thread
From: Elijah Newren @ 2020-04-02  5:15 UTC (permalink / raw)
  To: Ian Jackson
  Cc: Elijah Newren via GitGitGadget, Git Mailing List, Jonathan Nieder,
	Paul Gevers, Phillip Wood, Alban Gruin, Johannes Schindelin

On Wed, Apr 1, 2020 at 4:29 PM Ian Jackson
<ijackson@chiark.greenend.org.uk> wrote:
>
> Hi.  Thanks for looking at this.
>
> Elijah Newren via GitGitGadget writes ("[PATCH] sequencer: honor GIT_REFLOG_ACTION"):
> >     I'm not the best with getenv/setenv. The xstrdup() wrapping is
> >     apparently necessary on mac and bsd. The xstrdup seems like it leaves us
> >     with a memory leak, but since setenv(3) says to not alter or free it, I
> >     think it's right. Anyone have any alternative suggestions?
>
> I can try to help.  It's not entirely trivial.
>
> The setenv interface is a wrapper around putenv.  putenv has had a
> variety of different semantics.  Some of these sets of semantics
> cannot be used to re-set the same environment variable without a
> memory leak - and even figuring out what semantics you have would be
> complex and tend to produce code which would fail in bad ways.
> There's a short summary of the situation in Linux's putenv(3).
>
> Would it be possible for git to arrange to set GIT_REFLOG_ACTION only
> when it is invoking subprocesses ?  Otherwise it would update, and
> look at, a global variable of its own.  (Or a parameter to relevant
> functions if one doesn't like the action-at-a-distance effect of a
> global.)
>
> And, it seems to me that the reflog handling should be centralised.
>
> > +     char *reflog_action = getenv("GIT_REFLOG_ACTION");
> >
> >       va_start(ap, fmt);
> >       strbuf_reset(&buf);
> > -     strbuf_addstr(&buf, action_name(opts));
> > +     strbuf_addstr(&buf, reflog_action ? reflog_action : action_name(opts));
>
> Open coding this kind of thing at every site which needs to think
> about the reflog actions will surely result in some of the instances
> having bugs.
>
> Writing a single function that contans this (or most of it) would
> happily decouple all of its call sites from literally asking about
> getenv("GIT_REFLOG_ACTION") thereby making it easier to do the
> indirection-through-program-variables I suggest.

That sounds great, but I'm not sure that "only when invoking
subprocesses" will limit the places where we set the environment
variable all that much; it might actually expand it.  I wasn't there
for the whole history, but my understanding is the rebase code has
slowly transformed from the original all-shell rebase
implementation(s), to being a helper program that the shell could call
into for parts of its operations and passing control back and forth
between shell and C, to being a reimplementation of just invoking the
same commands that the shell script would have, to slowly transforming
into an actual library where invocations of other git subprocesses are
being replaced with relevant function calls.  It's a long cleanup
process that is still ongoing.  I'd like to get to the point where we
only invoke subprocesses if the user specifies --exec or a special
merge strategy, but that's a goal with a longer term timeframe than
fixing a 2.26 regression.

> Having said that,
>
> > diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh
> > index 61b76f33019..927a4f4a4e4 100755
> > --- a/t/t3406-rebase-message.sh
> > +++ b/t/t3406-rebase-message.sh
>
> This test case convinces me that the patch has the right behaviour for
> at least the case I care about :-).

Cool, sounds like it's a good immediate fix for the 2.26 regression,
and then longer term as we continue refactoring we can hopefully
isolate subprocess handling and writing of state.

As a heads up, though, my personal plans for rebase (subject to buy-in
from other stakeholders) is to make it do a lot more in-memory work.
In particular, this means for common cases there will be no subprocess
invocations, no writing of any state unless/until you hit a conflict,
no updating of any files in the working tree until all commits have
been created (or a conflict is hit), and no updating of the branch
until after all the commits have been created.  Thus, for the common
cases with no conflicts, there would only be 1 entry in the reflog of
HEAD the entire operation, rather than approximately 1 per commit.  I
have a proof-of-concept showing these ideas work for basic cases.  So,
I hope your tests don't depend on the number of entries added to
HEAD's reflog.

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

* Re: [PATCH] sequencer: honor GIT_REFLOG_ACTION
  2020-04-01 20:31 [PATCH] sequencer: honor GIT_REFLOG_ACTION Elijah Newren via GitGitGadget
  2020-04-01 20:46 ` Junio C Hamano
  2020-04-01 23:29 ` Ian Jackson
@ 2020-04-02  9:25 ` Phillip Wood
  2020-04-02 17:01   ` Elijah Newren
  2020-04-07 16:59 ` [PATCH v2] " Elijah Newren via GitGitGadget
  3 siblings, 1 reply; 14+ messages in thread
From: Phillip Wood @ 2020-04-02  9:25 UTC (permalink / raw)
  To: Elijah Newren via GitGitGadget, git
  Cc: jrnieder, elbrus, ijackson, phillip.wood, alban.gruin,
	Johannes.Schindelin, Elijah Newren

Hi Elijah

Thanks for fixing this

On 01/04/2020 21:31, Elijah Newren via GitGitGadget wrote:
> From: Elijah Newren <newren@gmail.com>
> 
> There is a lot of code to honor GIT_REFLOG_ACTION throughout git,
> including some in sequencer.c; unfortunately, reflog_message() and its
> callers ignored it.  Instruct reflog_message() to check the existing
> environment variable, and use it when present as an override to
> action_name().
> 
> Also restructure pick_commits() to only temporarily modify
> GIT_REFLOG_ACTION for a short duration and then restore the old value,
> so that when we do this setting within a loop we do not keep adding "
> (pick)" substrings and end up with a reflog message of the form
>      rebase (pick) (pick) (pick) (finish): returning to refs/heads/master
> 
> Signed-off-by: Elijah Newren <newren@gmail.com>
> ---
>      sequencer: honor GIT_REFLOG_ACTION
>      
>      I'm not the best with getenv/setenv. The xstrdup() wrapping is
>      apparently necessary on mac and bsd. The xstrdup seems like it leaves us
>      with a memory leak, but since setenv(3) says to not alter or free it, I
>      think it's right. Anyone have any alternative suggestions?
> 
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-746%2Fnewren%2Fhonor-reflog-action-in-sequencer-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-746/newren/honor-reflog-action-in-sequencer-v1
> Pull-Request: https://github.com/git/git/pull/746
> 
>   sequencer.c               |  9 +++++++--
>   t/t3406-rebase-message.sh | 16 ++++++++--------
>   2 files changed, 15 insertions(+), 10 deletions(-)
> 
> diff --git a/sequencer.c b/sequencer.c
> index e528225e787..5837fdaabbe 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -3708,10 +3708,11 @@ static const char *reflog_message(struct replay_opts *opts,
>   {
>   	va_list ap;
>   	static struct strbuf buf = STRBUF_INIT;
> +	char *reflog_action = getenv("GIT_REFLOG_ACTION");

Minor nit - you're using a string here rather that the pre-processor 
constant that is used below

>   	va_start(ap, fmt);
>   	strbuf_reset(&buf);
> -	strbuf_addstr(&buf, action_name(opts));
> +	strbuf_addstr(&buf, reflog_action ? reflog_action : action_name(opts));
>   	if (sub_action)
>   		strbuf_addf(&buf, " (%s)", sub_action);
>   	if (fmt) {
> @@ -3799,8 +3800,10 @@ static int pick_commits(struct repository *r,
>   			struct replay_opts *opts)
>   {
>   	int res = 0, reschedule = 0;
> +	char *prev_reflog_action;
>   
>   	setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
> +	prev_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));

I'm confused as to why saving the environment variable immediately after 
setting it works but the test shows it does - why doesn't this clobber 
the value of GIT_REFLOG_ACTION set by the user?

Best Wishes

Phillip

>   	if (opts->allow_ff)
>   		assert(!(opts->signoff || opts->no_commit ||
>   				opts->record_origin || opts->edit));
> @@ -3845,12 +3848,14 @@ static int pick_commits(struct repository *r,
>   		}
>   		if (item->command <= TODO_SQUASH) {
>   			if (is_rebase_i(opts))
> -				setenv("GIT_REFLOG_ACTION", reflog_message(opts,
> +				setenv(GIT_REFLOG_ACTION, reflog_message(opts,
>   					command_to_string(item->command), NULL),
>   					1);
>   			res = do_pick_commit(r, item->command, item->commit,
>   					     opts, is_final_fixup(todo_list),
>   					     &check_todo);
> +			if (is_rebase_i(opts))
> +				setenv(GIT_REFLOG_ACTION, prev_reflog_action, 1);
>   			if (is_rebase_i(opts) && res < 0) {
>   				/* Reschedule */
>   				advise(_(rescheduled_advice),
> diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh
> index 61b76f33019..927a4f4a4e4 100755
> --- a/t/t3406-rebase-message.sh
> +++ b/t/t3406-rebase-message.sh
> @@ -89,22 +89,22 @@ test_expect_success 'GIT_REFLOG_ACTION' '
>   	git checkout -b reflog-topic start &&
>   	test_commit reflog-to-rebase &&
>   
> -	git rebase --apply reflog-onto &&
> +	git rebase reflog-onto &&
>   	git log -g --format=%gs -3 >actual &&
>   	cat >expect <<-\EOF &&
> -	rebase finished: returning to refs/heads/reflog-topic
> -	rebase: reflog-to-rebase
> -	rebase: checkout reflog-onto
> +	rebase (finish): returning to refs/heads/reflog-topic
> +	rebase (pick): reflog-to-rebase
> +	rebase (start): checkout reflog-onto
>   	EOF
>   	test_cmp expect actual &&
>   
>   	git checkout -b reflog-prefix reflog-to-rebase &&
> -	GIT_REFLOG_ACTION=change-the-reflog git rebase --apply reflog-onto &&
> +	GIT_REFLOG_ACTION=change-the-reflog git rebase reflog-onto &&
>   	git log -g --format=%gs -3 >actual &&
>   	cat >expect <<-\EOF &&
> -	rebase finished: returning to refs/heads/reflog-prefix
> -	change-the-reflog: reflog-to-rebase
> -	change-the-reflog: checkout reflog-onto
> +	change-the-reflog (finish): returning to refs/heads/reflog-prefix
> +	change-the-reflog (pick): reflog-to-rebase
> +	change-the-reflog (start): checkout reflog-onto
>   	EOF
>   	test_cmp expect actual
>   '
> 
> base-commit: 274b9cc25322d9ee79aa8e6d4e86f0ffe5ced925
> 

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

* Re: [PATCH] sequencer: honor GIT_REFLOG_ACTION
  2020-04-02  5:15   ` Elijah Newren
@ 2020-04-02  9:39     ` Phillip Wood
  2020-04-02 17:40       ` Elijah Newren
  0 siblings, 1 reply; 14+ messages in thread
From: Phillip Wood @ 2020-04-02  9:39 UTC (permalink / raw)
  To: Elijah Newren, Ian Jackson
  Cc: Elijah Newren via GitGitGadget, Git Mailing List, Jonathan Nieder,
	Paul Gevers, Phillip Wood, Alban Gruin, Johannes Schindelin

On 02/04/2020 06:15, Elijah Newren wrote:
> On Wed, Apr 1, 2020 at 4:29 PM Ian Jackson
> <ijackson@chiark.greenend.org.uk> wrote:
>>
>> Hi.  Thanks for looking at this.
>>
>> Elijah Newren via GitGitGadget writes ("[PATCH] sequencer: honor GIT_REFLOG_ACTION"):
>>>      I'm not the best with getenv/setenv. The xstrdup() wrapping is
>>>      apparently necessary on mac and bsd. The xstrdup seems like it leaves us
>>>      with a memory leak, but since setenv(3) says to not alter or free it, I
>>>      think it's right. Anyone have any alternative suggestions?
>>
>> I can try to help.  It's not entirely trivial.
>>
>> The setenv interface is a wrapper around putenv.  putenv has had a
>> variety of different semantics.  Some of these sets of semantics
>> cannot be used to re-set the same environment variable without a
>> memory leak - and even figuring out what semantics you have would be
>> complex and tend to produce code which would fail in bad ways.
>> There's a short summary of the situation in Linux's putenv(3).
>>
>> Would it be possible for git to arrange to set GIT_REFLOG_ACTION only
>> when it is invoking subprocesses ? Otherwise it would update, and >> look at, a global variable of its own.  (Or a parameter to relevant
>> functions if one doesn't like the action-at-a-distance effect of a
>> global.)
>>
>> And, it seems to me that the reflog handling should be centralised.
>>
>>> +     char *reflog_action = getenv("GIT_REFLOG_ACTION");
>>>
>>>        va_start(ap, fmt);
>>>        strbuf_reset(&buf);
>>> -     strbuf_addstr(&buf, action_name(opts));
>>> +     strbuf_addstr(&buf, reflog_action ? reflog_action : action_name(opts));
>>
>> Open coding this kind of thing at every site which needs to think
>> about the reflog actions will surely result in some of the instances
>> having bugs.
>>
>> Writing a single function that contans this (or most of it) would
>> happily decouple all of its call sites from literally asking about
>> getenv("GIT_REFLOG_ACTION") thereby making it easier to do the
>> indirection-through-program-variables I suggest.
> 
> That sounds great, but I'm not sure that "only when invoking
> subprocesses" will limit the places where we set the environment
> variable all that much; it might actually expand it.

Off hand I think we'd need to change run_git_checkout(), 
run_git_commit() and do_merge() to set the environment variable and fix 
try_to_commit() to use a proper variable for the reflog message.

>  I wasn't there
> for the whole history, but my understanding is the rebase code has
> slowly transformed from the original all-shell rebase
> implementation(s), to being a helper program that the shell could call
> into for parts of its operations and passing control back and forth
> between shell and C, to being a reimplementation of just invoking the
> same commands that the shell script would have, to slowly transforming
> into an actual library where invocations of other git subprocesses are
> being replaced with relevant function calls.  It's a long cleanup
> process that is still ongoing.  I'd like to get to the point where we
> only invoke subprocesses if the user specifies --exec or a special
> merge strategy, but that's a goal with a longer term timeframe than
> fixing a 2.26 regression.
> 
>> Having said that,
>>
>>> diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh
>>> index 61b76f33019..927a4f4a4e4 100755
>>> --- a/t/t3406-rebase-message.sh
>>> +++ b/t/t3406-rebase-message.sh
>>
>> This test case convinces me that the patch has the right behaviour for
>> at least the case I care about :-).
> 
> Cool, sounds like it's a good immediate fix for the 2.26 regression,
> and then longer term as we continue refactoring we can hopefully
> isolate subprocess handling and writing of state.
> 
> As a heads up, though, my personal plans for rebase (subject to buy-in
> from other stakeholders) is to make it do a lot more in-memory work.
> In particular, this means for common cases there will be no subprocess
> invocations, no writing of any state unless/until you hit a conflict,
> no updating of any files in the working tree until all commits have
> been created (or a conflict is hit), 

I'm with you up to here - it sounds fantastic

> and no updating of the branch
> until after all the commits have been created.

We only update the branch reflog at the end of the rebase now.

> Thus, for the common
> cases with no conflicts, there would only be 1 entry in the reflog of
> HEAD the entire operation, rather than approximately 1 per commit. 

This I'm not so sure about. In the past where I've messed up a rebase 
and not noticed until after a subsequent rebase it has been really 
useful to be able to go through HEAD's reflog and find out where exactly 
I messed up by looking at the sequence of picks for the first rebase. 
Specifically it shows which commits where squashed together which you 
cannot get by running git log on the result of the rebase.

> I
> have a proof-of-concept showing these ideas work for basic cases. 

Sounds exciting

Best Wishes

Phillip

  So,
> I hope your tests don't depend on the number of entries added to
> HEAD's reflog.
> 

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

* Re: [PATCH] sequencer: honor GIT_REFLOG_ACTION
  2020-04-02  9:25 ` Phillip Wood
@ 2020-04-02 17:01   ` Elijah Newren
  2020-04-02 19:05     ` Phillip Wood
  0 siblings, 1 reply; 14+ messages in thread
From: Elijah Newren @ 2020-04-02 17:01 UTC (permalink / raw)
  To: Phillip Wood
  Cc: Elijah Newren via GitGitGadget, Git Mailing List, Jonathan Nieder,
	Paul Gevers, Ian Jackson, Alban Gruin, Johannes Schindelin

Hi Phillip,

On Thu, Apr 2, 2020 at 2:25 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
>
> Hi Elijah
>
> Thanks for fixing this
>
> On 01/04/2020 21:31, Elijah Newren via GitGitGadget wrote:
> > From: Elijah Newren <newren@gmail.com>
> >
> > There is a lot of code to honor GIT_REFLOG_ACTION throughout git,
> > including some in sequencer.c; unfortunately, reflog_message() and its
> > callers ignored it.  Instruct reflog_message() to check the existing
> > environment variable, and use it when present as an override to
> > action_name().
> >
> > Also restructure pick_commits() to only temporarily modify
> > GIT_REFLOG_ACTION for a short duration and then restore the old value,
> > so that when we do this setting within a loop we do not keep adding "
> > (pick)" substrings and end up with a reflog message of the form
> >      rebase (pick) (pick) (pick) (finish): returning to refs/heads/master
> >
> > Signed-off-by: Elijah Newren <newren@gmail.com>
> > ---
> >      sequencer: honor GIT_REFLOG_ACTION
> >
> >      I'm not the best with getenv/setenv. The xstrdup() wrapping is
> >      apparently necessary on mac and bsd. The xstrdup seems like it leaves us
> >      with a memory leak, but since setenv(3) says to not alter or free it, I
> >      think it's right. Anyone have any alternative suggestions?
> >
> > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-746%2Fnewren%2Fhonor-reflog-action-in-sequencer-v1
> > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-746/newren/honor-reflog-action-in-sequencer-v1
> > Pull-Request: https://github.com/git/git/pull/746
> >
> >   sequencer.c               |  9 +++++++--
> >   t/t3406-rebase-message.sh | 16 ++++++++--------
> >   2 files changed, 15 insertions(+), 10 deletions(-)
> >
> > diff --git a/sequencer.c b/sequencer.c
> > index e528225e787..5837fdaabbe 100644
> > --- a/sequencer.c
> > +++ b/sequencer.c
> > @@ -3708,10 +3708,11 @@ static const char *reflog_message(struct replay_opts *opts,
> >   {
> >       va_list ap;
> >       static struct strbuf buf = STRBUF_INIT;
> > +     char *reflog_action = getenv("GIT_REFLOG_ACTION");
>
> Minor nit - you're using a string here rather that the pre-processor
> constant that is used below

Yeah, true.  However, using a mixture of both styles is consistent
with the current code's inconsistency about which one should be used.
:-)

> >       va_start(ap, fmt);
> >       strbuf_reset(&buf);
> > -     strbuf_addstr(&buf, action_name(opts));
> > +     strbuf_addstr(&buf, reflog_action ? reflog_action : action_name(opts));
> >       if (sub_action)
> >               strbuf_addf(&buf, " (%s)", sub_action);
> >       if (fmt) {
> > @@ -3799,8 +3800,10 @@ static int pick_commits(struct repository *r,
> >                       struct replay_opts *opts)
> >   {
> >       int res = 0, reschedule = 0;
> > +     char *prev_reflog_action;
> >
> >       setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
> > +     prev_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
>
> I'm confused as to why saving the environment variable immediately after
> setting it works but the test shows it does - why doesn't this clobber
> the value of GIT_REFLOG_ACTION set by the user?

The third parameter, 0, means only set the environment variable if
it's not already set.

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

* Re: [PATCH] sequencer: honor GIT_REFLOG_ACTION
  2020-04-02  9:39     ` Phillip Wood
@ 2020-04-02 17:40       ` Elijah Newren
  0 siblings, 0 replies; 14+ messages in thread
From: Elijah Newren @ 2020-04-02 17:40 UTC (permalink / raw)
  To: Phillip Wood
  Cc: Ian Jackson, Elijah Newren via GitGitGadget, Git Mailing List,
	Jonathan Nieder, Paul Gevers, Alban Gruin, Johannes Schindelin

Hi Phillip,

On Thu, Apr 2, 2020 at 2:39 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
>
> On 02/04/2020 06:15, Elijah Newren wrote:

> > As a heads up, though, my personal plans for rebase (subject to buy-in
> > from other stakeholders) is to make it do a lot more in-memory work.
> > In particular, this means for common cases there will be no subprocess
> > invocations, no writing of any state unless/until you hit a conflict,
> > no updating of any files in the working tree until all commits have
> > been created (or a conflict is hit),
>
> I'm with you up to here - it sounds fantastic
>
> > and no updating of the branch
> > until after all the commits have been created.
>
> We only update the branch reflog at the end of the rebase now.
>
> > Thus, for the common
> > cases with no conflicts, there would only be 1 entry in the reflog of
> > HEAD the entire operation, rather than approximately 1 per commit.
>
> This I'm not so sure about. In the past where I've messed up a rebase
> and not noticed until after a subsequent rebase it has been really
> useful to be able to go through HEAD's reflog and find out where exactly
> I messed up by looking at the sequence of picks for the first rebase.
> Specifically it shows which commits where squashed together which you
> cannot get by running git log on the result of the rebase.

Interesting.   Hmm....

> > I
> > have a proof-of-concept showing these ideas work for basic cases.
>
> Sounds exciting

Feel free to take a look: See
https://github.com/newren/git/blob/git-merge-2020-demo/README.md and
https://github.com/newren/git/blob/git-merge-2020-demo/builtin/fast-rebase.c

Sadly, between sparse-checkout, expoential slowdown in dir.c, and
various reports about rebase for 2.26, I haven't been able to work on
that stuff since the morning of March 4.  And I've been ignoring some
non-git stuff that I really need to work on.  But hopefully I'll get
to start cleaning things up soon and sending them on to the list for
review.  I keep hoping...

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

* Re: [PATCH] sequencer: honor GIT_REFLOG_ACTION
  2020-04-02 17:01   ` Elijah Newren
@ 2020-04-02 19:05     ` Phillip Wood
  2020-04-07 14:50       ` Johannes Schindelin
  0 siblings, 1 reply; 14+ messages in thread
From: Phillip Wood @ 2020-04-02 19:05 UTC (permalink / raw)
  To: Elijah Newren, Phillip Wood
  Cc: Elijah Newren via GitGitGadget, Git Mailing List, Jonathan Nieder,
	Paul Gevers, Ian Jackson, Alban Gruin, Johannes Schindelin

Hi Elijah

On 02/04/2020 18:01, Elijah Newren wrote:
> Hi Phillip,
> 
> On Thu, Apr 2, 2020 at 2:25 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
>>
>> Hi Elijah
>>
>> Thanks for fixing this
>>
>> On 01/04/2020 21:31, Elijah Newren via GitGitGadget wrote:
>>> From: Elijah Newren <newren@gmail.com>
>>>
>>> There is a lot of code to honor GIT_REFLOG_ACTION throughout git,
>>> including some in sequencer.c; unfortunately, reflog_message() and its
>>> callers ignored it.  Instruct reflog_message() to check the existing
>>> environment variable, and use it when present as an override to
>>> action_name().
>>>
>>> Also restructure pick_commits() to only temporarily modify
>>> GIT_REFLOG_ACTION for a short duration and then restore the old value,
>>> so that when we do this setting within a loop we do not keep adding "
>>> (pick)" substrings and end up with a reflog message of the form
>>>       rebase (pick) (pick) (pick) (finish): returning to refs/heads/master
>>>
>>> Signed-off-by: Elijah Newren <newren@gmail.com>
>>> ---
>>>       sequencer: honor GIT_REFLOG_ACTION
>>>
>>>       I'm not the best with getenv/setenv. The xstrdup() wrapping is
>>>       apparently necessary on mac and bsd. The xstrdup seems like it leaves us
>>>       with a memory leak, but since setenv(3) says to not alter or free it, I
>>>       think it's right. Anyone have any alternative suggestions?
>>>
>>> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-746%2Fnewren%2Fhonor-reflog-action-in-sequencer-v1
>>> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-746/newren/honor-reflog-action-in-sequencer-v1
>>> Pull-Request: https://github.com/git/git/pull/746
>>>
>>>    sequencer.c               |  9 +++++++--
>>>    t/t3406-rebase-message.sh | 16 ++++++++--------
>>>    2 files changed, 15 insertions(+), 10 deletions(-)
>>>
>>> diff --git a/sequencer.c b/sequencer.c
>>> index e528225e787..5837fdaabbe 100644
>>> --- a/sequencer.c
>>> +++ b/sequencer.c
>>> @@ -3708,10 +3708,11 @@ static const char *reflog_message(struct replay_opts *opts,
>>>    {
>>>        va_list ap;
>>>        static struct strbuf buf = STRBUF_INIT;
>>> +     char *reflog_action = getenv("GIT_REFLOG_ACTION");
>>
>> Minor nit - you're using a string here rather that the pre-processor
>> constant that is used below
> 
> Yeah, true.  However, using a mixture of both styles is consistent
> with the current code's inconsistency about which one should be used.
> :-)

Nice!

>>>        va_start(ap, fmt);
>>>        strbuf_reset(&buf);
>>> -     strbuf_addstr(&buf, action_name(opts));
>>> +     strbuf_addstr(&buf, reflog_action ? reflog_action : action_name(opts));
>>>        if (sub_action)
>>>                strbuf_addf(&buf, " (%s)", sub_action);
>>>        if (fmt) {
>>> @@ -3799,8 +3800,10 @@ static int pick_commits(struct repository *r,
>>>                        struct replay_opts *opts)
>>>    {
>>>        int res = 0, reschedule = 0;
>>> +     char *prev_reflog_action;
>>>
>>>        setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
>>> +     prev_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
>>
>> I'm confused as to why saving the environment variable immediately after
>> setting it works but the test shows it does - why doesn't this clobber
>> the value of GIT_REFLOG_ACTION set by the user?
> 
> The third parameter, 0, means only set the environment variable if
> it's not already set.

Ah thanks, I thought I must be missing something fairly obvious but 
couldn't see what it was

Best Wishes

Phillip


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

* Re: [PATCH] sequencer: honor GIT_REFLOG_ACTION
  2020-04-02 19:05     ` Phillip Wood
@ 2020-04-07 14:50       ` Johannes Schindelin
  2020-04-07 15:18         ` Elijah Newren
  0 siblings, 1 reply; 14+ messages in thread
From: Johannes Schindelin @ 2020-04-07 14:50 UTC (permalink / raw)
  To: Phillip Wood
  Cc: Elijah Newren, Elijah Newren via GitGitGadget, Git Mailing List,
	Jonathan Nieder, Paul Gevers, Ian Jackson, Alban Gruin

Hi,

On Thu, 2 Apr 2020, Phillip Wood wrote:

> On 02/04/2020 18:01, Elijah Newren wrote:
> >
> > On Thu, Apr 2, 2020 at 2:25 AM Phillip Wood <phillip.wood123@gmail.com>
> > wrote:
> > >
> > > On 01/04/2020 21:31, Elijah Newren via GitGitGadget wrote:
> > >
> > > >        va_start(ap, fmt);
> > > >        strbuf_reset(&buf);
> > > > -     strbuf_addstr(&buf, action_name(opts));
> > > > +     strbuf_addstr(&buf, reflog_action ? reflog_action :
> > > > action_name(opts));
> > > >        if (sub_action)
> > > >                strbuf_addf(&buf, " (%s)", sub_action);
> > > >        if (fmt) {
> > > > @@ -3799,8 +3800,10 @@ static int pick_commits(struct repository *r,
> > > >                        struct replay_opts *opts)
> > > >    {
> > > >        int res = 0, reschedule = 0;
> > > > +     char *prev_reflog_action;
> > > >
> > > >        setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
> > > > +     prev_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
> > >
> > > I'm confused as to why saving the environment variable immediately after
> > > setting it works but the test shows it does - why doesn't this clobber
> > > the value of GIT_REFLOG_ACTION set by the user?
> >
> > The third parameter, 0, means only set the environment variable if
> > it's not already set.
>
> Ah thanks, I thought I must be missing something fairly obvious but couldn't
> see what it was

FWIW I was also about to comment on that. Maybe that warrants even a code
comment above the `prev_reflog_action`?

Ciao,
Dscho

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

* Re: [PATCH] sequencer: honor GIT_REFLOG_ACTION
  2020-04-07 14:50       ` Johannes Schindelin
@ 2020-04-07 15:18         ` Elijah Newren
  2020-04-07 22:37           ` Johannes Schindelin
  0 siblings, 1 reply; 14+ messages in thread
From: Elijah Newren @ 2020-04-07 15:18 UTC (permalink / raw)
  To: Johannes Schindelin
  Cc: Phillip Wood, Elijah Newren via GitGitGadget, Git Mailing List,
	Jonathan Nieder, Paul Gevers, Ian Jackson, Alban Gruin

On Tue, Apr 7, 2020 at 7:50 AM Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
>
> Hi,
>
> On Thu, 2 Apr 2020, Phillip Wood wrote:
>
> > On 02/04/2020 18:01, Elijah Newren wrote:
> > >
> > > On Thu, Apr 2, 2020 at 2:25 AM Phillip Wood <phillip.wood123@gmail.com>
> > > wrote:
> > > >
> > > > On 01/04/2020 21:31, Elijah Newren via GitGitGadget wrote:
> > > >
> > > > >        va_start(ap, fmt);
> > > > >        strbuf_reset(&buf);
> > > > > -     strbuf_addstr(&buf, action_name(opts));
> > > > > +     strbuf_addstr(&buf, reflog_action ? reflog_action :
> > > > > action_name(opts));
> > > > >        if (sub_action)
> > > > >                strbuf_addf(&buf, " (%s)", sub_action);
> > > > >        if (fmt) {
> > > > > @@ -3799,8 +3800,10 @@ static int pick_commits(struct repository *r,
> > > > >                        struct replay_opts *opts)
> > > > >    {
> > > > >        int res = 0, reschedule = 0;
> > > > > +     char *prev_reflog_action;
> > > > >
> > > > >        setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
> > > > > +     prev_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
> > > >
> > > > I'm confused as to why saving the environment variable immediately after
> > > > setting it works but the test shows it does - why doesn't this clobber
> > > > the value of GIT_REFLOG_ACTION set by the user?
> > >
> > > The third parameter, 0, means only set the environment variable if
> > > it's not already set.
> >
> > Ah thanks, I thought I must be missing something fairly obvious but couldn't
> > see what it was
>
> FWIW I was also about to comment on that. Maybe that warrants even a code
> comment above the `prev_reflog_action`?

Yeah, if it tripped you both up, I'll add such a comment to the code
to help explain it.

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

* [PATCH v2] sequencer: honor GIT_REFLOG_ACTION
  2020-04-01 20:31 [PATCH] sequencer: honor GIT_REFLOG_ACTION Elijah Newren via GitGitGadget
                   ` (2 preceding siblings ...)
  2020-04-02  9:25 ` Phillip Wood
@ 2020-04-07 16:59 ` Elijah Newren via GitGitGadget
  3 siblings, 0 replies; 14+ messages in thread
From: Elijah Newren via GitGitGadget @ 2020-04-07 16:59 UTC (permalink / raw)
  To: git
  Cc: jrnieder, elbrus, ijackson, phillip.wood, alban.gruin,
	Johannes.Schindelin, Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

There is a lot of code to honor GIT_REFLOG_ACTION throughout git,
including some in sequencer.c; unfortunately, reflog_message() and its
callers ignored it.  Instruct reflog_message() to check the existing
environment variable, and use it when present as an override to
action_name().

Also restructure pick_commits() to only temporarily modify
GIT_REFLOG_ACTION for a short duration and then restore the old value,
so that when we do this setting within a loop we do not keep adding "
(pick)" substrings and end up with a reflog message of the form
    rebase (pick) (pick) (pick) (finish): returning to refs/heads/master

Signed-off-by: Elijah Newren <newren@gmail.com>
---
    sequencer: honor GIT_REFLOG_ACTION
    
    Changes since v1:
    
     * Just use preprocessor constant (instead of mix of it and string
       constant)
     * Add a comment next to code that surprised both Phillip and Dscho

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-746%2Fnewren%2Fhonor-reflog-action-in-sequencer-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-746/newren/honor-reflog-action-in-sequencer-v2
Pull-Request: https://github.com/git/git/pull/746

Range-diff vs v1:

 1:  5c6d74af194 ! 1:  a12cc2d2c3a sequencer: honor GIT_REFLOG_ACTION
     @@ sequencer.c: static const char *reflog_message(struct replay_opts *opts,
       {
       	va_list ap;
       	static struct strbuf buf = STRBUF_INIT;
     -+	char *reflog_action = getenv("GIT_REFLOG_ACTION");
     ++	char *reflog_action = getenv(GIT_REFLOG_ACTION);
       
       	va_start(ap, fmt);
       	strbuf_reset(&buf);
     @@ sequencer.c: static int pick_commits(struct repository *r,
       	int res = 0, reschedule = 0;
      +	char *prev_reflog_action;
       
     ++	/* Note that 0 for 3rd parameter of setenv means set only if not set */
       	setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
      +	prev_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
       	if (opts->allow_ff)


 sequencer.c               | 10 ++++++++--
 t/t3406-rebase-message.sh | 16 ++++++++--------
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index e528225e787..24a62d5aa5d 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -3708,10 +3708,11 @@ static const char *reflog_message(struct replay_opts *opts,
 {
 	va_list ap;
 	static struct strbuf buf = STRBUF_INIT;
+	char *reflog_action = getenv(GIT_REFLOG_ACTION);
 
 	va_start(ap, fmt);
 	strbuf_reset(&buf);
-	strbuf_addstr(&buf, action_name(opts));
+	strbuf_addstr(&buf, reflog_action ? reflog_action : action_name(opts));
 	if (sub_action)
 		strbuf_addf(&buf, " (%s)", sub_action);
 	if (fmt) {
@@ -3799,8 +3800,11 @@ static int pick_commits(struct repository *r,
 			struct replay_opts *opts)
 {
 	int res = 0, reschedule = 0;
+	char *prev_reflog_action;
 
+	/* Note that 0 for 3rd parameter of setenv means set only if not set */
 	setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
+	prev_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
 	if (opts->allow_ff)
 		assert(!(opts->signoff || opts->no_commit ||
 				opts->record_origin || opts->edit));
@@ -3845,12 +3849,14 @@ static int pick_commits(struct repository *r,
 		}
 		if (item->command <= TODO_SQUASH) {
 			if (is_rebase_i(opts))
-				setenv("GIT_REFLOG_ACTION", reflog_message(opts,
+				setenv(GIT_REFLOG_ACTION, reflog_message(opts,
 					command_to_string(item->command), NULL),
 					1);
 			res = do_pick_commit(r, item->command, item->commit,
 					     opts, is_final_fixup(todo_list),
 					     &check_todo);
+			if (is_rebase_i(opts))
+				setenv(GIT_REFLOG_ACTION, prev_reflog_action, 1);
 			if (is_rebase_i(opts) && res < 0) {
 				/* Reschedule */
 				advise(_(rescheduled_advice),
diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh
index 61b76f33019..927a4f4a4e4 100755
--- a/t/t3406-rebase-message.sh
+++ b/t/t3406-rebase-message.sh
@@ -89,22 +89,22 @@ test_expect_success 'GIT_REFLOG_ACTION' '
 	git checkout -b reflog-topic start &&
 	test_commit reflog-to-rebase &&
 
-	git rebase --apply reflog-onto &&
+	git rebase reflog-onto &&
 	git log -g --format=%gs -3 >actual &&
 	cat >expect <<-\EOF &&
-	rebase finished: returning to refs/heads/reflog-topic
-	rebase: reflog-to-rebase
-	rebase: checkout reflog-onto
+	rebase (finish): returning to refs/heads/reflog-topic
+	rebase (pick): reflog-to-rebase
+	rebase (start): checkout reflog-onto
 	EOF
 	test_cmp expect actual &&
 
 	git checkout -b reflog-prefix reflog-to-rebase &&
-	GIT_REFLOG_ACTION=change-the-reflog git rebase --apply reflog-onto &&
+	GIT_REFLOG_ACTION=change-the-reflog git rebase reflog-onto &&
 	git log -g --format=%gs -3 >actual &&
 	cat >expect <<-\EOF &&
-	rebase finished: returning to refs/heads/reflog-prefix
-	change-the-reflog: reflog-to-rebase
-	change-the-reflog: checkout reflog-onto
+	change-the-reflog (finish): returning to refs/heads/reflog-prefix
+	change-the-reflog (pick): reflog-to-rebase
+	change-the-reflog (start): checkout reflog-onto
 	EOF
 	test_cmp expect actual
 '

base-commit: 274b9cc25322d9ee79aa8e6d4e86f0ffe5ced925
-- 
gitgitgadget

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

* Re: [PATCH] sequencer: honor GIT_REFLOG_ACTION
  2020-04-07 15:18         ` Elijah Newren
@ 2020-04-07 22:37           ` Johannes Schindelin
  2020-04-07 23:05             ` Junio C Hamano
  0 siblings, 1 reply; 14+ messages in thread
From: Johannes Schindelin @ 2020-04-07 22:37 UTC (permalink / raw)
  To: Elijah Newren
  Cc: Phillip Wood, Elijah Newren via GitGitGadget, Git Mailing List,
	Jonathan Nieder, Paul Gevers, Ian Jackson, Alban Gruin

Hi Elijah,

On Tue, 7 Apr 2020, Elijah Newren wrote:

> On Tue, Apr 7, 2020 at 7:50 AM Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
> >
> > On Thu, 2 Apr 2020, Phillip Wood wrote:
> >
> > > On 02/04/2020 18:01, Elijah Newren wrote:
> > > >
> > > > On Thu, Apr 2, 2020 at 2:25 AM Phillip Wood <phillip.wood123@gmail.com>
> > > > wrote:
> > > > >
> > > > > On 01/04/2020 21:31, Elijah Newren via GitGitGadget wrote:
> > > > >
> > > > > >        va_start(ap, fmt);
> > > > > >        strbuf_reset(&buf);
> > > > > > -     strbuf_addstr(&buf, action_name(opts));
> > > > > > +     strbuf_addstr(&buf, reflog_action ? reflog_action :
> > > > > > action_name(opts));
> > > > > >        if (sub_action)
> > > > > >                strbuf_addf(&buf, " (%s)", sub_action);
> > > > > >        if (fmt) {
> > > > > > @@ -3799,8 +3800,10 @@ static int pick_commits(struct repository *r,
> > > > > >                        struct replay_opts *opts)
> > > > > >    {
> > > > > >        int res = 0, reschedule = 0;
> > > > > > +     char *prev_reflog_action;
> > > > > >
> > > > > >        setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
> > > > > > +     prev_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
> > > > >
> > > > > I'm confused as to why saving the environment variable immediately after
> > > > > setting it works but the test shows it does - why doesn't this clobber
> > > > > the value of GIT_REFLOG_ACTION set by the user?
> > > >
> > > > The third parameter, 0, means only set the environment variable if
> > > > it's not already set.
> > >
> > > Ah thanks, I thought I must be missing something fairly obvious but couldn't
> > > see what it was
> >
> > FWIW I was also about to comment on that. Maybe that warrants even a code
> > comment above the `prev_reflog_action`?
>
> Yeah, if it tripped you both up, I'll add such a comment to the code
> to help explain it.

Thank you!
Dscho

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

* Re: [PATCH] sequencer: honor GIT_REFLOG_ACTION
  2020-04-07 22:37           ` Johannes Schindelin
@ 2020-04-07 23:05             ` Junio C Hamano
  0 siblings, 0 replies; 14+ messages in thread
From: Junio C Hamano @ 2020-04-07 23:05 UTC (permalink / raw)
  To: Johannes Schindelin
  Cc: Elijah Newren, Phillip Wood, Elijah Newren via GitGitGadget,
	Git Mailing List, Jonathan Nieder, Paul Gevers, Ian Jackson,
	Alban Gruin

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

>> > FWIW I was also about to comment on that. Maybe that warrants even a code
>> > comment above the `prev_reflog_action`?
>>
>> Yeah, if it tripped you both up, I'll add such a comment to the code
>> to help explain it.
>
> Thank you!

Thanks, all.

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

end of thread, other threads:[~2020-04-07 23:05 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-01 20:31 [PATCH] sequencer: honor GIT_REFLOG_ACTION Elijah Newren via GitGitGadget
2020-04-01 20:46 ` Junio C Hamano
2020-04-01 23:29 ` Ian Jackson
2020-04-02  5:15   ` Elijah Newren
2020-04-02  9:39     ` Phillip Wood
2020-04-02 17:40       ` Elijah Newren
2020-04-02  9:25 ` Phillip Wood
2020-04-02 17:01   ` Elijah Newren
2020-04-02 19:05     ` Phillip Wood
2020-04-07 14:50       ` Johannes Schindelin
2020-04-07 15:18         ` Elijah Newren
2020-04-07 22:37           ` Johannes Schindelin
2020-04-07 23:05             ` Junio C Hamano
2020-04-07 16:59 ` [PATCH v2] " Elijah Newren via GitGitGadget

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).