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

Re: [PATCH 4/8] tag: Implicitly supply --list given another list-like option

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Mar 20, 2017, 09:16 UTC
Message-ID
<CACBZZX41W40PzSdxsPU+=NP==LuYdAUcD2n4Q381opn63DfcqA@mail.gmail.com>
In-Reply-To
<20170320035549.smzgu2jkaxrhuxl4@sigill.intra.peff.net>
On Mon, Mar 20, 2017 at 4:55 AM, Jeff King <peff@peff.net> wrote:
Show 72 quoted lines
> On Sat, Mar 18, 2017 at 10:32:52AM +0000, Ævar Arnfjörð Bjarmason wrote:
>
>> With this change errors messages such as "--contains option is only
>> allowed with -l" don't make sense anymore, since options like
>> --contain turn on -l. Instead we error out when list-like options such
>> as --contain are used in conjunction with conflicting options such as
>> -d or -v.
>
> Yeah, I think this is the right approach.
>
>> This change does not consider "-n" a list-like option, even though
>> that might be logical. Permitting it would allow:
>>
>>     git tag -n 100
>>
>> As a synonym for:
>>
>>     git tag -n --list 100
>>
>> Which, while not technically ambiguous as the option must already be
>> provided as -n<num> rather than -n <num>, would be confusing.
>
> I'm not sure the existing behavior isn't confusing anyway (most optional
> arguments are). But I don't mind being conservative and leaving out "-n"
> for now; we can always convert it later if somebody feels strongly about
> it.
>
>> diff --git a/builtin/tag.c b/builtin/tag.c
>> index 0bba3fd070..3483636e59 100644
>> --- a/builtin/tag.c
>> +++ b/builtin/tag.c
>> @@ -454,8 +454,12 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
>>       }
>>       create_tag_object = (opt.sign || annotate || msg.given || msgfile);
>>
>> -     if (argc == 0 && !cmdmode && !create_tag_object)
>> -             cmdmode = 'l';
>> +     if (!cmdmode && !create_tag_object) {
>> +             if (argc == 0)
>> +                     cmdmode = 'l';
>> +             else if (filter.with_commit || filter.points_at.nr || filter.merge_commit)
>> +                     cmdmode = 'l';
>> +     }
>
> Makes sense.
>
>> @@ -483,15 +487,16 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
>>               if (column_active(colopts))
>>                       stop_column_filter();
>>               return ret;
>> +     } else {
>> +             if (filter.lines != -1)
>> +                     die(_("-n option is only allowed in list mode."));
>> +             if (filter.with_commit)
>> +                     die(_("--contains option is only allowed in list mode."));
>> +             if (filter.points_at.nr)
>> +                     die(_("--points-at option is only allowed in list mode."));
>> +             if (filter.merge_commit)
>> +                     die(_("--merged and --no-merged options are only allowed in list mode."));
>>       }
>> -     if (filter.lines != -1)
>> -             die(_("-n option is only allowed with -l."));
>> -     if (filter.with_commit)
>> -             die(_("--contains option is only allowed with -l."));
>> -     if (filter.points_at.nr)
>> -             die(_("--points-at option is only allowed with -l."));
>> -     if (filter.merge_commit)
>> -             die(_("--merged and --no-merged option are only allowed with -l"));
>
> I'm not sure why these go into the "else" clause here. The other side of
> the conditional (i.e., when we are in list mode) always returns. I don't
> _mind_ it, it's just surprising in this patch.

Changed it. It was a wart left over from an earlier version of this that didn't make it on-list where the else mattered.

> While we are re-wording the messages, we may want to drop the periods at
> the end of the first three (or keep it on the fourth one, but I our
> usual style is to omit it).
Done.
Show 6 quoted lines
>> --- a/t/t7004-tag.sh
>> +++ b/t/t7004-tag.sh
>
> The tests looked reasonable to me.
>
> -Peff
Previous: Jeff KingNext: Ævar Arnfjörð Bjarmason
Message 34 of 41 in “Various changes to the "tag" command”
  1. 0/8 Various changes to the "tag" commandÆvar Arnfjörð Bjarmason, Mar 18, 2017
  2. 1/8 tag: Remove a TODO item from the test suiteÆvar Arnfjörð Bjarmason, Mar 18, 2017
  3. Junio C HamanoMar 18, 2017
  4. 0/2 doc/SubmittingPatches: A couple of minor improvementsÆvar Arnfjörð Bjarmason, Mar 18, 2017
  5. 1/2 doc/SubmittingPatches: clarify the casing convention for "area: change..."Ævar Arnfjörð Bjarmason, Mar 18, 2017
  6. Junio C HamanoMar 18, 2017
  7. Ævar Arnfjörð BjarmasonMar 18, 2017
  8. Junio C HamanoMar 18, 2017
  9. 2/2 doc/SubmittingPatches: show how to get a CLI commit summaryÆvar Arnfjörð Bjarmason, Mar 18, 2017
  10. Junio C HamanoMar 18, 2017
  11. Jakub NarębskiMar 19, 2017
  12. Ævar Arnfjörð BjarmasonMar 19, 2017
  13. 5/8 tag: Implicitly supply --list given the -n optionÆvar Arnfjörð Bjarmason, Mar 18, 2017
  14. Jeff KingMar 20, 2017
  15. 2/8 tag: Refactor the options handling code to be less bizarroÆvar Arnfjörð Bjarmason, Mar 18, 2017
  16. Junio C HamanoMar 18, 2017
  17. Ævar Arnfjörð BjarmasonMar 18, 2017
  18. Junio C HamanoMar 18, 2017
  19. Ævar Arnfjörð BjarmasonMar 18, 2017
  20. 7/8 tag: Add tests for --with and --withoutÆvar Arnfjörð Bjarmason, Mar 18, 2017
  21. 8/8 tag: Change --point-at to default to HEADÆvar Arnfjörð Bjarmason, Mar 18, 2017
  22. Junio C HamanoMar 18, 2017
  23. Ævar Arnfjörð BjarmasonMar 18, 2017
  24. 3/8 tag: Change misleading --list <pattern> documentationÆvar Arnfjörð Bjarmason, Mar 18, 2017
  25. Junio C HamanoMar 18, 2017
  26. Ævar Arnfjörð BjarmasonMar 18, 2017
  27. Jeff KingMar 20, 2017
  28. Junio C HamanoMar 20, 2017
  29. Junio C HamanoMar 20, 2017
  30. Ævar Arnfjörð BjarmasonMar 20, 2017
  31. Jeff KingMar 20, 2017
  32. 4/8 tag: Implicitly supply --list given another list-like optionÆvar Arnfjörð Bjarmason, Mar 18, 2017
  33. Jeff KingMar 20, 2017
  34. Ævar Arnfjörð BjarmasonMar 20, 2017
  35. 6/8 ref-filter: Add --no-contains option to tag/branch/for-each-refÆvar Arnfjörð Bjarmason, Mar 18, 2017
  36. Jeff KingMar 20, 2017
  37. Ævar Arnfjörð BjarmasonMar 20, 2017
  38. Jeff KingMar 20, 2017
  39. Ævar Arnfjörð BjarmasonMar 20, 2017
  40. Jeff KingMar 20, 2017
  41. Junio C HamanoMar 20, 2017

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.