<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/parse-options.h, branch v2.50.0</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.50.0</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.50.0'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2025-04-17T15:15:16Z</updated>
<entry>
<title>parse-options: detect mismatches in integer signedness</title>
<updated>2025-04-17T15:15:16Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2025-04-17T10:49:42Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=791aeddfa2fdb9e830e24c50c97bb5e8bf3613e6'/>
<id>urn:sha1:791aeddfa2fdb9e830e24c50c97bb5e8bf3613e6</id>
<content type='text'>
It was reported that "t5620-backfill.sh" fails on s390x and sparc64 in a
test that exercises the "--min-batch-size" command line option. The
symptom was that the option didn't seem to have an effect: we didn't
fetch objects with a batch size of 20, but instead fetched all objects
at once.

As it turns out, the root cause is that `--min-batch-size` uses
`OPT_INTEGER()` to parse the command line option. While this macro
expects the caller to pass a pointer to an integer, we instead pass a
pointer to a `size_t`. This coincidentally works on most platforms, but
it breaks apart on the mentioned platforms because they are big endian.

This issue isn't specific to git-backfill(1): there are a couple of
other places where we have the same type confusion going on. This
indicates that the issue really is the interface that the parse-options
subsystem provides -- it is simply too easy to get this wrong as there
isn't any kind of compiler warning, and things just work on the most
common systems.

Address the systemic issue by introducing two new build asserts
`BARF_UNLESS_SIGNED()` and `BARF_UNLESS_UNSIGNED()`. As the names
already hint at, those macros will cause a compiler error when passed a
value that is not signed or unsigned, respectively.

Adapt `OPT_INTEGER()`, `OPT_UNSIGNED()` as well as `OPT_MAGNITUDE()` to
use those asserts. This uncovers a small set of sites where we indeed
have the same bug as in git-backfill(1). Adapt all of them to use the
correct option.

Reported-by: Todd Zullinger &lt;tmz@pobox.com&gt;
Reported-by: John Paul Adrian Glaubitz &lt;glaubitz@physik.fu-berlin.de&gt;
Helped-by: SZEDER Gábor &lt;szeder.dev@gmail.com&gt;
Helped-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options: introduce precision handling for `OPTION_UNSIGNED`</title>
<updated>2025-04-17T15:15:16Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2025-04-17T10:49:41Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=bc288c59298f199348418ca08322046c67c9a0a2'/>
<id>urn:sha1:bc288c59298f199348418ca08322046c67c9a0a2</id>
<content type='text'>
This commit is the equivalent to the preceding commit, but instead of
introducing precision handling for `OPTION_INTEGER` we introduce it for
`OPTION_UNSIGNED`.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options: introduce precision handling for `OPTION_INTEGER`</title>
<updated>2025-04-17T15:15:15Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2025-04-17T10:49:40Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=09705696f763bac370ac74926bef137eb712c0c8'/>
<id>urn:sha1:09705696f763bac370ac74926bef137eb712c0c8</id>
<content type='text'>
The `OPTION_INTEGER` option type accepts a signed integer. The type of
the underlying integer is a simple `int`, which restricts the range of
values accepted by such options. But there is a catch: because the
caller provides a pointer to the value via the `.value` field, which is
a simple void pointer. This has two consequences:

  - There is no check whether the passed value is sufficiently long to
    store the entire range of `int`. This can lead to integer wraparound
    in the best case and out-of-bounds writes in the worst case.

  - Even when a caller knows that they want to store a value larger than
    `INT_MAX` they don't have a way to do so.

In practice this doesn't tend to be a huge issue because users typically
don't end up passing huge values to most commands. But the parsing logic
is demonstrably broken, and it is too easy to get the calling convention
wrong.

Improve the situation by introducing a new `precision` field into the
structure. This field gets assigned automatically by `OPT_INTEGER_F()`
and tracks the size of the passed value. Like this it becomes possible
for the caller to pass arbitrarily-sized integers and the underlying
logic knows to handle it correctly by doing range checks. Furthermore,
convert the code to use `strtoimax()` intstead of `strtol()` so that we
can also parse values larger than `LONG_MAX`.

Note that we do not yet assert signedness of the passed variable, which
is another source of bugs. This will be handled in a subsequent commit.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options: rename `OPT_MAGNITUDE()` to `OPT_UNSIGNED()`</title>
<updated>2025-04-17T15:15:15Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2025-04-17T10:49:39Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=785c17df7817df8512d2cb92cfc079ef0b4de27c'/>
<id>urn:sha1:785c17df7817df8512d2cb92cfc079ef0b4de27c</id>
<content type='text'>
With the preceding commit, `OPT_INTEGER()` has learned to support unit
factors. Consequently, the major differencen between `OPT_INTEGER()` and
`OPT_MAGNITUDE()` isn't the support of unit factors anymore, as both of
them do support them now. Instead, the difference is that one handles
signed and the other handles unsigned integers.

Adapt the name of `OPT_MAGNITUDE()` accordingly by renaming it to
`OPT_UNSIGNED()`.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options.h: *.txt -&gt; *.adoc fixes</title>
<updated>2025-03-03T21:49:24Z</updated>
<author>
<name>Todd Zullinger</name>
<email>tmz@pobox.com</email>
</author>
<published>2025-03-03T20:44:20Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=458f8b0eab9af7b770a25e9277f70bb4df3c8d90'/>
<id>urn:sha1:458f8b0eab9af7b770a25e9277f70bb4df3c8d90</id>
<content type='text'>
Signed-off-by: Todd Zullinger &lt;tmz@pobox.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options: introduce die_for_incompatible_opt2()</title>
<updated>2025-02-06T20:23:54Z</updated>
<author>
<name>Toon Claes</name>
<email>toon@iotcl.com</email>
</author>
<published>2025-02-06T06:33:34Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=9144b9362b2ed972f5886dcc7beee6a2acce2708'/>
<id>urn:sha1:9144b9362b2ed972f5886dcc7beee6a2acce2708</id>
<content type='text'>
The functions die_for_incompatible_opt3() and
die_for_incompatible_opt4() already exist to die whenever a user
specifies three or four options respectively that are not compatible.

Introduce die_for_incompatible_opt2() which dies when two options that
are incompatible are set.

Signed-off-by: Toon Claes &lt;toon@iotcl.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options: add show_usage_with_options_if_asked()</title>
<updated>2025-01-17T21:30:02Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2025-01-16T21:35:49Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=1782abd7734acffb8ebc37b74e120fd4c4b9c4cc'/>
<id>urn:sha1:1782abd7734acffb8ebc37b74e120fd4c4b9c4cc</id>
<content type='text'>
Many commands call usage_with_options() when they are asked to give
the help message, but it sends the help text to the standard error
stream.  When the user asked for it with "git cmd -h", the help
message is the primary output from the command, hence we should send
it to the standard output stream, instead.

Introduce a helper function that captures the common pattern

	if (argc == 2 &amp;&amp; !strcmp(argv[1], "-h"))
		usage_with_options(usage, options);

and replaces it with

	show_usage_with_options_if_asked(argc, argv, usage, options);

to help correct code paths.

Note that this helper function still exits with status 129, and
t0012 insists on it.  After converting all the mistaken callers of
usage_with_options() to call this new helper, we may want to address
it---the end user is asking us to give the help text, and we are
doing exactly as asked, so there is no reason to exit with non-zero
status.

Suggested-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>t: introduce compatibility options to clar-based tests</title>
<updated>2024-12-13T14:48:47Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-12-13T10:41:22Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=9faf3963b6b567421ab29d263e00f0e6e59a39f5'/>
<id>urn:sha1:9faf3963b6b567421ab29d263e00f0e6e59a39f5</id>
<content type='text'>
Our unit tests that don't yet use the clar unit testing framework ignore
any option that they do not understand. It is thus fine to just pass
test options we set up globally to those unit tests as they are simply
ignored. This makes our life easier because we don't have to special
case those options with Meson, where test options are set up globally
via `meson test --test-args=`.

But our clar-based unit testing framework is way stricter here and will
fail in case it is passed an unknown option. Stub out these options with
no-ops to make our life a bit easier.

Note that this also requires us to remove the `-x` short option for
`--exclude`. This is because `-x` has another meaning in our integration
tests, as it enables shell tracing. I doubt there are a lot of people
out there using it as we only got a small hand full of clar tests in the
first place. So better change it now so that we can in the long run
improve compatibility between the two different test drivers.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>builtin: pass repository to sub commands</title>
<updated>2024-11-26T01:36:08Z</updated>
<author>
<name>Karthik Nayak</name>
<email>karthik.188@gmail.com</email>
</author>
<published>2024-11-25T14:55:30Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=6f33d8e255cb2ff738cd28eab22751efb7c2d6ce'/>
<id>urn:sha1:6f33d8e255cb2ff738cd28eab22751efb7c2d6ce</id>
<content type='text'>
In 9b1cb5070f (builtin: add a repository parameter for builtin
functions, 2024-09-13) the repository was passed down to all builtin
commands. This allowed the repository to be passed down to lower layers
without depending on the global `the_repository` variable.

Continue this work by also passing down the repository parameter from
the command to sub-commands. This will help pass down the repository to
other subsystems and cleanup usage of global variables like
'the_repository' and 'the_hash_algo'.

Signed-off-by: Karthik Nayak &lt;karthik.188@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options: cast long name for OPTION_ALIAS</title>
<updated>2024-06-07T17:30:53Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-06-07T06:38:54Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=e463c5e8a0c306b62c25ff5856087ab32403158a'/>
<id>urn:sha1:e463c5e8a0c306b62c25ff5856087ab32403158a</id>
<content type='text'>
We assign the long name for OPTION_ALIAS options to a non-constant value
field. We know that the variable will never be written to, but this will
cause warnings once we enable `-Wwrite-strings`.

Cast away the constness to be prepared for this change.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
