]> git.ipfire.org Git - thirdparty/git.git/log
thirdparty/git.git
3 weeks agoconfig: store allocated string in non-const pointer
Jeff King [Thu, 26 Mar 2026 19:23:20 +0000 (15:23 -0400)] 
config: store allocated string in non-const pointer

When git-config matches a url, we copy the variable section name and
store it in the "section" member of a urlmatch_config struct. That
member is const, since the url-matcher will not touch it (and other
callers really will have a const string).

But that means that we have only a const pointer to our allocated
string. We have to cast away the constness when we free it, and likewise
when we assign NUL to tie off the "." separating the subsection and key.
This latter happens implicitly via a strchr() call, but recent versions
of glibc have added annotations that let the compiler detect that and
complain.

Let's keep our own "section" pointer for the non-const string, and then
just point config.section at it. That avoids all of the casting, both
explicit and implicit.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agorev-parse: avoid writing to const string for parent marks
Jeff King [Thu, 26 Mar 2026 19:14:24 +0000 (15:14 -0400)] 
rev-parse: avoid writing to const string for parent marks

The previous commit cleared up some const confusion in handling parent
marks in revision.c, but we have roughly the same code duplicated in
rev-parse. This one is much easier to fix, because the handling of the
shortened string is all done in one place, after detecting any marks
(but without shortening the string between marks).

  As a side note, I suspect this means that it behaves differently than
  the revision.c parser for weird stuff like "foo^!^@^-", but that is
  outside the scope of this patch.

While we are here, let's also rename the variable "dotdot", which is
totally misleading (and which we already fixed in revision.c long ago
via f632dedd8d (handle_revision_arg: stop using "dotdot" as a generic
pointer, 2017-05-19)).

Doing that here makes the diff a little messier, but it also lets the
compiler help us make sure we did not miss any stray mentions of the
variable while we are changing its semantics.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agorevision: avoid writing to const string for parent marks
Jeff King [Thu, 26 Mar 2026 19:13:18 +0000 (15:13 -0400)] 
revision: avoid writing to const string for parent marks

We take in a "const char *", but may write a NUL into it when parsing
parent marks like "foo^-", since we want to isolate "foo" as a string
for further parsing. This is usually OK, as our "const" strings are
often actually argv strings which are technically writeable, but we'd
segfault with a string literal like:

  handle_revision_arg("HEAD^-", &revs, 0, 0);

Similar to how we handled dotdot in a previous commit, we can avoid this
by making a temporary copy of the left-hand side of the string. The cost
should negligible compared to the rest of the parsing (like actually
parsing commits to create their parent linked-lists).

There is one slightly tricky thing, though. We parse some of the marks
progressively, so that if we see "foo^!" for example, we'll strip that
down to "foo" not just for calling add_parents_only(), but also for the
rest of the function. That makes sense since we eventually want to pass
"foo" to get_oid_with_context(). But it also means that we'll keep
looking for other marks. In particular, "foo^-^!" is valid, though oddly
"foo^!^-" would ignore the "^-". I'm not sure if this is a weird
historical artifact of the implementation, or if there are important
corner cases.

So I've left the behavior unchanged. Each mark we find allocates a
string with the mark stripped, which means we could allocate multiple
times (and carry a free-able pointer for each to the end). But in
practice we won't, because of the three marks, "^@" jumps immediately to
the end without further parsing, and "^-^!" is nonsense that nobody
would pass. So you'd get one allocation in general, and never more than
two.

Another obvious option would be to just copy "arg" up front and be OK
with munging it. But that means we pay the cost even when we find no
marks. We could make a single copy upon finding a mark and then munge,
but that adds extra code to each site (checking whether somebody else
allocated, and if not, adjusting our "mark" pointer to be relative to
the copied string).

I aimed for something that was clear and obvious, if a bit verbose.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agorev-parse: simplify dotdot parsing
Jeff King [Thu, 26 Mar 2026 19:05:25 +0000 (15:05 -0400)] 
rev-parse: simplify dotdot parsing

The previous commit simplified the way that revision.c parses ".." and
"..." range operators. But there's roughly similar code in rev-parse.
This is less likely to trigger a segfault, as there is no library
function which we'd pass a string literal to, but it still causes the
compiler to complain about laundering away constness via strstr().

Let's give it the same treatment, copying the left-hand side of the
range operator into its own string.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agorevision: make handle_dotdot() interface less confusing
Jeff King [Thu, 26 Mar 2026 19:04:44 +0000 (15:04 -0400)] 
revision: make handle_dotdot() interface less confusing

There are two very subtle bits to the way we parse ".." (and "...")
range operators:

 1. In handle_dotdot_1(), we assume that the incoming arguments "dotdot"
    and "arg" are part of the same string, with the first digit of the
    range-operator blanked to a NUL. Then when we want the full name
    (e.g., to report an error), we replace the NUL with a dot to restore
    the original string.

 2. In handle_dotdot(), we take in a const string, but then we modify it
    by overwriting the range operator with a NUL. This has worked OK in
    practice since we tend to pass in buffers that are actually
    writeable (including argv), but segfaults with something like:

      handle_revision_arg("..HEAD", &revs, 0, 0);

    On top of that, building with recent versions of glibc causes the
    compiler to complain, because it notices when we use strchr() or
    strstr() to launder away constness (basically detecting the
    possibility of the segfault above via the type system).

Instead of munging the buffer, let's instead make a temporary copy of
the left-hand side of the range operator. That avoids any const
violations, and lets us pass around the parsed elements independently:
the left-hand side, the right-hand side, the number of dots (via the
"symmetric" flag), and the original full string for error messages.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agofast-import: add 'abort-if-invalid' mode to '--signed-tags=<mode>'
Justin Tobler [Thu, 26 Mar 2026 19:14:14 +0000 (14:14 -0500)] 
fast-import: add 'abort-if-invalid' mode to '--signed-tags=<mode>'

In git-fast-import(1), the 'abort-if-invalid' mode for the
'--signed-commits' option verifies commit signatures during import and
aborts the entire operation when verification fails. Extend the same
behavior to signed tag objects by introducing an 'abort-if-invalid' mode
for the '--signed-tags' option.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agofast-import: add 'sign-if-invalid' mode to '--signed-tags=<mode>'
Justin Tobler [Thu, 26 Mar 2026 19:14:13 +0000 (14:14 -0500)] 
fast-import: add 'sign-if-invalid' mode to '--signed-tags=<mode>'

With ee66c793f8 (fast-import: add mode to sign commits with invalid
signatures, 2026-03-12), git-fast-import(1) learned to verify commit
signatures during import and replace signatures that fail verification
with a newly generated one. Extend the same behavior to signed tag
objects by introducing a 'sign-if-invalid' mode for the '--signed-tags'
option.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agofast-import: add 'strip-if-invalid' mode to '--signed-tags=<mode>'
Justin Tobler [Thu, 26 Mar 2026 19:14:12 +0000 (14:14 -0500)] 
fast-import: add 'strip-if-invalid' mode to '--signed-tags=<mode>'

With c20f112e51 (fast-import: add 'strip-if-invalid' mode to
--signed-commits=<mode>, 2025-11-17), git-fast-import(1) learned to
verify commit signatures during import and strip signatures that fail
verification. Extend the same behavior to signed tag objects by
introducing a 'strip-if-invalid' mode for the '--signed-tags' option.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agofast-import: add 'abort-if-invalid' mode to '--signed-commits=<mode>'
Justin Tobler [Thu, 26 Mar 2026 19:14:11 +0000 (14:14 -0500)] 
fast-import: add 'abort-if-invalid' mode to '--signed-commits=<mode>'

The '--signed-commits=<mode>' option for git-fast-import(1) configures
how signed commits are handled when encountered. In cases where an
invalid commit signature is encountered, a user may wish to abort the
operation entirely. Introduce an 'abort-if-invalid' mode to do so.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agofast-export: check for unsupported signing modes earlier
Justin Tobler [Thu, 26 Mar 2026 19:14:10 +0000 (14:14 -0500)] 
fast-export: check for unsupported signing modes earlier

The '--signed-{commits,tags}' options for git-fast-export(1) support
only a subset of the modes accepted by git-fast-import(1). Unsupported
modes such as 'strip-if-invalid' and 'sign-if-invalid' are accepted
during option parsing, but cause the command to die later when a signed
object is encountered.

Instead, reject unsupported signing modes immediately after parsing the
option. This treats them the same as other unknown modes and avoids
deferring the error until object processing. This also removes
duplicated checks in commit/tag handling code.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agot5620: test backfill's unknown argument handling
Derrick Stolee [Thu, 26 Mar 2026 15:14:54 +0000 (15:14 +0000)] 
t5620: test backfill's unknown argument handling

Before the recent changes to parse rev-list arguments inside of 'git
backfill', the builtin would take arbitrary arguments without complaint (and
ignore them). This was noticed and a patch was sent [1] which motivates
this change.

[1] https://lore.kernel.org/git/20260321031643.5185-1-r.siddharth.shrimali@gmail.com/

Note that the revision machinery can output an "ambiguous argument"
warning if a value not starting with '--' is found and doesn't make
sense as a reference or a pathspec. For unrecognized arguments starting
with '--' we need to add logic into builtin/backfill.c to catch leftover
arguments.

Reported-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agopath-walk: support wildcard pathspecs for blob filtering
Derrick Stolee [Thu, 26 Mar 2026 15:14:53 +0000 (15:14 +0000)] 
path-walk: support wildcard pathspecs for blob filtering

Previously, walk_objects_by_path() silently ignored pathspecs containing
wildcards or magic by clearing them. This caused all blobs to be
downloaded regardless of the given pathspec. Wildcard pathspecs like
"d/file.*.txt" are useful for narrowing which blobs to process (e.g.,
during 'git backfill').

Support wildcard pathspecs by making two changes:

 1. Add an 'exact_pathspecs' flag to path_walk_context. When the
    pathspec has no wildcards or magic, set this flag and use the
    existing fast-path prefix matching in add_tree_entries(). When
    wildcards are present, skip that block since prefix matching
    cannot handle glob patterns.

 2. Add a match_pathspec() check in walk_path() to filter out blobs
    whose full path does not match the pathspec. This provides the
    actual blob-level filtering for wildcard pathspecs.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agobackfill: work with prefix pathspecs
Derrick Stolee [Thu, 26 Mar 2026 15:14:52 +0000 (15:14 +0000)] 
backfill: work with prefix pathspecs

The previous change allowed specifying revision arguments over the 'git
backfill' command-line. This created the opportunity for restricting the
initial commit set by filtering the revision walk through a pathspec. Other
than filtering the commit set (and thereby the root trees), this did not
restrict the path-walk implementation of 'git backfill' and did not restrict
the blobs that were downloaded to only those matching the pathspec.

Update the path-walk API to accept certain kinds of pathspecs and to
silently ignore anything too complex, for now. We will update this in the
next change to properly restrict to even complex pathspecs.

The current behavior focuses on pathspecs that match paths exactly. This
includes exact filenames, including directory names as prefixes. Pathspecs
containing wildcards or magic are cleared so the path walk downloads all
blobs, as before.

The reason for this restriction is to allow for a faster execution by
pruning the path walk to only trees that could contribute towards one of
those paths as a parent directory.

The test directory 'd/f/' (next to 'd/file*.txt') was prepared in a
previous commit to exercise the subtlety in prefix matching.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agobackfill: accept revision arguments
Derrick Stolee [Thu, 26 Mar 2026 15:14:51 +0000 (15:14 +0000)] 
backfill: accept revision arguments

The existing implementation of 'git backfill' only includes downloading
missing blobs reachable from HEAD. Advanced uses may desire more general
commit limiting options, such as '--all' for all references, specifying a
commit range via negative references, or specifying a recency of use such as
with '--since=<date>'.

All of these options are available if we use setup_revisions() to parse the
unknown arguments with the revision machinery. This opens up a large number
of possibilities, only a small set of which are tested here.

For documentation, we avoid duplicating the option documentation and instead
link to the documentation of 'git rev-list'.

Note that these arguments currently allow specifying a pathspec, which
modifies the commit history checks but does not limit the paths used in the
backfill logic. This will be updated in a future change.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agot5620: prepare branched repo for revision tests
Derrick Stolee [Thu, 26 Mar 2026 15:14:50 +0000 (15:14 +0000)] 
t5620: prepare branched repo for revision tests

Prepare the test infrastructure for upcoming changes that teach 'git
backfill' to accept revision arguments and pathspecs.

Add test_tick before each commit in the setup loop so that commit dates
are deterministic. This enables reliable testing with '--since'.

Rename the 'd/e/' directory to 'd/f/' so that the prefix 'd/f' is
ambiguous with the files 'd/file.*.txt'. This exercises the subtlety
in prefix pathspec matching that will be added in a later commit.

Create a branched version of the test repository (src-revs) with:
 - A 'side' branch merged into main, adding s/file.{1,2}.txt with
   two versions (4 new blobs, 52 total from main HEAD).
 - An unmerged 'other' branch adding o/file.{1,2}.txt (2 more blobs,
   54 total reachable from --all).

This structure makes --all, --first-parent, and --since produce
meaningfully different results when used with 'git backfill'.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agorevision: include object-name.h
Derrick Stolee [Thu, 26 Mar 2026 15:14:49 +0000 (15:14 +0000)] 
revision: include object-name.h

The REV_INFO_INIT macro includes a use of the DEFAULT_ABBREV macro, which is
defined in object-name.h. Include it in revision.h so consumers of
REV_INFO_INIT do not need to include this hidden dependency.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoworktree: reject NULL worktree in get_worktree_git_dir()
Phillip Wood [Thu, 26 Mar 2026 14:16:59 +0000 (14:16 +0000)] 
worktree: reject NULL worktree in get_worktree_git_dir()

This removes the final dependence on "the_repository" in
get_worktree_git_dir(). The last commit removed only caller that
passed a NULL worktree.

get_worktree_git_dir() has the following callers:

 - branch.c:prepare_checked_out_branches() which loops over all
   worktrees.

 - builtin/fsck.c:cmd_fsck() which loops over all worktrees.

 - builtin/receive-pack.c:update_worktree() which is called from
   update() only when "worktree" is non-NULL.

 - builtin/worktree.c:validate_no_submodules() which is called from
   check_clean_worktree() and move_worktree(), both of which supply
   a non-NULL worktree.

 - reachable.c:add_rebase_files() which loops over all worktrees.

 - revision.c:add_index_objects_to_pending() which loops over all
   worktrees.

 - worktree.c:is_current_worktree() which expects a non-NULL worktree.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoworktree add: stop reading ".git/HEAD"
Phillip Wood [Thu, 26 Mar 2026 14:16:58 +0000 (14:16 +0000)] 
worktree add: stop reading ".git/HEAD"

The function can_use_local_refs() prints a warning if there are no local
branches and HEAD is invalid or points to an unborn branch. As part of
the warning it prints the contents of ".git/HEAD". In a repository using
the reftable backend HEAD is not stored in the filesystem so reading
that file is pointless. In a repository using the files backend it is
unclear how useful printing it is - it would be better to diagnose the
problem for the user. For now, simplify the warning by not printing
the file contents and adjust the relevant test case accordingly. Also
fixup the test case to use test_grep so that anyone trying to debug a
test failure in the future is not met by a wall of silence.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoworktree: remove "the_repository" from is_current_worktree()
Phillip Wood [Thu, 26 Mar 2026 14:16:57 +0000 (14:16 +0000)] 
worktree: remove "the_repository" from is_current_worktree()

The "is_current" member of struct worktree was added in 750e8a60d69
(worktree.c: mark current worktree, 2016-04-22) and was used in
8d9fdd7087d (worktree.c: check whether branch is rebased in another
worktree, 2016-04-22) to optionally skip the current worktree when
seeing if a branch is already checked out in die_if_checked_out().

To determine if a worktree is "current" is_current_worktree() compares
the gitdir of the worktree to the gitdir of "the_repository"
and returns true when they match. To get the gitdir of the
worktree it calls get_workree_git_dir() which also depends on
"the_repository". This means that even if "wt->path" matches
"wt->repo->worktree" is_current_worktree(wt) will return false when
"wt->repo" is not "the_repository". Consequently die_if_checked_out()
will fail to skip such a worktree when checking if a branch is already
checked out and may die errounously. Fix this by using the worktree's
repository instance instead of "the_repository" when comparing gitdirs.

The use of "the_repository" in is_current_wortree() comes from
replacing get_git_dir() with repo_get_git_dir() in 246deeac951
(environment: make `get_git_dir()` accept a repository, 2024-09-12). In
get_worktree_git_dir() it comes from replacing git_common_path() with
repo_common_path() in 07242c2a5af (path: drop `git_common_path()`
in favor of `repo_common_path()`, 2025-02-07). In both cases the
replacements appear to have been mechanical.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoregexp: leave a pointer to resurrect workaround for Homebrew
Junio C Hamano [Mon, 23 Mar 2026 16:54:42 +0000 (09:54 -0700)] 
regexp: leave a pointer to resurrect workaround for Homebrew

Recently some GitHub CI jobs were broken by update on the platform
side, which was eventually resolved by image rollback, but in the
meantime Dscho invented a workaround patch to sidestep the broken
part of the platform.  Their future image update may contain the
same bug, in which case the workaround may again become needed.

As we do not want to be building with workaround that avoids system
regexp library altogether unless the system is known to be broken,
so short of an automated "detect broken system and apply workaround"
mechanism, let's use the folks who are compiling the code to detect
breakage on their system and cope with the breakage ;-)

Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoMerge branch 'sa/replay-revert' into tc/replay-ref
Junio C Hamano [Wed, 25 Mar 2026 21:22:38 +0000 (14:22 -0700)] 
Merge branch 'sa/replay-revert' into tc/replay-ref

* sa/replay-revert:
  replay: add --revert mode to reverse commit changes
  sequencer: extract revert message formatting into shared function

3 weeks agoreplay: add --revert mode to reverse commit changes
Siddharth Asthana [Wed, 25 Mar 2026 20:23:52 +0000 (01:53 +0530)] 
replay: add --revert mode to reverse commit changes

Add a `--revert <branch>` mode to git replay that undoes the changes
introduced by the specified commits. Like --onto and --advance, --revert
is a standalone mode: it takes a branch argument and updates that branch
with the newly created revert commits.

At GitLab, we need this in Gitaly for reverting commits directly on bare
repositories without requiring a working tree checkout.

The approach is the same as sequencer.c's do_pick_commit() -- cherry-pick
and revert are just the same three-way merge with swapped arguments:

  - Cherry-pick: merge(ancestor=parent, ours=current, theirs=commit)
  - Revert: merge(ancestor=commit, ours=current, theirs=parent)

We swap the base and pickme trees passed to merge_incore_nonrecursive()
to reverse the diff direction.

Reverts are processed newest-first (matching git revert behavior) to
reduce conflicts by peeling off changes from the top. Each revert
builds on the result of the previous one via the last_commit fallback
in the main replay loop, rather than relying on the parent-mapping
used for cherry-pick.

Revert commit messages follow the usual git revert conventions: prefixed
with "Revert" (or "Reapply" when reverting a revert), and including
"This reverts commit <hash>.". The author is set to the current user
rather than preserving the original author, matching git revert behavior.

Helped-by: Christian Couder <christian.couder@gmail.com>
Helped-by: Patrick Steinhardt <ps@pks.im>
Helped-by: Elijah Newren <newren@gmail.com>
Helped-by: Phillip Wood <phillip.wood123@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Siddharth Asthana <siddharthasthana31@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agosequencer: extract revert message formatting into shared function
Siddharth Asthana [Wed, 25 Mar 2026 20:23:51 +0000 (01:53 +0530)] 
sequencer: extract revert message formatting into shared function

The logic for formatting revert commit messages (handling "Revert" and
"Reapply" cases, appending "This reverts commit <ref>.", and handling
merge-parent references) currently lives inline in do_pick_commit().
The upcoming replay --revert mode needs to reuse this logic.

Extract all of this into a new sequencer_format_revert_message()
function. The function takes a repository, the subject line, commit,
parent, a use_commit_reference flag, and the output strbuf. It handles
both regular reverts ("Revert "<subject>"") and revert-of-revert cases
("Reapply "<subject>""), and uses refer_to_commit() internally to
format the commit reference.

Update refer_to_commit() to take a struct repository parameter instead
of relying on the_repository, and a bool instead of reading from
replay_opts directly. This makes it usable from the new shared function
without pulling in sequencer-specific state.

Signed-off-by: Siddharth Asthana <siddharthasthana31@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agohook: reject unknown hook names in git-hook(1)
Adrian Ratiu [Wed, 25 Mar 2026 19:55:03 +0000 (21:55 +0200)] 
hook: reject unknown hook names in git-hook(1)

Teach "git hook run" and "git hook list" to reject hook event names
that are not recognized by Git. This helps catch typos such as
"prereceive" when "pre-receive" was intended, since in 99% of the
cases users want known (already-existing) hook names.

The list of known hooks is derived from the generated hook-list.h
(built from Documentation/githooks.adoc). This is why the Makefile
is updated, so builtin/hook.c depends on hook-list.h. In meson the
header is already a dependency for all builtins, no change required.

The "--allow-unknown-hook-name" flag can be used to bypass this check.

Suggested-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agohook: show disabled hooks in "git hook list"
Adrian Ratiu [Wed, 25 Mar 2026 19:55:02 +0000 (21:55 +0200)] 
hook: show disabled hooks in "git hook list"

Disabled hooks were filtered out of the cache entirely, making them
invisible to "git hook list". Keep them in the cache with a new
"disabled" flag which is propagated to the respective struct hook.

"git hook list" now shows disabled hooks as tab-separated columns,
with the status as a prefix before the name (like scope with
--show-scope). With --show-scope it looks like:

$ git hook list --show-scope pre-commit
global linter
local disabled no-leaks
hook from hookdir

A disabled hook without a command issues a warning instead of the
fatal "hook.X.command must be configured" error. We could also throw
an error, however it seemd a bit excessive to me in this case.

Suggested-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agohook: show config scope in git hook list
Adrian Ratiu [Wed, 25 Mar 2026 19:55:01 +0000 (21:55 +0200)] 
hook: show config scope in git hook list

Users running "git hook list" can see which hooks are configured but
have no way to tell at which config scope (local, global, system...)
each hook was defined.

Store the scope from ctx->kvi->scope in the single-pass config callback,
then carry it through the cache to the hook structs, so we can expose it
to users via the "git hook list --show-scope" flag, which mirrors the
existing git config --show-scope convention.

Without the flag the output is unchanged.

The scope is printed as a tab-separated prefix (like "git config --show-scope"),
making it unambiguously machine-parseable even when the friendly name
contains spaces.

Example usage:
$ git hook list --show-scope pre-commit
global linter
local no-leaks
hook from hookdir

Traditional hooks from the hookdir are unaffected by --show-scope since
the config scope concept does not apply to them.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agohook: introduce hook_config_cache_entry for per-hook data
Adrian Ratiu [Wed, 25 Mar 2026 19:55:00 +0000 (21:55 +0200)] 
hook: introduce hook_config_cache_entry for per-hook data

Replace the bare `char *command` util pointer stored in each string_list
item with a heap-allocated `struct hook_config_cache_entry` that carries
that command string.

This is just a refactoring with no behavior changes, to give the cache
entry room to grow, so it can carry the additional hook metadata we'll
be adding in the following commits.

Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agot1800: add test to verify hook execution ordering
Adrian Ratiu [Wed, 25 Mar 2026 19:54:59 +0000 (21:54 +0200)] 
t1800: add test to verify hook execution ordering

There is a documented expectation that configured hooks are
run before the hook from the hookdir. Add a test for it.

While at it, I noticed that `git hook list -h` runs twice
in the `git hook usage` test, so remove one invocation.

Suggested-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agohook: make consistent use of friendly-name in docs
Adrian Ratiu [Wed, 25 Mar 2026 19:54:58 +0000 (21:54 +0200)] 
hook: make consistent use of friendly-name in docs

Both `name` and `friendly-name` is being used. Standardize on
`friendly-name` for consistency since name is rather generic,
even when used in the hooks namespace.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agohook: replace hook_list_clear() -> string_list_clear_func()
Adrian Ratiu [Wed, 25 Mar 2026 19:54:57 +0000 (21:54 +0200)] 
hook: replace hook_list_clear() -> string_list_clear_func()

Replace the custom function with string_list_clear_func() which
is a more common pattern for clearing a string_list.

To be able to do this, rework hook_clear() into hook_free(), so
it can be passed to string_list_clear_func().

A slight complication is the need to keep a copy of the internal
cb data free() pointer, however I think it's worth it since the
API becomes cleaner, e.g. no more calls with NULL function args
like hook_list_clear(hooks, NULL).

In other words, the callers don't need to keep track of hook
internal state to determine when cleanup is necessary or not
(pass NULL) because each `struct hook` now owns its data_free
callback.

Suggested-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agohook: detect & emit two more bugs
Adrian Ratiu [Wed, 25 Mar 2026 19:54:56 +0000 (21:54 +0200)] 
hook: detect & emit two more bugs

Trigger a bug when an unknown hook type is encountered while
setting up hook execution.

Also issue a bug if a configured hook is enabled without a cmd.

Mostly useful for defensive coding.

Suggested-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agohook: rename cb_data_free/alloc -> hook_data_free/alloc
Adrian Ratiu [Wed, 25 Mar 2026 19:54:55 +0000 (21:54 +0200)] 
hook: rename cb_data_free/alloc -> hook_data_free/alloc

Rename the hook callback function types to use the hook prefix.

This is a style fix with no logic changes.

Suggested-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agohook: fix minor style issues
Adrian Ratiu [Wed, 25 Mar 2026 19:54:54 +0000 (21:54 +0200)] 
hook: fix minor style issues

Fix some minor style nits pointed out by Patrick, Junio and Eric:
  * Use CALLOC_ARRAY instead of xcalloc.
  * Init struct members during declaration.
  * Simplify if condition boolean logic.
  * Missing curly braces in if/else stmts.
  * Unnecessary header includes.
  * Capitalization and full-stop in error/warn messages.
  * Curly brace on separate line when defining struct.
  * Comment spelling: free'd -> freed.
  * Sort the included headers.
  * Blank line fixes to improve readability.

These contain no logic changes, the code behaves the same as before.

Suggested-by: Eric Sunshine <sunshine@sunshineco.com>
Suggested-by: Junio C Hamano <gitster@pobox.com>
Suggested-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agobuiltin/receive-pack: properly init receive_hook strbuf
Adrian Ratiu [Wed, 25 Mar 2026 19:54:53 +0000 (21:54 +0200)] 
builtin/receive-pack: properly init receive_hook strbuf

The run_receive_hook() stack-allocated `struct receive_hook_feed_state`
is a template with initial values for child states allocated on the heap
for each hook process, by calling receive_hook_feed_state_alloc() when
spinning up each hook child.

All these values are already initialized to zero, however I forgot to
properly initialize the strbuf, which I left NULL.

This is more of a code cleanup because in practice it has no effect,
the states used by the children are always initialized, however it's
good to fix in case someone ends up accidentally dereferencing the NULL
pointer in the future.

Reported-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agohook: move unsorted_string_list_remove() to string-list.[ch]
Adrian Ratiu [Wed, 25 Mar 2026 19:54:52 +0000 (21:54 +0200)] 
hook: move unsorted_string_list_remove() to string-list.[ch]

Move the convenience wrapper from hook to string-list since
it's a more suitable place. Add a doc comment to the header.

Also add a free_util arg to make the function more generic
and make the API similar to other functions in string-list.h.
Update the existing call-sites.

Suggested-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoThe 21st batch
Junio C Hamano [Wed, 25 Mar 2026 19:57:55 +0000 (12:57 -0700)] 
The 21st batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoMerge branch 'ps/object-counting'
Junio C Hamano [Wed, 25 Mar 2026 19:58:04 +0000 (12:58 -0700)] 
Merge branch 'ps/object-counting'

The logic to count objects has been cleaned up.

* ps/object-counting:
  odb: introduce generic object counting
  odb/source: introduce generic object counting
  object-file: generalize counting objects
  object-file: extract logic to approximate object count
  packfile: extract logic to count number of objects
  odb: stop including "odb/source.h"

3 weeks agoMerge branch 'tb/incremental-midx-part-3.2'
Junio C Hamano [Wed, 25 Mar 2026 19:58:04 +0000 (12:58 -0700)] 
Merge branch 'tb/incremental-midx-part-3.2'

Further work on incremental repacking using MIDX/bitmap

* tb/incremental-midx-part-3.2:
  midx: enable reachability bitmaps during MIDX compaction
  midx: implement MIDX compaction
  t/helper/test-read-midx.c: plug memory leak when selecting layer
  midx-write.c: factor fanout layering from `compute_sorted_entries()`
  midx-write.c: enumerate `pack_int_id` values directly
  midx-write.c: extract `fill_pack_from_midx()`
  midx-write.c: introduce `midx_pack_perm()` helper
  midx: do not require packs to be sorted in lexicographic order
  midx-write.c: introduce `struct write_midx_opts`
  midx-write.c: don't use `pack_perm` when assigning `bitmap_pos`
  t/t5319-multi-pack-index.sh: fix copy-and-paste error in t5319.39
  git-multi-pack-index(1): align SYNOPSIS with 'git multi-pack-index -h'
  git-multi-pack-index(1): remove non-existent incompatibility
  builtin/multi-pack-index.c: make '--progress' a common option
  midx: introduce `midx_get_checksum_hex()`
  midx: rename `get_midx_checksum()` to `midx_get_checksum_hash()`
  midx: mark `get_midx_checksum()` arguments as const

3 weeks agorepo: show subcommand-specific help text
Mahi Kassa [Wed, 25 Mar 2026 11:51:48 +0000 (12:51 +0100)] 
repo: show subcommand-specific help text

Use subcommand-specific usage arrays for "git repo info" and
"git repo structure" so that each command shows only its own
synopsis in help output.

Add tests to cover the subcommand help behavior.

Signed-off-by: Mahi Kassa <mahlet.takassa@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agorepo: factor repo usage strings into shared macros
Mahi Kassa [Wed, 25 Mar 2026 11:51:47 +0000 (12:51 +0100)] 
repo: factor repo usage strings into shared macros

Factor the "git repo info" and "git repo structure" usage
strings into shared macros so they can be reused in multiple
usage arrays.

This is a preparatory refactoring for subsequent changes to
subcommand-specific help output.

Signed-off-by: Mahi Kassa <mahlet.takassa@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agot0061: simplify .bat test
Jeff King [Wed, 25 Mar 2026 06:13:57 +0000 (02:13 -0400)] 
t0061: simplify .bat test

The test added by 71f4960b91 (t0061: fix test for argv[0] with spaces
(MINGW only), 2019-10-01) checks that we can use a .bat file with spaces
as GIT_SSH.

This is a good test in the sense that it's how the original bug was
detected. And as the commit message there describes, there are some
elements of the bug that are likely to come up with GIT_SSH and not
elsewhere: namely that in addition to the .bat file having spaces, we
must pass an argument with spaces (which happens naturally with ssh,
since we pass the upload-pack shell command for the other side to run).

But using GIT_SSH does complicate matters:

  1. We actually run the ssh command _twice_, once to probe the ssh
     variant with "-G" in fill_ssh_args(), and then a second time to
     actually make the connection. So we have to account for that when
     checking the output.

  2. Our fake ssh .bat file does not actually run ssh. So we expect the
     command to fail, but not before the .bat file has touched the "out"
     marker file that tells us it has run.

     This works now, but is fragile. In particular, the .bat file by
     default will echo commands it runs to stdout. From the perspective
     of the parent Git process, this is protocol-breaking garbage, and
     upon seeing it will die().

     That is OK for now because we don't bother to do any cleanup of the
     child process. But there is a patch under discussion, dd3693eb08
     (transport-helper, connect: use clean_on_exit to reap children on
     abnormal exit, 2026-03-12), which causes us to kill() the .bat
     process. This happens before it actually touches the "out" file,
     causing the test to fail.

We can simplify this by just using the "test-tool run-command" helper.
That lets us run whatever command we like with the arguments we want.
The argument here has a space, which is enough to trigger the original
bug that 71f4960b91 was testing. I verified that by reverting eb7c786314
(mingw: support spawning programs containing spaces in their names,
2019-07-16), the original fix, and confirming that the test fails (but
succeeds without the revert).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoreplay: support replaying down from root commit
Toon Claes [Tue, 24 Mar 2026 19:35:41 +0000 (20:35 +0100)] 
replay: support replaying down from root commit

git-replay(1) doesn't allow replaying commits all the way down to the
root commit. Fix that.

Signed-off-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoThe 20th batch
Junio C Hamano [Tue, 24 Mar 2026 19:31:15 +0000 (12:31 -0700)] 
The 20th batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoMerge branch 'dd/cocci-do-not-pass-strbuf-by-value'
Junio C Hamano [Tue, 24 Mar 2026 19:31:34 +0000 (12:31 -0700)] 
Merge branch 'dd/cocci-do-not-pass-strbuf-by-value'

Add a coccinelle rule to break the build when "struct strbuf" gets
passed by value.

* dd/cocci-do-not-pass-strbuf-by-value:
  stash: do not pass strbuf by value
  coccinelle: detect struct strbuf passed by value

3 weeks agoMerge branch 'ty/doc-diff-u-wo-number'
Junio C Hamano [Tue, 24 Mar 2026 19:31:34 +0000 (12:31 -0700)] 
Merge branch 'ty/doc-diff-u-wo-number'

"git diff -U<num>" was too lenient in its command line parsing and
took an empty string as a valid <num>.

* ty/doc-diff-u-wo-number:
  diff: document -U without <n> as using default context

3 weeks agoMerge branch 'ps/upload-pack-buffer-more-writes'
Junio C Hamano [Tue, 24 Mar 2026 19:31:34 +0000 (12:31 -0700)] 
Merge branch 'ps/upload-pack-buffer-more-writes'

Reduce system overhead "git upload-pack" spends on relaying "git
pack-objects" output to the "git fetch" running on the other end of
the connection.

* ps/upload-pack-buffer-more-writes:
  builtin/pack-objects: reduce lock contention when writing packfile data
  csum-file: drop `hashfd_throughput()`
  csum-file: introduce `hashfd_ext()`
  sideband: use writev(3p) to send pktlines
  wrapper: introduce writev(3p) wrappers
  compat/posix: introduce writev(3p) wrapper
  upload-pack: reduce lock contention when writing packfile data
  upload-pack: prefer flushing data over sending keepalive
  upload-pack: adapt keepalives based on buffering
  upload-pack: fix debug statement when flushing packfile data

3 weeks agoMerge branch 'yc/histogram-hunk-shift-fix'
Junio C Hamano [Tue, 24 Mar 2026 19:31:34 +0000 (12:31 -0700)] 
Merge branch 'yc/histogram-hunk-shift-fix'

The final clean-up phase of the diff output could turn the result of
histogram diff algorithm suboptimal, which has been corrected.

* yc/histogram-hunk-shift-fix:
  xdiff: re-diff shifted change groups when using histogram algorithm

3 weeks agoMerge branch 'mf/t0008-cleanup'
Junio C Hamano [Tue, 24 Mar 2026 19:31:33 +0000 (12:31 -0700)] 
Merge branch 'mf/t0008-cleanup'

Test clean-up.

* mf/t0008-cleanup:
  t0008: improve test cleanup to fix failing test

3 weeks agoMerge branch 'pb/t4200-test-path-is-helpers'
Junio C Hamano [Tue, 24 Mar 2026 19:31:33 +0000 (12:31 -0700)] 
Merge branch 'pb/t4200-test-path-is-helpers'

Test clean-up.

* pb/t4200-test-path-is-helpers:
  t4200: convert test -[df] checks to test_path_* helpers

3 weeks agoMerge branch 'jk/transport-color-leakfix'
Junio C Hamano [Tue, 24 Mar 2026 19:31:33 +0000 (12:31 -0700)] 
Merge branch 'jk/transport-color-leakfix'

Leakfix.

* jk/transport-color-leakfix:
  transport: plug leaks in transport_color_config()

3 weeks agoMerge branch 'rj/pack-refs-tests-path-is-helpers'
Junio C Hamano [Tue, 24 Mar 2026 19:31:33 +0000 (12:31 -0700)] 
Merge branch 'rj/pack-refs-tests-path-is-helpers'

Test updates.

* rj/pack-refs-tests-path-is-helpers:
  t/pack-refs-tests: use test_path_is_missing

3 weeks agoMerge branch 'ps/history-split'
Junio C Hamano [Tue, 24 Mar 2026 19:31:32 +0000 (12:31 -0700)] 
Merge branch 'ps/history-split'

"git history" learned the "split" subcommand.

* ps/history-split:
  builtin/history: implement "split" subcommand
  builtin/history: split out extended function to create commits
  cache-tree: allow writing in-memory index as tree
  add-patch: allow disabling editing of hunks
  add-patch: add support for in-memory index patching
  add-patch: remove dependency on "add-interactive" subsystem
  add-patch: split out `struct interactive_options`
  add-patch: split out header from "add-interactive.h"

3 weeks agoMerge branch 'ps/clar-wo-path-max'
Junio C Hamano [Tue, 24 Mar 2026 19:31:32 +0000 (12:31 -0700)] 
Merge branch 'ps/clar-wo-path-max'

Clar (unit testing framework) update from the upstream.

* ps/clar-wo-path-max:
  clar: update to fix compilation on platforms without PATH_MAX

3 weeks agoMerge branch 'ss/t0410-delete-object-cleanup'
Junio C Hamano [Tue, 24 Mar 2026 19:31:31 +0000 (12:31 -0700)] 
Merge branch 'ss/t0410-delete-object-cleanup'

Test clean-up.

* ss/t0410-delete-object-cleanup:
  t0410: modernize delete_object helper

3 weeks agoMerge branch 'gj/user-manual-fix-grep-example'
Junio C Hamano [Tue, 24 Mar 2026 19:31:32 +0000 (12:31 -0700)] 
Merge branch 'gj/user-manual-fix-grep-example'

Fix an example in the user-manual.

* gj/user-manual-fix-grep-example:
  doc: fix git grep args order in Quick Reference

3 weeks agoMerge branch 'jt/fast-import-sign-again'
Junio C Hamano [Tue, 24 Mar 2026 19:31:31 +0000 (12:31 -0700)] 
Merge branch 'jt/fast-import-sign-again'

"git fast-import" learned to optionally replace signature on
commits whose signatures get invalidated due to replaying by
signing afresh.

* jt/fast-import-sign-again:
  fast-import: add mode to sign commits with invalid signatures
  gpg-interface: allow sign_buffer() to use default signing key
  commit: remove unused forward declaration

3 weeks agouse strvec_pushv() to add another strvec
Junio C Hamano [Tue, 24 Mar 2026 19:26:58 +0000 (12:26 -0700)] 
use strvec_pushv() to add another strvec

Add and apply a semantic patch that simplifies the code by letting
strvec_pushv() append the items of a second strvec instead of pushing
them one by one.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 weeks agoMerge branch 'ps/build-tweaks' into rs/use-strvec-pushv
Junio C Hamano [Tue, 24 Mar 2026 19:25:21 +0000 (12:25 -0700)] 
Merge branch 'ps/build-tweaks' into rs/use-strvec-pushv

The topic moves the coccinelle rules from contrib/ to tools/
directory, breaking merges with this topic.

* ps/build-tweaks:
  meson: precompile "git-compat-util.h"
  meson: compile compatibility sources separately
  git-compat-util.h: move warning infra to prepare for PCHs
  builds: move build scripts into "tools/"
  contrib: move "update-unicode.sh" script into "tools/"
  contrib: move "coverage-diff.sh" script into "tools/"
  contrib: move "coccinelle/" directory into "tools/"
  Introduce new "tools/" directory

3 weeks agocommit-graph: fix writing generations with dates exceeding 34 bits
Patrick Steinhardt [Tue, 24 Mar 2026 06:18:26 +0000 (07:18 +0100)] 
commit-graph: fix writing generations with dates exceeding 34 bits

The `timestamp_t` type is declared as `uintmax_t` and thus typically has
64 bits of precision. Usually, the full precision of such dates is not
required: it would be comforting to know that Git is still around in
millions of years, but all in all the chance is rather low.

We abuse this fact in the commit-graph: instead of storing the full 64
bits of precision, committer dates only store 34 bits. This is still
plenty of headroom, as it means that we can represent dates until year
2514. Commits which are dated beyond that year will simply get a date
whose remaining bits are masked.

The result of this is somewhat curious: the committer date will be
different depending on whether a commit gets parsed via the commit-graph
or via the object database. This isn't really too much of an issue in
general though, as we don't typically use the date parsed from the
commit-graph in user-facing output.

But with 024b4c9697 (commit: make `repo_parse_commit_no_graph()` more
robust, 2026-02-16) it started to become a problem when writing the
commit-graph itself. This commit changed `repo_parse_commit_no_graph()`
so that we re-parse the commit via the object database in case it was
already parsed beforehand via the commit-graph.

The consequence is that we may now act with two different commit dates
at different stages:

  - Initially, we use the 34-bit precision timestamp when writing the
    chunk generation data. We thus correctly compute the offsets
    relative to the on-disk timestamp here.

  - Later, when writing the overflow data, we may end up with the
    full-precision timestamp. When the date is larger than 34 bits the
    result of this is an underflow when computing the offset.

This causes a mismatch in the number of generation data overflow records
we want to write, and that ultimately causes Git to die.

Introduce a new helper function that computes the generation offset for
a commit while correctly masking the date to 34 bits. This makes the
previously-implicit assumptions about the commit date precision explicit
and thus hopefully less fragile going forward.

Adapt sites that compute the offset to use the function.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agorefspec: fix typo in comment
K Jayatheerth [Tue, 24 Mar 2026 01:57:34 +0000 (07:27 +0530)] 
refspec: fix typo in comment

Fix a long-standing typo in a comment: "refpsecs" -> "refspecs".

Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agoremote-curl: fall back to default hash outside repo
K Jayatheerth [Tue, 24 Mar 2026 01:57:33 +0000 (07:27 +0530)] 
remote-curl: fall back to default hash outside repo

When a remote helper like git-remote-http is invoked outside of a
repository (for example, by running git ls-remote in a non-git
directory), setup_git_directory_gently() leaves the_hash_algo
uninitialized as NULL.

If the user has a globally configured fetch refspec, remote-curl
attempts to parse it during initialization. Inside parse_refspec(),
it checks whether the LHS of the refspec is an exact OID by evaluating
llen == the_hash_algo->hexsz. Because the_hash_algo is NULL, this
results in a segmentation fault.

In 9e89dcb66a (builtin/ls-remote: fall back to SHA1 outside of a repo,
2024-08-02), we added a workaround to ls-remote to fall back to the
default hash algorithm to prevent exactly this type of crash when
parsing refspec capabilities. However, because remote-curl runs as a
separate process, it does not inherit that fallback and crashes anyway.

Instead of pushing a NULL-guard workaround down into parse_refspec(),
fix this by mirroring the ls-remote workaround directly in
remote-curl.c. If we are operating outside a repository, initialize
the_hash_algo to GIT_HASH_DEFAULT. This keeps the HTTP transport
consistent with non-HTTP transports that execute in-process, preventing
crashes without altering the generic refspec parsing logic.

Reported-by: Jo Liss <joliss@gmail.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agoformat-patch: --commit-list-format without prefix
Mirko Faina [Mon, 23 Mar 2026 16:57:35 +0000 (17:57 +0100)] 
format-patch: --commit-list-format without prefix

Having to prefix a custom format-string with "log:" when passed from the
CLI can be annoying. It would be great if this prefix wasn't required.

Teach make_cover_letter() to accept custom format-strings without the
"log:" prefix if a placeholder is detected.

Note that both here and in "git log --format" the check is done naively
by just checking for the presence of a '%'.

Signed-off-by: Mirko Faina <mroik@delayed.space>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agoformat-patch: add preset for --commit-list-format
Mirko Faina [Mon, 23 Mar 2026 16:57:34 +0000 (17:57 +0100)] 
format-patch: add preset for --commit-list-format

"git format-patch --commit-list-format" enables the user to make their
own format for the commit list in the cover letter. It would be nice to
have a ready to use format to replace shortlog.

Teach make_cover_letter() the "modern" format preset.
This new format is the same as: "log:[%(count)/%(total)] %s".

Signed-off-by: Mirko Faina <mroik@delayed.space>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agoformat-patch: wrap generate_commit_list_cover()
Mirko Faina [Mon, 23 Mar 2026 16:57:33 +0000 (17:57 +0100)] 
format-patch: wrap generate_commit_list_cover()

While most conventions should not allow for the text lines in commit
messages to get too long, when they do it could make emails harder to
read.

Teach generate_commit_list_cover() to wrap its commit lines if they are
too long.

Signed-off-by: Mirko Faina <mroik@delayed.space>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agoformat.commitListFormat: strip meaning from empty
Mirko Faina [Mon, 23 Mar 2026 16:57:32 +0000 (17:57 +0100)] 
format.commitListFormat: strip meaning from empty

The configuration variable format.commitListFormat allows for an empty
value. This is unusual and can create issues when interacting with this
configuration variable through the CLI.

Strip meaning to format.commitListFormat with an empty value.

Signed-off-by: Mirko Faina <mroik@delayed.space>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agodocs/pretty-formats: add %(count) and %(total)
Mirko Faina [Mon, 23 Mar 2026 16:57:31 +0000 (17:57 +0100)] 
docs/pretty-formats: add %(count) and %(total)

When --commit-list-format was introduced to format-patch, two new
placeholders were added to the PRETTY FORMATS code without being
documented. Do so now.

Signed-off-by: Mirko Faina <mroik@delayed.space>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agoformat-patch: rename --cover-letter-format option
Mirko Faina [Mon, 23 Mar 2026 16:57:30 +0000 (17:57 +0100)] 
format-patch: rename --cover-letter-format option

To align the name of the configuration variable and the name of the
command line option, either one should change name. By changing the name
of the option we get the added benefit of having --cover-<TAB> expand to
--cover-letter without ambiguity.

If the user gives the --cover-letter-format option it would be
reasonable to expect that the user wants to generate the cover letter
despite not giving --cover-letter.

Rename --cover-letter-format to --commit-list-format and make it imply
--cover-letter unless --no-cover-letter is given.

Signed-off-by: Mirko Faina <mroik@delayed.space>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agoformat-patch: refactor generate_commit_list_cover
Mirko Faina [Mon, 23 Mar 2026 16:57:29 +0000 (17:57 +0100)] 
format-patch: refactor generate_commit_list_cover

Refactor for readability and remove unnecessary initialization.

Signed-off-by: Mirko Faina <mroik@delayed.space>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agopretty.c: better die message %(count) and %(total)
Mirko Faina [Mon, 23 Mar 2026 16:57:28 +0000 (17:57 +0100)] 
pretty.c: better die message %(count) and %(total)

Improve die messages for commands that do not support %(count) and
%(total)

Signed-off-by: Mirko Faina <mroik@delayed.space>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agoThe 19th batch
Junio C Hamano [Mon, 23 Mar 2026 16:20:08 +0000 (09:20 -0700)] 
The 19th batch

Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agoMerge branch 'ty/mktree-wo-the-repository'
Junio C Hamano [Mon, 23 Mar 2026 16:20:31 +0000 (09:20 -0700)] 
Merge branch 'ty/mktree-wo-the-repository'

Code clean-up.

* ty/mktree-wo-the-repository:
  builtin/mktree: remove USE_THE_REPOSITORY_VARIABLE

4 weeks agoMerge branch 'bb/imap-send-openssl-4.0-prep'
Junio C Hamano [Mon, 23 Mar 2026 16:20:31 +0000 (09:20 -0700)] 
Merge branch 'bb/imap-send-openssl-4.0-prep'

"imap-send" used to use functions whose use is going to be removed
with OpenSSL 4.0; rewrite them using public API that has been
available since OpenSSL 1.1 since 2016 or so.

* bb/imap-send-openssl-4.0-prep:
  imap-send: move common code into function host_matches()
  imap-send: use the OpenSSL API to access the subject common name
  imap-send: use the OpenSSL API to access the subject alternative names

4 weeks agoMerge branch 'ac/help-sort-correctly'
Junio C Hamano [Mon, 23 Mar 2026 16:20:30 +0000 (09:20 -0700)] 
Merge branch 'ac/help-sort-correctly'

The code in "git help" that shows configuration items in sorted
order was awkwardly organized and prone to bugs.

* ac/help-sort-correctly:
  help: cleanup the contruction of keys_uniq

4 weeks agoMerge branch 'jc/test-allow-sed-with-ere'
Junio C Hamano [Mon, 23 Mar 2026 16:20:30 +0000 (09:20 -0700)] 
Merge branch 'jc/test-allow-sed-with-ere'

Adjust test-lint to allow "sed -E" to use ERE in the patterns.

* jc/test-allow-sed-with-ere:
  t: allow use of "sed -E"

4 weeks agoMerge branch 'ng/submodule-default-remote'
Junio C Hamano [Mon, 23 Mar 2026 16:20:30 +0000 (09:20 -0700)] 
Merge branch 'ng/submodule-default-remote'

Instead of hardcoded 'origin', use the configured default remote
when fetching from submodules.

* ng/submodule-default-remote:
  submodule: fetch missing objects from default remote

4 weeks agoMerge branch 'ms/t7605-test-path-is-helpers'
Junio C Hamano [Mon, 23 Mar 2026 16:20:30 +0000 (09:20 -0700)] 
Merge branch 'ms/t7605-test-path-is-helpers'

Test updates.

* ms/t7605-test-path-is-helpers:
  t7605: use test_path_is_file instead of test -f

4 weeks agoMerge branch 'cf/constness-fixes'
Junio C Hamano [Mon, 23 Mar 2026 16:20:29 +0000 (09:20 -0700)] 
Merge branch 'cf/constness-fixes'

Small code clean-up around the constness area.

* cf/constness-fixes:
  dir: avoid -Wdiscarded-qualifiers in remove_path()
  bloom: remove a misleading const qualifier

4 weeks agobuiltin/fsck: stop using `the_repository` in error reporting
Patrick Steinhardt [Mon, 23 Mar 2026 15:03:03 +0000 (16:03 +0100)] 
builtin/fsck: stop using `the_repository` in error reporting

In the preceding commit we have introduced the repository into `struct
fsck_object_report`. This allows us to drop remaining uses of the global
`the_repository` variable.

Drop them and remove `USE_THE_REPOSITORY_VARIABLE`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agobuiltin/fsck: stop using `the_repository` when marking objects
Patrick Steinhardt [Mon, 23 Mar 2026 15:03:02 +0000 (16:03 +0100)] 
builtin/fsck: stop using `the_repository` when marking objects

We implicitly rely on `the_repository` when marking objects for
connectivity. Refactor this to instead inject the repository via the
callback payload.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agobuiltin/fsck: stop using `the_repository` when checking packed objects
Patrick Steinhardt [Mon, 23 Mar 2026 15:03:01 +0000 (16:03 +0100)] 
builtin/fsck: stop using `the_repository` when checking packed objects

We implicitly rely on `the_repository` when checking objects part of a
packfile. These objects are iterated over via `verify_pack()`, which is
provided by the packfile subsystem, and a callback function is then
invoked for each of the objects in that specific pack.

Unfortunately, it is not possible to provide a payload to the callback
function. Refactor `verify_pack()` to accept a payload that is passed
through to the callback so that we can inject the repository and get rid
of the use of `the_repository`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agobuiltin/fsck: stop using `the_repository` with loose objects
Patrick Steinhardt [Mon, 23 Mar 2026 15:03:00 +0000 (16:03 +0100)] 
builtin/fsck: stop using `the_repository` with loose objects

We depend on `the_repository` when performing consistency checks for
loose objects. Refactor this to use a context-provided repository
instead that is injected via the `struct for_each_loose_cb`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agobuiltin/fsck: stop using `the_repository` when checking reflogs
Patrick Steinhardt [Mon, 23 Mar 2026 15:02:59 +0000 (16:02 +0100)] 
builtin/fsck: stop using `the_repository` when checking reflogs

We implicitly rely on `the_repository` when checking reflogs. Refactor
this to instead inject the repository via the callback payload.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agobuiltin/fsck: stop using `the_repository` when checking refs
Patrick Steinhardt [Mon, 23 Mar 2026 15:02:58 +0000 (16:02 +0100)] 
builtin/fsck: stop using `the_repository` when checking refs

We implicitly rely on `the_repository` when checking refs. Refactor this
to instead inject the repository via the callback payload.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agobuiltin/fsck: stop using `the_repository` when snapshotting refs
Patrick Steinhardt [Mon, 23 Mar 2026 15:02:57 +0000 (16:02 +0100)] 
builtin/fsck: stop using `the_repository` when snapshotting refs

We depedn on `the_repository` when snapshotting refs. Refactor this to
use a context-provided repository instead that is injected via the
`struct snapshot_ref_data`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agobuiltin/fsck: fix trivial dependence on `the_repository`
Patrick Steinhardt [Mon, 23 Mar 2026 15:02:56 +0000 (16:02 +0100)] 
builtin/fsck: fix trivial dependence on `the_repository`

We have a bunch of sites in "builtin/fsck.c" that depend on
`the_repository` even though we already have a repository available, or
in cases where we can trivially make it available.

Refactor such sites to use the context-provided repository instead.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agofsck: drop USE_THE_REPOSITORY
Patrick Steinhardt [Mon, 23 Mar 2026 15:02:55 +0000 (16:02 +0100)] 
fsck: drop USE_THE_REPOSITORY

Stop using `the_repository` in "fsck.c" in favor of the repository that
we've already got available via `struct fsck_options`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agofsck: store repository in fsck options
Patrick Steinhardt [Mon, 23 Mar 2026 15:02:54 +0000 (16:02 +0100)] 
fsck: store repository in fsck options

The fsck subsystem relies on `the_repository` quite a bit. While we
could of course explicitly pass a repository down the callchain, we
already have a `struct fsck_options` that we pass to almost all
functions.

Extend the options to also store the repository to make it readily
available.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agofsck: initialize fsck options via a function
Patrick Steinhardt [Mon, 23 Mar 2026 15:02:53 +0000 (16:02 +0100)] 
fsck: initialize fsck options via a function

We initialize the `struct fsck_options` via a set of macros, often in
global scope. In the next commit though we're about to introduce a new
repository field to the options that must be initialized, and naturally
we don't have a repo other than `the_repository` available in this
scope.

Refactor the code to instead intrdouce a new `fsck_options_init()`
function that initializes the options for us and move initialization
into function scope.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agofetch-pack: move fsck options into function scope
Patrick Steinhardt [Mon, 23 Mar 2026 15:02:52 +0000 (16:02 +0100)] 
fetch-pack: move fsck options into function scope

When fetching a packfile, we optionally verify received objects via the
fsck subsystem. The options for those consistency checks are declared in
global scope without a good reason, and they are never cleaned up. So in
case the options are reused, they may accumulate more state over time.

Furthermore, in subsequent changes we'll introduce a repository pointer
into the structure. Obviously though, we don't have a repository
available at static time, except for `the_repository`, which we don't
want to use here.

Refactor the code to move the options into the respective functions and
properly manage their lifecycle.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agodiff-highlight: fetch all config with one process
Jeff King [Mon, 23 Mar 2026 06:02:18 +0000 (02:02 -0400)] 
diff-highlight: fetch all config with one process

When diff-highlight was written, there was no way to fetch multiple
config keys _and_ have them interpreted as colors. So we were stuck
with either invoking git-config once for each config key, or fetching
them all and converting human-readable color names into ANSI codes
ourselves.

I chose the former, but it means that diff-highlight kicks off 6
git-config processes (even if you haven't configured anything, it has to
check each one).

But since Git 2.18.0, we can do:

   git config --type=color --get-regexp=^color\.diff-highlight\.

to get all of them in one shot.

Note that any callers which pass in colors directly to the module via
@OLD_HIGHLIGHT and @NEW_HIGHLIGHT (like diff-so-fancy plans to do) are
unaffected; those colors suppress any config lookup we'd do ourselves.

You can see the effect like:

  # diff-highlight suppresses git-config's stderr, so dump
  # trace through descriptor 3
  git show d1f33c753d | GIT_TRACE=3 diff-highlight 3>&2 >/dev/null

which drops from 6 lines down to 1.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agodiff-highlight: allow module callers to pass in color config
Scott Baker [Mon, 23 Mar 2026 06:02:15 +0000 (02:02 -0400)] 
diff-highlight: allow module callers to pass in color config

Users of the module may want to pass in their own color config for a few
obvious reasons:

  - they are pulling the config from different variables than
    diff-highlight itself uses

  - they are loading the config in a more efficient way (say, by parsing
    git-config --list) and don't want to incur the six (!) git-config
    calls that DiffHighlight.pm runs to check all config

Let's allow users of the module to pass in the color config, and
lazy-load it when needed if they haven't.

Signed-off-by: Scott Baker <scott@perturb.org>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agodiff-highlight: test color config
Jeff King [Mon, 23 Mar 2026 06:02:13 +0000 (02:02 -0400)] 
diff-highlight: test color config

We added configurable colors long ago in bca45fbc1f (diff-highlight:
allow configurable colors, 2014-11-20), but never actually tested it.
Since we'll be touching the color code in a moment, this is a good time
to beef up the tests.

Note that we cover both the highlight/reset style used by the default
colors, as well as the normal/highlight style added by that commit
(which was previously totally untested).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agodiff-highlight: use test_decode_color in tests
Jeff King [Mon, 23 Mar 2026 06:02:10 +0000 (02:02 -0400)] 
diff-highlight: use test_decode_color in tests

The diff-highlight tests use raw color bytes when comparing expected and
actual output. Let's use test_decode_color, which is our usual technique
in other tests. It makes reading test output diffs a bit easier, since
you're not relying on your terminal to interpret the result (or worse,
interpreting characters yourself via "cat -A").

This will also make it easier to add tests with new colors/attributes,
without having to pre-define the byte sequences ourselves.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agot: add matching negative attributes to test_decode_color
Jeff King [Mon, 23 Mar 2026 06:02:07 +0000 (02:02 -0400)] 
t: add matching negative attributes to test_decode_color

Most of the ANSI color attributes have an "off" variant. We don't use
these yet in our test suite, so we never bothered to decode them. Add
the ones that match the attributes we encode so we can make use of them.

There are even more attributes not covered on the positive side, so this
is meant to be useful but not all-inclusive.

Note that "nobold" and "nodim" are the same code, so I've decoded this
as "normal intensity".

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agodiff-highlight: check diff-highlight exit status in tests
Jeff King [Mon, 23 Mar 2026 06:02:05 +0000 (02:02 -0400)] 
diff-highlight: check diff-highlight exit status in tests

When testing diff-highlight, we pipe the output through a sanitizing
function. This loses the exit status of diff-highlight itself, which
could mean we are missing cases where it crashes or exits unexpectedly.
Use an extra tempfile to avoid the pipe.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agodiff-highlight: drop perl version dependency back to 5.8
Scott Baker [Mon, 23 Mar 2026 06:02:02 +0000 (02:02 -0400)] 
diff-highlight: drop perl version dependency back to 5.8

The diff-highlight code does not rely on any perl features beyond what
perl 5.8 provides. We bumped it to v5.26 along with the rest of the
project's perl scripts in 702d8c1f3b (Require Perl 5.26.0, 2024-10-23).

There's some value in just having a uniform baseline for the project,
but I think diff-highlight is special here:

  - it's in a contrib/ directory that is not frequently touched, so
    there is little risk of Git developers getting annoyed that modern
    perl features are not available

  - it provides a module used by other projects. In particular,
    diff-so-fancy relies on DiffHighlight.pm but does not otherwise
    require a perl version more modern than 5.8.

Let's drop back to the more conservative requirement.

Signed-off-by: Scott Baker <scott@perturb.org>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agodiff-highlight: mention build instructions
Jeff King [Mon, 23 Mar 2026 06:01:58 +0000 (02:01 -0400)] 
diff-highlight: mention build instructions

Once upon a time, this was just a script in a directory that could be
run directly. That changed in 0c977dbc81 (diff-highlight: split code
into module, 2017-06-15). Let's update the README to make it more clear
that you need to run make.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
4 weeks agoMerge branch 'master' of https://github.com/j6t/git-gui
Junio C Hamano [Sat, 21 Mar 2026 16:25:58 +0000 (09:25 -0700)] 
Merge branch 'master' of https://github.com/j6t/git-gui

* 'master' of https://github.com/j6t/git-gui:
  git-gui: grey out comment lines in commit message
  git-gui: wire up "git-gui--askyesno" with Meson
  git-gui: massage "git-gui--askyesno" with "generate-script.sh"
  git-gui: prefer shell at "/bin/sh" with Meson
  git-gui: fix use of GIT_CEILING_DIRECTORIES
  git-gui: shift tabstops to account for the first column of patch text

4 weeks agoMerge branch 'master' of https://github.com/j6t/gitk
Junio C Hamano [Sat, 21 Mar 2026 16:25:10 +0000 (09:25 -0700)] 
Merge branch 'master' of https://github.com/j6t/gitk

* 'master' of https://github.com/j6t/gitk:
  gitk: l10n: make PO headers identify the Gitk project
  gitk: ignore generated POT file
  gitk: i18n: use "Gitk" as package name in POT file
  gitk: commit translation files without file information
  gitk: support link color in the Preferences dialog
  gitk: use config settings for head/tag colors

4 weeks agoodb: introduce generic `odb_find_abbrev_len()`
Patrick Steinhardt [Fri, 20 Mar 2026 07:07:40 +0000 (08:07 +0100)] 
odb: introduce generic `odb_find_abbrev_len()`

Introduce a new generic `odb_find_abbrev_len()` function as well as
source-specific callback functions. This makes the logic to compute the
required prefix length to make a given object unique fully pluggable.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>