]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
2 weeks agotest-lib: respect GIT_TEST_INSTALLED when querying default hash
Kyle Lippincott [Tue, 15 Jul 2025 18:57:54 +0000 (18:57 +0000)] 
test-lib: respect GIT_TEST_INSTALLED when querying default hash

$GIT_TEST_INSTALLED can be set to use an "installed" git instead of the
one from $GIT_BUILD_DIR. This is used by my company's internal test
infrastructure, and not using $GIT_TEST_INSTALLED when querying the
default hash meant that the tests were failing because the hash was
effectively set to the empty string (since git didn't execute).

In the two places we attempt to detect/execute git itself prior to
overriding everything and putting it in $PATH, use identical logic for
identifying the git binary to execute. This also has the effect of
including the $X suffix when querying the default hash, but that's not
strictly necessary. You don't need to specify .exe when running a binary
on Windows, just when testing whether it exists or not.

Signed-off-by: Kyle Lippincott <spectral@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 weeks agoMerge branch 'bc/use-sha256-by-default-in-3.0' into kl/test-installed-fix
Junio C Hamano [Tue, 15 Jul 2025 21:31:01 +0000 (14:31 -0700)] 
Merge branch 'bc/use-sha256-by-default-in-3.0' into kl/test-installed-fix

2 weeks agoconfig: remove unneeded struct field
Phillip Wood [Tue, 15 Jul 2025 14:00:56 +0000 (15:00 +0100)] 
config: remove unneeded struct field

As well as receiving the config key and value, config callbacks
also receive a "struct key_value_info" containing information about
the source of the key-value pair. Accessing the "path" field of
this struct from a callback passed to repo_config() results in a
use-after-free. This happens because repo_config() first populates a
configset by calling config_with_options() and then iterates over the
configset with the callback passed by the caller. When the configset
is constructed it takes a shallow copy of the "struct key_value_info"
for each config setting. This leads to the use-after-free as the
"path" member is freed before config_with_options() returns.

We could fix this by interning the "path" field as we do
for the "filename" field but the "path" field is not actually
needed. It is populated with a copy of the "path" field from "struct
config_source". That field was added in d14d42440d8 (config: disallow
relative include paths from blobs, 2014-02-19) to distinguish between
relative include directives in files and those in blobs. However,
since 1b8132d99d8 (i18n: config: unfold error messages marked for
translation, 2016-07-28) we can differentiate these by looking at the
"origin_type" field in "struct key_value_info". So let's remove the
"path" members from "struct config_source" and "struct key_value_info"
and instead use a combination of the "filename" and "origin_type"
fields to determine the absolute path of relative includes.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 weeks agobloom: optimize multiple pathspec items in revision
Lidong Yan [Tue, 15 Jul 2025 02:56:22 +0000 (10:56 +0800)] 
bloom: optimize multiple pathspec items in revision

To enable optimize multiple pathspec items in revision traversal,
return 0 if all pathspec item is literal in forbid_bloom_filters().
Add for loops to initialize and check each pathspec item's bloom_keyvec
when optimization is possible.

Add new test cases in t/t4216-log-bloom.sh to ensure
 - consistent results between the optimization for multiple pathspec
   items using bloom filter and the case without bloom filter
   optimization.
 - does not use bloom filter if any pathspec item is not literal.

With these optimizations, we get some improvements for multi-pathspec runs
of 'git log'. First, in the Git repository we see these modest results:

Benchmark 1: old
 Time (mean ± σ):      73.1 ms ±   2.9 ms
 Range (min … max):    69.9 ms …  84.5 ms    42 runs

Benchmark 2: new
 Time (mean ± σ):      55.1 ms ±   2.9 ms
 Range (min … max):    51.1 ms …  61.2 ms    52 runs

Summary
 'new' ran
   1.33 ± 0.09 times faster than 'old'

But in a larger repo, such as the LLVM project repo below, we get even
better results:

Benchmark 1: old
 Time (mean ± σ):      1.974 s ±  0.006 s
 Range (min … max):    1.960 s …  1.983 s    10 runs

Benchmark 2: new
 Time (mean ± σ):     262.9 ms ±   2.4 ms
 Range (min … max):   257.7 ms … 266.2 ms    11 runs

Summary
 'new' ran
   7.51 ± 0.07 times faster than 'old'

Signed-off-by: Derrick Stolee <stolee@gmail.com>
[ly: rename convert_pathspec_to_filter() to convert_pathspec_to_bloom_keyvec()]
Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 weeks agoThe ninth batch
Junio C Hamano [Mon, 14 Jul 2025 18:18:42 +0000 (11:18 -0700)] 
The ninth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 weeks agoMerge branch 'rp/apply-intent-to-add-fix'
Junio C Hamano [Mon, 14 Jul 2025 18:19:29 +0000 (11:19 -0700)] 
Merge branch 'rp/apply-intent-to-add-fix'

"git apply -N" should start from the current index and register
only new files, but it instead started from an empty index, which
has been corrected.

* rp/apply-intent-to-add-fix:
  apply docs: clarify wording for --intent-to-add
  t4140: test apply --intent-to-add interactions
  apply: only write intents to add for new files
  apply: read in the index in --intent-to-add mode

2 weeks agoMerge branch 'sj/string-list'
Junio C Hamano [Mon, 14 Jul 2025 18:19:28 +0000 (11:19 -0700)] 
Merge branch 'sj/string-list'

Code and test clean-up around string-list API.

* sj/string-list:
  u-string-list: move "remove duplicates" test to "u-string-list.c"
  u-string-list: move "filter string" test to "u-string-list.c"
  u-string-list: move "test_split_in_place" to "u-string-list.c"
  u-string-list: move "test_split" into "u-string-list.c"
  string-list: enable sign compare warnings check
  string-list: return index directly when inserting an existing element
  string-list: remove unused "insert_at" parameter from add_entry
  string-list: fix sign compare warnings for loop iterator

2 weeks agoMerge branch 'rj/freebsd-sysinfo-build-fix'
Junio C Hamano [Mon, 14 Jul 2025 18:19:28 +0000 (11:19 -0700)] 
Merge branch 'rj/freebsd-sysinfo-build-fix'

Build fix for FreeBSD.

* rj/freebsd-sysinfo-build-fix:
  build: fix FreeBSD build when sysinfo compat library installed

2 weeks agoMerge branch 'ts/merge-orig-head-doc-fix'
Junio C Hamano [Mon, 14 Jul 2025 18:19:27 +0000 (11:19 -0700)] 
Merge branch 'ts/merge-orig-head-doc-fix'

Doc fix.

* ts/merge-orig-head-doc-fix:
  docs: correct ORIG_HEAD example in "git merge" documentation

2 weeks agoMerge branch 'ps/perlless-test-fixes'
Junio C Hamano [Mon, 14 Jul 2025 18:19:27 +0000 (11:19 -0700)] 
Merge branch 'ps/perlless-test-fixes'

Test fixes.

* ps/perlless-test-fixes:
  t5333: fix missing terminator for sed(1) 's' command
  t4150: fix warning printed by awk due to escaped '\@'

2 weeks agoMerge branch 're/ssh-sign-buffer-fix'
Junio C Hamano [Mon, 14 Jul 2025 18:19:26 +0000 (11:19 -0700)] 
Merge branch 're/ssh-sign-buffer-fix'

Tempfile removal fix in the codepath to sign commits with SSH keys.

* re/ssh-sign-buffer-fix:
  ssh signing: don't detach the filename strbuf from key_file tempfile

2 weeks agoMerge branch 'hy/read-cache-lock-error-fix'
Junio C Hamano [Mon, 14 Jul 2025 18:19:26 +0000 (11:19 -0700)] 
Merge branch 'hy/read-cache-lock-error-fix'

A failure to open the index file for writing due to conflicting
access did not state what went wrong, which has been corrected.

* hy/read-cache-lock-error-fix:
  read-cache: report lock error when refreshing index

2 weeks agoMerge branch 'kn/clang-format-updates'
Junio C Hamano [Mon, 14 Jul 2025 18:19:26 +0000 (11:19 -0700)] 
Merge branch 'kn/clang-format-updates'

Update ".clang-format" and ".editorconfig" to match our style guide
a bit better.

* kn/clang-format-updates:
  meson: add rule to run 'git clang-format'
  clang-format: add 'RemoveBracesLLVM' to the main config
  clang-format: set 'ColumnLimit' to 0

2 weeks agoMerge branch 'kh/doc-config-subcommands'
Junio C Hamano [Mon, 14 Jul 2025 18:19:25 +0000 (11:19 -0700)] 
Merge branch 'kh/doc-config-subcommands'

Documentation updates.

* kh/doc-config-subcommands:
  config: mention --url in the synopsis
  config: use --value instead of value-pattern
  config: document --[no-]value
  config: use --value=<pattern> consistently
  config: document --[no-]show-names

2 weeks agoMerge branch 'mc/netrc-service-names'
Junio C Hamano [Mon, 14 Jul 2025 18:19:25 +0000 (11:19 -0700)] 
Merge branch 'mc/netrc-service-names'

"netrc" credential helper has been improved to understand textual
service names (like smtp) in addition to the numeric port numbers
(like 25).

* mc/netrc-service-names:
  contrib: better support symbolic port names in git-credential-netrc
  contrib: warn for invalid netrc file ports in git-credential-netrc
  contrib: use a more portable shebang for git-credential-netrc

2 weeks agoMerge branch 'jc/coccicheck-fails-make-when-it-fails'
Junio C Hamano [Mon, 14 Jul 2025 18:19:24 +0000 (11:19 -0700)] 
Merge branch 'jc/coccicheck-fails-make-when-it-fails'

"make coccicheck" succeeds even when spatch made suggestions, which
has been updated to fail in such a case.

* jc/coccicheck-fails-make-when-it-fails:
  coccicheck: fail "make" when it fails

2 weeks agoMerge branch 'ps/use-reftable-as-default-in-3.0'
Junio C Hamano [Mon, 14 Jul 2025 18:19:24 +0000 (11:19 -0700)] 
Merge branch 'ps/use-reftable-as-default-in-3.0'

The reftable ref backend has matured enough; Git 3.0 will make it
the default format in a newly created repositories by default.

* ps/use-reftable-as-default-in-3.0:
  setup: use "reftable" format when experimental features are enabled
  BreakingChanges: announce switch to "reftable" format

2 weeks agoMerge branch 'jk/all-negative-diff-filter-fix'
Junio C Hamano [Mon, 14 Jul 2025 18:19:24 +0000 (11:19 -0700)] 
Merge branch 'jk/all-negative-diff-filter-fix'

A diff-filter with negative-only specification like "git log
--diff-filter=d" did not trigger correctly, which has been fixed.

* jk/all-negative-diff-filter-fix:
  setup_revisions(): turn on diffs for all-negative diff filter

2 weeks agoMerge branch 'ac/prune-wo-the-repository'
Junio C Hamano [Mon, 14 Jul 2025 18:19:23 +0000 (11:19 -0700)] 
Merge branch 'ac/prune-wo-the-repository'

Some code paths in the "git prune" used to ignore passed in
repository object and used the_repository singleton instance
instead, which has been corrected.

* ac/prune-wo-the-repository:
  builtin/prune: stop depending on 'the_repository'
  repository: move 'repository_format_precious_objects' to repo scope

2 weeks agoMerge branch 'bs/config-mak-freebsd'
Junio C Hamano [Mon, 14 Jul 2025 18:19:23 +0000 (11:19 -0700)] 
Merge branch 'bs/config-mak-freebsd'

Drop FreeBSD 4 support and assume we are at least at FreeBSD 6 with
memmem() supported.

* bs/config-mak-freebsd:
  build: retire NO_UINTMAX_T
  config.mak.uname: set NO_MEMMEM only for functional version

2 weeks agoMerge branch 'cb/total-ram-bsd-fix'
Junio C Hamano [Mon, 14 Jul 2025 18:19:22 +0000 (11:19 -0700)] 
Merge branch 'cb/total-ram-bsd-fix'

Use of sysctl() system call to learn the total RAM size used on
BSDs has been corrected.

* cb/total-ram-bsd-fix:
  builtin/gc: correct total_ram calculation with HAVE_BSD_SYSCTL

2 weeks agoMerge branch 'bs/remote-helpers-doc-markup-fix'
Junio C Hamano [Mon, 14 Jul 2025 18:19:22 +0000 (11:19 -0700)] 
Merge branch 'bs/remote-helpers-doc-markup-fix'

Docfix.

* bs/remote-helpers-doc-markup-fix:
  gitremote-helpers.adoc: fix formatting

2 weeks agogpg-interface: expand gpg.program as a path
Jonas Brandstötter [Fri, 11 Jul 2025 23:23:47 +0000 (01:23 +0200)] 
gpg-interface: expand gpg.program as a path

This allows using a custom gpg program under the user's home directory
by specifying a path starting with '~'

[gpg]
        program = "~/.local/bin/mygpg"

Signed-off-by: Jonas Brandstötter <jonas.brandstoetter@gmx.at>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 weeks agorevision: make helper for pathspec to bloom keyvec
Lidong Yan [Sat, 12 Jul 2025 09:35:16 +0000 (17:35 +0800)] 
revision: make helper for pathspec to bloom keyvec

When preparing to use bloom filters in a revision walk, Git populates a
boom_keyvec with an array of bloom keys for the components of a path.
Before we create the ability to map multiple pathspecs to multiple
bloom_keyvecs, extract the conversion from a pathspec to a bloom_keyvec
into its own helper method. This simplifies the state that persists in
prepare_to_use_bloom_filter() as well as makes the future change much
simpler.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 weeks agobloom: replace struct bloom_key * with struct bloom_keyvec
Lidong Yan [Sat, 12 Jul 2025 09:35:15 +0000 (17:35 +0800)] 
bloom: replace struct bloom_key * with struct bloom_keyvec

Previously, we stored bloom keys in a flat array and marked a commit
as NOT TREESAME if any key reported "definitely not changed".

To support multiple pathspec items, we now require that for each
pathspec item, there exists a bloom key reporting "definitely not
changed".

This "for every" condition makes a flat array insufficient, so we
introduce a new structure to group keys by a single pathspec item.
`struct bloom_keyvec` is introduced to replace `struct bloom_key *`
and `bloom_key_nr`. And because we want to support multiple pathspec
items, we added a bloom_keyvec * and a bloom_keyvec_nr field to
`struct rev_info` to represent an array of bloom_keyvecs. This commit
still optimize only one pathspec item, thus bloom_keyvec_nr can only
be 0 or 1.

New bloom_keyvec_* functions are added to create and destroy a keyvec.
bloom_filter_contains_vec() is added to check if all key in keyvec is
contained in a bloom filter.

Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 weeks agobloom: rename function operates on bloom_key
Lidong Yan [Sat, 12 Jul 2025 09:35:14 +0000 (17:35 +0800)] 
bloom: rename function operates on bloom_key

git code style requires that functions operating on a struct S
should be named in the form S_verb. However, the functions operating
on struct bloom_key do not follow this convention. Therefore,
fill_bloom_key() and clear_bloom_key() are renamed to bloom_key_fill()
and bloom_key_clear(), respectively.

Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 weeks agobloom: add test helper to return murmur3 hash
Lidong Yan [Sat, 12 Jul 2025 09:35:13 +0000 (17:35 +0800)] 
bloom: add test helper to return murmur3 hash

In bloom.h, murmur3_seeded_v2() is exported for the use of test murmur3
hash. To clarify that murmur3_seeded_v2() is exported solely for testing
purposes, a new helper function test_murmur3_seeded() was added instead
of exporting murmur3_seeded_v2() directly.

Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 weeks agogitk: Add support of SHA256 repositories
Takashi Iwai [Tue, 17 Jun 2025 05:59:54 +0000 (07:59 +0200)] 
gitk: Add support of SHA256 repositories

This patch adds a basic support of SHA256 Git repository to Gitk, so
that Gitk can show and operate on both SHA1 and SHA256 repos
gracefully.  Since SHA256 has a longer ID length (64 char) than SHA1
(40 char), many field widths are adjusted to fit with it.

A caveat is that the configuration of auto selection length is shared
between SHA1 and SHA256 repos.  That is, once when this value is saved
and read, it's applied to both repo types, which may result in shorter
selection than the full SHA256 ID.  We may introduce another
individual config for sha256 (actually I did write in the first
version), but for simplicity, the common config is used as of writing
this.

Many lines still refer "sha1" although they may point to both SHA1 and
SHA256.  They are left untouched for making the changes simpler.

This patch is based on the early work by Rostislav Krasny:
  https://patchwork.kernel.org/project/git/patch/pull.979.git.1623687519832.gitgitgadget@gmail.com
I refreshed, revised and extended to the latest state.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2 weeks agoci: use Meson's new `--slice` option
Patrick Steinhardt [Wed, 9 Jul 2025 06:23:42 +0000 (08:23 +0200)] 
ci: use Meson's new `--slice` option

As executing our test suite is notoriously slow on Windows we use matrix
jobs in our CI systems to slice up tests and run them via multiple jobs.
On Meson this is done with a comparatively complex PowerShell invocation
as Meson didn't yet have a native way to slice tests like this.

I have upstreamed a new `--slice` option [1] that addresses this use
case though, which has been merged and released with Meson 1.8. Both
GitLab and GitHub CI have Meson 1.8.2 available by now, so let's update
the jobs to use that new option.

[1]: https://github.com/mesonbuild/meson/pull/14092

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 weeks agomeson: update subproject wrappers
Patrick Steinhardt [Wed, 9 Jul 2025 06:23:41 +0000 (08:23 +0200)] 
meson: update subproject wrappers

Update subproject wrappers to newer versions by executing `meson wrap
update` in the project's root directory

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 weeks agodoc: correct doc for glob pathspec
Russell Hanneken [Tue, 8 Jul 2025 02:45:07 +0000 (22:45 -0400)] 
doc: correct doc for glob pathspec

gitglossary documents Git pathspecs. One type of pathspec is the "glob"
pathspec, prefixed with the magic word "glob".

Regarding glob pathspecs, gitglossary says, '"**/foo" matches file or
directory "foo" anywhere, the same as pattern "foo".' That last phrase
('the same as pattern "foo") is incorrect. "**/foo" and "foo" are not
equivalent. "**/foo" matches foo anywhere, but "foo" does not.

This change removes the incorrect phrase from the glob pathspec doc.

Signed-off-by: Russell Hanneken <rhanneken@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agodaemon: use sigaction() to install child_handler()
Carlo Marcelo Arenas Belón [Thu, 10 Jul 2025 19:45:43 +0000 (19:45 +0000)] 
daemon: use sigaction() to install child_handler()

Replace signal() with an equivalent invocation of sigaction(), but
make sure to NOT set SA_RESTART so the original code that expects
to be interrupted when children complete still works as designed.

This change has the added benefit of using BSD signal semantics reliably
and therefore not needing the rearming call in the signal handler.

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agocompat/mingw: allow sigaction(SIGCHLD)
Carlo Marcelo Arenas Belón [Thu, 10 Jul 2025 19:45:42 +0000 (19:45 +0000)] 
compat/mingw: allow sigaction(SIGCHLD)

A future change will start using sigaction to setup a SIGCHLD signal
handler.

The current code uses signal(), which returns SIG_ERR (but doesn't
seem to set errno) so instruct sigaction() to do the same.

A new SA flag will be needed, so copy the one from Cygwin; note that
the sigaction() implementation that is provided won't use it, so
its value is otherwise irrelevant.

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agosane-ctype: fix compiler error on Amazon Linux 2
Patrick Steinhardt [Thu, 10 Jul 2025 06:46:27 +0000 (08:46 +0200)] 
sane-ctype: fix compiler error on Amazon Linux 2

Compiling Git fails on Amazon Linux 2 when using GCC 7.3.1 with the
following compiler error:

    In file included from compat/posix.h:449:0,
                     from git-compat-util.h:26,
                     from daemon.c:3:
    compat/../sane-ctype.h:29:60: error: expected expression before ']' token
     #define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
                                                                ^
    compat/../sane-ctype.h:29:72: error: expected ')' before '!=' token
     #define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
                                                                            ^
    compat/../sane-ctype.h:29:60: error: expected expression before ']' token
     #define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
                                                                ^
    ... lots of similar lines ...

    compat/../sane-ctype.h:45:50: error: expected declaration specifiers or '...' before numeric constant
     #define toupper(x) sane_case((unsigned char)(x), 0)
                                                      ^
    /usr/include/ctype.h:142:12: error: expected identifier or '(' before 'int'
     extern int isascii (int __c) __THROW;
                ^
    compat/../sane-ctype.h:30:26: error: expected ')' before '&' token
     #define isascii(x) (((x) & ~0x7f) == 0)
                              ^
    compat/../sane-ctype.h:30:35: error: expected ')' before '==' token
     #define isascii(x) (((x) & ~0x7f) == 0)
                                       ^
    In file included from /usr/include/features.h:423:0,
                     from /usr/include/unistd.h:25,
                     from compat/posix.h:90,
                     from git-compat-util.h:26,
                     from daemon.c:3:
    compat/../sane-ctype.h:44:30: error: expected declaration specifiers or '...' before '(' token
     #define tolower(x) sane_case((unsigned char)(x), 0x20)
                                  ^
    compat/../sane-ctype.h:44:50: error: expected declaration specifiers or '...' before numeric constant
     #define tolower(x) sane_case((unsigned char)(x), 0x20)
                                                      ^
    compat/../sane-ctype.h:45:30: error: expected declaration specifiers or '...' before '(' token
     #define toupper(x) sane_case((unsigned char)(x), 0)
                                  ^
    compat/../sane-ctype.h:45:50: error: expected declaration specifiers or '...' before numeric constant
     #define toupper(x) sane_case((unsigned char)(x), 0)
                                                      ^

This error bisect back to 75a044f748 (git-compat-util.h: split out
POSIX-emulating bits, 2025-02-18), where lots of bits got split out of
"git-compat-util.h" into a new "compat/posix.h" header.

The compiler error isn't immediately obvious, doubly so because the
actual errors are ~3x as long as the above snippet. But what happens
here is that we transitively include <ctype.h> after we have included
our own "sane-ctype.h" header. Consequently, the function declarations
that exist in <ctype.h> for isascii(3p) et al will be mangled by our
macros of the same type. The result is of course completely broken.

It's unclear why this issue only happens on Amazon Linux 2. My guess is
that it's either specific to the compiler version or specific to the
glibc version. We don't explicitly include <ctypes.h> anywhere, but it's
being transitively included. So chances are that later versions of the
toolchain reorganized their headers so that <ctypes.h> is not included
transitively anymore.

Fix the issue by explicitly including <ctype.h> in "sane-ctype.h". This
ensures that the header guards will be activated and that any subsequent
include of the same header will become a no-op. With this we can then
safely override the function declarations with our own macros.

Reported-by: Stan Hu <stanhu@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agofast-(import|export): improve on commit signature output format
Christian Couder [Wed, 9 Jul 2025 14:12:53 +0000 (16:12 +0200)] 
fast-(import|export): improve on commit signature output format

A recent commit, d9cb0e6ff8 (fast-export, fast-import: add support for
signed-commits, 2025-03-10), added support for signed commits to
fast-export and fast-import.

When a signed commit is processed, fast-export can output either
"gpgsig sha1" or "gpgsig sha256" depending on whether the signed
commit uses the SHA-1 or SHA-256 Git object format.

However, this implementation has a number of limitations:

  - the output format was not properly described in the documentation,
  - the output format is not very informative as it doesn't even say
    if the signature is an OpenPGP, an SSH, or an X509 signature,
  - the implementation doesn't support having both one signature on
    the SHA-1 object and one on the SHA-256 object.

Let's improve on these limitations by improving fast-export and
fast-import so that:

  - all the signatures are exported,
  - at most one signature on the SHA-1 object and one on the SHA-256
    are imported,
  - if there is more than one signature on the SHA-1 object or on
    the SHA-256 object, fast-import emits a warning for each
    additional signature,
  - the output format is "gpgsig <git-hash-algo> <signature-format>",
    where <git-hash-algo> is the Git object format as before, and
    <signature-format> is the signature type ("openpgp", "x509",
    "ssh" or "unknown"),
  - the output is properly documented.

About the output format:

  - <git-hash-algo> allows to know which representation of the commit
    was signed (the SHA-1 or the SHA-256 version) which helps with
    both signature verification and interoperability between repos
    with different hash functions,

  - <signature-format> helps tools that process the fast-export
    stream, so they don't have to parse the ASCII armor to identify
    the signature type.

It could be even better to be able to import more than one signature
on the SHA-1 object and on the SHA-256 object, but other parts of
Git don't handle that well for now, so this is left for future
improvements.

Helped-by: brian m. carlson <sandals@crustytoothpaste.net>
Helped-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoparse-options: add precision handling for OPTION_COUNTUP
René Scharfe [Wed, 9 Jul 2025 09:46:28 +0000 (11:46 +0200)] 
parse-options: add precision handling for OPTION_COUNTUP

Similar to 09705696f7 (parse-options: introduce precision handling for
`OPTION_INTEGER`, 2025-04-17) support value variables of different sizes
for OPTION_COUNTUP.  Do that by requiring their "precision" to be set,
casting their "value" pointer accordingly and checking whether the value
fits.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoparse-options: add precision handling for OPTION_BITOP
René Scharfe [Wed, 9 Jul 2025 09:46:20 +0000 (11:46 +0200)] 
parse-options: add precision handling for OPTION_BITOP

Similar to 09705696f7 (parse-options: introduce precision handling for
`OPTION_INTEGER`, 2025-04-17) support value variables of different sizes
for OPTION_BITOP.  Do that by requiring their "precision" to be set,
casting their "value" pointer accordingly and checking whether the value
fits.

Check if "devfal" fits into an integer variable with the given
"precision", but don't check "extra", as its value is only used to clear
bits, so cannot lead to an overflow.  Not checking continues to allow
e.g., using -1 to clear all bits even if the value variable has a
narrower type than intptr_t.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoparse-options: add precision handling for OPTION_NEGBIT
René Scharfe [Wed, 9 Jul 2025 09:45:53 +0000 (11:45 +0200)] 
parse-options: add precision handling for OPTION_NEGBIT

Similar to 09705696f7 (parse-options: introduce precision handling for
`OPTION_INTEGER`, 2025-04-17) support value variables of different sizes
for OPTION_NEGBIT.  Do that by requiring their "precision" to be set,
casting their "value" pointer accordingly and checking whether the value
fits.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoparse-options: add precision handling for OPTION_BIT
René Scharfe [Wed, 9 Jul 2025 09:45:33 +0000 (11:45 +0200)] 
parse-options: add precision handling for OPTION_BIT

Similar to 09705696f7 (parse-options: introduce precision handling for
`OPTION_INTEGER`, 2025-04-17) support value variables of different sizes
for OPTION_BIT.  Do that by requiring their "precision" to be set,
casting their "value" pointer accordingly and checking whether the value
fits.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoparse-options: add precision handling for OPTION_SET_INT
René Scharfe [Wed, 9 Jul 2025 09:45:24 +0000 (11:45 +0200)] 
parse-options: add precision handling for OPTION_SET_INT

Similar to 09705696f7 (parse-options: introduce precision handling for
`OPTION_INTEGER`, 2025-04-17) support value variables of different sizes
for OPTION_SET_INT.  Do that by requiring their "precision" to be set,
casting their "value" pointer accordingly and checking whether the value
fits.

Factor out the casting code from the part of do_get_value() that handles
OPTION_INTEGER to avoid code duplication.  We're going to use it in the
next patches as well.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoparse-options: add precision handling for PARSE_OPT_CMDMODE
René Scharfe [Wed, 9 Jul 2025 09:45:14 +0000 (11:45 +0200)] 
parse-options: add precision handling for PARSE_OPT_CMDMODE

Build on 09705696f7 (parse-options: introduce precision handling for
`OPTION_INTEGER`, 2025-04-17) to support value variables of different
sizes for PARSE_OPT_CMDMODE options.  Do that by requiring their
"precision" to be set and casting their "value" pointer accordingly.

Call the function that does the raw casting do_get_int_value() to
reserve the name get_int_value() for a more friendly wrapper we're
going to introduce in one of the next patches.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoparse-options: require PARSE_OPT_NOARG for OPTION_BITOP
René Scharfe [Wed, 9 Jul 2025 09:44:09 +0000 (11:44 +0200)] 
parse-options: require PARSE_OPT_NOARG for OPTION_BITOP

OPTION_BITOP options don't take arguments.  Make sure they are declared
that way using the flag PARSE_OPT_NOARG.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agomeson: fix lookup of shell on MINGW64
Patrick Steinhardt [Wed, 9 Jul 2025 06:23:39 +0000 (08:23 +0200)] 
meson: fix lookup of shell on MINGW64

In 4cba20fbdc6 (meson: prefer shell at "/bin/sh", 2025-04-25) we have
addressed an issue where the shell path embedded into Git was looked up
via PATH, which easily led to unportable shell paths other than the
usual "/bin/sh" location. The fix was to simply add '/bin' to the search
path explicitly, which made us prefer that directory over the PATH-based
lookup.

This fix causes issues on MINGW64 though, which uses Windows-style
paths. "/bin" is not an absolute Windows-style path, but Meson expects
the directories to be absolute. This leads to the following error:

    meson.build:248:15: ERROR: Search directory /bin is not an absolute path.

Fix this by instead searching for both '/bin/sh' and 'sh', which also
causes us to prefer '/bin/sh' over a PATH-based lookup. Meson does
accept that path alright on MINGW64, even though it's not an absolute
Windows-style path, either.

Furthermore, this continues to work alright with cross-files, as well,
in case one wants to explicitly override the shell path:

    $ meson setup build
    ...
      Runtime executable paths
        perl       : /nix/store/gy10hw004rl2xfbfq41vnw0yb1w8rvbl-perl-5.40.0/bin/perl
        python     : /nix/store/sd81bvmch7njdpwx3lkjslixcbj5mivz-python3-3.13.4/bin/python3
        shell      : /bin/sh

    $ cat >cross.ini <<-EOF
    [binaries]
    sh = '/nix/store/94lg0shvsfc845zy8gnflvpqxxiyijbz-bash-interactive-5.2p37/bin/bash'
    EOF

    $ meson setup build --cross-file=cross.ini --wipe
    ...
      Runtime executable paths
        perl       : /nix/store/gy10hw004rl2xfbfq41vnw0yb1w8rvbl-perl-5.40.0/bin/perl
        python     : /nix/store/sd81bvmch7njdpwx3lkjslixcbj5mivz-python3-3.13.4/bin/python3
        shell      : /nix/store/94lg0shvsfc845zy8gnflvpqxxiyijbz-bash-interactive-5.2p37/bin/bash

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agomeson: clean up unnecessary variables
Patrick Steinhardt [Wed, 9 Jul 2025 06:23:38 +0000 (08:23 +0200)] 
meson: clean up unnecessary variables

The `manpage_target` variable isn't used at all, and the `manpage_path`
variable is only used in a single location. Remove the former variable
and inline the latter.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agomeson: improve summary of auto-detected features
Patrick Steinhardt [Wed, 9 Jul 2025 06:23:37 +0000 (08:23 +0200)] 
meson: improve summary of auto-detected features

The summary of auto-detected features prints a boolean for every option
to tell the user whether or not the feature has been auto-enabled or
not. This summary can be improved though, as in some cases this boolean
is derived from a dependency. So if we pass in the dependency directly,
then Meson knows to both print a boolean and, if the dependency was
found, it also prints a version number.

Adapt the code accordingly and enable `bool_yn` so that actual booleans
are formatted similarly to dependencies. Before this change:

  Auto-detected features
    benchmarks      : true
    curl            : true
    expat           : true
    gettext         : true
    gitweb          : true
    iconv           : true
    pcre2           : true
    perl            : true
    python          : true

And after this change, we now see the version numbers as expected:

  Auto-detected features
    benchmarks      : YES
    curl            : YES 8.14.1
    expat           : YES 2.7.1
    gettext         : YES
    gitweb          : YES
    iconv           : YES
    pcre2           : YES 10.44
    perl            : YES
    python          : YES

Note that this change also enables colorization of the boolean options,
green for "YES" and red for "NO".

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agomeson: stop printing 'https' option twice in our summaries
Patrick Steinhardt [Wed, 9 Jul 2025 06:23:36 +0000 (08:23 +0200)] 
meson: stop printing 'https' option twice in our summaries

The value for the 'https' backend option is printed twice: once via the
summary of auto-detected features and once via our summary of backends.
Drop it from the former summary.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agomeson: stop discovering native version of Python
Patrick Steinhardt [Wed, 9 Jul 2025 06:23:35 +0000 (08:23 +0200)] 
meson: stop discovering native version of Python

When Python features are enabled we search both for a native and
non-native version of Python. This is wrong though: we don't use Python
in our build process, so there is no need to search for it in the first
place.

There is one location where we use the native version of Python, namely
when deciding whether or not we want to wire up git-p4(1). This check is
invalid though, as we shouldn't check for the build host to have Python,
but for the target host.

Fix this invalid check to use the non-native version of Python and stop
searching for a native version of Python altogether.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoremote: detect collisions in remote names
Jeff King [Tue, 8 Jul 2025 22:59:46 +0000 (18:59 -0400)] 
remote: detect collisions in remote names

When two remotes collide in the destinations of their fetch refspecs,
the results can be confusing. For example, in this silly example:

  git config remote.one.url [...]
  git config remote.one.fetch +refs/heads/*:refs/remotes/collide/*
  git config remote.two.url [...]
  git config remote.two.fetch +refs/heads/*:refs/remotes/collide/*
  git fetch --all

we may try to write to the same ref twice (once for each remote we're
fetching). There's also a more subtle version of this. If you have
remotes "outer/inner" and "outer", then the ref "inner/branch" on the
second remote will conflict with just "branch" on the former (they both
want to write to "refs/remotes/outer/inner/branch").

We probably don't want to forbid this kind of overlap completely. While
the results can be confusing, there are legitimate reasons to have
multiple refs write into the same namespace (e.g., if one is a "backup"
of the other that is rarely fetched from).

But it may be worth limiting the porcelain "git remote" command to avoid
this confusion. The example above cannot be done with "git remote",
because it always[1] matches the refspecs to the remote name, and you
can only have one instance of each remote name. But you can still
trigger the more subtle variant like this:

  git remote add outer [...]
  git remote add outer/inner [...]

So let's detect that kind of name collision (in both directions) and
forbid it. You can still do whatever you like by manipulating the config
directly, but this should prevent the most obvious foot-gun.

[1] Almost always. With the --mirror option, the resulting refspec will
    just write into "refs/*"; the remote name does not appear in the ref
    namespace at all.

    Our new "names must not overlap" rule is not necessary for that
    case, but it seems reasonable to enforce it consistently. We already
    require all remote names to be valid in the ref namespace, even
    though we won't ever use them in that context for --mirror remotes.

    Likewise, our new rule doesn't help with overlap here. Any two
    mirror remotes will always overlap (in fact, any mirror remote along
    with any other single one, since refs/remotes/ is a subset of the
    mirrored refs). I'm not sure this is worth worrying about, but if it
    is, we'd want an additional rule like "mirror remotes must be the
    only remote".

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoThe eighth batch
Junio C Hamano [Tue, 8 Jul 2025 22:51:23 +0000 (15:51 -0700)] 
The eighth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoMerge branch 'kn/fetch-push-bulk-ref-update'
Junio C Hamano [Tue, 8 Jul 2025 22:49:19 +0000 (15:49 -0700)] 
Merge branch 'kn/fetch-push-bulk-ref-update'

"git push" and "git fetch" are taught to update refs in batches to
gain performance.

* kn/fetch-push-bulk-ref-update:
  receive-pack: handle reference deletions separately
  refs/files: skip updates with errors in batched updates
  receive-pack: use batched reference updates
  send-pack: fix memory leak around duplicate refs
  fetch: use batched reference updates
  refs: add function to translate errors to strings

3 weeks agoMerge branch 'maint-2.50'
Junio C Hamano [Tue, 8 Jul 2025 22:43:31 +0000 (15:43 -0700)] 
Merge branch 'maint-2.50'

* maint-2.50:
  t: avoid git config syntax from newer releases
  Documentation/RelNotes: use .adoc extension for new security releases

3 weeks agoMerge branch 'maint-2.49' into maint-2.50 maint
Junio C Hamano [Tue, 8 Jul 2025 22:42:33 +0000 (15:42 -0700)] 
Merge branch 'maint-2.49' into maint-2.50

* maint-2.49:
  t: avoid git config syntax from newer releases

3 weeks agoMerge branch 'maint-2.48' into maint-2.49
Junio C Hamano [Tue, 8 Jul 2025 22:42:14 +0000 (15:42 -0700)] 
Merge branch 'maint-2.48' into maint-2.49

* maint-2.48:
  t: avoid git config syntax from newer releases

3 weeks agoMerge branch 'maint-2.47' into maint-2.48
Junio C Hamano [Tue, 8 Jul 2025 22:42:02 +0000 (15:42 -0700)] 
Merge branch 'maint-2.47' into maint-2.48

* maint-2.47:
  t: avoid git config syntax from newer releases

3 weeks agoMerge branch 'maint-2.46' into maint-2.47
Junio C Hamano [Tue, 8 Jul 2025 22:41:51 +0000 (15:41 -0700)] 
Merge branch 'maint-2.46' into maint-2.47

* maint-2.46:
  t: avoid git config syntax from newer releases

3 weeks agoMerge branch 'maint-2.45' into maint-2.46
Junio C Hamano [Tue, 8 Jul 2025 22:40:52 +0000 (15:40 -0700)] 
Merge branch 'maint-2.45' into maint-2.46

This turns into a no-op merge, since more recent versions of Git
newer than 2.46 track do support the newer "git config" syntax.

* maint-2.45:
  t: avoid git config syntax from newer releases

3 weeks agoMerge branch 'maint-2.44' into maint-2.45
Junio C Hamano [Tue, 8 Jul 2025 22:35:35 +0000 (15:35 -0700)] 
Merge branch 'maint-2.44' into maint-2.45

* maint-2.44:
  t: avoid git config syntax from newer releases

3 weeks agoMerge branch 'maint-2.43' into maint-2.44
Junio C Hamano [Tue, 8 Jul 2025 22:33:02 +0000 (15:33 -0700)] 
Merge branch 'maint-2.43' into maint-2.44

* maint-2.43:
  t: avoid git config syntax from newer releases

3 weeks agoMerge branch 'tz/avoid-newer-config-syntax-in-older-maint-tracks' into maint-2.43
Junio C Hamano [Tue, 8 Jul 2025 22:31:56 +0000 (15:31 -0700)] 
Merge branch 'tz/avoid-newer-config-syntax-in-older-maint-tracks' into maint-2.43

* tz/avoid-newer-config-syntax-in-older-maint-tracks:
  t: avoid git config syntax from newer releases

3 weeks agot: avoid git config syntax from newer releases
Todd Zullinger [Tue, 8 Jul 2025 21:05:27 +0000 (17:05 -0400)] 
t: avoid git config syntax from newer releases

In a recent security release, 05e9cd64ee (config: quote values
containing CR character, 2025-05-19) added calls to `git config get`,
`git config set`, and `git config unset` which are not present on the
maint-2.43 branch.

These subcommands were added in the following commits, released in
git-2.46.0:

  4e51389000 (builtin/config: introduce "get" subcommand, 2024-05-06),
  00bbdde141 (builtin/config: introduce "set" subcommand, 2024-05-06),
  95ea69c67b (builtin/config: introduce "unset" subcommand, 2024-05-06)

Revert to the previous `git config` syntax for older maintenance
branches.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agot1006: fix broken TAP format
Patrick Steinhardt [Tue, 8 Jul 2025 10:18:58 +0000 (12:18 +0200)] 
t1006: fix broken TAP format

When running t1006 via Meson we receive an error about invalid TAP
format:

    $ meson test t1006-cat-file
    1/1 t1006-cat-file        OK              3.86s   420 subtests passed

    stdout: 147: UNKNOWN: c308ae01840d8e620ad554ee5d77fe114dc2d912:path with spaces
    stdout: 159: UNKNOWN: 3625298bf5e7c464a7d0e38ea80c2a5b5904d9a3e5b2b025b67f360e09b68dc7:path with spaces
    ERROR: Unknown TAP output lines for a supported TAP version.
    This is probably a bug in the test; if they are not TAP syntax, prefix them with a #

    Ok:                1
    Fail:              0

While Meson copes with it alright, it's still annoying to see these
errors on every test run.

The root cause of the broken format is a call to grep(1) that gets
executed outside of a test case, which has been added recently via
9fd38038b9c (t1006: update 'run_tests' to test generic object
specifiers, 2025-06-02). This call is done to determine whether a
subsequent test case is expected to succeed or fail, so it makes sense
to have it execute outside of a test case. But whenever we do that, we
must be extra careful to not generate any output that breaks the TAP
format.

Fix the issue by adding '-q' to the command so that it doesn't print
any matching lines.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agorefs/files: remove empty parent dirs when ref creation fails
Patrick Steinhardt [Tue, 8 Jul 2025 10:19:54 +0000 (12:19 +0200)] 
refs/files: remove empty parent dirs when ref creation fails

When creating a new reference in the "files" backend we first create the
directory hierarchy for that reference, then create the lockfile for
that reference, and finally rename the lockfile into place. When the
transaction gets aborted we prune the lockfile, but we don't clean up
the directory hierarchy that we may have created for the lockfile.

In some egde cases this can lead to lots of empty directories being
cluttered in the ".git/refs" directory that really serve no purpose at
all. We know to prune such empty directories when packing refs, but that
only patches over the issue.

Improve this by removing empty parents when cleaning up still-locked
references in `files_transaction_cleanup()`. This function is also
called when preparing or committing the transaction, so this change also
helps when not explicitly aborting the transaction.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agodocs/git-pack-refs: document heuristic used for packing loose refs
Patrick Steinhardt [Tue, 8 Jul 2025 11:23:56 +0000 (13:23 +0200)] 
docs/git-pack-refs: document heuristic used for packing loose refs

The `git pack-refs --auto` flag asks the ref backend to decide for
itself whether or not references need to be repacked. This is done to
ensure that we don't repack in cases where the backend is already in a
good-enough state, which is typically the case for the "reftable"
backend that performs auto-compaction on writes.

As such, we initially only had heuristics in place for the "reftable"
backend. The "files" backend didn't have any heuristics, so we'd repack
loose references every time `git pack-refs --auto` was executed. This
caused excessive repacking with that backend though, which is why we
eventually implemented a heuristic via c3459ae9ef2 (refs/files: use
heuristic to decide whether to repack with `--auto`, 2024-09-04).

The documentation for the `--auto` flag hasn't been updated accordingly
and still claims that we don't have any metrics for the "files" backend.
Update it to reflect the new reality.

Reported-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoMerge branch 'maint-2.49' into maint-2.50
Junio C Hamano [Tue, 8 Jul 2025 20:04:39 +0000 (13:04 -0700)] 
Merge branch 'maint-2.49' into maint-2.50

* maint-2.49:
  Documentation/RelNotes: use .adoc extension for new security releases

3 weeks agoDocumentation/RelNotes: use .adoc extension for new security releases
Taylor Blau [Tue, 8 Jul 2025 18:47:50 +0000 (14:47 -0400)] 
Documentation/RelNotes: use .adoc extension for new security releases

When preparing the latest round of security fixes, we wrote release
notes in v2.43.7, and then successively merged those up through to the
various 'maint' branches.

However, the 2.49 release series is the first to have commit 1f010d6bdf
(doc: use .adoc extension for AsciiDoc files, 2025-01-20). This means
that we should have renamed the new-but-historical release notes from
*.txt to *.adoc during the merge into the 'maint-2.49' branch, but
neglected to do so.

Rename them accordingly to match the convention introduced by
1f010d6bdf. Since the release materials in question here were prepared
before v2.50.0 was tagged, the 'maint' track for that release series is
OK as is.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoMerge branch 'js/fix-open-exec-git'
Johannes Sixt [Tue, 8 Jul 2025 19:22:00 +0000 (21:22 +0200)] 
Merge branch 'js/fix-open-exec-git'

This addresses CVE-2025-46835, Git GUI can create and overwrite a
user's files:

When a user clones an untrusted repository and is tricked into editing
a file located in a maliciously named directory in the repository, then
Git GUI can create and overwrite files for which the user has write
permission.

* js/fix-open-exec-git:
  git-gui: sanitize 'exec' arguments: convert new 'cygpath' calls
  git-gui: do not mistake command arguments as redirection operators
  git-gui: introduce function git_redir for git calls with redirections
  git-gui: pass redirections as separate argument to git_read
  git-gui: pass redirections as separate argument to _open_stdout_stderr
  git-gui: convert git_read*, git_write to be non-variadic
  git-gui: use git_read in githook_read
  git-gui: break out a separate function git_read_nice
  git-gui: remove option --stderr from git_read
  git-gui: sanitize 'exec' arguments: background
  git-gui: sanitize 'exec' arguments: simple cases
  git-gui: treat file names beginning with "|" as relative paths
  git-gui: remove git config --list handling for git < 1.5.3
  git-gui: remove HEAD detachment implementation for git < 1.5.3
  git-gui: remove Tcl 8.4 workaround on 2>@1 redirection

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
3 weeks agoMerge branch 'ml/replace-auto-execok'
Johannes Sixt [Tue, 8 Jul 2025 19:19:28 +0000 (21:19 +0200)] 
Merge branch 'ml/replace-auto-execok'

This addresses CVE-2025-46334, Git GUI malicious command injection on
Windows.

A malicious repository can ship versions of sh.exe or typical textconv
filter programs such as astextplain.  Due to the unfortunate design of
Tcl on Windows, the search path when looking for an executable always
includes the current directory.  The mentioned programs are invoked when
the user selects "Git Bash" or "Browse Files" from the menu.

* ml/replace-auto-execok:
  git-gui: override exec and open only on Windows
  git-gui: sanitize $PATH on all platforms
  git-gui: assure PATH has only absolute elements.
  git-gui: cleanup git-bash menu item
  git-gui: avoid auto_execok in do_windows_shortcut
  git-gui: avoid auto_execok for git-bash menu item
  git-gui: remove unused proc is_shellscript
  git-gui: remove special treatment of Windows from open_cmd_pipe
  git-gui: use only the configured shell
  git-gui: make _shellpath usable on startup
  git-gui: use [is_Windows], not bad _shellpath
  git-gui: _which, only add .exe suffix if not present

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
3 weeks agoMerge branch 'js/fix-open-exec'
Johannes Sixt [Tue, 8 Jul 2025 19:00:34 +0000 (21:00 +0200)] 
Merge branch 'js/fix-open-exec'

This addresses CVE-2025-27613, Gitk can create and truncate a user's
files:

When a user clones an untrusted repository and runs gitk without
additional command arguments, files for which the user has write
permission can be created and truncated. The option "Support per-file
encoding" must have been enabled before in Gitk's Preferences.  This
option is disabled by default.

The same happens when "Show origin of this line" is used in the main
window (regardless of whether "Support per-file encoding" is enabled or
not).

* js/fix-open-exec:
  gitk: sanitize 'open' arguments: revisit recently updated 'open' calls
  gitk: sanitize 'open' arguments: command pipeline
  gitk: collect construction of blameargs into a single conditional
  gitk: sanitize 'open' arguments: simple commands, readable and writable
  gitk: sanitize 'open' arguments: simple commands with redirections
  gitk: sanitize 'open' arguments: simple commands
  gitk: sanitize 'exec' arguments: redirect to process
  gitk: sanitize 'exec' arguments: redirections and background
  gitk: sanitize 'exec' arguments: redirections
  gitk: sanitize 'exec' arguments: 'eval exec'
  gitk: sanitize 'exec' arguments: simple cases
  gitk: have callers of diffcmd supply pipe symbol when necessary
  gitk: treat file names beginning with "|" as relative paths

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
3 weeks agoMerge branch 'ah/fix-open-with-stdin'
Johannes Sixt [Tue, 8 Jul 2025 18:46:24 +0000 (20:46 +0200)] 
Merge branch 'ah/fix-open-with-stdin'

This addresses CVE-2025-27614, Arbitrary command execution with Gitk:

A Git repository can be crafted in such a way that with some social
engineering a user who has cloned the repository can be tricked into
running any script (e.g., Bourne shell, Perl, Python, ...) supplied by
the attacker by invoking `gitk filename`, where `filename` has a
particular structure. The script is run with the privileges of the user.

* ah/fix-open-with-stdin:
  gitk: encode arguments correctly with "open"

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
3 weeks agoSync with Git 2.50.1
Junio C Hamano [Mon, 7 Jul 2025 22:08:10 +0000 (15:08 -0700)] 
Sync with Git 2.50.1

3 weeks agoThe seventh batch
Junio C Hamano [Mon, 7 Jul 2025 21:12:41 +0000 (14:12 -0700)] 
The seventh batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoMerge branch 'cb/ci-freebsd-update-to-14.3'
Junio C Hamano [Mon, 7 Jul 2025 21:12:57 +0000 (14:12 -0700)] 
Merge branch 'cb/ci-freebsd-update-to-14.3'

CI updates.

* cb/ci-freebsd-update-to-14.3:
  ci: update FreeBSD image to 14.3

3 weeks agoMerge branch 'jj/doc-branch-markup-fix'
Junio C Hamano [Mon, 7 Jul 2025 21:12:57 +0000 (14:12 -0700)] 
Merge branch 'jj/doc-branch-markup-fix'

Doc markup fix.

* jj/doc-branch-markup-fix:
  doc: improve formatting in branch section

3 weeks agoMerge branch 'cb/daemon-retry-interrupted-accept'
Junio C Hamano [Mon, 7 Jul 2025 21:12:57 +0000 (14:12 -0700)] 
Merge branch 'cb/daemon-retry-interrupted-accept'

When "git daemon" sees a signal while attempting to accept() a new
client, instead of retrying, it skipped it by mistake, which has
been corrected.

* cb/daemon-retry-interrupted-accept:
  daemon: correctly handle soft accept() errors in service_loop

3 weeks agoMerge branch 'jk/fix-leak-send-pack'
Junio C Hamano [Mon, 7 Jul 2025 21:12:56 +0000 (14:12 -0700)] 
Merge branch 'jk/fix-leak-send-pack'

Leakfix.

* jk/fix-leak-send-pack:
  send-pack: clean-up even when taking an early exit
  send-pack: clean up extra_have oid array

3 weeks agoMerge branch 'cb/daemon-fd-check-fix'
Junio C Hamano [Mon, 7 Jul 2025 21:12:56 +0000 (14:12 -0700)] 
Merge branch 'cb/daemon-fd-check-fix'

Remove unnecessary check from "git daemon" code.

* cb/daemon-fd-check-fix:
  daemon: remove unnecesary restriction for listener fd

3 weeks agoMerge branch 'jk/submodule-remote-lookup-cleanup'
Junio C Hamano [Mon, 7 Jul 2025 21:12:55 +0000 (14:12 -0700)] 
Merge branch 'jk/submodule-remote-lookup-cleanup'

Updating submodules from the upstream did not work well when
submodule's HEAD is detached, which has been improved.

* jk/submodule-remote-lookup-cleanup:
  submodule: look up remotes by URL first
  submodule: move get_default_remote_submodule()
  submodule--helper: improve logic for fallback remote name
  remote: remove the_repository from some functions
  dir: move starts_with_dot(_dot)_slash to dir.h
  remote: fix tear down of struct remote
  remote: remove branch->merge_name and fix branch_release()

3 weeks agodoc: git-log: convert log config to new doc format
Jean-Noël Avila [Mon, 7 Jul 2025 18:53:32 +0000 (18:53 +0000)] 
doc: git-log: convert log config to new doc format

- Use `backticks` for keywords and more complex option
descriptions. The new rendering engine will apply synopsis rules to
these spans.
- Explain possible options in description list instead of in a paragraph.

Signed-off-by: Jean-Noël Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agodoc: git-log: convert diff options to new doc format
Jean-Noël Avila [Mon, 7 Jul 2025 18:53:31 +0000 (18:53 +0000)] 
doc: git-log: convert diff options to new doc format

- Use `backticks` for keywords and more complex option
descriptions. The new rendering engine will apply synopsis rules to
these spans.
- In description lists, put each option on its own line, to make them more
searchable and enable automatic translation of the options.

Signed-off-by: Jean-Noël Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agodoc: git-log: convert pretty formats to new doc format
Jean-Noël Avila [Mon, 7 Jul 2025 18:53:30 +0000 (18:53 +0000)] 
doc: git-log: convert pretty formats to new doc format

- Use _<placeholder>_ instead of <placeholder> in the description
- Use `backticks` for keywords and more complex option
descriptions. The new rendering engine will apply synopsis rules to
these spans.

For all the formats in the form of %(foo), the formatting needs to be
heavier because we not want the parentheses to be rendered as syntax
elements,but as keywords, i.e. we need to circumvent the syntax highlighting
of synopsis.  In this particular case, this requires the heavy escaping of
the parts that contain parentheses with ++.

Signed-off-by: Jean-Noël Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agodoc: git-log: convert pretty options to new doc format
Jean-Noël Avila [Mon, 7 Jul 2025 18:53:29 +0000 (18:53 +0000)] 
doc: git-log: convert pretty options to new doc format

- Use _<placeholder>_ instead of <placeholder> in the description
- Use `backticks` for keywords and more complex option
descriptions. The new rendering engine will apply synopsis rules to
these spans.

Signed-off-by: Jean-Noël Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agodoc: git-log: convert rev list options to new doc format
Jean-Noël Avila [Mon, 7 Jul 2025 18:53:28 +0000 (18:53 +0000)] 
doc: git-log: convert rev list options to new doc format

- Fix some malformed synopis of options
- Use _<placeholder>_ instead of <placeholder> in the description
- Use `backticks` for keywords and more complex option
descriptions. The new rendering engine will apply synopsis rules to
these spans.
- Add the '%' sign to the characters of keywords.

Signed-off-by: Jean-Noël Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agodoc: git-log: convert line range format to new doc format
Jean-Noël Avila [Mon, 7 Jul 2025 18:53:27 +0000 (18:53 +0000)] 
doc: git-log: convert line range format to new doc format

- Use _<placeholder>_ instead of <placeholder> in the description
- Use `backticks` for keywords and more complex option
descriptions. The new rendering engine will apply synopsis rules to
these spans.

Signed-off-by: Jean-Noël Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agodoc: git-log: convert line range options to new doc format
Jean-Noël Avila [Mon, 7 Jul 2025 18:53:26 +0000 (18:53 +0000)] 
doc: git-log: convert line range options to new doc format

  format placeholders in italics and keywords in monospace
- Use _<placeholder>_ instead of <placeholder> in the description
- Use `backticks` for keywords and more complex option
descriptions. The new rendering engine will apply synopsis rules to
these spans.

Signed-off-by: Jean-Noël Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agodoc: git-log convert rev-list-description to new doc format
Jean-Noël Avila [Mon, 7 Jul 2025 18:53:25 +0000 (18:53 +0000)] 
doc: git-log convert rev-list-description to new doc format

Use `backticks` for commit ranges. The new rendering engine will apply
synopsis rules to these spans.

Signed-off-by: Jean-Noël Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agodoc: convert git-log to new documentation format
Jean-Noël Avila [Mon, 7 Jul 2025 18:53:24 +0000 (18:53 +0000)] 
doc: convert git-log to new documentation format

- Switch the synopsis to a synopsis block which will automatically
  format placeholders in italics and keywords in monospace
- Use _<placeholder>_ instead of <placeholder> in the description
- Use `backticks` for keywords and more complex option
descriptions. The new rendering engine will apply synopsis rules to
these spans.

We also transform inline descriptions of possible values of option
--decorate into a list, which is more readable and extensible.

Signed-off-by: Jean-Noël Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agossh signing: don't detach the filename strbuf from key_file tempfile
redoste [Mon, 7 Jul 2025 18:48:51 +0000 (20:48 +0200)] 
ssh signing: don't detach the filename strbuf from key_file tempfile

Detaching the filename string from the tempfile structure used to cause
delete_tempfile() to fail and the temporary file was not cleaned up.

While it's possible to get rid of the allocation and copy from
xstrdup(), it keeps the code symetric with the other branch since
interpolate_path() also allocates and ssh_signing_key_file is freed
in both cases.

The exisiting test was updated to check if the temporary files are
properly deleted. To prevent TMPDIR from leaking into the other tests, a
new subshell is created, however this prevents test_config from working.
The cleanup of the config changed in the subshell is done by
test_unconfig in a call to test_when_finished outside of it.

Helped-by: brian m. carlson <sandals@crustytoothpaste.net>
Helped-by: Patrick Steinhardt <ps@pks.im>
Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: redoste <redoste@redoste.xyz>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agobuiltin/gc: correct total_ram calculation with HAVE_BSD_SYSCTL
Carlo Marcelo Arenas Belón [Mon, 7 Jul 2025 16:45:18 +0000 (09:45 -0700)] 
builtin/gc: correct total_ram calculation with HAVE_BSD_SYSCTL

The calls to sysctl() assume a 64-bit memory size for the variable
holding the value, but the actual size depends on the key name and
platform, at least for HW_PHYSMEM.

Detect any mismatched reads, and retry with a shorter variable
when needed.

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agot5333: fix missing terminator for sed(1) 's' command
Patrick Steinhardt [Mon, 7 Jul 2025 11:08:34 +0000 (13:08 +0200)] 
t5333: fix missing terminator for sed(1) 's' command

In 6aec8d38fdd (t: refactor tests depending on Perl to print data,
2025-04-03) we have changed some of the tests in t4150 to use sed(1)
instead of Perl. One of the conversions is broken though:

    sed: -e expression #1, char 41: unterminated `s' command

Curiously enough, the test itself still passes. This is caused by a
sequence of failures:

  1. The output of sed(1) is piped into git-update-ref(1), and because
     sed(1) is the upstream command we don't notice that it fails.

  2. git-update-ref(1) does not receive any input and thus won't create
     any references.

  3. We then repack the repository with the configured pseudo merges
     pattern, but as we didn't create any references the pattern doesn't
     match anything.

  4. We use `test_pseudo_merges()` to compute the list of pseudo-merges
     and write it into a file. This file is empty as there are none.

  5. The loop over the pseudo-merges becomes a no-op.

  6. The final test succeeds as well because the number of lines in an
     empty file is obviously the same as the number of unique lines,
     namely zero.

Fix the issue by adding the terminating '|' to the sed(1) command.
Furthermore, make the test a tiny bit more robust by not using it as
part of a pipe.

Reported-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agot4150: fix warning printed by awk due to escaped '\@'
Patrick Steinhardt [Mon, 7 Jul 2025 11:08:33 +0000 (13:08 +0200)] 
t4150: fix warning printed by awk due to escaped '\@'

In 6aec8d38fdd (t: refactor tests depending on Perl to print data,
2025-04-03) we have changed one of the tests in t4150 to use awk(1)
instead of Perl. The test works, but at least gawk(1) prints a warning
now:

    awk: cmd. line:3: warning: escape sequence `\@' treated as plain `@'

Fix this by removing the backslash.

Reported-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agodocs: correct ORIG_HEAD example in "git merge" documentation
Timur Sultanaev [Sat, 5 Jul 2025 17:39:18 +0000 (17:39 +0000)] 
docs: correct ORIG_HEAD example in "git merge" documentation

Documentation for git-merge incorrectly notes that
tip of the current branch on ascii diagram is C,
while it is actually G (current branch is master,
HEAD on diagram is G).

Additionally diagrams on the page are adjusted
to use spaces instead of tabs, so that they align
regardless of tab size. This is in line with
diagrams on other git documentation pages.

Signed-off-by: Timur Sultanaev <str.write@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agobuild: fix FreeBSD build when sysinfo compat library installed
Ramsay Jones [Fri, 4 Jul 2025 22:23:11 +0000 (23:23 +0100)] 
build: fix FreeBSD build when sysinfo compat library installed

Commit 50dec7c566 ("config.mak.uname: add sysinfo() configuration for
cygwin", 2025-04-17) and later commit 187ce0222f ("configure.ac: upgrade
to a compilation check for sysinfo", 2025-05-19) added a 'sysinfo()'
check to the autoconf build.

The FreeBSD system has an optional sysinfo compatibility library, used
to assist in porting software, which causes the build to fail when it
is installed. The reason for the failure is the lack of '-lsysinfo'
during the linking step.

Several solutions were considered:

  - add a 'linking' check to configure.ac in order to determine the
    need to link a separate library (-lsysinfo). (This would require
    a similar change to meson.build).

  - change the order of the preprocessor conditionals in the total_ram()
    function in 'builtin/gc.c', so that the *BSD sysctl() function
    (in the HAVE_BSD_SYSCTL block) takes priority over the sysinfo()
    function (in the HAVE_SYSINFO block).

  - suppress the setting of HAVE_SYSINFO when HAVE_BSD_SYSCTL has been
    defined (in both configure.ac and meson.build).

The first solution above, while simple, adds unnecessary code (the
sysinfo compat function is likely implemented using sysctl() anyway)
when git is happy to use sysctl() on *BSD systems.

The second solution would only be required by the autoconf and meson
build systems, the Makefile already sets the build variables to the
required values (since they are not 'auto-detected').

Here we opt for the final solution above, since it only requires that
we prioritise the 'auto-detected' build variables in the autoconf and
meson builds.

In order to fix the FreeBSD build, move the sysinfo() check after the
determination of the HAVE_BSD_SYSCTL build variable, suppressing the
setting of HAVE_SYSINFO if HAVE_BSD_SYSCTL is defined. Apply this logic
to both the configure.ac and meson.build file.

[Thanks go to Renato Botelho <garga@FreeBSD.org> for testing this patch
on FreeBSD.]

Tested-by: Renato Botelho <garga@FreeBSD.org>
Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agobuiltin/prune: stop depending on 'the_repository'
Ayush Chandekar [Fri, 4 Jul 2025 14:12:35 +0000 (19:42 +0530)] 
builtin/prune: stop depending on 'the_repository'

Refactor builtin/prune.c to remove the dependency on the global
'the_repository'. Replace all the occurrences of 'the_repository' with
repo and thus remove the definition '#define
USE_THE_REPOSITORY_VARIABLE'. Also, add a test to make sure that 'git
prune -h' can be called when the repository is `NULL`.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>
Signed-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agorepository: move 'repository_format_precious_objects' to repo scope
Ayush Chandekar [Fri, 4 Jul 2025 14:12:34 +0000 (19:42 +0530)] 
repository: move 'repository_format_precious_objects' to repo scope

The 'extensions.preciousObjects' setting when set true, prevents
operations that might drop objects from the object storage. This setting
is populated in the global variable
'repository_format_precious_objects'.

Move this global variable to repo scope by adding it to 'struct
repository and also refactor all the occurences accordingly.

This change is part of an ongoing effort to eliminate global variables,
improve modularity and help libify the codebase.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>
Signed-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agou-string-list: move "remove duplicates" test to "u-string-list.c"
shejialuo [Sun, 29 Jun 2025 04:28:41 +0000 (12:28 +0800)] 
u-string-list: move "remove duplicates" test to "u-string-list.c"

We use "test-tool string-list remove_duplicates" to test the
"string_list_remove_duplicates" function. As we have introduced the unit
test, we'd better remove the logic from shell script to C program to
improve test speed and readability.

As all the tests in shell script are removed, let's just delete the
"t0063-string-list.sh" and update the "meson.build" file to align with
this change.

Also we could simply remove "DISABLE_SIGN_COMPARE_WARNINGS" due to we
have already deleted related code.

Unfortunately, we cannot totally remove "test-string-list.c" due to that
we would test the performance of sorting about string list by executing
"test-tool string-list sort" in "p0071-sort.sh".

Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agou-string-list: move "filter string" test to "u-string-list.c"
shejialuo [Sun, 29 Jun 2025 04:28:32 +0000 (12:28 +0800)] 
u-string-list: move "filter string" test to "u-string-list.c"

We use "test-tool string-list filter" to test the "filter_string_list"
function. As we have introduced the unit test, we'd better remove the
logic from shell script to C program to improve test speed and
readability.

Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agou-string-list: move "test_split_in_place" to "u-string-list.c"
shejialuo [Sun, 29 Jun 2025 04:28:23 +0000 (12:28 +0800)] 
u-string-list: move "test_split_in_place" to "u-string-list.c"

We use "test-tool string-list split_in_place" to test the
"string_list_split_in_place" function. As we have introduced the unit
test, we'd better remove the logic from shell script to C program to
improve test speed and readability.

Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agou-string-list: move "test_split" into "u-string-list.c"
shejialuo [Sun, 29 Jun 2025 04:28:14 +0000 (12:28 +0800)] 
u-string-list: move "test_split" into "u-string-list.c"

We rely on "test-tool string-list" command to test the functionality of
the "string-list". However, as we have introduced clar test framework,
we'd better move the shell script into C program to improve speed and
readability.

Create a new file "u-string-list.c" under "t/unit-tests", then update
the Makefile and "meson.build" to build the file. And let's first move
"test_split" into unit test and gradually convert the shell script into
C program.

In order to create `string_list` easily by simply specifying strings in
the function call, create "t_vcreate_string_list_dup" function to do
this.

Then port the shell script tests to C program and remove unused
"test-tool" code and tests.

Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agostring-list: enable sign compare warnings check
shejialuo [Sun, 29 Jun 2025 04:28:06 +0000 (12:28 +0800)] 
string-list: enable sign compare warnings check

In "add_entry", we call "get_entry_index" function to get the inserted
position. However, as the return type of "get_entry_index" function is
`int`, there is a sign compare warning when comparing the `index` with
the `list-nr` of unsigned type.

"get_entry_index" would always return unsigned index. However, the
current binary search algorithm initializes "left" to be "-1", which
necessitates the use of signed `int` return type.

The reason why we need to assign "left" to be "-1" is that in the
`while` loop, we increment "left" by 1 to determine whether the loop
should end. This design choice, while functional, forces us to use
signed arithmetic throughout the function.

To resolve this sign comparison issue, let's modify the binary search
algorithm with the following approach:

1. Initialize "left" to 0 instead of -1
2. Use `left < right` as the loop termination condition instead of
   `left + 1 < right`
3. When searching the right part, set `left = middle + 1` instead of
   `middle`

Then, we could delete "#define DISABLE_SIGN_COMPARE_WARNING" to enable
sign warnings check for "string-list".

Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agostring-list: return index directly when inserting an existing element
shejialuo [Sun, 29 Jun 2025 04:27:57 +0000 (12:27 +0800)] 
string-list: return index directly when inserting an existing element

When inserting an existing element, "add_entry" would convert "index"
value to "-1-index" to indicate the caller that this element is in the
list already. However, in "string_list_insert", we would simply convert
this to the original positive index without any further action.

In 8fd2cb4069 (Extract helper bits from c-merge-recursive work,
2006-07-25), we create "path-list.c" and then introduce above code path.

Let's directly return the index as we don't care about whether the
element is in the list by using "add_entry". In the future, if we want
to let "add_entry" tell the caller, we may add "int *exact_match"
parameter to "add_entry" instead of converting the index to negative to
indicate.

Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>