<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/worktree.c, branch jch</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=jch</id>
<link rel='self' href='https://git.shady.money/git/atom?h=jch'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2026-04-03T20:01:09Z</updated>
<entry>
<title>Merge branch 'pw/worktree-reduce-the-repository'</title>
<updated>2026-04-03T20:01:09Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2026-04-03T20:01:09Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=05ddb9ee8a4c619fbb0e7309fe291bff5cd7c987'/>
<id>urn:sha1:05ddb9ee8a4c619fbb0e7309fe291bff5cd7c987</id>
<content type='text'>
Reduce the reference to the_repository in the worktree subsystem.

* pw/worktree-reduce-the-repository:
  worktree: reject NULL worktree in get_worktree_git_dir()
  worktree add: stop reading ".git/HEAD"
  worktree: remove "the_repository" from is_current_worktree()
</content>
</entry>
<entry>
<title>worktree: reject NULL worktree in get_worktree_git_dir()</title>
<updated>2026-03-26T15:20:50Z</updated>
<author>
<name>Phillip Wood</name>
<email>phillip.wood@dunelm.org.uk</email>
</author>
<published>2026-03-26T14:16:59Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=758086869940c96585f05a0eefe6d2f24fd70630'/>
<id>urn:sha1:758086869940c96585f05a0eefe6d2f24fd70630</id>
<content type='text'>
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 &lt;phillip.wood@dunelm.org.uk&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: remove "the_repository" from is_current_worktree()</title>
<updated>2026-03-26T15:20:50Z</updated>
<author>
<name>Phillip Wood</name>
<email>phillip.wood@dunelm.org.uk</email>
</author>
<published>2026-03-26T14:16:57Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=0f7791476029b73ca9b7dfc0816bfee5f21c0dbb'/>
<id>urn:sha1:0f7791476029b73ca9b7dfc0816bfee5f21c0dbb</id>
<content type='text'>
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-&gt;path" matches
"wt-&gt;repo-&gt;worktree" is_current_worktree(wt) will return false when
"wt-&gt;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 &lt;phillip.wood@dunelm.org.uk&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'dd/list-objects-filter-options-wo-strbuf-split'</title>
<updated>2026-03-19T16:54:55Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2026-03-19T16:54:55Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=17b9c759bd5d3407f573bb2a6a78d81e94b51c39'/>
<id>urn:sha1:17b9c759bd5d3407f573bb2a6a78d81e94b51c39</id>
<content type='text'>
The way combined list-object filter options are parsed has been
revamped.

* dd/list-objects-filter-options-wo-strbuf-split:
  list-objects-filter-options: avoid strbuf_split_str()
  worktree: do not pass strbuf by value
</content>
</entry>
<entry>
<title>Merge branch 'ty/setup-error-tightening'</title>
<updated>2026-03-16T17:48:14Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2026-03-16T17:48:14Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=c563b12ce7aa6bf8130385c80c001b2340026ff5'/>
<id>urn:sha1:c563b12ce7aa6bf8130385c80c001b2340026ff5</id>
<content type='text'>
While discovering a ".git" directory, the code treats any stat()
failure as a sign that a filesystem entity .git does not exist
there, and ignores ".git" that is not a "gitdir" file or a
directory.  The code has been tightened to notice and report
filesystem corruption better.

* ty/setup-error-tightening:
  setup: improve error diagnosis for invalid .git files
</content>
</entry>
<entry>
<title>worktree: do not pass strbuf by value</title>
<updated>2026-03-11T18:08:53Z</updated>
<author>
<name>Deveshi Dwivedi</name>
<email>deveshigurgaon@gmail.com</email>
</author>
<published>2026-03-11T17:33:35Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=4107c0bb3455905aeacdba3be09b20e62b310eaa'/>
<id>urn:sha1:4107c0bb3455905aeacdba3be09b20e62b310eaa</id>
<content type='text'>
write_worktree_linking_files() takes two struct strbuf parameters by
value, even though it only reads path strings from them.

Passing a strbuf by value is misleading and dangerous. The structure
carries a pointer to its underlying character array; caller and callee
end up sharing that storage.  If the callee ever causes the strbuf to
be reallocated, the caller's copy becomes a dangling pointer, which
results in a double-free when the caller does strbuf_release().

The function only needs the string values, not the strbuf machinery.
Switch it to take const char * and update all callers to pass .buf.

Signed-off-by: Deveshi Dwivedi &lt;deveshigurgaon@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'ps/refs-for-each'</title>
<updated>2026-03-09T21:36:55Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2026-03-09T21:36:55Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=d445aecfb013ae7b45e946f9aea06464aee69ed8'/>
<id>urn:sha1:d445aecfb013ae7b45e946f9aea06464aee69ed8</id>
<content type='text'>
Code refactoring around refs-for-each-* API functions.

* ps/refs-for-each:
  refs: replace `refs_for_each_fullref_in()`
  refs: replace `refs_for_each_namespaced_ref()`
  refs: replace `refs_for_each_glob_ref()`
  refs: replace `refs_for_each_glob_ref_in()`
  refs: replace `refs_for_each_rawref_in()`
  refs: replace `refs_for_each_rawref()`
  refs: replace `refs_for_each_ref_in()`
  refs: improve verification for-each-ref options
  refs: generalize `refs_for_each_fullref_in_prefixes()`
  refs: generalize `refs_for_each_namespaced_ref()`
  refs: speed up `refs_for_each_glob_ref_in()`
  refs: introduce `refs_for_each_ref_ext`
  refs: rename `each_ref_fn`
  refs: rename `do_for_each_ref_flags`
  refs: move `do_for_each_ref_flags` further up
  refs: move `refs_head_ref_namespaced()`
  refs: remove unused `refs_for_each_include_root_ref()`
</content>
</entry>
<entry>
<title>setup: improve error diagnosis for invalid .git files</title>
<updated>2026-03-04T17:23:48Z</updated>
<author>
<name>Tian Yuchen</name>
<email>a3205153416@gmail.com</email>
</author>
<published>2026-03-04T14:15:26Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=1dd27bfbfdc0f3b2071ecb8b505476f4caa56a13'/>
<id>urn:sha1:1dd27bfbfdc0f3b2071ecb8b505476f4caa56a13</id>
<content type='text'>
'read_gitfile_gently()' treats any non-regular file as
'READ_GITFILE_ERR_NOT_A_FILE' and fails to discern between 'ENOENT'
and other stat failures. This flawed error reporting is noted by two
'NEEDSWORK' comments.

Address these comments by introducing two new error codes:
'READ_GITFILE_ERR_MISSING'(which groups the "file missing" scenarios
together) and 'READ_GITFILE_ERR_IS_A_DIR':

1. Update 'read_gitfile_error_die()' to treat 'IS_A_DIR', 'MISSING',
'NOT_A_FILE' and 'STAT_FAILED' as non-fatal no-ops. This accommodates
intentional non-repo scenarios (e.g., GIT_DIR=/dev/null).

2. Explicitly catch 'NOT_A_FILE' and 'STAT_FAILED' during
discovery and call 'die()' if 'die_on_error' is set.

3. Unconditionally pass '&amp;error_code' to 'read_gitfile_gently()'.

4. Only invoke 'is_git_directory()' when we explicitly receive
   'READ_GITFILE_ERR_IS_A_DIR', avoiding redundant checks.

Additionally, audit external callers of 'read_gitfile_gently()' in
'submodule.c' and 'worktree.c' to accommodate the refined error codes.

Signed-off-by: Tian Yuchen &lt;a3205153416@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>refs: rename `each_ref_fn`</title>
<updated>2026-02-23T21:21:18Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2026-02-23T11:59:39Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=635f08b7394b9dda013a0b78f4db11348dc7717b'/>
<id>urn:sha1:635f08b7394b9dda013a0b78f4db11348dc7717b</id>
<content type='text'>
Similar to the preceding commit, rename `each_ref_fn` to better match
our current best practices around how we name things.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>path: remove repository argument from worktree_git_path()</title>
<updated>2026-02-19T19:03:24Z</updated>
<author>
<name>Phillip Wood</name>
<email>phillip.wood@dunelm.org.uk</email>
</author>
<published>2026-02-19T14:26:33Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=a49cb0f093809e3e66566f161aa930f37346775d'/>
<id>urn:sha1:a49cb0f093809e3e66566f161aa930f37346775d</id>
<content type='text'>
worktree_git_path() takes a struct repository and a struct worktree
which also contains a struct repository. The repository argument
was added by a973f60dc7c (path: stop relying on `the_repository` in
`worktree_git_path()`, 2024-08-13) and exists because the worktree
argument is optional. Having two ways of passing a repository is
a potential foot-gun as if the the worktree argument is present the
repository argument must match the worktree's repository member. Since
the last commit there are no callers that pass a NULL worktree so lets
remove the repository argument. This removes the potential confusion
and lets us delete a number of uses of "the_repository".

worktree_git_path() has the following callers:

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

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

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

 - worktree.c:worktree_lock_reason() which dereferences wt before
   calling worktree_git_path().

 - wt-status.c:wt_status_check_bisect() and wt_status_check_rebase()
   which are always called with a non-NULL worktree after the last
   commit.

 - wt-status.c:git_branch() which is only called by
   wt_status_check_bisect() and wt_status_check_rebase().

Signed-off-by: Phillip Wood &lt;phillip.wood@dunelm.org.uk&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
