Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Chris Lasell <chrisl@pixar.com>
Cc: git@vger.kernel.org
Subject: Re: Bug: git-p4 edit_template() and P4EDITOR w/options
Date: Mon, 04 May 2015 15:38:34 -0700	[thread overview]
Message-ID: <xmqqzj5knf2t.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <xmqq4mnsottj.fsf@gitster.dls.corp.google.com> (Junio C. Hamano's message of "Mon, 04 May 2015 15:34:48 -0700")

Junio C Hamano <gitster@pobox.com> writes:

> Junio C Hamano <gitster@pobox.com> writes:
>
>> The relevant part of git-p4 is this:
>>
>>         # invoke the editor
>>         if os.environ.has_key("P4EDITOR") and (os.environ.get("P4EDITOR") != ""):
>>             editor = os.environ.get("P4EDITOR")
>>         else:
>>             editor = read_pipe("git var GIT_EDITOR").strip()
>>         system([editor, template_file])
>>
>> It grabs $EDITOR (or $GIT_EDITOR) and treats it as the path to the
>> editor executable, without letting shell to split that into words at
>> whitespace boundaries, so that you can say things like
>>
>> 	EDITOR="/User/me/My Programs/nano"
>>
>> The way we spawn EDITOR in our core codepaths matches what git-p4
>> does, too:
>>
>> 	const char *args[] = { editor, real_path(path), NULL };
>> 	struct child_process p = CHILD_PROCESS_INIT;
>> 	int ret, sig;
>>
>> 	p.argv = args;
>> 	p.env = env;
>> 	p.use_shell = 1;
>> 	if (start_command(&p) < 0)
>> 		return error("unable to start editor '%s'", editor);
>> 	...
>>
>> So...
>
> Well, I'll take that back.  I misread p.use_shell line.

So, use_shell==true codepath grabs that array with "editor", "path"
and turns it into an equivalent to

	sh -c "$EDITOR" "$path"

when $EDITOR has a "magic" character (including whitespace) in it.
So what git-p4 does is *not* in line with how we use the environment
variable.

Perhaps a single-liner patch like this would work?

-	system([editor, template_file])
+	system(["sh", "-c", editor, template_file])

  reply	other threads:[~2015-05-04 22:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-04 21:26 Bug: git-p4 edit_template() and P4EDITOR w/options Chris Lasell
2015-05-04 22:01 ` Junio C Hamano
2015-05-04 22:34   ` Junio C Hamano
2015-05-04 22:38     ` Junio C Hamano [this message]
2015-05-04 22:44       ` Junio C Hamano
2015-05-04 23:11         ` Jonathan Nieder
2015-05-05  0:22           ` Junio C Hamano
2015-05-04 22:46       ` Chris Lasell

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=xmqqzj5knf2t.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=chrisl@pixar.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