git@vger.kernel.org mailing list mirror (one of many)
 help / Atom feed
* [RFC PATCH v2] Allow aliases that include other aliases
@ 2018-09-05  8:54 Tim Schumacher
  2018-09-05 15:48 ` Duy Nguyen
                   ` (4 more replies)
  0 siblings, 5 replies; 37+ messages in thread
From: Tim Schumacher @ 2018-09-05  8:54 UTC (permalink / raw)
  To: git; +Cc: gitster, peff

Aliases can only contain non-alias git commands and their
arguments, not other user-defined aliases. Resolving further
(nested) aliases is prevented by breaking the loop after the
first alias was processed. Git then fails with a command-not-found
error.

Allow resolving nested aliases by not breaking the loop in
run_argv() after the first alias was processed. Instead, continue
incrementing `done_alias` until `handle_alias()` fails, which means that
there are no further aliases that can be processed. Prevent looping
aliases by storing substituted commands in `cmd_list` and checking if
a command has been substituted previously.
---

This is what I've come up with to prevent looping aliases. I'm not too
happy with the number of indentations needed, but this seemed to be the
easiest way to search an array for a value.

---
 git.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/git.c b/git.c
index c27c38738..fd90a3341 100644
--- a/git.c
+++ b/git.c
@@ -674,6 +674,8 @@ static void execv_dashed_external(const char **argv)
 static int run_argv(int *argcp, const char ***argv)
 {
 	int done_alias = 0;
+	const char **cmd_list = NULL;
+	int cmd_list_alloc = 0;
 
 	while (1) {
 		/*
@@ -691,17 +693,34 @@ static int run_argv(int *argcp, const char ***argv)
 		/* .. then try the external ones */
 		execv_dashed_external(*argv);
 
+		/* Increase the array size and add the current
+		 * command to it.
+		 */
+		cmd_list_alloc += strlen(*argv[0]) + 1;
+		REALLOC_ARRAY(cmd_list, cmd_list_alloc);
+		cmd_list[done_alias] = *argv[0];
+
+		/* Search the array for occurrences of that command,
+		 * abort if something has been found.
+		 */
+		for (int i = 0; i < done_alias; i++) {
+			if (!strcmp(cmd_list[i], *argv[0])) {
+				die("loop alias: %s is called twice",
+				    cmd_list[done_alias]);
+			}
+		}
+
 		/* It could be an alias -- this works around the insanity
 		 * of overriding "git log" with "git show" by having
 		 * alias.log = show
 		 */
-		if (done_alias)
-			break;
 		if (!handle_alias(argcp, argv))
 			break;
-		done_alias = 1;
+		done_alias++;
 	}
 
+	free(cmd_list);
+
 	return done_alias;
 }
 
-- 
2.19.0.rc1.2.g8f4faccc1


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

* Re: [RFC PATCH v2] Allow aliases that include other aliases
  2018-09-05  8:54 [RFC PATCH v2] Allow aliases that include other aliases Tim Schumacher
@ 2018-09-05 15:48 ` Duy Nguyen
  2018-09-05 19:02   ` Tim Schumacher
  2018-09-05 17:12 ` Junio C Hamano
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 37+ messages in thread
From: Duy Nguyen @ 2018-09-05 15:48 UTC (permalink / raw)
  To: timschumi; +Cc: Git Mailing List, Junio C Hamano, Jeff King

On Wed, Sep 5, 2018 at 10:56 AM Tim Schumacher <timschumi@gmx.de> wrote:
>
> Aliases can only contain non-alias git commands and their
> arguments, not other user-defined aliases. Resolving further
> (nested) aliases is prevented by breaking the loop after the
> first alias was processed. Git then fails with a command-not-found
> error.
>
> Allow resolving nested aliases by not breaking the loop in
> run_argv() after the first alias was processed. Instead, continue
> incrementing `done_alias` until `handle_alias()` fails, which means that
> there are no further aliases that can be processed. Prevent looping
> aliases by storing substituted commands in `cmd_list` and checking if
> a command has been substituted previously.
> ---
>
> This is what I've come up with to prevent looping aliases. I'm not too
> happy with the number of indentations needed, but this seemed to be the
> easiest way to search an array for a value.

You can just make all the new code a separate function, which reduces
indentation.

There's another thing I wanted (but probably a wrong thing to want):
if I define alias 'foo' in ~/.gitconfig, then I'd like to modify it in
some project by redefining it as alias.foo='foo --something' in
$GIT_DIR/config. This results in alias loop, but the loop is broken by
looking up 'foo' from a higher level config file instead.

This is not easy to do, and as I mentioned, I'm not even sure if it's
a sane thing to do.

> +               /* Increase the array size and add the current
> +                * command to it.
> +                */

I think this is pretty clear from the code, you don't need to add a
comment to explain how the next few lines work. Same comment for the
next comment block.

> +               cmd_list_alloc += strlen(*argv[0]) + 1;
> +               REALLOC_ARRAY(cmd_list, cmd_list_alloc);
> +               cmd_list[done_alias] = *argv[0];
> +
> +               /* Search the array for occurrences of that command,
> +                * abort if something has been found.
> +                */
> +               for (int i = 0; i < done_alias; i++) {
> +                       if (!strcmp(cmd_list[i], *argv[0])) {
> +                               die("loop alias: %s is called twice",

Please wrap the string in _() so that it can be translated in
different languages.

> +                                   cmd_list[done_alias]);
> +                       }
> +               }
> +
-- 
Duy

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

* Re: [RFC PATCH v2] Allow aliases that include other aliases
  2018-09-05  8:54 [RFC PATCH v2] Allow aliases that include other aliases Tim Schumacher
  2018-09-05 15:48 ` Duy Nguyen
@ 2018-09-05 17:12 ` Junio C Hamano
  2018-09-05 19:12   ` Tim Schumacher
  2018-09-05 17:34 ` Jeff King
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 37+ messages in thread
From: Junio C Hamano @ 2018-09-05 17:12 UTC (permalink / raw)
  To: Tim Schumacher; +Cc: git, peff

Tim Schumacher <timschumi@gmx.de> writes:

> @@ -691,17 +693,34 @@ static int run_argv(int *argcp, const char ***argv)
>  		/* .. then try the external ones */
>  		execv_dashed_external(*argv);
>  
> +		/* Increase the array size and add the current
> +		 * command to it.
> +		 */
> +		cmd_list_alloc += strlen(*argv[0]) + 1;
> +		REALLOC_ARRAY(cmd_list, cmd_list_alloc);
> +		cmd_list[done_alias] = *argv[0];
> +
> +		/* Search the array for occurrences of that command,
> +		 * abort if something has been found.
> +		 */
> +		for (int i = 0; i < done_alias; i++) {
> +			if (!strcmp(cmd_list[i], *argv[0])) {
> +				die("loop alias: %s is called twice",
> +				    cmd_list[done_alias]);
> +			}
> +		}
> +

Wouldn't all of the above become three or four lines that is so
clear that there is no need for any comment if you used string-list,
perhaps?

>  		/* It could be an alias -- this works around the insanity
>  		 * of overriding "git log" with "git show" by having
>  		 * alias.log = show
>  		 */

	/*
	 * Style: our multi-line comment begins with and ends with
	 * slash-asterisk and asterisk-slash on their own lines.
	 */

> -		if (done_alias)
> -			break;
>  		if (!handle_alias(argcp, argv))
>  			break;
> -		done_alias = 1;
> +		done_alias++;
>  	}
>  
> +	free(cmd_list);
> +
>  	return done_alias;
>  }

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

* Re: [RFC PATCH v2] Allow aliases that include other aliases
  2018-09-05  8:54 [RFC PATCH v2] Allow aliases that include other aliases Tim Schumacher
  2018-09-05 15:48 ` Duy Nguyen
  2018-09-05 17:12 ` Junio C Hamano
@ 2018-09-05 17:34 ` Jeff King
  2018-09-05 20:02   ` Tim Schumacher
  2018-09-05 21:51   ` Junio C Hamano
  2018-09-06 10:16 ` [PATCH v3] " Tim Schumacher
  2018-09-07 22:44 ` [RFC PATCH v4 1/3] Add support for nested aliases Tim Schumacher
  4 siblings, 2 replies; 37+ messages in thread
From: Jeff King @ 2018-09-05 17:34 UTC (permalink / raw)
  To: Tim Schumacher; +Cc: git, gitster

On Wed, Sep 05, 2018 at 10:54:27AM +0200, Tim Schumacher wrote:

> Aliases can only contain non-alias git commands and their
> arguments, not other user-defined aliases. Resolving further
> (nested) aliases is prevented by breaking the loop after the
> first alias was processed. Git then fails with a command-not-found
> error.
> 
> Allow resolving nested aliases by not breaking the loop in
> run_argv() after the first alias was processed. Instead, continue
> incrementing `done_alias` until `handle_alias()` fails, which means that
> there are no further aliases that can be processed. Prevent looping
> aliases by storing substituted commands in `cmd_list` and checking if
> a command has been substituted previously.
> ---
> 
> This is what I've come up with to prevent looping aliases. I'm not too
> happy with the number of indentations needed, but this seemed to be the
> easiest way to search an array for a value.

I think this approach is OK, though I wonder if we'd also be fine with
just:

  if (done_alias++ > 100)
	die("woah, is your alias looping?");

The point is just to prevent a runaway infinite loop, and this does that
while keeping the cost very low for the common case (not that one string
insertion is probably breaking the bank).

It could also extend to ! aliases if we wanted (i.e., my '!git foo'
example from earlier), but you'd have to carry the counter through the
environment between processes.

-Peff

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

* Re: [RFC PATCH v2] Allow aliases that include other aliases
  2018-09-05 15:48 ` Duy Nguyen
@ 2018-09-05 19:02   ` Tim Schumacher
  0 siblings, 0 replies; 37+ messages in thread
From: Tim Schumacher @ 2018-09-05 19:02 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: Git Mailing List, Junio C Hamano, Jeff King

On 05.09.18 17:48, Duy Nguyen wrote:
> On Wed, Sep 5, 2018 at 10:56 AM Tim Schumacher <timschumi@gmx.de> wrote:
>>
>> Aliases can only contain non-alias git commands and their
>> arguments, not other user-defined aliases. Resolving further
>> (nested) aliases is prevented by breaking the loop after the
>> first alias was processed. Git then fails with a command-not-found
>> error.
>>
>> Allow resolving nested aliases by not breaking the loop in
>> run_argv() after the first alias was processed. Instead, continue
>> incrementing `done_alias` until `handle_alias()` fails, which means that
>> there are no further aliases that can be processed. Prevent looping
>> aliases by storing substituted commands in `cmd_list` and checking if
>> a command has been substituted previously.
>> ---
>>
>> This is what I've come up with to prevent looping aliases. I'm not too
>> happy with the number of indentations needed, but this seemed to be the
>> easiest way to search an array for a value.
> 
> You can just make all the new code a separate function, which reduces
> indentation.

That would solve the issue, but I'm not sure if it is worth introducing
a new function exclusively for that. I didn't find anything about a
maximum indentation level in the code guidelines and since the new
parts stay within the width limit (and is imo still readable), would it
be ok to keep it like that?

> 
> There's another thing I wanted (but probably a wrong thing to want):
> if I define alias 'foo' in ~/.gitconfig, then I'd like to modify it in
> some project by redefining it as alias.foo='foo --something' in
> $GIT_DIR/config. This results in alias loop, but the loop is broken by
> looking up 'foo' from a higher level config file instead.
> 
> This is not easy to do, and as I mentioned, I'm not even sure if it's
> a sane thing to do.

The alias system is using the default functions of the config system,
I assume that adding such a functionality is not possible, at least not
without breaking compatibility.

> 
>> +               /* Increase the array size and add the current
>> +                * command to it.
>> +                */
> 
> I think this is pretty clear from the code, you don't need to add a
> comment to explain how the next few lines work. Same comment for the
> next comment block.

I'll remove them in v3.

> 
>> +               cmd_list_alloc += strlen(*argv[0]) + 1;
>> +               REALLOC_ARRAY(cmd_list, cmd_list_alloc);
>> +               cmd_list[done_alias] = *argv[0];
>> +
>> +               /* Search the array for occurrences of that command,
>> +                * abort if something has been found.
>> +                */
>> +               for (int i = 0; i < done_alias; i++) {
>> +                       if (!strcmp(cmd_list[i], *argv[0])) {
>> +                               die("loop alias: %s is called twice",
> 
> Please wrap the string in _() so that it can be translated in
> different languages.

I'll do that in v3 as well.

> 
>> +                                   cmd_list[done_alias]);
>> +                       }
>> +               }
>> +

Thanks for reviewing!

Tim

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

* Re: [RFC PATCH v2] Allow aliases that include other aliases
  2018-09-05 17:12 ` Junio C Hamano
@ 2018-09-05 19:12   ` Tim Schumacher
  0 siblings, 0 replies; 37+ messages in thread
From: Tim Schumacher @ 2018-09-05 19:12 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, peff

On 05.09.18 19:12, Junio C Hamano wrote:
> Tim Schumacher <timschumi@gmx.de> writes:
> 
>> @@ -691,17 +693,34 @@ static int run_argv(int *argcp, const char ***argv)
>>   		/* .. then try the external ones */
>>   		execv_dashed_external(*argv);
>>   
>> +		/* Increase the array size and add the current
>> +		 * command to it.
>> +		 */
>> +		cmd_list_alloc += strlen(*argv[0]) + 1;
>> +		REALLOC_ARRAY(cmd_list, cmd_list_alloc);
>> +		cmd_list[done_alias] = *argv[0];
>> +
>> +		/* Search the array for occurrences of that command,
>> +		 * abort if something has been found.
>> +		 */
>> +		for (int i = 0; i < done_alias; i++) {
>> +			if (!strcmp(cmd_list[i], *argv[0])) {
>> +				die("loop alias: %s is called twice",
>> +				    cmd_list[done_alias]);
>> +			}
>> +		}
>> +
> 
> Wouldn't all of the above become three or four lines that is so
> clear that there is no need for any comment if you used string-list,
> perhaps?

Whoops, I didn't know that string-list existed. I'll try reworking the
code to use that. Concerning the comments: I planned to remove them
anyways since the code should be simple enough to be understood without
them already.

> 
>>   		/* It could be an alias -- this works around the insanity
>>   		 * of overriding "git log" with "git show" by having
>>   		 * alias.log = show
>>   		 */
> 
> 	/*
> 	 * Style: our multi-line comment begins with and ends with
> 	 * slash-asterisk and asterisk-slash on their own lines.
> 	 */

I wasn't sure if I should have changed that (because I didn't introduce
that comment), but I can fix it in v3.

> 
>> -		if (done_alias)
>> -			break;
>>   		if (!handle_alias(argcp, argv))
>>   			break;
>> -		done_alias = 1;
>> +		done_alias++;
>>   	}
>>   
>> +	free(cmd_list);
>> +
>>   	return done_alias;
>>   }
> 

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

* Re: [RFC PATCH v2] Allow aliases that include other aliases
  2018-09-05 17:34 ` Jeff King
@ 2018-09-05 20:02   ` Tim Schumacher
  2018-09-06 13:38     ` Ævar Arnfjörð Bjarmason
  2018-09-06 14:17     ` Ævar Arnfjörð Bjarmason
  2018-09-05 21:51   ` Junio C Hamano
  1 sibling, 2 replies; 37+ messages in thread
From: Tim Schumacher @ 2018-09-05 20:02 UTC (permalink / raw)
  To: Jeff King; +Cc: git, gitster

On 05.09.18 19:34, Jeff King wrote:
> On Wed, Sep 05, 2018 at 10:54:27AM +0200, Tim Schumacher wrote:
> 
>> Aliases can only contain non-alias git commands and their
>> arguments, not other user-defined aliases. Resolving further
>> (nested) aliases is prevented by breaking the loop after the
>> first alias was processed. Git then fails with a command-not-found
>> error.
>>
>> Allow resolving nested aliases by not breaking the loop in
>> run_argv() after the first alias was processed. Instead, continue
>> incrementing `done_alias` until `handle_alias()` fails, which means that
>> there are no further aliases that can be processed. Prevent looping
>> aliases by storing substituted commands in `cmd_list` and checking if
>> a command has been substituted previously.
>> ---
>>
>> This is what I've come up with to prevent looping aliases. I'm not too
>> happy with the number of indentations needed, but this seemed to be the
>> easiest way to search an array for a value.
> 
> I think this approach is OK, though I wonder if we'd also be fine with
> just:
> 
>    if (done_alias++ > 100)
> 	die("woah, is your alias looping?");
> 
> The point is just to prevent a runaway infinite loop, and this does that
> while keeping the cost very low for the common case (not that one string
> insertion is probably breaking the bank).

I'd opt to use the list-approach instead of aborting when the
counter reaches 100 (or any other value), because it aborts
at the earliest known looping point. I didn't run any tests
comparing both solutions, but I assume the list would perform
faster than the hard-limit, even if it requires slightly more
memory and lines of code.

I hope that I can put the string-list struct to some use,
so that the solution using lists becomes an equally good
solution code-wise.

> 
> It could also extend to ! aliases if we wanted (i.e., my '!git foo'
> example from earlier), but you'd have to carry the counter through the
> environment between processes.

That is a question about "shooting oneself in the foot" again,
but I think trying to prevent that would require more changes
than I can make, and it is definitely out-of-scope for this
patch.

> 
> -Peff
> 
Thanks for reviewing,

Tim

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

* Re: [RFC PATCH v2] Allow aliases that include other aliases
  2018-09-05 17:34 ` Jeff King
  2018-09-05 20:02   ` Tim Schumacher
@ 2018-09-05 21:51   ` Junio C Hamano
  1 sibling, 0 replies; 37+ messages in thread
From: Junio C Hamano @ 2018-09-05 21:51 UTC (permalink / raw)
  To: Jeff King; +Cc: Tim Schumacher, git

Jeff King <peff@peff.net> writes:

>> This is what I've come up with to prevent looping aliases. I'm not too
>> happy with the number of indentations needed, but this seemed to be the
>> easiest way to search an array for a value.
>
> I think this approach is OK, though I wonder if we'd also be fine with
> just:
>
>   if (done_alias++ > 100)
> 	die("woah, is your alias looping?");
>
> The point is just to prevent a runaway infinite loop, and this does that
> while keeping the cost very low for the common case (not that one string
> insertion is probably breaking the bank).

Yeah, as a hack, I guess the simpler the solution, the better it
would be.


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

* [PATCH v3] Allow aliases that include other aliases
  2018-09-05  8:54 [RFC PATCH v2] Allow aliases that include other aliases Tim Schumacher
                   ` (2 preceding siblings ...)
  2018-09-05 17:34 ` Jeff King
@ 2018-09-06 10:16 ` " Tim Schumacher
  2018-09-06 14:01   ` Ævar Arnfjörð Bjarmason
  2018-09-06 14:59   ` Jeff King
  2018-09-07 22:44 ` [RFC PATCH v4 1/3] Add support for nested aliases Tim Schumacher
  4 siblings, 2 replies; 37+ messages in thread
From: Tim Schumacher @ 2018-09-06 10:16 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, pclouds

Aliases can only contain non-alias git commands and their
arguments, not other user-defined aliases. Resolving further
(nested) aliases is prevented by breaking the loop after the
first alias was processed. Git then fails with a command-not-found
error.

Allow resolving nested aliases by not breaking the loop in
run_argv() after the first alias was processed. Instead, continue
incrementing `done_alias` until `handle_alias()` fails, which means that
there are no further aliases that can be processed. Prevent looping
aliases by storing substituted commands in `cmd_list` and checking if
a command has been substituted previously.

While we're at it, fix a styling issue just below the added code.
---
 git.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/git.c b/git.c
index c27c38738..64f5fbd57 100644
--- a/git.c
+++ b/git.c
@@ -674,6 +674,7 @@ static void execv_dashed_external(const char **argv)
 static int run_argv(int *argcp, const char ***argv)
 {
 	int done_alias = 0;
+	struct string_list cmd_list = STRING_LIST_INIT_NODUP;
 
 	while (1) {
 		/*
@@ -691,17 +692,23 @@ static int run_argv(int *argcp, const char ***argv)
 		/* .. then try the external ones */
 		execv_dashed_external(*argv);
 
-		/* It could be an alias -- this works around the insanity
+		if (string_list_has_string(&cmd_list, *argv[0]))
+			die(_("loop alias: %s is called twice"), *argv[0]);
+
+		string_list_append(&cmd_list, *argv[0]);
+
+		/*
+		 * It could be an alias -- this works around the insanity
 		 * of overriding "git log" with "git show" by having
 		 * alias.log = show
 		 */
-		if (done_alias)
-			break;
 		if (!handle_alias(argcp, argv))
 			break;
-		done_alias = 1;
+		done_alias++;
 	}
 
+	string_list_clear(&cmd_list, 0);
+
 	return done_alias;
 }
 
-- 
2.19.0.rc1.2.g8008c49c4.dirty


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

* Re: [RFC PATCH v2] Allow aliases that include other aliases
  2018-09-05 20:02   ` Tim Schumacher
@ 2018-09-06 13:38     ` Ævar Arnfjörð Bjarmason
  2018-09-06 14:17     ` Ævar Arnfjörð Bjarmason
  1 sibling, 0 replies; 37+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-09-06 13:38 UTC (permalink / raw)
  To: Tim Schumacher; +Cc: Jeff King, git, gitster


On Wed, Sep 05 2018, Tim Schumacher wrote:

> On 05.09.18 19:34, Jeff King wrote:
>> On Wed, Sep 05, 2018 at 10:54:27AM +0200, Tim Schumacher wrote:
>>
>>> Aliases can only contain non-alias git commands and their
>>> arguments, not other user-defined aliases. Resolving further
>>> (nested) aliases is prevented by breaking the loop after the
>>> first alias was processed. Git then fails with a command-not-found
>>> error.
>>>
>>> Allow resolving nested aliases by not breaking the loop in
>>> run_argv() after the first alias was processed. Instead, continue
>>> incrementing `done_alias` until `handle_alias()` fails, which means that
>>> there are no further aliases that can be processed. Prevent looping
>>> aliases by storing substituted commands in `cmd_list` and checking if
>>> a command has been substituted previously.
>>> ---
>>>
>>> This is what I've come up with to prevent looping aliases. I'm not too
>>> happy with the number of indentations needed, but this seemed to be the
>>> easiest way to search an array for a value.
>>
>> I think this approach is OK, though I wonder if we'd also be fine with
>> just:
>>
>>    if (done_alias++ > 100)
>> 	die("woah, is your alias looping?");
>>
>> The point is just to prevent a runaway infinite loop, and this does that
>> while keeping the cost very low for the common case (not that one string
>> insertion is probably breaking the bank).
>
> I'd opt to use the list-approach instead of aborting when the
> counter reaches 100 (or any other value), because it aborts
> at the earliest known looping point. I didn't run any tests
> comparing both solutions, but I assume the list would perform
> faster than the hard-limit, even if it requires slightly more
> memory and lines of code.

I agree that this use of a list is better for a completely different
reason (which I'll comment on in the v4 thread), but this reason doesn't
make any sense to me.

If we're looking at performance we're paying a fixed performance cost
for storing this list of strings over a counter for everything we do
with aliases.

It only helps over a counter for the case where we do have a loop, but
at that point who cares? We're going to exit with an erro anyway and the
user has to fix his config, it doesn't matter if that error happens 1
millisecond earlier.

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

* Re: [PATCH v3] Allow aliases that include other aliases
  2018-09-06 10:16 ` [PATCH v3] " Tim Schumacher
@ 2018-09-06 14:01   ` Ævar Arnfjörð Bjarmason
  2018-09-06 14:57     ` Jeff King
  2018-09-06 14:59   ` Jeff King
  1 sibling, 1 reply; 37+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-09-06 14:01 UTC (permalink / raw)
  To: Tim Schumacher; +Cc: git, gitster, peff, pclouds


On Thu, Sep 06 2018, Tim Schumacher wrote:

> Aliases can only contain non-alias git commands and their
> arguments, not other user-defined aliases. Resolving further
> (nested) aliases is prevented by breaking the loop after the
> first alias was processed. Git then fails with a command-not-found
> error.
>
> Allow resolving nested aliases by not breaking the loop in
> run_argv() after the first alias was processed. Instead, continue
> incrementing `done_alias` until `handle_alias()` fails, which means that
> there are no further aliases that can be processed. Prevent looping
> aliases by storing substituted commands in `cmd_list` and checking if
> a command has been substituted previously.
>
> While we're at it, fix a styling issue just below the added code.
> ---
>  git.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/git.c b/git.c
> index c27c38738..64f5fbd57 100644
> --- a/git.c
> +++ b/git.c
> @@ -674,6 +674,7 @@ static void execv_dashed_external(const char **argv)
>  static int run_argv(int *argcp, const char ***argv)
>  {
>  	int done_alias = 0;
> +	struct string_list cmd_list = STRING_LIST_INIT_NODUP;
>
>  	while (1) {
>  		/*
> @@ -691,17 +692,23 @@ static int run_argv(int *argcp, const char ***argv)
>  		/* .. then try the external ones */
>  		execv_dashed_external(*argv);
>
> -		/* It could be an alias -- this works around the insanity
> +		if (string_list_has_string(&cmd_list, *argv[0]))
> +			die(_("loop alias: %s is called twice"), *argv[0]);
> +
> +		string_list_append(&cmd_list, *argv[0]);
> +
> +		/*
> +		 * It could be an alias -- this works around the insanity
>  		 * of overriding "git log" with "git show" by having
>  		 * alias.log = show
>  		 */
> -		if (done_alias)
> -			break;
>  		if (!handle_alias(argcp, argv))
>  			break;
> -		done_alias = 1;
> +		done_alias++;
>  	}
>
> +	string_list_clear(&cmd_list, 0);
> +
>  	return done_alias;
>  }

[In my just-sent
https://public-inbox.org/git/87r2i6rbiy.fsf@evledraar.gmail.com/ I
should have said "the v3 thread"]

Thanks for working on this, comments:

If we don't have some test for these sort of aliasing loops that fails
now, we really should add that in a 1/2 and fix it in this patch in 2/2.

This error reporting is quite bad, consider:

    [alias]
        foo = bar
        bar = baz
        baz = foo

We then say:

    $ ./git --exec-path=$PWD foo
    fatal: loop alias: bar is called twice

That makes sense from an implementaion perspective, i.e. we lookup "bar"
twice. But let's do better. If I have aliase like:

    a = b
    b = c
    c = d
    d = e
    e = c

It should be telling me that my "e" expansion looped back to the "c = d"
expansion. Here's a patch to implement that, feel free to either squash
it in with my Signed-Off-By, or tacked onto a v4 version of this,
whichever you think makes sense:

diff --git a/git.c b/git.c
index 64f5fbd572..38f1033e52 100644
--- a/git.c
+++ b/git.c
@@ -692,8 +692,64 @@ static int run_argv(int *argcp, const char ***argv)
 		/* .. then try the external ones */
 		execv_dashed_external(*argv);

-		if (string_list_has_string(&cmd_list, *argv[0]))
-			die(_("loop alias: %s is called twice"), *argv[0]);
+		if (string_list_has_string(&cmd_list, *argv[0])) {
+			struct strbuf sb = STRBUF_INIT;
+			int i, seen_at_idx = -1;
+
+			/*
+			 * Find the re-entry point for the alias
+			 * loop. TODO: There really should be a
+			 * "return the index of the first matching"
+			 * helper in string-list.c.
+			 */
+			for (i = 0; i < cmd_list.nr; i++) {
+				if (!strcmp(*argv[0], cmd_list.items[i].string))
+					seen_at_idx = i;
+			}
+			assert(seen_at_idx != -1);
+
+			for (i = 1; i < cmd_list.nr; i++) {
+				if (i - 1 == seen_at_idx)
+					/*
+					 * TRANSLATORS: This is a the
+					 * re-enttry point in the list
+					 * printed out by the "alias
+					 * loop" message below.
+					 */
+					strbuf_addf(&sb, _("    %d. %s = %s <== The re-entry point in the loop\n"),
+						    i,
+						    cmd_list.items[i - 1].string,
+						    cmd_list.items[i].string);
+				else
+					/*
+					 * TRANSLATORS: This is a
+					 * single item in the list
+					 * printed out by the "alias
+					 * loop" message below.
+					 */
+					strbuf_addf(&sb, _("    %d. %s = %s\n"),
+						    i,
+						    cmd_list.items[i - 1].string,
+						    cmd_list.items[i].string);
+			}
+			/*
+			 * TRANSLATORS: This is the last item in the
+			 * list printed out by the "alias loop"
+			 * message below.
+			 */
+			strbuf_addf(&sb, _("    %d. %s = %s <== This is where the loop started!"),
+				    i,
+				    cmd_list.items[i - 1].string,
+				    *argv[0]);
+			/*
+			 * TRANSLATORS: The %s here at the end is
+			 * going to be a list of aliases as formatted
+			 * by the messages whose comments mention
+			 * "alias loop" above.
+			 */
+			die(_("alias loop: When expanding the alias '%s' we ran into a loop:\n%s"),
+			    cmd_list.items[0].string, sb.buf);
+		}

 		string_list_append(&cmd_list, *argv[0]);

Now we'll print errors like:

    $ ./git --exec-path=$PWD a
    fatal: alias loop: When expanding the alias 'a' we ran into a loop:
        1. a = b
        2. b = c
        3. c = d <== The re-entry point in the loop
        4. d = e
        5. e = c <== This is where the loop started!

Or, in the much simpler case of foo = bar; bar = foo:

    $ ./git --exec-path=$PWD foo
    fatal: alias loop: When expanding the alias 'foo' we ran into a loop:
        1. foo = bar <== The re-entry point in the loop
        2. bar = foo <== This is where the loop started!

I haven't tested this much, so maybe there's some edge cases I haven't
thought of / bugs in this reporting code, but hey, that's what the tests
I suggested are for :)

It's a lot more verbose, but I think it's worth it to produce better
error messages.

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

* Re: [RFC PATCH v2] Allow aliases that include other aliases
  2018-09-05 20:02   ` Tim Schumacher
  2018-09-06 13:38     ` Ævar Arnfjörð Bjarmason
@ 2018-09-06 14:17     ` Ævar Arnfjörð Bjarmason
  1 sibling, 0 replies; 37+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-09-06 14:17 UTC (permalink / raw)
  To: Tim Schumacher; +Cc: Jeff King, git, gitster


On Wed, Sep 05 2018, Tim Schumacher wrote:

> On 05.09.18 19:34, Jeff King wrote:
>>
>> It could also extend to ! aliases if we wanted (i.e., my '!git foo'
>> example from earlier), but you'd have to carry the counter through the
>> environment between processes.
>
> That is a question about "shooting oneself in the foot" again,
> but I think trying to prevent that would require more changes
> than I can make, and it is definitely out-of-scope for this
> patch.

I agree it could be done later, but it would be great if you could
follow-up with that. Right now if you do:

    a = !git b
    b = !git a

You end up with a fork bomb, and we don't guard against this, and if you
have mixed execution / internal aliasing, e.g.:

    a = b
    b = c
    c = d
    d = !git a

The loop detection doesn't kick in.

It should be easy to add detection for this on top. See what we do with
git_config_push_parameter() in git.c already, i.e. you'd add some
simliar env variable, set items in the string list delimited by
e.g. whitespace, and then just pre-populate your string list with that
if it's set, and re-set it & carry it forward.

Then any combination of internal aliasing and custom commands will
benefit from loop detection.

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

* Re: [PATCH v3] Allow aliases that include other aliases
  2018-09-06 14:01   ` Ævar Arnfjörð Bjarmason
@ 2018-09-06 14:57     ` Jeff King
  2018-09-06 15:10       ` Ævar Arnfjörð Bjarmason
  2018-09-06 19:05       ` Tim Schumacher
  0 siblings, 2 replies; 37+ messages in thread
From: Jeff King @ 2018-09-06 14:57 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Tim Schumacher, git, gitster, pclouds

On Thu, Sep 06, 2018 at 04:01:39PM +0200, Ævar Arnfjörð Bjarmason wrote:

> If we don't have some test for these sort of aliasing loops that fails
> now, we really should add that in a 1/2 and fix it in this patch in 2/2.

Yes, I'd agree that this is worth adding a test (especially if the
output routines get more complex).

> That makes sense from an implementaion perspective, i.e. we lookup "bar"
> twice. But let's do better. If I have aliase like:
> 
>     a = b
>     b = c
>     c = d
>     d = e
>     e = c
> 
> It should be telling me that my "e" expansion looped back to the "c = d"
> expansion. Here's a patch to implement that, feel free to either squash
> it in with my Signed-Off-By, or tacked onto a v4 version of this,
> whichever you think makes sense:

I don't have a strong opinion on whether this is worth it, but I think
your implementation could be a little simpler:

> diff --git a/git.c b/git.c
> index 64f5fbd572..38f1033e52 100644
> --- a/git.c
> +++ b/git.c
> @@ -692,8 +692,64 @@ static int run_argv(int *argcp, const char ***argv)
>  		/* .. then try the external ones */
>  		execv_dashed_external(*argv);
> 
> -		if (string_list_has_string(&cmd_list, *argv[0]))
> -			die(_("loop alias: %s is called twice"), *argv[0]);
> +		if (string_list_has_string(&cmd_list, *argv[0])) {
> +			struct strbuf sb = STRBUF_INIT;
> +			int i, seen_at_idx = -1;
> +
> +			/*
> +			 * Find the re-entry point for the alias
> +			 * loop. TODO: There really should be a
> +			 * "return the index of the first matching"
> +			 * helper in string-list.c.
> +			 */
> +			for (i = 0; i < cmd_list.nr; i++) {
> +				if (!strcmp(*argv[0], cmd_list.items[i].string))
> +					seen_at_idx = i;
> +			}
> +			assert(seen_at_idx != -1);

The string-list code doesn't generally deal in indices. You can use
string_list_find_insert_index(), but its return value is a little funky
for the existing case. You can also just do:

  struct string_list_item *seen;
  ...
  seen = string_list_lookup(&cmd_list, *argv[0]);
  if (seen) {
	/* we have a loop */
	int idx = seen - cmd_list.items;

That's a little intimate with the string-list implementation as an array
of string_list, but it's already pretty standard to walk over and
dereference that list (including in your patch). But also see below.

Side note: there's actually a bigger problem with the original patch:
the string list is unsorted (because it uses string_list_append(), and
which is why your linear walk works here). But string_list_has_string()
assumes it is sorted.  So I think we'd actually want to use
unsorted_string_list_has_string() or unsorted_string_list_lookup().

> +			for (i = 1; i < cmd_list.nr; i++) {
> +				if (i - 1 == seen_at_idx)
> +					/*
> +					 * TRANSLATORS: This is a the
> +					 * re-enttry point in the list
> +					 * printed out by the "alias
> +					 * loop" message below.
> +					 */
> +					strbuf_addf(&sb, _("    %d. %s = %s <== The re-entry point in the loop\n"),
> +						    i,
> +						    cmd_list.items[i - 1].string,
> +						    cmd_list.items[i].string);

This is always going to show the right-hand of the equals as the
left-hand on the next line. Would it be simpler to just show the list?
Likewise, the last item in the list is always going to be "where the
loop started". Do we need to say that?

E.g., something like:

  seen = unsorted_string_list_lookup(&cmd_list, *argv[0]);
  if (seen) {
          for (i = 0; i < cmd_list.nr; i++) {
		struct string_list *item = cmd_list.items[i];

		strbuf_addf(&sb, "  %s", item->string);
		if (item == seen)
			strbuf_add(&sb, " <==");
		strbuf_addch(&sb, '\n');
	  }
	  /* We never added this to the list, but we were about to */
	  strbuf_addch("  %s\n", seen->string);
	  die(...);
  }

I guess it's not that far off of yours. Not using words to describe the
loop entry and exit points avoids translation, which avoids notes to
translators, which is most of what makes your patch long. ;)

-Peff

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

* Re: [PATCH v3] Allow aliases that include other aliases
  2018-09-06 10:16 ` [PATCH v3] " Tim Schumacher
  2018-09-06 14:01   ` Ævar Arnfjörð Bjarmason
@ 2018-09-06 14:59   ` Jeff King
  2018-09-06 18:40     ` Junio C Hamano
  1 sibling, 1 reply; 37+ messages in thread
From: Jeff King @ 2018-09-06 14:59 UTC (permalink / raw)
  To: Tim Schumacher; +Cc: git, gitster, pclouds

On Thu, Sep 06, 2018 at 12:16:58PM +0200, Tim Schumacher wrote:

> @@ -691,17 +692,23 @@ static int run_argv(int *argcp, const char ***argv)
>  		/* .. then try the external ones */
>  		execv_dashed_external(*argv);
>  
> -		/* It could be an alias -- this works around the insanity
> +		if (string_list_has_string(&cmd_list, *argv[0]))
> +			die(_("loop alias: %s is called twice"), *argv[0]);

I pointed this out in my response to Ævar, but I want to make sure it
gets seen. This call assumes the list is sorted, but...

> +		string_list_append(&cmd_list, *argv[0]);

This will create an unsorted list. You'd have to use
string_list_insert() here for a sorted list, or
unsorted_string_list_has_string() in the earlier call.

It's unfortunate that string_list makes this so easy to get wrong.

> +
> +		/*
> +		 * It could be an alias -- this works around the insanity
>  		 * of overriding "git log" with "git show" by having
>  		 * alias.log = show
>  		 */
> -		if (done_alias)
> -			break;
>  		if (!handle_alias(argcp, argv))
>  			break;
> -		done_alias = 1;
> +		done_alias++;

I don't think anybody cares about done_alias being an accurate count.
Should we just leave this as-is?

-Peff

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

* Re: [PATCH v3] Allow aliases that include other aliases
  2018-09-06 14:57     ` Jeff King
@ 2018-09-06 15:10       ` Ævar Arnfjörð Bjarmason
  2018-09-06 16:18         ` Jeff King
  2018-09-06 19:05       ` Tim Schumacher
  1 sibling, 1 reply; 37+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-09-06 15:10 UTC (permalink / raw)
  To: Jeff King; +Cc: Tim Schumacher, git, gitster, pclouds


On Thu, Sep 06 2018, Jeff King wrote:

> On Thu, Sep 06, 2018 at 04:01:39PM +0200, Ævar Arnfjörð Bjarmason wrote:
>
>> If we don't have some test for these sort of aliasing loops that fails
>> now, we really should add that in a 1/2 and fix it in this patch in 2/2.
>
> Yes, I'd agree that this is worth adding a test (especially if the
> output routines get more complex).
>
>> That makes sense from an implementaion perspective, i.e. we lookup "bar"
>> twice. But let's do better. If I have aliase like:
>>
>>     a = b
>>     b = c
>>     c = d
>>     d = e
>>     e = c
>>
>> It should be telling me that my "e" expansion looped back to the "c = d"
>> expansion. Here's a patch to implement that, feel free to either squash
>> it in with my Signed-Off-By, or tacked onto a v4 version of this,
>> whichever you think makes sense:
>
> I don't have a strong opinion on whether this is worth it, but I think
> your implementation could be a little simpler:
>
>> diff --git a/git.c b/git.c
>> index 64f5fbd572..38f1033e52 100644
>> --- a/git.c
>> +++ b/git.c
>> @@ -692,8 +692,64 @@ static int run_argv(int *argcp, const char ***argv)
>>  		/* .. then try the external ones */
>>  		execv_dashed_external(*argv);
>>
>> -		if (string_list_has_string(&cmd_list, *argv[0]))
>> -			die(_("loop alias: %s is called twice"), *argv[0]);
>> +		if (string_list_has_string(&cmd_list, *argv[0])) {
>> +			struct strbuf sb = STRBUF_INIT;
>> +			int i, seen_at_idx = -1;
>> +
>> +			/*
>> +			 * Find the re-entry point for the alias
>> +			 * loop. TODO: There really should be a
>> +			 * "return the index of the first matching"
>> +			 * helper in string-list.c.
>> +			 */
>> +			for (i = 0; i < cmd_list.nr; i++) {
>> +				if (!strcmp(*argv[0], cmd_list.items[i].string))
>> +					seen_at_idx = i;
>> +			}
>> +			assert(seen_at_idx != -1);
>
> The string-list code doesn't generally deal in indices. You can use
> string_list_find_insert_index(), but its return value is a little funky
> for the existing case. You can also just do:
>
>   struct string_list_item *seen;
>   ...
>   seen = string_list_lookup(&cmd_list, *argv[0]);
>   if (seen) {
> 	/* we have a loop */
> 	int idx = seen - cmd_list.items;
>
> That's a little intimate with the string-list implementation as an array
> of string_list, but it's already pretty standard to walk over and
> dereference that list (including in your patch). But also see below.
>
> Side note: there's actually a bigger problem with the original patch:
> the string list is unsorted (because it uses string_list_append(), and
> which is why your linear walk works here). But string_list_has_string()
> assumes it is sorted.  So I think we'd actually want to use
> unsorted_string_list_has_string() or unsorted_string_list_lookup().
>
>> +			for (i = 1; i < cmd_list.nr; i++) {
>> +				if (i - 1 == seen_at_idx)
>> +					/*
>> +					 * TRANSLATORS: This is a the
>> +					 * re-enttry point in the list
>> +					 * printed out by the "alias
>> +					 * loop" message below.
>> +					 */
>> +					strbuf_addf(&sb, _("    %d. %s = %s <== The re-entry point in the loop\n"),
>> +						    i,
>> +						    cmd_list.items[i - 1].string,
>> +						    cmd_list.items[i].string);
>
> This is always going to show the right-hand of the equals as the
> left-hand on the next line. Would it be simpler to just show the list?
> Likewise, the last item in the list is always going to be "where the
> loop started". Do we need to say that?

Yeah maybe that's overzealous. I figured in the spirit of clang & GCC
compiler messages these days there's no such thing as too dumbed down :)

> E.g., something like:
>
>   seen = unsorted_string_list_lookup(&cmd_list, *argv[0]);
>   if (seen) {
>           for (i = 0; i < cmd_list.nr; i++) {
> 		struct string_list *item = cmd_list.items[i];
>
> 		strbuf_addf(&sb, "  %s", item->string);
> 		if (item == seen)
> 			strbuf_add(&sb, " <==");
> 		strbuf_addch(&sb, '\n');
> 	  }
> 	  /* We never added this to the list, but we were about to */
> 	  strbuf_addch("  %s\n", seen->string);
> 	  die(...);
>   }
>
> I guess it's not that far off of yours. Not using words to describe the
> loop entry and exit points avoids translation, which avoids notes to
> translators, which is most of what makes your patch long. ;)

This still needs translation for RTL languages. I.e. they'd want to
print out the equivalent of "%s " followed by "==> %s ". We happen to
(unfortunately) not carry such a language yet, but it's worth
future-proofing output as we add it in case we get one.

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

* Re: [PATCH v3] Allow aliases that include other aliases
  2018-09-06 15:10       ` Ævar Arnfjörð Bjarmason
@ 2018-09-06 16:18         ` Jeff King
  0 siblings, 0 replies; 37+ messages in thread
From: Jeff King @ 2018-09-06 16:18 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Tim Schumacher, git, gitster, pclouds

On Thu, Sep 06, 2018 at 05:10:04PM +0200, Ævar Arnfjörð Bjarmason wrote:

> >   seen = unsorted_string_list_lookup(&cmd_list, *argv[0]);
> >   if (seen) {
> >           for (i = 0; i < cmd_list.nr; i++) {
> > 		struct string_list *item = cmd_list.items[i];
> >
> > 		strbuf_addf(&sb, "  %s", item->string);
> > 		if (item == seen)
> > 			strbuf_add(&sb, " <==");
> > 		strbuf_addch(&sb, '\n');
> > 	  }
> > 	  /* We never added this to the list, but we were about to */
> > 	  strbuf_addch("  %s\n", seen->string);
> > 	  die(...);
> >   }
> >
> > I guess it's not that far off of yours. Not using words to describe the
> > loop entry and exit points avoids translation, which avoids notes to
> > translators, which is most of what makes your patch long. ;)
> 
> This still needs translation for RTL languages. I.e. they'd want to
> print out the equivalent of "%s " followed by "==> %s ". We happen to
> (unfortunately) not carry such a language yet, but it's worth
> future-proofing output as we add it in case we get one.

I'd have thought even in an RTL language that something like an "I'm
pointing to this" sign wouldn't matter (i.e., an LTR language person,
I'd be fine with either "==> %s" or "%s <=="). But obviously I have no
experience in the matter, so I'd defer to people who read RTL (or at
least have handled i18n for it before).

-Peff

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

* Re: [PATCH v3] Allow aliases that include other aliases
  2018-09-06 14:59   ` Jeff King
@ 2018-09-06 18:40     ` Junio C Hamano
  2018-09-06 19:05       ` Jeff King
  2018-09-06 19:31       ` Tim Schumacher
  0 siblings, 2 replies; 37+ messages in thread
From: Junio C Hamano @ 2018-09-06 18:40 UTC (permalink / raw)
  To: Jeff King; +Cc: Tim Schumacher, git, pclouds

Jeff King <peff@peff.net> writes:

> On Thu, Sep 06, 2018 at 12:16:58PM +0200, Tim Schumacher wrote:
>
>> @@ -691,17 +692,23 @@ static int run_argv(int *argcp, const char ***argv)
>>  		/* .. then try the external ones */
>>  		execv_dashed_external(*argv);
>>  
>> -		/* It could be an alias -- this works around the insanity
>> +		if (string_list_has_string(&cmd_list, *argv[0]))
>> +			die(_("loop alias: %s is called twice"), *argv[0]);
>
> I pointed this out in my response to Ævar, but I want to make sure it
> gets seen. This call assumes the list is sorted, but...
>
>> +		string_list_append(&cmd_list, *argv[0]);
>
> This will create an unsorted list. You'd have to use
> string_list_insert() here for a sorted list, or
> unsorted_string_list_has_string() in the earlier call.

Correct.

Also, normal users who have never seen this loop that implements
alias expansion would not have a clue when they see "called twice".

I actually think the caller should also pass cmd to run_argv() and
then we should use it (and not argv[]) in this die() message.  When
the original command was foo that is aliased to bar, which in turn
is aliased to baz, which in turn is aliased to bar, especially that
"git foo" invocation was in a random script written six weeks ago by
the user, it would be a lot more helpful to see 

    "alias loop detected: expansion of 'git foo' does not terminate"

than

    "loop alias: bar is called twice".

given that 'bar' is not something the user called, or written in the
script she wrote six weeks ago.

> It's unfortunate that string_list makes this so easy to get wrong.
>
>> +
>> +		/*
>> +		 * It could be an alias -- this works around the insanity
>>  		 * of overriding "git log" with "git show" by having
>>  		 * alias.log = show
>>  		 */
>> -		if (done_alias)
>> -			break;
>>  		if (!handle_alias(argcp, argv))
>>  			break;
>> -		done_alias = 1;
>> +		done_alias++;
>
> I don't think anybody cares about done_alias being an accurate count.
> Should we just leave this as-is?

Good point.  The only caller treats it as a bool (i.e. "should the
failure be reported as failure to expand an alias cmd which resulted
in (updated) argv[0] that is not a git command?").

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

* Re: [PATCH v3] Allow aliases that include other aliases
  2018-09-06 18:40     ` Junio C Hamano
@ 2018-09-06 19:05       ` Jeff King
  2018-09-06 19:31       ` Tim Schumacher
  1 sibling, 0 replies; 37+ messages in thread
From: Jeff King @ 2018-09-06 19:05 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Ævar Arnfjörð Bjarmason, Tim Schumacher, git, pclouds

On Thu, Sep 06, 2018 at 11:40:14AM -0700, Junio C Hamano wrote:

> Also, normal users who have never seen this loop that implements
> alias expansion would not have a clue when they see "called twice".
> 
> I actually think the caller should also pass cmd to run_argv() and
> then we should use it (and not argv[]) in this die() message.  When
> the original command was foo that is aliased to bar, which in turn
> is aliased to baz, which in turn is aliased to bar, especially that
> "git foo" invocation was in a random script written six weeks ago by
> the user, it would be a lot more helpful to see 
> 
>     "alias loop detected: expansion of 'git foo' does not terminate"
> 
> than
> 
>     "loop alias: bar is called twice".
> 
> given that 'bar' is not something the user called, or written in the
> script she wrote six weeks ago.

Good point. I think Ævar's "print the whole list" solves that, because
items[0] is that first element. But I agree the fundamental message
should be "loop in 'git foo'".

-Peff

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

* Re: [PATCH v3] Allow aliases that include other aliases
  2018-09-06 14:57     ` Jeff King
  2018-09-06 15:10       ` Ævar Arnfjörð Bjarmason
@ 2018-09-06 19:05       ` Tim Schumacher
  2018-09-06 19:17         ` Jeff King
  1 sibling, 1 reply; 37+ messages in thread
From: Tim Schumacher @ 2018-09-06 19:05 UTC (permalink / raw)
  To: Jeff King, Ævar Arnfjörð Bjarmason; +Cc: git, gitster, pclouds

On 06.09.18 16:57, Jeff King wrote:
> On Thu, Sep 06, 2018 at 04:01:39PM +0200, Ævar Arnfjörð Bjarmason wrote:
> 
>> If we don't have some test for these sort of aliasing loops that fails
>> now, we really should add that in a 1/2 and fix it in this patch in 2/2.
> 
> Yes, I'd agree that this is worth adding a test (especially if the
> output routines get more complex).

I'll try to come up with a few tests (or one at this point, as we only have
a solution for internal aliases so far) and put them as 1/2. However, I don't know
what file I should put those tests into. t0001-init and t1300-config both seem
to test aliases, but I'm unsure if the new tests should go into one of those
files or a completely new one that is dedicated to aliases.

> 
>> That makes sense from an implementaion perspective, i.e. we lookup "bar"
>> twice. But let's do better. If I have aliase like:
>>
>>      a = b
>>      b = c
>>      c = d
>>      d = e
>>      e = c
>>
>> It should be telling me that my "e" expansion looped back to the "c = d"
>> expansion. Here's a patch to implement that, feel free to either squash
>> it in with my Signed-Off-By, or tacked onto a v4 version of this,
>> whichever you think makes sense:
> 
> I don't have a strong opinion on whether this is worth it, but I think
> your implementation could be a little simpler:
> 
>> diff --git a/git.c b/git.c
>> index 64f5fbd572..38f1033e52 100644
>> --- a/git.c
>> +++ b/git.c
>> @@ -692,8 +692,64 @@ static int run_argv(int *argcp, const char ***argv)
>>   		/* .. then try the external ones */
>>   		execv_dashed_external(*argv);
>>
>> -		if (string_list_has_string(&cmd_list, *argv[0]))
>> -			die(_("loop alias: %s is called twice"), *argv[0]);
>> +		if (string_list_has_string(&cmd_list, *argv[0])) {
>> +			struct strbuf sb = STRBUF_INIT;
>> +			int i, seen_at_idx = -1;
>> +
>> +			/*
>> +			 * Find the re-entry point for the alias
>> +			 * loop. TODO: There really should be a
>> +			 * "return the index of the first matching"
>> +			 * helper in string-list.c.
>> +			 */
>> +			for (i = 0; i < cmd_list.nr; i++) {
>> +				if (!strcmp(*argv[0], cmd_list.items[i].string))
>> +					seen_at_idx = i;
>> +			}
>> +			assert(seen_at_idx != -1);
> 
> The string-list code doesn't generally deal in indices. You can use
> string_list_find_insert_index(), but its return value is a little funky
> for the existing case. You can also just do:
> 
>    struct string_list_item *seen;
>    ...
>    seen = string_list_lookup(&cmd_list, *argv[0]);
>    if (seen) {
> 	/* we have a loop */
> 	int idx = seen - cmd_list.items;
> 
> That's a little intimate with the string-list implementation as an array
> of string_list, but it's already pretty standard to walk over and
> dereference that list (including in your patch). But also see below.
> 
> Side note: there's actually a bigger problem with the original patch:
> the string list is unsorted (because it uses string_list_append(), and
> which is why your linear walk works here). But string_list_has_string()
> assumes it is sorted.  So I think we'd actually want to use
> unsorted_string_list_has_string() or unsorted_string_list_lookup().

I'll update v4 to use use unsorted_string_list_has_string().
> 
>> +			for (i = 1; i < cmd_list.nr; i++) {
>> +				if (i - 1 == seen_at_idx)
>> +					/*
>> +					 * TRANSLATORS: This is a the
>> +					 * re-enttry point in the list
>> +					 * printed out by the "alias
>> +					 * loop" message below.
>> +					 */
>> +					strbuf_addf(&sb, _("    %d. %s = %s <== The re-entry point in the loop\n"),
>> +						    i,
>> +						    cmd_list.items[i - 1].string,
>> +						    cmd_list.items[i].string);
> 
> This is always going to show the right-hand of the equals as the
> left-hand on the next line. Would it be simpler to just show the list?
> Likewise, the last item in the list is always going to be "where the
> loop started". Do we need to say that?
> 
> E.g., something like:
> 
>    seen = unsorted_string_list_lookup(&cmd_list, *argv[0]);
>    if (seen) {
>            for (i = 0; i < cmd_list.nr; i++) {
> 		struct string_list *item = cmd_list.items[i];
> 
> 		strbuf_addf(&sb, "  %s", item->string);
> 		if (item == seen)
> 			strbuf_add(&sb, " <==");
> 		strbuf_addch(&sb, '\n');
> 	  }
> 	  /* We never added this to the list, but we were about to */
> 	  strbuf_addch("  %s\n", seen->string);
> 	  die(...);
>    }
> 
> I guess it's not that far off of yours. Not using words to describe the
> loop entry and exit points avoids translation, which avoids notes to
> translators, which is most of what makes your patch long. ;)
> 
> -Peff
> 

I'll tinker around with both code snippets, we'll see which one is
more convenient for the user.

Thanks to all of you for the input!

Tim

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

* Re: [PATCH v3] Allow aliases that include other aliases
  2018-09-06 19:05       ` Tim Schumacher
@ 2018-09-06 19:17         ` Jeff King
  0 siblings, 0 replies; 37+ messages in thread
From: Jeff King @ 2018-09-06 19:17 UTC (permalink / raw)
  To: Tim Schumacher
  Cc: Ævar Arnfjörð Bjarmason, git, gitster, pclouds

On Thu, Sep 06, 2018 at 09:05:50PM +0200, Tim Schumacher wrote:

> On 06.09.18 16:57, Jeff King wrote:
> > On Thu, Sep 06, 2018 at 04:01:39PM +0200, Ævar Arnfjörð Bjarmason wrote:
> > 
> > > If we don't have some test for these sort of aliasing loops that fails
> > > now, we really should add that in a 1/2 and fix it in this patch in 2/2.
> > 
> > Yes, I'd agree that this is worth adding a test (especially if the
> > output routines get more complex).
> 
> I'll try to come up with a few tests (or one at this point, as we only have
> a solution for internal aliases so far) and put them as 1/2. However, I don't know
> what file I should put those tests into. t0001-init and t1300-config both seem
> to test aliases, but I'm unsure if the new tests should go into one of those
> files or a completely new one that is dedicated to aliases.

Yeah, I don't think there's a good place right now. It probably make
sense to start a new one (t0014-alias, maybe? This seems like a basic
functionality that should come early in the suite).

-Peff

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

* Re: [PATCH v3] Allow aliases that include other aliases
  2018-09-06 18:40     ` Junio C Hamano
  2018-09-06 19:05       ` Jeff King
@ 2018-09-06 19:31       ` Tim Schumacher
  1 sibling, 0 replies; 37+ messages in thread
From: Tim Schumacher @ 2018-09-06 19:31 UTC (permalink / raw)
  To: Junio C Hamano, Jeff King; +Cc: git, pclouds

On 06.09.18 20:40, Junio C Hamano wrote:
> Jeff King <peff@peff.net> writes:
> 
>> On Thu, Sep 06, 2018 at 12:16:58PM +0200, Tim Schumacher wrote:
>>
>>> @@ -691,17 +692,23 @@ static int run_argv(int *argcp, const char ***argv)
>>>   		/* .. then try the external ones */
>>>   		execv_dashed_external(*argv);
>>>   
>>> -		/* It could be an alias -- this works around the insanity
>>> +		if (string_list_has_string(&cmd_list, *argv[0]))
>>> +			die(_("loop alias: %s is called twice"), *argv[0]);
>>
>> I pointed this out in my response to Ævar, but I want to make sure it
>> gets seen. This call assumes the list is sorted, but...
>>
>>> +		string_list_append(&cmd_list, *argv[0]);
>>
>> This will create an unsorted list. You'd have to use
>> string_list_insert() here for a sorted list, or
>> unsorted_string_list_has_string() in the earlier call.
> 
> Correct.
> 
> Also, normal users who have never seen this loop that implements
> alias expansion would not have a clue when they see "called twice".
> 
> I actually think the caller should also pass cmd to run_argv() and
> then we should use it (and not argv[]) in this die() message.

Could we just save the first element of the original argv for that
purpose? Or alternatively, use the first stored element in the
command list?

> When
> the original command was foo that is aliased to bar, which in turn
> is aliased to baz, which in turn is aliased to bar, especially that
> "git foo" invocation was in a random script written six weeks ago by
> the user, it would be a lot more helpful to see
> 
>      "alias loop detected: expansion of 'git foo' does not terminate"
> 
> than
> 
>      "loop alias: bar is called twice".
> 
> given that 'bar' is not something the user called, or written in the
> script she wrote six weeks ago.

Indeed, printing the command that the user called is a better message
than the command that is the entry-point of the loop. I'll change it
in v4.

> 
>> It's unfortunate that string_list makes this so easy to get wrong.
>>
>>> +
>>> +		/*
>>> +		 * It could be an alias -- this works around the insanity
>>>   		 * of overriding "git log" with "git show" by having
>>>   		 * alias.log = show
>>>   		 */
>>> -		if (done_alias)
>>> -			break;
>>>   		if (!handle_alias(argcp, argv))
>>>   			break;
>>> -		done_alias = 1;
>>> +		done_alias++;
>>
>> I don't think anybody cares about done_alias being an accurate count.
>> Should we just leave this as-is?
> 
> Good point.  The only caller treats it as a bool (i.e. "should the
> failure be reported as failure to expand an alias cmd which resulted
> in (updated) argv[0] that is not a git command?").
> 

As the string-list has its own counter, I guess the done_alias variable
can be reverted to a simple 0/1 value.

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

* [RFC PATCH v4 1/3] Add support for nested aliases
  2018-09-05  8:54 [RFC PATCH v2] Allow aliases that include other aliases Tim Schumacher
                   ` (3 preceding siblings ...)
  2018-09-06 10:16 ` [PATCH v3] " Tim Schumacher
@ 2018-09-07 22:44 ` Tim Schumacher
  2018-09-07 22:44   ` [RFC PATCH v4 2/3] Show the call history when an alias is looping Tim Schumacher
                     ` (3 more replies)
  4 siblings, 4 replies; 37+ messages in thread
From: Tim Schumacher @ 2018-09-07 22:44 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, avarab, pclouds

Aliases can only contain non-alias git commands and their
arguments, not other user-defined aliases. Resolving further
(nested) aliases is prevented by breaking the loop after the
first alias was processed. Git then fails with a command-not-found
error.

Allow resolving nested aliases by not breaking the loop in
run_argv() after the first alias was processed. Instead, continue
the loop until `handle_alias()` fails, which means that there are
no further aliases that can be processed. Prevent looping aliases
by storing substituted commands in `cmd_list` and checking if
a command has been substituted previously.

While we're at it, fix a styling issue just below the added code.

Signed-off-by: Tim Schumacher <timschumi@gmx.de>
---
Changes since v3:
 - Print the command that the user entered instead of the command
   which caused the loop (and a nicer, more explanatory error message)
 - Use unsorted_string_list_has_string() instead of the sorted version
 - Fix a code style issue just below the modified code
 - done_alias is a simple boolean again (instead of a counter)

 git.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/git.c b/git.c
index c27c38738..15727c17f 100644
--- a/git.c
+++ b/git.c
@@ -674,6 +674,7 @@ static void execv_dashed_external(const char **argv)
 static int run_argv(int *argcp, const char ***argv)
 {
 	int done_alias = 0;
+	struct string_list cmd_list = STRING_LIST_INIT_NODUP;
 
 	while (1) {
 		/*
@@ -691,17 +692,25 @@ static int run_argv(int *argcp, const char ***argv)
 		/* .. then try the external ones */
 		execv_dashed_external(*argv);
 
-		/* It could be an alias -- this works around the insanity
+		if (unsorted_string_list_has_string(&cmd_list, *argv[0])) {
+			die(_("alias loop detected: expansion of '%s' does"
+			      " not terminate"), cmd_list.items[0].string);
+		}
+
+		string_list_append(&cmd_list, *argv[0]);
+
+		/*
+		 * It could be an alias -- this works around the insanity
 		 * of overriding "git log" with "git show" by having
 		 * alias.log = show
 		 */
-		if (done_alias)
-			break;
 		if (!handle_alias(argcp, argv))
 			break;
 		done_alias = 1;
 	}
 
+	string_list_clear(&cmd_list, 0);
+
 	return done_alias;
 }
 
-- 
2.19.0.rc2.1.g4c98b8d69.dirty


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

* [RFC PATCH v4 2/3] Show the call history when an alias is looping
  2018-09-07 22:44 ` [RFC PATCH v4 1/3] Add support for nested aliases Tim Schumacher
@ 2018-09-07 22:44   ` Tim Schumacher
  2018-09-08 13:34     ` Duy Nguyen
  2018-09-07 22:44   ` [RFC PATCH v4 3/3] t0014: Introduce alias testing suite Tim Schumacher
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 37+ messages in thread
From: Tim Schumacher @ 2018-09-07 22:44 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, avarab, pclouds

Just printing the command that the user entered is not particularly
helpful when trying to find the alias that causes the loop.

Print the history of substituted commands to help the user find the
offending alias. Mark the entrypoint of the loop with "<==" and the
last command (which looped back to the entrypoint) with "==>".

Signed-off-by: Tim Schumacher <timschumi@gmx.de>
---

I now went with Peff's suggested code and I added in an arrow that points
away from the last command (which caused the loop). A "full" arrow (i.e.
starts at the last command, goes upwards and ends at the entrypoint) would
be more obvious/better, but adding much more code just for having a
vertical line wasn't worth it for me.

 git.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/git.c b/git.c
index 15727c17f..a20eb4fa1 100644
--- a/git.c
+++ b/git.c
@@ -675,6 +675,7 @@ static int run_argv(int *argcp, const char ***argv)
 {
 	int done_alias = 0;
 	struct string_list cmd_list = STRING_LIST_INIT_NODUP;
+	struct string_list_item *seen;
 
 	while (1) {
 		/*
@@ -692,9 +693,21 @@ static int run_argv(int *argcp, const char ***argv)
 		/* .. then try the external ones */
 		execv_dashed_external(*argv);
 
-		if (unsorted_string_list_has_string(&cmd_list, *argv[0])) {
+		seen = unsorted_string_list_lookup(&cmd_list, *argv[0]);
+		if (seen) {
+			int i;
+			struct strbuf sb = STRBUF_INIT;
+			for (i = 0; i < cmd_list.nr; i++) {
+				struct string_list_item *item = &cmd_list.items[i];
+
+				strbuf_addf(&sb, "\n  %s", item->string);
+				if (item == seen)
+					strbuf_addstr(&sb, " <==");
+				else if (i == cmd_list.nr - 1)
+					strbuf_addstr(&sb, " ==>");
+			}
 			die(_("alias loop detected: expansion of '%s' does"
-			      " not terminate"), cmd_list.items[0].string);
+			      " not terminate:%s"), cmd_list.items[0].string, sb.buf);
 		}
 
 		string_list_append(&cmd_list, *argv[0]);
-- 
2.19.0.rc2.1.g4c98b8d69.dirty


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

* [RFC PATCH v4 3/3] t0014: Introduce alias testing suite
  2018-09-07 22:44 ` [RFC PATCH v4 1/3] Add support for nested aliases Tim Schumacher
  2018-09-07 22:44   ` [RFC PATCH v4 2/3] Show the call history when an alias is looping Tim Schumacher
@ 2018-09-07 22:44   ` Tim Schumacher
  2018-09-07 23:38     ` Eric Sunshine
  2018-09-08 13:28   ` [RFC PATCH v4 1/3] Add support for nested aliases Duy Nguyen
  2018-09-16  7:50   ` [PATCH v5 " Tim Schumacher
  3 siblings, 1 reply; 37+ messages in thread
From: Tim Schumacher @ 2018-09-07 22:44 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, avarab, pclouds

Introduce a testing suite that is dedicated to aliases.
For now, check only if nested aliases work and if looping
aliases are detected successfully.

The looping aliases check for mixed execution is there but
expected to fail because there is no check in place yet.

Signed-off-by: Tim Schumacher <timschumi@gmx.de>
---

Those are the tests that I've come up with. It consists of tests
for nested aliases and looping aliases, both with internal calls
and external calls.

Unfortunately I don't have a fix for the last one yet, so I
marked it as expect_failure. The problem is that the test suite
is waiting a full minute until it aborts the running command
(which I guess should not take that long, as it blocks the whole
test suite for that span of time).

Should I try to decrease the timeout or should I remove that
test completely until I manage to get external calls fixed?

As a last thing, is there any better way to use single quotes
than to write '"'"'? It isn't that bad, but it is hard to read,
especially for bash newcomers.

 t/t0014-alias.sh | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100755 t/t0014-alias.sh

diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh
new file mode 100755
index 000000000..6c1e34694
--- /dev/null
+++ b/t/t0014-alias.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+test_description='git command aliasing'
+
+. ./test-lib.sh
+
+test_expect_success 'setup environment' '
+	git init
+'
+
+test_expect_success 'nested aliases - internal execution' '
+	git config alias.nested-internal-1 nested-internal-2 &&
+	git config alias.nested-internal-2 status
+'
+
+test_expect_success 'nested aliases - mixed execution' '
+	git config alias.nested-external-1 "!git nested-external-2" &&
+	git config alias.nested-external-2 status
+'
+
+test_expect_success 'looping aliases - internal execution' '
+	git config alias.loop-internal-1 loop-internal-2 &&
+	git config alias.loop-internal-2 loop-internal-3 &&
+	git config alias.loop-internal-3 loop-internal-2 &&
+	test_must_fail git loop-internal-1 2>output &&
+	grep -q "fatal: alias loop detected: expansion of '"'"'loop-internal-1'"'"' does not terminate" output &&
+	rm output
+'
+
+test_expect_failure 'looping aliases - mixed execution' '
+	git config alias.loop-mixed-1 loop-mixed-2 &&
+	git config alias.loop-mixed-2 "!git loop-mixed-1" &&
+	test_must_fail git loop-mixed-1 2>output &&
+	grep -q "fatal: alias loop detected: expansion of '"'"'loop-mixed-1'"'"' does not terminate" output &&
+	rm output
+'
+
+test_done
-- 
2.19.0.rc2.1.g4c98b8d69.dirty


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

* Re: [RFC PATCH v4 3/3] t0014: Introduce alias testing suite
  2018-09-07 22:44   ` [RFC PATCH v4 3/3] t0014: Introduce alias testing suite Tim Schumacher
@ 2018-09-07 23:38     ` Eric Sunshine
  2018-09-14 23:12       ` Tim Schumacher
  0 siblings, 1 reply; 37+ messages in thread
From: Eric Sunshine @ 2018-09-07 23:38 UTC (permalink / raw)
  To: timschumi
  Cc: Git List, Junio C Hamano, Jeff King,
	Ævar Arnfjörð Bjarmason,
	Nguyễn Thái Ngọc Duy

On Fri, Sep 7, 2018 at 6:44 PM Tim Schumacher <timschumi@gmx.de> wrote:
> Introduce a testing suite that is dedicated to aliases.
> For now, check only if nested aliases work and if looping
> aliases are detected successfully.
>
> The looping aliases check for mixed execution is there but
> expected to fail because there is no check in place yet.
>
> Signed-off-by: Tim Schumacher <timschumi@gmx.de>
> ---
> Unfortunately I don't have a fix for the last one yet, so I
> marked it as expect_failure. The problem is that the test suite
> is waiting a full minute until it aborts the running command
> (which I guess should not take that long, as it blocks the whole
> test suite for that span of time).
>
> Should I try to decrease the timeout or should I remove that
> test completely until I manage to get external calls fixed?

Perhaps just comment out that test for now and add a comment above it
explaining why it's commented out.

> As a last thing, is there any better way to use single quotes
> than to write '"'"'? It isn't that bad, but it is hard to read,
> especially for bash newcomers.

You should backslash-escape the quotes ("foo \'bar\' baz"), however,
in this case, it would make sense to use regex's with 'grep' to check
that you got the expected error message rather than reproducing the
message literally here in the script.

More below.

> diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh
> @@ -0,0 +1,38 @@
> +#!/bin/sh
> +
> +test_description='git command aliasing'
> +
> +. ./test-lib.sh
> +
> +test_expect_success 'setup environment' '
> +       git init
> +'

"git init" is invoked automatically by the test framework, so no need
for this test. You can drop it.

> +test_expect_success 'nested aliases - internal execution' '
> +       git config alias.nested-internal-1 nested-internal-2 &&
> +       git config alias.nested-internal-2 status
> +'

This isn't actually testing anything, is it? It's setting up the
aliases but never actually invoking them. I would have expected the
next line to actually run a command ("git nested-internal-1") and the
line after that to check that you got the expected output (whatever
"git status" would emit). Output from "git status" isn't necessarily
the easiest to test, though, so perhaps pick a different Git command
for testing (something for which the result can be very easily checked
-- maybe "git rm" or such).

> +test_expect_success 'nested aliases - mixed execution' '
> +       git config alias.nested-external-1 "!git nested-external-2" &&
> +       git config alias.nested-external-2 status
> +'

Same observation.

> +test_expect_success 'looping aliases - internal execution' '
> +       git config alias.loop-internal-1 loop-internal-2 &&
> +       git config alias.loop-internal-2 loop-internal-3 &&
> +       git config alias.loop-internal-3 loop-internal-2 &&
> +       test_must_fail git loop-internal-1 2>output &&
> +       grep -q "fatal: alias loop detected: expansion of '"'"'loop-internal-1'"'"' does not terminate" output &&

Don't bother using -q with 'grep'. Output is hidden already by the
test framework in normal mode, and not hidden when running in verbose
mode. And, the output of 'grep' might be helpful when debugging the
test if something goes wrong.

As noted above, you can use regex to match the expected error rather
than exactly duplicating the text of the message.

Finally, use 'test_i18ngrep' instead of 'grep' in order to play nice
with localization.

> +       rm output

Tests don't normally bother cleaning up their output files like this
since such output can be helpful when debugging the test if something
goes wrong. (You'd want to use test_when_finished to cleanup anyhow,
but you don't need it in this case.)

> +'

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

* Re: [RFC PATCH v4 1/3] Add support for nested aliases
  2018-09-07 22:44 ` [RFC PATCH v4 1/3] Add support for nested aliases Tim Schumacher
  2018-09-07 22:44   ` [RFC PATCH v4 2/3] Show the call history when an alias is looping Tim Schumacher
  2018-09-07 22:44   ` [RFC PATCH v4 3/3] t0014: Introduce alias testing suite Tim Schumacher
@ 2018-09-08 13:28   ` Duy Nguyen
  2018-09-16  7:46     ` Tim Schumacher
  2018-09-16  7:50   ` [PATCH v5 " Tim Schumacher
  3 siblings, 1 reply; 37+ messages in thread
From: Duy Nguyen @ 2018-09-08 13:28 UTC (permalink / raw)
  To: timschumi
  Cc: Git Mailing List, Junio C Hamano, Jeff King,
	Ævar Arnfjörð Bjarmason

On Sat, Sep 8, 2018 at 12:44 AM Tim Schumacher <timschumi@gmx.de> wrote:
> +               /*
> +                * It could be an alias -- this works around the insanity
>                  * of overriding "git log" with "git show" by having
>                  * alias.log = show
>                  */

I think this comment block is about the next two lines you just
deleted. So delete it to instead of fixing style.

> -               if (done_alias)
> -                       break;
>                 if (!handle_alias(argcp, argv))
>                         break;
>                 done_alias = 1;
>         }
-- 
Duy

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

* Re: [RFC PATCH v4 2/3] Show the call history when an alias is looping
  2018-09-07 22:44   ` [RFC PATCH v4 2/3] Show the call history when an alias is looping Tim Schumacher
@ 2018-09-08 13:34     ` Duy Nguyen
  2018-09-08 16:29       ` Jeff King
  0 siblings, 1 reply; 37+ messages in thread
From: Duy Nguyen @ 2018-09-08 13:34 UTC (permalink / raw)
  To: timschumi
  Cc: Git Mailing List, Junio C Hamano, Jeff King,
	Ævar Arnfjörð Bjarmason

On Sat, Sep 8, 2018 at 12:44 AM Tim Schumacher <timschumi@gmx.de> wrote:
>
> Just printing the command that the user entered is not particularly
> helpful when trying to find the alias that causes the loop.
>
> Print the history of substituted commands to help the user find the
> offending alias. Mark the entrypoint of the loop with "<==" and the
> last command (which looped back to the entrypoint) with "==>".

An even simpler way to give this information is simply suggest the
user tries again with GIT_TRACE=1. All alias expansion is shown there
and we teach the user about GIT_TRACE. But your approach is probably
more user friendly.
-- 
Duy

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

* Re: [RFC PATCH v4 2/3] Show the call history when an alias is looping
  2018-09-08 13:34     ` Duy Nguyen
@ 2018-09-08 16:29       ` Jeff King
  0 siblings, 0 replies; 37+ messages in thread
From: Jeff King @ 2018-09-08 16:29 UTC (permalink / raw)
  To: Duy Nguyen
  Cc: timschumi, Git Mailing List, Junio C Hamano,
	Ævar Arnfjörð Bjarmason

On Sat, Sep 08, 2018 at 03:34:34PM +0200, Duy Nguyen wrote:

> On Sat, Sep 8, 2018 at 12:44 AM Tim Schumacher <timschumi@gmx.de> wrote:
> >
> > Just printing the command that the user entered is not particularly
> > helpful when trying to find the alias that causes the loop.
> >
> > Print the history of substituted commands to help the user find the
> > offending alias. Mark the entrypoint of the loop with "<==" and the
> > last command (which looped back to the entrypoint) with "==>".
> 
> An even simpler way to give this information is simply suggest the
> user tries again with GIT_TRACE=1. All alias expansion is shown there
> and we teach the user about GIT_TRACE. But your approach is probably
> more user friendly.

Good point. I'm OK with the amount of code here for the nicer message
(but would be happy either way).

If we were going to track cross-process loops like Ævar suggested, I
think I'd rather go with a simple counter and just ask the user to run
with GIT_TRACE when it exceeds some maximum sanity value. For two
reasons:

  1. Passing a counter through the environment is way simpler than
     an arbitrarily-sized list.

  2. When you get into multiple processes, there's potentially more
     going on than just Git commands. You might have a git command which
     runs a hook which runs a third party script which runs a git
     command, which runs a hook, and so on. That full dump is going to
     be more useful.

-Peff

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

* Re: [RFC PATCH v4 3/3] t0014: Introduce alias testing suite
  2018-09-07 23:38     ` Eric Sunshine
@ 2018-09-14 23:12       ` Tim Schumacher
  2018-09-16  7:21         ` Eric Sunshine
  0 siblings, 1 reply; 37+ messages in thread
From: Tim Schumacher @ 2018-09-14 23:12 UTC (permalink / raw)
  To: Eric Sunshine
  Cc: Git List, Junio C Hamano, Jeff King,
	Ævar Arnfjörð Bjarmason,
	Nguyễn Thái Ngọc Duy

On 08.09.18 01:38, Eric Sunshine wrote:
> On Fri, Sep 7, 2018 at 6:44 PM Tim Schumacher <timschumi@gmx.de> wrote:
>> Introduce a testing suite that is dedicated to aliases.
>> For now, check only if nested aliases work and if looping
>> aliases are detected successfully.
>>
>> The looping aliases check for mixed execution is there but
>> expected to fail because there is no check in place yet.
>>
>> Signed-off-by: Tim Schumacher <timschumi@gmx.de>
>> ---
>> Unfortunately I don't have a fix for the last one yet, so I
>> marked it as expect_failure. The problem is that the test suite
>> is waiting a full minute until it aborts the running command
>> (which I guess should not take that long, as it blocks the whole
>> test suite for that span of time).
>>
>> Should I try to decrease the timeout or should I remove that
>> test completely until I manage to get external calls fixed?
> 
> Perhaps just comment out that test for now and add a comment above it
> explaining why it's commented out.

That will probably be the easiest thing to do. I commented it out for
now, added a short information about that to the code itself and a longer
explanation to the commit message.

> 
>> As a last thing, is there any better way to use single quotes
>> than to write '"'"'? It isn't that bad, but it is hard to read,
>> especially for bash newcomers.
> 
> You should backslash-escape the quotes ("foo \'bar\' baz"), however,
> in this case, it would make sense to use regex's with 'grep' to check
> that you got the expected error message rather than reproducing the
> message literally here in the script.

Backslash-escaping didn't work, that resulted in some parsing error.
I'm using i18ngrep now to search for the part of a message, which
eliminates the need for quotes completely.

> 
> More below.
> 
>> diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh
>> @@ -0,0 +1,38 @@
>> +#!/bin/sh
>> +
>> +test_description='git command aliasing'
>> +
>> +. ./test-lib.sh
>> +
>> +test_expect_success 'setup environment' '
>> +       git init
>> +'
> 
> "git init" is invoked automatically by the test framework, so no need
> for this test. You can drop it.
> 
>> +test_expect_success 'nested aliases - internal execution' '
>> +       git config alias.nested-internal-1 nested-internal-2 &&
>> +       git config alias.nested-internal-2 status
>> +'
> 
> This isn't actually testing anything, is it? It's setting up the
> aliases but never actually invoking them. I would have expected the
> next line to actually run a command ("git nested-internal-1") and the
> line after that to check that you got the expected output (whatever
> "git status" would emit). Output from "git status" isn't necessarily
> the easiest to test, though, so perhaps pick a different Git command
> for testing (something for which the result can be very easily checked
> -- maybe "git rm" or such).

Whoops, I didn't know when that went missing. I added it into a new version
of this patch.

Also, I decided to keep `git status`, because it seemed to be the only
command which doesn't need any files to produce some checkable output.
Checking the "On branch" message should be enough to confirm that the
command works as intended.

> 
>> +test_expect_success 'nested aliases - mixed execution' '
>> +       git config alias.nested-external-1 "!git nested-external-2" &&
>> +       git config alias.nested-external-2 status
>> +'
> 
> Same observation.
> 
>> +test_expect_success 'looping aliases - internal execution' '
>> +       git config alias.loop-internal-1 loop-internal-2 &&
>> +       git config alias.loop-internal-2 loop-internal-3 &&
>> +       git config alias.loop-internal-3 loop-internal-2 &&
>> +       test_must_fail git loop-internal-1 2>output &&
>> +       grep -q "fatal: alias loop detected: expansion of '"'"'loop-internal-1'"'"' does not terminate" output &&
> 
> Don't bother using -q with 'grep'. Output is hidden already by the
> test framework in normal mode, and not hidden when running in verbose
> mode. And, the output of 'grep' might be helpful when debugging the
> test if something goes wrong.
> 
> As noted above, you can use regex to match the expected error rather
> than exactly duplicating the text of the message.
> 
> Finally, use 'test_i18ngrep' instead of 'grep' in order to play nice
> with localization.
> 
>> +       rm output
> 
> Tests don't normally bother cleaning up their output files like this
> since such output can be helpful when debugging the test if something
> goes wrong. (You'd want to use test_when_finished to cleanup anyhow,
> but you don't need it in this case.)

I incorporated both of these suggestions.

> 
>> +'
> 

This is the first multi-patch series that I submitted, so I'm unsure if I
should send the updated patch only or if I should send the complete series
again as v5. Any pointers to what the correct procedure for this case is would
be appreciated.

Thanks for looking at this.

Tim

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

* Re: [RFC PATCH v4 3/3] t0014: Introduce alias testing suite
  2018-09-14 23:12       ` Tim Schumacher
@ 2018-09-16  7:21         ` Eric Sunshine
  0 siblings, 0 replies; 37+ messages in thread
From: Eric Sunshine @ 2018-09-16  7:21 UTC (permalink / raw)
  To: timschumi
  Cc: Git List, Junio C Hamano, Jeff King,
	Ævar Arnfjörð Bjarmason,
	Nguyễn Thái Ngọc Duy

On Fri, Sep 14, 2018 at 7:12 PM Tim Schumacher <timschumi@gmx.de> wrote:
> This is the first multi-patch series that I submitted, so I'm unsure if I
> should send the updated patch only or if I should send the complete series
> again as v5. Any pointers to what the correct procedure for this case is would
> be appreciated.

Re-send the entire series as v5. That makes it easier on reviewers
(who don't need to go searching through the mailing list archive to
get a full picture) and reduces Junio's workload since it's usually
easier for him to re-queue a series wholesale than having to
slice-and-dice some replacement patches into what was already queued.

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

* Re: [RFC PATCH v4 1/3] Add support for nested aliases
  2018-09-08 13:28   ` [RFC PATCH v4 1/3] Add support for nested aliases Duy Nguyen
@ 2018-09-16  7:46     ` Tim Schumacher
  2018-09-17 15:37       ` Junio C Hamano
  0 siblings, 1 reply; 37+ messages in thread
From: Tim Schumacher @ 2018-09-16  7:46 UTC (permalink / raw)
  To: Duy Nguyen
  Cc: Git Mailing List, Junio C Hamano, Jeff King,
	Ævar Arnfjörð Bjarmason

On 08.09.18 15:28, Duy Nguyen wrote:
> On Sat, Sep 8, 2018 at 12:44 AM Tim Schumacher <timschumi@gmx.de> wrote:
>> +               /*
>> +                * It could be an alias -- this works around the insanity
>>                   * of overriding "git log" with "git show" by having
>>                   * alias.log = show
>>                   */
> 
> I think this comment block is about the next two lines you just
> deleted. So delete it to instead of fixing style.

I think that comment is talking about the code that is handing the alias,
so it still would be valid.
The check might have peen placed in between to keep it logically grouped.

> 
>> -               if (done_alias)
>> -                       break;
>>                  if (!handle_alias(argcp, argv))
>>                          break;
>>                  done_alias = 1;
>>          }

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

* [PATCH v5 1/3] Add support for nested aliases
  2018-09-07 22:44 ` [RFC PATCH v4 1/3] Add support for nested aliases Tim Schumacher
                     ` (2 preceding siblings ...)
  2018-09-08 13:28   ` [RFC PATCH v4 1/3] Add support for nested aliases Duy Nguyen
@ 2018-09-16  7:50   ` " Tim Schumacher
  2018-09-16  7:50     ` [PATCH v5 2/3] Show the call history when an alias is looping Tim Schumacher
  2018-09-16  7:50     ` [PATCH v5 3/3] t0014: Introduce an alias testing suite Tim Schumacher
  3 siblings, 2 replies; 37+ messages in thread
From: Tim Schumacher @ 2018-09-16  7:50 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, avarab, pclouds

Aliases can only contain non-alias git commands and their
arguments, not other user-defined aliases. Resolving further
(nested) aliases is prevented by breaking the loop after the
first alias was processed. Git then fails with a command-not-found
error.

Allow resolving nested aliases by not breaking the loop in
run_argv() after the first alias was processed. Instead, continue
the loop until `handle_alias()` fails, which means that there are
no further aliases that can be processed. Prevent looping aliases
by storing substituted commands in `cmd_list` and checking if
a command has been substituted previously.

While we're at it, fix a styling issue just below the added code.

Signed-off-by: Tim Schumacher <timschumi@gmx.de>
---
Changes since v3:
 - Print the command that the user entered instead of the command
   which caused the loop (and a nicer, more explanatory error message)
 - Use unsorted_string_list_has_string() instead of the sorted version
 - Fix a code style issue just below the modified code
 - done_alias is a simple boolean again (instead of a counter)

Changes since v4: None.

 git.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/git.c b/git.c
index c27c38738..15727c17f 100644
--- a/git.c
+++ b/git.c
@@ -674,6 +674,7 @@ static void execv_dashed_external(const char **argv)
 static int run_argv(int *argcp, const char ***argv)
 {
 	int done_alias = 0;
+	struct string_list cmd_list = STRING_LIST_INIT_NODUP;
 
 	while (1) {
 		/*
@@ -691,17 +692,25 @@ static int run_argv(int *argcp, const char ***argv)
 		/* .. then try the external ones */
 		execv_dashed_external(*argv);
 
-		/* It could be an alias -- this works around the insanity
+		if (unsorted_string_list_has_string(&cmd_list, *argv[0])) {
+			die(_("alias loop detected: expansion of '%s' does"
+			      " not terminate"), cmd_list.items[0].string);
+		}
+
+		string_list_append(&cmd_list, *argv[0]);
+
+		/*
+		 * It could be an alias -- this works around the insanity
 		 * of overriding "git log" with "git show" by having
 		 * alias.log = show
 		 */
-		if (done_alias)
-			break;
 		if (!handle_alias(argcp, argv))
 			break;
 		done_alias = 1;
 	}
 
+	string_list_clear(&cmd_list, 0);
+
 	return done_alias;
 }
 
-- 
2.19.0.rc2.1.g4c98b8d69.dirty


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

* [PATCH v5 2/3] Show the call history when an alias is looping
  2018-09-16  7:50   ` [PATCH v5 " Tim Schumacher
@ 2018-09-16  7:50     ` Tim Schumacher
  2018-09-16  7:50     ` [PATCH v5 3/3] t0014: Introduce an alias testing suite Tim Schumacher
  1 sibling, 0 replies; 37+ messages in thread
From: Tim Schumacher @ 2018-09-16  7:50 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, avarab, pclouds

Just printing the command that the user entered is not particularly
helpful when trying to find the alias that causes the loop.

Print the history of substituted commands to help the user find the
offending alias. Mark the entrypoint of the loop with "<==" and the
last command (which looped back to the entrypoint) with "==>".

Signed-off-by: Tim Schumacher <timschumi@gmx.de>
---
No changes since v4.

 git.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/git.c b/git.c
index 15727c17f..a20eb4fa1 100644
--- a/git.c
+++ b/git.c
@@ -675,6 +675,7 @@ static int run_argv(int *argcp, const char ***argv)
 {
 	int done_alias = 0;
 	struct string_list cmd_list = STRING_LIST_INIT_NODUP;
+	struct string_list_item *seen;
 
 	while (1) {
 		/*
@@ -692,9 +693,21 @@ static int run_argv(int *argcp, const char ***argv)
 		/* .. then try the external ones */
 		execv_dashed_external(*argv);
 
-		if (unsorted_string_list_has_string(&cmd_list, *argv[0])) {
+		seen = unsorted_string_list_lookup(&cmd_list, *argv[0]);
+		if (seen) {
+			int i;
+			struct strbuf sb = STRBUF_INIT;
+			for (i = 0; i < cmd_list.nr; i++) {
+				struct string_list_item *item = &cmd_list.items[i];
+
+				strbuf_addf(&sb, "\n  %s", item->string);
+				if (item == seen)
+					strbuf_addstr(&sb, " <==");
+				else if (i == cmd_list.nr - 1)
+					strbuf_addstr(&sb, " ==>");
+			}
 			die(_("alias loop detected: expansion of '%s' does"
-			      " not terminate"), cmd_list.items[0].string);
+			      " not terminate:%s"), cmd_list.items[0].string, sb.buf);
 		}
 
 		string_list_append(&cmd_list, *argv[0]);
-- 
2.19.0.rc2.1.g4c98b8d69.dirty


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

* [PATCH v5 3/3] t0014: Introduce an alias testing suite
  2018-09-16  7:50   ` [PATCH v5 " Tim Schumacher
  2018-09-16  7:50     ` [PATCH v5 2/3] Show the call history when an alias is looping Tim Schumacher
@ 2018-09-16  7:50     ` Tim Schumacher
  1 sibling, 0 replies; 37+ messages in thread
From: Tim Schumacher @ 2018-09-16  7:50 UTC (permalink / raw)
  To: git; +Cc: gitster, peff, avarab, pclouds

Introduce a testing suite that is dedicated to aliases.
For now, check only if nested aliases work and if looping
aliases are detected successfully.

The looping aliases check for mixed execution is there but
disabled, because it is blocking the test suite for a full
minute. As soon as there is a solution for loops using
external commands, it should be enabled.

Signed-off-by: Tim Schumacher <timschumi@gmx.de>
---
Changes since v4:
 - Actually execute a command in the first two cases
 - Remove the "setup code"
 - Use i18ngrep to match the part of a message
 - Comment out the last test

 t/t0014-alias.sh | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100755 t/t0014-alias.sh

diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh
new file mode 100755
index 000000000..a070e645d
--- /dev/null
+++ b/t/t0014-alias.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+test_description='git command aliasing'
+
+. ./test-lib.sh
+
+test_expect_success 'nested aliases - internal execution' '
+	git config alias.nested-internal-1 nested-internal-2 &&
+	git config alias.nested-internal-2 status &&
+	git nested-internal-1 >output &&
+	test_i18ngrep "^On branch " output
+'
+
+test_expect_success 'nested aliases - mixed execution' '
+	git config alias.nested-external-1 nested-external-2 &&
+	git config alias.nested-external-2 "!git nested-external-3" &&
+	git config alias.nested-external-3 status &&
+	git nested-external-1 >output &&
+	test_i18ngrep "^On branch " output
+'
+
+test_expect_success 'looping aliases - internal execution' '
+	git config alias.loop-internal-1 loop-internal-2 &&
+	git config alias.loop-internal-2 loop-internal-3 &&
+	git config alias.loop-internal-3 loop-internal-2 &&
+	test_must_fail git loop-internal-1 2>output &&
+	test_i18ngrep "^fatal: alias loop detected: expansion of" output
+'
+
+# This test is disabled until external loops are fixed, because would block
+# the test suite for a full minute.
+#
+#test_expect_failure 'looping aliases - mixed execution' '
+#	git config alias.loop-mixed-1 loop-mixed-2 &&
+#	git config alias.loop-mixed-2 "!git loop-mixed-1" &&
+#	test_must_fail git loop-mixed-1 2>output &&
+#	test_i18ngrep "^fatal: alias loop detected: expansion of" output
+#'
+
+test_done
-- 
2.19.0.rc2.1.g4c98b8d69.dirty


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

* Re: [RFC PATCH v4 1/3] Add support for nested aliases
  2018-09-16  7:46     ` Tim Schumacher
@ 2018-09-17 15:37       ` Junio C Hamano
  2018-09-21 12:45         ` Tim Schumacher
  0 siblings, 1 reply; 37+ messages in thread
From: Junio C Hamano @ 2018-09-17 15:37 UTC (permalink / raw)
  To: Tim Schumacher
  Cc: Duy Nguyen, Git Mailing List, Jeff King,
	Ævar Arnfjörð Bjarmason

Tim Schumacher <timschumi@gmx.de> writes:

> On 08.09.18 15:28, Duy Nguyen wrote:
>> On Sat, Sep 8, 2018 at 12:44 AM Tim Schumacher <timschumi@gmx.de> wrote:
>>> +               /*
>>> +                * It could be an alias -- this works around the insanity
>>>                   * of overriding "git log" with "git show" by having
>>>                   * alias.log = show
>>>                   */
>>
>> I think this comment block is about the next two lines you just
>> deleted. So delete it to instead of fixing style.
>
> I think that comment is talking about the code that is handing the alias,
> so it still would be valid.

"this" in "this works around" refers to the fact that we first check
the builtins and on-GIT_EXEC_PATH commands before trying an alias,
which is an effective way to forbid an alias from taking over
existing command names.  So it is not about a particular code but is
about how the two sections of code are laid out.

It probably will make it clear if we reworded and made it a comment
about the whole while() loop may make sense, i.e.

	/*
	 * Check if av[0] is a command before seeing if it is an
	 * alias to avoid the insanity of overriding ...
	 */
	while (1) {
		...

but that can be done after the dust settles as a clean-up, I would
think.

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

* Re: [RFC PATCH v4 1/3] Add support for nested aliases
  2018-09-17 15:37       ` Junio C Hamano
@ 2018-09-21 12:45         ` Tim Schumacher
  2018-09-21 15:59           ` Junio C Hamano
  0 siblings, 1 reply; 37+ messages in thread
From: Tim Schumacher @ 2018-09-21 12:45 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Duy Nguyen, Git Mailing List, Jeff King,
	Ævar Arnfjörð Bjarmason

On 17.09.18 17:37, Junio C Hamano wrote:
> Tim Schumacher <timschumi@gmx.de> writes:
> 
>> On 08.09.18 15:28, Duy Nguyen wrote:
>>> On Sat, Sep 8, 2018 at 12:44 AM Tim Schumacher <timschumi@gmx.de> wrote:
>>>> +               /*
>>>> +                * It could be an alias -- this works around the insanity
>>>>                    * of overriding "git log" with "git show" by having
>>>>                    * alias.log = show
>>>>                    */
>>>
>>> I think this comment block is about the next two lines you just
>>> deleted. So delete it to instead of fixing style.
>>
>> I think that comment is talking about the code that is handing the alias,
>> so it still would be valid.
> 
> "this" in "this works around" refers to the fact that we first check
> the builtins and on-GIT_EXEC_PATH commands before trying an alias,
> which is an effective way to forbid an alias from taking over
> existing command names.  So it is not about a particular code but is
> about how the two sections of code are laid out.
> 
> It probably will make it clear if we reworded and made it a comment
> about the whole while() loop may make sense, i.e.
> 
> 	/*
> 	 * Check if av[0] is a command before seeing if it is an
> 	 * alias to avoid the insanity of overriding ...
> 	 */
> 	while (1) {
> 		...
> 

Imho, the "insanity" part makes the intention of that comment unclear, even if
it is located at the top of the while() loop. Giving an example is nice, but wouldn't
it be better to say something like the following?

	/*
	 * Check if av[0] is a command before seeing if it is an
	 * alias to avoid taking over existing commands
	 */

> but that can be done after the dust settles as a clean-up, I would
> think.
> 

I'll keep the changed comment in my local repository for now and publish it together
with other changes in v6, but I assume there won't be much additional feedback.

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

* Re: [RFC PATCH v4 1/3] Add support for nested aliases
  2018-09-21 12:45         ` Tim Schumacher
@ 2018-09-21 15:59           ` Junio C Hamano
  0 siblings, 0 replies; 37+ messages in thread
From: Junio C Hamano @ 2018-09-21 15:59 UTC (permalink / raw)
  To: Tim Schumacher
  Cc: Duy Nguyen, Git Mailing List, Jeff King,
	Ævar Arnfjörð Bjarmason

Tim Schumacher <timschumi@gmx.de> writes:

> it is located at the top of the while() loop. Giving an example is nice, but wouldn't
> it be better to say something like the following?
>
> 	/*
> 	 * Check if av[0] is a command before seeing if it is an
> 	 * alias to avoid taking over existing commands
> 	 */

If we have more concrete and constructive things to explain why we
choose to forbid it, that may be worth saying, but I agree that it
does not add much value to this comment to declare that an attempt
to take over existing commands is "insane".

Thanks.

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

end of thread, back to index

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-05  8:54 [RFC PATCH v2] Allow aliases that include other aliases Tim Schumacher
2018-09-05 15:48 ` Duy Nguyen
2018-09-05 19:02   ` Tim Schumacher
2018-09-05 17:12 ` Junio C Hamano
2018-09-05 19:12   ` Tim Schumacher
2018-09-05 17:34 ` Jeff King
2018-09-05 20:02   ` Tim Schumacher
2018-09-06 13:38     ` Ævar Arnfjörð Bjarmason
2018-09-06 14:17     ` Ævar Arnfjörð Bjarmason
2018-09-05 21:51   ` Junio C Hamano
2018-09-06 10:16 ` [PATCH v3] " Tim Schumacher
2018-09-06 14:01   ` Ævar Arnfjörð Bjarmason
2018-09-06 14:57     ` Jeff King
2018-09-06 15:10       ` Ævar Arnfjörð Bjarmason
2018-09-06 16:18         ` Jeff King
2018-09-06 19:05       ` Tim Schumacher
2018-09-06 19:17         ` Jeff King
2018-09-06 14:59   ` Jeff King
2018-09-06 18:40     ` Junio C Hamano
2018-09-06 19:05       ` Jeff King
2018-09-06 19:31       ` Tim Schumacher
2018-09-07 22:44 ` [RFC PATCH v4 1/3] Add support for nested aliases Tim Schumacher
2018-09-07 22:44   ` [RFC PATCH v4 2/3] Show the call history when an alias is looping Tim Schumacher
2018-09-08 13:34     ` Duy Nguyen
2018-09-08 16:29       ` Jeff King
2018-09-07 22:44   ` [RFC PATCH v4 3/3] t0014: Introduce alias testing suite Tim Schumacher
2018-09-07 23:38     ` Eric Sunshine
2018-09-14 23:12       ` Tim Schumacher
2018-09-16  7:21         ` Eric Sunshine
2018-09-08 13:28   ` [RFC PATCH v4 1/3] Add support for nested aliases Duy Nguyen
2018-09-16  7:46     ` Tim Schumacher
2018-09-17 15:37       ` Junio C Hamano
2018-09-21 12:45         ` Tim Schumacher
2018-09-21 15:59           ` Junio C Hamano
2018-09-16  7:50   ` [PATCH v5 " Tim Schumacher
2018-09-16  7:50     ` [PATCH v5 2/3] Show the call history when an alias is looping Tim Schumacher
2018-09-16  7:50     ` [PATCH v5 3/3] t0014: Introduce an alias testing suite Tim Schumacher

git@vger.kernel.org mailing list mirror (one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox