Re: Bug: git-p4 edit_template() and P4EDITOR w/options
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 4, 2015, 22:38 UTC
- Message-ID
- <xmqqzj5knf2t.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <xmqq4mnsottj.fsf@gitster.dls.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 34 quoted lines
> 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])