threads / patch / 23700

patchSet GIT_PATHNAME_PREFIX with aliases.

Subject: [PATCH] Set GIT_PATHNAME_PREFIX with aliases.

## tl;dr

23 messages between May 5, 2010 and May 6, 2010. Diffs are folded; open one to read it.

replies: 22people: 9as markdown or json

Jared Hance· May 5, 2010, 00:25 UTC · lore

The environment variable GIT_PATHNAME_PREFIX passes on the current working directory (where the git command was called from) to shell aliases (aliases that begin with "!"). This allows these shell aliases to know the directory that the git command was called from.

Signed-off-by: Jared Hance <jaredhance@gmail.com>
---
 git.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
Show changes to git.c +3 −0
diff --git a/git.c b/git.c
index 6bae305..836f753 100644
--- a/git.c
+++ b/git.c
@@ -167,6 +167,9 @@ static int handle_alias(int *argcp, const char ***argv)
 				free(alias_string);
 				alias_string = buf.buf;
 			}
+			static char current_dir[PATH_MAX+1];
+			setenv("GIT_PATHNAME_PREFIX", getcwd(current_dir, sizeof(current_dir)), 1);
+
 			trace_printf("trace: alias to shell cmd: %s => %s\n",
 				     alias_command, alias_string + 1);
 			ret = system(alias_string + 1);
-- 
1.7.0.4
Jeff King· May 5, 2010, 00:51 UTC · re: Jared Hance · lore

Re: [PATCH] Set GIT_PATHNAME_PREFIX with aliases.

On Tue, May 04, 2010 at 08:25:22PM -0400, Jared Hance wrote:
Show 5 quoted lines
> The environment variable GIT_PATHNAME_PREFIX passes on the
> current working directory (where the git command was called from)
> to shell aliases (aliases that begin with "!"). This allows these
> shell aliases to know the directory that the git command was called
> from.
Seems like a reasonable goal, but...
Show 12 quoted lines
> --- a/git.c
> +++ b/git.c
> @@ -167,6 +167,9 @@ static int handle_alias(int *argcp, const char ***argv)
>  				free(alias_string);
>  				alias_string = buf.buf;
>  			}
> +			static char current_dir[PATH_MAX+1];
> +			setenv("GIT_PATHNAME_PREFIX", getcwd(current_dir, sizeof(current_dir)), 1);
> +
>  			trace_printf("trace: alias to shell cmd: %s => %s\n",
>  				     alias_command, alias_string + 1);
>  			ret = system(alias_string + 1);
I see three problems:
  1. Don't declare variables in the middle of a function. It's a C99-ism
     that we avoid to retain portability with older compilers.
  2. On getcwd error, we setenv the value to NULL. Is that OK on all
     platforms (I am specifically thinking of our Windows *env wrappers,
     which have some restrictions, but I don't remember the details)?
  3. Most importantly, isn't this totally the wrong place to look at
     getcwd? We're just about to run system(), which means we will
     already have done our chdir() (which probably is the one happening
     in setup_git_directory). On even a simple test, it seems to always
     print the root of the repository for me.
     I think instead you want to pass in the prefix value computed by
     setup_git_directory to handle_alias.
-Peff
Johannes Sixt· May 5, 2010, 06:53 UTC · re: Jeff King · lore

Re: [PATCH] Set GIT_PATHNAME_PREFIX with aliases.

Am 5/5/2010 2:51, schrieb Jeff King:
Show 9 quoted lines
> On Tue, May 04, 2010 at 08:25:22PM -0400, Jared Hance wrote:
> 
>> The environment variable GIT_PATHNAME_PREFIX passes on the
>> current working directory (where the git command was called from)
>> to shell aliases (aliases that begin with "!"). This allows these
>> shell aliases to know the directory that the git command was called
>> from.
> 
> Seems like a reasonable goal, but...
Sorry, I disagree.

The availability of this environment variable doesn't help the alias writer a lot:

1. The alias is still burdened with the task to check *when* to use the
variable, i.e., whether an argument passed is absolute or relative, and
apply the variable only to a relative argument.
2. When more than one pathspec is passed to the alias, it is tedious to
apply $GIT_PATHNAME_PREFIX to each of them.

The only way where this variable could be used in a useful manner is to write the alias as

   !cd "${GIT_PATHNAME_PREFIX:-.}" && { do stuff... ; }
which is something that git should do before it invokes the alias.
-- Hannes
Jeff King· May 5, 2010, 07:01 UTC · re: Johannes Sixt · lore

Re: [PATCH] Set GIT_PATHNAME_PREFIX with aliases.

On Wed, May 05, 2010 at 08:53:35AM +0200, Johannes Sixt wrote:
Show 13 quoted lines
> Am 5/5/2010 2:51, schrieb Jeff King:
> > On Tue, May 04, 2010 at 08:25:22PM -0400, Jared Hance wrote:
> > 
> >> The environment variable GIT_PATHNAME_PREFIX passes on the
> >> current working directory (where the git command was called from)
> >> to shell aliases (aliases that begin with "!"). This allows these
> >> shell aliases to know the directory that the git command was called
> >> from.
> > 
> > Seems like a reasonable goal, but...
> 
> Sorry, I disagree.
> [reasons why it sucks]

Yes, I agree it sucks. The problem is that this information is totally lost now for shell aliases, so you can't even do these painful things. Your alias simply doesn't have access to that information at all. I am open to better interfaces (my "reasonable" above was not a ringing endorsement, but rather "I can see why you might want to do this").

> The only way where this variable could be used in a useful manner is to
> write the alias as
> 
>    !cd "${GIT_PATHNAME_PREFIX:-.}" && { do stuff... ; }
Agreed that is the only sane thing to do with it, but...
> which is something that git should do before it invokes the alias.

Wouldn't we then be breaking existing aliases which do not expect this new behavior?

-Peff
Eli Barzilay· May 5, 2010, 07:52 UTC · re: Jeff King · lore

Re: [PATCH] Set GIT_PATHNAME_PREFIX with aliases.

On May  5, Jeff King wrote:
Show 22 quoted lines
> On Wed, May 05, 2010 at 08:53:35AM +0200, Johannes Sixt wrote:
> 
> > Am 5/5/2010 2:51, schrieb Jeff King:
> > > On Tue, May 04, 2010 at 08:25:22PM -0400, Jared Hance wrote:
> > > 
> > >> The environment variable GIT_PATHNAME_PREFIX passes on the
> > >> current working directory (where the git command was called from)
> > >> to shell aliases (aliases that begin with "!"). This allows these
> > >> shell aliases to know the directory that the git command was called
> > >> from.
> > > 
> > > Seems like a reasonable goal, but...
> > 
> > Sorry, I disagree.
> > [reasons why it sucks]
> 
> Yes, I agree it sucks. The problem is that this information is
> totally lost now for shell aliases, so you can't even do these
> painful things.  Your alias simply doesn't have access to that
> information at all. I am open to better interfaces (my "reasonable"
> above was not a ringing endorsement, but rather "I can see why you
> might want to do this").

Something that Jonathan suggested earlier is a different magic character instead of "!" that will do the cd -- perhaps a second character would be more acceptable, something like "!!"...

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!
Junio C Hamano· May 5, 2010, 16:07 UTC · re: Eli Barzilay · lore

Re: [PATCH] Set GIT_PATHNAME_PREFIX with aliases.

Eli Barzilay <eli@barzilay.org> writes:
> On May  5, Jeff King wrote:
>> 
>> Yes, I agree it sucks.

I would not use such a strong word but I agree that it would have been nicer if the original directory were used.

> Something that Jonathan suggested earlier is a different magic
> character instead of "!" that will do the cd -- perhaps a second
> character would be more acceptable, something like "!!"...
That sounds a reasonable compromise.
Eli Barzilay· May 5, 2010, 20:28 UTC · re: Junio C Hamano · lore

[PATCH] An alias that starts with "!!" runs in the current directory.

With "!"-prefixed shell aliases, the shell command not only gets executed at the repository top level, but there is no way to know the current directory of the original call. This adds "!!"-prefixed aliases as a similar variant for "!"-prefixed ones, but the commands are executed in the original directory instead of the top level.

Signed-off-by: Eli Barzilay <eli@barzilay.org>
---
(Sending as a reply to the earlier message, keeping CCs.)

It looks like setup_git_directory_gently() returns the original CWD, but since it's not documented or commented, I don't know if this is reliable or not, so it might need to change.

Also, it might make more sense to document the "!!" variant first, since it is generally more useful, but the way things evolved with "!!" being the longer prefix, it seems to me that documenting it after "!" is more sensible.

 Documentation/config.txt |    9 +++++++--
 git.c                    |    8 ++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
Show changes to 2 files +15 −2

Documentation/config.txt, git.c

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 92f851e..055f4e3 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -549,13 +549,18 @@ alias.*::
 	spaces, the usual shell quoting and escaping is supported.
 	quote pair and a backslash can be used to quote them.
 +
-If the alias expansion is prefixed with an exclamation point,
+If the alias expansion is prefixed with a single exclamation point,
 it will be treated as a shell command.  For example, defining
 "alias.new = !gitk --all --not ORIG_HEAD", the invocation
 "git new" is equivalent to running the shell command
-"gitk --all --not ORIG_HEAD".  Note that shell commands will be
+"gitk --all --not ORIG_HEAD".  Note that such shell commands will be
 executed from the top-level directory of a repository, which may
 not necessarily be the current directory.
++
+If the alias expansion is prefixed with two exclamation points,
+it will be treader similarly to the above, except that the shell commands
+are executed at the current directory.
+
 
 am.keepcr::
 	If true, git-am will call git-mailsplit for patches in mbox format
diff --git a/git.c b/git.c
index 6bae305..f3f8346 100644
--- a/git.c
+++ b/git.c
@@ -167,6 +167,14 @@ static int handle_alias(int *argcp, const char ***argv)
 				free(alias_string);
 				alias_string = buf.buf;
 			}
+			/* going to exit anyway, so it's fine to change
+			 * alias_string to the actual command */
+			alias_string += 1;
+			if (alias_string[0] == '!') {
+				alias_string += 1;
+				if (subdir && chdir(subdir))
+					die_errno("Cannot change to '%s'", subdir);
+			}
 			trace_printf("trace: alias to shell cmd: %s => %s\n",
 				     alias_command, alias_string + 1);
 			ret = system(alias_string + 1);
-- 
1.7.1
Jared Hance· May 5, 2010, 20:52 UTC · re: Eli Barzilay · lore

Re: [PATCH] An alias that starts with &quot;!!&quot; runs in the current directory.

Eli Barzilay <eli <at> barzilay.org> writes:
>  			ret = system(alias_string + 1);

I don't think that this is correct. You already changed alias_string to the actual code earlier in the command, so I think that this will actually chop off the first letter of the command.

Eli Barzilay· May 5, 2010, 20:58 UTC · re: Jared Hance · lore

Re: [PATCH] An alias that starts with &quot;!!&quot; runs in the current directory.

On May  5, Jared Hance wrote:
Show 7 quoted lines
> Eli Barzilay <eli <at> barzilay.org> writes:
> 
> >  			ret = system(alias_string + 1);
> 
> I don't think that this is correct. You already changed alias_string
> to the actual code earlier in the command, so I think that this will
> actually chop off the first letter of the command.

(*sigh*) That's correct, I fixed this, but improperly remade the patch.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!
Eli Barzilay· May 5, 2010, 21:00 UTC · re: Eli Barzilay · lore

Re: [PATCH] An alias that starts with &quot;!!&quot; runs in the current directory.

On May  5, Eli Barzilay wrote:
Show 11 quoted lines
> On May  5, Jared Hance wrote:
> > Eli Barzilay <eli <at> barzilay.org> writes:
> > 
> > >  			ret = system(alias_string + 1);
> > 
> > I don't think that this is correct. You already changed alias_string
> > to the actual code earlier in the command, so I think that this will
> > actually chop off the first letter of the command.
> 
> (*sigh*)  That's correct, I fixed this, but improperly remade the
> patch.
Is there some convention for sending a fixed patch?
-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!
Jonathan Nieder· May 5, 2010, 21:24 UTC · re: Eli Barzilay · lore

Re-submitting patches

Hi Eli,
Eli Barzilay wrote:
> On May  5, Eli Barzilay wrote:
>> (*sigh*)  That's correct, I fixed this, but improperly remade the
>> patch.
>
> Is there some convention for sending a fixed patch?

With a small patch like this one, you can just send the fixed patch as a reply to the thread. Putting “[PATCH v2]” in the subject would make it clear that this is the newer and better version.

With larger patches, doing that too often can overload people. My preferred solution: describe the changes as soon as you want, but then take some time to polish them before resubmitting. This gives people time to breathe. ;-)

The “ideal patch flow” section in Documentation/SubmittingPatches says:

-------
 (3) Polish, refine, and re-send to the list and the people who
     spend their time to improve your patch.  Go back to step (2).
-------

Maybe this could be clearer. In particular, sometimes it is not obvious to people that even the patch submitter can pretend to be a reviewer and discuss small incremental changes.

Thanks for bringing it up, Jonathan

Eli Barzilay· May 5, 2010, 21:28 UTC · re: Jonathan Nieder · lore

Re: Re-submitting patches

On May  5, Jonathan Nieder wrote:
Show 13 quoted lines
> Hi Eli,
> 
> Eli Barzilay wrote:
> > On May  5, Eli Barzilay wrote:
> 
> >> (*sigh*)  That's correct, I fixed this, but improperly remade the
> >> patch.
> >
> > Is there some convention for sending a fixed patch?
> 
> With a small patch like this one, you can just send the fixed patch
> as a reply to the thread.  Putting “[PATCH v2]” in the subject would
> make it clear that this is the newer and better version.
Ah -- it's the "v2" that I missed, thanks.
> With larger patches, doing that too often can overload people.
> My preferred solution: describe the changes as soon as you want, but
> then take some time to polish them before resubmitting.  This gives
> people time to breathe. ;-)

Yes, I'd be much more careful if this was not a quick thing. (BTW, it would be nice if there is a way to get various publishing commands like `format-patch' and `pull' to spit out some warning if there are uncommitted changes -- that would have prevented me from sending the bogus one.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!
Eli Barzilay· May 5, 2010, 21:31 UTC · re: Eli Barzilay · lore

[PATCH v2] An alias that starts with "!!" runs in the current directory.

With "!"-prefixed shell aliases, the shell command not only gets executed at the repository top level, but there is no way to know the current directory of the original call. This adds "!!"-prefixed aliases as a similar variant for "!"-prefixed ones, but the commands are executed in the original directory instead of the top level.

Signed-off-by: Eli Barzilay <eli@barzilay.org>
---

It looks like setup_git_directory_gently() returns the original CWD, but since it's not documented or commented, I don't know if this is reliable or not, so it might need to change.

Also, it might make more sense to document the "!!" variant first, since it is generally more useful, but the way things evolved with "!!" being the longer prefix, it seems to me that documenting it after "!" is more sensible.

This fixes the broken use of alias_command that Jared Hance caught.
 Documentation/config.txt |    9 +++++++--
 git.c                    |   14 +++++++++++---
 2 files changed, 18 insertions(+), 5 deletions(-)
Show changes to 2 files +18 −5

Documentation/config.txt, git.c

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 92f851e..055f4e3 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -549,13 +549,18 @@ alias.*::
 	spaces, the usual shell quoting and escaping is supported.
 	quote pair and a backslash can be used to quote them.
 +
-If the alias expansion is prefixed with an exclamation point,
+If the alias expansion is prefixed with a single exclamation point,
 it will be treated as a shell command.  For example, defining
 "alias.new = !gitk --all --not ORIG_HEAD", the invocation
 "git new" is equivalent to running the shell command
-"gitk --all --not ORIG_HEAD".  Note that shell commands will be
+"gitk --all --not ORIG_HEAD".  Note that such shell commands will be
 executed from the top-level directory of a repository, which may
 not necessarily be the current directory.
++
+If the alias expansion is prefixed with two exclamation points,
+it will be treader similarly to the above, except that the shell commands
+are executed at the current directory.
+
 
 am.keepcr::
 	If true, git-am will call git-mailsplit for patches in mbox format
diff --git a/git.c b/git.c
index 6bae305..3d8ed20 100644
--- a/git.c
+++ b/git.c
@@ -167,14 +167,22 @@ static int handle_alias(int *argcp, const char ***argv)
 				free(alias_string);
 				alias_string = buf.buf;
 			}
+			/* going to exit anyway, so it's fine to change
+			 * alias_string to the actual command */
+			alias_string += 1;
+			if (alias_string[0] == '!') {
+				alias_string += 1;
+				if (subdir && chdir(subdir))
+					die_errno("Cannot change to '%s'", subdir);
+			}
 			trace_printf("trace: alias to shell cmd: %s => %s\n",
-				     alias_command, alias_string + 1);
-			ret = system(alias_string + 1);
+				     alias_command, alias_string);
+			ret = system(alias_string);
 			if (ret >= 0 && WIFEXITED(ret) &&
 			    WEXITSTATUS(ret) != 127)
 				exit(WEXITSTATUS(ret));
 			die("Failed to run '%s' when expanding alias '%s'",
-			    alias_string + 1, alias_command);
+			    alias_string, alias_command);
 		}
 		count = split_cmdline(alias_string, &new_argv);
 		if (count < 0)
-- 
1.7.1
Will Palmer· May 5, 2010, 22:22 UTC · re: Eli Barzilay · lore

Re: [PATCH v2] An alias that starts with "!!" runs in the current directory.

On Wed, 2010-05-05 at 17:31 -0400, Eli Barzilay wrote:
Show 7 quoted lines
> With "!"-prefixed shell aliases, the shell command not only gets
> executed at the repository top level, but there is no way to know the
> current directory of the original call.  This adds "!!"-prefixed aliases
> as a similar variant for "!"-prefixed ones, but the commands are
> executed in the original directory instead of the top level.
> 
> Signed-off-by: Eli Barzilay <eli@barzilay.org>

Is there any precedent for the "!!" syntax? Something like ".!", "./!", or "!(.)" would make the intention more clear, I'd think, as well as leaving room for other extensions to be added later, and some explicit-opposite, like "/!", to complement it. (It's not like people are going around with binaries called "!", is it?)

Ignore my suggestions if it turns out that "!!" is used by other things, but this one seems to be begging for someone else to come along with a "me too!"

-- 
-- Will
Eli Barzilay· May 5, 2010, 22:33 UTC · re: Will Palmer · lore

Re: [PATCH v2] An alias that starts with "!!" runs in the current directory.

On May  5, Will Palmer wrote:
Show 14 quoted lines
> On Wed, 2010-05-05 at 17:31 -0400, Eli Barzilay wrote:
> > With "!"-prefixed shell aliases, the shell command not only gets
> > executed at the repository top level, but there is no way to know the
> > current directory of the original call.  This adds "!!"-prefixed aliases
> > as a similar variant for "!"-prefixed ones, but the commands are
> > executed in the original directory instead of the top level.
> > 
> > Signed-off-by: Eli Barzilay <eli@barzilay.org>
> 
> Is there any precedent for the "!!" syntax? Something like ".!",
> "./!", or "!(.)" would make the intention more clear, I'd think, as
> well as leaving room for other extensions to be added later, and
> some explicit-opposite, like "/!", to complement it. (It's not like
> people are going around with binaries called "!", is it?)
[

The first time I saw the "!" syntax, it was slightly confusing to me in that it's similar to various shells using "!" for history expansion -- especially given that these things are popular with shell aliases made it hard to remember.

An alternative character that wouldn't have confused me, and even suggests shell commands is ";". So my preference would be for shell aliases to start with it and to be invoked in the original working directory, perhaps deprecating the "!" syntax.

But I'm new enough to be safely ignored... So this is all a parenthetical comment...

]
-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!
Junio C Hamano· May 5, 2010, 23:43 UTC · re: Will Palmer · lore

Re: [PATCH v2] An alias that starts with "!!" runs in the current directory.

Will Palmer <wmpalmer@gmail.com> writes:
> Is there any precedent for the "!!" syntax? Something like ".!", "./!",
> or "!(.)" would make the intention more clear, I'd think, as well as
> leaving room for other extensions to be added later...

While I don't think !! is particularly good (or bad), possible future extension is always a good reason to think about the notation carefully.

It probably is a good idea to switch aliases to start at the $cwd in 1.8.0 (or perhaps one major release after it), and using a notation that is more descriptive, something like "!(cwd)" vs "!(root)", may give us a better transtion strategy than casting cryptic "!!" in the stone.

What other variants might we want to be able to specify while defining and using aliases? If cwd vs root is the only distinction, then !(cwd) would be a bit overkill, but if we used !! for this new feature, I suspect that it would make it much harder to switch the default in the future.

Comments?
Adam Brewster· May 6, 2010, 00:05 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] An alias that starts with "!!" runs in the current directory.

On 5/5/10, Junio C Hamano <gitster@pobox.com> wrote:
Show 6 quoted lines
>
> It probably is a good idea to switch aliases to start at the $cwd in 1.8.0
> (or perhaps one major release after it), and using a notation that is more
> descriptive, something like "!(cwd)" vs "!(root)", may give us a better
> transtion strategy than casting cryptic "!!" in the stone.
>
For what it's worth, I like "!cmd".
Would it be good enough to set some environment variables?
    [alias]
    command_in_cwd = "!cd $GIT_CWD; ..."
Adam
Will Palmer· May 6, 2010, 06:21 UTC · re: Adam Brewster · lore

Re: [PATCH v2] An alias that starts with "!!" runs in the current directory.

On Wed, 2010-05-05 at 20:05 -0400, Adam Brewster wrote:
Show 16 quoted lines
> On 5/5/10, Junio C Hamano <gitster@pobox.com> wrote:
> >
> > It probably is a good idea to switch aliases to start at the $cwd in 1.8.0
> > (or perhaps one major release after it), and using a notation that is more
> > descriptive, something like "!(cwd)" vs "!(root)", may give us a better
> > transtion strategy than casting cryptic "!!" in the stone.
> >
> 
> For what it's worth, I like "!cmd".
> 
> Would it be good enough to set some environment variables?
> 
>     [alias]
>     command_in_cwd = "!cd $GIT_CWD; ..."
> 
> Adam

I'd be tempted to say that setting $GIT_CWD was an ideal solution, if Junio hadn't mentioned the possibility of cwd being the default in 1.8.0, which to me sounds much more sane than defaulting to the repository root. Defaulting to the root has never made sense to me and has some perfectly good built-ins to emulate if needed. I know I have at least two scripts-which-should-be-aliases sitting around because of this restriction.

-- 
-- Will
Will Palmer· May 6, 2010, 06:26 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] An alias that starts with "!!" runs in the current directory.

On Wed, 2010-05-05 at 16:43 -0700, Junio C Hamano wrote:
Show 8 quoted lines
> What other variants might we want to be able to specify while defining and
> using aliases?  If cwd vs root is the only distinction, then !(cwd) would
> be a bit overkill, but if we used !! for this new feature, I suspect that
> it would make it much harder to switch the default in the future.
> 
> Comments?
> 
> 

What I had in mind when I mentioned !(...) were some half-formed ideas about shortcuts for manipulating the environment, !(nopager), for example.

But these ideas were vague and I can't think of any off-hand which I would use other than !(cwd). I'd say !(root:path/to/dir), but that's obviously not necessary (any more than !(root) would be, if cwd were the default), and honestly I'm quite happy using shell functions for that sort of thing.

-- 
-- Will
Johannes Sixt· May 6, 2010, 06:36 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] An alias that starts with "!!" runs in the current directory.

Am 5/6/2010 1:43, schrieb Junio C Hamano:
> It probably is a good idea to switch aliases to start at the $cwd in 1.8.0
> (or perhaps one major release after it), and using a notation that is more
> descriptive, something like "!(cwd)" vs "!(root)", may give us a better
> transtion strategy than casting cryptic "!!" in the stone.

As always, we should start with the verbose tag, and if one turns out to be used frequently, use !! for it as a shortcut.

> What other variants might we want to be able to specify while defining and
> using aliases?  If cwd vs root is the only distinction, then !(cwd) would
> be a bit overkill, but if we used !! for this new feature, I suspect that
> it would make it much harder to switch the default in the future.

The syntax should use a symbol that is less likely to appear at the start of a shell script. Perhaps "!@cwd".

-- Hannes
Matthieu Moy· May 6, 2010, 07:02 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] An alias that starts with "!!" runs in the current directory.

Junio C Hamano <gitster@pobox.com> writes:
> It probably is a good idea to switch aliases to start at the $cwd in 1.8.0
> (or perhaps one major release after it), and using a notation that is more
> descriptive, something like "!(cwd)" vs "!(root)", may give us a better
> transtion strategy than casting cryptic "!!" in the stone.

I like this: Allow !(cwd) and !(root) today, with !(root) being just like "!", and change plain "!" to mean !(cwd) in a future major release.

If other people have ideas for other features, the syntax can also be extended to !(cwd,some-option) or so.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Junio C Hamano· May 5, 2010, 22:02 UTC · re: Eli Barzilay · lore

Re: [PATCH] An alias that starts with "!!" runs in the current directory.

Eli Barzilay <eli@barzilay.org> writes:
> It looks like setup_git_directory_gently() returns the original CWD,...

It is designed to return what we internally call "prefix". You however have to be careful as it can return NULL or an empty string when you are already at the top of the working tree.

Eli Barzilay· May 5, 2010, 22:13 UTC · re: Junio C Hamano · lore

Re: [PATCH] An alias that starts with "!!" runs in the current directory.

On May  5, Junio C Hamano wrote:
Show 7 quoted lines
> Eli Barzilay <eli@barzilay.org> writes:
> 
> > It looks like setup_git_directory_gently() returns the original CWD,...
> 
> It is designed to return what we internally call "prefix".  You
> however have to be careful as it can return NULL or an empty string
> when you are already at the top of the working tree.

OK, in this case it looks like it should work as expected. At least provided that chdir("") stays in the same directory -- and given the call at the end of handle_alias(), it looks like this assumption is already made. Does this sound right?

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

← back to recent threads