git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Make '!' aliases more useful
@ 2007-07-01 21:51 Johannes Schindelin
  2007-07-02 14:55 ` Theodore Tso
  0 siblings, 1 reply; 11+ messages in thread
From: Johannes Schindelin @ 2007-07-01 21:51 UTC (permalink / raw)
  To: git, gitster


When an alias starts with an exclamation mark, the rest is interpreted
as a shell command. However, all arguments passed to git used to be
ignored.

Now you can have an alias like

	$ git config alias.e '!echo'

and

	$ git e Hello World

does what you expect it to do.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---

	I have this in my $HOME/.gitconfig:

		[alias]
			debug = !GIT_PAGER= gdb --args git

	which allows me to debug, say "git log a..b" by saying "git debug 
	log a..b".

 git.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/git.c b/git.c
index 8ea70da..32e8aa9 100644
--- a/git.c
+++ b/git.c
@@ -205,6 +205,21 @@ static int handle_alias(int *argcp, const char ***argv)
 	git_config(git_alias_config);
 	if (alias_string) {
 		if (alias_string[0] == '!') {
+			if (*argcp > 1) {
+				int i, sz = PATH_MAX;
+				char *s = xmalloc(sz), *new_alias = s;
+
+				add_to_string(&s, &sz, alias_string, 0);
+				free(alias_string);
+				alias_string = new_alias;
+				for (i = 1; i < *argcp &&
+					!add_to_string(&s, &sz, " ", 0) &&
+					!add_to_string(&s, &sz, (*argv)[i], 1)
+					; i++)
+					; /* do nothing */
+				if (!sz)
+					die("Too many or long arguments");
+			}
 			trace_printf("trace: alias to shell cmd: %s => %s\n",
 				     alias_command, alias_string + 1);
 			ret = system(alias_string + 1);
-- 
1.5.2.2.3276.gf2524-dirty

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] Make '!' aliases more useful
  2007-07-01 21:51 [PATCH] Make '!' aliases more useful Johannes Schindelin
@ 2007-07-02 14:55 ` Theodore Tso
  2007-07-02 15:55   ` Johannes Schindelin
  0 siblings, 1 reply; 11+ messages in thread
From: Theodore Tso @ 2007-07-02 14:55 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git, gitster

On Sun, Jul 01, 2007 at 10:51:58PM +0100, Johannes Schindelin wrote:
> 
> When an alias starts with an exclamation mark, the rest is interpreted
> as a shell command. However, all arguments passed to git used to be
> ignored.
> 
> Now you can have an alias like
> 
> 	$ git config alias.e '!echo'
> 
> and
> 
> 	$ git e Hello World
> 
> does what you expect it to do.

But what if you don't want the argument passed at the end of the
alias, but somewhere else?  I suspect the better answer would be to
support $* and $1, $2, $3, et. al interpolation, no?  It was on my
list of things to do when I had a spare moment, but I never got around
to it.

					- Ted

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Make '!' aliases more useful
  2007-07-02 14:55 ` Theodore Tso
@ 2007-07-02 15:55   ` Johannes Schindelin
  2007-07-02 16:08     ` Theodore Tso
  0 siblings, 1 reply; 11+ messages in thread
From: Johannes Schindelin @ 2007-07-02 15:55 UTC (permalink / raw)
  To: Theodore Tso; +Cc: git, gitster

Hi,

On Mon, 2 Jul 2007, Theodore Tso wrote:

> On Sun, Jul 01, 2007 at 10:51:58PM +0100, Johannes Schindelin wrote:
> > 
> > When an alias starts with an exclamation mark, the rest is interpreted
> > as a shell command. However, all arguments passed to git used to be
> > ignored.
> > 
> > Now you can have an alias like
> > 
> > 	$ git config alias.e '!echo'
> > 
> > and
> > 
> > 	$ git e Hello World
> > 
> > does what you expect it to do.
> 
> But what if you don't want the argument passed at the end of the
> alias, but somewhere else?  I suspect the better answer would be to
> support $* and $1, $2, $3, et. al interpolation, no?  It was on my
> list of things to do when I had a spare moment, but I never got around
> to it.

There is a point where you do not want to complicate git, but rather write 
a script. This is such a point IMHO.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Make '!' aliases more useful
  2007-07-02 15:55   ` Johannes Schindelin
@ 2007-07-02 16:08     ` Theodore Tso
  2007-07-02 23:11       ` Junio C Hamano
  2007-07-03  7:07       ` Alex Riesen
  0 siblings, 2 replies; 11+ messages in thread
From: Theodore Tso @ 2007-07-02 16:08 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git, gitster

On Mon, Jul 02, 2007 at 04:55:24PM +0100, Johannes Schindelin wrote:
> > But what if you don't want the argument passed at the end of the
> > alias, but somewhere else?  I suspect the better answer would be to
> > support $* and $1, $2, $3, et. al interpolation, no?  It was on my
> > list of things to do when I had a spare moment, but I never got around
> > to it.
> 
> There is a point where you do not want to complicate git, but rather write 
> a script. This is such a point IMHO.

Such a point exists, I agree, but I would draw after $* and $1/$2/$3
interpolation.  There is a lot more value that gets added with
positional arguments support, and it makes git aliases more usable on
platforms such as Windows where scripting capability is much more
limited.

Regards,

					- Ted

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Make '!' aliases more useful
  2007-07-02 16:08     ` Theodore Tso
@ 2007-07-02 23:11       ` Junio C Hamano
  2007-07-03  1:14         ` Theodore Tso
  2007-07-03  7:07       ` Alex Riesen
  1 sibling, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2007-07-02 23:11 UTC (permalink / raw)
  To: Theodore Tso; +Cc: Johannes Schindelin, git, gitster

Theodore Tso <tytso@mit.edu> writes:

> On Mon, Jul 02, 2007 at 04:55:24PM +0100, Johannes Schindelin wrote:
>> > But what if you don't want the argument passed at the end of the
>> > alias, but somewhere else?  I suspect the better answer would be to
>> > support $* and $1, $2, $3, et. al interpolation, no?  It was on my
>> > list of things to do when I had a spare moment, but I never got around
>> > to it.
>> 
>> There is a point where you do not want to complicate git, but rather write 
>> a script. This is such a point IMHO.
>
> Such a point exists, I agree, but I would draw after $* and $1/$2/$3
> interpolation.  There is a lot more value that gets added with
> positional arguments support, and it makes git aliases more usable on
> platforms such as Windows where scripting capability is much more
> limited.

That actually sounds sensible, but you could alias

	!sh -c 'command $2 $1 $3'

to reorder the parameters, couldn't you?
	

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Make '!' aliases more useful
  2007-07-02 23:11       ` Junio C Hamano
@ 2007-07-03  1:14         ` Theodore Tso
  2007-07-03  1:37           ` Johannes Schindelin
  2007-07-03  7:24           ` Johannes Sixt
  0 siblings, 2 replies; 11+ messages in thread
From: Theodore Tso @ 2007-07-03  1:14 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Johannes Schindelin, git

On Mon, Jul 02, 2007 at 04:11:21PM -0700, Junio C Hamano wrote:
> > Such a point exists, I agree, but I would draw after $* and $1/$2/$3
> > interpolation.  There is a lot more value that gets added with
> > positional arguments support, and it makes git aliases more usable on
> > platforms such as Windows where scripting capability is much more
> > limited.
> 
> That actually sounds sensible, but you could alias
> 
> 	!sh -c 'command $2 $1 $3'
> 
> to reorder the parameters, couldn't you?

Um, how would that work on the Windows platform?

(I'm assuming here that we are trying to support Windows better, since
there are projects such as Mozilla, and MySQL that care very much
about first class Windows support.  We could say this isn't important
enough, and that would be fine; but I wanted to at least raise the
question.)

						- Ted

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Make '!' aliases more useful
  2007-07-03  1:14         ` Theodore Tso
@ 2007-07-03  1:37           ` Johannes Schindelin
  2007-07-03 12:10             ` Theodore Tso
  2007-07-03  7:24           ` Johannes Sixt
  1 sibling, 1 reply; 11+ messages in thread
From: Johannes Schindelin @ 2007-07-03  1:37 UTC (permalink / raw)
  To: Theodore Tso; +Cc: Junio C Hamano, git

Hi,

On Mon, 2 Jul 2007, Theodore Tso wrote:

> On Mon, Jul 02, 2007 at 04:11:21PM -0700, Junio C Hamano wrote:
> > > Such a point exists, I agree, but I would draw after $* and $1/$2/$3
> > > interpolation.  There is a lot more value that gets added with
> > > positional arguments support, and it makes git aliases more usable on
> > > platforms such as Windows where scripting capability is much more
> > > limited.
> > 
> > That actually sounds sensible, but you could alias
> > 
> > 	!sh -c 'command $2 $1 $3'
> > 
> > to reorder the parameters, couldn't you?
> 
> Um, how would that work on the Windows platform?
> 
> (I'm assuming here that we are trying to support Windows better, since
> there are projects such as Mozilla, and MySQL that care very much
> about first class Windows support.  We could say this isn't important
> enough, and that would be fine; but I wanted to at least raise the
> question.)

Windows support for those people unwilling to use cygwin amounts to 
anything, but a command line interface. Since aliases are _bound_ to 
the command line, I do not really get your point here.

In my view of things, for Windows support it is first of all important to 
get rid of the dependency on bash in the core parts. Then we should 
continue on the work Han-Wen did with his gub, and produce a proper 
Windows-clicky-style installer which installs git-gui with a proper 
Windows Start Menu item. But of course, then we should brace ourselves for 
a lot of clueless^Winterested users.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Make '!' aliases more useful
  2007-07-02 16:08     ` Theodore Tso
  2007-07-02 23:11       ` Junio C Hamano
@ 2007-07-03  7:07       ` Alex Riesen
  2007-07-03 11:27         ` Johannes Schindelin
  1 sibling, 1 reply; 11+ messages in thread
From: Alex Riesen @ 2007-07-03  7:07 UTC (permalink / raw)
  To: Theodore Tso; +Cc: Johannes Schindelin, git, gitster

On 7/2/07, Theodore Tso <tytso@mit.edu> wrote:
> On Mon, Jul 02, 2007 at 04:55:24PM +0100, Johannes Schindelin wrote:
> > > But what if you don't want the argument passed at the end of the
> > > alias, but somewhere else?  I suspect the better answer would be to
> > > support $* and $1, $2, $3, et. al interpolation, no?  It was on my
> > > list of things to do when I had a spare moment, but I never got around
> > > to it.
> >
> > There is a point where you do not want to complicate git, but rather write
> > a script. This is such a point IMHO.
>
> Such a point exists, I agree, but I would draw after $* and $1/$2/$3
> interpolation.  There is a lot more value that gets added with
> positional arguments support, and it makes git aliases more usable on
> platforms such as Windows where scripting capability is much more
> limited.

I don't think it is _possible_ to make it work on Windows properly: you have
to quote the arguments with whitespaces as there is nothing like argv there
(windows programs don't use command line, so it does not exist).
As the quoting is implemented in the programs the rules are all different
and mostly suboptimal.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Make '!' aliases more useful
  2007-07-03  1:14         ` Theodore Tso
  2007-07-03  1:37           ` Johannes Schindelin
@ 2007-07-03  7:24           ` Johannes Sixt
  1 sibling, 0 replies; 11+ messages in thread
From: Johannes Sixt @ 2007-07-03  7:24 UTC (permalink / raw)
  To: Theodore Tso; +Cc: git, Johannes Schindelin, Junio C Hamano

Theodore Tso wrote:
> 
> On Mon, Jul 02, 2007 at 04:11:21PM -0700, Junio C Hamano wrote:
> > > Such a point exists, I agree, but I would draw after $* and $1/$2/$3
> > > interpolation.  There is a lot more value that gets added with
> > > positional arguments support, and it makes git aliases more usable on
> > > platforms such as Windows where scripting capability is much more
> > > limited.
> >
> > That actually sounds sensible, but you could alias
> >
> >       !sh -c 'command $2 $1 $3'
> >
> > to reorder the parameters, couldn't you?
> 
> Um, how would that work on the Windows platform?

Shouldn't be a problem for Cygwin users, nor for MinGW port users. The
latter need a Bourne shell anyway for the various scripted git tools.

-- Hannes

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Make '!' aliases more useful
  2007-07-03  7:07       ` Alex Riesen
@ 2007-07-03 11:27         ` Johannes Schindelin
  0 siblings, 0 replies; 11+ messages in thread
From: Johannes Schindelin @ 2007-07-03 11:27 UTC (permalink / raw)
  To: Alex Riesen; +Cc: Theodore Tso, git, gitster

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2082 bytes --]

Hi,

On Tue, 3 Jul 2007, Alex Riesen wrote:

> On 7/2/07, Theodore Tso <tytso@mit.edu> wrote:
> > On Mon, Jul 02, 2007 at 04:55:24PM +0100, Johannes Schindelin wrote:
> > > > But what if you don't want the argument passed at the end of the
> > > > alias, but somewhere else?  I suspect the better answer would be to
> > > > support $* and $1, $2, $3, et. al interpolation, no?  It was on my
> > > > list of things to do when I had a spare moment, but I never got around
> > > > to it.
> > >
> > > There is a point where you do not want to complicate git, but rather
> > write
> > > a script. This is such a point IMHO.
> > 
> > Such a point exists, I agree, but I would draw after $* and $1/$2/$3
> > interpolation.  There is a lot more value that gets added with
> > positional arguments support, and it makes git aliases more usable on
> > platforms such as Windows where scripting capability is much more
> > limited.
> 
> I don't think it is _possible_ to make it work on Windows properly: you have
> to quote the arguments with whitespaces as there is nothing like argv there
> (windows programs don't use command line, so it does not exist).

Since the "!" aliases use system() (i.e. no argv, but a plain string as 
parameter), my patch already does that. It quotes the arguments properly.

> As the quoting is implemented in the programs the rules are all different
> and mostly suboptimal.

You mean the programs that could be called via "!" aliases? Yes, that is 
right. And there is also the problem that you have to convert path names 
if you are working on Windows, because of this c:\&@!§$ braindamage.

However, in this case Junio's idea to use the shell to do the hard work is 
again an alternative:

	[alias]
		alex = !sh -c 'd:\program.exe $(cygpath -w "$1")'

FWIW I do not think that executing the shell from time to time is a big 
problem. It's only that I would like to get rid of the dependency on perl 
and bash for the plain Windows user, who will not dare to leave the gui 
into the command line jungle where there be bisons, yaccs and kills.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Make '!' aliases more useful
  2007-07-03  1:37           ` Johannes Schindelin
@ 2007-07-03 12:10             ` Theodore Tso
  0 siblings, 0 replies; 11+ messages in thread
From: Theodore Tso @ 2007-07-03 12:10 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Junio C Hamano, git

On Tue, Jul 03, 2007 at 02:37:43AM +0100, Johannes Schindelin wrote:
> Windows support for those people unwilling to use cygwin amounts to 
> anything, but a command line interface. Since aliases are _bound_ to 
> the command line, I do not really get your point here.

You're right of course.  <small>Never mind...</small>

						- Ted

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-07-03 12:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-01 21:51 [PATCH] Make '!' aliases more useful Johannes Schindelin
2007-07-02 14:55 ` Theodore Tso
2007-07-02 15:55   ` Johannes Schindelin
2007-07-02 16:08     ` Theodore Tso
2007-07-02 23:11       ` Junio C Hamano
2007-07-03  1:14         ` Theodore Tso
2007-07-03  1:37           ` Johannes Schindelin
2007-07-03 12:10             ` Theodore Tso
2007-07-03  7:24           ` Johannes Sixt
2007-07-03  7:07       ` Alex Riesen
2007-07-03 11:27         ` 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).