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

Re: [PATCH] builtin-tag: fix fallouts from recent parsopt restriction.

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 17, 2007, 19:52 UTC
Message-ID
<7vy7bt6qv6.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20071217123307.GK7453@artemis.madism.org>
Pierre Habouzit <madcoder@debian.org> writes:
Show 17 quoted lines
> After having written this mail 4 time already, I came up with an idea I
> kind of like: like find, we could make {} be a placeholder for the
> "default" argument. For example:
>
>   $ git foo --abbrev {} 10
>   $ git log -M {} 1
>   ...
>
> {} would have the same semantics as your --long-opt-default. It tells the
> option parser that "no there isn't anything to grok for that command thank you
> very much". Of course if for some reason you really want to pass "{}" to the
> command, the stuck form holds:
>
>   $ git foo --long-opt={}
>   $ git foo -o{}
>
> What do you think ?
1. {} means a completely different thing to find ("place the real value
   here"); there is no similarity.  I would strongly oppose to it.  If
   you want to invoke opt with default but still want to pass "{}" as an
   argument unrelated to that opt, you would do "--opt={} {}".  That's
   double ugly.
2. For a long option with optional option-argument, --abbrev-default (or
   in the other order, --default-abbrev) to mark "there is no option
   argument, do not do your context sensitive parsing" and using an
   explicit '=' (e.g. --abbrev=<value>) to mark "this is the argument,
   do not do your context sensitive parsing" is much more readable.
3. There are only handful options with optional option-argument that
   does not have long format.  I think it is reasonable to require
   "stuck argument" to them.  For most of the short options that take
   optional option-argument, traditionally we did not allow them to be
   spelled as separate words, so there is no regression to introduce
   such a behaviour.  -B/-M/-C options to diff family would be handled
   sanely this way.
   Another possibility, which I do not like very much, is to add long
   format to them, if only for paranoid scripters who want rename
   detection with the default threshold and cannot say "diff -M $foo".
   They can say "diff --detect-rename-default $foo" instead ("-M" is a
   bad example here, as giving a single path never makes sense for -M so
   $foo cannot be a file whose name is e.g. "20", and default number of
   abbreviated commit object name is longer than 2 which means it would
   make it longer than "percentage" form of threshold).
So in short, for an option that takes optional option-argument:
   - if it is given as "--<long-name>-default", there is no optional
     argument, period.
   - if it is given as "--long-name" but there is no next word, there is
     no optional argument, either.
   - if it is given as "--long-name=value", that "value" is the
     argument.  Barf if it does not validate.
   - if it is given as "--long-name", and there is a next word, see if
     that is plausible as its argument.  Get it and signal the caller
     you consumed it, if it is.  Ignore it and signal the caller you
     didn't, if it isn't.
   - if it is given as "-svalue", that "value" is the argument.  Barf if
     it does not validate.
   - if it is given as "-s", and there is a next word, and if the option
     has long format counterpart as well, then see if the next word is
     plausible as its argument.  Get it and signal the caller you
     consumed it, if it is.  Ignore it and signal the caller you didn't,
     if it isn't.
   - if it is given as "-s" but the previous rule did not trigger, there
     is no optional argument.
Previous: Pierre HabouzitNext: Jeff King
Message 18 of 51 in “[RFH] convert shortlog to use parse_options”
  1. Jeff KingDec 13, 2007
  2. Pierre HabouzitDec 13, 2007
  3. Jeff KingDec 13, 2007
  4. Pierre HabouzitDec 13, 2007
  5. 1/2 parseopt: Enforce the use of the sticked form for optional arguments.Pierre Habouzit, Dec 13, 2007
  6. 2/2 parseopt: Add a gitcli(5) man page.Pierre Habouzit, Dec 13, 2007
  7. Wincent ColaiutaDec 13, 2007
  8. Pierre HabouzitDec 13, 2007
  9. (squashme) gitcli documentation fixupsJunio C Hamano, Dec 17, 2007
  10. Pierre HabouzitDec 17, 2007
  11. Pierre HabouzitDec 17, 2007
  12. builtin-tag: fix fallouts from recent parsopt restriction.Junio C Hamano, Dec 17, 2007
  13. Pierre HabouzitDec 17, 2007
  14. Junio C HamanoDec 17, 2007
  15. Pierre HabouzitDec 17, 2007
  16. Junio C HamanoDec 17, 2007
  17. Pierre HabouzitDec 17, 2007
  18. Junio C HamanoDec 17, 2007
  19. Jeff KingDec 17, 2007
  20. Pierre HabouzitDec 17, 2007
  21. Pierre HabouzitDec 17, 2007
  22. Jeff KingDec 17, 2007
  23. Pierre HabouzitDec 17, 2007
  24. Junio C HamanoDec 17, 2007
  25. Jeff KingDec 17, 2007
  26. Pierre HabouzitDec 17, 2007
  27. Pierre HabouzitDec 17, 2007
  28. Junio C HamanoDec 17, 2007
  29. Pierre HabouzitDec 17, 2007
  30. Pierre HabouzitDec 17, 2007
  31. Junio C HamanoDec 13, 2007
  32. Pierre HabouzitDec 13, 2007
  33. Pierre HabouzitDec 13, 2007
  34. Junio C HamanoDec 13, 2007
  35. Kristian HøgsbergDec 13, 2007
  36. Kristian HøgsbergDec 13, 2007
  37. Junio C HamanoDec 13, 2007
  38. Jeff KingDec 14, 2007
  39. Junio C HamanoDec 14, 2007
  40. Andreas EricssonDec 14, 2007
  41. Pierre HabouzitDec 14, 2007
  42. Junio C HamanoDec 14, 2007
  43. Pierre HabouzitDec 15, 2007
  44. Junio C HamanoDec 17, 2007
  45. Andreas EricssonDec 17, 2007
  46. Junio C HamanoDec 17, 2007
  47. Andreas EricssonDec 17, 2007
  48. Kristian HøgsbergDec 17, 2007
  49. Junio C HamanoDec 13, 2007
  50. Pierre HabouzitDec 13, 2007
  51. Pierre HabouzitDec 13, 2007

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.