Commit Graph

81368 Commits

Author SHA1 Message Date
Junio C Hamano
44acece03f Merge branch 'hn/checkout-track-fetch' into seen
"git checkout --track=..." learned to optionally fetch the branch
from the remote the new branch will work with.

* hn/checkout-track-fetch:
  checkout: extend --track with a "fetch" mode to refresh start-point
  branch: expose helpers for finding the remote owning a tracking ref
2026-06-15 10:27:28 -07:00
Junio C Hamano
119535dd13 Merge branch 'jt/config-lock-timeout' into seen
Configuration file locking now retries for a short period, avoiding
failures when multiple processes attempt to update the configuration
simultaneously.

* jt/config-lock-timeout:
  config: retry acquiring config.lock, configurable via core.configLockTimeout
2026-06-15 10:27:27 -07:00
Junio C Hamano
3f1b7e9586 Merge branch 'js/parseopt-subcommand-autocorrection' into seen
The parse-options library learned to auto-correct misspelled
subcommand names.

* js/parseopt-subcommand-autocorrection:
  SQUASH???
  doc: document autocorrect API
  parseopt: add tests for subcommand autocorrection
  parseopt: enable subcommand autocorrection for git-remote and git-notes
  parseopt: autocorrect mistyped subcommands
  autocorrect: provide config resolution API
  autocorrect: rename AUTOCORRECT_SHOW to AUTOCORRECT_HINT
  autocorrect: use mode and delay instead of magic numbers
  help: move tty check for autocorrection to autocorrect.c
  help: make autocorrect handling reusable
  parseopt: extract subcommand handling from parse_options_step()
2026-06-15 10:27:27 -07:00
Junio C Hamano
2f5bcdb9ae Merge branch 'pw/status-rebase-todo' into seen
The display of the rebase todo list in "git status" has been
improved to correctly abbreviate object IDs for more commands and
avoid misinterpreting refs as object IDs.

* pw/status-rebase-todo:
  status: improve rebase todo list parsing
  sequencer: factor out parsing of todo commands
2026-06-15 10:27:27 -07:00
Junio C Hamano
fbb4ccb328 Merge branch 'lp/repack-propagate-promisor-debugging-info' into seen
When fetching objects into a lazily cloned repository, .promisor
files are created with information meant to help debugging.  "git
repack" has been taught to carry this information forward to
packfiles that are newly created.

Retracted.
cf. <agx_GPfBKpkSc3Gx@lorenzo-VM>

* lp/repack-propagate-promisor-debugging-info:
  repack-promisor: add missing headers
  t7703: test for promisor file content after geometric repack
  t7700: test for promisor file content after repack
  repack-promisor: preserve content of promisor files after repack
  repack-promisor add helper to fill promisor file after repack
  pack-write: add explanation to promisor file content
2026-06-15 10:27:27 -07:00
Junio C Hamano
7087fed336 Merge branch 'ps/doc-recommend-b4' into jch
Project-specific configuration for b4 has been introduced, and the
documentation has been updated to recommend using it as a
streamlined method for submitting patches.

* ps/doc-recommend-b4:
  b4: introduce configuration for the Git project
  MyFirstContribution: recommend the use of b4
  MyFirstContribution: recommend shallow threading of cover letters
2026-06-15 10:27:20 -07:00
Junio C Hamano
cc33e45220 Merge branch 'en/commit-graph-timestamp-fix' into jch
compute_reachable_generation_numbers() in commit-graph used a 32-bit
integer to accumulate parent generations, which is OK for generation
number v1 (topological levels), but with generation number v2
(adjusted committer timestamps), it truncated timestamps beyond
2106.  Fixed by widening the accumulator to timestamp_t.

* en/commit-graph-timestamp-fix:
  commit-graph: use timestamp_t for max parent generation accumulator
2026-06-15 10:27:19 -07:00
Junio C Hamano
25aeba5eab Merge branch 'en/ort-harden-against-corrupt-trees' into jch
"ort" merge backend handles merging corrupt trees better by
aborting when it should.

* en/ort-harden-against-corrupt-trees:
  cache-tree: fix verify_cache() to catch non-adjacent D/F conflicts
  merge-ort: abort merge when trees have duplicate entries
  merge-ort: free diff pairs queue in clear_or_reinit_internal_opts()
  merge-ort: drop unnecessary show_all_errors from collect_merge_info()
  merge-ort: propagate callback errors from traverse_trees_wrapper()
2026-06-15 10:27:19 -07:00
Junio C Hamano
859830600c Merge branch 'kh/doc-trailers' into jch
Documentation updates.

* kh/doc-trailers:
  doc: interpret-trailers: document comment line treatment
  doc: interpret-trailers: commit to “trailer block” term
  doc: interpret-trailers: join new-trailers again
  doc: interpret-trailers: add key format example
  doc: interpret-trailers: explain key format
  doc: interpret-trailers: explain the format after the intro
  doc: interpret-trailers: not just for commit messages
  doc: interpret-trailers: use “metadata” in Name as well
  doc: interpret-trailers: replace “lines” with “metadata”
  doc: interpret-trailers: stop fixating on RFC 822
2026-06-15 10:27:19 -07:00
Junio C Hamano
fd4695cddd Merge branch 'za/completion-hide-dotfiles' into jch
The path completion for commands like `git rm` and `git mv`, is being
updated to hide dotfiles by default, unless the user explicitly starts
the path with a dot, matching standard shell-completion behavior.

* za/completion-hide-dotfiles:
  completion: hide dotfiles for selected path completion
2026-06-15 10:27:19 -07:00
Junio C Hamano
86d3b43d4a Merge branch 'kh/doc-replay-config' into jch
Doc update for "git replay" to actually refer to its configuration
variables.

* kh/doc-replay-config:
  doc: replay: move “default” to the right-hand side
  doc: replay: use a nested description list
  doc: replay: improve config description
  doc: link to config for git-replay(1)
2026-06-15 10:27:19 -07:00
Junio C Hamano
6e36a0b7fb ### match next 2026-06-15 10:27:19 -07:00
Junio C Hamano
eba23a7150 Merge branch 'dl/posix-unused-warning-clang' into jch
The UNUSED macro in 'compat/posix.h' has been updated to use a
newly introduced GIT_CLANG_PREREQ macro for compiler version
checks, and the existing GIT_GNUC_PREREQ macro has been modernized
to use explicit major/minor comparisons rather than bit-shifting.

* dl/posix-unused-warning-clang:
  compat/posix.h: simplify GIT_GNUC_PREREQ() comparison
  compat/posix.h: clean up GIT_GNUC_PREREQ() and UNUSED
  compat/posix.h: enable UNUSED warning messages for Clang
2026-06-15 10:27:19 -07:00
Junio C Hamano
36f5666b37 Merge branch 'td/ls-files-pathspec-prefilter' into jch
`git ls-files --modified` and `git ls-files --deleted` have been
optimized to filter with pathspec before calling lstat() when there is
only a single pathspec item, avoiding unnecessary filesystem access
for entries that will not be shown.

* td/ls-files-pathspec-prefilter:
  ls-files: filter pathspec before lstat
2026-06-15 10:27:18 -07:00
Junio C Hamano
a8bedfb79d Merge branch 'ta/doc-config-adoc-fixes' into jch
Various AsciiDoc markup fixes in 'git config' documentation and
related files to ensure lists and formatting are rendered correctly.

* ta/doc-config-adoc-fixes:
  doc: git-config: escape erroneous highlight markup
  doc: config/sideband: fix description list delimiter
  doc: config: terminate runaway lists
2026-06-15 10:27:18 -07:00
Junio C Hamano
0ca4231483 Merge branch 'ps/setup-drop-global-state' into jch
Continuation of "setup.c" refactoring to drop remaining global state
(`git_work_tree_cfg`, `is_bare_repository_cfg`). The most notable
outcome is that `is_bare_repository()` has been updated to no longer
implicitly rely on `the_repository`.

* ps/setup-drop-global-state:
  treewide: drop USE_THE_REPOSITORY_VARIABLE
  environment: stop using `the_repository` in `is_bare_repository()`
  environment: split up concerns of `is_bare_repository_cfg`
  builtin/init: stop modifying `is_bare_repository_cfg`
  setup: remove global `git_work_tree_cfg` variable
  builtin/init: simplify logic to configure worktree
  builtin/init: stop modifying global `git_work_tree_cfg` variable
2026-06-15 10:27:18 -07:00
Junio C Hamano
99eb089077 Merge branch 'jc/t1400-fifo-cleanup' into jch
Test cleanup.

* jc/t1400-fifo-cleanup:
  t1400: have fifo test clean after itself
2026-06-15 10:27:18 -07:00
Junio C Hamano
b6d3520e47 Merge branch 'td/describe-tag-iteration' into jch
'git describe' has been taught to pass the 'refs/tags/' prefix down to
the ref iterator when '--all' is not requested, avoiding unnecessary
iteration over non-tag refs.

* td/describe-tag-iteration:
  describe: limit default ref iteration to tags
2026-06-15 10:27:18 -07:00
Junio C Hamano
43c037c7bb Merge branch 'ty/move-protect-hfs-ntfs' into jch
The global configuration variables protect_hfs and protect_ntfs have
been migrated into struct repo_config_values to tie them to
per-repository configuration state.

* ty/move-protect-hfs-ntfs:
  environment: move 'protect_hfs' and 'protect_ntfs' into 'repo_config_values'
2026-06-15 10:27:17 -07:00
Junio C Hamano
392855964e Merge branch 'ps/transport-helper-tsan-fix' into jch
The TSAN race in transfer_debug() within transport-helper.c has been
resolved by initializing the debug flag early in
bidirectional_transfer_loop() before spawning worker threads, allowing
the removal of a TSAN suppression.

* ps/transport-helper-tsan-fix:
  transport-helper: fix TSAN race in transfer_debug()
2026-06-15 10:27:17 -07:00
Junio C Hamano
1a7ae52d86 Merge branch 'cc/promisor-auto-config-url-more' into jch
The handling of promisor-remote protocol capability has been
loosened to allow the other side to add to the list of promisor
remotes via the promisor.acceptFromServerURL configuration
variable.

* cc/promisor-auto-config-url-more:
  doc: promisor: improve acceptFromServer entry
  promisor-remote: auto-configure unknown remotes
  promisor-remote: trust known remotes matching acceptFromServerUrl
  promisor-remote: introduce promisor.acceptFromServerUrl
  promisor-remote: add 'local_name' to 'struct promisor_info'
  urlmatch: add url_normalize_pattern() helper
  urlmatch: change 'allow_globs' arg to bool
  t5710: simplify 'mkdir X' followed by 'git -C X init'
2026-06-15 10:27:17 -07:00
Junio C Hamano
27f3aa173c Merge branch 'hn/status-pull-advice-qualified' into jch
Advice shown by "git status" when the local branch is behind or has
diverged from its push branch has been updated to suggest "git pull
<remote> <branch>".

* hn/status-pull-advice-qualified:
  remote: qualify "git pull" advice for non-upstream compareBranches
2026-06-15 10:27:17 -07:00
Junio C Hamano
fdd7eec2bf Merge branch 'ab/index-pack-retain-child-bases' into jch
"git index-pack" has been optimized by retaining child bases in the
delta cache instead of immediately freeing them, letting the existing
cache limit policy decide eviction.

* ab/index-pack-retain-child-bases:
  index-pack: retain child bases in delta cache
2026-06-15 10:27:17 -07:00
Junio C Hamano
64df134198 ### 2026-06-15 10:27:17 -07:00
Junio C Hamano
41934a8afa Merge branch 'ta/typofixes' into jch
Typofixes

* ta/typofixes:
  docs: fix typos
2026-06-15 10:27:16 -07:00
Junio C Hamano
7f97c08727 Merge branch 'mm/subprocess-handshake-fix' into jch
The subprocess handshake during startup has been made gentler by using
packet_read_line_gently() instead of packet_read_line() to prevent the
parent Git process from dying abruptly when a configured subprocess
(e.g., a clean/smudge filter) fails to start.

* mm/subprocess-handshake-fix:
  sub-process: use gentle handshake to avoid die() on startup failure
2026-06-15 10:27:16 -07:00
Junio C Hamano
b9caa4dd10 Merge branch 'wy/docs-typofixes' into jch
Various typos, grammatical errors, and duplicated words in both
documentation and code comments have been corrected.

* wy/docs-typofixes:
  docs: fix typos and grammar
2026-06-15 10:27:16 -07:00
Junio C Hamano
03dac063b4 Merge branch 'jd/unpack-trees-wo-the-repository' into jch
A handful of inappropriate uses of the_repository have been
rewritten to use the right repository structure instance in the
unpack-trees.c codepath.

* jd/unpack-trees-wo-the-repository:
  unpack-trees: use repository from index instead of global
2026-06-15 10:27:16 -07:00
Junio C Hamano
48e75964ad Merge branch 'ps/t7527-fix-tap-output' into jch
A recent regression in t7527 that broke TAP output has been fixed,
some other test noise that also broke TAP output has been silenced,
and 'prove' is now configured to fail on invalid TAP output to
prevent future regressions.

* ps/t7527-fix-tap-output:
  t: let prove fail when parsing invalid TAP output
  t/lib-git-p4: silence output when killing p4d and its watchdog
  t/test-lib: silence EBUSY errors on Windows during test cleanup
  t7810: turn MB_REGEX check into a lazy prereq
  t7527: fix broken TAP output
  ci: unify Linux images across GitLab and GitHub
  gitlab-ci: add missing Linux jobs
  gitlab-ci: rearrange Linux jobs to match GitHub's order
2026-06-15 10:27:16 -07:00
Junio C Hamano
c3138f9d0d Merge branch 'jk/describe-contains-all-match-fix' into jch
The 'git describe --contains --all' command has been fixed to
properly honor the '--match' and '--exclude' options by passing
them down to 'git name-rev' with the appropriate reference
prefixes.

* jk/describe-contains-all-match-fix:
  describe: fix --exclude, --match with --contains and --all
2026-06-15 10:27:16 -07:00
Junio C Hamano
998a0bc412 Merge branch 'kk/streaming-walk-pqueue' into jch
Streaming revision walks have been optimized by using a priority queue
for date-sorting commits, speeding up walks repositories with many
merges.

* kk/streaming-walk-pqueue:
  revision: use priority queue for non-limited streaming walks
  revision: introduce rev_walk_mode to clarify get_revision_1()
  pack-objects: call release_revisions() after cruft traversal
2026-06-15 10:27:15 -07:00
Junio C Hamano
0feb51095d Merge branch 'mf/revision-max-count-oldest' into jch
"git rev-list" (and "git log" family of commands) learned a new "--max-count-oldest"
that picks oldest N commits in the range instead of the usual newest.

* mf/revision-max-count-oldest:
  bash-completions: add --max-count-oldest
  revision.c: implement --max-count-oldest
2026-06-15 10:27:15 -07:00
Junio C Hamano
6aae322133 Merge branch 'js/win-kill-child-more-gently' into jch
Advanced emulation of kill() used on Windows in GfW has been
upstreamed to improve the symptoms like left-behind .lock files and
that fails to let the child clean-up itself when it gets killed.

* js/win-kill-child-more-gently:
  mingw: really handle SIGINT
  mingw: kill child processes in a gentler way
2026-06-15 10:27:15 -07:00
Patrick Steinhardt
84b2ff7f2f b4: introduce configuration for the Git project
In the preceding commit we have extended our documentation to recommend
b4 for sending patch series to the mailing list. Introduce configuration
so that it knows to honor preferences of the Git project by default. For
now, this configuration does two things:

  - It configures "send-same-thread = shallow", which tells b4 to always
    send subsequent versions of the same patch series as a reply to the
    cover letter of the first version.

  - It configures "prep-cover-template", which tells b4 to use a custom
    template for the cover letter. The most important change compared to
    the default template is that our custom template also includes a
    range-diff.

There's potentially more things that we may want to configure going
forward, like for example auto-configuration of folks to Cc on certain
patches. But these two tweaks feel like a good place to start.

Note that these values only serve as defaults, and users may want to
tweak those defaults based on their own preference. Luckily, users can
do that without having to touch `.b4-config` at all, as b4 allows them
to override values via Git configuration:

    ```
    $ git config set b4.prep-cover-template /does/not/exist
    $ b4 send --dry-run
    ERROR: prep-cover-template says to use x, but it does not exist
    ```

So this gives users an easy way to override our defaults without having
to touch ".b4-config", which would dirty the tree.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-06-15 10:13:28 -07:00
Patrick Steinhardt
efe4ac7064 MyFirstContribution: recommend the use of b4
The b4 tool originates from the Linux kernel community and is intended
to help mailing-list based workflows. It automates a lot of the annoying
bookkeeping tasks that contributors typically need to do: tracking the
list of recipients, Message-IDs, range-diffs and the like. In addition
to that, b4 also has many other subcommands that help the maintainer and
reviewers.

The Git project uses the same infrastructure as the kernel, so this tool
is also a very good fit for us. Adapt "MyFirstContribution" to
explicitly recommend its use.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-06-15 10:13:28 -07:00
Patrick Steinhardt
16b2924aab MyFirstContribution: recommend shallow threading of cover letters
The "MyFirstContribution" document recommends the use of deep threading
of cover letters: every cover letter of subsequent iterations shall be
linked to the cover letter of the preceding version. The result of this
is that eventually, threads with many versions are getting nested so
deep that it becomes hard to follow.

Adapt the recommendation to instead propose shallow threading of cover
letters: instead of linking the cover letter to the previous cover
letter, the user is supposed to always link it to the first cover
letter. This still makes it easy to follow the iterations, but has the
benefit of nesting to a much shallower level.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-06-15 10:13:28 -07:00
Junio C Hamano
700432b2ba topic flush before -rc1 (batch 1)
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-06-15 07:42:00 -07:00
Junio C Hamano
ff1784217f Merge branch 'ak/typofixes'
Typofixes.

* ak/typofixes:
  doc: fix typos via codespell
2026-06-15 07:42:00 -07:00
Junio C Hamano
883a47ef64 Merge branch 'ob/more-repo-config-values'
Many core configuration variables have been migrated from global
variables into 'repo_config_values' to tie them to a specific
repository instance, avoiding cross-repository state leakage.

* ob/more-repo-config-values:
  environment: move "warn_on_object_refname_ambiguity" into `struct repo_config_values`
  environment: move "sparse_expect_files_outside_of_patterns" into `struct repo_config_values`
  environment: move "core_sparse_checkout_cone" into `struct repo_config_values`
  environment: move "precomposed_unicode" into `struct repo_config_values`
  environment: move "pack_compression_level" into `struct repo_config_values`
  environment: move `zlib_compression_level` into `struct repo_config_values`
  environment: move "check_stat" into `struct repo_config_values`
  environment: move "trust_ctime" into `struct repo_config_values`
2026-06-15 07:42:00 -07:00
Junio C Hamano
06c2bdd25e Merge branch 'am/doc-tech-hash-typofix'
Typofix.

* am/doc-tech-hash-typofix:
  doc: fix typo in GIT_ALTERNATE_OBJECT_DIRECTORIES
2026-06-15 07:42:00 -07:00
Junio C Hamano
f5e1cff9dc Merge branch 'lo/doc-format-patch-subject-prefix'
Wording used in "format-patch --subject-prefix" documentation
has been improved.

* lo/doc-format-patch-subject-prefix:
  Documentation: remove redundant 'instead' in --subject-prefix
2026-06-15 07:42:00 -07:00
Junio C Hamano
4d1d7b933e Merge branch 'ps/setup-centralize-odb-creation'
The setup logic to discover and configure repositories has been
refactored, and the initialization of the object database has been
centralized.

* ps/setup-centralize-odb-creation:
  setup: construct object database in `apply_repository_format()`
  repository: stop reading loose object map twice on repo init
  setup: stop initializing object database without repository
  setup: stop creating the object database in `setup_git_env()`
  repository: stop initializing the object database in `repo_set_gitdir()`
  setup: deduplicate logic to apply repository format
  setup: drop `setup_git_env()`
  t0001: plug test gaps for git-init(1) with GIT_OBJECT_DIRECTORY
2026-06-15 07:42:00 -07:00
Junio C Hamano
cfe6682042 Merge branch 'hn/config-typo-advice'
"git config foo.bar=baz" is not likely to be a request to read the
value of such a variable with '=' in its name; rather it is plausible
that the user meant "git config set foo.bar baz".  Give advice when
giving an error message.

* hn/config-typo-advice:
  config: improve diagnostic for "set" with missing value
  config: add git_config_key_is_valid() for quiet validation
2026-06-15 07:41:59 -07:00
Junio C Hamano
8b0f02bbbb Merge branch 'ls/doc-raw-timestamp-prefix'
Documentation and tests have been added to clarify that Git's internal
raw timestamp format requires a `@` prefix for values less than
100,000,000 to prevent ambiguity with other formats like YYYYMMDD.

* ls/doc-raw-timestamp-prefix:
  doc: document and test `@` prefix for raw timestamps
2026-06-15 07:41:59 -07:00
Junio C Hamano
a4a1cbcedb Merge branch 'jc/submitting-patches-cover-letter'
Guidelines on how to write a cover letter for a multi-patch series
have been added to SubmittingPatches, which also got a new marker
to separate the section for typofixes.

* jc/submitting-patches-cover-letter:
  SubmittingPatches: describe cover letter
  SubmittingPatches: separate typofixes section
2026-06-15 07:41:59 -07:00
Elijah Newren
fbcc5408fc commit-graph: use timestamp_t for max parent generation accumulator
compute_reachable_generation_numbers() computes each commit's
generation as

    max(c->date, max(parent.generation)) + 1

by walking its parents and accumulating their generations into a
local

    uint32_t max_gen = 0;

while info->get_generation() returns timestamp_t and
compute_generation_from_max() already takes its max_gen parameter
as timestamp_t.  For v1 (topological levels) the narrowing is
harmless because GENERATION_NUMBER_V1_MAX is less than 2^30, but
for v2 (corrected committer dates) it silently truncates any
parent generation that does not fit in 32 bits, i.e. any parent
whose committer timestamp is at or beyond 2106-02-07 UTC
(>= 2^32).

The truncated max then causes child commits to end up with a
corrected committer date that matches the parent's instead of being
at least 1 higher.  The bad value gets written into the commit-graph
and causes problems later, and can be noticed by running `git
commit-graph verify`.

Widen the accumulator to timestamp_t.

This is solely an in-memory arithmetic fix with no on-disk format
change: the on-disk format already encodes timestamp_t values and
existing readers handle them unchanged.  This merely allows the code to
compute the correct value to write to disk.

The narrowing was introduced in 80c928d947 (commit-graph:
simplify compute_generation_numbers(), 2023-03-20), which rewired
v2 to use the shared compute_reachable_generation_numbers()
helper; the helper's local accumulator had been declared uint32_t
in the immediately preceding 368d19b0b7 (commit-graph: refactor
compute_topological_levels(), 2023-03-20) when only v1 was using
it, where it was harmless.

Add a new test with a future-dated parent and a present-day child;
without the above fix, `git commit-graph verify` reports the
descendant's stored generation as below parent + 1.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-06-14 08:24:08 -07:00
Elijah Newren
0c8eb46fbb cache-tree: fix verify_cache() to catch non-adjacent D/F conflicts
verify_cache() checks that the index does not contain both "path" and
"path/file" before writing a tree.  It does this by comparing only
adjacent entries, relying on the assumption that "path/file" would
immediately follow "path" in sorted order.  Unfortunately, this
assumption does not always hold.  For example:

    docs                     <-- submodule entry
    docs-internal/README.md  <-- intervening entry
    docs/requirements.txt    <-- D/F conflict, NOT adjacent to "docs"

When this happens, verify_cache() silently misses the D/F conflict and
write-tree produces a corrupt tree object containing duplicate entries
(one for the submodule "docs" and one for the tree "docs").

I could not find any caller in current git that both allows the index to
get into this state and then tries to write it out without doing other
checks beyond the verify_cache() call in cache_tree_update(), but
verify_cache() is documented as a safety net for preventing corrupt
trees and should actually provide that guarantee.  A downstream consumer
that relied solely on cache_tree_update()'s internal checking via
verify_cache() to prevent duplicate tree entries was bitten by the gap.

Add a test that constructs a corrupt index directly (bypassing the D/F
checks in add_index_entry) and verifies that write-tree now rejects it.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-06-14 07:50:47 -07:00
Elijah Newren
43a5fa7f5a merge-ort: abort merge when trees have duplicate entries
Trees with duplicate entries are malformed; fsck reports "contains
duplicate file entries" for them.  merge-ort has from the beginning
assumed that we would never hit such trees.  It was written with the
assumption that traverse_trees() calls collect_merge_info_callback() at
most once per path.  The "sanity checks" in that callback (added in
d2bc1994f3 (merge-ort: implement a very basic collect_merge_info(),
2020-12-13)) verify properties of each individual call but not that
invariant.  The strmap_put() in setup_path_info() silently overwrites
the entry from any prior call for the same path, because it assumed
there would be no other path.  Unfortunately, supplemental data
structures for various optimizations could still be tweaked before the
extra paths were overwritten, and those data structures not matching
expected state could trip various assertions.

Change the return type of setup_path_info() from void to int to allow us
to detect this case, and abort the merge with a clear error message when
it occurs.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-06-14 07:50:47 -07:00
Elijah Newren
83ae606c98 merge-ort: free diff pairs queue in clear_or_reinit_internal_opts()
clear_or_reinit_internal_opts() is responsible for cleaning up the
various data structures in merge_options_internal.  It already handles
many renames-related structures (dirs_removed, dir_renames,
relevant_sources, cached_pairs, deferred, etc.) but does not free
renames->pairs[].queue.

In the normal code path, resolve_and_process_renames() frees
pairs[s].queue and reinitializes it with diff_queue_init() before
clear_or_reinit_internal_opts() runs, so the omission is harmless.
However, if collect_merge_info() encounters an error and returns early
(before resolve_and_process_renames() is ever called), any diff pairs
already queued by collect_rename_info()/add_pair() will have their
backing array leaked.

Fix this by freeing renames->pairs[].queue in the cleanup function.
In the normal path the pointer is already NULL (from the earlier
diff_queue_init() in resolve_and_process_renames()), so free(NULL) is
a safe no-op.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-06-14 07:50:47 -07:00
Elijah Newren
159e4d9034 merge-ort: drop unnecessary show_all_errors from collect_merge_info()
collect_merge_info() has set info.show_all_errors = 1 since
d2bc1994f3 (merge-ort: implement a very basic collect_merge_info(),
2020-12-13).  This setting was copied from unpack-trees.c where it
controls batching of error messages for porcelain display, but
merge-ort has no such error-batching logic and never needed it.

With show_all_errors set, traverse_trees() captures a negative callback
return but continues processing remaining entries rather than stopping
immediately.  Removing the setting restores the default behavior where
a negative return from collect_merge_info_callback() breaks out of the
traversal loop right away, allowing a future commit to exit early when
a corrupt tree is detected.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-06-14 07:50:47 -07:00