* [PATCH] launch_editor(): allow spaces in the filename
@ 2008-03-10 20:42 Johannes Schindelin
2008-03-10 21:32 ` Johannes Sixt
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: Johannes Schindelin @ 2008-03-10 20:42 UTC (permalink / raw)
To: Zeng.Shixin, theevancarroll, git, gitster
For some reason, the construct
sh -c "$0 \"$@\"" <editor> <file>
does not pick up quotes in <editor> as expected. So replace $0 with
<editor>.
This fixes
git config core.editor "c:/Program Files/What/Ever.exe"
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
Incidentally, this fixes issue 78 in msysGit.
Zeng (is this the correct way to address you?), Evan, please test.
builtin-tag.c | 6 +++++-
t/t7005-editor.sh | 28 ++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletions(-)
diff --git a/builtin-tag.c b/builtin-tag.c
index 28c36fd..8dd959f 100644
--- a/builtin-tag.c
+++ b/builtin-tag.c
@@ -50,12 +50,15 @@ void launch_editor(const char *path, struct strbuf *buffer, const char *const *e
size_t len = strlen(editor);
int i = 0;
const char *args[6];
+ struct strbuf arg0;
+ strbuf_init(&arg0, 0);
if (strcspn(editor, "$ \t'") != len) {
/* there are specials */
+ strbuf_addf(&arg0, "%s \"$@\"", editor);
args[i++] = "sh";
args[i++] = "-c";
- args[i++] = "$0 \"$@\"";
+ args[i++] = arg0.buf;
}
args[i++] = editor;
args[i++] = path;
@@ -63,6 +66,7 @@ void launch_editor(const char *path, struct strbuf *buffer, const char *const *e
if (run_command_v_opt_cd_env(args, 0, NULL, env))
die("There was a problem with the editor %s.", editor);
+ strbuf_release(&arg0);
}
if (!buffer)
diff --git a/t/t7005-editor.sh b/t/t7005-editor.sh
index c1cec55..5395b74 100755
--- a/t/t7005-editor.sh
+++ b/t/t7005-editor.sh
@@ -89,6 +89,34 @@ do
'
done
+test_expect_success 'editor with a space' '
+
+ if echo "echo space > \"\$1\"" > "e space.sh"
+ then
+ chmod a+x "e space.sh" &&
+ GIT_EDITOR="./e\ space.sh" \
+ git --exec-path=. commit --amend &&
+ test space = "$(git show -s --pretty=format:%s)"
+ else
+ say "Skipping; FS does not support spaces in filenames"
+ fi
+
+'
+
+unset GIT_EDITOR
+test_expect_success 'core.editor with a space' '
+
+ if test -f "e space.sh"
+ then
+ git config core.editor \"./e\ space.sh\" &&
+ git --exec-path=. commit --amend &&
+ test space = "$(git show -s --pretty=format:%s)"
+ else
+ say "Skipping; FS does not support spaces in filenames"
+ fi
+
+'
+
TERM="$OLD_TERM"
test_done
--
1.5.4.4.643.g7cb9b.dirty
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] launch_editor(): allow spaces in the filename
2008-03-10 20:42 [PATCH] launch_editor(): allow spaces in the filename Johannes Schindelin
@ 2008-03-10 21:32 ` Johannes Sixt
2008-03-10 21:37 ` Junio C Hamano
2008-03-10 22:18 ` Johannes Schindelin
2008-03-10 21:33 ` Junio C Hamano
` (2 subsequent siblings)
3 siblings, 2 replies; 11+ messages in thread
From: Johannes Sixt @ 2008-03-10 21:32 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Zeng.Shixin, theevancarroll, git, gitster
On Monday 10 March 2008 21:42, Johannes Schindelin wrote:
> For some reason, the construct
>
> sh -c "$0 \"$@\"" <editor> <file>
>
> does not pick up quotes in <editor> as expected. So replace $0 with
> <editor>.
No surprise. It must be
sh -c '"$0" "$@"' <editor> <file>
Note the extra quotes around $0.
> args[i++] = "sh";
> args[i++] = "-c";
> - args[i++] = "$0 \"$@\"";
> + args[i++] = arg0.buf;
IOW:
+ args[i++] = "\"$0\" \"$@\"";
-- Hannes
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] launch_editor(): allow spaces in the filename
2008-03-10 20:42 [PATCH] launch_editor(): allow spaces in the filename Johannes Schindelin
2008-03-10 21:32 ` Johannes Sixt
@ 2008-03-10 21:33 ` Junio C Hamano
2008-03-10 21:42 ` Junio C Hamano
2008-03-11 0:15 ` Junio C Hamano
3 siblings, 0 replies; 11+ messages in thread
From: Junio C Hamano @ 2008-03-10 21:33 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Zeng.Shixin, theevancarroll, git
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> For some reason, the construct
>
> sh -c "$0 \"$@\"" <editor> <file>
>
> does not pick up quotes in <editor> as expected. So replace $0 with
> <editor>.
That's not "for some reason" but "I am asking shell to split", and
sh -c '"$@"' ignoreme <editor> <files>...
would work better ;-).
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] launch_editor(): allow spaces in the filename
2008-03-10 21:32 ` Johannes Sixt
@ 2008-03-10 21:37 ` Junio C Hamano
2008-03-10 21:46 ` Johannes Sixt
2008-03-10 22:18 ` Johannes Schindelin
1 sibling, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2008-03-10 21:37 UTC (permalink / raw)
To: Johannes Sixt
Cc: Johannes Schindelin, Zeng.Shixin, theevancarroll, git, gitster
Johannes Sixt <johannes.sixt@telecom.at> writes:
> On Monday 10 March 2008 21:42, Johannes Schindelin wrote:
>> For some reason, the construct
>>
>> sh -c "$0 \"$@\"" <editor> <file>
>>
>> does not pick up quotes in <editor> as expected. So replace $0 with
>> <editor>.
>
> No surprise. It must be
>
> sh -c '"$0" "$@"' <editor> <file>
>
> Note the extra quotes around $0.
... assuming that there is no dq, $var_reference and other nastiness in
<editor> ;-)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] launch_editor(): allow spaces in the filename
2008-03-10 20:42 [PATCH] launch_editor(): allow spaces in the filename Johannes Schindelin
2008-03-10 21:32 ` Johannes Sixt
2008-03-10 21:33 ` Junio C Hamano
@ 2008-03-10 21:42 ` Junio C Hamano
2008-03-10 21:48 ` Junio C Hamano
2008-03-11 0:15 ` Junio C Hamano
3 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2008-03-10 21:42 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Zeng.Shixin, theevancarroll, git
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> For some reason, the construct
>
> sh -c "$0 \"$@\"" <editor> <file>
>
> does not pick up quotes in <editor> as expected. So replace $0 with
> <editor>.
>
> This fixes
>
> git config core.editor "c:/Program Files/What/Ever.exe"
>
Having sent a few messages about shell quoting, it makes me wonder if this
was done very deliberately in the first place, so that you can do things
like:
git config core.editor "emacs -nw"
Blame followed by list archive hunting around that timeperiod would tell.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] launch_editor(): allow spaces in the filename
2008-03-10 21:37 ` Junio C Hamano
@ 2008-03-10 21:46 ` Johannes Sixt
0 siblings, 0 replies; 11+ messages in thread
From: Johannes Sixt @ 2008-03-10 21:46 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Johannes Schindelin, Zeng.Shixin, theevancarroll
On Monday 10 March 2008 22:37, Junio C Hamano wrote:
> Johannes Sixt <johannes.sixt@telecom.at> writes:
> > On Monday 10 March 2008 21:42, Johannes Schindelin wrote:
> >> For some reason, the construct
> >>
> >> sh -c "$0 \"$@\"" <editor> <file>
> >>
> >> does not pick up quotes in <editor> as expected. So replace $0 with
> >> <editor>.
> >
> > No surprise. It must be
> >
> > sh -c '"$0" "$@"' <editor> <file>
> >
> > Note the extra quotes around $0.
>
> ... assuming that there is no dq, $var_reference and other nastiness in
> <editor> ;-)
They are not a problem; there isn't yet another level of evaluation. I just
tried with an <editor> that goes by this name:
f "$DISPLAY"b
and I got the expected result, i.e. it was found and executed.
-- Hannes
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] launch_editor(): allow spaces in the filename
2008-03-10 21:42 ` Junio C Hamano
@ 2008-03-10 21:48 ` Junio C Hamano
2008-03-10 22:24 ` Johannes Schindelin
0 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2008-03-10 21:48 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Zeng.Shixin, theevancarroll, git
Junio C Hamano <gitster@pobox.com> writes:
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> ...
>> This fixes
>>
>> git config core.editor "c:/Program Files/What/Ever.exe"
>>
>
> Having sent a few messages about shell quoting, it makes me wonder if this
> was done very deliberately in the first place, so that you can do things
> like:
>
> git config core.editor "emacs -nw"
>
> Blame followed by list archive hunting around that timeperiod would tell.
I'll let others look for the bug report and user request from the list
archive, but the pertinent commit is 5e2de4f9 (Fix $EDITOR regression
introduced by rewrite in C.):
When git-tag and git-commit launches the editor, they used to
honor EDITOR="editor -options args..." but recent rewrite in C
insisted on $EDITOR to be the path to the editor executable.
This restores the older behaviour.
In other words, your example is a user error and your patch is a
regression.
I guess the right way to do that would be:
git config core.editor '"c:/Program Files/What/Ever.exe"'
but I do not do windows, so this is obviously untested.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] launch_editor(): allow spaces in the filename
2008-03-10 21:32 ` Johannes Sixt
2008-03-10 21:37 ` Junio C Hamano
@ 2008-03-10 22:18 ` Johannes Schindelin
1 sibling, 0 replies; 11+ messages in thread
From: Johannes Schindelin @ 2008-03-10 22:18 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Zeng.Shixin, theevancarroll, git, gitster
Hi,
On Mon, 10 Mar 2008, Johannes Sixt wrote:
> On Monday 10 March 2008 21:42, Johannes Schindelin wrote:
> > For some reason, the construct
> >
> > sh -c "$0 \"$@\"" <editor> <file>
> >
> > does not pick up quotes in <editor> as expected. So replace $0 with
> > <editor>.
>
> No surprise. It must be
>
> sh -c '"$0" "$@"' <editor> <file>
>
> Note the extra quotes around $0.
>
> > args[i++] = "sh";
> > args[i++] = "-c";
> > - args[i++] = "$0 \"$@\"";
> > + args[i++] = arg0.buf;
>
> IOW:
>
> + args[i++] = "\"$0\" \"$@\"";
Isn't this wrong? What would this do with a core.editor like this:
[core]
editor = this-editor --with-this --option
Hmm?
Ciao,
Dscho
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] launch_editor(): allow spaces in the filename
2008-03-10 21:48 ` Junio C Hamano
@ 2008-03-10 22:24 ` Johannes Schindelin
0 siblings, 0 replies; 11+ messages in thread
From: Johannes Schindelin @ 2008-03-10 22:24 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Zeng.Shixin, theevancarroll, git
Hi,
On Mon, 10 Mar 2008, Junio C Hamano wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
> > Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> > ...
> >> This fixes
> >>
> >> git config core.editor "c:/Program Files/What/Ever.exe"
> >>
> >
> > Having sent a few messages about shell quoting, it makes me wonder if this
> > was done very deliberately in the first place, so that you can do things
> > like:
> >
> > git config core.editor "emacs -nw"
> >
> > Blame followed by list archive hunting around that timeperiod would tell.
>
> I'll let others look for the bug report and user request from the list
> archive, but the pertinent commit is 5e2de4f9 (Fix $EDITOR regression
> introduced by rewrite in C.):
>
> When git-tag and git-commit launches the editor, they used to
> honor EDITOR="editor -options args..." but recent rewrite in C
> insisted on $EDITOR to be the path to the editor executable.
>
> This restores the older behaviour.
>
> In other words, your example is a user error and your patch is a
> regression.
I was well aware of that commit when I wrote the patch, but...
> I guess the right way to do that would be:
>
> git config core.editor '"c:/Program Files/What/Ever.exe"'
>
> but I do not do windows, so this is obviously untested.
Ooops. The commit message I gave did not escape the double quotes, but I
_meant_ to, promise! So yes, it was my intention that
git config core.editor \"C:/Program\ Files/vim/vim71/gvim.exe\"
works, but
git config core.editor "C:/Program Files/vim/vim71/gvim.exe"
does not. Note that the test was written correctly.
Sorry,
Dscho
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] launch_editor(): allow spaces in the filename
2008-03-10 20:42 [PATCH] launch_editor(): allow spaces in the filename Johannes Schindelin
` (2 preceding siblings ...)
2008-03-10 21:42 ` Junio C Hamano
@ 2008-03-11 0:15 ` Junio C Hamano
2008-03-11 9:56 ` Johannes Schindelin
3 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2008-03-11 0:15 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Zeng.Shixin, theevancarroll, git
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> For some reason, the construct
>
> sh -c "$0 \"$@\"" <editor> <file>
>
> does not pick up quotes in <editor> as expected. So replace $0 with
> <editor>.
>
> This fixes
>
> git config core.editor "c:/Program Files/What/Ever.exe"
Ah, I misread your patch. The above example needs to be fixed as
discussed, but what the patch does to builtin-tag.c is fine.
> diff --git a/t/t7005-editor.sh b/t/t7005-editor.sh
> index c1cec55..5395b74 100755
> --- a/t/t7005-editor.sh
> +++ b/t/t7005-editor.sh
> @@ -89,6 +89,34 @@ do
> '
> done
>
> +test_expect_success 'editor with a space' '
> +
> + if echo "echo space > \"\$1\"" > "e space.sh"
> + then
> + chmod a+x "e space.sh" &&
> + GIT_EDITOR="./e\ space.sh" \
> + git --exec-path=. commit --amend &&
Why do you need --exec-path=. to tell the newly built git to find its
subcommands from t/trash directory, when you give an explicit instruction
to find GIT_EDITOR in "./"?
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] launch_editor(): allow spaces in the filename
2008-03-11 0:15 ` Junio C Hamano
@ 2008-03-11 9:56 ` Johannes Schindelin
0 siblings, 0 replies; 11+ messages in thread
From: Johannes Schindelin @ 2008-03-11 9:56 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Zeng.Shixin, theevancarroll, git
For some reason, the construct
sh -c "$0 \"$@\"" <editor> <file>
does not pick up quotes in <editor> as expected. So replace $0 with
<editor>.
This fixes
git config core.editor '"c:/Program Files/What/Ever.exe"'
In other words, you can specify an editor with spaces in its path using a
config containing something like this:
[core]
editor = \"c:/Program Files/Darn/Spaces.exe\"
NOTE: we cannot just replace the $0 with \"$0\", because we still want
this to work:
[core]
editor = emacs -nw
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
On Mon, 10 Mar 2008, Junio C Hamano wrote:
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
> > For some reason, the construct
> >
> > sh -c "$0 \"$@\"" <editor> <file>
> >
> > does not pick up quotes in <editor> as expected. So replace
> > $0 with <editor>.
> >
> > This fixes
> >
> > git config core.editor "c:/Program Files/What/Ever.exe"
>
> Ah, I misread your patch. The above example needs to be fixed
> as discussed, but what the patch does to builtin-tag.c is fine.
Here comes the fixed commit message and...
> > diff --git a/t/t7005-editor.sh b/t/t7005-editor.sh
> > index c1cec55..5395b74 100755
> > --- a/t/t7005-editor.sh
> > +++ b/t/t7005-editor.sh
> > @@ -89,6 +89,34 @@ do
> > '
> > done
> >
> > +test_expect_success 'editor with a space' '
> > +
> > + if echo "echo space > \"\$1\"" > "e space.sh"
> > + then
> > + chmod a+x "e space.sh" &&
> > + GIT_EDITOR="./e\ space.sh" \
> > + git --exec-path=. commit --amend &&
>
> Why do you need --exec-path=. to tell the newly built git to
> find its subcommands from t/trash directory, when you give an explicit
> instruction to find GIT_EDITOR in "./"?
... the fixed tests.
I copied this piece from the earlier tests. Probably it is only
needed to avoid "vi" from being found in the PATH (--exec-path's argument
is prepended to the PATH).
builtin-tag.c | 6 +++++-
t/t7005-editor.sh | 27 +++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletions(-)
diff --git a/builtin-tag.c b/builtin-tag.c
index 28c36fd..8dd959f 100644
--- a/builtin-tag.c
+++ b/builtin-tag.c
@@ -50,12 +50,15 @@ void launch_editor(const char *path, struct strbuf *buffer, const char *const *e
size_t len = strlen(editor);
int i = 0;
const char *args[6];
+ struct strbuf arg0;
+ strbuf_init(&arg0, 0);
if (strcspn(editor, "$ \t'") != len) {
/* there are specials */
+ strbuf_addf(&arg0, "%s \"$@\"", editor);
args[i++] = "sh";
args[i++] = "-c";
- args[i++] = "$0 \"$@\"";
+ args[i++] = arg0.buf;
}
args[i++] = editor;
args[i++] = path;
@@ -63,6 +66,7 @@ void launch_editor(const char *path, struct strbuf *buffer, const char *const *e
if (run_command_v_opt_cd_env(args, 0, NULL, env))
die("There was a problem with the editor %s.", editor);
+ strbuf_release(&arg0);
}
if (!buffer)
diff --git a/t/t7005-editor.sh b/t/t7005-editor.sh
index c1cec55..6a74b3a 100755
--- a/t/t7005-editor.sh
+++ b/t/t7005-editor.sh
@@ -89,6 +89,33 @@ do
'
done
+test_expect_success 'editor with a space' '
+
+ if echo "echo space > \"\$1\"" > "e space.sh"
+ then
+ chmod a+x "e space.sh" &&
+ GIT_EDITOR="./e\ space.sh" git commit --amend &&
+ test space = "$(git show -s --pretty=format:%s)"
+ else
+ say "Skipping; FS does not support spaces in filenames"
+ fi
+
+'
+
+unset GIT_EDITOR
+test_expect_success 'core.editor with a space' '
+
+ if test -f "e space.sh"
+ then
+ git config core.editor \"./e\ space.sh\" &&
+ git commit --amend &&
+ test space = "$(git show -s --pretty=format:%s)"
+ else
+ say "Skipping; FS does not support spaces in filenames"
+ fi
+
+'
+
TERM="$OLD_TERM"
test_done
--
1.5.4.4.643.g7cb9b.dirty
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2008-03-11 9:57 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-10 20:42 [PATCH] launch_editor(): allow spaces in the filename Johannes Schindelin
2008-03-10 21:32 ` Johannes Sixt
2008-03-10 21:37 ` Junio C Hamano
2008-03-10 21:46 ` Johannes Sixt
2008-03-10 22:18 ` Johannes Schindelin
2008-03-10 21:33 ` Junio C Hamano
2008-03-10 21:42 ` Junio C Hamano
2008-03-10 21:48 ` Junio C Hamano
2008-03-10 22:24 ` Johannes Schindelin
2008-03-11 0:15 ` Junio C Hamano
2008-03-11 9:56 ` Johannes Schindelin
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 NNTP newsgroup(s).