aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2026-03-25hook: reject unknown hook names in git-hook(1)Adrian Ratiu
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>
2026-03-25hook: show disabled hooks in "git hook list"Adrian Ratiu
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>
2026-03-25hook: show config scope in git hook listAdrian Ratiu
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>
2026-03-25hook: introduce hook_config_cache_entry for per-hook dataAdrian Ratiu
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>
2026-03-25t1800: add test to verify hook execution orderingAdrian Ratiu
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>
2026-03-25hook: make consistent use of friendly-name in docsAdrian Ratiu
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>
2026-03-25hook: replace hook_list_clear() -> string_list_clear_func()Adrian Ratiu
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>
2026-03-25hook: detect & emit two more bugsAdrian Ratiu
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>
2026-03-25hook: rename cb_data_free/alloc -> hook_data_free/allocAdrian Ratiu
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>
2026-03-25hook: fix minor style issuesAdrian Ratiu
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>
2026-03-25builtin/receive-pack: properly init receive_hook strbufAdrian Ratiu
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>
2026-03-25hook: move unsorted_string_list_remove() to string-list.[ch]Adrian Ratiu
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>
2026-03-25The 21st batchJunio C Hamano
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-03-25Merge branch 'ps/object-counting'Junio C Hamano
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"
2026-03-25Merge branch 'tb/incremental-midx-part-3.2'Junio C Hamano
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
2026-03-25repo: show subcommand-specific help textMahi Kassa
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>
2026-03-25repo: factor repo usage strings into shared macrosMahi Kassa
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>
2026-03-24t0061: simplify .bat testJeff King
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>
2026-03-24replay: support replaying down from root commitToon Claes
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>
2026-03-24The 20th batchJunio C Hamano
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-03-24Merge branch 'dd/cocci-do-not-pass-strbuf-by-value'Junio C Hamano
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
2026-03-24Merge branch 'ty/doc-diff-u-wo-number'Junio C Hamano
"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
2026-03-24Merge branch 'ps/upload-pack-buffer-more-writes'Junio C Hamano
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
2026-03-24Merge branch 'yc/histogram-hunk-shift-fix'Junio C Hamano
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
2026-03-24Merge branch 'mf/t0008-cleanup'Junio C Hamano
Test clean-up. * mf/t0008-cleanup: t0008: improve test cleanup to fix failing test
2026-03-24Merge branch 'pb/t4200-test-path-is-helpers'Junio C Hamano
Test clean-up. * pb/t4200-test-path-is-helpers: t4200: convert test -[df] checks to test_path_* helpers
2026-03-24Merge branch 'jk/transport-color-leakfix'Junio C Hamano
Leakfix. * jk/transport-color-leakfix: transport: plug leaks in transport_color_config()
2026-03-24Merge branch 'rj/pack-refs-tests-path-is-helpers'Junio C Hamano
Test updates. * rj/pack-refs-tests-path-is-helpers: t/pack-refs-tests: use test_path_is_missing
2026-03-24Merge branch 'ps/history-split'Junio C Hamano
"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"
2026-03-24Merge branch 'ps/clar-wo-path-max'Junio C Hamano
Clar (unit testing framework) update from the upstream. * ps/clar-wo-path-max: clar: update to fix compilation on platforms without PATH_MAX
2026-03-24Merge branch 'ss/t0410-delete-object-cleanup'Junio C Hamano
Test clean-up. * ss/t0410-delete-object-cleanup: t0410: modernize delete_object helper
2026-03-24Merge branch 'gj/user-manual-fix-grep-example'Junio C Hamano
Fix an example in the user-manual. * gj/user-manual-fix-grep-example: doc: fix git grep args order in Quick Reference
2026-03-24Merge branch 'jt/fast-import-sign-again'Junio C Hamano
"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
2026-03-24use strvec_pushv() to add another strvecJunio C Hamano
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>
2026-03-24Merge branch 'ps/build-tweaks' into rs/use-strvec-pushvJunio C Hamano
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
2026-03-24commit-graph: fix writing generations with dates exceeding 34 bitsPatrick Steinhardt
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>
2026-03-23refspec: fix typo in commentK Jayatheerth
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>
2026-03-23remote-curl: fall back to default hash outside repoK Jayatheerth
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>
2026-03-23format-patch: --commit-list-format without prefixMirko Faina
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>
2026-03-23format-patch: add preset for --commit-list-formatMirko Faina
"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>
2026-03-23format-patch: wrap generate_commit_list_cover()Mirko Faina
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>
2026-03-23format.commitListFormat: strip meaning from emptyMirko Faina
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>
2026-03-23docs/pretty-formats: add %(count) and %(total)Mirko Faina
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>
2026-03-23format-patch: rename --cover-letter-format optionMirko Faina
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>
2026-03-23format-patch: refactor generate_commit_list_coverMirko Faina
Refactor for readability and remove unnecessary initialization. Signed-off-by: Mirko Faina <mroik@delayed.space> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-03-23pretty.c: better die message %(count) and %(total)Mirko Faina
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>
2026-03-23The 19th batchJunio C Hamano
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-03-23Merge branch 'ty/mktree-wo-the-repository'Junio C Hamano
Code clean-up. * ty/mktree-wo-the-repository: builtin/mktree: remove USE_THE_REPOSITORY_VARIABLE
2026-03-23Merge branch 'bb/imap-send-openssl-4.0-prep'Junio C Hamano
"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
2026-03-23Merge branch 'ac/help-sort-correctly'Junio C Hamano
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