git/builtin
shejialuo fdf3820b7e builtin/refs: get worktrees without reading head information
In "packed-backend.c", there are some functions such as "create_snapshot"
and "next_record" which would check the correctness of the content of
the "packed-ref" file. When anything is bad, the program will die.

It may seem that we have nothing relevant to above feature, because we
are going to read and parse the raw "packed-ref" file without creating
the snapshot and using the ref iterator to check the consistency.

However, when using "get_worktrees" in "builtin/refs", we would parse
the "HEAD" information. If the referent of the "HEAD" is inside the
"packed-ref", we will call "create_snapshot" function to parse the
"packed-ref" to get the information. No matter whether the entry of
"HEAD" in "packed-ref" is correct, "create_snapshot" would call
"verify_buffer_safe" to check whether there is a newline in the last
line of the file. If not, the program will die.

Although this behavior has no harm for the program, it will
short-circuit the program. When the users execute "git refs verify" or
"git fsck", we should avoid reading the head information, which may
execute the read operation in packed backend with stricter checks to die
the program. Instead, we should continue to check other parts of the
"packed-refs" file completely.

Fortunately, in 465a22b338 (worktree: skip reading HEAD when repairing
worktrees, 2023-12-29), we have introduced a function
"get_worktrees_internal" which allows us to get worktrees without
reading head information.

Create a new exposed function "get_worktrees_without_reading_head", then
replace the "get_worktrees" in "builtin/refs" with the new created
function.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-02-27 14:03:07 -08:00
..
add.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
am.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
annotate.c Merge branch 'jc/a-commands-without-the-repo' 2024-10-25 14:02:36 -04:00
apply.c
archive.c archive: remove the_repository global variable 2024-10-11 09:37:18 -07:00
bisect.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
blame.c builtin/blame: fix type of `length` variable when emitting object ID 2024-12-06 20:20:05 +09:00
branch.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
bugreport.c
bundle.c Merge branch 'jt/bundle-fsck' 2024-12-13 07:33:36 -08:00
cat-file.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
check-attr.c
check-ignore.c
check-mailmap.c
check-ref-format.c refs: drop strbuf_ prefix from helpers 2024-12-03 12:38:49 +09:00
checkout--worker.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
checkout-index.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
checkout.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
clean.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
clone.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
column.c
commit-graph.c builtin: pass repository to sub commands 2024-11-26 10:36:08 +09:00
commit-tree.c
commit.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
config.c builtin: pass repository to sub commands 2024-11-26 10:36:08 +09:00
count-objects.c packfile: pass down repository to `has_object[_kept]_pack` 2024-12-04 08:21:54 +09:00
credential-cache--daemon.c
credential-cache.c Merge branch 'rj/cygwin-exit' 2024-11-01 12:53:19 -04:00
credential-store.c
credential.c
describe.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
diagnose.c
diff-files.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
diff-index.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
diff-tree.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
diff.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
difftool.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
fast-export.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
fast-import.c Merge branch 'ps/weak-sha1-for-tail-sum-fix' 2025-01-01 09:21:14 -08:00
fetch-pack.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
fetch.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
fmt-merge-msg.c
for-each-ref.c
for-each-repo.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
fsck.c packfile: pass down repository to `for_each_packed_object` 2024-12-04 08:21:54 +09:00
fsmonitor--daemon.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
gc.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
get-tar-commit-id.c
grep.c Revert barrier-based LSan threading race workaround 2025-01-01 14:13:01 -08:00
hash-object.c
help.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
hook.c builtin: pass repository to sub commands 2024-11-26 10:36:08 +09:00
index-pack.c Revert barrier-based LSan threading race workaround 2025-01-01 14:13:01 -08:00
init-db.c builtin/init-db: fix leaking directory paths 2024-11-21 08:23:45 +09:00
interpret-trailers.c trailer: spread usage of "trailer_block" language 2024-10-14 12:33:02 -04:00
log.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
ls-files.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
ls-remote.c builtin/ls-remote: plug leaking server options 2024-11-04 22:37:51 -08:00
ls-tree.c
mailinfo.c
mailsplit.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
merge-base.c
merge-file.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
merge-index.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
merge-ours.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
merge-recursive.c
merge-tree.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
merge.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
mktag.c
mktree.c
multi-pack-index.c midx-write: pass down repository to `write_midx_file[_only]` 2024-12-04 10:32:20 +09:00
mv.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
name-rev.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
notes.c builtin: pass repository to sub commands 2024-11-26 10:36:08 +09:00
pack-objects.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
pack-redundant.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
pack-refs.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
patch-id.c builtin/patch-id: fix type of `get_one_patchid()` 2024-12-06 20:20:05 +09:00
prune-packed.c
prune.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
pull.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
push.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
range-diff.c Merge branch 'js/range-diff-diff-merges' 2024-12-23 09:32:17 -08:00
read-tree.c
rebase.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
receive-pack.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
reflog.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
refs.c builtin/refs: get worktrees without reading head information 2025-02-27 14:03:07 -08:00
remote-ext.c
remote-fd.c
remote.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
repack.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
replace.c refs: allow passing flags when setting up a transaction 2024-11-21 07:59:14 +09:00
replay.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
rerere.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
reset.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
rev-list.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
rev-parse.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
revert.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
rm.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
send-pack.c builtin/send-pack: fix leaking list of push options 2024-09-30 11:23:09 -07:00
shortlog.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
show-branch.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
show-index.c Merge branch 'as/show-index-uninitialized-hash' 2024-12-23 09:32:12 -08:00
show-ref.c
sparse-checkout.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
stash.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
stripspace.c
submodule--helper.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
symbolic-ref.c
tag.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
unpack-file.c
unpack-objects.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
update-index.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
update-ref.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
update-server-info.c
upload-archive.c
upload-pack.c Merge branch 'bc/allow-upload-pack-from-other-people' 2024-12-10 10:04:55 +09:00
var.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
verify-commit.c
verify-pack.c
verify-tag.c
worktree.c Merge branch 'ps/build-sign-compare' 2024-12-23 09:32:11 -08:00
write-tree.c