git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Johannes Sixt <j.sixt@viscovery.net>
Cc: Ramkumar Ramachandra <artagnon@gmail.com>,
	Git List <git@vger.kernel.org>
Subject: Re: [PATCH v2 6/7] rebase: write better reflog messages
Date: Wed, 19 Jun 2013 09:58:40 -0700	[thread overview]
Message-ID: <7vy5a611hb.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: 51C1442A.2010904@viscovery.net

Johannes Sixt <j.sixt@viscovery.net> writes:

> Am 6/18/2013 20:55, schrieb Ramkumar Ramachandra:
>> Now that the "checkout" invoked internally from "rebase" knows to honor
>> GIT_REFLOG_ACTION, we can start to use it to write a better reflog
>> message when "rebase anotherbranch", "rebase --onto branch",
>> etc. internally checks out the new fork point.  We will write:
>> 
>>   rebase: checkout master
>> 
>> instead of the old
>> 
>>   rebase
>
>> diff --git a/git-rebase--am.sh b/git-rebase--am.sh
>> index 34e3102..69fae7a 100644
>> --- a/git-rebase--am.sh
>> +++ b/git-rebase--am.sh
>> @@ -5,11 +5,13 @@
>>  
>>  case "$action" in
>>  continue)
>> +	GIT_REFLOG_ACTION="$base_reflog_action"
>
> I haven't followed the topic closely, but I wonder why there are so many
> explicit assignments to GIT_REFLOG_ACTION. Is calling set_reflog_action
> (defined in git-sh-setup) the wrong thing to do?

Excellent question, and I think this illustrates why the recent
reroll that uses an approach to use base_reflog_action is not
complete and needs further work (to put it mildly).

set_reflog_action is designed to be used once at the very top of a
program, like this in "git am", for example:

	set_reflog_action am

The helper function sets the given string to GIT_REFLOG_ACTION only
when GIT_REFLOG_ACTION is not yet set.  Thanks to this, "git am",
when run as the top-level program, will use "am" in GIT_REFLOG_ACTION
and the reflog entries made by whatever it does will say "am did this".

Because of the conditional assignment, when "git am" is run as a
subprogram (i.e. an implementation detail) of "git rebase", the call
to the helper function at the beginning will *not* have any effect.
So "git rebase" can do this:

	set_reflog_action rebase
	... do its own preparation, like checking out "onto" commit
        ... decide to do "format-patch" to "am" pipeline
        	git format-patch --stdout >mbox
		git am mbox

and the reflog entries made inside "git am" invocation will say
"rebase", not "am".

The approach to introduce base_reflog_action may be valid, but if we
were to go that route, set_reflog_action needs to learn the new
convention.  Perhaps by doing something like this:

 1. set_reflog_action to set GIT_REFLOG_NAME and GIT_REFLOG_ACTION;
    Program names like "am", "rebase" will be set to this value.

 2. If the program does not want to say anything more than its
    program name in the reflog, it does not have to do anything.
    GIT_REFLOG_ACTION that is set upfront (or inherited from the
    calling program) will be written in the reflog.

 3. If the program wants to say more than just its name, it needs to
    arrange GIT_REFLOG_ACTION not to be clobbered.  It can do so in
    various ways:

   a) A one-shot invocation of any program that writes to reflog can
      do:

	GIT_REFLOG_ACTION="$GIT_REFLOG_NAME: custom message" \
        	git cmd

      An important thing is that GIT_REFLOG_ACTION is left as the
      original, i.e. "am" or "rebase", so that calls to programs that
      write reflog using the default (i.e. program name only) will
      not be affected.

   b) Or it can temporarily change it and revert it back (necessary
      to use shell function like "output" that cannot use the above
      "single shot export" technique):

	GIT_REFLOG_ACTION="$GIT_REFLOG_NAME: custom message"
        output git cmd
 	GIT_REFLOG_ACTION=$GIT_REFLOG_NAME

But after writing it down this way, I realize that introduction of
base_reflog_action (or GIT_REFLOG_NAME which is a moral equivalent)
is not helping us at all.  As long as calls to "git" command in the
second category exists in these scripts, GIT_REFLOG_ACTION *must* be
kept pristine after set_reflog_action sets it, so we can get rid of
this new variable, and rewrite 3.a and 3.b like so:

    3-a)

	GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: custom message" \
        	git cmd

    3-b)

	SAVED=$GIT_REFLOG_ACTION
	GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: custom message"
        output git cmd
 	GIT_REFLOG_ACTION=$SAVED

	    or

	(
                GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: custom message"
                output git cmd
	)

That essentially boils down to the very original suggestion I made
before Ram introduced the base_reflog_action.

  parent reply	other threads:[~2013-06-19 16:59 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-18 18:55 [PATCH v2 0/7] Re-roll rr/rebase-checkout-reflog Ramkumar Ramachandra
2013-06-18 18:55 ` [PATCH v2 1/7] t/t7512-status-help: test "HEAD detached from" Ramkumar Ramachandra
2013-06-18 18:55 ` [PATCH v2 2/7] wt-status: remove unused field in grab_1st_switch_cbdata Ramkumar Ramachandra
2013-06-18 18:55 ` [PATCH v2 3/7] t/t2012-checkout-last: test "checkout -" after a rebase Ramkumar Ramachandra
2013-06-18 18:55 ` [PATCH v2 4/7] status: do not depend on rebase reflog messages Ramkumar Ramachandra
2013-06-18 18:55 ` [PATCH v2 5/7] checkout: respect GIT_REFLOG_ACTION Ramkumar Ramachandra
2013-06-18 18:55 ` [PATCH v2 6/7] rebase: write better reflog messages Ramkumar Ramachandra
2013-06-18 20:35   ` Junio C Hamano
2013-06-19  5:39   ` Johannes Sixt
2013-06-19  6:09     ` Ramkumar Ramachandra
2013-06-19  6:24       ` Johannes Sixt
2013-06-19 16:58     ` Junio C Hamano [this message]
2013-06-19 17:53       ` Junio C Hamano
2013-06-19 18:29         ` Junio C Hamano
2013-06-18 18:55 ` [PATCH v2 7/7] rebase -i: " Ramkumar Ramachandra
2013-06-18 20:36   ` Junio C Hamano
2013-06-18 20:38     ` Ramkumar Ramachandra
2013-06-18 20:55       ` Junio C Hamano
2013-06-19  4:07         ` Ramkumar Ramachandra

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=7vy5a611hb.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=j.sixt@viscovery.net \
    /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.
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).