All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, Paul Tan <pyokagan@gmail.com>
Subject: Re: [PATCH 2/3] pager: factor out a helper to prepare a child process to run the pager
Date: Tue, 16 Feb 2016 15:49:55 -0800	[thread overview]
Message-ID: <xmqqk2m4kyfw.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20160216232657.GB18634@sigill.intra.peff.net> (Jeff King's message of "Tue, 16 Feb 2016 18:26:58 -0500")

Jeff King <peff@peff.net> writes:

> On Tue, Feb 16, 2016 at 03:06:56PM -0800, Junio C Hamano wrote:
>
>> diff --git a/pager.c b/pager.c
>> index 5dbcc5a..1406370 100644
>> --- a/pager.c
>> +++ b/pager.c
>> @@ -53,6 +53,23 @@ const char *git_pager(int stdout_is_tty)
>>  	return pager;
>>  }
>>  
>> +void prepare_pager_args(struct child_process *pager_process, ...)
>> +{
>> +	va_list ap;
>> +	const char *arg;
>> +
>> +	va_start(ap, pager_process);
>> +	while ((arg = va_arg(ap, const char *)))
>> +		argv_array_push(&pager_process->args, arg);
>> +	va_end(ap);
>> +
>> +	pager_process->use_shell = 1;
>> +	if (!getenv("LESS"))
>> +		argv_array_push(&pager_process->env_array, "LESS=FRX");
>> +	if (!getenv("LV"))
>> +		argv_array_push(&pager_process->env_array, "LV=-c");
>> +}
>
> When reading this, I had to wonder what the "..." args were supposed to
> be. I figured it out when I read the caller, but I wonder if a comment
> would help. Also, we are expecting the pager here as the first argument,
> so maybe:
>
>   void prepare_pager_args(struct child_process *pager_process,
>                           const char *pager, ...);
>
> would be a better signature.

;-)

I had that originally, and then incorrectly fed pager to va_start()
which broke the whole thing.

> That also made me wonder if we could simply
> get away with:
>
>   void prepare_pager_args(struct child_process *pager_process,
>                           const char *pager);
>
> and have callers argv_array_push() themselves afterwards.

After all that may be a nicer way to structure.

> And if you put the git_pager() call inside prepare_pager_args (which I
> agree would be cleaner), we just have:
>
>   void prepare_pager_args(struct child_process *pager_process);
>
> which is pretty self-explanatory (though it might need a new name; I'd
> be tempted to call it init_pager_process() or something, and actually
> have it do the child_process_init() to make sure it is working with a
> sane clean slate).

Conceptually I am on the same page, but I am not sure how well that
interacts with what "git am -i" codepath wants to do, though.

One big difference between the "we'll feed our output to pager"
codepath and "we'll spawn a pager to let a file on the filesystem be
read" codepath is that the former needs to call git_pager() and
check the NULL-ness of the return value to decide that it does not
want to spawn a pager and let the standard output just go straight
to the outside world.  The latter, on the other hand, does want to
spawn something to cause the file to be presented to the end user
even git_pager() returns NULL.

And that is why I didn't make this helper call git_pager() itself.

  reply	other threads:[~2016-02-16 23:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-16 23:06 [PATCH 0/3] fix "v"iew subcommand in "git am -i" Junio C Hamano
2016-02-16 23:06 ` [PATCH 1/3] pager: lose a separate argv[] Junio C Hamano
2016-02-16 23:06 ` [PATCH 2/3] pager: factor out a helper to prepare a child process to run the pager Junio C Hamano
2016-02-16 23:26   ` Jeff King
2016-02-16 23:49     ` Junio C Hamano [this message]
2016-02-17  0:32       ` Jeff King
2016-02-16 23:06 ` [PATCH 3/3] am -i: fix "v"iew Junio C Hamano
2016-02-17 19:15 ` [PATCH v2 0/3] fix "v"iew subcommand in "git am -i" Junio C Hamano
2016-02-17 19:15   ` [PATCH v2 1/3] pager: lose a separate argv[] Junio C Hamano
2016-02-17 19:15   ` [PATCH v2 2/3] pager: factor out a helper to prepare a child process to run the pager Junio C Hamano
2016-02-17 19:15   ` [PATCH v2 3/3] am -i: fix "v"iew Junio C Hamano
2016-02-17 19:19   ` [PATCH v2 0/3] fix "v"iew subcommand in "git am -i" Jeff King

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=xmqqk2m4kyfw.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=pyokagan@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.