]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
7 months agomeson: stop linking libcurl into all executables
Patrick Steinhardt [Wed, 26 Feb 2025 08:22:16 +0000 (09:22 +0100)] 
meson: stop linking libcurl into all executables

We set up libcurl via the `libgit_dependencies` variable, which gets
propagated into every user of the `libgit` dependency. This is not
necessary though, as most of our executables aren't even supposed to
link against libcurl.

Fix this by only propagating include directories as a libgit dependency
and propagating the full curl dependency via `libgit_curl`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 months agomeson: introduce `libgit_curl` dependency
Patrick Steinhardt [Wed, 26 Feb 2025 08:22:15 +0000 (09:22 +0100)] 
meson: introduce `libgit_curl` dependency

We've got a set of common source files that we use for those executables
that link against libcurl. The setup is somewhat repetitive though.
Simplify it by declaring a `libgit_curl` dependency that bundles all of
it together.

Note that we don't include curl itself as a dependency. This is because
we already pull it in transitively via the libgit dependency, which is
unfortunate because libgit itself shouldn't actually link against curl
in the first place. This will get fixed in the next commit.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 months agomeson: simplify use of the common-main library
Patrick Steinhardt [Wed, 26 Feb 2025 08:22:14 +0000 (09:22 +0100)] 
meson: simplify use of the common-main library

The "common-main.c" file is used by multiple executables. In order to
make it easy to set it up we have created a separate library that these
executables can link against. All of these executables also want to link
against `libgit.a` though, which makes it necessary to specify both of
these as dependencies for every executable.

Simplify this a bit by declaring the library as a source dependency:
instead of creating a static library, we now instead compile the common
set of files into each executable separately.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 months agomeson: inline the static 'git' library
Patrick Steinhardt [Wed, 26 Feb 2025 08:22:13 +0000 (09:22 +0100)] 
meson: inline the static 'git' library

When setting up `libgit.a` we first create the static library itself,
and then declare it as part of a dependency such that compile arguments,
include directories and transitive dependencies get propagated to the
users of that library. As such, the static library isn't expected to be
used by anything but the declared dependency.

Inline the static library so that we don't even use a separate variable
for it. This avoids any kind of confusion that may arise and clarifies
how the library is supposed to be used.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 months agomeson: fix OpenSSL fallback when not explicitly required
Patrick Steinhardt [Wed, 26 Feb 2025 08:22:12 +0000 (09:22 +0100)] 
meson: fix OpenSSL fallback when not explicitly required

When OpenSSL isn't provided by the system we know to fall back to the
subproject wrapper. This is especially helpful on Windows systems, where
you typically don't have OpenSSL available, in order to reduce the
number of required dependencies.

The fallback is broken though when the OpenSSL backend is set to 'auto'
as we end up calling `dependency('openssl', required: false)` in that
case, which implicitly disables falling back to the wrapper.

Fix the issue by re-allowing the fallback in case either OpenSSL is
required or in case the backend is set to 'auto'. While at it, fix
reporting of the backend in case the user asked us to pick no HTTPS
backend at all.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 months agomeson: fix exec path with enabled runtime prefix
Patrick Steinhardt [Wed, 26 Feb 2025 08:22:11 +0000 (09:22 +0100)] 
meson: fix exec path with enabled runtime prefix

When the runtime prefix option is enabled, Git is built such that it
knows to locate its binaries relative to the directory a binary is being
executed from. This requires us to figure out relative paths, which is
handled in `system_prefix()` by trying to strip a couple of well-known
paths.

One of these paths, GIT_EXEC_PATH, is expected to be absolute when
runtime prefixes are enabled, but relative otherwise. And while our
Makefile gets this correctly, in Meson we always wire up the absolute
path, which may result in us not being able to find binaries.

Fix this by conditionally injecting the paths depending on whether or
not the `runtime_prefix` option is enabled.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoMerge branch 'ps/build-meson-fixes' into ps/build-meson-fixes-0130
Junio C Hamano [Thu, 30 Jan 2025 22:33:55 +0000 (14:33 -0800)] 
Merge branch 'ps/build-meson-fixes' into ps/build-meson-fixes-0130

* ps/build-meson-fixes:
  ci: wire up Visual Studio build with Meson
  ci: raise error when Meson generates warnings
  meson: fix compilation with Visual Studio
  meson: make the CSPRNG backend configurable
  meson: wire up fuzzers
  meson: wire up generation of distribution archive
  meson: wire up development environments
  meson: fix dependencies for generated headers
  meson: populate project version via GIT-VERSION-GEN
  GIT-VERSION-GEN: allow running without input and output files
  GIT-VERSION-GEN: simplify computing the dirty marker

8 months agoThe fifth batch
Junio C Hamano [Wed, 29 Jan 2025 21:38:09 +0000 (13:38 -0800)] 
The fifth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoMerge branch 'ps/reflog-migration-with-logall-fix'
Junio C Hamano [Wed, 29 Jan 2025 22:05:10 +0000 (14:05 -0800)] 
Merge branch 'ps/reflog-migration-with-logall-fix'

The "git refs migrate" command did not migrate the reflog for
refs/stash, which is the contents of the stashes, which has been
corrected.

* ps/reflog-migration-with-logall-fix:
  refs: fix migration of reflogs respecting "core.logAllRefUpdates"

8 months agoMerge branch 'am/trace2-with-valueless-true'
Junio C Hamano [Wed, 29 Jan 2025 22:05:10 +0000 (14:05 -0800)] 
Merge branch 'am/trace2-with-valueless-true'

The trace2 code was not prepared to show a configuration variable
that is set to true using the valueless true syntax, which has been
corrected.

* am/trace2-with-valueless-true:
  trace2: prevent segfault on config collection with valueless true

8 months agoMerge branch 'kn/reflog-symref-fix'
Junio C Hamano [Wed, 29 Jan 2025 22:05:09 +0000 (14:05 -0800)] 
Merge branch 'kn/reflog-symref-fix'

reflog entries for symbolic ref updates were broken, which has been
corrected.

* kn/reflog-symref-fix:
  refs: fix creation of reflog entries for symrefs

8 months agoMerge branch 'rs/ref-fitler-used-atoms-value-fix'
Junio C Hamano [Wed, 29 Jan 2025 22:05:09 +0000 (14:05 -0800)] 
Merge branch 'rs/ref-fitler-used-atoms-value-fix'

"git branch --sort=..." and "git for-each-ref --format=... --sort=..."
did not work as expected with some atoms, which has been corrected.

* rs/ref-fitler-used-atoms-value-fix:
  ref-filter: remove ref_format_clear()
  ref-filter: move is-base tip to used_atom
  ref-filter: move ahead-behind bases into used_atom

8 months agoMerge branch 'ja/doc-commit-markup-updates'
Junio C Hamano [Wed, 29 Jan 2025 22:05:09 +0000 (14:05 -0800)] 
Merge branch 'ja/doc-commit-markup-updates'

Doc updates.

* ja/doc-commit-markup-updates:
  doc: migrate git-commit manpage secondary files to new format
  doc: convert git commit config to new format
  doc: make more direct explanations in git commit options
  doc: the mode param of -u of git commit is optional
  doc: apply new documentation guidelines to git commit

8 months agoMerge branch 'ds/path-walk-1'
Junio C Hamano [Wed, 29 Jan 2025 22:05:08 +0000 (14:05 -0800)] 
Merge branch 'ds/path-walk-1'

Introduce a new API to visit objects in batches based on a common
path, or by type.

* ds/path-walk-1:
  path-walk: drop redundant parse_tree() call
  path-walk: reorder object visits
  path-walk: mark trees and blobs as UNINTERESTING
  path-walk: visit tags and cached objects
  path-walk: allow consumer to specify object types
  t6601: add helper for testing path-walk API
  test-lib-functions: add test_cmp_sorted
  path-walk: introduce an object walk by path

8 months agoThe fourth batch
Junio C Hamano [Tue, 28 Jan 2025 21:01:59 +0000 (13:01 -0800)] 
The fourth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoMerge branch 'jp/t8002-printf-fix'
Junio C Hamano [Tue, 28 Jan 2025 21:02:24 +0000 (13:02 -0800)] 
Merge branch 'jp/t8002-printf-fix'

Test fix.

* jp/t8002-printf-fix:
  t8002: fix ambiguous printf conversion specifications

8 months agoMerge branch 'ps/reftable-sign-compare'
Junio C Hamano [Tue, 28 Jan 2025 21:02:24 +0000 (13:02 -0800)] 
Merge branch 'ps/reftable-sign-compare'

The reftable/ library code has been made -Wsign-compare clean.

* ps/reftable-sign-compare:
  reftable: address trivial -Wsign-compare warnings
  reftable/blocksource: adjust `read_block()` to return `ssize_t`
  reftable/blocksource: adjust type of the block length
  reftable/block: adjust type of the restart length
  reftable/block: adapt header and footer size to return a `size_t`
  reftable/basics: adjust `hash_size()` to return `uint32_t`
  reftable/basics: adjust `common_prefix_size()` to return `size_t`
  reftable/record: handle overflows when decoding varints
  reftable/record: drop unused `print` function pointer
  meson: stop disabling -Wsign-compare

8 months agoMerge branch 'mh/credential-cache-authtype-request-fix'
Junio C Hamano [Tue, 28 Jan 2025 21:02:24 +0000 (13:02 -0800)] 
Merge branch 'mh/credential-cache-authtype-request-fix'

The "cache" credential back-end did not handle authtype correctly,
which has been corrected.

* mh/credential-cache-authtype-request-fix:
  credential-cache: respect authtype capability

8 months agoMerge branch 'jk/pack-header-parse-alignment-fix'
Junio C Hamano [Tue, 28 Jan 2025 21:02:23 +0000 (13:02 -0800)] 
Merge branch 'jk/pack-header-parse-alignment-fix'

It was possible for "git unpack-objects" and "git index-pack" to
make an unaligned access, which has been corrected.

* jk/pack-header-parse-alignment-fix:
  index-pack, unpack-objects: use skip_prefix to avoid magic number
  index-pack, unpack-objects: use get_be32() for reading pack header
  parse_pack_header_option(): avoid unaligned memory writes
  packfile: factor out --pack_header argument parsing
  bswap.h: squelch potential sparse -Wcast-truncate warnings

8 months agoMerge branch 'ps/build-meson-subtree'
Junio C Hamano [Tue, 28 Jan 2025 21:02:23 +0000 (13:02 -0800)] 
Merge branch 'ps/build-meson-subtree'

The meson-driven build is now aware of "git-subtree" housed in
contrib/subtree hierarchy.

* ps/build-meson-subtree:
  meson: wire up the git-subtree(1) command
  meson: introduce build option for contrib
  contrib/subtree: fix building docs

8 months agoMerge branch 'mh/connect-sign-compare'
Junio C Hamano [Tue, 28 Jan 2025 21:02:23 +0000 (13:02 -0800)] 
Merge branch 'mh/connect-sign-compare'

The code in connect.c has been updated to work around complaints
from -Wsign-compare.

* mh/connect-sign-compare:
  connect: address -Wsign-compare warnings

8 months agoMerge branch 'sk/unit-tests'
Junio C Hamano [Tue, 28 Jan 2025 21:02:22 +0000 (13:02 -0800)] 
Merge branch 'sk/unit-tests'

Move a few more unit tests to the clar test framework.

* sk/unit-tests:
  t/unit-tests: convert reftable tree test to use clar test framework
  t/unit-tests: adapt priority queue test to use clar test framework
  t/unit-tests: convert mem-pool test to use clar test framework
  t/unit-tests: handle dashes in test suite filenames

8 months agoMerge branch 'jc/show-usage-help'
Junio C Hamano [Tue, 28 Jan 2025 21:02:22 +0000 (13:02 -0800)] 
Merge branch 'jc/show-usage-help'

The help text from "git $cmd -h" appear on the standard output for
some $cmd and the standard error for others.  The built-in commands
have been fixed to show them on the standard output consistently.

* jc/show-usage-help:
  builtin: send usage() help text to standard output
  oddballs: send usage() help text to standard output
  builtins: send usage_with_options() help text to standard output
  usage: add show_usage_if_asked()
  parse-options: add show_usage_with_options_if_asked()
  t0012: optionally check that "-h" output goes to stdout

8 months agoThe third batch
Junio C Hamano [Thu, 23 Jan 2025 22:24:50 +0000 (14:24 -0800)] 
The third batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoMerge branch 'jc/cli-doc-option-and-config'
Junio C Hamano [Thu, 23 Jan 2025 23:07:02 +0000 (15:07 -0800)] 
Merge branch 'jc/cli-doc-option-and-config'

Doc update.

* jc/cli-doc-option-and-config:
  gitcli: document that command line trumps config and env

8 months agoMerge branch 'mh/doc-credential-helpers-with-pat'
Junio C Hamano [Thu, 23 Jan 2025 23:07:02 +0000 (15:07 -0800)] 
Merge branch 'mh/doc-credential-helpers-with-pat'

Document that it is insecure to use Personal Access Tokens, which
some hosting providers take as username/password, embedded in URLs.

* mh/doc-credential-helpers-with-pat:
  docs: discuss caching personal access tokens
  docs: list popular credential helpers

8 months agoMerge branch 'ak/instaweb-python-port-binding-fix'
Junio C Hamano [Thu, 23 Jan 2025 23:07:02 +0000 (15:07 -0800)] 
Merge branch 'ak/instaweb-python-port-binding-fix'

The "instaweb" bound only to local IP address without "--local" and
to all addresses with "--local", which was the other way around, when
using Python's http.server class, which has been corrected.

* ak/instaweb-python-port-binding-fix:
  instaweb: fix ip binding for the python http.server

8 months agoMerge branch 'sj/meson-doc-technical-dependency-fix'
Junio C Hamano [Thu, 23 Jan 2025 23:07:01 +0000 (15:07 -0800)] 
Merge branch 'sj/meson-doc-technical-dependency-fix'

The meson build procedure for Documentation/technical/ hierarchy was
missing necessary dependencies, which has been corrected.

* sj/meson-doc-technical-dependency-fix:
  meson: fix missing deps for technical articles

8 months agoMerge branch 'tc/meson-use-our-version-def-h'
Junio C Hamano [Thu, 23 Jan 2025 23:07:01 +0000 (15:07 -0800)] 
Merge branch 'tc/meson-use-our-version-def-h'

The meson build procedure looked for the 'version-def.h' file in a
wrong directory, which has been corrected.

* tc/meson-use-our-version-def-h:
  meson: ensure correct version-def.h is used

8 months agoMerge branch 'en/object-name-with-funny-refname-fix'
Junio C Hamano [Thu, 23 Jan 2025 23:07:01 +0000 (15:07 -0800)] 
Merge branch 'en/object-name-with-funny-refname-fix'

Extended SHA-1 expression parser did not work well when a branch
with an unusual name (e.g. "foo{bar") is involved.

* en/object-name-with-funny-refname-fix:
  object-name: be more strict in parsing describe-like output
  object-name: fix resolution of object names containing curly braces

8 months agotrace2: prevent segfault on config collection with valueless true
Adam Murray [Fri, 10 Jan 2025 07:28:20 +0000 (07:28 +0000)] 
trace2: prevent segfault on config collection with valueless true

When TRACE2 analytics is enabled, a configuration variable set to
"valueless true" causes a segfault.

Steps to Reproduce

    GIT_TRACE2=true GIT_TRACE2_CONFIG_PARAMS=status.*
    git -c status.relativePaths version
    Expected Result
    git version 2.46.0
    Actual Result
    zsh: segmentation fault GIT_TRACE2=true

Add checks to prevent the segfault and instead show that the
variable without value.

Signed-off-by: Adam Murray <ad@canva.com>
Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agorefs: fix creation of reflog entries for symrefs
Karthik Nayak [Thu, 23 Jan 2025 11:29:44 +0000 (12:29 +0100)] 
refs: fix creation of reflog entries for symrefs

The commit 297c09eabb (refs: allow multiple reflog entries for the
same refname, 2024-12-16) added logic to exit early in
`lock_ref_for_update()` after obtaining the required lock. This was
added as a performance optimization on a false assumption that no
further processing was required for reflog-only updates.

However the assumption was wrong.  For a symref's reflog entry, the
update needs to be populated with the old_oid value, but the early
exit skipped this necessary step.

This caused a bug in Git 2.48 in the files backend where target
references of symrefs being updated would create a corrupted reflog
entry for the symref since the old_oid is not populated.

Everything the early exit skipped in the code path is necessary for
both regular and symbolic ref, so eliminate the mistaken
optimization, and also add a test to ensure that such an issue
doesn't arise in the future.

Reported-by: Nika Layzell <nika@thelayzells.com>
Co-authored-by: Jeff King <peff@peff.net>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agopath-walk: drop redundant parse_tree() call
Jeff King [Thu, 23 Jan 2025 00:36:13 +0000 (19:36 -0500)] 
path-walk: drop redundant parse_tree() call

This call to parse_tree() was flagged by Coverity for ignoring the
return value. But if we look a little further up the function, we can
see that there is already a call to parse_tree_gently(), and we'll
return early if that fails. So by this point the tree will always be
parsed, and the call is redundant.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoci: wire up Visual Studio build with Meson
Patrick Steinhardt [Wed, 22 Jan 2025 12:05:54 +0000 (13:05 +0100)] 
ci: wire up Visual Studio build with Meson

Add a new job to GitHub Actions and GitLab CI that builds and tests
Meson-based builds with Visual Studio.

A couple notes:

  - While the build job is mandatory, the test job is marked as "manual"
    on GitLab so that it doesn't run by default. We already have a bunch
    of Windows-based jobs, and the computational overhead that these
    cause is simply out of proportion to run the test suite twice.

    The same isn't true for GitHub as I could not find a way to make a
    subset of jobs manually triggered.

  - We disable Perl. This is because we pick up Perl from Git for
    Windows, which outputs different paths ("/c/" instead of "C:\") than
    what we expect in our tests.

  - We don't use the Git for Windows SDK. Instead, the build only
    depends on Visual Studio, Meson and Git for Windows. All the other
    dependencies like curl, pcre2 and zlib get pulled in and compiled
    automatically by Meson and thus do not have to be provided by the
    system.

  - We open-code "ci/run-test-slice.sh". This is because we only have
    direct access to PowerShell, so we manually implement the logic.
    There is an upstream pull request for the Meson build system [1] to
    implement test slicing in Meson directly.

  - We don't process test artifacts for failed CI jobs. This is done to
    keep down prerequisites to a minimum.

All tests are passing.

[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>
8 months agoci: raise error when Meson generates warnings
Patrick Steinhardt [Wed, 22 Jan 2025 12:05:53 +0000 (13:05 +0100)] 
ci: raise error when Meson generates warnings

Meson prints warnings in several cases, like for example when using a
feature supported by the current version of Meson, but not yet supported
by the minimum required version as declared by the project. These
warnings will not cause the setup to fail by default, which makes it
quite easy to miss them.

Improve this by passing `--fatal-meson-warnings` to `meson setup` so
that our CI jobs will fail on warnings.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agomeson: fix compilation with Visual Studio
Patrick Steinhardt [Wed, 22 Jan 2025 12:05:52 +0000 (13:05 +0100)] 
meson: fix compilation with Visual Studio

The Visual Studio compiler defaults to C89 unless explicitly asked to
use a different version of the C standard. We don't specify any C
standard at all though in our Meson build, and consequently compiling
Git fails:

    ...\git\git-compat-util.h(14): fatal error C1189: #error:  "Required C99 support is in a test phase.  Please see git-compat-util.h for more details."

Fix the issue by specifying the project's C standard. Funny enough,
specifying C99 does not work because apparently, `__STDC_VERSION__` is
not getting defined in that version at all. Instead, we have to specify
C11 as the project's C standard, which is also done in our CMake build
instructions.

We don't want to generally enforce C11 though, as our requiremets only
state that a C99 compiler is required. In fact, we don't even require
plain C99, but rather the GNU variant thereof.

Meson allows us to handle this case rather easily by specifying
"gnu99,c11", which will cause it to fall back to C11 in case GNU C99 is
unsupported. This feature has only been introduced with Meson 1.3.0
though, and we support 0.61.0 and newer. In case we use such an oldish
version though we fall back to requiring GNU99 unconditionally. This
means that Windows essentially requires Meson 1.3.0 and newer when using
Visual Studio, but I doubt that this is ever going to be a real problem.

Tested-by: M Hickford <mirth.hickford@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agomeson: make the CSPRNG backend configurable
Patrick Steinhardt [Wed, 22 Jan 2025 12:05:51 +0000 (13:05 +0100)] 
meson: make the CSPRNG backend configurable

The CSPRNG backend is not configurable in Meson and isn't quite
discoverable, either. Make it configurable and add the actual backend
used to the summary.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agomeson: wire up fuzzers
Patrick Steinhardt [Wed, 22 Jan 2025 12:05:50 +0000 (13:05 +0100)] 
meson: wire up fuzzers

Meson does not yet know to build our fuzzers. Introduce a new build
option "fuzzers" and wire up the fuzzers in case it is enabled. Adapt
our CI jobs so that they build the fuzzers by default.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agomeson: wire up generation of distribution archive
Patrick Steinhardt [Wed, 22 Jan 2025 12:05:49 +0000 (13:05 +0100)] 
meson: wire up generation of distribution archive

Meson knows to generate distribution archives via `meson dist`. In
addition to generating the archive itself, this target also knows to
compile and execute tests from that archive, which helps to ensure that
the result is an adequate drop-in replacement for the versioned project.

While this already works as-is, one omission is that we don't propagate
the commit that this is built from into the resulting archive. This can
be fixed though by adding a distribution script that propagates the
version into the "version" file, which GIT-VERSION-GEN knows to read if
present.

Use GIT-VERSION-GEN to populate that file. As the script is executed in
the build directory, not in the directory where we generate the archive,
we have to use a shell to resolve the "MESON_DIST_ROOT" environment
variable.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agomeson: wire up development environments
Patrick Steinhardt [Wed, 22 Jan 2025 12:05:48 +0000 (13:05 +0100)] 
meson: wire up development environments

The Meson build system is able to wire up development environments. The
intent is to make build artifacts of the project available. This is
typically used to export e.g. paths to linkable libraries, which isn't
all that interesting in our context given that we don't have an official
library interface.

But what we can use this mechanism for is to expose the built Git
executables as well as the build directory. This allows users to play
around with the built Git version in the devenv, and allows them to
execute our test scripts directly with the built distribution.

Wire up this feature, which can then be used via `meson devenv` in the
build directory.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agomeson: fix dependencies for generated headers
Patrick Steinhardt [Wed, 22 Jan 2025 12:05:47 +0000 (13:05 +0100)] 
meson: fix dependencies for generated headers

We generate a couple of headers from our documentation. These headers
are added to the libgit sources, but two of them aren't used by the
library, but instead by our builtins. This can cause parallel builds to
fail because the builtin object may be compiled before the header was
generated.

Fix the issue by adding both "config-list.h" and "hook-list.h" to the
list of builtin sources. While "command-list.h" is generated similarly,
it is used by "help.c" and thus part of the libgit sources indeed.

Reported-by: Evan Martin <evan.martin@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agomeson: populate project version via GIT-VERSION-GEN
Patrick Steinhardt [Wed, 22 Jan 2025 12:05:46 +0000 (13:05 +0100)] 
meson: populate project version via GIT-VERSION-GEN

The Git version for Meson is currently wired up manually. It can thus
grow (and already has grown) stale quite easily, as having multiple
sources of truth is never a good idea. This issue is mostly of cosmetic
nature as we don't use the project version anywhere, and instead use the
GIT-VERSION-GEN script to propagate the correct version into our build.
But it is somewhat puzzling when `meson setup` announces to build an old
Git release.

There are a couple of alternatives for how to solve this:

  - We can keep the version undefined, but this makes Meson output
    "undefined" for the version, as well.

  - We can use GIT-VERSION-GEN to generate the version for us. At the
    point of configuring the project we haven't yet figured out host
    details though, and thus we didn't yet set up the shell environment.
    While not an issue for Unix-based systems, this would be an issue in
    Windows, where the shell typically gets provided via Git for Windows
    and thus requires some special setup.

  - We can pull the default version out of GIT-VERSION-GEN and move it
    into its own file. This likely requires some adjustments for scripts
    that bump the version, but allows Meson to read the version from
    that file trivially.

Pick the second option and use GIT-VERSION-GEN as it gives us the most
accurate version. In order to fix the bootstrapping issue on Windows
systems we simply set the version to 'unknown' in case no shell was
found. As the version is only of cosmetic value this isn't really much
of an issue.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoGIT-VERSION-GEN: allow running without input and output files
Patrick Steinhardt [Wed, 22 Jan 2025 12:05:45 +0000 (13:05 +0100)] 
GIT-VERSION-GEN: allow running without input and output files

The GIT-VERSION-GEN script requires an input file containing formatting
directives to be replaced as well as an output file that will get
overwritten in case the file contents have changed. When computing the
project version for Meson we don't want to have either though:

  - We only want to compute the version without anything else, but don't
    have an input file that would match that exact format. While we
    could of course introduce a new file just for that usecase, it feels
    suboptimal to add another file every time we want to have a slightly
    different format for versioned data.

  - The computed version needs to be read from stdout so that Meson can
    wire it up for the project.

Extend the script to handle both usecases by recognizing `--format=` as
alternative to providing an input path and by writing to stdout in case
no output file was given.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoGIT-VERSION-GEN: simplify computing the dirty marker
Patrick Steinhardt [Wed, 22 Jan 2025 12:05:44 +0000 (13:05 +0100)] 
GIT-VERSION-GEN: simplify computing the dirty marker

The GIT-VERSION-GEN script computes the version that Git is being built
from. When building from a commit with an unclean worktree it knows to
append "-dirty" to that version to indicate that there were custom
changes applied and that it isn't the exact same as that commit.

The dirtiness check is done manually via git-diff-index(1), which is
somewhat puzzling though: we already use git-describe(1) to compute the
version, which also knows to compute dirtiness via the "--dirty" flag.
But digging back in history explains why: the "-dirty" suffix was added
in 31e0b2ca81 (GIT 1.5.4.3, 2008-02-23), and git-describe(1) didn't yet
have support for "--dirty" back then.

Refactor the script to use git-describe(1). Despite being simpler, it
also results in a small speedup:

    Benchmark 1: git describe --dirty --match "v[0-9]*"
      Time (mean ± σ):      12.5 ms ±   0.3 ms    [User: 6.3 ms, System: 8.8 ms]
      Range (min … max):    12.0 ms …  13.5 ms    200 runs

    Benchmark 2: git describe --match "v[0-9]*" HEAD && git update-index -q --refresh && git diff-index --name-only HEAD --
      Time (mean ± σ):      17.9 ms ±   1.1 ms    [User: 8.8 ms, System: 14.4 ms]
      Range (min … max):    17.0 ms …  30.6 ms    148 runs

    Summary
      git describe --dirty --match "v[0-9]*" ran
        1.43 ± 0.09 times faster than git describe --match "v[0-9]*" && git update-index -q --refresh && git diff-index --name-only HEAD --

While the speedup doesn't really matter on Unix-based systems, where
filesystem operations are typically fast, they do matter on Windows
where the commands take a couple hundred milliseconds. A quick and dirty
check on that system shows a speedup from ~800ms to ~400ms.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agorefs: fix migration of reflogs respecting "core.logAllRefUpdates"
Patrick Steinhardt [Wed, 22 Jan 2025 09:48:06 +0000 (10:48 +0100)] 
refs: fix migration of reflogs respecting "core.logAllRefUpdates"

In 246cebe320 (refs: add support for migrating reflogs, 2024-12-16) we
have added support to git-refs(1) to migrate reflogs between reference
backends. It was reported [1] though that not we don't migrate reflogs
for a subset of references, most importantly "refs/stash".

This issue is caused by us still honoring "core.logAllRefUpdates" when
trying to migrate reflogs: we do queue the updates, but depending on the
value of that config we may decide to just skip writing the reflog entry
altogether. And given that:

  - The default for "core.logAllRefUpdates" is to only create reflogs
    for branches, remotes, note refs and "HEAD"

  - "refs/stash" is neither of these ref types.

We end up skipping the reflog creation for that particular reference.

Fix the bug by setting `REF_FORCE_CREATE_REFLOG`, which instructs the
ref backends to create the reflog entry regardless of the config or any
preexisting state.

[1]: <Z5BTQRlsOj1sygun@tapette.crustytoothpaste.net>

Reported-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable: address trivial -Wsign-compare warnings
Patrick Steinhardt [Mon, 20 Jan 2025 16:17:28 +0000 (17:17 +0100)] 
reftable: address trivial -Wsign-compare warnings

Address the last couple of trivial -Wsign-compare warnings in the
reftable library and remove the DISABLE_SIGN_COMPARE_WARNINGS macro that
we have in "reftable/system.h".

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable/blocksource: adjust `read_block()` to return `ssize_t`
Patrick Steinhardt [Mon, 20 Jan 2025 16:17:27 +0000 (17:17 +0100)] 
reftable/blocksource: adjust `read_block()` to return `ssize_t`

The `block_source_read_block()` function and its implementations return
an integer as a result that reflects either the number of bytes read, or
an error. As such its return type, a signed integer, isn't wrong, but it
doesn't give the reader a good hint what it actually returns.

Refactor the function to return an `ssize_t` instead, which is typical
for functions similar to read(3p) and should thus give readers a better
signal what they can expect as a result.

Adjust callers to better handle the returned value to avoid warnings
with -Wsign-compare. One of these callers is `reader_get_block()`, whose
return value is only ever used by its callers to figure out whether or
not the read was successful. So instead of bubbling up the `ssize_t`
there, too, we adapt it to only indicate success or errors.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable/blocksource: adjust type of the block length
Patrick Steinhardt [Mon, 20 Jan 2025 16:17:26 +0000 (17:17 +0100)] 
reftable/blocksource: adjust type of the block length

The block length is used to track the number of bytes available in a
specific block. As such, it is never set to a negative value, but is
still represented by a signed integer.

Adjust the type of the variable to be `size_t`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable/block: adjust type of the restart length
Patrick Steinhardt [Mon, 20 Jan 2025 16:17:25 +0000 (17:17 +0100)] 
reftable/block: adjust type of the restart length

The restart length is tracked as a positive integer even though it
cannot ever be negative. Furthermore, it is effectively capped via the
MAX_RESTARTS variable.

Adjust the type of the variable to be `uint32_t`. While this type is
excessive given that MAX_RESTARTS fits into an `uint16_t`, other places
already use 32 bit integers for restarts, so this type is being more
consistent.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable/block: adapt header and footer size to return a `size_t`
Patrick Steinhardt [Mon, 20 Jan 2025 16:17:24 +0000 (17:17 +0100)] 
reftable/block: adapt header and footer size to return a `size_t`

The functions `header_size()` and `footer_size()` return a positive
integer representing the size of the header and footer, respectively,
dependent on the version of the reftable format. Similar to the
preceding commit, these functions return a signed integer though, which
is nonsensical given that there is no way for these functions to return
negative.

Adapt the functions to return a `size_t` instead to fix a couple of sign
comparison warnings.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable/basics: adjust `hash_size()` to return `uint32_t`
Patrick Steinhardt [Mon, 20 Jan 2025 16:17:23 +0000 (17:17 +0100)] 
reftable/basics: adjust `hash_size()` to return `uint32_t`

The `hash_size()` function returns the number of bytes used by the hash
function. Weirdly enough though, it returns a signed integer for its
size even though the size obviously cannot ever be negative. The only
case where it could be negative is if the function returned an error
when asked for an unknown hash, but we assert(3p) instead.

Adjust the type of `hash_size()` to be `uint32_t` and adapt all places
that use signed integers for the hash size to follow suit. This also
allows us to get rid of a couple asserts that we had which verified that
the size was indeed positive, which further stresses the point that this
refactoring makes sense.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable/basics: adjust `common_prefix_size()` to return `size_t`
Patrick Steinhardt [Mon, 20 Jan 2025 16:17:22 +0000 (17:17 +0100)] 
reftable/basics: adjust `common_prefix_size()` to return `size_t`

The `common_prefix_size()` function computes the length of the common
prefix between two buffers. As such its return value will always be an
unsigned integer, as the length cannot be negative. Regardless of that,
the function returns a signed integer, which is nonsensical and causes a
couple of -Wsign-compare warnings all over the place.

Adjust the function to return a `size_t` instead.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable/record: handle overflows when decoding varints
Patrick Steinhardt [Mon, 20 Jan 2025 16:17:21 +0000 (17:17 +0100)] 
reftable/record: handle overflows when decoding varints

The logic to decode varints isn't able to detect integer overflows: as
long as the buffer still has more data available, and as long as the
current byte has its 0x80 bit set, we'll continue to add up these values
to the result. This will eventually cause the `uint64_t` to overflow, at
which point we'll return an invalid result.

Refactor the function so that it is able to detect such overflows. The
implementation is basically copied from Git's own `decode_varint()`,
which already knows to handle overflows. The only adjustment is that we
also take into account the string view's length in order to not overrun
it. The reftable documentation explicitly notes that those two encoding
schemas are supposed to be the same:

    Varint encoding
    ^^^^^^^^^^^^^^^

    Varint encoding is identical to the ofs-delta encoding method used
    within pack files.

    Decoder works as follows:

    ....
    val = buf[ptr] & 0x7f
    while (buf[ptr] & 0x80) {
      ptr++
      val = ((val + 1) << 7) | (buf[ptr] & 0x7f)
    }
    ....

While at it, refactor `put_var_int()` in the same way by copying over
the implementation of `encode_varint()`. While `put_var_int()` doesn't
have an issue with overflows, it generates warnings with -Wsign-compare.
The implementation of `encode_varint()` doesn't, is battle-tested and at
the same time way simpler than what we currently have.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoreftable/record: drop unused `print` function pointer
Patrick Steinhardt [Mon, 20 Jan 2025 16:17:20 +0000 (17:17 +0100)] 
reftable/record: drop unused `print` function pointer

In 42c424d69d (t/helper: inline printing of reftable records,
2024-08-22) we stopped using the `print` function of the reftable record
vtable and instead moved its implementation into the single user of it.
We didn't remove the function itself from the vtable though. Drop it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agomeson: stop disabling -Wsign-compare
Patrick Steinhardt [Mon, 20 Jan 2025 16:17:19 +0000 (17:17 +0100)] 
meson: stop disabling -Wsign-compare

In 4f9264b0cd (config.mak.dev: drop `-Wno-sign-compare`, 2024-12-06) we
have started an effort to make our codebase compile with -Wsign-compare.
But while we removed the -Wno-sign-compare flag from "config.mak.dev",
we didn't adjust the Meson build instructions in the same way.

Fix this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agot8002: fix ambiguous printf conversion specifications
Jan Palus [Mon, 20 Jan 2025 11:41:06 +0000 (12:41 +0100)] 
t8002: fix ambiguous printf conversion specifications

In e7fb2ca945 (builtin/blame: fix out-of-bounds write with blank
boundary commits, 2025-01-10), we have introduced two new tests that
expect a certain amount of padding. This padding is generated via
printf using the "%0.s" conversion specification. That directive is
ambiguous because it might be interpreted as field width (most shells)
or 0-padding flag for numeric fields (coreutils).

Fix this issue by using "%${N}s" instead, which is already being
used in other tests (i.e. t5300, t0450) and is unambiguous.

Helped-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Jan Palus <jpalus@fastmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoref-filter: remove ref_format_clear()
René Scharfe [Sat, 18 Jan 2025 17:11:59 +0000 (18:11 +0100)] 
ref-filter: remove ref_format_clear()

Now that ref_format_clear() no longer releases any memory we don't need
it anymore.  Remove it and its counterpart, ref_format_init().

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoref-filter: move is-base tip to used_atom
René Scharfe [Sat, 18 Jan 2025 17:11:51 +0000 (18:11 +0100)] 
ref-filter: move is-base tip to used_atom

The string_list "is_base_tips" in struct ref_format stores the
committish part of "is-base:<committish>".  It has the same problems
that its sibling string_list "bases" had.  Fix them the same way as the
previous commit did for the latter, by replacing the string_list with
fields in "used_atom".

Helped-by: Jeff King <peff@peff.net>
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoref-filter: move ahead-behind bases into used_atom
René Scharfe [Sat, 18 Jan 2025 17:11:34 +0000 (18:11 +0100)] 
ref-filter: move ahead-behind bases into used_atom

verify_ref_format() parses a ref-filter format string and stores
recognized items in the static array "used_atom".  For
"ahead-behind:<committish>" it stores the committish part in a
string_list member "bases" of struct ref_format.

ref_sorting_options() also parses bare ref-filter format items and
stores stores recognized ones in "used_atom" as well.  The committish
parts go to a dummy struct ref_format in parse_sorting_atom(), though,
and are leaked and forgotten.

If verify_ref_format() is called before ref_sorting_options(), like in
git for-each-ref, then all works well if the sort key is included in the
format string.  If it isn't then sorting cannot work as the committishes
are missing.

If ref_sorting_options() is called first, like in git branch, then we
have the additional issue that if the sort key is included in the format
string then filter_ahead_behind() can't see its committish, will not
generate any results for it and thus it will be expanded to an empty
string.

Fix those issues by replacing the string_list with a field in used_atom
for storing the committish.  This way it can be shared for handling both
ref-filter format strings and sorting options in the same command.

Reported-by: Ross Goldberg <ross.goldberg@gmail.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoThe second batch
Junio C Hamano [Tue, 21 Jan 2025 16:41:17 +0000 (08:41 -0800)] 
The second batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoMerge branch 'sk/unit-test-hash'
Junio C Hamano [Tue, 21 Jan 2025 16:44:55 +0000 (08:44 -0800)] 
Merge branch 'sk/unit-test-hash'

Test update.

* sk/unit-test-hash:
  t/unit-tests: convert hash to use clar test framework

8 months agoMerge branch 'mh/gitattr-doc-markup-fix'
Junio C Hamano [Tue, 21 Jan 2025 16:44:55 +0000 (08:44 -0800)] 
Merge branch 'mh/gitattr-doc-markup-fix'

Doc markup fix.

* mh/gitattr-doc-markup-fix:
  docs: fix typesetting of merge driver placeholders

8 months agoMerge branch 'dk/zsh-config-completion-fix'
Junio C Hamano [Tue, 21 Jan 2025 16:44:55 +0000 (08:44 -0800)] 
Merge branch 'dk/zsh-config-completion-fix'

Completion script updates for zsh

* dk/zsh-config-completion-fix:
  completion: repair config completion for Zsh

8 months agoMerge branch 'aj/difftool-config-doc-fix'
Junio C Hamano [Tue, 21 Jan 2025 16:44:54 +0000 (08:44 -0800)] 
Merge branch 'aj/difftool-config-doc-fix'

Docfix.

* aj/difftool-config-doc-fix:
  difftool docs: restore correct position of tool list

8 months agoMerge branch 'ps/the-repository'
Junio C Hamano [Tue, 21 Jan 2025 16:44:54 +0000 (08:44 -0800)] 
Merge branch 'ps/the-repository'

More code paths have a repository passed through the callchain,
instead of assuming the primary the_repository object.

* ps/the-repository:
  match-trees: stop using `the_repository`
  graph: stop using `the_repository`
  add-interactive: stop using `the_repository`
  tmp-objdir: stop using `the_repository`
  resolve-undo: stop using `the_repository`
  credential: stop using `the_repository`
  mailinfo: stop using `the_repository`
  diagnose: stop using `the_repository`
  server-info: stop using `the_repository`
  send-pack: stop using `the_repository`
  serve: stop using `the_repository`
  trace: stop using `the_repository`
  pager: stop using `the_repository`
  progress: stop using `the_repository`

8 months agoMerge branch 'jt/fsck-skiplist-parse-fix'
Junio C Hamano [Tue, 21 Jan 2025 16:44:53 +0000 (08:44 -0800)] 
Merge branch 'jt/fsck-skiplist-parse-fix'

A misconfigured "fsck.skiplist" configuration variable was not
diagnosed as an error, which has been corrected.

* jt/fsck-skiplist-parse-fix:
  fsck: reject misconfigured fsck.skipList

8 months agoMerge branch 'ps/reftable-get-random-fix'
Junio C Hamano [Tue, 21 Jan 2025 16:44:53 +0000 (08:44 -0800)] 
Merge branch 'ps/reftable-get-random-fix'

The code to compute "unique" name used git_rand() which can fail or
get stuck; the callsite does not require cryptographic security.
Introduce the "insecure" mode and use it appropriately.

* ps/reftable-get-random-fix:
  reftable/stack: accept insecure random bytes
  wrapper: allow generating insecure random bytes

8 months agoMerge branch 'jk/t7407-use-test-grep'
Junio C Hamano [Tue, 21 Jan 2025 16:44:52 +0000 (08:44 -0800)] 
Merge branch 'jk/t7407-use-test-grep'

Test clean-up.

* jk/t7407-use-test-grep:
  t7407: use test_grep

8 months agoMerge branch 'jk/lsan-race-ignore-false-positive'
Junio C Hamano [Tue, 21 Jan 2025 16:44:52 +0000 (08:44 -0800)] 
Merge branch 'jk/lsan-race-ignore-false-positive'

The code to check LSan results has been simplified and made more
robust.

* jk/lsan-race-ignore-false-positive:
  test-lib: add a few comments to LSan log checking
  test-lib: simplify lsan results check
  test-lib: invert return value of check_test_results_san_file_empty

8 months agoindex-pack, unpack-objects: use skip_prefix to avoid magic number
Jeff King [Sun, 19 Jan 2025 13:25:53 +0000 (08:25 -0500)] 
index-pack, unpack-objects: use skip_prefix to avoid magic number

When parsing --pack_header=, we manually skip 14 bytes to the data.
Let's use skip_prefix() to do this automatically.

Note that we overwrite our pointer to the front of the string, so we
have to add more context to the error message. We could avoid this by
declaring an extra pointer to hold the value, but I think the modified
message is actually preferable; it should give translators a bit more
context.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoindex-pack, unpack-objects: use get_be32() for reading pack header
Jeff King [Sun, 19 Jan 2025 13:25:47 +0000 (08:25 -0500)] 
index-pack, unpack-objects: use get_be32() for reading pack header

Both of these commands read the incoming pack into a static unsigned
char buffer in BSS, and then parse it by casting the start of the buffer
to a struct pack_header. This can result in SIGBUS on some platforms if
the compiler doesn't place the buffer in a position that is properly
aligned for 4-byte integers.

This reportedly happens with unpack-objects (but not index-pack) on
sparc64 when compiled with clang (but not gcc). But we are definitely in
the wrong in both spots; since the buffer's type is unsigned char, we
can't depend on larger alignment. When it works it is only because we
are lucky.

We'll fix this by switching to get_be32() to read the headers (just like
the last few commits similarly switched us to put_be32() for writing
into the same buffer).

It would be nice to factor this out into a common helper function, but
the interface ends up quite awkward. Either the caller needs to hardcode
how many bytes we'll need, or it needs to pass us its fill()/use()
functions as pointers. So I've just fixed both spots in the same way;
this is not code that is likely to be repeated a third time (most of the
pack reading code uses an mmap'd buffer, which should be properly
aligned).

I did make one tweak to the shared code: our pack_version_ok() macro
expects us to pass the big-endian value we'd get by casting. We can
introduce a "native" variant which uses the host integer ordering.

Reported-by: Koakuma <koachan@protonmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agoparse_pack_header_option(): avoid unaligned memory writes
Jeff King [Sun, 19 Jan 2025 13:23:44 +0000 (08:23 -0500)] 
parse_pack_header_option(): avoid unaligned memory writes

In order to recreate a pack header in our in-memory buffer, we cast the
buffer to a "struct pack_header" and assign the individual fields. This
is reported to cause SIGBUS on sparc64 due to alignment issues.

We can work around this by using put_be32() which will write individual
bytes into the buffer.

Reported-by: Koakuma <koachan@protonmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agopackfile: factor out --pack_header argument parsing
Jeff King [Sun, 19 Jan 2025 13:23:37 +0000 (08:23 -0500)] 
packfile: factor out --pack_header argument parsing

Both index-pack and unpack-objects accept a --pack_header argument. This
is an undocumented internal argument used by receive-pack and fetch to
pass along information about the header of the pack, which they've
already read from the incoming stream.

In preparation for a bugfix, let's factor the duplicated code into a
common helper.

The callers are still responsible for identifying the option. While this
could likewise be factored out, it is more flexible this way (e.g., if
they ever started using parse-options and wanted to handle both the
stuck and unstuck forms).

Likewise, the callers are responsible for reporting errors, though they
both just call die(). I've tweaked unpack-objects to match index-pack in
marking the error for translation.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
8 months agobswap.h: squelch potential sparse -Wcast-truncate warnings
Junio C Hamano [Sun, 19 Jan 2025 13:23:08 +0000 (08:23 -0500)] 
bswap.h: squelch potential sparse -Wcast-truncate warnings

In put_be32(), we right-shift a uint32_t value various amounts and then
assign the low 8-bits to individual "unsigned char" bytes, throwing away
the high bits. For shifts smaller than 24 bits, those thrown away bits
will be arbitrary bits from the original uint32_t.

This works exactly as we want, but if you feed a constant, then sparse
complains. For example if we write this (which we plan to do in a future
patch):

  put_be32(hdr, PACK_SIGNATURE);

then "make sparse" produces:

  compat/bswap.h:175:22: error: cast truncates bits from constant value (5041 becomes 41)
  compat/bswap.h:176:22: error: cast truncates bits from constant value (504143 becomes 43)
  compat/bswap.h:177:22: error: cast truncates bits from constant value (5041434b becomes 4b)

And the same issue exists in the other put_be*() functions, when used
with a constant.

We can silence this warning by explicitly masking off the truncated
bits. The compiler is smart enough to know the result is the same, and
the asm generated by gcc (with both -O0 and -O2) is identical.

Curiously this line already exists:

put_be32(&hdr_version, INDEX_EXTENSION_VERSION2);

in the fsmonitor.c file, but it does not get flagged because the CPP
macro expands to a small integer (2).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agot/unit-tests: convert reftable tree test to use clar test framework
Seyi Kuforiji [Fri, 17 Jan 2025 12:29:26 +0000 (13:29 +0100)] 
t/unit-tests: convert reftable tree test to use clar test framework

Adapts reftable tree test script to clar framework by using clar
assertions where necessary.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com>
Acked-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agot/unit-tests: adapt priority queue test to use clar test framework
Seyi Kuforiji [Fri, 17 Jan 2025 12:29:25 +0000 (13:29 +0100)] 
t/unit-tests: adapt priority queue test to use clar test framework

Convert the prio-queue test script to clar framework by using clar
assertions where necessary. Test functions are created as a standalone
to test different cases.

update the type of the variable `j` from int to `size_t`, this ensures
compatibility with the type used for result_size, which is also size_t,
preventing a potential warning or error caused by comparisons between
signed and unsigned integers.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com>
Acked-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agot/unit-tests: convert mem-pool test to use clar test framework
Seyi Kuforiji [Fri, 17 Jan 2025 12:29:24 +0000 (13:29 +0100)] 
t/unit-tests: convert mem-pool test to use clar test framework

Adapt the mem-pool test script to use clar framework by using clar
assertions where necessary.Test functions are created as a standalone to
test different test cases.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com>
Acked-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agot/unit-tests: handle dashes in test suite filenames
Seyi Kuforiji [Fri, 17 Jan 2025 12:29:23 +0000 (13:29 +0100)] 
t/unit-tests: handle dashes in test suite filenames

"generate-clar-decls.sh" script is designed to extract function
signatures that match a specific pattern derived from the unit test
file's name. The script does not know to massage file names with dashes,
which will make it search for functions that look like, for example,
`test_mem-pool_*`. Having dashes in function names is not allowed
though, so these patterns won't ever match a legal function name.

Adapt script to translate dashes (`-`) in test suite filenames to
underscores (`_`) to correctly extract the function signatures and run
the corresponding tests. This will be used by subsequent commits which
follows the same construct.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com>
Acked-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agobuiltin: send usage() help text to standard output
Junio C Hamano [Thu, 16 Jan 2025 21:35:53 +0000 (13:35 -0800)] 
builtin: send usage() help text to standard output

Using the show_usage_and_exit_if_asked() helper we introduced
earlier, fix callers of usage() that want to show the help text when
explicitly asked by the end-user.  The help text now goes to the
standard output stream for them.

These are the bog standard "if we got only '-h', then that is a
request for help" callers.  Their

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

are simply replaced with

show_usage_and_exit_if_asked(argc, argv, message);

With this, the built-ins tested by t0012 all send their help text to
their standard output stream, so the check in t0012 that was half
tightened earlier is now fully tightened to insist on standard error
stream being empty.

Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agooddballs: send usage() help text to standard output
Junio C Hamano [Thu, 16 Jan 2025 21:35:52 +0000 (13:35 -0800)] 
oddballs: send usage() help text to standard output

Using the show_usage_if_asked() helper we introduced earlier, fix
callers of usage() that want to show the help text when explicitly
asked by the end-user.  The help text now goes to the standard
output stream for them.

The callers in this step are oddballs in that their invocations of
usage() are *not* guarded by

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

There are (unnecessarily) being clever ones that do things like

if (argc != 2 || !strcmp(argv[1], "-h")
usage(...);

to say "I know I take only one argument, so argc != 2 is always an
error regardless of what is in argv[].  Ah, by the way, even if argc
is 2, "-h" is a request for usage text, so we do the same".

Some like "git var -h" just do not treat "-h" any specially, and let
it take the same error code paths as a parameter error.

Now we cannot do the same, so these callers are rewrittin to do the
show_usage_and_exit_if_asked() first and then handle the usage error
the way they used to.

Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agobuiltins: send usage_with_options() help text to standard output
Junio C Hamano [Thu, 16 Jan 2025 21:35:51 +0000 (13:35 -0800)] 
builtins: send usage_with_options() help text to standard output

Using the show_usage_with_options_if_asked() helper we introduced
earlier, fix callers of usage_with_options() that want to show the
help text when explicitly asked by the end-user.  The help text now
goes to the standard output stream for them.

The test in t7600 for "git merge -h" may want to be retired, as the
same is covered by t0012 already, but it is specifically testing that
the "-h" option gets a response even with a corrupt index file, so
for now let's leave it there.

Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agousage: add show_usage_if_asked()
Junio C Hamano [Thu, 16 Jan 2025 21:35:50 +0000 (13:35 -0800)] 
usage: add show_usage_if_asked()

Some commands call usage() when they are asked to give the help
message with "git cmd -h", but this has the same problem as we
fixed with callers of usage_with_options() for the same purpose.

Introduce a helper function that captures the common pattern

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

and replaces it with

show_usage_if_asked(argc, argv, usage);

to help correct these 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.

Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoparse-options: add show_usage_with_options_if_asked()
Junio C Hamano [Thu, 16 Jan 2025 21:35:49 +0000 (13:35 -0800)] 
parse-options: add show_usage_with_options_if_asked()

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 && !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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agot0012: optionally check that "-h" output goes to stdout
Jeff King [Thu, 16 Jan 2025 21:35:48 +0000 (13:35 -0800)] 
t0012: optionally check that "-h" output goes to stdout

For most commands, "git foo -h" will send the help output to stdout, as
this is what parse-options.c does. But some commands send it to stderr
instead. This is usually because they call usage_with_options(), and
should be switched to show_usage_help_and_exit_if_asked().

Currently t0012 is permissive and allows either behavior. We'd like it
to eventually enforce that help goes to stdout, and teaching it to do so
identifies the commands that need to be changed. But during the
transition period, we don't want to enforce that for most test runs.

So let's introduce a flag that will let most test runs use the
permissive behavior, and people interested in converting commands can
run:

  GIT_TEST_HELP_MUST_BE_STDOUT=1 ./t0012-help.sh

to see the failures. Eventually (when all builtins have been converted)
we'll remove this flag entirely and always check the strict behavior.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agogitcli: document that command line trumps config and env
Junio C Hamano [Fri, 17 Jan 2025 02:05:13 +0000 (18:05 -0800)] 
gitcli: document that command line trumps config and env

We centrally explain that "--no-whatever" is the way to countermand
the "--whatever" option.  Explain that a configured default and the
value specified by an environment variable can be overridden by the
corresponding command line option, too.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Acked-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agomeson: wire up the git-subtree(1) command
Patrick Steinhardt [Fri, 17 Jan 2025 09:56:07 +0000 (10:56 +0100)] 
meson: wire up the git-subtree(1) command

Wire up the git-subtree(1) command, which is part of "contrib/". Note
that we have to move around the exact location where we include the
"contrib/" subdirectory so that it comes after building the docs so that
we have access to some of the common functionality.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agomeson: introduce build option for contrib
Patrick Steinhardt [Fri, 17 Jan 2025 09:56:06 +0000 (10:56 +0100)] 
meson: introduce build option for contrib

We unconditionally wire up building command completion present in the
"contrib/" directory. This may or may not be what users want, and we
don't provide a way to disable it.

Introduce a new "contrib" build option. This option is introduced as an
array so that users can manually pick which exact features they want to
include from the "contrib" directory. By default, we build and install
shell completions, which is a commonly used feature and also the current
default.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agocontrib/subtree: fix building docs
Patrick Steinhardt [Fri, 17 Jan 2025 09:56:05 +0000 (10:56 +0100)] 
contrib/subtree: fix building docs

In a38edab7c8 (Makefile: generate doc versions via GIT-VERSION-GEN,
2024-12-06), we have refactored how we build our documentation by
injecting the Git version into the Asciidoc and AsciiDoctor config
files instead of doing so via arguments. As such, the original config
files were removed, where the expectation is that they get generated via
`GIT-VERSION-GEN` now.

Whie the git-subtree(1) command part of "contrib/" also builds docs
using these same config files, its Makefile wasn't adjusted accordingly
and thus building the docs is broken.

Fix this by using `GIT-VERSION-GEN` to generate those files.

Reported-by: Renato Botelho <garga@FreeBSD.org>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoconnect: address -Wsign-compare warnings
Mike Hommey [Fri, 17 Jan 2025 07:49:09 +0000 (16:49 +0900)] 
connect: address -Wsign-compare warnings

Most of the warnings were about loop variables being declared as ints
with a condition using a size_t, whereby switching the variable to
size_t fixes the warning.

One other case was comparing the result of strlen to an int passed
as an argument, which turns out could just as well be passed as a
size_t, albeit trickling to other functions.

Signed-off-by: Mike Hommey <mh@glandium.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoThe first batch
Junio C Hamano [Fri, 17 Jan 2025 00:10:42 +0000 (16:10 -0800)] 
The first batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agoMerge branch 'mb/t7110-use-test-path-helper'
Junio C Hamano [Fri, 17 Jan 2025 00:35:14 +0000 (16:35 -0800)] 
Merge branch 'mb/t7110-use-test-path-helper'

Test modernization.

* mb/t7110-use-test-path-helper:
  t7110: replace `test -f` with `test_path_is_*` helpers

9 months agoMerge branch 'ps/meson-weak-sha1-build'
Junio C Hamano [Fri, 17 Jan 2025 00:35:14 +0000 (16:35 -0800)] 
Merge branch 'ps/meson-weak-sha1-build'

meson-based build now supports the unsafe-sha1 build knob.

* ps/meson-weak-sha1-build:
  meson: provide a summary of configured backends
  meson: wire up unsafe SHA1 backend
  meson: add missing dots for build options
  meson: simplify conditions for HTTPS and SHA1 dependencies
  meson: require SecurityFramework when it's used as SHA1 backend
  meson: deduplicate access to SHA1/SHA256 backend options
  meson: consistenlty spell 'CommonCrypto'

9 months agoMerge branch 'ps/more-sign-compare'
Junio C Hamano [Fri, 17 Jan 2025 00:35:14 +0000 (16:35 -0800)] 
Merge branch 'ps/more-sign-compare'

More -Wsign-compare fixes.

* ps/more-sign-compare:
  sign-compare: avoid comparing ptrdiff with an int/unsigned
  commit-reach: use `size_t` to track indices when computing merge bases
  shallow: fix -Wsign-compare warnings
  builtin/log: fix remaining -Wsign-compare warnings
  builtin/log: use `size_t` to track indices
  commit-reach: use `size_t` to track indices in `get_reachable_subset()`
  commit-reach: use `size_t` to track indices in `remove_redundant()`
  commit-reach: fix type of `min_commit_date`
  commit-reach: fix index used to loop through unsigned integer
  prio-queue: fix type of `insertion_ctr`

9 months agoMerge branch 'ps/object-collision-check'
Junio C Hamano [Fri, 17 Jan 2025 00:35:13 +0000 (16:35 -0800)] 
Merge branch 'ps/object-collision-check'

CI jobs gave sporadic failures, which turns out that that the
object finalization code was giving an error when it did not have
to.

* ps/object-collision-check:
  object-file: retry linking file into place when occluding file vanishes
  object-file: don't special-case missing source file in collision check
  object-file: rename variables in `check_collision()`
  object-file: fix race in object collision check

9 months agoMerge branch 'as/long-option-help-i18n'
Junio C Hamano [Fri, 17 Jan 2025 00:35:13 +0000 (16:35 -0800)] 
Merge branch 'as/long-option-help-i18n'

Tweak the help text used for the option value placeholders by
parse-options API so that translations can customize the "<>"
placeholder signal (e.g. "--option=<value>").

* as/long-option-help-i18n:
  parse-options: localize mark-up of placeholder text in the short help

9 months agoMerge branch 're/submodule-parse-opt'
Junio C Hamano [Fri, 17 Jan 2025 00:35:13 +0000 (16:35 -0800)] 
Merge branch 're/submodule-parse-opt'

"git submodule" learned various ways to spell the same option,
e.g. "--branch=B" can be spelled "--branch B" or "-bB".

* re/submodule-parse-opt:
  git-submodule.sh: rename some variables
  git-submodule.sh: improve variables readability
  git-submodule.sh: add some comments
  git-submodule.sh: get rid of unused variable
  git-submodule.sh: get rid of isnumber
  git-submodule.sh: improve parsing of short options
  git-submodule.sh: improve parsing of some long options

9 months agodoc: migrate git-commit manpage secondary files to new format
Jean-Noël Avila [Wed, 15 Jan 2025 20:23:48 +0000 (20:23 +0000)] 
doc: migrate git-commit manpage secondary files to new format

Signed-off-by: Jean-Noël Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agodoc: convert git commit config to new format
Jean-Noël Avila [Wed, 15 Jan 2025 20:23:47 +0000 (20:23 +0000)] 
doc: convert git commit config to new format

Also prevent git-commit manpage to refer to itself in the config
description by using a variable.

Signed-off-by: Jean-Noël Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agodoc: make more direct explanations in git commit options
Jean-Noël Avila [Wed, 15 Jan 2025 20:23:46 +0000 (20:23 +0000)] 
doc: make more direct explanations in git commit options

- Use imperative mood
- make use of the placeholder format to simplify style

Signed-off-by: Jean-Noël Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
9 months agodoc: the mode param of -u of git commit is optional
Jean-Noël Avila [Wed, 15 Jan 2025 20:23:45 +0000 (20:23 +0000)] 
doc: the mode param of -u of git commit is optional

Fix the synopsis to reflect the option description.

Signed-off-by: Jean-Noël Avila <jn.avila@free.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>