<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/parse-options.c, branch v2.32.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.32.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.32.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2021-03-21T21:39:10Z</updated>
<entry>
<title>parse-options: don't leak alias help messages</title>
<updated>2021-03-21T21:39:10Z</updated>
<author>
<name>Andrzej Hunt</name>
<email>ajrhunt@google.com</email>
</author>
<published>2021-03-21T16:58:36Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=64cc539fd2f8e02f39cfae21e9523da2532c0467'/>
<id>urn:sha1:64cc539fd2f8e02f39cfae21e9523da2532c0467</id>
<content type='text'>
preprocess_options() allocates new strings for help messages for
OPTION_ALIAS. Therefore we also need to clean those help messages up
when freeing the returned options.

First introduced in:
  7c280589cf (parse-options: teach "git cmd -h" to show alias as alias, 2020-03-16)

The preprocessed options themselves no longer contain any indication
that a given option is/was an alias - therefore we add a new flag to
indicate former aliases. (An alternative approach would be to look back
at the original options to determine which options are aliases - but
that seems like a fragile approach. Or we could even look at the
alias_groups list - which might be less fragile, but would be slower
as it requires nested looping.)

As far as I can tell, parse_options() is only ever used once per
command, and the help messages are small - hence this leak has very
little impact.

This leak was found while running t0001. LSAN output can be found below:

Direct leak of 65 byte(s) in 1 object(s) allocated from:
    #0 0x49a859 in realloc /home/abuild/rpmbuild/BUILD/llvm-11.0.0.src/build/../projects/compiler-rt/lib/asan/asan_malloc_linux.cpp:164:3
    #1 0x9aae36 in xrealloc /home/ahunt/oss-fuzz/git/wrapper.c:126:8
    #2 0x939d8d in strbuf_grow /home/ahunt/oss-fuzz/git/strbuf.c:98:2
    #3 0x93b936 in strbuf_vaddf /home/ahunt/oss-fuzz/git/strbuf.c:392:3
    #4 0x93b7ff in strbuf_addf /home/ahunt/oss-fuzz/git/strbuf.c:333:2
    #5 0x86747e in preprocess_options /home/ahunt/oss-fuzz/git/parse-options.c:666:3
    #6 0x866ed2 in parse_options /home/ahunt/oss-fuzz/git/parse-options.c:847:17
    #7 0x51c4a7 in cmd_clone /home/ahunt/oss-fuzz/git/builtin/clone.c:989:9
    #8 0x4cd60d in run_builtin /home/ahunt/oss-fuzz/git/git.c:453:11
    #9 0x4cb2da in handle_builtin /home/ahunt/oss-fuzz/git/git.c:704:3
    #10 0x4ccc37 in run_argv /home/ahunt/oss-fuzz/git/git.c:771:4
    #11 0x4cac29 in cmd_main /home/ahunt/oss-fuzz/git/git.c:902:19
    #12 0x69c9fe in main /home/ahunt/oss-fuzz/git/common-main.c:52:11
    #13 0x7fdac42d4349 in __libc_start_main (/lib64/libc.so.6+0x24349)

Signed-off-by: Andrzej Hunt &lt;ajrhunt@google.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>MacOS: precompose_argv_prefix()</title>
<updated>2021-02-03T22:09:37Z</updated>
<author>
<name>Torsten Bögershausen</name>
<email>tboegi@web.de</email>
</author>
<published>2021-02-03T16:28:23Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=5c327502dbf7a27c8784c20037851206a87857c1'/>
<id>urn:sha1:5c327502dbf7a27c8784c20037851206a87857c1</id>
<content type='text'>
The following sequence leads to a "BUG" assertion running under MacOS:

  DIR=git-test-restore-p
  Adiarnfd=$(printf 'A\314\210')
  DIRNAME=xx${Adiarnfd}yy
  mkdir $DIR &amp;&amp;
  cd $DIR &amp;&amp;
  git init &amp;&amp;
  mkdir $DIRNAME &amp;&amp;
  cd $DIRNAME &amp;&amp;
  echo "Initial" &gt;file &amp;&amp;
  git add file &amp;&amp;
  echo "One more line" &gt;&gt;file &amp;&amp;
  echo y | git restore -p .

 Initialized empty Git repository in /tmp/git-test-restore-p/.git/
 BUG: pathspec.c:495: error initializing pathspec_item
 Cannot close git diff-index --cached --numstat
 [snip]

The command `git restore` is run from a directory inside a Git repo.
Git needs to split the $CWD into 2 parts:
The path to the repo and "the rest", if any.
"The rest" becomes a "prefix" later used inside the pathspec code.

As an example, "/path/to/repo/dir-inside-repå" would determine
"/path/to/repo" as the root of the repo, the place where the
configuration file .git/config is found.

The rest becomes the prefix ("dir-inside-repå"), from where the
pathspec machinery expands the ".", more about this later.
If there is a decomposed form, (making the decomposing visible like this),
"dir-inside-rep°a" doesn't match "dir-inside-repå".

Git commands need to:

 (a) read the configuration variable "core.precomposeunicode"
 (b) precocompose argv[]
 (c) precompose the prefix, if there was any

The first commit,
76759c7dff53 "git on Mac OS and precomposed unicode"
addressed (a) and (b).

The call to precompose_argv() was added into parse-options.c,
because that seemed to be a good place when the patch was written.

Commands that don't use parse-options need to do (a) and (b) themselfs.

The commands `diff-files`, `diff-index`, `diff-tree` and `diff`
learned (a) and (b) in
commit 90a78b83e0b8 "diff: run arguments through precompose_argv"

Branch names (or refs in general) using decomposed code points
resulting in decomposed file names had been fixed in
commit 8e712ef6fc97 "Honor core.precomposeUnicode in more places"

The bug report from above shows 2 things:
- more commands need to handle precomposed unicode
- (c) should be implemented for all commands using pathspecs

Solution:
precompose_argv() now handles the prefix (if needed), and is renamed into
precompose_argv_prefix().

Inside this function the config variable core.precomposeunicode is read
into the global variable precomposed_unicode, as before.
This reading is skipped if precomposed_unicode had been read before.

The original patch for preocomposed unicode, 76759c7dff53, placed
precompose_argv() into parse-options.c

Now add it into git.c::run_builtin() as well.  Existing precompose
calls in diff-files.c and others may become redundant, and if we
audit the callflows that reach these places to make sure that they
can never be reached without going through the new call added to
run_builtin(), we might be able to remove these existing ones.

But in this commit, we do not bother to do so and leave these
precompose callsites as they are.  Because precompose() is
idempotent and can be called on an already precomposed string
safely, this is safer than removing existing calls without fully
vetting the callflows.

There is certainly room for cleanups - this change intends to be a bug fix.
Cleanups needs more tests in e.g. t/t3910-mac-os-precompose.sh, and should
be done in future commits.

[1] git-bugreport-2021-01-06-1209.txt (git can't deal with special characters)
[2] https://lore.kernel.org/git/A102844A-9501-4A86-854D-E3B387D378AA@icloud.com/

Reported-by: Daniel Troger &lt;random_n0body@icloud.com&gt;
Helped-By: Philippe Blain &lt;levraiphilippeblain@gmail.com&gt;
Signed-off-by: Torsten Bögershausen &lt;tboegi@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options: add --git-completion-helper-all</title>
<updated>2020-08-20T00:46:17Z</updated>
<author>
<name>Ryan Zoeller</name>
<email>rtzoeller@rtzoeller.com</email>
</author>
<published>2020-08-19T23:06:08Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=a0abe5e3b72c721a687ad9dc1a4a9bafe938c738'/>
<id>urn:sha1:a0abe5e3b72c721a687ad9dc1a4a9bafe938c738</id>
<content type='text'>
--git-completion-helper excludes hidden options, such as --allow-empty
for git commit. This is typically helpful, but occasionally we want
auto-completion for obscure flags. --git-completion-helper-all returns
all options, even if they are marked as hidden or nocomplete.

Signed-off-by: Ryan Zoeller &lt;rtzoeller@rtzoeller.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>parse-options: teach "git cmd -h" to show alias as alias</title>
<updated>2020-03-16T21:27:07Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2020-03-16T20:22:54Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=7c280589cffa6f55f6bef0496776334f1e3cdcb5'/>
<id>urn:sha1:7c280589cffa6f55f6bef0496776334f1e3cdcb5</id>
<content type='text'>
There is a long-standing NEEDSWORK comment that complains about
inconsistency between how an aliased option ("git clone --recurse"
which is the only one that currently exists) gives a help text in
a usage-error message vs "git cmd -h").  Get rid of it and then
make sure we say an option is an alias for another, instead of
repeating the same short help text for both, which leads to "they
seem to do the same---is there any subtle difference?" puzzlement
to end-users.

Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'pb/am-show-current-patch'</title>
<updated>2020-03-09T18:21:19Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2020-03-09T18:21:19Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=0e0d717537547e8fcba441e4f65237c7fd227a34'/>
<id>urn:sha1:0e0d717537547e8fcba441e4f65237c7fd227a34</id>
<content type='text'>
"git am --short-current-patch" is a way to show the piece of e-mail
for the stopped step, which is not suitable to directly feed "git
apply" (it is designed to be a good "git am" input).  It learned a
new option to show only the patch part.

* pb/am-show-current-patch:
  am: support --show-current-patch=diff to retrieve .git/rebase-apply/patch
  am: support --show-current-patch=raw as a synonym for--show-current-patch
  am: convert "resume" variable to a struct
  parse-options: convert "command mode" to a flag
  parse-options: add testcases for OPT_CMDMODE()
</content>
</entry>
<entry>
<title>parse-options: convert "command mode" to a flag</title>
<updated>2020-02-20T21:20:40Z</updated>
<author>
<name>Paolo Bonzini</name>
<email>pbonzini@redhat.com</email>
</author>
<published>2020-02-20T14:15:16Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=bc8620b44094e9fb6fc20d141678f9b845c19193'/>
<id>urn:sha1:bc8620b44094e9fb6fc20d141678f9b845c19193</id>
<content type='text'>
OPTION_CMDMODE is essentially OPTION_SET_INT plus an extra check that
the variable had not set before.  In order to allow custom processing
of the option, for example a "command mode" option that also has an
argument, it would be nice to use OPTION_CALLBACK and not have to rewrite
the extra check on incompatible options.  In other words, making the
processing of the option orthogonal to the "only one of these" behavior
provided by OPTION_CMDMODE.

Add a new flag that takes care of the check, and modify OPT_CMDMODE to
use it together with OPTION_SET_INT.  The new flag still requires that the
option value points to an int, but any OPTION_* value can be specified as
long as it does not require a non-int type for opt-&gt;value.

Signed-off-by: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'jb/parse-options-message-fix'</title>
<updated>2020-02-12T20:41:37Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2020-02-12T20:41:37Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=db72f8c940b3c49286fb88958b3c50fe6f0d6319'/>
<id>urn:sha1:db72f8c940b3c49286fb88958b3c50fe6f0d6319</id>
<content type='text'>
Error message fix.

* jb/parse-options-message-fix:
  parse-options: lose an unnecessary space in an error message
</content>
</entry>
<entry>
<title>parse-options: lose an unnecessary space in an error message</title>
<updated>2020-02-05T18:49:29Z</updated>
<author>
<name>Jacques Bodin-Hullin</name>
<email>j.bodinhullin@monsieurbiz.com</email>
</author>
<published>2020-02-05T13:07:23Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=395518cf7a290f78232979593351d366a228e5c0'/>
<id>urn:sha1:395518cf7a290f78232979593351d366a228e5c0</id>
<content type='text'>
Signed-off-by: Jacques Bodin-Hullin &lt;j.bodinhullin@monsieurbiz.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>C: use skip_prefix() to avoid hardcoded string length</title>
<updated>2020-01-31T21:03:45Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2020-01-30T19:35:46Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=145136a95a8755528aa012a4ce0ed50d1ec39e24'/>
<id>urn:sha1:145136a95a8755528aa012a4ce0ed50d1ec39e24</id>
<content type='text'>
We often skip an optional prefix in a string with a hardcoded
constant, e.g.

	if (starts_with(string, "prefix"))
		string += 6;

which is less error prone when written

	skip_prefix(string, "prefix", &amp;string);

Note that this changes a few error messages from "git reflog expire
--expire=nonsense.timestamp", which used to complain by saying

    '--expire=nonsense.timestamp' is not a valid timestamp

but with this change, we say

    'nonsense.timestamp' is not a valid timestamp

which is more technically correct (the string with --expire= as
a prefix obviously cannot be a valid timestamp, but the error is
about the part of the input without that prefix).

Helped-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Fix spelling errors in code comments</title>
<updated>2019-11-10T07:00:54Z</updated>
<author>
<name>Elijah Newren</name>
<email>newren@gmail.com</email>
</author>
<published>2019-11-05T17:07:23Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=15beaaa3d1f6b555900446deb5e376b4f806d734'/>
<id>urn:sha1:15beaaa3d1f6b555900446deb5e376b4f806d734</id>
<content type='text'>
Reported-by: Jens Schleusener &lt;Jens.Schleusener@fossies.org&gt;
Signed-off-by: Elijah Newren &lt;newren@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
