<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/parse-options.c, branch v2.34.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.34.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.34.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2021-11-09T21:19:06Z</updated>
<entry>
<title>Merge branch 'ab/parse-options-cleanup'</title>
<updated>2021-11-09T21:19:06Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2021-11-09T21:19:06Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=84c99b20231e77fe1df7ea487e3dc24359cba028'/>
<id>urn:sha1:84c99b20231e77fe1df7ea487e3dc24359cba028</id>
<content type='text'>
Last minute fix to the update already in 'master'.

* ab/parse-options-cleanup:
  parse-options.[ch]: revert use of "enum" for parse_options()
</content>
</entry>
<entry>
<title>parse-options.[ch]: revert use of "enum" for parse_options()</title>
<updated>2021-11-09T17:45:37Z</updated>
<author>
<name>Ævar Arnfjörð Bjarmason</name>
<email>avarab@gmail.com</email>
</author>
<published>2021-11-09T11:04:43Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=06a199f38b50ccea198c29216c69bb389ca23391'/>
<id>urn:sha1:06a199f38b50ccea198c29216c69bb389ca23391</id>
<content type='text'>
Revert the parse_options() prototype change in my recent
352e761388b (parse-options.[ch]: consistently use "enum
parse_opt_result", 2021-10-08) was incorrect. The parse_options()
function returns the number of argc elements that haven't been
processed, not "enum parse_opt_result".

Reported-by: SZEDER Gábor &lt;szeder.dev@gmail.com&gt;
Signed-off-by: Ævar Arnfjörð Bjarmason &lt;avarab@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'ab/parse-options-cleanup'</title>
<updated>2021-10-25T23:06:59Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2021-10-25T23:06:59Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=65ca3245f99e3595ac483e4af5b2ff34b7985635'/>
<id>urn:sha1:65ca3245f99e3595ac483e4af5b2ff34b7985635</id>
<content type='text'>
Random changes to parse-options implementation.

* ab/parse-options-cleanup:
  parse-options: change OPT_{SHORT,UNSET} to an enum
  parse-options tests: test optname() output
  parse-options.[ch]: make opt{bug,name}() "static"
  commit-graph: stop using optname()
  parse-options.c: move optname() earlier in the file
  parse-options.h: make the "flags" in "struct option" an enum
  parse-options.c: use exhaustive "case" arms for "enum parse_opt_result"
  parse-options.[ch]: consistently use "enum parse_opt_result"
  parse-options.[ch]: consistently use "enum parse_opt_flags"
  parse-options.h: move PARSE_OPT_SHELL_EVAL between enums
</content>
</entry>
<entry>
<title>Merge branch 'ab/align-parse-options-help'</title>
<updated>2021-10-13T22:15:58Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2021-10-13T22:15:58Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=d7bc8521518d4821c5d2e18742991a6ad05efee1'/>
<id>urn:sha1:d7bc8521518d4821c5d2e18742991a6ad05efee1</id>
<content type='text'>
When "git cmd -h" shows more than one line of usage text (e.g.
the cmd subcommand may take sub-sub-command), parse-options API
learned to align these lines, even across i18n/l10n.

* ab/align-parse-options-help:
  parse-options: properly align continued usage output
  git rev-parse --parseopt tests: add more usagestr tests
  send-pack: properly use parse_options() API for usage string
  parse-options API users: align usage output in C-strings
</content>
</entry>
<entry>
<title>parse-options: change OPT_{SHORT,UNSET} to an enum</title>
<updated>2021-10-08T21:13:11Z</updated>
<author>
<name>Ævar Arnfjörð Bjarmason</name>
<email>avarab@gmail.com</email>
</author>
<published>2021-10-08T19:07:46Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=d342834529495508fa1f23e223d4917cbdcfb54d'/>
<id>urn:sha1:d342834529495508fa1f23e223d4917cbdcfb54d</id>
<content type='text'>
Change the comparisons against OPT_SHORT and OPT_UNSET to an enum
which keeps track of how a given option got parsed. The case of "0"
was an implicit OPT_LONG, so let's add an explicit label for it.

Due to the xor in 0f1930c5875 (parse-options: allow positivation of
options starting, with no-, 2012-02-25) the code already relied on
this being set back to 0. To avoid refactoring the logic involved in
that let's just start the enum at "0" instead of the usual "1&lt;&lt;0" (1),
but BUG() out if we don't have one of our expected flags.

Signed-off-by: Ævar Arnfjörð Bjarmason &lt;avarab@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options.[ch]: make opt{bug,name}() "static"</title>
<updated>2021-10-08T21:13:11Z</updated>
<author>
<name>Ævar Arnfjörð Bjarmason</name>
<email>avarab@gmail.com</email>
</author>
<published>2021-10-08T19:07:44Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=28794ec72e284ba398b562bc117e091853ef0332'/>
<id>urn:sha1:28794ec72e284ba398b562bc117e091853ef0332</id>
<content type='text'>
Change these two functions to "static", the last user of "optname()"
outside of parse-options.c itself went away in the preceding commit,
for the reasons noted in 9440b831ad5 (parse-options: replace
opterror() with optname(), 2018-11-10) we shouldn't be adding any more
users of it.

The "optbug()" function was never used outside of parse-options.c, but
was made non-static in 1f275b7c4ca (parse-options: export opterr,
optbug, 2011-08-11). I think the only external user of optname() was
the commit-graph.c caller added in 09e0327f57 (builtin/commit-graph.c:
introduce '--max-new-filters=&lt;n&gt;', 2020-09-18).

Signed-off-by: Ævar Arnfjörð Bjarmason &lt;avarab@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options.c: move optname() earlier in the file</title>
<updated>2021-10-08T21:13:11Z</updated>
<author>
<name>Ævar Arnfjörð Bjarmason</name>
<email>avarab@gmail.com</email>
</author>
<published>2021-10-08T19:07:42Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=3c2047a711a47fbaf0b20d8f9a551c764a6c3f34'/>
<id>urn:sha1:3c2047a711a47fbaf0b20d8f9a551c764a6c3f34</id>
<content type='text'>
In preparation for making "optname" a static function move it above
its first user in parse-options.c.

Signed-off-by: Ævar Arnfjörð Bjarmason &lt;avarab@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options.c: use exhaustive "case" arms for "enum parse_opt_result"</title>
<updated>2021-10-08T21:13:11Z</updated>
<author>
<name>Ævar Arnfjörð Bjarmason</name>
<email>avarab@gmail.com</email>
</author>
<published>2021-10-08T19:07:40Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=1b887353d75f62c957e04c7d6ff706142c761a4c'/>
<id>urn:sha1:1b887353d75f62c957e04c7d6ff706142c761a4c</id>
<content type='text'>
Change the "default" case in parse_options() that handles the return
value of parse_options_step() to simply have a "case" arm for
PARSE_OPT_UNKNOWN, instead of leaving it to a comment. This means the
compiler can warn us about any missing case arms.

This adjusts code added in ff43ec3e2d2 (parse-opt: create
parse_options_step., 2008-06-23), given its age it may pre-date the
existence (or widespread use) of this coding style, which we've since
adopted more widely.

Signed-off-by: Ævar Arnfjörð Bjarmason &lt;avarab@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options.[ch]: consistently use "enum parse_opt_result"</title>
<updated>2021-10-08T21:13:11Z</updated>
<author>
<name>Ævar Arnfjörð Bjarmason</name>
<email>avarab@gmail.com</email>
</author>
<published>2021-10-08T19:07:39Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=352e761388b5fa41bf40e7c04edf3cb07d888d94'/>
<id>urn:sha1:352e761388b5fa41bf40e7c04edf3cb07d888d94</id>
<content type='text'>
Use the "enum parse_opt_result" instead of an "int flags" as the
return value of the applicable functions in parse-options.c.

This will help catch future bugs, such as the missing "case" arms in
the two existing users of the API in "blame.c" and "shortlog.c". A
third caller in 309be813c9b (update-index: migrate to parse-options
API, 2010-12-01) was already checking for these.

As can be seen when trying to sort through the deluge of warnings
produced when compiling this with CC=g++ (mostly unrelated to this
change) we're not consistently using "enum parse_opt_result" even now,
i.e. we'll return error() and "return 0;". See f41179f16ba
(parse-options: avoid magic return codes, 2019-01-27) for a commit
which started changing some of that.

I'm not doing any more of that exhaustive migration here, and it's
probably not worthwhile past the point of being able to check "enum
parse_opt_result" in switch().

Signed-off-by: Ævar Arnfjörð Bjarmason &lt;avarab@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options.[ch]: consistently use "enum parse_opt_flags"</title>
<updated>2021-10-08T21:13:11Z</updated>
<author>
<name>Ævar Arnfjörð Bjarmason</name>
<email>avarab@gmail.com</email>
</author>
<published>2021-10-08T19:07:38Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=3f9ab7ccdea91b8312a14d39ce752b4d6685d067'/>
<id>urn:sha1:3f9ab7ccdea91b8312a14d39ce752b4d6685d067</id>
<content type='text'>
Use the "enum parse_opt_flags" instead of an "int flags" as arguments
to the various functions in parse-options.c.

Even though this is an enum bitfield there's there's a benefit to
doing this when it comes to the wider C ecosystem. E.g. the GNU
debugger (gdb) will helpfully detect and print out meaningful enum
labels in this case. Here's the output before and after when breaking
in "parse_options()" after invoking "git stash show":

Before:

    (gdb) p flags
    $1 = 9

After:

    (gdb) p flags
    $1 = (PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_UNKNOWN)

Of course as noted in[1] there's a limit to this smartness,
i.e. manually setting it with unrelated enum labels won't be
caught. There are some third-party extensions to do more exhaustive
checking[2], perhaps we'll be able to make use of them sooner than
later.

We've also got prior art using this pattern in the codebase. See
e.g. "enum bloom_filter_computed" added in 312cff52074 (bloom: split
'get_bloom_filter()' in two, 2020-09-16) and the "permitted" enum
added in ce910287e72 (add -p: fix checking of user input, 2020-08-17).

1. https://lore.kernel.org/git/87mtnvvj3c.fsf@evledraar.gmail.com/
2. https://github.com/sinelaw/elfs-clang-plugins/blob/master/enums_conversion/README.md

Signed-off-by: Ævar Arnfjörð Bjarmason &lt;avarab@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
