git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3] Allow aliases that include other aliases

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 6, 2018, 18:40 UTC
Message-ID
<xmqqy3cezcz5.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20180906145942.GB1209@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 18 quoted lines
> 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.

Show 17 quoted lines
> 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?").

Previous: Jeff KingNext: Jeff King
Message 34 of 52 in “Allow aliases that include other aliases”
  1. Allow aliases that include other aliasesTim Schumacher, Sep 5, 2018
  2. Duy NguyenSep 5, 2018
  3. Tim SchumacherSep 5, 2018
  4. Junio C HamanoSep 5, 2018
  5. Tim SchumacherSep 5, 2018
  6. Jeff KingSep 5, 2018
  7. Tim SchumacherSep 5, 2018
  8. Ævar Arnfjörð BjarmasonSep 6, 2018
  9. Ævar Arnfjörð BjarmasonSep 6, 2018
  10. alias: detect loops in mixed execution modeÆvar Arnfjörð Bjarmason, Oct 18, 2018
  11. Ævar Arnfjörð BjarmasonOct 19, 2018
  12. Jeff KingOct 19, 2018
  13. Ævar Arnfjörð BjarmasonOct 20, 2018
  14. Jeff KingOct 19, 2018
  15. Ævar Arnfjörð BjarmasonOct 20, 2018
  16. Jeff KingOct 20, 2018
  17. Ævar Arnfjörð BjarmasonOct 20, 2018
  18. Jeff KingOct 22, 2018
  19. Ævar Arnfjörð BjarmasonOct 22, 2018
  20. Junio C HamanoOct 22, 2018
  21. Jeff KingOct 26, 2018
  22. Ævar Arnfjörð BjarmasonOct 26, 2018
  23. Junio C HamanoOct 29, 2018
  24. Jeff KingOct 29, 2018
  25. Junio C HamanoSep 5, 2018
  26. Allow aliases that include other aliasesTim Schumacher, Sep 6, 2018
  27. Ævar Arnfjörð BjarmasonSep 6, 2018
  28. Jeff KingSep 6, 2018
  29. Ævar Arnfjörð BjarmasonSep 6, 2018
  30. Jeff KingSep 6, 2018
  31. Tim SchumacherSep 6, 2018
  32. Jeff KingSep 6, 2018
  33. Jeff KingSep 6, 2018
  34. Junio C HamanoSep 6, 2018
  35. Jeff KingSep 6, 2018
  36. Tim SchumacherSep 6, 2018
  37. 1/3 Add support for nested aliasesTim Schumacher, Sep 7, 2018
  38. 2/3 Show the call history when an alias is loopingTim Schumacher, Sep 7, 2018
  39. Duy NguyenSep 8, 2018
  40. Jeff KingSep 8, 2018
  41. 3/3 t0014: Introduce alias testing suiteTim Schumacher, Sep 7, 2018
  42. Eric SunshineSep 7, 2018
  43. Tim SchumacherSep 14, 2018
  44. Eric SunshineSep 16, 2018
  45. Duy NguyenSep 8, 2018
  46. Tim SchumacherSep 16, 2018
  47. Junio C HamanoSep 17, 2018
  48. Tim SchumacherSep 21, 2018
  49. Junio C HamanoSep 21, 2018
  50. 1/3 Add support for nested aliasesTim Schumacher, Sep 16, 2018
  51. 2/3 Show the call history when an alias is loopingTim Schumacher, Sep 16, 2018
  52. 3/3 t0014: Introduce an alias testing suiteTim Schumacher, Sep 16, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.