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

Re: [RFC PATCH v2] Allow aliases that include other aliases

From
Tim Schumacher <timschumi@gmx.de>
Date
Sep 5, 2018, 19:02 UTC
Message-ID
<5c618de8-6676-8fa4-fe19-4db44befd73c@gmx.de>
In-Reply-To
<CACsJy8BLEtBWyAuRBphv_PVisKao0YaBewKJXECEuCVzvk9qXg@mail.gmail.com>
On 05.09.18 17:48, Duy Nguyen wrote:
Show 22 quoted lines
> 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?

Show 9 quoted lines
> 
> 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.

Show 8 quoted lines
> 
>> +               /* 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.
Show 14 quoted lines
> 
>> +               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.
Show 5 quoted lines
> 
>> +                                   cmd_list[done_alias]);
>> +                       }
>> +               }
>> +
Thanks for reviewing!
Tim
Previous: Duy NguyenNext: Junio C Hamano
Message 3 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.