From 7fb89047cc3957bf829233786c00edd5d87f0225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Justo?= Date: Sun, 22 Jan 2023 02:38:10 +0100 Subject: [PATCH 001/508] bisect: fix "reset" when branch is checked out elsewhere MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since 1d0fa89 (checkout: add --ignore-other-wortrees, 2015-01-03) we have a safety valve in checkout/switch to prevent the same branch from being checked out simultaneously in multiple worktrees. If a branch is bisected in a worktree while also being checked out in another worktree; when the bisection is finished, checking out the branch back in the current worktree may fail. Let's teach bisect to use the "--ignore-other-worktrees" flag. Signed-off-by: Rubén Justo Signed-off-by: Junio C Hamano --- builtin/bisect.c | 3 ++- t/t6030-bisect-porcelain.sh | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/builtin/bisect.c b/builtin/bisect.c index 7301740267..e405fff9e9 100644 --- a/builtin/bisect.c +++ b/builtin/bisect.c @@ -244,7 +244,8 @@ static int bisect_reset(const char *commit) struct child_process cmd = CHILD_PROCESS_INIT; cmd.git_cmd = 1; - strvec_pushl(&cmd.args, "checkout", branch.buf, "--", NULL); + strvec_pushl(&cmd.args, "checkout", "--ignore-other-worktrees", + branch.buf, "--", NULL); if (run_command(&cmd)) { error(_("could not check out original" " HEAD '%s'. Try 'git bisect" diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index 3ba4fdf615..fb01bd6abc 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -122,6 +122,29 @@ test_expect_success 'bisect start without -- takes unknown arg as pathspec' ' grep bar ".git/BISECT_NAMES" ' +test_expect_success 'bisect reset: back in a branch checked out also elsewhere' ' + echo "shared" > branch.expect && + test_bisect_reset() { + git -C $1 bisect start && + git -C $1 bisect good $HASH1 && + git -C $1 bisect bad $HASH3 && + git -C $1 bisect reset && + git -C $1 branch --show-current > branch.output && + cmp branch.expect branch.output + } && + test_when_finished " + git worktree remove wt1 && + git worktree remove wt2 && + git branch -d shared + " && + git worktree add wt1 -b shared && + git worktree add wt2 -f shared && + # we test in both worktrees to ensure that works + # as expected with "first" and "next" worktrees + test_bisect_reset wt1 && + test_bisect_reset wt2 +' + test_expect_success 'bisect reset: back in the main branch' ' git bisect reset && echo "* main" > branch.expect && From fb18dd2831323d5dece711cdbcaa9dcd8bf4edab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 6 Feb 2023 23:44:28 +0100 Subject: [PATCH 002/508] auto-crlf tests: don't lose exit code in loops and outside tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change the functions which are called from within "test_expect_success" to add the "|| return 1" idiom to their for-loops, so we won't lose the exit code of "cp", "git" etc. Then for those setup functions that aren't called from a "test_expect_success" we need to put the setup code in a "test_expect_success" as well. It would not be enough to properly &&-chain these, as the calling code is the top-level script itself. As we don't run the tests with "set -e" we won't report failing commands at the top-level. The "checkout" part of this would miss memory leaks under SANITIZE=leak, this code doesn't leak (the relevant "git checkout" leak has been fixed), but in a past version of git we'd continue past this failure under SANITIZE=leak when these invocations had errored out, even under "--immediate". For checkout_files() we could run one test_expect_success() instead of the 5 we run now in a loop. But as this function added in [1] is already taking pains to split up its setup into phases (there are 5 more "test_expect_success()" at the end of it already, see [1]), let's follow that existing convention. 1. 343151dcbdf (t0027: combinations of core.autocrlf, core.eol and text, 2014-06-29) Helped-by: René Scharfe Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t0027-auto-crlf.sh | 66 +++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/t/t0027-auto-crlf.sh b/t/t0027-auto-crlf.sh index a94ac1eae3..2f57c8669c 100755 --- a/t/t0027-auto-crlf.sh +++ b/t/t0027-auto-crlf.sh @@ -70,7 +70,8 @@ create_NNO_MIX_files () { cp CRLF ${pfx}_CRLF.txt && cp CRLF_mix_LF ${pfx}_CRLF_mix_LF.txt && cp LF_mix_CR ${pfx}_LF_mix_CR.txt && - cp CRLF_nul ${pfx}_CRLF_nul.txt + cp CRLF_nul ${pfx}_CRLF_nul.txt || + return 1 done done done @@ -101,7 +102,8 @@ commit_check_warn () { do fname=${pfx}_$f.txt && cp $f $fname && - git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" + git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" || + return 1 done && git commit -m "core.autocrlf $crlf" && check_warning "$lfname" ${pfx}_LF.err && @@ -121,15 +123,19 @@ commit_chk_wrnNNO () { lfmixcr=$1 ; shift crlfnul=$1 ; shift pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf} - #Commit files on top of existing file - create_gitattributes "$attr" $aeol && - for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul - do - fname=${pfx}_$f.txt && - cp $f $fname && - printf Z >>"$fname" && - git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" - done + + test_expect_success 'setup commit NNO files' ' + #Commit files on top of existing file + create_gitattributes "$attr" $aeol && + for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul + do + fname=${pfx}_$f.txt && + cp $f $fname && + printf Z >>"$fname" && + git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" || + return 1 + done + ' test_expect_success "commit NNO files crlf=$crlf attr=$attr LF" ' check_warning "$lfwarn" ${pfx}_LF.err @@ -163,15 +169,19 @@ commit_MIX_chkwrn () { lfmixcr=$1 ; shift crlfnul=$1 ; shift pfx=MIX_attr_${attr}_aeol_${aeol}_${crlf} - #Commit file with CLRF_mix_LF on top of existing file - create_gitattributes "$attr" $aeol && - for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul - do - fname=${pfx}_$f.txt && - cp CRLF_mix_LF $fname && - printf Z >>"$fname" && - git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" - done + + test_expect_success 'setup commit file with mixed EOL' ' + #Commit file with CLRF_mix_LF on top of existing file + create_gitattributes "$attr" $aeol && + for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul + do + fname=${pfx}_$f.txt && + cp CRLF_mix_LF $fname && + printf Z >>"$fname" && + git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" || + return 1 + done + ' test_expect_success "commit file with mixed EOL onto LF crlf=$crlf attr=$attr" ' check_warning "$lfwarn" ${pfx}_LF.err @@ -289,17 +299,17 @@ checkout_files () { lfmixcrlf=$1 ; shift lfmixcr=$1 ; shift crlfnul=$1 ; shift - create_gitattributes "$attr" $ident $aeol && - git config core.autocrlf $crlf && + test_expect_success "setup config for checkout attr=$attr ident=$ident aeol=$aeol core.autocrlf=$crlf" ' + create_gitattributes "$attr" $ident $aeol && + git config core.autocrlf $crlf + ' pfx=eol_${ceol}_crlf_${crlf}_attr_${attr}_ && for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul do - rm crlf_false_attr__$f.txt && - if test -z "$ceol"; then - git checkout -- crlf_false_attr__$f.txt - else - git -c core.eol=$ceol checkout -- crlf_false_attr__$f.txt - fi + test_expect_success "setup $f checkout ${ceol:+ with -c core.eol=$ceol}" ' + rm -f crlf_false_attr__$f.txt && + git ${ceol:+-c core.eol=$ceol} checkout -- crlf_false_attr__$f.txt + ' done test_expect_success "ls-files --eol attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol" ' From 62f3a45bb49f9436f1cd754b02ac549b1f6514cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 6 Feb 2023 23:44:29 +0100 Subject: [PATCH 003/508] t/lib-patch-mode.sh: fix ignored exit codes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix code added in b319ef70a94 (Add a small patch-mode testing library, 2009-08-13) to use &&-chaining. This avoids losing both the exit code of a "git" and the "cat" processes. This fixes cases where we'd have e.g. missed memory leaks under SANITIZE=leak, this code doesn't leak now as far as I can tell, but I discovered it while looking at leaks in related code. For "verify_saved_head()" we could make use of "test_cmp_rev" with some changes, but it uses "git rev-parse --verify", and this existing test does not. I think it could safely use it, but let's avoid the while-at-it change, and narrowly fix the exit code problem. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/lib-patch-mode.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/t/lib-patch-mode.sh b/t/lib-patch-mode.sh index cfd76bf987..89ca1f7805 100644 --- a/t/lib-patch-mode.sh +++ b/t/lib-patch-mode.sh @@ -29,8 +29,12 @@ set_and_save_state () { # verify_state verify_state () { - test "$(cat "$1")" = "$2" && - test "$(git show :"$1")" = "$3" + echo "$2" >expect && + test_cmp expect "$1" && + + echo "$3" >expect && + git show :"$1" >actual && + test_cmp expect actual } # verify_saved_state @@ -46,5 +50,6 @@ save_head () { } verify_saved_head () { - test "$(cat _head)" = "$(git rev-parse HEAD)" + git rev-parse HEAD >actual && + test_cmp _head actual } From 0cd1a8818db35df70c88d7864682146bf4fa8227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 6 Feb 2023 23:44:30 +0100 Subject: [PATCH 004/508] tests: don't lose exit status with "(cd ...; test $(git ...))" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rewrite tests that ran "git" inside command substitution and lost the exit status of "git" so that we notice the failing "git". Have them use modern patterns such as a "test_cmp" of the expected outputs instead. We'll fix more of these these in the subsequent commit, for now we're only converting the cases where this loss of exit code was combined with spawning a sub-shell. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/lib-httpd.sh | 8 ++++++-- t/lib-submodule-update.sh | 22 +++++++++------------- t/t0060-path-utils.sh | 5 ++++- t/t3200-branch.sh | 8 ++++++-- t/t5605-clone-local.sh | 12 +++++++++--- t/t7402-submodule-rebase.sh | 14 +++++++++++--- 6 files changed, 45 insertions(+), 24 deletions(-) diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh index 608949ea80..b8b1d044e8 100644 --- a/t/lib-httpd.sh +++ b/t/lib-httpd.sh @@ -217,8 +217,12 @@ test_http_push_nonff () { git commit -a -m path2 --amend && test_must_fail git push -v origin >output 2>&1 && - (cd "$REMOTE_REPO" && - test $HEAD = $(git rev-parse --verify HEAD)) + ( + cd "$REMOTE_REPO" && + echo "$HEAD" >expect && + git rev-parse --verify HEAD >actual && + test_cmp expect actual + ) ' test_expect_success 'non-fast-forward push show ref status' ' diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh index 2d31fcfda1..d7c2b670b4 100644 --- a/t/lib-submodule-update.sh +++ b/t/lib-submodule-update.sh @@ -168,20 +168,16 @@ replace_gitfile_with_git_dir () { # Note that this only supports submodules at the root level of the # superproject, with the default name, i.e. same as its path. test_git_directory_is_unchanged () { - ( - cd ".git/modules/$1" && - # does core.worktree point at the right place? - test "$(git config core.worktree)" = "../../../$1" && - # remove it temporarily before comparing, as - # "$1/.git/config" lacks it... - git config --unset core.worktree - ) && + # does core.worktree point at the right place? + echo "../../../$1" >expect && + git -C ".git/modules/$1" config core.worktree >actual && + test_cmp expect actual && + # remove it temporarily before comparing, as + # "$1/.git/config" lacks it... + git -C ".git/modules/$1" config --unset core.worktree && diff -r ".git/modules/$1" "$1/.git" && - ( - # ... and then restore. - cd ".git/modules/$1" && - git config core.worktree "../../../$1" - ) + # ... and then restore. + git -C ".git/modules/$1" config core.worktree "../../../$1" } test_git_directory_exists () { diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 68e29c904a..dcc78fb6a7 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -255,7 +255,10 @@ test_expect_success 'prefix_path rejects absolute path to dir with same beginnin test_expect_success SYMLINKS 'prefix_path works with absolute path to a symlink to work tree having same beginning as work tree' ' git init repo && ln -s repo repolink && - test "a" = "$(cd repo && test-tool path-utils prefix_path prefix "$(pwd)/../repolink/a")" + echo "a" >expect && + repo_path="$(cd repo && pwd)" && + test-tool -C repo path-utils prefix_path prefix "$repo_path/../repolink/a" >actual && + test_cmp expect actual ' relative_path /foo/a/b/c/ /foo/a/b/ c/ diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 5a169b68d6..5a8a48287c 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -245,9 +245,13 @@ test_expect_success 'git branch -M baz bam should succeed within a worktree in w ( cd bazdir && git branch -M baz bam && - test $(git rev-parse --abbrev-ref HEAD) = bam + echo bam >expect && + git rev-parse --abbrev-ref HEAD >actual && + test_cmp expect actual ) && - test $(git rev-parse --abbrev-ref HEAD) = bam && + echo bam >expect && + git rev-parse --abbrev-ref HEAD >actual && + test_cmp expect actual && rm -r bazdir && git worktree prune ' diff --git a/t/t5605-clone-local.sh b/t/t5605-clone-local.sh index 38b850c10e..1d7b1abda1 100755 --- a/t/t5605-clone-local.sh +++ b/t/t5605-clone-local.sh @@ -15,8 +15,12 @@ test_expect_success 'preparing origin repository' ' : >file && git add . && git commit -m1 && git clone --bare . a.git && git clone --bare . x && - test "$(cd a.git && git config --bool core.bare)" = true && - test "$(cd x && git config --bool core.bare)" = true && + echo true >expect && + git -C a.git config --bool core.bare >actual && + test_cmp expect actual && + echo true >expect && + git -C x config --bool core.bare >actual && + test_cmp expect actual && git bundle create b1.bundle --all && git bundle create b2.bundle main && mkdir dir && @@ -29,7 +33,9 @@ test_expect_success 'preparing origin repository' ' test_expect_success 'local clone without .git suffix' ' git clone -l -s a b && (cd b && - test "$(git config --bool core.bare)" = false && + echo false >expect && + git config --bool core.bare >actual && + test_cmp expect actual && git fetch) ' diff --git a/t/t7402-submodule-rebase.sh b/t/t7402-submodule-rebase.sh index ebeca12a71..1927a86283 100755 --- a/t/t7402-submodule-rebase.sh +++ b/t/t7402-submodule-rebase.sh @@ -82,11 +82,19 @@ test_expect_success 'stash with a dirty submodule' ' CURRENT=$(cd submodule && git rev-parse HEAD) && git stash && test new != $(cat file) && - test submodule = $(git diff --name-only) && - test $CURRENT = $(cd submodule && git rev-parse HEAD) && + echo submodule >expect && + git diff --name-only >actual && + test_cmp expect actual && + + echo "$CURRENT" >expect && + git -C submodule rev-parse HEAD >actual && + test_cmp expect actual && + git stash apply && test new = $(cat file) && - test $CURRENT = $(cd submodule && git rev-parse HEAD) + echo "$CURRENT" >expect && + git -C submodule rev-parse HEAD >actual && + test_cmp expect actual ' From c7e03b4e39d40b431764797d3a792169cd375705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 6 Feb 2023 23:44:32 +0100 Subject: [PATCH 005/508] tests: don't lose "git" exit codes in "! ( git ... | grep )" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change tests that would lose the "git" exit code via a negation pattern to: - In the case of "t0055-beyond-symlinks.sh" compare against the expected output instead. We could use the same pattern as in the "t3700-add.sh" below, doing so would have the advantage that if we added an earlier test we wouldn't need to adjust the "expect" output. But as "t0055-beyond-symlinks.sh" is a small and focused test (less than 40 lines in total) let's use "test_cmp" instead. - For "t3700-add.sh" use "sed -n" to print the expected "bad" part, and use "test_must_be_empty" to assert that it's not there. If we used "grep" we'd get a non-zero exit code. We could use "test_expect_code 1 grep", but this is more consistent with existing patterns in the test suite. We can also remove a repeated invocation of "git ls-files" for the last test that's being modified in that file, and search the existing "files" output instead. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t0055-beyond-symlinks.sh | 14 ++++++++++++-- t/t3700-add.sh | 18 +++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/t/t0055-beyond-symlinks.sh b/t/t0055-beyond-symlinks.sh index 6bada37022..c3eb1158ef 100755 --- a/t/t0055-beyond-symlinks.sh +++ b/t/t0055-beyond-symlinks.sh @@ -15,12 +15,22 @@ test_expect_success SYMLINKS setup ' test_expect_success SYMLINKS 'update-index --add beyond symlinks' ' test_must_fail git update-index --add c/d && - ! ( git ls-files | grep c/d ) + cat >expect <<-\EOF && + a + b/d + EOF + git ls-files >actual && + test_cmp expect actual ' test_expect_success SYMLINKS 'add beyond symlinks' ' test_must_fail git add c/d && - ! ( git ls-files | grep c/d ) + cat >expect <<-\EOF && + a + b/d + EOF + git ls-files >actual && + test_cmp expect actual ' test_done diff --git a/t/t3700-add.sh b/t/t3700-add.sh index 51afbd7b24..82dd768944 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -106,24 +106,32 @@ test_expect_success '.gitignore test setup' ' test_expect_success '.gitignore is honored' ' git add . && - ! (git ls-files | grep "\\.ig") + git ls-files >files && + sed -n "/\\.ig/p" actual && + test_must_be_empty actual ' test_expect_success 'error out when attempting to add ignored ones without -f' ' test_must_fail git add a.?? && - ! (git ls-files | grep "\\.ig") + git ls-files >files && + sed -n "/\\.ig/p" actual && + test_must_be_empty actual ' test_expect_success 'error out when attempting to add ignored ones without -f' ' test_must_fail git add d.?? && - ! (git ls-files | grep "\\.ig") + git ls-files >files && + sed -n "/\\.ig/p" actual && + test_must_be_empty actual ' test_expect_success 'error out when attempting to add ignored ones but add others' ' touch a.if && test_must_fail git add a.?? && - ! (git ls-files | grep "\\.ig") && - (git ls-files | grep a.if) + git ls-files >files && + sed -n "/\\.ig/p" actual && + test_must_be_empty actual && + grep a.if files ' test_expect_success 'add ignored ones with -f' ' From 4bd0785dc2eb7b3f23d25c8013337cc51ab1065d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 6 Feb 2023 23:44:31 +0100 Subject: [PATCH 006/508] tests: don't lose exit status with "test $(git ...)" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As with the preceding commit, rewrite tests that ran "git" inside command substitution and lost the exit status of "git" so that we notice the failing "git". This time around we're converting cases that didn't involve a containing sub-shell around the command substitution. In the case of "t0060-path-utils.sh" and "t2005-checkout-index-symlinks.sh" convert the relevant code to using the modern style of indentation and newline wrapping while having to change it. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/lib-submodule-update.sh | 4 +- t/t0001-init.sh | 9 ++- t/t0002-gitfile.sh | 4 +- t/t0060-path-utils.sh | 103 +++++++++++++++++++++-------- t/t0100-previous.sh | 8 ++- t/t1504-ceiling-dirs.sh | 8 ++- t/t2005-checkout-index-symlinks.sh | 8 ++- t/t5522-pull-symlink.sh | 4 +- t/t7402-submodule-rebase.sh | 9 ++- t/t7504-commit-msg-hook.sh | 4 +- t/t7810-grep.sh | 4 +- 11 files changed, 120 insertions(+), 45 deletions(-) diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh index d7c2b670b4..dee14992c5 100644 --- a/t/lib-submodule-update.sh +++ b/t/lib-submodule-update.sh @@ -185,7 +185,9 @@ test_git_directory_exists () { if test -f sub1/.git then # does core.worktree point at the right place? - test "$(git -C .git/modules/$1 config core.worktree)" = "../../../$1" + echo "../../../$1" >expect && + git -C ".git/modules/$1" config core.worktree >actual && + test_cmp expect actual fi } diff --git a/t/t0001-init.sh b/t/t0001-init.sh index d479303efa..30a6edca1d 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -598,9 +598,14 @@ test_expect_success 'invalid default branch name' ' test_expect_success 'branch -m with the initial branch' ' git init rename-initial && git -C rename-initial branch -m renamed && - test renamed = $(git -C rename-initial symbolic-ref --short HEAD) && + echo renamed >expect && + git -C rename-initial symbolic-ref --short HEAD >actual && + test_cmp expect actual && + git -C rename-initial branch -m renamed again && - test again = $(git -C rename-initial symbolic-ref --short HEAD) + echo again >expect && + git -C rename-initial symbolic-ref --short HEAD >actual && + test_cmp expect actual ' test_done diff --git a/t/t0002-gitfile.sh b/t/t0002-gitfile.sh index 26eaca095a..e013d38f48 100755 --- a/t/t0002-gitfile.sh +++ b/t/t0002-gitfile.sh @@ -33,7 +33,9 @@ test_expect_success 'bad setup: invalid .git file path' ' test_expect_success 'final setup + check rev-parse --git-dir' ' echo "gitdir: $REAL" >.git && - test "$REAL" = "$(git rev-parse --git-dir)" + echo "$REAL" >expect && + git rev-parse --git-dir >actual && + test_cmp expect actual ' test_expect_success 'check hash-object' ' diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index dcc78fb6a7..0afa3d0d31 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -10,20 +10,27 @@ TEST_PASSES_SANITIZE_LEAK=true norm_path() { expected=$(test-tool path-utils print_path "$2") - test_expect_success $3 "normalize path: $1 => $2" \ - "test \"\$(test-tool path-utils normalize_path_copy '$1')\" = '$expected'" + test_expect_success $3 "normalize path: $1 => $2" " + echo '$expected' >expect && + test-tool path-utils normalize_path_copy '$1' >actual && + test_cmp expect actual + " } relative_path() { expected=$(test-tool path-utils print_path "$3") - test_expect_success $4 "relative path: $1 $2 => $3" \ - "test \"\$(test-tool path-utils relative_path '$1' '$2')\" = '$expected'" + test_expect_success $4 "relative path: $1 $2 => $3" " + echo '$expected' >expect && + test-tool path-utils relative_path '$1' '$2' >actual && + test_cmp expect actual + " } test_submodule_relative_url() { test_expect_success "test_submodule_relative_url: $1 $2 $3 => $4" " - actual=\$(test-tool submodule resolve-relative-url '$1' '$2' '$3') && - test \"\$actual\" = '$4' + echo '$4' >expect && + test-tool submodule resolve-relative-url '$1' '$2' '$3' >actual && + test_cmp expect actual " } @@ -64,9 +71,11 @@ ancestor() { expected=$(($expected-$rootslash+$rootoff)) ;; esac - test_expect_success $4 "longest ancestor: $1 $2 => $expected" \ - "actual=\$(test-tool path-utils longest_ancestor_length '$1' '$2') && - test \"\$actual\" = '$expected'" + test_expect_success $4 "longest ancestor: $1 $2 => $expected" " + echo '$expected' >expect && + test-tool path-utils longest_ancestor_length '$1' '$2' >actual && + test_cmp expect actual + " } # Some absolute path tests should be skipped on Windows due to path mangling @@ -166,8 +175,10 @@ ancestor D:/Users/me C:/ -1 MINGW ancestor //server/share/my-directory //server/share/ 14 MINGW test_expect_success 'strip_path_suffix' ' - test c:/msysgit = $(test-tool path-utils strip_path_suffix \ - c:/msysgit/libexec//git-core libexec/git-core) + echo c:/msysgit >expect && + test-tool path-utils strip_path_suffix \ + c:/msysgit/libexec//git-core libexec/git-core >actual && + test_cmp expect actual ' test_expect_success 'absolute path rejects the empty string' ' @@ -188,35 +199,61 @@ test_expect_success 'real path rejects the empty string' ' ' test_expect_success POSIX 'real path works on absolute paths 1' ' + echo / >expect && + test-tool path-utils real_path "/" >actual && + test_cmp expect actual && + nopath="hopefully-absent-path" && - test "/" = "$(test-tool path-utils real_path "/")" && - test "/$nopath" = "$(test-tool path-utils real_path "/$nopath")" + echo "/$nopath" >expect && + test-tool path-utils real_path "/$nopath" >actual && + test_cmp expect actual ' test_expect_success 'real path works on absolute paths 2' ' - nopath="hopefully-absent-path" && # Find an existing top-level directory for the remaining tests: d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") && - test "$d" = "$(test-tool path-utils real_path "$d")" && - test "$d/$nopath" = "$(test-tool path-utils real_path "$d/$nopath")" + echo "$d" >expect && + test-tool path-utils real_path "$d" >actual && + test_cmp expect actual && + + nopath="hopefully-absent-path" && + echo "$d/$nopath" >expect && + test-tool path-utils real_path "$d/$nopath" >actual && + test_cmp expect actual ' test_expect_success POSIX 'real path removes extra leading slashes' ' + echo "/" >expect && + test-tool path-utils real_path "///" >actual && + test_cmp expect actual && + nopath="hopefully-absent-path" && - test "/" = "$(test-tool path-utils real_path "///")" && - test "/$nopath" = "$(test-tool path-utils real_path "///$nopath")" && + echo "/$nopath" >expect && + test-tool path-utils real_path "///$nopath" >actual && + test_cmp expect actual && + # Find an existing top-level directory for the remaining tests: d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") && - test "$d" = "$(test-tool path-utils real_path "//$d")" && - test "$d/$nopath" = "$(test-tool path-utils real_path "//$d/$nopath")" + echo "$d" >expect && + test-tool path-utils real_path "//$d" >actual && + test_cmp expect actual && + + echo "$d/$nopath" >expect && + test-tool path-utils real_path "//$d/$nopath" >actual && + test_cmp expect actual ' test_expect_success 'real path removes other extra slashes' ' - nopath="hopefully-absent-path" && # Find an existing top-level directory for the remaining tests: d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") && - test "$d" = "$(test-tool path-utils real_path "$d///")" && - test "$d/$nopath" = "$(test-tool path-utils real_path "$d///$nopath")" + echo "$d" >expect && + test-tool path-utils real_path "$d///" >actual && + test_cmp expect actual && + + nopath="hopefully-absent-path" && + echo "$d/$nopath" >expect && + test-tool path-utils real_path "$d///$nopath" >actual && + test_cmp expect actual ' test_expect_success SYMLINKS 'real path works on symlinks' ' @@ -227,19 +264,29 @@ test_expect_success SYMLINKS 'real path works on symlinks' ' mkdir third && dir="$(cd .git && pwd -P)" && dir2=third/../second/other/.git && - test "$dir" = "$(test-tool path-utils real_path $dir2)" && + echo "$dir" >expect && + test-tool path-utils real_path $dir2 >actual && + test_cmp expect actual && file="$dir"/index && - test "$file" = "$(test-tool path-utils real_path $dir2/index)" && + echo "$file" >expect && + test-tool path-utils real_path $dir2/index >actual && + test_cmp expect actual && basename=blub && - test "$dir/$basename" = "$(cd .git && test-tool path-utils real_path "$basename")" && + echo "$dir/$basename" >expect && + test-tool -C .git path-utils real_path "$basename" >actual && + test_cmp expect actual && ln -s ../first/file .git/syml && sym="$(cd first && pwd -P)"/file && - test "$sym" = "$(test-tool path-utils real_path "$dir2/syml")" + echo "$sym" >expect && + test-tool path-utils real_path "$dir2/syml" >actual && + test_cmp expect actual ' test_expect_success SYMLINKS 'prefix_path works with absolute paths to work tree symlinks' ' ln -s target symlink && - test "$(test-tool path-utils prefix_path prefix "$(pwd)/symlink")" = "symlink" + echo "symlink" >expect && + test-tool path-utils prefix_path prefix "$(pwd)/symlink" >actual && + test_cmp expect actual ' test_expect_success 'prefix_path works with only absolute path to work tree' ' diff --git a/t/t0100-previous.sh b/t/t0100-previous.sh index a16cc3d298..70a3223f21 100755 --- a/t/t0100-previous.sh +++ b/t/t0100-previous.sh @@ -12,7 +12,9 @@ test_expect_success 'branch -d @{-1}' ' test_commit A && git checkout -b junk && git checkout - && - test "$(git symbolic-ref HEAD)" = refs/heads/main && + echo refs/heads/main >expect && + git symbolic-ref HEAD >actual && + test_cmp expect actual && git branch -d @{-1} && test_must_fail git rev-parse --verify refs/heads/junk ' @@ -21,7 +23,9 @@ test_expect_success 'branch -d @{-12} when there is not enough switches yet' ' git reflog expire --expire=now && git checkout -b junk2 && git checkout - && - test "$(git symbolic-ref HEAD)" = refs/heads/main && + echo refs/heads/main >expect && + git symbolic-ref HEAD >actual && + test_cmp expect actual && test_must_fail git branch -d @{-12} && git rev-parse --verify refs/heads/main ' diff --git a/t/t1504-ceiling-dirs.sh b/t/t1504-ceiling-dirs.sh index 0fafcf9dde..c1679e31d8 100755 --- a/t/t1504-ceiling-dirs.sh +++ b/t/t1504-ceiling-dirs.sh @@ -6,8 +6,12 @@ TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_prefix() { - test_expect_success "$1" \ - "test '$2' = \"\$(git rev-parse --show-prefix)\"" + local expect="$2" && + test_expect_success "$1: git rev-parse --show-prefix is '$2'" ' + echo "$expect" >expect && + git rev-parse --show-prefix >actual && + test_cmp expect actual + ' } test_fail() { diff --git a/t/t2005-checkout-index-symlinks.sh b/t/t2005-checkout-index-symlinks.sh index 112682a45a..67d18cfa10 100755 --- a/t/t2005-checkout-index-symlinks.sh +++ b/t/t2005-checkout-index-symlinks.sh @@ -22,8 +22,10 @@ test_expect_success \ git checkout-index symlink && test -f symlink' -test_expect_success \ -'the file must be the blob we added during the setup' ' -test "$(git hash-object -t blob symlink)" = $l' +test_expect_success 'the file must be the blob we added during the setup' ' + echo "$l" >expect && + git hash-object -t blob symlink >actual && + test_cmp expect actual +' test_done diff --git a/t/t5522-pull-symlink.sh b/t/t5522-pull-symlink.sh index bcff460d0a..9fb73a8c3e 100755 --- a/t/t5522-pull-symlink.sh +++ b/t/t5522-pull-symlink.sh @@ -78,7 +78,9 @@ test_expect_success SYMLINKS 'pushing from symlinked subdir' ' git commit -m push ./file && git push ) && - test push = $(git show HEAD:subdir/file) + echo push >expect && + git show HEAD:subdir/file >actual && + test_cmp expect actual ' test_done diff --git a/t/t7402-submodule-rebase.sh b/t/t7402-submodule-rebase.sh index 1927a86283..c74798e8d2 100755 --- a/t/t7402-submodule-rebase.sh +++ b/t/t7402-submodule-rebase.sh @@ -55,12 +55,15 @@ chmod a+x fake-editor.sh test_expect_success 'interactive rebase with a dirty submodule' ' - test submodule = $(git diff --name-only) && + echo submodule >expect && + git diff --name-only >actual && + test_cmp expect actual && HEAD=$(git rev-parse HEAD) && GIT_EDITOR="\"$(pwd)/fake-editor.sh\"" EDITOR_TEXT="pick $HEAD" \ git rebase -i HEAD^ && - test submodule = $(git diff --name-only) - + echo submodule >expect && + git diff --name-only >actual && + test_cmp expect actual ' test_expect_success 'rebase with dirty file and submodule fails' ' diff --git a/t/t7504-commit-msg-hook.sh b/t/t7504-commit-msg-hook.sh index a39de8c112..c0f024eb1e 100755 --- a/t/t7504-commit-msg-hook.sh +++ b/t/t7504-commit-msg-hook.sh @@ -101,7 +101,9 @@ test_expect_success 'setup: commit-msg hook that always fails' ' ' commit_msg_is () { - test "$(git log --pretty=format:%s%b -1)" = "$1" + printf "%s" "$1" >expect && + git log --pretty=format:%s%b -1 >actual && + test_cmp expect actual } test_expect_success 'with failing hook' ' diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 8eded6ab27..39d6d713ec 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -1001,7 +1001,9 @@ test_expect_success 'log --committer does not search in timestamp' ' test_expect_success 'grep with CE_VALID file' ' git update-index --assume-unchanged t/t && rm t/t && - test "$(git grep test)" = "t/t:test" && + echo "t/t:test" >expect && + git grep test >actual && + test_cmp expect actual && git update-index --no-assume-unchanged t/t && git checkout t/t ' From 9fdc79ecba0f4a3ef885f1409d2db5a1dbabd649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 6 Feb 2023 23:44:33 +0100 Subject: [PATCH 007/508] tests: don't lose misc "git" exit codes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix a few miscellaneous cases where: - We lost the "git" exit code via "git ... | grep" - Likewise by having a $(git) argument to git itself - Used "test -z" to check that a command emitted no output, we can use "test_must_be_empty" and &&-chaining instead. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t1401-symbolic-ref.sh | 3 ++- t/t3701-add-interactive.sh | 8 +++++--- t/t7516-commit-races.sh | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/t/t1401-symbolic-ref.sh b/t/t1401-symbolic-ref.sh index d708acdb81..5e36899d20 100755 --- a/t/t1401-symbolic-ref.sh +++ b/t/t1401-symbolic-ref.sh @@ -33,7 +33,8 @@ test_expect_success 'symbolic-ref refuses non-ref for HEAD' ' reset_to_sane test_expect_success 'symbolic-ref refuses bare sha1' ' - test_must_fail git symbolic-ref HEAD $(git rev-parse HEAD) + rev=$(git rev-parse HEAD) && + test_must_fail git symbolic-ref HEAD "$rev" ' reset_to_sane diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 5841f280fb..f1fe5d6067 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -296,9 +296,11 @@ test_expect_success FILEMODE 'stage mode and hunk' ' echo content >>file && chmod +x file && printf "y\\ny\\n" | git add -p && - git diff --cached file | grep "new mode" && - git diff --cached file | grep "+content" && - test -z "$(git diff file)" + git diff --cached file >out && + grep "new mode" out && + grep "+content" out && + git diff file >out && + test_must_be_empty out ' # end of tests disabled when filemode is not usable diff --git a/t/t7516-commit-races.sh b/t/t7516-commit-races.sh index f2ce14e907..2d38a16480 100755 --- a/t/t7516-commit-races.sh +++ b/t/t7516-commit-races.sh @@ -10,7 +10,8 @@ test_expect_success 'race to create orphan commit' ' test_must_fail env EDITOR=./hare-editor git commit --allow-empty -m tortoise -e && git show -s --pretty=format:%s >subject && grep hare subject && - test -z "$(git show -s --pretty=format:%P)" + git show -s --pretty=format:%P >out && + test_must_be_empty out ' test_expect_success 'race to create non-orphan commit' ' From fd2d4c135ed974fdddf2af687748d28c58575984 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 9 Feb 2023 12:24:14 -0800 Subject: [PATCH 008/508] gpg-interface: lazily initialize and read the configuration Instead of forcing the porcelain commands to always read the configuration variables related to the signing and verifying signatures, lazily initialize the necessary subsystem on demand upon the first use. This hopefully would make it more future-proof as we do not have to think and decide whether we should call git_gpg_config() in the git_config() callback for each command. A few git_config() callback functions that used to be custom callbacks are now just a thin wrapper around git_default_config(). We could further remove, git_FOO_config and replace calls to git_config(git_FOO_config) with git_config(git_default_config), but to make it clear which ones are affected and the effect is only the removal of git_gpg_config(), it is vastly preferred not to do such a change in this step (they can be done on top once the dust settled). Signed-off-by: Junio C Hamano --- builtin/am.c | 6 ------ builtin/commit-tree.c | 3 --- builtin/commit.c | 4 ---- builtin/log.c | 2 -- builtin/merge.c | 3 --- builtin/pull.c | 6 ------ builtin/push.c | 5 ----- builtin/receive-pack.c | 4 ---- builtin/send-pack.c | 2 -- builtin/tag.c | 5 ----- builtin/verify-commit.c | 3 --- builtin/verify-tag.c | 3 --- fmt-merge-msg.c | 5 ----- gpg-interface.c | 24 +++++++++++++++++++++++- gpg-interface.h | 1 - sequencer.c | 4 ---- t/t7031-verify-tag-signed-ssh.sh | 10 ++++++++++ 17 files changed, 33 insertions(+), 57 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 82a41cbfc4..40126b59c5 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -2314,12 +2314,6 @@ static int parse_opt_show_current_patch(const struct option *opt, const char *ar static int git_am_config(const char *k, const char *v, void *cb UNUSED) { - int status; - - status = git_gpg_config(k, v, NULL); - if (status) - return status; - return git_default_config(k, v, NULL); } diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index cc8d584be2..f6a099d601 100644 --- a/builtin/commit-tree.c +++ b/builtin/commit-tree.c @@ -39,9 +39,6 @@ static void new_parent(struct commit *parent, struct commit_list **parents_p) static int commit_tree_config(const char *var, const char *value, void *cb) { - int status = git_gpg_config(var, value, NULL); - if (status) - return status; return git_default_config(var, value, cb); } diff --git a/builtin/commit.c b/builtin/commit.c index 44b763d7cd..794500dc9e 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1600,7 +1600,6 @@ int cmd_status(int argc, const char **argv, const char *prefix) static int git_commit_config(const char *k, const char *v, void *cb) { struct wt_status *s = cb; - int status; if (!strcmp(k, "commit.template")) return git_config_pathname(&template_file, k, v); @@ -1620,9 +1619,6 @@ static int git_commit_config(const char *k, const char *v, void *cb) return 0; } - status = git_gpg_config(k, v, NULL); - if (status) - return status; return git_status_config(k, v, s); } diff --git a/builtin/log.c b/builtin/log.c index 04412dd9c9..56741c6d37 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -601,8 +601,6 @@ static int git_log_config(const char *var, const char *value, void *cb) return 0; } - if (git_gpg_config(var, value, cb) < 0) - return -1; return git_diff_ui_config(var, value, cb); } diff --git a/builtin/merge.c b/builtin/merge.c index 74de2ebd2b..289c13656c 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -659,9 +659,6 @@ static int git_merge_config(const char *k, const char *v, void *cb) } status = fmt_merge_msg_config(k, v, cb); - if (status) - return status; - status = git_gpg_config(k, v, NULL); if (status) return status; return git_diff_ui_config(k, v, cb); diff --git a/builtin/pull.c b/builtin/pull.c index 1ab4de0005..4367727db6 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -359,8 +359,6 @@ static enum rebase_type config_get_rebase(int *rebase_unspecified) */ static int git_pull_config(const char *var, const char *value, void *cb) { - int status; - if (!strcmp(var, "rebase.autostash")) { config_autostash = git_config_bool(var, value); return 0; @@ -372,10 +370,6 @@ static int git_pull_config(const char *var, const char *value, void *cb) check_trust_level = 0; } - status = git_gpg_config(var, value, cb); - if (status) - return status; - return git_default_config(var, value, cb); } diff --git a/builtin/push.c b/builtin/push.c index 60ac8017e5..8f8904dd08 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -502,11 +502,6 @@ static int git_push_config(const char *k, const char *v, void *cb) { const char *slot_name; int *flags = cb; - int status; - - status = git_gpg_config(k, v, NULL); - if (status) - return status; if (!strcmp(k, "push.followtags")) { if (git_config_bool(k, v)) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index a90af30363..9894dbdc79 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -133,10 +133,6 @@ static int receive_pack_config(const char *var, const char *value, void *cb) { int status = parse_hide_refs_config(var, value, "receive", &hidden_refs); - if (status) - return status; - - status = git_gpg_config(var, value, NULL); if (status) return status; diff --git a/builtin/send-pack.c b/builtin/send-pack.c index 4c5d125fa0..c31e27346b 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -130,8 +130,6 @@ static void print_helper_status(struct ref *ref) static int send_pack_config(const char *k, const char *v, void *cb) { - git_gpg_config(k, v, NULL); - if (!strcmp(k, "push.gpgsign")) { const char *value; if (!git_config_get_value("push.gpgsign", &value)) { diff --git a/builtin/tag.c b/builtin/tag.c index d428c45dc8..725cfcd62b 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -180,8 +180,6 @@ static const char tag_template_nocleanup[] = static int git_tag_config(const char *var, const char *value, void *cb) { - int status; - if (!strcmp(var, "tag.gpgsign")) { config_sign_tag = git_config_bool(var, value); return 0; @@ -194,9 +192,6 @@ static int git_tag_config(const char *var, const char *value, void *cb) return 0; } - status = git_gpg_config(var, value, cb); - if (status) - return status; if (!strcmp(var, "tag.forcesignannotated")) { force_sign_annotate = git_config_bool(var, value); return 0; diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c index 3ebad32b0f..3c5d0b024c 100644 --- a/builtin/verify-commit.c +++ b/builtin/verify-commit.c @@ -54,9 +54,6 @@ static int verify_commit(const char *name, unsigned flags) static int git_verify_commit_config(const char *var, const char *value, void *cb) { - int status = git_gpg_config(var, value, cb); - if (status) - return status; return git_default_config(var, value, cb); } diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c index 217566952d..ecffb069bf 100644 --- a/builtin/verify-tag.c +++ b/builtin/verify-tag.c @@ -21,9 +21,6 @@ static const char * const verify_tag_usage[] = { static int git_verify_tag_config(const char *var, const char *value, void *cb) { - int status = git_gpg_config(var, value, cb); - if (status) - return status; return git_default_config(var, value, cb); } diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c index f48f44f9cd..9b83c95a08 100644 --- a/fmt-merge-msg.c +++ b/fmt-merge-msg.c @@ -17,8 +17,6 @@ static struct string_list suppress_dest_patterns = STRING_LIST_INIT_DUP; int fmt_merge_msg_config(const char *key, const char *value, void *cb) { - int status = 0; - if (!strcmp(key, "merge.log") || !strcmp(key, "merge.summary")) { int is_bool; merge_log_config = git_config_bool_or_int(key, value, &is_bool); @@ -37,9 +35,6 @@ int fmt_merge_msg_config(const char *key, const char *value, void *cb) string_list_append(&suppress_dest_patterns, value); suppress_dest_pattern_seen = 1; } else { - status = git_gpg_config(key, value, NULL); - if (status) - return status; return git_default_config(key, value, cb); } return 0; diff --git a/gpg-interface.c b/gpg-interface.c index 687236430b..404d4cccf3 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -9,6 +9,18 @@ #include "tempfile.h" #include "alias.h" +static int git_gpg_config(const char *, const char *, void *); + +static void gpg_interface_lazy_init(void) +{ + static int done; + + if (done) + return; + done = 1; + git_config(git_gpg_config, NULL); +} + static char *configured_signing_key; static const char *ssh_default_key_command, *ssh_allowed_signers, *ssh_revocation_file; static enum signature_trust_level configured_min_trust_level = TRUST_UNDEFINED; @@ -632,6 +644,8 @@ int check_signature(struct signature_check *sigc, struct gpg_format *fmt; int status; + gpg_interface_lazy_init(); + sigc->result = 'N'; sigc->trust_level = -1; @@ -695,11 +709,13 @@ int parse_signature(const char *buf, size_t size, struct strbuf *payload, struct void set_signing_key(const char *key) { + gpg_interface_lazy_init(); + free(configured_signing_key); configured_signing_key = xstrdup(key); } -int git_gpg_config(const char *var, const char *value, void *cb UNUSED) +static int git_gpg_config(const char *var, const char *value, void *cb UNUSED) { struct gpg_format *fmt = NULL; char *fmtname = NULL; @@ -888,6 +904,8 @@ static const char *get_ssh_key_id(void) { /* Returns a textual but unique representation of the signing key */ const char *get_signing_key_id(void) { + gpg_interface_lazy_init(); + if (use_format->get_key_id) { return use_format->get_key_id(); } @@ -898,6 +916,8 @@ const char *get_signing_key_id(void) const char *get_signing_key(void) { + gpg_interface_lazy_init(); + if (configured_signing_key) return configured_signing_key; if (use_format->get_default_key) { @@ -923,6 +943,8 @@ const char *gpg_trust_level_to_str(enum signature_trust_level level) int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key) { + gpg_interface_lazy_init(); + return use_format->sign_buffer(buffer, signature, signing_key); } diff --git a/gpg-interface.h b/gpg-interface.h index 8a9ef41779..143cdc1c02 100644 --- a/gpg-interface.h +++ b/gpg-interface.h @@ -79,7 +79,6 @@ int sign_buffer(struct strbuf *buffer, struct strbuf *signature, */ const char *gpg_trust_level_to_str(enum signature_trust_level level); -int git_gpg_config(const char *, const char *, void *); void set_signing_key(const char *); const char *get_signing_key(void); diff --git a/sequencer.c b/sequencer.c index 3e4a197289..a234b1ff88 100644 --- a/sequencer.c +++ b/sequencer.c @@ -263,10 +263,6 @@ static int git_sequencer_config(const char *k, const char *v, void *cb) if (opts->action == REPLAY_REVERT && !strcmp(k, "revert.reference")) opts->commit_use_reference = git_config_bool(k, v); - status = git_gpg_config(k, v, NULL); - if (status) - return status; - return git_diff_basic_config(k, v, NULL); } diff --git a/t/t7031-verify-tag-signed-ssh.sh b/t/t7031-verify-tag-signed-ssh.sh index 36eb86a4b1..20913b3713 100755 --- a/t/t7031-verify-tag-signed-ssh.sh +++ b/t/t7031-verify-tag-signed-ssh.sh @@ -200,4 +200,14 @@ test_expect_success GPGSSH 'verifying a forged tag with --format should fail sil test_must_be_empty actual-forged ' +test_expect_success GPGSSH 'rev-list --format=%G' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + git rev-list -1 --format="%G? %H" sixth-signed >actual && + cat >expect <<-EOF && + commit $(git rev-parse sixth-signed^0) + G $(git rev-parse sixth-signed^0) + EOF + test_cmp expect actual +' + test_done From c5773dc078f05a98c9359938dbce3b3dc70aa3bd Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 11 Feb 2023 11:15:26 +0000 Subject: [PATCH 009/508] commit-reach: avoid NULL dereference The loop at the top of can_all_from_reach_with_flag() already accounts for `from->objects[i].item' being NULL, so it follows the cleanup loop should also account for a NULL `from_one'. I managed to segfault here on one of my giant, many-remote repos using `git fetch --negotiation-tip=... --negotiation-only' where the --negotiation-tip= argument was a glob which (inadvertently) captured more refs than I wanted. I have not reproduced this in a standalone test case. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- commit-reach.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/commit-reach.c b/commit-reach.c index 5a845440a9..7e422b0cd3 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -628,8 +628,12 @@ cleanup: } free(list); - for (i = 0; i < from->nr; i++) - from->objects[i].item->flags &= ~assign_flag; + for (i = 0; i < from->nr; i++) { + struct object *from_one = from->objects[i].item; + + if (from_one) + from_one->flags &= ~assign_flag; + } return result; } From 8bff5ca030d314d613e1ab58f07b27914d6dfd33 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 24 Feb 2023 00:09:20 +0000 Subject: [PATCH 010/508] treewide: ensure one of the appropriate headers is sourced first We had several C files ignoring the rule to include one of the appropriate headers first; fix that. While at it, the rule in Documentation/CodingGuidelines about which header to include has also fallen out of sync, so update the wording to mention other allowed headers. Unfortunately, C files in reftable/ don't actually follow the previous or updated rule. If you follow the #include chain in its C files, reftable/system.h _tends_ to be first (i.e. record.c first includes record.h, which first includes basics.h, which first includees system.h), but not always (e.g. publicbasics.c includes another header first that does not include system.h). However, I'm going to punt on making actual changes to the C files in reftable/ since I do not want to risk bringing it out-of-sync with any version being used externally. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- Documentation/CodingGuidelines | 8 ++++++-- cbtree.c | 1 + compat/fsmonitor/fsm-ipc-win32.c | 1 + compat/fsmonitor/fsm-settings-darwin.c | 1 + diff-merges.c | 1 + fmt-merge-msg.c | 1 + oidtree.c | 1 + oss-fuzz/fuzz-commit-graph.c | 1 + oss-fuzz/fuzz-pack-headers.c | 1 + oss-fuzz/fuzz-pack-idx.c | 1 + prune-packed.c | 1 + rebase.c | 1 + refs/debug.c | 2 +- sub-process.c | 1 + 14 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 9d5c27807a..003393ed16 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -442,8 +442,12 @@ For C programs: detail. - The first #include in C files, except in platform specific compat/ - implementations, must be either "git-compat-util.h", "cache.h" or - "builtin.h". You do not have to include more than one of these. + implementations and sha1dc/, must be either "git-compat-util.h" or + one of the approved headers that includes it first for you. (The + approved headers currently include "cache.h", "builtin.h", + "t/helper/test-tool.h", "xdiff/xinclude.h", or + "reftable/system.h"). You do not have to include more than one of + these. - A C file must directly include the header files that declare the functions and the types it uses, except for the functions and types diff --git a/cbtree.c b/cbtree.c index 336e46dbba..c1cc30a5dc 100644 --- a/cbtree.c +++ b/cbtree.c @@ -4,6 +4,7 @@ * Based on Adam Langley's adaptation of Dan Bernstein's public domain code * git clone https://github.com/agl/critbit.git */ +#include "git-compat-util.h" #include "cbtree.h" static struct cb_node *cb_node_of(const void *p) diff --git a/compat/fsmonitor/fsm-ipc-win32.c b/compat/fsmonitor/fsm-ipc-win32.c index e08c505c14..c9536dfb66 100644 --- a/compat/fsmonitor/fsm-ipc-win32.c +++ b/compat/fsmonitor/fsm-ipc-win32.c @@ -1,3 +1,4 @@ +#include "git-compat-util.h" #include "config.h" #include "fsmonitor-ipc.h" diff --git a/compat/fsmonitor/fsm-settings-darwin.c b/compat/fsmonitor/fsm-settings-darwin.c index 6abbc7af3a..58b623fbb9 100644 --- a/compat/fsmonitor/fsm-settings-darwin.c +++ b/compat/fsmonitor/fsm-settings-darwin.c @@ -1,3 +1,4 @@ +#include "git-compat-util.h" #include "config.h" #include "fsmonitor.h" #include "fsmonitor-ipc.h" diff --git a/diff-merges.c b/diff-merges.c index 85cbefa5af..faa7bc73a3 100644 --- a/diff-merges.c +++ b/diff-merges.c @@ -1,3 +1,4 @@ +#include "git-compat-util.h" #include "diff-merges.h" #include "revision.h" diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c index f48f44f9cd..f317f12990 100644 --- a/fmt-merge-msg.c +++ b/fmt-merge-msg.c @@ -1,3 +1,4 @@ +#include "git-compat-util.h" #include "config.h" #include "refs.h" #include "object-store.h" diff --git a/oidtree.c b/oidtree.c index 0d39389bee..7d57b7b19e 100644 --- a/oidtree.c +++ b/oidtree.c @@ -2,6 +2,7 @@ * A wrapper around cbtree which stores oids * May be used to replace oid-array for prefix (abbreviation) matches */ +#include "git-compat-util.h" #include "oidtree.h" #include "alloc.h" #include "hash.h" diff --git a/oss-fuzz/fuzz-commit-graph.c b/oss-fuzz/fuzz-commit-graph.c index 914026f5d8..2992079dd9 100644 --- a/oss-fuzz/fuzz-commit-graph.c +++ b/oss-fuzz/fuzz-commit-graph.c @@ -1,3 +1,4 @@ +#include "git-compat-util.h" #include "commit-graph.h" #include "repository.h" diff --git a/oss-fuzz/fuzz-pack-headers.c b/oss-fuzz/fuzz-pack-headers.c index 99da1d0fd3..150c0f5fa2 100644 --- a/oss-fuzz/fuzz-pack-headers.c +++ b/oss-fuzz/fuzz-pack-headers.c @@ -1,3 +1,4 @@ +#include "git-compat-util.h" #include "packfile.h" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); diff --git a/oss-fuzz/fuzz-pack-idx.c b/oss-fuzz/fuzz-pack-idx.c index 0c3d777aac..609a343ee3 100644 --- a/oss-fuzz/fuzz-pack-idx.c +++ b/oss-fuzz/fuzz-pack-idx.c @@ -1,3 +1,4 @@ +#include "git-compat-util.h" #include "object-store.h" #include "packfile.h" diff --git a/prune-packed.c b/prune-packed.c index 261520b472..d2813f6a40 100644 --- a/prune-packed.c +++ b/prune-packed.c @@ -1,3 +1,4 @@ +#include "git-compat-util.h" #include "object-store.h" #include "packfile.h" #include "progress.h" diff --git a/rebase.c b/rebase.c index 6775cddb28..17a570f1ff 100644 --- a/rebase.c +++ b/rebase.c @@ -1,3 +1,4 @@ +#include "git-compat-util.h" #include "rebase.h" #include "config.h" #include "gettext.h" diff --git a/refs/debug.c b/refs/debug.c index eed8bc94b0..ff7766bc63 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -1,4 +1,4 @@ - +#include "git-compat-util.h" #include "refs-internal.h" #include "trace.h" diff --git a/sub-process.c b/sub-process.c index 6d4232294d..1daf5a9752 100644 --- a/sub-process.c +++ b/sub-process.c @@ -1,6 +1,7 @@ /* * Generic implementation of background process infrastructure. */ +#include "git-compat-util.h" #include "sub-process.h" #include "sigchain.h" #include "pkt-line.h" From f332121e75d3aa2b0ce7efd120ac3ede19e9a733 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 24 Feb 2023 00:09:21 +0000 Subject: [PATCH 011/508] treewide: remove unnecessary git-compat-util.h includes in headers For sanity, we should probably do one of the following: (a) make C and header files both depend upon everything they need (b) consistently exclude git-compat-util.h from headers and require it be the first include in C files Currently, we have some of the headers following (a) and others following (b), which makes things messy. In the past I was pushed towards (b), as per [1] and [2]. Further, during this series I discovered that this mixture empirically will mean that we end up with C files that do not directly include git-compat-util.h, and do include headers that don't include git-compat-util.h, with the result that we likely have headers included before an indirect inclusion of git-compat-util.h. Since git-compat-util.h has tricky platform-specific stuff that is meant to be included before everything else, this state of affairs is risky and may lead to things breaking in subtle ways (and only on some platforms) as per [1] and [2]. Since including git-compat-util.h in existing header files makes it harder for us to catch C files that are missing that include, let's switch to (b) to make the enforcement of this rule easier. Remove the inclusion of git-compat-util.h from header files other than the ones that have been approved as alternate first includes. [1] https://lore.kernel.org/git/20180811173406.GA9119@sigill.intra.peff.net/ [2] https://lore.kernel.org/git/20180811174301.GA9287@sigill.intra.peff.net/ Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- advice.h | 2 -- cbtree.h | 2 -- chunk-format.h | 1 - commit-graph.h | 1 - commit-slab-impl.h | 2 -- hash.h | 1 - pack-mtimes.h | 2 -- pkt-line.h | 1 - repository.h | 1 - sub-process.h | 1 - trace.h | 1 - 11 files changed, 15 deletions(-) diff --git a/advice.h b/advice.h index 07e0f76833..3e1b48bf68 100644 --- a/advice.h +++ b/advice.h @@ -1,8 +1,6 @@ #ifndef ADVICE_H #define ADVICE_H -#include "git-compat-util.h" - struct string_list; /* diff --git a/cbtree.h b/cbtree.h index 0be14fb7ee..43193abdda 100644 --- a/cbtree.h +++ b/cbtree.h @@ -14,8 +14,6 @@ #ifndef CBTREE_H #define CBTREE_H -#include "git-compat-util.h" - struct cb_node; struct cb_node { struct cb_node *child[2]; diff --git a/chunk-format.h b/chunk-format.h index 7885aa0848..025c38f938 100644 --- a/chunk-format.h +++ b/chunk-format.h @@ -1,7 +1,6 @@ #ifndef CHUNK_FORMAT_H #define CHUNK_FORMAT_H -#include "git-compat-util.h" #include "hash.h" struct hashfile; diff --git a/commit-graph.h b/commit-graph.h index 37faee6b66..bb88bec7aa 100644 --- a/commit-graph.h +++ b/commit-graph.h @@ -1,7 +1,6 @@ #ifndef COMMIT_GRAPH_H #define COMMIT_GRAPH_H -#include "git-compat-util.h" #include "object-store.h" #include "oidset.h" diff --git a/commit-slab-impl.h b/commit-slab-impl.h index 557738df27..4a414ee905 100644 --- a/commit-slab-impl.h +++ b/commit-slab-impl.h @@ -1,8 +1,6 @@ #ifndef COMMIT_SLAB_IMPL_H #define COMMIT_SLAB_IMPL_H -#include "git-compat-util.h" - #define implement_static_commit_slab(slabname, elemtype) \ implement_commit_slab(slabname, elemtype, MAYBE_UNUSED static) diff --git a/hash.h b/hash.h index 36b64165fc..351afc2ce3 100644 --- a/hash.h +++ b/hash.h @@ -1,7 +1,6 @@ #ifndef HASH_H #define HASH_H -#include "git-compat-util.h" #include "repository.h" #if defined(SHA1_APPLE) diff --git a/pack-mtimes.h b/pack-mtimes.h index cc957b3e85..107327cec0 100644 --- a/pack-mtimes.h +++ b/pack-mtimes.h @@ -1,8 +1,6 @@ #ifndef PACK_MTIMES_H #define PACK_MTIMES_H -#include "git-compat-util.h" - #define MTIMES_SIGNATURE 0x4d544d45 /* "MTME" */ #define MTIMES_VERSION 1 diff --git a/pkt-line.h b/pkt-line.h index 79c538b99e..8e9846f315 100644 --- a/pkt-line.h +++ b/pkt-line.h @@ -1,7 +1,6 @@ #ifndef PKTLINE_H #define PKTLINE_H -#include "git-compat-util.h" #include "strbuf.h" #include "sideband.h" diff --git a/repository.h b/repository.h index e8c67ffe16..15a8afc5fb 100644 --- a/repository.h +++ b/repository.h @@ -1,7 +1,6 @@ #ifndef REPOSITORY_H #define REPOSITORY_H -#include "git-compat-util.h" #include "path.h" struct config_set; diff --git a/sub-process.h b/sub-process.h index e85f21fa1a..6a61638a8a 100644 --- a/sub-process.h +++ b/sub-process.h @@ -1,7 +1,6 @@ #ifndef SUBPROCESS_H #define SUBPROCESS_H -#include "git-compat-util.h" #include "hashmap.h" #include "run-command.h" diff --git a/trace.h b/trace.h index 4e771f86ac..1a75824b15 100644 --- a/trace.h +++ b/trace.h @@ -1,7 +1,6 @@ #ifndef TRACE_H #define TRACE_H -#include "git-compat-util.h" #include "strbuf.h" /** From ba3d1c73daa02152acf4729d45ca7fe4d71d5747 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 24 Feb 2023 00:09:22 +0000 Subject: [PATCH 012/508] treewide: remove unnecessary cache.h includes We had several header files include cache.h unnecessarily. Remove those. These have all been verified via both ensuring that gcc -E $HEADER | grep '"cache.h"' found no hits and that cat >temp.c < Signed-off-by: Junio C Hamano --- checkout.h | 2 +- entry.h | 4 +++- khash.h | 1 - oidmap.h | 1 - pretty.h | 2 +- reflog-walk.h | 2 -- refs/refs-internal.h | 1 - remote.h | 1 - sequencer.h | 2 +- xdiff-interface.h | 2 +- 10 files changed, 7 insertions(+), 11 deletions(-) diff --git a/checkout.h b/checkout.h index 1152133bd7..1917f3b323 100644 --- a/checkout.h +++ b/checkout.h @@ -1,7 +1,7 @@ #ifndef CHECKOUT_H #define CHECKOUT_H -#include "cache.h" +#include "hash.h" /* * Check if the branch name uniquely matches a branch name on a remote diff --git a/entry.h b/entry.h index 2d4fbb88c8..7329f918a9 100644 --- a/entry.h +++ b/entry.h @@ -1,9 +1,11 @@ #ifndef ENTRY_H #define ENTRY_H -#include "cache.h" #include "convert.h" +struct cache_entry; +struct index_state; + struct checkout { struct index_state *istate; const char *base_dir; diff --git a/khash.h b/khash.h index cb79bf8856..85362718c5 100644 --- a/khash.h +++ b/khash.h @@ -26,7 +26,6 @@ #ifndef __AC_KHASH_H #define __AC_KHASH_H -#include "cache.h" #include "hashmap.h" #define AC_VERSION_KHASH_H "0.2.8" diff --git a/oidmap.h b/oidmap.h index c66a83ab1d..c1642927fa 100644 --- a/oidmap.h +++ b/oidmap.h @@ -1,7 +1,6 @@ #ifndef OIDMAP_H #define OIDMAP_H -#include "cache.h" #include "hashmap.h" /* diff --git a/pretty.h b/pretty.h index f34e24c53a..9508c22f03 100644 --- a/pretty.h +++ b/pretty.h @@ -1,11 +1,11 @@ #ifndef PRETTY_H #define PRETTY_H -#include "cache.h" #include "date.h" #include "string-list.h" struct commit; +struct repository; struct strbuf; struct process_trailer_options; diff --git a/reflog-walk.h b/reflog-walk.h index 8076f10d9f..4d93a26957 100644 --- a/reflog-walk.h +++ b/reflog-walk.h @@ -1,8 +1,6 @@ #ifndef REFLOG_WALK_H #define REFLOG_WALK_H -#include "cache.h" - struct commit; struct reflog_walk_info; struct date_mode; diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 69f93b0e2a..a85d113123 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -1,7 +1,6 @@ #ifndef REFS_REFS_INTERNAL_H #define REFS_REFS_INTERNAL_H -#include "cache.h" #include "refs.h" #include "iterator.h" diff --git a/remote.h b/remote.h index 1ebbe42792..5b38ee20b8 100644 --- a/remote.h +++ b/remote.h @@ -1,7 +1,6 @@ #ifndef REMOTE_H #define REMOTE_H -#include "cache.h" #include "parse-options.h" #include "hashmap.h" #include "refspec.h" diff --git a/sequencer.h b/sequencer.h index 3bcdfa1b58..33dbaf5b66 100644 --- a/sequencer.h +++ b/sequencer.h @@ -1,11 +1,11 @@ #ifndef SEQUENCER_H #define SEQUENCER_H -#include "cache.h" #include "strbuf.h" #include "wt-status.h" struct commit; +struct index_state; struct repository; const char *git_path_commit_editmsg(void); diff --git a/xdiff-interface.h b/xdiff-interface.h index 4301a7eef2..3750794afe 100644 --- a/xdiff-interface.h +++ b/xdiff-interface.h @@ -1,7 +1,7 @@ #ifndef XDIFF_INTERFACE_H #define XDIFF_INTERFACE_H -#include "cache.h" +#include "hash.h" #include "xdiff/xdiff.h" /* From 15db4e7f4ac20cc41902a2479c7784fff8edf2e9 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 24 Feb 2023 00:09:23 +0000 Subject: [PATCH 013/508] treewide: remove unnecessary cache.h includes in source files We had several C files include cache.h unnecessarily. Replace those with an include of "git-compat-util.h" instead. Much like the previous commit, these have all been verified via both ensuring that gcc -E $SOURCE_FILE | grep '"cache.h"' found no hits and that make DEVELOPER=1 ${OBJECT_FILE_FOR_SOURCE_FILE} successfully compiles without warnings. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- hashmap.c | 2 +- imap-send.c | 2 +- json-writer.c | 2 +- kwset.c | 2 +- levenshtein.c | 2 +- linear-assignment.c | 2 +- mem-pool.c | 2 +- oidmap.c | 2 +- repo-settings.c | 2 +- serve.c | 3 ++- shell.c | 2 +- t/helper/test-crontab.c | 1 - t/helper/test-ctype.c | 1 - t/helper/test-json-writer.c | 1 - t/helper/test-pcre2-config.c | 1 - t/helper/test-prio-queue.c | 1 - t/helper/test-run-command.c | 2 -- t/helper/test-sigchain.c | 1 - t/helper/test-simple-ipc.c | 3 ++- t/helper/test-wildmatch.c | 1 - thread-utils.c | 2 +- trace2.c | 3 ++- trace2/tr2_ctr.c | 2 +- trace2/tr2_tbuf.c | 2 +- trace2/tr2_tgt_event.c | 2 +- trace2/tr2_tgt_normal.c | 2 +- trace2/tr2_tgt_perf.c | 2 +- trace2/tr2_tmr.c | 3 ++- unix-stream-server.c | 2 +- 29 files changed, 25 insertions(+), 30 deletions(-) diff --git a/hashmap.c b/hashmap.c index cf5fea87eb..ee45ef0085 100644 --- a/hashmap.c +++ b/hashmap.c @@ -1,7 +1,7 @@ /* * Generic implementation of hash-based key value mappings. */ -#include "cache.h" +#include "git-compat-util.h" #include "hashmap.h" #define FNV32_BASE ((unsigned int) 0x811c9dc5) diff --git a/imap-send.c b/imap-send.c index a50af56b82..93e9018439 100644 --- a/imap-send.c +++ b/imap-send.c @@ -21,7 +21,7 @@ * along with this program; if not, see . */ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "credential.h" #include "exec-cmd.h" diff --git a/json-writer.c b/json-writer.c index f1cfd8fa8c..005c820aa4 100644 --- a/json-writer.c +++ b/json-writer.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "json-writer.h" void jw_init(struct json_writer *jw) diff --git a/kwset.c b/kwset.c index 08aadf0311..4b14d4f86b 100644 --- a/kwset.c +++ b/kwset.c @@ -32,7 +32,7 @@ String Matching: An Aid to Bibliographic Search," CACM June 1975, Vol. 18, No. 6, which describes the failure function used below. */ -#include "cache.h" +#include "git-compat-util.h" #include "kwset.h" #include "compat/obstack.h" diff --git a/levenshtein.c b/levenshtein.c index d2632690d5..fd8026fe20 100644 --- a/levenshtein.c +++ b/levenshtein.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "levenshtein.h" /* diff --git a/linear-assignment.c b/linear-assignment.c index ecffc09be6..5416cbcf40 100644 --- a/linear-assignment.c +++ b/linear-assignment.c @@ -3,7 +3,7 @@ * algorithm for dense and sparse linear assignment problems. Computing, * 38(4), 325-340. */ -#include "cache.h" +#include "git-compat-util.h" #include "linear-assignment.h" #define COST(column, row) cost[(column) + column_count * (row)] diff --git a/mem-pool.c b/mem-pool.c index 599d8e895f..c34846d176 100644 --- a/mem-pool.c +++ b/mem-pool.c @@ -2,7 +2,7 @@ * Memory Pool implementation logic. */ -#include "cache.h" +#include "git-compat-util.h" #include "mem-pool.h" #define BLOCK_GROWTH_SIZE (1024 * 1024 - sizeof(struct mp_block)) diff --git a/oidmap.c b/oidmap.c index 49965fe856..8c1a139c97 100644 --- a/oidmap.c +++ b/oidmap.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "oidmap.h" static int oidmap_neq(const void *hashmap_cmp_fn_data UNUSED, diff --git a/repo-settings.c b/repo-settings.c index 3dbd3f0e2e..0a6c0b381f 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "repository.h" #include "midx.h" diff --git a/serve.c b/serve.c index cbf4a143cf..d128822347 100644 --- a/serve.c +++ b/serve.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "repository.h" #include "config.h" #include "pkt-line.h" @@ -8,6 +8,7 @@ #include "serve.h" #include "upload-pack.h" #include "bundle-uri.h" +#include "trace2.h" static int advertise_sid = -1; static int client_hash_algo = GIT_HASH_SHA1; diff --git a/shell.c b/shell.c index af0d7c734f..5c67e7bd97 100644 --- a/shell.c +++ b/shell.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "quote.h" #include "exec-cmd.h" #include "strbuf.h" diff --git a/t/helper/test-crontab.c b/t/helper/test-crontab.c index e6c1b1e22b..597027a96e 100644 --- a/t/helper/test-crontab.c +++ b/t/helper/test-crontab.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" /* * Usage: test-tool crontab -l| diff --git a/t/helper/test-ctype.c b/t/helper/test-ctype.c index 92c4c2313e..d6c1a2ed09 100644 --- a/t/helper/test-ctype.c +++ b/t/helper/test-ctype.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" static int rc; diff --git a/t/helper/test-json-writer.c b/t/helper/test-json-writer.c index 8c3edacc00..86887f5320 100644 --- a/t/helper/test-json-writer.c +++ b/t/helper/test-json-writer.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" #include "json-writer.h" static const char *expect_obj1 = "{\"a\":\"abc\",\"b\":42,\"c\":true}"; diff --git a/t/helper/test-pcre2-config.c b/t/helper/test-pcre2-config.c index 5258fdddba..5d0b2a2e10 100644 --- a/t/helper/test-pcre2-config.c +++ b/t/helper/test-pcre2-config.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" #include "grep.h" int cmd__pcre2_config(int argc, const char **argv) diff --git a/t/helper/test-prio-queue.c b/t/helper/test-prio-queue.c index 133b5e6f4a..ac4c65d705 100644 --- a/t/helper/test-prio-queue.c +++ b/t/helper/test-prio-queue.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" #include "prio-queue.h" static int intcmp(const void *va, const void *vb, void *data) diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c index 3ecb830f4a..67b42ef50e 100644 --- a/t/helper/test-run-command.c +++ b/t/helper/test-run-command.c @@ -9,8 +9,6 @@ */ #include "test-tool.h" -#include "git-compat-util.h" -#include "cache.h" #include "run-command.h" #include "strvec.h" #include "strbuf.h" diff --git a/t/helper/test-sigchain.c b/t/helper/test-sigchain.c index d013bccdda..d1cf7377b7 100644 --- a/t/helper/test-sigchain.c +++ b/t/helper/test-sigchain.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" #include "sigchain.h" #define X(f) \ diff --git a/t/helper/test-simple-ipc.c b/t/helper/test-simple-ipc.c index 28365ff85b..3d1436da59 100644 --- a/t/helper/test-simple-ipc.c +++ b/t/helper/test-simple-ipc.c @@ -3,13 +3,14 @@ */ #include "test-tool.h" -#include "cache.h" +#include "gettext.h" #include "strbuf.h" #include "simple-ipc.h" #include "parse-options.h" #include "thread-utils.h" #include "strvec.h" #include "run-command.h" +#include "trace2.h" #ifndef SUPPORTS_SIMPLE_IPC int cmd__simple_ipc(int argc, const char **argv) diff --git a/t/helper/test-wildmatch.c b/t/helper/test-wildmatch.c index 2c103d1824..a95bb4da9b 100644 --- a/t/helper/test-wildmatch.c +++ b/t/helper/test-wildmatch.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" int cmd__wildmatch(int argc, const char **argv) { diff --git a/thread-utils.c b/thread-utils.c index 5329845691..1f89ffab4c 100644 --- a/thread-utils.c +++ b/thread-utils.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "thread-utils.h" #if defined(hpux) || defined(__hpux) || defined(_hpux) diff --git a/trace2.c b/trace2.c index 279bddf53b..e8ba62c0c3 100644 --- a/trace2.c +++ b/trace2.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "json-writer.h" #include "quote.h" @@ -6,6 +6,7 @@ #include "sigchain.h" #include "thread-utils.h" #include "version.h" +#include "trace.h" #include "trace2/tr2_cfg.h" #include "trace2/tr2_cmd_name.h" #include "trace2/tr2_ctr.h" diff --git a/trace2/tr2_ctr.c b/trace2/tr2_ctr.c index 483ca7c308..b342d3b1a3 100644 --- a/trace2/tr2_ctr.c +++ b/trace2/tr2_ctr.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "thread-utils.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" diff --git a/trace2/tr2_tbuf.c b/trace2/tr2_tbuf.c index 2498482d9a..c3b3822ed7 100644 --- a/trace2/tr2_tbuf.c +++ b/trace2/tr2_tbuf.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "tr2_tbuf.h" void tr2_tbuf_local_time(struct tr2_tbuf *tb) diff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c index 16f6332755..9e7aab6d51 100644 --- a/trace2/tr2_tgt_event.c +++ b/trace2/tr2_tgt_event.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "json-writer.h" #include "run-command.h" diff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c index fbbef68dfc..8672c2c2d0 100644 --- a/trace2/tr2_tgt_normal.c +++ b/trace2/tr2_tgt_normal.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "run-command.h" #include "quote.h" diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c index adae803263..3f2b2d5311 100644 --- a/trace2/tr2_tgt_perf.c +++ b/trace2/tr2_tgt_perf.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "run-command.h" #include "quote.h" diff --git a/trace2/tr2_tmr.c b/trace2/tr2_tmr.c index 786762dfd2..31d0e4d1bd 100644 --- a/trace2/tr2_tmr.c +++ b/trace2/tr2_tmr.c @@ -1,8 +1,9 @@ -#include "cache.h" +#include "git-compat-util.h" #include "thread-utils.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" #include "trace2/tr2_tmr.h" +#include "trace.h" #define MY_MAX(a, b) ((a) > (b) ? (a) : (b)) #define MY_MIN(a, b) ((a) < (b) ? (a) : (b)) diff --git a/unix-stream-server.c b/unix-stream-server.c index efa2a207ab..22ac2373e0 100644 --- a/unix-stream-server.c +++ b/unix-stream-server.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "lockfile.h" #include "unix-socket.h" #include "unix-stream-server.h" From 36bf19589055fb71aac0ed6719dfe5b385adc2bf Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 24 Feb 2023 00:09:24 +0000 Subject: [PATCH 014/508] alloc.h: move ALLOC_GROW() functions from cache.h This allows us to replace includes of cache.h with includes of the much smaller alloc.h in many places. It does mean that we also need to add includes of alloc.h in a number of C files. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- add-patch.c | 1 + alias.c | 4 +- alloc.h | 75 ++++++++++++++++++++++++++++++ apply.c | 1 + archive-tar.c | 3 +- archive.c | 3 +- attr.c | 1 + builtin/blame.c | 3 +- builtin/cat-file.c | 1 + builtin/checkout--worker.c | 1 + builtin/config.c | 2 +- builtin/credential-cache--daemon.c | 1 + builtin/fetch-pack.c | 1 + builtin/fsmonitor--daemon.c | 1 + builtin/grep.c | 1 + builtin/index-pack.c | 1 + builtin/log.c | 3 +- builtin/merge.c | 1 + builtin/mktree.c | 1 + builtin/mv.c | 1 + builtin/name-rev.c | 2 +- builtin/pack-objects.c | 2 +- builtin/repack.c | 2 +- builtin/rev-parse.c | 1 + builtin/revert.c | 3 +- builtin/rm.c | 1 + builtin/submodule--helper.c | 1 + bulk-checkin.c | 3 +- cache-tree.c | 3 +- cache.h | 75 ------------------------------ chunk-format.c | 3 +- commit-reach.c | 3 +- compat/mingw.c | 1 + config.c | 3 +- daemon.c | 1 + delta-islands.c | 3 +- diff.c | 1 + diffcore-rename.c | 1 + dir-iterator.c | 3 +- dir.c | 3 +- ewah/bitmap.c | 3 +- ewah/ewah_bitmap.c | 2 +- fetch-pack.c | 3 +- fmt-merge-msg.c | 1 + fsck.c | 3 +- fsmonitor-settings.c | 3 +- help.c | 3 +- http-backend.c | 3 +- line-log.c | 1 + list-objects-filter-options.c | 4 +- list-objects-filter.c | 1 + midx.c | 3 +- object-file.c | 3 +- oid-array.c | 3 +- pack-bitmap-write.c | 3 +- pack-bitmap.c | 3 +- pack-objects.c | 3 +- packfile.c | 3 +- parallel-checkout.c | 1 + pretty.c | 1 + prio-queue.c | 3 +- quote.c | 1 + read-cache.c | 1 + ref-filter.c | 5 +- reflog-walk.c | 3 +- refs.c | 3 +- refs/packed-backend.c | 3 +- refs/ref-cache.c | 3 +- refspec.c | 3 +- remote-curl.c | 3 +- remote.c | 3 +- rerere.c | 3 +- revision.c | 3 +- sequencer.c | 1 + server-info.c | 3 +- shallow.c | 3 +- sigchain.c | 3 +- sparse-index.c | 1 + split-index.c | 1 + strbuf.c | 3 +- string-list.c | 3 +- strvec.c | 3 +- submodule-config.c | 1 + submodule.c | 4 +- t/helper/test-reach.c | 2 +- trace2/tr2_tls.c | 4 +- trailer.c | 1 + transport.c | 4 +- tree-walk.c | 1 + userdiff.c | 4 +- worktree.c | 3 +- 91 files changed, 219 insertions(+), 134 deletions(-) diff --git a/add-patch.c b/add-patch.c index a86a92e164..c6e451c136 100644 --- a/add-patch.c +++ b/add-patch.c @@ -1,5 +1,6 @@ #include "cache.h" #include "add-interactive.h" +#include "alloc.h" #include "strbuf.h" #include "run-command.h" #include "strvec.h" diff --git a/alias.c b/alias.c index 00abde0817..e814948ced 100644 --- a/alias.c +++ b/alias.c @@ -1,6 +1,8 @@ -#include "cache.h" +#include "git-compat-util.h" #include "alias.h" +#include "alloc.h" #include "config.h" +#include "gettext.h" #include "string-list.h" struct config_alias_data { diff --git a/alloc.h b/alloc.h index 3f4a0ad310..4312db4bd0 100644 --- a/alloc.h +++ b/alloc.h @@ -17,4 +17,79 @@ void *alloc_object_node(struct repository *r); struct alloc_state *allocate_alloc_state(void); void clear_alloc_state(struct alloc_state *s); +#define alloc_nr(x) (((x)+16)*3/2) + +/** + * Dynamically growing an array using realloc() is error prone and boring. + * + * Define your array with: + * + * - a pointer (`item`) that points at the array, initialized to `NULL` + * (although please name the variable based on its contents, not on its + * type); + * + * - an integer variable (`alloc`) that keeps track of how big the current + * allocation is, initialized to `0`; + * + * - another integer variable (`nr`) to keep track of how many elements the + * array currently has, initialized to `0`. + * + * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n, + * alloc)`. This ensures that the array can hold at least `n` elements by + * calling `realloc(3)` and adjusting `alloc` variable. + * + * ------------ + * sometype *item; + * size_t nr; + * size_t alloc + * + * for (i = 0; i < nr; i++) + * if (we like item[i] already) + * return; + * + * // we did not like any existing one, so add one + * ALLOC_GROW(item, nr + 1, alloc); + * item[nr++] = value you like; + * ------------ + * + * You are responsible for updating the `nr` variable. + * + * If you need to specify the number of elements to allocate explicitly + * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`. + * + * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some + * added niceties. + * + * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'. + */ +#define ALLOC_GROW(x, nr, alloc) \ + do { \ + if ((nr) > alloc) { \ + if (alloc_nr(alloc) < (nr)) \ + alloc = (nr); \ + else \ + alloc = alloc_nr(alloc); \ + REALLOC_ARRAY(x, alloc); \ + } \ + } while (0) + +/* + * Similar to ALLOC_GROW but handles updating of the nr value and + * zeroing the bytes of the newly-grown array elements. + * + * DO NOT USE any expression with side-effect for any of the + * arguments. + */ +#define ALLOC_GROW_BY(x, nr, increase, alloc) \ + do { \ + if (increase) { \ + size_t new_nr = nr + (increase); \ + if (new_nr < nr) \ + BUG("negative growth in ALLOC_GROW_BY"); \ + ALLOC_GROW(x, new_nr, alloc); \ + memset((x) + nr, 0, sizeof(*(x)) * (increase)); \ + nr = new_nr; \ + } \ + } while (0) + #endif diff --git a/apply.c b/apply.c index 5cc5479c9c..7f12ebf04c 100644 --- a/apply.c +++ b/apply.c @@ -8,6 +8,7 @@ */ #include "cache.h" +#include "alloc.h" #include "config.h" #include "object-store.h" #include "blob.h" diff --git a/archive-tar.c b/archive-tar.c index f8fad2946e..9406f03e80 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -1,7 +1,8 @@ /* * Copyright (c) 2005, 2006 Rene Scharfe */ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "tar.h" #include "archive.h" diff --git a/archive.c b/archive.c index f2a8756d84..35719e5e36 100644 --- a/archive.c +++ b/archive.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "refs.h" #include "object-store.h" diff --git a/attr.c b/attr.c index 1053dfcd4b..657ee52229 100644 --- a/attr.c +++ b/attr.c @@ -7,6 +7,7 @@ */ #include "cache.h" +#include "alloc.h" #include "config.h" #include "exec-cmd.h" #include "attr.h" diff --git a/builtin/blame.c b/builtin/blame.c index 71f925e456..4d1609c9ac 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -5,7 +5,8 @@ * See COPYING for licensing conditions */ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "color.h" #include "builtin.h" diff --git a/builtin/cat-file.c b/builtin/cat-file.c index cc17635e76..5b8be7cb63 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -5,6 +5,7 @@ */ #define USE_THE_INDEX_VARIABLE #include "cache.h" +#include "alloc.h" #include "config.h" #include "builtin.h" #include "diff.h" diff --git a/builtin/checkout--worker.c b/builtin/checkout--worker.c index ede7dc32a4..0a7d762573 100644 --- a/builtin/checkout--worker.c +++ b/builtin/checkout--worker.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "alloc.h" #include "config.h" #include "entry.h" #include "parallel-checkout.h" diff --git a/builtin/config.c b/builtin/config.c index 060cf9f3e0..ca006e9cc1 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -1,5 +1,5 @@ #include "builtin.h" -#include "cache.h" +#include "alloc.h" #include "config.h" #include "color.h" #include "parse-options.h" diff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c index f3c89831d4..590aefc6ea 100644 --- a/builtin/credential-cache--daemon.c +++ b/builtin/credential-cache--daemon.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "alloc.h" #include "parse-options.h" #ifndef NO_UNIX_SOCKETS diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index afe679368d..113f22c09d 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "alloc.h" #include "pkt-line.h" #include "fetch-pack.h" #include "remote.h" diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c index 0feef8caf6..cae804a190 100644 --- a/builtin/fsmonitor--daemon.c +++ b/builtin/fsmonitor--daemon.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "alloc.h" #include "config.h" #include "parse-options.h" #include "fsmonitor.h" diff --git a/builtin/grep.c b/builtin/grep.c index f7821c5fbb..a08e5841dd 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -4,6 +4,7 @@ * Copyright (c) 2006 Junio C Hamano */ #include "cache.h" +#include "alloc.h" #include "repository.h" #include "config.h" #include "blob.h" diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 6648f2daef..7e4b69f9a3 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "alloc.h" #include "config.h" #include "delta.h" #include "pack.h" diff --git a/builtin/log.c b/builtin/log.c index 04412dd9c9..85540963d9 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -4,7 +4,8 @@ * (C) Copyright 2006 Linus Torvalds * 2006 Junio Hamano */ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "refs.h" #include "object-store.h" diff --git a/builtin/merge.c b/builtin/merge.c index 0a3c10a096..716a23f880 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -8,6 +8,7 @@ #define USE_THE_INDEX_VARIABLE #include "cache.h" +#include "alloc.h" #include "config.h" #include "parse-options.h" #include "builtin.h" diff --git a/builtin/mktree.c b/builtin/mktree.c index 06d81400f5..ec721ffb94 100644 --- a/builtin/mktree.c +++ b/builtin/mktree.c @@ -4,6 +4,7 @@ * Copyright (c) Junio C Hamano, 2006, 2009 */ #include "builtin.h" +#include "alloc.h" #include "quote.h" #include "tree.h" #include "parse-options.h" diff --git a/builtin/mv.c b/builtin/mv.c index edd7b931fd..8129050377 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -5,6 +5,7 @@ */ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "alloc.h" #include "config.h" #include "pathspec.h" #include "lockfile.h" diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 97959bfaf9..29752e7afe 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -1,5 +1,5 @@ #include "builtin.h" -#include "cache.h" +#include "alloc.h" #include "repository.h" #include "config.h" #include "commit.h" diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 74a167a180..72c33fd739 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1,5 +1,5 @@ #include "builtin.h" -#include "cache.h" +#include "alloc.h" #include "repository.h" #include "config.h" #include "attr.h" diff --git a/builtin/repack.c b/builtin/repack.c index f649379531..545b368168 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -1,5 +1,5 @@ #include "builtin.h" -#include "cache.h" +#include "alloc.h" #include "config.h" #include "dir.h" #include "parse-options.h" diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index e67999e5eb..fd4f59ff2b 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -5,6 +5,7 @@ */ #define USE_THE_INDEX_VARIABLE #include "cache.h" +#include "alloc.h" #include "config.h" #include "commit.h" #include "refs.h" diff --git a/builtin/revert.c b/builtin/revert.c index 77d2035616..62986a7b1b 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "builtin.h" #include "parse-options.h" diff --git a/builtin/rm.c b/builtin/rm.c index 8844f90655..dc198f7908 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -5,6 +5,7 @@ */ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "alloc.h" #include "advice.h" #include "config.h" #include "lockfile.h" diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 4c173d8b37..9edc785d8d 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1,5 +1,6 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "alloc.h" #include "repository.h" #include "cache.h" #include "config.h" diff --git a/bulk-checkin.c b/bulk-checkin.c index 855b68ec23..62ed104c7e 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -1,7 +1,8 @@ /* * Copyright (c) 2011, Google Inc. */ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "bulk-checkin.h" #include "lockfile.h" #include "repository.h" diff --git a/cache-tree.c b/cache-tree.c index 88c2c04f87..256f98c3c3 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "lockfile.h" #include "tree.h" #include "tree-walk.h" diff --git a/cache.h b/cache.h index 12789903e8..0f1f9dde56 100644 --- a/cache.h +++ b/cache.h @@ -656,81 +656,6 @@ void initialize_repository_version(int hash_algo, int reinit); void sanitize_stdfds(void); int daemonize(void); -#define alloc_nr(x) (((x)+16)*3/2) - -/** - * Dynamically growing an array using realloc() is error prone and boring. - * - * Define your array with: - * - * - a pointer (`item`) that points at the array, initialized to `NULL` - * (although please name the variable based on its contents, not on its - * type); - * - * - an integer variable (`alloc`) that keeps track of how big the current - * allocation is, initialized to `0`; - * - * - another integer variable (`nr`) to keep track of how many elements the - * array currently has, initialized to `0`. - * - * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n, - * alloc)`. This ensures that the array can hold at least `n` elements by - * calling `realloc(3)` and adjusting `alloc` variable. - * - * ------------ - * sometype *item; - * size_t nr; - * size_t alloc - * - * for (i = 0; i < nr; i++) - * if (we like item[i] already) - * return; - * - * // we did not like any existing one, so add one - * ALLOC_GROW(item, nr + 1, alloc); - * item[nr++] = value you like; - * ------------ - * - * You are responsible for updating the `nr` variable. - * - * If you need to specify the number of elements to allocate explicitly - * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`. - * - * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some - * added niceties. - * - * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'. - */ -#define ALLOC_GROW(x, nr, alloc) \ - do { \ - if ((nr) > alloc) { \ - if (alloc_nr(alloc) < (nr)) \ - alloc = (nr); \ - else \ - alloc = alloc_nr(alloc); \ - REALLOC_ARRAY(x, alloc); \ - } \ - } while (0) - -/* - * Similar to ALLOC_GROW but handles updating of the nr value and - * zeroing the bytes of the newly-grown array elements. - * - * DO NOT USE any expression with side-effect for any of the - * arguments. - */ -#define ALLOC_GROW_BY(x, nr, increase, alloc) \ - do { \ - if (increase) { \ - size_t new_nr = nr + (increase); \ - if (new_nr < nr) \ - BUG("negative growth in ALLOC_GROW_BY"); \ - ALLOC_GROW(x, new_nr, alloc); \ - memset((x) + nr, 0, sizeof(*(x)) * (increase)); \ - nr = new_nr; \ - } \ - } while (0) - /* Initialize and use the cache information */ struct lock_file; void preload_index(struct index_state *index, diff --git a/chunk-format.c b/chunk-format.c index 0275b74a89..f65e9a1e42 100644 --- a/chunk-format.c +++ b/chunk-format.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "chunk-format.h" #include "csum-file.h" diff --git a/commit-reach.c b/commit-reach.c index 2e33c599a8..1f0ddc5c88 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "commit.h" #include "commit-graph.h" #include "decorate.h" diff --git a/compat/mingw.c b/compat/mingw.c index e433740381..3afbde7894 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -7,6 +7,7 @@ #include "../strbuf.h" #include "../run-command.h" #include "../cache.h" +#include "../alloc.h" #include "win32/lazyload.h" #include "../config.h" #include "dir.h" diff --git a/config.c b/config.c index 00090a32fc..1d22f23251 100644 --- a/config.c +++ b/config.c @@ -5,7 +5,8 @@ * Copyright (C) Johannes Schindelin, 2005 * */ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "date.h" #include "branch.h" #include "config.h" diff --git a/daemon.c b/daemon.c index 0ae7d12b5c..eb733d222f 100644 --- a/daemon.c +++ b/daemon.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "alloc.h" #include "config.h" #include "pkt-line.h" #include "run-command.h" diff --git a/delta-islands.c b/delta-islands.c index 8b234cb85b..1cfdc2cc04 100644 --- a/delta-islands.c +++ b/delta-islands.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "attr.h" #include "object.h" #include "blob.h" diff --git a/diff.c b/diff.c index 329eebf16a..3c3565995d 100644 --- a/diff.c +++ b/diff.c @@ -2,6 +2,7 @@ * Copyright (C) 2005 Junio C Hamano */ #include "cache.h" +#include "alloc.h" #include "config.h" #include "tempfile.h" #include "quote.h" diff --git a/diffcore-rename.c b/diffcore-rename.c index c0422d9e70..62c0299984 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -3,6 +3,7 @@ * Copyright (C) 2005 Junio C Hamano */ #include "cache.h" +#include "alloc.h" #include "diff.h" #include "diffcore.h" #include "object-store.h" diff --git a/dir-iterator.c b/dir-iterator.c index 3764dd81a1..87364d68a2 100644 --- a/dir-iterator.c +++ b/dir-iterator.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "dir.h" #include "iterator.h" #include "dir-iterator.h" diff --git a/dir.c b/dir.c index 4e99f0c868..d3f1aeaca3 100644 --- a/dir.c +++ b/dir.c @@ -5,7 +5,8 @@ * Copyright (C) Linus Torvalds, 2005-2006 * Junio Hamano, 2005-2006 */ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "dir.h" #include "object-store.h" diff --git a/ewah/bitmap.c b/ewah/bitmap.c index ac61864163..12d6aa398e 100644 --- a/ewah/bitmap.c +++ b/ewah/bitmap.c @@ -16,7 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "ewok.h" #define EWAH_MASK(x) ((eword_t)1 << (x % BITS_IN_EWORD)) diff --git a/ewah/ewah_bitmap.c b/ewah/ewah_bitmap.c index 6fe48d3ae0..c6d4ffc87c 100644 --- a/ewah/ewah_bitmap.c +++ b/ewah/ewah_bitmap.c @@ -17,9 +17,9 @@ * along with this program; if not, see . */ #include "git-compat-util.h" +#include "alloc.h" #include "ewok.h" #include "ewok_rlw.h" -#include "cache.h" static inline size_t min_size(size_t a, size_t b) { diff --git a/fetch-pack.c b/fetch-pack.c index 04016d1e32..271e2a6fbd 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "repository.h" #include "config.h" #include "lockfile.h" diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c index f317f12990..d4d6fd3d9d 100644 --- a/fmt-merge-msg.c +++ b/fmt-merge-msg.c @@ -1,4 +1,5 @@ #include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "refs.h" #include "object-store.h" diff --git a/fsck.c b/fsck.c index 2b18717ee8..20e1aac39a 100644 --- a/fsck.c +++ b/fsck.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "object-store.h" #include "repository.h" #include "object.h" diff --git a/fsmonitor-settings.c b/fsmonitor-settings.c index 899bfe9c81..b62acf44ae 100644 --- a/fsmonitor-settings.c +++ b/fsmonitor-settings.c @@ -1,5 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" +#include "gettext.h" #include "repository.h" #include "fsmonitor-ipc.h" #include "fsmonitor-settings.h" diff --git a/help.c b/help.c index 812af4cdea..5f84a50b94 100644 --- a/help.c +++ b/help.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "builtin.h" #include "exec-cmd.h" diff --git a/http-backend.c b/http-backend.c index 8ab58e55f8..d756d120dc 100644 --- a/http-backend.c +++ b/http-backend.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "repository.h" #include "refs.h" diff --git a/line-log.c b/line-log.c index a7f3e7f6ce..4956eae748 100644 --- a/line-log.c +++ b/line-log.c @@ -1,4 +1,5 @@ #include "git-compat-util.h" +#include "alloc.h" #include "line-range.h" #include "cache.h" #include "tag.h" diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c index ee01bcd2cc..1d25a5737d 100644 --- a/list-objects-filter-options.c +++ b/list-objects-filter-options.c @@ -1,6 +1,8 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "commit.h" #include "config.h" +#include "gettext.h" #include "revision.h" #include "strvec.h" #include "list-objects.h" diff --git a/list-objects-filter.c b/list-objects-filter.c index 7ed21cb299..e40ea9b0a8 100644 --- a/list-objects-filter.c +++ b/list-objects-filter.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "alloc.h" #include "dir.h" #include "tag.h" #include "commit.h" diff --git a/midx.c b/midx.c index 7cfad04a24..84d7a53d66 100644 --- a/midx.c +++ b/midx.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "csum-file.h" #include "dir.h" diff --git a/object-file.c b/object-file.c index 939865c1ae..18d65220d7 100644 --- a/object-file.c +++ b/object-file.c @@ -6,7 +6,8 @@ * This handles basic git object files - packing, unpacking, * creation etc. */ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "string-list.h" #include "lockfile.h" diff --git a/oid-array.c b/oid-array.c index 73ba76e9e9..e8228c777b 100644 --- a/oid-array.c +++ b/oid-array.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "oid-array.h" #include "hash-lookup.h" diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index cfa67a510f..155939e77b 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "object-store.h" #include "commit.h" #include "tag.h" diff --git a/pack-bitmap.c b/pack-bitmap.c index d2a42abf28..5a97834120 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "commit.h" #include "strbuf.h" #include "tag.h" diff --git a/pack-objects.c b/pack-objects.c index 272e8d4517..ccab09fe65 100644 --- a/pack-objects.c +++ b/pack-objects.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "object.h" #include "pack.h" #include "pack-objects.h" diff --git a/packfile.c b/packfile.c index 79e21ab18e..3e3063de44 100644 --- a/packfile.c +++ b/packfile.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "list.h" #include "pack.h" #include "repository.h" diff --git a/parallel-checkout.c b/parallel-checkout.c index 4f6819f240..decdc8d8a1 100644 --- a/parallel-checkout.c +++ b/parallel-checkout.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "alloc.h" #include "config.h" #include "entry.h" #include "parallel-checkout.h" diff --git a/pretty.c b/pretty.c index 1e1e21878c..b608084449 100644 --- a/pretty.c +++ b/pretty.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "alloc.h" #include "config.h" #include "commit.h" #include "utf8.h" diff --git a/prio-queue.c b/prio-queue.c index d31b48e725..dc2476be53 100644 --- a/prio-queue.c +++ b/prio-queue.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "prio-queue.h" static inline int compare(struct prio_queue *queue, int i, int j) diff --git a/quote.c b/quote.c index 26719d21d1..2453397fbb 100644 --- a/quote.c +++ b/quote.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "alloc.h" #include "quote.h" #include "strvec.h" diff --git a/read-cache.c b/read-cache.c index 35e5657877..3cc8e312dc 100644 --- a/read-cache.c +++ b/read-cache.c @@ -4,6 +4,7 @@ * Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "alloc.h" #include "config.h" #include "diff.h" #include "diffcore.h" diff --git a/ref-filter.c b/ref-filter.c index f8203c6b05..c8230a0858 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1,5 +1,5 @@ -#include "builtin.h" -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "parse-options.h" #include "refs.h" #include "wildmatch.h" @@ -13,7 +13,6 @@ #include "ref-filter.h" #include "revision.h" #include "utf8.h" -#include "git-compat-util.h" #include "version.h" #include "trailer.h" #include "wt-status.h" diff --git a/reflog-walk.c b/reflog-walk.c index 8a4d8fa3bd..4ba1a10c82 100644 --- a/reflog-walk.c +++ b/reflog-walk.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "commit.h" #include "refs.h" #include "diff.h" diff --git a/refs.c b/refs.c index e31dbcda59..f90f953551 100644 --- a/refs.c +++ b/refs.c @@ -2,7 +2,8 @@ * The backend-independent part of the reference module. */ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "hashmap.h" #include "lockfile.h" diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 6f5a0709fb..186dcafcd0 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -1,4 +1,5 @@ -#include "../cache.h" +#include "../git-compat-util.h" +#include "../alloc.h" #include "../config.h" #include "../refs.h" #include "refs-internal.h" diff --git a/refs/ref-cache.c b/refs/ref-cache.c index 32afd8a40b..dc1ca49c85 100644 --- a/refs/ref-cache.c +++ b/refs/ref-cache.c @@ -1,4 +1,5 @@ -#include "../cache.h" +#include "../git-compat-util.h" +#include "../alloc.h" #include "../refs.h" #include "refs-internal.h" #include "ref-cache.h" diff --git a/refspec.c b/refspec.c index 63e3112104..ec336ec5e9 100644 --- a/refspec.c +++ b/refspec.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "strvec.h" #include "refs.h" #include "refspec.h" diff --git a/remote-curl.c b/remote-curl.c index a76b6405eb..380ef3fccf 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "remote.h" #include "connect.h" diff --git a/remote.c b/remote.c index 60869beebe..daade49a6f 100644 --- a/remote.c +++ b/remote.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "remote.h" #include "urlmatch.h" diff --git a/rerere.c b/rerere.c index 876ab435da..d4bcb90853 100644 --- a/rerere.c +++ b/rerere.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "lockfile.h" #include "string-list.h" diff --git a/revision.c b/revision.c index 21f5f572c2..b8f925f088 100644 --- a/revision.c +++ b/revision.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "object-store.h" #include "tag.h" diff --git a/sequencer.c b/sequencer.c index 65a34f9676..fcf8740ce1 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "alloc.h" #include "config.h" #include "lockfile.h" #include "dir.h" diff --git a/server-info.c b/server-info.c index 0ec6c0c165..f07daa16f3 100644 --- a/server-info.c +++ b/server-info.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "dir.h" #include "repository.h" #include "refs.h" diff --git a/shallow.c b/shallow.c index 17f9bcdb5f..7dc73fb898 100644 --- a/shallow.c +++ b/shallow.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "repository.h" #include "tempfile.h" #include "lockfile.h" diff --git a/sigchain.c b/sigchain.c index 022677b6ab..ee778c0580 100644 --- a/sigchain.c +++ b/sigchain.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "sigchain.h" #define SIGCHAIN_MAX_SIGNALS 32 diff --git a/sparse-index.c b/sparse-index.c index 147a13386a..63216b3e57 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "alloc.h" #include "repository.h" #include "sparse-index.h" #include "tree.h" diff --git a/split-index.c b/split-index.c index 5d0f04763e..95ecfa5319 100644 --- a/split-index.c +++ b/split-index.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "alloc.h" #include "split-index.h" #include "ewah/ewok.h" diff --git a/strbuf.c b/strbuf.c index c383f41a3c..bc4c2c09e6 100644 --- a/strbuf.c +++ b/strbuf.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "refs.h" #include "string-list.h" #include "utf8.h" diff --git a/string-list.c b/string-list.c index 42bacaec55..db473f273e 100644 --- a/string-list.c +++ b/string-list.c @@ -1,5 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" #include "string-list.h" +#include "alloc.h" void string_list_init_nodup(struct string_list *list) { diff --git a/strvec.c b/strvec.c index 61a76ce6cb..94d504e380 100644 --- a/strvec.c +++ b/strvec.c @@ -1,5 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" #include "strvec.h" +#include "alloc.h" #include "strbuf.h" const char *empty_strvec[] = { NULL }; diff --git a/submodule-config.c b/submodule-config.c index 4dc61b3a78..bb7c35fc31 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "alloc.h" #include "dir.h" #include "repository.h" #include "config.h" diff --git a/submodule.c b/submodule.c index 3a0dfc417c..340ffad1c2 100644 --- a/submodule.c +++ b/submodule.c @@ -1,5 +1,5 @@ - -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "repository.h" #include "config.h" #include "submodule-config.h" diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c index 2f65c7f6a5..883d8e20a8 100644 --- a/t/helper/test-reach.c +++ b/t/helper/test-reach.c @@ -1,5 +1,5 @@ #include "test-tool.h" -#include "cache.h" +#include "alloc.h" #include "commit.h" #include "commit-reach.h" #include "config.h" diff --git a/trace2/tr2_tls.c b/trace2/tr2_tls.c index 04900bb4c3..9f46ae12f5 100644 --- a/trace2/tr2_tls.c +++ b/trace2/tr2_tls.c @@ -1,5 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "thread-utils.h" +#include "trace.h" #include "trace2/tr2_tls.h" /* diff --git a/trailer.c b/trailer.c index 0fd5b142a3..72c3fed5c6 100644 --- a/trailer.c +++ b/trailer.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "alloc.h" #include "config.h" #include "string-list.h" #include "run-command.h" diff --git a/transport.c b/transport.c index 77a61a9d7b..ac9e06a6ce 100644 --- a/transport.c +++ b/transport.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "transport.h" #include "hook.h" @@ -10,6 +11,7 @@ #include "walker.h" #include "bundle.h" #include "dir.h" +#include "gettext.h" #include "refs.h" #include "refspec.h" #include "branch.h" diff --git a/tree-walk.c b/tree-walk.c index 74f4d710e8..d22f3fe5b0 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -1,5 +1,6 @@ #include "cache.h" #include "tree-walk.h" +#include "alloc.h" #include "dir.h" #include "object-store.h" #include "tree.h" diff --git a/userdiff.c b/userdiff.c index 94cca1a2a8..7f0ecbffbb 100644 --- a/userdiff.c +++ b/userdiff.c @@ -1,7 +1,9 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "userdiff.h" #include "attr.h" +#include "strbuf.h" static struct userdiff_driver *drivers; static int ndrivers; diff --git a/worktree.c b/worktree.c index aa43c64119..c99939a4d1 100644 --- a/worktree.c +++ b/worktree.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "repository.h" #include "refs.h" #include "strbuf.h" From 41227cb138c91fbd369ac6ee4877f253b39260cc Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 24 Feb 2023 00:09:25 +0000 Subject: [PATCH 015/508] hash.h: move some oid-related declarations from cache.h These defines and enum are all oid-related and as such seem to make more sense being included in hash.h. Further, moving them there allows us to remove some includes of cache.h in other files. The change to line-log.h might look unrelated, but line-log.h includes diffcore.h, which previously included cache.h, which included the kitchen sink. Since this patch makes diffcore.h no longer include cache.h, the compiler complains about the 'struct string_list *' function parameter. Add a forward declaration for struct string_list to address this. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- cache.h | 34 -------------------- diffcore.h | 4 ++- hash.h | 34 ++++++++++++++++++++ line-log.h | 1 + submodule-config.h | 1 - t/helper/test-submodule-nested-repo-config.c | 1 + tree-walk.h | 4 ++- 7 files changed, 42 insertions(+), 37 deletions(-) diff --git a/cache.h b/cache.h index 0f1f9dde56..daf6150bb3 100644 --- a/cache.h +++ b/cache.h @@ -1363,40 +1363,6 @@ struct object_context { char *path; }; -#define GET_OID_QUIETLY 01 -#define GET_OID_COMMIT 02 -#define GET_OID_COMMITTISH 04 -#define GET_OID_TREE 010 -#define GET_OID_TREEISH 020 -#define GET_OID_BLOB 040 -#define GET_OID_FOLLOW_SYMLINKS 0100 -#define GET_OID_RECORD_PATH 0200 -#define GET_OID_ONLY_TO_DIE 04000 -#define GET_OID_REQUIRE_PATH 010000 - -#define GET_OID_DISAMBIGUATORS \ - (GET_OID_COMMIT | GET_OID_COMMITTISH | \ - GET_OID_TREE | GET_OID_TREEISH | \ - GET_OID_BLOB) - -enum get_oid_result { - FOUND = 0, - MISSING_OBJECT = -1, /* The requested object is missing */ - SHORT_NAME_AMBIGUOUS = -2, - /* The following only apply when symlinks are followed */ - DANGLING_SYMLINK = -4, /* - * The initial symlink is there, but - * (transitively) points to a missing - * in-tree file - */ - SYMLINK_LOOP = -5, - NOT_DIR = -6, /* - * Somewhere along the symlink chain, a path is - * requested which contains a file as a - * non-final element. - */ -}; - int repo_get_oid(struct repository *r, const char *str, struct object_id *oid); __attribute__((format (printf, 2, 3))) int get_oidf(struct object_id *oid, const char *fmt, ...); diff --git a/diffcore.h b/diffcore.h index 9b588a1ee1..1701ed50b9 100644 --- a/diffcore.h +++ b/diffcore.h @@ -4,9 +4,11 @@ #ifndef DIFFCORE_H #define DIFFCORE_H -#include "cache.h" +#include "hash.h" struct diff_options; +struct mem_pool; +struct oid_array; struct repository; struct strintmap; struct strmap; diff --git a/hash.h b/hash.h index 351afc2ce3..d39f73618c 100644 --- a/hash.h +++ b/hash.h @@ -123,6 +123,40 @@ struct object_id { int algo; /* XXX requires 4-byte alignment */ }; +#define GET_OID_QUIETLY 01 +#define GET_OID_COMMIT 02 +#define GET_OID_COMMITTISH 04 +#define GET_OID_TREE 010 +#define GET_OID_TREEISH 020 +#define GET_OID_BLOB 040 +#define GET_OID_FOLLOW_SYMLINKS 0100 +#define GET_OID_RECORD_PATH 0200 +#define GET_OID_ONLY_TO_DIE 04000 +#define GET_OID_REQUIRE_PATH 010000 + +#define GET_OID_DISAMBIGUATORS \ + (GET_OID_COMMIT | GET_OID_COMMITTISH | \ + GET_OID_TREE | GET_OID_TREEISH | \ + GET_OID_BLOB) + +enum get_oid_result { + FOUND = 0, + MISSING_OBJECT = -1, /* The requested object is missing */ + SHORT_NAME_AMBIGUOUS = -2, + /* The following only apply when symlinks are followed */ + DANGLING_SYMLINK = -4, /* + * The initial symlink is there, but + * (transitively) points to a missing + * in-tree file + */ + SYMLINK_LOOP = -5, + NOT_DIR = -6, /* + * Somewhere along the symlink chain, a path is + * requested which contains a file as a + * non-final element. + */ +}; + /* A suitably aligned type for stack allocations of hash contexts. */ union git_hash_ctx { git_SHA_CTX sha1; diff --git a/line-log.h b/line-log.h index 82ae8d98a4..adff361b1b 100644 --- a/line-log.h +++ b/line-log.h @@ -5,6 +5,7 @@ struct rev_info; struct commit; +struct string_list; /* A range [start,end]. Lines are numbered starting at 0, and the * ranges include start but exclude end. */ diff --git a/submodule-config.h b/submodule-config.h index 28a8ca6bf4..c2045875bb 100644 --- a/submodule-config.h +++ b/submodule-config.h @@ -1,7 +1,6 @@ #ifndef SUBMODULE_CONFIG_CACHE_H #define SUBMODULE_CONFIG_CACHE_H -#include "cache.h" #include "config.h" #include "hashmap.h" #include "submodule.h" diff --git a/t/helper/test-submodule-nested-repo-config.c b/t/helper/test-submodule-nested-repo-config.c index dc1c14bde3..a3848a8b66 100644 --- a/t/helper/test-submodule-nested-repo-config.c +++ b/t/helper/test-submodule-nested-repo-config.c @@ -1,4 +1,5 @@ #include "test-tool.h" +#include "cache.h" #include "submodule-config.h" static void die_usage(const char **argv, const char *msg) diff --git a/tree-walk.h b/tree-walk.h index 6305d53150..25fe27e352 100644 --- a/tree-walk.h +++ b/tree-walk.h @@ -1,7 +1,9 @@ #ifndef TREE_WALK_H #define TREE_WALK_H -#include "cache.h" +#include "hash.h" + +struct index_state; #define MAX_TRAVERSE_TREES 8 From b73ecb48114926d063d7ab96943bafcc0ae913b6 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 24 Feb 2023 00:09:26 +0000 Subject: [PATCH 016/508] hex.h: move some hex-related declarations from cache.h hex.c contains code for hex-related functions, but for some reason these functions were declared in the catch-all cache.h. Move the function declarations into a hex.h header instead. This also allows us to remove includes of cache.h from a few C files. For now, we make cache.h include hex.h, so that it is easier to review the direct changes being made by this patch. In the next patch, we will remove that, and add the necessary direct '#include "hex.h"' in the hundreds of C files that need it. Note that reviewing the header changes in this commit might be simplified via git log --no-walk -p --color-moved $COMMIT -- '*.h'` In particular, it highlights the simple movement of code in .h files rather nicely. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- cache.h | 79 +------------------------------------------- git-compat-util.h | 1 + hex.c | 3 +- hex.h | 84 +++++++++++++++++++++++++++++++++++++++++++++++ mailinfo.c | 4 ++- oidset.c | 4 ++- wildmatch.c | 2 +- 7 files changed, 95 insertions(+), 82 deletions(-) create mode 100644 hex.h diff --git a/cache.h b/cache.h index daf6150bb3..d0619ce2e6 100644 --- a/cache.h +++ b/cache.h @@ -13,6 +13,7 @@ #include "string-list.h" #include "pack-revindex.h" #include "hash.h" +#include "hex.h" #include "path.h" #include "oid-array.h" #include "repository.h" @@ -1325,22 +1326,6 @@ int finalize_object_file(const char *tmpfile, const char *filename); /* Helper to check and "touch" a file */ int check_and_freshen_file(const char *fn, int freshen); -extern const signed char hexval_table[256]; -static inline unsigned int hexval(unsigned char c) -{ - return hexval_table[c]; -} - -/* - * Convert two consecutive hexadecimal digits into a char. Return a - * negative value on error. Don't run over the end of short strings. - */ -static inline int hex2chr(const char *s) -{ - unsigned int val = hexval(s[0]); - return (val & ~0xf) ? val : (val << 4) | hexval(s[1]); -} - /* Convert to/from hex/sha1 representation */ #define MINIMUM_ABBREV minimum_abbrev #define DEFAULT_ABBREV default_abbrev @@ -1393,68 +1378,6 @@ int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_f int set_disambiguate_hint_config(const char *var, const char *value); -/* - * Try to read a SHA1 in hexadecimal format from the 40 characters - * starting at hex. Write the 20-byte result to sha1 in binary form. - * Return 0 on success. Reading stops if a NUL is encountered in the - * input, so it is safe to pass this function an arbitrary - * null-terminated string. - */ -int get_sha1_hex(const char *hex, unsigned char *sha1); -int get_oid_hex(const char *hex, struct object_id *sha1); - -/* Like get_oid_hex, but for an arbitrary hash algorithm. */ -int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_hash_algo *algop); - -/* - * Read `len` pairs of hexadecimal digits from `hex` and write the - * values to `binary` as `len` bytes. Return 0 on success, or -1 if - * the input does not consist of hex digits). - */ -int hex_to_bytes(unsigned char *binary, const char *hex, size_t len); - -/* - * Convert a binary hash in "unsigned char []" or an object name in - * "struct object_id *" to its hex equivalent. The `_r` variant is reentrant, - * and writes the NUL-terminated output to the buffer `out`, which must be at - * least `GIT_MAX_HEXSZ + 1` bytes, and returns a pointer to out for - * convenience. - * - * The non-`_r` variant returns a static buffer, but uses a ring of 4 - * buffers, making it safe to make multiple calls for a single statement, like: - * - * printf("%s -> %s", hash_to_hex(one), hash_to_hex(two)); - * printf("%s -> %s", oid_to_hex(one), oid_to_hex(two)); - */ -char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash, const struct git_hash_algo *); -char *oid_to_hex_r(char *out, const struct object_id *oid); -char *hash_to_hex_algop(const unsigned char *hash, const struct git_hash_algo *); /* static buffer result! */ -char *hash_to_hex(const unsigned char *hash); /* same static buffer */ -char *oid_to_hex(const struct object_id *oid); /* same static buffer */ - -/* - * Parse a 40-character hexadecimal object ID starting from hex, updating the - * pointer specified by end when parsing stops. The resulting object ID is - * stored in oid. Returns 0 on success. Parsing will stop on the first NUL or - * other invalid character. end is only updated on success; otherwise, it is - * unmodified. - */ -int parse_oid_hex(const char *hex, struct object_id *oid, const char **end); - -/* Like parse_oid_hex, but for an arbitrary hash algorithm. */ -int parse_oid_hex_algop(const char *hex, struct object_id *oid, const char **end, - const struct git_hash_algo *algo); - - -/* - * These functions work like get_oid_hex and parse_oid_hex, but they will parse - * a hex value for any algorithm. The algorithm is detected based on the length - * and the algorithm in use is returned. If this is not a hex object ID in any - * algorithm, returns GIT_HASH_UNKNOWN. - */ -int get_oid_hex_any(const char *hex, struct object_id *oid); -int parse_oid_hex_any(const char *hex, struct object_id *oid, const char **end); - /* * This reads short-hand syntax that not only evaluates to a commit * object name, but also can act as if the end user spelled the name diff --git a/git-compat-util.h b/git-compat-util.h index 4f0028ce60..f77f986fbf 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -1225,6 +1225,7 @@ extern const unsigned char tolower_trans_tbl[256]; #undef isxdigit extern const unsigned char sane_ctype[256]; +extern const signed char hexval_table[256]; #define GIT_SPACE 0x01 #define GIT_DIGIT 0x02 #define GIT_ALPHA 0x04 diff --git a/hex.c b/hex.c index 4f64d34696..0a1bddc128 100644 --- a/hex.c +++ b/hex.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "hex.h" const signed char hexval_table[256] = { -1, -1, -1, -1, -1, -1, -1, -1, /* 00-07 */ diff --git a/hex.h b/hex.h new file mode 100644 index 0000000000..e2abfc56fa --- /dev/null +++ b/hex.h @@ -0,0 +1,84 @@ +#ifndef HEX_H +#define HEX_H + +#include "hash.h" + +extern const signed char hexval_table[256]; +static inline unsigned int hexval(unsigned char c) +{ + return hexval_table[c]; +} + +/* + * Convert two consecutive hexadecimal digits into a char. Return a + * negative value on error. Don't run over the end of short strings. + */ +static inline int hex2chr(const char *s) +{ + unsigned int val = hexval(s[0]); + return (val & ~0xf) ? val : (val << 4) | hexval(s[1]); +} + +/* + * Try to read a SHA1 in hexadecimal format from the 40 characters + * starting at hex. Write the 20-byte result to sha1 in binary form. + * Return 0 on success. Reading stops if a NUL is encountered in the + * input, so it is safe to pass this function an arbitrary + * null-terminated string. + */ +int get_sha1_hex(const char *hex, unsigned char *sha1); +int get_oid_hex(const char *hex, struct object_id *sha1); + +/* Like get_oid_hex, but for an arbitrary hash algorithm. */ +int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_hash_algo *algop); + +/* + * Read `len` pairs of hexadecimal digits from `hex` and write the + * values to `binary` as `len` bytes. Return 0 on success, or -1 if + * the input does not consist of hex digits). + */ +int hex_to_bytes(unsigned char *binary, const char *hex, size_t len); + +/* + * Convert a binary hash in "unsigned char []" or an object name in + * "struct object_id *" to its hex equivalent. The `_r` variant is reentrant, + * and writes the NUL-terminated output to the buffer `out`, which must be at + * least `GIT_MAX_HEXSZ + 1` bytes, and returns a pointer to out for + * convenience. + * + * The non-`_r` variant returns a static buffer, but uses a ring of 4 + * buffers, making it safe to make multiple calls for a single statement, like: + * + * printf("%s -> %s", hash_to_hex(one), hash_to_hex(two)); + * printf("%s -> %s", oid_to_hex(one), oid_to_hex(two)); + */ +char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash, const struct git_hash_algo *); +char *oid_to_hex_r(char *out, const struct object_id *oid); +char *hash_to_hex_algop(const unsigned char *hash, const struct git_hash_algo *); /* static buffer result! */ +char *hash_to_hex(const unsigned char *hash); /* same static buffer */ +char *oid_to_hex(const struct object_id *oid); /* same static buffer */ + +/* + * Parse a 40-character hexadecimal object ID starting from hex, updating the + * pointer specified by end when parsing stops. The resulting object ID is + * stored in oid. Returns 0 on success. Parsing will stop on the first NUL or + * other invalid character. end is only updated on success; otherwise, it is + * unmodified. + */ +int parse_oid_hex(const char *hex, struct object_id *oid, const char **end); + +/* Like parse_oid_hex, but for an arbitrary hash algorithm. */ +int parse_oid_hex_algop(const char *hex, struct object_id *oid, const char **end, + const struct git_hash_algo *algo); + + +/* + * These functions work like get_oid_hex and parse_oid_hex, but they will parse + * a hex value for any algorithm. The algorithm is detected based on the length + * and the algorithm in use is returned. If this is not a hex object ID in any + * algorithm, returns GIT_HASH_UNKNOWN. + */ +int get_oid_hex_any(const char *hex, struct object_id *oid); +int parse_oid_hex_any(const char *hex, struct object_id *oid, const char **end); + +#endif diff --git a/mailinfo.c b/mailinfo.c index 833d28612f..9f1495ddcf 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -1,5 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" +#include "gettext.h" +#include "hex.h" #include "utf8.h" #include "strbuf.h" #include "mailinfo.h" diff --git a/oidset.c b/oidset.c index b36a2bae86..d1e5376316 100644 --- a/oidset.c +++ b/oidset.c @@ -1,5 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" #include "oidset.h" +#include "hex.h" +#include "strbuf.h" void oidset_init(struct oidset *set, size_t initial_size) { diff --git a/wildmatch.c b/wildmatch.c index 7e5a7ea1ea..42e38e3459 100644 --- a/wildmatch.c +++ b/wildmatch.c @@ -9,7 +9,7 @@ ** work differently than '*', and to fix the character-class code. */ -#include "cache.h" +#include "git-compat-util.h" #include "wildmatch.h" typedef unsigned char uchar; From 41771fa435a44ff8be3f23753bde0309a2a65b03 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 24 Feb 2023 00:09:27 +0000 Subject: [PATCH 017/508] cache.h: remove dependence on hex.h; make other files include it explicitly Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- add-interactive.c | 1 + apply.c | 1 + archive-tar.c | 1 + archive-zip.c | 1 + archive.c | 1 + bisect.c | 1 + blame.c | 1 + branch.c | 1 + builtin/am.c | 1 + builtin/bisect.c | 1 + builtin/blame.c | 1 + builtin/cat-file.c | 1 + builtin/checkout.c | 1 + builtin/clone.c | 1 + builtin/commit-graph.c | 1 + builtin/commit-tree.c | 1 + builtin/describe.c | 1 + builtin/diff-tree.c | 1 + builtin/difftool.c | 1 + builtin/fast-export.c | 1 + builtin/fast-import.c | 1 + builtin/fetch-pack.c | 1 + builtin/fetch.c | 1 + builtin/fsck.c | 1 + builtin/gc.c | 1 + builtin/grep.c | 1 + builtin/hash-object.c | 1 + builtin/index-pack.c | 1 + builtin/log.c | 1 + builtin/ls-remote.c | 1 + builtin/ls-tree.c | 1 + builtin/merge-base.c | 1 + builtin/merge-index.c | 1 + builtin/merge-tree.c | 1 + builtin/merge.c | 1 + builtin/mktag.c | 1 + builtin/mktree.c | 1 + builtin/name-rev.c | 1 + builtin/notes.c | 1 + builtin/pack-objects.c | 1 + builtin/pack-redundant.c | 1 + builtin/patch-id.c | 1 + builtin/prune.c | 1 + builtin/pull.c | 1 + builtin/read-tree.c | 1 + builtin/rebase.c | 1 + builtin/receive-pack.c | 1 + builtin/repack.c | 1 + builtin/replace.c | 1 + builtin/reset.c | 1 + builtin/rev-list.c | 1 + builtin/rev-parse.c | 1 + builtin/send-pack.c | 1 + builtin/show-branch.c | 1 + builtin/show-index.c | 1 + builtin/show-ref.c | 1 + builtin/stash.c | 1 + builtin/submodule--helper.c | 1 + builtin/tag.c | 1 + builtin/unpack-file.c | 1 + builtin/unpack-objects.c | 1 + builtin/update-index.c | 1 + builtin/worktree.c | 1 + builtin/write-tree.c | 1 + bulk-checkin.c | 1 + bundle.c | 1 + cache-tree.c | 1 + cache.h | 1 - color.c | 1 + combine-diff.c | 1 + commit-graph.c | 1 + commit-reach.c | 1 + commit.c | 1 + compat/fsmonitor/fsm-ipc-darwin.c | 1 + connect.c | 1 + connected.c | 1 + convert.c | 1 + delta-islands.c | 1 + diagnose.c | 1 + diff-lib.c | 1 + diff.c | 1 + entry.c | 1 + fetch-pack.c | 1 + fmt-merge-msg.c | 1 + fsck.c | 1 + grep.c | 1 + http-backend.c | 1 + http-fetch.c | 1 + http-push.c | 1 + http-walker.c | 1 + http.c | 1 + line-log.c | 1 + list-objects-filter.c | 1 + list-objects.c | 1 + log-tree.c | 1 + ls-refs.c | 1 + match-trees.c | 1 + merge-ort.c | 1 + merge-recursive.c | 1 + merge.c | 1 + midx.c | 1 + negotiator/skipping.c | 1 + notes-merge.c | 1 + notes.c | 1 + object-file.c | 1 + object-name.c | 1 + object.c | 1 + pack-bitmap-write.c | 1 + pack-bitmap.c | 1 + pack-check.c | 1 + pack-write.c | 1 + packfile.c | 1 + parallel-checkout.c | 1 + patch-ids.c | 1 + path.c | 1 + pkt-line.c | 1 + pretty.c | 1 + promisor-remote.c | 1 + protocol-caps.c | 1 + reachable.c | 1 + read-cache.c | 1 + ref-filter.c | 1 + refs.c | 1 + refs/debug.c | 1 + refs/files-backend.c | 1 + refs/packed-backend.c | 1 + refspec.c | 1 + remote-curl.c | 1 + remote.c | 1 + replace-object.c | 1 + rerere.c | 1 + reset.c | 1 + revision.c | 1 + send-pack.c | 1 + sequencer.c | 1 + server-info.c | 1 + sha1dc_git.c | 1 + shallow.c | 1 + strbuf.c | 1 + strvec.c | 1 + submodule-config.c | 1 + submodule.c | 1 + t/helper/test-bloom.c | 1 + t/helper/test-cache-tree.c | 1 + t/helper/test-dump-cache-tree.c | 1 + t/helper/test-dump-split-index.c | 1 + t/helper/test-dump-untracked-cache.c | 1 + t/helper/test-fast-rebase.c | 1 + t/helper/test-hash.c | 1 + t/helper/test-match-trees.c | 1 + t/helper/test-oid-array.c | 1 + t/helper/test-oidmap.c | 1 + t/helper/test-oidtree.c | 1 + t/helper/test-pack-mtimes.c | 1 + t/helper/test-partial-clone.c | 1 + t/helper/test-proc-receive.c | 1 + t/helper/test-reach.c | 1 + t/helper/test-read-midx.c | 1 + t/helper/test-ref-store.c | 1 + t/helper/test-repository.c | 1 + tag.c | 1 + trace2/tr2_sid.c | 1 + transport-helper.c | 1 + transport.c | 1 + tree-walk.c | 1 + tree.c | 1 + unpack-trees.c | 1 + upload-pack.c | 1 + url.c | 1 + urlmatch.c | 1 + walker.c | 1 + wt-status.c | 1 + xdiff-interface.c | 1 + 173 files changed, 172 insertions(+), 1 deletion(-) diff --git a/add-interactive.c b/add-interactive.c index 00a0f6f96f..ae25ec50bc 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -3,6 +3,7 @@ #include "color.h" #include "config.h" #include "diffcore.h" +#include "hex.h" #include "revision.h" #include "refs.h" #include "string-list.h" diff --git a/apply.c b/apply.c index 7f12ebf04c..8776ab939a 100644 --- a/apply.c +++ b/apply.c @@ -15,6 +15,7 @@ #include "delta.h" #include "diff.h" #include "dir.h" +#include "hex.h" #include "xdiff-interface.h" #include "ll-merge.h" #include "lockfile.h" diff --git a/archive-tar.c b/archive-tar.c index 9406f03e80..ee27fa0b39 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -4,6 +4,7 @@ #include "git-compat-util.h" #include "alloc.h" #include "config.h" +#include "hex.h" #include "tar.h" #include "archive.h" #include "object-store.h" diff --git a/archive-zip.c b/archive-zip.c index 0456f1ebf1..c5d1f72eb8 100644 --- a/archive-zip.c +++ b/archive-zip.c @@ -4,6 +4,7 @@ #include "cache.h" #include "config.h" #include "archive.h" +#include "hex.h" #include "streaming.h" #include "utf8.h" #include "object-store.h" diff --git a/archive.c b/archive.c index 35719e5e36..c7869ae906 100644 --- a/archive.c +++ b/archive.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "alloc.h" #include "config.h" +#include "hex.h" #include "refs.h" #include "object-store.h" #include "commit.h" diff --git a/bisect.c b/bisect.c index ef5ee5a643..1409150c5c 100644 --- a/bisect.c +++ b/bisect.c @@ -2,6 +2,7 @@ #include "config.h" #include "commit.h" #include "diff.h" +#include "hex.h" #include "revision.h" #include "refs.h" #include "list-objects.h" diff --git a/blame.c b/blame.c index 8bfeaa1c63..e45d8a3bf9 100644 --- a/blame.c +++ b/blame.c @@ -5,6 +5,7 @@ #include "mergesort.h" #include "diff.h" #include "diffcore.h" +#include "hex.h" #include "tag.h" #include "blame.h" #include "alloc.h" diff --git a/branch.c b/branch.c index e5614b53b3..5aaf073dce 100644 --- a/branch.c +++ b/branch.c @@ -2,6 +2,7 @@ #include "cache.h" #include "config.h" #include "branch.h" +#include "hex.h" #include "refs.h" #include "refspec.h" #include "remote.h" diff --git a/builtin/am.c b/builtin/am.c index e0848ddadf..3b5ea50cc5 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -8,6 +8,7 @@ #include "config.h" #include "builtin.h" #include "exec-cmd.h" +#include "hex.h" #include "parse-options.h" #include "dir.h" #include "run-command.h" diff --git a/builtin/bisect.c b/builtin/bisect.c index 7301740267..e8ee4a4dc8 100644 --- a/builtin/bisect.c +++ b/builtin/bisect.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "hex.h" #include "parse-options.h" #include "bisect.h" #include "refs.h" diff --git a/builtin/blame.c b/builtin/blame.c index 4d1609c9ac..fdd9f0c0fc 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -10,6 +10,7 @@ #include "config.h" #include "color.h" #include "builtin.h" +#include "hex.h" #include "repository.h" #include "commit.h" #include "diff.h" diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 5b8be7cb63..3040016e27 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -9,6 +9,7 @@ #include "config.h" #include "builtin.h" #include "diff.h" +#include "hex.h" #include "parse-options.h" #include "userdiff.h" #include "streaming.h" diff --git a/builtin/checkout.c b/builtin/checkout.c index a5155cf55c..21a4335abb 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -9,6 +9,7 @@ #include "config.h" #include "diff.h" #include "dir.h" +#include "hex.h" #include "hook.h" #include "ll-merge.h" #include "lockfile.h" diff --git a/builtin/clone.c b/builtin/clone.c index 65b5b7db6d..462c286274 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -11,6 +11,7 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "config.h" +#include "hex.h" #include "lockfile.h" #include "parse-options.h" #include "fetch-pack.h" diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 93704f95a9..6dc83dc51b 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -1,6 +1,7 @@ #include "builtin.h" #include "config.h" #include "dir.h" +#include "hex.h" #include "lockfile.h" #include "parse-options.h" #include "repository.h" diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index cc8d584be2..fefeed5d4b 100644 --- a/builtin/commit-tree.c +++ b/builtin/commit-tree.c @@ -5,6 +5,7 @@ */ #include "cache.h" #include "config.h" +#include "hex.h" #include "object-store.h" #include "repository.h" #include "commit.h" diff --git a/builtin/describe.c b/builtin/describe.c index eea1e330c0..5b5930f5c8 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -1,6 +1,7 @@ #define USE_THE_INDEX_VARIABLE #include "cache.h" #include "config.h" +#include "hex.h" #include "lockfile.h" #include "commit.h" #include "tag.h" diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index 25b853b85c..a393efa4f0 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -3,6 +3,7 @@ #include "config.h" #include "diff.h" #include "commit.h" +#include "hex.h" #include "log-tree.h" #include "builtin.h" #include "submodule.h" diff --git a/builtin/difftool.c b/builtin/difftool.c index dbbfb19f19..01681d0fb8 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -17,6 +17,7 @@ #include "builtin.h" #include "run-command.h" #include "exec-cmd.h" +#include "hex.h" #include "parse-options.h" #include "strvec.h" #include "strbuf.h" diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 39a890fc00..78493c6d2b 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -6,6 +6,7 @@ #include "builtin.h" #include "cache.h" #include "config.h" +#include "hex.h" #include "refs.h" #include "refspec.h" #include "object-store.h" diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 7134683ab9..160e2eedb7 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "hex.h" #include "repository.h" #include "config.h" #include "lockfile.h" diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index 113f22c09d..702c9a3397 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "alloc.h" +#include "hex.h" #include "pkt-line.h" #include "fetch-pack.h" #include "remote.h" diff --git a/builtin/fetch.c b/builtin/fetch.c index a21ce89312..a77099ba88 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -3,6 +3,7 @@ */ #include "cache.h" #include "config.h" +#include "hex.h" #include "repository.h" #include "refs.h" #include "refspec.h" diff --git a/builtin/fsck.c b/builtin/fsck.c index d207bd909b..af0fab660d 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -1,6 +1,7 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "cache.h" +#include "hex.h" #include "repository.h" #include "config.h" #include "commit.h" diff --git a/builtin/gc.c b/builtin/gc.c index 02455fdcd7..67c7fe8a6e 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -11,6 +11,7 @@ */ #include "builtin.h" +#include "hex.h" #include "repository.h" #include "config.h" #include "tempfile.h" diff --git a/builtin/grep.c b/builtin/grep.c index a08e5841dd..c590fcb19d 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -5,6 +5,7 @@ */ #include "cache.h" #include "alloc.h" +#include "hex.h" #include "repository.h" #include "config.h" #include "blob.h" diff --git a/builtin/hash-object.c b/builtin/hash-object.c index 44db83f07f..1848768b97 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -6,6 +6,7 @@ */ #include "builtin.h" #include "config.h" +#include "hex.h" #include "object-store.h" #include "blob.h" #include "quote.h" diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 7e4b69f9a3..21c0e109dd 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -2,6 +2,7 @@ #include "alloc.h" #include "config.h" #include "delta.h" +#include "hex.h" #include "pack.h" #include "csum-file.h" #include "blob.h" diff --git a/builtin/log.c b/builtin/log.c index 85540963d9..99489bcb64 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -7,6 +7,7 @@ #include "git-compat-util.h" #include "alloc.h" #include "config.h" +#include "hex.h" #include "refs.h" #include "object-store.h" #include "color.h" diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index 6516177348..2dfbd8ed9b 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "hex.h" #include "transport.h" #include "ref-filter.h" #include "remote.h" diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 8cc8c995df..64d8e54318 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -5,6 +5,7 @@ */ #include "cache.h" #include "config.h" +#include "hex.h" #include "object-store.h" #include "blob.h" #include "tree.h" diff --git a/builtin/merge-base.c b/builtin/merge-base.c index 6f3941f2a4..be8f3b221c 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -2,6 +2,7 @@ #include "cache.h" #include "config.h" #include "commit.h" +#include "hex.h" #include "refs.h" #include "diff.h" #include "revision.h" diff --git a/builtin/merge-index.c b/builtin/merge-index.c index 452f833ac4..c875f5d37e 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -1,5 +1,6 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "hex.h" #include "run-command.h" static const char *pgm; diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 828dc81c42..e782518164 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -3,6 +3,7 @@ #include "tree-walk.h" #include "xdiff-interface.h" #include "help.h" +#include "hex.h" #include "commit.h" #include "commit-reach.h" #include "merge-ort.h" diff --git a/builtin/merge.c b/builtin/merge.c index 716a23f880..7347b738e5 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -10,6 +10,7 @@ #include "cache.h" #include "alloc.h" #include "config.h" +#include "hex.h" #include "parse-options.h" #include "builtin.h" #include "lockfile.h" diff --git a/builtin/mktag.c b/builtin/mktag.c index 5d22909122..42c2457c70 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "hex.h" #include "parse-options.h" #include "tag.h" #include "replace-object.h" diff --git a/builtin/mktree.c b/builtin/mktree.c index ec721ffb94..848c7b4747 100644 --- a/builtin/mktree.c +++ b/builtin/mktree.c @@ -5,6 +5,7 @@ */ #include "builtin.h" #include "alloc.h" +#include "hex.h" #include "quote.h" #include "tree.h" #include "parse-options.h" diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 29752e7afe..723ba616a8 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "alloc.h" +#include "hex.h" #include "repository.h" #include "config.h" #include "commit.h" diff --git a/builtin/notes.c b/builtin/notes.c index 80d9dfd25c..bba4c2e39f 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -10,6 +10,7 @@ #include "cache.h" #include "config.h" #include "builtin.h" +#include "hex.h" #include "notes.h" #include "object-store.h" #include "repository.h" diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 72c33fd739..2b5e85988c 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "alloc.h" +#include "hex.h" #include "repository.h" #include "config.h" #include "attr.h" diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c index ecd49ca268..82115c5808 100644 --- a/builtin/pack-redundant.c +++ b/builtin/pack-redundant.c @@ -7,6 +7,7 @@ */ #include "builtin.h" +#include "hex.h" #include "repository.h" #include "packfile.h" #include "object-store.h" diff --git a/builtin/patch-id.c b/builtin/patch-id.c index f840fbf1c7..338b15cd7b 100644 --- a/builtin/patch-id.c +++ b/builtin/patch-id.c @@ -2,6 +2,7 @@ #include "builtin.h" #include "config.h" #include "diff.h" +#include "hex.h" #include "parse-options.h" static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result) diff --git a/builtin/prune.c b/builtin/prune.c index 2719220108..db767b7a8f 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -1,6 +1,7 @@ #include "cache.h" #include "commit.h" #include "diff.h" +#include "hex.h" #include "revision.h" #include "builtin.h" #include "reachable.h" diff --git a/builtin/pull.c b/builtin/pull.c index 1ab4de0005..963a47f0b8 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -9,6 +9,7 @@ #include "cache.h" #include "config.h" #include "builtin.h" +#include "hex.h" #include "parse-options.h" #include "exec-cmd.h" #include "run-command.h" diff --git a/builtin/read-tree.c b/builtin/read-tree.c index 3ce7541783..018fa9cde2 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -7,6 +7,7 @@ #define USE_THE_INDEX_VARIABLE #include "cache.h" #include "config.h" +#include "hex.h" #include "lockfile.h" #include "object.h" #include "tree.h" diff --git a/builtin/rebase.c b/builtin/rebase.c index 6635f10d52..ef8ce2f72c 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -6,6 +6,7 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "hex.h" #include "run-command.h" #include "exec-cmd.h" #include "strvec.h" diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index cd5c7a28ef..3d2b4c8b4f 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1,6 +1,7 @@ #include "builtin.h" #include "repository.h" #include "config.h" +#include "hex.h" #include "lockfile.h" #include "pack.h" #include "refs.h" diff --git a/builtin/repack.c b/builtin/repack.c index 545b368168..966430a465 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -2,6 +2,7 @@ #include "alloc.h" #include "config.h" #include "dir.h" +#include "hex.h" #include "parse-options.h" #include "run-command.h" #include "sigchain.h" diff --git a/builtin/replace.c b/builtin/replace.c index a29e911d30..cdcb39f737 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -11,6 +11,7 @@ #include "cache.h" #include "config.h" #include "builtin.h" +#include "hex.h" #include "refs.h" #include "parse-options.h" #include "run-command.h" diff --git a/builtin/reset.c b/builtin/reset.c index 0697fa89de..58f567afd3 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -10,6 +10,7 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "config.h" +#include "hex.h" #include "lockfile.h" #include "tag.h" #include "object.h" diff --git a/builtin/rev-list.c b/builtin/rev-list.c index d42db0b0cc..e4c9b74762 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -2,6 +2,7 @@ #include "config.h" #include "commit.h" #include "diff.h" +#include "hex.h" #include "revision.h" #include "list-objects.h" #include "list-objects-filter.h" diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index fd4f59ff2b..e1fa9c6348 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -8,6 +8,7 @@ #include "alloc.h" #include "config.h" #include "commit.h" +#include "hex.h" #include "refs.h" #include "quote.h" #include "builtin.h" diff --git a/builtin/send-pack.c b/builtin/send-pack.c index 4c5d125fa0..127ced435d 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -1,6 +1,7 @@ #include "builtin.h" #include "config.h" #include "commit.h" +#include "hex.h" #include "refs.h" #include "pkt-line.h" #include "sideband.h" diff --git a/builtin/show-branch.c b/builtin/show-branch.c index 358ac3e519..8342b68aef 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -1,5 +1,6 @@ #include "cache.h" #include "config.h" +#include "hex.h" #include "pretty.h" #include "refs.h" #include "builtin.h" diff --git a/builtin/show-index.c b/builtin/show-index.c index 0e0b9fb95b..98ec40ddf4 100644 --- a/builtin/show-index.c +++ b/builtin/show-index.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "hex.h" #include "pack.h" #include "parse-options.h" diff --git a/builtin/show-ref.c b/builtin/show-ref.c index 3af6a53ee9..1f28d7fe4b 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -1,6 +1,7 @@ #include "builtin.h" #include "cache.h" #include "config.h" +#include "hex.h" #include "refs.h" #include "object-store.h" #include "object.h" diff --git a/builtin/stash.c b/builtin/stash.c index 3a4f9fd566..6a12fed271 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1,6 +1,7 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "config.h" +#include "hex.h" #include "parse-options.h" #include "refs.h" #include "lockfile.h" diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 9edc785d8d..2bbabbb28e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1,6 +1,7 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "alloc.h" +#include "hex.h" #include "repository.h" #include "cache.h" #include "config.h" diff --git a/builtin/tag.c b/builtin/tag.c index d428c45dc8..be094882d0 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -9,6 +9,7 @@ #include "cache.h" #include "config.h" #include "builtin.h" +#include "hex.h" #include "refs.h" #include "object-store.h" #include "tag.h" diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c index 88de32b7d7..e9b105a539 100644 --- a/builtin/unpack-file.c +++ b/builtin/unpack-file.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "config.h" +#include "hex.h" #include "object-store.h" static char *create_temp_file(struct object_id *oid) diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 43789b8ef2..e125b12188 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -2,6 +2,7 @@ #include "cache.h" #include "bulk-checkin.h" #include "config.h" +#include "hex.h" #include "object-store.h" #include "object.h" #include "delta.h" diff --git a/builtin/update-index.c b/builtin/update-index.c index bf38885d54..11dc135271 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -7,6 +7,7 @@ #include "cache.h" #include "bulk-checkin.h" #include "config.h" +#include "hex.h" #include "lockfile.h" #include "quote.h" #include "cache-tree.h" diff --git a/builtin/worktree.c b/builtin/worktree.c index 254283aa6f..80d05e246d 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -3,6 +3,7 @@ #include "config.h" #include "builtin.h" #include "dir.h" +#include "hex.h" #include "parse-options.h" #include "strvec.h" #include "branch.h" diff --git a/builtin/write-tree.c b/builtin/write-tree.c index 078010315f..7ad0d05945 100644 --- a/builtin/write-tree.c +++ b/builtin/write-tree.c @@ -7,6 +7,7 @@ #include "builtin.h" #include "cache.h" #include "config.h" +#include "hex.h" #include "tree.h" #include "cache-tree.h" #include "parse-options.h" diff --git a/bulk-checkin.c b/bulk-checkin.c index 62ed104c7e..d64cd5c52d 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -4,6 +4,7 @@ #include "git-compat-util.h" #include "alloc.h" #include "bulk-checkin.h" +#include "hex.h" #include "lockfile.h" #include "repository.h" #include "csum-file.h" diff --git a/bundle.c b/bundle.c index 6ab6cd7378..99d7de97f6 100644 --- a/bundle.c +++ b/bundle.c @@ -1,6 +1,7 @@ #include "cache.h" #include "lockfile.h" #include "bundle.h" +#include "hex.h" #include "object-store.h" #include "repository.h" #include "object.h" diff --git a/cache-tree.c b/cache-tree.c index 256f98c3c3..9d46ecef09 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "alloc.h" +#include "hex.h" #include "lockfile.h" #include "tree.h" #include "tree-walk.h" diff --git a/cache.h b/cache.h index d0619ce2e6..0c631e75b5 100644 --- a/cache.h +++ b/cache.h @@ -13,7 +13,6 @@ #include "string-list.h" #include "pack-revindex.h" #include "hash.h" -#include "hex.h" #include "path.h" #include "oid-array.h" #include "repository.h" diff --git a/color.c b/color.c index f05d8a81d7..6b577ce0a7 100644 --- a/color.c +++ b/color.c @@ -1,6 +1,7 @@ #include "cache.h" #include "config.h" #include "color.h" +#include "hex.h" static int git_use_color_default = GIT_COLOR_AUTO; int color_stdout_is_tty = -1; diff --git a/combine-diff.c b/combine-diff.c index 1a39b5dde0..91051dc325 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -4,6 +4,7 @@ #include "blob.h" #include "diff.h" #include "diffcore.h" +#include "hex.h" #include "quote.h" #include "xdiff-interface.h" #include "xdiff/xmacros.h" diff --git a/commit-graph.c b/commit-graph.c index c11b59f28b..5e6098ff35 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "config.h" +#include "hex.h" #include "lockfile.h" #include "pack.h" #include "packfile.h" diff --git a/commit-reach.c b/commit-reach.c index 1f0ddc5c88..5ba822a720 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -3,6 +3,7 @@ #include "commit.h" #include "commit-graph.h" #include "decorate.h" +#include "hex.h" #include "prio-queue.h" #include "tree.h" #include "ref-filter.h" diff --git a/commit.c b/commit.c index e433c33bb0..cb683a6df5 100644 --- a/commit.c +++ b/commit.c @@ -2,6 +2,7 @@ #include "tag.h" #include "commit.h" #include "commit-graph.h" +#include "hex.h" #include "repository.h" #include "object-store.h" #include "pkt-line.h" diff --git a/compat/fsmonitor/fsm-ipc-darwin.c b/compat/fsmonitor/fsm-ipc-darwin.c index d67b0ee50d..eb25123fa1 100644 --- a/compat/fsmonitor/fsm-ipc-darwin.c +++ b/compat/fsmonitor/fsm-ipc-darwin.c @@ -1,5 +1,6 @@ #include "cache.h" #include "config.h" +#include "hex.h" #include "strbuf.h" #include "fsmonitor.h" #include "fsmonitor-ipc.h" diff --git a/connect.c b/connect.c index 63e59641c0..134069574a 100644 --- a/connect.c +++ b/connect.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "cache.h" #include "config.h" +#include "hex.h" #include "pkt-line.h" #include "quote.h" #include "refs.h" diff --git a/connected.c b/connected.c index b90fd61790..39cb1e1074 100644 --- a/connected.c +++ b/connected.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hex.h" #include "object-store.h" #include "run-command.h" #include "sigchain.h" diff --git a/convert.c b/convert.c index a54d1690c0..349c7e4af1 100644 --- a/convert.c +++ b/convert.c @@ -1,5 +1,6 @@ #include "cache.h" #include "config.h" +#include "hex.h" #include "object-store.h" #include "attr.h" #include "run-command.h" diff --git a/delta-islands.c b/delta-islands.c index 1cfdc2cc04..c3785135fb 100644 --- a/delta-islands.c +++ b/delta-islands.c @@ -4,6 +4,7 @@ #include "object.h" #include "blob.h" #include "commit.h" +#include "hex.h" #include "tag.h" #include "tree.h" #include "delta.h" diff --git a/diagnose.c b/diagnose.c index 8f26569896..4a8ee4e5cf 100644 --- a/diagnose.c +++ b/diagnose.c @@ -4,6 +4,7 @@ #include "archive.h" #include "dir.h" #include "help.h" +#include "hex.h" #include "strvec.h" #include "object-store.h" #include "packfile.h" diff --git a/diff-lib.c b/diff-lib.c index dec040c366..70b3578b90 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -6,6 +6,7 @@ #include "commit.h" #include "diff.h" #include "diffcore.h" +#include "hex.h" #include "revision.h" #include "cache-tree.h" #include "unpack-trees.h" diff --git a/diff.c b/diff.c index 3c3565995d..ec911bdf18 100644 --- a/diff.c +++ b/diff.c @@ -9,6 +9,7 @@ #include "diff.h" #include "diffcore.h" #include "delta.h" +#include "hex.h" #include "xdiff-interface.h" #include "color.h" #include "attr.h" diff --git a/entry.c b/entry.c index 971ab26871..c97cfa833b 100644 --- a/entry.c +++ b/entry.c @@ -2,6 +2,7 @@ #include "blob.h" #include "object-store.h" #include "dir.h" +#include "hex.h" #include "streaming.h" #include "submodule.h" #include "progress.h" diff --git a/fetch-pack.c b/fetch-pack.c index 271e2a6fbd..95a992bcd4 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -2,6 +2,7 @@ #include "alloc.h" #include "repository.h" #include "config.h" +#include "hex.h" #include "lockfile.h" #include "refs.h" #include "pkt-line.h" diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c index d4d6fd3d9d..9609eb3cef 100644 --- a/fmt-merge-msg.c +++ b/fmt-merge-msg.c @@ -5,6 +5,7 @@ #include "object-store.h" #include "diff.h" #include "diff-merges.h" +#include "hex.h" #include "revision.h" #include "tag.h" #include "string-list.h" diff --git a/fsck.c b/fsck.c index 20e1aac39a..871c0a9a25 100644 --- a/fsck.c +++ b/fsck.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "alloc.h" +#include "hex.h" #include "object-store.h" #include "repository.h" #include "object.h" diff --git a/grep.c b/grep.c index cee44a78d0..68e9328dfd 100644 --- a/grep.c +++ b/grep.c @@ -1,6 +1,7 @@ #include "cache.h" #include "config.h" #include "grep.h" +#include "hex.h" #include "object-store.h" #include "userdiff.h" #include "xdiff-interface.h" diff --git a/http-backend.c b/http-backend.c index d756d120dc..45290031e0 100644 --- a/http-backend.c +++ b/http-backend.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "alloc.h" #include "config.h" +#include "hex.h" #include "repository.h" #include "refs.h" #include "pkt-line.h" diff --git a/http-fetch.c b/http-fetch.c index 258fec2068..8db35b9767 100644 --- a/http-fetch.c +++ b/http-fetch.c @@ -1,6 +1,7 @@ #include "cache.h" #include "config.h" #include "exec-cmd.h" +#include "hex.h" #include "http.h" #include "walker.h" #include "strvec.h" diff --git a/http-push.c b/http-push.c index 7f71316456..88aa045ecb 100644 --- a/http-push.c +++ b/http-push.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hex.h" #include "repository.h" #include "commit.h" #include "tag.h" diff --git a/http-walker.c b/http-walker.c index b8f0f98ae1..c3e902c40e 100644 --- a/http-walker.c +++ b/http-walker.c @@ -1,6 +1,7 @@ #include "cache.h" #include "repository.h" #include "commit.h" +#include "hex.h" #include "walker.h" #include "http.h" #include "list.h" diff --git a/http.c b/http.c index c4b6ddef28..86b0745af9 100644 --- a/http.c +++ b/http.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "git-curl-compat.h" +#include "hex.h" #include "http.h" #include "config.h" #include "pack.h" diff --git a/line-log.c b/line-log.c index 4956eae748..1bf89c9acc 100644 --- a/line-log.c +++ b/line-log.c @@ -2,6 +2,7 @@ #include "alloc.h" #include "line-range.h" #include "cache.h" +#include "hex.h" #include "tag.h" #include "blob.h" #include "tree.h" diff --git a/list-objects-filter.c b/list-objects-filter.c index e40ea9b0a8..5d7b331660 100644 --- a/list-objects-filter.c +++ b/list-objects-filter.c @@ -1,6 +1,7 @@ #include "cache.h" #include "alloc.h" #include "dir.h" +#include "hex.h" #include "tag.h" #include "commit.h" #include "tree.h" diff --git a/list-objects.c b/list-objects.c index 7528fe1db2..ab5745bbfe 100644 --- a/list-objects.c +++ b/list-objects.c @@ -1,6 +1,7 @@ #include "cache.h" #include "tag.h" #include "commit.h" +#include "hex.h" #include "tree.h" #include "blob.h" #include "diff.h" diff --git a/log-tree.c b/log-tree.c index 1dd5fcbf7b..ee3dfb6b65 100644 --- a/log-tree.c +++ b/log-tree.c @@ -2,6 +2,7 @@ #include "commit-reach.h" #include "config.h" #include "diff.h" +#include "hex.h" #include "object-store.h" #include "repository.h" #include "tmp-objdir.h" diff --git a/ls-refs.c b/ls-refs.c index 697d4beb8d..f4c6b9b762 100644 --- a/ls-refs.c +++ b/ls-refs.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hex.h" #include "repository.h" #include "refs.h" #include "remote.h" diff --git a/match-trees.c b/match-trees.c index 49398e599f..c38dcbac7c 100644 --- a/match-trees.c +++ b/match-trees.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hex.h" #include "tree.h" #include "tree-walk.h" #include "object-store.h" diff --git a/merge-ort.c b/merge-ort.c index d1611ca400..4c5be8ed91 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -26,6 +26,7 @@ #include "diff.h" #include "diffcore.h" #include "dir.h" +#include "hex.h" #include "entry.h" #include "ll-merge.h" #include "object-store.h" diff --git a/merge-recursive.c b/merge-recursive.c index ae469f8cc8..ee144676b7 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -18,6 +18,7 @@ #include "diff.h" #include "diffcore.h" #include "dir.h" +#include "hex.h" #include "ll-merge.h" #include "lockfile.h" #include "object-store.h" diff --git a/merge.c b/merge.c index 445b4f19aa..2c8b845684 100644 --- a/merge.c +++ b/merge.c @@ -1,6 +1,7 @@ #include "cache.h" #include "diff.h" #include "diffcore.h" +#include "hex.h" #include "lockfile.h" #include "commit.h" #include "run-command.h" diff --git a/midx.c b/midx.c index 84d7a53d66..24799bef51 100644 --- a/midx.c +++ b/midx.c @@ -3,6 +3,7 @@ #include "config.h" #include "csum-file.h" #include "dir.h" +#include "hex.h" #include "lockfile.h" #include "packfile.h" #include "object-store.h" diff --git a/negotiator/skipping.c b/negotiator/skipping.c index 0f5ac48e87..28f8769bd4 100644 --- a/negotiator/skipping.c +++ b/negotiator/skipping.c @@ -2,6 +2,7 @@ #include "skipping.h" #include "../commit.h" #include "../fetch-negotiator.h" +#include "../hex.h" #include "../prio-queue.h" #include "../refs.h" #include "../tag.h" diff --git a/notes-merge.c b/notes-merge.c index b4cc594a79..5b1a9ff13f 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -5,6 +5,7 @@ #include "repository.h" #include "diff.h" #include "diffcore.h" +#include "hex.h" #include "xdiff-interface.h" #include "ll-merge.h" #include "dir.h" diff --git a/notes.c b/notes.c index f2805d51bb..c9e4b8b4a5 100644 --- a/notes.c +++ b/notes.c @@ -1,5 +1,6 @@ #include "cache.h" #include "config.h" +#include "hex.h" #include "notes.h" #include "object-store.h" #include "blob.h" diff --git a/object-file.c b/object-file.c index 18d65220d7..43a39dd8d3 100644 --- a/object-file.c +++ b/object-file.c @@ -9,6 +9,7 @@ #include "git-compat-util.h" #include "alloc.h" #include "config.h" +#include "hex.h" #include "string-list.h" #include "lockfile.h" #include "delta.h" diff --git a/object-name.c b/object-name.c index 2dd1a0f56e..97bb94d226 100644 --- a/object-name.c +++ b/object-name.c @@ -1,5 +1,6 @@ #include "cache.h" #include "config.h" +#include "hex.h" #include "tag.h" #include "commit.h" #include "tree.h" diff --git a/object.c b/object.c index 344087de4d..609fed1b73 100644 --- a/object.c +++ b/object.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hex.h" #include "object.h" #include "replace-object.h" #include "object-store.h" diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index 155939e77b..891d9d2772 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "alloc.h" +#include "hex.h" #include "object-store.h" #include "commit.h" #include "tag.h" diff --git a/pack-bitmap.c b/pack-bitmap.c index 5a97834120..a321d6fae8 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "alloc.h" #include "commit.h" +#include "hex.h" #include "strbuf.h" #include "tag.h" #include "diff.h" diff --git a/pack-check.c b/pack-check.c index bfb593ba72..7ed594d667 100644 --- a/pack-check.c +++ b/pack-check.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hex.h" #include "repository.h" #include "pack.h" #include "pack-revindex.h" diff --git a/pack-write.c b/pack-write.c index 3363729748..041e573bc1 100644 --- a/pack-write.c +++ b/pack-write.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hex.h" #include "pack.h" #include "csum-file.h" #include "remote.h" diff --git a/packfile.c b/packfile.c index 3e3063de44..4088735a7d 100644 --- a/packfile.c +++ b/packfile.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "alloc.h" +#include "hex.h" #include "list.h" #include "pack.h" #include "repository.h" diff --git a/parallel-checkout.c b/parallel-checkout.c index decdc8d8a1..2455aa356d 100644 --- a/parallel-checkout.c +++ b/parallel-checkout.c @@ -2,6 +2,7 @@ #include "alloc.h" #include "config.h" #include "entry.h" +#include "hex.h" #include "parallel-checkout.h" #include "pkt-line.h" #include "progress.h" diff --git a/patch-ids.c b/patch-ids.c index 3153446626..a4473a88fa 100644 --- a/patch-ids.c +++ b/patch-ids.c @@ -2,6 +2,7 @@ #include "diff.h" #include "commit.h" #include "hash-lookup.h" +#include "hex.h" #include "patch-ids.h" static int patch_id_defined(struct commit *commit) diff --git a/path.c b/path.c index 492e17ad12..97561c3b14 100644 --- a/path.c +++ b/path.c @@ -2,6 +2,7 @@ * Utilities for paths and pathnames */ #include "cache.h" +#include "hex.h" #include "repository.h" #include "strbuf.h" #include "string-list.h" diff --git a/pkt-line.c b/pkt-line.c index ce4e73b683..1ea7f8600e 100644 --- a/pkt-line.c +++ b/pkt-line.c @@ -1,5 +1,6 @@ #include "cache.h" #include "pkt-line.h" +#include "hex.h" #include "run-command.h" char packet_buffer[LARGE_PACKET_MAX]; diff --git a/pretty.c b/pretty.c index b608084449..2401e3ed36 100644 --- a/pretty.c +++ b/pretty.c @@ -2,6 +2,7 @@ #include "alloc.h" #include "config.h" #include "commit.h" +#include "hex.h" #include "utf8.h" #include "diff.h" #include "revision.h" diff --git a/promisor-remote.c b/promisor-remote.c index faa7612941..1db566982e 100644 --- a/promisor-remote.c +++ b/promisor-remote.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hex.h" #include "object-store.h" #include "promisor-remote.h" #include "config.h" diff --git a/protocol-caps.c b/protocol-caps.c index bbde91810a..f9bc2a8b90 100644 --- a/protocol-caps.c +++ b/protocol-caps.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "protocol-caps.h" #include "gettext.h" +#include "hex.h" #include "pkt-line.h" #include "strvec.h" #include "hash.h" diff --git a/reachable.c b/reachable.c index aba63ebeb3..be9d40923d 100644 --- a/reachable.c +++ b/reachable.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hex.h" #include "refs.h" #include "tag.h" #include "commit.h" diff --git a/read-cache.c b/read-cache.c index 3cc8e312dc..1bcf673271 100644 --- a/read-cache.c +++ b/read-cache.c @@ -8,6 +8,7 @@ #include "config.h" #include "diff.h" #include "diffcore.h" +#include "hex.h" #include "tempfile.h" #include "lockfile.h" #include "cache-tree.h" diff --git a/ref-filter.c b/ref-filter.c index c8230a0858..d862718508 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "alloc.h" +#include "hex.h" #include "parse-options.h" #include "refs.h" #include "wildmatch.h" diff --git a/refs.c b/refs.c index f90f953551..f22adf6d45 100644 --- a/refs.c +++ b/refs.c @@ -6,6 +6,7 @@ #include "alloc.h" #include "config.h" #include "hashmap.h" +#include "hex.h" #include "lockfile.h" #include "iterator.h" #include "refs.h" diff --git a/refs/debug.c b/refs/debug.c index ff7766bc63..adc34c836f 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -1,4 +1,5 @@ #include "git-compat-util.h" +#include "hex.h" #include "refs-internal.h" #include "trace.h" diff --git a/refs/files-backend.c b/refs/files-backend.c index b89954355d..6f257c7005 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1,5 +1,6 @@ #include "../cache.h" #include "../config.h" +#include "../hex.h" #include "../refs.h" #include "refs-internal.h" #include "ref-cache.h" diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 186dcafcd0..b665d0f7d9 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -1,6 +1,7 @@ #include "../git-compat-util.h" #include "../alloc.h" #include "../config.h" +#include "../hex.h" #include "../refs.h" #include "refs-internal.h" #include "packed-backend.h" diff --git a/refspec.c b/refspec.c index ec336ec5e9..28d90911aa 100644 --- a/refspec.c +++ b/refspec.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "alloc.h" +#include "hex.h" #include "strvec.h" #include "refs.h" #include "refspec.h" diff --git a/remote-curl.c b/remote-curl.c index 380ef3fccf..ed7e3a043a 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "alloc.h" #include "config.h" +#include "hex.h" #include "remote.h" #include "connect.h" #include "strbuf.h" diff --git a/remote.c b/remote.c index daade49a6f..b04e5da338 100644 --- a/remote.c +++ b/remote.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "alloc.h" #include "config.h" +#include "hex.h" #include "remote.h" #include "urlmatch.h" #include "refs.h" diff --git a/replace-object.c b/replace-object.c index 320be2522d..0cf056c4fb 100644 --- a/replace-object.c +++ b/replace-object.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hex.h" #include "oidmap.h" #include "object-store.h" #include "replace-object.h" diff --git a/rerere.c b/rerere.c index d4bcb90853..a67abaab07 100644 --- a/rerere.c +++ b/rerere.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "alloc.h" #include "config.h" +#include "hex.h" #include "lockfile.h" #include "string-list.h" #include "rerere.h" diff --git a/reset.c b/reset.c index 5ded23611f..58b3829ff7 100644 --- a/reset.c +++ b/reset.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "cache-tree.h" +#include "hex.h" #include "lockfile.h" #include "refs.h" #include "reset.h" diff --git a/revision.c b/revision.c index b8f925f088..e356bc4aae 100644 --- a/revision.c +++ b/revision.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "alloc.h" #include "config.h" +#include "hex.h" #include "object-store.h" #include "tag.h" #include "blob.h" diff --git a/send-pack.c b/send-pack.c index f2e19838c9..954104673f 100644 --- a/send-pack.c +++ b/send-pack.c @@ -1,6 +1,7 @@ #include "builtin.h" #include "config.h" #include "commit.h" +#include "hex.h" #include "refs.h" #include "object-store.h" #include "pkt-line.h" diff --git a/sequencer.c b/sequencer.c index fcf8740ce1..af1e07fe76 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1,6 +1,7 @@ #include "cache.h" #include "alloc.h" #include "config.h" +#include "hex.h" #include "lockfile.h" #include "dir.h" #include "object-store.h" diff --git a/server-info.c b/server-info.c index f07daa16f3..4043689202 100644 --- a/server-info.c +++ b/server-info.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "alloc.h" #include "dir.h" +#include "hex.h" #include "repository.h" #include "refs.h" #include "object.h" diff --git a/sha1dc_git.c b/sha1dc_git.c index 5c300e812e..72709606fd 100644 --- a/sha1dc_git.c +++ b/sha1dc_git.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hex.h" #ifdef DC_SHA1_EXTERNAL /* diff --git a/shallow.c b/shallow.c index 7dc73fb898..1cbb05ba0e 100644 --- a/shallow.c +++ b/shallow.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "alloc.h" +#include "hex.h" #include "repository.h" #include "tempfile.h" #include "lockfile.h" diff --git a/strbuf.c b/strbuf.c index bc4c2c09e6..1c57ac6574 100644 --- a/strbuf.c +++ b/strbuf.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "alloc.h" +#include "hex.h" #include "refs.h" #include "string-list.h" #include "utf8.h" diff --git a/strvec.c b/strvec.c index 94d504e380..17d54b6c3b 100644 --- a/strvec.c +++ b/strvec.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "strvec.h" #include "alloc.h" +#include "hex.h" #include "strbuf.h" const char *empty_strvec[] = { NULL }; diff --git a/submodule-config.c b/submodule-config.c index bb7c35fc31..89a7bf0a93 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -1,6 +1,7 @@ #include "cache.h" #include "alloc.h" #include "dir.h" +#include "hex.h" #include "repository.h" #include "config.h" #include "submodule-config.h" diff --git a/submodule.c b/submodule.c index 340ffad1c2..9d89299772 100644 --- a/submodule.c +++ b/submodule.c @@ -7,6 +7,7 @@ #include "dir.h" #include "diff.h" #include "commit.h" +#include "hex.h" #include "revision.h" #include "run-command.h" #include "diffcore.h" diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c index 6c900ca668..787fd52455 100644 --- a/t/helper/test-bloom.c +++ b/t/helper/test-bloom.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "bloom.h" +#include "hex.h" #include "test-tool.h" #include "commit.h" diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c index 9159a17301..615e648e55 100644 --- a/t/helper/test-cache-tree.c +++ b/t/helper/test-cache-tree.c @@ -1,6 +1,7 @@ #define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" +#include "hex.h" #include "tree.h" #include "cache-tree.h" #include "parse-options.h" diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c index 454f17b1a0..92dfc1aa8c 100644 --- a/t/helper/test-dump-cache-tree.c +++ b/t/helper/test-dump-cache-tree.c @@ -1,6 +1,7 @@ #define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" +#include "hex.h" #include "tree.h" #include "cache-tree.h" diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c index 0ea97b8407..813d0a38fa 100644 --- a/t/helper/test-dump-split-index.c +++ b/t/helper/test-dump-split-index.c @@ -1,6 +1,7 @@ #define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" +#include "hex.h" #include "split-index.h" #include "ewah/ewok.h" diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c index 6d53683f13..af953fabe8 100644 --- a/t/helper/test-dump-untracked-cache.c +++ b/t/helper/test-dump-untracked-cache.c @@ -2,6 +2,7 @@ #include "test-tool.h" #include "cache.h" #include "dir.h" +#include "hex.h" static int compare_untracked(const void *a_, const void *b_) { diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c index efc82dd80c..b1edb92a03 100644 --- a/t/helper/test-fast-rebase.c +++ b/t/helper/test-fast-rebase.c @@ -15,6 +15,7 @@ #include "cache-tree.h" #include "commit.h" +#include "hex.h" #include "lockfile.h" #include "merge-ort.h" #include "refs.h" diff --git a/t/helper/test-hash.c b/t/helper/test-hash.c index 5860dab0ff..016248106a 100644 --- a/t/helper/test-hash.c +++ b/t/helper/test-hash.c @@ -1,5 +1,6 @@ #include "test-tool.h" #include "cache.h" +#include "hex.h" int cmd_hash_impl(int ac, const char **av, int algo) { diff --git a/t/helper/test-match-trees.c b/t/helper/test-match-trees.c index 4079fdee06..04bc2563f3 100644 --- a/t/helper/test-match-trees.c +++ b/t/helper/test-match-trees.c @@ -1,5 +1,6 @@ #include "test-tool.h" #include "cache.h" +#include "hex.h" #include "tree.h" int cmd__match_trees(int ac, const char **av) diff --git a/t/helper/test-oid-array.c b/t/helper/test-oid-array.c index d1324d086a..0906993ad5 100644 --- a/t/helper/test-oid-array.c +++ b/t/helper/test-oid-array.c @@ -1,5 +1,6 @@ #include "test-tool.h" #include "cache.h" +#include "hex.h" #include "oid-array.h" static int print_oid(const struct object_id *oid, void *data) diff --git a/t/helper/test-oidmap.c b/t/helper/test-oidmap.c index 0acf99931e..883d40efd4 100644 --- a/t/helper/test-oidmap.c +++ b/t/helper/test-oidmap.c @@ -1,5 +1,6 @@ #include "test-tool.h" #include "cache.h" +#include "hex.h" #include "oidmap.h" #include "strbuf.h" diff --git a/t/helper/test-oidtree.c b/t/helper/test-oidtree.c index d48a409f4e..0b82431a70 100644 --- a/t/helper/test-oidtree.c +++ b/t/helper/test-oidtree.c @@ -1,5 +1,6 @@ #include "test-tool.h" #include "cache.h" +#include "hex.h" #include "oidtree.h" static enum cb_next print_oid(const struct object_id *oid, void *data) diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c index f7b79daf4c..f68b3761b6 100644 --- a/t/helper/test-pack-mtimes.c +++ b/t/helper/test-pack-mtimes.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "test-tool.h" +#include "hex.h" #include "strbuf.h" #include "object-store.h" #include "packfile.h" diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c index 3f102cfddd..da17fd37eb 100644 --- a/t/helper/test-partial-clone.c +++ b/t/helper/test-partial-clone.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hex.h" #include "test-tool.h" #include "repository.h" #include "object-store.h" diff --git a/t/helper/test-proc-receive.c b/t/helper/test-proc-receive.c index a4b305f494..7e12d4f9aa 100644 --- a/t/helper/test-proc-receive.c +++ b/t/helper/test-proc-receive.c @@ -1,5 +1,6 @@ #include "cache.h" #include "connect.h" +#include "hex.h" #include "parse-options.h" #include "pkt-line.h" #include "sigchain.h" diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c index 883d8e20a8..de8f26639d 100644 --- a/t/helper/test-reach.c +++ b/t/helper/test-reach.c @@ -3,6 +3,7 @@ #include "commit.h" #include "commit-reach.h" #include "config.h" +#include "hex.h" #include "parse-options.h" #include "ref-filter.h" #include "string-list.h" diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c index 27072ba94d..0a883cdf26 100644 --- a/t/helper/test-read-midx.c +++ b/t/helper/test-read-midx.c @@ -1,5 +1,6 @@ #include "test-tool.h" #include "cache.h" +#include "hex.h" #include "midx.h" #include "repository.h" #include "object-store.h" diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index ae8a5648da..1745b088b7 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -1,5 +1,6 @@ #include "test-tool.h" #include "cache.h" +#include "hex.h" #include "refs.h" #include "worktree.h" #include "object-store.h" diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c index 56f0e3c1be..10a6dfc216 100644 --- a/t/helper/test-repository.c +++ b/t/helper/test-repository.c @@ -3,6 +3,7 @@ #include "commit-graph.h" #include "commit.h" #include "config.h" +#include "hex.h" #include "object-store.h" #include "object.h" #include "repository.h" diff --git a/tag.c b/tag.c index dfbcd7fcc2..18b718cca6 100644 --- a/tag.c +++ b/tag.c @@ -6,6 +6,7 @@ #include "blob.h" #include "alloc.h" #include "gpg-interface.h" +#include "hex.h" #include "packfile.h" const char *tag_type = "tag"; diff --git a/trace2/tr2_sid.c b/trace2/tr2_sid.c index dc6e75ef13..5f1ce6f85c 100644 --- a/trace2/tr2_sid.c +++ b/trace2/tr2_sid.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hex.h" #include "trace2/tr2_tbuf.h" #include "trace2/tr2_sid.h" diff --git a/transport-helper.c b/transport-helper.c index 3ea7c2bb5a..82ac63e260 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -4,6 +4,7 @@ #include "run-command.h" #include "commit.h" #include "diff.h" +#include "hex.h" #include "revision.h" #include "remote.h" #include "string-list.h" diff --git a/transport.c b/transport.c index ac9e06a6ce..906dbad5a0 100644 --- a/transport.c +++ b/transport.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "alloc.h" #include "config.h" +#include "hex.h" #include "transport.h" #include "hook.h" #include "pkt-line.h" diff --git a/tree-walk.c b/tree-walk.c index d22f3fe5b0..0e2f5ceb71 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -2,6 +2,7 @@ #include "tree-walk.h" #include "alloc.h" #include "dir.h" +#include "hex.h" #include "object-store.h" #include "tree.h" #include "pathspec.h" diff --git a/tree.c b/tree.c index 410e3b477e..76a6534f67 100644 --- a/tree.c +++ b/tree.c @@ -1,5 +1,6 @@ #include "cache.h" #include "cache-tree.h" +#include "hex.h" #include "tree.h" #include "object-store.h" #include "blob.h" diff --git a/unpack-trees.c b/unpack-trees.c index 3d05e45a27..9c1f2a14b4 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -3,6 +3,7 @@ #include "repository.h" #include "config.h" #include "dir.h" +#include "hex.h" #include "tree.h" #include "tree-walk.h" #include "cache-tree.h" diff --git a/upload-pack.c b/upload-pack.c index 551f22ffa5..fa4bb61e4f 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -1,5 +1,6 @@ #include "cache.h" #include "config.h" +#include "hex.h" #include "refs.h" #include "pkt-line.h" #include "sideband.h" diff --git a/url.c b/url.c index e04bd60b6b..bf318c0520 100644 --- a/url.c +++ b/url.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hex.h" #include "url.h" int is_urlschemechar(int first_flag, int ch) diff --git a/urlmatch.c b/urlmatch.c index 620a648efc..2965cbe774 100644 --- a/urlmatch.c +++ b/urlmatch.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hex.h" #include "urlmatch.h" #define URL_ALPHA "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" diff --git a/walker.c b/walker.c index 99d0e0eae0..c046936378 100644 --- a/walker.c +++ b/walker.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hex.h" #include "walker.h" #include "repository.h" #include "object-store.h" diff --git a/wt-status.c b/wt-status.c index 3162241a57..90525bd26f 100644 --- a/wt-status.c +++ b/wt-status.c @@ -4,6 +4,7 @@ #include "dir.h" #include "commit.h" #include "diff.h" +#include "hex.h" #include "revision.h" #include "diffcore.h" #include "quote.h" diff --git a/xdiff-interface.c b/xdiff-interface.c index e87950de32..5baf6ceb94 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -1,5 +1,6 @@ #include "cache.h" #include "config.h" +#include "hex.h" #include "object-store.h" #include "xdiff-interface.h" #include "xdiff/xtypes.h" From b6c09c03eba37934871239ff98d88bd023c60b5a Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 24 Feb 2023 00:09:28 +0000 Subject: [PATCH 018/508] pretty.h: move has_non_ascii() declaration from commit.h The function is defined in pretty.c, so this moves the declaration to a more logical place. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- commit.h | 1 - diffcore-pickaxe.c | 4 ++-- pretty.h | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/commit.h b/commit.h index cc2c5da7bd..06657b4c6e 100644 --- a/commit.h +++ b/commit.h @@ -205,7 +205,6 @@ void free_commit_list(struct commit_list *list); struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */ -int has_non_ascii(const char *text); const char *logmsg_reencode(const struct commit *commit, char **commit_encoding, const char *output_encoding); diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c index 03fcbcb40b..13c98a7b5e 100644 --- a/diffcore-pickaxe.c +++ b/diffcore-pickaxe.c @@ -2,12 +2,12 @@ * Copyright (C) 2005 Junio C Hamano * Copyright (C) 2010 Google Inc. */ -#include "cache.h" +#include "git-compat-util.h" #include "diff.h" #include "diffcore.h" #include "xdiff-interface.h" #include "kwset.h" -#include "commit.h" +#include "pretty.h" #include "quote.h" typedef int (*pickaxe_fn)(mmfile_t *one, mmfile_t *two, diff --git a/pretty.h b/pretty.h index 9508c22f03..921dd6e0ca 100644 --- a/pretty.h +++ b/pretty.h @@ -153,6 +153,8 @@ int commit_format_is_empty(enum cmit_fmt); /* Make subject of commit message suitable for filename */ void format_sanitized_subject(struct strbuf *sb, const char *msg, size_t len); +int has_non_ascii(const char *text); + /* * Set values of fields in "struct process_trailer_options" * according to trailers arguments. From b5fa608180d4270b3495258ab098426551a18372 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 24 Feb 2023 00:09:29 +0000 Subject: [PATCH 019/508] ident.h: move ident-related declarations out of cache.h These functions were all defined in a separate ident.c already, so create ident.h and move the declarations into that file. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- builtin/cat-file.c | 1 + builtin/check-mailmap.c | 1 + builtin/config.c | 1 + builtin/var.c | 1 + cache.h | 58 ----------------------------------- config.c | 1 + gpg-interface.c | 1 + ident.c | 5 ++- ident.h | 67 +++++++++++++++++++++++++++++++++++++++++ refs/files-backend.c | 1 + revision.h | 1 + 11 files changed, 79 insertions(+), 59 deletions(-) create mode 100644 ident.h diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 3040016e27..88c5ea8b26 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -10,6 +10,7 @@ #include "builtin.h" #include "diff.h" #include "hex.h" +#include "ident.h" #include "parse-options.h" #include "userdiff.h" #include "streaming.h" diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c index 7dc47e4793..96db3ddb4b 100644 --- a/builtin/check-mailmap.c +++ b/builtin/check-mailmap.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "config.h" +#include "ident.h" #include "mailmap.h" #include "parse-options.h" #include "string-list.h" diff --git a/builtin/config.c b/builtin/config.c index ca006e9cc1..49d832d409 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -2,6 +2,7 @@ #include "alloc.h" #include "config.h" #include "color.h" +#include "ident.h" #include "parse-options.h" #include "urlmatch.h" #include "quote.h" diff --git a/builtin/var.c b/builtin/var.c index a80c1df86f..d9943be9af 100644 --- a/builtin/var.c +++ b/builtin/var.c @@ -5,6 +5,7 @@ */ #include "builtin.h" #include "config.h" +#include "ident.h" #include "refs.h" static const char var_usage[] = "git var (-l | )"; diff --git a/cache.h b/cache.h index 0c631e75b5..4e0d9bccc0 100644 --- a/cache.h +++ b/cache.h @@ -1445,65 +1445,10 @@ struct object *repo_peel_to_type(struct repository *r, #define peel_to_type(name, namelen, obj, type) \ repo_peel_to_type(the_repository, name, namelen, obj, type) -#define IDENT_STRICT 1 -#define IDENT_NO_DATE 2 -#define IDENT_NO_NAME 4 - -enum want_ident { - WANT_BLANK_IDENT, - WANT_AUTHOR_IDENT, - WANT_COMMITTER_IDENT -}; - -const char *git_author_info(int); -const char *git_committer_info(int); -const char *fmt_ident(const char *name, const char *email, - enum want_ident whose_ident, - const char *date_str, int); -const char *fmt_name(enum want_ident); -const char *ident_default_name(void); -const char *ident_default_email(void); const char *git_editor(void); const char *git_sequence_editor(void); const char *git_pager(int stdout_is_tty); int is_terminal_dumb(void); -int git_ident_config(const char *, const char *, void *); -/* - * Prepare an ident to fall back on if the user didn't configure it. - */ -void prepare_fallback_ident(const char *name, const char *email); -void reset_ident_date(void); - -struct ident_split { - const char *name_begin; - const char *name_end; - const char *mail_begin; - const char *mail_end; - const char *date_begin; - const char *date_end; - const char *tz_begin; - const char *tz_end; -}; -/* - * Signals an success with 0, but time part of the result may be NULL - * if the input lacks timestamp and zone - */ -int split_ident_line(struct ident_split *, const char *, int); - -/* - * Given a commit or tag object buffer and the commit or tag headers, replaces - * the idents in the headers with their canonical versions using the mailmap mechanism. - */ -void apply_mailmap_to_header(struct strbuf *, const char **, struct string_list *); - -/* - * Compare split idents for equality or strict ordering. Note that we - * compare only the ident part of the line, ignoring any timestamp. - * - * Because there are two fields, we must choose one as the primary key; we - * currently arbitrarily pick the email. - */ -int ident_cmp(const struct ident_split *, const struct ident_split *); struct cache_def { struct strbuf path; @@ -1570,9 +1515,6 @@ int update_server_info(int); const char *get_log_output_encoding(void); const char *get_commit_output_encoding(void); -int committer_ident_sufficiently_given(void); -int author_ident_sufficiently_given(void); - extern const char *git_commit_encoding; extern const char *git_log_output_encoding; extern const char *git_mailmap_file; diff --git a/config.c b/config.c index 1d22f23251..d3ab9417a4 100644 --- a/config.c +++ b/config.c @@ -11,6 +11,7 @@ #include "branch.h" #include "config.h" #include "environment.h" +#include "ident.h" #include "repository.h" #include "lockfile.h" #include "exec-cmd.h" diff --git a/gpg-interface.c b/gpg-interface.c index 687236430b..bd13fc92fe 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -4,6 +4,7 @@ #include "run-command.h" #include "strbuf.h" #include "dir.h" +#include "ident.h" #include "gpg-interface.h" #include "sigchain.h" #include "tempfile.h" diff --git a/ident.c b/ident.c index 6de76f9421..8fad92d700 100644 --- a/ident.c +++ b/ident.c @@ -5,10 +5,13 @@ * * Copyright (C) 2005 Linus Torvalds */ -#include "cache.h" +#include "git-compat-util.h" +#include "ident.h" #include "config.h" #include "date.h" +#include "gettext.h" #include "mailmap.h" +#include "strbuf.h" static struct strbuf git_default_name = STRBUF_INIT; static struct strbuf git_default_email = STRBUF_INIT; diff --git a/ident.h b/ident.h new file mode 100644 index 0000000000..96a64896a0 --- /dev/null +++ b/ident.h @@ -0,0 +1,67 @@ +#ifndef IDENT_H +#define IDENT_H + +#include "string-list.h" + +struct ident_split { + const char *name_begin; + const char *name_end; + const char *mail_begin; + const char *mail_end; + const char *date_begin; + const char *date_end; + const char *tz_begin; + const char *tz_end; +}; + +#define IDENT_STRICT 1 +#define IDENT_NO_DATE 2 +#define IDENT_NO_NAME 4 + +enum want_ident { + WANT_BLANK_IDENT, + WANT_AUTHOR_IDENT, + WANT_COMMITTER_IDENT +}; + +const char *ident_default_name(void); +const char *ident_default_email(void); +/* + * Prepare an ident to fall back on if the user didn't configure it. + */ +void prepare_fallback_ident(const char *name, const char *email); +void reset_ident_date(void); +/* + * Signals an success with 0, but time part of the result may be NULL + * if the input lacks timestamp and zone + */ +int split_ident_line(struct ident_split *, const char *, int); + +/* + * Given a commit or tag object buffer and the commit or tag headers, replaces + * the idents in the headers with their canonical versions using the mailmap mechanism. + */ +void apply_mailmap_to_header(struct strbuf *, const char **, struct string_list *); + +/* + * Compare split idents for equality or strict ordering. Note that we + * compare only the ident part of the line, ignoring any timestamp. + * + * Because there are two fields, we must choose one as the primary key; we + * currently arbitrarily pick the email. + */ +int ident_cmp(const struct ident_split *, const struct ident_split *); + +const char *git_author_info(int); +const char *git_committer_info(int); +const char *fmt_ident(const char *name, const char *email, + enum want_ident whose_ident, + const char *date_str, int); +const char *fmt_name(enum want_ident); + +int committer_ident_sufficiently_given(void); +int author_ident_sufficiently_given(void); + +int git_ident_config(const char *, const char *, void *); + +#endif diff --git a/refs/files-backend.c b/refs/files-backend.c index 6f257c7005..31bc5c45ee 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -5,6 +5,7 @@ #include "refs-internal.h" #include "ref-cache.h" #include "packed-backend.h" +#include "../ident.h" #include "../iterator.h" #include "../dir-iterator.h" #include "../lockfile.h" diff --git a/revision.h b/revision.h index 30febad09a..ab71443696 100644 --- a/revision.h +++ b/revision.h @@ -8,6 +8,7 @@ #include "pretty.h" #include "diff.h" #include "commit-slab-decl.h" +#include "ident.h" #include "list-objects-filter-options.h" /** From a64215b6cd5e67939187475c5b248dc5d13e3d60 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 24 Feb 2023 00:09:30 +0000 Subject: [PATCH 020/508] object.h: stop depending on cache.h; make cache.h depend on object.h Things should be able to depend on object.h without pulling in all of cache.h. Move an enum to allow this. Note that a couple files previously depended on things brought in through cache.h indirectly (revision.h -> commit.h -> object.h -> cache.h). As such, this change requires making existing dependencies more explicit in half a dozen files. The inclusion of strbuf.h in some headers if of particular note: these headers directly embedded a strbuf in some new structs, meaning they should have been including strbuf.h all along but were indirectly getting the necessary definitions. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- alloc.c | 2 +- blame.h | 1 - blob.c | 2 +- cache-tree.h | 1 - cache.h | 21 +-------------------- diff-merges.c | 1 + diff.h | 2 +- diffcore-delta.c | 2 +- fsck.h | 1 + help.c | 1 + list-objects-filter-options.h | 3 ++- negotiator/noop.c | 2 +- object.h | 22 +++++++++++++++++++++- shallow.h | 2 ++ t/helper/test-bloom.c | 2 +- t/helper/test-example-decorate.c | 2 +- worktree.h | 1 - 17 files changed, 36 insertions(+), 32 deletions(-) diff --git a/alloc.c b/alloc.c index 27f697e4c8..2886aa9354 100644 --- a/alloc.c +++ b/alloc.c @@ -8,7 +8,7 @@ * up with maximal alignment because it doesn't know what the object alignment * for the new allocation is. */ -#include "cache.h" +#include "git-compat-util.h" #include "object.h" #include "blob.h" #include "tree.h" diff --git a/blame.h b/blame.h index 38bde535b3..b60d1d81e3 100644 --- a/blame.h +++ b/blame.h @@ -1,7 +1,6 @@ #ifndef BLAME_H #define BLAME_H -#include "cache.h" #include "commit.h" #include "xdiff-interface.h" #include "revision.h" diff --git a/blob.c b/blob.c index 8f83523b0c..888e28a559 100644 --- a/blob.c +++ b/blob.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "blob.h" #include "repository.h" #include "alloc.h" diff --git a/cache-tree.h b/cache-tree.h index bd97caa07b..faae88be63 100644 --- a/cache-tree.h +++ b/cache-tree.h @@ -1,7 +1,6 @@ #ifndef CACHE_TREE_H #define CACHE_TREE_H -#include "cache.h" #include "tree.h" #include "tree-walk.h" diff --git a/cache.h b/cache.h index 4e0d9bccc0..d0e105ec58 100644 --- a/cache.h +++ b/cache.h @@ -14,6 +14,7 @@ #include "pack-revindex.h" #include "hash.h" #include "path.h" +#include "object.h" #include "oid-array.h" #include "repository.h" #include "mem-pool.h" @@ -453,26 +454,6 @@ void prefetch_cache_entries(const struct index_state *istate, extern struct index_state the_index; #endif -#define TYPE_BITS 3 - -/* - * Values in this enum (except those outside the 3 bit range) are part - * of pack file format. See gitformat-pack(5) for more information. - */ -enum object_type { - OBJ_BAD = -1, - OBJ_NONE = 0, - OBJ_COMMIT = 1, - OBJ_TREE = 2, - OBJ_BLOB = 3, - OBJ_TAG = 4, - /* 5 for future expansion */ - OBJ_OFS_DELTA = 6, - OBJ_REF_DELTA = 7, - OBJ_ANY, - OBJ_MAX -}; - static inline enum object_type object_type(unsigned int mode) { return S_ISDIR(mode) ? OBJ_TREE : diff --git a/diff-merges.c b/diff-merges.c index faa7bc73a3..ec97616db1 100644 --- a/diff-merges.c +++ b/diff-merges.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "diff-merges.h" +#include "gettext.h" #include "revision.h" typedef void (*diff_merges_setup_func_t)(struct rev_info *); diff --git a/diff.h b/diff.h index 41eb2c3d42..b90036f529 100644 --- a/diff.h +++ b/diff.h @@ -8,6 +8,7 @@ #include "pathspec.h" #include "object.h" #include "oidset.h" +#include "strbuf.h" /** * The diff API is for programs that compare two sets of files (e.g. two trees, @@ -71,7 +72,6 @@ struct oid_array; struct option; struct repository; struct rev_info; -struct strbuf; struct userdiff_driver; typedef int (*pathchange_fn_t)(struct diff_options *options, diff --git a/diffcore-delta.c b/diffcore-delta.c index 18d8f766d7..c30b56e983 100644 --- a/diffcore-delta.c +++ b/diffcore-delta.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "diff.h" #include "diffcore.h" diff --git a/fsck.h b/fsck.h index 668330880e..e17730e9da 100644 --- a/fsck.h +++ b/fsck.h @@ -1,6 +1,7 @@ #ifndef GIT_FSCK_H #define GIT_FSCK_H +#include "object.h" #include "oidset.h" enum fsck_msg_type { diff --git a/help.c b/help.c index 5f84a50b94..216777d2bf 100644 --- a/help.c +++ b/help.c @@ -5,6 +5,7 @@ #include "exec-cmd.h" #include "run-command.h" #include "levenshtein.h" +#include "gettext.h" #include "help.h" #include "command-list.h" #include "string-list.h" diff --git a/list-objects-filter-options.h b/list-objects-filter-options.h index 1fe393f447..ef03b45132 100644 --- a/list-objects-filter-options.h +++ b/list-objects-filter-options.h @@ -1,9 +1,10 @@ #ifndef LIST_OBJECTS_FILTER_OPTIONS_H #define LIST_OBJECTS_FILTER_OPTIONS_H -#include "cache.h" +#include "object.h" #include "parse-options.h" #include "string-list.h" +#include "strbuf.h" /* * The list of defined filters for list-objects. diff --git a/negotiator/noop.c b/negotiator/noop.c index 60569b8350..7b72937686 100644 --- a/negotiator/noop.c +++ b/negotiator/noop.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "noop.h" #include "../commit.h" #include "../fetch-negotiator.h" diff --git a/object.h b/object.h index 31ebe11458..fc45b158da 100644 --- a/object.h +++ b/object.h @@ -1,7 +1,7 @@ #ifndef OBJECT_H #define OBJECT_H -#include "cache.h" +#include "hash.h" struct buffer_slab; @@ -81,6 +81,26 @@ struct object_array { */ #define FLAG_BITS 28 +#define TYPE_BITS 3 + +/* + * Values in this enum (except those outside the 3 bit range) are part + * of pack file format. See gitformat-pack(5) for more information. + */ +enum object_type { + OBJ_BAD = -1, + OBJ_NONE = 0, + OBJ_COMMIT = 1, + OBJ_TREE = 2, + OBJ_BLOB = 3, + OBJ_TAG = 4, + /* 5 for future expansion */ + OBJ_OFS_DELTA = 6, + OBJ_REF_DELTA = 7, + OBJ_ANY, + OBJ_MAX +}; + /* * The object type is stored in 3 bits. */ diff --git a/shallow.h b/shallow.h index aba6ff5829..e9ca7e4bc8 100644 --- a/shallow.h +++ b/shallow.h @@ -6,6 +6,8 @@ #include "repository.h" #include "strbuf.h" +struct oid_array; + void set_alternate_shallow_file(struct repository *r, const char *path, int override); int register_shallow(struct repository *r, const struct object_id *oid); int unregister_shallow(const struct object_id *oid); diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c index 787fd52455..127f134a2a 100644 --- a/t/helper/test-bloom.c +++ b/t/helper/test-bloom.c @@ -1,4 +1,4 @@ -#include "git-compat-util.h" +#include "cache.h" #include "bloom.h" #include "hex.h" #include "test-tool.h" diff --git a/t/helper/test-example-decorate.c b/t/helper/test-example-decorate.c index b9d1200eb9..7c7fc8efc1 100644 --- a/t/helper/test-example-decorate.c +++ b/t/helper/test-example-decorate.c @@ -1,5 +1,5 @@ #include "test-tool.h" -#include "cache.h" +#include "git-compat-util.h" #include "object.h" #include "decorate.h" diff --git a/worktree.h b/worktree.h index 9dcea6fc8c..2baeca2a8a 100644 --- a/worktree.h +++ b/worktree.h @@ -1,7 +1,6 @@ #ifndef WORKTREE_H #define WORKTREE_H -#include "cache.h" #include "refs.h" struct strbuf; From ac48adf488794417b1060b5ed2377a9fd4c33c17 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 24 Feb 2023 00:09:31 +0000 Subject: [PATCH 021/508] dir.h: refactor to no longer need to include cache.h Moving a few functions around allows us to make dir.h no longer need to include cache.h. This commit is best viewed with: git log -1 -p --color-moved Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- cache.h | 31 +++++++++++-------------------- dir.h | 16 ++-------------- pathspec.h | 5 +++++ statinfo.h | 24 ++++++++++++++++++++++++ trace2/tr2_sysenv.c | 2 +- 5 files changed, 43 insertions(+), 35 deletions(-) create mode 100644 statinfo.h diff --git a/cache.h b/cache.h index d0e105ec58..fdb3125f00 100644 --- a/cache.h +++ b/cache.h @@ -14,9 +14,11 @@ #include "pack-revindex.h" #include "hash.h" #include "path.h" +#include "pathspec.h" #include "object.h" #include "oid-array.h" #include "repository.h" +#include "statinfo.h" #include "mem-pool.h" typedef struct git_zstream { @@ -119,26 +121,6 @@ struct cache_header { #define INDEX_FORMAT_LB 2 #define INDEX_FORMAT_UB 4 -/* - * The "cache_time" is just the low 32 bits of the - * time. It doesn't matter if it overflows - we only - * check it for equality in the 32 bits we save. - */ -struct cache_time { - uint32_t sec; - uint32_t nsec; -}; - -struct stat_data { - struct cache_time sd_ctime; - struct cache_time sd_mtime; - unsigned int sd_dev; - unsigned int sd_ino; - unsigned int sd_uid; - unsigned int sd_gid; - unsigned int sd_size; -}; - struct cache_entry { struct hashmap_entry ent; struct stat_data ce_stat_data; @@ -294,6 +276,15 @@ static inline unsigned int canon_mode(unsigned int mode) return S_IFGITLINK; } +static inline int ce_path_match(struct index_state *istate, + const struct cache_entry *ce, + const struct pathspec *pathspec, + char *seen) +{ + return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen, + S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode)); +} + #define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1) #define SOMETHING_CHANGED (1 << 0) /* unclassified changes go here */ diff --git a/dir.h b/dir.h index 8acfc04418..fc4386ae50 100644 --- a/dir.h +++ b/dir.h @@ -1,8 +1,9 @@ #ifndef DIR_H #define DIR_H -#include "cache.h" #include "hashmap.h" +#include "pathspec.h" +#include "statinfo.h" #include "strbuf.h" /** @@ -363,10 +364,6 @@ int count_slashes(const char *s); int simple_length(const char *match); int no_wildcard(const char *string); char *common_prefix(const struct pathspec *pathspec); -int match_pathspec(struct index_state *istate, - const struct pathspec *pathspec, - const char *name, int namelen, - int prefix, char *seen, int is_dir); int report_path_error(const char *ps_matched, const struct pathspec *pathspec); int within_depth(const char *name, int namelen, int depth, int max_depth); @@ -533,15 +530,6 @@ int submodule_path_match(struct index_state *istate, const char *submodule_name, char *seen); -static inline int ce_path_match(struct index_state *istate, - const struct cache_entry *ce, - const struct pathspec *pathspec, - char *seen) -{ - return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen, - S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode)); -} - static inline int dir_path_match(struct index_state *istate, const struct dir_entry *ent, const struct pathspec *pathspec, diff --git a/pathspec.h b/pathspec.h index 41f6adfbb4..a5b38e0907 100644 --- a/pathspec.h +++ b/pathspec.h @@ -171,6 +171,11 @@ int match_pathspec_attrs(struct index_state *istate, const char *name, int namelen, const struct pathspec_item *item); +int match_pathspec(struct index_state *istate, + const struct pathspec *pathspec, + const char *name, int namelen, + int prefix, char *seen, int is_dir); + /* * Determine whether a pathspec will match only entire index entries (non-sparse * files and/or entire sparse directories). If the pathspec has the potential to diff --git a/statinfo.h b/statinfo.h new file mode 100644 index 0000000000..e49e3054ea --- /dev/null +++ b/statinfo.h @@ -0,0 +1,24 @@ +#ifndef STATINFO_H +#define STATINFO_H + +/* + * The "cache_time" is just the low 32 bits of the + * time. It doesn't matter if it overflows - we only + * check it for equality in the 32 bits we save. + */ +struct cache_time { + uint32_t sec; + uint32_t nsec; +}; + +struct stat_data { + struct cache_time sd_ctime; + struct cache_time sd_mtime; + unsigned int sd_dev; + unsigned int sd_ino; + unsigned int sd_uid; + unsigned int sd_gid; + unsigned int sd_size; +}; + +#endif diff --git a/trace2/tr2_sysenv.c b/trace2/tr2_sysenv.c index a380dcf910..069786cb92 100644 --- a/trace2/tr2_sysenv.c +++ b/trace2/tr2_sysenv.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "dir.h" #include "tr2_sysenv.h" From 1c02840008b61676373f3703696dc0c07e6eff7d Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 24 Feb 2023 00:09:32 +0000 Subject: [PATCH 022/508] object-store.h: move struct object_info from cache.h Move struct object_info, and a few related #define's from cache.h to object-store.h. A surprising effect of this change is that replace-object.h, which includes object-store.h, now needs to directly include cache.h since that is where read_replace_refs is declared and that variable is used in one of its inline functions. The next commit will move that declaration and fix that unfortunate new direct inclusion of cache.h. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- merge-blobs.c | 2 +- object-store.h | 128 +++++++++++++++++++++++------------------------ protocol-caps.c | 1 + replace-object.h | 1 + 4 files changed, 67 insertions(+), 65 deletions(-) diff --git a/merge-blobs.c b/merge-blobs.c index 8138090f81..aedcab8113 100644 --- a/merge-blobs.c +++ b/merge-blobs.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "run-command.h" #include "xdiff-interface.h" #include "ll-merge.h" diff --git a/object-store.h b/object-store.h index 1a713d89d7..82201ec3e7 100644 --- a/object-store.h +++ b/object-store.h @@ -1,7 +1,7 @@ #ifndef OBJECT_STORE_H #define OBJECT_STORE_H -#include "cache.h" +#include "object.h" #include "oidmap.h" #include "list.h" #include "oid-array.h" @@ -284,6 +284,69 @@ int pretend_object_file(void *, unsigned long, enum object_type, int force_object_loose(const struct object_id *oid, time_t mtime); +struct object_info { + /* Request */ + enum object_type *typep; + unsigned long *sizep; + off_t *disk_sizep; + struct object_id *delta_base_oid; + struct strbuf *type_name; + void **contentp; + + /* Response */ + enum { + OI_CACHED, + OI_LOOSE, + OI_PACKED, + OI_DBCACHED + } whence; + union { + /* + * struct { + * ... Nothing to expose in this case + * } cached; + * struct { + * ... Nothing to expose in this case + * } loose; + */ + struct { + struct packed_git *pack; + off_t offset; + unsigned int is_delta; + } packed; + } u; +}; + +/* + * Initializer for a "struct object_info" that wants no items. You may + * also memset() the memory to all-zeroes. + */ +#define OBJECT_INFO_INIT { 0 } + +/* Invoke lookup_replace_object() on the given hash */ +#define OBJECT_INFO_LOOKUP_REPLACE 1 +/* Allow reading from a loose object file of unknown/bogus type */ +#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2 +/* Do not retry packed storage after checking packed and loose storage */ +#define OBJECT_INFO_QUICK 8 +/* + * Do not attempt to fetch the object if missing (even if fetch_is_missing is + * nonzero). + */ +#define OBJECT_INFO_SKIP_FETCH_OBJECT 16 +/* + * This is meant for bulk prefetching of missing blobs in a partial + * clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK + */ +#define OBJECT_INFO_FOR_PREFETCH (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK) + +/* Die if object corruption (not just an object being missing) was detected. */ +#define OBJECT_INFO_DIE_IF_CORRUPT 32 + +int oid_object_info_extended(struct repository *r, + const struct object_id *, + struct object_info *, unsigned flags); + /* * Open the loose object at path, check its hash, and return the contents, * use the "oi" argument to assert things about the object, or e.g. populate its @@ -381,69 +444,6 @@ static inline void obj_read_unlock(void) pthread_mutex_unlock(&obj_read_mutex); } -struct object_info { - /* Request */ - enum object_type *typep; - unsigned long *sizep; - off_t *disk_sizep; - struct object_id *delta_base_oid; - struct strbuf *type_name; - void **contentp; - - /* Response */ - enum { - OI_CACHED, - OI_LOOSE, - OI_PACKED, - OI_DBCACHED - } whence; - union { - /* - * struct { - * ... Nothing to expose in this case - * } cached; - * struct { - * ... Nothing to expose in this case - * } loose; - */ - struct { - struct packed_git *pack; - off_t offset; - unsigned int is_delta; - } packed; - } u; -}; - -/* - * Initializer for a "struct object_info" that wants no items. You may - * also memset() the memory to all-zeroes. - */ -#define OBJECT_INFO_INIT { 0 } - -/* Invoke lookup_replace_object() on the given hash */ -#define OBJECT_INFO_LOOKUP_REPLACE 1 -/* Allow reading from a loose object file of unknown/bogus type */ -#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2 -/* Do not retry packed storage after checking packed and loose storage */ -#define OBJECT_INFO_QUICK 8 -/* - * Do not attempt to fetch the object if missing (even if fetch_is_missing is - * nonzero). - */ -#define OBJECT_INFO_SKIP_FETCH_OBJECT 16 -/* - * This is meant for bulk prefetching of missing blobs in a partial - * clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK - */ -#define OBJECT_INFO_FOR_PREFETCH (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK) - -/* Die if object corruption (not just an object being missing) was detected. */ -#define OBJECT_INFO_DIE_IF_CORRUPT 32 - -int oid_object_info_extended(struct repository *r, - const struct object_id *, - struct object_info *, unsigned flags); - /* * Iterate over the files in the loose-object parts of the object * directory "path", triggering the following callbacks: diff --git a/protocol-caps.c b/protocol-caps.c index f9bc2a8b90..874bc815b4 100644 --- a/protocol-caps.c +++ b/protocol-caps.c @@ -5,6 +5,7 @@ #include "pkt-line.h" #include "strvec.h" #include "hash.h" +#include "hex.h" #include "object.h" #include "object-store.h" #include "string-list.h" diff --git a/replace-object.h b/replace-object.h index 3fbc32eb7b..3c92ae9461 100644 --- a/replace-object.h +++ b/replace-object.h @@ -1,6 +1,7 @@ #ifndef REPLACE_OBJECT_H #define REPLACE_OBJECT_H +#include "cache.h" #include "oidmap.h" #include "repository.h" #include "object-store.h" From cbeab74713b6a97dfe6cf9e3bd9dbf7c68ea4e7b Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 24 Feb 2023 00:09:33 +0000 Subject: [PATCH 023/508] replace-object.h: move read_replace_refs declaration from cache.h to here Adjust several files to be more explicit about their dependency on replace-objects to accommodate this change. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- builtin/cat-file.c | 1 + builtin/commit-graph.c | 1 + builtin/fsck.c | 1 + builtin/index-pack.c | 1 + builtin/pack-objects.c | 1 + builtin/prune.c | 1 + builtin/replace.c | 1 + builtin/unpack-objects.c | 1 + builtin/upload-pack.c | 1 + cache.h | 8 -------- config.c | 1 + environment.c | 1 + git.c | 1 + log-tree.c | 1 + replace-object.h | 9 ++++++++- 15 files changed, 21 insertions(+), 9 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 88c5ea8b26..b7a73acb07 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -18,6 +18,7 @@ #include "oid-array.h" #include "packfile.h" #include "object-store.h" +#include "replace-object.h" #include "promisor-remote.h" #include "mailmap.h" diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 6dc83dc51b..d3be7f3b31 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -8,6 +8,7 @@ #include "commit-graph.h" #include "object-store.h" #include "progress.h" +#include "replace-object.h" #include "tag.h" #define BUILTIN_COMMIT_GRAPH_VERIFY_USAGE \ diff --git a/builtin/fsck.c b/builtin/fsck.c index af0fab660d..134b0bd18c 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -20,6 +20,7 @@ #include "decorate.h" #include "packfile.h" #include "object-store.h" +#include "replace-object.h" #include "resolve-undo.h" #include "run-command.h" #include "worktree.h" diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 21c0e109dd..b451755f40 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -16,6 +16,7 @@ #include "thread-utils.h" #include "packfile.h" #include "object-store.h" +#include "replace-object.h" #include "promisor-remote.h" static const char index_pack_usage[] = diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 2b5e85988c..2e73284f10 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -32,6 +32,7 @@ #include "list.h" #include "packfile.h" #include "object-store.h" +#include "replace-object.h" #include "dir.h" #include "midx.h" #include "trace2.h" diff --git a/builtin/prune.c b/builtin/prune.c index db767b7a8f..f2ed45ccf0 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -8,6 +8,7 @@ #include "parse-options.h" #include "progress.h" #include "prune-packed.h" +#include "replace-object.h" #include "object-store.h" #include "shallow.h" diff --git a/builtin/replace.c b/builtin/replace.c index cdcb39f737..71d8e949e3 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -16,6 +16,7 @@ #include "parse-options.h" #include "run-command.h" #include "object-store.h" +#include "replace-object.h" #include "repository.h" #include "tag.h" diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index e125b12188..1908dcfcff 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -9,6 +9,7 @@ #include "pack.h" #include "blob.h" #include "commit.h" +#include "replace-object.h" #include "tag.h" #include "tree.h" #include "tree-walk.h" diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c index 25b69da2bf..7a3c68720f 100644 --- a/builtin/upload-pack.c +++ b/builtin/upload-pack.c @@ -4,6 +4,7 @@ #include "pkt-line.h" #include "parse-options.h" #include "protocol.h" +#include "replace-object.h" #include "upload-pack.h" #include "serve.h" diff --git a/cache.h b/cache.h index fdb3125f00..0221bc6d5c 100644 --- a/cache.h +++ b/cache.h @@ -886,14 +886,6 @@ void set_shared_repository(int value); int get_shared_repository(void); void reset_shared_repository(void); -/* - * Do replace refs need to be checked this run? This variable is - * initialized to true unless --no-replace-object is used or - * $GIT_NO_REPLACE_OBJECTS is set, but is set to false by some - * commands that do not want replace references to be active. - */ -extern int read_replace_refs; - /* * These values are used to help identify parts of a repository to fsync. * FSYNC_COMPONENT_NONE identifies data that will not be a persistent part of the diff --git a/config.c b/config.c index d3ab9417a4..d0aff55fa6 100644 --- a/config.c +++ b/config.c @@ -23,6 +23,7 @@ #include "utf8.h" #include "dir.h" #include "color.h" +#include "replace-object.h" #include "refs.h" #include "worktree.h" diff --git a/environment.c b/environment.c index 1ee3686fd8..89d89110e4 100644 --- a/environment.c +++ b/environment.c @@ -17,6 +17,7 @@ #include "commit.h" #include "strvec.h" #include "object-store.h" +#include "replace-object.h" #include "tmp-objdir.h" #include "chdir-notify.h" #include "shallow.h" diff --git a/git.c b/git.c index 96b0a2837d..389f46887e 100644 --- a/git.c +++ b/git.c @@ -4,6 +4,7 @@ #include "help.h" #include "run-command.h" #include "alias.h" +#include "replace-object.h" #include "shallow.h" #define RUN_SETUP (1<<0) diff --git a/log-tree.c b/log-tree.c index ee3dfb6b65..043e0df685 100644 --- a/log-tree.c +++ b/log-tree.c @@ -13,6 +13,7 @@ #include "merge-ort.h" #include "reflog-walk.h" #include "refs.h" +#include "replace-object.h" #include "string-list.h" #include "color.h" #include "gpg-interface.h" diff --git a/replace-object.h b/replace-object.h index 3c92ae9461..500482b02b 100644 --- a/replace-object.h +++ b/replace-object.h @@ -1,11 +1,18 @@ #ifndef REPLACE_OBJECT_H #define REPLACE_OBJECT_H -#include "cache.h" #include "oidmap.h" #include "repository.h" #include "object-store.h" +/* + * Do replace refs need to be checked this run? This variable is + * initialized to true unless --no-replace-object is used or + * $GIT_NO_REPLACE_OBJECTS is set, but is set to false by some + * commands that do not want replace references to be active. + */ +extern int read_replace_refs; + struct replace_object { struct oidmap_entry original; struct object_id replacement; From fc7bd51b06424694c2e3dd97c11fa095d84d52b1 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 24 Feb 2023 00:09:34 +0000 Subject: [PATCH 024/508] treewide: replace cache.h with more direct headers, where possible Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- advice.c | 4 +++- decorate.c | 3 ++- diffcore-order.c | 3 ++- diffcore-rename.c | 6 +++++- diffcore-rotate.c | 3 ++- graph.c | 3 ++- hook.c | 5 ++++- quote.c | 1 + sha1dc_git.c | 3 ++- unix-socket.c | 3 ++- url.c | 3 ++- urlmatch.c | 4 +++- 12 files changed, 30 insertions(+), 11 deletions(-) diff --git a/advice.c b/advice.c index fd18968943..a5ea460ab8 100644 --- a/advice.c +++ b/advice.c @@ -1,6 +1,8 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "advice.h" #include "config.h" #include "color.h" +#include "gettext.h" #include "help.h" #include "string-list.h" diff --git a/decorate.c b/decorate.c index 2036d15967..71e79daa82 100644 --- a/decorate.c +++ b/decorate.c @@ -2,7 +2,8 @@ * decorate.c - decorate a git object with some arbitrary * data. */ -#include "cache.h" +#include "git-compat-util.h" +#include "hashmap.h" #include "object.h" #include "decorate.h" diff --git a/diffcore-order.c b/diffcore-order.c index 19e73311f9..57ccab2846 100644 --- a/diffcore-order.c +++ b/diffcore-order.c @@ -1,7 +1,8 @@ /* * Copyright (C) 2005 Junio C Hamano */ -#include "cache.h" +#include "git-compat-util.h" +#include "gettext.h" #include "diff.h" #include "diffcore.h" diff --git a/diffcore-rename.c b/diffcore-rename.c index 62c0299984..7e9ff96d43 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -2,15 +2,19 @@ * * Copyright (C) 2005 Junio C Hamano */ -#include "cache.h" +#include "git-compat-util.h" #include "alloc.h" #include "diff.h" #include "diffcore.h" #include "object-store.h" #include "hashmap.h" +#include "mem-pool.h" +#include "oid-array.h" #include "progress.h" #include "promisor-remote.h" +#include "string-list.h" #include "strmap.h" +#include "trace2.h" /* Table of rename/copy destinations */ diff --git a/diffcore-rotate.c b/diffcore-rotate.c index 445f060ab0..533986cf63 100644 --- a/diffcore-rotate.c +++ b/diffcore-rotate.c @@ -2,7 +2,8 @@ * Copyright (C) 2021, Google LLC. * Based on diffcore-order.c, which is Copyright (C) 2005, Junio C Hamano */ -#include "cache.h" +#include "git-compat-util.h" +#include "gettext.h" #include "diff.h" #include "diffcore.h" diff --git a/graph.c b/graph.c index 568b6e7cd4..2a9dc430fa 100644 --- a/graph.c +++ b/graph.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "gettext.h" #include "config.h" #include "commit.h" #include "color.h" diff --git a/hook.c b/hook.c index 1a84831863..f6ddd79098 100644 --- a/hook.c +++ b/hook.c @@ -1,7 +1,10 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "advice.h" +#include "gettext.h" #include "hook.h" #include "run-command.h" #include "config.h" +#include "strbuf.h" const char *find_hook(const char *name) { diff --git a/quote.c b/quote.c index 2453397fbb..7ccb5a06cd 100644 --- a/quote.c +++ b/quote.c @@ -1,6 +1,7 @@ #include "cache.h" #include "alloc.h" #include "quote.h" +#include "strbuf.h" #include "strvec.h" int quote_path_fully = 1; diff --git a/sha1dc_git.c b/sha1dc_git.c index 72709606fd..9b675a046e 100644 --- a/sha1dc_git.c +++ b/sha1dc_git.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "sha1dc_git.h" #include "hex.h" #ifdef DC_SHA1_EXTERNAL diff --git a/unix-socket.c b/unix-socket.c index e0be1badb5..79800d8063 100644 --- a/unix-socket.c +++ b/unix-socket.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "strbuf.h" #include "unix-socket.h" #define DEFAULT_UNIX_STREAM_LISTEN_BACKLOG (5) diff --git a/url.c b/url.c index bf318c0520..2e1a9f6fee 100644 --- a/url.c +++ b/url.c @@ -1,5 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" #include "hex.h" +#include "strbuf.h" #include "url.h" int is_urlschemechar(int first_flag, int ch) diff --git a/urlmatch.c b/urlmatch.c index 2965cbe774..eba0bdd77f 100644 --- a/urlmatch.c +++ b/urlmatch.c @@ -1,5 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "gettext.h" #include "hex.h" +#include "strbuf.h" #include "urlmatch.h" #define URL_ALPHA "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" From eef65c716ceb23fd4570d1a0dfbd84d7b5f1e039 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 24 Feb 2023 00:09:35 +0000 Subject: [PATCH 025/508] Remove unnecessary includes of builtin.h Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- diff-no-index.c | 1 - merge-recursive.c | 1 - send-pack.c | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/diff-no-index.c b/diff-no-index.c index 05fafd0019..a3cf358baf 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -13,7 +13,6 @@ #include "diffcore.h" #include "revision.h" #include "log-tree.h" -#include "builtin.h" #include "parse-options.h" #include "string-list.h" #include "dir.h" diff --git a/merge-recursive.c b/merge-recursive.c index ee144676b7..89731f4090 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -10,7 +10,6 @@ #include "alloc.h" #include "attr.h" #include "blob.h" -#include "builtin.h" #include "cache-tree.h" #include "commit.h" #include "commit-reach.h" diff --git a/send-pack.c b/send-pack.c index 954104673f..423a5cfe22 100644 --- a/send-pack.c +++ b/send-pack.c @@ -1,4 +1,4 @@ -#include "builtin.h" +#include "git-compat-util.h" #include "config.h" #include "commit.h" #include "hex.h" From f524970185963a180ecf3a750a31405c4d0de484 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Fri, 24 Feb 2023 00:09:36 +0000 Subject: [PATCH 026/508] diff.h: remove unnecessary include of object.h Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- diff.h | 1 - 1 file changed, 1 deletion(-) diff --git a/diff.h b/diff.h index b90036f529..f80bd297ca 100644 --- a/diff.h +++ b/diff.h @@ -6,7 +6,6 @@ #include "tree-walk.h" #include "pathspec.h" -#include "object.h" #include "oidset.h" #include "strbuf.h" From fe6258c348ad79a3c11e309995d88cdf08cde984 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:34:44 -0500 Subject: [PATCH 027/508] ref-filter: drop unused atom parameter from get_worktree_path() The get_worktree_path() function is used to populate the %(worktreepath) value, but it has never used its "atom" parameter since it was added in 2582083fa1 (ref-filter: add worktreepath atom, 2019-04-28). Normally we'd use the atom struct to cache any work we do, but in this case there's a global hashmap that does that caching already. So we can just drop the unused parameter. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- ref-filter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index f8203c6b05..434a28c830 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1822,7 +1822,7 @@ static void lazy_init_worktree_map(void) populate_worktree_map(&(ref_to_worktree_map.map), ref_to_worktree_map.worktrees); } -static char *get_worktree_path(const struct used_atom *atom, const struct ref_array_item *ref) +static char *get_worktree_path(const struct ref_array_item *ref) { struct hashmap_entry entry, *e; struct ref_to_worktree_entry *lookup_result; @@ -1881,7 +1881,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) refname = get_refname(atom, ref); else if (atom_type == ATOM_WORKTREEPATH) { if (ref->kind == FILTER_REFS_BRANCHES) - v->s = get_worktree_path(atom, ref); + v->s = get_worktree_path(ref); else v->s = xstrdup(""); continue; From c4716086d8653ff2761b5f8b0452c97c24e117ed Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:37:22 -0500 Subject: [PATCH 028/508] ls-refs: drop config caching The code for the v2 ls-refs command has an ensure_config_read() function that tries to read the lsrefs.unborn config only once and caches it in some static global variables. There's no real need for this caching. In any given process we'd only need the value twice (once to decide whether to advertise, and once if somebody runs the command). And since the config code already has its own cache, each access is only incurring a hash lookup and string comparison anyway. Since the values we set are going to be specific to the_repository, the globals we set are a mild anti-pattern. In practice it's not a bug (yet) since the server-side v2 code only handles a single repository anyway. But it doesn't hurt to take a small step in the right direction and model a good approach. Note that we currently set two booleans: advertise_unborn and allow_unborn. But we can get away with a single value, since "advertise" naturally implies "allow". That lets us just convert this to a function with a return value. Note that we still always read from the_repository; we'll deal with that in a follow-on patch. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- ls-refs.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/ls-refs.c b/ls-refs.c index 697d4beb8d..4863813655 100644 --- a/ls-refs.c +++ b/ls-refs.c @@ -8,38 +8,32 @@ #include "config.h" #include "string-list.h" -static int config_read; -static int advertise_unborn; -static int allow_unborn; - -static void ensure_config_read(void) +static enum { + UNBORN_IGNORE = 0, + UNBORN_ALLOW, + UNBORN_ADVERTISE /* implies ALLOW */ +} unborn_config(void) { const char *str = NULL; - if (config_read) - return; - if (repo_config_get_string_tmp(the_repository, "lsrefs.unborn", &str)) { /* * If there is no such config, advertise and allow it by * default. */ - advertise_unborn = 1; - allow_unborn = 1; + return UNBORN_ADVERTISE; } else { if (!strcmp(str, "advertise")) { - advertise_unborn = 1; - allow_unborn = 1; + return UNBORN_ADVERTISE; } else if (!strcmp(str, "allow")) { - allow_unborn = 1; + return UNBORN_ALLOW; } else if (!strcmp(str, "ignore")) { - /* do nothing */ + return UNBORN_IGNORE; } else { die(_("invalid value for '%s': '%s'"), "lsrefs.unborn", str); } } - config_read = 1; } /* @@ -159,7 +153,6 @@ int ls_refs(struct repository *r, struct packet_reader *request) strbuf_init(&data.buf, 0); string_list_init_dup(&data.hidden_refs); - ensure_config_read(); git_config(ls_refs_config, &data); while (packet_reader_read(request) == PACKET_READ_NORMAL) { @@ -175,7 +168,7 @@ int ls_refs(struct repository *r, struct packet_reader *request) strvec_push(&data.prefixes, out); } else if (!strcmp("unborn", arg)) - data.unborn = allow_unborn; + data.unborn = !!unborn_config(); else die(_("unexpected line: '%s'"), arg); } @@ -206,11 +199,8 @@ int ls_refs(struct repository *r, struct packet_reader *request) int ls_refs_advertise(struct repository *r, struct strbuf *value) { - if (value) { - ensure_config_read(); - if (advertise_unborn) - strbuf_addstr(value, "unborn"); - } + if (value && unborn_config() == UNBORN_ADVERTISE) + strbuf_addstr(value, "unborn"); return 1; } From 4b4e75dd4f1dac0c25bded7466b0cc20c9649efb Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:38:10 -0500 Subject: [PATCH 029/508] serve: use repository pointer to get config A few of the v2 "serve" callbacks ignore their repository parameter and read config using the_repository (either directly or implicitly by calling wrapper functions). This isn't a bug since the server code only handles a single main repository anyway (and indeed, if you look at the callers, these repository parameters will always be the_repository). But in the long run we want to get rid of the_repository, so let's take a tiny step in that direction. As a bonus, this silences some -Wunused-parameter warnings. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- bundle-uri.c | 2 +- ls-refs.c | 8 ++++---- serve.c | 2 +- upload-pack.c | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bundle-uri.c b/bundle-uri.c index 8a3c39ce57..177c181040 100644 --- a/bundle-uri.c +++ b/bundle-uri.c @@ -884,7 +884,7 @@ int bundle_uri_command(struct repository *r, * Read all "bundle.*" config lines to the client as key=value * packet lines. */ - git_config(config_to_packet_line, &writer); + repo_config(r, config_to_packet_line, &writer); packet_writer_flush(&writer); diff --git a/ls-refs.c b/ls-refs.c index 4863813655..bd9ab2c348 100644 --- a/ls-refs.c +++ b/ls-refs.c @@ -12,11 +12,11 @@ static enum { UNBORN_IGNORE = 0, UNBORN_ALLOW, UNBORN_ADVERTISE /* implies ALLOW */ -} unborn_config(void) +} unborn_config(struct repository *r) { const char *str = NULL; - if (repo_config_get_string_tmp(the_repository, "lsrefs.unborn", &str)) { + if (repo_config_get_string_tmp(r, "lsrefs.unborn", &str)) { /* * If there is no such config, advertise and allow it by * default. @@ -168,7 +168,7 @@ int ls_refs(struct repository *r, struct packet_reader *request) strvec_push(&data.prefixes, out); } else if (!strcmp("unborn", arg)) - data.unborn = !!unborn_config(); + data.unborn = !!unborn_config(r); else die(_("unexpected line: '%s'"), arg); } @@ -199,7 +199,7 @@ int ls_refs(struct repository *r, struct packet_reader *request) int ls_refs_advertise(struct repository *r, struct strbuf *value) { - if (value && unborn_config() == UNBORN_ADVERTISE) + if (value && unborn_config(r) == UNBORN_ADVERTISE) strbuf_addstr(value, "unborn"); return 1; diff --git a/serve.c b/serve.c index cbf4a143cf..2ccc03c16b 100644 --- a/serve.c +++ b/serve.c @@ -48,7 +48,7 @@ static void object_format_receive(struct repository *r, static int session_id_advertise(struct repository *r, struct strbuf *value) { if (advertise_sid == -1 && - git_config_get_bool("transfer.advertisesid", &advertise_sid)) + repo_config_get_bool(r, "transfer.advertisesid", &advertise_sid)) advertise_sid = 0; if (!advertise_sid) return 0; diff --git a/upload-pack.c b/upload-pack.c index 551f22ffa5..bcb702a5ba 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -1775,26 +1775,26 @@ int upload_pack_advertise(struct repository *r, strbuf_addstr(value, "shallow wait-for-done"); - if (!repo_config_get_bool(the_repository, + if (!repo_config_get_bool(r, "uploadpack.allowfilter", &allow_filter_value) && allow_filter_value) strbuf_addstr(value, " filter"); - if (!repo_config_get_bool(the_repository, + if (!repo_config_get_bool(r, "uploadpack.allowrefinwant", &allow_ref_in_want) && allow_ref_in_want) strbuf_addstr(value, " ref-in-want"); if (git_env_bool("GIT_TEST_SIDEBAND_ALL", 0) || - (!repo_config_get_bool(the_repository, + (!repo_config_get_bool(r, "uploadpack.allowsidebandall", &allow_sideband_all_value) && allow_sideband_all_value)) strbuf_addstr(value, " sideband-all"); - if (!repo_config_get_string(the_repository, + if (!repo_config_get_string(r, "uploadpack.blobpackfileuri", &str) && str) { From 74595cca21a41e4be6ca8d578d805b70b7653e98 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:38:23 -0500 Subject: [PATCH 030/508] serve: mark unused parameters in virtual functions Each v2 "serve" action has a virtual function for advertising and implementing the command. A few of these are so trivial that they don't need to look at their parameters, especially the "repository" parameter. We can mark them so that -Wunused-parameter doesn't complain. Note that upload_pack_v2() probably _should_ be using its repository pointer. But teaching the functions it calls to do so is non-trivial. Even using it for something as simple as reading config is tricky, both because it shares code with the v1 upload pack, and because the git_protected_config() mechanism it uses does not have a repo-specific interface. So we'll just annotate it for now, and cleaning it up can be part of the larger work to drop references to the_repository. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- serve.c | 10 +++++----- upload-pack.c | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/serve.c b/serve.c index 2ccc03c16b..e08a980083 100644 --- a/serve.c +++ b/serve.c @@ -12,13 +12,13 @@ static int advertise_sid = -1; static int client_hash_algo = GIT_HASH_SHA1; -static int always_advertise(struct repository *r, - struct strbuf *value) +static int always_advertise(struct repository *r UNUSED, + struct strbuf *value UNUSED) { return 1; } -static int agent_advertise(struct repository *r, +static int agent_advertise(struct repository *r UNUSED, struct strbuf *value) { if (value) @@ -34,7 +34,7 @@ static int object_format_advertise(struct repository *r, return 1; } -static void object_format_receive(struct repository *r, +static void object_format_receive(struct repository *r UNUSED, const char *algo_name) { if (!algo_name) @@ -57,7 +57,7 @@ static int session_id_advertise(struct repository *r, struct strbuf *value) return 1; } -static void session_id_receive(struct repository *r, +static void session_id_receive(struct repository *r UNUSED, const char *client_sid) { if (!client_sid) diff --git a/upload-pack.c b/upload-pack.c index bcb702a5ba..f6f4da0fef 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -1699,7 +1699,7 @@ enum fetch_state { FETCH_DONE, }; -int upload_pack_v2(struct repository *r, struct packet_reader *request) +int upload_pack_v2(struct repository *r UNUSED, struct packet_reader *request) { enum fetch_state state = FETCH_PROCESS_ARGS; struct upload_pack_data data; From 07ffb954b3421f78c5789477a540d400bbe647a2 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:38:30 -0500 Subject: [PATCH 031/508] object-name: mark unused parameters in disambiguate callbacks The object-name disambiguation code triggers a callback for each possible object id we find. This is really used for two purposes: - "hint" functions like disambiguate_commit_only report back on whether the value is usable - iterator functions like repo_for_each_abbrev() use it to collect and report matching names. Compiling with -Wunused-parameter generates several warnings, but they're distinct for each type. The "hint" functions never look at the void cb_data pointer; they only care whether the oid matches our hint. The iterator functions never look at the "struct repository" parameter; they're just reporting back the oids they see, and always return 0. So arguably these could be two separate interfaces: int (*hint)(struct repository *r, const struct object_id *oid); void (*iter)(const struct object_id *oid, void *cb_data); But doing so would complicate the disambiguation code, which now has to accept and call the two different types. Since we can easily squelch the compiler warnings by annotating the functions, let's just do that. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- object-name.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/object-name.c b/object-name.c index 2dd1a0f56e..7d1986ad48 100644 --- a/object-name.c +++ b/object-name.c @@ -223,7 +223,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds, static int disambiguate_commit_only(struct repository *r, const struct object_id *oid, - void *cb_data_unused) + void *cb_data UNUSED) { int kind = oid_object_info(r, oid, NULL); return kind == OBJ_COMMIT; @@ -231,7 +231,7 @@ static int disambiguate_commit_only(struct repository *r, static int disambiguate_committish_only(struct repository *r, const struct object_id *oid, - void *cb_data_unused) + void *cb_data UNUSED) { struct object *obj; int kind; @@ -251,7 +251,7 @@ static int disambiguate_committish_only(struct repository *r, static int disambiguate_tree_only(struct repository *r, const struct object_id *oid, - void *cb_data_unused) + void *cb_data UNUSED) { int kind = oid_object_info(r, oid, NULL); return kind == OBJ_TREE; @@ -259,7 +259,7 @@ static int disambiguate_tree_only(struct repository *r, static int disambiguate_treeish_only(struct repository *r, const struct object_id *oid, - void *cb_data_unused) + void *cb_data UNUSED) { struct object *obj; int kind; @@ -279,7 +279,7 @@ static int disambiguate_treeish_only(struct repository *r, static int disambiguate_blob_only(struct repository *r, const struct object_id *oid, - void *cb_data_unused) + void *cb_data UNUSED) { int kind = oid_object_info(r, oid, NULL); return kind == OBJ_BLOB; @@ -473,7 +473,7 @@ static int collect_ambiguous(const struct object_id *oid, void *data) return 0; } -static int repo_collect_ambiguous(struct repository *r, +static int repo_collect_ambiguous(struct repository *r UNUSED, const struct object_id *oid, void *data) { @@ -665,7 +665,7 @@ static int extend_abbrev_len(const struct object_id *oid, void *cb_data) return 0; } -static int repo_extend_abbrev_len(struct repository *r, +static int repo_extend_abbrev_len(struct repository *r UNUSED, const struct object_id *oid, void *cb_data) { From 77ef8b0e1e9e9e70aa8756b45ed12a190a3bcc91 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:38:35 -0500 Subject: [PATCH 032/508] http-backend: mark argc/argv unused We can't drop them because it's cmd_main(), which has a set prototype, but the CGI interface does not do anything with such arguments. Arguably we could detect them and complain. It's possible this could detect misconfigurations or other mistakes, but: - as far as I can tell common webservers like apache do not have any mechanism to pass arguments to a CGI at all, so this isn't a mistake one could even make - it's possible that some obscure webserver might pass arguments, and we'd break that case. I have no idea if such a webserver exists; the CGI standard says only "The script is invoked in a system-defined manner". So probably it would not hurt to detect them, but it also is unlikely to help anyone. Let's just mark them as unused, which retains the current behavior but silences -Wunused-parameter. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- http-backend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http-backend.c b/http-backend.c index 8ab58e55f8..fc3ab97c0f 100644 --- a/http-backend.c +++ b/http-backend.c @@ -736,7 +736,7 @@ static int bad_request(struct strbuf *hdr, const struct service_cmd *c) return 0; } -int cmd_main(int argc, const char **argv) +int cmd_main(int argc UNUSED, const char **argv UNUSED) { char *method = getenv("REQUEST_METHOD"); const char *proto_header; From 2be1506a788a24e87ba4b53a1654c9ff40402750 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:38:43 -0500 Subject: [PATCH 033/508] http-backend: mark unused parameters in virtual functions The http-backend dispatches requests via a table of virtual functions. Some of the functions ignore their "arg" parameter, because it's implicit in the function (e.g., get_info_refs knows that it is dispatched only for a request to "/info/refs"). Mark these unused parameters to silence -Wunused-parameter. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- http-backend.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/http-backend.c b/http-backend.c index fc3ab97c0f..db963e64d7 100644 --- a/http-backend.c +++ b/http-backend.c @@ -524,7 +524,7 @@ static int show_text_ref(const char *name, const struct object_id *oid, return 0; } -static void get_info_refs(struct strbuf *hdr, char *arg) +static void get_info_refs(struct strbuf *hdr, char *arg UNUSED) { const char *service_name = get_parameter("service"); struct strbuf buf = STRBUF_INIT; @@ -578,7 +578,7 @@ static int show_head_ref(const char *refname, const struct object_id *oid, return 0; } -static void get_head(struct strbuf *hdr, char *arg) +static void get_head(struct strbuf *hdr, char *arg UNUSED) { struct strbuf buf = STRBUF_INIT; @@ -588,7 +588,7 @@ static void get_head(struct strbuf *hdr, char *arg) strbuf_release(&buf); } -static void get_info_packs(struct strbuf *hdr, char *arg) +static void get_info_packs(struct strbuf *hdr, char *arg UNUSED) { size_t objdirlen = strlen(get_object_directory()); struct strbuf buf = STRBUF_INIT; From 5fe9e1ce2f7e0be5ea817f2e4ae2c7edecf771c0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:39:06 -0500 Subject: [PATCH 034/508] ref-filter: mark unused callback parameters The ref-filter code uses virtual functions to handle specific atoms, but many of the functions ignore some parameters: - most atom parsers do not need the ref_format itself, unless they are looking at centralized options like use_color, quote_style, etc. - meta-atom handlers like append_atom(), align_atom_handler(), etc, can't generate errors, so ignore their "err" parameter - likewise, the handlers for then/else/end do not even need to look at their atom_value, as the "if" handler put everything they need into the ref_formatting_state stack Since these functions all have to conform to virtual function interfaces, we can't just drop the unused parameters, but must mark them as UNUSED (to appease -Wunused-parameter). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- ref-filter.c | 62 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 434a28c830..acdee7fe3d 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -282,7 +282,8 @@ static int refname_atom_parser_internal(struct refname_atom *atom, const char *a return 0; } -static int remote_ref_atom_parser(struct ref_format *format, struct used_atom *atom, +static int remote_ref_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { struct string_list params = STRING_LIST_INIT_DUP; @@ -329,7 +330,8 @@ static int remote_ref_atom_parser(struct ref_format *format, struct used_atom *a return 0; } -static int objecttype_atom_parser(struct ref_format *format, struct used_atom *atom, +static int objecttype_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (arg) @@ -341,7 +343,8 @@ static int objecttype_atom_parser(struct ref_format *format, struct used_atom *a return 0; } -static int objectsize_atom_parser(struct ref_format *format, struct used_atom *atom, +static int objectsize_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (!arg) { @@ -361,7 +364,8 @@ static int objectsize_atom_parser(struct ref_format *format, struct used_atom *a return 0; } -static int deltabase_atom_parser(struct ref_format *format, struct used_atom *atom, +static int deltabase_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (arg) @@ -373,7 +377,8 @@ static int deltabase_atom_parser(struct ref_format *format, struct used_atom *at return 0; } -static int body_atom_parser(struct ref_format *format, struct used_atom *atom, +static int body_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (arg) @@ -382,7 +387,8 @@ static int body_atom_parser(struct ref_format *format, struct used_atom *atom, return 0; } -static int subject_atom_parser(struct ref_format *format, struct used_atom *atom, +static int subject_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (!arg) @@ -394,7 +400,8 @@ static int subject_atom_parser(struct ref_format *format, struct used_atom *atom return 0; } -static int trailers_atom_parser(struct ref_format *format, struct used_atom *atom, +static int trailers_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { atom->u.contents.trailer_opts.no_divider = 1; @@ -448,8 +455,9 @@ static int contents_atom_parser(struct ref_format *format, struct used_atom *ato return 0; } -static int raw_atom_parser(struct ref_format *format, struct used_atom *atom, - const char *arg, struct strbuf *err) +static int raw_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, + const char *arg, struct strbuf *err) { if (!arg) atom->u.raw_data.option = RAW_BARE; @@ -460,7 +468,8 @@ static int raw_atom_parser(struct ref_format *format, struct used_atom *atom, return 0; } -static int oid_atom_parser(struct ref_format *format, struct used_atom *atom, +static int oid_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (!arg) @@ -479,7 +488,8 @@ static int oid_atom_parser(struct ref_format *format, struct used_atom *atom, return 0; } -static int person_email_atom_parser(struct ref_format *format, struct used_atom *atom, +static int person_email_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (!arg) @@ -493,7 +503,8 @@ static int person_email_atom_parser(struct ref_format *format, struct used_atom return 0; } -static int refname_atom_parser(struct ref_format *format, struct used_atom *atom, +static int refname_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { return refname_atom_parser_internal(&atom->u.refname, arg, atom->name, err); @@ -510,7 +521,8 @@ static align_type parse_align_position(const char *s) return -1; } -static int align_atom_parser(struct ref_format *format, struct used_atom *atom, +static int align_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { struct align *align = &atom->u.align; @@ -562,7 +574,8 @@ static int align_atom_parser(struct ref_format *format, struct used_atom *atom, return 0; } -static int if_atom_parser(struct ref_format *format, struct used_atom *atom, +static int if_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (!arg) { @@ -577,7 +590,8 @@ static int if_atom_parser(struct ref_format *format, struct used_atom *atom, return 0; } -static int rest_atom_parser(struct ref_format *format, struct used_atom *atom, +static int rest_atom_parser(struct ref_format *format, + struct used_atom *atom UNUSED, const char *arg, struct strbuf *err) { if (arg) @@ -586,7 +600,8 @@ static int rest_atom_parser(struct ref_format *format, struct used_atom *atom, return 0; } -static int head_atom_parser(struct ref_format *format, struct used_atom *atom, +static int head_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (arg) @@ -791,7 +806,7 @@ static void quote_formatting(struct strbuf *s, const char *str, ssize_t len, int } static int append_atom(struct atom_value *v, struct ref_formatting_state *state, - struct strbuf *unused_err) + struct strbuf *err UNUSED) { /* * Quote formatting is only done when the stack has a single @@ -841,7 +856,7 @@ static void end_align_handler(struct ref_formatting_stack **stack) } static int align_atom_handler(struct atom_value *atomv, struct ref_formatting_state *state, - struct strbuf *unused_err) + struct strbuf *err UNUSED) { struct ref_formatting_stack *new_stack; @@ -888,7 +903,7 @@ static void if_then_else_handler(struct ref_formatting_stack **stack) } static int if_atom_handler(struct atom_value *atomv, struct ref_formatting_state *state, - struct strbuf *unused_err) + struct strbuf *err UNUSED) { struct ref_formatting_stack *new_stack; struct if_then_else *if_then_else = xcalloc(1, @@ -915,7 +930,8 @@ static int is_empty(struct strbuf *buf) return cur == end; } -static int then_atom_handler(struct atom_value *atomv, struct ref_formatting_state *state, +static int then_atom_handler(struct atom_value *atomv UNUSED, + struct ref_formatting_state *state, struct strbuf *err) { struct ref_formatting_stack *cur = state->stack; @@ -952,7 +968,8 @@ static int then_atom_handler(struct atom_value *atomv, struct ref_formatting_sta return 0; } -static int else_atom_handler(struct atom_value *atomv, struct ref_formatting_state *state, +static int else_atom_handler(struct atom_value *atomv UNUSED, + struct ref_formatting_state *state, struct strbuf *err) { struct ref_formatting_stack *prev = state->stack; @@ -973,7 +990,8 @@ static int else_atom_handler(struct atom_value *atomv, struct ref_formatting_sta return 0; } -static int end_atom_handler(struct atom_value *atomv, struct ref_formatting_state *state, +static int end_atom_handler(struct atom_value *atomv UNUSED, + struct ref_formatting_state *state, struct strbuf *err) { struct ref_formatting_stack *current = state->stack; From d3dcfa047f415de5590b60781dcdf11492e25d41 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:39:15 -0500 Subject: [PATCH 035/508] mark "pointless" data pointers in callbacks Both the object_array_filter() and trie_find() functions use callback functions that let the caller specify which elements match. These callbacks take a void pointer in case the caller wants to pass in extra data. But in each case, the single user of these functions just passes NULL, and the callback ignores the extra pointer. We could just remove these unused parameters from the callback interface entirely. But it's good practice to provide such a pointer, as it guides future callers of the function in the right direction (rather than tempting them to access global data). Plus it's consistent with other generic callback interfaces. So let's instead annotate the unused parameters, in order to silence the compiler's -Wunused-parameter warning. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- path.c | 3 ++- revision.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/path.c b/path.c index 492e17ad12..0b641233e3 100644 --- a/path.c +++ b/path.c @@ -347,7 +347,8 @@ static void init_common_trie(void) * Helper function for update_common_dir: returns 1 if the dir * prefix is common. */ -static int check_common(const char *unmatched, void *value, void *baton) +static int check_common(const char *unmatched, void *value, + void *baton UNUSED) { struct common_dir *dir = value; diff --git a/revision.c b/revision.c index 21f5f572c2..4a24fc3fcd 100644 --- a/revision.c +++ b/revision.c @@ -4159,7 +4159,7 @@ static struct commit *get_revision_1(struct rev_info *revs) * Return true for entries that have not yet been shown. (This is an * object_array_each_func_t.) */ -static int entry_unshown(struct object_array_entry *entry, void *cb_data_unused) +static int entry_unshown(struct object_array_entry *entry, void *cb_data UNUSED) { return !(entry->item->flags & SHOWN); } From ce41759ed5edac9d30a73640b4fdd155c9f9fee0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:39:18 -0500 Subject: [PATCH 036/508] run-command: mark error routine parameters as unused After forking but before exec-ing a command, we install special error/warn/die handlers in the child. These ignore the error messages they get, since the idea is that they shouldn't be called in the first place. Arguably they could pass along that error message _in addition_ to saying "error() should not be called in a child", but since the whole point is to avoid any conflicts on stdio/malloc locks, etc, we're better to just keep these simple. Seeing them trigger is effectively a bug, and the developer is probably better off grabbing a stack trace. But we do want to mark the functions so that -Wunused-parameter doesn't complain. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- run-command.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/run-command.c b/run-command.c index 6bd16acb06..ba617655b2 100644 --- a/run-command.c +++ b/run-command.c @@ -341,19 +341,19 @@ static void child_close_pair(int fd[2]) child_close(fd[1]); } -static void child_error_fn(const char *err, va_list params) +static void child_error_fn(const char *err UNUSED, va_list params UNUSED) { const char msg[] = "error() should not be called in child\n"; xwrite(2, msg, sizeof(msg) - 1); } -static void child_warn_fn(const char *err, va_list params) +static void child_warn_fn(const char *err UNUSED, va_list params UNUSED) { const char msg[] = "warn() should not be called in child\n"; xwrite(2, msg, sizeof(msg) - 1); } -static void NORETURN child_die_fn(const char *err, va_list params) +static void NORETURN child_die_fn(const char *err UNUSED, va_list params UNUSED) { const char msg[] = "die() should not be called in child\n"; xwrite(2, msg, sizeof(msg) - 1); From 9ec03b59a8c4f5a0b4e666bd179a8eed71484825 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:39:20 -0500 Subject: [PATCH 037/508] mark unused parameters in signal handlers Signal handlers receive their signal number as a parameter, but many don't care what it is (because they only handle one signal, or because their action is the same regardless of the signal). Mark such parameters to silence -Wunused-parameter. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/fast-import.c | 2 +- builtin/log.c | 2 +- daemon.c | 2 +- progress.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 7134683ab9..4a8c835062 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -436,7 +436,7 @@ static void set_checkpoint_signal(void) #else -static void checkpoint_signal(int signo) +static void checkpoint_signal(int signo UNUSED) { checkpoint_requested = 1; } diff --git a/builtin/log.c b/builtin/log.c index 04412dd9c9..813b768e24 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -436,7 +436,7 @@ static void log_show_early(struct rev_info *revs, struct commit_list *list) setitimer(ITIMER_REAL, &early_output_timer, NULL); } -static void early_output(int signal) +static void early_output(int signal UNUSED) { show_early_output = log_show_early; } diff --git a/daemon.c b/daemon.c index 0ae7d12b5c..06d5bc6931 100644 --- a/daemon.c +++ b/daemon.c @@ -928,7 +928,7 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen) add_child(&cld, addr, addrlen); } -static void child_handler(int signo) +static void child_handler(int signo UNUSED) { /* * Otherwise empty handler because systemcalls will get interrupted diff --git a/progress.c b/progress.c index 0cdd875d37..9b33a2df32 100644 --- a/progress.c +++ b/progress.c @@ -59,7 +59,7 @@ void progress_test_force_update(void) } -static void progress_interval(int signum) +static void progress_interval(int signum UNUSED) { progress_update = 1; } From c50dca2a18077306eb6796938d3d01c76590b4c6 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:39:22 -0500 Subject: [PATCH 038/508] list-objects: mark unused callback parameters Our graph-traversal functions take callbacks for showing commits and objects, but not all callbacks need each parameter. Likewise for the similar traverse_bitmap_commit_list(), which has a different interface but serves the same purpose. And the include_check mechanism, which passes along a void pointer which is not always used. Mark the unused ones to to make -Wunused-parameter happy. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/pack-objects.c | 11 ++++++----- builtin/rev-list.c | 10 +++++----- pack-bitmap.c | 6 ++++-- reachable.c | 12 +++++++----- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 74a167a180..fb92a9686b 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1590,7 +1590,7 @@ static int add_object_entry(const struct object_id *oid, enum object_type type, static int add_object_entry_from_bitmap(const struct object_id *oid, enum object_type type, - int flags, uint32_t name_hash, + int flags UNUSED, uint32_t name_hash, struct packed_git *pack, off_t offset) { display_progress(progress_state, ++nr_seen); @@ -3464,7 +3464,7 @@ static void add_cruft_object_entry(const struct object_id *oid, enum object_type return; } -static void show_cruft_object(struct object *obj, const char *name, void *data) +static void show_cruft_object(struct object *obj, const char *name, void *data UNUSED) { /* * if we did not record it earlier, it's at least as old as our @@ -3484,7 +3484,7 @@ static void show_cruft_commit(struct commit *commit, void *data) show_cruft_object((struct object*)commit, NULL, data); } -static int cruft_include_check_obj(struct object *obj, void *data) +static int cruft_include_check_obj(struct object *obj, void *data UNUSED) { return !has_object_kept_pack(&obj->oid, IN_CORE_KEEP_PACKS); } @@ -3663,7 +3663,7 @@ static void read_object_list_from_stdin(void) } } -static void show_commit(struct commit *commit, void *data) +static void show_commit(struct commit *commit, void *data UNUSED) { add_object_entry(&commit->object.oid, OBJ_COMMIT, NULL, 0); @@ -3674,7 +3674,8 @@ static void show_commit(struct commit *commit, void *data) propagate_island_marks(commit); } -static void show_object(struct object *obj, const char *name, void *data) +static void show_object(struct object *obj, const char *name, + void *data UNUSED) { add_preferred_base_object(name); add_object_entry(&obj->oid, obj->type, name, 0); diff --git a/builtin/rev-list.c b/builtin/rev-list.c index d42db0b0cc..cceb5de975 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -362,11 +362,11 @@ static int show_bisect_vars(struct rev_list_info *info, int reaches, int all) static int show_object_fast( const struct object_id *oid, - enum object_type type, - int exclude, - uint32_t name_hash, - struct packed_git *found_pack, - off_t found_offset) + enum object_type type UNUSED, + int exclude UNUSED, + uint32_t name_hash UNUSED, + struct packed_git *found_pack UNUSED, + off_t found_offset UNUSED) { fprintf(stdout, "%s\n", oid_to_hex(oid)); return 1; diff --git a/pack-bitmap.c b/pack-bitmap.c index d2a42abf28..c8994a0f00 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -951,7 +951,8 @@ static void show_object(struct object *object, const char *name, void *data_) bitmap_set(data->base, bitmap_pos); } -static void show_commit(struct commit *commit, void *data) +static void show_commit(struct commit *commit UNUSED, + void *data UNUSED) { } @@ -1940,7 +1941,8 @@ static void test_bitmap_type(struct bitmap_test_data *tdata, type_name(bitmap_type)); } -static void test_show_object(struct object *object, const char *name, +static void test_show_object(struct object *object, + const char *name UNUSED, void *data) { struct bitmap_test_data *tdata = data; diff --git a/reachable.c b/reachable.c index aba63ebeb3..08f290c2be 100644 --- a/reachable.c +++ b/reachable.c @@ -48,7 +48,9 @@ static int add_one_ref(const char *path, const struct object_id *oid, * The traversal will have already marked us as SEEN, so we * only need to handle any progress reporting here. */ -static void mark_object(struct object *obj, const char *name, void *data) +static void mark_object(struct object *obj UNUSED, + const char *name UNUSED, + void *data) { update_progress(data); } @@ -202,10 +204,10 @@ int add_unseen_recent_objects_to_traversal(struct rev_info *revs, static int mark_object_seen(const struct object_id *oid, enum object_type type, - int exclude, - uint32_t name_hash, - struct packed_git *found_pack, - off_t found_offset) + int exclude UNUSED, + uint32_t name_hash UNUSED, + struct packed_git *found_pack UNUSED, + off_t found_offset UNUSED) { struct object *obj = lookup_object_by_type(the_repository, oid, type); if (!obj) From be252d3349f1a5fdf7aaf53390f3ce555b5de9d9 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:39:24 -0500 Subject: [PATCH 039/508] for_each_object: mark unused callback parameters The for_each_{loose,packed}_object interface uses callback functions, but not every callback needs all of the parameters. Mark the unused ones to satisfy -Wunused-parameter. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/cat-file.c | 8 ++++---- builtin/count-objects.c | 6 ++++-- builtin/fsck.c | 25 +++++++++++++------------ builtin/gc.c | 14 +++++++------- builtin/pack-objects.c | 15 ++++++++------- builtin/prune.c | 6 ++++-- builtin/repack.c | 5 +++-- builtin/rev-list.c | 3 ++- diagnose.c | 3 ++- midx.c | 2 +- object-file.c | 3 ++- packfile.c | 4 ++-- reachable.c | 3 ++- revision.c | 4 ++-- 14 files changed, 56 insertions(+), 45 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index cc17635e76..0dec21c107 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -559,7 +559,7 @@ static int batch_object_cb(const struct object_id *oid, void *vdata) } static int collect_loose_object(const struct object_id *oid, - const char *path, + const char *path UNUSED, void *data) { oid_array_append(data, oid); @@ -567,8 +567,8 @@ static int collect_loose_object(const struct object_id *oid, } static int collect_packed_object(const struct object_id *oid, - struct packed_git *pack, - uint32_t pos, + struct packed_git *pack UNUSED, + uint32_t pos UNUSED, void *data) { oid_array_append(data, oid); @@ -591,7 +591,7 @@ static int batch_unordered_object(const struct object_id *oid, } static int batch_unordered_loose(const struct object_id *oid, - const char *path, + const char *path UNUSED, void *data) { return batch_unordered_object(oid, NULL, 0, data); diff --git a/builtin/count-objects.c b/builtin/count-objects.c index 07b9419596..bb21bc43e4 100644 --- a/builtin/count-objects.c +++ b/builtin/count-objects.c @@ -57,7 +57,8 @@ static void loose_garbage(const char *path) report_garbage(PACKDIR_FILE_GARBAGE, path); } -static int count_loose(const struct object_id *oid, const char *path, void *data) +static int count_loose(const struct object_id *oid, const char *path, + void *data UNUSED) { struct stat st; @@ -72,7 +73,8 @@ static int count_loose(const struct object_id *oid, const char *path, void *data return 0; } -static int count_cruft(const char *basename, const char *path, void *data) +static int count_cruft(const char *basename UNUSED, const char *path, + void *data UNUSED) { loose_garbage(path); return 0; diff --git a/builtin/fsck.c b/builtin/fsck.c index d207bd909b..56aba054ed 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -233,17 +233,17 @@ static void mark_unreachable_referents(const struct object_id *oid) } static int mark_loose_unreachable_referents(const struct object_id *oid, - const char *path, - void *data) + const char *path UNUSED, + void *data UNUSED) { mark_unreachable_referents(oid); return 0; } static int mark_packed_unreachable_referents(const struct object_id *oid, - struct packed_git *pack, - uint32_t pos, - void *data) + struct packed_git *pack UNUSED, + uint32_t pos UNUSED, + void *data UNUSED) { mark_unreachable_referents(oid); return 0; @@ -661,14 +661,15 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data) return 0; /* keep checking other objects, even if we saw an error */ } -static int fsck_cruft(const char *basename, const char *path, void *data) +static int fsck_cruft(const char *basename, const char *path, + void *data UNUSED) { if (!starts_with(basename, "tmp_obj_")) fprintf_ln(stderr, _("bad sha1 file: %s"), path); return 0; } -static int fsck_subdir(unsigned int nr, const char *path, void *data) +static int fsck_subdir(unsigned int nr, const char *path UNUSED, void *data) { struct for_each_loose_cb *cb_data = data; struct progress *progress = cb_data->progress; @@ -803,17 +804,17 @@ static void mark_object_for_connectivity(const struct object_id *oid) } static int mark_loose_for_connectivity(const struct object_id *oid, - const char *path, - void *data) + const char *path UNUSED, + void *data UNUSED) { mark_object_for_connectivity(oid); return 0; } static int mark_packed_for_connectivity(const struct object_id *oid, - struct packed_git *pack, - uint32_t pos, - void *data) + struct packed_git *pack UNUSED, + uint32_t pos UNUSED, + void *data UNUSED) { mark_object_for_connectivity(oid); return 0; diff --git a/builtin/gc.c b/builtin/gc.c index 02455fdcd7..4486438624 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -976,9 +976,9 @@ struct write_loose_object_data { static int loose_object_auto_limit = 100; -static int loose_object_count(const struct object_id *oid, - const char *path, - void *data) +static int loose_object_count(const struct object_id *oid UNUSED, + const char *path UNUSED, + void *data) { int *count = (int*)data; if (++(*count) >= loose_object_auto_limit) @@ -1003,15 +1003,15 @@ static int loose_object_auto_condition(void) NULL, NULL, &count); } -static int bail_on_loose(const struct object_id *oid, - const char *path, - void *data) +static int bail_on_loose(const struct object_id *oid UNUSED, + const char *path UNUSED, + void *data UNUSED) { return 1; } static int write_loose_object_to_stdin(const struct object_id *oid, - const char *path, + const char *path UNUSED, void *data) { struct write_loose_object_data *d = (struct write_loose_object_data *)data; diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index fb92a9686b..d7eebeb6eb 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3260,13 +3260,14 @@ static int add_object_entry_from_pack(const struct object_id *oid, return 0; } -static void show_commit_pack_hint(struct commit *commit, void *_data) +static void show_commit_pack_hint(struct commit *commit UNUSED, + void *data UNUSED) { /* nothing to do; commits don't have a namehash */ } static void show_object_pack_hint(struct object *object, const char *name, - void *_data) + void *data UNUSED) { struct object_entry *oe = packlist_find(&to_pack, &object->oid); if (!oe) @@ -3762,7 +3763,7 @@ static void show_edge(struct commit *commit) static int add_object_in_unpacked_pack(const struct object_id *oid, struct packed_git *pack, uint32_t pos, - void *_data) + void *data UNUSED) { if (cruft) { off_t offset; @@ -3796,7 +3797,7 @@ static void add_objects_in_unpacked_packs(void) } static int add_loose_object(const struct object_id *oid, const char *path, - void *data) + void *data UNUSED) { enum object_type type = oid_object_info(the_repository, oid, NULL); @@ -3947,13 +3948,13 @@ static int get_object_list_from_bitmap(struct rev_info *revs) } static void record_recent_object(struct object *obj, - const char *name, - void *data) + const char *name UNUSED, + void *data UNUSED) { oid_array_append(&recent_objects, &obj->oid); } -static void record_recent_commit(struct commit *commit, void *data) +static void record_recent_commit(struct commit *commit, void *data UNUSED) { oid_array_append(&recent_objects, &commit->object.oid); } diff --git a/builtin/prune.c b/builtin/prune.c index 2719220108..4580890393 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -98,7 +98,8 @@ static int prune_object(const struct object_id *oid, const char *fullpath, return 0; } -static int prune_cruft(const char *basename, const char *path, void *data) +static int prune_cruft(const char *basename, const char *path, + void *data UNUSED) { if (starts_with(basename, "tmp_obj_")) prune_tmp_file(path); @@ -107,7 +108,8 @@ static int prune_cruft(const char *basename, const char *path, void *data) return 0; } -static int prune_subdir(unsigned int nr, const char *path, void *data) +static int prune_subdir(unsigned int nr UNUSED, const char *path, + void *data UNUSED) { if (!show_only) rmdir(path); diff --git a/builtin/repack.c b/builtin/repack.c index f649379531..36b511c564 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -182,8 +182,9 @@ static void prepare_pack_objects(struct child_process *cmd, * Write oid to the given struct child_process's stdin, starting it first if * necessary. */ -static int write_oid(const struct object_id *oid, struct packed_git *pack, - uint32_t pos, void *data) +static int write_oid(const struct object_id *oid, + struct packed_git *pack UNUSED, + uint32_t pos UNUSED, void *data) { struct child_process *cmd = data; diff --git a/builtin/rev-list.c b/builtin/rev-list.c index cceb5de975..888ad6b5c0 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -257,7 +257,8 @@ static inline void finish_object__ma(struct object *obj) } } -static int finish_object(struct object *obj, const char *name, void *cb_data) +static int finish_object(struct object *obj, const char *name UNUSED, + void *cb_data) { struct rev_list_info *info = cb_data; if (oid_object_info_extended(the_repository, &obj->oid, NULL, 0) < 0) { diff --git a/diagnose.c b/diagnose.c index 8f26569896..e7c42b3a71 100644 --- a/diagnose.c +++ b/diagnose.c @@ -43,7 +43,8 @@ int option_parse_diagnose(const struct option *opt, const char *arg, int unset) return error(_("invalid --%s value '%s'"), opt->long_name, arg); } -static void dir_file_stats_objects(const char *full_path, size_t full_path_len, +static void dir_file_stats_objects(const char *full_path, + size_t full_path_len UNUSED, const char *file_name, void *data) { struct strbuf *buf = data; diff --git a/midx.c b/midx.c index 7cfad04a24..d761cc50bd 100644 --- a/midx.c +++ b/midx.c @@ -1607,7 +1607,7 @@ struct clear_midx_data { const char *ext; }; -static void clear_midx_file_ext(const char *full_path, size_t full_path_len, +static void clear_midx_file_ext(const char *full_path, size_t full_path_len UNUSED, const char *file_name, void *_data) { struct clear_midx_data *data = _data; diff --git a/object-file.c b/object-file.c index 939865c1ae..389d452e48 100644 --- a/object-file.c +++ b/object-file.c @@ -2644,7 +2644,8 @@ int for_each_loose_object(each_loose_object_fn cb, void *data, return 0; } -static int append_loose_object(const struct object_id *oid, const char *path, +static int append_loose_object(const struct object_id *oid, + const char *path UNUSED, void *data) { oidtree_insert(data, oid); diff --git a/packfile.c b/packfile.c index 79e21ab18e..4dc0e15aa5 100644 --- a/packfile.c +++ b/packfile.c @@ -2204,8 +2204,8 @@ int for_each_packed_object(each_packed_object_fn cb, void *data, } static int add_promisor_object(const struct object_id *oid, - struct packed_git *pack, - uint32_t pos, + struct packed_git *pack UNUSED, + uint32_t pos UNUSED, void *set_) { struct oidset *set = set_; diff --git a/reachable.c b/reachable.c index 08f290c2be..0afe80c203 100644 --- a/reachable.c +++ b/reachable.c @@ -154,7 +154,8 @@ static int add_recent_loose(const struct object_id *oid, } static int add_recent_packed(const struct object_id *oid, - struct packed_git *p, uint32_t pos, + struct packed_git *p, + uint32_t pos, void *data) { struct object *obj; diff --git a/revision.c b/revision.c index 4a24fc3fcd..65fca1ed6c 100644 --- a/revision.c +++ b/revision.c @@ -3440,8 +3440,8 @@ void reset_revision_walk(void) } static int mark_uninteresting(const struct object_id *oid, - struct packed_git *pack, - uint32_t pos, + struct packed_git *pack UNUSED, + uint32_t pos UNUSED, void *cb) { struct rev_info *revs = cb; From 1758712248ab134a99cf73dcb62c115d955697d8 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:39:27 -0500 Subject: [PATCH 040/508] prio-queue: mark unused parameters in comparison functions The prio_queue_compare_fn interface has a void pointer to allow callers to pass arbitrary data, but most comparison functions don't need it. Mark those cases to make -Wunused-parameter happy. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- commit.c | 6 ++++-- negotiator/skipping.c | 2 +- t/helper/test-prio-queue.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/commit.c b/commit.c index e433c33bb0..0606d16e3a 100644 --- a/commit.c +++ b/commit.c @@ -801,7 +801,8 @@ int compare_commits_by_author_date(const void *a_, const void *b_, return 0; } -int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void *unused) +int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, + void *unused UNUSED) { const struct commit *a = a_, *b = b_; const timestamp_t generation_a = commit_graph_generation(a), @@ -821,7 +822,8 @@ int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void return 0; } -int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused) +int compare_commits_by_commit_date(const void *a_, const void *b_, + void *unused UNUSED) { const struct commit *a = a_, *b = b_; /* newer commits with larger date first */ diff --git a/negotiator/skipping.c b/negotiator/skipping.c index 0f5ac48e87..4867efc5f5 100644 --- a/negotiator/skipping.c +++ b/negotiator/skipping.c @@ -50,7 +50,7 @@ struct data { int non_common_revs; }; -static int compare(const void *a_, const void *b_, void *unused) +static int compare(const void *a_, const void *b_, void *data UNUSED) { const struct entry *a = a_; const struct entry *b = b_; diff --git a/t/helper/test-prio-queue.c b/t/helper/test-prio-queue.c index 133b5e6f4a..496c7be07d 100644 --- a/t/helper/test-prio-queue.c +++ b/t/helper/test-prio-queue.c @@ -2,7 +2,7 @@ #include "cache.h" #include "prio-queue.h" -static int intcmp(const void *va, const void *vb, void *data) +static int intcmp(const void *va, const void *vb, void *data UNUSED) { const int *a = va, *b = vb; return *a - *b; From 3c50c88f426dddd6c4cb1c1ae847a1eddd5eafee Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:39:31 -0500 Subject: [PATCH 041/508] notes: mark unused callback parameters for_each_note() requires a callback, but not all callbacks need all of the parameters. Likewise, init_notes() takes a callback to implement the "combine" strategy, but the "ignore" variant obviously doesn't look at its arguments at all. Mark unused parameters as appropriate to silence compiler warnings. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/notes.c | 5 +++-- notes.c | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/builtin/notes.c b/builtin/notes.c index 80d9dfd25c..d5713a9fac 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -113,8 +113,9 @@ static void free_note_data(struct note_data *d) } static int list_each_note(const struct object_id *object_oid, - const struct object_id *note_oid, char *note_path, - void *cb_data) + const struct object_id *note_oid, + char *note_path UNUSED, + void *cb_data UNUSED) { printf("%s %s\n", oid_to_hex(note_oid), oid_to_hex(object_oid)); return 0; diff --git a/notes.c b/notes.c index f2805d51bb..20af123d91 100644 --- a/notes.c +++ b/notes.c @@ -752,7 +752,7 @@ static int write_each_non_note_until(const char *note_path, return 0; } -static int write_each_note(const struct object_id *object_oid, +static int write_each_note(const struct object_id *object_oid UNUSED, const struct object_id *note_oid, char *note_path, void *cb_data) { @@ -780,8 +780,9 @@ struct note_delete_list { }; static int prune_notes_helper(const struct object_id *object_oid, - const struct object_id *note_oid, char *note_path, - void *cb_data) + const struct object_id *note_oid UNUSED, + char *note_path UNUSED, + void *cb_data) { struct note_delete_list **l = (struct note_delete_list **) cb_data; struct note_delete_list *n; @@ -848,8 +849,8 @@ int combine_notes_overwrite(struct object_id *cur_oid, return 0; } -int combine_notes_ignore(struct object_id *cur_oid, - const struct object_id *new_oid) +int combine_notes_ignore(struct object_id *cur_oid UNUSED, + const struct object_id *new_oid UNUSED) { return 0; } From 65daa9ba1c86052d7a889a407b95c3ffa61be47b Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:39:35 -0500 Subject: [PATCH 042/508] fetch-pack: mark unused parameter in callback function The for_each_cached_alternate() interface requires a callback that takes a negotiator parameter, but not all implementations need it. Mark the unused one as such to appease -Wunused-parameter. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- fetch-pack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fetch-pack.c b/fetch-pack.c index 04016d1e32..67a7786865 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -722,7 +722,7 @@ static void filter_refs(struct fetch_pack_args *args, *refs = newlist; } -static void mark_alternate_complete(struct fetch_negotiator *unused, +static void mark_alternate_complete(struct fetch_negotiator *negotiator UNUSED, struct object *obj) { mark_complete(&obj->oid); From c764e2806013e65c1ebee4b82afe3da1b55d3e51 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:39:37 -0500 Subject: [PATCH 043/508] rewrite_parents(): mark unused callback parameter The rewrite_parents() function takes a callback, but not every callback needs the "rev" parameter. Mark the unused one so -Wunused-parameter will be happy. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- line-log.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/line-log.c b/line-log.c index a7f3e7f6ce..1ab2d75f29 100644 --- a/line-log.c +++ b/line-log.c @@ -1281,7 +1281,8 @@ int line_log_process_ranges_arbitrary_commit(struct rev_info *rev, struct commit return changed; } -static enum rewrite_result line_log_rewrite_one(struct rev_info *rev, struct commit **pp) +static enum rewrite_result line_log_rewrite_one(struct rev_info *rev UNUSED, + struct commit **pp) { for (;;) { struct commit *p = *pp; From 43090008e365a5dfec5a167b5ab64b1f0c1345a6 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:39:40 -0500 Subject: [PATCH 044/508] for_each_commit_graft(): mark unused callback parameter The for_each_commit_graft() functions takes a callback, but not every callback uses the void data parameter. Mark the unused one to appease the -Wunused-parameter warning. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- log-tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/log-tree.c b/log-tree.c index 1dd5fcbf7b..0f08864ae8 100644 --- a/log-tree.c +++ b/log-tree.c @@ -196,7 +196,8 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid, return 0; } -static int add_graft_decoration(const struct commit_graft *graft, void *cb_data) +static int add_graft_decoration(const struct commit_graft *graft, + void *cb_data UNUSED) { struct commit *commit = lookup_commit(the_repository, &graft->oid); if (!commit) From 1bff855419b0cb338e7ef53b77f99207704bf63e Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:39:43 -0500 Subject: [PATCH 045/508] userformat_want_item(): mark unused parameter This function is used as a callback to strbuf_expand(), so it must conform to the correct interface. But naturally it doesn't need to touch its "sb" parameter, since it is only examining the placeholder string, and not actually writing any output. So mark the unused parameter to silence -Wunused-parameter. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- pretty.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pretty.c b/pretty.c index 1e1e21878c..2e47292407 100644 --- a/pretty.c +++ b/pretty.c @@ -1857,7 +1857,8 @@ static size_t format_commit_item(struct strbuf *sb, /* in UTF-8 */ return consumed + 1; } -static size_t userformat_want_item(struct strbuf *sb, const char *placeholder, +static size_t userformat_want_item(struct strbuf *sb UNUSED, + const char *placeholder, void *context) { struct userformat_want *w = context; From a5c76b3698f3672afecd65eed233b095123ae1d6 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:39:46 -0500 Subject: [PATCH 046/508] run_processes_parallel: mark unused callback parameters Our parallel process API takes several callbacks via function pointers in the run_process_paralell_opts struct. Not every callback needs every parameter; let's mark the unused ones to make -Wunused-parameter happy. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/fetch.c | 6 ++++-- builtin/submodule--helper.c | 4 ++-- hook.c | 12 ++++++------ submodule.c | 4 ++-- t/helper/test-run-command.c | 14 +++++++------- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index a21ce89312..c6b1845429 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1890,7 +1890,8 @@ struct parallel_fetch_state { int next, result; }; -static int fetch_next_remote(struct child_process *cp, struct strbuf *out, +static int fetch_next_remote(struct child_process *cp, + struct strbuf *out UNUSED, void *cb, void **task_cb) { struct parallel_fetch_state *state = cb; @@ -1912,7 +1913,8 @@ static int fetch_next_remote(struct child_process *cp, struct strbuf *out, return 1; } -static int fetch_failed_to_start(struct strbuf *out, void *cb, void *task_cb) +static int fetch_failed_to_start(struct strbuf *out UNUSED, + void *cb, void *task_cb) { struct parallel_fetch_state *state = cb; const char *remote = task_cb; diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 4c173d8b37..ad272a0d93 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2132,9 +2132,9 @@ static int update_clone_get_next_task(struct child_process *child, return 0; } -static int update_clone_start_failure(struct strbuf *err, +static int update_clone_start_failure(struct strbuf *err UNUSED, void *suc_cb, - void *idx_task_cb) + void *idx_task_cb UNUSED) { struct submodule_update_clone *suc = suc_cb; diff --git a/hook.c b/hook.c index 1a84831863..866ef0408b 100644 --- a/hook.c +++ b/hook.c @@ -43,9 +43,9 @@ int hook_exists(const char *name) } static int pick_next_hook(struct child_process *cp, - struct strbuf *out, + struct strbuf *out UNUSED, void *pp_cb, - void **pp_task_cb) + void **pp_task_cb UNUSED) { struct hook_cb_data *hook_cb = pp_cb; const char *hook_path = hook_cb->hook_path; @@ -77,9 +77,9 @@ static int pick_next_hook(struct child_process *cp, return 1; } -static int notify_start_failure(struct strbuf *out, +static int notify_start_failure(struct strbuf *out UNUSED, void *pp_cb, - void *pp_task_cp) + void *pp_task_cp UNUSED) { struct hook_cb_data *hook_cb = pp_cb; @@ -89,9 +89,9 @@ static int notify_start_failure(struct strbuf *out, } static int notify_hook_finished(int result, - struct strbuf *out, + struct strbuf *out UNUSED, void *pp_cb, - void *pp_task_cb) + void *pp_task_cb UNUSED) { struct hook_cb_data *hook_cb = pp_cb; struct run_hooks_opt *opt = hook_cb->options; diff --git a/submodule.c b/submodule.c index 3a0dfc417c..a24269db71 100644 --- a/submodule.c +++ b/submodule.c @@ -1739,7 +1739,7 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err, return 0; } -static int fetch_start_failure(struct strbuf *err, +static int fetch_start_failure(struct strbuf *err UNUSED, void *cb, void *task_cb) { struct submodule_parallel_fetch *spf = cb; @@ -1760,7 +1760,7 @@ static int commit_missing_in_sub(const struct object_id *oid, void *data) return type != OBJ_COMMIT; } -static int fetch_finish(int retvalue, struct strbuf *err, +static int fetch_finish(int retvalue, struct strbuf *err UNUSED, void *cb, void *task_cb) { struct submodule_parallel_fetch *spf = cb; diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c index 3ecb830f4a..98fa224640 100644 --- a/t/helper/test-run-command.c +++ b/t/helper/test-run-command.c @@ -24,7 +24,7 @@ static int number_callbacks; static int parallel_next(struct child_process *cp, struct strbuf *err, void *cb, - void **task_cb) + void **task_cb UNUSED) { struct child_process *d = cb; if (number_callbacks >= 4) @@ -40,10 +40,10 @@ static int parallel_next(struct child_process *cp, return 1; } -static int no_job(struct child_process *cp, +static int no_job(struct child_process *cp UNUSED, struct strbuf *err, - void *cb, - void **task_cb) + void *cb UNUSED, + void **task_cb UNUSED) { if (err) strbuf_addstr(err, "no further jobs available\n"); @@ -52,10 +52,10 @@ static int no_job(struct child_process *cp, return 0; } -static int task_finished(int result, +static int task_finished(int result UNUSED, struct strbuf *err, - void *pp_cb, - void *pp_task_cb) + void *pp_cb UNUSED, + void *pp_task_cb UNUSED) { if (err) strbuf_addstr(err, "asking for a quick stop\n"); From 506ebaac96b7d9a42853c16d0523fd493b7991da Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 01:39:48 -0500 Subject: [PATCH 047/508] help: mark unused parameter in git_unknown_cmd_config() The extra callback parameter became unused in 0918d08887 (help.c: fix autocorrect in work tree for bare repository, 2022-10-29), but we can't get rid of it because we must conform to the config callback interface. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- help.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/help.c b/help.c index 812af4cdea..8393c25586 100644 --- a/help.c +++ b/help.c @@ -540,7 +540,8 @@ static struct cmdnames aliases; #define AUTOCORRECT_NEVER (-2) #define AUTOCORRECT_IMMEDIATELY (-1) -static int git_unknown_cmd_config(const char *var, const char *value, void *cb) +static int git_unknown_cmd_config(const char *var, const char *value, + void *cb UNUSED) { const char *p; From 8840069a37e69129ed3c2792ddb172557f98e205 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 03:07:32 -0500 Subject: [PATCH 048/508] fsck: factor out index fsck The code to fsck an index operates directly on the_index. Let's move it into its own function in preparation for handling the index files from other worktrees. Since we now have only a single reference to the_index, let's drop our USE_THE_INDEX_VARIABLE definition and just use the_repository.index directly. That's a minor cleanup, but also ensures that we didn't miss any references when moving the code into fsck_index(). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/fsck.c | 54 ++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index d207bd909b..fa101e0db2 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -1,4 +1,3 @@ -#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "cache.h" #include "repository.h" @@ -796,6 +795,35 @@ static int fsck_resolve_undo(struct index_state *istate) return 0; } +static void fsck_index(struct index_state *istate) +{ + unsigned int i; + + /* TODO: audit for interaction with sparse-index. */ + ensure_full_index(istate); + for (i = 0; i < istate->cache_nr; i++) { + unsigned int mode; + struct blob *blob; + struct object *obj; + + mode = istate->cache[i]->ce_mode; + if (S_ISGITLINK(mode)) + continue; + blob = lookup_blob(the_repository, + &istate->cache[i]->oid); + if (!blob) + continue; + obj = &blob->object; + obj->flags |= USED; + fsck_put_object_name(&fsck_walk_options, &obj->oid, + ":%s", istate->cache[i]->name); + mark_object_reachable(obj); + } + if (istate->cache_tree) + fsck_cache_tree(istate->cache_tree); + fsck_resolve_undo(istate); +} + static void mark_object_for_connectivity(const struct object_id *oid) { struct object *obj = lookup_unknown_object(the_repository, oid); @@ -959,29 +987,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) verify_index_checksum = 1; verify_ce_order = 1; repo_read_index(the_repository); - /* TODO: audit for interaction with sparse-index. */ - ensure_full_index(&the_index); - for (i = 0; i < the_index.cache_nr; i++) { - unsigned int mode; - struct blob *blob; - struct object *obj; - - mode = the_index.cache[i]->ce_mode; - if (S_ISGITLINK(mode)) - continue; - blob = lookup_blob(the_repository, - &the_index.cache[i]->oid); - if (!blob) - continue; - obj = &blob->object; - obj->flags |= USED; - fsck_put_object_name(&fsck_walk_options, &obj->oid, - ":%s", the_index.cache[i]->name); - mark_object_reachable(obj); - } - if (the_index.cache_tree) - fsck_cache_tree(the_index.cache_tree); - fsck_resolve_undo(&the_index); + fsck_index(the_repository->index); } check_connectivity(); From fb64ca526a7c695aa137c2d2577585ddea5cce28 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 03:09:57 -0500 Subject: [PATCH 049/508] fsck: check index files in all worktrees We check the index file for the main worktree, but completely ignore the index files in other worktrees. These should be checked, too, as they are part of the repository state (and in particular, errors in those index files may cause repo-wide operations like "git gc" to complain). Reported-by: Johannes Sixt Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/fsck.c | 18 ++++++++++++++++-- t/t1450-fsck.sh | 12 ++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index fa101e0db2..c11cb2a95f 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -984,10 +984,24 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) } if (keep_cache_objects) { + struct worktree **worktrees, **p; + verify_index_checksum = 1; verify_ce_order = 1; - repo_read_index(the_repository); - fsck_index(the_repository->index); + + worktrees = get_worktrees(); + for (p = worktrees; *p; p++) { + struct worktree *wt = *p; + struct index_state istate = + INDEX_STATE_INIT(the_repository); + + if (read_index_from(&istate, + worktree_git_path(wt, "index"), + get_worktree_git_dir(wt)) > 0) + fsck_index(&istate); + discard_index(&istate); + } + free_worktrees(worktrees); } check_connectivity(); diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index de0f6d5e7f..e01a519a69 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -1023,4 +1023,16 @@ test_expect_success 'fsck error on gitattributes with excessive size' ' test_cmp expected actual ' +test_expect_success 'fsck detects problems in worktree index' ' + test_when_finished "git worktree remove -f wt" && + git worktree add wt && + + echo "this will be removed to break the worktree index" >wt/file && + git -C wt add file && + blob=$(git -C wt rev-parse :file) && + remove_object $blob && + + test_must_fail git fsck +' + test_done From 592ec63b38ca7e2fb069ce1bf41b47a6f5a4ef8a Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 24 Feb 2023 03:12:11 -0500 Subject: [PATCH 050/508] fsck: mention file path for index errors If we encounter an error in an index file, we may say something like: error: 1234abcd: invalid sha1 pointer in resolve-undo But if you have multiple worktrees, each with its own index, it can be very helpful to know which file had the problem. So let's pass that path down through the various index-fsck functions and use it where appropriate. After this patch you should get something like: error: 1234abcd: invalid sha1 pointer in resolve-undo of .git/worktrees/wt/index That's a bit verbose, but since the point is that you shouldn't see this normally, we're better to err on the side of more details. I've also added the index filename to the name used by "fsck --name-objects", which will show up if we find the object to be missing, etc. This is bending the rules a little there, as the option claims to write names that can be fed to rev-parse. But there is no revision syntax to access the index of another worktree, so the best we can do is make up something that a human will probably understand. I did take care to retain the existing ":file" syntax for the current worktree. So the uglier output should kick in only when it's actually necessary. See the included tests for examples of both forms. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/fsck.c | 42 +++++++++++++++++++++++++++--------------- t/t1450-fsck.sh | 20 +++++++++++++++++++- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index c11cb2a95f..1b032eebb1 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -731,19 +731,19 @@ static int fsck_head_link(const char *head_ref_name, return 0; } -static int fsck_cache_tree(struct cache_tree *it) +static int fsck_cache_tree(struct cache_tree *it, const char *index_path) { int i; int err = 0; if (verbose) - fprintf_ln(stderr, _("Checking cache tree")); + fprintf_ln(stderr, _("Checking cache tree of %s"), index_path); if (0 <= it->entry_count) { struct object *obj = parse_object(the_repository, &it->oid); if (!obj) { - error(_("%s: invalid sha1 pointer in cache-tree"), - oid_to_hex(&it->oid)); + error(_("%s: invalid sha1 pointer in cache-tree of %s"), + oid_to_hex(&it->oid), index_path); errors_found |= ERROR_REFS; return 1; } @@ -754,11 +754,12 @@ static int fsck_cache_tree(struct cache_tree *it) err |= objerror(obj, _("non-tree in cache-tree")); } for (i = 0; i < it->subtree_nr; i++) - err |= fsck_cache_tree(it->down[i]->cache_tree); + err |= fsck_cache_tree(it->down[i]->cache_tree, index_path); return err; } -static int fsck_resolve_undo(struct index_state *istate) +static int fsck_resolve_undo(struct index_state *istate, + const char *index_path) { struct string_list_item *item; struct string_list *resolve_undo = istate->resolve_undo; @@ -781,8 +782,9 @@ static int fsck_resolve_undo(struct index_state *istate) obj = parse_object(the_repository, &ru->oid[i]); if (!obj) { - error(_("%s: invalid sha1 pointer in resolve-undo"), - oid_to_hex(&ru->oid[i])); + error(_("%s: invalid sha1 pointer in resolve-undo of %s"), + oid_to_hex(&ru->oid[i]), + index_path); errors_found |= ERROR_REFS; continue; } @@ -795,7 +797,8 @@ static int fsck_resolve_undo(struct index_state *istate) return 0; } -static void fsck_index(struct index_state *istate) +static void fsck_index(struct index_state *istate, const char *index_path, + int is_main_index) { unsigned int i; @@ -816,12 +819,14 @@ static void fsck_index(struct index_state *istate) obj = &blob->object; obj->flags |= USED; fsck_put_object_name(&fsck_walk_options, &obj->oid, - ":%s", istate->cache[i]->name); + "%s:%s", + is_main_index ? "" : index_path, + istate->cache[i]->name); mark_object_reachable(obj); } if (istate->cache_tree) - fsck_cache_tree(istate->cache_tree); - fsck_resolve_undo(istate); + fsck_cache_tree(istate->cache_tree, index_path); + fsck_resolve_undo(istate, index_path); } static void mark_object_for_connectivity(const struct object_id *oid) @@ -994,12 +999,19 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) struct worktree *wt = *p; struct index_state istate = INDEX_STATE_INIT(the_repository); + char *path; - if (read_index_from(&istate, - worktree_git_path(wt, "index"), + /* + * Make a copy since the buffer is reusable + * and may get overwritten by other calls + * while we're examining the index. + */ + path = xstrdup(worktree_git_path(wt, "index")); + if (read_index_from(&istate, path, get_worktree_git_dir(wt)) > 0) - fsck_index(&istate); + fsck_index(&istate, path, wt->is_current); discard_index(&istate); + free(path); } free_worktrees(worktrees); } diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index e01a519a69..82c92de7ca 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -1032,7 +1032,25 @@ test_expect_success 'fsck detects problems in worktree index' ' blob=$(git -C wt rev-parse :file) && remove_object $blob && - test_must_fail git fsck + test_must_fail git fsck --name-objects >actual 2>&1 && + cat >expect <<-EOF && + missing blob $blob (.git/worktrees/wt/index:file) + EOF + test_cmp expect actual +' + +test_expect_success 'fsck reports problems in main index without filename' ' + test_when_finished "rm -f .git/index && git read-tree HEAD" && + echo "this object will be removed to break the main index" >file && + git add file && + blob=$(git rev-parse :file) && + remove_object $blob && + + test_must_fail git fsck --name-objects >actual 2>&1 && + cat >expect <<-EOF && + missing blob $blob (:file) + EOF + test_cmp expect actual ' test_done From 662078caacd450f93faa72e0e7d8580c42621415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Justo?= Date: Sat, 25 Feb 2023 15:21:51 +0100 Subject: [PATCH 051/508] worktree: introduce is_shared_symref() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a new function, is_shared_symref(), which contains the heart of find_shared_symref(). Refactor find_shared_symref() to use the new function is_shared_symref(). Soon, we will use is_shared_symref() to search for symref beyond the first worktree that matches. Signed-off-by: Rubén Justo Signed-off-by: Junio C Hamano --- worktree.c | 62 +++++++++++++++++++++++++++--------------------------- worktree.h | 6 ++++++ 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/worktree.c b/worktree.c index aa43c64119..40cb9874b7 100644 --- a/worktree.c +++ b/worktree.c @@ -403,44 +403,44 @@ int is_worktree_being_bisected(const struct worktree *wt, * bisect). New commands that do similar things should update this * function as well. */ +int is_shared_symref(const struct worktree *wt, const char *symref, + const char *target) +{ + const char *symref_target; + struct ref_store *refs; + int flags; + + if (wt->is_bare) + return 0; + + if (wt->is_detached && !strcmp(symref, "HEAD")) { + if (is_worktree_being_rebased(wt, target)) + return 1; + if (is_worktree_being_bisected(wt, target)) + return 1; + } + + refs = get_worktree_ref_store(wt); + symref_target = refs_resolve_ref_unsafe(refs, symref, 0, + NULL, &flags); + if ((flags & REF_ISSYMREF) && + symref_target && !strcmp(symref_target, target)) + return 1; + + return 0; +} + const struct worktree *find_shared_symref(struct worktree **worktrees, const char *symref, const char *target) { - const struct worktree *existing = NULL; - int i = 0; - for (i = 0; worktrees[i]; i++) { - struct worktree *wt = worktrees[i]; - const char *symref_target; - struct ref_store *refs; - int flags; - - if (wt->is_bare) - continue; - - if (wt->is_detached && !strcmp(symref, "HEAD")) { - if (is_worktree_being_rebased(wt, target)) { - existing = wt; - break; - } - if (is_worktree_being_bisected(wt, target)) { - existing = wt; - break; - } - } - - refs = get_worktree_ref_store(wt); - symref_target = refs_resolve_ref_unsafe(refs, symref, 0, - NULL, &flags); - if ((flags & REF_ISSYMREF) && - symref_target && !strcmp(symref_target, target)) { - existing = wt; - break; - } + for (int i = 0; worktrees[i]; i++) { + if (is_shared_symref(worktrees[i], symref, target)) + return worktrees[i]; } - return existing; + return NULL; } int submodule_uses_worktrees(const char *path) diff --git a/worktree.h b/worktree.h index 9dcea6fc8c..7889c4761d 100644 --- a/worktree.h +++ b/worktree.h @@ -149,6 +149,12 @@ const struct worktree *find_shared_symref(struct worktree **worktrees, const char *symref, const char *target); +/* + * Returns true if a symref points to a ref in a worktree. + */ +int is_shared_symref(const struct worktree *wt, + const char *symref, const char *target); + /* * Similar to head_ref() for all HEADs _except_ one from the current * worktree, which is covered by head_ref(). From faa4d5983bc1739351f49269660285a2628a3d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Justo?= Date: Sat, 25 Feb 2023 15:22:02 +0100 Subject: [PATCH 052/508] branch: fix die_if_checked_out() when ignore_current_worktree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In 8d9fdd7 (worktree.c: check whether branch is rebased in another worktree, 2016-04-22) die_if_checked_out() learned a new option ignore_current_worktree, to modify the operation from "die() if the branch is checked out in any worktree" to "die() if the branch is checked out in any worktree other than the current one". Unfortunately we implemented it by checking the flag is_current in the worktree that find_shared_symref() returns. When the same branch is checked out in several worktrees simultaneously, find_shared_symref() will return the first matching worktree in the list composed by get_worktrees(). If one of the worktrees with the checked out branch is the current worktree, find_shared_symref() may or may not return it, depending on the order in the list. Instead of find_shared_symref(), let's do the search using use the recently introduced API is_shared_symref(), and consider ignore_current_worktree when necessary. Signed-off-by: Rubén Justo Signed-off-by: Junio C Hamano --- branch.c | 14 +++++++++----- worktree.c | 3 +-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/branch.c b/branch.c index d182756827..e04710b2b5 100644 --- a/branch.c +++ b/branch.c @@ -820,12 +820,16 @@ void remove_branch_state(struct repository *r, int verbose) void die_if_checked_out(const char *branch, int ignore_current_worktree) { struct worktree **worktrees = get_worktrees(); - const struct worktree *wt; - wt = find_shared_symref(worktrees, "HEAD", branch); - if (wt && (!ignore_current_worktree || !wt->is_current)) { - skip_prefix(branch, "refs/heads/", &branch); - die(_("'%s' is already checked out at '%s'"), branch, wt->path); + for (int i = 0; worktrees[i]; i++) { + if (worktrees[i]->is_current && ignore_current_worktree) + continue; + + if (is_shared_symref(worktrees[i], "HEAD", branch)) { + skip_prefix(branch, "refs/heads/", &branch); + die(_("'%s' is already checked out at '%s'"), + branch, worktrees[i]->path); + } } free_worktrees(worktrees); diff --git a/worktree.c b/worktree.c index 40cb9874b7..34043d8fe0 100644 --- a/worktree.c +++ b/worktree.c @@ -435,10 +435,9 @@ const struct worktree *find_shared_symref(struct worktree **worktrees, const char *target) { - for (int i = 0; worktrees[i]; i++) { + for (int i = 0; worktrees[i]; i++) if (is_shared_symref(worktrees[i], symref, target)) return worktrees[i]; - } return NULL; } From 279f42fa27b4ffd0b3ac7c9378043eeb413f0f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Justo?= Date: Sat, 25 Feb 2023 15:22:13 +0100 Subject: [PATCH 053/508] rebase: refuse to switch to a branch already checked out elsewhere (test) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In b5cabb4a9 (rebase: refuse to switch to branch already checked out elsewhere, 2020-02-23) we add a condition to prevent a rebase operation involving a switch to a branch that is already checked out in another worktree. A bug has recently been fixed that caused this to not work as expected. Let's add a test to notice if this changes in the future. Signed-off-by: Rubén Justo Signed-off-by: Junio C Hamano --- t/t3400-rebase.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index d5a8ee39fc..3ce918fdb8 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -388,6 +388,20 @@ test_expect_success 'switch to branch checked out here' ' git rebase main main ' +test_expect_success 'switch to branch checked out elsewhere fails' ' + test_when_finished " + git worktree remove wt1 && + git worktree remove wt2 && + git branch -d shared + " && + git worktree add wt1 -b shared && + git worktree add wt2 -f shared && + # we test in both worktrees to ensure that works + # as expected with "first" and "next" worktrees + test_must_fail git -C wt1 rebase shared shared && + test_must_fail git -C wt2 rebase shared shared +' + test_expect_success 'switch to branch not checked out' ' git checkout main && git branch other && From 894ea945095b74542c6c4f4aefbe20f5b68be437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Justo?= Date: Sat, 25 Feb 2023 15:22:23 +0100 Subject: [PATCH 054/508] switch: reject if the branch is already checked out elsewhere (test) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since 5883034 (checkout: reject if the branch is already checked out elsewhere) in normal use, we do not allow multiple worktrees having the same checked out branch. A bug has recently been fixed that caused this to not work as expected. Let's add a test to notice if this changes in the future. Signed-off-by: Rubén Justo Signed-off-by: Junio C Hamano --- t/t2060-switch.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/t/t2060-switch.sh b/t/t2060-switch.sh index 5a7caf958c..e247a4735b 100755 --- a/t/t2060-switch.sh +++ b/t/t2060-switch.sh @@ -146,4 +146,33 @@ test_expect_success 'tracking info copied with autoSetupMerge=inherit' ' test_cmp_config "" --default "" branch.main2.merge ' +test_expect_success 'switch back when temporarily detached and checked out elsewhere ' ' + test_when_finished " + git worktree remove wt1 ||: + git worktree remove wt2 ||: + git checkout - ||: + git branch -D shared ||: + " && + git checkout -b shared && + test_commit shared-first && + HASH1=$(git rev-parse --verify HEAD) && + test_commit shared-second && + test_commit shared-third && + HASH2=$(git rev-parse --verify HEAD) && + git worktree add wt1 -f shared && + git -C wt1 bisect start && + git -C wt1 bisect good $HASH1 && + git -C wt1 bisect bad $HASH2 && + git worktree add wt2 -f shared && + git -C wt2 bisect start && + git -C wt2 bisect good $HASH1 && + git -C wt2 bisect bad $HASH2 && + # we test in both worktrees to ensure that works + # as expected with "first" and "next" worktrees + test_must_fail git -C wt1 switch shared && + git -C wt1 switch --ignore-other-worktrees shared && + test_must_fail git -C wt2 switch shared && + git -C wt2 switch --ignore-other-worktrees shared +' + test_done From 8d3e7eac529b42319622692028b45670bdff8835 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 26 Feb 2023 17:29:43 -0500 Subject: [PATCH 055/508] fsck: check even zero-entry index files In fb64ca526a (fsck: check index files in all worktrees, 2023-02-24), we swapped out a call to vanilla repo_read_index() for a series of read_index_from() calls, one per worktree. The code for the latter was copied from add_index_objects_to_pending(), which checks for a positive return value from the index reading function, and we do the same here in fsck now. But this is probably the wrong thing. I had interpreted the check as "don't operate on the index struct if there was an error". But in reality, if there is an error then the index-reading code will simply die (which admittedly is not great for fsck, but that is not a new problem). The return value here is actually the number of entries read. So it makes sense for add_index_objects_to_pending() to ignore a zero-entry index (there is nothing to add). But for fsck, we would still want to check any extensions, etc (though presumably it is unlikely to have them in an empty index, I don't think it's impossible). So we should ignore the return value from read_index_from() entirely. This matches the behavior before fb64ca526a, when we ignored the return value from repo_read_index(). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/fsck.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 1b032eebb1..64614b43b2 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -1007,9 +1007,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) * while we're examining the index. */ path = xstrdup(worktree_git_path(wt, "index")); - if (read_index_from(&istate, path, - get_worktree_git_dir(wt)) > 0) - fsck_index(&istate, path, wt->is_current); + read_index_from(&istate, path, get_worktree_git_dir(wt)); + fsck_index(&istate, path, wt->is_current); discard_index(&istate); free(path); } From cc5d1d32fd489f7eb98f762de303b499f2117638 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 26 Feb 2023 17:40:46 -0500 Subject: [PATCH 056/508] drop pure pass-through config callbacks Commit fd2d4c135e (gpg-interface: lazily initialize and read the configuration, 2023-02-09) shrunk a few custom config callbacks so that they are just one-liners of: return git_default_config(...); We can drop them entirely and replace them direct calls of git_default_config() intead. This makes the code a little shorter and easier to understand (with the downside being that if they do grow custom options again later, we'll have to recreate the functions). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/am.c | 7 +------ builtin/commit-tree.c | 7 +------ builtin/verify-commit.c | 7 +------ builtin/verify-tag.c | 7 +------ 4 files changed, 4 insertions(+), 24 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 40126b59c5..fccf40f8ee 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -2312,11 +2312,6 @@ static int parse_opt_show_current_patch(const struct option *opt, const char *ar return 0; } -static int git_am_config(const char *k, const char *v, void *cb UNUSED) -{ - return git_default_config(k, v, NULL); -} - int cmd_am(int argc, const char **argv, const char *prefix) { struct am_state state; @@ -2440,7 +2435,7 @@ int cmd_am(int argc, const char **argv, const char *prefix) if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(usage, options); - git_config(git_am_config, NULL); + git_config(git_default_config, NULL); am_state_init(&state); diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index f6a099d601..c0bbe9373d 100644 --- a/builtin/commit-tree.c +++ b/builtin/commit-tree.c @@ -37,11 +37,6 @@ static void new_parent(struct commit *parent, struct commit_list **parents_p) commit_list_insert(parent, parents_p); } -static int commit_tree_config(const char *var, const char *value, void *cb) -{ - return git_default_config(var, value, cb); -} - static int parse_parent_arg_callback(const struct option *opt, const char *arg, int unset) { @@ -118,7 +113,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix) OPT_END() }; - git_config(commit_tree_config, NULL); + git_config(git_default_config, NULL); if (argc < 2 || !strcmp(argv[1], "-h")) usage_with_options(commit_tree_usage, options); diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c index 3c5d0b024c..7aedf10e85 100644 --- a/builtin/verify-commit.c +++ b/builtin/verify-commit.c @@ -52,11 +52,6 @@ static int verify_commit(const char *name, unsigned flags) return run_gpg_verify((struct commit *)obj, flags); } -static int git_verify_commit_config(const char *var, const char *value, void *cb) -{ - return git_default_config(var, value, cb); -} - int cmd_verify_commit(int argc, const char **argv, const char *prefix) { int i = 1, verbose = 0, had_error = 0; @@ -67,7 +62,7 @@ int cmd_verify_commit(int argc, const char **argv, const char *prefix) OPT_END() }; - git_config(git_verify_commit_config, NULL); + git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, verify_commit_options, verify_commit_usage, PARSE_OPT_KEEP_ARGV0); diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c index ecffb069bf..5c00b0b0f7 100644 --- a/builtin/verify-tag.c +++ b/builtin/verify-tag.c @@ -19,11 +19,6 @@ static const char * const verify_tag_usage[] = { NULL }; -static int git_verify_tag_config(const char *var, const char *value, void *cb) -{ - return git_default_config(var, value, cb); -} - int cmd_verify_tag(int argc, const char **argv, const char *prefix) { int i = 1, verbose = 0, had_error = 0; @@ -36,7 +31,7 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix) OPT_END() }; - git_config(git_verify_tag_config, NULL); + git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, verify_tag_options, verify_tag_usage, PARSE_OPT_KEEP_ARGV0); From 24a49cf78eef2a13bc3f7c730e236d58b5e2ebbe Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 27 Feb 2023 15:28:08 +0000 Subject: [PATCH 057/508] t2021: fix platform-specific leftover cruft t2021.6 existed to test the status of a symlink that was left around by previous tests. It tried to also clean up the symlink after it was done so that subsequent tests wouldn't be tripped up by it. Unfortunately, since this test had a SYMLINK prerequisite, that made the cleanup platform dependent...and made a testcase I was trying to add to this testsuite fail (that testcase will be included in the next patch). Before we go and add new testcases, fix this cleanup by moving it into a separate test. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- t/t2021-checkout-overwrite.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/t/t2021-checkout-overwrite.sh b/t/t2021-checkout-overwrite.sh index 713c3fa603..baca66e1a3 100755 --- a/t/t2021-checkout-overwrite.sh +++ b/t/t2021-checkout-overwrite.sh @@ -50,10 +50,13 @@ test_expect_success 'checkout commit with dir must not remove untracked a/b' ' test_expect_success SYMLINKS 'the symlink remained' ' - test_when_finished "rm a/b" && test -h a/b ' +test_expect_success 'cleanup after previous symlink tests' ' + rm a/b +' + test_expect_success SYMLINKS 'checkout -f must not follow symlinks when removing entries' ' git checkout -f start && mkdir dir && From b413a827126abd54fa95470be7c63fa4f00d5d47 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 27 Feb 2023 15:28:09 +0000 Subject: [PATCH 058/508] unpack-trees: heed requests to overwrite ignored files When a directory exists but has only ignored files within it and we are trying to switch to a branch that has a file where that directory is, the behavior depends upon --[no]-overwrite-ignore. If the user wants to --overwrite-ignore (the default), then we should delete the ignored file and directory and switch to the new branch. The code to handle this in verify_clean_subdirectory() in unpack-trees tried to handle this via paying attention to the exclude_per_dir setting of the internal dir field. This came from commit c81935348b ("Fix switching to a branch with D/F when current branch has file D.", 2007-03-15), which pre-dated 039bc64e88 ("core.excludesfile clean-up", 2007-11-14), and thus did not pay attention to ignore patterns from other relevant files. Change it to use setup_standard_excludes() so that it is also aware of excludes specified in other locations. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- t/t2021-checkout-overwrite.sh | 11 +++++++++++ unpack-trees.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/t/t2021-checkout-overwrite.sh b/t/t2021-checkout-overwrite.sh index baca66e1a3..034f62c13c 100755 --- a/t/t2021-checkout-overwrite.sh +++ b/t/t2021-checkout-overwrite.sh @@ -69,4 +69,15 @@ test_expect_success SYMLINKS 'checkout -f must not follow symlinks when removing test_path_is_file untracked/f ' +test_expect_success 'checkout --overwrite-ignore should succeed if only ignored files in the way' ' + git checkout -b df_conflict && + test_commit contents some_dir && + git checkout start && + mkdir some_dir && + echo autogenerated information >some_dir/ignore && + echo ignore >.git/info/exclude && + git checkout --overwrite-ignore df_conflict && + ! test_path_is_dir some_dir +' + test_done diff --git a/unpack-trees.c b/unpack-trees.c index 3d05e45a27..4518d33ed9 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -2337,7 +2337,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce, memset(&d, 0, sizeof(d)); if (o->dir) - d.exclude_per_dir = o->dir->exclude_per_dir; + setup_standard_excludes(&d); i = read_directory(&d, o->src_index, pathbuf, namelen+1, NULL); dir_clear(&d); free(pathbuf); From 5fdf285e6254fff4d9560f72878456f0a53e2e38 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 27 Feb 2023 15:28:10 +0000 Subject: [PATCH 059/508] dir: separate public from internal portion of dir_struct In order to make it clearer to callers what portions of dir_struct are public API, and avoid errors from them setting fields that are meant as internal API, split the fields used for internal implementation reasons into a separate embedded struct. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- dir.c | 114 +++++++++++++++++++++++++++++----------------------------- dir.h | 82 ++++++++++++++++++++++-------------------- 2 files changed, 102 insertions(+), 94 deletions(-) diff --git a/dir.c b/dir.c index 4e99f0c868..7adf242026 100644 --- a/dir.c +++ b/dir.c @@ -1190,7 +1190,7 @@ struct pattern_list *add_pattern_list(struct dir_struct *dir, struct pattern_list *pl; struct exclude_list_group *group; - group = &dir->exclude_list_group[group_type]; + group = &dir->internal.exclude_list_group[group_type]; ALLOC_GROW(group->pl, group->nr + 1, group->alloc); pl = &group->pl[group->nr++]; memset(pl, 0, sizeof(*pl)); @@ -1211,7 +1211,7 @@ static void add_patterns_from_file_1(struct dir_struct *dir, const char *fname, * differently when dir->untracked is non-NULL. */ if (!dir->untracked) - dir->unmanaged_exclude_files++; + dir->internal.unmanaged_exclude_files++; pl = add_pattern_list(dir, EXC_FILE, fname); if (add_patterns(fname, "", 0, pl, NULL, 0, oid_stat) < 0) die(_("cannot use %s as an exclude file"), fname); @@ -1219,7 +1219,7 @@ static void add_patterns_from_file_1(struct dir_struct *dir, const char *fname, void add_patterns_from_file(struct dir_struct *dir, const char *fname) { - dir->unmanaged_exclude_files++; /* see validate_untracked_cache() */ + dir->internal.unmanaged_exclude_files++; /* see validate_untracked_cache() */ add_patterns_from_file_1(dir, fname, NULL); } @@ -1519,7 +1519,7 @@ static struct path_pattern *last_matching_pattern_from_lists( struct exclude_list_group *group; struct path_pattern *pattern; for (i = EXC_CMDL; i <= EXC_FILE; i++) { - group = &dir->exclude_list_group[i]; + group = &dir->internal.exclude_list_group[i]; for (j = group->nr - 1; j >= 0; j--) { pattern = last_matching_pattern_from_list( pathname, pathlen, basename, dtype_p, @@ -1545,20 +1545,20 @@ static void prep_exclude(struct dir_struct *dir, struct untracked_cache_dir *untracked; int current; - group = &dir->exclude_list_group[EXC_DIRS]; + group = &dir->internal.exclude_list_group[EXC_DIRS]; /* * Pop the exclude lists from the EXCL_DIRS exclude_list_group * which originate from directories not in the prefix of the * path being checked. */ - while ((stk = dir->exclude_stack) != NULL) { + while ((stk = dir->internal.exclude_stack) != NULL) { if (stk->baselen <= baselen && - !strncmp(dir->basebuf.buf, base, stk->baselen)) + !strncmp(dir->internal.basebuf.buf, base, stk->baselen)) break; - pl = &group->pl[dir->exclude_stack->exclude_ix]; - dir->exclude_stack = stk->prev; - dir->pattern = NULL; + pl = &group->pl[dir->internal.exclude_stack->exclude_ix]; + dir->internal.exclude_stack = stk->prev; + dir->internal.pattern = NULL; free((char *)pl->src); /* see strbuf_detach() below */ clear_pattern_list(pl); free(stk); @@ -1566,7 +1566,7 @@ static void prep_exclude(struct dir_struct *dir, } /* Skip traversing into sub directories if the parent is excluded */ - if (dir->pattern) + if (dir->internal.pattern) return; /* @@ -1574,12 +1574,12 @@ static void prep_exclude(struct dir_struct *dir, * memset(dir, 0, sizeof(*dir)) before use. Changing all of * them seems lots of work for little benefit. */ - if (!dir->basebuf.buf) - strbuf_init(&dir->basebuf, PATH_MAX); + if (!dir->internal.basebuf.buf) + strbuf_init(&dir->internal.basebuf, PATH_MAX); /* Read from the parent directories and push them down. */ current = stk ? stk->baselen : -1; - strbuf_setlen(&dir->basebuf, current < 0 ? 0 : current); + strbuf_setlen(&dir->internal.basebuf, current < 0 ? 0 : current); if (dir->untracked) untracked = stk ? stk->ucd : dir->untracked->root; else @@ -1599,32 +1599,33 @@ static void prep_exclude(struct dir_struct *dir, die("oops in prep_exclude"); cp++; untracked = - lookup_untracked(dir->untracked, untracked, + lookup_untracked(dir->untracked, + untracked, base + current, cp - base - current); } - stk->prev = dir->exclude_stack; + stk->prev = dir->internal.exclude_stack; stk->baselen = cp - base; stk->exclude_ix = group->nr; stk->ucd = untracked; pl = add_pattern_list(dir, EXC_DIRS, NULL); - strbuf_add(&dir->basebuf, base + current, stk->baselen - current); - assert(stk->baselen == dir->basebuf.len); + strbuf_add(&dir->internal.basebuf, base + current, stk->baselen - current); + assert(stk->baselen == dir->internal.basebuf.len); /* Abort if the directory is excluded */ if (stk->baselen) { int dt = DT_DIR; - dir->basebuf.buf[stk->baselen - 1] = 0; - dir->pattern = last_matching_pattern_from_lists(dir, + dir->internal.basebuf.buf[stk->baselen - 1] = 0; + dir->internal.pattern = last_matching_pattern_from_lists(dir, istate, - dir->basebuf.buf, stk->baselen - 1, - dir->basebuf.buf + current, &dt); - dir->basebuf.buf[stk->baselen - 1] = '/'; - if (dir->pattern && - dir->pattern->flags & PATTERN_FLAG_NEGATIVE) - dir->pattern = NULL; - if (dir->pattern) { - dir->exclude_stack = stk; + dir->internal.basebuf.buf, stk->baselen - 1, + dir->internal.basebuf.buf + current, &dt); + dir->internal.basebuf.buf[stk->baselen - 1] = '/'; + if (dir->internal.pattern && + dir->internal.pattern->flags & PATTERN_FLAG_NEGATIVE) + dir->internal.pattern = NULL; + if (dir->internal.pattern) { + dir->internal.exclude_stack = stk; return; } } @@ -1647,15 +1648,15 @@ static void prep_exclude(struct dir_struct *dir, */ !is_null_oid(&untracked->exclude_oid))) { /* - * dir->basebuf gets reused by the traversal, but we - * need fname to remain unchanged to ensure the src - * member of each struct path_pattern correctly + * dir->internal.basebuf gets reused by the traversal, + * but we need fname to remain unchanged to ensure the + * src member of each struct path_pattern correctly * back-references its source file. Other invocations * of add_pattern_list provide stable strings, so we * strbuf_detach() and free() here in the caller. */ struct strbuf sb = STRBUF_INIT; - strbuf_addbuf(&sb, &dir->basebuf); + strbuf_addbuf(&sb, &dir->internal.basebuf); strbuf_addstr(&sb, dir->exclude_per_dir); pl->src = strbuf_detach(&sb, NULL); add_patterns(pl->src, pl->src, stk->baselen, pl, istate, @@ -1681,10 +1682,10 @@ static void prep_exclude(struct dir_struct *dir, invalidate_gitignore(dir->untracked, untracked); oidcpy(&untracked->exclude_oid, &oid_stat.oid); } - dir->exclude_stack = stk; + dir->internal.exclude_stack = stk; current = stk->baselen; } - strbuf_setlen(&dir->basebuf, baselen); + strbuf_setlen(&dir->internal.basebuf, baselen); } /* @@ -1704,8 +1705,8 @@ struct path_pattern *last_matching_pattern(struct dir_struct *dir, prep_exclude(dir, istate, pathname, basename-pathname); - if (dir->pattern) - return dir->pattern; + if (dir->internal.pattern) + return dir->internal.pattern; return last_matching_pattern_from_lists(dir, istate, pathname, pathlen, basename, dtype_p); @@ -1742,7 +1743,7 @@ static struct dir_entry *dir_add_name(struct dir_struct *dir, if (index_file_exists(istate, pathname, len, ignore_case)) return NULL; - ALLOC_GROW(dir->entries, dir->nr+1, dir->alloc); + ALLOC_GROW(dir->entries, dir->nr+1, dir->internal.alloc); return dir->entries[dir->nr++] = dir_entry_new(pathname, len); } @@ -1753,7 +1754,7 @@ struct dir_entry *dir_add_ignored(struct dir_struct *dir, if (!index_name_is_other(istate, pathname, len)) return NULL; - ALLOC_GROW(dir->ignored, dir->ignored_nr+1, dir->ignored_alloc); + ALLOC_GROW(dir->ignored, dir->ignored_nr+1, dir->internal.ignored_alloc); return dir->ignored[dir->ignored_nr++] = dir_entry_new(pathname, len); } @@ -2569,7 +2570,7 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir, if (open_cached_dir(&cdir, dir, untracked, istate, &path, check_only)) goto out; - dir->visited_directories++; + dir->internal.visited_directories++; if (untracked) untracked->check_only = !!check_only; @@ -2578,7 +2579,7 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir, /* check how the file or directory should be treated */ state = treat_path(dir, untracked, &cdir, istate, &path, baselen, pathspec); - dir->visited_paths++; + dir->internal.visited_paths++; if (state > dir_state) dir_state = state; @@ -2586,7 +2587,8 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir, /* recurse into subdir if instructed by treat_path */ if (state == path_recurse) { struct untracked_cache_dir *ud; - ud = lookup_untracked(dir->untracked, untracked, + ud = lookup_untracked(dir->untracked, + untracked, path.buf + baselen, path.len - baselen); subdir_state = @@ -2846,7 +2848,7 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d * condition also catches running setup_standard_excludes() * before setting dir->untracked! */ - if (dir->unmanaged_exclude_files) + if (dir->internal.unmanaged_exclude_files) return NULL; /* @@ -2875,7 +2877,7 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d * EXC_CMDL is not considered in the cache. If people set it, * skip the cache. */ - if (dir->exclude_list_group[EXC_CMDL].nr) + if (dir->internal.exclude_list_group[EXC_CMDL].nr) return NULL; if (!ident_in_untracked(dir->untracked)) { @@ -2935,15 +2937,15 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d /* Validate $GIT_DIR/info/exclude and core.excludesfile */ root = dir->untracked->root; - if (!oideq(&dir->ss_info_exclude.oid, + if (!oideq(&dir->internal.ss_info_exclude.oid, &dir->untracked->ss_info_exclude.oid)) { invalidate_gitignore(dir->untracked, root); - dir->untracked->ss_info_exclude = dir->ss_info_exclude; + dir->untracked->ss_info_exclude = dir->internal.ss_info_exclude; } - if (!oideq(&dir->ss_excludes_file.oid, + if (!oideq(&dir->internal.ss_excludes_file.oid, &dir->untracked->ss_excludes_file.oid)) { invalidate_gitignore(dir->untracked, root); - dir->untracked->ss_excludes_file = dir->ss_excludes_file; + dir->untracked->ss_excludes_file = dir->internal.ss_excludes_file; } /* Make sure this directory is not dropped out at saving phase */ @@ -2969,9 +2971,9 @@ static void emit_traversal_statistics(struct dir_struct *dir, } trace2_data_intmax("read_directory", repo, - "directories-visited", dir->visited_directories); + "directories-visited", dir->internal.visited_directories); trace2_data_intmax("read_directory", repo, - "paths-visited", dir->visited_paths); + "paths-visited", dir->internal.visited_paths); if (!dir->untracked) return; @@ -2993,8 +2995,8 @@ int read_directory(struct dir_struct *dir, struct index_state *istate, struct untracked_cache_dir *untracked; trace2_region_enter("dir", "read_directory", istate->repo); - dir->visited_paths = 0; - dir->visited_directories = 0; + dir->internal.visited_paths = 0; + dir->internal.visited_directories = 0; if (has_symlink_leading_path(path, len)) { trace2_region_leave("dir", "read_directory", istate->repo); @@ -3342,14 +3344,14 @@ void setup_standard_excludes(struct dir_struct *dir) excludes_file = xdg_config_home("ignore"); if (excludes_file && !access_or_warn(excludes_file, R_OK, 0)) add_patterns_from_file_1(dir, excludes_file, - dir->untracked ? &dir->ss_excludes_file : NULL); + dir->untracked ? &dir->internal.ss_excludes_file : NULL); /* per repository user preference */ if (startup_info->have_repository) { const char *path = git_path_info_exclude(); if (!access_or_warn(path, R_OK, 0)) add_patterns_from_file_1(dir, path, - dir->untracked ? &dir->ss_info_exclude : NULL); + dir->untracked ? &dir->internal.ss_info_exclude : NULL); } } @@ -3405,7 +3407,7 @@ void dir_clear(struct dir_struct *dir) struct dir_struct new = DIR_INIT; for (i = EXC_CMDL; i <= EXC_FILE; i++) { - group = &dir->exclude_list_group[i]; + group = &dir->internal.exclude_list_group[i]; for (j = 0; j < group->nr; j++) { pl = &group->pl[j]; if (i == EXC_DIRS) @@ -3422,13 +3424,13 @@ void dir_clear(struct dir_struct *dir) free(dir->ignored); free(dir->entries); - stk = dir->exclude_stack; + stk = dir->internal.exclude_stack; while (stk) { struct exclude_stack *prev = stk->prev; free(stk); stk = prev; } - strbuf_release(&dir->basebuf); + strbuf_release(&dir->internal.basebuf); memcpy(dir, &new, sizeof(*dir)); } diff --git a/dir.h b/dir.h index 8acfc04418..33fd848fc8 100644 --- a/dir.h +++ b/dir.h @@ -215,14 +215,9 @@ struct dir_struct { /* The number of members in `entries[]` array. */ int nr; - /* Internal use; keeps track of allocation of `entries[]` array.*/ - int alloc; - /* The number of members in `ignored[]` array. */ int ignored_nr; - int ignored_alloc; - /* bit-field of options */ enum { @@ -296,51 +291,62 @@ struct dir_struct { */ struct dir_entry **ignored; + /* Enable/update untracked file cache if set */ + struct untracked_cache *untracked; + /** * The name of the file to be read in each directory for excluded files * (typically `.gitignore`). */ const char *exclude_per_dir; - /* - * We maintain three groups of exclude pattern lists: - * - * EXC_CMDL lists patterns explicitly given on the command line. - * EXC_DIRS lists patterns obtained from per-directory ignore files. - * EXC_FILE lists patterns from fallback ignore files, e.g. - * - .git/info/exclude - * - core.excludesfile - * - * Each group contains multiple exclude lists, a single list - * per source. - */ + struct dir_struct_internal { + /* Keeps track of allocation of `entries[]` array.*/ + int alloc; + + /* Keeps track of allocation of `ignored[]` array. */ + int ignored_alloc; + + /* + * We maintain three groups of exclude pattern lists: + * + * EXC_CMDL lists patterns explicitly given on the command line. + * EXC_DIRS lists patterns obtained from per-directory ignore + * files. + * EXC_FILE lists patterns from fallback ignore files, e.g. + * - .git/info/exclude + * - core.excludesfile + * + * Each group contains multiple exclude lists, a single list + * per source. + */ #define EXC_CMDL 0 #define EXC_DIRS 1 #define EXC_FILE 2 - struct exclude_list_group exclude_list_group[3]; + struct exclude_list_group exclude_list_group[3]; - /* - * Temporary variables which are used during loading of the - * per-directory exclude lists. - * - * exclude_stack points to the top of the exclude_stack, and - * basebuf contains the full path to the current - * (sub)directory in the traversal. Exclude points to the - * matching exclude struct if the directory is excluded. - */ - struct exclude_stack *exclude_stack; - struct path_pattern *pattern; - struct strbuf basebuf; + /* + * Temporary variables which are used during loading of the + * per-directory exclude lists. + * + * exclude_stack points to the top of the exclude_stack, and + * basebuf contains the full path to the current + * (sub)directory in the traversal. Exclude points to the + * matching exclude struct if the directory is excluded. + */ + struct exclude_stack *exclude_stack; + struct path_pattern *pattern; + struct strbuf basebuf; - /* Enable untracked file cache if set */ - struct untracked_cache *untracked; - struct oid_stat ss_info_exclude; - struct oid_stat ss_excludes_file; - unsigned unmanaged_exclude_files; + /* Additional metadata related to 'untracked' */ + struct oid_stat ss_info_exclude; + struct oid_stat ss_excludes_file; + unsigned unmanaged_exclude_files; - /* Stats about the traversal */ - unsigned visited_paths; - unsigned visited_directories; + /* Stats about the traversal */ + unsigned visited_paths; + unsigned visited_directories; + } internal; }; #define DIR_INIT { 0 } From 59e009bf15cefd89105c3e162776ccf10f4e68f1 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 27 Feb 2023 15:28:11 +0000 Subject: [PATCH 060/508] dir: add a usage note to exclude_per_dir As evidenced by the fix a couple commits ago, places in the code using exclude_per_dir are likely buggy and should be adapted to call setup_standard_excludes() instead. Unfortunately, the usage of exclude_per_dir has been hardcoded into the arguments ls-files accepts, so we cannot actually remove it. Add a note that it is deprecated and no other callers should use it directly. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- dir.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dir.h b/dir.h index 33fd848fc8..2196e12630 100644 --- a/dir.h +++ b/dir.h @@ -295,8 +295,12 @@ struct dir_struct { struct untracked_cache *untracked; /** - * The name of the file to be read in each directory for excluded files - * (typically `.gitignore`). + * Deprecated: ls-files is the only allowed caller; all other callers + * should leave this as NULL; it pre-dated the + * setup_standard_excludes() mechanism that replaces this. + * + * This field tracks the name of the file to be read in each directory + * for excluded files (typically `.gitignore`). */ const char *exclude_per_dir; From d144a9d30d883ec4b2ea5ed065e1b42237217c14 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 27 Feb 2023 15:28:12 +0000 Subject: [PATCH 061/508] dir: mark output only fields of dir_struct as such While at it, also group these fields together for convenience. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- dir.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dir.h b/dir.h index 2196e12630..e8106e1eca 100644 --- a/dir.h +++ b/dir.h @@ -212,12 +212,6 @@ struct untracked_cache { */ struct dir_struct { - /* The number of members in `entries[]` array. */ - int nr; - - /* The number of members in `ignored[]` array. */ - int ignored_nr; - /* bit-field of options */ enum { @@ -282,14 +276,20 @@ struct dir_struct { DIR_SKIP_NESTED_GIT = 1<<9 } flags; + /* The number of members in `entries[]` array. */ + int nr; /* output only */ + + /* The number of members in `ignored[]` array. */ + int ignored_nr; /* output only */ + /* An array of `struct dir_entry`, each element of which describes a path. */ - struct dir_entry **entries; + struct dir_entry **entries; /* output only */ /** * used for ignored paths with the `DIR_SHOW_IGNORED_TOO` and * `DIR_COLLECT_IGNORED` flags. */ - struct dir_entry **ignored; + struct dir_entry **ignored; /* output only */ /* Enable/update untracked file cache if set */ struct untracked_cache *untracked; From 5d4f4a592e99e8fb220b2db410f0d81203f3762e Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 27 Feb 2023 15:28:13 +0000 Subject: [PATCH 062/508] unpack-trees: clean up some flow control The update_sparsity() function was introduced in commit 7af7a25853 ("unpack-trees: add a new update_sparsity() function", 2020-03-27). Prior to that, unpack_trees() was used, but that had a few bugs because the needs of the caller were different, and different enough that unpack_trees() could not easily be modified to handle both usecases. The implementation detail that update_sparsity() was written by copying unpack_trees() and then streamlining it, and then modifying it in the needed ways still shows through in that there are leftover vestiges in both functions that are no longer needed. Clean them up. In particular: * update_sparsity() allows a pattern list to be passed in, but unpack_trees() never should use a different pattern list. Add a check and a BUG() if this gets violated. * update_sparsity() has a check early on that will BUG() if o->skip_sparse_checkout is set; as such, there's no need to check for that condition again later in the code. We can simply remove the check and its corresponding goto label. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- unpack-trees.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/unpack-trees.c b/unpack-trees.c index 4518d33ed9..bad3120a76 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1873,6 +1873,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES); if (o->dir) BUG("o->dir is for internal use only"); + if (o->pl) + BUG("o->pl is for internal use only"); trace_performance_enter(); trace2_region_enter("unpack_trees", "unpack_trees", the_repository); @@ -1899,7 +1901,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options if (!core_apply_sparse_checkout || !o->update) o->skip_sparse_checkout = 1; - if (!o->skip_sparse_checkout && !o->pl) { + if (!o->skip_sparse_checkout) { memset(&pl, 0, sizeof(pl)); free_pattern_list = 1; populate_from_existing_patterns(o, &pl); @@ -2113,8 +2115,6 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o) memset(&pl, 0, sizeof(pl)); free_pattern_list = 1; populate_from_existing_patterns(o, &pl); - if (o->skip_sparse_checkout) - goto skip_sparse_checkout; } /* Expand sparse directories as needed */ @@ -2142,7 +2142,6 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o) ret = UPDATE_SPARSITY_WARNINGS; } -skip_sparse_checkout: if (check_updates(o, o->src_index)) ret = UPDATE_SPARSITY_WORKTREE_UPDATE_FAILURES; From 1147c56ff70d5d1152601a73c9e76b9856ceebf6 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 27 Feb 2023 15:28:14 +0000 Subject: [PATCH 063/508] sparse-checkout: avoid using internal API of unpack-trees struct unpack_trees_options has the following field and comment: struct pattern_list *pl; /* for internal use */ Despite the internal-use comment, commit e091228e17 ("sparse-checkout: update working directory in-process", 2019-11-21) starting setting this field from an external caller. At the time, the only way around that would have been to modify unpack_trees() to take an extra pattern_list argument, and there's a lot of callers of that function. However, when we split update_sparsity() off as a separate function, with sparse-checkout being the sole caller, the need to update other callers went away. Fix this API problem by adding a pattern_list argument to update_sparsity() and stop setting the internal o.pl field directly. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- builtin/sparse-checkout.c | 3 +-- unpack-trees.c | 18 +++++++++++------- unpack-trees.h | 3 ++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index c373815491..4b7390ce36 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -219,14 +219,13 @@ static int update_working_directory(struct pattern_list *pl) o.dst_index = r->index; index_state_init(&o.result, r); o.skip_sparse_checkout = 0; - o.pl = pl; setup_work_tree(); repo_hold_locked_index(r, &lock_file, LOCK_DIE_ON_ERROR); setup_unpack_trees_porcelain(&o, "sparse-checkout"); - result = update_sparsity(&o); + result = update_sparsity(&o, pl); clear_unpack_trees_porcelain(&o); if (result == UPDATE_SPARSITY_WARNINGS) diff --git a/unpack-trees.c b/unpack-trees.c index bad3120a76..6e4ca6fe80 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -2091,10 +2091,10 @@ return_failed: * * CE_NEW_SKIP_WORKTREE is used internally. */ -enum update_sparsity_result update_sparsity(struct unpack_trees_options *o) +enum update_sparsity_result update_sparsity(struct unpack_trees_options *o, + struct pattern_list *pl) { enum update_sparsity_result ret = UPDATE_SPARSITY_SUCCESS; - struct pattern_list pl; int i; unsigned old_show_all_errors; int free_pattern_list = 0; @@ -2111,11 +2111,12 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o) trace_performance_enter(); /* If we weren't given patterns, use the recorded ones */ - if (!o->pl) { - memset(&pl, 0, sizeof(pl)); + if (!pl) { free_pattern_list = 1; - populate_from_existing_patterns(o, &pl); + pl = xcalloc(1, sizeof(*pl)); + populate_from_existing_patterns(o, pl); } + o->pl = pl; /* Expand sparse directories as needed */ expand_index(o->src_index, o->pl); @@ -2147,8 +2148,11 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o) display_warning_msgs(o); o->show_all_errors = old_show_all_errors; - if (free_pattern_list) - clear_pattern_list(&pl); + if (free_pattern_list) { + clear_pattern_list(pl); + free(pl); + o->pl = NULL; + } trace_performance_leave("update_sparsity"); return ret; } diff --git a/unpack-trees.h b/unpack-trees.h index 3a7b3e5f00..f3a6e4f90e 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -112,7 +112,8 @@ enum update_sparsity_result { UPDATE_SPARSITY_WORKTREE_UPDATE_FAILURES = -2 }; -enum update_sparsity_result update_sparsity(struct unpack_trees_options *options); +enum update_sparsity_result update_sparsity(struct unpack_trees_options *options, + struct pattern_list *pl); int verify_uptodate(const struct cache_entry *ce, struct unpack_trees_options *o); From 33b1b4c7681703c44babdbd229cc96a3ad540569 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 27 Feb 2023 15:28:15 +0000 Subject: [PATCH 064/508] sparse-checkout: avoid using internal API of unpack-trees, take 2 Commit 2f6b1eb794 ("cache API: add a "INDEX_STATE_INIT" macro/function, add release_index()", 2023-01-12) mistakenly added some initialization of a member of unpack_trees_options that was intended to be internal-only. This initialization should be done within update_sparsity() instead. Note that while o->result is mostly meant for unpack_trees() and update_sparsity() mostly operates without o->result, check_ok_to_remove() does consult it so we need to ensure it is properly initialized. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- builtin/sparse-checkout.c | 1 - unpack-trees.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 4b7390ce36..8d5ae6f2a6 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -217,7 +217,6 @@ static int update_working_directory(struct pattern_list *pl) o.head_idx = -1; o.src_index = r->index; o.dst_index = r->index; - index_state_init(&o.result, r); o.skip_sparse_checkout = 0; setup_work_tree(); diff --git a/unpack-trees.c b/unpack-trees.c index 6e4ca6fe80..c8dacd76c5 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -2101,6 +2101,7 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o, old_show_all_errors = o->show_all_errors; o->show_all_errors = 1; + index_state_init(&o->result, o->src_index->repo); /* Sanity checks */ if (!o->update || o->index_only || o->skip_sparse_checkout) From 576de3d95608df759c1f09e84f4ce1cea3c404d4 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 27 Feb 2023 15:28:16 +0000 Subject: [PATCH 065/508] unpack_trees: start splitting internal fields from public API This just splits the two fields already marked as internal-only into a separate internal struct. Future commits will add more fields that were meant to be internal-only but were not explicitly marked as such to the same struct. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- unpack-trees.c | 40 ++++++++++++++++++++-------------------- unpack-trees.h | 7 +++++-- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/unpack-trees.c b/unpack-trees.c index c8dacd76c5..ecf89d5bfe 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1809,7 +1809,7 @@ static void populate_from_existing_patterns(struct unpack_trees_options *o, if (get_sparse_checkout_patterns(pl) < 0) o->skip_sparse_checkout = 1; else - o->pl = pl; + o->internal.pl = pl; } static void update_sparsity_for_prefix(const char *prefix, @@ -1871,10 +1871,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options if (len > MAX_UNPACK_TREES) die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES); - if (o->dir) - BUG("o->dir is for internal use only"); - if (o->pl) - BUG("o->pl is for internal use only"); + if (o->internal.dir) + BUG("o->internal.dir is for internal use only"); + if (o->internal.pl) + BUG("o->internal.pl is for internal use only"); trace_performance_enter(); trace2_region_enter("unpack_trees", "unpack_trees", the_repository); @@ -1891,9 +1891,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options BUG("UNPACK_RESET_OVERWRITE_UNTRACKED incompatible with preserved ignored files"); if (!o->preserve_ignored) { - o->dir = &dir; - o->dir->flags |= DIR_SHOW_IGNORED; - setup_standard_excludes(o->dir); + o->internal.dir = &dir; + o->internal.dir->flags |= DIR_SHOW_IGNORED; + setup_standard_excludes(o->internal.dir); } if (o->prefix) @@ -1943,7 +1943,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options * Sparse checkout loop #1: set NEW_SKIP_WORKTREE on existing entries */ if (!o->skip_sparse_checkout) - mark_new_skip_worktree(o->pl, o->src_index, 0, + mark_new_skip_worktree(o->internal.pl, o->src_index, 0, CE_NEW_SKIP_WORKTREE, o->verbose_update); if (!dfc) @@ -2009,7 +2009,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options * If they will have NEW_SKIP_WORKTREE, also set CE_SKIP_WORKTREE * so apply_sparse_checkout() won't attempt to remove it from worktree */ - mark_new_skip_worktree(o->pl, &o->result, + mark_new_skip_worktree(o->internal.pl, &o->result, CE_ADDED, CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE, o->verbose_update); @@ -2067,9 +2067,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options done: if (free_pattern_list) clear_pattern_list(&pl); - if (o->dir) { - dir_clear(o->dir); - o->dir = NULL; + if (o->internal.dir) { + dir_clear(o->internal.dir); + o->internal.dir = NULL; } trace2_region_leave("unpack_trees", "unpack_trees", the_repository); trace_performance_leave("unpack_trees"); @@ -2117,14 +2117,14 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o, pl = xcalloc(1, sizeof(*pl)); populate_from_existing_patterns(o, pl); } - o->pl = pl; + o->internal.pl = pl; /* Expand sparse directories as needed */ - expand_index(o->src_index, o->pl); + expand_index(o->src_index, o->internal.pl); /* Set NEW_SKIP_WORKTREE on existing entries. */ mark_all_ce_unused(o->src_index); - mark_new_skip_worktree(o->pl, o->src_index, 0, + mark_new_skip_worktree(o->internal.pl, o->src_index, 0, CE_NEW_SKIP_WORKTREE, o->verbose_update); /* Then loop over entries and update/remove as needed */ @@ -2152,7 +2152,7 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o, if (free_pattern_list) { clear_pattern_list(pl); free(pl); - o->pl = NULL; + o->internal.pl = NULL; } trace_performance_leave("update_sparsity"); return ret; @@ -2340,7 +2340,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce, pathbuf = xstrfmt("%.*s/", namelen, ce->name); memset(&d, 0, sizeof(d)); - if (o->dir) + if (o->internal.dir) setup_standard_excludes(&d); i = read_directory(&d, o->src_index, pathbuf, namelen+1, NULL); dir_clear(&d); @@ -2395,8 +2395,8 @@ static int check_ok_to_remove(const char *name, int len, int dtype, if (ignore_case && icase_exists(o, name, len, st)) return 0; - if (o->dir && - is_excluded(o->dir, o->src_index, name, &dtype)) + if (o->internal.dir && + is_excluded(o->internal.dir, o->src_index, name, &dtype)) /* * ce->name is explicitly excluded, so it is Ok to * overwrite it. diff --git a/unpack-trees.h b/unpack-trees.h index f3a6e4f90e..5c1a9314a0 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -97,9 +97,12 @@ struct unpack_trees_options { struct index_state *src_index; struct index_state result; - struct pattern_list *pl; /* for internal use */ - struct dir_struct *dir; /* for internal use only */ struct checkout_metadata meta; + + struct unpack_trees_options_internal { + struct pattern_list *pl; + struct dir_struct *dir; + } internal; }; int unpack_trees(unsigned n, struct tree_desc *t, From 13e1fd6e38f17fe7fecfb6e6c30af053a3c2c420 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 27 Feb 2023 15:28:17 +0000 Subject: [PATCH 066/508] unpack-trees: mark fields only used internally as internal Continue the work from the previous patch by finding additional fields which are only used internally but not yet explicitly marked as such, and include them in the internal fields struct. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- unpack-trees.c | 159 +++++++++++++++++++++++++------------------------ unpack-trees.h | 26 ++++---- 2 files changed, 95 insertions(+), 90 deletions(-) diff --git a/unpack-trees.c b/unpack-trees.c index ecf89d5bfe..dd4b55ef49 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -66,8 +66,8 @@ static const char *unpack_plumbing_errors[NB_UNPACK_TREES_WARNING_TYPES] = { }; #define ERRORMSG(o,type) \ - ( ((o) && (o)->msgs[(type)]) \ - ? ((o)->msgs[(type)]) \ + ( ((o) && (o)->internal.msgs[(type)]) \ + ? ((o)->internal.msgs[(type)]) \ : (unpack_plumbing_errors[(type)]) ) static const char *super_prefixed(const char *path, const char *super_prefix) @@ -108,10 +108,10 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, const char *cmd) { int i; - const char **msgs = opts->msgs; + const char **msgs = opts->internal.msgs; const char *msg; - strvec_init(&opts->msgs_to_free); + strvec_init(&opts->internal.msgs_to_free); if (!strcmp(cmd, "checkout")) msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE) @@ -129,7 +129,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, "Please commit your changes or stash them before you %s.") : _("Your local changes to the following files would be overwritten by %s:\n%%s"); msgs[ERROR_WOULD_OVERWRITE] = msgs[ERROR_NOT_UPTODATE_FILE] = - strvec_pushf(&opts->msgs_to_free, msg, cmd, cmd); + strvec_pushf(&opts->internal.msgs_to_free, msg, cmd, cmd); msgs[ERROR_NOT_UPTODATE_DIR] = _("Updating the following directories would lose untracked files in them:\n%s"); @@ -153,7 +153,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, "Please move or remove them before you %s.") : _("The following untracked working tree files would be removed by %s:\n%%s"); msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = - strvec_pushf(&opts->msgs_to_free, msg, cmd, cmd); + strvec_pushf(&opts->internal.msgs_to_free, msg, cmd, cmd); if (!strcmp(cmd, "checkout")) msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE) @@ -171,7 +171,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, "Please move or remove them before you %s.") : _("The following untracked working tree files would be overwritten by %s:\n%%s"); msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = - strvec_pushf(&opts->msgs_to_free, msg, cmd, cmd); + strvec_pushf(&opts->internal.msgs_to_free, msg, cmd, cmd); /* * Special case: ERROR_BIND_OVERLAP refers to a pair of paths, we @@ -189,16 +189,16 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, msgs[WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN] = _("The following paths were already present and thus not updated despite sparse patterns:\n%s"); - opts->show_all_errors = 1; + opts->internal.show_all_errors = 1; /* rejected paths may not have a static buffer */ - for (i = 0; i < ARRAY_SIZE(opts->unpack_rejects); i++) - opts->unpack_rejects[i].strdup_strings = 1; + for (i = 0; i < ARRAY_SIZE(opts->internal.unpack_rejects); i++) + opts->internal.unpack_rejects[i].strdup_strings = 1; } void clear_unpack_trees_porcelain(struct unpack_trees_options *opts) { - strvec_clear(&opts->msgs_to_free); - memset(opts->msgs, 0, sizeof(opts->msgs)); + strvec_clear(&opts->internal.msgs_to_free); + memset(opts->internal.msgs, 0, sizeof(opts->internal.msgs)); } static int do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce, @@ -210,7 +210,7 @@ static int do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce, set |= CE_WT_REMOVE; ce->ce_flags = (ce->ce_flags & ~clear) | set; - return add_index_entry(&o->result, ce, + return add_index_entry(&o->internal.result, ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE); } @@ -218,7 +218,7 @@ static void add_entry(struct unpack_trees_options *o, const struct cache_entry *ce, unsigned int set, unsigned int clear) { - do_add_entry(o, dup_cache_entry(ce, &o->result), set, clear); + do_add_entry(o, dup_cache_entry(ce, &o->internal.result), set, clear); } /* @@ -233,7 +233,7 @@ static int add_rejected_path(struct unpack_trees_options *o, if (o->quiet) return -1; - if (!o->show_all_errors) + if (!o->internal.show_all_errors) return error(ERRORMSG(o, e), super_prefixed(path, o->super_prefix)); @@ -241,7 +241,7 @@ static int add_rejected_path(struct unpack_trees_options *o, * Otherwise, insert in a list for future display by * display_(error|warning)_msgs() */ - string_list_append(&o->unpack_rejects[e], path); + string_list_append(&o->internal.unpack_rejects[e], path); return -1; } @@ -253,7 +253,7 @@ static void display_error_msgs(struct unpack_trees_options *o) int e; unsigned error_displayed = 0; for (e = 0; e < NB_UNPACK_TREES_ERROR_TYPES; e++) { - struct string_list *rejects = &o->unpack_rejects[e]; + struct string_list *rejects = &o->internal.unpack_rejects[e]; if (rejects->nr > 0) { int i; @@ -281,7 +281,7 @@ static void display_warning_msgs(struct unpack_trees_options *o) unsigned warning_displayed = 0; for (e = NB_UNPACK_TREES_ERROR_TYPES + 1; e < NB_UNPACK_TREES_WARNING_TYPES; e++) { - struct string_list *rejects = &o->unpack_rejects[e]; + struct string_list *rejects = &o->internal.unpack_rejects[e]; if (rejects->nr > 0) { int i; @@ -600,13 +600,14 @@ static void mark_ce_used(struct cache_entry *ce, struct unpack_trees_options *o) { ce->ce_flags |= CE_UNPACKED; - if (o->cache_bottom < o->src_index->cache_nr && - o->src_index->cache[o->cache_bottom] == ce) { - int bottom = o->cache_bottom; + if (o->internal.cache_bottom < o->src_index->cache_nr && + o->src_index->cache[o->internal.cache_bottom] == ce) { + int bottom = o->internal.cache_bottom; + while (bottom < o->src_index->cache_nr && o->src_index->cache[bottom]->ce_flags & CE_UNPACKED) bottom++; - o->cache_bottom = bottom; + o->internal.cache_bottom = bottom; } } @@ -652,7 +653,7 @@ static void mark_ce_used_same_name(struct cache_entry *ce, static struct cache_entry *next_cache_entry(struct unpack_trees_options *o) { const struct index_state *index = o->src_index; - int pos = o->cache_bottom; + int pos = o->internal.cache_bottom; while (pos < index->cache_nr) { struct cache_entry *ce = index->cache[pos]; @@ -711,7 +712,7 @@ static void restore_cache_bottom(struct traverse_info *info, int bottom) if (o->diff_index_cached) return; - o->cache_bottom = bottom; + o->internal.cache_bottom = bottom; } static int switch_cache_bottom(struct traverse_info *info) @@ -721,13 +722,13 @@ static int switch_cache_bottom(struct traverse_info *info) if (o->diff_index_cached) return 0; - ret = o->cache_bottom; + ret = o->internal.cache_bottom; pos = find_cache_pos(info->prev, info->name, info->namelen); if (pos < -1) - o->cache_bottom = -2 - pos; + o->internal.cache_bottom = -2 - pos; else if (pos < 0) - o->cache_bottom = o->src_index->cache_nr; + o->internal.cache_bottom = o->src_index->cache_nr; return ret; } @@ -873,9 +874,9 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, * save and restore cache_bottom anyway to not miss * unprocessed entries before 'pos'. */ - bottom = o->cache_bottom; + bottom = o->internal.cache_bottom; ret = traverse_by_cache_tree(pos, nr_entries, n, info); - o->cache_bottom = bottom; + o->internal.cache_bottom = bottom; return ret; } @@ -1212,7 +1213,7 @@ static int unpack_single_entry(int n, unsigned long mask, * cache entry from the index aware logic. */ src[i + o->merge] = create_ce_entry(info, names + i, stage, - &o->result, o->merge, + &o->internal.result, o->merge, bit & dirmask); } @@ -1237,7 +1238,7 @@ static int unpack_single_entry(int n, unsigned long mask, static int unpack_failed(struct unpack_trees_options *o, const char *message) { - discard_index(&o->result); + discard_index(&o->internal.result); if (!o->quiet && !o->exiting_early) { if (message) return error("%s", message); @@ -1260,7 +1261,7 @@ static int find_cache_pos(struct traverse_info *info, struct index_state *index = o->src_index; int pfxlen = info->pathlen; - for (pos = o->cache_bottom; pos < index->cache_nr; pos++) { + for (pos = o->internal.cache_bottom; pos < index->cache_nr; pos++) { const struct cache_entry *ce = index->cache[pos]; const char *ce_name, *ce_slash; int cmp, ce_len; @@ -1271,8 +1272,8 @@ static int find_cache_pos(struct traverse_info *info, * we can never match it; don't check it * again. */ - if (pos == o->cache_bottom) - ++o->cache_bottom; + if (pos == o->internal.cache_bottom) + ++o->internal.cache_bottom; continue; } if (!ce_in_traverse_path(ce, info)) { @@ -1450,7 +1451,7 @@ static int unpack_sparse_callback(int n, unsigned long mask, unsigned long dirma */ if (!is_null_oid(&names[0].oid)) { src[0] = create_ce_entry(info, &names[0], 0, - &o->result, 1, + &o->internal.result, 1, dirmask & (1ul << 0)); src[0]->ce_flags |= (CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE); } @@ -1560,7 +1561,7 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str * in 'mark_ce_used()' */ if (!src[0] || !S_ISSPARSEDIR(src[0]->ce_mode)) - o->cache_bottom += matches; + o->internal.cache_bottom += matches; return mask; } } @@ -1907,37 +1908,37 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options populate_from_existing_patterns(o, &pl); } - index_state_init(&o->result, o->src_index->repo); - o->result.initialized = 1; - o->result.timestamp.sec = o->src_index->timestamp.sec; - o->result.timestamp.nsec = o->src_index->timestamp.nsec; - o->result.version = o->src_index->version; + index_state_init(&o->internal.result, o->src_index->repo); + o->internal.result.initialized = 1; + o->internal.result.timestamp.sec = o->src_index->timestamp.sec; + o->internal.result.timestamp.nsec = o->src_index->timestamp.nsec; + o->internal.result.version = o->src_index->version; if (!o->src_index->split_index) { - o->result.split_index = NULL; + o->internal.result.split_index = NULL; } else if (o->src_index == o->dst_index) { /* * o->dst_index (and thus o->src_index) will be discarded - * and overwritten with o->result at the end of this function, + * and overwritten with o->internal.result at the end of this function, * so just use src_index's split_index to avoid having to * create a new one. */ - o->result.split_index = o->src_index->split_index; - o->result.split_index->refcount++; + o->internal.result.split_index = o->src_index->split_index; + o->internal.result.split_index->refcount++; } else { - o->result.split_index = init_split_index(&o->result); + o->internal.result.split_index = init_split_index(&o->internal.result); } - oidcpy(&o->result.oid, &o->src_index->oid); + oidcpy(&o->internal.result.oid, &o->src_index->oid); o->merge_size = len; mark_all_ce_unused(o->src_index); - o->result.fsmonitor_last_update = + o->internal.result.fsmonitor_last_update = xstrdup_or_null(o->src_index->fsmonitor_last_update); - o->result.fsmonitor_has_run_once = o->src_index->fsmonitor_has_run_once; + o->internal.result.fsmonitor_has_run_once = o->src_index->fsmonitor_has_run_once; if (!o->src_index->initialized && !repo->settings.command_requires_full_index && - is_sparse_index_allowed(&o->result, 0)) - o->result.sparse_index = 1; + is_sparse_index_allowed(&o->internal.result, 0)) + o->internal.result.sparse_index = 1; /* * Sparse checkout loop #1: set NEW_SKIP_WORKTREE on existing entries @@ -1957,7 +1958,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options setup_traverse_info(&info, prefix); info.fn = unpack_callback; info.data = o; - info.show_all_errors = o->show_all_errors; + info.show_all_errors = o->internal.show_all_errors; info.pathspec = o->pathspec; if (o->prefix) { @@ -1998,7 +1999,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options } mark_all_ce_unused(o->src_index); - if (o->trivial_merges_only && o->nontrivial_merge) { + if (o->trivial_merges_only && o->internal.nontrivial_merge) { ret = unpack_failed(o, "Merge requires file-level merging"); goto done; } @@ -2009,13 +2010,13 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options * If they will have NEW_SKIP_WORKTREE, also set CE_SKIP_WORKTREE * so apply_sparse_checkout() won't attempt to remove it from worktree */ - mark_new_skip_worktree(o->internal.pl, &o->result, + mark_new_skip_worktree(o->internal.pl, &o->internal.result, CE_ADDED, CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE, o->verbose_update); ret = 0; - for (i = 0; i < o->result.cache_nr; i++) { - struct cache_entry *ce = o->result.cache[i]; + for (i = 0; i < o->internal.result.cache_nr; i++) { + struct cache_entry *ce = o->internal.result.cache[i]; /* * Entries marked with CE_ADDED in merged_entry() do not have @@ -2029,7 +2030,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options verify_absent(ce, WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN, o)) ret = 1; - if (apply_sparse_checkout(&o->result, ce, o)) + if (apply_sparse_checkout(&o->internal.result, ce, o)) ret = 1; } if (ret == 1) { @@ -2037,30 +2038,30 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options * Inability to sparsify or de-sparsify individual * paths is not an error, but just a warning. */ - if (o->show_all_errors) + if (o->internal.show_all_errors) display_warning_msgs(o); ret = 0; } } - ret = check_updates(o, &o->result) ? (-2) : 0; + ret = check_updates(o, &o->internal.result) ? (-2) : 0; if (o->dst_index) { - move_index_extensions(&o->result, o->src_index); + move_index_extensions(&o->internal.result, o->src_index); if (!ret) { if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0)) - cache_tree_verify(the_repository, &o->result); + cache_tree_verify(the_repository, &o->internal.result); if (!o->skip_cache_tree_update && - !cache_tree_fully_valid(o->result.cache_tree)) - cache_tree_update(&o->result, + !cache_tree_fully_valid(o->internal.result.cache_tree)) + cache_tree_update(&o->internal.result, WRITE_TREE_SILENT | WRITE_TREE_REPAIR); } - o->result.updated_workdir = 1; + o->internal.result.updated_workdir = 1; discard_index(o->dst_index); - *o->dst_index = o->result; + *o->dst_index = o->internal.result; } else { - discard_index(&o->result); + discard_index(&o->internal.result); } o->src_index = NULL; @@ -2076,7 +2077,7 @@ done: return ret; return_failed: - if (o->show_all_errors) + if (o->internal.show_all_errors) display_error_msgs(o); mark_all_ce_unused(o->src_index); ret = unpack_failed(o, NULL); @@ -2099,9 +2100,9 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o, unsigned old_show_all_errors; int free_pattern_list = 0; - old_show_all_errors = o->show_all_errors; - o->show_all_errors = 1; - index_state_init(&o->result, o->src_index->repo); + old_show_all_errors = o->internal.show_all_errors; + o->internal.show_all_errors = 1; + index_state_init(&o->internal.result, o->src_index->repo); /* Sanity checks */ if (!o->update || o->index_only || o->skip_sparse_checkout) @@ -2148,7 +2149,7 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o, ret = UPDATE_SPARSITY_WORKTREE_UPDATE_FAILURES; display_warning_msgs(o); - o->show_all_errors = old_show_all_errors; + o->internal.show_all_errors = old_show_all_errors; if (free_pattern_list) { clear_pattern_list(pl); free(pl); @@ -2248,15 +2249,15 @@ static int verify_uptodate_sparse(const struct cache_entry *ce, } /* - * TODO: We should actually invalidate o->result, not src_index [1]. + * TODO: We should actually invalidate o->internal.result, not src_index [1]. * But since cache tree and untracked cache both are not copied to - * o->result until unpacking is complete, we invalidate them on + * o->internal.result until unpacking is complete, we invalidate them on * src_index instead with the assumption that they will be copied to * dst_index at the end. * * [1] src_index->cache_tree is also used in unpack_callback() so if - * we invalidate o->result, we need to update it to use - * o->result.cache_tree as well. + * we invalidate o->internal.result, we need to update it to use + * o->internal.result.cache_tree as well. */ static void invalidate_ce_path(const struct cache_entry *ce, struct unpack_trees_options *o) @@ -2424,7 +2425,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype, * delete this path, which is in a subdirectory that * is being replaced with a blob. */ - result = index_file_exists(&o->result, name, len, 0); + result = index_file_exists(&o->internal.result, name, len, 0); if (result) { if (result->ce_flags & CE_REMOVE) return 0; @@ -2525,7 +2526,7 @@ static int merged_entry(const struct cache_entry *ce, struct unpack_trees_options *o) { int update = CE_UPDATE; - struct cache_entry *merge = dup_cache_entry(ce, &o->result); + struct cache_entry *merge = dup_cache_entry(ce, &o->internal.result); if (!old) { /* @@ -2620,7 +2621,7 @@ static int merged_sparse_dir(const struct cache_entry * const *src, int n, setup_traverse_info(&info, src[0]->name); info.fn = unpack_sparse_callback; info.data = o; - info.show_all_errors = o->show_all_errors; + info.show_all_errors = o->internal.show_all_errors; info.pathspec = o->pathspec; /* Get the tree descriptors of the sparse directory in each of the merging trees */ @@ -2838,7 +2839,7 @@ int threeway_merge(const struct cache_entry * const *stages, return -1; } - o->nontrivial_merge = 1; + o->internal.nontrivial_merge = 1; /* #2, #3, #4, #6, #7, #9, #10, #11. */ count = 0; diff --git a/unpack-trees.h b/unpack-trees.h index 5c1a9314a0..0335c89bc7 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -59,7 +59,6 @@ struct unpack_trees_options { preserve_ignored, clone, index_only, - nontrivial_merge, trivial_merges_only, verbose_update, aggressive, @@ -70,22 +69,13 @@ struct unpack_trees_options { skip_sparse_checkout, quiet, exiting_early, - show_all_errors, dry_run, skip_cache_tree_update; enum unpack_trees_reset_type reset; const char *prefix; const char *super_prefix; - int cache_bottom; struct pathspec *pathspec; merge_fn_t fn; - const char *msgs[NB_UNPACK_TREES_WARNING_TYPES]; - struct strvec msgs_to_free; - /* - * Store error messages in an array, each case - * corresponding to a error message type - */ - struct string_list unpack_rejects[NB_UNPACK_TREES_WARNING_TYPES]; int head_idx; int merge_size; @@ -95,11 +85,25 @@ struct unpack_trees_options { struct index_state *dst_index; struct index_state *src_index; - struct index_state result; struct checkout_metadata meta; struct unpack_trees_options_internal { + unsigned int nontrivial_merge, + show_all_errors; + + int cache_bottom; + const char *msgs[NB_UNPACK_TREES_WARNING_TYPES]; + struct strvec msgs_to_free; + + /* + * Store error messages in an array, each case + * corresponding to a error message type + */ + struct string_list unpack_rejects[NB_UNPACK_TREES_WARNING_TYPES]; + + struct index_state result; + struct pattern_list *pl; struct dir_struct *dir; } internal; From 0d680a7158b647ced6a4e24a8687decc2ad6fb78 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 27 Feb 2023 15:28:18 +0000 Subject: [PATCH 067/508] unpack-trees: rewrap a few overlong lines from previous patch The previous patch made many lines a little longer, resulting in four becoming a bit too long. They were left as-is for the previous patch to facilitate reviewers verifying that we were just adding "internal." in a bunch of places, but rewrap them now. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- unpack-trees.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/unpack-trees.c b/unpack-trees.c index dd4b55ef49..cac5dd0da3 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1213,8 +1213,8 @@ static int unpack_single_entry(int n, unsigned long mask, * cache entry from the index aware logic. */ src[i + o->merge] = create_ce_entry(info, names + i, stage, - &o->internal.result, o->merge, - bit & dirmask); + &o->internal.result, + o->merge, bit & dirmask); } if (o->merge) { @@ -1918,14 +1918,15 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options } else if (o->src_index == o->dst_index) { /* * o->dst_index (and thus o->src_index) will be discarded - * and overwritten with o->internal.result at the end of this function, - * so just use src_index's split_index to avoid having to - * create a new one. + * and overwritten with o->internal.result at the end of + * this function, so just use src_index's split_index to + * avoid having to create a new one. */ o->internal.result.split_index = o->src_index->split_index; o->internal.result.split_index->refcount++; } else { - o->internal.result.split_index = init_split_index(&o->internal.result); + o->internal.result.split_index = + init_split_index(&o->internal.result); } oidcpy(&o->internal.result.oid, &o->src_index->oid); o->merge_size = len; @@ -2049,7 +2050,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options move_index_extensions(&o->internal.result, o->src_index); if (!ret) { if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0)) - cache_tree_verify(the_repository, &o->internal.result); + cache_tree_verify(the_repository, + &o->internal.result); if (!o->skip_cache_tree_update && !cache_tree_fully_valid(o->internal.result.cache_tree)) cache_tree_update(&o->internal.result, From 1ca13dd3ca6e153a2bc5b0b53555996cdd668e93 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 27 Feb 2023 15:28:19 +0000 Subject: [PATCH 068/508] unpack-trees: special case read-tree debugging as internal usage builtin/read-tree.c has some special functionality explicitly designed for debugging unpack-trees.[ch]. Associated with that is two fields that no other external caller would or should use. Mark these as internal to unpack-trees, but allow builtin/read-tree to read or write them for this special case. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- builtin/read-tree.c | 10 +++++----- unpack-trees.c | 22 +++++++++++----------- unpack-trees.h | 6 +++--- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/builtin/read-tree.c b/builtin/read-tree.c index 3ce7541783..6034408d48 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -87,9 +87,9 @@ static int debug_merge(const struct cache_entry * const *stages, { int i; - printf("* %d-way merge\n", o->merge_size); + printf("* %d-way merge\n", o->internal.merge_size); debug_stage("index", stages[0], o); - for (i = 1; i <= o->merge_size; i++) { + for (i = 1; i <= o->internal.merge_size; i++) { char buf[24]; xsnprintf(buf, sizeof(buf), "ent#%d", i); debug_stage(buf, stages[i], o); @@ -144,7 +144,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) OPT__DRY_RUN(&opts.dry_run, N_("don't update the index or the work tree")), OPT_BOOL(0, "no-sparse-checkout", &opts.skip_sparse_checkout, N_("skip applying sparse checkout filter")), - OPT_BOOL(0, "debug-unpack", &opts.debug_unpack, + OPT_BOOL(0, "debug-unpack", &opts.internal.debug_unpack, N_("debug unpack-trees")), OPT_CALLBACK_F(0, "recurse-submodules", NULL, "checkout", "control recursive updating of submodules", @@ -247,7 +247,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) opts.head_idx = 1; } - if (opts.debug_unpack) + if (opts.internal.debug_unpack) opts.fn = debug_merge; /* If we're going to prime_cache_tree later, skip cache tree update */ @@ -263,7 +263,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) if (unpack_trees(nr_trees, t, &opts)) return 128; - if (opts.debug_unpack || opts.dry_run) + if (opts.internal.debug_unpack || opts.dry_run) return 0; /* do not write the index out */ /* diff --git a/unpack-trees.c b/unpack-trees.c index cac5dd0da3..3e5f4bd235 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -839,7 +839,7 @@ static int traverse_by_cache_tree(int pos, int nr_entries, int nr_names, mark_ce_used(src[0], o); } free(tree_ce); - if (o->debug_unpack) + if (o->internal.debug_unpack) printf("Unpacked %d entries from %s to %s using cache-tree\n", nr_entries, o->src_index->cache[pos]->name, @@ -1488,7 +1488,7 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str while (!p->mode) p++; - if (o->debug_unpack) + if (o->internal.debug_unpack) debug_unpack_callback(n, mask, dirmask, names, info); /* Are we supposed to look at the index too? */ @@ -1929,7 +1929,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options init_split_index(&o->internal.result); } oidcpy(&o->internal.result.oid, &o->src_index->oid); - o->merge_size = len; + o->internal.merge_size = len; mark_all_ce_unused(o->src_index); o->internal.result.fsmonitor_last_update = @@ -2882,9 +2882,9 @@ int twoway_merge(const struct cache_entry * const *src, const struct cache_entry *oldtree = src[1]; const struct cache_entry *newtree = src[2]; - if (o->merge_size != 2) + if (o->internal.merge_size != 2) return error("Cannot do a twoway merge of %d trees", - o->merge_size); + o->internal.merge_size); if (oldtree == o->df_conflict_entry) oldtree = NULL; @@ -2964,9 +2964,9 @@ int bind_merge(const struct cache_entry * const *src, const struct cache_entry *old = src[0]; const struct cache_entry *a = src[1]; - if (o->merge_size != 1) + if (o->internal.merge_size != 1) return error("Cannot do a bind merge of %d trees", - o->merge_size); + o->internal.merge_size); if (a && old) return o->quiet ? -1 : error(ERRORMSG(o, ERROR_BIND_OVERLAP), @@ -2990,9 +2990,9 @@ int oneway_merge(const struct cache_entry * const *src, const struct cache_entry *old = src[0]; const struct cache_entry *a = src[1]; - if (o->merge_size != 1) + if (o->internal.merge_size != 1) return error("Cannot do a oneway merge of %d trees", - o->merge_size); + o->internal.merge_size); if (!a || a == o->df_conflict_entry) return deleted_entry(old, old, o); @@ -3027,8 +3027,8 @@ int stash_worktree_untracked_merge(const struct cache_entry * const *src, const struct cache_entry *worktree = src[1]; const struct cache_entry *untracked = src[2]; - if (o->merge_size != 2) - BUG("invalid merge_size: %d", o->merge_size); + if (o->internal.merge_size != 2) + BUG("invalid merge_size: %d", o->internal.merge_size); if (worktree && untracked) return error(_("worktree and untracked commit have duplicate entries: %s"), diff --git a/unpack-trees.h b/unpack-trees.h index 0335c89bc7..e8737adfed 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -65,7 +65,6 @@ struct unpack_trees_options { skip_unmerged, initial_checkout, diff_index_cached, - debug_unpack, skip_sparse_checkout, quiet, exiting_early, @@ -78,7 +77,6 @@ struct unpack_trees_options { merge_fn_t fn; int head_idx; - int merge_size; struct cache_entry *df_conflict_entry; void *unpack_data; @@ -90,8 +88,10 @@ struct unpack_trees_options { struct unpack_trees_options_internal { unsigned int nontrivial_merge, - show_all_errors; + show_all_errors, + debug_unpack; /* used by read-tree debugging */ + int merge_size; /* used by read-tree debugging */ int cache_bottom; const char *msgs[NB_UNPACK_TREES_WARNING_TYPES]; struct strvec msgs_to_free; From f297424a3a02b552865798ac8367cf657ef1df2d Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 27 Feb 2023 15:28:20 +0000 Subject: [PATCH 069/508] unpack-trees: add usage notices around df_conflict_entry Avoid making users believe they need to initialize df_conflict_entry to something (as happened with other output only fields before) with a quick comment and a small sanity check. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- unpack-trees.c | 2 ++ unpack-trees.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/unpack-trees.c b/unpack-trees.c index 3e5f4bd235..a37ab292bb 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1876,6 +1876,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options BUG("o->internal.dir is for internal use only"); if (o->internal.pl) BUG("o->internal.pl is for internal use only"); + if (o->df_conflict_entry) + BUG("o->df_conflict_entry is an output only field"); trace_performance_enter(); trace2_region_enter("unpack_trees", "unpack_trees", the_repository); diff --git a/unpack-trees.h b/unpack-trees.h index e8737adfed..61c06eb7c5 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -78,7 +78,7 @@ struct unpack_trees_options { int head_idx; - struct cache_entry *df_conflict_entry; + struct cache_entry *df_conflict_entry; /* output only */ void *unpack_data; struct index_state *dst_index; From c6ce27ab08d30dd9d626d7a56cb928bc5792eb27 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 12 Feb 2023 09:04:26 +0000 Subject: [PATCH 070/508] fetch: support hideRefs to speed up connectivity checks With roughly 800 remotes all fetching into their own refs/remotes/$REMOTE/* island, the connectivity check[1] gets expensive for each fetch on systems which lack sufficient RAM to cache objects. To do a no-op fetch on one $REMOTE out of hundreds, hideRefs now allows the no-op fetch to take ~30 seconds instead of ~20 minutes on a noisy, RAM-constrained machine (localhost, so no network latency): git -c fetch.hideRefs=refs \ -c fetch.hideRefs='!refs/remotes/$REMOTE/' \ fetch $REMOTE [1] `git rev-list --objects --stdin --not --all --quiet --alternate-refs' Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- Documentation/git-rev-parse.txt | 9 +++++---- Documentation/rev-list-options.txt | 9 +++++---- builtin/fetch.c | 2 ++ builtin/rev-list.c | 2 +- revision.c | 3 ++- t/t5510-fetch.sh | 9 +++++++++ t/t6018-rev-list-glob.sh | 2 +- t/t6021-rev-list-exclude-hidden.sh | 2 +- 8 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt index bcd8069287..f26a7591e3 100644 --- a/Documentation/git-rev-parse.txt +++ b/Documentation/git-rev-parse.txt @@ -197,10 +197,11 @@ respectively, and they must begin with `refs/` when applied to `--glob` or `--all`. If a trailing '/{asterisk}' is intended, it must be given explicitly. ---exclude-hidden=[receive|uploadpack]:: - Do not include refs that would be hidden by `git-receive-pack` or - `git-upload-pack` by consulting the appropriate `receive.hideRefs` or - `uploadpack.hideRefs` configuration along with `transfer.hideRefs` (see +--exclude-hidden=[fetch|receive|uploadpack]:: + Do not include refs that would be hidden by `git-fetch`, + `git-receive-pack` or `git-upload-pack` by consulting the appropriate + `fetch.hideRefs`, `receive.hideRefs` or `uploadpack.hideRefs` + configuration along with `transfer.hideRefs` (see linkgit:git-config[1]). This option affects the next pseudo-ref option `--all` or `--glob` and is cleared after processing them. diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt index 0d90d5b154..90c73d6708 100644 --- a/Documentation/rev-list-options.txt +++ b/Documentation/rev-list-options.txt @@ -195,10 +195,11 @@ respectively, and they must begin with `refs/` when applied to `--glob` or `--all`. If a trailing '/{asterisk}' is intended, it must be given explicitly. ---exclude-hidden=[receive|uploadpack]:: - Do not include refs that would be hidden by `git-receive-pack` or - `git-upload-pack` by consulting the appropriate `receive.hideRefs` or - `uploadpack.hideRefs` configuration along with `transfer.hideRefs` (see +--exclude-hidden=[fetch|receive|uploadpack]:: + Do not include refs that would be hidden by `git-fetch`, + `git-receive-pack` or `git-upload-pack` by consulting the appropriate + `fetch.hideRefs`, `receive.hideRefs` or `uploadpack.hideRefs` + configuration along with `transfer.hideRefs` (see linkgit:git-config[1]). This option affects the next pseudo-ref option `--all` or `--glob` and is cleared after processing them. diff --git a/builtin/fetch.c b/builtin/fetch.c index a09606b472..edbeb19d3b 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1132,6 +1132,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, if (!connectivity_checked) { struct check_connected_options opt = CHECK_CONNECTED_INIT; + opt.exclude_hidden_refs_section = "fetch"; rm = ref_map; if (check_connected(iterate_ref_map, &rm, &opt)) { rc = error(_("%s did not send all necessary objects\n"), url); @@ -1325,6 +1326,7 @@ static int check_exist_and_connected(struct ref *ref_map) } opt.quiet = 1; + opt.exclude_hidden_refs_section = "fetch"; return check_connected(iterate_ref_map, &rm, &opt); } diff --git a/builtin/rev-list.c b/builtin/rev-list.c index d42db0b0cc..2ab3efd233 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -38,7 +38,7 @@ static const char rev_list_usage[] = " --tags\n" " --remotes\n" " --stdin\n" -" --exclude-hidden=[receive|uploadpack]\n" +" --exclude-hidden=[fetch|receive|uploadpack]\n" " --quiet\n" " ordering output:\n" " --topo-order\n" diff --git a/revision.c b/revision.c index 21f5f572c2..50940699e4 100644 --- a/revision.c +++ b/revision.c @@ -1574,7 +1574,8 @@ void exclude_hidden_refs(struct ref_exclusions *exclusions, const char *section) { struct exclude_hidden_refs_cb cb; - if (strcmp(section, "receive") && strcmp(section, "uploadpack")) + if (strcmp(section, "fetch") && strcmp(section, "receive") && + strcmp(section, "uploadpack")) die(_("unsupported section for hidden refs: %s"), section); if (exclusions->hidden_refs_configured) diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 34a1261520..dc44da9c79 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -1171,6 +1171,15 @@ test_expect_success '--no-show-forced-updates' ' ) ' +for section in fetch transfer +do + test_expect_success "$section.hideRefs affects connectivity check" ' + GIT_TRACE="$PWD"/trace git -c $section.hideRefs=refs -c \ + $section.hideRefs="!refs/tags/" fetch && + grep "git rev-list .*--exclude-hidden=fetch" trace + ' +done + setup_negotiation_tip () { SERVER="$1" URL="$2" diff --git a/t/t6018-rev-list-glob.sh b/t/t6018-rev-list-glob.sh index aabf590dda..67d523d405 100755 --- a/t/t6018-rev-list-glob.sh +++ b/t/t6018-rev-list-glob.sh @@ -187,7 +187,7 @@ test_expect_success 'rev-parse --exclude=ref with --remotes=glob' ' compare rev-parse "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two" ' -for section in receive uploadpack +for section in fetch receive uploadpack do test_expect_success "rev-parse --exclude-hidden=$section with --all" ' compare "-c transfer.hideRefs=refs/remotes/ rev-parse" "--branches --tags" "--exclude-hidden=$section --all" diff --git a/t/t6021-rev-list-exclude-hidden.sh b/t/t6021-rev-list-exclude-hidden.sh index 11c50b7c0d..1a9d37e638 100755 --- a/t/t6021-rev-list-exclude-hidden.sh +++ b/t/t6021-rev-list-exclude-hidden.sh @@ -22,7 +22,7 @@ test_expect_success 'invalid section' ' test_cmp expected err ' -for section in receive uploadpack +for section in fetch receive uploadpack do test_expect_success "$section: passed multiple times" ' echo "fatal: --exclude-hidden= passed more than once" >expected && From ee8a88826af1137f0b192caa39b016032ac96af2 Mon Sep 17 00:00:00 2001 From: Andy Koppe Date: Sun, 26 Feb 2023 18:43:54 +0000 Subject: [PATCH 071/508] restore: fault --staged --worktree with merge opts The 'restore' command already rejects the --merge, --conflict, --ours and --theirs options when combined with --staged, but accepts them when --worktree is added as well. Unfortunately that doesn't appear to do anything useful. The --ours and --theirs options seem to be ignored when both --staged and --worktree are given, whereas with --merge or --conflict, the command has the same effect as if the --staged option wasn't present. So reject those options with '--staged --worktree' as well, using opts->accept_ref to distinguish restore from checkout. Add test for both '--staged' and '--staged --worktree'. Signed-off-by: Andy Koppe Signed-off-by: Junio C Hamano --- builtin/checkout.c | 29 +++++++++++++++++++++-------- t/t2070-restore.sh | 16 ++++++++++++++++ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 2a132392fb..25d269e2f8 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -487,15 +487,28 @@ static int checkout_paths(const struct checkout_opts *opts, die(_("'%s' must be used when '%s' is not specified"), "--worktree", "--source"); - if (opts->checkout_index && !opts->checkout_worktree && - opts->writeout_stage) - die(_("'%s' or '%s' cannot be used with %s"), - "--ours", "--theirs", "--staged"); + /* + * Reject --staged option to the restore command when combined with + * merge-related options. Use the accept_ref flag to distinguish it + * from the checkout command, which does not accept --staged anyway. + * + * `restore --ours|--theirs --worktree --staged` could mean resolving + * conflicted paths to one side in both the worktree and the index, + * but does not currently. + * + * `restore --merge|--conflict=