]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
4 months agoreftable/basics: introduce `REFTABLE_UNUSED` annotation
Patrick Steinhardt [Tue, 18 Feb 2025 09:20:50 +0000 (10:20 +0100)] 
reftable/basics: introduce `REFTABLE_UNUSED` annotation

Introduce the `REFTABLE_UNUSED` annotation and replace all existing
users of `UNUSED` in the reftable library to use the new macro instead.

Note that we unconditionally define `MAYBE_UNUSED` in the exact same
way, so doing so unconditionally for `REFTABLE_UNUSED` should be fine,
too.

Suggested-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/basics: stop using `SWAP()` macro
Patrick Steinhardt [Tue, 18 Feb 2025 09:20:49 +0000 (10:20 +0100)] 
reftable/basics: stop using `SWAP()` macro

Stop using `SWAP()` macro in favor of an open-coded variant of it. Note
that this also requires us to open-code the build assert that `SWAP()`
itself uses to verify that the size of both variables matches.

This is done to reduce our dependency on the Git codebase.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/stack: stop using `sleep_millisec()`
Patrick Steinhardt [Tue, 18 Feb 2025 09:20:48 +0000 (10:20 +0100)] 
reftable/stack: stop using `sleep_millisec()`

Refactor our use of `sleep_millisec()` by open-coding it with poll(3p),
which is the current implementation of this function. Ideally, we'd use
a more direct way to sleep, but there is no equivalent to sleep(3p) that
would accept milliseconds as input.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/system: introduce `reftable_rand()`
Patrick Steinhardt [Tue, 18 Feb 2025 09:20:47 +0000 (10:20 +0100)] 
reftable/system: introduce `reftable_rand()`

Introduce a new system-level `reftable_rand()` function that generates a
single unsigned integer for us. The implementation of this function is
to be provided by the calling codebase, which allows us to more easily
hook into pre-seeded random number generators.

Adapt the two callsites where we generated random data.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/reader: stop using `ARRAY_SIZE()` macro
Patrick Steinhardt [Tue, 18 Feb 2025 09:20:46 +0000 (10:20 +0100)] 
reftable/reader: stop using `ARRAY_SIZE()` macro

We have a single user of the `ARRAY_SIZE()` macro in the reftable
reader. Drop its use to reduce our dependence on the Git codebase.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/basics: provide wrappers for big endian conversion
Patrick Steinhardt [Tue, 18 Feb 2025 09:20:45 +0000 (10:20 +0100)] 
reftable/basics: provide wrappers for big endian conversion

We're using a mixture of big endian conversion functions provided by
both the reftable library, but also by the Git codebase. Refactor the
code so that we exclusively use reftable-provided wrappers in order to
untangle us from the Git codebase.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/basics: stop using `st_mult()` in array allocators
Patrick Steinhardt [Tue, 18 Feb 2025 09:20:44 +0000 (10:20 +0100)] 
reftable/basics: stop using `st_mult()` in array allocators

We're using `st_mult()` as part of our macro helpers that allocate
arrays. This is bad due two two reasons:

  - `st_mult()` causes us to die in case the multiplication overflows.

  - `st_mult()` ties us to the Git codebase.

Refactor the code to instead detect overflows manually and return an
error in such cases.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable: stop using `BUG()` in trivial cases
Patrick Steinhardt [Tue, 18 Feb 2025 09:20:43 +0000 (10:20 +0100)] 
reftable: stop using `BUG()` in trivial cases

Stop using `BUG()` in the remaining trivial cases that we still have in
the reftable library. Instead of aborting the program, we'll now bubble
up a `REFTABLE_API_ERROR` to indicate misuse of the calling conventions.

Note that in both `reftable_reader_{inc,dec}ref()` we simply stop
calling `BUG()` altogether. The only situation where the counter should
be zero is when the structure has already been free'd anyway, so we
would run into undefined behaviour regardless of whether we try to abort
the program or not.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/record: don't `BUG()` in `reftable_record_cmp()`
Patrick Steinhardt [Tue, 18 Feb 2025 09:20:42 +0000 (10:20 +0100)] 
reftable/record: don't `BUG()` in `reftable_record_cmp()`

The reftable library aborts with a bug in case `reftable_record_cmp()`
is invoked with two records of differing types. This would cause the
program to die without the caller being able to handle the error, which
is not something we want in the context of library code. And it ties us
to the Git codebase.

Refactor the code such that `reftable_record_cmp()` returns an error
code separate from the actual comparison result. This requires us to
also adapt some callers up the callchain in a similar fashion.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/record: stop using `BUG()` in `reftable_record_init()`
Patrick Steinhardt [Tue, 18 Feb 2025 09:20:41 +0000 (10:20 +0100)] 
reftable/record: stop using `BUG()` in `reftable_record_init()`

We're aborting the program via `BUG()` in case `reftable_record_init()`
was invoked with an unknown record type. This is bad because we may now
die in library code, and because it makes us depend on the Git codebase.

Refactor the code such that `reftable_record_init()` can return an error
code to the caller. Adapt any callers accordingly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/record: stop using `COPY_ARRAY()`
Patrick Steinhardt [Tue, 18 Feb 2025 09:20:40 +0000 (10:20 +0100)] 
reftable/record: stop using `COPY_ARRAY()`

Drop our use of `COPY_ARRAY()`, replacing it with an open-coded variant
thereof. This is done to reduce our dependency on the Git library.

While at it, guard the whole array copy logic so that we only copy it in
case there actually is anything to be copied. Otherwise, we may end up
trying to allocate a zero-sized array, which will return a NULL pointer
and thus cause us to return an `REFTABLE_OUT_OF_MEMORY_ERROR`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/blocksource: stop using `xmmap()`
Patrick Steinhardt [Tue, 18 Feb 2025 09:20:39 +0000 (10:20 +0100)] 
reftable/blocksource: stop using `xmmap()`

We use `xmmap()` to map reftables into memory. This function has two
problems:

  - It causes us to die in case the mmap fails.

  - It ties us to the Git codebase.

Refactor the code to use mmap(3p) instead with manual error checking.
Note that this function may not be the system-provided mmap(3p), but may
point to our `git_mmap()` wrapper that emulates the syscall on systems
that do not have mmap(3p) available.

Fix `reftable_block_source_from_file()` to properly bubble up the error
code in case the map(3p) call fails.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/stack: stop using `write_in_full()`
Patrick Steinhardt [Tue, 18 Feb 2025 09:20:38 +0000 (10:20 +0100)] 
reftable/stack: stop using `write_in_full()`

Similar to the preceding commit, drop our use of `write_in_full()` and
implement a new wrapper `reftable_write_full()` that handles this logic
for us. This is done to reduce our dependency on the Git library.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoreftable/stack: stop using `read_in_full()`
Patrick Steinhardt [Tue, 18 Feb 2025 09:20:37 +0000 (10:20 +0100)] 
reftable/stack: stop using `read_in_full()`

There is a single callsite of `read_in_full()` in the reftable library.
Open-code the function to reduce our dependency on the Git library.

Note that we only partially port over the logic from `read_in_full()`
and its underlying `xread()` helper. Most importantly, the latter also
knows to handle `EWOULDBLOCK` via `handle_nonblock()`. This logic is
irrelevant for us though because the reftable library never sets the
`O_NONBLOCK` option in the first place.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoThe eleventh batch
Junio C Hamano [Sat, 15 Feb 2025 01:53:32 +0000 (17:53 -0800)] 
The eleventh batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoMerge branch 'ps/doc-http-upload-archive-service'
Junio C Hamano [Sat, 15 Feb 2025 01:53:49 +0000 (17:53 -0800)] 
Merge branch 'ps/doc-http-upload-archive-service'

Doc update.

* ps/doc-http-upload-archive-service:
  doc: documentation for http.uploadarchive config option

4 months agoMerge branch 'kn/reflog-migration-fix-followup'
Junio C Hamano [Sat, 15 Feb 2025 01:53:48 +0000 (17:53 -0800)] 
Merge branch 'kn/reflog-migration-fix-followup'

Code clean-up.

* kn/reflog-migration-fix-followup:
  reftable: prevent 'update_index' changes after adding records
  refs: use 'uint64_t' for 'ref_update.index'
  refs: mark `ref_transaction_update_reflog()` as static

4 months agoMerge branch 'bf/fetch-set-head-fix'
Junio C Hamano [Sat, 15 Feb 2025 01:53:48 +0000 (17:53 -0800)] 
Merge branch 'bf/fetch-set-head-fix'

Fetching into a bare repository incorrectly assumed it always used
a mirror layout when deciding to update remote-tracking HEAD, which
has been corrected.

* bf/fetch-set-head-fix:
  fetch set_head: fix non-mirror remotes in bare repositories
  fetch set_head: refactor to use remote directly

4 months agoMerge branch 'op/worktree-is-main-bare-fix'
Junio C Hamano [Sat, 15 Feb 2025 01:53:48 +0000 (17:53 -0800)] 
Merge branch 'op/worktree-is-main-bare-fix'

Going into a secondary worktree and asking "is the main worktree
bare?" did not work correctly when per-worktree configuration
option was in use, which has been corrected.

* op/worktree-is-main-bare-fix:
  worktree: detect from secondary worktree if main worktree is bare

4 months agoMerge branch 'tc/clone-single-revision'
Junio C Hamano [Sat, 15 Feb 2025 01:53:47 +0000 (17:53 -0800)] 
Merge branch 'tc/clone-single-revision'

"git clone" learned to make a shallow clone for a single commit
that is not necessarily be at the tip of any branch.

* tc/clone-single-revision:
  builtin/clone: teach git-clone(1) the --revision= option
  parse-options: introduce die_for_incompatible_opt2()
  clone: introduce struct clone_opts in builtin/clone.c
  clone: add tags refspec earlier to fetch refspec
  clone: refactor wanted_peer_refs()
  clone: make it possible to specify --tags
  clone: cut down on global variables in clone.c

4 months agoMerge branch 'bc/doc-adoc-not-txt'
Junio C Hamano [Sat, 15 Feb 2025 01:53:47 +0000 (17:53 -0800)] 
Merge branch 'bc/doc-adoc-not-txt'

All the documentation .txt files have been renamed to .adoc to help
content aware editors.

* bc/doc-adoc-not-txt:
  Remove obsolete ".txt" extensions for AsciiDoc files
  doc: use .adoc extension for AsciiDoc files
  gitattributes: mark AsciiDoc files as LF-only
  editorconfig: add .adoc extension
  doc: update gitignore for .adoc extension

4 months agoThe tenth batch
Junio C Hamano [Wed, 12 Feb 2025 18:09:08 +0000 (10:09 -0800)] 
The tenth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoMerge branch 'da/help-autocorrect-one-fix'
Junio C Hamano [Wed, 12 Feb 2025 18:08:55 +0000 (10:08 -0800)] 
Merge branch 'da/help-autocorrect-one-fix'

"git -c help.autocorrect=0 psuh" shows the suggested typofix,
unlike the previous attempt in the base topic.

* da/help-autocorrect-one-fix:
  help: add "show" as a valid configuration value
  help: show the suggested command when help.autocorrect is false

4 months agoMerge branch 'sc/help-autocorrect-one'
Junio C Hamano [Wed, 12 Feb 2025 18:08:54 +0000 (10:08 -0800)] 
Merge branch 'sc/help-autocorrect-one'

"[help] autocorrect = 1" used to be a way to say "please wait for
0.1 second after suggesting a typofix of the command name before
running that command"; now it means "yes, if there is a plausible
typofix for the command name, please run it immediately".

* sc/help-autocorrect-one:
  help: interpret boolean string values for help.autocorrect

4 months agoMerge branch 'ms/remote-valid-remote-name'
Junio C Hamano [Wed, 12 Feb 2025 18:08:54 +0000 (10:08 -0800)] 
Merge branch 'ms/remote-valid-remote-name'

Code shuffling.

* ms/remote-valid-remote-name:
  remote: relocate valid_remote_name

4 months agoMerge branch 'ms/refspec-cleanup'
Junio C Hamano [Wed, 12 Feb 2025 18:08:54 +0000 (10:08 -0800)] 
Merge branch 'ms/refspec-cleanup'

Code clean-up.  cf. <Z6G-toOJjMmK8iJG@pks.im>

* ms/refspec-cleanup:
  refspec: relocate apply_refspecs and related funtions
  refspec: relocate matching related functions
  remote: rename query_refspecs functions
  refspec: relocate refname_matches_negative_refspec_item
  remote: rename function omit_name_by_refspec

4 months agoMerge branch 'jp/doc-trailer-config'
Junio C Hamano [Wed, 12 Feb 2025 18:08:53 +0000 (10:08 -0800)] 
Merge branch 'jp/doc-trailer-config'

Documentaiton updates.

* jp/doc-trailer-config:
  config.txt: add trailer.* variables

4 months agoMerge branch 'zh/gc-expire-to'
Junio C Hamano [Wed, 12 Feb 2025 18:08:53 +0000 (10:08 -0800)] 
Merge branch 'zh/gc-expire-to'

"git gc" learned the "--expire-to" option and passes it down to
underlying "git repack".

* zh/gc-expire-to:
  gc: add `--expire-to` option

4 months agoMerge branch 'js/libgit-rust'
Junio C Hamano [Wed, 12 Feb 2025 18:08:53 +0000 (10:08 -0800)] 
Merge branch 'js/libgit-rust'

Foreign language interface for Rust into our code base has been added.

* js/libgit-rust:
  libgit: add higher-level libgit crate
  libgit-sys: also export some config_set functions
  libgit-sys: introduce Rust wrapper for libgit.a
  common-main: split init and exit code into new files

4 months agoMerge branch 'ac/t5401-use-test-path-is-file'
Junio C Hamano [Wed, 12 Feb 2025 18:08:52 +0000 (10:08 -0800)] 
Merge branch 'ac/t5401-use-test-path-is-file'

Test clean-up.

* ac/t5401-use-test-path-is-file:
  t5401: prefer test_path_is_* helper function

4 months agoMerge branch 'ac/t6423-unhide-git-exit-status'
Junio C Hamano [Wed, 12 Feb 2025 18:08:52 +0000 (10:08 -0800)] 
Merge branch 'ac/t6423-unhide-git-exit-status'

Test clean-up.

* ac/t6423-unhide-git-exit-status:
  t6423: fix suppression of Git’s exit code in tests

4 months agoMerge branch 'ps/repack-keep-unreachable-in-unpacked-repo'
Junio C Hamano [Wed, 12 Feb 2025 18:08:51 +0000 (10:08 -0800)] 
Merge branch 'ps/repack-keep-unreachable-in-unpacked-repo'

"git repack --keep-unreachable" to send unreachable objects to the
main pack "git repack -ad" produces did not work when there is no
existing packs, which has been corrected.

* ps/repack-keep-unreachable-in-unpacked-repo:
  builtin/repack: fix `--keep-unreachable` when there are no packs

4 months agoMerge branch 'ds/name-hash-tweaks'
Junio C Hamano [Wed, 12 Feb 2025 18:08:51 +0000 (10:08 -0800)] 
Merge branch 'ds/name-hash-tweaks'

"git pack-objects" and its wrapper "git repack" learned an option
to use an alternative path-hash function to improve delta-base
selection to produce a packfile with deeper history than window
size.

* ds/name-hash-tweaks:
  pack-objects: prevent name hash version change
  test-tool: add helper for name-hash values
  p5313: add size comparison test
  pack-objects: add GIT_TEST_NAME_HASH_VERSION
  repack: add --name-hash-version option
  pack-objects: add --name-hash-version option
  pack-objects: create new name-hash function version

4 months agoThe ninth batch
Junio C Hamano [Mon, 10 Feb 2025 18:18:17 +0000 (10:18 -0800)] 
The ninth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoMerge branch 'jk/ci-coverity-update'
Junio C Hamano [Mon, 10 Feb 2025 18:18:31 +0000 (10:18 -0800)] 
Merge branch 'jk/ci-coverity-update'

CI update to make Coverity job work again.

* jk/ci-coverity-update:
  ci: set CI_JOB_IMAGE for coverity job

4 months agoMerge branch 'sk/unit-tests-0130'
Junio C Hamano [Mon, 10 Feb 2025 18:18:31 +0000 (10:18 -0800)] 
Merge branch 'sk/unit-tests-0130'

Convert a handful of unit tests to work with the clar framework.

* sk/unit-tests-0130:
  t/unit-tests: convert strcmp-offset test to use clar test framework
  t/unit-tests: convert strbuf test to use clar test framework
  t/unit-tests: adapt example decorate test to use clar test framework
  t/unit-tests: convert hashmap test to use clar test framework

4 months agoMerge branch 'ps/hash-cleanup'
Junio C Hamano [Mon, 10 Feb 2025 18:18:30 +0000 (10:18 -0800)] 
Merge branch 'ps/hash-cleanup'

Further code clean-up on the use of hash functions.  Now the
context object knows what hash function it is working with.

* ps/hash-cleanup:
  global: adapt callers to use generic hash context helpers
  hash: provide generic wrappers to update hash contexts
  hash: stop typedeffing the hash context
  hash: convert hashing context to a structure

4 months agoMerge branch 'jt/gitlab-ci-base-fix'
Junio C Hamano [Mon, 10 Feb 2025 18:18:30 +0000 (10:18 -0800)] 
Merge branch 'jt/gitlab-ci-base-fix'

Two CI tasks, whitespace check and style check, work on the
difference from the base version and the version being checked, but
the base was computed incorrectly in GitLab CI in some cases, which
has been corrected.

* jt/gitlab-ci-base-fix:
  ci: fix base commit fallback for check-whitespace and check-style

4 months agoMerge branch 'pw/apply-ulong-overflow-check'
Junio C Hamano [Mon, 10 Feb 2025 18:18:30 +0000 (10:18 -0800)] 
Merge branch 'pw/apply-ulong-overflow-check'

"git apply" internally uses unsigned long for line numbers and uses
strtoul() to parse numbers on the hunk headers.  It however forgot
to check parse errors.

* pw/apply-ulong-overflow-check:
  apply: detect overflow when parsing hunk header

4 months agoMerge branch 'ps/setup-reinit-fixes'
Junio C Hamano [Mon, 10 Feb 2025 18:18:29 +0000 (10:18 -0800)] 
Merge branch 'ps/setup-reinit-fixes'

"git init" to reinitialize a repository that already exists cannot
change the hash function and ref backends; such a request is
silently ignored now.

* ps/setup-reinit-fixes:
  setup: fix reinit of repos with incompatible GIT_DEFAULT_HASH
  setup: fix reinit of repos with incompatible GIT_DEFAULT_REF_FORMAT
  t0001: remove duplicate test

4 months agoThe eighth batch
Junio C Hamano [Thu, 6 Feb 2025 22:24:26 +0000 (14:24 -0800)] 
The eighth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoMerge branch 'ps/leakfixes-0129'
Junio C Hamano [Thu, 6 Feb 2025 22:56:45 +0000 (14:56 -0800)] 
Merge branch 'ps/leakfixes-0129'

A few more leakfixes.

* ps/leakfixes-0129:
  scalar: free result of `remote_default_branch()`
  unix-socket: fix memory leak when chdir(3p) fails

4 months agoMerge branch 'ps/zlib-ng'
Junio C Hamano [Thu, 6 Feb 2025 22:56:45 +0000 (14:56 -0800)] 
Merge branch 'ps/zlib-ng'

The code paths to interact with zlib has been cleaned up in
preparation for building with zlib-ng.

* ps/zlib-ng:
  ci: make "linux-musl" job use zlib-ng
  ci: switch linux-musl to use Meson
  compat/zlib: allow use of zlib-ng as backend
  git-zlib: cast away potential constness of `next_in` pointer
  compat/zlib: provide stubs for `deflateSetHeader()`
  compat/zlib: provide `deflateBound()` shim centrally
  git-compat-util: move include of "compat/zlib.h" into "git-zlib.h"
  compat: introduce new "zlib.h" header
  git-compat-util: drop `z_const` define
  compat: drop `uncompress2()` compatibility shim

4 months agoMerge branch 'js/bundle-unbundle-fd-reuse-fix'
Junio C Hamano [Thu, 6 Feb 2025 22:56:44 +0000 (14:56 -0800)] 
Merge branch 'js/bundle-unbundle-fd-reuse-fix'

The code path used when "git fetch" fetches from a bundle file
closed the same file descriptor twice, which sometimes broke things
unexpectedly when the file descriptor was reused, which has been
corrected.

* js/bundle-unbundle-fd-reuse-fix:
  bundle: avoid closing file descriptor twice

4 months agoMerge branch 'ps/ci-misc-updates'
Junio C Hamano [Thu, 6 Feb 2025 22:56:44 +0000 (14:56 -0800)] 
Merge branch 'ps/ci-misc-updates'

CI updates (containerization, dropping stale ones, etc.).

* ps/ci-misc-updates:
  ci: remove stale code for Azure Pipelines
  ci: use latest Ubuntu release
  ci: stop special-casing for Ubuntu 16.04
  gitlab-ci: add linux32 job testing against i386
  gitlab-ci: remove the "linux-old" job
  github: simplify computation of the job's distro
  github: convert all Linux jobs to be containerized
  github: adapt containerized jobs to be rootless
  t7422: fix flaky test caused by buffered stdout
  t0060: fix EBUSY in MinGW when setting up runtime prefix

4 months agodoc: documentation for http.uploadarchive config option
Piotr Szlazak [Thu, 6 Feb 2025 17:45:27 +0000 (17:45 +0000)] 
doc: documentation for http.uploadarchive config option

In Git v2.44.0 support for 'git archive' over HTTP protocol
was added, but it was nowhere documented how it should be
enabled in git-http-backend.

Add missing documentation.

Signed-off-by: Piotr Szlazak <piotr.szlazak@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agobuiltin/clone: teach git-clone(1) the --revision= option
Toon Claes [Thu, 6 Feb 2025 06:33:35 +0000 (07:33 +0100)] 
builtin/clone: teach git-clone(1) the --revision= option

The git-clone(1) command has the option `--branch` that allows the user
to select the branch they want HEAD to point to. In a non-bare
repository this also checks out that branch.

Option `--branch` also accepts a tag. When a tag name is provided, the
commit this tag points to is checked out and HEAD is detached. Thus
`--branch` can be used to clone a repository and check out a ref kept
under `refs/heads` or `refs/tags`. But some other refs might be in use
as well. For example Git forges might use refs like `refs/pull/<id>` and
`refs/merge-requests/<id>` to track pull/merge requests. These refs
cannot be selected upon git-clone(1).

Add option `--revision` to git-clone(1). This option accepts a fully
qualified reference, or a hexadecimal commit ID. This enables the user
to clone and check out any revision they want. `--revision` can be used
in conjunction with `--depth` to do a minimal clone that only contains
the blob and tree for a single revision. This can be useful for
automated tests running in CI systems.

Using option `--branch` and `--single-branch` together is a similar
scenario, but serves a different purpose. Using these two options, a
singlet remote tracking branch is created and the fetch refspec is set
up so git-fetch(1) will receive updates on that branch from the remote.
This allows the user work on that single branch.

Option `--revision` on contrary detaches HEAD, creates no tracking
branches, and writes no fetch refspec.

Signed-off-by: Toon Claes <toon@iotcl.com>
Acked-by: Patrick Steinhardt <ps@pks.im>
[jc: removed unnecessary TEST_PASSES_SANITIZE_LEAK from the test]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoparse-options: introduce die_for_incompatible_opt2()
Toon Claes [Thu, 6 Feb 2025 06:33:34 +0000 (07:33 +0100)] 
parse-options: introduce die_for_incompatible_opt2()

The functions die_for_incompatible_opt3() and
die_for_incompatible_opt4() already exist to die whenever a user
specifies three or four options respectively that are not compatible.

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

Signed-off-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoclone: introduce struct clone_opts in builtin/clone.c
Toon Claes [Thu, 6 Feb 2025 06:33:33 +0000 (07:33 +0100)] 
clone: introduce struct clone_opts in builtin/clone.c

There is a lot of state stored in global variables in builtin/clone.c.
In the long run we'd like to remove many of those.

Introduce `struct clone_opts` in this file. This struct will be used to
contain all details needed to perform the clone. The struct object can
be thrown around to all the functions that need these details.

The first field we're adding is `wants_head`. In some scenarios
(specifically when both `--single-branch` and `--branch` are given) we
are not interested in `HEAD` on the remote. The field `wants_head` in
`struct clone_opts` will hold this information. We could have put
`option_branch` and `option_single_branch` into that struct instead, but
in a following commit we'll be using `wants_head` as well.

Signed-off-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoclone: add tags refspec earlier to fetch refspec
Toon Claes [Thu, 6 Feb 2025 06:33:32 +0000 (07:33 +0100)] 
clone: add tags refspec earlier to fetch refspec

In clone.c we call refspec_ref_prefixes() to copy the fetch refspecs
from the `remote->fetch` refspec into `ref_prefixes` of
`transport_ls_refs_options`. Afterwards we add the tags prefix
`refs/tags/` prefix as well. At a later point, in wanted_peer_refs() we
process refs using both `remote->fetch` and `TAG_REFSPEC`.

Simplify the code by appending `TAG_REFSPEC` to `remote->fetch` before
calling refspec_ref_prefixes().

To be able to do this, we set `option_tags` to 0 when --mirror is given.
This is because --mirror mirrors (hence the name) all the refs,
including tags and they do not need to be treated separately.

Signed-off-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoclone: refactor wanted_peer_refs()
Toon Claes [Thu, 6 Feb 2025 06:33:31 +0000 (07:33 +0100)] 
clone: refactor wanted_peer_refs()

The function wanted_peer_refs() is used to map the refs returned by the
server to refs we will save in our clone.

Over time this function grown to be very complex. Refactor it.

Previously, there was a separate code path for when
`option_single_branch` was set. It resulted in duplicated code and
deeper nested conditions. After this refactor the code path for when
`option_single_branch` is truthy modifies `refs` and then falls through
to the common code path. This approach relies on the `refspec` being set
correctly and thus only mapping refs that are relevant.

Signed-off-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoclone: make it possible to specify --tags
Toon Claes [Thu, 6 Feb 2025 06:33:30 +0000 (07:33 +0100)] 
clone: make it possible to specify --tags

Option --no-tags was added in 0dab2468ee (clone: add a --no-tags option
to clone without tags, 2017-04-26). At the time there was no need to
support --tags as well, although there was some conversation about
it[1].

To simplify the code and to prepare for future commits, invert the flag
internally. Functionally there is no change, because the flag is
default-enabled passing `--tags` has no effect, so there's no need to
add tests for this.

[1]: https://lore.kernel.org/git/CAGZ79kbHuMpiavJ90kQLEL_AR0BEyArcZoEWAjPPhOFacN16YQ@mail.gmail.com/

Signed-off-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoclone: cut down on global variables in clone.c
Toon Claes [Thu, 6 Feb 2025 06:33:29 +0000 (07:33 +0100)] 
clone: cut down on global variables in clone.c

In clone.c the `struct option` which is used to parse the input options
for git-clone(1) is a global variable. Due to this, many variables that
are used to parse the value into, are also global.

Make `builtin_clone_options` a local variable in cmd_clone() and carry
along all variables that are only used in that function.

Signed-off-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoworktree: detect from secondary worktree if main worktree is bare
Olga Pilipenco [Wed, 5 Feb 2025 06:30:13 +0000 (06:30 +0000)] 
worktree: detect from secondary worktree if main worktree is bare

When extensions.worktreeConfig is true and the main worktree is
bare -- that is, its config.worktree file contains core.bare=true
-- commands run from secondary worktrees incorrectly see the main
worktree as not bare. As such, those commands incorrectly think
that the repository's default branch (typically "main" or
"master") is checked out in the bare repository even though it's
not. This makes it impossible, for instance, to checkout or delete
the default branch from a secondary worktree, among other
shortcomings.

This problem occurs because, when extensions.worktreeConfig is
true, commands run in secondary worktrees only consult
$commondir/config and $commondir/worktrees/<id>/config.worktree,
thus they never see the main worktree's core.bare=true setting in
$commondir/config.worktree.

Fix this problem by consulting the main worktree's config.worktree
file when checking whether it is bare. (This extra work is
performed only when running from a secondary worktree.)

Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Olga Pilipenco <olga.pilipenco@shopify.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agobuiltin/repack: fix `--keep-unreachable` when there are no packs
Patrick Steinhardt [Tue, 4 Feb 2025 07:00:41 +0000 (08:00 +0100)] 
builtin/repack: fix `--keep-unreachable` when there are no packs

The "--keep-unreachable" flag is supposed to append any unreachable
objects to the newly written pack. This flag is explicitly documented as
appending both packed and loose unreachable objects to the new packfile.
And while this works alright when repacking with preexisting packfiles,
it stops working when the repository does not have any packfiles at all.

The root cause are the conditions used to decide whether or not we want
to append "--pack-loose-unreachable" to git-pack-objects(1). There are
a couple of conditions here:

  - `has_existing_non_kept_packs()` checks whether there are existing
    packfiles. This condition makes sense to guard "--keep-pack=",
    "--unpack-unreachable" and "--keep-unreachable", because all of
    these flags only make sense in combination with existing packfiles.
    But it does not make sense to disable `--pack-loose-unreachable`
    when there aren't any preexisting packfiles, as loose objects can be
    packed into the new packfile regardless of that.

  - `delete_redundant` checks whether we want to delete any objects or
    packs that are about to become redundant. The documentation of
    `--keep-unreachable` explicitly says that `git repack -ad` needs to
    be executed for the flag to have an effect.

    It is not immediately obvious why such redundant objects need to be
    deleted in order for "--pack-unreachable-objects" to be effective.
    But as things are working as documented this is nothing we'll change
    for now.

  - `pack_everything & PACK_CRUFT` checks that we're not creating a
    cruft pack. This condition makes sense in the context of
    "--pack-loose-unreachable", as unreachable objects would end up in
    the cruft pack anyway.

So while the second and third condition are sensible, it does not make
any sense to condition `--pack-loose-unreachable` on the existence of
packfiles.

Fix the bug by splitting out the "--pack-loose-unreachable" and only
making it depend on the second and third condition. Like this, loose
unreachable objects will be packed regardless of any preexisting
packfiles.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoremote: relocate valid_remote_name
Meet Soni [Tue, 4 Feb 2025 14:28:52 +0000 (19:58 +0530)] 
remote: relocate valid_remote_name

Move the `valid_remote_name()` function from the refspec subsystem to
the remote subsystem to better align with the separation of concerns.

Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agorefspec: relocate apply_refspecs and related funtions
Meet Soni [Tue, 4 Feb 2025 04:05:58 +0000 (09:35 +0530)] 
refspec: relocate apply_refspecs and related funtions

Move the functions `apply_refspecs()` and `apply_negative_refspecs()`
from `remote.c` to `refspec.c`. These functions focus on applying
refspecs, so centralizing them in `refspec.c` improves code organization
by keeping refspec-related logic in one place.

Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agorefspec: relocate matching related functions
Meet Soni [Tue, 4 Feb 2025 04:05:57 +0000 (09:35 +0530)] 
refspec: relocate matching related functions

Move the functions `refspec_find_match()`, `refspec_find_all_matches()`
and `refspec_find_negative_match()` from `remote.c` to `refspec.c`.
These functions focus on matching refspecs, so centralizing them in
`refspec.c` improves code organization by keeping refspec-related logic
in one place.

Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoremote: rename query_refspecs functions
Meet Soni [Tue, 4 Feb 2025 04:05:56 +0000 (09:35 +0530)] 
remote: rename query_refspecs functions

Rename functions related to handling refspecs in preparation for their
move from `remote.c` to `refspec.c`. Update their names to better
reflect their intent:

    - `query_refspecs()` -> `refspec_find_match()` for clarity, as it
      finds a single matching refspec.

    - `query_refspecs_multiple()` -> `refspec_find_all_matches()` to
      better reflect that it collects all matching refspecs instead of
      returning just the first match.

    - `query_matches_negative_refspec()` ->
      `refspec_find_negative_match()` for consistency with the
      updated naming convention, even though this static function
      didn't strictly require renaming.

Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agorefspec: relocate refname_matches_negative_refspec_item
Meet Soni [Tue, 4 Feb 2025 04:05:55 +0000 (09:35 +0530)] 
refspec: relocate refname_matches_negative_refspec_item

Move the functions `refname_matches_negative_refspec_item()`,
`refspec_match()`, and `match_name_with_pattern()` from `remote.c` to
`refspec.c`. These functions focus on refspec matching, so placing them
in `refspec.c` aligns with the separation of concerns. Keep
refspec-related logic in `refspec.c` and remote-specific logic in
`remote.c` for better code organization.

Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoremote: rename function omit_name_by_refspec
Meet Soni [Tue, 4 Feb 2025 04:05:54 +0000 (09:35 +0530)] 
remote: rename function omit_name_by_refspec

Rename the function `omit_name_by_refspec()` to
`refname_matches_negative_refspec_item()` to provide clearer intent.
The previous function name was vague and did not accurately describe its
purpose. By using `refname_matches_negative_refspec_item`, make the
function's purpose more intuitive, clarifying that it checks if a
reference name matches any negative refspec.

Rename function parameters for consistency with existing naming
conventions. Use `refname` instead of `name` to align with terminology
in `refs.h`.

Remove the redundant doc comment since the function name is now
self-explanatory.

Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agot6423: fix suppression of Git’s exit code in tests
Ayush Chandekar [Sun, 2 Feb 2025 12:09:26 +0000 (17:39 +0530)] 
t6423: fix suppression of Git’s exit code in tests

Some test in t6423 supress Git's exit code, which can cause test
failures go unnoticed. Specifically using git <subcommand> |
<other-command> masks potential failures of the Git command.

This commit ensures that Git's exit status is correctly propogated by:
- Avoiding pipes that suppress exit codes.

Signed-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agohelp: add "show" as a valid configuration value
David Aguilar [Sat, 1 Feb 2025 21:33:19 +0000 (13:33 -0800)] 
help: add "show" as a valid configuration value

Add a literal value for showing the suggested autocorrection
for consistency with the rest of the help.autocorrect options.

Signed-off-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agohelp: show the suggested command when help.autocorrect is false
David Aguilar [Sat, 1 Feb 2025 21:33:18 +0000 (13:33 -0800)] 
help: show the suggested command when help.autocorrect is false

Make the handling of false boolean values for help.autocorrect
consistent with the handling of value 0 by showing the suggested
commands but not running them.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoMerge branch 'sc/help-autocorrect-one' into da/help-autocorrect-one-fix
Junio C Hamano [Mon, 3 Feb 2025 23:21:57 +0000 (15:21 -0800)] 
Merge branch 'sc/help-autocorrect-one' into da/help-autocorrect-one-fix

* sc/help-autocorrect-one:
  help: interpret boolean string values for help.autocorrect

4 months agot5401: prefer test_path_is_* helper function
ambar chakravartty [Sat, 1 Feb 2025 07:12:10 +0000 (12:42 +0530)] 
t5401: prefer test_path_is_* helper function

"test -f" does not provide a nice error message when we hit test
failures, so use test_path_is_file instead.

Signed-off-by: ambar chakravartty <amch9605@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoThe seventh batch
Junio C Hamano [Mon, 3 Feb 2025 18:23:05 +0000 (10:23 -0800)] 
The seventh batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoMerge branch 'kn/reflog-migration-fix-fix'
Junio C Hamano [Mon, 3 Feb 2025 18:23:34 +0000 (10:23 -0800)] 
Merge branch 'kn/reflog-migration-fix-fix'

Fix bugs in an earlier attempt to fix "git refs migration".

* kn/reflog-migration-fix-fix:
  refs/reftable: fix uninitialized memory access of `max_index`
  reftable: write correct max_update_index to header

4 months agoMerge branch 'kn/pack-write-with-reduced-globals'
Junio C Hamano [Mon, 3 Feb 2025 18:23:34 +0000 (10:23 -0800)] 
Merge branch 'kn/pack-write-with-reduced-globals'

Code clean-up.

* kn/pack-write-with-reduced-globals:
  pack-write: pass hash_algo to internal functions
  pack-write: pass hash_algo to `write_rev_file()`
  pack-write: pass hash_algo to `write_idx_file()`
  pack-write: pass repository to `index_pack_lockfile()`
  pack-write: pass hash_algo to `fixup_pack_header_footer()`

4 months agoMerge branch 'ps/build-meson-fixes'
Junio C Hamano [Mon, 3 Feb 2025 18:23:34 +0000 (10:23 -0800)] 
Merge branch 'ps/build-meson-fixes'

More build fixes and enhancements on meson based build procedure.

* 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

4 months agoMerge branch 'ps/3.0-remote-deprecation'
Junio C Hamano [Mon, 3 Feb 2025 18:23:33 +0000 (10:23 -0800)] 
Merge branch 'ps/3.0-remote-deprecation'

Following the procedure we established to introduce breaking
changes for Git 3.0, allow an early opt-in for removing support of
$GIT_DIR/branches/ and $GIT_DIR/remotes/ directories to configure
remotes.

* ps/3.0-remote-deprecation:
  remote: announce removal of "branches/" and "remotes/"
  builtin/pack-redundant: remove subcommand with breaking changes
  ci: repurpose "linux-gcc" job for deprecations
  ci: merge linux-gcc-default into linux-gcc
  Makefile: wire up build option for deprecated features

4 months agoMerge branch 'jk/combine-diff-cleanup'
Junio C Hamano [Mon, 3 Feb 2025 18:23:33 +0000 (10:23 -0800)] 
Merge branch 'jk/combine-diff-cleanup'

Code clean-up for code paths around combined diff.

* jk/combine-diff-cleanup:
  tree-diff: make list tail-passing more explicit
  tree-diff: simplify emit_path() list management
  tree-diff: use the name "tail" to refer to list tail
  tree-diff: drop list-tail argument to diff_tree_paths()
  combine-diff: drop public declaration of combine_diff_path_size()
  tree-diff: inline path_appendnew()
  tree-diff: pass whole path string to path_appendnew()
  tree-diff: drop path_appendnew() alloc optimization
  run_diff_files(): de-mystify the size of combine_diff_path struct
  diff: add a comment about combine_diff_path.parent.path
  combine-diff: use pointer for parent paths
  tree-diff: clear parent array in path_appendnew()
  combine-diff: add combine_diff_path_new()
  run_diff_files(): delay allocation of combine_diff_path

4 months agoMerge branch 'tb/unsafe-hash-cleanup'
Junio C Hamano [Mon, 3 Feb 2025 18:23:32 +0000 (10:23 -0800)] 
Merge branch 'tb/unsafe-hash-cleanup'

The API around choosing to use unsafe variant of SHA-1
implementation has been updated in an attempt to make it harder to
abuse.

* tb/unsafe-hash-cleanup:
  hash.h: drop unsafe_ function variants
  csum-file: introduce hashfile_checkpoint_init()
  t/helper/test-hash.c: use unsafe_hash_algo()
  csum-file.c: use unsafe_hash_algo()
  hash.h: introduce `unsafe_hash_algo()`
  csum-file.c: extract algop from hashfile_checksum_valid()
  csum-file: store the hash algorithm as a struct field
  t/helper/test-tool: implement sha1-unsafe helper

4 months agoci: set CI_JOB_IMAGE for coverity job
Jeff King [Fri, 31 Jan 2025 23:30:15 +0000 (18:30 -0500)] 
ci: set CI_JOB_IMAGE for coverity job

The main GitHub Actions workflow switched away from the "$distro"
variable in b133d3071a (github: simplify computation of the job's
distro, 2025-01-10). Since the Coverity job also depends on our
ci/install-dependencies.sh script, it needs to likewise set CI_JOB_IMAGE
to find the correct dependencies (without this patch, we don't install
curl and the build fails).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoMerge branch 'ps/ci-misc-updates' into jk/ci-coverity-update
Junio C Hamano [Mon, 3 Feb 2025 17:24:25 +0000 (09:24 -0800)] 
Merge branch 'ps/ci-misc-updates' into jk/ci-coverity-update

* ps/ci-misc-updates:
  ci: remove stale code for Azure Pipelines
  ci: use latest Ubuntu release
  ci: stop special-casing for Ubuntu 16.04
  gitlab-ci: add linux32 job testing against i386
  gitlab-ci: remove the "linux-old" job
  github: simplify computation of the job's distro
  github: convert all Linux jobs to be containerized
  github: adapt containerized jobs to be rootless
  t7422: fix flaky test caused by buffered stdout
  t0060: fix EBUSY in MinGW when setting up runtime prefix

4 months agot/unit-tests: convert strcmp-offset test to use clar test framework
Seyi Kuforiji [Fri, 31 Jan 2025 22:14:20 +0000 (23:14 +0100)] 
t/unit-tests: convert strcmp-offset test to use clar test framework

Adapt strcmp-offset test script to clar framework by using clar
assertions where necessary. Introduce `test_strcmp_offset__empty()` to
verify `check_strcmp_offset()` behavior when both input strings are
empty. This ensures the function correctly handles edge cases and
returns expected values.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agot/unit-tests: convert strbuf test to use clar test framework
Seyi Kuforiji [Fri, 31 Jan 2025 22:14:19 +0000 (23:14 +0100)] 
t/unit-tests: convert strbuf test to use clar test framework

Adapt strbuf 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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agot/unit-tests: adapt example decorate test to use clar test framework
Seyi Kuforiji [Fri, 31 Jan 2025 22:14:18 +0000 (23:14 +0100)] 
t/unit-tests: adapt example decorate test to use clar test framework

Introduce `test_example_decorate__initialize()` to explicitly set up
object IDs and retrieve corresponding objects before tests run. This
ensures a consistent and predictable test state without relying on data
from previous tests.

Add `test_example_decorate__cleanup()` to clear decorations after each
test, preventing interference between tests and ensuring each runs in
isolation.

Adapt example decorate test script to clar framework by using clar
assertions where necessary. Previously, tests relied on data written by
earlier tests, leading to unintended dependencies between them. This
explicitly initializes the necessary state within
`test_example_decorate__readd`, ensuring it does not depend on prior
test executions.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agot/unit-tests: convert hashmap test to use clar test framework
Seyi Kuforiji [Fri, 31 Jan 2025 22:14:17 +0000 (23:14 +0100)] 
t/unit-tests: convert hashmap test to use clar test framework

Adapts hashmap 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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoci: fix base commit fallback for check-whitespace and check-style
Justin Tobler [Fri, 31 Jan 2025 17:39:38 +0000 (11:39 -0600)] 
ci: fix base commit fallback for check-whitespace and check-style

The check-whitespace and check-style CI scripts require a base commit.
In GitLab CI, the base commit can be provided by several different
predefined CI variables depending on the type of pipeline being
performed.

In 30c4f7e350 (check-whitespace: detect if no base_commit is provided,
2024-07-23), the GitLab check-whitespace CI job was modified to support
CI_MERGE_REQUEST_DIFF_BASE_SHA as a fallback base commit if
CI_MERGE_REQUEST_TARGET_BRANCH_SHA was not provided. The same fallback
strategy was also implemented for the GitLab check-style CI job in
bce7e52d4e (ci: run style check on GitHub and GitLab, 2024-07-23).

The base commit fallback is implemented using shell parameter expansion
where, if the first variable is unset, the second variable is used as
fallback. In GitLab CI, these variables can be set but null. This has
the unintended effect of selecting an empty first variable which results
in CI jobs providing an invalid base commit and failing.

Fix the issue by defaulting to the fallback variable if the first is
unset or null.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoglobal: adapt callers to use generic hash context helpers
Patrick Steinhardt [Fri, 31 Jan 2025 12:55:31 +0000 (13:55 +0100)] 
global: adapt callers to use generic hash context helpers

Adapt callers to use generic hash context helpers instead of using the
hash algorithm to update them. This makes the callsites easier to reason
about and removes the possibility that the wrong hash algorithm is used
to update the hash context's state. And as a nice side effect this also
gets rid of a bunch of users of `the_hash_algo`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agohash: provide generic wrappers to update hash contexts
Patrick Steinhardt [Fri, 31 Jan 2025 12:55:30 +0000 (13:55 +0100)] 
hash: provide generic wrappers to update hash contexts

The hash context is supposed to be updated via the `git_hash_algo`
structure, which contains a list of function pointers to update, clone
or finalize a hashing context. This requires the callers to track which
algorithm was used to initialize the context and continue to use the
exact same algorithm. If they fail to do that correctly, it can happen
that we start to access context state of one hash algorithm with
functions of a different hash algorithm. The result would typically be a
segfault, as could be seen e.g. in the patches part of 98422943f0 (Merge
branch 'ps/weak-sha1-for-tail-sum-fix', 2025-01-01).

The situation was significantly improved starting with 04292c3796
(hash.h: drop unsafe_ function variants, 2025-01-23) and its parent
commits. These refactorings ensure that it is not possible to mix up
safe and unsafe variants of the same hash algorithm anymore. But in
theory, it is still possible to mix up different hash algorithms with
each other, even though this is a lot less likely to happen.

But still, we can do better: instead of asking the caller to remember
the hash algorithm used to initialize a context, we can instead make the
context itself remember which algorithm it has been initialized with. If
we do so, callers can use a set of generic helpers to update the context
and don't need to be aware of the hash algorithm at all anymore.

Adapt the context initialization functions to store the hash algorithm
in the hashing context and introduce these generic helpers. Callers will
be adapted in the subsequent commit.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agohash: stop typedeffing the hash context
Patrick Steinhardt [Fri, 31 Jan 2025 12:55:29 +0000 (13:55 +0100)] 
hash: stop typedeffing the hash context

We generally avoid using `typedef` in the Git codebase. One exception
though is the `git_hash_ctx`, likely because it used to be a union
rather than a struct until the preceding commit refactored it. But now
that it is a normal `struct` there isn't really a need for a typedef
anymore.

Drop the typedef and adapt all callers accordingly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agohash: convert hashing context to a structure
Patrick Steinhardt [Fri, 31 Jan 2025 12:55:28 +0000 (13:55 +0100)] 
hash: convert hashing context to a structure

The `git_hash_context` is a union containing the different hash-specific
states for SHA1, its unsafe variant as well as SHA256. We know that only
one of these states will ever be in use at the same time because hash
contexts cannot be used for multiple different hashes at the same point
in time.

We're about to extend the structure though to keep track of the hash
algorithm used to initialize the context, which is impossible to do
while the context is a union. Refactor it to instead be a structure that
contains the union of context states.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoMerge branch 'tb/unsafe-hash-cleanup' into ps/hash-cleanup
Junio C Hamano [Fri, 31 Jan 2025 18:05:46 +0000 (10:05 -0800)] 
Merge branch 'tb/unsafe-hash-cleanup' into ps/hash-cleanup

* tb/unsafe-hash-cleanup:
  hash.h: drop unsafe_ function variants
  csum-file: introduce hashfile_checkpoint_init()
  t/helper/test-hash.c: use unsafe_hash_algo()
  csum-file.c: use unsafe_hash_algo()
  hash.h: introduce `unsafe_hash_algo()`
  csum-file.c: extract algop from hashfile_checksum_valid()
  csum-file: store the hash algorithm as a struct field
  t/helper/test-tool: implement sha1-unsafe helper

4 months agoThe sixth batch
Junio C Hamano [Fri, 31 Jan 2025 16:42:07 +0000 (08:42 -0800)] 
The sixth batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoMerge branch 'jc/show-index-h-update'
Junio C Hamano [Fri, 31 Jan 2025 17:44:16 +0000 (09:44 -0800)] 
Merge branch 'jc/show-index-h-update'

Doc and short-help text for "show-index" has been clarified to
stress that the command reads its data from the standard input.

* jc/show-index-h-update:
  show-index: the short help should say the command reads from its input

4 months agoMerge branch 'ja/doc-notes-markup-updates'
Junio C Hamano [Fri, 31 Jan 2025 17:44:15 +0000 (09:44 -0800)] 
Merge branch 'ja/doc-notes-markup-updates'

Doc mark-up updates.

* ja/doc-notes-markup-updates:
  doc: convert git-notes to new documentation format

4 months agoMerge branch 'sk/strlen-returns-size_t'
Junio C Hamano [Fri, 31 Jan 2025 17:44:15 +0000 (09:44 -0800)] 
Merge branch 'sk/strlen-returns-size_t'

Code clean-up.

* sk/strlen-returns-size_t:
  date.c: Fix type missmatch warings from msvc

4 months agoMerge branch 'ja/doc-restore-markup-update'
Junio C Hamano [Fri, 31 Jan 2025 17:44:15 +0000 (09:44 -0800)] 
Merge branch 'ja/doc-restore-markup-update'

Doc mark-up updates.

* ja/doc-restore-markup-update:
  doc: convert git-restore to new style format

4 months agosetup: fix reinit of repos with incompatible GIT_DEFAULT_HASH
Patrick Steinhardt [Thu, 30 Jan 2025 16:24:19 +0000 (17:24 +0100)] 
setup: fix reinit of repos with incompatible GIT_DEFAULT_HASH

The exact same issue as described in the preceding commit also exists
for GIT_DEFAULT_HASH. Thus, reinitializing a repository that e.g. uses
SHA1 with `GIT_DEFAULT_HASH=sha256 git init` will cause the object
format of that repository to change to SHA256. This is of course bogus
as any existing objects and refs will not be converted, thus causing
repository corruption:

    $ git init repo
    Initialized empty Git repository in /tmp/repo/.git/
    $ cd repo/
    $ git commit --allow-empty -m message
    [main (root-commit) 35a7344] message
    $ GIT_DEFAULT_HASH=sha256 git init
    Reinitialized existing Git repository in /tmp/repo/.git/
    $ git show
    fatal: your current branch appears to be broken

Fix the issue by ignoring the environment variable in case the repo has
already been initialized with an object hash.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agosetup: fix reinit of repos with incompatible GIT_DEFAULT_REF_FORMAT
Patrick Steinhardt [Thu, 30 Jan 2025 16:24:18 +0000 (17:24 +0100)] 
setup: fix reinit of repos with incompatible GIT_DEFAULT_REF_FORMAT

The GIT_DEFAULT_REF_FORMAT environment variable can be set to influence
the default ref format that new repostiories shall be initialized with.
While this is the expected behaviour when creating a new repository, it
is not when reinitializing a repository: we should retain the ref format
currently used by it in that case.

This doesn't work correctly right now:

    $ git init --ref-format=files repo
    Initialized empty Git repository in /tmp/repo/.git/
    $ GIT_DEFAULT_REF_FORMAT=reftable git init repo
    fatal: could not open '/tmp/repo/.git/refs/heads' for writing: Is a directory

Instead of retaining the current ref format, the reinitialization tries
to reinitialize the repository with the different format. This action
fails when git-init(1) tries to write the ".git/refs/heads" stub, which
in the context of the reftable backend is always written as a file so
that we can detect clients which inadvertently try to access the repo
with the wrong ref format. Seems like the protection mechanism works for
this case, as well.

Fix the issue by ignoring the environment variable in case the repo has
already been initialized with a ref storage format.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agot0001: remove duplicate test
Patrick Steinhardt [Thu, 30 Jan 2025 16:24:17 +0000 (17:24 +0100)] 
t0001: remove duplicate test

The test in question is an exact copy of the testcase preceding it.
Remove it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoapply: detect overflow when parsing hunk header
Phillip Wood [Thu, 30 Jan 2025 11:08:30 +0000 (11:08 +0000)] 
apply: detect overflow when parsing hunk header

"git apply" uses strtoul() to parse the numbers in the hunk header but
silently ignores overflows. As LONG_MAX is a legitimate return value for
strtoul() we need to set errno to zero before the call to strtoul() and
check that it is still zero afterwards. The error message we display is
not particularly helpful as it does not say what was wrong.  However, it
seems pretty unlikely that users are going to trigger this error in
practice and we can always improve it later if needed.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agoscalar: free result of `remote_default_branch()`
Patrick Steinhardt [Thu, 30 Jan 2025 06:17:39 +0000 (07:17 +0100)] 
scalar: free result of `remote_default_branch()`

We don't free the result of `remote_default_branch()`, leading to a
memory leak. This leak is exposed by t9211, but only when run with Meson
with the `-Db_sanitize=leak` option:

    Direct leak of 5 byte(s) in 1 object(s) allocated from:
        #0 0x5555555cfb93 in malloc (scalar+0x7bb93)
        #1 0x5555556b05c2 in do_xmalloc ../wrapper.c:55:8
        #2 0x5555556b06c4 in do_xmallocz ../wrapper.c:89:8
        #3 0x5555556b0656 in xmallocz ../wrapper.c:97:9
        #4 0x5555556b0728 in xmemdupz ../wrapper.c:113:16
        #5 0x5555556b07a7 in xstrndup ../wrapper.c:119:9
        #6 0x5555555d3a4b in remote_default_branch ../scalar.c:338:14
        #7 0x5555555d20e6 in cmd_clone ../scalar.c:493:28
        #8 0x5555555d196b in cmd_main ../scalar.c:992:14
        #9 0x5555557c4059 in main ../common-main.c:64:11
        #10 0x7ffff7a2a1fb in __libc_start_call_main (/nix/store/h7zcxabfxa7v5xdna45y2hplj31ncf8a-glibc-2.40-36/lib/libc.so.6+0x2a1fb) (BuildId: 0a855678aa0cb573cecbb2bcc73ab8239ec472d0)
        #11 0x7ffff7a2a2b8 in __libc_start_main@GLIBC_2.2.5 (/nix/store/h7zcxabfxa7v5xdna45y2hplj31ncf8a-glibc-2.40-36/lib/libc.so.6+0x2a2b8) (BuildId: 0a855678aa0cb573cecbb2bcc73ab8239ec472d0)
        #12 0x555555592054 in _start (scalar+0x3e054)

    DEDUP_TOKEN: __interceptor_malloc--do_xmalloc--do_xmallocz--xmallocz--xmemdupz--xstrndup--remote_default_branch--cmd_clone--cmd_main--main--__libc_start_call_main--__libc_start_main@GLIBC_2.2.5--_start
    SUMMARY: LeakSanitizer: 5 byte(s) leaked in 1 allocation(s).

As the `branch` variable may contain a string constant obtained from
parsing command line arguments we cannot free the leaking variable
directly. Instead, introduce a new `branch_to_free` variable that only
ever gets assigned the allocated string and free that one to plug the
leak.

It is unclear why the leak isn't flagged when running the test via our
Makefile.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agounix-socket: fix memory leak when chdir(3p) fails
Patrick Steinhardt [Thu, 30 Jan 2025 06:17:38 +0000 (07:17 +0100)] 
unix-socket: fix memory leak when chdir(3p) fails

When trying to create a Unix socket in a path that exceeds the maximum
socket name length we try to first change the directory into the parent
folder before creating the socket to reduce the length of the name. When
this fails we error out of `unix_sockaddr_init()` with an error code,
which indicates to the caller that the context has not been initialized.
Consequently, they don't release that context.

This leads to a memory leak: when we have already populated the context
with the original directory that we need to chdir(3p) back into, but
then the chdir(3p) into the socket's parent directory fails, then we
won't release the original directory's path. The leak is exposed by
t0301, but only when running tests in a directory hierarchy whose path
is long enough to make the socket name length exceed the maximum socket
name length:

    Direct leak of 129 byte(s) in 1 object(s) allocated from:
        #0 0x5555555e85c6 in realloc.part.0 lsan_interceptors.cpp.o
        #1 0x55555590e3d6 in xrealloc ../wrapper.c:140:8
        #2 0x5555558c8fc6 in strbuf_grow ../strbuf.c:114:2
        #3 0x5555558cacab in strbuf_getcwd ../strbuf.c:605:3
        #4 0x555555923ff6 in unix_sockaddr_init ../unix-socket.c:65:7
        #5 0x555555923e42 in unix_stream_connect ../unix-socket.c:84:6
        #6 0x55555562a984 in send_request ../builtin/credential-cache.c:46:11
        #7 0x55555562a89e in do_cache ../builtin/credential-cache.c:108:6
        #8 0x55555562a655 in cmd_credential_cache ../builtin/credential-cache.c:178:3
        #9 0x555555700547 in run_builtin ../git.c:480:11
        #10 0x5555556ff0e0 in handle_builtin ../git.c:740:9
        #11 0x5555556ffee8 in run_argv ../git.c:807:4
        #12 0x5555556fee6b in cmd_main ../git.c:947:19
        #13 0x55555593f689 in main ../common-main.c:64:11
        #14 0x7ffff7a2a1fb in __libc_start_call_main (/nix/store/h7zcxabfxa7v5xdna45y2hplj31ncf8a-glibc-2.40-36/lib/libc.so.6+0x2a1fb) (BuildId: 0a855678aa0cb573cecbb2bcc73ab8239ec472d0)
        #15 0x7ffff7a2a2b8 in __libc_start_main@GLIBC_2.2.5 (/nix/store/h7zcxabfxa7v5xdna45y2hplj31ncf8a-glibc-2.40-36/lib/libc.so.6+0x2a2b8) (BuildId: 0a855678aa0cb573cecbb2bcc73ab8239ec472d0)
        #16 0x5555555ad1d4 in _start (git+0x591d4)

    DEDUP_TOKEN: ___interceptor_realloc.part.0--xrealloc--strbuf_grow--strbuf_getcwd--unix_sockaddr_init--unix_stream_connect--send_request--do_cache--cmd_credential_cache--run_builtin--handle_builtin--run_argv--cmd_main--main--__libc_start_call_main--__libc_start_main@GLIBC_2.2.5--_start
    SUMMARY: LeakSanitizer: 129 byte(s) leaked in 1 allocation(s).

Fix this leak.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agolibgit: add higher-level libgit crate
Calvin Wan [Wed, 29 Jan 2025 21:50:44 +0000 (13:50 -0800)] 
libgit: add higher-level libgit crate

The C functions exported by libgit-sys do not provide an idiomatic Rust
interface. To make it easier to use these functions via Rust, add a
higher-level "libgit" crate, that wraps the lower-level configset API
with an interface that is more Rust-y.

This combination of $X and $X-sys crates is a common pattern for FFI in
Rust, as documented in "The Cargo Book" [1].

[1] https://doc.rust-lang.org/cargo/reference/build-scripts.html#-sys-packages

Co-authored-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Calvin Wan <calvinwan@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 months agolibgit-sys: also export some config_set functions
Josh Steadmon [Wed, 29 Jan 2025 21:50:43 +0000 (13:50 -0800)] 
libgit-sys: also export some config_set functions

In preparation for implementing a higher-level Rust API for accessing
Git configs, export some of the upstream configset API via libgitpub and
libgit-sys. Since this will be exercised as part of the higher-level API
in the next commit, no tests have been added for libgit-sys.

While we're at it, add git_configset_alloc() and git_configset_free()
functions in libgitpub so that callers can manage config_set structs on
the heap. This also allows non-C external consumers to treat config_sets
as opaque structs.

Co-authored-by: Calvin Wan <calvinwan@google.com>
Signed-off-by: Calvin Wan <calvinwan@google.com>
Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 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>
4 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"