Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/main.yml10
-rw-r--r--.gitignore1
-rw-r--r--.mailmap1
-rw-r--r--Documentation/CodingGuidelines8
-rw-r--r--Documentation/MyFirstContribution.txt32
-rw-r--r--Documentation/MyFirstObjectWalk.txt28
-rw-r--r--Documentation/RelNotes/2.42.0.txt296
-rw-r--r--Documentation/SubmittingPatches141
-rw-r--r--Documentation/config.txt2
-rw-r--r--Documentation/config/advice.txt4
-rw-r--r--Documentation/config/feature.txt3
-rw-r--r--Documentation/config/gc.txt15
-rw-r--r--Documentation/config/pack.txt17
-rw-r--r--Documentation/diff-options.txt7
-rw-r--r--Documentation/git-bisect.txt11
-rw-r--r--Documentation/git-cat-file.txt15
-rw-r--r--Documentation/git-credential.txt2
-rw-r--r--Documentation/git-cvsserver.txt2
-rw-r--r--Documentation/git-describe.txt4
-rw-r--r--Documentation/git-diff.txt9
-rw-r--r--Documentation/git-for-each-ref.txt56
-rw-r--r--Documentation/git-format-patch.txt2
-rw-r--r--Documentation/git-hash-object.txt5
-rw-r--r--Documentation/git-interpret-trailers.txt134
-rw-r--r--Documentation/git-ls-files.txt6
-rw-r--r--Documentation/git-ls-remote.txt48
-rw-r--r--Documentation/git-ls-tree.txt8
-rw-r--r--Documentation/git-merge.txt11
-rw-r--r--Documentation/git-mktag.txt2
-rw-r--r--Documentation/git-notes.txt43
-rw-r--r--Documentation/git-pack-refs.txt29
-rw-r--r--Documentation/git-show-branch.txt16
-rw-r--r--Documentation/git-show-ref.txt40
-rw-r--r--Documentation/git-sparse-checkout.txt2
-rw-r--r--Documentation/git-stash.txt2
-rw-r--r--Documentation/git-submodule.txt31
-rw-r--r--Documentation/git-tag.txt10
-rw-r--r--Documentation/git-var.txt23
-rw-r--r--Documentation/git-worktree.txt16
-rw-r--r--Documentation/git.txt4
-rw-r--r--Documentation/gitattributes.txt5
-rw-r--r--Documentation/gitcredentials.txt13
-rw-r--r--Documentation/gitignore.txt10
-rw-r--r--Documentation/gitmodules.txt6
-rw-r--r--Documentation/gitweb.txt2
-rw-r--r--Documentation/object-format-disclaimer.txt15
-rw-r--r--Documentation/rev-list-options.txt9
-rw-r--r--Documentation/revisions.txt50
-rw-r--r--Documentation/technical/api-merge.txt4
-rw-r--r--Documentation/technical/remembering-renames.txt2
-rw-r--r--Documentation/urls-remotes.txt2
-rw-r--r--Documentation/user-manual.txt45
-rwxr-xr-xGIT-VERSION-GEN2
-rw-r--r--Makefile15
l---------RelNotes2
-rw-r--r--abspath.c36
-rw-r--r--abspath.h21
-rw-r--r--add-interactive.c6
-rw-r--r--add-patch.c17
-rw-r--r--advice.c1
-rw-r--r--advice.h1
-rw-r--r--alias.c4
-rw-r--r--alloc.h75
-rw-r--r--apply.c19
-rw-r--r--archive-tar.c8
-rw-r--r--archive-zip.c3
-rw-r--r--archive.c4
-rw-r--r--attr.c21
-rw-r--r--attr.h9
-rw-r--r--bisect.c3
-rw-r--r--blame.c10
-rw-r--r--blame.h1
-rw-r--r--branch.c17
-rw-r--r--builtin.h3
-rw-r--r--builtin/add.c113
-rw-r--r--builtin/am.c21
-rw-r--r--builtin/apply.c1
-rw-r--r--builtin/archive.c1
-rw-r--r--builtin/bisect.c3
-rw-r--r--builtin/blame.c8
-rw-r--r--builtin/branch.c46
-rw-r--r--builtin/bugreport.c1
-rw-r--r--builtin/bundle.c41
-rw-r--r--builtin/cat-file.c133
-rw-r--r--builtin/check-attr.c1
-rw-r--r--builtin/check-ignore.c1
-rw-r--r--builtin/check-mailmap.c1
-rw-r--r--builtin/check-ref-format.c3
-rw-r--r--builtin/checkout--worker.c2
-rw-r--r--builtin/checkout-index.c2
-rw-r--r--builtin/checkout.c23
-rw-r--r--builtin/clean.c12
-rw-r--r--builtin/clone.c23
-rw-r--r--builtin/column.c4
-rw-r--r--builtin/commit-graph.c8
-rw-r--r--builtin/commit-tree.c5
-rw-r--r--builtin/commit.c48
-rw-r--r--builtin/config.c92
-rw-r--r--builtin/count-objects.c8
-rw-r--r--builtin/credential-cache--daemon.c18
-rw-r--r--builtin/credential-cache.c2
-rw-r--r--builtin/credential-store.c34
-rw-r--r--builtin/describe.c24
-rw-r--r--builtin/diff-files.c5
-rw-r--r--builtin/diff-index.c6
-rw-r--r--builtin/diff-tree.c11
-rw-r--r--builtin/diff.c5
-rw-r--r--builtin/difftool.c13
-rw-r--r--builtin/fast-export.c3
-rw-r--r--builtin/fast-import.c5
-rw-r--r--builtin/fetch-pack.c1
-rw-r--r--builtin/fetch.c167
-rw-r--r--builtin/fmt-merge-msg.c1
-rw-r--r--builtin/for-each-ref.c9
-rw-r--r--builtin/for-each-repo.c3
-rw-r--r--builtin/fsck.c30
-rw-r--r--builtin/fsmonitor--daemon.c16
-rw-r--r--builtin/gc.c4
-rw-r--r--builtin/get-tar-commit-id.c4
-rw-r--r--builtin/grep.c22
-rw-r--r--builtin/hash-object.c3
-rw-r--r--builtin/help.c8
-rw-r--r--builtin/hook.c1
-rw-r--r--builtin/index-pack.c19
-rw-r--r--builtin/init-db.c475
-rw-r--r--builtin/interpret-trailers.c1
-rw-r--r--builtin/log.c38
-rw-r--r--builtin/ls-files.c263
-rw-r--r--builtin/ls-remote.c2
-rw-r--r--builtin/ls-tree.c134
-rw-r--r--builtin/mailinfo.c3
-rw-r--r--builtin/mailsplit.c1
-rw-r--r--builtin/merge-base.c1
-rw-r--r--builtin/merge-file.c1
-rw-r--r--builtin/merge-index.c2
-rw-r--r--builtin/merge-ours.c1
-rw-r--r--builtin/merge-recursive.c1
-rw-r--r--builtin/merge-tree.c8
-rw-r--r--builtin/merge.c24
-rw-r--r--builtin/mktag.c11
-rw-r--r--builtin/mktree.c4
-rw-r--r--builtin/multi-pack-index.c5
-rw-r--r--builtin/mv.c3
-rw-r--r--builtin/name-rev.c2
-rw-r--r--builtin/notes.c175
-rw-r--r--builtin/pack-objects.c46
-rw-r--r--builtin/pack-redundant.c2
-rw-r--r--builtin/pack-refs.c31
-rw-r--r--builtin/patch-id.c7
-rw-r--r--builtin/prune.c9
-rw-r--r--builtin/pull.c11
-rw-r--r--builtin/push.c37
-rw-r--r--builtin/range-diff.c2
-rw-r--r--builtin/read-tree.c9
-rw-r--r--builtin/rebase.c9
-rw-r--r--builtin/receive-pack.c27
-rw-r--r--builtin/reflog.c9
-rw-r--r--builtin/remote.c23
-rw-r--r--builtin/repack.c49
-rw-r--r--builtin/replace.c13
-rw-r--r--builtin/rerere.c2
-rw-r--r--builtin/reset.c37
-rw-r--r--builtin/rev-list.c5
-rw-r--r--builtin/rev-parse.c14
-rw-r--r--builtin/revert.c2
-rw-r--r--builtin/rm.c3
-rw-r--r--builtin/send-pack.c5
-rw-r--r--builtin/shortlog.c2
-rw-r--r--builtin/show-branch.c34
-rw-r--r--builtin/show-index.c1
-rw-r--r--builtin/show-ref.c3
-rw-r--r--builtin/sparse-checkout.c1
-rw-r--r--builtin/stash.c9
-rw-r--r--builtin/stripspace.c7
-rw-r--r--builtin/submodule--helper.c18
-rw-r--r--builtin/symbolic-ref.c2
-rw-r--r--builtin/tag.c56
-rw-r--r--builtin/unpack-file.c3
-rw-r--r--builtin/unpack-objects.c9
-rw-r--r--builtin/update-index.c5
-rw-r--r--builtin/update-ref.c3
-rw-r--r--builtin/update-server-info.c3
-rw-r--r--builtin/upload-archive.c2
-rw-r--r--builtin/upload-pack.c4
-rw-r--r--builtin/var.c174
-rw-r--r--builtin/verify-commit.c5
-rw-r--r--builtin/verify-pack.c2
-rw-r--r--builtin/verify-tag.c3
-rw-r--r--builtin/worktree.c244
-rw-r--r--builtin/write-tree.c1
-rw-r--r--bulk-checkin.c4
-rw-r--r--bundle-uri.c11
-rw-r--r--bundle.c6
-rw-r--r--cache-tree.c6
-rw-r--r--chunk-format.c1
-rwxr-xr-xci/lib.sh7
-rwxr-xr-xci/run-build-and-tests.sh1
-rw-r--r--color.c8
-rw-r--r--color.h6
-rw-r--r--combine-diff.c3
-rw-r--r--commit-graph.c122
-rw-r--r--commit-graph.h2
-rw-r--r--commit-reach.c3
-rw-r--r--commit.c4
-rw-r--r--compat/fsmonitor/fsm-health-darwin.c2
-rw-r--r--compat/fsmonitor/fsm-health-win32.c4
-rw-r--r--compat/fsmonitor/fsm-ipc-darwin.c3
-rw-r--r--compat/fsmonitor/fsm-listen-darwin.c3
-rw-r--r--compat/fsmonitor/fsm-listen-win32.c4
-rw-r--r--compat/fsmonitor/fsm-path-utils-darwin.c4
-rw-r--r--compat/fsmonitor/fsm-path-utils-win32.c5
-rw-r--r--compat/fsmonitor/fsm-settings-darwin.c2
-rw-r--r--compat/fsmonitor/fsm-settings-win32.c4
-rw-r--r--compat/mingw.c9
-rw-r--r--compat/mingw.h7
-rw-r--r--compat/precompose_utf8.c3
-rw-r--r--compat/sha1-chunked.c3
-rw-r--r--compat/simple-ipc/ipc-win32.c2
-rw-r--r--compat/terminal.c1
-rw-r--r--compat/win32/trace2_win32_process_info.c6
-rw-r--r--config.c607
-rw-r--r--config.h84
-rw-r--r--configure.ac11
-rw-r--r--connect.c5
-rw-r--r--connected.c2
-rw-r--r--contrib/buildsystems/CMakeLists.txt2
-rw-r--r--contrib/coccinelle/README40
-rw-r--r--contrib/coccinelle/config_fn_ctx.pending.cocci144
-rw-r--r--contrib/coccinelle/git_config_number.cocci27
-rw-r--r--contrib/completion/git-completion.bash59
-rw-r--r--convert.c34
-rw-r--r--copy.c1
-rw-r--r--credential.c8
-rw-r--r--credential.h2
-rw-r--r--csum-file.c1
-rw-r--r--ctype.c36
-rw-r--r--daemon.c63
-rw-r--r--decorate.c1
-rw-r--r--delta-islands.c5
-rw-r--r--diagnose.c2
-rw-r--r--diff-lib.c14
-rw-r--r--diff-no-index.c120
-rw-r--r--diff.c85
-rw-r--r--diff.h20
-rw-r--r--diffcore-break.c4
-rw-r--r--diffcore-order.c1
-rw-r--r--diffcore-pickaxe.c1
-rw-r--r--diffcore-rename.c3
-rw-r--r--dir-iterator.c1
-rw-r--r--dir.c12
-rw-r--r--dir.h19
-rw-r--r--editor.c1
-rw-r--r--entry.c7
-rw-r--r--environment.c12
-rw-r--r--environment.h6
-rw-r--r--ewah/bitmap.c1
-rw-r--r--ewah/ewah_bitmap.c1
-rw-r--r--exec-cmd.c3
-rw-r--r--fetch-pack.c10
-rw-r--r--fmt-merge-msg.c20
-rw-r--r--fmt-merge-msg.h3
-rw-r--r--fsck.c21
-rw-r--r--fsck.h4
-rw-r--r--fsmonitor-ipc.c4
-rw-r--r--fsmonitor-ll.h52
-rw-r--r--fsmonitor.c2
-rw-r--r--fsmonitor.h49
-rw-r--r--git-compat-util.h288
-rw-r--r--git.c3
-rw-r--r--gpg-interface.c13
-rw-r--r--grep.c10
-rw-r--r--grep.h4
-rw-r--r--hash-ll.h37
-rw-r--r--hash-lookup.c3
-rw-r--r--hashmap.h21
-rw-r--r--help.c10
-rw-r--r--hex.c2
-rw-r--r--hex.h10
-rw-r--r--hook.c1
-rw-r--r--http-backend.c7
-rw-r--r--http-push.c4
-rw-r--r--http-walker.c2
-rw-r--r--http.c26
-rw-r--r--ident.c5
-rw-r--r--ident.h4
-rw-r--r--imap-send.c42
-rw-r--r--khash.h3
-rw-r--r--kwset.c36
-rw-r--r--kwset.h2
-rw-r--r--line-log.c2
-rw-r--r--list-objects-filter-options.c1
-rw-r--r--list-objects-filter-options.h1
-rw-r--r--list-objects-filter.c3
-rw-r--r--list-objects.c4
-rw-r--r--log-tree.c6
-rw-r--r--log-tree.h2
-rw-r--r--ls-refs.c8
-rw-r--r--mailinfo.c5
-rw-r--r--mailmap.c2
-rw-r--r--match-trees.c3
-rw-r--r--merge-blobs.c4
-rw-r--r--merge-ll.c (renamed from ll-merge.c)44
-rw-r--r--merge-ll.h (renamed from ll-merge.h)0
-rw-r--r--merge-ort-wrappers.c3
-rw-r--r--merge-ort.c9
-rw-r--r--merge-recursive.c10
-rw-r--r--merge.c5
-rw-r--r--merge.h17
-rw-r--r--midx.c45
-rw-r--r--name-hash.c5
-rw-r--r--name-hash.h16
-rw-r--r--notes-cache.c3
-rw-r--r--notes-merge.c6
-rw-r--r--notes-utils.c4
-rw-r--r--notes.c6
-rw-r--r--notes.h19
-rw-r--r--object-file.c13
-rw-r--r--object-name.c20
-rw-r--r--object-name.h9
-rw-r--r--object-store-ll.h533
-rw-r--r--object-store.h528
-rw-r--r--object.c9
-rw-r--r--object.h2
-rw-r--r--oid-array.c1
-rw-r--r--oidmap.h1
-rw-r--r--oidtree.c1
-rw-r--r--oss-fuzz/fuzz-pack-idx.c2
-rw-r--r--pack-bitmap-write.c4
-rw-r--r--pack-bitmap.c264
-rw-r--r--pack-bitmap.h4
-rw-r--r--pack-check.c2
-rw-r--r--pack-mtimes.c3
-rw-r--r--pack-objects.c1
-rw-r--r--pack-objects.h2
-rw-r--r--pack-revindex.c3
-rw-r--r--pack-write.c3
-rw-r--r--packfile.c23
-rw-r--r--pager.c5
-rw-r--r--parallel-checkout.c5
-rw-r--r--parse-options.c16
-rw-r--r--parse-options.h6
-rw-r--r--patch-ids.c1
-rw-r--r--path.c23
-rw-r--r--path.h5
-rw-r--r--pathspec.c23
-rw-r--r--pathspec.h8
-rw-r--r--pkt-line.c13
-rw-r--r--pkt-line.h2
-rw-r--r--preload-index.c4
-rw-r--r--preload-index.h15
-rw-r--r--pretty.c111
-rw-r--r--prio-queue.c1
-rw-r--r--promisor-remote.c6
-rw-r--r--protocol-caps.c2
-rw-r--r--prune-packed.c2
-rw-r--r--quote.c1
-rw-r--r--range-diff.c1
-rw-r--r--reachable.c87
-rw-r--r--read-cache-ll.h (renamed from cache.h)148
-rw-r--r--read-cache.c348
-rw-r--r--read-cache.h45
-rw-r--r--rebase-interactive.c16
-rw-r--r--ref-filter.c465
-rw-r--r--ref-filter.h12
-rw-r--r--reflog-walk.c2
-rw-r--r--reflog.c2
-rw-r--r--refs.c97
-rw-r--r--refs.h37
-rw-r--r--refs/debug.c9
-rw-r--r--refs/files-backend.c35
-rw-r--r--refs/packed-backend.c209
-rw-r--r--refs/refs-internal.h10
-rw-r--r--refspec.c1
-rw-r--r--remote-curl.c4
-rw-r--r--remote.c22
-rw-r--r--remote.h4
-rw-r--r--replace-object.c30
-rw-r--r--replace-object.h32
-rw-r--r--repo-settings.c8
-rw-r--r--repository.c7
-rw-r--r--repository.h19
-rw-r--r--rerere.c12
-rw-r--r--resolve-undo.c4
-rw-r--r--revision.c100
-rw-r--r--revision.h9
-rw-r--r--run-command.c18
-rw-r--r--run-command.h4
-rw-r--r--sane-ctype.h66
-rw-r--r--scalar.c4
-rw-r--r--send-pack.c3
-rw-r--r--sequencer.c64
-rw-r--r--serve.c1
-rw-r--r--server-info.c5
-rw-r--r--setup.c524
-rw-r--r--setup.h9
-rw-r--r--sha1/openssl.h49
-rw-r--r--sha256/gcrypt.h13
-rw-r--r--sha256/openssl.h49
-rw-r--r--shallow.c8
-rw-r--r--sigchain.c1
-rw-r--r--sparse-index.c7
-rw-r--r--sparse-index.h2
-rw-r--r--split-index.c4
-rw-r--r--statinfo.c87
-rw-r--r--statinfo.h65
-rw-r--r--strbuf.c208
-rw-r--r--strbuf.h162
-rw-r--r--streaming.c3
-rw-r--r--string-list.c1
-rw-r--r--strvec.c1
-rw-r--r--submodule-config.c38
-rw-r--r--submodule-config.h3
-rw-r--r--submodule.c7
-rw-r--r--t/README10
-rw-r--r--t/annotate-tests.sh9
-rw-r--r--t/helper/test-cache-tree.c2
-rw-r--r--t/helper/test-config.c24
-rw-r--r--t/helper/test-delta.c1
-rw-r--r--t/helper/test-dump-cache-tree.c2
-rw-r--r--t/helper/test-dump-fsmonitor.c2
-rw-r--r--t/helper/test-dump-split-index.c5
-rw-r--r--t/helper/test-dump-untracked-cache.c2
-rw-r--r--t/helper/test-fast-rebase.c3
-rw-r--r--t/helper/test-fsmonitor-client.c3
-rw-r--r--t/helper/test-hash-speed.c2
-rw-r--r--t/helper/test-index-version.c2
-rw-r--r--t/helper/test-lazy-init-name-hash.c3
-rw-r--r--t/helper/test-oid-array.c2
-rw-r--r--t/helper/test-pack-mtimes.c2
-rw-r--r--t/helper/test-parse-options.c2
-rw-r--r--t/helper/test-partial-clone.c2
-rw-r--r--t/helper/test-path-utils.c2
-rw-r--r--t/helper/test-reach.c3
-rw-r--r--t/helper/test-read-cache.c3
-rw-r--r--t/helper/test-read-graph.c2
-rw-r--r--t/helper/test-read-midx.c2
-rw-r--r--t/helper/test-ref-store.c31
-rw-r--r--t/helper/test-repository.c2
-rw-r--r--t/helper/test-revision-walking.c1
-rw-r--r--t/helper/test-scrap-cache-tree.c2
-rw-r--r--t/helper/test-sha1.c2
-rw-r--r--t/helper/test-sha256.c2
-rw-r--r--t/helper/test-strcmp-offset.c2
-rw-r--r--t/helper/test-userdiff.c4
-rw-r--r--t/helper/test-wildmatch.c1
-rw-r--r--t/helper/test-write-cache.c2
-rwxr-xr-xt/lib-commit-graph.sh34
-rw-r--r--t/lib-credential.sh103
-rw-r--r--t/lib-gpg.sh24
-rwxr-xr-xt/perf/p2000-sparse-operations.sh3
-rwxr-xr-xt/t0000-basic.sh2
-rwxr-xr-xt/t0007-git-var.sh100
-rwxr-xr-xt/t0030-stripspace.sh560
-rwxr-xr-xt/t0040-parse-options.sh5
-rwxr-xr-xt/t0041-usage.sh1
-rwxr-xr-xt/t0091-bugreport.sh67
-rwxr-xr-xt/t0211-trace2-perf.sh4
-rwxr-xr-xt/t1001-read-tree-m-2way.sh2
-rwxr-xr-xt/t1002-read-tree-m-u-2way.sh589
-rwxr-xr-xt/t1006-cat-file.sh249
-rwxr-xr-xt/t1092-sparse-checkout-compatibility.sh79
-rwxr-xr-xt/t1300-config.sh27
-rwxr-xr-xt/t1301-shared-repo.sh22
-rwxr-xr-xt/t1419-exclude-refs.sh122
-rwxr-xr-xt/t1450-fsck.sh4
-rwxr-xr-xt/t1507-rev-parse-upstream.sh1
-rwxr-xr-xt/t1508-at-combinations.sh1
-rwxr-xr-xt/t1514-rev-parse-push.sh1
-rwxr-xr-xt/t1800-hook.sh20
-rwxr-xr-xt/t2027-checkout-track.sh1
-rwxr-xr-xt/t2200-add-update.sh11
-rwxr-xr-xt/t2400-worktree-add.sh507
-rwxr-xr-xt/t2407-worktree-heads.sh10
-rwxr-xr-xt/t3007-ls-files-recurse-submodules.sh33
-rwxr-xr-xt/t3013-ls-files-format.sh35
-rwxr-xr-xt/t3101-ls-tree-dirname.sh8
-rwxr-xr-xt/t3200-branch.sh1
-rwxr-xr-xt/t3202-show-branch.sh25
-rwxr-xr-xt/t3203-branch-output.sh16
-rwxr-xr-xt/t3204-branch-name-interpretation.sh1
-rwxr-xr-xt/t3210-pack-refs.sh191
-rwxr-xr-xt/t3301-notes.sh169
-rwxr-xr-xt/t3321-notes-stripspace.sh577
-rwxr-xr-xt/t3402-rebase-merge.sh1
-rwxr-xr-xt/t3404-rebase-interactive.sh26
-rwxr-xr-xt/t3500-cherry.sh69
-rwxr-xr-xt/t3700-add.sh34
-rwxr-xr-xt/t3701-add-interactive.sh38
-rwxr-xr-xt/t3903-stash.sh26
-rwxr-xr-xt/t4000-diff-format.sh34
-rwxr-xr-xt/t4002-diff-basic.sh243
-rwxr-xr-xt/t4003-diff-rename-1.sh62
-rwxr-xr-xt/t4004-diff-rename-symlink.sh42
-rwxr-xr-xt/t4053-diff-no-index.sh64
-rwxr-xr-xt/t4141-apply-too-large.sh2
-rwxr-xr-xt/t4202-log.sh23
-rwxr-xr-xt/t4203-mailmap.sh4
-rwxr-xr-xt/t4205-log-pretty-formats.sh17
-rwxr-xr-xt/t4206-log-follow-harder-copies.sh36
-rwxr-xr-xt/t5300-pack-object.sh184
-rwxr-xr-xt/t5301-sliding-window.sh100
-rwxr-xr-xt/t5303-pack-corruption-resilience.sh584
-rwxr-xr-xt/t5304-prune.sh14
-rwxr-xr-xt/t5306-pack-nobase.sh94
-rwxr-xr-xt/t5310-pack-bitmaps.sh38
-rwxr-xr-xt/t5318-commit-graph.sh388
-rwxr-xr-xt/t5319-multi-pack-index.sh12
-rwxr-xr-xt/t5324-split-commit-graph.sh3
-rwxr-xr-xt/t5326-multi-pack-bitmaps.sh35
-rwxr-xr-xt/t5328-commit-graph-64bit-time.sh54
-rwxr-xr-xt/t5329-pack-objects-cruft.sh171
-rwxr-xr-xt/t5351-unpack-large-objects.sh6
-rwxr-xr-xt/t5404-tracking-branches.sh1
-rwxr-xr-xt/t5516-fetch-push.sh11
-rwxr-xr-xt/t5517-push-mirror.sh1
-rwxr-xr-xt/t5525-fetch-tagopt.sh1
-rwxr-xr-xt/t5606-clone-options.sh10
-rwxr-xr-xt/t5616-partial-clone.sh10
-rwxr-xr-xt/t6017-rev-list-stdin.sh51
-rwxr-xr-xt/t6020-bundle-misc.sh6
-rwxr-xr-xt/t6040-tracking-info.sh1
-rwxr-xr-xt/t6050-replace.sh296
-rwxr-xr-xt/t6120-describe.sh8
-rwxr-xr-xt/t6135-pathspec-with-attrs.sh46
-rwxr-xr-xt/t6300-for-each-ref.sh365
-rwxr-xr-xt/t6302-for-each-ref-filter.sh2
-rwxr-xr-xt/t6406-merge-attr.sh23
-rwxr-xr-xt/t7004-tag.sh19
-rwxr-xr-xt/t7101-reset-empty-subdirs.sh48
-rwxr-xr-xt/t7102-reset.sh10
-rwxr-xr-xt/t7110-reset-merge.sh314
-rwxr-xr-xt/t7111-reset-table.sh20
-rwxr-xr-xt/t7201-co.sh92
-rwxr-xr-xt/t7400-submodule-basic.sh16
-rwxr-xr-xt/t7406-submodule-update.sh23
-rwxr-xr-xt/t7502-commit-porcelain.sh19
-rwxr-xr-xt/t7508-status.sh53
-rwxr-xr-xt/t7510-signed-commit.sh7
-rwxr-xr-xt/t7512-status-help.sh22
-rwxr-xr-xt/t7518-ident-corner-cases.sh11
-rwxr-xr-xt/t7600-merge.sh40
-rwxr-xr-xt/t7700-repack.sh67
-rwxr-xr-xt/t7701-repack-unpack-unreachable.sh42
-rwxr-xr-xt/t7814-grep-recurse-submodules.sh40
-rwxr-xr-xt/t9001-send-email.sh2
-rwxr-xr-xt/t9100-git-svn-basic.sh31
-rwxr-xr-xt/t9104-git-svn-follow-parent.sh62
-rwxr-xr-xt/t9200-git-cvsexportcommit.sh351
-rwxr-xr-xt/t9400-git-cvsserver-server.sh530
-rw-r--r--t/test-lib-functions.sh22
-rw-r--r--tag.c3
-rw-r--r--tempfile.c2
-rw-r--r--tmp-objdir.c3
-rw-r--r--trace.c1
-rw-r--r--trace2.c5
-rw-r--r--trace2.h11
-rw-r--r--trace2/tr2_cfg.c17
-rw-r--r--trace2/tr2_ctr.c15
-rw-r--r--trace2/tr2_sysenv.c3
-rw-r--r--trace2/tr2_tgt.h4
-rw-r--r--trace2/tr2_tgt_event.c4
-rw-r--r--trace2/tr2_tgt_normal.c4
-rw-r--r--trace2/tr2_tgt_perf.c4
-rw-r--r--trace2/tr2_tls.c1
-rw-r--r--trailer.c3
-rw-r--r--transport-helper.c2
-rw-r--r--transport.c4
-rw-r--r--tree-diff.c3
-rw-r--r--tree-walk.c39
-rw-r--r--tree-walk.h2
-rw-r--r--tree.c4
-rw-r--r--unpack-trees.c6
-rw-r--r--unpack-trees.h2
-rw-r--r--upload-pack.c68
-rw-r--r--urlmatch.c7
-rw-r--r--urlmatch.h8
-rw-r--r--usage.c1
-rw-r--r--userdiff.c1
-rw-r--r--versioncmp.c1
-rw-r--r--walker.c3
-rw-r--r--worktree.c9
-rw-r--r--wrapper.c22
-rw-r--r--wrapper.h106
-rw-r--r--write-or-die.c1
-rw-r--r--wt-status.c18
-rw-r--r--xdiff-interface.c8
-rw-r--r--xdiff-interface.h4
587 files changed, 13803 insertions, 7547 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 30492eacdd..079645b776 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -246,9 +246,6 @@ jobs:
fail-fast: false
matrix:
vector:
- - jobname: linux-clang
- cc: clang
- pool: ubuntu-latest
- jobname: linux-sha256
cc: clang
pool: ubuntu-latest
@@ -273,11 +270,8 @@ jobs:
- jobname: linux-leaks
cc: gcc
pool: ubuntu-latest
- - jobname: linux-asan
- cc: gcc
- pool: ubuntu-latest
- - jobname: linux-ubsan
- cc: gcc
+ - jobname: linux-asan-ubsan
+ cc: clang
pool: ubuntu-latest
env:
CC: ${{matrix.vector.cc}}
diff --git a/.gitignore b/.gitignore
index e875c59054..5e56e471b3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -222,6 +222,7 @@
/TAGS
/cscope*
/compile_commands.json
+/.cache/
*.hcc
*.obj
*.lib
diff --git a/.mailmap b/.mailmap
index 733e047aa8..dc31d70b8c 100644
--- a/.mailmap
+++ b/.mailmap
@@ -80,6 +80,7 @@ Frank Lichtenheld <frank@lichtenheld.de> <flichtenheld@astaro.com>
Fredrik Kuivinen <frekui@gmail.com> <freku045@student.liu.se>
Frédéric Heitzmann <frederic.heitzmann@gmail.com>
Garry Dolley <gdolley@ucla.edu> <gdolley@arpnetworks.com>
+Glen Choo <glencbz@gmail.com> <chooglen@google.com>
Greg Price <price@mit.edu> <price@MIT.EDU>
Greg Price <price@mit.edu> <price@ksplice.com>
Heiko Voigt <hvoigt@hvoigt.net> <git-list@hvoigt.net>
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 003393ed16..65af8d82ce 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -188,6 +188,10 @@ For shell scripts specifically (not exhaustive):
hopefully nobody starts using "local" before they are reimplemented
in C ;-)
+ - Use octal escape sequences (e.g. "\302\242"), not hexadecimal (e.g.
+ "\xc2\xa2") in printf format strings, since hexadecimal escape
+ sequences are not portable.
+
For C programs:
@@ -444,7 +448,7 @@ For C programs:
- The first #include in C files, except in platform specific compat/
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",
+ approved headers currently include "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.
@@ -687,7 +691,7 @@ Writing Documentation:
Do: [-q | --quiet]
Don't: [-q|--quiet]
- Don't use spacing around "|" tokens when they're used to seperate the
+ Don't use spacing around "|" tokens when they're used to separate the
alternate arguments of an option:
Do: --track[=(direct|inherit)]
Don't: --track[=(direct | inherit)]
diff --git a/Documentation/MyFirstContribution.txt b/Documentation/MyFirstContribution.txt
index 56130e4bec..62d11a5cd7 100644
--- a/Documentation/MyFirstContribution.txt
+++ b/Documentation/MyFirstContribution.txt
@@ -1256,6 +1256,38 @@ index 88f126184c..38da593a60 100644
[[now-what]]
== My Patch Got Emailed - Now What?
+Please give reviewers enough time to process your initial patch before
+sending an updated version. That is, resist the temptation to send a new
+version immediately, because others may have already started reviewing
+your initial version.
+
+While waiting for review comments, you may find mistakes in your initial
+patch, or perhaps realize a different and better way to achieve the goal
+of the patch. In this case you may communicate your findings to other
+reviewers as follows:
+
+ - If the mistakes you found are minor, send a reply to your patch as if
+ you were a reviewer and mention that you will fix them in an
+ updated version.
+
+ - On the other hand, if you think you want to change the course so
+ drastically that reviews on the initial patch would be a waste of
+ time (for everyone involved), retract the patch immediately with
+ a reply like "I am working on a much better approach, so please
+ ignore this patch and wait for the updated version."
+
+Now, the above is a good practice if you sent your initial patch
+prematurely without polish. But a better approach of course is to avoid
+sending your patch prematurely in the first place.
+
+Please be considerate of the time needed by reviewers to examine each
+new version of your patch. Rather than seeing the initial version right
+now (followed by several "oops, I like this version better than the
+previous one" patches over 2 days), reviewers would strongly prefer if a
+single polished version came 2 days later instead, and that version with
+fewer mistakes were the only one they would need to review.
+
+
[[reviewing]]
=== Responding to Reviews
diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt
index eee513e86f..c68cdb11b9 100644
--- a/Documentation/MyFirstObjectWalk.txt
+++ b/Documentation/MyFirstObjectWalk.txt
@@ -41,6 +41,7 @@ Open up a new file `builtin/walken.c` and set up the command handler:
*/
#include "builtin.h"
+#include "trace.h"
int cmd_walken(int argc, const char **argv, const char *prefix)
{
@@ -49,12 +50,13 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
}
----
-NOTE: `trace_printf()` differs from `printf()` in that it can be turned on or
-off at runtime. For the purposes of this tutorial, we will write `walken` as
-though it is intended for use as a "plumbing" command: that is, a command which
-is used primarily in scripts, rather than interactively by humans (a "porcelain"
-command). So we will send our debug output to `trace_printf()` instead. When
-running, enable trace output by setting the environment variable `GIT_TRACE`.
+NOTE: `trace_printf()`, defined in `trace.h`, differs from `printf()` in
+that it can be turned on or off at runtime. For the purposes of this
+tutorial, we will write `walken` as though it is intended for use as
+a "plumbing" command: that is, a command which is used primarily in
+scripts, rather than interactively by humans (a "porcelain" command).
+So we will send our debug output to `trace_printf()` instead.
+When running, enable trace output by setting the environment variable `GIT_TRACE`.
Add usage text and `-h` handling, like all subcommands should consistently do
(our test suite will notice and complain if you fail to do so).
@@ -124,7 +126,7 @@ parameters provided by the user over the CLI.
`nr` represents the number of `rev_cmdline_entry` present in the array.
-`alloc` is used by the `ALLOC_GROW` macro. Check `cache.h` - this variable is
+`alloc` is used by the `ALLOC_GROW` macro. Check `alloc.h` - this variable is
used to track the allocated size of the list.
Per entry, we find:
@@ -341,6 +343,10 @@ the walk loop below the `prepare_revision_walk()` call within your
`walken_commit_walk()`:
----
+#include "pretty.h"
+
+...
+
static void walken_commit_walk(struct rev_info *rev)
{
struct commit *commit;
@@ -754,6 +760,10 @@ reachable objects are walked in order to populate the list.
First, add the `struct oidset` and related items we will use to iterate it:
----
+#include "oidset.h"
+
+...
+
static void walken_object_walk(
...
@@ -805,6 +815,10 @@ just walks of commits. First, we'll make our handlers chattier - modify
go:
----
+#include "hex.h"
+
+...
+
static void walken_show_commit(struct commit *cmt, void *buf)
{
trace_printf("commit: %s\n", oid_to_hex(&cmt->object.oid));
diff --git a/Documentation/RelNotes/2.42.0.txt b/Documentation/RelNotes/2.42.0.txt
new file mode 100644
index 0000000000..f2262f84bf
--- /dev/null
+++ b/Documentation/RelNotes/2.42.0.txt
@@ -0,0 +1,296 @@
+Git v2.42 Release Notes
+=======================
+
+UI, Workflows & Features
+
+ * "git pack-refs" learns "--include" and "--exclude" to tweak the ref
+ hierarchy to be packed using pattern matching.
+
+ * 'git worktree add' learned how to create a worktree based on an
+ orphaned branch with `--orphan`.
+
+ * "git pack-objects" learned to invoke a new hook program that
+ enumerates extra objects to be used as anchoring points to keep
+ otherwise unreachable objects in cruft packs.
+
+ * Add more "git var" for toolsmiths to learn various locations Git is
+ configured with either via the configuration or hardcoded defaults.
+
+ * 'git notes append' was taught '--separator' to specify string to insert
+ between paragraphs.
+
+ * The "git for-each-ref" family of commands learned placeholders
+ related to GPG signature verification.
+
+ * "git diff --no-index" learned to read from named pipes as if they
+ were regular files, to allow "git diff <(process) <(substitution)"
+ some shells support.
+
+ * Help newbies by suggesting that there are cases where force-pushing
+ is a valid and sensible thing to update a branch at a remote
+ repository, rather than reconciling with merge/rebase.
+
+ * "git blame --contents=file" has been taught to work in a bare
+ repository.
+
+ * "git branch -f X" to repoint the branch X said that X was "checked
+ out" in another worktree, even when branch X was not and instead
+ being bisected or rebased. The message was reworded to say the
+ branch was "in use".
+
+ * Tone down the warning on SHA-256 repositories being an experimental
+ curiosity. We do not have support for them to interoperate with
+ traditional SHA-1 repositories, but at this point, we do not plan
+ to make breaking changes to SHA-256 repositories and there is no
+ longer need for such a strongly phrased warning.
+
+
+Performance, Internal Implementation, Development Support etc.
+
+ * "git diff-tree" has been taught to take advantage of the
+ sparse-index feature.
+
+ * Clang's sanitizer implementation seems to work better than GCC's.
+ (merge d88d727143 jk/ci-use-clang-for-sanitizer-jobs later to maint).
+
+ * The object traversal using reachability bitmap done by
+ "pack-object" has been tweaked to take advantage of the fact that
+ using "boundary" commits as representative of all the uninteresting
+ ones can save quite a lot of object enumeration.
+
+ * discover_git_directory() no longer touches the_repository.
+
+ * "git worktree" learned to work better with sparse index feature.
+
+ * When the external merge driver is killed by a signal, its output
+ should not be trusted as a resolution with conflicts that is
+ proposed by the driver, but the code did.
+
+ * The set-up code for the get_revision() API now allows feeding
+ options like --all and --not in the --stdin mode.
+
+ * Move functions that are not about pure string manipulation out of
+ strbuf.[ch]
+
+ * "imap-send" codepaths got cleaned up to get rid of unused
+ parameters.
+
+ * Enumerating refs in the packed-refs file, while excluding refs that
+ match certain patterns, has been optimized.
+
+ * Mark-up unused parameters in the code so that we can eventually
+ enable -Wunused-parameter by default.
+
+ * Instead of inventing a custom counter variables for debugging,
+ use existing trace2 facility in the fsync customization codepath.
+
+ * "git branch --list --format=<format>" and friends are taught
+ a new "%(describe)" placeholder.
+
+ * Clarify how to choose the starting point for a new topic in
+ developer guidance document.
+
+ * The implementation of "get_sha1_hex()" that reads a hexadecimal
+ string that spells a full object name has been extended to cope
+ with any hash function used in the repository, but the "sha1" in
+ its name survived. Rename it to get_hash_hex(), a name that is
+ more consistent within its friends like get_hash_hex_algop().
+
+ * Command line parser fix, and a small parse-options API update.
+
+
+Fixes since v2.41
+-----------------
+
+ * "git tag" learned to leave the "$GIT_DIR/TAG_EDITMSG" file when the
+ command failed, so that the user can salvage what they typed.
+ (merge 08c12ec1d0 kh/keep-tag-editmsg-upon-failure later to maint).
+
+ * The "-s" (silent, squelch) option of the "diff" family of commands
+ did not interact with other options that specify the output format
+ well. This has been cleaned up so that it will clear all the
+ formatting options given before.
+ (merge 9d484b92ed jc/diff-s-with-other-options later to maint).
+
+ * Update documentation regarding Coccinelle patches.
+ (merge 3bd0097cfc gc/doc-cocci-updates later to maint).
+
+ * Some atoms that can be used in "--format=<format>" for "git ls-tree"
+ were not supported by "git ls-files", even though they were relevant
+ in the context of the latter.
+ (merge 4d28c4f75f zh/ls-files-format-atoms later to maint).
+
+ * Document more pseudo-refs and teach the command line completion
+ machinery to complete AUTO_MERGE.
+ (merge 982ff3a649 pb/complete-and-document-auto-merge-and-friends later to maint).
+
+ * "git submodule" code trusted the data coming from the config (and
+ the in-tree .gitmodules file) too much without validating, leading
+ to NULL dereference if the user mucks with a repository (e.g.
+ submodule.<name>.url is removed). This has been corrected.
+ (merge fbc806acd1 tb/submodule-null-deref-fix later to maint).
+
+ * The value of config.worktree is per-repository, but has been kept
+ in a singleton global variable per process. This has been OK as
+ most Git operations interacted with a single repository at a time,
+ but not right for operations like recursive "grep" that want to
+ access multiple repositories from a single process without forking.
+
+ The global variable has been eliminated and made into a member in
+ the per-repository data structure.
+ (merge 3867f6d650 vd/worktree-config-is-per-repository later to maint).
+
+ * "git [-c log.follow=true] log [--follow] ':(glob)f**'" used to barf.
+ (merge 8260bc5902 jk/log-follow-with-non-literal-pathspec later to maint).
+
+ * Introduce a mechanism to disable replace refs globally and per
+ repository.
+ (merge 9c7d1b057f ds/disable-replace-refs later to maint).
+
+ * "git cat-file --batch" and friends learned "-Z" that uses NUL
+ delimiter for both input and output.
+ (merge f79e18849b ps/cat-file-null-output later to maint).
+
+ * The reimplemented "git add -i" did not honor color.ui configuration.
+ (merge 6f74648cea ds/add-i-color-configuration-fix later to maint).
+
+ * Compilation fix for platforms without D_TYPE in struct dirent.
+ (merge 03bf92b9bf as/dtype-compilation-fix later to maint).
+
+ * Suggest to refrain from using hex literals that are non-portable
+ when writing printf(1) format strings.
+ (merge f0b68f0546 jt/doc-use-octal-with-printf later to maint).
+
+ * Simplify error message when run-command fails to start a command.
+ (merge 6d224ac286 rs/run-command-exec-error-on-noent later to maint).
+
+ * Gracefully deal with a stale MIDX file that lists a packfile that
+ no longer exists.
+ (merge 06f3867865 tb/open-midx-bitmap-fallback later to maint).
+
+ * Even when diff.ignoreSubmodules tells us to ignore submodule
+ changes, "git commit" with an index that already records changes to
+ submodules should include the submodule changes in the resulting
+ commit, but it did not.
+ (merge 5768478edc js/defeat-ignore-submodules-config-with-explicit-addition later to maint).
+
+ * When "git commit --trailer=..." invokes the interpret-trailers
+ machinery, it knows what it feeds to interpret-trailers is a full
+ log message without any patch, but failed to express that by
+ passing the "--no-divider" option, which has been corrected.
+ (merge be3d654343 jk/commit-use-no-divider-with-interpret-trailers later to maint).
+
+ * Avoid breakage of "git pack-objects --cruft" due to inconsistency
+ between the way the code enumerates packfiles in the repository.
+ (merge 73320e49ad tb/collect-pack-filenames-fix later to maint).
+
+ * We create .pack and then .idx, we consider only packfiles that have
+ .idx usable (those with only .pack are not ready yet), so we should
+ remove .idx before removing .pack for consistency.
+ (merge 0dd1324a73 ds/remove-idx-before-pack later to maint).
+
+ * Partially revert a sanity check that the rest of the config code
+ was not ready, to avoid triggering it in a corner case.
+ (merge a53f43f900 gc/config-partial-submodule-kvi-fix later to maint).
+
+ * "git apply" punts when it is fed too large a patch input; the error
+ message it gives when it happens has been clarified.
+ (merge 42612e18d2 pw/apply-too-large later to maint).
+
+ * During a cherry-pick or revert session that works on multiple
+ commits, "git status" did not give correct information, which has
+ been corrected.
+ (merge a096a889f4 jk/cherry-pick-revert-status later to maint).
+
+ * A few places failed to differentiate the case where the index is
+ truly empty (nothing added) and we haven't yet read from the
+ on-disk index file, which have been corrected.
+ (merge 2ee045eea1 js/empty-index-fixes later to maint).
+
+ * "git bugreport" tests did not test what it wanted to test, which
+ has been corrected.
+ (merge 1aa92b8500 ma/t0091-fixup later to maint).
+
+ * Code snippets in a tutorial document no longer compiled after
+ recent header shuffling, which have been corrected.
+ (merge bbd7c7b7c0 vd/adjust-mfow-doc-to-updated-headers later to maint).
+
+ * "git ls-files '(attr:X)D/'" that triggers the common prefix
+ optimization codepath failed to read from "D/.gitattributes",
+ which has been corrected.
+ (merge f4a8fde057 jc/pathspec-match-with-common-prefix later to maint).
+
+ * "git fsck --no-progress" still spewed noise from the commit-graph
+ subsystem, which has been corrected.
+ (merge 9281cd07f0 tb/fsck-no-progress later to maint).
+
+ * Various offset computation in the code that accesses the packfiles
+ and other data in the object layer has been hardened against
+ arithmetic overflow, especially on 32-bit systems.
+ (merge 9a25cad7e0 tb/object-access-overflow-protection later to maint).
+
+ * Names of MinGW header files are spelled in mixed case in some
+ source files, but the build host can be using case sensitive
+ filesystem with header files with their name spelled in all
+ lowercase.
+ (merge 4a53d0d0bc mh/mingw-case-sensitive-build later to maint).
+
+ * Update message mark-up for i18n in "git bundle".
+ (merge bbb6acd998 dk/bundle-i18n-more later to maint).
+
+ * "git tag --list --points-at X" showed tags that directly refers to
+ object X, but did not list a tag that points at such a tag, which
+ has been corrected.
+
+ * "./configure --with-expat=no" did not work as a way to refuse use
+ of the expat library on a system with the library installed, which
+ has been corrected.
+ (merge fb8f7269c2 ah/autoconf-fixes later to maint).
+
+ * When the user edits "rebase -i" todo file so that it starts with a
+ "fixup", which would make it invalid, the command truncated the
+ rest of the file before giving an error and returning the control
+ back to the user. Stop truncating to make it easier to correct
+ such a malformed todo file.
+ (merge 9645a087c2 ah/sequencer-rewrite-todo-fix later to maint).
+
+ * Rewrite the description of giving a custom command to the
+ submodule.<name>.update configuration variable.
+ (merge 7cebc5bd78 pv/doc-submodule-update-settings later to maint).
+
+ * Other code cleanup, docfix, build fix, etc.
+ (merge 51f9d2e563 sa/doc-ls-remote later to maint).
+ (merge c6d26a9dda jk/format-patch-message-id-unleak later to maint).
+ (merge f7e063f326 ps/fetch-cleanups later to maint).
+ (merge e4cf013468 tl/quote-problematic-arg-for-clarity later to maint).
+ (merge 20025fdfc7 tz/test-ssh-verifytime-fix later to maint).
+ (merge e48a21df65 tz/test-fix-pthreads-prereq later to maint).
+ (merge 68b51172e3 mh/commit-reach-get-reachable-plug-leak later to maint).
+ (merge aeee1408ce kh/use-default-notes-doc later to maint).
+ (merge 3b8724bce6 jc/test-modernization later to maint).
+ (merge 447a3b7331 jc/test-modernization-2 later to maint).
+ (merge d57fa7fc73 la/doc-interpret-trailers later to maint).
+ (merge 548afb0d9a la/docs-typofixes later to maint).
+ (merge 3744ffcbcd rs/doc-ls-tree-hex-literal later to maint).
+ (merge 6c26da8404 mh/credential-erase-improvements later to maint).
+ (merge 78e56cff69 tz/lib-gpg-prereq-fix later to maint).
+ (merge 80d32e84b5 rj/leakfixes later to maint).
+ (merge 0a868031ed pb/complete-diff-options later to maint).
+ (merge d4f28279ad jc/doc-hash-object-types later to maint).
+ (merge 1876a5ae15 ks/t4205-test-describe-with-abbrev-fix later to maint).
+ (merge 6e6a529b57 jk/fsck-indices-in-worktrees later to maint).
+ (merge 3e81b896f7 rs/packet-length-simplify later to maint).
+ (merge 4c9cb51fe7 mh/doc-credential-helpers later to maint).
+ (merge 3437f549dd jr/gitignore-doc-example-markup later to maint).
+ (merge 947ebd62a0 jc/am-parseopt-fix later to maint).
+ (merge e12cb98e1e jc/branch-parseopt-fix later to maint).
+ (merge d6f598e443 jc/gitignore-doc-pattern-markup later to maint).
+ (merge a2dad4868b jc/transport-parseopt-fix later to maint).
+ (merge 68cbb20e73 jc/parse-options-show-branch later to maint).
+ (merge 3821eb6c3d jc/parse-options-reset later to maint).
+ (merge c48af99a3e bb/trace2-comment-fix later to maint).
+ (merge c95ae3ff9c rs/describe-parseopt-fix later to maint).
+ (merge 36f76d2a25 rs/pack-objects-parseopt-fix later to maint).
+ (merge 30c8c55cbf jc/tree-walk-drop-base-offset later to maint).
+ (merge d089a06421 rs/bundle-parseopt-cleanup later to maint).
+ (merge 823839bda1 ew/sha256-gcrypt-leak-fixes later to maint).
diff --git a/Documentation/SubmittingPatches b/Documentation/SubmittingPatches
index b218e27357..973d7a81d4 100644
--- a/Documentation/SubmittingPatches
+++ b/Documentation/SubmittingPatches
@@ -3,45 +3,101 @@ Submitting Patches
== Guidelines
-Here are some guidelines for people who want to contribute their code to this
-software. There is also a link:MyFirstContribution.html[step-by-step tutorial]
+Here are some guidelines for contributing back to this
+project. There is also a link:MyFirstContribution.html[step-by-step tutorial]
available which covers many of these same guidelines.
-[[base-branch]]
-=== Decide what to base your work on.
-
-In general, always base your work on the oldest branch that your
-change is relevant to.
-
-* A bugfix should be based on `maint` in general. If the bug is not
- present in `maint`, base it on `master`. For a bug that's not yet
- in `master`, find the topic that introduces the regression, and
- base your work on the tip of the topic.
-
-* A new feature should be based on `master` in general. If the new
- feature depends on other topics that are in `next`, but not in
- `master`, fork a branch from the tip of `master`, merge these topics
- to the branch, and work on that branch. You can remind yourself of
- how you prepared the base with `git log --first-parent master..`.
-
-* Corrections and enhancements to a topic not yet in `master` should
- be based on the tip of that topic. If the topic has not been merged
- to `next`, it's alright to add a note to squash minor corrections
- into the series.
-
-* In the exceptional case that a new feature depends on several topics
- not in `master`, start working on `next` or `seen` privately and
- send out patches only for discussion. Once your new feature starts
- to stabilize, you would have to rebase it (see the "depends on other
- topics" above).
-
-* Some parts of the system have dedicated maintainers with their own
- repositories (see the section "Subsystems" below). Changes to
- these parts should be based on their trees.
-
-To find the tip of a topic branch, run `git log --first-parent
-master..seen` and look for the merge commit. The second parent of this
-commit is the tip of the topic branch.
+[[choose-starting-point]]
+=== Choose a starting point.
+
+As a preliminary step, you must first choose a starting point for your
+work. Typically this means choosing a branch, although technically
+speaking it is actually a particular commit (typically the HEAD, or tip,
+of the branch).
+
+There are several important branches to be aware of. Namely, there are
+four integration branches as discussed in linkgit:gitworkflows[7]:
+
+* maint
+* master
+* next
+* seen
+
+The branches lower on the list are typically descendants of the ones
+that come before it. For example, `maint` is an "older" branch than
+`master` because `master` usually has patches (commits) on top of
+`maint`.
+
+There are also "topic" branches, which contain work from other
+contributors. Topic branches are created by the Git maintainer (in
+their fork) to organize the current set of incoming contributions on
+the mailing list, and are itemized in the regular "What's cooking in
+git.git" announcements. To find the tip of a topic branch, run `git log
+--first-parent master..seen` and look for the merge commit. The second
+parent of this commit is the tip of the topic branch.
+
+There is one guiding principle for choosing the right starting point: in
+general, always base your work on the oldest integration branch that
+your change is relevant to (see "Merge upwards" in
+linkgit:gitworkflows[7]). What this principle means is that for the
+vast majority of cases, the starting point for new work should be the
+latest HEAD commit of `maint` or `master` based on the following cases:
+
+* If you are fixing bugs in the released version, use `maint` as the
+ starting point (which may mean you have to fix things without using
+ new API features on the cutting edge that recently appeared in
+ `master` but were not available in the released version).
+
+* Otherwise (such as if you are adding new features) use `master`.
+
+
+NOTE: In exceptional cases, a bug that was introduced in an old
+version may have to be fixed for users of releases that are much older
+than the recent releases. `git describe --contains X` may describe
+`X` as `v2.30.0-rc2-gXXXXXX` for the commit `X` that introduced the
+bug, and the bug may be so high-impact that we may need to issue a new
+maintenance release for Git 2.30.x series, when "Git 2.41.0" is the
+current release. In such a case, you may want to use the tip of the
+maintenance branch for the 2.30.x series, which may be available in the
+`maint-2.30` branch in https://github.com/gitster/git[the maintainer's
+"broken out" repo].
+
+This also means that `next` or `seen` are inappropriate starting points
+for your work, if you want your work to have a realistic chance of
+graduating to `master`. They are simply not designed to be used as a
+base for new work; they are only there to make sure that topics in
+flight work well together. This is why both `next` and `seen` are
+frequently re-integrated with incoming patches on the mailing list and
+force-pushed to replace previous versions of themselves. A topic that is
+literally built on top of `next` cannot be merged to `master` without
+dragging in all the other topics in `next`, some of which may not be
+ready.
+
+For example, if you are making tree-wide changes, while somebody else is
+also making their own tree-wide changes, your work may have severe
+overlap with the other person's work. This situation may tempt you to
+use `next` as your starting point (because it would have the other
+person's work included in it), but doing so would mean you'll not only
+depend on the other person's work, but all the other random things from
+other contributors that are already integrated into `next`. And as soon
+as `next` is updated with a new version, all of your work will need to
+be rebased anyway in order for them to be cleanly applied by the
+maintainer.
+
+Under truly exceptional circumstances where you absolutely must depend
+on a select few topic branches that are already in `next` but not in
+`master`, you may want to create your own custom base-branch by forking
+`master` and merging the required topic branches to it. You could then
+work on top of this base-branch. But keep in mind that this base-branch
+would only be known privately to you. So when you are ready to send
+your patches to the list, be sure to communicate how you created it in
+your cover letter. This critical piece of information would allow
+others to recreate your base-branch on their end in order for them to
+try out your work.
+
+Finally, note that some parts of the system have dedicated maintainers
+with their own separate source code repositories (see the section
+"Subsystems" below).
[[separate-commits]]
=== Make separate commits for logically separate changes.
@@ -317,10 +373,13 @@ Please make sure your patch does not add commented out debugging code,
or include any extra files which do not relate to what your patch
is trying to achieve. Make sure to review
your patch after generating it, to ensure accuracy. Before
-sending out, please make sure it cleanly applies to the base you
-have chosen in the "Decide what to base your work on" section,
-and unless it targets the `master` branch (which is the default),
-mark your patches as such.
+sending out, please make sure it cleanly applies to the starting point you
+have chosen in the "Choose a starting point" section.
+
+NOTE: From the perspective of those reviewing your patch, the `master`
+branch is the default expected starting point. So if you have chosen a
+different starting point, please communicate this choice in your cover
+letter.
[[send-patches]]
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 0e93aef862..229b63a454 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -182,7 +182,7 @@ included, Git breaks the cycle by prohibiting these files from affecting
the resolution of these conditions (thus, prohibiting them from
declaring remote URLs).
+
-As for the naming of this keyword, it is for forwards compatibiliy with
+As for the naming of this keyword, it is for forwards compatibility with
a naming scheme that supports more variable-based include conditions,
but currently Git only supports the exact keyword described above.
diff --git a/Documentation/config/advice.txt b/Documentation/config/advice.txt
index c96b5b2e5d..c548a91e67 100644
--- a/Documentation/config/advice.txt
+++ b/Documentation/config/advice.txt
@@ -138,4 +138,8 @@ advice.*::
checkout.
diverging::
Advice shown when a fast-forward is not possible.
+ worktreeAddOrphan::
+ Advice shown when a user tries to create a worktree from an
+ invalid reference, to instruct how to create a new orphan
+ branch instead.
--
diff --git a/Documentation/config/feature.txt b/Documentation/config/feature.txt
index 17b4d39f89..bf9546fca4 100644
--- a/Documentation/config/feature.txt
+++ b/Documentation/config/feature.txt
@@ -14,6 +14,9 @@ feature.experimental::
+
* `fetch.negotiationAlgorithm=skipping` may improve fetch negotiation times by
skipping more commits at a time, reducing the number of round trips.
++
+* `pack.useBitmapBoundaryTraversal=true` may improve bitmap traversal times by
+walking fewer objects.
feature.manyFiles::
Enable config options that optimize for repos with many files in the
diff --git a/Documentation/config/gc.txt b/Documentation/config/gc.txt
index 7f95c866e1..ca47eb2008 100644
--- a/Documentation/config/gc.txt
+++ b/Documentation/config/gc.txt
@@ -130,6 +130,21 @@ or rebase occurring. Since these changes are not part of the current
project most users will want to expire them sooner, which is why the
default is more aggressive than `gc.reflogExpire`.
+gc.recentObjectsHook::
+ When considering whether or not to remove an object (either when
+ generating a cruft pack or storing unreachable objects as
+ loose), use the shell to execute the specified command(s).
+ Interpret their output as object IDs which Git will consider as
+ "recent", regardless of their age. By treating their mtimes as
+ "now", any objects (and their descendants) mentioned in the
+ output will be kept regardless of their true age.
++
+Output must contain exactly one hex object ID per line, and nothing
+else. Objects which cannot be found in the repository are ignored.
+Multiple hooks are supported, but all must exit successfully, else the
+operation (either generating a cruft pack or unpacking unreachable
+objects) will be halted.
+
gc.rerereResolved::
Records of conflicted merge you resolved earlier are
kept for this many days when 'git rerere gc' is run.
diff --git a/Documentation/config/pack.txt b/Documentation/config/pack.txt
index d4c7c9d4e4..3748136d14 100644
--- a/Documentation/config/pack.txt
+++ b/Documentation/config/pack.txt
@@ -123,6 +123,23 @@ pack.useBitmaps::
true. You should not generally need to turn this off unless
you are debugging pack bitmaps.
+pack.useBitmapBoundaryTraversal::
+ When true, Git will use an experimental algorithm for computing
+ reachability queries with bitmaps. Instead of building up
+ complete bitmaps for all of the negated tips and then OR-ing
+ them together, consider negated tips with existing bitmaps as
+ additive (i.e. OR-ing them into the result if they exist,
+ ignoring them otherwise), and build up a bitmap at the boundary
+ instead.
++
+When using this algorithm, Git may include too many objects as a result
+of not opening up trees belonging to certain UNINTERESTING commits. This
+inexactness matches the non-bitmap traversal algorithm.
++
+In many cases, this can provide a speed-up over the exact algorithm,
+particularly when there is poor bitmap coverage of the negated side of
+the query.
+
pack.useSparse::
When true, git will default to using the '--sparse' option in
'git pack-objects' when the '--revs' option is present. This
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 08ab86189a..9f33f88771 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -35,8 +35,11 @@ endif::git-diff[]
-s::
--no-patch::
- Suppress diff output. Useful for commands like `git show` that
- show the patch by default, or to cancel the effect of `--patch`.
+ Suppress all output from the diff machinery. Useful for
+ commands like `git show` that show the patch by default to
+ squelch their output, or to cancel the effect of options like
+ `--patch`, `--stat` earlier on the command line in an alias.
+
endif::git-format-patch[]
ifdef::git-log[]
diff --git a/Documentation/git-bisect.txt b/Documentation/git-bisect.txt
index fbb39fbdf5..7872dba3ae 100644
--- a/Documentation/git-bisect.txt
+++ b/Documentation/git-bisect.txt
@@ -204,9 +204,14 @@ as an alternative to `visualize`):
$ git bisect visualize
------------
-If the `DISPLAY` environment variable is not set, 'git log' is used
-instead. You can also give command-line options such as `-p` and
-`--stat`.
+Git detects a graphical environment through various environment variables:
+`DISPLAY`, which is set in X Window System environments on Unix systems.
+`SESSIONNAME`, which is set under Cygwin in interactive desktop sessions.
+`MSYSTEM`, which is set under Msys2 and Git for Windows.
+`SECURITYSESSIONID`, which may be set on macOS in interactive desktop sessions.
+
+If none of these environment variables is set, 'git log' is used instead.
+You can also give command-line options such as `-p` and `--stat`.
------------
$ git bisect visualize --stat
diff --git a/Documentation/git-cat-file.txt b/Documentation/git-cat-file.txt
index 411de2e27d..0e4936d182 100644
--- a/Documentation/git-cat-file.txt
+++ b/Documentation/git-cat-file.txt
@@ -14,7 +14,7 @@ SYNOPSIS
'git cat-file' (-t | -s) [--allow-unknown-type] <object>
'git cat-file' (--batch | --batch-check | --batch-command) [--batch-all-objects]
[--buffer] [--follow-symlinks] [--unordered]
- [--textconv | --filters] [-z]
+ [--textconv | --filters] [-Z]
'git cat-file' (--textconv | --filters)
[<rev>:<path|tree-ish> | --path=<path|tree-ish> <rev>]
@@ -243,10 +243,16 @@ respectively print:
/etc/passwd
--
+-Z::
+ Only meaningful with `--batch`, `--batch-check`, or
+ `--batch-command`; input and output is NUL-delimited instead of
+ newline-delimited.
+
-z::
Only meaningful with `--batch`, `--batch-check`, or
`--batch-command`; input is NUL-delimited instead of
- newline-delimited.
+ newline-delimited. This option is deprecated in favor of
+ `-Z` as the output can otherwise be ambiguous.
OUTPUT
@@ -384,6 +390,11 @@ notdir SP <size> LF
is printed when, during symlink resolution, a file is used as a
directory name.
+Alternatively, when `-Z` is passed, the line feeds in any of the above examples
+are replaced with NUL terminators. This ensures that output will be parsable if
+the output itself would contain a linefeed and is thus recommended for
+scripting purposes.
+
CAVEATS
-------
diff --git a/Documentation/git-credential.txt b/Documentation/git-credential.txt
index 0e6d9e85ec..a220afed4f 100644
--- a/Documentation/git-credential.txt
+++ b/Documentation/git-credential.txt
@@ -39,7 +39,7 @@ for later use.
If the action is `reject`, git-credential will send the description to
any configured credential helpers, which may erase any stored
-credential matching the description.
+credentials matching the description.
If the action is `approve` or `reject`, no output should be emitted.
diff --git a/Documentation/git-cvsserver.txt b/Documentation/git-cvsserver.txt
index 53f111bc0a..cf4a5a283e 100644
--- a/Documentation/git-cvsserver.txt
+++ b/Documentation/git-cvsserver.txt
@@ -118,7 +118,7 @@ for example:
myuser:$5$.NqmNH1vwfzGpV8B$znZIcumu1tNLATgV2l6e1/mY8RzhUDHMOaVOeL1cxV3
------
You can use the 'htpasswd' facility that comes with Apache to make these
-files, but only with the -d option (or -B if your system suports it).
+files, but only with the -d option (or -B if your system supports it).
Preferably use the system specific utility that manages password hash
creation in your platform (e.g. mkpasswd in Linux, encrypt in OpenBSD or
diff --git a/Documentation/git-describe.txt b/Documentation/git-describe.txt
index c6a79c2a0f..08ff715709 100644
--- a/Documentation/git-describe.txt
+++ b/Documentation/git-describe.txt
@@ -140,7 +140,7 @@ at the end.
The number of additional commits is the number
of commits which would be displayed by "git log v1.0.4..parent".
-The hash suffix is "-g" + an unambigous abbreviation for the tip commit
+The hash suffix is "-g" + an unambiguous abbreviation for the tip commit
of parent (which was `2414721b194453f058079d897d13c4e377f92dc6`). The
length of the abbreviation scales as the repository grows, using the
approximate number of objects in the repository and a bit of math
@@ -203,7 +203,7 @@ BUGS
Tree objects as well as tag objects not pointing at commits, cannot be described.
When describing blobs, the lightweight tags pointing at blobs are ignored,
-but the blob is still described as <committ-ish>:<path> despite the lightweight
+but the blob is still described as <commit-ish>:<path> despite the lightweight
tag being favorable.
GIT
diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt
index 52b679256c..08087ffad5 100644
--- a/Documentation/git-diff.txt
+++ b/Documentation/git-diff.txt
@@ -102,7 +102,11 @@ If --merge-base is given, use the merge base of the two commits for the
Just in case you are doing something exotic, it should be
noted that all of the <commit> in the above description, except
in the `--merge-base` case and in the last two forms that use `..`
-notations, can be any <tree>.
+notations, can be any <tree>. A tree of interest is the one pointed to
+by the special ref `AUTO_MERGE`, which is written by the 'ort' merge
+strategy upon hitting merge conflicts (see linkgit:git-merge[1]).
+Comparing the working tree with `AUTO_MERGE` shows changes you've made
+so far to resolve textual conflicts (see the examples below).
For a more complete list of ways to spell <commit>, see
"SPECIFYING REVISIONS" section in linkgit:gitrevisions[7].
@@ -152,6 +156,7 @@ Various ways to check your working tree::
$ git diff <1>
$ git diff --cached <2>
$ git diff HEAD <3>
+$ git diff AUTO_MERGE <4>
------------
+
<1> Changes in the working tree not yet staged for the next commit.
@@ -159,6 +164,8 @@ $ git diff HEAD <3>
would be committing if you run `git commit` without `-a` option.
<3> Changes in the working tree since your last commit; what you
would be committing if you run `git commit -a`
+<4> Changes in the working tree you've made to resolve textual
+ conflicts so far.
Comparing with arbitrary commits::
+
diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt
index 1e215d4e73..11b2bc3121 100644
--- a/Documentation/git-for-each-ref.txt
+++ b/Documentation/git-for-each-ref.txt
@@ -14,6 +14,7 @@ SYNOPSIS
[--points-at=<object>]
[--merged[=<object>]] [--no-merged[=<object>]]
[--contains[=<object>]] [--no-contains[=<object>]]
+ [--exclude=<pattern> ...]
DESCRIPTION
-----------
@@ -102,6 +103,11 @@ OPTIONS
Do not print a newline after formatted refs where the format expands
to the empty string.
+--exclude=<pattern>::
+ If one or more patterns are given, only refs which do not match
+ any excluded pattern(s) are shown. Matching is done using the
+ same rules as `<pattern>` above.
+
FIELD NAMES
-----------
@@ -221,6 +227,33 @@ symref::
`:lstrip` and `:rstrip` options in the same way as `refname`
above.
+signature::
+ The GPG signature of a commit.
+
+signature:grade::
+ Show "G" for a good (valid) signature, "B" for a bad
+ signature, "U" for a good signature with unknown validity, "X"
+ for a good signature that has expired, "Y" for a good
+ signature made by an expired key, "R" for a good signature
+ made by a revoked key, "E" if the signature cannot be
+ checked (e.g. missing key) and "N" for no signature.
+
+signature:signer::
+ The signer of the GPG signature of a commit.
+
+signature:key::
+ The key of the GPG signature of a commit.
+
+signature:fingerprint::
+ The fingerprint of the GPG signature of a commit.
+
+signature:primarykeyfingerprint::
+ The primary key fingerprint of the GPG signature of a commit.
+
+signature:trustlevel::
+ The trust level of the GPG signature of a commit. Possible
+ outputs are `ultimate`, `fully`, `marginal`, `never` and `undefined`.
+
worktreepath::
The absolute path to the worktree in which the ref is checked
out, if it is checked out in any linked worktree. Empty string
@@ -231,6 +264,29 @@ ahead-behind:<committish>::
commits ahead and behind, respectively, when comparing the output
ref to the `<committish>` specified in the format.
+describe[:options]::
+ A human-readable name, like linkgit:git-describe[1];
+ empty string for undescribable commits. The `describe` string may
+ be followed by a colon and one or more comma-separated options.
++
+--
+tags=<bool-value>;;
+ Instead of only considering annotated tags, consider
+ lightweight tags as well; see the corresponding option in
+ linkgit:git-describe[1] for details.
+abbrev=<number>;;
+ Use at least <number> hexadecimal digits; see the corresponding
+ option in linkgit:git-describe[1] for details.
+match=<pattern>;;
+ Only consider tags matching the given `glob(7)` pattern,
+ excluding the "refs/tags/" prefix; see the corresponding option
+ in linkgit:git-describe[1] for details.
+exclude=<pattern>;;
+ Do not consider tags matching the given `glob(7)` pattern,
+ excluding the "refs/tags/" prefix; see the corresponding option
+ in linkgit:git-describe[1] for details.
+--
+
In addition to the above, for commit and tag objects, the header
field names (`tree`, `parent`, `object`, `type`, and `tag`) can
be used to specify the value in the header field.
diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt
index b1c13fb39a..373b46fc0d 100644
--- a/Documentation/git-format-patch.txt
+++ b/Documentation/git-format-patch.txt
@@ -245,7 +245,7 @@ populated with placeholder text.
or "--reroll-count=4rev2" are allowed), but the downside of
using such a reroll-count is that the range-diff/interdiff
with the previous version does not state exactly which
- version the new interation is compared against.
+ version the new iteration is compared against.
--to=<email>::
Add a `To:` header to the email headers. This is in addition
diff --git a/Documentation/git-hash-object.txt b/Documentation/git-hash-object.txt
index 472b5bb995..8577f7a7d4 100644
--- a/Documentation/git-hash-object.txt
+++ b/Documentation/git-hash-object.txt
@@ -3,7 +3,7 @@ git-hash-object(1)
NAME
----
-git-hash-object - Compute object ID and optionally creates a blob from a file
+git-hash-object - Compute object ID and optionally create an object from a file
SYNOPSIS
@@ -25,7 +25,8 @@ OPTIONS
-------
-t <type>::
- Specify the type (default: "blob").
+ Specify the type of object to be created (default: "blob"). Possible
+ values are `commit`, `tree`, `blob`, and `tag`.
-w::
Actually write the object into the object database.
diff --git a/Documentation/git-interpret-trailers.txt b/Documentation/git-interpret-trailers.txt
index 4b97f812be..55d8961466 100644
--- a/Documentation/git-interpret-trailers.txt
+++ b/Documentation/git-interpret-trailers.txt
@@ -14,21 +14,38 @@ SYNOPSIS
DESCRIPTION
-----------
-Help parsing or adding 'trailers' lines, that look similar to RFC 822 e-mail
+Add or parse 'trailer' lines that look similar to RFC 822 e-mail
headers, at the end of the otherwise free-form part of a commit
-message.
+message. For example, in the following commit message
-This command reads some patches or commit messages from either the
-<file> arguments or the standard input if no <file> is specified. If
-`--parse` is specified, the output consists of the parsed trailers.
+------------------------------------------------
+subject
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+
+Signed-off-by: Alice <alice@example.com>
+Signed-off-by: Bob <bob@example.com>
+------------------------------------------------
+
+the last two lines starting with "Signed-off-by" are trailers.
+This command reads commit messages from either the
+<file> arguments or the standard input if no <file> is specified.
+If `--parse` is specified, the output consists of the parsed trailers.
Otherwise, this command applies the arguments passed using the
-`--trailer` option, if any, to the commit message part of each input
-file. The result is emitted on the standard output.
+`--trailer` option, if any, to each input file. The result is emitted on the
+standard output.
+
+This command can also operate on the output of linkgit:git-format-patch[1],
+which is more elaborate than a plain commit message. Namely, such output
+includes a commit message (as above), a "---" divider line, and a patch part.
+For these inputs, the divider and patch parts are not modified by
+this command and are emitted as is on the output, unless
+`--no-divider` is specified.
Some configuration variables control the way the `--trailer` arguments
-are applied to each commit message and the way any existing trailer in
-the commit message is changed. They also make it possible to
+are applied to each input and the way any existing trailer in
+the input is changed. They also make it possible to
automatically add some trailers.
By default, a '<token>=<value>' or '<token>:<value>' argument given
@@ -36,41 +53,46 @@ using `--trailer` will be appended after the existing trailers only if
the last trailer has a different (<token>, <value>) pair (or if there
is no existing trailer). The <token> and <value> parts will be trimmed
to remove starting and trailing whitespace, and the resulting trimmed
-<token> and <value> will appear in the message like this:
+<token> and <value> will appear in the output like this:
------------------------------------------------
token: value
------------------------------------------------
This means that the trimmed <token> and <value> will be separated by
-`': '` (one colon followed by one space).
+`': '` (one colon followed by one space). For convenience, the <token> can be a
+shortened string key (e.g., "sign") instead of the full string which should
+appear before the separator on the output (e.g., "Signed-off-by"). This can be
+configured using the 'trailer.<token>.key' configuration variable.
By default the new trailer will appear at the end of all the existing
trailers. If there is no existing trailer, the new trailer will appear
-after the commit message part of the output, and, if there is no line
-with only spaces at the end of the commit message part, one blank line
-will be added before the new trailer.
+at the end of the input. A blank line will be added before the new
+trailer if there isn't one already.
-Existing trailers are extracted from the input message by looking for
+Existing trailers are extracted from the input by looking for
a group of one or more lines that (i) is all trailers, or (ii) contains at
least one Git-generated or user-configured trailer and consists of at
least 25% trailers.
The group must be preceded by one or more empty (or whitespace-only) lines.
-The group must either be at the end of the message or be the last
+The group must either be at the end of the input or be the last
non-whitespace lines before a line that starts with '---' (followed by a
-space or the end of the line). Such three minus signs start the patch
-part of the message. See also `--no-divider` below.
+space or the end of the line).
When reading trailers, there can be no whitespace before or inside the
-token, but any number of regular space and tab characters are allowed
-between the token and the separator. There can be whitespaces before,
-inside or after the value. The value may be split over multiple lines
+<token>, but any number of regular space and tab characters are allowed
+between the <token> and the separator. There can be whitespaces before,
+inside or after the <value>. The <value> may be split over multiple lines
with each subsequent line starting with at least one whitespace, like
-the "folding" in RFC 822.
+the "folding" in RFC 822. Example:
+
+------------------------------------------------
+token: This is a very long value, with spaces and
+ newlines in it.
+------------------------------------------------
-Note that 'trailers' do not follow and are not intended to follow many
-rules for RFC 822 headers. For example they do not follow
-the encoding rules and probably many other rules.
+Note that trailers do not follow (nor are they intended to follow) many of the
+rules for RFC 822 headers. For example they do not follow the encoding rule.
OPTIONS
-------
@@ -79,12 +101,12 @@ OPTIONS
--trim-empty::
If the <value> part of any trailer contains only whitespace,
- the whole trailer will be removed from the resulting message.
+ the whole trailer will be removed from the output.
This applies to existing trailers as well as new trailers.
--trailer <token>[(=|:)<value>]::
Specify a (<token>, <value>) pair that should be applied as a
- trailer to the input messages. See the description of this
+ trailer to the inputs. See the description of this
command.
--where <placement>::
@@ -98,7 +120,7 @@ OPTIONS
--if-exists <action>::
--no-if-exists::
Specify what action will be performed when there is already at
- least one trailer with the same <token> in the message. A setting
+ least one trailer with the same <token> in the input. A setting
provided with '--if-exists' overrides all configuration variables
and applies to all '--trailer' options until the next occurrence of
'--if-exists' or '--no-if-exists'. Possible actions are `addIfDifferent`,
@@ -107,7 +129,7 @@ OPTIONS
--if-missing <action>::
--no-if-missing::
Specify what action will be performed when there is no other
- trailer with the same <token> in the message. A setting
+ trailer with the same <token> in the input. A setting
provided with '--if-missing' overrides all configuration variables
and applies to all '--trailer' options until the next occurrence of
'--if-missing' or '--no-if-missing'. Possible actions are `doNothing`
@@ -174,7 +196,7 @@ first trailer with the same <token>.
trailer.ifexists::
This option makes it possible to choose what action will be
performed when there is already at least one trailer with the
- same <token> in the message.
+ same <token> in the input.
+
The valid values for this option are: `addIfDifferentNeighbor` (this
is the default), `addIfDifferent`, `add`, `replace` or `doNothing`.
@@ -184,10 +206,10 @@ trailer with the same (<token>, <value>) pair is above or below the line
where the new trailer will be added.
+
With `addIfDifferent`, a new trailer will be added only if no trailer
-with the same (<token>, <value>) pair is already in the message.
+with the same (<token>, <value>) pair is already in the input.
+
With `add`, a new trailer will be added, even if some trailers with
-the same (<token>, <value>) pair are already in the message.
+the same (<token>, <value>) pair are already in the input.
+
With `replace`, an existing trailer with the same <token> will be
deleted and the new trailer will be added. The deleted trailer will be
@@ -195,12 +217,12 @@ the closest one (with the same <token>) to the place where the new one
will be added.
+
With `doNothing`, nothing will be done; that is no new trailer will be
-added if there is already one with the same <token> in the message.
+added if there is already one with the same <token> in the input.
trailer.ifmissing::
This option makes it possible to choose what action will be
performed when there is not yet any trailer with the same
- <token> in the message.
+ <token> in the input.
+
The valid values for this option are: `add` (this is the default) and
`doNothing`.
@@ -235,13 +257,13 @@ trailer.<token>.ifmissing::
that option for trailers with the specified <token>.
trailer.<token>.command::
+ Deprecated in favor of 'trailer.<token>.cmd'.
This option behaves in the same way as 'trailer.<token>.cmd', except
that it doesn't pass anything as argument to the specified command.
Instead the first occurrence of substring $ARG is replaced by the
- value that would be passed as argument.
+ <value> that would be passed as argument.
+
-The 'trailer.<token>.command' option has been deprecated in favor of
-'trailer.<token>.cmd' due to the fact that $ARG in the user's command is
+Note that $ARG in the user's command is
only replaced once and that the original way of replacing $ARG is not safe.
+
When both 'trailer.<token>.cmd' and 'trailer.<token>.command' are given
@@ -249,10 +271,10 @@ for the same <token>, 'trailer.<token>.cmd' is used and
'trailer.<token>.command' is ignored.
trailer.<token>.cmd::
- This option can be used to specify a shell command that will be called:
+ This option can be used to specify a shell command that will be called
once to automatically add a trailer with the specified <token>, and then
- each time a '--trailer <token>=<value>' argument to modify the <value> of
- the trailer that this option would produce.
+ called each time a '--trailer <token>=<value>' argument is specified to
+ modify the <value> of the trailer that this option would produce.
+
When the specified command is first called to add a trailer
with the specified <token>, the behavior is as if a special
@@ -272,37 +294,37 @@ EXAMPLES
--------
* Configure a 'sign' trailer with a 'Signed-off-by' key, and then
- add two of these trailers to a message:
+ add two of these trailers to a commit message file:
+
------------
$ git config trailer.sign.key "Signed-off-by"
$ cat msg.txt
subject
-message
+body text
$ git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>' <msg.txt
subject
-message
+body text
Signed-off-by: Alice <alice@example.com>
Signed-off-by: Bob <bob@example.com>
------------
-* Use the `--in-place` option to edit a message file in place:
+* Use the `--in-place` option to edit a commit message file in place:
+
------------
$ cat msg.txt
subject
-message
+body text
Signed-off-by: Bob <bob@example.com>
$ git interpret-trailers --trailer 'Acked-by: Alice <alice@example.com>' --in-place msg.txt
$ cat msg.txt
subject
-message
+body text
Signed-off-by: Bob <bob@example.com>
Acked-by: Alice <alice@example.com>
@@ -325,7 +347,7 @@ $ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Re
$ cat msg1.txt
subject
-message
+body text
$ git config trailer.sign.key "Signed-off-by: "
$ git config trailer.sign.ifmissing add
$ git config trailer.sign.ifexists doNothing
@@ -333,19 +355,19 @@ $ git config trailer.sign.cmd 'echo "$(git config user.name) <$(git config user.
$ git interpret-trailers --trailer sign <msg1.txt
subject
-message
+body text
Signed-off-by: Bob <bob@example.com>
$ cat msg2.txt
subject
-message
+body text
Signed-off-by: Alice <alice@example.com>
$ git interpret-trailers --trailer sign <msg2.txt
subject
-message
+body text
Signed-off-by: Alice <alice@example.com>
------------
@@ -373,14 +395,14 @@ test -n "$1" && git log --author="$1" --pretty="%an <%ae>" -1 || true
$ cat msg.txt
subject
-message
+body text
$ git config trailer.help.key "Helped-by: "
$ git config trailer.help.ifExists "addIfDifferentNeighbor"
$ git config trailer.help.cmd "~/bin/glog-find-author"
$ git interpret-trailers --trailer="help:Junio" --trailer="help:Couder" <msg.txt
subject
-message
+body text
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Christian Couder <christian.couder@gmail.com>
@@ -397,14 +419,14 @@ test -n "$1" && git log --grep "$1" --pretty=reference -1 || true
$ cat msg.txt
subject
-message
+body text
$ git config trailer.ref.key "Reference-to: "
$ git config trailer.ref.ifExists "replace"
$ git config trailer.ref.cmd "~/bin/glog-grep"
$ git interpret-trailers --trailer="ref:Add copyright notices." <msg.txt
subject
-message
+body text
Reference-to: 8bc9a0c769 (Add copyright notices., 2005-04-07)
------------
@@ -416,7 +438,7 @@ Reference-to: 8bc9a0c769 (Add copyright notices., 2005-04-07)
$ cat msg.txt
subject
-message
+body text
see: HEAD~2
$ cat ~/bin/glog-ref
@@ -429,7 +451,7 @@ $ git config trailer.see.cmd "glog-ref"
$ git interpret-trailers --trailer=see <msg.txt
subject
-message
+body text
See-also: fe3187489d69c4 (subject of related commit)
------------
diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt
index 1abdd3c21c..1bc0328bb7 100644
--- a/Documentation/git-ls-files.txt
+++ b/Documentation/git-ls-files.txt
@@ -270,8 +270,14 @@ interpolated. The following "fieldname" are understood:
objectmode::
The mode of the file which is recorded in the index.
+objecttype::
+ The object type of the file which is recorded in the index.
objectname::
The name of the file which is recorded in the index.
+objectsize[:padded]::
+ The object size of the file which is recorded in the index
+ ("-" if the object is a `commit` or `tree`).
+ It also supports a padded format of size with "%(objectsize:padded)".
stage::
The stage of the file which is recorded in the index.
eolinfo:index::
diff --git a/Documentation/git-ls-remote.txt b/Documentation/git-ls-remote.txt
index ff3da547dd..1c4f696ab5 100644
--- a/Documentation/git-ls-remote.txt
+++ b/Documentation/git-ls-remote.txt
@@ -96,27 +96,51 @@ OPTIONS
separator (so `bar` matches `refs/heads/bar` but not
`refs/heads/foobar`).
+OUTPUT
+------
+
+The output is in the format:
+
+------------
+<oid> TAB <ref> LF
+------------
+
+When showing an annotated tag, unless `--refs` is given, two such
+lines are shown: one with the refname for the tag itself as `<ref>`,
+and another with `<ref>` followed by `^{}`. The `<oid>` on the latter
+line shows the name of the object the tag points at.
+
EXAMPLES
--------
+* List all references (including symbolics and pseudorefs), peeling
+ tags:
++
+----
+$ git ls-remote
+27d43aaaf50ef0ae014b88bba294f93658016a2e HEAD
+950264636c68591989456e3ba0a5442f93152c1a refs/heads/main
+d9ab777d41f92a8c1684c91cfb02053d7dd1046b refs/heads/next
+d4ca2e3147b409459955613c152220f4db848ee1 refs/tags/v2.40.0
+73876f4861cd3d187a4682290ab75c9dccadbc56 refs/tags/v2.40.0^{}
----
-$ git ls-remote --tags .
-d6602ec5194c87b0fc87103ca4d67251c76f233a refs/tags/v0.99
-f25a265a342aed6041ab0cc484224d9ca54b6f41 refs/tags/v0.99.1
-7ceca275d047c90c0c7d5afb13ab97efdf51bd6e refs/tags/v0.99.3
-c5db5456ae3b0873fc659c19fafdde22313cc441 refs/tags/v0.99.2
-0918385dbd9656cab0d1d81ba7453d49bbc16250 refs/tags/junio-gpg-pub
+* List all references matching given patterns:
++
+----
$ git ls-remote http://www.kernel.org/pub/scm/git/git.git master seen rc
5fe978a5381f1fbad26a80e682ddd2a401966740 refs/heads/master
c781a84b5204fb294c9ccc79f8b3baceeb32c061 refs/heads/seen
+----
-$ git remote add korg http://www.kernel.org/pub/scm/git/git.git
-$ git ls-remote --tags korg v\*
-d6602ec5194c87b0fc87103ca4d67251c76f233a refs/tags/v0.99
-f25a265a342aed6041ab0cc484224d9ca54b6f41 refs/tags/v0.99.1
-c5db5456ae3b0873fc659c19fafdde22313cc441 refs/tags/v0.99.2
-7ceca275d047c90c0c7d5afb13ab97efdf51bd6e refs/tags/v0.99.3
+* List only tags matching a given wildcard pattern:
++
+----
+$ git ls-remote --tags http://www.kernel.org/pub/scm/git/git.git v\*
+485a869c64a68cc5795dd99689797c5900f4716d refs/tags/v2.39.2
+cbf04937d5b9fcf0a76c28f69e6294e9e3ecd7e6 refs/tags/v2.39.2^{}
+d4ca2e3147b409459955613c152220f4db848ee1 refs/tags/v2.40.0
+73876f4861cd3d187a4682290ab75c9dccadbc56 refs/tags/v2.40.0^{}
----
SEE ALSO
diff --git a/Documentation/git-ls-tree.txt b/Documentation/git-ls-tree.txt
index 0240adb8ee..6572095d8d 100644
--- a/Documentation/git-ls-tree.txt
+++ b/Documentation/git-ls-tree.txt
@@ -86,9 +86,9 @@ OPTIONS
--format=<format>::
A string that interpolates `%(fieldname)` from the result
being shown. It also interpolates `%%` to `%`, and
- `%xx` where `xx` are hex digits interpolates to character
- with hex code `xx`; for example `%00` interpolates to
- `\0` (NUL), `%09` to `\t` (TAB) and `%0a` to `\n` (LF).
+ `%xNN` where `NN` are hex digits interpolates to character
+ with hex code `NN`; for example `%x00` interpolates to
+ `\0` (NUL), `%x09` to `\t` (TAB) and `%x0a` to `\n` (LF).
When specified, `--format` cannot be combined with other
format-altering options, including `--long`, `--name-only`
and `--object-only`.
@@ -145,7 +145,7 @@ FIELD NAMES
-----------
Various values from structured fields can be used to interpolate
-into the resulting output. For each outputing line, the following
+into the resulting output. For each outputting line, the following
names can be used:
objectmode::
diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt
index 0aeff572a5..8625c5cb0e 100644
--- a/Documentation/git-merge.txt
+++ b/Documentation/git-merge.txt
@@ -194,9 +194,13 @@ happens:
versions: stage 1 stores the version from the common ancestor,
stage 2 from `HEAD`, and stage 3 from `MERGE_HEAD` (you
can inspect the stages with `git ls-files -u`). The working
- tree files contain the result of the "merge" program; i.e. 3-way
+ tree files contain the result of the merge operation; i.e. 3-way
merge results with familiar conflict markers `<<<` `===` `>>>`.
-5. No other changes are made. In particular, the local
+5. A special ref `AUTO_MERGE` is written, pointing to a tree
+ corresponding to the current content of the working tree (including
+ conflict markers for textual conflicts). Note that this ref is only
+ written when the 'ort' merge strategy is used (the default).
+6. No other changes are made. In particular, the local
modifications you had before you started merge will stay the
same and the index entries for them stay as they were,
i.e. matching `HEAD`.
@@ -336,7 +340,8 @@ You can work through the conflict with a number of tools:
* Look at the diffs. `git diff` will show a three-way diff,
highlighting changes from both the `HEAD` and `MERGE_HEAD`
- versions.
+ versions. `git diff AUTO_MERGE` will show what changes you've
+ made so far to resolve textual conflicts.
* Look at the diffs from each branch. `git log --merge -p <path>`
will show diffs first for the `HEAD` version and then the
diff --git a/Documentation/git-mktag.txt b/Documentation/git-mktag.txt
index 466a697519..b2a2e80d42 100644
--- a/Documentation/git-mktag.txt
+++ b/Documentation/git-mktag.txt
@@ -33,7 +33,7 @@ from warnings to errors (so e.g. a missing "tagger" line is an error).
Extra headers in the object are also an error under mktag, but ignored
by linkgit:git-fsck[1]. This extra check can be turned off by setting
-the appropriate `fsck.<msg-id>` varible:
+the appropriate `fsck.<msg-id>` variable:
git -c fsck.extraHeaderEntry=ignore mktag <my-tag-with-headers
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index efbc10f0f5..bc1bfa3791 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -9,10 +9,10 @@ SYNOPSIS
--------
[verse]
'git notes' [list [<object>]]
-'git notes' add [-f] [--allow-empty] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
+'git notes' add [-f] [--allow-empty] [--[no-]separator | --separator=<paragraph-break>] [--[no-]stripspace] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
'git notes' copy [-f] ( --stdin | <from-object> [<to-object>] )
-'git notes' append [--allow-empty] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
-'git notes' edit [--allow-empty] [<object>]
+'git notes' append [--allow-empty] [--[no-]separator | --separator=<paragraph-break>] [--[no-]stripspace] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
+'git notes' edit [--allow-empty] [<object>] [--[no-]stripspace]
'git notes' show [<object>]
'git notes' merge [-v | -q] [-s <strategy> ] <notes-ref>
'git notes' merge --commit [-v | -q]
@@ -65,7 +65,9 @@ add::
However, if you're using `add` interactively (using an editor
to supply the notes contents), then - instead of aborting -
the existing notes will be opened in the editor (like the `edit`
- subcommand).
+ subcommand). If you specify multiple `-m` and `-F`, a blank
+ line will be inserted between the messages. Use the `--separator`
+ option to insert other delimiters.
copy::
Copy the notes for the first object onto the second object (defaults to
@@ -85,8 +87,12 @@ corresponding <to-object>. (The optional `<rest>` is ignored so that
the command can read the input given to the `post-rewrite` hook.)
append::
- Append to the notes of an existing object (defaults to HEAD).
- Creates a new notes object if needed.
+ Append new message(s) given by `-m` or `-F` options to an
+ existing note, or add them as a new note if one does not
+ exist, for the object (defaults to HEAD). When appending to
+ an existing note, a blank line is added before each new
+ message as an inter-paragraph separator. The separator can
+ be customized with the `--separator` option.
edit::
Edit the notes for a given object (defaults to HEAD).
@@ -135,20 +141,26 @@ OPTIONS
If multiple `-m` options are given, their values
are concatenated as separate paragraphs.
Lines starting with `#` and empty lines other than a
- single line between paragraphs will be stripped out.
+ single line between paragraphs will be stripped out,
+ if you wish to keep them verbatim, use `--no-stripspace`.
-F <file>::
--file=<file>::
Take the note message from the given file. Use '-' to
read the note message from the standard input.
Lines starting with `#` and empty lines other than a
- single line between paragraphs will be stripped out.
+ single line between paragraphs will be stripped out,
+ if you wish to keep them verbatim, use with
+ `--no-stripspace` option.
-C <object>::
--reuse-message=<object>::
Take the given blob object (for example, another note) as the
note message. (Use `git notes copy <object>` instead to
- copy notes between objects.)
+ copy notes between objects.). By default, message will be
+ copied verbatim, but if you wish to strip out the lines
+ starting with `#` and empty lines other than a single line
+ between paragraphs, use with`--stripspace` option.
-c <object>::
--reedit-message=<object>::
@@ -159,6 +171,19 @@ OPTIONS
Allow an empty note object to be stored. The default behavior is
to automatically remove empty notes.
+--[no-]separator, --separator=<paragraph-break>::
+ Specify a string used as a custom inter-paragraph separator
+ (a newline is added at the end as needed). If `--no-separator`, no
+ separators will be added between paragraphs. Defaults to a blank
+ line.
+
+--[no-]stripspace::
+ Strip leading and trailing whitespace from the note message.
+ Also strip out empty lines other than a single line between
+ paragraphs. For lines starting with `#` will be stripped out
+ in non-editor cases like "-m", "-F" and "-C", but not in
+ editor case like "git notes edit", "-c", etc.
+
--ref <ref>::
Manipulate the notes tree in <ref>. This overrides
`GIT_NOTES_REF` and the "core.notesRef" configuration. The ref
diff --git a/Documentation/git-pack-refs.txt b/Documentation/git-pack-refs.txt
index 154081f2de..284956acb3 100644
--- a/Documentation/git-pack-refs.txt
+++ b/Documentation/git-pack-refs.txt
@@ -8,7 +8,7 @@ git-pack-refs - Pack heads and tags for efficient repository access
SYNOPSIS
--------
[verse]
-'git pack-refs' [--all] [--no-prune]
+'git pack-refs' [--all] [--no-prune] [--include <pattern>] [--exclude <pattern>]
DESCRIPTION
-----------
@@ -51,14 +51,37 @@ The command by default packs all tags and refs that are already
packed, and leaves other refs
alone. This is because branches are expected to be actively
developed and packing their tips does not help performance.
-This option causes branch tips to be packed as well. Useful for
-a repository with many branches of historical interests.
+This option causes all refs to be packed as well, with the exception
+of hidden refs, broken refs, and symbolic refs. Useful for a repository
+with many branches of historical interests.
--no-prune::
The command usually removes loose refs under `$GIT_DIR/refs`
hierarchy after packing them. This option tells it not to.
+--include <pattern>::
+
+Pack refs based on a `glob(7)` pattern. Repetitions of this option
+accumulate inclusion patterns. If a ref is both included in `--include` and
+`--exclude`, `--exclude` takes precedence. Using `--include` will preclude all
+tags from being included by default. Symbolic refs and broken refs will never
+be packed. When used with `--all`, it will be a noop. Use `--no-include` to clear
+and reset the list of patterns.
+
+--exclude <pattern>::
+
+Do not pack refs matching the given `glob(7)` pattern. Repetitions of this option
+accumulate exclusion patterns. Use `--no-exclude` to clear and reset the list of
+patterns. If a ref is already packed, including it with `--exclude` will not
+unpack it.
+
+When used with `--all`, pack only loose refs which do not match any of
+the provided `--exclude` patterns.
+
+When used with `--include`, refs provided to `--include`, minus refs that are
+provided to `--exclude` will be packed.
+
BUGS
----
diff --git a/Documentation/git-show-branch.txt b/Documentation/git-show-branch.txt
index 71f608b1ff..58cf6210cd 100644
--- a/Documentation/git-show-branch.txt
+++ b/Documentation/git-show-branch.txt
@@ -74,8 +74,7 @@ OPTIONS
that is the common ancestor of all the branches. This
flag tells the command to go <n> more common commits
beyond that. When <n> is negative, display only the
- <reference>s given, without showing the commit ancestry
- tree.
+ <ref>s given, without showing the commit ancestry tree.
--list::
Synonym to `--more=-1`
@@ -88,8 +87,8 @@ OPTIONS
the case of three or more commits.
--independent::
- Among the <reference>s given, display only the ones that
- cannot be reached from any other <reference>.
+ Among the <ref>s given, display only the ones that cannot be
+ reached from any other <ref>.
--no-name::
Do not show naming strings for each commit.
@@ -132,10 +131,11 @@ are mutually exclusive.
OUTPUT
------
-Given N <references>, the first N lines are the one-line
-description from their commit message. The branch head that is
-pointed at by $GIT_DIR/HEAD is prefixed with an asterisk `*`
-character while other heads are prefixed with a `!` character.
+
+Given N <ref>s, the first N lines are the one-line description from
+their commit message. The branch head that is pointed at by
+$GIT_DIR/HEAD is prefixed with an asterisk `*` character while other
+heads are prefixed with a `!` character.
Following these N lines, one-line log for each commit is
displayed, indented N places. If a commit is on the I-th
diff --git a/Documentation/git-show-ref.txt b/Documentation/git-show-ref.txt
index d1d56f68b4..44c7387d78 100644
--- a/Documentation/git-show-ref.txt
+++ b/Documentation/git-show-ref.txt
@@ -23,7 +23,7 @@ particular ref exists.
By default, shows the tags, heads, and remote refs.
-The --exclude-existing form is a filter that does the inverse. It reads
+The `--exclude-existing` form is a filter that does the inverse. It reads
refs from stdin, one ref per line, and shows those that don't exist in
the local repository.
@@ -47,14 +47,14 @@ OPTIONS
-d::
--dereference::
- Dereference tags into object IDs as well. They will be shown with "{caret}{}"
+ Dereference tags into object IDs as well. They will be shown with `{caret}{}`
appended.
-s::
--hash[=<n>]::
- Only show the SHA-1 hash, not the reference name. When combined with
- --dereference the dereferenced tag will still be shown after the SHA-1.
+ Only show the OID, not the reference name. When combined with
+ `--dereference`, the dereferenced tag will still be shown after the OID.
--verify::
@@ -70,15 +70,15 @@ OPTIONS
-q::
--quiet::
- Do not print any results to stdout. When combined with `--verify` this
+ Do not print any results to stdout. When combined with `--verify`, this
can be used to silently check if a reference exists.
--exclude-existing[=<pattern>]::
- Make 'git show-ref' act as a filter that reads refs from stdin of the
- form "`^(?:<anything>\s)?<refname>(?:\^{})?$`"
+ Make `git show-ref` act as a filter that reads refs from stdin of the
+ form `^(?:<anything>\s)?<refname>(?:\^{})?$`
and performs the following actions on each:
- (1) strip "{caret}{}" at the end of line if any;
+ (1) strip `{caret}{}` at the end of line if any;
(2) ignore if pattern is provided and does not head-match refname;
(3) warn if refname is not a well-formed refname and skip;
(4) ignore if refname is a ref that exists in the local repository;
@@ -96,7 +96,13 @@ OPTIONS
OUTPUT
------
-The output is in the format: '<SHA-1 ID>' '<space>' '<reference name>'.
+The output is in the format:
+
+------------
+<oid> SP <ref> LF
+------------
+
+For example,
-----------------------------------------------------------------------------
$ git show-ref --head --dereference
@@ -110,7 +116,13 @@ $ git show-ref --head --dereference
...
-----------------------------------------------------------------------------
-When using --hash (and not --dereference) the output format is: '<SHA-1 ID>'
+When using `--hash` (and not `--dereference`), the output is in the format:
+
+------------
+<oid> LF
+------------
+
+For example,
-----------------------------------------------------------------------------
$ git show-ref --heads --hash
@@ -142,10 +154,10 @@ When using the `--verify` flag, the command requires an exact path:
will only match the exact branch called "master".
-If nothing matches, 'git show-ref' will return an error code of 1,
+If nothing matches, `git show-ref` will return an error code of 1,
and in the case of verification, it will show an error message.
-For scripting, you can ask it to be quiet with the "--quiet" flag, which
+For scripting, you can ask it to be quiet with the `--quiet` flag, which
allows you to do things like
-----------------------------------------------------------------------------
@@ -157,11 +169,11 @@ to check whether a particular branch exists or not (notice how we don't
actually want to show any results, and we want to use the full refname for it
in order to not trigger the problem with ambiguous partial matches).
-To show only tags, or only proper branch heads, use "--tags" and/or "--heads"
+To show only tags, or only proper branch heads, use `--tags` and/or `--heads`
respectively (using both means that it shows tags and heads, but not other
random references under the refs/ subdirectory).
-To do automatic tag object dereferencing, use the "-d" or "--dereference"
+To do automatic tag object dereferencing, use the `-d` or `--dereference`
flag, so you can do
-----------------------------------------------------------------------------
diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt
index 53dc17aa77..529a8edd9c 100644
--- a/Documentation/git-sparse-checkout.txt
+++ b/Documentation/git-sparse-checkout.txt
@@ -286,7 +286,7 @@ patterns in non-cone mode has a number of shortcomings:
problem above? Also, if it suggests paths, what if the user has a
file or directory that begins with either a '!' or '#' or has a '*',
'\', '?', '[', or ']' in its name? And if it suggests paths, will
- it complete "/pro" to "/proc" (in the root filesytem) rather than to
+ it complete "/pro" to "/proc" (in the root filesystem) rather than to
"/progress.txt" in the current directory? (Note that users are
likely to want to start paths with a leading '/' in non-cone mode,
for the same reason that .gitignore files often have one.)
diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
index f4bb6114d9..06fb7f1d18 100644
--- a/Documentation/git-stash.txt
+++ b/Documentation/git-stash.txt
@@ -366,7 +366,7 @@ only the commit ends-up being in the stash and not on the current branch.
# ... hack hack hack ...
$ git add --patch foo # add unrelated changes to the index
$ git stash push --staged # save these changes to the stash
-# ... hack hack hack, finish curent changes ...
+# ... hack hack hack, finish current changes ...
$ git commit -m 'Massive' # commit fully tested changes
$ git switch fixup-branch # switch to another branch
$ git stash pop # to finish work on the saved changes
diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index 4d3ab6b9f9..695730609a 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -95,7 +95,7 @@ too (and can also report changes to a submodule's work tree).
init [--] [<path>...]::
Initialize the submodules recorded in the index (which were
added and committed elsewhere) by setting `submodule.$name.url`
- in .git/config. It uses the same setting from `.gitmodules` as
+ in `.git/config`, using the same setting from `.gitmodules` as
a template. If the URL is relative, it will be resolved using
the default remote. If there is no default remote, the current
repository will be assumed to be upstream.
@@ -105,9 +105,12 @@ If no path is specified and submodule.active has been configured, submodules
configured to be active will be initialized, otherwise all submodules are
initialized.
+
-When present, it will also copy the value of `submodule.$name.update`.
-This command does not alter existing information in .git/config.
-You can then customize the submodule clone URLs in .git/config
+It will also copy the value of `submodule.$name.update`, if present in
+the `.gitmodules` file, to `.git/config`, but (1) this command does not
+alter existing information in `.git/config`, and (2) `submodule.$name.update`
+that is set to a custom command is *not* copied for security reasons.
++
+You can then customize the submodule clone URLs in `.git/config`
for your local setup and proceed to `git submodule update`;
you can also just use `git submodule update --init` without
the explicit 'init' step if you do not intend to customize
@@ -143,6 +146,8 @@ the submodules. The "updating" can be done in several ways depending
on command line options and the value of `submodule.<name>.update`
configuration variable. The command line option takes precedence over
the configuration variable. If neither is given, a 'checkout' is performed.
+(note: what is in `.gitmodules` file is irrelevant at this point;
+see `git submodule init` above for how `.gitmodules` is used).
The 'update' procedures supported both from the command line as well as
through the `submodule.<name>.update` configuration are:
@@ -160,16 +165,18 @@ checked out in the submodule.
merge;; the commit recorded in the superproject will be merged
into the current branch in the submodule.
-The following 'update' procedures are only available via the
-`submodule.<name>.update` configuration variable:
+The following update procedures have additional limitations:
- custom command;; arbitrary shell command that takes a single
- argument (the sha1 of the commit recorded in the
- superproject) is executed. When `submodule.<name>.update`
- is set to '!command', the remainder after the exclamation mark
- is the custom command.
+ custom command;; mechanism for running arbitrary commands with the
+ commit ID as an argument. Specifically, if the
+ `submodule.<name>.update` configuration variable is set to
+ `!custom command`, the object name of the commit recorded in the
+ superproject for the submodule is appended to the `custom command`
+ string and executed. Note that this mechanism is not supported in
+ the `.gitmodules` file or on the command line.
- none;; the submodule is not updated.
+ none;; the submodule is not updated. This update procedure is not
+ allowed on the command line.
If the submodule is not yet initialized, and you just want to use the
setting as stored in `.gitmodules`, you can automatically initialize the
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index 7f61c1edb3..d42efb3112 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -381,6 +381,16 @@ $ GIT_COMMITTER_DATE="2006-10-02 10:31" git tag -s v1.0.1
include::date-formats.txt[]
+FILES
+-----
+
+`$GIT_DIR/TAG_EDITMSG`::
+ This file contains the message of an in-progress annotated
+ tag. If `git tag` exits due to an error before creating an
+ annotated tag then the tag message that has been provided by the
+ user in an editor session will be available in this file, but
+ may be overwritten by the next invocation of `git tag`.
+
NOTES
-----
diff --git a/Documentation/git-var.txt b/Documentation/git-var.txt
index f40202b8e3..c38fb3968b 100644
--- a/Documentation/git-var.txt
+++ b/Documentation/git-var.txt
@@ -71,6 +71,29 @@ endif::git-default-pager[]
GIT_DEFAULT_BRANCH::
The name of the first branch created in newly initialized repositories.
+GIT_SHELL_PATH::
+ The path of the binary providing the POSIX shell for commands which use the shell.
+
+GIT_ATTR_SYSTEM::
+ The path to the system linkgit:gitattributes[5] file, if one is enabled.
+
+GIT_ATTR_GLOBAL::
+ The path to the global (per-user) linkgit:gitattributes[5] file.
+
+GIT_CONFIG_SYSTEM::
+ The path to the system configuration file, if one is enabled.
+
+GIT_CONFIG_GLOBAL::
+ The path to the global (per-user) configuration files, if any.
+
+Most path values contain only one value. However, some can contain multiple
+values, which are separated by newlines, and are listed in order from highest to
+lowest priority. Callers should be prepared for any such path value to contain
+multiple items.
+
+Note that paths are printed even if they do not exist, but not if they are
+disabled by other environment variables.
+
SEE ALSO
--------
linkgit:git-commit-tree[1]
diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
index 063d6eeb99..a4fbf5e838 100644
--- a/Documentation/git-worktree.txt
+++ b/Documentation/git-worktree.txt
@@ -10,7 +10,7 @@ SYNOPSIS
--------
[verse]
'git worktree add' [-f] [--detach] [--checkout] [--lock [--reason <string>]]
- [-b <new-branch>] <path> [<commit-ish>]
+ [--orphan] [(-b | -B) <new-branch>] <path> [<commit-ish>]
'git worktree list' [-v | --porcelain [-z]]
'git worktree lock' [--reason <string>] <worktree>
'git worktree move' <worktree> <new-path>
@@ -95,6 +95,16 @@ exist, a new branch based on `HEAD` is automatically created as if
`-b <branch>` was given. If `<branch>` does exist, it will be checked out
in the new worktree, if it's not checked out anywhere else, otherwise the
command will refuse to create the worktree (unless `--force` is used).
++
+If `<commit-ish>` is omitted, neither `--detach`, or `--orphan` is
+used, and there are no valid local branches (or remote branches if
+`--guess-remote` is specified) then, as a convenience, the new worktree is
+associated with a new orphan branch named `<branch>` (after
+`$(basename <path>)` if neither `-b` or `-B` is used) as if `--orphan` was
+passed to the command. In the event the repository has a remote and
+`--guess-remote` is used, but no remote or local branches exist, then the
+command fails with a warning reminding the user to fetch from their remote
+first (or override by using `-f/--force`).
list::
@@ -222,6 +232,10 @@ This can also be set up as the default behaviour by using the
With `prune`, do not remove anything; just report what it would
remove.
+--orphan::
+ With `add`, make the new worktree and index empty, associating
+ the worktree with a new orphan/unborn branch named `<new-branch>`.
+
--porcelain::
With `list`, output in an easy-to-parse format for scripts.
This format will remain stable across Git versions and regardless of user
diff --git a/Documentation/git.txt b/Documentation/git.txt
index f0cafa2290..11228956cd 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -553,8 +553,8 @@ double-quotes and respecting backslash escapes. E.g., the value
If this variable is set, the default hash algorithm for new
repositories will be set to this value. This value is
ignored when cloning and the setting of the remote repository
- is always used. The default is "sha1". THIS VARIABLE IS
- EXPERIMENTAL! See `--object-format` in linkgit:git-init[1].
+ is always used. The default is "sha1".
+ See `--object-format` in linkgit:git-init[1].
Git Commits
~~~~~~~~~~~
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 02a3ec83e4..6deb89a296 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -1132,7 +1132,10 @@ size (see below).
The merge driver is expected to leave the result of the merge in
the file named with `%A` by overwriting it, and exit with zero
status if it managed to merge them cleanly, or non-zero if there
-were conflicts.
+were conflicts. When the driver crashes (e.g. killed by SEGV),
+it is expected to exit with non-zero status that are higher than
+128, and in such a case, the merge results in a failure (which is
+different from producing a conflict).
The `merge.*.recursive` variable specifies what other merge
driver to use when the merge driver is called for an internal
diff --git a/Documentation/gitcredentials.txt b/Documentation/gitcredentials.txt
index 100f045bb1..71dd19731a 100644
--- a/Documentation/gitcredentials.txt
+++ b/Documentation/gitcredentials.txt
@@ -104,6 +104,17 @@ $ git help credential-foo
$ git config --global credential.helper foo
-------------------------------------------
+=== Available helpers
+
+The community maintains a comprehensive list of Git credential helpers at
+https://git-scm.com/doc/credential-helpers.
+
+=== OAuth
+
+An alternative to inputting passwords or personal access tokens is to use an
+OAuth credential helper. Initial authentication opens a browser window to the
+host. Subsequent authentication happens in the background. Many popular Git
+hosts support OAuth.
CREDENTIAL CONTEXTS
-------------------
@@ -260,7 +271,7 @@ appended to its command line, which is one of:
`erase`::
- Remove a matching credential, if any, from the helper's storage.
+ Remove matching credentials, if any, from the helper's storage.
The details of the credential will be provided on the helper's stdin
stream. The exact format is the same as the input/output format of the
diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index 4c17f2356c..5e0964ef41 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -88,7 +88,7 @@ PATTERN FORMAT
Put a backslash ("`\`") in front of the first "`!`" for patterns
that begin with a literal "`!`", for example, "`\!important!.txt`".
- - The slash '/' is used as the directory separator. Separators may
+ - The slash "`/`" is used as the directory separator. Separators may
occur at the beginning, middle or end of the `.gitignore` search pattern.
- If there is a separator at the beginning or middle (or both) of the
@@ -174,10 +174,10 @@ EXAMPLES
is not relevant if there is already a middle slash in
the pattern.
- - The pattern "foo/*", matches "foo/test.json"
- (a regular file), "foo/bar" (a directory), but it does not match
- "foo/bar/hello.c" (a regular file), as the asterisk in the
- pattern does not match "bar/hello.c" which has a slash in it.
+ - The pattern `foo/*`, matches `foo/test.json`
+ (a regular file), `foo/bar` (a directory), but it does not match
+ `foo/bar/hello.c` (a regular file), as the asterisk in the
+ pattern does not match `bar/hello.c` which has a slash in it.
--------------------------------------------------------------
$ git status
diff --git a/Documentation/gitmodules.txt b/Documentation/gitmodules.txt
index dcee09b500..d9bec8b187 100644
--- a/Documentation/gitmodules.txt
+++ b/Documentation/gitmodules.txt
@@ -43,9 +43,9 @@ submodule.<name>.update::
command in the superproject. This is only used by `git
submodule init` to initialize the configuration variable of
the same name. Allowed values here are 'checkout', 'rebase',
- 'merge' or 'none'. See description of 'update' command in
- linkgit:git-submodule[1] for their meaning. For security
- reasons, the '!command' form is not accepted here.
+ 'merge' or 'none', but not '!command' (for security reasons).
+ See the description of the 'update' command in
+ linkgit:git-submodule[1] for more details.
submodule.<name>.branch::
A remote branch name for tracking updates in the upstream submodule.
diff --git a/Documentation/gitweb.txt b/Documentation/gitweb.txt
index 7cee9d3689..af6bf3c45e 100644
--- a/Documentation/gitweb.txt
+++ b/Documentation/gitweb.txt
@@ -503,7 +503,7 @@ repositories, you can configure Apache like this:
The above configuration expects your public repositories to live under
`/pub/git` and will serve them as `http://git.domain.org/dir-under-pub-git`,
-both as clonable Git URL and as browseable gitweb interface. If you then
+both as clonable Git URL and as browsable gitweb interface. If you then
start your linkgit:git-daemon[1] with `--base-path=/pub/git --export-all`
then you can even use the `git://` URL with exactly the same path.
diff --git a/Documentation/object-format-disclaimer.txt b/Documentation/object-format-disclaimer.txt
index 4cb106f0d1..e561e6668c 100644
--- a/Documentation/object-format-disclaimer.txt
+++ b/Documentation/object-format-disclaimer.txt
@@ -1,6 +1,9 @@
-THIS OPTION IS EXPERIMENTAL! SHA-256 support is experimental and still
-in an early stage. A SHA-256 repository will in general not be able to
-share work with "regular" SHA-1 repositories. It should be assumed
-that, e.g., Git internal file formats in relation to SHA-256
-repositories may change in backwards-incompatible ways. Only use
-`--object-format=sha256` for testing purposes.
+Note: At present, there is no interoperability between SHA-256
+repositories and SHA-1 repositories.
+
+Historically, we warned that SHA-256 repositories may later need
+backward incompatible changes when we introduce such interoperability
+features. Today, we only expect compatible changes. Furthermore, if such
+changes prove to be necessary, it can be expected that SHA-256 repositories
+created with today's Git will be usable by future versions of Git
+without data loss.
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index 3000888a90..e6468bf0eb 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -236,10 +236,11 @@ ifndef::git-rev-list[]
endif::git-rev-list[]
--stdin::
- In addition to the '<commit>' listed on the command
- line, read them from the standard input. If a `--` separator is
- seen, stop reading commits and start reading paths to limit the
- result.
+ In addition to getting arguments from the command line, read
+ them for standard input as well. This accepts commits and
+ pseudo-options like `--all` and `--glob=`. When a `--` separator
+ is seen, the following input is treated as paths and used to
+ limit the result.
ifdef::git-rev-list[]
--quiet::
diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt
index 9aa58052bc..6ea6c7cead 100644
--- a/Documentation/revisions.txt
+++ b/Documentation/revisions.txt
@@ -30,10 +30,11 @@ characters and to avoid word splitting.
explicitly say 'heads/master' to tell Git which one you mean.
When ambiguous, a '<refname>' is disambiguated by taking the
first match in the following rules:
-
++
. If '$GIT_DIR/<refname>' exists, that is what you mean (this is usually
- useful only for `HEAD`, `FETCH_HEAD`, `ORIG_HEAD`, `MERGE_HEAD`
- and `CHERRY_PICK_HEAD`);
+ useful only for `HEAD`, `FETCH_HEAD`, `ORIG_HEAD`, `MERGE_HEAD`,
+ `REBASE_HEAD`, `REVERT_HEAD`, `CHERRY_PICK_HEAD`, `BISECT_HEAD`
+ and `AUTO_MERGE`);
. otherwise, 'refs/<refname>' if it exists;
@@ -44,19 +45,38 @@ characters and to avoid word splitting.
. otherwise, 'refs/remotes/<refname>' if it exists;
. otherwise, 'refs/remotes/<refname>/HEAD' if it exists.
+
+
-`HEAD` names the commit on which you based the changes in the working tree.
-`FETCH_HEAD` records the branch which you fetched from a remote repository
-with your last `git fetch` invocation.
-`ORIG_HEAD` is created by commands that move your `HEAD` in a drastic
-way (`git am`, `git merge`, `git rebase`, `git reset`),
-to record the position of the `HEAD` before their operation, so that
-you can easily change the tip of the branch back to the state before you ran
-them.
-`MERGE_HEAD` records the commit(s) which you are merging into your branch
-when you run `git merge`.
-`CHERRY_PICK_HEAD` records the commit which you are cherry-picking
-when you run `git cherry-pick`.
+ `HEAD`:::
+ names the commit on which you based the changes in the working tree.
+ `FETCH_HEAD`:::
+ records the branch which you fetched from a remote repository with
+ your last `git fetch` invocation.
+ `ORIG_HEAD`:::
+ is created by commands that move your `HEAD` in a drastic way (`git
+ am`, `git merge`, `git rebase`, `git reset`), to record the position
+ of the `HEAD` before their operation, so that you can easily change
+ the tip of the branch back to the state before you ran them.
+ `MERGE_HEAD`:::
+ records the commit(s) which you are merging into your branch when you
+ run `git merge`.
+ `REBASE_HEAD`:::
+ during a rebase, records the commit at which the operation is
+ currently stopped, either because of conflicts or an `edit` command in
+ an interactive rebase.
+ `REVERT_HEAD`:::
+ records the commit which you are reverting when you run `git revert`.
+ `CHERRY_PICK_HEAD`:::
+ records the commit which you are cherry-picking when you run `git
+ cherry-pick`.
+ `BISECT_HEAD`:::
+ records the current commit to be tested when you run `git bisect
+ --no-checkout`.
+ `AUTO_MERGE`:::
+ records a tree object corresponding to the state the
+ 'ort' merge strategy wrote to the working tree when a merge operation
+ resulted in conflicts.
+
+
Note that any of the 'refs/*' cases above may come either from
the `$GIT_DIR/refs` directory or from the `$GIT_DIR/packed-refs` file.
diff --git a/Documentation/technical/api-merge.txt b/Documentation/technical/api-merge.txt
index 487d4d83ff..c2ba01828c 100644
--- a/Documentation/technical/api-merge.txt
+++ b/Documentation/technical/api-merge.txt
@@ -28,9 +28,9 @@ and `diff.c` for examples.
* `struct ll_merge_options`
-Check ll-merge.h for details.
+Check merge-ll.h for details.
Low-level (single file) merge
-----------------------------
-Check ll-merge.h for details.
+Check merge-ll.h for details.
diff --git a/Documentation/technical/remembering-renames.txt b/Documentation/technical/remembering-renames.txt
index 1e34d91390..73f41761e2 100644
--- a/Documentation/technical/remembering-renames.txt
+++ b/Documentation/technical/remembering-renames.txt
@@ -664,7 +664,7 @@ skip-irrelevant-renames optimization means we sometimes don't detect
renames for any files within a directory that was renamed, in which
case we will not have been able to detect any rename for the directory
itself. In such a case, we do not know whether the directory was
-renamed; we want to be careful to avoid cacheing some kind of "this
+renamed; we want to be careful to avoid caching some kind of "this
directory was not renamed" statement. If we did, then a subsequent
commit being rebased could add a file to the old directory, and the
user would expect it to end up in the correct directory -- something
diff --git a/Documentation/urls-remotes.txt b/Documentation/urls-remotes.txt
index e410912fe5..ae8c2db427 100644
--- a/Documentation/urls-remotes.txt
+++ b/Documentation/urls-remotes.txt
@@ -35,7 +35,7 @@ config file would appear like this:
The `<pushurl>` is used for pushes only. It is optional and defaults
to `<URL>`. Pushing to a remote affects all defined pushurls or to all
defined urls if no pushurls are defined. Fetch, however, will only
-fetch from the first defined url if muliple urls are defined.
+fetch from the first defined url if multiple urls are defined.
Named file in `$GIT_DIR/remotes`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt
index dc9c6a663a..4281396093 100644
--- a/Documentation/user-manual.txt
+++ b/Documentation/user-manual.txt
@@ -1343,6 +1343,33 @@ $ git diff -3 file.txt # diff against stage 3
$ git diff --theirs file.txt # same as the above.
-------------------------------------------------
+When using the 'ort' merge strategy (the default), before updating the working
+tree with the result of the merge, Git writes a special ref named AUTO_MERGE
+reflecting the state of the tree it is about to write. Conflicted paths with
+textual conflicts that could not be automatically merged are written to this
+tree with conflict markers, just as in the working tree. AUTO_MERGE can thus be
+used with linkgit:git-diff[1] to show the changes you've made so far to resolve
+conflicts. Using the same example as above, after resolving the conflict we
+get:
+
+-------------------------------------------------
+$ git diff AUTO_MERGE
+diff --git a/file.txt b/file.txt
+index cd10406..8bf5ae7 100644
+--- a/file.txt
++++ b/file.txt
+@@ -1,5 +1 @@
+-<<<<<<< HEAD:file.txt
+-Hello world
+-=======
+-Goodbye
+->>>>>>> 77976da35a11db4580b80ae27e8d65caf5208086:file.txt
++Goodbye world
+-------------------------------------------------
+
+Notice that the diff shows we deleted the conflict markers and both versions of
+the content line, and wrote "Goodbye world" instead.
+
The linkgit:git-log[1] and linkgit:gitk[1] commands also provide special help
for merges:
@@ -4102,13 +4129,11 @@ Note that terminology has changed since that revision. For example, the
README in that revision uses the word "changeset" to describe what we
now call a <<def_commit_object,commit>>.
-Also, we do not call it "cache" any more, but rather "index"; however, the
-file is still called `cache.h`. Remark: Not much reason to change it now,
-especially since there is no good single name for it anyway, because it is
-basically _the_ header file which is included by _all_ of Git's C sources.
+Also, we do not call it "cache" any more, but rather "index"; however,
+the file is still called `read-cache.h`.
If you grasp the ideas in that initial commit, you should check out a
-more recent version and skim `cache.h`, `object.h` and `commit.h`.
+more recent version and skim `read-cache-ll.h`, `object.h` and `commit.h`.
In the early days, Git (in the tradition of UNIX) was a bunch of programs
which were extremely simple, and which you used in scripts, piping the
@@ -4119,11 +4144,11 @@ many of these parts have become builtins, and some of the core has been
and to avoid code duplication.
By now, you know what the index is (and find the corresponding data
-structures in `cache.h`), and that there are just a couple of object types
-(blobs, trees, commits and tags) which inherit their common structure from
-`struct object`, which is their first member (and thus, you can cast e.g.
-`(struct object *)commit` to achieve the _same_ as `&commit->object`, i.e.
-get at the object name and flags).
+structures in `read-cache-ll.h`), and that there are just a couple of
+object types (blobs, trees, commits and tags) which inherit their
+common structure from `struct object`, which is their first member
+(and thus, you can cast e.g. `(struct object *)commit` to achieve the
+_same_ as `&commit->object`, i.e. get at the object name and flags).
Now is a good point to take a break to let this information sink in.
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index b37f72a552..7313f8aa3e 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -1,7 +1,7 @@
#!/bin/sh
GVF=GIT-VERSION-FILE
-DEF_VER=v2.41.0
+DEF_VER=v2.42.0-rc0
LF='
'
diff --git a/Makefile b/Makefile
index e440728c24..ace3e5a506 100644
--- a/Makefile
+++ b/Makefile
@@ -1051,7 +1051,6 @@ LIB_OBJS += linear-assignment.o
LIB_OBJS += list-objects-filter-options.o
LIB_OBJS += list-objects-filter.o
LIB_OBJS += list-objects.o
-LIB_OBJS += ll-merge.o
LIB_OBJS += lockfile.o
LIB_OBJS += log-tree.o
LIB_OBJS += ls-refs.o
@@ -1060,6 +1059,7 @@ LIB_OBJS += mailmap.o
LIB_OBJS += match-trees.o
LIB_OBJS += mem-pool.o
LIB_OBJS += merge-blobs.o
+LIB_OBJS += merge-ll.o
LIB_OBJS += merge-ort.o
LIB_OBJS += merge-ort-wrappers.o
LIB_OBJS += merge-recursive.o
@@ -1142,6 +1142,7 @@ LIB_OBJS += sigchain.o
LIB_OBJS += sparse-index.o
LIB_OBJS += split-index.o
LIB_OBJS += stable-qsort.o
+LIB_OBJS += statinfo.o
LIB_OBJS += strbuf.o
LIB_OBJS += streaming.o
LIB_OBJS += string-list.o
@@ -1951,7 +1952,7 @@ endif
BASIC_CFLAGS += \
-DSHA1DC_NO_STANDARD_INCLUDES \
-DSHA1DC_INIT_SAFE_HASH_DEFAULT=0 \
- -DSHA1DC_CUSTOM_INCLUDE_SHA1_C="\"cache.h\"" \
+ -DSHA1DC_CUSTOM_INCLUDE_SHA1_C="\"git-compat-util.h\"" \
-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="\"git-compat-util.h\""
endif
endif
@@ -2742,8 +2743,8 @@ exec-cmd.sp exec-cmd.s exec-cmd.o: EXTRA_CPPFLAGS = \
'-DBINDIR="$(bindir_relative_SQ)"' \
'-DFALLBACK_RUNTIME_PREFIX="$(prefix_SQ)"'
-builtin/init-db.sp builtin/init-db.s builtin/init-db.o: GIT-PREFIX
-builtin/init-db.sp builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \
+setup.sp setup.s setup.o: GIT-PREFIX
+setup.sp setup.s setup.o: EXTRA_CPPFLAGS = \
-DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"'
config.sp config.s config.o: GIT-PREFIX
@@ -3215,6 +3216,12 @@ $(SP_OBJ): %.sp: %.c %.o
sparse: $(SP_OBJ)
EXCEPT_HDRS := $(GENERATED_H) unicode-width.h compat/% xdiff/%
+ifndef OPENSSL_SHA1
+ EXCEPT_HDRS += sha1/openssl.h
+endif
+ifndef OPENSSL_SHA256
+ EXCEPT_HDRS += sha256/openssl.h
+endif
ifndef NETTLE_SHA256
EXCEPT_HDRS += sha256/nettle.h
endif
diff --git a/RelNotes b/RelNotes
index 4da73c9a6d..0527f30c2d 120000
--- a/RelNotes
+++ b/RelNotes
@@ -1 +1 @@
-Documentation/RelNotes/2.41.0.txt \ No newline at end of file
+Documentation/RelNotes/2.42.0.txt \ No newline at end of file
diff --git a/abspath.c b/abspath.c
index d032f5dce5..1202cde23d 100644
--- a/abspath.c
+++ b/abspath.c
@@ -289,3 +289,39 @@ char *prefix_filename_except_for_dash(const char *pfx, const char *arg)
return xstrdup(arg);
return prefix_filename(pfx, arg);
}
+
+void strbuf_add_absolute_path(struct strbuf *sb, const char *path)
+{
+ if (!*path)
+ die("The empty string is not a valid path");
+ if (!is_absolute_path(path)) {
+ struct stat cwd_stat, pwd_stat;
+ size_t orig_len = sb->len;
+ char *cwd = xgetcwd();
+ char *pwd = getenv("PWD");
+ if (pwd && strcmp(pwd, cwd) &&
+ !stat(cwd, &cwd_stat) &&
+ (cwd_stat.st_dev || cwd_stat.st_ino) &&
+ !stat(pwd, &pwd_stat) &&
+ pwd_stat.st_dev == cwd_stat.st_dev &&
+ pwd_stat.st_ino == cwd_stat.st_ino)
+ strbuf_addstr(sb, pwd);
+ else
+ strbuf_addstr(sb, cwd);
+ if (sb->len > orig_len && !is_dir_sep(sb->buf[sb->len - 1]))
+ strbuf_addch(sb, '/');
+ free(cwd);
+ }
+ strbuf_addstr(sb, path);
+}
+
+void strbuf_add_real_path(struct strbuf *sb, const char *path)
+{
+ if (sb->len) {
+ struct strbuf resolved = STRBUF_INIT;
+ strbuf_realpath(&resolved, path, 1);
+ strbuf_addbuf(sb, &resolved);
+ strbuf_release(&resolved);
+ } else
+ strbuf_realpath(sb, path, 1);
+}
diff --git a/abspath.h b/abspath.h
index 7cd3de5e9d..4653080d5e 100644
--- a/abspath.h
+++ b/abspath.h
@@ -30,4 +30,25 @@ static inline int is_absolute_path(const char *path)
return is_dir_sep(path[0]) || has_dos_drive_prefix(path);
}
+/**
+ * Add a path to a buffer, converting a relative path to an
+ * absolute one in the process. Symbolic links are not
+ * resolved.
+ */
+void strbuf_add_absolute_path(struct strbuf *sb, const char *path);
+
+/**
+ * Canonize `path` (make it absolute, resolve symlinks, remove extra
+ * slashes) and append it to `sb`. Die with an informative error
+ * message if there is a problem.
+ *
+ * The directory part of `path` (i.e., everything up to the last
+ * dir_sep) must denote a valid, existing directory, but the last
+ * component need not exist.
+ *
+ * Callers that don't mind links should use the more lightweight
+ * strbuf_add_absolute_path() instead.
+ */
+void strbuf_add_real_path(struct strbuf *sb, const char *path);
+
#endif /* ABSPATH_H */
diff --git a/add-interactive.c b/add-interactive.c
index de877ca052..add9a1ad43 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -1,10 +1,14 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "add-interactive.h"
#include "color.h"
#include "config.h"
#include "diffcore.h"
#include "gettext.h"
+#include "hash.h"
#include "hex.h"
+#include "preload-index.h"
+#include "read-cache-ll.h"
+#include "repository.h"
#include "revision.h"
#include "refs.h"
#include "string-list.h"
diff --git a/add-patch.c b/add-patch.c
index 8d770d203f..bfe19876cd 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -1,11 +1,12 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "add-interactive.h"
#include "advice.h"
-#include "alloc.h"
#include "editor.h"
#include "environment.h"
#include "gettext.h"
#include "object-name.h"
+#include "read-cache-ll.h"
+#include "repository.h"
#include "strbuf.h"
#include "run-command.h"
#include "strvec.h"
@@ -1105,10 +1106,11 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)
size_t i;
strbuf_reset(&s->buf);
- strbuf_commented_addf(&s->buf, _("Manual hunk edit mode -- see bottom for "
- "a quick guide.\n"));
+ strbuf_commented_addf(&s->buf, comment_line_char,
+ _("Manual hunk edit mode -- see bottom for "
+ "a quick guide.\n"));
render_hunk(s, hunk, 0, 0, &s->buf);
- strbuf_commented_addf(&s->buf,
+ strbuf_commented_addf(&s->buf, comment_line_char,
_("---\n"
"To remove '%c' lines, make them ' ' lines "
"(context).\n"
@@ -1117,12 +1119,13 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)
s->mode->is_reverse ? '+' : '-',
s->mode->is_reverse ? '-' : '+',
comment_line_char);
- strbuf_commented_addf(&s->buf, "%s", _(s->mode->edit_hunk_hint));
+ strbuf_commented_addf(&s->buf, comment_line_char, "%s",
+ _(s->mode->edit_hunk_hint));
/*
* TRANSLATORS: 'it' refers to the patch mentioned in the previous
* messages.
*/
- strbuf_commented_addf(&s->buf,
+ strbuf_commented_addf(&s->buf, comment_line_char,
_("If it does not apply cleanly, you will be "
"given an opportunity to\n"
"edit again. If all lines of the hunk are "
diff --git a/advice.c b/advice.c
index d6232439c3..e5a9bb9b44 100644
--- a/advice.c
+++ b/advice.c
@@ -78,6 +78,7 @@ static struct {
[ADVICE_SUBMODULES_NOT_UPDATED] = { "submodulesNotUpdated", 1 },
[ADVICE_UPDATE_SPARSE_PATH] = { "updateSparsePath", 1 },
[ADVICE_WAITING_FOR_EDITOR] = { "waitingForEditor", 1 },
+ [ADVICE_WORKTREE_ADD_ORPHAN] = { "worktreeAddOrphan", 1 },
};
static const char turn_off_instructions[] =
diff --git a/advice.h b/advice.h
index 0f584163f5..2affbe1426 100644
--- a/advice.h
+++ b/advice.h
@@ -49,6 +49,7 @@ struct string_list;
ADVICE_UPDATE_SPARSE_PATH,
ADVICE_WAITING_FOR_EDITOR,
ADVICE_SKIPPED_CHERRY_PICKS,
+ ADVICE_WORKTREE_ADD_ORPHAN,
};
int git_default_advice_config(const char *var, const char *value);
diff --git a/alias.c b/alias.c
index 54a1a23d2c..5a238f2e30 100644
--- a/alias.c
+++ b/alias.c
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "alias.h"
-#include "alloc.h"
#include "config.h"
#include "gettext.h"
#include "strbuf.h"
@@ -12,7 +11,8 @@ struct config_alias_data {
struct string_list *list;
};
-static int config_alias_cb(const char *key, const char *value, void *d)
+static int config_alias_cb(const char *key, const char *value,
+ const struct config_context *ctx UNUSED, void *d)
{
struct config_alias_data *data = d;
const char *p;
diff --git a/alloc.h b/alloc.h
index 4312db4bd0..3f4a0ad310 100644
--- a/alloc.h
+++ b/alloc.h
@@ -17,79 +17,4 @@ 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 6212ab3a1b..3d69fec836 100644
--- a/apply.c
+++ b/apply.c
@@ -7,12 +7,11 @@
*
*/
-#include "cache.h"
+#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "base85.h"
#include "config.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "blob.h"
#include "delta.h"
#include "diff.h"
@@ -21,19 +20,22 @@
#include "gettext.h"
#include "hex.h"
#include "xdiff-interface.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
#include "lockfile.h"
+#include "name-hash.h"
#include "object-name.h"
#include "object-file.h"
#include "parse-options.h"
+#include "path.h"
#include "quote.h"
+#include "read-cache.h"
#include "rerere.h"
#include "apply.h"
#include "entry.h"
#include "setup.h"
#include "symlinks.h"
+#include "wildmatch.h"
#include "ws.h"
-#include "wrapper.h"
struct gitdiff_data {
struct strbuf *root;
@@ -410,9 +412,10 @@ static void say_patch_name(FILE *output, const char *fmt, struct patch *patch)
static int read_patch_file(struct strbuf *sb, int fd)
{
- if (strbuf_read(sb, fd, 0) < 0 || sb->len >= MAX_APPLY_SIZE)
- return error_errno("git apply: failed to read");
-
+ if (strbuf_read(sb, fd, 0) < 0)
+ return error_errno(_("failed to read patch"));
+ else if (sb->len >= MAX_APPLY_SIZE)
+ return error(_("patch too large"));
/*
* Make sure that we have some slop in the buffer
* so that we can do speculative "memcmp" etc, and
diff --git a/archive-tar.c b/archive-tar.c
index 4cd81d8161..0726996839 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -2,14 +2,13 @@
* Copyright (c) 2005, 2006 Rene Scharfe
*/
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "gettext.h"
#include "git-zlib.h"
#include "hex.h"
#include "tar.h"
#include "archive.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "streaming.h"
#include "run-command.h"
#include "write-or-die.h"
@@ -411,14 +410,15 @@ static int tar_filter_config(const char *var, const char *value,
return 0;
}
-static int git_tar_config(const char *var, const char *value, void *cb)
+static int git_tar_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "tar.umask")) {
if (value && !strcmp(value, "user")) {
tar_umask = umask(0);
umask(tar_umask);
} else {
- tar_umask = git_config_int(var, value);
+ tar_umask = git_config_int(var, value, ctx->kvi);
}
return 0;
}
diff --git a/archive-zip.c b/archive-zip.c
index d0d065a312..7229e3e454 100644
--- a/archive-zip.c
+++ b/archive-zip.c
@@ -9,7 +9,7 @@
#include "hex.h"
#include "streaming.h"
#include "utf8.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "userdiff.h"
#include "write-or-die.h"
#include "xdiff-interface.h"
@@ -617,6 +617,7 @@ static void dos_time(timestamp_t *timestamp, int *dos_date, int *dos_time)
}
static int archive_zip_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *data UNUSED)
{
return userdiff_config(var, value);
diff --git a/archive.c b/archive.c
index 2ea9cbef92..ca11db185b 100644
--- a/archive.c
+++ b/archive.c
@@ -1,15 +1,15 @@
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "convert.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
+#include "path.h"
#include "pretty.h"
#include "setup.h"
#include "refs.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "commit.h"
#include "tree.h"
#include "tree-walk.h"
diff --git a/attr.c b/attr.c
index d45d34058d..ff0a3e7b61 100644
--- a/attr.c
+++ b/attr.c
@@ -6,18 +6,19 @@
* an insanely large number of attributes.
*/
-#include "cache.h"
-#include "alloc.h"
+#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
#include "exec-cmd.h"
#include "attr.h"
#include "dir.h"
#include "gettext.h"
+#include "path.h"
#include "utf8.h"
#include "quote.h"
+#include "read-cache-ll.h"
#include "revision.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "setup.h"
#include "thread-utils.h"
#include "tree-walk.h"
@@ -870,7 +871,7 @@ static struct attr_stack *read_attr(struct index_state *istate,
return res;
}
-static const char *git_etc_gitattributes(void)
+const char *git_attr_system_file(void)
{
static const char *system_wide;
if (!system_wide)
@@ -878,7 +879,7 @@ static const char *git_etc_gitattributes(void)
return system_wide;
}
-static const char *get_home_gitattributes(void)
+const char *git_attr_global_file(void)
{
if (!git_attributes_file)
git_attributes_file = xdg_config_home("attributes");
@@ -886,7 +887,7 @@ static const char *get_home_gitattributes(void)
return git_attributes_file;
}
-static int git_attr_system(void)
+int git_attr_system_is_enabled(void)
{
return !git_env_bool("GIT_ATTR_NOSYSTEM", 0);
}
@@ -920,14 +921,14 @@ static void bootstrap_attr_stack(struct index_state *istate,
push_stack(stack, e, NULL, 0);
/* system-wide frame */
- if (git_attr_system()) {
- e = read_attr_from_file(git_etc_gitattributes(), flags);
+ if (git_attr_system_is_enabled()) {
+ e = read_attr_from_file(git_attr_system_file(), flags);
push_stack(stack, e, NULL, 0);
}
/* home directory */
- if (get_home_gitattributes()) {
- e = read_attr_from_file(get_home_gitattributes(), flags);
+ if (git_attr_global_file()) {
+ e = read_attr_from_file(git_attr_global_file(), flags);
push_stack(stack, e, NULL, 0);
}
diff --git a/attr.h b/attr.h
index 676bd17ce2..2b745df405 100644
--- a/attr.h
+++ b/attr.h
@@ -227,4 +227,13 @@ void git_attr_set_direction(enum git_attr_direction new_direction);
void attr_start(void);
+/* Return the system gitattributes file. */
+const char *git_attr_system_file(void);
+
+/* Return the global gitattributes file, if any. */
+const char *git_attr_global_file(void);
+
+/* Return whether the system gitattributes file is enabled and should be used. */
+int git_attr_system_is_enabled(void);
+
#endif /* ATTR_H */
diff --git a/bisect.c b/bisect.c
index 8d5f8e5885..1be8e0a271 100644
--- a/bisect.c
+++ b/bisect.c
@@ -18,7 +18,8 @@
#include "commit-slab.h"
#include "commit-reach.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "path.h"
#include "dir.h"
static struct oid_array good_revs;
diff --git a/blame.c b/blame.c
index b830654062..141756975b 100644
--- a/blame.c
+++ b/blame.c
@@ -1,6 +1,6 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "refs.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "cache-tree.h"
#include "mergesort.h"
#include "convert.h"
@@ -8,6 +8,8 @@
#include "diffcore.h"
#include "gettext.h"
#include "hex.h"
+#include "path.h"
+#include "read-cache.h"
#include "setup.h"
#include "tag.h"
#include "trace2.h"
@@ -2804,7 +2806,9 @@ void setup_scoreboard(struct blame_scoreboard *sb,
parent_oid = &head_oid;
}
- setup_work_tree();
+ if (!sb->contents_from)
+ setup_work_tree();
+
sb->final = fake_working_tree_commit(sb->repo,
&sb->revs->diffopt,
sb->path, sb->contents_from,
diff --git a/blame.h b/blame.h
index b60d1d81e3..31ddc85f19 100644
--- a/blame.h
+++ b/blame.h
@@ -2,6 +2,7 @@
#define BLAME_H
#include "commit.h"
+#include "oidset.h"
#include "xdiff-interface.h"
#include "revision.h"
#include "prio-queue.h"
diff --git a/branch.c b/branch.c
index ba3914adf5..3e4684f79f 100644
--- a/branch.c
+++ b/branch.c
@@ -6,6 +6,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-name.h"
+#include "path.h"
#include "refs.h"
#include "refspec.h"
#include "remote.h"
@@ -37,7 +38,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)
if (!remote_find_tracking(remote, &tracking->spec)) {
switch (++tracking->matches) {
case 1:
- string_list_append(tracking->srcs, tracking->spec.src);
+ string_list_append_nodup(tracking->srcs, tracking->spec.src);
tracking->remote = remote->name;
break;
case 2:
@@ -233,7 +234,7 @@ static int inherit_tracking(struct tracking *tracking, const char *orig_ref)
return -1;
}
- tracking->remote = xstrdup(branch->remote_name);
+ tracking->remote = branch->remote_name;
for (i = 0; i < branch->merge_nr; i++)
string_list_append(tracking->srcs, branch->merge_name[i]);
return 0;
@@ -333,7 +334,7 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
if (!skip_prefix(tracking.srcs->items[0].string,
"refs/heads/", &tracked_branch) ||
strcmp(tracked_branch, new_ref))
- return;
+ goto cleanup;
}
if (tracking.srcs->nr < 1)
@@ -470,7 +471,7 @@ int validate_new_branchname(const char *name, struct strbuf *ref, int force)
if ((path = branch_checked_out(ref->buf)))
die(_("cannot force update the branch '%s' "
- "checked out at '%s'"),
+ "used by worktree at '%s'"),
ref->buf + strlen("refs/heads/"), path);
return 1;
@@ -480,9 +481,12 @@ static int check_tracking_branch(struct remote *remote, void *cb_data)
{
char *tracking_branch = cb_data;
struct refspec_item query;
+ int res;
memset(&query, 0, sizeof(struct refspec_item));
query.dst = tracking_branch;
- return !remote_find_tracking(remote, &query);
+ res = !remote_find_tracking(remote, &query);
+ free(query.src);
+ return res;
}
static int validate_remote_tracking_branch(char *ref)
@@ -638,9 +642,10 @@ void dwim_and_setup_tracking(struct repository *r, const char *new_ref,
const char *orig_ref, enum branch_track track,
int quiet)
{
- char *real_orig_ref;
+ char *real_orig_ref = NULL;
dwim_branch_start(r, orig_ref, track, &real_orig_ref, NULL);
setup_tracking(new_ref, real_orig_ref, track, quiet);
+ free(real_orig_ref);
}
/**
diff --git a/builtin.h b/builtin.h
index cb0db67681..d560baa661 100644
--- a/builtin.h
+++ b/builtin.h
@@ -2,9 +2,6 @@
#define BUILTIN_H
#include "git-compat-util.h"
-#include "strbuf.h"
-#include "cache.h"
-#include "commit.h"
/*
* builtin API
diff --git a/builtin/add.c b/builtin/add.c
index 76cc026a68..4b0dd798df 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -4,10 +4,9 @@
* Copyright (C) 2006 Linus Torvalds
*/
#define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
#include "advice.h"
#include "config.h"
-#include "builtin.h"
#include "lockfile.h"
#include "editor.h"
#include "dir.h"
@@ -17,8 +16,12 @@
#include "cache-tree.h"
#include "run-command.h"
#include "parse-options.h"
+#include "path.h"
+#include "preload-index.h"
#include "diff.h"
#include "diffcore.h"
+#include "read-cache.h"
+#include "repository.h"
#include "revision.h"
#include "bulk-checkin.h"
#include "strvec.h"
@@ -36,11 +39,6 @@ static int pathspec_file_nul;
static int include_sparse;
static const char *pathspec_from_file;
-struct update_callback_data {
- int flags;
- int add_errors;
-};
-
static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
{
int i, ret = 0;
@@ -69,95 +67,6 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
return ret;
}
-static int fix_unmerged_status(struct diff_filepair *p,
- struct update_callback_data *data)
-{
- if (p->status != DIFF_STATUS_UNMERGED)
- return p->status;
- if (!(data->flags & ADD_CACHE_IGNORE_REMOVAL) && !p->two->mode)
- /*
- * This is not an explicit add request, and the
- * path is missing from the working tree (deleted)
- */
- return DIFF_STATUS_DELETED;
- else
- /*
- * Either an explicit add request, or path exists
- * in the working tree. An attempt to explicitly
- * add a path that does not exist in the working tree
- * will be caught as an error by the caller immediately.
- */
- return DIFF_STATUS_MODIFIED;
-}
-
-static void update_callback(struct diff_queue_struct *q,
- struct diff_options *opt UNUSED, void *cbdata)
-{
- int i;
- struct update_callback_data *data = cbdata;
-
- for (i = 0; i < q->nr; i++) {
- struct diff_filepair *p = q->queue[i];
- const char *path = p->one->path;
-
- if (!include_sparse && !path_in_sparse_checkout(path, &the_index))
- continue;
-
- switch (fix_unmerged_status(p, data)) {
- default:
- die(_("unexpected diff status %c"), p->status);
- case DIFF_STATUS_MODIFIED:
- case DIFF_STATUS_TYPE_CHANGED:
- if (add_file_to_index(&the_index, path, data->flags)) {
- if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
- die(_("updating files failed"));
- data->add_errors++;
- }
- break;
- case DIFF_STATUS_DELETED:
- if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
- break;
- if (!(data->flags & ADD_CACHE_PRETEND))
- remove_file_from_index(&the_index, path);
- if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE))
- printf(_("remove '%s'\n"), path);
- break;
- }
- }
-}
-
-int add_files_to_cache(const char *prefix,
- const struct pathspec *pathspec, int flags)
-{
- struct update_callback_data data;
- struct rev_info rev;
-
- memset(&data, 0, sizeof(data));
- data.flags = flags;
-
- repo_init_revisions(the_repository, &rev, prefix);
- setup_revisions(0, NULL, &rev, NULL);
- if (pathspec)
- copy_pathspec(&rev.prune_data, pathspec);
- rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
- rev.diffopt.format_callback = update_callback;
- rev.diffopt.format_callback_data = &data;
- rev.diffopt.flags.override_submodule_config = 1;
- rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
-
- /*
- * Use an ODB transaction to optimize adding multiple objects.
- * This function is invoked from commands other than 'add', which
- * may not have their own transaction active.
- */
- begin_odb_transaction();
- run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
- end_odb_transaction();
-
- release_revisions(&rev);
- return !!data.add_errors;
-}
-
static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
{
int i, retval = 0;
@@ -357,7 +266,8 @@ static struct option builtin_add_options[] = {
OPT_END(),
};
-static int add_config(const char *var, const char *value, void *cb)
+static int add_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "add.ignoreerrors") ||
!strcmp(var, "add.ignore-errors")) {
@@ -365,7 +275,10 @@ static int add_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_default_config(var, value, cb);
+ if (git_color_config(var, value, cb) < 0)
+ return -1;
+
+ return git_default_config(var, value, ctx, cb);
}
static const char embedded_advice[] = N_(
@@ -640,7 +553,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
if (add_renormalize)
exit_status |= renormalize_tracked_files(&pathspec, flags);
else
- exit_status |= add_files_to_cache(prefix, &pathspec, flags);
+ exit_status |= add_files_to_cache(the_repository, prefix,
+ &pathspec, include_sparse,
+ flags);
if (add_new_files)
exit_status |= add_files(&dir, flags);
diff --git a/builtin/am.c b/builtin/am.c
index 5c83f2e003..8bde034fae 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -4,11 +4,10 @@
* Based on git-am.sh by Junio C Hamano.
*/
#define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
#include "abspath.h"
#include "advice.h"
#include "config.h"
-#include "builtin.h"
#include "editor.h"
#include "environment.h"
#include "exec-cmd.h"
@@ -29,6 +28,7 @@
#include "unpack-trees.h"
#include "branch.h"
#include "object-name.h"
+#include "preload-index.h"
#include "sequencer.h"
#include "revision.h"
#include "merge-recursive.h"
@@ -41,9 +41,9 @@
#include "string-list.h"
#include "packfile.h"
#include "pager.h"
+#include "path.h"
#include "repository.h"
#include "pretty.h"
-#include "wrapper.h"
/**
* Returns the length of the first line of msg.
@@ -786,7 +786,7 @@ static int split_mail_conv(mail_conv_fn fn, struct am_state *state,
* A split_mail_conv() callback that converts an StGit patch to an RFC2822
* message suitable for parsing with git-mailinfo.
*/
-static int stgit_patch_to_mail(FILE *out, FILE *in, int keep_cr)
+static int stgit_patch_to_mail(FILE *out, FILE *in, int keep_cr UNUSED)
{
struct strbuf sb = STRBUF_INIT;
int subject_printed = 0;
@@ -869,7 +869,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths,
* A split_patches_conv() callback that converts a mercurial patch to a RFC2822
* message suitable for parsing with git-mailinfo.
*/
-static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr)
+static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr UNUSED)
{
struct strbuf sb = STRBUF_INIT;
int rc = 0;
@@ -1283,7 +1283,7 @@ static int parse_mail(struct am_state *state, const char *mail)
strbuf_addstr(&msg, "\n\n");
strbuf_addbuf(&msg, &mi.log_message);
- strbuf_stripspace(&msg, 0);
+ strbuf_stripspace(&msg, '\0');
assert(!state->author_name);
state->author_name = strbuf_detach(&author_name, NULL);
@@ -2347,12 +2347,9 @@ int cmd_am(int argc, const char **argv, const char *prefix)
N_("pass -b flag to git-mailinfo"), KEEP_NON_PATCH),
OPT_BOOL('m', "message-id", &state.message_id,
N_("pass -m flag to git-mailinfo")),
- OPT_SET_INT_F(0, "keep-cr", &keep_cr,
- N_("pass --keep-cr flag to git-mailsplit for mbox format"),
- 1, PARSE_OPT_NONEG),
- OPT_SET_INT_F(0, "no-keep-cr", &keep_cr,
- N_("do not pass --keep-cr flag to git-mailsplit independent of am.keepcr"),
- 0, PARSE_OPT_NONEG),
+ OPT_SET_INT(0, "keep-cr", &keep_cr,
+ N_("pass --keep-cr flag to git-mailsplit for mbox format"),
+ 1),
OPT_BOOL('c', "scissors", &state.scissors,
N_("strip everything before a scissors line")),
OPT_CALLBACK_F(0, "quoted-cr", &state.quoted_cr, N_("action"),
diff --git a/builtin/apply.c b/builtin/apply.c
index e3ff02a09e..c18b7ea5d3 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -1,4 +1,3 @@
-#include "cache.h"
#include "builtin.h"
#include "gettext.h"
#include "parse-options.h"
diff --git a/builtin/archive.c b/builtin/archive.c
index b0eaa3c14a..90761fdfee 100644
--- a/builtin/archive.c
+++ b/builtin/archive.c
@@ -2,7 +2,6 @@
* Copyright (c) 2006 Franck Bui-Huu
* Copyright (c) 2006 Rene Scharfe
*/
-#include "cache.h"
#include "builtin.h"
#include "archive.h"
#include "gettext.h"
diff --git a/builtin/bisect.c b/builtin/bisect.c
index 4812450c39..65478ef40f 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "cache.h"
#include "copy.h"
#include "environment.h"
#include "gettext.h"
@@ -12,10 +11,10 @@
#include "strvec.h"
#include "run-command.h"
#include "oid-array.h"
+#include "path.h"
#include "prompt.h"
#include "quote.h"
#include "revision.h"
-#include "wrapper.h"
static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
diff --git a/builtin/blame.c b/builtin/blame.c
index 2df6039a6e..9c987d6567 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -6,7 +6,6 @@
*/
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "color.h"
#include "builtin.h"
@@ -29,7 +28,7 @@
#include "dir.h"
#include "progress.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "pager.h"
#include "blame.h"
#include "refs.h"
@@ -694,7 +693,8 @@ static const char *add_prefix(const char *prefix, const char *path)
return prefix_path(prefix, prefix ? strlen(prefix) : 0, path);
}
-static int git_blame_config(const char *var, const char *value, void *cb)
+static int git_blame_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "blame.showroot")) {
show_root = git_config_bool(var, value);
@@ -767,7 +767,7 @@ static int git_blame_config(const char *var, const char *value, void *cb)
if (userdiff_config(var, value) < 0)
return -1;
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static int blame_copy_callback(const struct option *option, const char *arg, int unset)
diff --git a/builtin/branch.c b/builtin/branch.c
index e6c2655af6..08da650516 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -5,20 +5,20 @@
* Based on git-branch.sh by Junio C Hamano.
*/
-#include "cache.h"
+#include "builtin.h"
#include "config.h"
#include "color.h"
#include "editor.h"
#include "environment.h"
#include "refs.h"
#include "commit.h"
-#include "builtin.h"
#include "gettext.h"
#include "object-name.h"
#include "remote.h"
#include "parse-options.h"
#include "branch.h"
#include "diff.h"
+#include "path.h"
#include "revision.h"
#include "string-list.h"
#include "column.h"
@@ -28,7 +28,6 @@
#include "worktree.h"
#include "help.h"
#include "commit-reach.h"
-#include "wrapper.h"
static const char * const builtin_branch_usage[] = {
N_("git branch [<options>] [-r | -a] [--merged] [--no-merged]"),
@@ -83,7 +82,8 @@ static unsigned int colopts;
define_list_config_array(color_branch_slots);
-static int git_branch_config(const char *var, const char *value, void *cb)
+static int git_branch_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
const char *slot_name;
@@ -117,7 +117,10 @@ static int git_branch_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_color_default_config(var, value, cb);
+ if (git_color_config(var, value, cb) < 0)
+ return -1;
+
+ return git_default_config(var, value, ctx, cb);
}
static const char *branch_get_color(enum color_branch ix)
@@ -366,17 +369,8 @@ static const char *quote_literal_for_format(const char *s)
static struct strbuf buf = STRBUF_INIT;
strbuf_reset(&buf);
- while (*s) {
- const char *ep = strchrnul(s, '%');
- if (s < ep)
- strbuf_add(&buf, s, ep - s);
- if (*ep == '%') {
- strbuf_addstr(&buf, "%%");
- s = ep + 1;
- } else {
- s = ep;
- }
- }
+ while (strbuf_expand_step(&buf, &s))
+ strbuf_addstr(&buf, "%%");
return buf.buf;
}
@@ -674,7 +668,7 @@ static int edit_branch_description(const char *branch_name)
exists = !read_branch_desc(&buf, branch_name);
if (!buf.len || buf.buf[buf.len-1] != '\n')
strbuf_addch(&buf, '\n');
- strbuf_commented_addf(&buf,
+ strbuf_commented_addf(&buf, comment_line_char,
_("Please edit the description for the branch\n"
" %s\n"
"Lines starting with '%c' will be stripped.\n"),
@@ -685,7 +679,7 @@ static int edit_branch_description(const char *branch_name)
strbuf_release(&buf);
return -1;
}
- strbuf_stripspace(&buf, 1);
+ strbuf_stripspace(&buf, comment_line_char);
strbuf_addf(&name, "branch.%s.description", branch_name);
if (buf.len || exists)
@@ -707,7 +701,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
int reflog = 0, quiet = 0, icase = 0, force = 0,
recurse_submodules_explicit = 0;
enum branch_track track;
- struct ref_filter filter;
+ struct ref_filter filter = REF_FILTER_INIT;
static struct ref_sorting *sorting;
struct string_list sorting_options = STRING_LIST_INIT_DUP;
struct ref_format format = REF_FORMAT_INIT;
@@ -726,8 +720,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
OPT_STRING('u', "set-upstream-to", &new_upstream, N_("upstream"), N_("change the upstream info")),
OPT_BOOL(0, "unset-upstream", &unset_upstream, N_("unset the upstream info")),
OPT__COLOR(&branch_use_color, N_("use colored output")),
- OPT_SET_INT('r', "remotes", &filter.kind, N_("act on remote-tracking branches"),
- FILTER_REFS_REMOTES),
+ OPT_SET_INT_F('r', "remotes", &filter.kind, N_("act on remote-tracking branches"),
+ FILTER_REFS_REMOTES,
+ PARSE_OPT_NONEG),
OPT_CONTAINS(&filter.with_commit, N_("print only branches that contain the commit")),
OPT_NO_CONTAINS(&filter.no_commit, N_("print only branches that don't contain the commit")),
OPT_WITH(&filter.with_commit, N_("print only branches that contain the commit")),
@@ -735,8 +730,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
OPT__ABBREV(&filter.abbrev),
OPT_GROUP(N_("Specific git-branch actions:")),
- OPT_SET_INT('a', "all", &filter.kind, N_("list both remote-tracking and local branches"),
- FILTER_REFS_REMOTES | FILTER_REFS_BRANCHES),
+ OPT_SET_INT_F('a', "all", &filter.kind, N_("list both remote-tracking and local branches"),
+ FILTER_REFS_REMOTES | FILTER_REFS_BRANCHES,
+ PARSE_OPT_NONEG),
OPT_BIT('d', "delete", &delete, N_("delete fully merged branch"), 1),
OPT_BIT('D', NULL, &delete, N_("delete branch (even if not merged)"), 2),
OPT_BIT('m', "move", &rename, N_("move/rename a branch and its reflog"), 1),
@@ -765,7 +761,6 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
setup_ref_filter_porcelain_msg();
- memset(&filter, 0, sizeof(filter));
filter.kind = FILTER_REFS_BRANCHES;
filter.abbrev = -1;
@@ -832,6 +827,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
if (list)
setup_auto_pager("branch", 1);
+ UNLEAK(sorting_options);
+
if (delete) {
if (!argc)
die(_("branch name required"));
@@ -859,6 +856,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
print_columns(&output, colopts, NULL);
string_list_clear(&output, 0);
ref_sorting_release(sorting);
+ ref_filter_clear(&filter);
return 0;
} else if (edit_description) {
const char *branch_name;
diff --git a/builtin/bugreport.c b/builtin/bugreport.c
index daf6c23657..d2ae5c305d 100644
--- a/builtin/bugreport.c
+++ b/builtin/bugreport.c
@@ -11,7 +11,6 @@
#include "diagnose.h"
#include "object-file.h"
#include "setup.h"
-#include "wrapper.h"
static void get_system_info(struct strbuf *sys_info)
{
diff --git a/builtin/bundle.c b/builtin/bundle.c
index 44113389d7..3ad11dc5d0 100644
--- a/builtin/bundle.c
+++ b/builtin/bundle.c
@@ -6,7 +6,6 @@
#include "parse-options.h"
#include "pkt-line.h"
#include "repository.h"
-#include "cache.h"
#include "bundle.h"
/*
@@ -69,42 +68,36 @@ static int parse_options_cmd_bundle(int argc,
}
static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
- int all_progress_implied = 1;
- int progress = isatty(STDERR_FILENO);
- struct strvec pack_opts;
+ struct strvec pack_opts = STRVEC_INIT;
int version = -1;
int ret;
struct option options[] = {
- OPT_SET_INT('q', "quiet", &progress,
- N_("do not show progress meter"), 0),
- OPT_SET_INT(0, "progress", &progress,
- N_("show progress meter"), 1),
- OPT_SET_INT_F(0, "all-progress", &progress,
- N_("historical; same as --progress"), 2,
- PARSE_OPT_HIDDEN),
- OPT_HIDDEN_BOOL(0, "all-progress-implied",
- &all_progress_implied,
- N_("historical; does nothing")),
+ OPT_PASSTHRU_ARGV('q', "quiet", &pack_opts, NULL,
+ N_("do not show progress meter"),
+ PARSE_OPT_NOARG),
+ OPT_PASSTHRU_ARGV(0, "progress", &pack_opts, NULL,
+ N_("show progress meter"),
+ PARSE_OPT_NOARG),
+ OPT_PASSTHRU_ARGV(0, "all-progress", &pack_opts, NULL,
+ N_("historical; same as --progress"),
+ PARSE_OPT_NOARG | PARSE_OPT_HIDDEN),
+ OPT_PASSTHRU_ARGV(0, "all-progress-implied", &pack_opts, NULL,
+ N_("historical; does nothing"),
+ PARSE_OPT_NOARG | PARSE_OPT_HIDDEN),
OPT_INTEGER(0, "version", &version,
N_("specify bundle format version")),
OPT_END()
};
char *bundle_file;
+ if (isatty(STDERR_FILENO))
+ strvec_push(&pack_opts, "--progress");
+ strvec_push(&pack_opts, "--all-progress-implied");
+
argc = parse_options_cmd_bundle(argc, argv, prefix,
builtin_bundle_create_usage, options, &bundle_file);
/* bundle internals use argv[1] as further parameters */
- strvec_init(&pack_opts);
- if (progress == 0)
- strvec_push(&pack_opts, "--quiet");
- else if (progress == 1)
- strvec_push(&pack_opts, "--progress");
- else if (progress == 2)
- strvec_push(&pack_opts, "--all-progress");
- if (progress && all_progress_implied)
- strvec_push(&pack_opts, "--all-progress-implied");
-
if (!startup_info->have_repository)
die(_("Need a repository to create a bundle."));
ret = !!create_bundle(the_repository, bundle_file, argc, argv, &pack_opts, version);
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 0bafc14e6c..694c8538df 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -4,11 +4,9 @@
* Copyright (C) Linus Torvalds, 2005
*/
#define USE_THE_INDEX_VARIABLE
-#include "cache.h"
-#include "alloc.h"
+#include "builtin.h"
#include "config.h"
#include "convert.h"
-#include "builtin.h"
#include "diff.h"
#include "environment.h"
#include "gettext.h"
@@ -22,7 +20,7 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "replace-object.h"
#include "promisor-remote.h"
#include "mailmap.h"
@@ -42,7 +40,8 @@ struct batch_options {
int all_objects;
int unordered;
int transform_mode; /* may be 'w' or 'c' for --filters or --textconv */
- int nul_terminated;
+ char input_delim;
+ char output_delim;
const char *format;
};
@@ -309,10 +308,8 @@ static int is_atom(const char *atom, const char *s, int slen)
}
static void expand_atom(struct strbuf *sb, const char *atom, int len,
- void *vdata)
+ struct expand_data *data)
{
- struct expand_data *data = vdata;
-
if (is_atom("objectname", atom, len)) {
if (!data->mark_query)
strbuf_addstr(sb, oid_to_hex(&data->oid));
@@ -346,19 +343,21 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len,
die("unknown format element: %.*s", len, atom);
}
-static size_t expand_format(struct strbuf *sb, const char *start, void *data)
+static void expand_format(struct strbuf *sb, const char *start,
+ struct expand_data *data)
{
- const char *end;
-
- if (*start != '(')
- return 0;
- end = strchr(start + 1, ')');
- if (!end)
- die("format element '%s' does not end in ')'", start);
-
- expand_atom(sb, start + 1, end - start - 1, data);
-
- return end - start + 1;
+ while (strbuf_expand_step(sb, &start)) {
+ const char *end;
+
+ if (skip_prefix(start, "%", &start) || *start != '(')
+ strbuf_addch(sb, '%');
+ else if (!(end = strchr(start + 1, ')')))
+ die("format element '%s' does not end in ')'", start);
+ else {
+ expand_atom(sb, start + 1, end - start - 1, data);
+ start = end + 1;
+ }
+ }
}
static void batch_write(struct batch_options *opt, const void *data, int len)
@@ -437,11 +436,12 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
}
}
-static void print_default_format(struct strbuf *scratch, struct expand_data *data)
+static void print_default_format(struct strbuf *scratch, struct expand_data *data,
+ struct batch_options *opt)
{
- strbuf_addf(scratch, "%s %s %"PRIuMAX"\n", oid_to_hex(&data->oid),
+ strbuf_addf(scratch, "%s %s %"PRIuMAX"%c", oid_to_hex(&data->oid),
type_name(data->type),
- (uintmax_t)data->size);
+ (uintmax_t)data->size, opt->output_delim);
}
/*
@@ -470,8 +470,8 @@ static void batch_object_write(const char *obj_name,
&data->oid, &data->info,
OBJECT_INFO_LOOKUP_REPLACE);
if (ret < 0) {
- printf("%s missing\n",
- obj_name ? obj_name : oid_to_hex(&data->oid));
+ printf("%s missing%c",
+ obj_name ? obj_name : oid_to_hex(&data->oid), opt->output_delim);
fflush(stdout);
return;
}
@@ -492,17 +492,17 @@ static void batch_object_write(const char *obj_name,
strbuf_reset(scratch);
if (!opt->format) {
- print_default_format(scratch, data);
+ print_default_format(scratch, data, opt);
} else {
- strbuf_expand(scratch, opt->format, expand_format, data);
- strbuf_addch(scratch, '\n');
+ expand_format(scratch, opt->format, data);
+ strbuf_addch(scratch, opt->output_delim);
}
batch_write(opt, scratch->buf, scratch->len);
if (opt->batch_mode == BATCH_MODE_CONTENTS) {
print_object_or_die(opt, data);
- batch_write(opt, "\n", 1);
+ batch_write(opt, &opt->output_delim, 1);
}
}
@@ -520,22 +520,25 @@ static void batch_one_object(const char *obj_name,
if (result != FOUND) {
switch (result) {
case MISSING_OBJECT:
- printf("%s missing\n", obj_name);
+ printf("%s missing%c", obj_name, opt->output_delim);
break;
case SHORT_NAME_AMBIGUOUS:
- printf("%s ambiguous\n", obj_name);
+ printf("%s ambiguous%c", obj_name, opt->output_delim);
break;
case DANGLING_SYMLINK:
- printf("dangling %"PRIuMAX"\n%s\n",
- (uintmax_t)strlen(obj_name), obj_name);
+ printf("dangling %"PRIuMAX"%c%s%c",
+ (uintmax_t)strlen(obj_name),
+ opt->output_delim, obj_name, opt->output_delim);
break;
case SYMLINK_LOOP:
- printf("loop %"PRIuMAX"\n%s\n",
- (uintmax_t)strlen(obj_name), obj_name);
+ printf("loop %"PRIuMAX"%c%s%c",
+ (uintmax_t)strlen(obj_name),
+ opt->output_delim, obj_name, opt->output_delim);
break;
case NOT_DIR:
- printf("notdir %"PRIuMAX"\n%s\n",
- (uintmax_t)strlen(obj_name), obj_name);
+ printf("notdir %"PRIuMAX"%c%s%c",
+ (uintmax_t)strlen(obj_name),
+ opt->output_delim, obj_name, opt->output_delim);
break;
default:
BUG("unknown get_sha1_with_context result %d\n",
@@ -547,9 +550,9 @@ static void batch_one_object(const char *obj_name,
}
if (ctx.mode == 0) {
- printf("symlink %"PRIuMAX"\n%s\n",
+ printf("symlink %"PRIuMAX"%c%s%c",
(uintmax_t)ctx.symlink_path.len,
- ctx.symlink_path.buf);
+ opt->output_delim, ctx.symlink_path.buf, opt->output_delim);
fflush(stdout);
return;
}
@@ -694,20 +697,12 @@ static void batch_objects_command(struct batch_options *opt,
struct queued_cmd *queued_cmd = NULL;
size_t alloc = 0, nr = 0;
- while (1) {
- int i, ret;
+ while (strbuf_getdelim_strip_crlf(&input, stdin, opt->input_delim) != EOF) {
+ int i;
const struct parse_cmd *cmd = NULL;
const char *p = NULL, *cmd_end;
struct queued_cmd call = {0};
- if (opt->nul_terminated)
- ret = strbuf_getline_nul(&input, stdin);
- else
- ret = strbuf_getline(&input, stdin);
-
- if (ret)
- break;
-
if (!input.len)
die(_("empty command in input"));
if (isspace(*input.buf))
@@ -777,9 +772,8 @@ static int batch_objects(struct batch_options *opt)
*/
memset(&data, 0, sizeof(data));
data.mark_query = 1;
- strbuf_expand(&output,
+ expand_format(&output,
opt->format ? opt->format : DEFAULT_FORMAT,
- expand_format,
&data);
data.mark_query = 0;
strbuf_release(&output);
@@ -805,7 +799,7 @@ static int batch_objects(struct batch_options *opt)
if (repo_has_promisor_remote(the_repository))
warning("This repository uses promisor remotes. Some objects may not be loaded.");
- read_replace_refs = 0;
+ disable_replace_refs();
cb.opt = opt;
cb.expand = &data;
@@ -851,16 +845,7 @@ static int batch_objects(struct batch_options *opt)
goto cleanup;
}
- while (1) {
- int ret;
- if (opt->nul_terminated)
- ret = strbuf_getline_nul(&input, stdin);
- else
- ret = strbuf_getline(&input, stdin);
-
- if (ret == EOF)
- break;
-
+ while (strbuf_getdelim_strip_crlf(&input, stdin, opt->input_delim) != EOF) {
if (data.split_on_whitespace) {
/*
* Split at first whitespace, tying off the beginning
@@ -885,12 +870,13 @@ static int batch_objects(struct batch_options *opt)
return retval;
}
-static int git_cat_file_config(const char *var, const char *value, void *cb)
+static int git_cat_file_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (userdiff_config(var, value) < 0)
return -1;
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static int batch_option_callback(const struct option *opt,
@@ -929,6 +915,8 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
const char *exp_type = NULL, *obj_name = NULL;
struct batch_options batch = {0};
int unknown_type = 0;
+ int input_nul_terminated = 0;
+ int nul_terminated = 0;
const char * const usage[] = {
N_("git cat-file <type> <object>"),
@@ -936,7 +924,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
N_("git cat-file (-t | -s) [--allow-unknown-type] <object>"),
N_("git cat-file (--batch | --batch-check | --batch-command) [--batch-all-objects]\n"
" [--buffer] [--follow-symlinks] [--unordered]\n"
- " [--textconv | --filters] [-z]"),
+ " [--textconv | --filters] [-Z]"),
N_("git cat-file (--textconv | --filters)\n"
" [<rev>:<path|tree-ish> | --path=<path|tree-ish> <rev>]"),
NULL
@@ -965,7 +953,9 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
N_("like --batch, but don't emit <contents>"),
PARSE_OPT_OPTARG | PARSE_OPT_NONEG,
batch_option_callback),
- OPT_BOOL('z', NULL, &batch.nul_terminated, N_("stdin is NUL-terminated")),
+ OPT_BOOL_F('z', NULL, &input_nul_terminated, N_("stdin is NUL-terminated"),
+ PARSE_OPT_HIDDEN),
+ OPT_BOOL('Z', NULL, &nul_terminated, N_("stdin and stdout is NUL-terminated")),
OPT_CALLBACK_F(0, "batch-command", &batch, N_("format"),
N_("read commands from stdin"),
PARSE_OPT_OPTARG | PARSE_OPT_NONEG,
@@ -1024,9 +1014,18 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
else if (batch.all_objects)
usage_msg_optf(_("'%s' requires a batch mode"), usage, options,
"--batch-all-objects");
- else if (batch.nul_terminated)
+ else if (input_nul_terminated)
usage_msg_optf(_("'%s' requires a batch mode"), usage, options,
"-z");
+ else if (nul_terminated)
+ usage_msg_optf(_("'%s' requires a batch mode"), usage, options,
+ "-Z");
+
+ batch.input_delim = batch.output_delim = '\n';
+ if (input_nul_terminated)
+ batch.input_delim = '\0';
+ if (nul_terminated)
+ batch.input_delim = batch.output_delim = '\0';
/* Batch defaults */
if (batch.buffer_output < 0)
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index e27b86d150..b22ff748c3 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -1,6 +1,5 @@
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
-#include "cache.h"
#include "config.h"
#include "attr.h"
#include "environment.h"
diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c
index e4b78782a3..906cd96753 100644
--- a/builtin/check-ignore.c
+++ b/builtin/check-ignore.c
@@ -1,6 +1,5 @@
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
-#include "cache.h"
#include "config.h"
#include "dir.h"
#include "gettext.h"
diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c
index 002d2941e9..b8a05b8e07 100644
--- a/builtin/check-mailmap.c
+++ b/builtin/check-mailmap.c
@@ -4,6 +4,7 @@
#include "ident.h"
#include "mailmap.h"
#include "parse-options.h"
+#include "strbuf.h"
#include "string-list.h"
#include "write-or-die.h"
diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
index 57f0505070..5eb6bdc3f6 100644
--- a/builtin/check-ref-format.c
+++ b/builtin/check-ref-format.c
@@ -2,9 +2,8 @@
* GIT - The information manager from hell
*/
-#include "cache.h"
-#include "refs.h"
#include "builtin.h"
+#include "refs.h"
#include "setup.h"
#include "strbuf.h"
diff --git a/builtin/checkout--worker.c b/builtin/checkout--worker.c
index 2120dd1d30..6b62b5375b 100644
--- a/builtin/checkout--worker.c
+++ b/builtin/checkout--worker.c
@@ -1,11 +1,11 @@
#include "builtin.h"
-#include "alloc.h"
#include "config.h"
#include "entry.h"
#include "gettext.h"
#include "parallel-checkout.h"
#include "parse-options.h"
#include "pkt-line.h"
+#include "read-cache-ll.h"
static void packet_to_pc_item(const char *buffer, int len,
struct parallel_checkout_item *pc_item)
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index 9375a05539..f62f13f2b5 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -16,7 +16,9 @@
#include "parse-options.h"
#include "entry.h"
#include "parallel-checkout.h"
+#include "read-cache-ll.h"
#include "setup.h"
+#include "sparse-index.h"
#define CHECKOUT_ALL 4
static int nul_term_line;
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 715eeb5048..f53612f468 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -13,13 +13,16 @@
#include "gettext.h"
#include "hex.h"
#include "hook.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
#include "lockfile.h"
#include "mem-pool.h"
#include "merge-recursive.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "parse-options.h"
+#include "path.h"
+#include "preload-index.h"
+#include "read-cache.h"
#include "refs.h"
#include "remote.h"
#include "resolve-undo.h"
@@ -861,7 +864,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
* entries in the index.
*/
- add_files_to_cache(NULL, NULL, 0);
+ add_files_to_cache(the_repository, NULL, NULL, 0, 0);
init_merge_options(&o, the_repository);
o.verbosity = 0;
work = write_in_core_index_as_tree(the_repository);
@@ -913,7 +916,7 @@ static void report_tracking(struct branch_info *new_branch_info)
struct strbuf sb = STRBUF_INIT;
struct branch *branch = branch_get(new_branch_info->name);
- if (!format_tracking_info(branch, &sb, AHEAD_BEHIND_FULL))
+ if (!format_tracking_info(branch, &sb, AHEAD_BEHIND_FULL, 1))
return;
fputs(sb.buf, stdout);
strbuf_release(&sb);
@@ -1186,7 +1189,8 @@ static int switch_branches(const struct checkout_opts *opts,
return ret || writeout_error;
}
-static int git_checkout_config(const char *var, const char *value, void *cb)
+static int git_checkout_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
struct checkout_opts *opts = cb;
@@ -1202,7 +1206,7 @@ static int git_checkout_config(const char *var, const char *value, void *cb)
if (starts_with(var, "submodule."))
return git_default_submodule_config(var, value, NULL);
- return git_xmerge_config(var, value, NULL);
+ return git_xmerge_config(var, value, ctx, NULL);
}
static void setup_new_branch_info_and_source_tree(
@@ -1689,8 +1693,13 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
}
if (opts->conflict_style) {
+ struct key_value_info kvi = KVI_INIT;
+ struct config_context ctx = {
+ .kvi = &kvi,
+ };
opts->merge = 1; /* implied */
- git_xmerge_config("merge.conflictstyle", opts->conflict_style, NULL);
+ git_xmerge_config("merge.conflictstyle", opts->conflict_style,
+ &ctx, NULL);
}
if (opts->force) {
opts->discard_changes = 1;
diff --git a/builtin/clean.c b/builtin/clean.c
index 78852d28ce..49c224e626 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -9,11 +9,12 @@
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "abspath.h"
-#include "cache.h"
#include "config.h"
#include "dir.h"
#include "gettext.h"
#include "parse-options.h"
+#include "path.h"
+#include "read-cache-ll.h"
#include "repository.h"
#include "setup.h"
#include "string-list.h"
@@ -103,7 +104,8 @@ struct menu_stuff {
define_list_config_array(color_interactive_slots);
-static int git_clean_config(const char *var, const char *value, void *cb)
+static int git_clean_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
const char *slot_name;
@@ -130,8 +132,10 @@ static int git_clean_config(const char *var, const char *value, void *cb)
return 0;
}
- /* inspect the color.ui config variable and others */
- return git_color_default_config(var, value, cb);
+ if (git_color_config(var, value, cb) < 0)
+ return -1;
+
+ return git_default_config(var, value, ctx, cb);
}
static const char *clean_get_color(enum color_clean ix)
diff --git a/builtin/clone.c b/builtin/clone.c
index 15f9912b4c..c6357af949 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -23,7 +23,7 @@
#include "refs.h"
#include "refspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "tree.h"
#include "tree-walk.h"
#include "unpack-trees.h"
@@ -39,12 +39,12 @@
#include "setup.h"
#include "connected.h"
#include "packfile.h"
+#include "path.h"
#include "pkt-line.h"
#include "list-objects-filter-options.h"
#include "hook.h"
#include "bundle.h"
#include "bundle-uri.h"
-#include "wrapper.h"
/*
* Overall FIXMEs:
@@ -161,10 +161,7 @@ static struct option builtin_clone_options[] = {
N_("set config inside the new repository")),
OPT_STRING_LIST(0, "server-option", &server_options,
N_("server-specific"), N_("option to transmit")),
- OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
- TRANSPORT_FAMILY_IPV4),
- OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
- TRANSPORT_FAMILY_IPV6),
+ OPT_IPVERSION(&family),
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
OPT_BOOL(0, "also-filter-submodules", &option_filter_submodules,
N_("apply partial clone filters to submodules")),
@@ -790,7 +787,8 @@ static int checkout(int submodule_progress, int filter_submodules)
return err;
}
-static int git_clone_config(const char *k, const char *v, void *cb)
+static int git_clone_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(k, "clone.defaultremotename")) {
free(remote_name);
@@ -801,17 +799,19 @@ static int git_clone_config(const char *k, const char *v, void *cb)
if (!strcmp(k, "clone.filtersubmodules"))
config_filter_submodules = git_config_bool(k, v);
- return git_default_config(k, v, cb);
+ return git_default_config(k, v, ctx, cb);
}
-static int write_one_config(const char *key, const char *value, void *data)
+static int write_one_config(const char *key, const char *value,
+ const struct config_context *ctx,
+ void *data)
{
/*
* give git_clone_config a chance to write config values back to the
* environment, since git_config_set_multivar_gently only deals with
* config-file writes
*/
- int apply_failed = git_clone_config(key, value, data);
+ int apply_failed = git_clone_config(key, value, ctx, data);
if (apply_failed)
return apply_failed;
@@ -930,6 +930,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
int submodule_progress;
int filter_submodules = 0;
int hash_algo;
+ const int do_not_override_repo_unix_permissions = -1;
struct transport_ls_refs_options transport_ls_refs_options =
TRANSPORT_LS_REFS_OPTIONS_INIT;
@@ -1097,7 +1098,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
}
init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,
- INIT_DB_QUIET);
+ do_not_override_repo_unix_permissions, INIT_DB_QUIET);
if (real_git_dir) {
free((char *)git_dir);
diff --git a/builtin/column.c b/builtin/column.c
index de623a16c2..a83be8bc99 100644
--- a/builtin/column.c
+++ b/builtin/column.c
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "cache.h"
#include "config.h"
#include "gettext.h"
#include "strbuf.h"
@@ -13,7 +12,8 @@ static const char * const builtin_column_usage[] = {
};
static unsigned int colopts;
-static int column_config(const char *var, const char *value, void *cb)
+static int column_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED, void *cb)
{
return git_column_config(var, value, cb, &colopts);
}
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index a3d00fa232..c88389df24 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "commit.h"
#include "config.h"
#include "dir.h"
#include "environment.h"
@@ -8,7 +9,7 @@
#include "parse-options.h"
#include "repository.h"
#include "commit-graph.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "progress.h"
#include "replace-object.h"
#include "tag.h"
@@ -186,10 +187,11 @@ static int write_option_max_new_filters(const struct option *opt,
}
static int git_commit_graph_write_config(const char *var, const char *value,
+ const struct config_context *ctx,
void *cb UNUSED)
{
if (!strcmp(var, "commitgraph.maxnewfilters"))
- write_opts.max_new_filters = git_config_int(var, value);
+ write_opts.max_new_filters = git_config_int(var, value, ctx->kvi);
/*
* No need to fall-back to 'git_default_config', since this was already
* called in 'cmd_commit_graph()'.
@@ -324,7 +326,7 @@ int cmd_commit_graph(int argc, const char **argv, const char *prefix)
git_config(git_default_config, NULL);
- read_replace_refs = 0;
+ disable_replace_refs();
save_commit_buffer = 0;
argc = parse_options(argc, argv, prefix, options,
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index d1d251c3de..02625e7176 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -3,16 +3,15 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
-#include "cache.h"
+#include "builtin.h"
#include "config.h"
#include "gettext.h"
#include "hex.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "repository.h"
#include "commit.h"
#include "tree.h"
-#include "builtin.h"
#include "utf8.h"
#include "gpg-interface.h"
#include "parse-options.h"
diff --git a/builtin/commit.c b/builtin/commit.c
index e67c4be221..7da5f92448 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -6,7 +6,7 @@
*/
#define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
#include "advice.h"
#include "config.h"
#include "lockfile.h"
@@ -15,7 +15,6 @@
#include "dir.h"
#include "editor.h"
#include "environment.h"
-#include "builtin.h"
#include "diff.h"
#include "diffcore.h"
#include "commit.h"
@@ -30,6 +29,9 @@
#include "utf8.h"
#include "object-name.h"
#include "parse-options.h"
+#include "path.h"
+#include "preload-index.h"
+#include "read-cache.h"
#include "string-list.h"
#include "rerere.h"
#include "unpack-trees.h"
@@ -38,6 +40,7 @@
#include "gpg-interface.h"
#include "column.h"
#include "sequencer.h"
+#include "sparse-index.h"
#include "mailmap.h"
#include "help.h"
#include "commit-reach.h"
@@ -447,7 +450,8 @@ static const char *prepare_index(const char **argv, const char *prefix,
if (all || (also && pathspec.nr)) {
repo_hold_locked_index(the_repository, &index_lock,
LOCK_DIE_ON_ERROR);
- add_files_to_cache(also ? prefix : NULL, &pathspec, 0);
+ add_files_to_cache(the_repository, also ? prefix : NULL,
+ &pathspec, 0, 0);
refresh_cache_or_die(refresh_flags);
cache_tree_update(&the_index, WRITE_TREE_SILENT);
if (write_locked_index(&the_index, &index_lock, 0))
@@ -763,7 +767,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
struct commit *c;
c = lookup_commit_reference_by_name(squash_message);
if (!c)
- die(_("could not lookup commit %s"), squash_message);
+ die(_("could not lookup commit '%s'"), squash_message);
ctx.output_encoding = get_commit_output_encoding();
repo_format_commit_message(the_repository, c,
"squash! %s\n\n", &sb,
@@ -798,7 +802,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
char *fmt;
commit = lookup_commit_reference_by_name(fixup_commit);
if (!commit)
- die(_("could not lookup commit %s"), fixup_commit);
+ die(_("could not lookup commit '%s'"), fixup_commit);
ctx.output_encoding = get_commit_output_encoding();
fmt = xstrfmt("%s! %%s\n\n", fixup_prefix);
repo_format_commit_message(the_repository, commit, fmt, &sb,
@@ -893,7 +897,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
s->hints = 0;
if (clean_message_contents)
- strbuf_stripspace(&sb, 0);
+ strbuf_stripspace(&sb, '\0');
if (signoff)
append_signoff(&sb, ignore_non_trailer(sb.buf, sb.len), 0);
@@ -998,11 +1002,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
struct object_id oid;
const char *parent = "HEAD";
- if (!the_index.cache_nr) {
- discard_index(&the_index);
- if (repo_read_index(the_repository) < 0)
- die(_("Cannot read index"));
- }
+ if (!the_index.initialized && repo_read_index(the_repository) < 0)
+ die(_("Cannot read index"));
if (amend)
parent = "HEAD^1";
@@ -1043,7 +1044,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
struct child_process run_trailer = CHILD_PROCESS_INIT;
strvec_pushl(&run_trailer.args, "interpret-trailers",
- "--in-place", git_path_commit_editmsg(), NULL);
+ "--in-place", "--no-divider",
+ git_path_commit_editmsg(), NULL);
strvec_pushv(&run_trailer.args, trailer_args.v);
run_trailer.git_cmd = 1;
if (run_command(&run_trailer))
@@ -1189,7 +1191,7 @@ static const char *read_commit_message(const char *name)
commit = lookup_commit_reference_by_name(name);
if (!commit)
- die(_("could not lookup commit %s"), name);
+ die(_("could not lookup commit '%s'"), name);
out_enc = get_commit_output_encoding();
return repo_logmsg_reencode(the_repository, commit, NULL, out_enc);
}
@@ -1405,7 +1407,8 @@ static int parse_status_slot(const char *slot)
return LOOKUP_CONFIG(color_status_slots, slot);
}
-static int git_status_config(const char *k, const char *v, void *cb)
+static int git_status_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
struct wt_status *s = cb;
const char *slot_name;
@@ -1414,7 +1417,8 @@ static int git_status_config(const char *k, const char *v, void *cb)
return git_column_config(k, v, "status", &s->colopts);
if (!strcmp(k, "status.submodulesummary")) {
int is_bool;
- s->submodule_summary = git_config_bool_or_int(k, v, &is_bool);
+ s->submodule_summary = git_config_bool_or_int(k, v, ctx->kvi,
+ &is_bool);
if (is_bool && s->submodule_summary)
s->submodule_summary = -1;
return 0;
@@ -1474,11 +1478,11 @@ static int git_status_config(const char *k, const char *v, void *cb)
}
if (!strcmp(k, "diff.renamelimit")) {
if (s->rename_limit == -1)
- s->rename_limit = git_config_int(k, v);
+ s->rename_limit = git_config_int(k, v, ctx->kvi);
return 0;
}
if (!strcmp(k, "status.renamelimit")) {
- s->rename_limit = git_config_int(k, v);
+ s->rename_limit = git_config_int(k, v, ctx->kvi);
return 0;
}
if (!strcmp(k, "diff.renames")) {
@@ -1490,7 +1494,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
s->detect_rename = git_config_rename(k, v);
return 0;
}
- return git_diff_ui_config(k, v, NULL);
+ return git_diff_ui_config(k, v, ctx, NULL);
}
int cmd_status(int argc, const char **argv, const char *prefix)
@@ -1605,7 +1609,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
return 0;
}
-static int git_commit_config(const char *k, const char *v, void *cb)
+static int git_commit_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
struct wt_status *s = cb;
@@ -1623,11 +1628,12 @@ static int git_commit_config(const char *k, const char *v, void *cb)
}
if (!strcmp(k, "commit.verbose")) {
int is_bool;
- config_commit_verbose = git_config_bool_or_int(k, v, &is_bool);
+ config_commit_verbose = git_config_bool_or_int(k, v, ctx->kvi,
+ &is_bool);
return 0;
}
- return git_status_config(k, v, s);
+ return git_status_config(k, v, ctx, s);
}
int cmd_commit(int argc, const char **argv, const char *prefix)
diff --git a/builtin/config.c b/builtin/config.c
index ff2fe8ef12..11a4d4ef14 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -1,10 +1,10 @@
#include "builtin.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "color.h"
#include "editor.h"
#include "environment.h"
+#include "repository.h"
#include "gettext.h"
#include "ident.h"
#include "parse-options.h"
@@ -12,8 +12,8 @@
#include "path.h"
#include "quote.h"
#include "setup.h"
+#include "strbuf.h"
#include "worktree.h"
-#include "wrapper.h"
static const char *const builtin_config_usage[] = {
N_("git config [<options>]"),
@@ -193,37 +193,42 @@ static void check_argc(int argc, int min, int max)
usage_builtin_config();
}
-static void show_config_origin(struct strbuf *buf)
+static void show_config_origin(const struct key_value_info *kvi,
+ struct strbuf *buf)
{
const char term = end_nul ? '\0' : '\t';
- strbuf_addstr(buf, current_config_origin_type());
+ strbuf_addstr(buf, config_origin_type_name(kvi->origin_type));
strbuf_addch(buf, ':');
if (end_nul)
- strbuf_addstr(buf, current_config_name());
+ strbuf_addstr(buf, kvi->filename ? kvi->filename : "");
else
- quote_c_style(current_config_name(), buf, NULL, 0);
+ quote_c_style(kvi->filename ? kvi->filename : "", buf, NULL, 0);
strbuf_addch(buf, term);
}
-static void show_config_scope(struct strbuf *buf)
+static void show_config_scope(const struct key_value_info *kvi,
+ struct strbuf *buf)
{
const char term = end_nul ? '\0' : '\t';
- const char *scope = config_scope_name(current_config_scope());
+ const char *scope = config_scope_name(kvi->scope);
strbuf_addstr(buf, N_(scope));
strbuf_addch(buf, term);
}
static int show_all_config(const char *key_, const char *value_,
+ const struct config_context *ctx,
void *cb UNUSED)
{
+ const struct key_value_info *kvi = ctx->kvi;
+
if (show_origin || show_scope) {
struct strbuf buf = STRBUF_INIT;
if (show_scope)
- show_config_scope(&buf);
+ show_config_scope(kvi, &buf);
if (show_origin)
- show_config_origin(&buf);
+ show_config_origin(kvi, &buf);
/* Use fwrite as "buf" can contain \0's if "end_null" is set. */
fwrite(buf.buf, 1, buf.len, stdout);
strbuf_release(&buf);
@@ -241,12 +246,13 @@ struct strbuf_list {
int alloc;
};
-static int format_config(struct strbuf *buf, const char *key_, const char *value_)
+static int format_config(struct strbuf *buf, const char *key_,
+ const char *value_, const struct key_value_info *kvi)
{
if (show_scope)
- show_config_scope(buf);
+ show_config_scope(kvi, buf);
if (show_origin)
- show_config_origin(buf);
+ show_config_origin(kvi, buf);
if (show_keys)
strbuf_addstr(buf, key_);
if (!omit_values) {
@@ -255,13 +261,14 @@ static int format_config(struct strbuf *buf, const char *key_, const char *value
if (type == TYPE_INT)
strbuf_addf(buf, "%"PRId64,
- git_config_int64(key_, value_ ? value_ : ""));
+ git_config_int64(key_, value_ ? value_ : "", kvi));
else if (type == TYPE_BOOL)
strbuf_addstr(buf, git_config_bool(key_, value_) ?
"true" : "false");
else if (type == TYPE_BOOL_OR_INT) {
int is_bool, v;
- v = git_config_bool_or_int(key_, value_, &is_bool);
+ v = git_config_bool_or_int(key_, value_, kvi,
+ &is_bool);
if (is_bool)
strbuf_addstr(buf, v ? "true" : "false");
else
@@ -300,9 +307,11 @@ static int format_config(struct strbuf *buf, const char *key_, const char *value
return 0;
}
-static int collect_config(const char *key_, const char *value_, void *cb)
+static int collect_config(const char *key_, const char *value_,
+ const struct config_context *ctx, void *cb)
{
struct strbuf_list *values = cb;
+ const struct key_value_info *kvi = ctx->kvi;
if (!use_key_regexp && strcmp(key_, key))
return 0;
@@ -317,7 +326,7 @@ static int collect_config(const char *key_, const char *value_, void *cb)
ALLOC_GROW(values->items, values->nr + 1, values->alloc);
strbuf_init(&values->items[values->nr], 0);
- return format_config(&values->items[values->nr++], key_, value_);
+ return format_config(&values->items[values->nr++], key_, value_, kvi);
}
static int get_value(const char *key_, const char *regex_, unsigned flags)
@@ -375,14 +384,18 @@ static int get_value(const char *key_, const char *regex_, unsigned flags)
}
config_with_options(collect_config, &values,
- &given_config_source, &config_options);
+ &given_config_source, the_repository,
+ &config_options);
if (!values.nr && default_value) {
+ struct key_value_info kvi = KVI_INIT;
struct strbuf *item;
+
+ kvi_from_param(&kvi);
ALLOC_GROW(values.items, values.nr + 1, values.alloc);
item = &values.items[values.nr++];
strbuf_init(item, 0);
- if (format_config(item, key_, default_value) < 0)
+ if (format_config(item, key_, default_value, &kvi) < 0)
die(_("failed to format default config value: %s"),
default_value);
}
@@ -411,7 +424,8 @@ free_strings:
return ret;
}
-static char *normalize_value(const char *key, const char *value)
+static char *normalize_value(const char *key, const char *value,
+ struct key_value_info *kvi)
{
if (!value)
return NULL;
@@ -426,12 +440,12 @@ static char *normalize_value(const char *key, const char *value)
*/
return xstrdup(value);
if (type == TYPE_INT)
- return xstrfmt("%"PRId64, git_config_int64(key, value));
+ return xstrfmt("%"PRId64, git_config_int64(key, value, kvi));
if (type == TYPE_BOOL)
return xstrdup(git_config_bool(key, value) ? "true" : "false");
if (type == TYPE_BOOL_OR_INT) {
int is_bool, v;
- v = git_config_bool_or_int(key, value, &is_bool);
+ v = git_config_bool_or_int(key, value, kvi, &is_bool);
if (!is_bool)
return xstrfmt("%d", v);
else
@@ -468,6 +482,7 @@ static const char *get_colorbool_slot;
static char parsed_color[COLOR_MAXLEN];
static int git_get_color_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
if (!strcmp(var, get_color_slot)) {
@@ -486,7 +501,8 @@ static void get_color(const char *var, const char *def_color)
get_color_found = 0;
parsed_color[0] = '\0';
config_with_options(git_get_color_config, NULL,
- &given_config_source, &config_options);
+ &given_config_source, the_repository,
+ &config_options);
if (!get_color_found && def_color) {
if (color_parse(def_color, parsed_color) < 0)
@@ -500,6 +516,7 @@ static int get_colorbool_found;
static int get_diff_color_found;
static int get_color_ui_found;
static int git_get_colorbool_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *data UNUSED)
{
if (!strcmp(var, get_colorbool_slot))
@@ -518,7 +535,8 @@ static int get_colorbool(const char *var, int print)
get_diff_color_found = -1;
get_color_ui_found = -1;
config_with_options(git_get_colorbool_config, NULL,
- &given_config_source, &config_options);
+ &given_config_source, the_repository,
+ &config_options);
if (get_colorbool_found < 0) {
if (!strcmp(get_colorbool_slot, "color.diff"))
@@ -555,13 +573,17 @@ static void check_write(void)
struct urlmatch_current_candidate_value {
char value_is_null;
struct strbuf value;
+ struct key_value_info kvi;
};
-static int urlmatch_collect_fn(const char *var, const char *value, void *cb)
+static int urlmatch_collect_fn(const char *var, const char *value,
+ const struct config_context *ctx,
+ void *cb)
{
struct string_list *values = cb;
struct string_list_item *item = string_list_insert(values, var);
struct urlmatch_current_candidate_value *matched = item->util;
+ const struct key_value_info *kvi = ctx->kvi;
if (!matched) {
matched = xmalloc(sizeof(*matched));
@@ -570,6 +592,7 @@ static int urlmatch_collect_fn(const char *var, const char *value, void *cb)
} else {
strbuf_reset(&matched->value);
}
+ matched->kvi = *kvi;
if (value) {
strbuf_addstr(&matched->value, value);
@@ -607,7 +630,8 @@ static int get_urlmatch(const char *var, const char *url)
}
config_with_options(urlmatch_config_entry, &config,
- &given_config_source, &config_options);
+ &given_config_source, the_repository,
+ &config_options);
ret = !values.nr;
@@ -616,7 +640,8 @@ static int get_urlmatch(const char *var, const char *url)
struct strbuf buf = STRBUF_INIT;
format_config(&buf, item->string,
- matched->value_is_null ? NULL : matched->value.buf);
+ matched->value_is_null ? NULL : matched->value.buf,
+ &matched->kvi);
fwrite(buf.buf, 1, buf.len, stdout);
strbuf_release(&buf);
@@ -650,6 +675,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
char *value = NULL;
int flags = 0;
int ret = 0;
+ struct key_value_info default_kvi = KVI_INIT;
given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT));
@@ -713,7 +739,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
given_config_source.scope = CONFIG_SCOPE_LOCAL;
} else if (use_worktree_config) {
struct worktree **worktrees = get_worktrees();
- if (repository_format_worktree_config)
+ if (the_repository->repository_format_worktree_config)
given_config_source.file = git_pathdup("config.worktree");
else if (worktrees[0] && worktrees[1])
die(_("--worktree cannot be used with multiple "
@@ -827,7 +853,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
if (actions == ACTION_LIST) {
check_argc(argc, 0, 0);
if (config_with_options(show_all_config, NULL,
- &given_config_source,
+ &given_config_source, the_repository,
&config_options) < 0) {
if (given_config_source.file)
die_errno(_("unable to read config file '%s'"),
@@ -867,7 +893,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
else if (actions == ACTION_SET) {
check_write();
check_argc(argc, 2, 2);
- value = normalize_value(argv[0], argv[1]);
+ value = normalize_value(argv[0], argv[1], &default_kvi);
ret = git_config_set_in_file_gently(given_config_source.file, argv[0], value);
if (ret == CONFIG_NOTHING_SET)
error(_("cannot overwrite multiple values with a single value\n"
@@ -876,7 +902,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
else if (actions == ACTION_SET_ALL) {
check_write();
check_argc(argc, 2, 3);
- value = normalize_value(argv[0], argv[1]);
+ value = normalize_value(argv[0], argv[1], &default_kvi);
ret = git_config_set_multivar_in_file_gently(given_config_source.file,
argv[0], value, argv[2],
flags);
@@ -884,7 +910,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
else if (actions == ACTION_ADD) {
check_write();
check_argc(argc, 2, 2);
- value = normalize_value(argv[0], argv[1]);
+ value = normalize_value(argv[0], argv[1], &default_kvi);
ret = git_config_set_multivar_in_file_gently(given_config_source.file,
argv[0], value,
CONFIG_REGEX_NONE,
@@ -893,7 +919,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
else if (actions == ACTION_REPLACE_ALL) {
check_write();
check_argc(argc, 2, 3);
- value = normalize_value(argv[0], argv[1]);
+ value = normalize_value(argv[0], argv[1], &default_kvi);
ret = git_config_set_multivar_in_file_gently(given_config_source.file,
argv[0], value, argv[2],
flags | CONFIG_FLAGS_MULTI_REPLACE);
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index f3d8f1bcbb..2d4bb5e8d0 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -4,17 +4,17 @@
* Copyright (c) 2006 Junio C Hamano
*/
-#include "cache.h"
+#include "builtin.h"
#include "config.h"
#include "dir.h"
#include "environment.h"
#include "gettext.h"
+#include "path.h"
#include "repository.h"
-#include "builtin.h"
#include "parse-options.h"
#include "quote.h"
#include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
static unsigned long garbage;
static off_t size_garbage;
@@ -82,7 +82,7 @@ static int count_cruft(const char *basename UNUSED, const char *path,
return 0;
}
-static int print_alternate(struct object_directory *odb, void *data)
+static int print_alternate(struct object_directory *odb, void *data UNUSED)
{
printf("alternate: ");
quote_c_style(odb->path, NULL, stdout, 0);
diff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c
index 756c5f02ae..3a6a750a8e 100644
--- a/builtin/credential-cache--daemon.c
+++ b/builtin/credential-cache--daemon.c
@@ -1,6 +1,5 @@
#include "builtin.h"
#include "abspath.h"
-#include "alloc.h"
#include "gettext.h"
#include "object-file.h"
#include "parse-options.h"
@@ -38,19 +37,22 @@ static struct credential_cache_entry *lookup_credential(const struct credential
int i;
for (i = 0; i < entries_nr; i++) {
struct credential *e = &entries[i].item;
- if (credential_match(c, e))
+ if (credential_match(c, e, 0))
return &entries[i];
}
return NULL;
}
-static void remove_credential(const struct credential *c)
+static void remove_credential(const struct credential *c, int match_password)
{
struct credential_cache_entry *e;
- e = lookup_credential(c);
- if (e)
- e->expiration = 0;
+ int i;
+ for (i = 0; i < entries_nr; i++) {
+ e = &entries[i];
+ if (credential_match(c, &e->item, match_password))
+ e->expiration = 0;
+ }
}
static timestamp_t check_expirations(void)
@@ -151,14 +153,14 @@ static void serve_one_client(FILE *in, FILE *out)
exit(0);
}
else if (!strcmp(action.buf, "erase"))
- remove_credential(&c);
+ remove_credential(&c, 1);
else if (!strcmp(action.buf, "store")) {
if (timeout < 0)
warning("cache client didn't specify a timeout");
else if (!c.username || !c.password)
warning("cache client gave us a partial credential");
else {
- remove_credential(&c);
+ remove_credential(&c, 0);
cache_credential(&c, timeout);
}
}
diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c
index 0ffacfdd83..43b9d0e5b1 100644
--- a/builtin/credential-cache.c
+++ b/builtin/credential-cache.c
@@ -2,7 +2,7 @@
#include "gettext.h"
#include "parse-options.h"
#include "path.h"
-#include "wrapper.h"
+#include "strbuf.h"
#include "write-or-die.h"
#ifndef NO_UNIX_SOCKETS
diff --git a/builtin/credential-store.c b/builtin/credential-store.c
index 30c6ccf56c..4a492411bb 100644
--- a/builtin/credential-store.c
+++ b/builtin/credential-store.c
@@ -13,7 +13,8 @@ static struct lock_file credential_lock;
static int parse_credential_file(const char *fn,
struct credential *c,
void (*match_cb)(struct credential *),
- void (*other_cb)(struct strbuf *))
+ void (*other_cb)(struct strbuf *),
+ int match_password)
{
FILE *fh;
struct strbuf line = STRBUF_INIT;
@@ -30,7 +31,7 @@ static int parse_credential_file(const char *fn,
while (strbuf_getline_lf(&line, fh) != EOF) {
if (!credential_from_url_gently(&entry, line.buf, 1) &&
entry.username && entry.password &&
- credential_match(c, &entry)) {
+ credential_match(c, &entry, match_password)) {
found_credential = 1;
if (match_cb) {
match_cb(&entry);
@@ -60,7 +61,7 @@ static void print_line(struct strbuf *buf)
}
static void rewrite_credential_file(const char *fn, struct credential *c,
- struct strbuf *extra)
+ struct strbuf *extra, int match_password)
{
int timeout_ms = 1000;
@@ -69,11 +70,30 @@ static void rewrite_credential_file(const char *fn, struct credential *c,
die_errno(_("unable to get credential storage lock in %d ms"), timeout_ms);
if (extra)
print_line(extra);
- parse_credential_file(fn, c, NULL, print_line);
+ parse_credential_file(fn, c, NULL, print_line, match_password);
if (commit_lock_file(&credential_lock) < 0)
die_errno("unable to write credential store");
}
+static int is_rfc3986_unreserved(char ch)
+{
+ return isalnum(ch) ||
+ ch == '-' || ch == '_' || ch == '.' || ch == '~';
+}
+
+static int is_rfc3986_reserved_or_unreserved(char ch)
+{
+ if (is_rfc3986_unreserved(ch))
+ return 1;
+ switch (ch) {
+ case '!': case '*': case '\'': case '(': case ')': case ';':
+ case ':': case '@': case '&': case '=': case '+': case '$':
+ case ',': case '/': case '?': case '#': case '[': case ']':
+ return 1;
+ }
+ return 0;
+}
+
static void store_credential_file(const char *fn, struct credential *c)
{
struct strbuf buf = STRBUF_INIT;
@@ -91,7 +111,7 @@ static void store_credential_file(const char *fn, struct credential *c)
is_rfc3986_reserved_or_unreserved);
}
- rewrite_credential_file(fn, c, &buf);
+ rewrite_credential_file(fn, c, &buf, 0);
strbuf_release(&buf);
}
@@ -138,7 +158,7 @@ static void remove_credential(const struct string_list *fns, struct credential *
return;
for_each_string_list_item(fn, fns)
if (!access(fn->string, F_OK))
- rewrite_credential_file(fn->string, c, NULL);
+ rewrite_credential_file(fn->string, c, NULL, 1);
}
static void lookup_credential(const struct string_list *fns, struct credential *c)
@@ -146,7 +166,7 @@ static void lookup_credential(const struct string_list *fns, struct credential *
struct string_list_item *fn;
for_each_string_list_item(fn, fns)
- if (parse_credential_file(fn->string, c, print_entry, NULL))
+ if (parse_credential_file(fn->string, c, print_entry, NULL, 0))
return; /* Found credential */
}
diff --git a/builtin/describe.c b/builtin/describe.c
index 55b4baaa22..b28a4a1f82 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -1,5 +1,5 @@
#define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
@@ -9,21 +9,23 @@
#include "tag.h"
#include "blob.h"
#include "refs.h"
-#include "builtin.h"
#include "exec-cmd.h"
#include "object-name.h"
#include "parse-options.h"
+#include "read-cache-ll.h"
#include "revision.h"
#include "diff.h"
#include "hashmap.h"
#include "setup.h"
#include "strvec.h"
#include "run-command.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "list-objects.h"
#include "commit-slab.h"
+#include "wildmatch.h"
#define MAX_TAGS (FLAG_BITS - 1)
+#define DEFAULT_CANDIDATES 10
define_commit_slab(commit_names, struct commit_name *);
@@ -40,7 +42,7 @@ static int tags; /* Allow lightweight tags */
static int longformat;
static int first_parent;
static int abbrev = -1; /* unspecified */
-static int max_candidates = 10;
+static int max_candidates = DEFAULT_CANDIDATES;
static struct hashmap names;
static int have_util;
static struct string_list patterns = STRING_LIST_INIT_NODUP;
@@ -556,6 +558,15 @@ static void describe(const char *arg, int last_one)
strbuf_release(&sb);
}
+static int option_parse_exact_match(const struct option *opt, const char *arg,
+ int unset)
+{
+ BUG_ON_OPT_ARG(arg);
+
+ max_candidates = unset ? DEFAULT_CANDIDATES : 0;
+ return 0;
+}
+
int cmd_describe(int argc, const char **argv, const char *prefix)
{
int contains = 0;
@@ -567,8 +578,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
OPT_BOOL(0, "long", &longformat, N_("always use long format")),
OPT_BOOL(0, "first-parent", &first_parent, N_("only follow first parent")),
OPT__ABBREV(&abbrev),
- OPT_SET_INT(0, "exact-match", &max_candidates,
- N_("only output exact matches"), 0),
+ OPT_CALLBACK_F(0, "exact-match", NULL, NULL,
+ N_("only output exact matches"),
+ PARSE_OPT_NOARG, option_parse_exact_match),
OPT_INTEGER(0, "candidates", &max_candidates,
N_("consider <n> most recent tags (default: 10)")),
OPT_STRING_LIST(0, "match", &patterns, N_("pattern"),
diff --git a/builtin/diff-files.c b/builtin/diff-files.c
index 360464e6ef..50330b8dd2 100644
--- a/builtin/diff-files.c
+++ b/builtin/diff-files.c
@@ -3,13 +3,14 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
-#include "cache.h"
+#include "builtin.h"
#include "config.h"
#include "diff.h"
#include "diff-merges.h"
#include "commit.h"
+#include "preload-index.h"
+#include "repository.h"
#include "revision.h"
-#include "builtin.h"
#include "submodule.h"
static const char diff_files_usage[] =
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index b9a19bb7d3..9db7139b83 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -1,11 +1,13 @@
-#include "cache.h"
+#include "builtin.h"
#include "config.h"
#include "diff.h"
#include "diff-merges.h"
#include "commit.h"
+#include "preload-index.h"
+#include "repository.h"
#include "revision.h"
-#include "builtin.h"
#include "setup.h"
+#include "sparse-index.h"
#include "submodule.h"
static const char diff_cache_usage[] =
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index 0b02c62b85..c9ba35f143 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -1,14 +1,15 @@
#define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
#include "config.h"
#include "diff.h"
#include "commit.h"
#include "gettext.h"
#include "hex.h"
#include "log-tree.h"
-#include "builtin.h"
#include "submodule.h"
+#include "read-cache-ll.h"
#include "repository.h"
+#include "revision.h"
#include "tree.h"
static struct rev_info log_tree_opt;
@@ -98,7 +99,7 @@ static const char diff_tree_usage[] =
" --root include the initial commit as diff against /dev/null\n"
COMMON_DIFF_OPTIONS_HELP;
-static void diff_tree_tweak_rev(struct rev_info *rev, struct setup_revision_opt *opt)
+static void diff_tree_tweak_rev(struct rev_info *rev)
{
if (!rev->diffopt.output_format) {
if (rev->dense_combined_merges)
@@ -122,6 +123,10 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
usage(diff_tree_usage);
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
+
+ prepare_repo_settings(the_repository);
+ the_repository->settings.command_requires_full_index = 0;
+
repo_init_revisions(the_repository, opt, prefix);
if (repo_read_index(the_repository) < 0)
die(_("index file corrupt"));
diff --git a/builtin/diff.c b/builtin/diff.c
index 7b64659fe7..b19530c996 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -4,7 +4,7 @@
* Copyright (c) 2006 Junio C Hamano
*/
#define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
#include "config.h"
#include "ewah/ewok.h"
#include "lockfile.h"
@@ -16,9 +16,10 @@
#include "diff.h"
#include "diff-merges.h"
#include "diffcore.h"
+#include "preload-index.h"
+#include "read-cache-ll.h"
#include "revision.h"
#include "log-tree.h"
-#include "builtin.h"
#include "setup.h"
#include "submodule.h"
#include "oid-array.h"
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 0049342f5c..0f5eae9cd4 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -12,26 +12,26 @@
* Copyright (C) 2016 Johannes Schindelin
*/
#define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
#include "abspath.h"
#include "config.h"
#include "copy.h"
-#include "builtin.h"
#include "run-command.h"
#include "environment.h"
#include "exec-cmd.h"
#include "gettext.h"
#include "hex.h"
#include "parse-options.h"
+#include "read-cache-ll.h"
+#include "sparse-index.h"
#include "strvec.h"
#include "strbuf.h"
#include "lockfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "dir.h"
#include "entry.h"
#include "setup.h"
-#include "wrapper.h"
static int trust_exit_code;
@@ -40,14 +40,15 @@ static const char *const builtin_difftool_usage[] = {
NULL
};
-static int difftool_config(const char *var, const char *value, void *cb)
+static int difftool_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "difftool.trustexitcode")) {
trust_exit_code = git_config_bool(var, value);
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static int print_tool_help(void)
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 9a95f6a1a8..56dc69fac1 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -4,14 +4,13 @@
* Copyright (C) 2007 Johannes E. Schindelin
*/
#include "builtin.h"
-#include "cache.h"
#include "config.h"
#include "gettext.h"
#include "hex.h"
#include "refs.h"
#include "refspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "commit.h"
#include "object.h"
#include "tag.h"
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index bbd9b2b3e7..4dbb10aff3 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1,6 +1,5 @@
#include "builtin.h"
#include "abspath.h"
-#include "cache.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
@@ -13,6 +12,7 @@
#include "commit.h"
#include "delta.h"
#include "pack.h"
+#include "path.h"
#include "refs.h"
#include "csum-file.h"
#include "quote.h"
@@ -21,12 +21,11 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "mem-pool.h"
#include "commit-reach.h"
#include "khash.h"
#include "date.h"
-#include "wrapper.h"
#define PACK_ID_BITS 16
#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 3ba0fe5a39..44c05ee86c 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "alloc.h"
#include "gettext.h"
#include "hex.h"
#include "object-file.h"
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 849a9be421..eed4a7cdb6 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1,7 +1,7 @@
/*
* "git fetch"
*/
-#include "cache.h"
+#include "builtin.h"
#include "advice.h"
#include "config.h"
#include "gettext.h"
@@ -11,11 +11,10 @@
#include "refs.h"
#include "refspec.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "oidset.h"
#include "oid-array.h"
#include "commit.h"
-#include "builtin.h"
#include "string-list.h"
#include "remote.h"
#include "transport.h"
@@ -29,6 +28,7 @@
#include "utf8.h"
#include "packfile.h"
#include "pager.h"
+#include "path.h"
#include "pkt-line.h"
#include "list-objects-filter-options.h"
#include "commit-reach.h"
@@ -58,7 +58,6 @@ enum {
};
enum display_format {
- DISPLAY_FORMAT_UNKNOWN = 0,
DISPLAY_FORMAT_FULL,
DISPLAY_FORMAT_COMPACT,
DISPLAY_FORMAT_PORCELAIN,
@@ -74,14 +73,11 @@ struct display_state {
int url_len, shown_url;
};
-static int fetch_prune_config = -1; /* unspecified */
-static int fetch_show_forced_updates = 1;
static uint64_t forced_updates_ms = 0;
static int prefetch = 0;
static int prune = -1; /* unspecified */
#define PRUNE_BY_DEFAULT 0 /* do we prune by default? */
-static int fetch_prune_tags_config = -1; /* unspecified */
static int prune_tags = -1; /* unspecified */
#define PRUNE_TAGS_BY_DEFAULT 0 /* do we prune tags by default? */
@@ -90,8 +86,6 @@ static int write_fetch_head = 1;
static int verbosity, deepen_relative, set_upstream, refetch;
static int progress = -1;
static int tags = TAGS_DEFAULT, update_shallow, deepen;
-static int submodule_fetch_jobs_config = -1;
-static int fetch_parallel_config = 1;
static int atomic_fetch;
static enum transport_family family;
static const char *depth;
@@ -101,7 +95,6 @@ static struct string_list deepen_not = STRING_LIST_INIT_NODUP;
static struct strbuf default_rla = STRBUF_INIT;
static struct transport *gtransport;
static struct transport *gsecondary;
-static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
static struct refspec refmap = REFSPEC_INIT_FETCH;
static struct list_objects_filter_options filter_options = LIST_OBJECTS_FILTER_INIT;
static struct string_list server_options = STRING_LIST_INIT_DUP;
@@ -109,47 +102,54 @@ static struct string_list negotiation_tip = STRING_LIST_INIT_NODUP;
struct fetch_config {
enum display_format display_format;
+ int prune;
+ int prune_tags;
+ int show_forced_updates;
+ int recurse_submodules;
+ int parallel;
+ int submodule_fetch_jobs;
};
-static int git_fetch_config(const char *k, const char *v, void *cb)
+static int git_fetch_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
struct fetch_config *fetch_config = cb;
if (!strcmp(k, "fetch.prune")) {
- fetch_prune_config = git_config_bool(k, v);
+ fetch_config->prune = git_config_bool(k, v);
return 0;
}
if (!strcmp(k, "fetch.prunetags")) {
- fetch_prune_tags_config = git_config_bool(k, v);
+ fetch_config->prune_tags = git_config_bool(k, v);
return 0;
}
if (!strcmp(k, "fetch.showforcedupdates")) {
- fetch_show_forced_updates = git_config_bool(k, v);
+ fetch_config->show_forced_updates = git_config_bool(k, v);
return 0;
}
if (!strcmp(k, "submodule.recurse")) {
int r = git_config_bool(k, v) ?
RECURSE_SUBMODULES_ON : RECURSE_SUBMODULES_OFF;
- recurse_submodules = r;
+ fetch_config->recurse_submodules = r;
}
if (!strcmp(k, "submodule.fetchjobs")) {
- submodule_fetch_jobs_config = parse_submodule_fetchjobs(k, v);
+ fetch_config->submodule_fetch_jobs = parse_submodule_fetchjobs(k, v, ctx->kvi);
return 0;
} else if (!strcmp(k, "fetch.recursesubmodules")) {
- recurse_submodules = parse_fetch_recurse_submodules_arg(k, v);
+ fetch_config->recurse_submodules = parse_fetch_recurse_submodules_arg(k, v);
return 0;
}
if (!strcmp(k, "fetch.parallel")) {
- fetch_parallel_config = git_config_int(k, v);
- if (fetch_parallel_config < 0)
+ fetch_config->parallel = git_config_int(k, v, ctx->kvi);
+ if (fetch_config->parallel < 0)
die(_("fetch.parallel cannot be negative"));
- if (!fetch_parallel_config)
- fetch_parallel_config = online_cpus();
+ if (!fetch_config->parallel)
+ fetch_config->parallel = online_cpus();
return 0;
}
@@ -165,7 +165,7 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
"fetch.output", v);
}
- return git_default_config(k, v, cb);
+ return git_default_config(k, v, ctx, cb);
}
static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
@@ -892,7 +892,8 @@ static int update_local_ref(struct ref *ref,
struct ref_transaction *transaction,
struct display_state *display_state,
const struct ref *remote_ref,
- int summary_width)
+ int summary_width,
+ const struct fetch_config *config)
{
struct commit *current = NULL, *updated;
int fast_forward = 0;
@@ -954,11 +955,10 @@ static int update_local_ref(struct ref *ref,
* Base this on the remote's ref name, as it's
* more likely to follow a standard layout.
*/
- const char *name = remote_ref ? remote_ref->name : "";
- if (starts_with(name, "refs/tags/")) {
+ if (starts_with(remote_ref->name, "refs/tags/")) {
msg = "storing tag";
what = _("[new tag]");
- } else if (starts_with(name, "refs/heads/")) {
+ } else if (starts_with(remote_ref->name, "refs/heads/")) {
msg = "storing head";
what = _("[new branch]");
} else {
@@ -974,7 +974,7 @@ static int update_local_ref(struct ref *ref,
return r;
}
- if (fetch_show_forced_updates) {
+ if (config->show_forced_updates) {
uint64_t t_before = getnanotime();
fast_forward = repo_in_merge_bases(the_repository, current,
updated);
@@ -1127,7 +1127,8 @@ static int store_updated_refs(struct display_state *display_state,
const char *remote_name,
int connectivity_checked,
struct ref_transaction *transaction, struct ref *ref_map,
- struct fetch_head *fetch_head)
+ struct fetch_head *fetch_head,
+ const struct fetch_config *config)
{
int rc = 0;
struct strbuf note = STRBUF_INIT;
@@ -1210,7 +1211,7 @@ static int store_updated_refs(struct display_state *display_state,
ref->force = rm->peer_ref->force;
}
- if (recurse_submodules != RECURSE_SUBMODULES_OFF &&
+ if (config->recurse_submodules != RECURSE_SUBMODULES_OFF &&
(!rm->peer_ref || !oideq(&ref->old_oid, &ref->new_oid))) {
check_for_new_submodule_commits(&rm->old_oid);
}
@@ -1243,7 +1244,7 @@ static int store_updated_refs(struct display_state *display_state,
if (ref) {
rc |= update_local_ref(ref, transaction, display_state,
- rm, summary_width);
+ rm, summary_width, config);
free(ref);
} else if (write_fetch_head || dry_run) {
/*
@@ -1267,7 +1268,7 @@ static int store_updated_refs(struct display_state *display_state,
"branches"), remote_name);
if (advice_enabled(ADVICE_FETCH_SHOW_FORCED_UPDATES)) {
- if (!fetch_show_forced_updates) {
+ if (!config->show_forced_updates) {
warning(_(warn_show_forced_updates));
} else if (forced_updates_ms > FORCED_UPDATES_DELAY_WARNING_IN_MS) {
warning(_(warn_time_show_forced_updates),
@@ -1328,7 +1329,8 @@ static int fetch_and_consume_refs(struct display_state *display_state,
struct transport *transport,
struct ref_transaction *transaction,
struct ref *ref_map,
- struct fetch_head *fetch_head)
+ struct fetch_head *fetch_head,
+ const struct fetch_config *config)
{
int connectivity_checked = 1;
int ret;
@@ -1351,7 +1353,7 @@ static int fetch_and_consume_refs(struct display_state *display_state,
trace2_region_enter("fetch", "consume_refs", the_repository);
ret = store_updated_refs(display_state, transport->remote->name,
connectivity_checked, transaction, ref_map,
- fetch_head);
+ fetch_head, config);
trace2_region_leave("fetch", "consume_refs", the_repository);
out:
@@ -1522,7 +1524,8 @@ static int backfill_tags(struct display_state *display_state,
struct transport *transport,
struct ref_transaction *transaction,
struct ref *ref_map,
- struct fetch_head *fetch_head)
+ struct fetch_head *fetch_head,
+ const struct fetch_config *config)
{
int retcode, cannot_reuse;
@@ -1543,7 +1546,8 @@ static int backfill_tags(struct display_state *display_state,
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
transport_set_option(transport, TRANS_OPT_DEPTH, "0");
transport_set_option(transport, TRANS_OPT_DEEPEN_RELATIVE, NULL);
- retcode = fetch_and_consume_refs(display_state, transport, transaction, ref_map, fetch_head);
+ retcode = fetch_and_consume_refs(display_state, transport, transaction, ref_map,
+ fetch_head, config);
if (gsecondary) {
transport_disconnect(gsecondary);
@@ -1555,7 +1559,7 @@ static int backfill_tags(struct display_state *display_state,
static int do_fetch(struct transport *transport,
struct refspec *rs,
- enum display_format display_format)
+ const struct fetch_config *config)
{
struct ref_transaction *transaction = NULL;
struct ref *ref_map = NULL;
@@ -1641,7 +1645,8 @@ static int do_fetch(struct transport *transport,
if (retcode)
goto cleanup;
- display_state_init(&display_state, ref_map, transport->url, display_format);
+ display_state_init(&display_state, ref_map, transport->url,
+ config->display_format);
if (atomic_fetch) {
transaction = ref_transaction_begin(&err);
@@ -1669,7 +1674,8 @@ static int do_fetch(struct transport *transport,
retcode = 1;
}
- if (fetch_and_consume_refs(&display_state, transport, transaction, ref_map, &fetch_head)) {
+ if (fetch_and_consume_refs(&display_state, transport, transaction, ref_map,
+ &fetch_head, config)) {
retcode = 1;
goto cleanup;
}
@@ -1692,7 +1698,7 @@ static int do_fetch(struct transport *transport,
* the transaction and don't commit anything.
*/
if (backfill_tags(&display_state, transport, transaction, tags_ref_map,
- &fetch_head))
+ &fetch_head, config))
retcode = 1;
}
@@ -1794,7 +1800,9 @@ struct remote_group_data {
struct string_list *list;
};
-static int get_remote_group(const char *key, const char *value, void *priv)
+static int get_remote_group(const char *key, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *priv)
{
struct remote_group_data *g = priv;
@@ -1830,7 +1838,7 @@ static int add_remote_or_group(const char *name, struct string_list *list)
}
static void add_options_to_argv(struct strvec *argv,
- enum display_format format)
+ const struct fetch_config *config)
{
if (dry_run)
strvec_push(argv, "--dry-run");
@@ -1844,11 +1852,11 @@ static void add_options_to_argv(struct strvec *argv,
strvec_push(argv, "--force");
if (keep)
strvec_push(argv, "--keep");
- if (recurse_submodules == RECURSE_SUBMODULES_ON)
+ if (config->recurse_submodules == RECURSE_SUBMODULES_ON)
strvec_push(argv, "--recurse-submodules");
- else if (recurse_submodules == RECURSE_SUBMODULES_OFF)
+ else if (config->recurse_submodules == RECURSE_SUBMODULES_OFF)
strvec_push(argv, "--no-recurse-submodules");
- else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
+ else if (config->recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
strvec_push(argv, "--recurse-submodules=on-demand");
if (tags == TAGS_SET)
strvec_push(argv, "--tags");
@@ -1866,7 +1874,7 @@ static void add_options_to_argv(struct strvec *argv,
strvec_push(argv, "--ipv6");
if (!write_fetch_head)
strvec_push(argv, "--no-write-fetch-head");
- if (format == DISPLAY_FORMAT_PORCELAIN)
+ if (config->display_format == DISPLAY_FORMAT_PORCELAIN)
strvec_pushf(argv, "--porcelain");
}
@@ -1876,7 +1884,7 @@ struct parallel_fetch_state {
const char **argv;
struct string_list *remotes;
int next, result;
- enum display_format format;
+ const struct fetch_config *config;
};
static int fetch_next_remote(struct child_process *cp,
@@ -1896,7 +1904,7 @@ static int fetch_next_remote(struct child_process *cp,
strvec_push(&cp->args, remote);
cp->git_cmd = 1;
- if (verbosity >= 0 && state->format != DISPLAY_FORMAT_PORCELAIN)
+ if (verbosity >= 0 && state->config->display_format != DISPLAY_FORMAT_PORCELAIN)
printf(_("Fetching %s\n"), remote);
return 1;
@@ -1929,7 +1937,7 @@ static int fetch_finished(int result, struct strbuf *out,
}
static int fetch_multiple(struct string_list *list, int max_children,
- enum display_format format)
+ const struct fetch_config *config)
{
int i, result = 0;
struct strvec argv = STRVEC_INIT;
@@ -1947,10 +1955,10 @@ static int fetch_multiple(struct string_list *list, int max_children,
strvec_pushl(&argv, "-c", "fetch.bundleURI=",
"fetch", "--append", "--no-auto-gc",
"--no-write-commit-graph", NULL);
- add_options_to_argv(&argv, format);
+ add_options_to_argv(&argv, config);
if (max_children != 1 && list->nr != 1) {
- struct parallel_fetch_state state = { argv.v, list, 0, 0, format };
+ struct parallel_fetch_state state = { argv.v, list, 0, 0, config };
const struct run_process_parallel_opts opts = {
.tr2_category = "fetch",
.tr2_label = "parallel/fetch",
@@ -1974,7 +1982,7 @@ static int fetch_multiple(struct string_list *list, int max_children,
strvec_pushv(&cmd.args, argv.v);
strvec_push(&cmd.args, name);
- if (verbosity >= 0 && format != DISPLAY_FORMAT_PORCELAIN)
+ if (verbosity >= 0 && config->display_format != DISPLAY_FORMAT_PORCELAIN)
printf(_("Fetching %s\n"), name);
cmd.git_cmd = 1;
if (run_command(&cmd)) {
@@ -2030,7 +2038,7 @@ static inline void fetch_one_setup_partial(struct remote *remote)
static int fetch_one(struct remote *remote, int argc, const char **argv,
int prune_tags_ok, int use_stdin_refspecs,
- enum display_format display_format)
+ const struct fetch_config *config)
{
struct refspec rs = REFSPEC_INIT_FETCH;
int i;
@@ -2048,8 +2056,8 @@ static int fetch_one(struct remote *remote, int argc, const char **argv,
/* no command line request */
if (0 <= remote->prune)
prune = remote->prune;
- else if (0 <= fetch_prune_config)
- prune = fetch_prune_config;
+ else if (0 <= config->prune)
+ prune = config->prune;
else
prune = PRUNE_BY_DEFAULT;
}
@@ -2058,8 +2066,8 @@ static int fetch_one(struct remote *remote, int argc, const char **argv,
/* no command line request */
if (0 <= remote->prune_tags)
prune_tags = remote->prune_tags;
- else if (0 <= fetch_prune_tags_config)
- prune_tags = fetch_prune_tags_config;
+ else if (0 <= config->prune_tags)
+ prune_tags = config->prune_tags;
else
prune_tags = PRUNE_TAGS_BY_DEFAULT;
}
@@ -2097,7 +2105,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv,
sigchain_push_common(unlock_pack_on_signal);
atexit(unlock_pack_atexit);
sigchain_push(SIGPIPE, SIG_IGN);
- exit_code = do_fetch(gtransport, &rs, display_format);
+ exit_code = do_fetch(gtransport, &rs, config);
sigchain_pop(SIGPIPE);
refspec_clear(&rs);
transport_disconnect(gtransport);
@@ -2109,6 +2117,12 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
{
struct fetch_config config = {
.display_format = DISPLAY_FORMAT_FULL,
+ .prune = -1,
+ .prune_tags = -1,
+ .show_forced_updates = 1,
+ .recurse_submodules = RECURSE_SUBMODULES_DEFAULT,
+ .parallel = 1,
+ .submodule_fetch_jobs = -1,
};
const char *submodule_prefix = "";
const char *bundle_uri;
@@ -2193,10 +2207,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
OPT_CALLBACK_F(0, "refmap", NULL, N_("refmap"),
N_("specify fetch refmap"), PARSE_OPT_NONEG, parse_refmap_arg),
OPT_STRING_LIST('o', "server-option", &server_options, N_("server-specific"), N_("option to transmit")),
- OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
- TRANSPORT_FAMILY_IPV4),
- OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
- TRANSPORT_FAMILY_IPV6),
+ OPT_IPVERSION(&family),
OPT_STRING_LIST(0, "negotiation-tip", &negotiation_tip, N_("revision"),
N_("report that we have only objects reachable from this object")),
OPT_BOOL(0, "negotiate-only", &negotiate_only,
@@ -2206,7 +2217,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
N_("run 'maintenance --auto' after fetching")),
OPT_BOOL(0, "auto-gc", &enable_auto_gc,
N_("run 'maintenance --auto' after fetching")),
- OPT_BOOL(0, "show-forced-updates", &fetch_show_forced_updates,
+ OPT_BOOL(0, "show-forced-updates", &config.show_forced_updates,
N_("check for forced-updates on all updated branches")),
OPT_BOOL(0, "write-commit-graph", &fetch_write_commit_graph,
N_("write the commit-graph after fetching")),
@@ -2237,7 +2248,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
builtin_fetch_options, builtin_fetch_usage, 0);
if (recurse_submodules_cli != RECURSE_SUBMODULES_DEFAULT)
- recurse_submodules = recurse_submodules_cli;
+ config.recurse_submodules = recurse_submodules_cli;
if (negotiate_only) {
switch (recurse_submodules_cli) {
@@ -2248,7 +2259,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
* submodules. Skip it by setting recurse_submodules to
* RECURSE_SUBMODULES_OFF.
*/
- recurse_submodules = RECURSE_SUBMODULES_OFF;
+ config.recurse_submodules = RECURSE_SUBMODULES_OFF;
break;
default:
@@ -2257,11 +2268,11 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
}
}
- if (recurse_submodules != RECURSE_SUBMODULES_OFF) {
- int *sfjc = submodule_fetch_jobs_config == -1
- ? &submodule_fetch_jobs_config : NULL;
- int *rs = recurse_submodules == RECURSE_SUBMODULES_DEFAULT
- ? &recurse_submodules : NULL;
+ if (config.recurse_submodules != RECURSE_SUBMODULES_OFF) {
+ int *sfjc = config.submodule_fetch_jobs == -1
+ ? &config.submodule_fetch_jobs : NULL;
+ int *rs = config.recurse_submodules == RECURSE_SUBMODULES_DEFAULT
+ ? &config.recurse_submodules : NULL;
fetch_config_from_gitmodules(sfjc, rs);
}
@@ -2275,7 +2286,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
* Reference updates in submodules would be ambiguous
* in porcelain mode, so we reject this combination.
*/
- recurse_submodules = RECURSE_SUBMODULES_OFF;
+ config.recurse_submodules = RECURSE_SUBMODULES_OFF;
break;
default:
@@ -2385,7 +2396,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
if (filter_options.choice || repo_has_promisor_remote(the_repository))
fetch_one_setup_partial(remote);
result = fetch_one(remote, argc, argv, prune_tags_ok, stdin_refspecs,
- config.display_format);
+ &config);
} else {
int max_children = max_jobs;
@@ -2402,10 +2413,10 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
"from one remote"));
if (max_children < 0)
- max_children = fetch_parallel_config;
+ max_children = config.parallel;
/* TODO should this also die if we have a previous partial-clone? */
- result = fetch_multiple(&list, max_children, config.display_format);
+ result = fetch_multiple(&list, max_children, &config);
}
/*
@@ -2417,20 +2428,20 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
* the fetched history from each remote, so there is no need
* to fetch submodules from here.
*/
- if (!result && remote && (recurse_submodules != RECURSE_SUBMODULES_OFF)) {
+ if (!result && remote && (config.recurse_submodules != RECURSE_SUBMODULES_OFF)) {
struct strvec options = STRVEC_INIT;
int max_children = max_jobs;
if (max_children < 0)
- max_children = submodule_fetch_jobs_config;
+ max_children = config.submodule_fetch_jobs;
if (max_children < 0)
- max_children = fetch_parallel_config;
+ max_children = config.parallel;
- add_options_to_argv(&options, config.display_format);
+ add_options_to_argv(&options, &config);
result = fetch_submodules(the_repository,
&options,
submodule_prefix,
- recurse_submodules,
+ config.recurse_submodules,
recurse_submodules_default,
verbosity < 0,
max_children);
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index cc81241642..0f9855b680 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -3,7 +3,6 @@
#include "fmt-merge-msg.h"
#include "gettext.h"
#include "parse-options.h"
-#include "wrapper.h"
static const char * const fmt_merge_msg_usage[] = {
N_("git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]"),
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 695fc8f4a5..350bfa6e81 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -1,11 +1,11 @@
#include "builtin.h"
-#include "cache.h"
#include "config.h"
#include "gettext.h"
#include "refs.h"
#include "object.h"
#include "parse-options.h"
#include "ref-filter.h"
+#include "strbuf.h"
#include "strvec.h"
#include "commit-reach.h"
@@ -24,7 +24,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
struct string_list sorting_options = STRING_LIST_INIT_DUP;
int maxcount = 0, icase = 0, omit_empty = 0;
struct ref_array array;
- struct ref_filter filter;
+ struct ref_filter filter = REF_FILTER_INIT;
struct ref_format format = REF_FORMAT_INIT;
struct strbuf output = STRBUF_INIT;
struct strbuf err = STRBUF_INIT;
@@ -47,6 +47,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
OPT_INTEGER( 0 , "count", &maxcount, N_("show only <n> matched refs")),
OPT_STRING( 0 , "format", &format.format, N_("format"), N_("format to use for the output")),
OPT__COLOR(&format.use_color, N_("respect format colors")),
+ OPT_REF_FILTER_EXCLUDE(&filter),
OPT_REF_SORT(&sorting_options),
OPT_CALLBACK(0, "points-at", &filter.points_at,
N_("object"), N_("print only refs which points at the given object"),
@@ -61,7 +62,6 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
};
memset(&array, 0, sizeof(array));
- memset(&filter, 0, sizeof(filter));
format.format = "%(objectname) %(objecttype)\t%(refname)";
@@ -121,8 +121,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
strbuf_release(&err);
strbuf_release(&output);
ref_array_clear(&array);
- free_commit_list(filter.with_commit);
- free_commit_list(filter.no_commit);
+ ref_filter_clear(&filter);
ref_sorting_release(sorting);
strvec_clear(&vec);
return 0;
diff --git a/builtin/for-each-repo.c b/builtin/for-each-repo.c
index 37daf7bec1..28186b30f5 100644
--- a/builtin/for-each-repo.c
+++ b/builtin/for-each-repo.c
@@ -1,6 +1,5 @@
-#include "cache.h"
-#include "config.h"
#include "builtin.h"
+#include "config.h"
#include "gettext.h"
#include "parse-options.h"
#include "path.h"
diff --git a/builtin/fsck.c b/builtin/fsck.c
index dcc165bf0c..c1d0290026 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "cache.h"
#include "gettext.h"
#include "hex.h"
#include "repository.h"
@@ -21,10 +20,13 @@
#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "path.h"
+#include "read-cache-ll.h"
#include "replace-object.h"
#include "resolve-undo.h"
#include "run-command.h"
+#include "sparse-index.h"
#include "worktree.h"
#include "pack-revindex.h"
#include "pack-bitmap.h"
@@ -90,11 +92,11 @@ static int objerror(struct object *obj, const char *err)
return -1;
}
-static int fsck_error_func(struct fsck_options *o,
+static int fsck_error_func(struct fsck_options *o UNUSED,
const struct object_id *oid,
enum object_type object_type,
enum fsck_msg_type msg_type,
- enum fsck_msg_id msg_id,
+ enum fsck_msg_id msg_id UNUSED,
const char *message)
{
switch (msg_type) {
@@ -119,7 +121,7 @@ static int fsck_error_func(struct fsck_options *o,
static struct object_array pending;
static int mark_object(struct object *obj, enum object_type type,
- void *data, struct fsck_options *options)
+ void *data, struct fsck_options *options UNUSED)
{
struct object *parent = data;
@@ -204,8 +206,8 @@ static int traverse_reachable(void)
return !!result;
}
-static int mark_used(struct object *obj, enum object_type object_type,
- void *data, struct fsck_options *options)
+static int mark_used(struct object *obj, int type UNUSED,
+ void *data UNUSED, struct fsck_options *options UNUSED)
{
if (!obj)
return 1;
@@ -808,7 +810,7 @@ static int fsck_resolve_undo(struct index_state *istate,
}
static void fsck_index(struct index_state *istate, const char *index_path,
- int is_main_index)
+ int is_current_worktree)
{
unsigned int i;
@@ -830,7 +832,7 @@ static void fsck_index(struct index_state *istate, const char *index_path,
obj->flags |= USED;
fsck_put_object_name(&fsck_walk_options, &obj->oid,
"%s:%s",
- is_main_index ? "" : index_path,
+ is_current_worktree ? "" : index_path,
istate->cache[i]->name);
mark_object_reachable(obj);
}
@@ -929,7 +931,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
fetch_if_missing = 0;
errors_found = 0;
- read_replace_refs = 0;
+ disable_replace_refs();
save_commit_buffer = 0;
argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
@@ -1072,6 +1074,10 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
commit_graph_verify.git_cmd = 1;
strvec_pushl(&commit_graph_verify.args, "commit-graph",
"verify", "--object-dir", odb->path, NULL);
+ if (show_progress)
+ strvec_push(&commit_graph_verify.args, "--progress");
+ else
+ strvec_push(&commit_graph_verify.args, "--no-progress");
if (run_command(&commit_graph_verify))
errors_found |= ERROR_COMMIT_GRAPH;
}
@@ -1086,6 +1092,10 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
midx_verify.git_cmd = 1;
strvec_pushl(&midx_verify.args, "multi-pack-index",
"verify", "--object-dir", odb->path, NULL);
+ if (show_progress)
+ strvec_push(&midx_verify.args, "--progress");
+ else
+ strvec_push(&midx_verify.args, "--no-progress");
if (run_command(&midx_verify))
errors_found |= ERROR_MULTI_PACK_INDEX;
}
diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c
index f6dd9a784c..7e99c4d61b 100644
--- a/builtin/fsmonitor--daemon.c
+++ b/builtin/fsmonitor--daemon.c
@@ -1,19 +1,20 @@
#include "builtin.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
#include "parse-options.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
#include "fsmonitor-ipc.h"
#include "fsmonitor-path-utils.h"
+#include "fsmonitor-settings.h"
#include "compat/fsmonitor/fsm-health.h"
#include "compat/fsmonitor/fsm-listen.h"
#include "fsmonitor--daemon.h"
#include "simple-ipc.h"
#include "khash.h"
#include "pkt-line.h"
+#include "trace.h"
#include "trace2.h"
static const char * const builtin_fsmonitor__daemon_usage[] = {
@@ -37,10 +38,11 @@ static int fsmonitor__start_timeout_sec = 60;
#define FSMONITOR__ANNOUNCE_STARTUP "fsmonitor.announcestartup"
static int fsmonitor__announce_startup = 0;
-static int fsmonitor_config(const char *var, const char *value, void *cb)
+static int fsmonitor_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, FSMONITOR__IPC_THREADS)) {
- int i = git_config_int(var, value);
+ int i = git_config_int(var, value, ctx->kvi);
if (i < 1)
return error(_("value of '%s' out of range: %d"),
FSMONITOR__IPC_THREADS, i);
@@ -49,7 +51,7 @@ static int fsmonitor_config(const char *var, const char *value, void *cb)
}
if (!strcmp(var, FSMONITOR__START_TIMEOUT)) {
- int i = git_config_int(var, value);
+ int i = git_config_int(var, value, ctx->kvi);
if (i < 0)
return error(_("value of '%s' out of range: %d"),
FSMONITOR__START_TIMEOUT, i);
@@ -59,7 +61,7 @@ static int fsmonitor_config(const char *var, const char *value, void *cb)
if (!strcmp(var, FSMONITOR__ANNOUNCE_STARTUP)) {
int is_bool;
- int i = git_config_bool_or_int(var, value, &is_bool);
+ int i = git_config_bool_or_int(var, value, ctx->kvi, &is_bool);
if (i < 0)
return error(_("value of '%s' not bool or int: %d"),
var, i);
@@ -67,7 +69,7 @@ static int fsmonitor_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
/*
diff --git a/builtin/gc.c b/builtin/gc.c
index f3942188a6..19d73067aa 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -27,9 +27,10 @@
#include "commit-graph.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "pack.h"
#include "pack-objects.h"
+#include "path.h"
#include "blob.h"
#include "tree.h"
#include "promisor-remote.h"
@@ -40,7 +41,6 @@
#include "hook.h"
#include "setup.h"
#include "trace2.h"
-#include "wrapper.h"
#define FAILED_RUN "failed to run %s"
diff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c
index 564cfcac4f..20d0dfe9cf 100644
--- a/builtin/get-tar-commit-id.c
+++ b/builtin/get-tar-commit-id.c
@@ -1,12 +1,10 @@
/*
* Copyright (c) 2005, 2006 Rene Scharfe
*/
-#include "cache.h"
+#include "builtin.h"
#include "commit.h"
#include "tar.h"
-#include "builtin.h"
#include "quote.h"
-#include "wrapper.h"
static const char builtin_get_tar_commit_id_usage[] =
"git get-tar-commit-id";
diff --git a/builtin/grep.c b/builtin/grep.c
index b86c754def..50e712a184 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -3,8 +3,7 @@
*
* Copyright (c) 2006 Junio C Hamano
*/
-#include "cache.h"
-#include "alloc.h"
+#include "builtin.h"
#include "gettext.h"
#include "hex.h"
#include "repository.h"
@@ -14,7 +13,6 @@
#include "commit.h"
#include "tag.h"
#include "tree-walk.h"
-#include "builtin.h"
#include "parse-options.h"
#include "string-list.h"
#include "run-command.h"
@@ -28,9 +26,11 @@
#include "submodule-config.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "packfile.h"
#include "pager.h"
+#include "path.h"
+#include "read-cache-ll.h"
#include "write-or-die.h"
static const char *grep_prefix;
@@ -290,14 +290,18 @@ static int wait_all(void)
return hit;
}
-static int grep_cmd_config(const char *var, const char *value, void *cb)
+static int grep_cmd_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
- int st = grep_config(var, value, cb);
- if (git_color_default_config(var, value, NULL) < 0)
+ int st = grep_config(var, value, ctx, cb);
+
+ if (git_color_config(var, value, cb) < 0)
+ st = -1;
+ else if (git_default_config(var, value, ctx, cb) < 0)
st = -1;
if (!strcmp(var, "grep.threads")) {
- num_threads = git_config_int(var, value);
+ num_threads = git_config_int(var, value, ctx->kvi);
if (num_threads < 0)
die(_("invalid number of threads specified (%d) for %s"),
num_threads, var);
@@ -639,7 +643,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
strbuf_addstr(&name, base->buf + tn_len);
match = tree_entry_interesting(repo->index,
&entry, &name,
- 0, pathspec);
+ pathspec);
strbuf_setlen(&name, name_base_len);
if (match == all_entries_not_interesting)
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index a380121166..5ffec99dce 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -10,12 +10,13 @@
#include "gettext.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "blob.h"
#include "quote.h"
#include "parse-options.h"
#include "exec-cmd.h"
#include "setup.h"
+#include "strbuf.h"
#include "write-or-die.h"
/*
diff --git a/builtin/help.c b/builtin/help.c
index d3cf4af3f6..dc1fbe2b98 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -1,9 +1,8 @@
/*
* Builtin help command
*/
-#include "cache.h"
-#include "config.h"
#include "builtin.h"
+#include "config.h"
#include "exec-cmd.h"
#include "gettext.h"
#include "pager.h"
@@ -398,7 +397,8 @@ static int add_man_viewer_info(const char *var, const char *value)
return 0;
}
-static int git_help_config(const char *var, const char *value, void *cb)
+static int git_help_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "help.format")) {
if (!value)
@@ -421,7 +421,7 @@ static int git_help_config(const char *var, const char *value, void *cb)
if (starts_with(var, "man."))
return add_man_viewer_info(var, value);
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static struct cmdnames main_cmds, other_cmds;
diff --git a/builtin/hook.c b/builtin/hook.c
index 88051795c7..09b51a6487 100644
--- a/builtin/hook.c
+++ b/builtin/hook.c
@@ -1,4 +1,3 @@
-#include "cache.h"
#include "builtin.h"
#include "config.h"
#include "gettext.h"
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index bb67e16655..006ffdc9c5 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "alloc.h"
#include "config.h"
#include "delta.h"
#include "environment.h"
@@ -14,17 +13,17 @@
#include "progress.h"
#include "fsck.h"
#include "exec-cmd.h"
+#include "strbuf.h"
#include "streaming.h"
#include "thread-utils.h"
#include "packfile.h"
#include "pack-revindex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "oid-array.h"
#include "replace-object.h"
#include "promisor-remote.h"
#include "setup.h"
-#include "wrapper.h"
static const char index_pack_usage[] =
"git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--[no-]rev-index] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])";
@@ -222,7 +221,8 @@ static void cleanup_thread(void)
}
static int mark_link(struct object *obj, enum object_type type,
- void *data, struct fsck_options *options)
+ void *data UNUSED,
+ struct fsck_options *options UNUSED)
{
if (!obj)
return -1;
@@ -1581,18 +1581,19 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
strbuf_release(&pack_name);
}
-static int git_index_pack_config(const char *k, const char *v, void *cb)
+static int git_index_pack_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
struct pack_idx_option *opts = cb;
if (!strcmp(k, "pack.indexversion")) {
- opts->version = git_config_int(k, v);
+ opts->version = git_config_int(k, v, ctx->kvi);
if (opts->version > 2)
die(_("bad pack.indexVersion=%"PRIu32), opts->version);
return 0;
}
if (!strcmp(k, "pack.threads")) {
- nr_threads = git_config_int(k, v);
+ nr_threads = git_config_int(k, v, ctx->kvi);
if (nr_threads < 0)
die(_("invalid number of threads specified (%d)"),
nr_threads);
@@ -1608,7 +1609,7 @@ static int git_index_pack_config(const char *k, const char *v, void *cb)
else
opts->flags &= ~WRITE_REV;
}
- return git_default_config(k, v, cb);
+ return git_default_config(k, v, ctx, cb);
}
static int cmp_uint32(const void *a_, const void *b_)
@@ -1752,7 +1753,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
if (argc == 2 && !strcmp(argv[1], "-h"))
usage(index_pack_usage);
- read_replace_refs = 0;
+ disable_replace_refs();
fsck_options.walk = mark_link;
reset_pack_idx_option(&opts);
diff --git a/builtin/init-db.c b/builtin/init-db.c
index aef4036105..cb727c826f 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -3,484 +3,16 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
-#include "cache.h"
+#include "builtin.h"
#include "abspath.h"
#include "config.h"
-#include "copy.h"
#include "environment.h"
#include "gettext.h"
-#include "refs.h"
-#include "builtin.h"
-#include "exec-cmd.h"
#include "object-file.h"
#include "parse-options.h"
#include "path.h"
#include "setup.h"
-#include "worktree.h"
-#include "wrapper.h"
-
-#ifndef DEFAULT_GIT_TEMPLATE_DIR
-#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
-#endif
-
-#ifdef NO_TRUSTABLE_FILEMODE
-#define TEST_FILEMODE 0
-#else
-#define TEST_FILEMODE 1
-#endif
-
-#define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
-
-static int init_is_bare_repository = 0;
-static int init_shared_repository = -1;
-
-static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
- DIR *dir)
-{
- size_t path_baselen = path->len;
- size_t template_baselen = template_path->len;
- struct dirent *de;
-
- /* Note: if ".git/hooks" file exists in the repository being
- * re-initialized, /etc/core-git/templates/hooks/update would
- * cause "git init" to fail here. I think this is sane but
- * it means that the set of templates we ship by default, along
- * with the way the namespace under .git/ is organized, should
- * be really carefully chosen.
- */
- safe_create_dir(path->buf, 1);
- while ((de = readdir(dir)) != NULL) {
- struct stat st_git, st_template;
- int exists = 0;
-
- strbuf_setlen(path, path_baselen);
- strbuf_setlen(template_path, template_baselen);
-
- if (de->d_name[0] == '.')
- continue;
- strbuf_addstr(path, de->d_name);
- strbuf_addstr(template_path, de->d_name);
- if (lstat(path->buf, &st_git)) {
- if (errno != ENOENT)
- die_errno(_("cannot stat '%s'"), path->buf);
- }
- else
- exists = 1;
-
- if (lstat(template_path->buf, &st_template))
- die_errno(_("cannot stat template '%s'"), template_path->buf);
-
- if (S_ISDIR(st_template.st_mode)) {
- DIR *subdir = opendir(template_path->buf);
- if (!subdir)
- die_errno(_("cannot opendir '%s'"), template_path->buf);
- strbuf_addch(path, '/');
- strbuf_addch(template_path, '/');
- copy_templates_1(path, template_path, subdir);
- closedir(subdir);
- }
- else if (exists)
- continue;
- else if (S_ISLNK(st_template.st_mode)) {
- struct strbuf lnk = STRBUF_INIT;
- if (strbuf_readlink(&lnk, template_path->buf,
- st_template.st_size) < 0)
- die_errno(_("cannot readlink '%s'"), template_path->buf);
- if (symlink(lnk.buf, path->buf))
- die_errno(_("cannot symlink '%s' '%s'"),
- lnk.buf, path->buf);
- strbuf_release(&lnk);
- }
- else if (S_ISREG(st_template.st_mode)) {
- if (copy_file(path->buf, template_path->buf, st_template.st_mode))
- die_errno(_("cannot copy '%s' to '%s'"),
- template_path->buf, path->buf);
- }
- else
- error(_("ignoring template %s"), template_path->buf);
- }
-}
-
-static void copy_templates(const char *template_dir, const char *init_template_dir)
-{
- struct strbuf path = STRBUF_INIT;
- struct strbuf template_path = STRBUF_INIT;
- size_t template_len;
- struct repository_format template_format = REPOSITORY_FORMAT_INIT;
- struct strbuf err = STRBUF_INIT;
- DIR *dir;
- char *to_free = NULL;
-
- if (!template_dir)
- template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
- if (!template_dir)
- template_dir = init_template_dir;
- if (!template_dir)
- template_dir = to_free = system_path(DEFAULT_GIT_TEMPLATE_DIR);
- if (!template_dir[0]) {
- free(to_free);
- return;
- }
-
- strbuf_addstr(&template_path, template_dir);
- strbuf_complete(&template_path, '/');
- template_len = template_path.len;
-
- dir = opendir(template_path.buf);
- if (!dir) {
- warning(_("templates not found in %s"), template_dir);
- goto free_return;
- }
-
- /* Make sure that template is from the correct vintage */
- strbuf_addstr(&template_path, "config");
- read_repository_format(&template_format, template_path.buf);
- strbuf_setlen(&template_path, template_len);
-
- /*
- * No mention of version at all is OK, but anything else should be
- * verified.
- */
- if (template_format.version >= 0 &&
- verify_repository_format(&template_format, &err) < 0) {
- warning(_("not copying templates from '%s': %s"),
- template_dir, err.buf);
- strbuf_release(&err);
- goto close_free_return;
- }
-
- strbuf_addstr(&path, get_git_common_dir());
- strbuf_complete(&path, '/');
- copy_templates_1(&path, &template_path, dir);
-close_free_return:
- closedir(dir);
-free_return:
- free(to_free);
- strbuf_release(&path);
- strbuf_release(&template_path);
- clear_repository_format(&template_format);
-}
-
-/*
- * If the git_dir is not directly inside the working tree, then git will not
- * find it by default, and we need to set the worktree explicitly.
- */
-static int needs_work_tree_config(const char *git_dir, const char *work_tree)
-{
- if (!strcmp(work_tree, "/") && !strcmp(git_dir, "/.git"))
- return 0;
- if (skip_prefix(git_dir, work_tree, &git_dir) &&
- !strcmp(git_dir, "/.git"))
- return 0;
- return 1;
-}
-
-void initialize_repository_version(int hash_algo, int reinit)
-{
- char repo_version_string[10];
- int repo_version = GIT_REPO_VERSION;
-
- if (hash_algo != GIT_HASH_SHA1)
- repo_version = GIT_REPO_VERSION_READ;
-
- /* This forces creation of new config file */
- xsnprintf(repo_version_string, sizeof(repo_version_string),
- "%d", repo_version);
- git_config_set("core.repositoryformatversion", repo_version_string);
-
- if (hash_algo != GIT_HASH_SHA1)
- git_config_set("extensions.objectformat",
- hash_algos[hash_algo].name);
- else if (reinit)
- git_config_set_gently("extensions.objectformat", NULL);
-}
-
-static int create_default_files(const char *template_path,
- const char *original_git_dir,
- const char *initial_branch,
- const struct repository_format *fmt,
- int quiet)
-{
- struct stat st1;
- struct strbuf buf = STRBUF_INIT;
- char *path;
- char junk[2];
- int reinit;
- int filemode;
- struct strbuf err = STRBUF_INIT;
- const char *init_template_dir = NULL;
- const char *work_tree = get_git_work_tree();
-
- /*
- * First copy the templates -- we might have the default
- * config file there, in which case we would want to read
- * from it after installing.
- *
- * Before reading that config, we also need to clear out any cached
- * values (since we've just potentially changed what's available on
- * disk).
- */
- git_config_get_pathname("init.templatedir", &init_template_dir);
- copy_templates(template_path, init_template_dir);
- free((char *)init_template_dir);
- git_config_clear();
- reset_shared_repository();
- git_config(git_default_config, NULL);
-
- /*
- * We must make sure command-line options continue to override any
- * values we might have just re-read from the config.
- */
- is_bare_repository_cfg = init_is_bare_repository || !work_tree;
- if (init_shared_repository != -1)
- set_shared_repository(init_shared_repository);
-
- /*
- * We would have created the above under user's umask -- under
- * shared-repository settings, we would need to fix them up.
- */
- if (get_shared_repository()) {
- adjust_shared_perm(get_git_dir());
- }
-
- /*
- * We need to create a "refs" dir in any case so that older
- * versions of git can tell that this is a repository.
- */
- safe_create_dir(git_path("refs"), 1);
- adjust_shared_perm(git_path("refs"));
-
- if (refs_init_db(&err))
- die("failed to set up refs db: %s", err.buf);
-
- /*
- * Point the HEAD symref to the initial branch with if HEAD does
- * not yet exist.
- */
- path = git_path_buf(&buf, "HEAD");
- reinit = (!access(path, R_OK)
- || readlink(path, junk, sizeof(junk)-1) != -1);
- if (!reinit) {
- char *ref;
-
- if (!initial_branch)
- initial_branch = git_default_branch_name(quiet);
-
- ref = xstrfmt("refs/heads/%s", initial_branch);
- if (check_refname_format(ref, 0) < 0)
- die(_("invalid initial branch name: '%s'"),
- initial_branch);
-
- if (create_symref("HEAD", ref, NULL) < 0)
- exit(1);
- free(ref);
- }
-
- initialize_repository_version(fmt->hash_algo, 0);
-
- /* Check filemode trustability */
- path = git_path_buf(&buf, "config");
- filemode = TEST_FILEMODE;
- if (TEST_FILEMODE && !lstat(path, &st1)) {
- struct stat st2;
- filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
- !lstat(path, &st2) &&
- st1.st_mode != st2.st_mode &&
- !chmod(path, st1.st_mode));
- if (filemode && !reinit && (st1.st_mode & S_IXUSR))
- filemode = 0;
- }
- git_config_set("core.filemode", filemode ? "true" : "false");
-
- if (is_bare_repository())
- git_config_set("core.bare", "true");
- else {
- git_config_set("core.bare", "false");
- /* allow template config file to override the default */
- if (log_all_ref_updates == LOG_REFS_UNSET)
- git_config_set("core.logallrefupdates", "true");
- if (needs_work_tree_config(original_git_dir, work_tree))
- git_config_set("core.worktree", work_tree);
- }
-
- if (!reinit) {
- /* Check if symlink is supported in the work tree */
- path = git_path_buf(&buf, "tXXXXXX");
- if (!close(xmkstemp(path)) &&
- !unlink(path) &&
- !symlink("testing", path) &&
- !lstat(path, &st1) &&
- S_ISLNK(st1.st_mode))
- unlink(path); /* good */
- else
- git_config_set("core.symlinks", "false");
-
- /* Check if the filesystem is case-insensitive */
- path = git_path_buf(&buf, "CoNfIg");
- if (!access(path, F_OK))
- git_config_set("core.ignorecase", "true");
- probe_utf8_pathname_composition();
- }
-
- strbuf_release(&buf);
- return reinit;
-}
-
-static void create_object_directory(void)
-{
- struct strbuf path = STRBUF_INIT;
- size_t baselen;
-
- strbuf_addstr(&path, get_object_directory());
- baselen = path.len;
-
- safe_create_dir(path.buf, 1);
-
- strbuf_setlen(&path, baselen);
- strbuf_addstr(&path, "/pack");
- safe_create_dir(path.buf, 1);
-
- strbuf_setlen(&path, baselen);
- strbuf_addstr(&path, "/info");
- safe_create_dir(path.buf, 1);
-
- strbuf_release(&path);
-}
-
-static void separate_git_dir(const char *git_dir, const char *git_link)
-{
- struct stat st;
-
- if (!stat(git_link, &st)) {
- const char *src;
-
- if (S_ISREG(st.st_mode))
- src = read_gitfile(git_link);
- else if (S_ISDIR(st.st_mode))
- src = git_link;
- else
- die(_("unable to handle file type %d"), (int)st.st_mode);
-
- if (rename(src, git_dir))
- die_errno(_("unable to move %s to %s"), src, git_dir);
- repair_worktrees(NULL, NULL);
- }
-
- write_file(git_link, "gitdir: %s", git_dir);
-}
-
-static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash)
-{
- const char *env = getenv(GIT_DEFAULT_HASH_ENVIRONMENT);
- /*
- * If we already have an initialized repo, don't allow the user to
- * specify a different algorithm, as that could cause corruption.
- * Otherwise, if the user has specified one on the command line, use it.
- */
- if (repo_fmt->version >= 0 && hash != GIT_HASH_UNKNOWN && hash != repo_fmt->hash_algo)
- die(_("attempt to reinitialize repository with different hash"));
- else if (hash != GIT_HASH_UNKNOWN)
- repo_fmt->hash_algo = hash;
- else if (env) {
- int env_algo = hash_algo_by_name(env);
- if (env_algo == GIT_HASH_UNKNOWN)
- die(_("unknown hash algorithm '%s'"), env);
- repo_fmt->hash_algo = env_algo;
- }
-}
-
-int init_db(const char *git_dir, const char *real_git_dir,
- const char *template_dir, int hash, const char *initial_branch,
- unsigned int flags)
-{
- int reinit;
- int exist_ok = flags & INIT_DB_EXIST_OK;
- char *original_git_dir = real_pathdup(git_dir, 1);
- struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
-
- if (real_git_dir) {
- struct stat st;
-
- if (!exist_ok && !stat(git_dir, &st))
- die(_("%s already exists"), git_dir);
-
- if (!exist_ok && !stat(real_git_dir, &st))
- die(_("%s already exists"), real_git_dir);
-
- set_git_dir(real_git_dir, 1);
- git_dir = get_git_dir();
- separate_git_dir(git_dir, original_git_dir);
- }
- else {
- set_git_dir(git_dir, 1);
- git_dir = get_git_dir();
- }
- startup_info->have_repository = 1;
-
- /* Ensure `core.hidedotfiles` is processed */
- git_config(platform_core_config, NULL);
-
- safe_create_dir(git_dir, 0);
-
- init_is_bare_repository = is_bare_repository();
-
- /* Check to see if the repository version is right.
- * Note that a newly created repository does not have
- * config file, so this will not fail. What we are catching
- * is an attempt to reinitialize new repository with an old tool.
- */
- check_repository_format(&repo_fmt);
-
- validate_hash_algorithm(&repo_fmt, hash);
-
- reinit = create_default_files(template_dir, original_git_dir,
- initial_branch, &repo_fmt,
- flags & INIT_DB_QUIET);
- if (reinit && initial_branch)
- warning(_("re-init: ignored --initial-branch=%s"),
- initial_branch);
-
- create_object_directory();
-
- if (get_shared_repository()) {
- char buf[10];
- /* We do not spell "group" and such, so that
- * the configuration can be read by older version
- * of git. Note, we use octal numbers for new share modes,
- * and compatibility values for PERM_GROUP and
- * PERM_EVERYBODY.
- */
- if (get_shared_repository() < 0)
- /* force to the mode value */
- xsnprintf(buf, sizeof(buf), "0%o", -get_shared_repository());
- else if (get_shared_repository() == PERM_GROUP)
- xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP);
- else if (get_shared_repository() == PERM_EVERYBODY)
- xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
- else
- BUG("invalid value for shared_repository");
- git_config_set("core.sharedrepository", buf);
- git_config_set("receive.denyNonFastforwards", "true");
- }
-
- if (!(flags & INIT_DB_QUIET)) {
- int len = strlen(git_dir);
-
- if (reinit)
- printf(get_shared_repository()
- ? _("Reinitialized existing shared Git repository in %s%s\n")
- : _("Reinitialized existing Git repository in %s%s\n"),
- git_dir, len && git_dir[len-1] != '/' ? "/" : "");
- else
- printf(get_shared_repository()
- ? _("Initialized empty shared Git repository in %s%s\n")
- : _("Initialized empty Git repository in %s%s\n"),
- git_dir, len && git_dir[len-1] != '/' ? "/" : "");
- }
-
- free(original_git_dir);
- return 0;
-}
+#include "strbuf.h"
static int guess_repository_type(const char *git_dir)
{
@@ -546,6 +78,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
const char *object_format = NULL;
const char *initial_branch = NULL;
int hash_algo = GIT_HASH_UNKNOWN;
+ int init_shared_repository = -1;
const struct option init_db_options[] = {
OPT_STRING(0, "template", &template_dir, N_("template-directory"),
N_("directory from which templates will be used")),
@@ -703,5 +236,5 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
flags |= INIT_DB_EXIST_OK;
return init_db(git_dir, real_git_dir, template_dir, hash_algo,
- initial_branch, flags);
+ initial_branch, init_shared_repository, flags);
}
diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c
index 107ac28f0e..c5e8345265 100644
--- a/builtin/interpret-trailers.c
+++ b/builtin/interpret-trailers.c
@@ -5,7 +5,6 @@
*
*/
-#include "cache.h"
#include "builtin.h"
#include "gettext.h"
#include "parse-options.h"
diff --git a/builtin/log.c b/builtin/log.c
index 676de107d6..db3a88bfe9 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -6,7 +6,6 @@
*/
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
@@ -14,7 +13,7 @@
#include "refs.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "pager.h"
#include "color.h"
#include "commit.h"
@@ -564,7 +563,8 @@ static int cmd_log_walk(struct rev_info *rev)
return retval;
}
-static int git_log_config(const char *var, const char *value, void *cb)
+static int git_log_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
const char *slot_name;
@@ -573,7 +573,7 @@ static int git_log_config(const char *var, const char *value, void *cb)
if (!strcmp(var, "format.subjectprefix"))
return git_config_string(&fmt_patch_subject_prefix, var, value);
if (!strcmp(var, "format.filenamemaxlength")) {
- fmt_patch_name_max = git_config_int(var, value);
+ fmt_patch_name_max = git_config_int(var, value, ctx->kvi);
return 0;
}
if (!strcmp(var, "format.encodeemailheaders")) {
@@ -613,7 +613,7 @@ static int git_log_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_diff_ui_config(var, value, cb);
+ return git_diff_ui_config(var, value, ctx, cb);
}
int cmd_whatchanged(int argc, const char **argv, const char *prefix)
@@ -718,8 +718,7 @@ static int show_tree_object(const struct object_id *oid UNUSED,
return 0;
}
-static void show_setup_revisions_tweak(struct rev_info *rev,
- struct setup_revision_opt *opt)
+static void show_setup_revisions_tweak(struct rev_info *rev)
{
if (rev->first_parent_only)
diff_merges_default_to_first_parent(rev);
@@ -862,11 +861,10 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
return cmd_log_deinit(cmd_log_walk(&rev), &rev);
}
-static void log_setup_revisions_tweak(struct rev_info *rev,
- struct setup_revision_opt *opt)
+static void log_setup_revisions_tweak(struct rev_info *rev)
{
if (rev->diffopt.flags.default_follow_renames &&
- rev->prune_data.nr == 1)
+ diff_check_follow_pathspec(&rev->prune_data, 0))
rev->diffopt.flags.follow_renames = 1;
if (rev->first_parent_only)
@@ -979,7 +977,8 @@ static enum cover_from_description parse_cover_from_description(const char *arg)
die(_("%s: invalid cover from description mode"), arg);
}
-static int git_format_config(const char *var, const char *value, void *cb)
+static int git_format_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "format.headers")) {
if (!value)
@@ -1108,7 +1107,7 @@ static int git_format_config(const char *var, const char *value, void *cb)
if (!strcmp(var, "diff.noprefix"))
return 0;
- return git_log_config(var, value, cb);
+ return git_log_config(var, value, ctx, cb);
}
static const char *output_directory = NULL;
@@ -1406,7 +1405,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
}
}
-static const char *clean_message_id(const char *msg_id)
+static char *clean_message_id(const char *msg_id)
{
char ch;
const char *a, *z, *m;
@@ -1424,7 +1423,7 @@ static const char *clean_message_id(const char *msg_id)
if (!z)
die(_("insane in-reply-to: %s"), msg_id);
if (++z == m)
- return a;
+ return xstrdup(a);
return xmemdupz(a, z - a);
}
@@ -2310,11 +2309,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
if (in_reply_to || thread || cover_letter) {
rev.ref_message_ids = xmalloc(sizeof(*rev.ref_message_ids));
- string_list_init_nodup(rev.ref_message_ids);
+ string_list_init_dup(rev.ref_message_ids);
}
if (in_reply_to) {
- const char *msgid = clean_message_id(in_reply_to);
- string_list_append(rev.ref_message_ids, msgid);
+ char *msgid = clean_message_id(in_reply_to);
+ string_list_append_nodup(rev.ref_message_ids, msgid);
}
rev.numbered_files = just_numbers;
rev.patch_suffix = fmt_patch_suffix;
@@ -2370,8 +2369,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
&& (!cover_letter || rev.nr > 1))
free(rev.message_id);
else
- string_list_append(rev.ref_message_ids,
- rev.message_id);
+ string_list_append_nodup(rev.ref_message_ids,
+ rev.message_id);
}
gen_message_id(&rev, oid_to_hex(&commit->object.oid));
}
@@ -2420,6 +2419,7 @@ done:
strbuf_release(&rdiff_title);
strbuf_release(&sprefix);
free(to_free);
+ free(rev.message_id);
if (rev.ref_message_ids)
string_list_clear(rev.ref_message_ids, 0);
free(rev.ref_message_ids);
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 625f48f0d6..a0229c3277 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -5,13 +5,12 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
-#include "cache.h"
+#include "builtin.h"
#include "repository.h"
#include "config.h"
#include "convert.h"
#include "quote.h"
#include "dir.h"
-#include "builtin.h"
#include "gettext.h"
#include "object-name.h"
#include "strbuf.h"
@@ -20,11 +19,17 @@
#include "parse-options.h"
#include "resolve-undo.h"
#include "string-list.h"
+#include "path.h"
#include "pathspec.h"
+#include "read-cache.h"
#include "run-command.h"
#include "setup.h"
+#include "sparse-index.h"
#include "submodule.h"
#include "submodule-config.h"
+#include "object-store.h"
+#include "hex.h"
+
static int abbrev;
static int show_deleted;
@@ -241,68 +246,75 @@ static void show_submodule(struct repository *superproject,
repo_clear(&subrepo);
}
-struct show_index_data {
- const char *pathname;
- struct index_state *istate;
- const struct cache_entry *ce;
-};
-
-static size_t expand_show_index(struct strbuf *sb, const char *start,
- void *context)
+static void expand_objectsize(struct strbuf *line, const struct object_id *oid,
+ const enum object_type type, unsigned int padded)
{
- struct show_index_data *data = context;
- const char *end;
- const char *p;
- size_t len = strbuf_expand_literal_cb(sb, start, NULL);
- struct stat st;
-
- if (len)
- return len;
- if (*start != '(')
- die(_("bad ls-files format: element '%s' "
- "does not start with '('"), start);
-
- end = strchr(start + 1, ')');
- if (!end)
- die(_("bad ls-files format: element '%s' "
- "does not end in ')'"), start);
-
- len = end - start + 1;
- if (skip_prefix(start, "(objectmode)", &p))
- strbuf_addf(sb, "%06o", data->ce->ce_mode);
- else if (skip_prefix(start, "(objectname)", &p))
- strbuf_add_unique_abbrev(sb, &data->ce->oid, abbrev);
- else if (skip_prefix(start, "(stage)", &p))
- strbuf_addf(sb, "%d", ce_stage(data->ce));
- else if (skip_prefix(start, "(eolinfo:index)", &p))
- strbuf_addstr(sb, S_ISREG(data->ce->ce_mode) ?
- get_cached_convert_stats_ascii(data->istate,
- data->ce->name) : "");
- else if (skip_prefix(start, "(eolinfo:worktree)", &p))
- strbuf_addstr(sb, !lstat(data->pathname, &st) &&
- S_ISREG(st.st_mode) ?
- get_wt_convert_stats_ascii(data->pathname) : "");
- else if (skip_prefix(start, "(eolattr)", &p))
- strbuf_addstr(sb, get_convert_attr_ascii(data->istate,
- data->pathname));
- else if (skip_prefix(start, "(path)", &p))
- write_name_to_buf(sb, data->pathname);
- else
- die(_("bad ls-files format: %%%.*s"), (int)len, start);
-
- return len;
+ if (type == OBJ_BLOB) {
+ unsigned long size;
+ if (oid_object_info(the_repository, oid, &size) < 0)
+ die(_("could not get object info about '%s'"),
+ oid_to_hex(oid));
+ if (padded)
+ strbuf_addf(line, "%7"PRIuMAX, (uintmax_t)size);
+ else
+ strbuf_addf(line, "%"PRIuMAX, (uintmax_t)size);
+ } else if (padded) {
+ strbuf_addf(line, "%7s", "-");
+ } else {
+ strbuf_addstr(line, "-");
+ }
}
static void show_ce_fmt(struct repository *repo, const struct cache_entry *ce,
const char *format, const char *fullname) {
- struct show_index_data data = {
- .pathname = fullname,
- .istate = repo->index,
- .ce = ce,
- };
struct strbuf sb = STRBUF_INIT;
- strbuf_expand(&sb, format, expand_show_index, &data);
+ while (strbuf_expand_step(&sb, &format)) {
+ const char *end;
+ size_t len;
+ struct stat st;
+
+ if (skip_prefix(format, "%", &format))
+ strbuf_addch(&sb, '%');
+ else if ((len = strbuf_expand_literal(&sb, format)))
+ format += len;
+ else if (*format != '(')
+ die(_("bad ls-files format: element '%s' "
+ "does not start with '('"), format);
+ else if (!(end = strchr(format + 1, ')')))
+ die(_("bad ls-files format: element '%s' "
+ "does not end in ')'"), format);
+ else if (skip_prefix(format, "(objectmode)", &format))
+ strbuf_addf(&sb, "%06o", ce->ce_mode);
+ else if (skip_prefix(format, "(objectname)", &format))
+ strbuf_add_unique_abbrev(&sb, &ce->oid, abbrev);
+ else if (skip_prefix(format, "(objecttype)", &format))
+ strbuf_addstr(&sb, type_name(object_type(ce->ce_mode)));
+ else if (skip_prefix(format, "(objectsize:padded)", &format))
+ expand_objectsize(&sb, &ce->oid,
+ object_type(ce->ce_mode), 1);
+ else if (skip_prefix(format, "(objectsize)", &format))
+ expand_objectsize(&sb, &ce->oid,
+ object_type(ce->ce_mode), 0);
+ else if (skip_prefix(format, "(stage)", &format))
+ strbuf_addf(&sb, "%d", ce_stage(ce));
+ else if (skip_prefix(format, "(eolinfo:index)", &format))
+ strbuf_addstr(&sb, S_ISREG(ce->ce_mode) ?
+ get_cached_convert_stats_ascii(repo->index,
+ ce->name) : "");
+ else if (skip_prefix(format, "(eolinfo:worktree)", &format))
+ strbuf_addstr(&sb, !lstat(fullname, &st) &&
+ S_ISREG(st.st_mode) ?
+ get_wt_convert_stats_ascii(fullname) : "");
+ else if (skip_prefix(format, "(eolattr)", &format))
+ strbuf_addstr(&sb, get_convert_attr_ascii(repo->index,
+ fullname));
+ else if (skip_prefix(format, "(path)", &format))
+ write_name_to_buf(&sb, fullname);
+ else
+ die(_("bad ls-files format: %%%.*s"),
+ (int)(end - format + 1), format);
+ }
strbuf_addch(&sb, line_terminator);
fwrite(sb.buf, sb.len, 1, stdout);
strbuf_release(&sb);
@@ -516,143 +528,6 @@ static int get_common_prefix_len(const char *common_prefix)
return common_prefix_len;
}
-static int read_one_entry_opt(struct index_state *istate,
- const struct object_id *oid,
- struct strbuf *base,
- const char *pathname,
- unsigned mode, int opt)
-{
- int len;
- struct cache_entry *ce;
-
- if (S_ISDIR(mode))
- return READ_TREE_RECURSIVE;
-
- len = strlen(pathname);
- ce = make_empty_cache_entry(istate, base->len + len);
-
- ce->ce_mode = create_ce_mode(mode);
- ce->ce_flags = create_ce_flags(1);
- ce->ce_namelen = base->len + len;
- memcpy(ce->name, base->buf, base->len);
- memcpy(ce->name + base->len, pathname, len+1);
- oidcpy(&ce->oid, oid);
- return add_index_entry(istate, ce, opt);
-}
-
-static int read_one_entry(const struct object_id *oid, struct strbuf *base,
- const char *pathname, unsigned mode,
- void *context)
-{
- struct index_state *istate = context;
- return read_one_entry_opt(istate, oid, base, pathname,
- mode,
- ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
-}
-
-/*
- * This is used when the caller knows there is no existing entries at
- * the stage that will conflict with the entry being added.
- */
-static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base,
- const char *pathname, unsigned mode,
- void *context)
-{
- struct index_state *istate = context;
- return read_one_entry_opt(istate, oid, base, pathname,
- mode, ADD_CACHE_JUST_APPEND);
-}
-
-/*
- * Read the tree specified with --with-tree option
- * (typically, HEAD) into stage #1 and then
- * squash them down to stage #0. This is used for
- * --error-unmatch to list and check the path patterns
- * that were given from the command line. We are not
- * going to write this index out.
- */
-void overlay_tree_on_index(struct index_state *istate,
- const char *tree_name, const char *prefix)
-{
- struct tree *tree;
- struct object_id oid;
- struct pathspec pathspec;
- struct cache_entry *last_stage0 = NULL;
- int i;
- read_tree_fn_t fn = NULL;
- int err;
-
- if (repo_get_oid(the_repository, tree_name, &oid))
- die("tree-ish %s not found.", tree_name);
- tree = parse_tree_indirect(&oid);
- if (!tree)
- die("bad tree-ish %s", tree_name);
-
- /* Hoist the unmerged entries up to stage #3 to make room */
- /* TODO: audit for interaction with sparse-index. */
- ensure_full_index(istate);
- for (i = 0; i < istate->cache_nr; i++) {
- struct cache_entry *ce = istate->cache[i];
- if (!ce_stage(ce))
- continue;
- ce->ce_flags |= CE_STAGEMASK;
- }
-
- if (prefix) {
- static const char *(matchbuf[1]);
- matchbuf[0] = NULL;
- parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC,
- PATHSPEC_PREFER_CWD, prefix, matchbuf);
- } else
- memset(&pathspec, 0, sizeof(pathspec));
-
- /*
- * See if we have cache entry at the stage. If so,
- * do it the original slow way, otherwise, append and then
- * sort at the end.
- */
- for (i = 0; !fn && i < istate->cache_nr; i++) {
- const struct cache_entry *ce = istate->cache[i];
- if (ce_stage(ce) == 1)
- fn = read_one_entry;
- }
-
- if (!fn)
- fn = read_one_entry_quick;
- err = read_tree(the_repository, tree, &pathspec, fn, istate);
- clear_pathspec(&pathspec);
- if (err)
- die("unable to read tree entries %s", tree_name);
-
- /*
- * Sort the cache entry -- we need to nuke the cache tree, though.
- */
- if (fn == read_one_entry_quick) {
- cache_tree_free(&istate->cache_tree);
- QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare);
- }
-
- for (i = 0; i < istate->cache_nr; i++) {
- struct cache_entry *ce = istate->cache[i];
- switch (ce_stage(ce)) {
- case 0:
- last_stage0 = ce;
- /* fallthru */
- default:
- continue;
- case 1:
- /*
- * If there is stage #0 entry for this, we do not
- * need to show it. We use CE_UPDATE bit to mark
- * such an entry.
- */
- if (last_stage0 &&
- !strcmp(last_stage0->name, ce->name))
- ce->ce_flags |= CE_UPDATE;
- }
- }
-}
-
static const char * const ls_files_usage[] = {
N_("git ls-files [<options>] [<file>...]"),
NULL
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index cb6cb77e08..fc76575430 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "cache.h"
#include "gettext.h"
#include "hex.h"
#include "transport.h"
@@ -8,6 +7,7 @@
#include "remote.h"
#include "refs.h"
#include "parse-options.h"
+#include "wildmatch.h"
static const char * const ls_remote_usage[] = {
N_("git ls-remote [--heads] [--tags] [--refs] [--upload-pack=<exec>]\n"
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 077977a461..f558db5f3b 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -3,17 +3,17 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
-#include "cache.h"
+#include "builtin.h"
#include "config.h"
#include "gettext.h"
#include "hex.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "blob.h"
#include "tree.h"
#include "commit.h"
+#include "path.h"
#include "quote.h"
-#include "builtin.h"
#include "parse-options.h"
#include "pathspec.h"
@@ -50,68 +50,10 @@ struct ls_tree_options {
LS_SHOW_TREES = 1 << 2,
} ls_options;
struct pathspec pathspec;
- int chomp_prefix;
- const char *ls_tree_prefix;
+ const char *prefix;
const char *format;
};
-struct show_tree_data {
- struct ls_tree_options *options;
- unsigned mode;
- enum object_type type;
- const struct object_id *oid;
- const char *pathname;
- struct strbuf *base;
-};
-
-static size_t expand_show_tree(struct strbuf *sb, const char *start,
- void *context)
-{
- struct show_tree_data *data = context;
- struct ls_tree_options *options = data->options;
- const char *end;
- const char *p;
- unsigned int errlen;
- size_t len = strbuf_expand_literal_cb(sb, start, NULL);
-
- if (len)
- return len;
- if (*start != '(')
- die(_("bad ls-tree format: element '%s' does not start with '('"), start);
-
- end = strchr(start + 1, ')');
- if (!end)
- die(_("bad ls-tree format: element '%s' does not end in ')'"), start);
-
- len = end - start + 1;
- if (skip_prefix(start, "(objectmode)", &p)) {
- strbuf_addf(sb, "%06o", data->mode);
- } else if (skip_prefix(start, "(objecttype)", &p)) {
- strbuf_addstr(sb, type_name(data->type));
- } else if (skip_prefix(start, "(objectsize:padded)", &p)) {
- expand_objectsize(sb, data->oid, data->type, 1);
- } else if (skip_prefix(start, "(objectsize)", &p)) {
- expand_objectsize(sb, data->oid, data->type, 0);
- } else if (skip_prefix(start, "(objectname)", &p)) {
- strbuf_add_unique_abbrev(sb, data->oid, options->abbrev);
- } else if (skip_prefix(start, "(path)", &p)) {
- const char *name = data->base->buf;
- const char *prefix = options->chomp_prefix ? options->ls_tree_prefix : NULL;
- struct strbuf sbuf = STRBUF_INIT;
- size_t baselen = data->base->len;
-
- strbuf_addstr(data->base, data->pathname);
- name = relative_path(data->base->buf, prefix, &sbuf);
- quote_c_style(name, sb, NULL, 0);
- strbuf_setlen(data->base, baselen);
- strbuf_release(&sbuf);
- } else {
- errlen = (unsigned long)len;
- die(_("bad ls-tree format: %%%.*s"), errlen, start);
- }
- return len;
-}
-
static int show_recursive(struct ls_tree_options *options, const char *base,
size_t baselen, const char *pathname)
{
@@ -150,14 +92,7 @@ static int show_tree_fmt(const struct object_id *oid, struct strbuf *base,
int recurse = 0;
struct strbuf sb = STRBUF_INIT;
enum object_type type = object_type(mode);
- struct show_tree_data cb_data = {
- .options = options,
- .mode = mode,
- .type = type,
- .oid = oid,
- .pathname = pathname,
- .base = base,
- };
+ const char *format = options->format;
if (type == OBJ_TREE && show_recursive(options, base->buf, base->len, pathname))
recurse = READ_TREE_RECURSIVE;
@@ -166,7 +101,45 @@ static int show_tree_fmt(const struct object_id *oid, struct strbuf *base,
if (type == OBJ_BLOB && (options->ls_options & LS_TREE_ONLY))
return 0;
- strbuf_expand(&sb, options->format, expand_show_tree, &cb_data);
+ while (strbuf_expand_step(&sb, &format)) {
+ const char *end;
+ size_t len;
+
+ if (skip_prefix(format, "%", &format))
+ strbuf_addch(&sb, '%');
+ else if ((len = strbuf_expand_literal(&sb, format)))
+ format += len;
+ else if (*format != '(')
+ die(_("bad ls-tree format: element '%s' "
+ "does not start with '('"), format);
+ else if (!(end = strchr(format + 1, ')')))
+ die(_("bad ls-tree format: element '%s' "
+ "does not end in ')'"), format);
+ else if (skip_prefix(format, "(objectmode)", &format))
+ strbuf_addf(&sb, "%06o", mode);
+ else if (skip_prefix(format, "(objecttype)", &format))
+ strbuf_addstr(&sb, type_name(type));
+ else if (skip_prefix(format, "(objectsize:padded)", &format))
+ expand_objectsize(&sb, oid, type, 1);
+ else if (skip_prefix(format, "(objectsize)", &format))
+ expand_objectsize(&sb, oid, type, 0);
+ else if (skip_prefix(format, "(objectname)", &format))
+ strbuf_add_unique_abbrev(&sb, oid, options->abbrev);
+ else if (skip_prefix(format, "(path)", &format)) {
+ const char *name;
+ const char *prefix = options->prefix;
+ struct strbuf sbuf = STRBUF_INIT;
+ size_t baselen = base->len;
+
+ strbuf_addstr(base, pathname);
+ name = relative_path(base->buf, prefix, &sbuf);
+ quote_c_style(name, &sb, NULL, 0);
+ strbuf_setlen(base, baselen);
+ strbuf_release(&sbuf);
+ } else
+ die(_("bad ls-tree format: %%%.*s"),
+ (int)(end - format + 1), format);
+ }
strbuf_addch(&sb, options->null_termination ? '\0' : '\n');
fwrite(sb.buf, sb.len, 1, stdout);
strbuf_release(&sb);
@@ -198,7 +171,7 @@ static void show_tree_common_default_long(struct ls_tree_options *options,
const char *pathname,
const size_t baselen)
{
- const char *prefix = options->chomp_prefix ? options->ls_tree_prefix : NULL;
+ const char *prefix = options->prefix;
strbuf_addstr(base, pathname);
@@ -283,7 +256,7 @@ static int show_tree_name_only(const struct object_id *oid, struct strbuf *base,
if (early >= 0)
return early;
- prefix = options->chomp_prefix ? options->ls_tree_prefix : NULL;
+ prefix = options->prefix;
strbuf_addstr(base, pathname);
if (options->null_termination) {
struct strbuf sb = STRBUF_INIT;
@@ -370,6 +343,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
struct object_id oid;
struct tree *tree;
int i, full_tree = 0;
+ int full_name = !prefix || !*prefix;
read_tree_fn_t fn = NULL;
enum ls_tree_cmdmode cmdmode = MODE_DEFAULT;
int null_termination = 0;
@@ -391,8 +365,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
MODE_NAME_STATUS),
OPT_CMDMODE(0, "object-only", &cmdmode, N_("list only objects"),
MODE_OBJECT_ONLY),
- OPT_SET_INT(0, "full-name", &options.chomp_prefix,
- N_("use full path names"), 0),
+ OPT_BOOL(0, "full-name", &full_name, N_("use full path names")),
OPT_BOOL(0, "full-tree", &full_tree,
N_("list entire tree; not just current directory "
"(implies --full-name)")),
@@ -406,18 +379,15 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
int ret;
git_config(git_default_config, NULL);
- options.ls_tree_prefix = prefix;
- if (prefix)
- options.chomp_prefix = strlen(prefix);
argc = parse_options(argc, argv, prefix, ls_tree_options,
ls_tree_usage, 0);
options.null_termination = null_termination;
- if (full_tree) {
- options.ls_tree_prefix = prefix = NULL;
- options.chomp_prefix = 0;
- }
+ if (full_tree)
+ prefix = NULL;
+ options.prefix = full_name ? NULL : prefix;
+
/*
* We wanted to detect conflicts between --name-only and
* --name-status, but once we're done with that subsequent
diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index a032a1c388..53b55dd71c 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -2,9 +2,8 @@
* Another stupid program, this one parsing the headers of an
* email to figure out authorship and subject
*/
-#include "cache.h"
-#include "abspath.h"
#include "builtin.h"
+#include "abspath.h"
#include "environment.h"
#include "gettext.h"
#include "utf8.h"
diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c
index 0b6193a091..3af9ddb8ae 100644
--- a/builtin/mailsplit.c
+++ b/builtin/mailsplit.c
@@ -4,7 +4,6 @@
* It just splits a mbox into a list of files: "0001" "0002" ..
* so you can process them further from there.
*/
-#include "cache.h"
#include "builtin.h"
#include "gettext.h"
#include "string-list.h"
diff --git a/builtin/merge-base.c b/builtin/merge-base.c
index 854019a32d..e68b7fe45d 100644
--- a/builtin/merge-base.c
+++ b/builtin/merge-base.c
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "cache.h"
#include "config.h"
#include "commit.h"
#include "gettext.h"
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 781818d08f..d7eb4c6540 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -1,6 +1,5 @@
#include "builtin.h"
#include "abspath.h"
-#include "cache.h"
#include "config.h"
#include "gettext.h"
#include "setup.h"
diff --git a/builtin/merge-index.c b/builtin/merge-index.c
index ab16e70f23..270d5f644a 100644
--- a/builtin/merge-index.c
+++ b/builtin/merge-index.c
@@ -1,8 +1,10 @@
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "hex.h"
+#include "read-cache-ll.h"
#include "repository.h"
#include "run-command.h"
+#include "sparse-index.h"
static const char *pgm;
static int one_shot, quiet;
diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c
index c2e519301e..932924e5d0 100644
--- a/builtin/merge-ours.c
+++ b/builtin/merge-ours.c
@@ -10,6 +10,7 @@
#include "git-compat-util.h"
#include "builtin.h"
#include "diff.h"
+#include "repository.h"
static const char builtin_merge_ours_usage[] =
"git merge-ours <base>... -- HEAD <remote>...";
diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c
index b9e980384a..3366699657 100644
--- a/builtin/merge-recursive.c
+++ b/builtin/merge-recursive.c
@@ -1,4 +1,3 @@
-#include "cache.h"
#include "builtin.h"
#include "advice.h"
#include "commit.h"
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index b8f8a8b5d9..0de42aecf4 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -9,7 +9,7 @@
#include "commit-reach.h"
#include "merge-ort.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "parse-options.h"
#include "repository.h"
#include "blob.h"
@@ -324,7 +324,9 @@ static void unresolved(const struct traverse_info *info, struct name_entry n[3])
* The successful merge rules are the same as for the three-way merge
* in git-read-tree.
*/
-static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *info)
+static int threeway_callback(int n UNUSED, unsigned long mask,
+ unsigned long dirmask UNUSED,
+ struct name_entry *entry, struct traverse_info *info)
{
/* Same in both? */
if (same_entry(entry+1, entry+2) || both_empty(entry+1, entry+2)) {
@@ -448,7 +450,7 @@ static int real_merge(struct merge_tree_options *o,
base_commit = lookup_commit_reference_by_name(merge_base);
if (!base_commit)
- die(_("could not lookup commit %s"), merge_base);
+ die(_("could not lookup commit '%s'"), merge_base);
opt.ancestor = merge_base;
base_tree = repo_get_commit_tree(the_repository, base_commit);
diff --git a/builtin/merge.c b/builtin/merge.c
index 8da3e46abb..de68910177 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -7,10 +7,9 @@
*/
#define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
#include "abspath.h"
#include "advice.h"
-#include "alloc.h"
#include "config.h"
#include "editor.h"
#include "environment.h"
@@ -18,7 +17,6 @@
#include "hex.h"
#include "object-name.h"
#include "parse-options.h"
-#include "builtin.h"
#include "lockfile.h"
#include "run-command.h"
#include "hook.h"
@@ -28,6 +26,7 @@
#include "refspec.h"
#include "commit.h"
#include "diffcore.h"
+#include "path.h"
#include "revision.h"
#include "unpack-trees.h"
#include "cache-tree.h"
@@ -37,6 +36,7 @@
#include "color.h"
#include "rerere.h"
#include "help.h"
+#include "merge.h"
#include "merge-recursive.h"
#include "merge-ort-wrappers.h"
#include "resolve-undo.h"
@@ -52,7 +52,6 @@
#include "commit-reach.h"
#include "wt-status.h"
#include "commit-graph.h"
-#include "wrapper.h"
#define DEFAULT_TWOHEAD (1<<0)
#define DEFAULT_OCTOPUS (1<<1)
@@ -623,7 +622,8 @@ static void parse_branch_merge_options(char *bmo)
free(argv);
}
-static int git_merge_config(const char *k, const char *v, void *cb)
+static int git_merge_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
int status;
const char *str;
@@ -668,10 +668,10 @@ static int git_merge_config(const char *k, const char *v, void *cb)
return 0;
}
- status = fmt_merge_msg_config(k, v, cb);
+ status = fmt_merge_msg_config(k, v, ctx, cb);
if (status)
return status;
- return git_diff_ui_config(k, v, cb);
+ return git_diff_ui_config(k, v, ctx, cb);
}
static int read_tree_trivial(struct object_id *common, struct object_id *head,
@@ -879,13 +879,15 @@ static void prepare_to_commit(struct commit_list *remoteheads)
strbuf_addch(&msg, '\n');
if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) {
wt_status_append_cut_line(&msg);
- strbuf_commented_addf(&msg, "\n");
+ strbuf_commented_addf(&msg, comment_line_char, "\n");
}
- strbuf_commented_addf(&msg, _(merge_editor_comment));
+ strbuf_commented_addf(&msg, comment_line_char,
+ _(merge_editor_comment));
if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS)
- strbuf_commented_addf(&msg, _(scissors_editor_comment));
+ strbuf_commented_addf(&msg, comment_line_char,
+ _(scissors_editor_comment));
else
- strbuf_commented_addf(&msg,
+ strbuf_commented_addf(&msg, comment_line_char,
_(no_scissors_editor_comment), comment_line_char);
}
if (signoff)
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 44fa56eff3..d8e0b5afc0 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -2,10 +2,11 @@
#include "gettext.h"
#include "hex.h"
#include "parse-options.h"
+#include "strbuf.h"
#include "tag.h"
#include "replace-object.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "fsck.h"
#include "config.h"
@@ -17,11 +18,11 @@ static int option_strict = 1;
static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
-static int mktag_fsck_error_func(struct fsck_options *o,
- const struct object_id *oid,
- enum object_type object_type,
+static int mktag_fsck_error_func(struct fsck_options *o UNUSED,
+ const struct object_id *oid UNUSED,
+ enum object_type object_type UNUSED,
enum fsck_msg_type msg_type,
- enum fsck_msg_id msg_id,
+ enum fsck_msg_id msg_id UNUSED,
const char *message)
{
switch (msg_type) {
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 09a7bd5c5c..9a22d4e277 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -4,13 +4,13 @@
* Copyright (c) Junio C Hamano, 2006, 2009
*/
#include "builtin.h"
-#include "alloc.h"
#include "gettext.h"
#include "hex.h"
#include "quote.h"
+#include "strbuf.h"
#include "tree.h"
#include "parse-options.h"
-#include "object-store.h"
+#include "object-store-ll.h"
static struct treeent {
unsigned mode;
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 1b5083f8b2..a72aebecaa 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -1,13 +1,13 @@
#include "builtin.h"
#include "abspath.h"
-#include "cache.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
#include "parse-options.h"
#include "midx.h"
+#include "strbuf.h"
#include "trace2.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#define BUILTIN_MIDX_WRITE_USAGE \
N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]" \
@@ -82,6 +82,7 @@ static struct option *add_common_options(struct option *prev)
}
static int git_multi_pack_index_write_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
if (!strcmp(var, "pack.writebitmaphashcache")) {
diff --git a/builtin/mv.c b/builtin/mv.c
index 665bd27448..fa84fcb20d 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -7,10 +7,10 @@
#include "builtin.h"
#include "abspath.h"
#include "advice.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
+#include "name-hash.h"
#include "object-file.h"
#include "pathspec.h"
#include "lockfile.h"
@@ -18,6 +18,7 @@
#include "cache-tree.h"
#include "string-list.h"
#include "parse-options.h"
+#include "read-cache-ll.h"
#include "repository.h"
#include "setup.h"
#include "submodule.h"
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 4d15a23fc4..c706fa3720 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
@@ -15,6 +14,7 @@
#include "hash-lookup.h"
#include "commit-slab.h"
#include "commit-graph.h"
+#include "wildmatch.h"
/*
* One day. See the 'name a rev shortly after epoch' test in t6120 when
diff --git a/builtin/notes.c b/builtin/notes.c
index d5788352b6..9f38863dd5 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -7,15 +7,17 @@
* and builtin/tag.c by Kristian Høgsberg and Carlos Rica.
*/
-#include "cache.h"
-#include "config.h"
#include "builtin.h"
+#include "config.h"
+#include "alloc.h"
#include "editor.h"
+#include "environment.h"
#include "gettext.h"
#include "hex.h"
#include "notes.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "path.h"
#include "repository.h"
#include "blob.h"
#include "pretty.h"
@@ -29,11 +31,12 @@
#include "worktree.h"
#include "write-or-die.h"
+static const char *separator = "\n";
static const char * const git_notes_usage[] = {
N_("git notes [--ref <notes-ref>] [list [<object>]]"),
- N_("git notes [--ref <notes-ref>] add [-f] [--allow-empty] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"),
+ N_("git notes [--ref <notes-ref>] add [-f] [--allow-empty] [--[no-]separator|--separator=<paragraph-break>] [--[no-]stripspace] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"),
N_("git notes [--ref <notes-ref>] copy [-f] <from-object> <to-object>"),
- N_("git notes [--ref <notes-ref>] append [--allow-empty] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"),
+ N_("git notes [--ref <notes-ref>] append [--allow-empty] [--[no-]separator|--separator=<paragraph-break>] [--[no-]stripspace] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"),
N_("git notes [--ref <notes-ref>] edit [--allow-empty] [<object>]"),
N_("git notes [--ref <notes-ref>] show [<object>]"),
N_("git notes [--ref <notes-ref>] merge [-v | -q] [-s <strategy>] <notes-ref>"),
@@ -101,11 +104,26 @@ static const char * const git_notes_get_ref_usage[] = {
static const char note_template[] =
N_("Write/edit the notes for the following object:");
+enum notes_stripspace {
+ UNSPECIFIED = -1,
+ NO_STRIPSPACE = 0,
+ STRIPSPACE = 1,
+};
+
+struct note_msg {
+ enum notes_stripspace stripspace;
+ struct strbuf buf;
+};
+
struct note_data {
int given;
int use_editor;
+ int stripspace;
char *edit_path;
struct strbuf buf;
+ struct note_msg **messages;
+ size_t msg_nr;
+ size_t msg_alloc;
};
static void free_note_data(struct note_data *d)
@@ -115,6 +133,12 @@ static void free_note_data(struct note_data *d)
free(d->edit_path);
}
strbuf_release(&d->buf);
+
+ while (d->msg_nr--) {
+ strbuf_release(&d->messages[d->msg_nr]->buf);
+ free(d->messages[d->msg_nr]);
+ }
+ free(d->messages);
}
static int list_each_note(const struct object_id *object_oid,
@@ -157,7 +181,7 @@ static void write_commented_object(int fd, const struct object_id *object)
if (strbuf_read(&buf, show.out, 0) < 0)
die_errno(_("could not read 'show' output"));
- strbuf_add_commented_lines(&cbuf, buf.buf, buf.len);
+ strbuf_add_commented_lines(&cbuf, buf.buf, buf.len, comment_line_char);
write_or_die(fd, cbuf.buf, cbuf.len);
strbuf_release(&cbuf);
@@ -185,9 +209,10 @@ static void prepare_note_data(const struct object_id *object, struct note_data *
copy_obj_to_fd(fd, old_note);
strbuf_addch(&buf, '\n');
- strbuf_add_commented_lines(&buf, "\n", strlen("\n"));
- strbuf_add_commented_lines(&buf, _(note_template), strlen(_(note_template)));
- strbuf_add_commented_lines(&buf, "\n", strlen("\n"));
+ strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_char);
+ strbuf_add_commented_lines(&buf, _(note_template), strlen(_(note_template)),
+ comment_line_char);
+ strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_char);
write_or_die(fd, buf.buf, buf.len);
write_commented_object(fd, object);
@@ -199,7 +224,8 @@ static void prepare_note_data(const struct object_id *object, struct note_data *
if (launch_editor(d->edit_path, &d->buf, NULL)) {
die(_("please supply the note contents using either -m or -F option"));
}
- strbuf_stripspace(&d->buf, 1);
+ if (d->stripspace)
+ strbuf_stripspace(&d->buf, comment_line_char);
}
}
@@ -215,66 +241,102 @@ static void write_note_data(struct note_data *d, struct object_id *oid)
}
}
+static void append_separator(struct strbuf *message)
+{
+ size_t sep_len = 0;
+
+ if (!separator)
+ return;
+ else if ((sep_len = strlen(separator)) && separator[sep_len - 1] == '\n')
+ strbuf_addstr(message, separator);
+ else
+ strbuf_addf(message, "%s%s", separator, "\n");
+}
+
+static void concat_messages(struct note_data *d)
+{
+ struct strbuf msg = STRBUF_INIT;
+ size_t i;
+
+ for (i = 0; i < d->msg_nr ; i++) {
+ if (d->buf.len)
+ append_separator(&d->buf);
+ strbuf_add(&msg, d->messages[i]->buf.buf, d->messages[i]->buf.len);
+ strbuf_addbuf(&d->buf, &msg);
+ if ((d->stripspace == UNSPECIFIED &&
+ d->messages[i]->stripspace == STRIPSPACE) ||
+ d->stripspace == STRIPSPACE)
+ strbuf_stripspace(&d->buf, 0);
+ strbuf_reset(&msg);
+ }
+ strbuf_release(&msg);
+}
+
static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
{
struct note_data *d = opt->value;
+ struct note_msg *msg = xmalloc(sizeof(*msg));
BUG_ON_OPT_NEG(unset);
- strbuf_grow(&d->buf, strlen(arg) + 2);
- if (d->buf.len)
- strbuf_addch(&d->buf, '\n');
- strbuf_addstr(&d->buf, arg);
- strbuf_stripspace(&d->buf, 0);
-
- d->given = 1;
+ strbuf_init(&msg->buf, strlen(arg));
+ strbuf_addstr(&msg->buf, arg);
+ ALLOC_GROW_BY(d->messages, d->msg_nr, 1, d->msg_alloc);
+ d->messages[d->msg_nr - 1] = msg;
+ msg->stripspace = STRIPSPACE;
return 0;
}
static int parse_file_arg(const struct option *opt, const char *arg, int unset)
{
struct note_data *d = opt->value;
+ struct note_msg *msg = xmalloc(sizeof(*msg));
BUG_ON_OPT_NEG(unset);
- if (d->buf.len)
- strbuf_addch(&d->buf, '\n');
+ strbuf_init(&msg->buf , 0);
if (!strcmp(arg, "-")) {
- if (strbuf_read(&d->buf, 0, 1024) < 0)
+ if (strbuf_read(&msg->buf, 0, 1024) < 0)
die_errno(_("cannot read '%s'"), arg);
- } else if (strbuf_read_file(&d->buf, arg, 1024) < 0)
+ } else if (strbuf_read_file(&msg->buf, arg, 1024) < 0)
die_errno(_("could not open or read '%s'"), arg);
- strbuf_stripspace(&d->buf, 0);
- d->given = 1;
+ ALLOC_GROW_BY(d->messages, d->msg_nr, 1, d->msg_alloc);
+ d->messages[d->msg_nr - 1] = msg;
+ msg->stripspace = STRIPSPACE;
return 0;
}
static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
{
struct note_data *d = opt->value;
- char *buf;
+ struct note_msg *msg = xmalloc(sizeof(*msg));
+ char *value;
struct object_id object;
enum object_type type;
unsigned long len;
BUG_ON_OPT_NEG(unset);
- if (d->buf.len)
- strbuf_addch(&d->buf, '\n');
-
+ strbuf_init(&msg->buf, 0);
if (repo_get_oid(the_repository, arg, &object))
die(_("failed to resolve '%s' as a valid ref."), arg);
- if (!(buf = repo_read_object_file(the_repository, &object, &type, &len)))
+ if (!(value = repo_read_object_file(the_repository, &object, &type, &len)))
die(_("failed to read object '%s'."), arg);
if (type != OBJ_BLOB) {
- free(buf);
+ strbuf_release(&msg->buf);
+ free(value);
+ free(msg);
die(_("cannot read note data from non-blob object '%s'."), arg);
}
- strbuf_add(&d->buf, buf, len);
- free(buf);
- d->given = 1;
+ strbuf_add(&msg->buf, value, len);
+ free(value);
+
+ msg->buf.len = len;
+ ALLOC_GROW_BY(d->messages, d->msg_nr, 1, d->msg_alloc);
+ d->messages[d->msg_nr - 1] = msg;
+ msg->stripspace = NO_STRIPSPACE;
return 0;
}
@@ -286,6 +348,16 @@ static int parse_reedit_arg(const struct option *opt, const char *arg, int unset
return parse_reuse_arg(opt, arg, unset);
}
+static int parse_separator_arg(const struct option *opt, const char *arg,
+ int unset)
+{
+ if (unset)
+ *(const char **)opt->value = NULL;
+ else
+ *(const char **)opt->value = arg ? arg : "\n";
+ return 0;
+}
+
static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
{
struct strbuf buf = STRBUF_INIT;
@@ -408,7 +480,8 @@ static int add(int argc, const char **argv, const char *prefix)
struct notes_tree *t;
struct object_id object, new_note;
const struct object_id *note;
- struct note_data d = { 0, 0, NULL, STRBUF_INIT };
+ struct note_data d = { .buf = STRBUF_INIT, .stripspace = UNSPECIFIED };
+
struct option options[] = {
OPT_CALLBACK_F('m', "message", &d, N_("message"),
N_("note contents as a string"), PARSE_OPT_NONEG,
@@ -425,6 +498,12 @@ static int add(int argc, const char **argv, const char *prefix)
OPT_BOOL(0, "allow-empty", &allow_empty,
N_("allow storing empty note")),
OPT__FORCE(&force, N_("replace existing notes"), PARSE_OPT_NOCOMPLETE),
+ OPT_CALLBACK_F(0, "separator", &separator,
+ N_("<paragraph-break>"),
+ N_("insert <paragraph-break> between paragraphs"),
+ PARSE_OPT_OPTARG, parse_separator_arg),
+ OPT_BOOL(0, "stripspace", &d.stripspace,
+ N_("remove unnecessary whitespace")),
OPT_END()
};
@@ -436,6 +515,10 @@ static int add(int argc, const char **argv, const char *prefix)
usage_with_options(git_notes_add_usage, options);
}
+ if (d.msg_nr)
+ concat_messages(&d);
+ d.given = !!d.buf.len;
+
object_ref = argc > 1 ? argv[1] : "HEAD";
if (repo_get_oid(the_repository, object_ref, &object))
@@ -574,7 +657,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
const struct object_id *note;
char *logmsg;
const char * const *usage;
- struct note_data d = { 0, 0, NULL, STRBUF_INIT };
+ struct note_data d = { .buf = STRBUF_INIT, .stripspace = UNSPECIFIED };
struct option options[] = {
OPT_CALLBACK_F('m', "message", &d, N_("message"),
N_("note contents as a string"), PARSE_OPT_NONEG,
@@ -590,6 +673,12 @@ static int append_edit(int argc, const char **argv, const char *prefix)
parse_reuse_arg),
OPT_BOOL(0, "allow-empty", &allow_empty,
N_("allow storing empty note")),
+ OPT_CALLBACK_F(0, "separator", &separator,
+ N_("<paragraph-break>"),
+ N_("insert <paragraph-break> between paragraphs"),
+ PARSE_OPT_OPTARG, parse_separator_arg),
+ OPT_BOOL(0, "stripspace", &d.stripspace,
+ N_("remove unnecessary whitespace")),
OPT_END()
};
int edit = !strcmp(argv[0], "edit");
@@ -603,6 +692,10 @@ static int append_edit(int argc, const char **argv, const char *prefix)
usage_with_options(usage, options);
}
+ if (d.msg_nr)
+ concat_messages(&d);
+ d.given = !!d.buf.len;
+
if (d.given && edit)
fprintf(stderr, _("The -m/-F/-c/-C options have been deprecated "
"for the 'edit' subcommand.\n"
@@ -622,15 +715,17 @@ static int append_edit(int argc, const char **argv, const char *prefix)
/* Append buf to previous note contents */
unsigned long size;
enum object_type type;
- char *prev_buf = repo_read_object_file(the_repository, note,
- &type, &size);
+ struct strbuf buf = STRBUF_INIT;
+ char *prev_buf = repo_read_object_file(the_repository, note, &type, &size);
- strbuf_grow(&d.buf, size + 1);
- if (d.buf.len && prev_buf && size)
- strbuf_insertstr(&d.buf, 0, "\n");
if (prev_buf && size)
- strbuf_insert(&d.buf, 0, prev_buf, size);
+ strbuf_add(&buf, prev_buf, size);
+ if (d.buf.len && prev_buf && size)
+ append_separator(&buf);
+ strbuf_insert(&d.buf, 0, buf.buf, buf.len);
+
free(prev_buf);
+ strbuf_release(&buf);
}
if (d.buf.len || allow_empty) {
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 9cfc8801f9..d2a162d528 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
@@ -34,7 +33,7 @@
#include "list.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "replace-object.h"
#include "dir.h"
#include "midx.h"
@@ -43,7 +42,6 @@
#include "promisor-remote.h"
#include "pack-mtimes.h"
#include "parse-options.h"
-#include "wrapper.h"
/*
* Objects we are going to pack are collected in the `to_pack` structure.
@@ -3135,26 +3133,27 @@ static void prepare_pack(int window, int depth)
free(delta_list);
}
-static int git_pack_config(const char *k, const char *v, void *cb)
+static int git_pack_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(k, "pack.window")) {
- window = git_config_int(k, v);
+ window = git_config_int(k, v, ctx->kvi);
return 0;
}
if (!strcmp(k, "pack.windowmemory")) {
- window_memory_limit = git_config_ulong(k, v);
+ window_memory_limit = git_config_ulong(k, v, ctx->kvi);
return 0;
}
if (!strcmp(k, "pack.depth")) {
- depth = git_config_int(k, v);
+ depth = git_config_int(k, v, ctx->kvi);
return 0;
}
if (!strcmp(k, "pack.deltacachesize")) {
- max_delta_cache_size = git_config_int(k, v);
+ max_delta_cache_size = git_config_int(k, v, ctx->kvi);
return 0;
}
if (!strcmp(k, "pack.deltacachelimit")) {
- cache_max_small_delta_size = git_config_int(k, v);
+ cache_max_small_delta_size = git_config_int(k, v, ctx->kvi);
return 0;
}
if (!strcmp(k, "pack.writebitmaphashcache")) {
@@ -3180,7 +3179,7 @@ static int git_pack_config(const char *k, const char *v, void *cb)
return 0;
}
if (!strcmp(k, "pack.threads")) {
- delta_search_threads = git_config_int(k, v);
+ delta_search_threads = git_config_int(k, v, ctx->kvi);
if (delta_search_threads < 0)
die(_("invalid number of threads specified (%d)"),
delta_search_threads);
@@ -3191,7 +3190,7 @@ static int git_pack_config(const char *k, const char *v, void *cb)
return 0;
}
if (!strcmp(k, "pack.indexversion")) {
- pack_idx_opts.version = git_config_int(k, v);
+ pack_idx_opts.version = git_config_int(k, v, ctx->kvi);
if (pack_idx_opts.version > 2)
die(_("bad pack.indexVersion=%"PRIu32),
pack_idx_opts.version);
@@ -3227,7 +3226,7 @@ static int git_pack_config(const char *k, const char *v, void *cb)
ex->uri = xstrdup(pack_end + 1);
oidmap_put(&configured_exclusions, ex);
}
- return git_default_config(k, v, cb);
+ return git_default_config(k, v, ctx, cb);
}
/* Counters for trace2 output when in --stdin-packs mode. */
@@ -4118,6 +4117,18 @@ static void add_extra_kept_packs(const struct string_list *names)
}
}
+static int option_parse_quiet(const struct option *opt, const char *arg,
+ int unset)
+{
+ BUG_ON_OPT_ARG(arg);
+
+ if (!unset)
+ progress = 0;
+ else if (!progress)
+ progress = 1;
+ return 0;
+}
+
static int option_parse_index_version(const struct option *opt,
const char *arg, int unset)
{
@@ -4179,8 +4190,9 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
LIST_OBJECTS_FILTER_INIT;
struct option pack_objects_options[] = {
- OPT_SET_INT('q', "quiet", &progress,
- N_("do not show progress meter"), 0),
+ OPT_CALLBACK_F('q', "quiet", NULL, NULL,
+ N_("do not show progress meter"),
+ PARSE_OPT_NOARG, option_parse_quiet),
OPT_SET_INT(0, "progress", &progress,
N_("show progress meter"), 1),
OPT_SET_INT(0, "all-progress", &progress,
@@ -4256,8 +4268,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
N_("ignore this pack")),
OPT_INTEGER(0, "compression", &pack_compression_level,
N_("pack compression level")),
- OPT_SET_INT(0, "keep-true-parents", &grafts_replace_parents,
- N_("do not hide commits by grafts"), 0),
+ OPT_BOOL(0, "keep-true-parents", &grafts_keep_true_parents,
+ N_("do not hide commits by grafts")),
OPT_BOOL(0, "use-bitmap-index", &use_bitmap_index,
N_("use a bitmap index if available to speed up counting objects")),
OPT_SET_INT(0, "write-bitmap-index", &write_bitmap_index,
@@ -4284,7 +4296,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
if (DFS_NUM_STATES > (1 << OE_DFS_STATE_BITS))
BUG("too many dfs states, increase OE_DFS_STATE_BITS");
- read_replace_refs = 0;
+ disable_replace_refs();
sparse = git_env_bool("GIT_TEST_PACK_SPARSE", -1);
if (the_repository->gitdir) {
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 43e9d12dfd..4c735ba069 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -11,7 +11,7 @@
#include "hex.h"
#include "repository.h"
#include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#define BLKSIZE 512
diff --git a/builtin/pack-refs.c b/builtin/pack-refs.c
index 9833815fb3..bcf383cac9 100644
--- a/builtin/pack-refs.c
+++ b/builtin/pack-refs.c
@@ -4,22 +4,45 @@
#include "parse-options.h"
#include "refs.h"
#include "repository.h"
+#include "revision.h"
static char const * const pack_refs_usage[] = {
- N_("git pack-refs [--all] [--no-prune]"),
+ N_("git pack-refs [--all] [--no-prune] [--include <pattern>] [--exclude <pattern>]"),
NULL
};
int cmd_pack_refs(int argc, const char **argv, const char *prefix)
{
unsigned int flags = PACK_REFS_PRUNE;
+ static struct ref_exclusions excludes = REF_EXCLUSIONS_INIT;
+ static struct string_list included_refs = STRING_LIST_INIT_NODUP;
+ struct pack_refs_opts pack_refs_opts = { .exclusions = &excludes,
+ .includes = &included_refs,
+ .flags = flags };
+ static struct string_list option_excluded_refs = STRING_LIST_INIT_NODUP;
+ struct string_list_item *item;
+
struct option opts[] = {
- OPT_BIT(0, "all", &flags, N_("pack everything"), PACK_REFS_ALL),
- OPT_BIT(0, "prune", &flags, N_("prune loose refs (default)"), PACK_REFS_PRUNE),
+ OPT_BIT(0, "all", &pack_refs_opts.flags, N_("pack everything"), PACK_REFS_ALL),
+ OPT_BIT(0, "prune", &pack_refs_opts.flags, N_("prune loose refs (default)"), PACK_REFS_PRUNE),
+ OPT_STRING_LIST(0, "include", pack_refs_opts.includes, N_("pattern"),
+ N_("references to include")),
+ OPT_STRING_LIST(0, "exclude", &option_excluded_refs, N_("pattern"),
+ N_("references to exclude")),
OPT_END(),
};
git_config(git_default_config, NULL);
if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
usage_with_options(pack_refs_usage, opts);
- return refs_pack_refs(get_main_ref_store(the_repository), flags);
+
+ for_each_string_list_item(item, &option_excluded_refs)
+ add_ref_exclusion(pack_refs_opts.exclusions, item->string);
+
+ if (pack_refs_opts.flags & PACK_REFS_ALL)
+ string_list_append(pack_refs_opts.includes, "*");
+
+ if (!pack_refs_opts.includes->nr)
+ string_list_append(pack_refs_opts.includes, "refs/tags/*");
+
+ return refs_pack_refs(get_main_ref_store(the_repository), &pack_refs_opts);
}
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 9d5585d3a7..3894d2b970 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -1,8 +1,8 @@
-#include "cache.h"
#include "builtin.h"
#include "config.h"
#include "diff.h"
#include "gettext.h"
+#include "hash.h"
#include "hex.h"
#include "parse-options.h"
@@ -196,7 +196,8 @@ struct patch_id_opts {
int verbatim;
};
-static int git_patch_id_config(const char *var, const char *value, void *cb)
+static int git_patch_id_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
struct patch_id_opts *opts = cb;
@@ -209,7 +210,7 @@ static int git_patch_id_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
int cmd_patch_id(int argc, const char **argv, const char *prefix)
diff --git a/builtin/prune.c b/builtin/prune.c
index 5dc9b20720..57fe31467f 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -1,19 +1,20 @@
-#include "cache.h"
+#include "builtin.h"
#include "commit.h"
#include "diff.h"
+#include "dir.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
#include "revision.h"
-#include "builtin.h"
#include "reachable.h"
#include "parse-options.h"
+#include "path.h"
#include "progress.h"
#include "prune-packed.h"
#include "replace-object.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "shallow.h"
static const char * const prune_usage[] = {
@@ -164,7 +165,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
expire = TIME_MAX;
save_commit_buffer = 0;
- read_replace_refs = 0;
+ disable_replace_refs();
repo_init_revisions(the_repository, &revs, prefix);
argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
diff --git a/builtin/pull.c b/builtin/pull.c
index 0c7bac97b7..be2b2c9ebc 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -6,12 +6,12 @@
* Fetch one or more remote refs and merge it/them into the current HEAD.
*/
#define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
#include "advice.h"
#include "config.h"
-#include "builtin.h"
#include "gettext.h"
#include "hex.h"
+#include "merge.h"
#include "object-name.h"
#include "parse-options.h"
#include "exec-cmd.h"
@@ -19,6 +19,8 @@
#include "oid-array.h"
#include "remote.h"
#include "dir.h"
+#include "path.h"
+#include "read-cache-ll.h"
#include "rebase.h"
#include "refs.h"
#include "refspec.h"
@@ -361,7 +363,8 @@ static enum rebase_type config_get_rebase(int *rebase_unspecified)
/**
* Read config variables.
*/
-static int git_pull_config(const char *var, const char *value, void *cb)
+static int git_pull_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "rebase.autostash")) {
config_autostash = git_config_bool(var, value);
@@ -374,7 +377,7 @@ static int git_pull_config(const char *var, const char *value, void *cb)
check_trust_level = 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
/**
diff --git a/builtin/push.c b/builtin/push.c
index dbdf609daf..2e708383c2 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -1,7 +1,7 @@
/*
* "git push"
*/
-#include "cache.h"
+#include "builtin.h"
#include "advice.h"
#include "branch.h"
#include "config.h"
@@ -10,7 +10,6 @@
#include "refs.h"
#include "refspec.h"
#include "run-command.h"
-#include "builtin.h"
#include "remote.h"
#include "transport.h"
#include "parse-options.h"
@@ -302,21 +301,21 @@ static void setup_default_push_refspecs(int *flags, struct remote *remote)
static const char message_advice_pull_before_push[] =
N_("Updates were rejected because the tip of your current branch is behind\n"
- "its remote counterpart. Integrate the remote changes (e.g.\n"
- "'git pull ...') before pushing again.\n"
+ "its remote counterpart. If you want to integrate the remote changes,\n"
+ "use 'git pull' before pushing again.\n"
"See the 'Note about fast-forwards' in 'git push --help' for details.");
static const char message_advice_checkout_pull_push[] =
N_("Updates were rejected because a pushed branch tip is behind its remote\n"
- "counterpart. Check out this branch and integrate the remote changes\n"
- "(e.g. 'git pull ...') before pushing again.\n"
+ "counterpart. If you want to integrate the remote changes, use 'git pull'\n"
+ "before pushing again.\n"
"See the 'Note about fast-forwards' in 'git push --help' for details.");
static const char message_advice_ref_fetch_first[] =
- N_("Updates were rejected because the remote contains work that you do\n"
- "not have locally. This is usually caused by another repository pushing\n"
- "to the same ref. You may want to first integrate the remote changes\n"
- "(e.g., 'git pull ...') before pushing again.\n"
+ N_("Updates were rejected because the remote contains work that you do not\n"
+ "have locally. This is usually caused by another repository pushing to\n"
+ "the same ref. If you want to integrate the remote changes, use\n"
+ "'git pull' before pushing again.\n"
"See the 'Note about fast-forwards' in 'git push --help' for details.");
static const char message_advice_ref_already_exists[] =
@@ -328,10 +327,10 @@ static const char message_advice_ref_needs_force[] =
"without using the '--force' option.\n");
static const char message_advice_ref_needs_update[] =
- N_("Updates were rejected because the tip of the remote-tracking\n"
- "branch has been updated since the last checkout. You may want\n"
- "to integrate those changes locally (e.g., 'git pull ...')\n"
- "before forcing an update.\n");
+ N_("Updates were rejected because the tip of the remote-tracking branch has\n"
+ "been updated since the last checkout. If you want to integrate the\n"
+ "remote changes, use 'git pull' before pushing again.\n"
+ "See the 'Note about fast-forwards' in 'git push --help' for details.");
static void advise_pull_before_push(void)
{
@@ -510,7 +509,8 @@ static void set_push_cert_flags(int *flags, int v)
}
-static int git_push_config(const char *k, const char *v, void *cb)
+static int git_push_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
const char *slot_name;
int *flags = cb;
@@ -577,7 +577,7 @@ static int git_push_config(const char *k, const char *v, void *cb)
return 0;
}
- return git_default_config(k, v, NULL);
+ return git_default_config(k, v, ctx, NULL);
}
int cmd_push(int argc, const char **argv, const char *prefix)
@@ -627,10 +627,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
PARSE_OPT_OPTARG, option_parse_push_signed),
OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC),
OPT_STRING_LIST('o', "push-option", &push_options_cmdline, N_("server-specific"), N_("option to transmit")),
- OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
- TRANSPORT_FAMILY_IPV4),
- OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
- TRANSPORT_FAMILY_IPV6),
+ OPT_IPVERSION(&family),
OPT_END()
};
diff --git a/builtin/range-diff.c b/builtin/range-diff.c
index 04339a92ea..e455a4795c 100644
--- a/builtin/range-diff.c
+++ b/builtin/range-diff.c
@@ -1,10 +1,10 @@
-#include "cache.h"
#include "builtin.h"
#include "gettext.h"
#include "object-name.h"
#include "parse-options.h"
#include "range-diff.h"
#include "config.h"
+#include "repository.h"
#include "revision.h"
static const char * const builtin_range_diff_usage[] = {
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 440f19b1b8..1fec702a04 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -5,7 +5,7 @@
*/
#define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
#include "config.h"
#include "gettext.h"
#include "hex.h"
@@ -17,11 +17,11 @@
#include "cache-tree.h"
#include "unpack-trees.h"
#include "dir.h"
-#include "builtin.h"
#include "parse-options.h"
#include "repository.h"
#include "resolve-undo.h"
#include "setup.h"
+#include "sparse-index.h"
#include "submodule.h"
#include "submodule-config.h"
@@ -102,12 +102,13 @@ static int debug_merge(const struct cache_entry * const *stages,
return 0;
}
-static int git_read_tree_config(const char *var, const char *value, void *cb)
+static int git_read_tree_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "submodule.recurse"))
return git_default_submodule_config(var, value, cb);
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
diff --git a/builtin/rebase.c b/builtin/rebase.c
index ace1d5e8d1..50cb85751f 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -24,6 +24,7 @@
#include "object-file.h"
#include "object-name.h"
#include "parse-options.h"
+#include "path.h"
#include "commit.h"
#include "diff.h"
#include "wt-status.h"
@@ -36,7 +37,6 @@
#include "reset.h"
#include "trace2.h"
#include "hook.h"
-#include "wrapper.h"
static char const * const builtin_rebase_usage[] = {
N_("git rebase [-i] [options] [--exec <cmd>] "
@@ -209,7 +209,7 @@ static int edit_todo_file(unsigned flags)
if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
return error_errno(_("could not read '%s'."), todo_file);
- strbuf_stripspace(&todo_list.buf, 1);
+ strbuf_stripspace(&todo_list.buf, comment_line_char);
res = edit_todo_list(the_repository, &todo_list, &new_todo, NULL, NULL, flags);
if (!res && todo_list_write_to_file(the_repository, &new_todo, todo_file,
NULL, NULL, -1, flags & ~(TODO_LIST_SHORTEN_IDS)))
@@ -772,7 +772,8 @@ static void parse_rebase_merges_value(struct rebase_options *options, const char
die(_("Unknown rebase-merges mode: %s"), value);
}
-static int rebase_config(const char *var, const char *value, void *data)
+static int rebase_config(const char *var, const char *value,
+ const struct config_context *ctx, void *data)
{
struct rebase_options *opts = data;
@@ -831,7 +832,7 @@ static int rebase_config(const char *var, const char *value, void *data)
return git_config_string(&opts->default_backend, var, value);
}
- return git_default_config(var, value, data);
+ return git_default_config(var, value, ctx, data);
}
static int checkout_up_to_date(struct rebase_options *options)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 1a31a58367..fb8e1549d1 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -30,7 +30,8 @@
#include "oidset.h"
#include "packfile.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "path.h"
#include "protocol.h"
#include "commit-reach.h"
#include "server-info.h"
@@ -39,7 +40,6 @@
#include "worktree.h"
#include "shallow.h"
#include "parse-options.h"
-#include "wrapper.h"
static const char * const receive_pack_usage[] = {
N_("git receive-pack <git-dir>"),
@@ -90,7 +90,7 @@ static struct object_id push_cert_oid;
static struct signature_check sigcheck;
static const char *push_cert_nonce;
static const char *cert_nonce_seed;
-static struct string_list hidden_refs = STRING_LIST_INIT_DUP;
+static struct strvec hidden_refs = STRVEC_INIT;
static const char *NONCE_UNSOLICITED = "UNSOLICITED";
static const char *NONCE_BAD = "BAD";
@@ -139,7 +139,8 @@ static enum deny_action parse_deny_action(const char *var, const char *value)
return DENY_IGNORE;
}
-static int receive_pack_config(const char *var, const char *value, void *cb)
+static int receive_pack_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
int status = parse_hide_refs_config(var, value, "receive", &hidden_refs);
@@ -157,12 +158,12 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
}
if (strcmp(var, "receive.unpacklimit") == 0) {
- receive_unpack_limit = git_config_int(var, value);
+ receive_unpack_limit = git_config_int(var, value, ctx->kvi);
return 0;
}
if (strcmp(var, "transfer.unpacklimit") == 0) {
- transfer_unpack_limit = git_config_int(var, value);
+ transfer_unpack_limit = git_config_int(var, value, ctx->kvi);
return 0;
}
@@ -230,7 +231,7 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
return git_config_string(&cert_nonce_seed, var, value);
if (strcmp(var, "receive.certnonceslop") == 0) {
- nonce_stamp_slop_limit = git_config_ulong(var, value);
+ nonce_stamp_slop_limit = git_config_ulong(var, value, ctx->kvi);
return 0;
}
@@ -245,12 +246,12 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
}
if (strcmp(var, "receive.keepalive") == 0) {
- keepalive_in_sec = git_config_int(var, value);
+ keepalive_in_sec = git_config_int(var, value, ctx->kvi);
return 0;
}
if (strcmp(var, "receive.maxinputsize") == 0) {
- max_input_size = git_config_int64(var, value);
+ max_input_size = git_config_int64(var, value, ctx->kvi);
return 0;
}
@@ -266,7 +267,7 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static void show_ref(const char *path, const struct object_id *oid)
@@ -337,7 +338,9 @@ static void write_head_info(void)
{
static struct oidset seen = OIDSET_INIT;
- for_each_ref(show_ref_cb, &seen);
+ refs_for_each_fullref_in(get_main_ref_store(the_repository), "",
+ hidden_refs_to_excludes(&hidden_refs),
+ show_ref_cb, &seen);
for_each_alternate_ref(show_one_alternate_ref, &seen);
oidset_clear(&seen);
if (!sent_capabilities)
@@ -2619,7 +2622,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
packet_flush(1);
oid_array_clear(&shallow);
oid_array_clear(&ref);
- string_list_clear(&hidden_refs, 0);
+ strvec_clear(&hidden_refs);
free((void *)push_cert_nonce);
return 0;
}
diff --git a/builtin/reflog.c b/builtin/reflog.c
index a1fa0c855f..df63a5892e 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -1,8 +1,10 @@
#include "builtin.h"
#include "config.h"
#include "gettext.h"
+#include "repository.h"
#include "revision.h"
#include "reachable.h"
+#include "wildmatch.h"
#include "worktree.h"
#include "reflog.h"
#include "parse-options.h"
@@ -108,7 +110,8 @@ static struct reflog_expire_cfg *find_cfg_ent(const char *pattern, size_t len)
#define EXPIRE_TOTAL 01
#define EXPIRE_UNREACH 02
-static int reflog_expire_config(const char *var, const char *value, void *cb)
+static int reflog_expire_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
const char *pattern, *key;
size_t pattern_len;
@@ -117,7 +120,7 @@ static int reflog_expire_config(const char *var, const char *value, void *cb)
struct reflog_expire_cfg *ent;
if (parse_config_key(var, "gc", &pattern, &pattern_len, &key) < 0)
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
if (!strcmp(key, "reflogexpire")) {
slot = EXPIRE_TOTAL;
@@ -128,7 +131,7 @@ static int reflog_expire_config(const char *var, const char *value, void *cb)
if (git_config_expiry_date(&expire, var, value))
return -1;
} else
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
if (!pattern) {
switch (slot) {
diff --git a/builtin/remote.c b/builtin/remote.c
index 1e0b137d97..d91bbe728d 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -2,6 +2,7 @@
#include "config.h"
#include "gettext.h"
#include "parse-options.h"
+#include "path.h"
#include "transport.h"
#include "remote.h"
#include "string-list.h"
@@ -10,7 +11,7 @@
#include "rebase.h"
#include "refs.h"
#include "refspec.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "strvec.h"
#include "commit-reach.h"
#include "progress.h"
@@ -167,10 +168,9 @@ static int add(int argc, const char **argv, const char *prefix)
struct option options[] = {
OPT_BOOL('f', "fetch", &fetch, N_("fetch the remote branches")),
OPT_SET_INT(0, "tags", &fetch_tags,
- N_("import all tags and associated objects when fetching"),
+ N_("import all tags and associated objects when fetching\n"
+ "or do not fetch any tag at all (--no-tags)"),
TAGS_SET),
- OPT_SET_INT(0, NULL, &fetch_tags,
- N_("or do not fetch any tag at all (--no-tags)"), TAGS_UNSET),
OPT_STRING_LIST('t', "track", &track, N_("branch"),
N_("branch(es) to track")),
OPT_STRING('m', "master", &master, N_("branch"), N_("master branch")),
@@ -268,6 +268,7 @@ static const char *abbrev_ref(const char *name, const char *prefix)
#define abbrev_branch(name) abbrev_ref((name), "refs/heads/")
static int config_read_branches(const char *key, const char *value,
+ const struct config_context *ctx UNUSED,
void *data UNUSED)
{
const char *orig_key = key;
@@ -645,17 +646,19 @@ struct push_default_info
};
static int config_read_push_default(const char *key, const char *value,
- void *cb)
+ const struct config_context *ctx, void *cb)
{
+ const struct key_value_info *kvi = ctx->kvi;
+
struct push_default_info* info = cb;
if (strcmp(key, "remote.pushdefault") ||
!value || strcmp(value, info->old_name))
return 0;
- info->scope = current_config_scope();
+ info->scope = kvi->scope;
strbuf_reset(&info->origin);
- strbuf_addstr(&info->origin, current_config_name());
- info->linenr = current_config_line();
+ strbuf_addstr(&info->origin, config_origin_type_name(kvi->origin_type));
+ info->linenr = kvi->linenr;
return 0;
}
@@ -1494,7 +1497,9 @@ static int prune(int argc, const char **argv, const char *prefix)
return result;
}
-static int get_remote_default(const char *key, const char *value UNUSED, void *priv)
+static int get_remote_default(const char *key, const char *value UNUSED,
+ const struct config_context *ctx UNUSED,
+ void *priv)
{
if (strcmp(key, "remotes.default") == 0) {
int *found = priv;
diff --git a/builtin/repack.c b/builtin/repack.c
index 0541c3ce15..aea5ca9d44 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -1,11 +1,11 @@
#include "builtin.h"
-#include "alloc.h"
#include "config.h"
#include "dir.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
#include "parse-options.h"
+#include "path.h"
#include "run-command.h"
#include "server-info.h"
#include "sigchain.h"
@@ -15,7 +15,7 @@
#include "midx.h"
#include "packfile.h"
#include "prune-packed.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "promisor-remote.h"
#include "shallow.h"
#include "pack.h"
@@ -59,7 +59,8 @@ struct pack_objects_args {
int local;
};
-static int repack_config(const char *var, const char *value, void *cb)
+static int repack_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
struct pack_objects_args *cruft_po_args = cb;
if (!strcmp(var, "repack.usedeltabaseoffset")) {
@@ -91,12 +92,12 @@ static int repack_config(const char *var, const char *value, void *cb)
return git_config_string(&cruft_po_args->depth, var, value);
if (!strcmp(var, "repack.cruftthreads"))
return git_config_string(&cruft_po_args->threads, var, value);
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
/*
- * Adds all packs hex strings to either fname_nonkept_list or
- * fname_kept_list based on whether each pack has a corresponding
+ * Adds all packs hex strings (pack-$HASH) to either fname_nonkept_list
+ * or fname_kept_list based on whether each pack has a corresponding
* .keep file or not. Packs without a .keep file are not to be kept
* if we are going to pack everything into one file.
*/
@@ -104,40 +105,38 @@ static void collect_pack_filenames(struct string_list *fname_nonkept_list,
struct string_list *fname_kept_list,
const struct string_list *extra_keep)
{
- DIR *dir;
- struct dirent *e;
- char *fname;
-
- if (!(dir = opendir(packdir)))
- return;
+ struct packed_git *p;
+ struct strbuf buf = STRBUF_INIT;
- while ((e = readdir(dir)) != NULL) {
- size_t len;
+ for (p = get_all_packs(the_repository); p; p = p->next) {
int i;
+ const char *base;
- if (!strip_suffix(e->d_name, ".pack", &len))
+ if (!p->pack_local)
continue;
+ base = pack_basename(p);
+
for (i = 0; i < extra_keep->nr; i++)
- if (!fspathcmp(e->d_name, extra_keep->items[i].string))
+ if (!fspathcmp(base, extra_keep->items[i].string))
break;
- fname = xmemdupz(e->d_name, len);
+ strbuf_reset(&buf);
+ strbuf_addstr(&buf, base);
+ strbuf_strip_suffix(&buf, ".pack");
- if ((extra_keep->nr > 0 && i < extra_keep->nr) ||
- (file_exists(mkpath("%s/%s.keep", packdir, fname)))) {
- string_list_append_nodup(fname_kept_list, fname);
- } else {
+ if ((extra_keep->nr > 0 && i < extra_keep->nr) || p->pack_keep)
+ string_list_append(fname_kept_list, buf.buf);
+ else {
struct string_list_item *item;
- item = string_list_append_nodup(fname_nonkept_list,
- fname);
- if (file_exists(mkpath("%s/%s.mtimes", packdir, fname)))
+ item = string_list_append(fname_nonkept_list, buf.buf);
+ if (p->is_cruft)
item->util = (void*)(uintptr_t)CRUFT_PACK;
}
}
- closedir(dir);
string_list_sort(fname_kept_list);
+ strbuf_release(&buf);
}
static void remove_redundant_pack(const char *dir_name, const char *base_name)
diff --git a/builtin/replace.c b/builtin/replace.c
index 981f189443..da59600ad2 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -8,22 +8,23 @@
* git-tag.sh and mktag.c by Linus Torvalds.
*/
-#include "cache.h"
-#include "config.h"
#include "builtin.h"
+#include "config.h"
#include "editor.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
#include "refs.h"
#include "parse-options.h"
+#include "path.h"
#include "run-command.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "replace-object.h"
#include "repository.h"
#include "tag.h"
+#include "wildmatch.h"
static const char * const git_replace_usage[] = {
N_("git replace [-f] <object> <replacement>"),
@@ -48,7 +49,7 @@ struct show_data {
static int show_reference(struct repository *r, const char *refname,
const struct object_id *oid,
- int flag, void *cb_data)
+ int flag UNUSED, void *cb_data)
{
struct show_data *data = cb_data;
@@ -408,7 +409,7 @@ struct check_mergetag_data {
const char **argv;
};
-static int check_one_mergetag(struct commit *commit,
+static int check_one_mergetag(struct commit *commit UNUSED,
struct commit_extra_header *extra,
void *data)
{
@@ -566,7 +567,7 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
OPT_END()
};
- read_replace_refs = 0;
+ disable_replace_refs();
git_config(git_default_config, NULL);
argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0);
diff --git a/builtin/rerere.c b/builtin/rerere.c
index d4bd52797f..07a9d37275 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "cache.h"
#include "config.h"
#include "dir.h"
#include "gettext.h"
@@ -7,7 +6,6 @@
#include "repository.h"
#include "string-list.h"
#include "rerere.h"
-#include "wrapper.h"
#include "xdiff/xdiff.h"
#include "xdiff-interface.h"
#include "pathspec.h"
diff --git a/builtin/reset.c b/builtin/reset.c
index f99f32d580..4b018d20e3 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -13,6 +13,7 @@
#include "config.h"
#include "environment.h"
#include "gettext.h"
+#include "hash.h"
#include "hex.h"
#include "lockfile.h"
#include "tag.h"
@@ -26,9 +27,11 @@
#include "branch.h"
#include "object-name.h"
#include "parse-options.h"
+#include "path.h"
#include "unpack-trees.h"
#include "cache-tree.h"
#include "setup.h"
+#include "sparse-index.h"
#include "submodule.h"
#include "submodule-config.h"
#include "trace.h"
@@ -312,12 +315,13 @@ static int reset_refs(const char *rev, const struct object_id *oid)
return update_ref_status;
}
-static int git_reset_config(const char *var, const char *value, void *cb)
+static int git_reset_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "submodule.recurse"))
return git_default_submodule_config(var, value, cb);
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
int cmd_reset(int argc, const char **argv, const char *prefix)
@@ -334,18 +338,25 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
OPT__QUIET(&quiet, N_("be quiet, only report errors")),
OPT_BOOL(0, "no-refresh", &no_refresh,
N_("skip refreshing the index after reset")),
- OPT_SET_INT(0, "mixed", &reset_type,
- N_("reset HEAD and index"), MIXED),
- OPT_SET_INT(0, "soft", &reset_type, N_("reset only HEAD"), SOFT),
- OPT_SET_INT(0, "hard", &reset_type,
- N_("reset HEAD, index and working tree"), HARD),
- OPT_SET_INT(0, "merge", &reset_type,
- N_("reset HEAD, index and working tree"), MERGE),
- OPT_SET_INT(0, "keep", &reset_type,
- N_("reset HEAD but keep local changes"), KEEP),
+ OPT_SET_INT_F(0, "mixed", &reset_type,
+ N_("reset HEAD and index"),
+ MIXED, PARSE_OPT_NONEG),
+ OPT_SET_INT_F(0, "soft", &reset_type,
+ N_("reset only HEAD"),
+ SOFT, PARSE_OPT_NONEG),
+ OPT_SET_INT_F(0, "hard", &reset_type,
+ N_("reset HEAD, index and working tree"),
+ HARD, PARSE_OPT_NONEG),
+ OPT_SET_INT_F(0, "merge", &reset_type,
+ N_("reset HEAD, index and working tree"),
+ MERGE, PARSE_OPT_NONEG),
+ OPT_SET_INT_F(0, "keep", &reset_type,
+ N_("reset HEAD but keep local changes"),
+ KEEP, PARSE_OPT_NONEG),
OPT_CALLBACK_F(0, "recurse-submodules", NULL,
- "reset", "control recursive updating of submodules",
- PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater),
+ "reset", "control recursive updating of submodules",
+ PARSE_OPT_OPTARG,
+ option_parse_recurse_submodules_worktree_updater),
OPT_BOOL('p', "patch", &patch_mode, N_("select hunks interactively")),
OPT_BOOL('N', "intent-to-add", &intent_to_add,
N_("record only the fact that removed paths will be added later")),
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 6dc8be492a..ff715d6918 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "builtin.h"
#include "config.h"
#include "commit.h"
#include "diff.h"
@@ -12,10 +12,9 @@
#include "object.h"
#include "object-name.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "pack.h"
#include "pack-bitmap.h"
-#include "builtin.h"
#include "log-tree.h"
#include "graph.h"
#include "bisect.h"
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 852e49e340..fde8861ca4 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -4,20 +4,21 @@
* Copyright (C) Linus Torvalds, 2005
*/
#define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "commit.h"
#include "environment.h"
#include "gettext.h"
+#include "hash.h"
#include "hex.h"
#include "refs.h"
#include "quote.h"
-#include "builtin.h"
#include "object-name.h"
#include "parse-options.h"
+#include "path.h"
#include "diff.h"
+#include "read-cache-ll.h"
#include "revision.h"
#include "setup.h"
#include "split-index.h"
@@ -156,9 +157,12 @@ static void show_rev(int type, const struct object_id *oid, const char *name)
*/
break;
case 1: /* happy */
- if (abbrev_ref)
+ if (abbrev_ref) {
+ char *old = full;
full = shorten_unambiguous_ref(full,
abbrev_ref_strict);
+ free(old);
+ }
show_with_type(type, full);
break;
default: /* ambiguous */
@@ -221,7 +225,7 @@ static int anti_reference(const char *refname, const struct object_id *oid,
return 0;
}
-static int show_abbrev(const struct object_id *oid, void *cb_data)
+static int show_abbrev(const struct object_id *oid, void *cb_data UNUSED)
{
show_rev(NORMAL, oid, NULL);
return 0;
diff --git a/builtin/revert.c b/builtin/revert.c
index 0240ec8593..e6f9a1ad26 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -1,10 +1,10 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "builtin.h"
#include "parse-options.h"
#include "diff.h"
#include "gettext.h"
+#include "repository.h"
#include "revision.h"
#include "rerere.h"
#include "dir.h"
diff --git a/builtin/rm.c b/builtin/rm.c
index b4589c824c..dff819ae50 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -5,7 +5,6 @@
*/
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
-#include "alloc.h"
#include "advice.h"
#include "config.h"
#include "lockfile.h"
@@ -16,9 +15,11 @@
#include "tree-walk.h"
#include "object-name.h"
#include "parse-options.h"
+#include "read-cache.h"
#include "repository.h"
#include "string-list.h"
#include "setup.h"
+#include "sparse-index.h"
#include "submodule.h"
#include "pathspec.h"
diff --git a/builtin/send-pack.c b/builtin/send-pack.c
index 4784143004..cd6d9e4112 100644
--- a/builtin/send-pack.c
+++ b/builtin/send-pack.c
@@ -131,7 +131,8 @@ static void print_helper_status(struct ref *ref)
strbuf_release(&buf);
}
-static int send_pack_config(const char *k, const char *v, void *cb)
+static int send_pack_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(k, "push.gpgsign")) {
const char *value;
@@ -151,7 +152,7 @@ static int send_pack_config(const char *k, const char *v, void *cb)
}
}
}
- return git_default_config(k, v, cb);
+ return git_default_config(k, v, ctx, cb);
}
int cmd_send_pack(int argc, const char **argv, const char *prefix)
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index 46f4e0832a..1307ed2b88 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -1,11 +1,11 @@
#include "builtin.h"
-#include "cache.h"
#include "config.h"
#include "commit.h"
#include "diff.h"
#include "environment.h"
#include "gettext.h"
#include "string-list.h"
+#include "repository.h"
#include "revision.h"
#include "utf8.h"
#include "mailmap.h"
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 7ef4a642c1..b01ec761d2 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "builtin.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
@@ -6,7 +6,6 @@
#include "hex.h"
#include "pretty.h"
#include "refs.h"
-#include "builtin.h"
#include "color.h"
#include "strvec.h"
#include "object-name.h"
@@ -15,6 +14,7 @@
#include "dir.h"
#include "commit-slab.h"
#include "date.h"
+#include "wildmatch.h"
static const char* show_branch_usage[] = {
N_("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n"
@@ -559,7 +559,8 @@ static void append_one_rev(const char *av)
die("bad sha1 reference %s", av);
}
-static int git_show_branch_config(const char *var, const char *value, void *cb)
+static int git_show_branch_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "showbranch.default")) {
if (!value)
@@ -579,7 +580,10 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_color_default_config(var, value, cb);
+ if (git_color_config(var, value, cb) < 0)
+ return -1;
+
+ return git_default_config(var, value, ctx, cb);
}
static int omit_in_dense(struct commit *commit, struct commit **rev, int n)
@@ -645,7 +649,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
int with_current_branch = 0;
int head_at = -1;
int topics = 0;
- int dense = 1;
+ int sparse = 0;
const char *reflog_base = NULL;
struct option builtin_show_branch_options[] = {
OPT_BOOL('a', "all", &all_heads,
@@ -667,17 +671,17 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
N_("show possible merge bases")),
OPT_BOOL(0, "independent", &independent,
N_("show refs unreachable from any other ref")),
- OPT_SET_INT(0, "topo-order", &sort_order,
- N_("show commits in topological order"),
- REV_SORT_IN_GRAPH_ORDER),
+ OPT_SET_INT_F(0, "topo-order", &sort_order,
+ N_("show commits in topological order"),
+ REV_SORT_IN_GRAPH_ORDER, PARSE_OPT_NONEG),
OPT_BOOL(0, "topics", &topics,
N_("show only commits not on the first branch")),
- OPT_SET_INT(0, "sparse", &dense,
- N_("show merges reachable from only one tip"), 0),
- OPT_SET_INT(0, "date-order", &sort_order,
- N_("topologically sort, maintaining date order "
- "where possible"),
- REV_SORT_BY_COMMIT_DATE),
+ OPT_SET_INT(0, "sparse", &sparse,
+ N_("show merges reachable from only one tip"), 1),
+ OPT_SET_INT_F(0, "date-order", &sort_order,
+ N_("topologically sort, maintaining date order "
+ "where possible"),
+ REV_SORT_BY_COMMIT_DATE, PARSE_OPT_NONEG),
OPT_CALLBACK_F('g', "reflog", &reflog_base, N_("<n>[,<base>]"),
N_("show <n> most recent ref-log entries starting at "
"base"),
@@ -936,7 +940,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
!is_merge_point &&
(this_flag & (1u << REV_SHIFT)))
continue;
- if (dense && is_merge &&
+ if (!sparse && is_merge &&
omit_in_dense(commit, rev, num_rev))
continue;
for (i = 0; i < num_rev; i++) {
diff --git a/builtin/show-index.c b/builtin/show-index.c
index d839e55335..540dc3dad1 100644
--- a/builtin/show-index.c
+++ b/builtin/show-index.c
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "cache.h"
#include "gettext.h"
#include "hash.h"
#include "hex.h"
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index a2243b4219..5110814f79 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -1,11 +1,10 @@
#include "builtin.h"
-#include "cache.h"
#include "config.h"
#include "gettext.h"
#include "hex.h"
#include "refs.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "object.h"
#include "tag.h"
#include "string-list.h"
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 40d420f06c..5c8ffb1f75 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "cache.h"
#include "config.h"
#include "dir.h"
#include "environment.h"
diff --git a/builtin/stash.c b/builtin/stash.c
index a7e17ffe38..fe64cde9ce 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -4,6 +4,7 @@
#include "config.h"
#include "environment.h"
#include "gettext.h"
+#include "hash.h"
#include "hex.h"
#include "object-name.h"
#include "parse-options.h"
@@ -17,9 +18,12 @@
#include "run-command.h"
#include "dir.h"
#include "entry.h"
+#include "preload-index.h"
+#include "read-cache.h"
#include "rerere.h"
#include "revision.h"
#include "setup.h"
+#include "sparse-index.h"
#include "log-tree.h"
#include "diffcore.h"
#include "exec-cmd.h"
@@ -837,7 +841,8 @@ static int show_stat = 1;
static int show_patch;
static int show_include_untracked;
-static int git_stash_config(const char *var, const char *value, void *cb)
+static int git_stash_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "stash.showstat")) {
show_stat = git_config_bool(var, value);
@@ -851,7 +856,7 @@ static int git_stash_config(const char *var, const char *value, void *cb)
show_include_untracked = git_config_bool(var, value);
return 0;
}
- return git_diff_basic_config(var, value, cb);
+ return git_diff_basic_config(var, value, ctx, cb);
}
static void diff_include_untracked(const struct stash_info *info, struct diff_options *diff_opt)
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index 9451eb69ff..7b700a9fb1 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -1,6 +1,6 @@
#include "builtin.h"
-#include "cache.h"
#include "config.h"
+#include "environment.h"
#include "gettext.h"
#include "parse-options.h"
#include "setup.h"
@@ -13,7 +13,7 @@ static void comment_lines(struct strbuf *buf)
size_t len;
msg = strbuf_detach(buf, &len);
- strbuf_add_commented_lines(buf, msg, len);
+ strbuf_add_commented_lines(buf, msg, len, comment_line_char);
free(msg);
}
@@ -58,7 +58,8 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
die_errno("could not read the input");
if (mode == STRIP_DEFAULT || mode == STRIP_COMMENTS)
- strbuf_stripspace(&buf, mode == STRIP_COMMENTS);
+ strbuf_stripspace(&buf,
+ mode == STRIP_COMMENTS ? comment_line_char : '\0');
else
comment_lines(&buf);
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 6bf8d666ce..f6871efd95 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1,18 +1,20 @@
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "abspath.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
#include "repository.h"
-#include "cache.h"
#include "config.h"
#include "parse-options.h"
#include "quote.h"
+#include "path.h"
#include "pathspec.h"
+#include "preload-index.h"
#include "dir.h"
+#include "read-cache.h"
#include "setup.h"
+#include "sparse-index.h"
#include "submodule.h"
#include "submodule-config.h"
#include "string-list.h"
@@ -26,7 +28,7 @@
#include "diff.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "advice.h"
#include "branch.h"
#include "list-objects-filter-options.h"
@@ -2024,14 +2026,17 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
strbuf_reset(&sb);
strbuf_addf(&sb, "submodule.%s.url", sub->name);
if (repo_config_get_string_tmp(the_repository, sb.buf, &url)) {
- if (starts_with_dot_slash(sub->url) ||
- starts_with_dot_dot_slash(sub->url)) {
+ if (sub->url && (starts_with_dot_slash(sub->url) ||
+ starts_with_dot_dot_slash(sub->url))) {
url = resolve_relative_url(sub->url, NULL, 0);
need_free_url = 1;
} else
url = sub->url;
}
+ if (!url)
+ die(_("cannot clone submodule '%s' without a URL"), sub->name);
+
strbuf_reset(&sb);
strbuf_addf(&sb, "%s/.git", ce->name);
needs_cloning = !file_exists(sb.buf);
@@ -2189,12 +2194,13 @@ static int update_clone_task_finished(int result,
}
static int git_update_clone_config(const char *var, const char *value,
+ const struct config_context *ctx,
void *cb)
{
int *max_jobs = cb;
if (!strcmp(var, "submodule.fetchjobs"))
- *max_jobs = parse_submodule_fetchjobs(var, value);
+ *max_jobs = parse_submodule_fetchjobs(var, value, ctx->kvi);
return 0;
}
diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index 10198a74fa..c9defe4d2e 100644
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
@@ -1,9 +1,9 @@
#include "builtin.h"
#include "config.h"
-#include "cache.h"
#include "gettext.h"
#include "refs.h"
#include "parse-options.h"
+#include "strbuf.h"
static const char * const git_symbolic_ref_usage[] = {
N_("git symbolic-ref [-m <reason>] <name> <ref>"),
diff --git a/builtin/tag.c b/builtin/tag.c
index 1850a6a6fd..3918eacbb5 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -6,17 +6,17 @@
* Based on git-tag.sh and mktag.c by Linus Torvalds.
*/
-#include "cache.h"
+#include "builtin.h"
#include "advice.h"
#include "config.h"
-#include "builtin.h"
#include "editor.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
#include "refs.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "path.h"
#include "tag.h"
#include "run-command.h"
#include "parse-options.h"
@@ -121,7 +121,7 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
return had_error;
}
-static int collect_tags(const char *name, const char *ref,
+static int collect_tags(const char *name UNUSED, const char *ref,
const struct object_id *oid, void *cb_data)
{
struct string_list *ref_list = cb_data;
@@ -155,7 +155,7 @@ static int delete_tags(const char **argv)
return result;
}
-static int verify_tag(const char *name, const char *ref,
+static int verify_tag(const char *name, const char *ref UNUSED,
const struct object_id *oid, void *cb_data)
{
int flags;
@@ -188,7 +188,8 @@ static const char tag_template_nocleanup[] =
"Lines starting with '%c' will be kept; you may remove them"
" yourself if you want to.\n");
-static int git_tag_config(const char *var, const char *value, void *cb)
+static int git_tag_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "tag.gpgsign")) {
config_sign_tag = git_config_bool(var, value);
@@ -209,7 +210,11 @@ static int git_tag_config(const char *var, const char *value, void *cb)
if (starts_with(var, "column."))
return git_column_config(var, value, "tag", &colopts);
- return git_color_default_config(var, value, cb);
+
+ if (git_color_config(var, value, cb) < 0)
+ return -1;
+
+ return git_default_config(var, value, ctx, cb);
}
static void write_tag_body(int fd, const struct object_id *oid)
@@ -271,11 +276,10 @@ static const char message_advice_nested_tag[] =
static void create_tag(const struct object_id *object, const char *object_ref,
const char *tag,
struct strbuf *buf, struct create_tag_options *opt,
- struct object_id *prev, struct object_id *result)
+ struct object_id *prev, struct object_id *result, char *path)
{
enum object_type type;
struct strbuf header = STRBUF_INIT;
- char *path = NULL;
type = oid_object_info(the_repository, object, NULL);
if (type <= OBJ_NONE)
@@ -299,7 +303,6 @@ static void create_tag(const struct object_id *object, const char *object_ref,
int fd;
/* write the template message before editing: */
- path = git_pathdup("TAG_EDITMSG");
fd = xopen(path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
if (opt->message_given) {
@@ -311,9 +314,11 @@ static void create_tag(const struct object_id *object, const char *object_ref,
struct strbuf buf = STRBUF_INIT;
strbuf_addch(&buf, '\n');
if (opt->cleanup_mode == CLEANUP_ALL)
- strbuf_commented_addf(&buf, _(tag_template), tag, comment_line_char);
+ strbuf_commented_addf(&buf, comment_line_char,
+ _(tag_template), tag, comment_line_char);
else
- strbuf_commented_addf(&buf, _(tag_template_nocleanup), tag, comment_line_char);
+ strbuf_commented_addf(&buf, comment_line_char,
+ _(tag_template_nocleanup), tag, comment_line_char);
write_or_die(fd, buf.buf, buf.len);
strbuf_release(&buf);
}
@@ -327,7 +332,8 @@ static void create_tag(const struct object_id *object, const char *object_ref,
}
if (opt->cleanup_mode != CLEANUP_NONE)
- strbuf_stripspace(buf, opt->cleanup_mode == CLEANUP_ALL);
+ strbuf_stripspace(buf,
+ opt->cleanup_mode == CLEANUP_ALL ? comment_line_char : '\0');
if (!opt->message_given && !buf->len)
die(_("no tag message?"));
@@ -341,10 +347,6 @@ static void create_tag(const struct object_id *object, const char *object_ref,
path);
exit(128);
}
- if (path) {
- unlink_or_warn(path);
- free(path);
- }
}
static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
@@ -443,7 +445,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
struct msg_arg msg = { .buf = STRBUF_INIT };
struct ref_transaction *transaction;
struct strbuf err = STRBUF_INIT;
- struct ref_filter filter;
+ struct ref_filter filter = REF_FILTER_INIT;
struct ref_sorting *sorting;
struct string_list sorting_options = STRING_LIST_INIT_DUP;
struct ref_format format = REF_FORMAT_INIT;
@@ -495,13 +497,13 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
};
int ret = 0;
const char *only_in_list = NULL;
+ char *path = NULL;
setup_ref_filter_porcelain_msg();
git_config(git_tag_config, &sorting_options);
memset(&opt, 0, sizeof(opt));
- memset(&filter, 0, sizeof(filter));
filter.lines = -1;
opt.sign = -1;
@@ -629,7 +631,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
if (create_tag_object) {
if (force_sign_annotate && !annotate)
opt.sign = 1;
- create_tag(&object, object_ref, tag, &buf, &opt, &prev, &object);
+ path = git_pathdup("TAG_EDITMSG");
+ create_tag(&object, object_ref, tag, &buf, &opt, &prev, &object,
+ path);
}
transaction = ref_transaction_begin(&err);
@@ -637,8 +641,17 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
ref_transaction_update(transaction, ref.buf, &object, &prev,
create_reflog ? REF_FORCE_CREATE_REFLOG : 0,
reflog_msg.buf, &err) ||
- ref_transaction_commit(transaction, &err))
+ ref_transaction_commit(transaction, &err)) {
+ if (path)
+ fprintf(stderr,
+ _("The tag message has been left in %s\n"),
+ path);
die("%s", err.buf);
+ }
+ if (path) {
+ unlink_or_warn(path);
+ free(path);
+ }
ref_transaction_free(transaction);
if (force && !is_null_oid(&prev) && !oideq(&prev, &object))
printf(_("Updated tag '%s' (was %s)\n"), tag,
@@ -646,6 +659,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
cleanup:
ref_sorting_release(sorting);
+ ref_filter_clear(&filter);
strbuf_release(&buf);
strbuf_release(&ref);
strbuf_release(&reflog_msg);
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index b35a4b9dfe..c129e2bb6c 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -2,8 +2,7 @@
#include "config.h"
#include "hex.h"
#include "object-name.h"
-#include "object-store.h"
-#include "wrapper.h"
+#include "object-store-ll.h"
static char *create_temp_file(struct object_id *oid)
{
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 2c52c3a741..32505255a0 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -1,18 +1,18 @@
#include "builtin.h"
-#include "cache.h"
#include "bulk-checkin.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
#include "git-zlib.h"
#include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "object.h"
#include "delta.h"
#include "pack.h"
#include "blob.h"
#include "commit.h"
#include "replace-object.h"
+#include "strbuf.h"
#include "tag.h"
#include "tree.h"
#include "tree-walk.h"
@@ -215,7 +215,8 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
* Verify its reachability and validity recursively and write it out.
*/
static int check_object(struct object *obj, enum object_type type,
- void *data, struct fsck_options *options)
+ void *data UNUSED,
+ struct fsck_options *options UNUSED)
{
struct obj_buffer *obj_buf;
@@ -609,7 +610,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
int i;
struct object_id oid;
- read_replace_refs = 0;
+ disable_replace_refs();
git_config(git_default_config, NULL);
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 5fab9ad2ec..aee3cb8cbd 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -4,7 +4,7 @@
* Copyright (C) Linus Torvalds, 2005
*/
#define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "builtin.h"
#include "bulk-checkin.h"
#include "config.h"
#include "environment.h"
@@ -15,15 +15,16 @@
#include "quote.h"
#include "cache-tree.h"
#include "tree-walk.h"
-#include "builtin.h"
#include "object-file.h"
#include "refs.h"
#include "resolve-undo.h"
#include "parse-options.h"
#include "pathspec.h"
#include "dir.h"
+#include "read-cache.h"
#include "repository.h"
#include "setup.h"
+#include "sparse-index.h"
#include "split-index.h"
#include "symlinks.h"
#include "fsmonitor.h"
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 0c59b1c9ef..242102273e 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -1,9 +1,8 @@
-#include "cache.h"
+#include "builtin.h"
#include "config.h"
#include "gettext.h"
#include "hash.h"
#include "refs.h"
-#include "builtin.h"
#include "object-name.h"
#include "parse-options.h"
#include "quote.h"
diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c
index 19dce3c065..1dc3971ede 100644
--- a/builtin/update-server-info.c
+++ b/builtin/update-server-info.c
@@ -1,6 +1,5 @@
-#include "cache.h"
-#include "config.h"
#include "builtin.h"
+#include "config.h"
#include "gettext.h"
#include "parse-options.h"
#include "server-info.h"
diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c
index 44ad400e18..1b09e5e1aa 100644
--- a/builtin/upload-archive.c
+++ b/builtin/upload-archive.c
@@ -1,9 +1,9 @@
/*
* Copyright (c) 2006 Franck Bui-Huu
*/
-#include "cache.h"
#include "builtin.h"
#include "archive.h"
+#include "path.h"
#include "pkt-line.h"
#include "sideband.h"
#include "repository.h"
diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c
index beb9dd0861..9b021ef026 100644
--- a/builtin/upload-pack.c
+++ b/builtin/upload-pack.c
@@ -1,9 +1,9 @@
-#include "cache.h"
#include "builtin.h"
#include "exec-cmd.h"
#include "gettext.h"
#include "pkt-line.h"
#include "parse-options.h"
+#include "path.h"
#include "protocol.h"
#include "replace-object.h"
#include "upload-pack.h"
@@ -36,7 +36,7 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix)
};
packet_trace_identity("upload-pack");
- read_replace_refs = 0;
+ disable_replace_refs();
argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0);
diff --git a/builtin/var.c b/builtin/var.c
index 2149998980..74161bdf1c 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -4,60 +4,188 @@
* Copyright (C) Eric Biederman, 2005
*/
#include "builtin.h"
+#include "attr.h"
#include "config.h"
#include "editor.h"
#include "ident.h"
#include "pager.h"
#include "refs.h"
+#include "path.h"
+#include "strbuf.h"
static const char var_usage[] = "git var (-l | <variable>)";
-static const char *editor(int flag)
+static char *committer(int ident_flag)
{
- return git_editor();
+ return xstrdup_or_null(git_committer_info(ident_flag));
}
-static const char *sequence_editor(int flag)
+static char *author(int ident_flag)
{
- return git_sequence_editor();
+ return xstrdup_or_null(git_author_info(ident_flag));
}
-static const char *pager(int flag)
+static char *editor(int ident_flag UNUSED)
+{
+ return xstrdup_or_null(git_editor());
+}
+
+static char *sequence_editor(int ident_flag UNUSED)
+{
+ return xstrdup_or_null(git_sequence_editor());
+}
+
+static char *pager(int ident_flag UNUSED)
{
const char *pgm = git_pager(1);
if (!pgm)
pgm = "cat";
- return pgm;
+ return xstrdup(pgm);
+}
+
+static char *default_branch(int ident_flag UNUSED)
+{
+ return xstrdup_or_null(git_default_branch_name(1));
+}
+
+static char *shell_path(int ident_flag UNUSED)
+{
+ return xstrdup(SHELL_PATH);
}
-static const char *default_branch(int flag)
+static char *git_attr_val_system(int ident_flag UNUSED)
{
- return git_default_branch_name(1);
+ if (git_attr_system_is_enabled()) {
+ char *file = xstrdup(git_attr_system_file());
+ normalize_path_copy(file, file);
+ return file;
+ }
+ return NULL;
+}
+
+static char *git_attr_val_global(int ident_flag UNUSED)
+{
+ char *file = xstrdup(git_attr_global_file());
+ if (file) {
+ normalize_path_copy(file, file);
+ return file;
+ }
+ return NULL;
+}
+
+static char *git_config_val_system(int ident_flag UNUSED)
+{
+ if (git_config_system()) {
+ char *file = git_system_config();
+ normalize_path_copy(file, file);
+ return file;
+ }
+ return NULL;
+}
+
+static char *git_config_val_global(int ident_flag UNUSED)
+{
+ struct strbuf buf = STRBUF_INIT;
+ char *user, *xdg;
+ size_t unused;
+
+ git_global_config(&user, &xdg);
+ if (xdg && *xdg) {
+ normalize_path_copy(xdg, xdg);
+ strbuf_addf(&buf, "%s\n", xdg);
+ }
+ if (user && *user) {
+ normalize_path_copy(user, user);
+ strbuf_addf(&buf, "%s\n", user);
+ }
+ free(xdg);
+ free(user);
+ strbuf_trim_trailing_newline(&buf);
+ if (buf.len == 0) {
+ strbuf_release(&buf);
+ return NULL;
+ }
+ return strbuf_detach(&buf, &unused);
}
struct git_var {
const char *name;
- const char *(*read)(int);
+ char *(*read)(int);
+ int multivalued;
};
static struct git_var git_vars[] = {
- { "GIT_COMMITTER_IDENT", git_committer_info },
- { "GIT_AUTHOR_IDENT", git_author_info },
- { "GIT_EDITOR", editor },
- { "GIT_SEQUENCE_EDITOR", sequence_editor },
- { "GIT_PAGER", pager },
- { "GIT_DEFAULT_BRANCH", default_branch },
- { "", NULL },
+ {
+ .name = "GIT_COMMITTER_IDENT",
+ .read = committer,
+ },
+ {
+ .name = "GIT_AUTHOR_IDENT",
+ .read = author,
+ },
+ {
+ .name = "GIT_EDITOR",
+ .read = editor,
+ },
+ {
+ .name = "GIT_SEQUENCE_EDITOR",
+ .read = sequence_editor,
+ },
+ {
+ .name = "GIT_PAGER",
+ .read = pager,
+ },
+ {
+ .name = "GIT_DEFAULT_BRANCH",
+ .read = default_branch,
+ },
+ {
+ .name = "GIT_SHELL_PATH",
+ .read = shell_path,
+ },
+ {
+ .name = "GIT_ATTR_SYSTEM",
+ .read = git_attr_val_system,
+ },
+ {
+ .name = "GIT_ATTR_GLOBAL",
+ .read = git_attr_val_global,
+ },
+ {
+ .name = "GIT_CONFIG_SYSTEM",
+ .read = git_config_val_system,
+ },
+ {
+ .name = "GIT_CONFIG_GLOBAL",
+ .read = git_config_val_global,
+ .multivalued = 1,
+ },
+ {
+ .name = "",
+ .read = NULL,
+ },
};
static void list_vars(void)
{
struct git_var *ptr;
- const char *val;
+ char *val;
for (ptr = git_vars; ptr->read; ptr++)
- if ((val = ptr->read(0)))
- printf("%s=%s\n", ptr->name, val);
+ if ((val = ptr->read(0))) {
+ if (ptr->multivalued && *val) {
+ struct string_list list = STRING_LIST_INIT_DUP;
+ int i;
+
+ string_list_split(&list, val, '\n', -1);
+ for (i = 0; i < list.nr; i++)
+ printf("%s=%s\n", ptr->name, list.items[i].string);
+ string_list_clear(&list, 0);
+ } else {
+ printf("%s=%s\n", ptr->name, val);
+ }
+ free(val);
+ }
}
static const struct git_var *get_git_var(const char *var)
@@ -71,19 +199,20 @@ static const struct git_var *get_git_var(const char *var)
return NULL;
}
-static int show_config(const char *var, const char *value, void *cb)
+static int show_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (value)
printf("%s=%s\n", var, value);
else
printf("%s\n", var);
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
int cmd_var(int argc, const char **argv, const char *prefix UNUSED)
{
const struct git_var *git_var;
- const char *val;
+ char *val;
if (argc != 2)
usage(var_usage);
@@ -104,6 +233,7 @@ int cmd_var(int argc, const char **argv, const char *prefix UNUSED)
return 1;
printf("%s\n", val);
+ free(val);
return 0;
}
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index 5d99b82a64..9680b58701 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -5,12 +5,11 @@
*
* Based on git-verify-tag
*/
-#include "cache.h"
-#include "config.h"
#include "builtin.h"
+#include "config.h"
#include "gettext.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "repository.h"
#include "commit.h"
#include "run-command.h"
diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c
index 190fd69540..011dddd2dc 100644
--- a/builtin/verify-pack.c
+++ b/builtin/verify-pack.c
@@ -1,9 +1,9 @@
#include "builtin.h"
-#include "cache.h"
#include "config.h"
#include "gettext.h"
#include "run-command.h"
#include "parse-options.h"
+#include "strbuf.h"
#define VERIFY_PACK_VERBOSE 01
#define VERIFY_PACK_STAT_ONLY 02
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index c6019a0ad8..d8753270eb 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -5,9 +5,8 @@
*
* Based on git-verify-tag.sh
*/
-#include "cache.h"
-#include "config.h"
#include "builtin.h"
+#include "config.h"
#include "gettext.h"
#include "tag.h"
#include "run-command.h"
diff --git a/builtin/worktree.c b/builtin/worktree.c
index f3180463be..4cd01842de 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -1,9 +1,9 @@
-#include "cache.h"
+#include "builtin.h"
#include "abspath.h"
+#include "advice.h"
#include "checkout.h"
#include "config.h"
#include "copy.h"
-#include "builtin.h"
#include "dir.h"
#include "environment.h"
#include "gettext.h"
@@ -11,9 +11,12 @@
#include "object-file.h"
#include "object-name.h"
#include "parse-options.h"
+#include "path.h"
#include "strvec.h"
#include "branch.h"
+#include "read-cache-ll.h"
#include "refs.h"
+#include "remote.h"
#include "repository.h"
#include "run-command.h"
#include "hook.h"
@@ -21,12 +24,12 @@
#include "submodule.h"
#include "utf8.h"
#include "worktree.h"
-#include "wrapper.h"
#include "quote.h"
#define BUILTIN_WORKTREE_ADD_USAGE \
N_("git worktree add [-f] [--detach] [--checkout] [--lock [--reason <string>]]\n" \
- " [-b <new-branch>] <path> [<commit-ish>]")
+ " [--orphan] [(-b | -B) <new-branch>] <path> [<commit-ish>]")
+
#define BUILTIN_WORKTREE_LIST_USAGE \
N_("git worktree list [-v | --porcelain [-z]]")
#define BUILTIN_WORKTREE_LOCK_USAGE \
@@ -42,6 +45,23 @@
#define BUILTIN_WORKTREE_UNLOCK_USAGE \
N_("git worktree unlock <worktree>")
+#define WORKTREE_ADD_DWIM_ORPHAN_INFER_TEXT \
+ _("No possible source branch, inferring '--orphan'")
+
+#define WORKTREE_ADD_ORPHAN_WITH_DASH_B_HINT_TEXT \
+ _("If you meant to create a worktree containing a new orphan branch\n" \
+ "(branch with no commits) for this repository, you can do so\n" \
+ "using the --orphan flag:\n" \
+ "\n" \
+ " git worktree add --orphan -b %s %s\n")
+
+#define WORKTREE_ADD_ORPHAN_NO_DASH_B_HINT_TEXT \
+ _("If you meant to create a worktree containing a new orphan branch\n" \
+ "(branch with no commits) for this repository, you can do so\n" \
+ "using the --orphan flag:\n" \
+ "\n" \
+ " git worktree add --orphan %s\n")
+
static const char * const git_worktree_usage[] = {
BUILTIN_WORKTREE_ADD_USAGE,
BUILTIN_WORKTREE_LIST_USAGE,
@@ -99,6 +119,7 @@ struct add_opts {
int detach;
int quiet;
int checkout;
+ int orphan;
const char *keep_locked;
};
@@ -107,14 +128,15 @@ static int verbose;
static int guess_remote;
static timestamp_t expire;
-static int git_worktree_config(const char *var, const char *value, void *cb)
+static int git_worktree_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "worktree.guessremote")) {
guess_remote = git_config_bool(var, value);
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static int delete_git_dir(const char *id)
@@ -372,6 +394,22 @@ static int checkout_worktree(const struct add_opts *opts,
return run_command(&cp);
}
+static int make_worktree_orphan(const char * ref, const struct add_opts *opts,
+ struct strvec *child_env)
+{
+ struct strbuf symref = STRBUF_INIT;
+ struct child_process cp = CHILD_PROCESS_INIT;
+
+ validate_new_branchname(ref, &symref, 0);
+ strvec_pushl(&cp.args, "symbolic-ref", "HEAD", symref.buf, NULL);
+ if (opts->quiet)
+ strvec_push(&cp.args, "--quiet");
+ strvec_pushv(&cp.env, child_env->v);
+ strbuf_release(&symref);
+ cp.git_cmd = 1;
+ return run_command(&cp);
+}
+
static int add_worktree(const char *path, const char *refname,
const struct add_opts *opts)
{
@@ -401,7 +439,7 @@ static int add_worktree(const char *path, const char *refname,
die_if_checked_out(symref.buf, 0);
}
commit = lookup_commit_reference_by_name(refname);
- if (!commit)
+ if (!commit && !opts->orphan)
die(_("invalid reference: %s"), refname);
name = worktree_basename(path, &len);
@@ -483,17 +521,17 @@ static int add_worktree(const char *path, const char *refname,
* values from the current worktree into the new one, that way the
* new worktree behaves the same as this one.
*/
- if (repository_format_worktree_config)
+ if (the_repository->repository_format_worktree_config)
copy_filtered_worktree_config(sb_repo.buf);
strvec_pushf(&child_env, "%s=%s", GIT_DIR_ENVIRONMENT, sb_git.buf);
strvec_pushf(&child_env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT, path);
cp.git_cmd = 1;
- if (!is_branch)
+ if (!is_branch && commit) {
strvec_pushl(&cp.args, "update-ref", "HEAD",
oid_to_hex(&commit->object.oid), NULL);
- else {
+ } else {
strvec_pushl(&cp.args, "symbolic-ref", "HEAD",
symref.buf, NULL);
if (opts->quiet)
@@ -505,6 +543,10 @@ static int add_worktree(const char *path, const char *refname,
if (ret)
goto done;
+ if (opts->orphan &&
+ (ret = make_worktree_orphan(refname, opts, &child_env)))
+ goto done;
+
if (opts->checkout &&
(ret = checkout_worktree(opts, &child_env)))
goto done;
@@ -524,7 +566,7 @@ done:
* Hook failure does not warrant worktree deletion, so run hook after
* is_junk is cleared, but do return appropriate code when hook fails.
*/
- if (!ret && opts->checkout) {
+ if (!ret && opts->checkout && !opts->orphan) {
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
strvec_pushl(&opt.env, "GIT_DIR", "GIT_WORK_TREE", NULL);
@@ -572,7 +614,7 @@ static void print_preparing_worktree_line(int detach,
else {
struct commit *commit = lookup_commit_reference_by_name(branch);
if (!commit)
- die(_("invalid reference: %s"), branch);
+ BUG(_("unreachable: invalid reference: %s"), branch);
fprintf_ln(stderr, _("Preparing worktree (detached HEAD %s)"),
repo_find_unique_abbrev(the_repository, &commit->object.oid, DEFAULT_ABBREV));
}
@@ -580,6 +622,123 @@ static void print_preparing_worktree_line(int detach,
}
}
+/**
+ * Callback to short circuit iteration over refs on the first reference
+ * corresponding to a valid oid.
+ *
+ * Returns 0 on failure and non-zero on success.
+ */
+static int first_valid_ref(const char *refname,
+ const struct object_id *oid,
+ int flags,
+ void *cb_data)
+{
+ return 1;
+}
+
+/**
+ * Verifies HEAD and determines whether there exist any valid local references.
+ *
+ * - Checks whether HEAD points to a valid reference.
+ *
+ * - Checks whether any valid local branches exist.
+ *
+ * - Emits a warning if there exist any valid branches but HEAD does not point
+ * to a valid reference.
+ *
+ * Returns 1 if any of the previous checks are true, otherwise returns 0.
+ */
+static int can_use_local_refs(const struct add_opts *opts)
+{
+ if (head_ref(first_valid_ref, NULL)) {
+ return 1;
+ } else if (for_each_branch_ref(first_valid_ref, NULL)) {
+ if (!opts->quiet) {
+ struct strbuf path = STRBUF_INIT;
+ struct strbuf contents = STRBUF_INIT;
+
+ strbuf_add_real_path(&path, get_worktree_git_dir(NULL));
+ strbuf_addstr(&path, "/HEAD");
+ strbuf_read_file(&contents, path.buf, 64);
+ strbuf_stripspace(&contents, 0);
+ strbuf_strip_suffix(&contents, "\n");
+
+ warning(_("HEAD points to an invalid (or orphaned) reference.\n"
+ "HEAD path: '%s'\n"
+ "HEAD contents: '%s'"),
+ path.buf, contents.buf);
+ strbuf_release(&path);
+ strbuf_release(&contents);
+ }
+ return 1;
+ }
+ return 0;
+}
+
+/**
+ * Reports whether the necessary flags were set and whether the repository has
+ * remote references to attempt DWIM tracking of upstream branches.
+ *
+ * 1. Checks that `--guess-remote` was used or `worktree.guessRemote = true`.
+ *
+ * 2. Checks whether any valid remote branches exist.
+ *
+ * 3. Checks that there exists at least one remote and emits a warning/error
+ * if both checks 1. and 2. are false (can be bypassed with `--force`).
+ *
+ * Returns 1 if checks 1. and 2. are true, otherwise 0.
+ */
+static int can_use_remote_refs(const struct add_opts *opts)
+{
+ if (!guess_remote) {
+ return 0;
+ } else if (for_each_remote_ref(first_valid_ref, NULL)) {
+ return 1;
+ } else if (!opts->force && remote_get(NULL)) {
+ die(_("No local or remote refs exist despite at least one remote\n"
+ "present, stopping; use 'add -f' to overide or fetch a remote first"));
+ }
+ return 0;
+}
+
+/**
+ * Determines whether `--orphan` should be inferred in the evaluation of
+ * `worktree add path/` or `worktree add -b branch path/` and emits an error
+ * if the supplied arguments would produce an illegal combination when the
+ * `--orphan` flag is included.
+ *
+ * `opts` and `opt_track` contain the other options & flags supplied to the
+ * command.
+ *
+ * remote determines whether to check `can_use_remote_refs()` or not. This
+ * is primarily to differentiate between the basic `add` DWIM and `add -b`.
+ *
+ * Returns 1 when inferring `--orphan`, 0 otherwise, and emits an error when
+ * `--orphan` is inferred but doing so produces an illegal combination of
+ * options and flags. Additionally produces an error when remote refs are
+ * checked and the repo is in a state that looks like the user added a remote
+ * but forgot to fetch (and did not override the warning with -f).
+ */
+static int dwim_orphan(const struct add_opts *opts, int opt_track, int remote)
+{
+ if (can_use_local_refs(opts)) {
+ return 0;
+ } else if (remote && can_use_remote_refs(opts)) {
+ return 0;
+ } else if (!opts->quiet) {
+ fprintf_ln(stderr, WORKTREE_ADD_DWIM_ORPHAN_INFER_TEXT);
+ }
+
+ if (opt_track) {
+ die(_("'%s' and '%s' cannot be used together"), "--orphan",
+ "--track");
+ } else if (!opts->checkout) {
+ die(_("'%s' and '%s' cannot be used together"), "--orphan",
+ "--no-checkout");
+ }
+ return 1;
+}
+
static const char *dwim_branch(const char *path, const char **new_branch)
{
int n;
@@ -616,6 +775,7 @@ static int add(int ac, const char **av, const char *prefix)
const char *opt_track = NULL;
const char *lock_reason = NULL;
int keep_locked = 0;
+ int used_new_branch_options;
struct option options[] = {
OPT__FORCE(&opts.force,
N_("checkout <branch> even if already checked out in other worktree"),
@@ -624,6 +784,7 @@ static int add(int ac, const char **av, const char *prefix)
N_("create a new branch")),
OPT_STRING('B', NULL, &new_branch_force, N_("branch"),
N_("create or reset a branch")),
+ OPT_BOOL(0, "orphan", &opts.orphan, N_("create unborn/orphaned branch")),
OPT_BOOL('d', "detach", &opts.detach, N_("detach HEAD at named commit")),
OPT_BOOL(0, "checkout", &opts.checkout, N_("populate the new working tree")),
OPT_BOOL(0, "lock", &keep_locked, N_("keep the new working tree locked")),
@@ -644,6 +805,17 @@ static int add(int ac, const char **av, const char *prefix)
ac = parse_options(ac, av, prefix, options, git_worktree_add_usage, 0);
if (!!opts.detach + !!new_branch + !!new_branch_force > 1)
die(_("options '%s', '%s', and '%s' cannot be used together"), "-b", "-B", "--detach");
+ if (opts.detach && opts.orphan)
+ die(_("options '%s', and '%s' cannot be used together"),
+ "--orphan", "--detach");
+ if (opts.orphan && opt_track)
+ die(_("'%s' and '%s' cannot be used together"), "--orphan", "--track");
+ if (opts.orphan && !opts.checkout)
+ die(_("'%s' and '%s' cannot be used together"), "--orphan",
+ "--no-checkout");
+ if (opts.orphan && ac == 2)
+ die(_("'%s' and '%s' cannot be used together"), "--orphan",
+ _("<commit-ish>"));
if (lock_reason && !keep_locked)
die(_("the option '%s' requires '%s'"), "--reason", "--lock");
if (lock_reason)
@@ -656,6 +828,7 @@ static int add(int ac, const char **av, const char *prefix)
path = prefix_filename(prefix, av[0]);
branch = ac < 2 ? "HEAD" : av[1];
+ used_new_branch_options = new_branch || new_branch_force;
if (!strcmp(branch, "-"))
branch = "@{-1}";
@@ -672,13 +845,28 @@ static int add(int ac, const char **av, const char *prefix)
strbuf_release(&symref);
}
- if (ac < 2 && !new_branch && !opts.detach) {
+ if (opts.orphan && !new_branch) {
+ int n;
+ const char *s = worktree_basename(path, &n);
+ new_branch = xstrndup(s, n);
+ } else if (opts.orphan) {
+ // No-op
+ } else if (opts.detach) {
+ // Check HEAD
+ if (!strcmp(branch, "HEAD"))
+ can_use_local_refs(&opts);
+ } else if (ac < 2 && new_branch) {
+ // DWIM: Infer --orphan when repo has no refs.
+ opts.orphan = dwim_orphan(&opts, !!opt_track, 0);
+ } else if (ac < 2) {
+ // DWIM: Guess branch name from path.
const char *s = dwim_branch(path, &new_branch);
if (s)
branch = s;
- }
- if (ac == 2 && !new_branch && !opts.detach) {
+ // DWIM: Infer --orphan when repo has no refs.
+ opts.orphan = (!s) && dwim_orphan(&opts, !!opt_track, 1);
+ } else if (ac == 2) {
struct object_id oid;
struct commit *commit;
const char *remote;
@@ -691,11 +879,31 @@ static int add(int ac, const char **av, const char *prefix)
branch = remote;
}
}
+
+ if (!strcmp(branch, "HEAD"))
+ can_use_local_refs(&opts);
+
+ }
+
+ if (!opts.orphan && !lookup_commit_reference_by_name(branch)) {
+ int attempt_hint = !opts.quiet && (ac < 2);
+ if (attempt_hint && used_new_branch_options) {
+ advise_if_enabled(ADVICE_WORKTREE_ADD_ORPHAN,
+ WORKTREE_ADD_ORPHAN_WITH_DASH_B_HINT_TEXT,
+ new_branch, path);
+ } else if (attempt_hint) {
+ advise_if_enabled(ADVICE_WORKTREE_ADD_ORPHAN,
+ WORKTREE_ADD_ORPHAN_NO_DASH_B_HINT_TEXT, path);
+ }
+ die(_("invalid reference: %s"), branch);
}
+
if (!opts.quiet)
print_preparing_worktree_line(opts.detach, branch, new_branch, !!new_branch_force);
- if (new_branch) {
+ if (opts.orphan) {
+ branch = new_branch;
+ } else if (new_branch) {
struct child_process cp = CHILD_PROCESS_INIT;
cp.git_cmd = 1;
strvec_push(&cp.args, "branch");
@@ -1200,5 +1408,9 @@ int cmd_worktree(int ac, const char **av, const char *prefix)
prefix = "";
ac = parse_options(ac, av, prefix, options, git_worktree_usage, 0);
+
+ prepare_repo_settings(the_repository);
+ the_repository->settings.command_requires_full_index = 0;
+
return fn(ac, av, prefix);
}
diff --git a/builtin/write-tree.c b/builtin/write-tree.c
index 84b83318c9..66e83d0ecb 100644
--- a/builtin/write-tree.c
+++ b/builtin/write-tree.c
@@ -5,7 +5,6 @@
*/
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
-#include "cache.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
diff --git a/bulk-checkin.c b/bulk-checkin.c
index d843279715..73bff3a23d 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -2,7 +2,6 @@
* Copyright (c) 2011, Google Inc.
*/
#include "git-compat-util.h"
-#include "alloc.h"
#include "bulk-checkin.h"
#include "environment.h"
#include "gettext.h"
@@ -16,8 +15,7 @@
#include "tmp-objdir.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
-#include "wrapper.h"
+#include "object-store-ll.h"
static int odb_transaction_nesting;
diff --git a/bundle-uri.c b/bundle-uri.c
index 2a2db1a1d3..4b5c49b93d 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -4,7 +4,7 @@
#include "copy.h"
#include "environment.h"
#include "gettext.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "refs.h"
#include "run-command.h"
#include "hashmap.h"
@@ -224,7 +224,9 @@ static int bundle_list_update(const char *key, const char *value,
return 0;
}
-static int config_to_bundle_list(const char *key, const char *value, void *data)
+static int config_to_bundle_list(const char *key, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *data)
{
struct bundle_list *list = data;
return bundle_list_update(key, value, list);
@@ -253,6 +255,7 @@ int bundle_uri_parse_config_format(const char *uri,
}
result = git_config_from_file_with_options(config_to_bundle_list,
filename, list,
+ CONFIG_SCOPE_UNKNOWN,
&opts);
if (!result && list->mode == BUNDLE_MODE_NONE) {
@@ -871,7 +874,9 @@ cached:
return advertise_bundle_uri;
}
-static int config_to_packet_line(const char *key, const char *value, void *data)
+static int config_to_packet_line(const char *key, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *data)
{
struct packet_reader *writer = data;
diff --git a/bundle.c b/bundle.c
index a5505368de..a9744da255 100644
--- a/bundle.c
+++ b/bundle.c
@@ -4,7 +4,7 @@
#include "environment.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "repository.h"
#include "object.h"
#include "commit.h"
@@ -271,10 +271,10 @@ int verify_bundle(struct repository *r,
list_refs(r, 0, NULL);
}
- printf_ln("The bundle uses this hash algorithm: %s",
+ printf_ln(_("The bundle uses this hash algorithm: %s"),
header->hash_algo->name);
if (header->filter.choice)
- printf_ln("The bundle uses this filter: %s",
+ printf_ln(_("The bundle uses this filter: %s"),
list_objects_filter_spec(&header->filter));
}
cleanup:
diff --git a/cache-tree.c b/cache-tree.c
index ebfe649b33..641427ed41 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -1,5 +1,4 @@
-#include "cache.h"
-#include "alloc.h"
+#include "git-compat-util.h"
#include "environment.h"
#include "hex.h"
#include "lockfile.h"
@@ -8,7 +7,8 @@
#include "cache-tree.h"
#include "bulk-checkin.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "read-cache-ll.h"
#include "replace-object.h"
#include "promisor-remote.h"
#include "sparse-index.h"
diff --git a/chunk-format.c b/chunk-format.c
index e7d613c907..140dfa0dcc 100644
--- a/chunk-format.c
+++ b/chunk-format.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "chunk-format.h"
#include "csum-file.h"
#include "gettext.h"
diff --git a/ci/lib.sh b/ci/lib.sh
index db7105e8a8..369d462f13 100755
--- a/ci/lib.sh
+++ b/ci/lib.sh
@@ -278,11 +278,8 @@ linux-leaks)
export GIT_TEST_PASSING_SANITIZE_LEAK=true
export GIT_TEST_SANITIZE_LEAK_LOG=true
;;
-linux-asan)
- export SANITIZE=address
- ;;
-linux-ubsan)
- export SANITIZE=undefined
+linux-asan-ubsan)
+ export SANITIZE=address,undefined
;;
esac
diff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh
index a18b13a41d..2528f25e31 100755
--- a/ci/run-build-and-tests.sh
+++ b/ci/run-build-and-tests.sh
@@ -29,6 +29,7 @@ linux-TEST-vars)
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
export GIT_TEST_NO_WRITE_REV_INDEX=1
export GIT_TEST_CHECKOUT_WORKERS=2
+ export GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL=1
;;
linux-clang)
export GIT_TEST_DEFAULT_HASH=sha1
diff --git a/color.c b/color.c
index 83abb11eda..b24b19566b 100644
--- a/color.c
+++ b/color.c
@@ -430,14 +430,6 @@ int git_color_config(const char *var, const char *value, void *cb UNUSED)
return 0;
}
-int git_color_default_config(const char *var, const char *value, void *cb)
-{
- if (git_color_config(var, value, cb) < 0)
- return -1;
-
- return git_default_config(var, value, cb);
-}
-
void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb)
{
if (*color)
diff --git a/color.h b/color.h
index cfc8f841b2..bb28343be2 100644
--- a/color.h
+++ b/color.h
@@ -88,12 +88,8 @@ extern const int column_colors_ansi_max;
*/
extern int color_stdout_is_tty;
-/*
- * Use the first one if you need only color config; the second is a convenience
- * if you are just going to change to git_default_config, too.
- */
+/* Parse color config. */
int git_color_config(const char *var, const char *value, void *cb);
-int git_color_default_config(const char *var, const char *value, void *cb);
/*
* Parse a config option, which can be a boolean or one of
diff --git a/combine-diff.c b/combine-diff.c
index 1e3cd7fb17..f90f442482 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1,5 +1,5 @@
#include "git-compat-util.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "commit.h"
#include "convert.h"
#include "blob.h"
@@ -17,7 +17,6 @@
#include "userdiff.h"
#include "oid-array.h"
#include "revision.h"
-#include "wrapper.h"
static int compare_paths(const struct combine_diff_path *one,
const struct diff_filespec *two)
diff --git a/commit-graph.c b/commit-graph.c
index 843bdb458d..0aa1640d15 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -12,8 +12,9 @@
#include "hash-lookup.h"
#include "commit-graph.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "oid-array.h"
+#include "path.h"
#include "alloc.h"
#include "hashmap.h"
#include "replace-object.h"
@@ -25,7 +26,6 @@
#include "trace2.h"
#include "tree.h"
#include "chunk-format.h"
-#include "wrapper.h"
void git_test_write_commit_graph_or_die(void)
{
@@ -204,14 +204,12 @@ static struct commit_graph *alloc_commit_graph(void)
return g;
}
-extern int read_replace_refs;
-
static int commit_graph_compatible(struct repository *r)
{
if (!r->gitdir)
return 0;
- if (read_replace_refs) {
+ if (replace_refs_enabled(r)) {
prepare_replace_object(r);
if (hashmap_get_size(&r->objects->replace_map->map))
return 0;
@@ -482,7 +480,7 @@ static int add_graph_to_chain(struct commit_graph *g,
if (!cur_g ||
!oideq(&oids[n], &cur_g->oid) ||
- !hasheq(oids[n].hash, g->chunk_base_graphs + g->hash_len * n)) {
+ !hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_len, n))) {
warning(_("commit-graph chain does not match"));
return 0;
}
@@ -492,8 +490,15 @@ static int add_graph_to_chain(struct commit_graph *g,
g->base_graph = chain;
- if (chain)
+ if (chain) {
+ if (unsigned_add_overflows(chain->num_commits,
+ chain->num_commits_in_base)) {
+ warning(_("commit count in base graph too high: %"PRIuMAX),
+ (uintmax_t)chain->num_commits_in_base);
+ return 0;
+ }
g->num_commits_in_base = chain->num_commits + chain->num_commits_in_base;
+ }
return 1;
}
@@ -747,7 +752,7 @@ static void load_oid_from_graph(struct commit_graph *g,
lex_index = pos - g->num_commits_in_base;
- oidread(oid, g->chunk_oid_lookup + g->hash_len * lex_index);
+ oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_len, lex_index));
}
static struct commit_list **insert_parent_or_die(struct repository *r,
@@ -783,7 +788,7 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
die(_("invalid commit position. commit-graph is likely corrupt"));
lex_index = pos - g->num_commits_in_base;
- commit_data = g->chunk_commit_data + GRAPH_DATA_WIDTH * lex_index;
+ commit_data = g->chunk_commit_data + st_mult(GRAPH_DATA_WIDTH, lex_index);
graph_data = commit_graph_data_at(item);
graph_data->graph_pos = pos;
@@ -793,14 +798,14 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
item->date = (timestamp_t)((date_high << 32) | date_low);
if (g->read_generation_data) {
- offset = (timestamp_t)get_be32(g->chunk_generation_data + sizeof(uint32_t) * lex_index);
+ offset = (timestamp_t)get_be32(g->chunk_generation_data + st_mult(sizeof(uint32_t), lex_index));
if (offset & CORRECTED_COMMIT_DATE_OFFSET_OVERFLOW) {
if (!g->chunk_generation_data_overflow)
die(_("commit-graph requires overflow generation data but has none"));
offset_pos = offset ^ CORRECTED_COMMIT_DATE_OFFSET_OVERFLOW;
- graph_data->generation = item->date + get_be64(g->chunk_generation_data_overflow + 8 * offset_pos);
+ graph_data->generation = item->date + get_be64(g->chunk_generation_data_overflow + st_mult(8, offset_pos));
} else
graph_data->generation = item->date + offset;
} else
@@ -831,7 +836,7 @@ static int fill_commit_in_graph(struct repository *r,
fill_commit_graph_info(item, g, pos);
lex_index = pos - g->num_commits_in_base;
- commit_data = g->chunk_commit_data + (g->hash_len + 16) * lex_index;
+ commit_data = g->chunk_commit_data + st_mult(g->hash_len + 16, lex_index);
item->object.parsed = 1;
@@ -853,7 +858,7 @@ static int fill_commit_in_graph(struct repository *r,
}
parent_data_ptr = (uint32_t*)(g->chunk_extra_edges +
- 4 * (uint64_t)(edge_value & GRAPH_EDGE_LAST_MASK));
+ st_mult(4, edge_value & GRAPH_EDGE_LAST_MASK));
do {
edge_value = get_be32(parent_data_ptr);
pptr = insert_parent_or_die(r, g,
@@ -973,7 +978,7 @@ static struct tree *load_tree_for_commit(struct repository *r,
g = g->base_graph;
commit_data = g->chunk_commit_data +
- GRAPH_DATA_WIDTH * (graph_pos - g->num_commits_in_base);
+ st_mult(GRAPH_DATA_WIDTH, graph_pos - g->num_commits_in_base);
oidread(&oid, commit_data);
set_commit_tree(c, lookup_tree(r, &oid));
@@ -1953,35 +1958,35 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
add_chunk(cf, GRAPH_CHUNKID_OIDFANOUT, GRAPH_FANOUT_SIZE,
write_graph_chunk_fanout);
- add_chunk(cf, GRAPH_CHUNKID_OIDLOOKUP, hashsz * ctx->commits.nr,
+ add_chunk(cf, GRAPH_CHUNKID_OIDLOOKUP, st_mult(hashsz, ctx->commits.nr),
write_graph_chunk_oids);
- add_chunk(cf, GRAPH_CHUNKID_DATA, (hashsz + 16) * ctx->commits.nr,
+ add_chunk(cf, GRAPH_CHUNKID_DATA, st_mult(hashsz + 16, ctx->commits.nr),
write_graph_chunk_data);
if (ctx->write_generation_data)
add_chunk(cf, GRAPH_CHUNKID_GENERATION_DATA,
- sizeof(uint32_t) * ctx->commits.nr,
+ st_mult(sizeof(uint32_t), ctx->commits.nr),
write_graph_chunk_generation_data);
if (ctx->num_generation_data_overflows)
add_chunk(cf, GRAPH_CHUNKID_GENERATION_DATA_OVERFLOW,
- sizeof(timestamp_t) * ctx->num_generation_data_overflows,
+ st_mult(sizeof(timestamp_t), ctx->num_generation_data_overflows),
write_graph_chunk_generation_data_overflow);
if (ctx->num_extra_edges)
add_chunk(cf, GRAPH_CHUNKID_EXTRAEDGES,
- 4 * ctx->num_extra_edges,
+ st_mult(4, ctx->num_extra_edges),
write_graph_chunk_extra_edges);
if (ctx->changed_paths) {
add_chunk(cf, GRAPH_CHUNKID_BLOOMINDEXES,
- sizeof(uint32_t) * ctx->commits.nr,
+ st_mult(sizeof(uint32_t), ctx->commits.nr),
write_graph_chunk_bloom_indexes);
add_chunk(cf, GRAPH_CHUNKID_BLOOMDATA,
- sizeof(uint32_t) * 3
- + ctx->total_bloom_filter_data_size,
+ st_add(sizeof(uint32_t) * 3,
+ ctx->total_bloom_filter_data_size),
write_graph_chunk_bloom_data);
}
if (ctx->num_commit_graphs_after > 1)
add_chunk(cf, GRAPH_CHUNKID_BASE,
- hashsz * (ctx->num_commit_graphs_after - 1),
+ st_mult(hashsz, ctx->num_commit_graphs_after - 1),
write_graph_chunk_base);
hashwrite_be32(f, GRAPH_SIGNATURE);
@@ -1999,7 +2004,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
get_num_chunks(cf));
ctx->progress = start_delayed_progress(
progress_title.buf,
- get_num_chunks(cf) * ctx->commits.nr);
+ st_mult(get_num_chunks(cf), ctx->commits.nr));
}
write_chunkfile(cf, ctx);
@@ -2105,11 +2110,16 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
if (flags != COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED &&
flags != COMMIT_GRAPH_SPLIT_REPLACE) {
- while (g && (g->num_commits <= size_mult * num_commits ||
+ while (g && (g->num_commits <= st_mult(size_mult, num_commits) ||
(max_commits && num_commits > max_commits))) {
if (g->odb != ctx->odb)
break;
+ if (unsigned_add_overflows(num_commits, g->num_commits))
+ die(_("cannot merge graphs with %"PRIuMAX", "
+ "%"PRIuMAX" commits"),
+ (uintmax_t)num_commits,
+ (uintmax_t)g->num_commits);
num_commits += g->num_commits;
g = g->base_graph;
@@ -2167,6 +2177,11 @@ static void merge_commit_graph(struct write_commit_graph_context *ctx,
uint32_t i;
uint32_t offset = g->num_commits_in_base;
+ if (unsigned_add_overflows(ctx->commits.nr, g->num_commits))
+ die(_("cannot merge graph %s, too many commits: %"PRIuMAX),
+ oid_to_hex(&g->oid),
+ (uintmax_t)st_add(ctx->commits.nr, g->num_commits));
+
ALLOC_GROW(ctx->commits.list, ctx->commits.nr + g->num_commits, ctx->commits.alloc);
for (i = 0; i < g->num_commits; i++) {
@@ -2437,7 +2452,7 @@ int write_commit_graph(struct object_directory *odb,
struct commit_graph *g = ctx->r->objects->commit_graph;
for (i = 0; i < g->num_commits; i++) {
struct object_id oid;
- oidread(&oid, g->chunk_oid_lookup + g->hash_len * i);
+ oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
oid_array_append(&ctx->oids, &oid);
}
}
@@ -2543,18 +2558,14 @@ static int commit_graph_checksum_valid(struct commit_graph *g)
return hashfile_checksum_valid(g->data, g->data_len);
}
-int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
+static int verify_one_commit_graph(struct repository *r,
+ struct commit_graph *g,
+ struct progress *progress,
+ uint64_t *seen)
{
uint32_t i, cur_fanout_pos = 0;
struct object_id prev_oid, cur_oid;
int generation_zero = 0;
- struct progress *progress = NULL;
- int local_error = 0;
-
- if (!g) {
- graph_report("no commit-graph file loaded");
- return 1;
- }
verify_commit_graph_error = verify_commit_graph_lite(g);
if (verify_commit_graph_error)
@@ -2568,7 +2579,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
for (i = 0; i < g->num_commits; i++) {
struct commit *graph_commit;
- oidread(&cur_oid, g->chunk_oid_lookup + g->hash_len * i);
+ oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
if (i && oidcmp(&prev_oid, &cur_oid) >= 0)
graph_report(_("commit-graph has incorrect OID order: %s then %s"),
@@ -2605,18 +2616,14 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
if (verify_commit_graph_error & ~VERIFY_COMMIT_GRAPH_ERROR_HASH)
return verify_commit_graph_error;
- if (flags & COMMIT_GRAPH_WRITE_PROGRESS)
- progress = start_progress(_("Verifying commits in commit graph"),
- g->num_commits);
-
for (i = 0; i < g->num_commits; i++) {
struct commit *graph_commit, *odb_commit;
struct commit_list *graph_parents, *odb_parents;
timestamp_t max_generation = 0;
timestamp_t generation;
- display_progress(progress, i + 1);
- oidread(&cur_oid, g->chunk_oid_lookup + g->hash_len * i);
+ display_progress(progress, ++(*seen));
+ oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_len, i));
graph_commit = lookup_commit(r, &cur_oid);
odb_commit = (struct commit *)create_object(r, &cur_oid, alloc_commit_node(r));
@@ -2698,12 +2705,37 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
graph_commit->date,
odb_commit->date);
}
- stop_progress(&progress);
- local_error = verify_commit_graph_error;
+ return verify_commit_graph_error;
+}
- if (!(flags & COMMIT_GRAPH_VERIFY_SHALLOW) && g->base_graph)
- local_error |= verify_commit_graph(r, g->base_graph, flags);
+int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
+{
+ struct progress *progress = NULL;
+ int local_error = 0;
+ uint64_t seen = 0;
+
+ if (!g) {
+ graph_report("no commit-graph file loaded");
+ return 1;
+ }
+
+ if (flags & COMMIT_GRAPH_WRITE_PROGRESS) {
+ uint64_t total = g->num_commits;
+ if (!(flags & COMMIT_GRAPH_VERIFY_SHALLOW))
+ total += g->num_commits_in_base;
+
+ progress = start_progress(_("Verifying commits in commit graph"),
+ total);
+ }
+
+ for (; g; g = g->base_graph) {
+ local_error |= verify_one_commit_graph(r, g, progress, &seen);
+ if (flags & COMMIT_GRAPH_VERIFY_SHALLOW)
+ break;
+ }
+
+ stop_progress(&progress);
return local_error;
}
diff --git a/commit-graph.h b/commit-graph.h
index 83aaa1dbb9..5e534f0fcc 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -1,7 +1,7 @@
#ifndef COMMIT_GRAPH_H
#define COMMIT_GRAPH_H
-#include "object-store.h"
+#include "object-store-ll.h"
#include "oidset.h"
#define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
diff --git a/commit-reach.c b/commit-reach.c
index 70bde8af05..4b7c233fd4 100644
--- a/commit-reach.c
+++ b/commit-reach.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "commit.h"
#include "commit-graph.h"
#include "decorate.h"
@@ -944,6 +943,8 @@ struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
}
}
+ clear_prio_queue(&queue);
+
clear_commit_marks_many(nr_to, to, PARENT1);
clear_commit_marks_many(nr_from, from, PARENT2);
diff --git a/commit.c b/commit.c
index 0fb9316931..b3223478bc 100644
--- a/commit.c
+++ b/commit.c
@@ -7,7 +7,7 @@
#include "hex.h"
#include "repository.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "pkt-line.h"
#include "utf8.h"
#include "diff.h"
@@ -516,7 +516,7 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b
* The clone is shallow if nr_parent < 0, and we must
* not traverse its real parents even when we unhide them.
*/
- if (graft && (graft->nr_parent < 0 || grafts_replace_parents))
+ if (graft && (graft->nr_parent < 0 || !grafts_keep_true_parents))
continue;
new_parent = lookup_commit(r, &parent);
if (!new_parent)
diff --git a/compat/fsmonitor/fsm-health-darwin.c b/compat/fsmonitor/fsm-health-darwin.c
index 4c291f8a06..5b1709d63f 100644
--- a/compat/fsmonitor/fsm-health-darwin.c
+++ b/compat/fsmonitor/fsm-health-darwin.c
@@ -1,6 +1,6 @@
#include "git-compat-util.h"
#include "config.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
#include "fsm-health.h"
#include "fsmonitor--daemon.h"
diff --git a/compat/fsmonitor/fsm-health-win32.c b/compat/fsmonitor/fsm-health-win32.c
index fe11bdd9ce..2d4e245beb 100644
--- a/compat/fsmonitor/fsm-health-win32.c
+++ b/compat/fsmonitor/fsm-health-win32.c
@@ -1,6 +1,6 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "config.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
#include "fsm-health.h"
#include "fsmonitor--daemon.h"
#include "gettext.h"
diff --git a/compat/fsmonitor/fsm-ipc-darwin.c b/compat/fsmonitor/fsm-ipc-darwin.c
index 793073aaa7..6f3a95410c 100644
--- a/compat/fsmonitor/fsm-ipc-darwin.c
+++ b/compat/fsmonitor/fsm-ipc-darwin.c
@@ -2,9 +2,10 @@
#include "config.h"
#include "gettext.h"
#include "hex.h"
+#include "path.h"
#include "repository.h"
#include "strbuf.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
#include "fsmonitor-ipc.h"
#include "fsmonitor-path-utils.h"
diff --git a/compat/fsmonitor/fsm-listen-darwin.c b/compat/fsmonitor/fsm-listen-darwin.c
index 23e24b4b37..36c7e13281 100644
--- a/compat/fsmonitor/fsm-listen-darwin.c
+++ b/compat/fsmonitor/fsm-listen-darwin.c
@@ -24,12 +24,13 @@
#endif
#include "git-compat-util.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
#include "fsm-listen.h"
#include "fsmonitor--daemon.h"
#include "fsmonitor-path-utils.h"
#include "gettext.h"
#include "string-list.h"
+#include "trace.h"
struct fsm_listen_data
{
diff --git a/compat/fsmonitor/fsm-listen-win32.c b/compat/fsmonitor/fsm-listen-win32.c
index 677b1bbdec..a361a7db20 100644
--- a/compat/fsmonitor/fsm-listen-win32.c
+++ b/compat/fsmonitor/fsm-listen-win32.c
@@ -1,6 +1,6 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "config.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
#include "fsm-listen.h"
#include "fsmonitor--daemon.h"
#include "gettext.h"
diff --git a/compat/fsmonitor/fsm-path-utils-darwin.c b/compat/fsmonitor/fsm-path-utils-darwin.c
index 45eb4a9b9e..049f97eaaf 100644
--- a/compat/fsmonitor/fsm-path-utils-darwin.c
+++ b/compat/fsmonitor/fsm-path-utils-darwin.c
@@ -1,6 +1,8 @@
-#include "fsmonitor.h"
+#include "git-compat-util.h"
+#include "fsmonitor-ll.h"
#include "fsmonitor-path-utils.h"
#include "gettext.h"
+#include "trace.h"
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
diff --git a/compat/fsmonitor/fsm-path-utils-win32.c b/compat/fsmonitor/fsm-path-utils-win32.c
index 4024baafb9..c8a3e9dcdb 100644
--- a/compat/fsmonitor/fsm-path-utils-win32.c
+++ b/compat/fsmonitor/fsm-path-utils-win32.c
@@ -1,7 +1,8 @@
-#include "cache.h"
-#include "fsmonitor.h"
+#include "git-compat-util.h"
+#include "fsmonitor-ll.h"
#include "fsmonitor-path-utils.h"
#include "gettext.h"
+#include "trace.h"
/*
* Check remote working directory protocol.
diff --git a/compat/fsmonitor/fsm-settings-darwin.c b/compat/fsmonitor/fsm-settings-darwin.c
index 58b623fbb9..a382590635 100644
--- a/compat/fsmonitor/fsm-settings-darwin.c
+++ b/compat/fsmonitor/fsm-settings-darwin.c
@@ -1,6 +1,6 @@
#include "git-compat-util.h"
#include "config.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
#include "fsmonitor-ipc.h"
#include "fsmonitor-settings.h"
#include "fsmonitor-path-utils.h"
diff --git a/compat/fsmonitor/fsm-settings-win32.c b/compat/fsmonitor/fsm-settings-win32.c
index a8af31b71d..b6f6744494 100644
--- a/compat/fsmonitor/fsm-settings-win32.c
+++ b/compat/fsmonitor/fsm-settings-win32.c
@@ -1,7 +1,7 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "config.h"
#include "repository.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
#include "fsmonitor-settings.h"
#include "fsmonitor-path-utils.h"
diff --git a/compat/mingw.c b/compat/mingw.c
index d06cdc6254..ec5280da16 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -6,7 +6,6 @@
#include <wchar.h>
#include "../strbuf.h"
#include "../run-command.h"
-#include "../cache.h"
#include "../abspath.h"
#include "../alloc.h"
#include "win32/lazyload.h"
@@ -244,7 +243,8 @@ static int core_restrict_inherited_handles = -1;
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
static char *unset_environment_variables;
-int mingw_core_config(const char *var, const char *value, void *cb)
+int mingw_core_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "core.hidedotfiles")) {
if (value && !strcasecmp(value, "dotgitonly"))
@@ -1347,6 +1347,11 @@ static char *path_lookup(const char *cmd, int exe_only)
return prog;
}
+char *mingw_locate_in_PATH(const char *cmd)
+{
+ return path_lookup(cmd, 0);
+}
+
static const wchar_t *wcschrnul(const wchar_t *s, wchar_t c)
{
while (*s && *s != c)
diff --git a/compat/mingw.h b/compat/mingw.h
index 209cf7ceba..6aec50e412 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -11,7 +11,9 @@ typedef _sigset_t sigset_t;
#undef _POSIX_THREAD_SAFE_FUNCTIONS
#endif
-int mingw_core_config(const char *var, const char *value, void *cb);
+struct config_context;
+int mingw_core_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb);
#define platform_core_config mingw_core_config
/*
@@ -175,6 +177,9 @@ pid_t waitpid(pid_t pid, int *status, int options);
#define kill mingw_kill
int mingw_kill(pid_t pid, int sig);
+#define locate_in_PATH mingw_locate_in_PATH
+char *mingw_locate_in_PATH(const char *cmd);
+
#ifndef NO_OPENSSL
#include <openssl/ssl.h>
static inline int mingw_SSL_set_fd(SSL *ssl, int fd)
diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
index a4d11376ba..0bd5c24250 100644
--- a/compat/precompose_utf8.c
+++ b/compat/precompose_utf8.c
@@ -5,11 +5,12 @@
#define PRECOMPOSE_UNICODE_C
-#include "cache.h"
+#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
#include "path.h"
+#include "strbuf.h"
#include "utf8.h"
#include "precompose_utf8.h"
diff --git a/compat/sha1-chunked.c b/compat/sha1-chunked.c
index 6adfcfd540..a4a6f930d7 100644
--- a/compat/sha1-chunked.c
+++ b/compat/sha1-chunked.c
@@ -1,4 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
+#include "hash-ll.h"
int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len)
{
diff --git a/compat/simple-ipc/ipc-win32.c b/compat/simple-ipc/ipc-win32.c
index 6adce3c650..8bfe51248e 100644
--- a/compat/simple-ipc/ipc-win32.c
+++ b/compat/simple-ipc/ipc-win32.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "abspath.h"
#include "gettext.h"
#include "simple-ipc.h"
diff --git a/compat/terminal.c b/compat/terminal.c
index d87e321189..83d95e8656 100644
--- a/compat/terminal.c
+++ b/compat/terminal.c
@@ -6,7 +6,6 @@
#include "run-command.h"
#include "string-list.h"
#include "hashmap.h"
-#include "wrapper.h"
#if defined(HAVE_DEV_TTY) || defined(GIT_WINDOWS_NATIVE)
diff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c
index a4e33768f4..3ef0936f6f 100644
--- a/compat/win32/trace2_win32_process_info.c
+++ b/compat/win32/trace2_win32_process_info.c
@@ -1,10 +1,10 @@
-#include "../../cache.h"
+#include "../../git-compat-util.h"
#include "../../json-writer.h"
#include "../../repository.h"
#include "../../trace2.h"
#include "lazyload.h"
-#include <Psapi.h>
-#include <tlHelp32.h>
+#include <psapi.h>
+#include <tlhelp32.h>
/*
* An arbitrarily chosen value to limit the size of the ancestor
diff --git a/config.c b/config.c
index b79baf83e3..3846a37be9 100644
--- a/config.c
+++ b/config.c
@@ -8,7 +8,6 @@
#include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"
-#include "alloc.h"
#include "date.h"
#include "branch.h"
#include "config.h"
@@ -25,18 +24,20 @@
#include "hashmap.h"
#include "string-list.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "pager.h"
+#include "path.h"
#include "utf8.h"
#include "dir.h"
#include "color.h"
#include "replace-object.h"
#include "refs.h"
#include "setup.h"
+#include "strvec.h"
#include "trace2.h"
+#include "wildmatch.h"
#include "worktree.h"
#include "ws.h"
-#include "wrapper.h"
#include "write-or-die.h"
struct config_source {
@@ -66,78 +67,6 @@ struct config_source {
};
#define CONFIG_SOURCE_INIT { 0 }
-struct config_reader {
- /*
- * These members record the "current" config source, which can be
- * accessed by parsing callbacks.
- *
- * The "source" variable will be non-NULL only when we are actually
- * parsing a real config source (file, blob, cmdline, etc).
- *
- * The "config_kvi" variable will be non-NULL only when we are feeding
- * cached config from a configset into a callback.
- *
- * They cannot be non-NULL at the same time. If they are both NULL, then
- * we aren't parsing anything (and depending on the function looking at
- * the variables, it's either a bug for it to be called in the first
- * place, or it's a function which can be reused for non-config
- * purposes, and should fall back to some sane behavior).
- */
- struct config_source *source;
- struct key_value_info *config_kvi;
- /*
- * The "scope" of the current config source being parsed (repo, global,
- * etc). Like "source", this is only set when parsing a config source.
- * It's not part of "source" because it transcends a single file (i.e.,
- * a file included from .git/config is still in "repo" scope).
- *
- * When iterating through a configset, the equivalent value is
- * "config_kvi.scope" (see above).
- */
- enum config_scope parsing_scope;
-};
-/*
- * Where possible, prefer to accept "struct config_reader" as an arg than to use
- * "the_reader". "the_reader" should only be used if that is infeasible, e.g. in
- * a public function.
- */
-static struct config_reader the_reader;
-
-static inline void config_reader_push_source(struct config_reader *reader,
- struct config_source *top)
-{
- if (reader->config_kvi)
- BUG("source should not be set while iterating a config set");
- top->prev = reader->source;
- reader->source = top;
-}
-
-static inline struct config_source *config_reader_pop_source(struct config_reader *reader)
-{
- struct config_source *ret;
- if (!reader->source)
- BUG("tried to pop config source, but we weren't reading config");
- ret = reader->source;
- reader->source = reader->source->prev;
- return ret;
-}
-
-static inline void config_reader_set_kvi(struct config_reader *reader,
- struct key_value_info *kvi)
-{
- if (kvi && (reader->source || reader->parsing_scope))
- BUG("kvi should not be set while parsing a config source");
- reader->config_kvi = kvi;
-}
-
-static inline void config_reader_set_scope(struct config_reader *reader,
- enum config_scope scope)
-{
- if (scope && reader->config_kvi)
- BUG("scope should only be set when iterating through a config source");
- reader->parsing_scope = scope;
-}
-
static int pack_compression_seen;
static int zlib_compression_seen;
@@ -199,7 +128,7 @@ struct config_include_data {
void *data;
const struct config_options *opts;
struct git_config_source *config_source;
- struct config_reader *config_reader;
+ struct repository *repo;
/*
* All remote URLs discovered when reading all config files.
@@ -208,7 +137,8 @@ struct config_include_data {
};
#define CONFIG_INCLUDE_INIT { 0 }
-static int git_config_include(const char *var, const char *value, void *data);
+static int git_config_include(const char *var, const char *value,
+ const struct config_context *ctx, void *data);
#define MAX_INCLUDE_DEPTH 10
static const char include_depth_advice[] = N_(
@@ -217,7 +147,8 @@ static const char include_depth_advice[] = N_(
"from\n"
" %s\n"
"This might be due to circular includes.");
-static int handle_path_include(struct config_source *cs, const char *path,
+static int handle_path_include(const struct key_value_info *kvi,
+ const char *path,
struct config_include_data *inc)
{
int ret = 0;
@@ -239,14 +170,14 @@ static int handle_path_include(struct config_source *cs, const char *path,
if (!is_absolute_path(path)) {
char *slash;
- if (!cs || !cs->path) {
+ if (!kvi || !kvi->path) {
ret = error(_("relative config includes must come from files"));
goto cleanup;
}
- slash = find_last_dir_sep(cs->path);
+ slash = find_last_dir_sep(kvi->path);
if (slash)
- strbuf_add(&buf, cs->path, slash - cs->path + 1);
+ strbuf_add(&buf, kvi->path, slash - kvi->path + 1);
strbuf_addstr(&buf, path);
path = buf.buf;
}
@@ -254,10 +185,11 @@ static int handle_path_include(struct config_source *cs, const char *path,
if (!access_or_die(path, R_OK, 0)) {
if (++inc->depth > MAX_INCLUDE_DEPTH)
die(_(include_depth_advice), MAX_INCLUDE_DEPTH, path,
- !cs ? "<unknown>" :
- cs->name ? cs->name :
+ !kvi ? "<unknown>" :
+ kvi->filename ? kvi->filename :
"the command line");
- ret = git_config_from_file(git_config_include, path, inc);
+ ret = git_config_from_file_with_options(git_config_include, path, inc,
+ kvi->scope, NULL);
inc->depth--;
}
cleanup:
@@ -272,7 +204,7 @@ static void add_trailing_starstar_for_dir(struct strbuf *pat)
strbuf_addstr(pat, "**");
}
-static int prepare_include_condition_pattern(struct config_source *cs,
+static int prepare_include_condition_pattern(const struct key_value_info *kvi,
struct strbuf *pat)
{
struct strbuf path = STRBUF_INIT;
@@ -289,11 +221,11 @@ static int prepare_include_condition_pattern(struct config_source *cs,
if (pat->buf[0] == '.' && is_dir_sep(pat->buf[1])) {
const char *slash;
- if (!cs || !cs->path)
+ if (!kvi || !kvi->path)
return error(_("relative config include "
"conditionals must come from files"));
- strbuf_realpath(&path, cs->path, 1);
+ strbuf_realpath(&path, kvi->path, 1);
slash = find_last_dir_sep(path.buf);
if (!slash)
BUG("how is this possible?");
@@ -308,7 +240,7 @@ static int prepare_include_condition_pattern(struct config_source *cs,
return prefix;
}
-static int include_by_gitdir(struct config_source *cs,
+static int include_by_gitdir(const struct key_value_info *kvi,
const struct config_options *opts,
const char *cond, size_t cond_len, int icase)
{
@@ -325,7 +257,7 @@ static int include_by_gitdir(struct config_source *cs,
strbuf_realpath(&text, git_dir, 1);
strbuf_add(&pattern, cond, cond_len);
- prefix = prepare_include_condition_pattern(cs, &pattern);
+ prefix = prepare_include_condition_pattern(kvi, &pattern);
again:
if (prefix < 0)
@@ -387,7 +319,8 @@ static int include_by_branch(const char *cond, size_t cond_len)
return ret;
}
-static int add_remote_url(const char *var, const char *value, void *data)
+static int add_remote_url(const char *var, const char *value,
+ const struct config_context *ctx UNUSED, void *data)
{
struct string_list *remote_urls = data;
const char *remote_name;
@@ -406,21 +339,17 @@ static void populate_remote_urls(struct config_include_data *inc)
{
struct config_options opts;
- enum config_scope store_scope = inc->config_reader->parsing_scope;
-
opts = *inc->opts;
opts.unconditional_remote_url = 1;
- config_reader_set_scope(inc->config_reader, 0);
-
inc->remote_urls = xmalloc(sizeof(*inc->remote_urls));
string_list_init_dup(inc->remote_urls);
- config_with_options(add_remote_url, inc->remote_urls, inc->config_source, &opts);
-
- config_reader_set_scope(inc->config_reader, store_scope);
+ config_with_options(add_remote_url, inc->remote_urls,
+ inc->config_source, inc->repo, &opts);
}
static int forbid_remote_url(const char *var, const char *value UNUSED,
+ const struct config_context *ctx UNUSED,
void *data UNUSED)
{
const char *remote_name;
@@ -464,16 +393,16 @@ static int include_by_remote_url(struct config_include_data *inc,
inc->remote_urls);
}
-static int include_condition_is_true(struct config_source *cs,
+static int include_condition_is_true(const struct key_value_info *kvi,
struct config_include_data *inc,
const char *cond, size_t cond_len)
{
const struct config_options *opts = inc->opts;
if (skip_prefix_mem(cond, cond_len, "gitdir:", &cond, &cond_len))
- return include_by_gitdir(cs, opts, cond, cond_len, 0);
+ return include_by_gitdir(kvi, opts, cond, cond_len, 0);
else if (skip_prefix_mem(cond, cond_len, "gitdir/i:", &cond, &cond_len))
- return include_by_gitdir(cs, opts, cond, cond_len, 1);
+ return include_by_gitdir(kvi, opts, cond, cond_len, 1);
else if (skip_prefix_mem(cond, cond_len, "onbranch:", &cond, &cond_len))
return include_by_branch(cond, cond_len);
else if (skip_prefix_mem(cond, cond_len, "hasconfig:remote.*.url:", &cond,
@@ -484,10 +413,11 @@ static int include_condition_is_true(struct config_source *cs,
return 0;
}
-static int git_config_include(const char *var, const char *value, void *data)
+static int git_config_include(const char *var, const char *value,
+ const struct config_context *ctx,
+ void *data)
{
struct config_include_data *inc = data;
- struct config_source *cs = inc->config_reader->source;
const char *cond, *key;
size_t cond_len;
int ret;
@@ -496,21 +426,21 @@ static int git_config_include(const char *var, const char *value, void *data)
* Pass along all values, including "include" directives; this makes it
* possible to query information on the includes themselves.
*/
- ret = inc->fn(var, value, inc->data);
+ ret = inc->fn(var, value, ctx, inc->data);
if (ret < 0)
return ret;
if (!strcmp(var, "include.path"))
- ret = handle_path_include(cs, value, inc);
+ ret = handle_path_include(ctx->kvi, value, inc);
if (!parse_config_key(var, "includeif", &cond, &cond_len, &key) &&
- cond && include_condition_is_true(cs, inc, cond, cond_len) &&
+ cond && include_condition_is_true(ctx->kvi, inc, cond, cond_len) &&
!strcmp(key, "path")) {
config_fn_t old_fn = inc->fn;
if (inc->opts->unconditional_remote_url)
inc->fn = forbid_remote_url;
- ret = handle_path_include(cs, value, inc);
+ ret = handle_path_include(ctx->kvi, value, inc);
inc->fn = old_fn;
}
@@ -668,27 +598,45 @@ out_free_ret_1:
}
static int config_parse_pair(const char *key, const char *value,
- config_fn_t fn, void *data)
+ struct key_value_info *kvi,
+ config_fn_t fn, void *data)
{
char *canonical_name;
int ret;
+ struct config_context ctx = {
+ .kvi = kvi,
+ };
if (!strlen(key))
return error(_("empty config key"));
if (git_config_parse_key(key, &canonical_name, NULL))
return -1;
- ret = (fn(canonical_name, value, data) < 0) ? -1 : 0;
+ ret = (fn(canonical_name, value, &ctx, data) < 0) ? -1 : 0;
free(canonical_name);
return ret;
}
+
+/* for values read from `git_config_from_parameters()` */
+void kvi_from_param(struct key_value_info *out)
+{
+ out->filename = NULL;
+ out->linenr = -1;
+ out->origin_type = CONFIG_ORIGIN_CMDLINE;
+ out->scope = CONFIG_SCOPE_COMMAND;
+ out->path = NULL;
+}
+
int git_config_parse_parameter(const char *text,
config_fn_t fn, void *data)
{
const char *value;
struct strbuf **pair;
int ret;
+ struct key_value_info kvi = KVI_INIT;
+
+ kvi_from_param(&kvi);
pair = strbuf_split_str(text, '=', 2);
if (!pair[0])
@@ -707,12 +655,13 @@ int git_config_parse_parameter(const char *text,
return error(_("bogus config parameter: %s"), text);
}
- ret = config_parse_pair(pair[0]->buf, value, fn, data);
+ ret = config_parse_pair(pair[0]->buf, value, &kvi, fn, data);
strbuf_list_free(pair);
return ret;
}
-static int parse_config_env_list(char *env, config_fn_t fn, void *data)
+static int parse_config_env_list(char *env, struct key_value_info *kvi,
+ config_fn_t fn, void *data)
{
char *cur = env;
while (cur && *cur) {
@@ -746,7 +695,7 @@ static int parse_config_env_list(char *env, config_fn_t fn, void *data)
CONFIG_DATA_ENVIRONMENT);
}
- if (config_parse_pair(key, value, fn, data) < 0)
+ if (config_parse_pair(key, value, kvi, fn, data) < 0)
return -1;
}
else {
@@ -770,11 +719,9 @@ int git_config_from_parameters(config_fn_t fn, void *data)
struct strvec to_free = STRVEC_INIT;
int ret = 0;
char *envw = NULL;
- struct config_source source = CONFIG_SOURCE_INIT;
-
- source.origin_type = CONFIG_ORIGIN_CMDLINE;
- config_reader_push_source(&the_reader, &source);
+ struct key_value_info kvi = KVI_INIT;
+ kvi_from_param(&kvi);
env = getenv(CONFIG_COUNT_ENVIRONMENT);
if (env) {
unsigned long count;
@@ -810,7 +757,7 @@ int git_config_from_parameters(config_fn_t fn, void *data)
}
strbuf_reset(&envvar);
- if (config_parse_pair(key, value, fn, data) < 0) {
+ if (config_parse_pair(key, value, &kvi, fn, data) < 0) {
ret = -1;
goto out;
}
@@ -821,7 +768,7 @@ int git_config_from_parameters(config_fn_t fn, void *data)
if (env) {
/* sq_dequote will write over it */
envw = xstrdup(env);
- if (parse_config_env_list(envw, fn, data) < 0) {
+ if (parse_config_env_list(envw, &kvi, fn, data) < 0) {
ret = -1;
goto out;
}
@@ -831,7 +778,6 @@ out:
strbuf_release(&envvar);
strvec_clear(&to_free);
free(envw);
- config_reader_pop_source(&the_reader);
return ret;
}
@@ -932,12 +878,15 @@ static char *parse_value(struct config_source *cs)
}
}
-static int get_value(struct config_source *cs, config_fn_t fn, void *data,
- struct strbuf *name)
+static int get_value(struct config_source *cs, struct key_value_info *kvi,
+ config_fn_t fn, void *data, struct strbuf *name)
{
int c;
char *value;
int ret;
+ struct config_context ctx = {
+ .kvi = kvi,
+ };
/* Get the full name */
for (;;) {
@@ -966,7 +915,8 @@ static int get_value(struct config_source *cs, config_fn_t fn, void *data,
* accurate line number in error messages.
*/
cs->linenr--;
- ret = fn(name->buf, value, data);
+ kvi->linenr = cs->linenr;
+ ret = fn(name->buf, value, &ctx, data);
if (ret >= 0)
cs->linenr++;
return ret;
@@ -1056,7 +1006,7 @@ static int do_event(struct config_source *cs, enum config_event_t type,
if (data->previous_type != CONFIG_EVENT_EOF &&
data->opts->event_fn(data->previous_type, data->previous_offset,
- offset, data->opts->event_fn_data) < 0)
+ offset, cs, data->opts->event_fn_data) < 0)
return -1;
data->previous_type = type;
@@ -1065,8 +1015,20 @@ static int do_event(struct config_source *cs, enum config_event_t type,
return 0;
}
+static void kvi_from_source(struct config_source *cs,
+ enum config_scope scope,
+ struct key_value_info *out)
+{
+ out->filename = strintern(cs->name);
+ out->origin_type = cs->origin_type;
+ out->linenr = cs->linenr;
+ out->scope = scope;
+ out->path = cs->path;
+}
+
static int git_parse_source(struct config_source *cs, config_fn_t fn,
- void *data, const struct config_options *opts)
+ struct key_value_info *kvi, void *data,
+ const struct config_options *opts)
{
int comment = 0;
size_t baselen = 0;
@@ -1150,7 +1112,7 @@ static int git_parse_source(struct config_source *cs, config_fn_t fn,
*/
strbuf_setlen(var, baselen);
strbuf_addch(var, tolower(c));
- if (get_value(cs, fn, data, var) < 0)
+ if (get_value(cs, kvi, fn, data, var) < 0)
break;
}
@@ -1326,80 +1288,78 @@ int git_parse_ssize_t(const char *value, ssize_t *ret)
return 1;
}
-static int reader_config_name(struct config_reader *reader, const char **out);
-static int reader_origin_type(struct config_reader *reader,
- enum config_origin_type *type);
NORETURN
-static void die_bad_number(struct config_reader *reader, const char *name,
- const char *value)
+static void die_bad_number(const char *name, const char *value,
+ const struct key_value_info *kvi)
{
const char *error_type = (errno == ERANGE) ?
N_("out of range") : N_("invalid unit");
const char *bad_numeric = N_("bad numeric config value '%s' for '%s': %s");
- const char *config_name = NULL;
- enum config_origin_type config_origin = CONFIG_ORIGIN_UNKNOWN;
+
+ if (!kvi)
+ BUG("kvi should not be NULL");
if (!value)
value = "";
- /* Ignoring the return value is okay since we handle missing values. */
- reader_config_name(reader, &config_name);
- reader_origin_type(reader, &config_origin);
-
- if (!config_name)
+ if (!kvi->filename)
die(_(bad_numeric), value, name, _(error_type));
- switch (config_origin) {
+ switch (kvi->origin_type) {
case CONFIG_ORIGIN_BLOB:
die(_("bad numeric config value '%s' for '%s' in blob %s: %s"),
- value, name, config_name, _(error_type));
+ value, name, kvi->filename, _(error_type));
case CONFIG_ORIGIN_FILE:
die(_("bad numeric config value '%s' for '%s' in file %s: %s"),
- value, name, config_name, _(error_type));
+ value, name, kvi->filename, _(error_type));
case CONFIG_ORIGIN_STDIN:
die(_("bad numeric config value '%s' for '%s' in standard input: %s"),
value, name, _(error_type));
case CONFIG_ORIGIN_SUBMODULE_BLOB:
die(_("bad numeric config value '%s' for '%s' in submodule-blob %s: %s"),
- value, name, config_name, _(error_type));
+ value, name, kvi->filename, _(error_type));
case CONFIG_ORIGIN_CMDLINE:
die(_("bad numeric config value '%s' for '%s' in command line %s: %s"),
- value, name, config_name, _(error_type));
+ value, name, kvi->filename, _(error_type));
default:
die(_("bad numeric config value '%s' for '%s' in %s: %s"),
- value, name, config_name, _(error_type));
+ value, name, kvi->filename, _(error_type));
}
}
-int git_config_int(const char *name, const char *value)
+int git_config_int(const char *name, const char *value,
+ const struct key_value_info *kvi)
{
int ret;
if (!git_parse_int(value, &ret))
- die_bad_number(&the_reader, name, value);
+ die_bad_number(name, value, kvi);
return ret;
}
-int64_t git_config_int64(const char *name, const char *value)
+int64_t git_config_int64(const char *name, const char *value,
+ const struct key_value_info *kvi)
{
int64_t ret;
if (!git_parse_int64(value, &ret))
- die_bad_number(&the_reader, name, value);
+ die_bad_number(name, value, kvi);
return ret;
}
-unsigned long git_config_ulong(const char *name, const char *value)
+unsigned long git_config_ulong(const char *name, const char *value,
+ const struct key_value_info *kvi)
{
unsigned long ret;
if (!git_parse_ulong(value, &ret))
- die_bad_number(&the_reader, name, value);
+ die_bad_number(name, value, kvi);
return ret;
}
-ssize_t git_config_ssize_t(const char *name, const char *value)
+ssize_t git_config_ssize_t(const char *name, const char *value,
+ const struct key_value_info *kvi)
{
ssize_t ret;
if (!git_parse_ssize_t(value, &ret))
- die_bad_number(&the_reader, name, value);
+ die_bad_number(name, value, kvi);
return ret;
}
@@ -1504,7 +1464,8 @@ int git_parse_maybe_bool(const char *value)
return -1;
}
-int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
+int git_config_bool_or_int(const char *name, const char *value,
+ const struct key_value_info *kvi, int *is_bool)
{
int v = git_parse_maybe_bool_text(value);
if (0 <= v) {
@@ -1512,7 +1473,7 @@ int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
return v;
}
*is_bool = 0;
- return git_config_int(name, value);
+ return git_config_int(name, value, kvi);
}
int git_config_bool(const char *name, const char *value)
@@ -1560,7 +1521,8 @@ int git_config_color(char *dest, const char *var, const char *value)
return 0;
}
-static int git_default_core_config(const char *var, const char *value, void *cb)
+static int git_default_core_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
/* This needs a better name */
if (!strcmp(var, "core.filemode")) {
@@ -1637,7 +1599,7 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
else if (!git_parse_maybe_bool_text(value))
default_abbrev = the_hash_algo->hexsz;
else {
- int abbrev = git_config_int(var, value);
+ int abbrev = git_config_int(var, value, ctx->kvi);
if (abbrev < minimum_abbrev || abbrev > the_hash_algo->hexsz)
return error(_("abbrev length out of range: %d"), abbrev);
default_abbrev = abbrev;
@@ -1649,7 +1611,7 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
return set_disambiguate_hint_config(var, value);
if (!strcmp(var, "core.loosecompression")) {
- int level = git_config_int(var, value);
+ int level = git_config_int(var, value, ctx->kvi);
if (level == -1)
level = Z_DEFAULT_COMPRESSION;
else if (level < 0 || level > Z_BEST_COMPRESSION)
@@ -1660,7 +1622,7 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
}
if (!strcmp(var, "core.compression")) {
- int level = git_config_int(var, value);
+ int level = git_config_int(var, value, ctx->kvi);
if (level == -1)
level = Z_DEFAULT_COMPRESSION;
else if (level < 0 || level > Z_BEST_COMPRESSION)
@@ -1674,7 +1636,7 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
if (!strcmp(var, "core.packedgitwindowsize")) {
int pgsz_x2 = getpagesize() * 2;
- packed_git_window_size = git_config_ulong(var, value);
+ packed_git_window_size = git_config_ulong(var, value, ctx->kvi);
/* This value must be multiple of (pagesize * 2) */
packed_git_window_size /= pgsz_x2;
@@ -1685,17 +1647,17 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
}
if (!strcmp(var, "core.bigfilethreshold")) {
- big_file_threshold = git_config_ulong(var, value);
+ big_file_threshold = git_config_ulong(var, value, ctx->kvi);
return 0;
}
if (!strcmp(var, "core.packedgitlimit")) {
- packed_git_limit = git_config_ulong(var, value);
+ packed_git_limit = git_config_ulong(var, value, ctx->kvi);
return 0;
}
if (!strcmp(var, "core.deltabasecachelimit")) {
- delta_base_cache_limit = git_config_ulong(var, value);
+ delta_base_cache_limit = git_config_ulong(var, value, ctx->kvi);
return 0;
}
@@ -1839,13 +1801,8 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
return 0;
}
- if (!strcmp(var, "core.usereplacerefs")) {
- read_replace_refs = git_config_bool(var, value);
- return 0;
- }
-
/* Add other config variables here and to Documentation/config.txt. */
- return platform_core_config(var, value, cb);
+ return platform_core_config(var, value, ctx, cb);
}
static int git_default_sparse_config(const char *var, const char *value)
@@ -1947,15 +1904,16 @@ static int git_default_mailmap_config(const char *var, const char *value)
return 0;
}
-int git_default_config(const char *var, const char *value, void *cb)
+int git_default_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (starts_with(var, "core."))
- return git_default_core_config(var, value, cb);
+ return git_default_core_config(var, value, ctx, cb);
if (starts_with(var, "user.") ||
starts_with(var, "author.") ||
starts_with(var, "committer."))
- return git_ident_config(var, value, cb);
+ return git_ident_config(var, value, ctx, cb);
if (starts_with(var, "i18n."))
return git_default_i18n_config(var, value);
@@ -1978,12 +1936,12 @@ int git_default_config(const char *var, const char *value, void *cb)
}
if (!strcmp(var, "pack.packsizelimit")) {
- pack_size_limit_cfg = git_config_ulong(var, value);
+ pack_size_limit_cfg = git_config_ulong(var, value, ctx->kvi);
return 0;
}
if (!strcmp(var, "pack.compression")) {
- int level = git_config_int(var, value);
+ int level = git_config_int(var, value, ctx->kvi);
if (level == -1)
level = Z_DEFAULT_COMPRESSION;
else if (level < 0 || level > Z_BEST_COMPRESSION)
@@ -2005,10 +1963,11 @@ int git_default_config(const char *var, const char *value, void *cb)
* fgetc, ungetc, ftell of top need to be initialized before calling
* this function.
*/
-static int do_config_from(struct config_reader *reader,
- struct config_source *top, config_fn_t fn, void *data,
+static int do_config_from(struct config_source *top, config_fn_t fn,
+ void *data, enum config_scope scope,
const struct config_options *opts)
{
+ struct key_value_info kvi = KVI_INIT;
int ret;
/* push config-file parsing state stack */
@@ -2017,23 +1976,21 @@ static int do_config_from(struct config_reader *reader,
top->total_len = 0;
strbuf_init(&top->value, 1024);
strbuf_init(&top->var, 1024);
- config_reader_push_source(reader, top);
+ kvi_from_source(top, scope, &kvi);
- ret = git_parse_source(top, fn, data, opts);
+ ret = git_parse_source(top, fn, &kvi, data, opts);
- /* pop config-file parsing state stack */
strbuf_release(&top->value);
strbuf_release(&top->var);
- config_reader_pop_source(reader);
return ret;
}
-static int do_config_from_file(struct config_reader *reader,
- config_fn_t fn,
+static int do_config_from_file(config_fn_t fn,
const enum config_origin_type origin_type,
const char *name, const char *path, FILE *f,
- void *data, const struct config_options *opts)
+ void *data, enum config_scope scope,
+ const struct config_options *opts)
{
struct config_source top = CONFIG_SOURCE_INIT;
int ret;
@@ -2048,19 +2005,20 @@ static int do_config_from_file(struct config_reader *reader,
top.do_ftell = config_file_ftell;
flockfile(f);
- ret = do_config_from(reader, &top, fn, data, opts);
+ ret = do_config_from(&top, fn, data, scope, opts);
funlockfile(f);
return ret;
}
-static int git_config_from_stdin(config_fn_t fn, void *data)
+static int git_config_from_stdin(config_fn_t fn, void *data,
+ enum config_scope scope)
{
- return do_config_from_file(&the_reader, fn, CONFIG_ORIGIN_STDIN, "",
- NULL, stdin, data, NULL);
+ return do_config_from_file(fn, CONFIG_ORIGIN_STDIN, "", NULL, stdin,
+ data, scope, NULL);
}
int git_config_from_file_with_options(config_fn_t fn, const char *filename,
- void *data,
+ void *data, enum config_scope scope,
const struct config_options *opts)
{
int ret = -1;
@@ -2070,8 +2028,8 @@ int git_config_from_file_with_options(config_fn_t fn, const char *filename,
BUG("filename cannot be NULL");
f = fopen_or_warn(filename, "r");
if (f) {
- ret = do_config_from_file(&the_reader, fn, CONFIG_ORIGIN_FILE,
- filename, filename, f, data, opts);
+ ret = do_config_from_file(fn, CONFIG_ORIGIN_FILE, filename,
+ filename, f, data, scope, opts);
fclose(f);
}
return ret;
@@ -2079,13 +2037,15 @@ int git_config_from_file_with_options(config_fn_t fn, const char *filename,
int git_config_from_file(config_fn_t fn, const char *filename, void *data)
{
- return git_config_from_file_with_options(fn, filename, data, NULL);
+ return git_config_from_file_with_options(fn, filename, data,
+ CONFIG_SCOPE_UNKNOWN, NULL);
}
int git_config_from_mem(config_fn_t fn,
const enum config_origin_type origin_type,
const char *name, const char *buf, size_t len,
- void *data, const struct config_options *opts)
+ void *data, enum config_scope scope,
+ const struct config_options *opts)
{
struct config_source top = CONFIG_SOURCE_INIT;
@@ -2100,14 +2060,15 @@ int git_config_from_mem(config_fn_t fn,
top.do_ungetc = config_buf_ungetc;
top.do_ftell = config_buf_ftell;
- return do_config_from(&the_reader, &top, fn, data, opts);
+ return do_config_from(&top, fn, data, scope, opts);
}
int git_config_from_blob_oid(config_fn_t fn,
const char *name,
struct repository *repo,
const struct object_id *oid,
- void *data)
+ void *data,
+ enum config_scope scope)
{
enum object_type type;
char *buf;
@@ -2123,7 +2084,7 @@ int git_config_from_blob_oid(config_fn_t fn,
}
ret = git_config_from_mem(fn, CONFIG_ORIGIN_BLOB, name, buf, size,
- data, NULL);
+ data, scope, NULL);
free(buf);
return ret;
@@ -2132,13 +2093,14 @@ int git_config_from_blob_oid(config_fn_t fn,
static int git_config_from_blob_ref(config_fn_t fn,
struct repository *repo,
const char *name,
- void *data)
+ void *data,
+ enum config_scope scope)
{
struct object_id oid;
if (repo_get_oid(repo, name, &oid) < 0)
return error(_("unable to resolve config blob '%s'"), name);
- return git_config_from_blob_oid(fn, name, repo, &oid, data);
+ return git_config_from_blob_oid(fn, name, repo, &oid, data, scope);
}
char *git_system_config(void)
@@ -2191,8 +2153,8 @@ int git_config_system(void)
return !git_env_bool("GIT_CONFIG_NOSYSTEM", 0);
}
-static int do_git_config_sequence(struct config_reader *reader,
- const struct config_options *opts,
+static int do_git_config_sequence(const struct config_options *opts,
+ const struct repository *repo,
config_fn_t fn, void *data)
{
int ret = 0;
@@ -2200,122 +2162,125 @@ static int do_git_config_sequence(struct config_reader *reader,
char *xdg_config = NULL;
char *user_config = NULL;
char *repo_config;
- enum config_scope prev_parsing_scope = reader->parsing_scope;
+ char *worktree_config;
+
+ /*
+ * Ensure that either:
+ * - the git_dir and commondir are both set, or
+ * - the git_dir and commondir are both NULL
+ */
+ if (!opts->git_dir != !opts->commondir)
+ BUG("only one of commondir and git_dir is non-NULL");
- if (opts->commondir)
+ if (opts->commondir) {
repo_config = mkpathdup("%s/config", opts->commondir);
- else if (opts->git_dir)
- BUG("git_dir without commondir");
- else
+ worktree_config = mkpathdup("%s/config.worktree", opts->git_dir);
+ } else {
repo_config = NULL;
+ worktree_config = NULL;
+ }
- config_reader_set_scope(reader, CONFIG_SCOPE_SYSTEM);
if (git_config_system() && system_config &&
!access_or_die(system_config, R_OK,
opts->system_gently ? ACCESS_EACCES_OK : 0))
- ret += git_config_from_file(fn, system_config, data);
+ ret += git_config_from_file_with_options(fn, system_config,
+ data, CONFIG_SCOPE_SYSTEM,
+ NULL);
- config_reader_set_scope(reader, CONFIG_SCOPE_GLOBAL);
git_global_config(&user_config, &xdg_config);
if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK))
- ret += git_config_from_file(fn, xdg_config, data);
+ ret += git_config_from_file_with_options(fn, xdg_config, data,
+ CONFIG_SCOPE_GLOBAL, NULL);
if (user_config && !access_or_die(user_config, R_OK, ACCESS_EACCES_OK))
- ret += git_config_from_file(fn, user_config, data);
+ ret += git_config_from_file_with_options(fn, user_config, data,
+ CONFIG_SCOPE_GLOBAL, NULL);
- config_reader_set_scope(reader, CONFIG_SCOPE_LOCAL);
if (!opts->ignore_repo && repo_config &&
!access_or_die(repo_config, R_OK, 0))
- ret += git_config_from_file(fn, repo_config, data);
+ ret += git_config_from_file_with_options(fn, repo_config, data,
+ CONFIG_SCOPE_LOCAL, NULL);
- config_reader_set_scope(reader, CONFIG_SCOPE_WORKTREE);
- if (!opts->ignore_worktree && repository_format_worktree_config) {
- char *path = git_pathdup("config.worktree");
- if (!access_or_die(path, R_OK, 0))
- ret += git_config_from_file(fn, path, data);
- free(path);
+ if (!opts->ignore_worktree && worktree_config &&
+ repo && repo->repository_format_worktree_config &&
+ !access_or_die(worktree_config, R_OK, 0)) {
+ ret += git_config_from_file_with_options(fn, worktree_config, data,
+ CONFIG_SCOPE_WORKTREE,
+ NULL);
}
- config_reader_set_scope(reader, CONFIG_SCOPE_COMMAND);
if (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0)
die(_("unable to parse command-line config"));
- config_reader_set_scope(reader, prev_parsing_scope);
free(system_config);
free(xdg_config);
free(user_config);
free(repo_config);
+ free(worktree_config);
return ret;
}
int config_with_options(config_fn_t fn, void *data,
struct git_config_source *config_source,
+ struct repository *repo,
const struct config_options *opts)
{
struct config_include_data inc = CONFIG_INCLUDE_INIT;
- enum config_scope prev_scope = the_reader.parsing_scope;
int ret;
if (opts->respect_includes) {
inc.fn = fn;
inc.data = data;
inc.opts = opts;
+ inc.repo = repo;
inc.config_source = config_source;
- inc.config_reader = &the_reader;
fn = git_config_include;
data = &inc;
}
- if (config_source)
- config_reader_set_scope(&the_reader, config_source->scope);
-
/*
* If we have a specific filename, use it. Otherwise, follow the
* regular lookup sequence.
*/
if (config_source && config_source->use_stdin) {
- ret = git_config_from_stdin(fn, data);
+ ret = git_config_from_stdin(fn, data, config_source->scope);
} else if (config_source && config_source->file) {
- ret = git_config_from_file(fn, config_source->file, data);
+ ret = git_config_from_file_with_options(fn, config_source->file,
+ data, config_source->scope,
+ NULL);
} else if (config_source && config_source->blob) {
- struct repository *repo = config_source->repo ?
- config_source->repo : the_repository;
ret = git_config_from_blob_ref(fn, repo, config_source->blob,
- data);
+ data, config_source->scope);
} else {
- ret = do_git_config_sequence(&the_reader, opts, fn, data);
+ ret = do_git_config_sequence(opts, repo, fn, data);
}
if (inc.remote_urls) {
string_list_clear(inc.remote_urls, 0);
FREE_AND_NULL(inc.remote_urls);
}
- config_reader_set_scope(&the_reader, prev_scope);
return ret;
}
-static void configset_iter(struct config_reader *reader, struct config_set *set,
- config_fn_t fn, void *data)
+static void configset_iter(struct config_set *set, config_fn_t fn, void *data)
{
int i, value_index;
struct string_list *values;
struct config_set_element *entry;
struct configset_list *list = &set->list;
+ struct config_context ctx = CONFIG_CONTEXT_INIT;
for (i = 0; i < list->nr; i++) {
entry = list->items[i].e;
value_index = list->items[i].value_index;
values = &entry->value_list;
- config_reader_set_kvi(reader, values->items[value_index].util);
-
- if (fn(entry->key, values->items[value_index].string, data) < 0)
+ ctx.kvi = values->items[value_index].util;
+ if (fn(entry->key, values->items[value_index].string, &ctx, data) < 0)
git_die_config_linenr(entry->key,
- reader->config_kvi->filename,
- reader->config_kvi->linenr);
-
- config_reader_set_kvi(reader, NULL);
+ ctx.kvi->filename,
+ ctx.kvi->linenr);
}
}
@@ -2343,7 +2308,7 @@ void read_early_config(config_fn_t cb, void *data)
opts.git_dir = gitdir.buf;
}
- config_with_options(cb, data, NULL, &opts);
+ config_with_options(cb, data, NULL, NULL, &opts);
strbuf_release(&commondir);
strbuf_release(&gitdir);
@@ -2363,7 +2328,7 @@ void read_very_early_config(config_fn_t cb, void *data)
opts.ignore_cmdline = 1;
opts.system_gently = 1;
- config_with_options(cb, data, NULL, &opts);
+ config_with_options(cb, data, NULL, NULL, &opts);
}
RESULT_MUST_BE_USED
@@ -2391,7 +2356,7 @@ static int configset_find_element(struct config_set *set, const char *key,
return 0;
}
-static int configset_add_value(struct config_reader *reader,
+static int configset_add_value(const struct key_value_info *kvi_p,
struct config_set *set, const char *key,
const char *value)
{
@@ -2422,19 +2387,7 @@ static int configset_add_value(struct config_reader *reader,
l_item->e = e;
l_item->value_index = e->value_list.nr - 1;
- if (!reader->source)
- BUG("configset_add_value has no source");
- if (reader->source->name) {
- kv_info->filename = strintern(reader->source->name);
- kv_info->linenr = reader->source->linenr;
- kv_info->origin_type = reader->source->origin_type;
- } else {
- /* for values read from `git_config_from_parameters()` */
- kv_info->filename = NULL;
- kv_info->linenr = -1;
- kv_info->origin_type = CONFIG_ORIGIN_CMDLINE;
- }
- kv_info->scope = reader->parsing_scope;
+ *kv_info = *kvi_p;
si->util = kv_info;
return 0;
@@ -2482,32 +2435,26 @@ void git_configset_clear(struct config_set *set)
set->list.items = NULL;
}
-struct configset_add_data {
- struct config_set *config_set;
- struct config_reader *config_reader;
-};
-#define CONFIGSET_ADD_INIT { 0 }
-
-static int config_set_callback(const char *key, const char *value, void *cb)
+static int config_set_callback(const char *key, const char *value,
+ const struct config_context *ctx,
+ void *cb)
{
- struct configset_add_data *data = cb;
- configset_add_value(data->config_reader, data->config_set, key, value);
+ struct config_set *set = cb;
+ configset_add_value(ctx->kvi, set, key, value);
return 0;
}
int git_configset_add_file(struct config_set *set, const char *filename)
{
- struct configset_add_data data = CONFIGSET_ADD_INIT;
- data.config_reader = &the_reader;
- data.config_set = set;
- return git_config_from_file(config_set_callback, filename, &data);
+ return git_config_from_file(config_set_callback, filename, set);
}
-int git_configset_get_value(struct config_set *set, const char *key, const char **value)
+int git_configset_get_value(struct config_set *set, const char *key,
+ const char **value, struct key_value_info *kvi)
{
const struct string_list *values = NULL;
int ret;
-
+ struct string_list_item item;
/*
* Follows "last one wins" semantic, i.e., if there are multiple matches for the
* queried key in the files of the configset, the value returned will be the last
@@ -2517,7 +2464,10 @@ int git_configset_get_value(struct config_set *set, const char *key, const char
return ret;
assert(values->nr > 0);
- *value = values->items[values->nr - 1].string;
+ item = values->items[values->nr - 1];
+ *value = item.string;
+ if (kvi)
+ *kvi = *((struct key_value_info *)item.util);
return 0;
}
@@ -2570,7 +2520,7 @@ int git_configset_get(struct config_set *set, const char *key)
int git_configset_get_string(struct config_set *set, const char *key, char **dest)
{
const char *value;
- if (!git_configset_get_value(set, key, &value))
+ if (!git_configset_get_value(set, key, &value, NULL))
return git_config_string((const char **)dest, key, value);
else
return 1;
@@ -2580,7 +2530,7 @@ static int git_configset_get_string_tmp(struct config_set *set, const char *key,
const char **dest)
{
const char *value;
- if (!git_configset_get_value(set, key, &value)) {
+ if (!git_configset_get_value(set, key, &value, NULL)) {
if (!value)
return config_error_nonbool(key);
*dest = value;
@@ -2593,8 +2543,10 @@ static int git_configset_get_string_tmp(struct config_set *set, const char *key,
int git_configset_get_int(struct config_set *set, const char *key, int *dest)
{
const char *value;
- if (!git_configset_get_value(set, key, &value)) {
- *dest = git_config_int(key, value);
+ struct key_value_info kvi;
+
+ if (!git_configset_get_value(set, key, &value, &kvi)) {
+ *dest = git_config_int(key, value, &kvi);
return 0;
} else
return 1;
@@ -2603,8 +2555,10 @@ int git_configset_get_int(struct config_set *set, const char *key, int *dest)
int git_configset_get_ulong(struct config_set *set, const char *key, unsigned long *dest)
{
const char *value;
- if (!git_configset_get_value(set, key, &value)) {
- *dest = git_config_ulong(key, value);
+ struct key_value_info kvi;
+
+ if (!git_configset_get_value(set, key, &value, &kvi)) {
+ *dest = git_config_ulong(key, value, &kvi);
return 0;
} else
return 1;
@@ -2613,7 +2567,7 @@ int git_configset_get_ulong(struct config_set *set, const char *key, unsigned lo
int git_configset_get_bool(struct config_set *set, const char *key, int *dest)
{
const char *value;
- if (!git_configset_get_value(set, key, &value)) {
+ if (!git_configset_get_value(set, key, &value, NULL)) {
*dest = git_config_bool(key, value);
return 0;
} else
@@ -2624,8 +2578,10 @@ int git_configset_get_bool_or_int(struct config_set *set, const char *key,
int *is_bool, int *dest)
{
const char *value;
- if (!git_configset_get_value(set, key, &value)) {
- *dest = git_config_bool_or_int(key, value, is_bool);
+ struct key_value_info kvi;
+
+ if (!git_configset_get_value(set, key, &value, &kvi)) {
+ *dest = git_config_bool_or_int(key, value, &kvi, is_bool);
return 0;
} else
return 1;
@@ -2634,7 +2590,7 @@ int git_configset_get_bool_or_int(struct config_set *set, const char *key,
int git_configset_get_maybe_bool(struct config_set *set, const char *key, int *dest)
{
const char *value;
- if (!git_configset_get_value(set, key, &value)) {
+ if (!git_configset_get_value(set, key, &value, NULL)) {
*dest = git_parse_maybe_bool(value);
if (*dest == -1)
return -1;
@@ -2646,7 +2602,7 @@ int git_configset_get_maybe_bool(struct config_set *set, const char *key, int *d
int git_configset_get_pathname(struct config_set *set, const char *key, const char **dest)
{
const char *value;
- if (!git_configset_get_value(set, key, &value))
+ if (!git_configset_get_value(set, key, &value, NULL))
return git_config_pathname(dest, key, value);
else
return 1;
@@ -2656,7 +2612,6 @@ int git_configset_get_pathname(struct config_set *set, const char *key, const ch
static void repo_read_config(struct repository *repo)
{
struct config_options opts = { 0 };
- struct configset_add_data data = CONFIGSET_ADD_INIT;
opts.respect_includes = 1;
opts.commondir = repo->commondir;
@@ -2668,10 +2623,8 @@ static void repo_read_config(struct repository *repo)
git_configset_clear(repo->config);
git_configset_init(repo->config);
- data.config_set = repo->config;
- data.config_reader = &the_reader;
-
- if (config_with_options(config_set_callback, &data, NULL, &opts) < 0)
+ if (config_with_options(config_set_callback, repo->config, NULL,
+ repo, &opts) < 0)
/*
* config_with_options() normally returns only
* zero, as most errors are fatal, and
@@ -2703,7 +2656,7 @@ static void repo_config_clear(struct repository *repo)
void repo_config(struct repository *repo, config_fn_t fn, void *data)
{
git_config_check_init(repo);
- configset_iter(&the_reader, repo->config, fn, data);
+ configset_iter(repo->config, fn, data);
}
int repo_config_get(struct repository *repo, const char *key)
@@ -2716,7 +2669,7 @@ int repo_config_get_value(struct repository *repo,
const char *key, const char **value)
{
git_config_check_init(repo);
- return git_configset_get_value(repo->config, key, value);
+ return git_configset_get_value(repo->config, key, value, NULL);
}
int repo_config_get_value_multi(struct repository *repo, const char *key,
@@ -2810,19 +2763,17 @@ static void read_protected_config(void)
.ignore_worktree = 1,
.system_gently = 1,
};
- struct configset_add_data data = CONFIGSET_ADD_INIT;
git_configset_init(&protected_config);
- data.config_set = &protected_config;
- data.config_reader = &the_reader;
- config_with_options(config_set_callback, &data, NULL, &opts);
+ config_with_options(config_set_callback, &protected_config, NULL,
+ NULL, &opts);
}
void git_protected_config(config_fn_t fn, void *data)
{
if (!protected_config.hash_initialized)
read_protected_config();
- configset_iter(&the_reader, &protected_config, fn, data);
+ configset_iter(&protected_config, fn, data);
}
/* Functions used historically to read configuration from 'the_repository' */
@@ -3012,7 +2963,6 @@ void git_die_config(const char *key, const char *err, ...)
*/
struct config_store_data {
- struct config_reader *config_reader;
size_t baselen;
char *key;
int do_not_match;
@@ -3058,11 +3008,10 @@ static int matches(const char *key, const char *value,
(value && !regexec(store->value_pattern, value, 0, NULL, 0));
}
-static int store_aux_event(enum config_event_t type,
- size_t begin, size_t end, void *data)
+static int store_aux_event(enum config_event_t type, size_t begin, size_t end,
+ struct config_source *cs, void *data)
{
struct config_store_data *store = data;
- struct config_source *cs = store->config_reader->source;
ALLOC_GROW(store->parsed, store->parsed_nr + 1, store->parsed_alloc);
store->parsed[store->parsed_nr].begin = begin;
@@ -3098,7 +3047,8 @@ static int store_aux_event(enum config_event_t type,
return 0;
}
-static int store_aux(const char *key, const char *value, void *cb)
+static int store_aux(const char *key, const char *value,
+ const struct config_context *ctx UNUSED, void *cb)
{
struct config_store_data *store = cb;
@@ -3327,7 +3277,7 @@ int repo_config_set_worktree_gently(struct repository *r,
const char *key, const char *value)
{
/* Only use worktree-specific config if it is already enabled. */
- if (repository_format_worktree_config) {
+ if (r->repository_format_worktree_config) {
char *file = repo_git_path(r, "config.worktree");
int ret = git_config_set_multivar_in_file_gently(
file, key, value, NULL, 0);
@@ -3382,8 +3332,6 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
size_t contents_sz;
struct config_store_data store = CONFIG_STORE_INIT;
- store.config_reader = &the_reader;
-
/* parse-key returns negative; flip the sign to feed exit(3) */
ret = 0 - git_config_parse_key(key, &store.key, &store.baselen);
if (ret)
@@ -3472,7 +3420,8 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
*/
if (git_config_from_file_with_options(store_aux,
config_filename,
- &store, &opts)) {
+ &store, CONFIG_SCOPE_UNKNOWN,
+ &opts)) {
error(_("invalid config file %s"), config_filename);
ret = CONFIG_INVALID_FILE;
goto out_free;
@@ -3833,6 +3782,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
output[0] = '\t';
}
} else {
+ strbuf_release(&copystr);
copystr = store_create_section(new_name, &store);
}
}
@@ -3879,6 +3829,7 @@ out_no_rollback:
free(filename_buf);
config_store_data_clear(&store);
strbuf_release(&buf);
+ strbuf_release(&copystr);
return ret;
}
@@ -3952,25 +3903,8 @@ int parse_config_key(const char *var,
return 0;
}
-static int reader_origin_type(struct config_reader *reader,
- enum config_origin_type *type)
-{
- if (the_reader.config_kvi)
- *type = reader->config_kvi->origin_type;
- else if(the_reader.source)
- *type = reader->source->origin_type;
- else
- return 1;
- return 0;
-}
-
-const char *current_config_origin_type(void)
+const char *config_origin_type_name(enum config_origin_type type)
{
- enum config_origin_type type = CONFIG_ORIGIN_UNKNOWN;
-
- if (reader_origin_type(&the_reader, &type))
- BUG("current_config_origin_type called outside config callback");
-
switch (type) {
case CONFIG_ORIGIN_BLOB:
return "blob";
@@ -4007,41 +3941,6 @@ const char *config_scope_name(enum config_scope scope)
}
}
-static int reader_config_name(struct config_reader *reader, const char **out)
-{
- if (the_reader.config_kvi)
- *out = reader->config_kvi->filename;
- else if (the_reader.source)
- *out = reader->source->name;
- else
- return 1;
- return 0;
-}
-
-const char *current_config_name(void)
-{
- const char *name;
- if (reader_config_name(&the_reader, &name))
- BUG("current_config_name called outside config callback");
- return name ? name : "";
-}
-
-enum config_scope current_config_scope(void)
-{
- if (the_reader.config_kvi)
- return the_reader.config_kvi->scope;
- else
- return the_reader.parsing_scope;
-}
-
-int current_config_line(void)
-{
- if (the_reader.config_kvi)
- return the_reader.config_kvi->linenr;
- else
- return the_reader.source->linenr;
-}
-
int lookup_config(const char **mapping, int nr_mapping, const char *var)
{
int i;
diff --git a/config.h b/config.h
index 247b572b37..6332d74904 100644
--- a/config.h
+++ b/config.h
@@ -3,6 +3,7 @@
#include "hashmap.h"
#include "string-list.h"
+#include "repository.h"
/**
@@ -49,8 +50,6 @@ const char *config_scope_name(enum config_scope scope);
struct git_config_source {
unsigned int use_stdin:1;
const char *file;
- /* The repository if blob is not NULL; leave blank for the_repository */
- struct repository *repo;
const char *blob;
enum config_scope scope;
};
@@ -73,6 +72,7 @@ enum config_event_t {
CONFIG_EVENT_ERROR
};
+struct config_source;
/*
* The parser event function (if not NULL) is called with the event type and
* the begin/end offsets of the parsed elements.
@@ -82,6 +82,7 @@ enum config_event_t {
*/
typedef int (*config_parser_event_fn_t)(enum config_event_t type,
size_t begin_offset, size_t end_offset,
+ struct config_source *cs,
void *event_fn_data);
struct config_options {
@@ -101,6 +102,10 @@ struct config_options {
const char *commondir;
const char *git_dir;
+ /*
+ * event_fn and event_fn_data are for internal use only. Handles events
+ * emitted by the config parser.
+ */
config_parser_event_fn_t event_fn;
void *event_fn_data;
enum config_error_action {
@@ -111,8 +116,31 @@ struct config_options {
} error_action;
};
+/* Config source metadata for a given config key-value pair */
+struct key_value_info {
+ const char *filename;
+ int linenr;
+ enum config_origin_type origin_type;
+ enum config_scope scope;
+ const char *path;
+};
+#define KVI_INIT { \
+ .filename = NULL, \
+ .linenr = -1, \
+ .origin_type = CONFIG_ORIGIN_UNKNOWN, \
+ .scope = CONFIG_SCOPE_UNKNOWN, \
+ .path = NULL, \
+}
+
+/* Captures additional information that a config callback can use. */
+struct config_context {
+ /* Config source metadata for key and value. */
+ const struct key_value_info *kvi;
+};
+#define CONFIG_CONTEXT_INIT { 0 }
+
/**
- * A config callback function takes three parameters:
+ * A config callback function takes four parameters:
*
* - the name of the parsed variable. This is in canonical "flat" form: the
* section, subsection, and variable segments will be separated by dots,
@@ -123,15 +151,22 @@ struct config_options {
* value specified, the value will be NULL (typically this means it
* should be interpreted as boolean true).
*
+ * - the 'config context', that is, additional information about the config
+ * iteration operation provided by the config machinery. For example, this
+ * includes information about the config source being parsed (e.g. the
+ * filename).
+ *
* - a void pointer passed in by the caller of the config API; this can
* contain callback-specific data
*
* A config callback should return 0 for success, or -1 if the variable
* could not be parsed properly.
*/
-typedef int (*config_fn_t)(const char *, const char *, void *);
+typedef int (*config_fn_t)(const char *, const char *,
+ const struct config_context *, void *);
-int git_default_config(const char *, const char *, void *);
+int git_default_config(const char *, const char *,
+ const struct config_context *, void *);
/**
* Read a specific file in git-config format.
@@ -142,16 +177,18 @@ int git_default_config(const char *, const char *, void *);
int git_config_from_file(config_fn_t fn, const char *, void *);
int git_config_from_file_with_options(config_fn_t fn, const char *,
- void *,
+ void *, enum config_scope,
const struct config_options *);
int git_config_from_mem(config_fn_t fn,
const enum config_origin_type,
const char *name,
const char *buf, size_t len,
- void *data, const struct config_options *opts);
+ void *data, enum config_scope scope,
+ const struct config_options *opts);
int git_config_from_blob_oid(config_fn_t fn, const char *name,
struct repository *repo,
- const struct object_id *oid, void *data);
+ const struct object_id *oid, void *data,
+ enum config_scope scope);
void git_config_push_parameter(const char *text);
void git_config_push_env(const char *spec);
int git_config_from_parameters(config_fn_t fn, void *data);
@@ -196,6 +233,7 @@ void git_config(config_fn_t fn, void *);
*/
int config_with_options(config_fn_t fn, void *,
struct git_config_source *config_source,
+ struct repository *repo,
const struct config_options *opts);
/**
@@ -219,22 +257,26 @@ int git_parse_maybe_bool(const char *);
* Parse the string to an integer, including unit factors. Dies on error;
* otherwise, returns the parsed result.
*/
-int git_config_int(const char *, const char *);
+int git_config_int(const char *, const char *, const struct key_value_info *);
-int64_t git_config_int64(const char *, const char *);
+int64_t git_config_int64(const char *, const char *,
+ const struct key_value_info *);
/**
* Identical to `git_config_int`, but for unsigned longs.
*/
-unsigned long git_config_ulong(const char *, const char *);
+unsigned long git_config_ulong(const char *, const char *,
+ const struct key_value_info *);
-ssize_t git_config_ssize_t(const char *, const char *);
+ssize_t git_config_ssize_t(const char *, const char *,
+ const struct key_value_info *);
/**
* Same as `git_config_bool`, except that integers are returned as-is, and
* an `is_bool` flag is unset.
*/
-int git_config_bool_or_int(const char *, const char *, int *);
+int git_config_bool_or_int(const char *, const char *,
+ const struct key_value_info *, int *);
/**
* Parse a string into a boolean value, respecting keywords like "true" and
@@ -356,10 +398,8 @@ void git_global_config(char **user, char **xdg);
int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
-enum config_scope current_config_scope(void);
-const char *current_config_origin_type(void);
-const char *current_config_name(void);
-int current_config_line(void);
+const char *config_origin_type_name(enum config_origin_type type);
+void kvi_from_param(struct key_value_info *out);
/*
* Match and parse a config key of the form:
@@ -501,7 +541,8 @@ int git_configset_get(struct config_set *cs, const char *key);
* touching `value`. The caller should not free or modify `value`, as it
* is owned by the cache.
*/
-int git_configset_get_value(struct config_set *cs, const char *key, const char **dest);
+int git_configset_get_value(struct config_set *cs, const char *key,
+ const char **dest, struct key_value_info *kvi);
int git_configset_get_string(struct config_set *cs, const char *key, char **dest);
int git_configset_get_int(struct config_set *cs, const char *key, int *dest);
@@ -667,13 +708,6 @@ int git_config_get_expiry(const char *key, const char **output);
/* parse either "this many days" integer, or "5.days.ago" approxidate */
int git_config_get_expiry_in_days(const char *key, timestamp_t *, timestamp_t now);
-struct key_value_info {
- const char *filename;
- int linenr;
- enum config_origin_type origin_type;
- enum config_scope scope;
-};
-
/**
* First prints the error message specified by the caller in `err` and then
* dies printing the line number and the file name of the highest priority
diff --git a/configure.ac b/configure.ac
index 38ff86678a..276593cd9d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -546,6 +546,8 @@ fi
# git-http-push are not built, and you cannot use http:// and https://
# transports.
+if test -z "$NO_CURL"; then
+
GIT_STASH_FLAGS($CURLDIR)
AC_CHECK_LIB([curl], [curl_global_init],
@@ -554,6 +556,8 @@ AC_CHECK_LIB([curl], [curl_global_init],
GIT_UNSTASH_FLAGS($CURLDIR)
+fi
+
GIT_CONF_SUBST([NO_CURL])
if test -z "$NO_CURL"; then
@@ -581,6 +585,8 @@ fi
# Define NO_EXPAT if you do not have expat installed. git-http-push is
# not built, and you cannot push using http:// and https:// transports.
+if test -z "$NO_EXPAT"; then
+
GIT_STASH_FLAGS($EXPATDIR)
AC_CHECK_LIB([expat], [XML_ParserCreate],
@@ -589,6 +595,8 @@ AC_CHECK_LIB([expat], [XML_ParserCreate],
GIT_UNSTASH_FLAGS($EXPATDIR)
+fi
+
GIT_CONF_SUBST([NO_EXPAT])
#
@@ -636,7 +644,6 @@ LIBS="$old_LIBS"
GIT_UNSTASH_FLAGS($ICONVDIR)
GIT_CONF_SUBST([NEEDS_LIBICONV])
-GIT_CONF_SUBST([NO_ICONV])
if test -n "$NO_ICONV"; then
NEEDS_LIBICONV=
@@ -644,6 +651,8 @@ fi
fi
+GIT_CONF_SUBST([NO_ICONV])
+
#
# Define NO_DEFLATE_BOUND if deflateBound is missing from zlib.
diff --git a/connect.c b/connect.c
index 3a0186280c..0d77737a53 100644
--- a/connect.c
+++ b/connect.c
@@ -12,6 +12,7 @@
#include "url.h"
#include "string-list.h"
#include "oid-array.h"
+#include "path.h"
#include "transport.h"
#include "trace2.h"
#include "strbuf.h"
@@ -964,7 +965,7 @@ static struct child_process *git_tcp_connect(int fd[2], char *host, int flags)
static char *git_proxy_command;
static int git_proxy_command_options(const char *var, const char *value,
- void *cb)
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "core.gitproxy")) {
const char *for_pos;
@@ -1010,7 +1011,7 @@ static int git_proxy_command_options(const char *var, const char *value,
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static int git_use_proxy(const char *host)
diff --git a/connected.c b/connected.c
index d672521da4..8f89376dbc 100644
--- a/connected.c
+++ b/connected.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "run-command.h"
#include "sigchain.h"
#include "connected.h"
diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt
index 2f6e0197ff..4faa419cc3 100644
--- a/contrib/buildsystems/CMakeLists.txt
+++ b/contrib/buildsystems/CMakeLists.txt
@@ -227,7 +227,7 @@ add_compile_definitions(GIT_HOST_CPU="${CMAKE_SYSTEM_PROCESSOR}")
add_compile_definitions(SHA256_BLK INTERNAL_QSORT RUNTIME_PREFIX)
add_compile_definitions(NO_OPENSSL SHA1_DC SHA1DC_NO_STANDARD_INCLUDES
SHA1DC_INIT_SAFE_HASH_DEFAULT=0
- SHA1DC_CUSTOM_INCLUDE_SHA1_C="cache.h"
+ SHA1DC_CUSTOM_INCLUDE_SHA1_C="git-compat-util.h"
SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="git-compat-util.h" )
list(APPEND compat_SOURCES sha1dc_git.c sha1dc/sha1.c sha1dc/ubc_check.c block-sha1/sha1.c sha256/block/sha256.c compat/qsort_s.c)
diff --git a/contrib/coccinelle/README b/contrib/coccinelle/README
index d1daa1f626..055ad0e06a 100644
--- a/contrib/coccinelle/README
+++ b/contrib/coccinelle/README
@@ -1,7 +1,9 @@
-This directory provides examples of Coccinelle (http://coccinelle.lip6.fr/)
-semantic patches that might be useful to developers.
+= coccinelle
-There are two types of semantic patches:
+This directory provides Coccinelle (http://coccinelle.lip6.fr/) semantic patches
+that might be useful to developers.
+
+== Types of semantic patches
* Using the semantic transformation to check for bad patterns in the code;
The target 'make coccicheck' is designed to check for these patterns and
@@ -42,7 +44,7 @@ There are two types of semantic patches:
This allows to expose plans of pending large scale refactorings without
impacting the bad pattern checks.
-Git-specific tips & things to know about how we run "spatch":
+== Git-specific tips & things to know about how we run "spatch":
* The "make coccicheck" will piggy-back on
"COMPUTE_HEADER_DEPENDENCIES". If you've built a given object file
@@ -90,3 +92,33 @@ Git-specific tips & things to know about how we run "spatch":
The absolute times will differ for you, but the relative speedup
from caching should be on that order.
+
+== Authoring and reviewing coccinelle changes
+
+* When a .cocci is made, both the Git changes and .cocci file should be
+ reviewed. When reviewing such a change, do your best to understand the .cocci
+ changes (e.g. by asking the author to explain the change) and be explicit
+ about your understanding of the changes. This helps us decide whether input
+ from coccinelle experts is needed or not. If you aren't sure of the cocci
+ changes, indicate what changes you actively endorse and leave an Acked-by
+ (instead of Reviewed-by).
+
+* Authors should consider that reviewers may not be coccinelle experts, thus the
+ the .cocci changes may not be self-evident. A plain text description of the
+ changes is strongly encouraged, especially when using more esoteric features
+ of the language.
+
+* .cocci rules should target only the problem it is trying to solve; "collateral
+ damage" is not allowed. Reviewers should look out and flag overly-broad rules.
+
+* Consider the cost-benefit ratio of .cocci changes. In particular, consider the
+ effect on the runtime of "make coccicheck", and how often your .cocci check
+ will catch something valuable. As a rule of thumb, rules that can bail early
+ if a file doesn't have a particular token will have a small impact on runtime,
+ and vice-versa.
+
+* .cocci files used for refactoring should be temporarily kept in-tree to aid
+ the refactoring of out-of-tree code (e.g. in-flight topics). Periodically
+ evaluate the cost-benefit ratio to determine when the file should be removed.
+ For example, consider how many out-of-tree users are left and how much this
+ slows down "make coccicheck".
diff --git a/contrib/coccinelle/config_fn_ctx.pending.cocci b/contrib/coccinelle/config_fn_ctx.pending.cocci
new file mode 100644
index 0000000000..6d3d1000a9
--- /dev/null
+++ b/contrib/coccinelle/config_fn_ctx.pending.cocci
@@ -0,0 +1,144 @@
+@ get_fn @
+identifier fn, R;
+@@
+(
+(
+git_config_from_file
+|
+git_config_from_file_with_options
+|
+git_config_from_mem
+|
+git_config_from_blob_oid
+|
+read_early_config
+|
+read_very_early_config
+|
+config_with_options
+|
+git_config
+|
+git_protected_config
+|
+config_from_gitmodules
+)
+ (fn, ...)
+|
+repo_config(R, fn, ...)
+)
+
+@ extends get_fn @
+identifier C1, C2, D;
+@@
+int fn(const char *C1, const char *C2,
++ const struct config_context *ctx,
+ void *D);
+
+@ extends get_fn @
+@@
+int fn(const char *, const char *,
++ const struct config_context *,
+ void *);
+
+@ extends get_fn @
+// Don't change fns that look like callback fns but aren't
+identifier fn2 != tar_filter_config && != git_diff_heuristic_config &&
+ != git_default_submodule_config && != git_color_config &&
+ != bundle_list_update && != parse_object_filter_config;
+identifier C1, C2, D1, D2, S;
+attribute name UNUSED;
+@@
+int fn(const char *C1, const char *C2,
++ const struct config_context *ctx,
+ void *D1) {
+<+...
+(
+fn2(C1, C2
++ , ctx
+, D2);
+|
+if(fn2(C1, C2
++ , ctx
+, D2) < 0) { ... }
+|
+return fn2(C1, C2
++ , ctx
+, D2);
+|
+S = fn2(C1, C2
++ , ctx
+, D2);
+)
+...+>
+ }
+
+@ extends get_fn@
+identifier C1, C2, D;
+attribute name UNUSED;
+@@
+int fn(const char *C1, const char *C2,
++ const struct config_context *ctx UNUSED,
+ void *D) {...}
+
+
+// The previous rules don't catch all callbacks, especially if they're defined
+// in a separate file from the git_config() call. Fix these manually.
+@@
+identifier C1, C2, D;
+attribute name UNUSED;
+@@
+int
+(
+git_ident_config
+|
+urlmatch_collect_fn
+|
+write_one_config
+|
+forbid_remote_url
+|
+credential_config_callback
+)
+ (const char *C1, const char *C2,
++ const struct config_context *ctx UNUSED,
+ void *D) {...}
+
+@@
+identifier C1, C2, D, D2, S, fn2;
+@@
+int
+(
+http_options
+|
+git_status_config
+|
+git_commit_config
+|
+git_default_core_config
+|
+grep_config
+)
+ (const char *C1, const char *C2,
++ const struct config_context *ctx,
+ void *D) {
+<+...
+(
+fn2(C1, C2
++ , ctx
+, D2);
+|
+if(fn2(C1, C2
++ , ctx
+, D2) < 0) { ... }
+|
+return fn2(C1, C2
++ , ctx
+, D2);
+|
+S = fn2(C1, C2
++ , ctx
+, D2);
+)
+...+>
+ }
diff --git a/contrib/coccinelle/git_config_number.cocci b/contrib/coccinelle/git_config_number.cocci
new file mode 100644
index 0000000000..7b57dceefe
--- /dev/null
+++ b/contrib/coccinelle/git_config_number.cocci
@@ -0,0 +1,27 @@
+@@
+identifier C1, C2, C3;
+@@
+(
+(
+git_config_int
+|
+git_config_int64
+|
+git_config_ulong
+|
+git_config_ssize_t
+)
+ (C1, C2
++ , ctx->kvi
+ )
+|
+(
+git_configset_get_value
+|
+git_config_bool_or_int
+)
+ (C1, C2
++ , ctx->kvi
+ , C3
+ )
+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index dc95c34cc8..133ec92bfa 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -767,7 +767,7 @@ __git_refs ()
track=""
;;
*)
- for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD; do
+ for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD REVERT_HEAD BISECT_HEAD AUTO_MERGE; do
case "$i" in
$match*|$umatch*)
if [ -e "$dir/$i" ]; then
@@ -1733,32 +1733,44 @@ __git_color_moved_opts="no default plain blocks zebra dimmed-zebra"
__git_color_moved_ws_opts="no ignore-space-at-eol ignore-space-change
ignore-all-space allow-indentation-change"
+__git_ws_error_highlight_opts="context old new all default"
+
+# Options for the diff machinery (diff, log, show, stash, range-diff, ...)
__git_diff_common_options="--stat --numstat --shortstat --summary
--patch-with-stat --name-only --name-status --color
--no-color --color-words --no-renames --check
--color-moved --color-moved= --no-color-moved
--color-moved-ws= --no-color-moved-ws
--full-index --binary --abbrev --diff-filter=
+ --find-copies --find-object --find-renames
+ --no-relative --relative
--find-copies-harder --ignore-cr-at-eol
--text --ignore-space-at-eol --ignore-space-change
--ignore-all-space --ignore-blank-lines --exit-code
- --quiet --ext-diff --no-ext-diff
+ --quiet --ext-diff --no-ext-diff --unified=
--no-prefix --src-prefix= --dst-prefix=
- --inter-hunk-context=
+ --inter-hunk-context= --function-context
--patience --histogram --minimal
--raw --word-diff --word-diff-regex=
--dirstat --dirstat= --dirstat-by-file
--dirstat-by-file= --cumulative
- --diff-algorithm=
+ --diff-algorithm= --default-prefix
--submodule --submodule= --ignore-submodules
--indent-heuristic --no-indent-heuristic
- --textconv --no-textconv
- --patch --no-patch
- --anchored=
+ --textconv --no-textconv --break-rewrites
+ --patch --no-patch --cc --combined-all-paths
+ --anchored= --compact-summary --ignore-matching-lines=
+ --irreversible-delete --line-prefix --no-stat
+ --output= --output-indicator-context=
+ --output-indicator-new= --output-indicator-old=
+ --ws-error-highlight=
+ --pickaxe-all --pickaxe-regex
"
-__git_diff_difftool_options="--cached --staged --pickaxe-all --pickaxe-regex
- --base --ours --theirs --no-index --relative --merge-base
+# Options for diff/difftool
+__git_diff_difftool_options="--cached --staged
+ --base --ours --theirs --no-index --merge-base
+ --ita-invisible-in-index --ita-visible-in-index
$__git_diff_common_options"
_git_diff ()
@@ -1782,6 +1794,10 @@ _git_diff ()
__gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
return
;;
+ --ws-error-highlight=*)
+ __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
+ return
+ ;;
--*)
__gitcomp "$__git_diff_difftool_options"
return
@@ -2024,6 +2040,12 @@ __git_log_shortlog_options="
--author= --committer= --grep=
--all-match --invert-grep
"
+# Options accepted by log and show
+__git_log_show_options="
+ --diff-merges --diff-merges= --no-diff-merges --remerge-diff
+"
+
+__git_diff_merges_opts="off none on first-parent 1 separate m combined c dense-combined cc remerge r"
__git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
__git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default human raw unix auto: format:"
@@ -2072,15 +2094,24 @@ _git_log ()
__gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
return
;;
+ --ws-error-highlight=*)
+ __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
+ return
+ ;;
--no-walk=*)
__gitcomp "sorted unsorted" "" "${cur##--no-walk=}"
return
;;
+ --diff-merges=*)
+ __gitcomp "$__git_diff_merges_opts" "" "${cur##--diff-merges=}"
+ return
+ ;;
--*)
__gitcomp "
$__git_log_common_options
$__git_log_shortlog_options
$__git_log_gitk_options
+ $__git_log_show_options
--root --topo-order --date-order --reverse
--follow --full-diff
--abbrev-commit --no-abbrev-commit --abbrev=
@@ -2097,7 +2128,6 @@ _git_log ()
--expand-tabs --expand-tabs= --no-expand-tabs
$merge
$__git_diff_common_options
- --pickaxe-all --pickaxe-regex
"
return
;;
@@ -2992,10 +3022,19 @@ _git_show ()
__gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
return
;;
+ --ws-error-highlight=*)
+ __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
+ return
+ ;;
+ --diff-merges=*)
+ __gitcomp "$__git_diff_merges_opts" "" "${cur##--diff-merges=}"
+ return
+ ;;
--*)
__gitcomp "--pretty= --format= --abbrev-commit --no-abbrev-commit
--oneline --show-signature
--expand-tabs --expand-tabs= --no-expand-tabs
+ $__git_log_show_options
$__git_diff_common_options
"
return
diff --git a/convert.c b/convert.c
index 9ee79fe469..a8870baff3 100644
--- a/convert.c
+++ b/convert.c
@@ -1,21 +1,21 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "advice.h"
#include "config.h"
#include "convert.h"
#include "copy.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "attr.h"
#include "run-command.h"
#include "quote.h"
+#include "read-cache-ll.h"
#include "sigchain.h"
#include "pkt-line.h"
#include "sub-process.h"
#include "trace.h"
#include "utf8.h"
-#include "ll-merge.h"
-#include "wrapper.h"
+#include "merge-ll.h"
/*
* convert.c - convert a file when checking it out and checking it in.
@@ -633,23 +633,21 @@ static int filter_buffer_or_fd(int in UNUSED, int out, void *data)
*/
struct child_process child_process = CHILD_PROCESS_INIT;
struct filter_params *params = (struct filter_params *)data;
+ const char *format = params->cmd;
int write_err, status;
/* apply % substitution to cmd */
struct strbuf cmd = STRBUF_INIT;
- struct strbuf path = STRBUF_INIT;
- struct strbuf_expand_dict_entry dict[] = {
- { "f", NULL, },
- { NULL, NULL, },
- };
-
- /* quote the path to preserve spaces, etc. */
- sq_quote_buf(&path, params->path);
- dict[0].value = path.buf;
- /* expand all %f with the quoted path */
- strbuf_expand(&cmd, params->cmd, strbuf_expand_dict_cb, &dict);
- strbuf_release(&path);
+ /* expand all %f with the quoted path; quote to preserve space, etc. */
+ while (strbuf_expand_step(&cmd, &format)) {
+ if (skip_prefix(format, "%", &format))
+ strbuf_addch(&cmd, '%');
+ else if (skip_prefix(format, "f", &format))
+ sq_quote_buf(&cmd, params->path);
+ else
+ strbuf_addch(&cmd, '%');
+ }
strvec_push(&child_process.args, cmd.buf);
child_process.use_shell = 1;
@@ -1015,7 +1013,9 @@ static int apply_filter(const char *path, const char *src, size_t len,
return 0;
}
-static int read_convert_config(const char *var, const char *value, void *cb UNUSED)
+static int read_convert_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb UNUSED)
{
const char *key, *name;
size_t namelen;
diff --git a/copy.c b/copy.c
index 882c79cffb..23d84c6c1d 100644
--- a/copy.c
+++ b/copy.c
@@ -1,7 +1,6 @@
#include "git-compat-util.h"
#include "copy.h"
#include "path.h"
-#include "wrapper.h"
int copy_fd(int ifd, int ofd)
{
diff --git a/credential.c b/credential.c
index 023b59d571..d664754163 100644
--- a/credential.c
+++ b/credential.c
@@ -33,13 +33,14 @@ void credential_clear(struct credential *c)
}
int credential_match(const struct credential *want,
- const struct credential *have)
+ const struct credential *have, int match_password)
{
#define CHECK(x) (!want->x || (have->x && !strcmp(want->x, have->x)))
return CHECK(protocol) &&
CHECK(host) &&
CHECK(path) &&
- CHECK(username);
+ CHECK(username) &&
+ (!match_password || CHECK(password));
#undef CHECK
}
@@ -48,6 +49,7 @@ static int credential_from_potentially_partial_url(struct credential *c,
const char *url);
static int credential_config_callback(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *data)
{
struct credential *c = data;
@@ -102,7 +104,7 @@ static int match_partial_url(const char *url, void *cb)
warning(_("skipping credential lookup for key: credential.%s"),
url);
else
- matches = credential_match(&want, c);
+ matches = credential_match(&want, c, 0);
credential_clear(&want);
return matches;
diff --git a/credential.h b/credential.h
index b8e2936d1d..acc41adf54 100644
--- a/credential.h
+++ b/credential.h
@@ -211,6 +211,6 @@ void credential_from_url(struct credential *, const char *url);
int credential_from_url_gently(struct credential *, const char *url, int quiet);
int credential_match(const struct credential *want,
- const struct credential *have);
+ const struct credential *have, int match_password);
#endif /* CREDENTIAL_H */
diff --git a/csum-file.c b/csum-file.c
index daf9b06dff..cd01713244 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -11,7 +11,6 @@
#include "progress.h"
#include "csum-file.h"
#include "hash.h"
-#include "wrapper.h"
static void verify_buffer_or_die(struct hashfile *f,
const void *buf,
diff --git a/ctype.c b/ctype.c
index fc0225cebd..3451745550 100644
--- a/ctype.c
+++ b/ctype.c
@@ -28,39 +28,3 @@ const unsigned char sane_ctype[256] = {
A, A, A, A, A, A, A, A, A, A, A, R, R, U, P, X, /* 112..127 */
/* Nothing in the 128.. range */
};
-
-/* For case-insensitive kwset */
-const unsigned char tolower_trans_tbl[256] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
- ' ', '!', '"', '#', '$', '%', '&', 0x27,
- '(', ')', '*', '+', ',', '-', '.', '/',
- '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', ':', ';', '<', '=', '>', '?',
- '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
- 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
- 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
- 'x', 'y', 'z', '[', 0x5c, ']', '^', '_',
- '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
- 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
- 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
- 'x', 'y', 'z', '{', '|', '}', '~', 0x7f,
- 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
- 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
- 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
- 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
- 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
- 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
- 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
- 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
- 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
- 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
- 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
- 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
- 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
- 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
- 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
- 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
-};
diff --git a/daemon.c b/daemon.c
index 7139cc201d..f5e597114b 100644
--- a/daemon.c
+++ b/daemon.c
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "path.h"
@@ -10,7 +9,6 @@
#include "setup.h"
#include "strbuf.h"
#include "string-list.h"
-#include "wrapper.h"
#ifdef NO_INITGROUPS
#define initgroups(x, y) (0) /* nothing */
@@ -144,42 +142,6 @@ static void NORETURN daemon_die(const char *err, va_list params)
exit(1);
}
-struct expand_path_context {
- const char *directory;
- struct hostinfo *hostinfo;
-};
-
-static size_t expand_path(struct strbuf *sb, const char *placeholder, void *ctx)
-{
- struct expand_path_context *context = ctx;
- struct hostinfo *hi = context->hostinfo;
-
- switch (placeholder[0]) {
- case 'H':
- strbuf_addbuf(sb, &hi->hostname);
- return 1;
- case 'C':
- if (placeholder[1] == 'H') {
- strbuf_addstr(sb, get_canon_hostname(hi));
- return 2;
- }
- break;
- case 'I':
- if (placeholder[1] == 'P') {
- strbuf_addstr(sb, get_ip_address(hi));
- return 2;
- }
- break;
- case 'P':
- strbuf_addbuf(sb, &hi->tcp_port);
- return 1;
- case 'D':
- strbuf_addstr(sb, context->directory);
- return 1;
- }
- return 0;
-}
-
static const char *path_ok(const char *directory, struct hostinfo *hi)
{
static char rpath[PATH_MAX];
@@ -223,10 +185,7 @@ static const char *path_ok(const char *directory, struct hostinfo *hi)
}
else if (interpolated_path && hi->saw_extended_args) {
struct strbuf expanded_path = STRBUF_INIT;
- struct expand_path_context context;
-
- context.directory = directory;
- context.hostinfo = hi;
+ const char *format = interpolated_path;
if (*dir != '/') {
/* Allow only absolute */
@@ -234,8 +193,24 @@ static const char *path_ok(const char *directory, struct hostinfo *hi)
return NULL;
}
- strbuf_expand(&expanded_path, interpolated_path,
- expand_path, &context);
+ while (strbuf_expand_step(&expanded_path, &format)) {
+ if (skip_prefix(format, "%", &format))
+ strbuf_addch(&expanded_path, '%');
+ else if (skip_prefix(format, "H", &format))
+ strbuf_addbuf(&expanded_path, &hi->hostname);
+ else if (skip_prefix(format, "CH", &format))
+ strbuf_addstr(&expanded_path,
+ get_canon_hostname(hi));
+ else if (skip_prefix(format, "IP", &format))
+ strbuf_addstr(&expanded_path,
+ get_ip_address(hi));
+ else if (skip_prefix(format, "P", &format))
+ strbuf_addbuf(&expanded_path, &hi->tcp_port);
+ else if (skip_prefix(format, "D", &format))
+ strbuf_addstr(&expanded_path, directory);
+ else
+ strbuf_addch(&expanded_path, '%');
+ }
rlen = strlcpy(interp_path, expanded_path.buf,
sizeof(interp_path));
diff --git a/decorate.c b/decorate.c
index 71e79daa82..a5c43c0c14 100644
--- a/decorate.c
+++ b/decorate.c
@@ -3,7 +3,6 @@
* data.
*/
#include "git-compat-util.h"
-#include "hashmap.h"
#include "object.h"
#include "decorate.h"
diff --git a/delta-islands.c b/delta-islands.c
index c824a5f6a4..5de5759f3f 100644
--- a/delta-islands.c
+++ b/delta-islands.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "attr.h"
#include "object.h"
#include "blob.h"
@@ -341,7 +340,9 @@ static void free_remote_islands(kh_str_t *remote_islands)
kh_destroy_str(remote_islands);
}
-static int island_config_callback(const char *k, const char *v, void *cb)
+static int island_config_callback(const char *k, const char *v,
+ const struct config_context *ctx UNUSED,
+ void *cb)
{
struct island_load_data *ild = cb;
diff --git a/diagnose.c b/diagnose.c
index c8c7ebcfa3..8430064000 100644
--- a/diagnose.c
+++ b/diagnose.c
@@ -7,7 +7,7 @@
#include "gettext.h"
#include "hex.h"
#include "strvec.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "packfile.h"
#include "parse-options.h"
#include "write-or-die.h"
diff --git a/diff-lib.c b/diff-lib.c
index 60e979dc1b..6b0c6a7180 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -1,18 +1,21 @@
/*
* Copyright (C) 2005 Junio C Hamano
*/
-#include "cache.h"
+#include "git-compat-util.h"
#include "quote.h"
#include "commit.h"
#include "diff.h"
#include "diffcore.h"
#include "gettext.h"
+#include "hash.h"
#include "hex.h"
#include "object-name.h"
+#include "read-cache.h"
#include "revision.h"
#include "cache-tree.h"
#include "unpack-trees.h"
#include "refs.h"
+#include "repository.h"
#include "submodule.h"
#include "symlinks.h"
#include "trace.h"
@@ -669,8 +672,15 @@ int index_differs_from(struct repository *r,
setup_revisions(0, NULL, &rev, &opt);
rev.diffopt.flags.quick = 1;
rev.diffopt.flags.exit_with_status = 1;
- if (flags)
+ if (flags) {
diff_flags_or(&rev.diffopt.flags, flags);
+ /*
+ * Now that flags are merged, honor override_submodule_config
+ * and ignore_submodules from passed flags.
+ */
+ if (flags->override_submodule_config)
+ rev.diffopt.flags.ignore_submodules = flags->ignore_submodules;
+ }
rev.diffopt.ita_invisible_in_index = ita_invisible_in_index;
run_diff_index(&rev, 1);
has_changes = rev.diffopt.flags.has_changes;
diff --git a/diff-no-index.c b/diff-no-index.c
index 4296940f90..4771cf02aa 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -41,42 +41,81 @@ static int read_directory_contents(const char *path, struct string_list *list)
*/
static const char file_from_standard_input[] = "-";
-static int get_mode(const char *path, int *mode)
+/*
+ * For paths given on the command-line we treat "-" as stdin and named
+ * pipes and symbolic links to named pipes specially.
+ */
+enum special {
+ SPECIAL_NONE,
+ SPECIAL_STDIN,
+ SPECIAL_PIPE,
+};
+
+static int get_mode(const char *path, int *mode, enum special *special)
{
struct stat st;
- if (!path || !strcmp(path, "/dev/null"))
+ if (!path || !strcmp(path, "/dev/null")) {
*mode = 0;
#ifdef GIT_WINDOWS_NATIVE
- else if (!strcasecmp(path, "nul"))
+ } else if (!strcasecmp(path, "nul")) {
*mode = 0;
#endif
- else if (path == file_from_standard_input)
+ } else if (path == file_from_standard_input) {
*mode = create_ce_mode(0666);
- else if (lstat(path, &st))
+ *special = SPECIAL_STDIN;
+ } else if (lstat(path, &st)) {
return error("Could not access '%s'", path);
- else
+ } else {
*mode = st.st_mode;
+ }
+ /*
+ * For paths on the command-line treat named pipes and symbolic
+ * links that resolve to a named pipe specially.
+ */
+ if (special &&
+ (S_ISFIFO(*mode) ||
+ (S_ISLNK(*mode) && !stat(path, &st) && S_ISFIFO(st.st_mode)))) {
+ *mode = create_ce_mode(0666);
+ *special = SPECIAL_PIPE;
+ }
+
return 0;
}
-static int populate_from_stdin(struct diff_filespec *s)
+static void populate_common(struct diff_filespec *s, struct strbuf *buf)
{
- struct strbuf buf = STRBUF_INIT;
size_t size = 0;
- if (strbuf_read(&buf, 0, 0) < 0)
- return error_errno("error while reading from stdin");
-
s->should_munmap = 0;
- s->data = strbuf_detach(&buf, &size);
+ s->data = strbuf_detach(buf, &size);
s->size = size;
s->should_free = 1;
s->is_stdin = 1;
- return 0;
}
-static struct diff_filespec *noindex_filespec(const char *name, int mode)
+static void populate_from_pipe(struct diff_filespec *s)
+{
+ struct strbuf buf = STRBUF_INIT;
+ int fd = xopen(s->path, O_RDONLY);
+
+ if (strbuf_read(&buf, fd, 0) < 0)
+ die_errno("error while reading from '%s'", s->path);
+ close(fd);
+ populate_common(s, &buf);
+}
+
+static void populate_from_stdin(struct diff_filespec *s)
+{
+ struct strbuf buf = STRBUF_INIT;
+
+ if (strbuf_read(&buf, 0, 0) < 0)
+ die_errno("error while reading from stdin");
+ populate_common(s, &buf);
+}
+
+static struct diff_filespec *noindex_filespec(const char *name, int mode,
+ enum special special)
{
struct diff_filespec *s;
@@ -84,17 +123,22 @@ static struct diff_filespec *noindex_filespec(const char *name, int mode)
name = "/dev/null";
s = alloc_filespec(name);
fill_filespec(s, null_oid(), 0, mode);
- if (name == file_from_standard_input)
+ if (special == SPECIAL_STDIN)
populate_from_stdin(s);
+ else if (special == SPECIAL_PIPE)
+ populate_from_pipe(s);
return s;
}
static int queue_diff(struct diff_options *o,
- const char *name1, const char *name2)
+ const char *name1, const char *name2, int recursing)
{
int mode1 = 0, mode2 = 0;
+ enum special special1 = SPECIAL_NONE, special2 = SPECIAL_NONE;
- if (get_mode(name1, &mode1) || get_mode(name2, &mode2))
+ /* Paths can only be special if we're not recursing. */
+ if (get_mode(name1, &mode1, recursing ? NULL : &special1) ||
+ get_mode(name2, &mode2, recursing ? NULL : &special2))
return -1;
if (mode1 && mode2 && S_ISDIR(mode1) != S_ISDIR(mode2)) {
@@ -102,14 +146,14 @@ static int queue_diff(struct diff_options *o,
if (S_ISDIR(mode1)) {
/* 2 is file that is created */
- d1 = noindex_filespec(NULL, 0);
- d2 = noindex_filespec(name2, mode2);
+ d1 = noindex_filespec(NULL, 0, SPECIAL_NONE);
+ d2 = noindex_filespec(name2, mode2, special2);
name2 = NULL;
mode2 = 0;
} else {
/* 1 is file that is deleted */
- d1 = noindex_filespec(name1, mode1);
- d2 = noindex_filespec(NULL, 0);
+ d1 = noindex_filespec(name1, mode1, special1);
+ d2 = noindex_filespec(NULL, 0, SPECIAL_NONE);
name1 = NULL;
mode1 = 0;
}
@@ -174,7 +218,7 @@ static int queue_diff(struct diff_options *o,
n2 = buffer2.buf;
}
- ret = queue_diff(o, n1, n2);
+ ret = queue_diff(o, n1, n2, 1);
}
string_list_clear(&p1, 0);
string_list_clear(&p2, 0);
@@ -190,8 +234,8 @@ static int queue_diff(struct diff_options *o,
SWAP(name1, name2);
}
- d1 = noindex_filespec(name1, mode1);
- d2 = noindex_filespec(name2, mode2);
+ d1 = noindex_filespec(name1, mode1, special1);
+ d2 = noindex_filespec(name2, mode2, special2);
diff_queue(&diff_queued_diff, d1, d2);
return 0;
}
@@ -216,13 +260,27 @@ static void append_basename(struct strbuf *path, const char *dir, const char *fi
*/
static void fixup_paths(const char **path, struct strbuf *replacement)
{
- unsigned int isdir0, isdir1;
+ struct stat st;
+ unsigned int isdir0 = 0, isdir1 = 0;
+ unsigned int ispipe0 = 0, ispipe1 = 0;
+
+ if (path[0] != file_from_standard_input && !stat(path[0], &st)) {
+ isdir0 = S_ISDIR(st.st_mode);
+ ispipe0 = S_ISFIFO(st.st_mode);
+ }
+
+ if (path[1] != file_from_standard_input && !stat(path[1], &st)) {
+ isdir1 = S_ISDIR(st.st_mode);
+ ispipe1 = S_ISFIFO(st.st_mode);
+ }
+
+ if ((path[0] == file_from_standard_input && isdir1) ||
+ (isdir0 && path[1] == file_from_standard_input))
+ die(_("cannot compare stdin to a directory"));
+
+ if ((isdir0 && ispipe1) || (ispipe0 && isdir1))
+ die(_("cannot compare a named pipe to a directory"));
- if (path[0] == file_from_standard_input ||
- path[1] == file_from_standard_input)
- return;
- isdir0 = is_directory(path[0]);
- isdir1 = is_directory(path[1]);
if (isdir0 == isdir1)
return;
if (isdir0) {
@@ -296,7 +354,7 @@ int diff_no_index(struct rev_info *revs,
setup_diff_pager(&revs->diffopt);
revs->diffopt.flags.exit_with_status = 1;
- if (queue_diff(&revs->diffopt, paths[0], paths[1]))
+ if (queue_diff(&revs->diffopt, paths[0], paths[1], 0))
goto out;
diff_set_mnemonic_prefix(&revs->diffopt, "1/", "2/");
diffcore_std(&revs->diffopt);
diff --git a/diff.c b/diff.c
index 3c88c37908..ee3eb629e3 100644
--- a/diff.c
+++ b/diff.c
@@ -1,9 +1,8 @@
/*
* Copyright (C) 2005 Junio C Hamano
*/
-#include "cache.h"
+#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "base85.h"
#include "config.h"
#include "convert.h"
@@ -20,13 +19,13 @@
#include "attr.h"
#include "run-command.h"
#include "utf8.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "userdiff.h"
#include "submodule-config.h"
#include "submodule.h"
#include "hashmap.h"
#include "mem-pool.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
#include "string-list.h"
#include "strvec.h"
#include "graph.h"
@@ -39,10 +38,10 @@
#include "dir.h"
#include "object-file.h"
#include "object-name.h"
+#include "read-cache-ll.h"
#include "setup.h"
#include "strmap.h"
#include "ws.h"
-#include "wrapper.h"
#ifdef NO_FAST_WORKING_DIRECTORY
#define FAST_WORKING_DIRECTORY 0
@@ -357,7 +356,8 @@ static unsigned parse_color_moved_ws(const char *arg)
return ret;
}
-int git_diff_ui_config(const char *var, const char *value, void *cb)
+int git_diff_ui_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
diff_use_color_default = git_config_colorbool(var, value);
@@ -378,13 +378,14 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
return 0;
}
if (!strcmp(var, "diff.context")) {
- diff_context_default = git_config_int(var, value);
+ diff_context_default = git_config_int(var, value, ctx->kvi);
if (diff_context_default < 0)
return -1;
return 0;
}
if (!strcmp(var, "diff.interhunkcontext")) {
- diff_interhunk_context_default = git_config_int(var, value);
+ diff_interhunk_context_default = git_config_int(var, value,
+ ctx->kvi);
if (diff_interhunk_context_default < 0)
return -1;
return 0;
@@ -410,7 +411,7 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
return 0;
}
if (!strcmp(var, "diff.statgraphwidth")) {
- diff_stat_graph_width = git_config_int(var, value);
+ diff_stat_graph_width = git_config_int(var, value, ctx->kvi);
return 0;
}
if (!strcmp(var, "diff.external"))
@@ -440,15 +441,16 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
if (git_color_config(var, value, cb) < 0)
return -1;
- return git_diff_basic_config(var, value, cb);
+ return git_diff_basic_config(var, value, ctx, cb);
}
-int git_diff_basic_config(const char *var, const char *value, void *cb)
+int git_diff_basic_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
const char *name;
if (!strcmp(var, "diff.renamelimit")) {
- diff_rename_limit_default = git_config_int(var, value);
+ diff_rename_limit_default = git_config_int(var, value, ctx->kvi);
return 0;
}
@@ -495,7 +497,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
if (git_diff_heuristic_config(var, value, cb) < 0)
return -1;
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static char *quote_two(const char *one, const char *two)
@@ -4751,6 +4753,31 @@ unsigned diff_filter_bit(char status)
return filter_bit[(int) status];
}
+int diff_check_follow_pathspec(struct pathspec *ps, int die_on_error)
+{
+ unsigned forbidden_magic;
+
+ if (ps->nr != 1) {
+ if (die_on_error)
+ die(_("--follow requires exactly one pathspec"));
+ return 0;
+ }
+
+ forbidden_magic = ps->items[0].magic & ~(PATHSPEC_FROMTOP |
+ PATHSPEC_LITERAL);
+ if (forbidden_magic) {
+ if (die_on_error) {
+ struct strbuf sb = STRBUF_INIT;
+ pathspec_magic_names(forbidden_magic, &sb);
+ die(_("pathspec magic not supported by --follow: %s"),
+ sb.buf);
+ }
+ return 0;
+ }
+
+ return 1;
+}
+
void diff_setup_done(struct diff_options *options)
{
unsigned check_mask = DIFF_FORMAT_NAME |
@@ -4858,8 +4885,8 @@ void diff_setup_done(struct diff_options *options)
options->diff_path_counter = 0;
- if (options->flags.follow_renames && options->pathspec.nr != 1)
- die(_("--follow requires exactly one pathspec"));
+ if (options->flags.follow_renames)
+ diff_check_follow_pathspec(&options->pathspec, 1);
if (!options->use_color || external_diff())
options->color_moved = 0;
@@ -4936,6 +4963,7 @@ static int diff_opt_stat(const struct option *opt, const char *value, int unset)
} else
BUG("%s should not get here", opt->long_name);
+ options->output_format &= ~DIFF_FORMAT_NO_OUTPUT;
options->output_format |= DIFF_FORMAT_DIFFSTAT;
options->stat_name_width = name_width;
options->stat_graph_width = graph_width;
@@ -4955,6 +4983,7 @@ static int parse_dirstat_opt(struct diff_options *options, const char *params)
* The caller knows a dirstat-related option is given from the command
* line; allow it to say "return this_function();"
*/
+ options->output_format &= ~DIFF_FORMAT_NO_OUTPUT;
options->output_format |= DIFF_FORMAT_DIRSTAT;
return 1;
}
@@ -5154,6 +5183,7 @@ static int diff_opt_compact_summary(const struct option *opt,
options->flags.stat_with_summary = 0;
} else {
options->flags.stat_with_summary = 1;
+ options->output_format &= ~DIFF_FORMAT_NO_OUTPUT;
options->output_format |= DIFF_FORMAT_DIFFSTAT;
}
return 0;
@@ -5491,6 +5521,10 @@ static int diff_opt_rotate_to(const struct option *opt, const char *arg, int uns
return 0;
}
+/*
+ * Consider adding new flags to __git_diff_common_options
+ * in contrib/completion/git-completion.bash
+ */
struct option *add_diff_options(const struct option *opts,
struct diff_options *options)
{
@@ -5499,9 +5533,8 @@ struct option *add_diff_options(const struct option *opts,
OPT_BITOP('p', "patch", &options->output_format,
N_("generate patch"),
DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT),
- OPT_BIT_F('s', "no-patch", &options->output_format,
- N_("suppress diff output"),
- DIFF_FORMAT_NO_OUTPUT, PARSE_OPT_NONEG),
+ OPT_SET_INT('s', "no-patch", &options->output_format,
+ N_("suppress diff output"), DIFF_FORMAT_NO_OUTPUT),
OPT_BITOP('u', NULL, &options->output_format,
N_("generate patch"),
DIFF_FORMAT_PATCH, DIFF_FORMAT_NO_OUTPUT),
@@ -5510,9 +5543,9 @@ struct option *add_diff_options(const struct option *opts,
PARSE_OPT_NONEG | PARSE_OPT_OPTARG, diff_opt_unified),
OPT_BOOL('W', "function-context", &options->flags.funccontext,
N_("generate diffs with <n> lines context")),
- OPT_BIT_F(0, "raw", &options->output_format,
+ OPT_BITOP(0, "raw", &options->output_format,
N_("generate the diff in raw format"),
- DIFF_FORMAT_RAW, PARSE_OPT_NONEG),
+ DIFF_FORMAT_RAW, DIFF_FORMAT_NO_OUTPUT),
OPT_BITOP(0, "patch-with-raw", &options->output_format,
N_("synonym for '-p --raw'"),
DIFF_FORMAT_PATCH | DIFF_FORMAT_RAW,
@@ -5521,12 +5554,12 @@ struct option *add_diff_options(const struct option *opts,
N_("synonym for '-p --stat'"),
DIFF_FORMAT_PATCH | DIFF_FORMAT_DIFFSTAT,
DIFF_FORMAT_NO_OUTPUT),
- OPT_BIT_F(0, "numstat", &options->output_format,
+ OPT_BITOP(0, "numstat", &options->output_format,
N_("machine friendly --stat"),
- DIFF_FORMAT_NUMSTAT, PARSE_OPT_NONEG),
- OPT_BIT_F(0, "shortstat", &options->output_format,
+ DIFF_FORMAT_NUMSTAT, DIFF_FORMAT_NO_OUTPUT),
+ OPT_BITOP(0, "shortstat", &options->output_format,
N_("output only the last line of --stat"),
- DIFF_FORMAT_SHORTSTAT, PARSE_OPT_NONEG),
+ DIFF_FORMAT_SHORTSTAT, DIFF_FORMAT_NO_OUTPUT),
OPT_CALLBACK_F('X', "dirstat", options, N_("<param1,param2>..."),
N_("output the distribution of relative amount of changes for each sub-directory"),
PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
@@ -5542,9 +5575,9 @@ struct option *add_diff_options(const struct option *opts,
OPT_BIT_F(0, "check", &options->output_format,
N_("warn if changes introduce conflict markers or whitespace errors"),
DIFF_FORMAT_CHECKDIFF, PARSE_OPT_NONEG),
- OPT_BIT_F(0, "summary", &options->output_format,
+ OPT_BITOP(0, "summary", &options->output_format,
N_("condensed summary such as creations, renames and mode changes"),
- DIFF_FORMAT_SUMMARY, PARSE_OPT_NONEG),
+ DIFF_FORMAT_SUMMARY, DIFF_FORMAT_NO_OUTPUT),
OPT_BIT_F(0, "name-only", &options->output_format,
N_("show only names of changed files"),
DIFF_FORMAT_NAME, PARSE_OPT_NONEG),
diff --git a/diff.h b/diff.h
index 3a7a9e8b88..260c454155 100644
--- a/diff.h
+++ b/diff.h
@@ -4,10 +4,12 @@
#ifndef DIFF_H
#define DIFF_H
+#include "hash-ll.h"
#include "pathspec.h"
-#include "oidset.h"
#include "strbuf.h"
+struct oidset;
+
/**
* The diff API is for programs that compare two sets of files (e.g. two trees,
* one tree and the index) and present the found difference in various ways.
@@ -531,14 +533,24 @@ void free_diffstat_info(struct diffstat_t *diffstat);
int parse_long_opt(const char *opt, const char **argv,
const char **optarg);
-int git_diff_basic_config(const char *var, const char *value, void *cb);
+struct config_context;
+int git_diff_basic_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb);
int git_diff_heuristic_config(const char *var, const char *value, void *cb);
void init_diff_ui_defaults(void);
-int git_diff_ui_config(const char *var, const char *value, void *cb);
+int git_diff_ui_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb);
void repo_diff_setup(struct repository *, struct diff_options *);
struct option *add_diff_options(const struct option *, struct diff_options *);
int diff_opt_parse(struct diff_options *, const char **, int, const char *);
void diff_setup_done(struct diff_options *);
+
+/*
+ * Returns true if the pathspec can work with --follow mode. If die_on_error is
+ * set, die() with a specific error message rather than returning false.
+ */
+int diff_check_follow_pathspec(struct pathspec *ps, int die_on_error);
+
int git_config_rename(const char *var, const char *value);
#define DIFF_DETECT_RENAME 1
@@ -694,4 +706,6 @@ void print_stat_summary(FILE *fp, int files,
int insertions, int deletions);
void setup_diff_pager(struct diff_options *);
+extern int diff_auto_refresh_index;
+
#endif /* DIFF_H */
diff --git a/diffcore-break.c b/diffcore-break.c
index 5462420bbb..f57ece2757 100644
--- a/diffcore-break.c
+++ b/diffcore-break.c
@@ -1,9 +1,11 @@
/*
* Copyright (C) 2005 Junio C Hamano
*/
-#include "cache.h"
+#include "git-compat-util.h"
#include "diff.h"
#include "diffcore.h"
+#include "hash.h"
+#include "object.h"
#include "promisor-remote.h"
static int should_break(struct repository *r,
diff --git a/diffcore-order.c b/diffcore-order.c
index 57ccab2846..e7d20ebd2d 100644
--- a/diffcore-order.c
+++ b/diffcore-order.c
@@ -5,6 +5,7 @@
#include "gettext.h"
#include "diff.h"
#include "diffcore.h"
+#include "wildmatch.h"
static char **order;
static int order_cnt;
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index 13c98a7b5e..b195fa4eb3 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -7,6 +7,7 @@
#include "diffcore.h"
#include "xdiff-interface.h"
#include "kwset.h"
+#include "oidset.h"
#include "pretty.h"
#include "quote.h"
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 8e2e7a3ad7..5a6e2bcac7 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -3,10 +3,9 @@
* Copyright (C) 2005 Junio C Hamano
*/
#include "git-compat-util.h"
-#include "alloc.h"
#include "diff.h"
#include "diffcore.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "hashmap.h"
#include "mem-pool.h"
#include "oid-array.h"
diff --git a/dir-iterator.c b/dir-iterator.c
index fb7c47f0e8..278b04243a 100644
--- a/dir-iterator.c
+++ b/dir-iterator.c
@@ -1,5 +1,4 @@
#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 a7469df3ac..8486e4d56f 100644
--- a/dir.c
+++ b/dir.c
@@ -7,14 +7,15 @@
*/
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "convert.h"
#include "dir.h"
#include "environment.h"
#include "gettext.h"
+#include "name-hash.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "path.h"
#include "attr.h"
#include "refs.h"
#include "wildmatch.h"
@@ -22,13 +23,14 @@
#include "utf8.h"
#include "varint.h"
#include "ewah/ewok.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
+#include "read-cache-ll.h"
#include "setup.h"
+#include "sparse-index.h"
#include "submodule-config.h"
#include "symlinks.h"
#include "trace2.h"
#include "tree.h"
-#include "wrapper.h"
/*
* Tells read_directory_recursive how a file or directory should be treated.
@@ -374,7 +376,7 @@ static int match_pathspec_item(struct index_state *istate,
return 0;
if (item->attr_match_nr &&
- !match_pathspec_attrs(istate, name, namelen, item))
+ !match_pathspec_attrs(istate, name - prefix, namelen + prefix, item))
return 0;
/* If the match was just the prefix, we matched */
diff --git a/dir.h b/dir.h
index 79b85a01ee..ad06682fd5 100644
--- a/dir.h
+++ b/dir.h
@@ -1,11 +1,14 @@
#ifndef DIR_H
#define DIR_H
+#include "hash-ll.h"
#include "hashmap.h"
#include "pathspec.h"
#include "statinfo.h"
#include "strbuf.h"
+struct repository;
+
/**
* The directory listing API is used to enumerate paths in the work tree,
* optionally taking `.git/info/exclude` and `.gitignore` files per directory
@@ -40,6 +43,8 @@
*
*/
+struct repository;
+
struct dir_entry {
unsigned int len;
char name[FLEX_ARRAY]; /* more */
@@ -641,18 +646,4 @@ static inline int starts_with_dot_dot_slash_native(const char *const path)
return path_match_flags(path, what | PATH_MATCH_NATIVE);
}
-#if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)
-#define DTYPE(de) ((de)->d_type)
-#else
-#undef DT_UNKNOWN
-#undef DT_DIR
-#undef DT_REG
-#undef DT_LNK
-#define DT_UNKNOWN 0
-#define DT_DIR 1
-#define DT_REG 2
-#define DT_LNK 3
-#define DTYPE(de) DT_UNKNOWN
-#endif
-
#endif
diff --git a/editor.c b/editor.c
index 38c5dbbb79..b67b802ddf 100644
--- a/editor.c
+++ b/editor.c
@@ -11,7 +11,6 @@
#include "strvec.h"
#include "run-command.h"
#include "sigchain.h"
-#include "wrapper.h"
#ifndef DEFAULT_EDITOR
#define DEFAULT_EDITOR "vi"
diff --git a/entry.c b/entry.c
index 91a540bd29..43767f9043 100644
--- a/entry.c
+++ b/entry.c
@@ -1,10 +1,12 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "blob.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "dir.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
+#include "name-hash.h"
+#include "sparse-index.h"
#include "streaming.h"
#include "submodule.h"
#include "symlinks.h"
@@ -12,7 +14,6 @@
#include "fsmonitor.h"
#include "entry.h"
#include "parallel-checkout.h"
-#include "wrapper.h"
static void create_directories(const char *path, int path_len,
const struct checkout *state)
diff --git a/environment.c b/environment.c
index 28d18eaca8..f98d76f080 100644
--- a/environment.c
+++ b/environment.c
@@ -20,14 +20,14 @@
#include "commit.h"
#include "strvec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "path.h"
#include "replace-object.h"
#include "tmp-objdir.h"
#include "chdir-notify.h"
#include "setup.h"
#include "shallow.h"
#include "trace.h"
-#include "wrapper.h"
#include "write-or-die.h"
int trust_executable_bit = 1;
@@ -42,7 +42,6 @@ int is_bare_repository_cfg = -1; /* unspecified */
int warn_ambiguous_refs = 1;
int warn_on_object_refname_ambiguity = 1;
int repository_format_precious_objects;
-int repository_format_worktree_config;
const char *git_commit_encoding;
const char *git_log_output_encoding;
char *apply_default_whitespace;
@@ -63,7 +62,6 @@ const char *editor_program;
const char *askpass_program;
const char *excludes_file;
enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
-int read_replace_refs = 1;
enum eol core_eol = EOL_UNSET;
int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
char *check_roundtrip_encoding = "SHIFT-JIS";
@@ -75,7 +73,7 @@ enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
#endif
enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
char *notes_ref_name;
-int grafts_replace_parents = 1;
+int grafts_keep_true_parents;
int core_apply_sparse_checkout;
int core_sparse_checkout_cone;
int sparse_expect_files_outside_of_patterns;
@@ -110,7 +108,7 @@ char *git_work_tree_cfg;
static char *git_namespace;
/*
- * Repository-local GIT_* environment variables; see cache.h for details.
+ * Repository-local GIT_* environment variables; see environment.h for details.
*/
const char * const local_repo_env[] = {
ALTERNATE_DB_ENVIRONMENT,
@@ -184,7 +182,7 @@ void setup_git_env(const char *git_dir)
strvec_clear(&to_free);
if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
- read_replace_refs = 0;
+ disable_replace_refs();
replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT);
git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base
: "refs/replace/");
diff --git a/environment.h b/environment.h
index 30cb7e0fa3..c5377473c6 100644
--- a/environment.h
+++ b/environment.h
@@ -1,9 +1,8 @@
#ifndef ENVIRONMENT_H
#define ENVIRONMENT_H
-#include "strvec.h"
-
struct repository;
+struct strvec;
/*
* The character that begins a commented line in user-editable file
@@ -194,10 +193,9 @@ extern enum object_creation_mode object_creation_mode;
extern char *notes_ref_name;
-extern int grafts_replace_parents;
+extern int grafts_keep_true_parents;
extern int repository_format_precious_objects;
-extern int repository_format_worktree_config;
/*
* Create a temporary file rooted in the object database directory, or
diff --git a/ewah/bitmap.c b/ewah/bitmap.c
index 12d6aa398e..7b525b1ecd 100644
--- a/ewah/bitmap.c
+++ b/ewah/bitmap.c
@@ -17,7 +17,6 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#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 c6d4ffc87c..8785cbc54a 100644
--- a/ewah/ewah_bitmap.c
+++ b/ewah/ewah_bitmap.c
@@ -17,7 +17,6 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "git-compat-util.h"
-#include "alloc.h"
#include "ewok.h"
#include "ewok_rlw.h"
diff --git a/exec-cmd.c b/exec-cmd.c
index 1e34e48c0e..1d597e84ea 100644
--- a/exec-cmd.c
+++ b/exec-cmd.c
@@ -1,10 +1,11 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "abspath.h"
#include "environment.h"
#include "exec-cmd.h"
#include "gettext.h"
#include "path.h"
#include "quote.h"
+#include "run-command.h"
#include "strvec.h"
#include "trace.h"
#include "trace2.h"
diff --git a/fetch-pack.c b/fetch-pack.c
index 0f71054fba..65c1ff4bb4 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "repository.h"
#include "config.h"
#include "date.h"
@@ -24,7 +23,8 @@
#include "oid-array.h"
#include "oidset.h"
#include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "path.h"
#include "connected.h"
#include "fetch-negotiator.h"
#include "fsck.h"
@@ -33,7 +33,6 @@
#include "commit-graph.h"
#include "sigchain.h"
#include "mergesort.h"
-#include "wrapper.h"
static int transfer_unpack_limit = -1;
static int fetch_unpack_limit = -1;
@@ -1860,7 +1859,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
return ref;
}
-static int fetch_pack_config_cb(const char *var, const char *value, void *cb)
+static int fetch_pack_config_cb(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (strcmp(var, "fetch.fsck.skiplist") == 0) {
const char *path;
@@ -1882,7 +1882,7 @@ static int fetch_pack_config_cb(const char *var, const char *value, void *cb)
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
static void fetch_pack_config(void)
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index 5af0d4715b..66e47449a0 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -1,10 +1,9 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "refs.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "diff.h"
#include "diff-merges.h"
#include "hex.h"
@@ -15,16 +14,18 @@
#include "fmt-merge-msg.h"
#include "commit-reach.h"
#include "gpg-interface.h"
+#include "wildmatch.h"
static int use_branch_desc;
static int suppress_dest_pattern_seen;
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 fmt_merge_msg_config(const char *key, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(key, "merge.log") || !strcmp(key, "merge.summary")) {
int is_bool;
- merge_log_config = git_config_bool_or_int(key, value, &is_bool);
+ merge_log_config = git_config_bool_or_int(key, value, ctx->kvi, &is_bool);
if (!is_bool && merge_log_config < 0)
return error("%s: negative length %s", key, value);
if (is_bool && merge_log_config)
@@ -40,7 +41,7 @@ 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 {
- return git_default_config(key, value, cb);
+ return git_default_config(key, value, ctx, cb);
}
return 0;
}
@@ -508,7 +509,8 @@ static void fmt_tag_signature(struct strbuf *tagbuf,
strbuf_complete_line(tagbuf);
if (sig->len) {
strbuf_addch(tagbuf, '\n');
- strbuf_add_commented_lines(tagbuf, sig->buf, sig->len);
+ strbuf_add_commented_lines(tagbuf, sig->buf, sig->len,
+ comment_line_char);
}
}
@@ -554,7 +556,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
strbuf_addch(&tagline, '\n');
strbuf_add_commented_lines(&tagline,
origins.items[first_tag].string,
- strlen(origins.items[first_tag].string));
+ strlen(origins.items[first_tag].string),
+ comment_line_char);
strbuf_insert(&tagbuf, 0, tagline.buf,
tagline.len);
strbuf_release(&tagline);
@@ -562,7 +565,8 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
strbuf_addch(&tagbuf, '\n');
strbuf_add_commented_lines(&tagbuf,
origins.items[i].string,
- strlen(origins.items[i].string));
+ strlen(origins.items[i].string),
+ comment_line_char);
fmt_tag_signature(&tagbuf, &sig, buf, len);
}
strbuf_release(&payload);
diff --git a/fmt-merge-msg.h b/fmt-merge-msg.h
index 99054042dc..73ca3e4465 100644
--- a/fmt-merge-msg.h
+++ b/fmt-merge-msg.h
@@ -13,7 +13,8 @@ struct fmt_merge_msg_opts {
};
extern int merge_log_config;
-int fmt_merge_msg_config(const char *key, const char *value, void *cb);
+int fmt_merge_msg_config(const char *key, const char *value,
+ const struct config_context *ctx, void *cb);
int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
struct fmt_merge_msg_opts *);
diff --git a/fsck.c b/fsck.c
index 3261ef9ec2..2b1e348005 100644
--- a/fsck.c
+++ b/fsck.c
@@ -1,8 +1,9 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "date.h"
+#include "dir.h"
#include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "path.h"
#include "repository.h"
#include "object.h"
#include "attr.h"
@@ -1163,7 +1164,9 @@ struct fsck_gitmodules_data {
int ret;
};
-static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata)
+static int fsck_gitmodules_fn(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *vdata)
{
struct fsck_gitmodules_data *data = vdata;
const char *subsection, *key;
@@ -1236,7 +1239,8 @@ static int fsck_blob(const struct object_id *oid, const char *buf,
data.ret = 0;
config_opts.error_action = CONFIG_ERROR_SILENT;
if (git_config_from_mem(fsck_gitmodules_fn, CONFIG_ORIGIN_BLOB,
- ".gitmodules", buf, size, &data, &config_opts))
+ ".gitmodules", buf, size, &data,
+ CONFIG_SCOPE_UNKNOWN, &config_opts))
data.ret |= report(options, oid, OBJ_BLOB,
FSCK_MSG_GITMODULES_PARSE,
"could not parse gitmodules blob");
@@ -1305,9 +1309,9 @@ int fsck_buffer(const struct object_id *oid, enum object_type type,
int fsck_error_function(struct fsck_options *o,
const struct object_id *oid,
- enum object_type object_type,
+ enum object_type object_type UNUSED,
enum fsck_msg_type msg_type,
- enum fsck_msg_id msg_id,
+ enum fsck_msg_id msg_id UNUSED,
const char *message)
{
if (msg_type == FSCK_WARN) {
@@ -1373,7 +1377,8 @@ int fsck_finish(struct fsck_options *options)
return ret;
}
-int git_fsck_config(const char *var, const char *value, void *cb)
+int git_fsck_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
struct fsck_options *options = cb;
if (strcmp(var, "fsck.skiplist") == 0) {
@@ -1394,7 +1399,7 @@ int git_fsck_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
/*
diff --git a/fsck.h b/fsck.h
index e17730e9da..6359ba359b 100644
--- a/fsck.h
+++ b/fsck.h
@@ -233,10 +233,12 @@ void fsck_put_object_name(struct fsck_options *options,
const char *fsck_describe_object(struct fsck_options *options,
const struct object_id *oid);
+struct key_value_info;
/*
* git_config() callback for use by fsck-y tools that want to support
* fsck.<msg> fsck.skipList etc.
*/
-int git_fsck_config(const char *var, const char *value, void *cb);
+int git_fsck_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb);
#endif
diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c
index 6a6a89764a..88575aa54c 100644
--- a/fsmonitor-ipc.c
+++ b/fsmonitor-ipc.c
@@ -1,5 +1,5 @@
-#include "cache.h"
-#include "fsmonitor.h"
+#include "git-compat-util.h"
+#include "fsmonitor-ll.h"
#include "gettext.h"
#include "simple-ipc.h"
#include "fsmonitor-ipc.h"
diff --git a/fsmonitor-ll.h b/fsmonitor-ll.h
new file mode 100644
index 0000000000..0504ca07d6
--- /dev/null
+++ b/fsmonitor-ll.h
@@ -0,0 +1,52 @@
+#ifndef FSMONITOR_LL_H
+#define FSMONITOR_LL_H
+
+struct index_state;
+struct strbuf;
+
+extern struct trace_key trace_fsmonitor;
+
+/*
+ * Read the fsmonitor index extension and (if configured) restore the
+ * CE_FSMONITOR_VALID state.
+ */
+int read_fsmonitor_extension(struct index_state *istate, const void *data, unsigned long sz);
+
+/*
+ * Fill the fsmonitor_dirty ewah bits with their state from the index,
+ * before it is split during writing.
+ */
+void fill_fsmonitor_bitmap(struct index_state *istate);
+
+/*
+ * Write the CE_FSMONITOR_VALID state into the fsmonitor index
+ * extension. Reads from the fsmonitor_dirty ewah in the index.
+ */
+void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate);
+
+/*
+ * Add/remove the fsmonitor index extension
+ */
+void add_fsmonitor(struct index_state *istate);
+void remove_fsmonitor(struct index_state *istate);
+
+/*
+ * Add/remove the fsmonitor index extension as necessary based on the current
+ * core.fsmonitor setting.
+ */
+void tweak_fsmonitor(struct index_state *istate);
+
+/*
+ * Run the configured fsmonitor integration script and clear the
+ * CE_FSMONITOR_VALID bit for any files returned as dirty. Also invalidate
+ * any corresponding untracked cache directory structures. Optimized to only
+ * run the first time it is called.
+ */
+void refresh_fsmonitor(struct index_state *istate);
+
+/*
+ * Does the received result contain the "trivial" response?
+ */
+int fsmonitor_is_trivial_response(const struct strbuf *query_result);
+
+#endif /* FSMONITOR_LL_H */
diff --git a/fsmonitor.c b/fsmonitor.c
index 28c083d4d8..f670c50937 100644
--- a/fsmonitor.c
+++ b/fsmonitor.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "config.h"
#include "dir.h"
#include "environment.h"
diff --git a/fsmonitor.h b/fsmonitor.h
index c67e0ebc09..5195a8624d 100644
--- a/fsmonitor.h
+++ b/fsmonitor.h
@@ -1,56 +1,13 @@
#ifndef FSMONITOR_H
#define FSMONITOR_H
-#include "cache.h"
+#include "fsmonitor-ll.h"
#include "dir.h"
#include "fsmonitor-settings.h"
+#include "object.h"
+#include "read-cache-ll.h"
#include "trace.h"
-extern struct trace_key trace_fsmonitor;
-
-/*
- * Read the fsmonitor index extension and (if configured) restore the
- * CE_FSMONITOR_VALID state.
- */
-int read_fsmonitor_extension(struct index_state *istate, const void *data, unsigned long sz);
-
-/*
- * Fill the fsmonitor_dirty ewah bits with their state from the index,
- * before it is split during writing.
- */
-void fill_fsmonitor_bitmap(struct index_state *istate);
-
-/*
- * Write the CE_FSMONITOR_VALID state into the fsmonitor index
- * extension. Reads from the fsmonitor_dirty ewah in the index.
- */
-void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate);
-
-/*
- * Add/remove the fsmonitor index extension
- */
-void add_fsmonitor(struct index_state *istate);
-void remove_fsmonitor(struct index_state *istate);
-
-/*
- * Add/remove the fsmonitor index extension as necessary based on the current
- * core.fsmonitor setting.
- */
-void tweak_fsmonitor(struct index_state *istate);
-
-/*
- * Run the configured fsmonitor integration script and clear the
- * CE_FSMONITOR_VALID bit for any files returned as dirty. Also invalidate
- * any corresponding untracked cache directory structures. Optimized to only
- * run the first time it is called.
- */
-void refresh_fsmonitor(struct index_state *istate);
-
-/*
- * Does the received result contain the "trivial" response?
- */
-int fsmonitor_is_trivial_response(const struct strbuf *query_result);
-
/*
* Check if refresh_fsmonitor has been called at least once.
* refresh_fsmonitor is idempotent. Returns true if fsmonitor is
diff --git a/git-compat-util.h b/git-compat-util.h
index 5b2b99c17c..d32aa754ae 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -440,8 +440,10 @@ typedef uintmax_t timestamp_t;
#endif
#ifndef platform_core_config
+struct config_context;
static inline int noop_core_config(const char *var UNUSED,
const char *value UNUSED,
+ const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
return 0;
@@ -625,9 +627,7 @@ static inline int git_has_dir_sep(const char *path)
#include "compat/bswap.h"
-#include "wildmatch.h"
-
-struct strbuf;
+#include "wrapper.h"
/* General helper functions */
NORETURN void usage(const char *err);
@@ -679,9 +679,6 @@ void set_warn_routine(report_fn routine);
report_fn get_warn_routine(void);
void set_die_is_recursing_routine(int (*routine)(void));
-int starts_with(const char *str, const char *prefix);
-int istarts_with(const char *str, const char *prefix);
-
/*
* If the string "str" begins with the string found in "prefix", return 1.
* The "out" parameter is set to "str + strlen(prefix)" (i.e., to the point in
@@ -711,29 +708,6 @@ static inline int skip_prefix(const char *str, const char *prefix,
}
/*
- * If the string "str" is the same as the string in "prefix", then the "arg"
- * parameter is set to the "def" parameter and 1 is returned.
- * If the string "str" begins with the string found in "prefix" and then a
- * "=" sign, then the "arg" parameter is set to "str + strlen(prefix) + 1"
- * (i.e., to the point in the string right after the prefix and the "=" sign),
- * and 1 is returned.
- *
- * Otherwise, return 0 and leave "arg" untouched.
- *
- * When we accept both a "--key" and a "--key=<val>" option, this function
- * can be used instead of !strcmp(arg, "--key") and then
- * skip_prefix(arg, "--key=", &arg) to parse such an option.
- */
-int skip_to_optional_arg_default(const char *str, const char *prefix,
- const char **arg, const char *def);
-
-static inline int skip_to_optional_arg(const char *str, const char *prefix,
- const char **arg)
-{
- return skip_to_optional_arg_default(str, prefix, arg, "");
-}
-
-/*
* Like skip_prefix, but promises never to read past "len" bytes of the input
* buffer, and returns the remaining number of bytes in "out" via "outlen".
*/
@@ -777,12 +751,6 @@ static inline int strip_suffix(const char *str, const char *suffix, size_t *len)
return strip_suffix_mem(str, len, suffix);
}
-static inline int ends_with(const char *str, const char *suffix)
-{
- size_t len;
- return strip_suffix(str, suffix, &len);
-}
-
#define SWAP(a, b) do { \
void *_swap_a_ptr = &(a); \
void *_swap_b_ptr = &(b); \
@@ -1079,36 +1047,6 @@ static inline int cast_size_t_to_int(size_t a)
# define xalloca(size) (xmalloc(size))
# define xalloca_free(p) (free(p))
#endif
-char *xstrdup(const char *str);
-void *xmalloc(size_t size);
-void *xmallocz(size_t size);
-void *xmallocz_gently(size_t size);
-void *xmemdupz(const void *data, size_t len);
-char *xstrndup(const char *str, size_t len);
-void *xrealloc(void *ptr, size_t size);
-void *xcalloc(size_t nmemb, size_t size);
-void xsetenv(const char *name, const char *value, int overwrite);
-void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
-const char *mmap_os_err(void);
-void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset);
-int xopen(const char *path, int flags, ...);
-ssize_t xread(int fd, void *buf, size_t len);
-ssize_t xwrite(int fd, const void *buf, size_t len);
-ssize_t xpread(int fd, void *buf, size_t len, off_t offset);
-int xdup(int fd);
-FILE *xfopen(const char *path, const char *mode);
-FILE *xfdopen(int fd, const char *mode);
-int xmkstemp(char *temp_filename);
-int xmkstemp_mode(char *temp_filename, int mode);
-char *xgetcwd(void);
-FILE *fopen_for_writing(const char *path);
-FILE *fopen_or_warn(const char *path, const char *mode);
-
-/*
- * Like strncmp, but only return zero if s is NUL-terminated and exactly len
- * characters long. If it is not, consider it greater than t.
- */
-int xstrncmpz(const char *s, const char *t, size_t len);
/*
* FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note
@@ -1198,6 +1136,81 @@ static inline void move_array(void *dst, const void *src, size_t n, size_t size)
#define FLEXPTR_ALLOC_STR(x, ptrname, str) \
FLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str))
+#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)
+
static inline char *xstrdup_or_null(const char *str)
{
return str ? xstrdup(str) : NULL;
@@ -1210,79 +1223,11 @@ static inline size_t xsize_t(off_t len)
return (size_t) len;
}
-__attribute__((format (printf, 3, 4)))
-int xsnprintf(char *dst, size_t max, const char *fmt, ...);
-
#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX 256
#endif
-int xgethostname(char *buf, size_t len);
-
-/* in ctype.c, for kwset users */
-extern const unsigned char tolower_trans_tbl[256];
-
-/* Sane ctype - no locale, and works with signed chars */
-#undef isascii
-#undef isspace
-#undef isdigit
-#undef isalpha
-#undef isalnum
-#undef isprint
-#undef islower
-#undef isupper
-#undef tolower
-#undef toupper
-#undef iscntrl
-#undef ispunct
-#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
-#define GIT_GLOB_SPECIAL 0x08
-#define GIT_REGEX_SPECIAL 0x10
-#define GIT_PATHSPEC_MAGIC 0x20
-#define GIT_CNTRL 0x40
-#define GIT_PUNCT 0x80
-#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
-#define isascii(x) (((x) & ~0x7f) == 0)
-#define isspace(x) sane_istest(x,GIT_SPACE)
-#define isdigit(x) sane_istest(x,GIT_DIGIT)
-#define isalpha(x) sane_istest(x,GIT_ALPHA)
-#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
-#define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)
-#define islower(x) sane_iscase(x, 1)
-#define isupper(x) sane_iscase(x, 0)
-#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)
-#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)
-#define iscntrl(x) (sane_istest(x,GIT_CNTRL))
-#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \
- GIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)
-#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)
-#define tolower(x) sane_case((unsigned char)(x), 0x20)
-#define toupper(x) sane_case((unsigned char)(x), 0)
-#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)
-
-static inline int sane_case(int x, int high)
-{
- if (sane_istest(x, GIT_ALPHA))
- x = (x & ~0x20) | high;
- return x;
-}
-
-static inline int sane_iscase(int x, int is_lower)
-{
- if (!sane_istest(x, GIT_ALPHA))
- return 0;
-
- if (is_lower)
- return (x & 0x20) != 0;
- else
- return (x & 0x20) == 0;
-}
+#include "sane-ctype.h"
/*
* Like skip_prefix, but compare case-insensitively. Note that the comparison
@@ -1459,72 +1404,6 @@ void bug_fl(const char *file, int line, const char *fmt, ...);
#endif
#endif
-enum fsync_action {
- FSYNC_WRITEOUT_ONLY,
- FSYNC_HARDWARE_FLUSH
-};
-
-/*
- * Issues an fsync against the specified file according to the specified mode.
- *
- * FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating
- * systems to flush the OS cache without issuing a flush command to the storage
- * controller. If those interfaces are unavailable, the function fails with
- * ENOSYS.
- *
- * FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that
- * changes are durable. It is not expected to fail.
- */
-int git_fsync(int fd, enum fsync_action action);
-
-/*
- * Writes out trace statistics for fsync using the trace2 API.
- */
-void trace_git_fsync_stats(void);
-
-/*
- * Preserves errno, prints a message, but gives no warning for ENOENT.
- * Returns 0 on success, which includes trying to unlink an object that does
- * not exist.
- */
-int unlink_or_warn(const char *path);
- /*
- * Tries to unlink file. Returns 0 if unlink succeeded
- * or the file already didn't exist. Returns -1 and
- * appends a message to err suitable for
- * 'error("%s", err->buf)' on error.
- */
-int unlink_or_msg(const char *file, struct strbuf *err);
-/*
- * Preserves errno, prints a message, but gives no warning for ENOENT.
- * Returns 0 on success, which includes trying to remove a directory that does
- * not exist.
- */
-int rmdir_or_warn(const char *path);
-/*
- * Calls the correct function out of {unlink,rmdir}_or_warn based on
- * the supplied file mode.
- */
-int remove_or_warn(unsigned int mode, const char *path);
-
-/*
- * Call access(2), but warn for any error except "missing file"
- * (ENOENT or ENOTDIR).
- */
-#define ACCESS_EACCES_OK (1U << 0)
-int access_or_warn(const char *path, int mode, unsigned flag);
-int access_or_die(const char *path, int mode, unsigned flag);
-
-/* Warn on an inaccessible file if errno indicates this is an error */
-int warn_on_fopen_errors(const char *path);
-
-/*
- * Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent
- * may be racy. Do not use this as protection against an attacker who can
- * simultaneously create paths.
- */
-int open_nofollow(const char *path, int flags);
-
#ifndef SHELL_PATH
# define SHELL_PATH "/bin/sh"
#endif
@@ -1664,13 +1543,4 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset)
((uintptr_t)&(ptr)->member - (uintptr_t)(ptr))
#endif /* !__GNUC__ */
-void sleep_millisec(int millisec);
-
-/*
- * Generate len bytes from the system cryptographically secure PRNG.
- * Returns 0 on success and -1 on error, setting errno. The inability to
- * satisfy the full request is an error.
- */
-int csprng_bytes(void *buf, size_t len);
-
#endif
diff --git a/git.c b/git.c
index 2f42da20f4..c67e44dd82 100644
--- a/git.c
+++ b/git.c
@@ -5,6 +5,7 @@
#include "gettext.h"
#include "help.h"
#include "pager.h"
+#include "read-cache-ll.h"
#include "run-command.h"
#include "alias.h"
#include "replace-object.h"
@@ -186,7 +187,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
if (envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "--no-replace-objects")) {
- read_replace_refs = 0;
+ disable_replace_refs();
setenv(NO_REPLACE_OBJECTS_ENVIRONMENT, "1", 1);
if (envchanged)
*envchanged = 1;
diff --git a/gpg-interface.c b/gpg-interface.c
index 19a3471a0b..48f43c5a21 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -12,9 +12,10 @@
#include "sigchain.h"
#include "tempfile.h"
#include "alias.h"
-#include "wrapper.h"
+#include "environment.h"
-static int git_gpg_config(const char *, const char *, void *);
+static int git_gpg_config(const char *, const char *,
+ const struct config_context *, void *);
static void gpg_interface_lazy_init(void)
{
@@ -586,8 +587,8 @@ static int verify_ssh_signed_buffer(struct signature_check *sigc,
}
}
- strbuf_stripspace(&ssh_keygen_out, 0);
- strbuf_stripspace(&ssh_keygen_err, 0);
+ strbuf_stripspace(&ssh_keygen_out, '\0');
+ strbuf_stripspace(&ssh_keygen_err, '\0');
/* Add stderr outputs to show the user actual ssh-keygen errors */
strbuf_add(&ssh_keygen_out, ssh_principals_err.buf, ssh_principals_err.len);
strbuf_add(&ssh_keygen_out, ssh_keygen_err.buf, ssh_keygen_err.len);
@@ -720,7 +721,9 @@ void set_signing_key(const char *key)
configured_signing_key = xstrdup(key);
}
-static int git_gpg_config(const char *var, const char *value, void *cb UNUSED)
+static int git_gpg_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb UNUSED)
{
struct gpg_format *fmt = NULL;
char *fmtname = NULL;
diff --git a/grep.c b/grep.c
index f00986c451..0904d55b24 100644
--- a/grep.c
+++ b/grep.c
@@ -3,7 +3,7 @@
#include "gettext.h"
#include "grep.h"
#include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "pretty.h"
#include "userdiff.h"
#include "xdiff-interface.h"
@@ -12,7 +12,6 @@
#include "commit.h"
#include "quote.h"
#include "help.h"
-#include "wrapper.h"
static int grep_source_load(struct grep_source *gs);
static int grep_source_is_binary(struct grep_source *gs,
@@ -56,7 +55,8 @@ define_list_config_array_extra(color_grep_slots, {"match"});
* Read the configuration file once and store it in
* the grep_defaults template.
*/
-int grep_config(const char *var, const char *value, void *cb)
+int grep_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
struct grep_opt *opt = cb;
const char *slot;
@@ -91,9 +91,9 @@ int grep_config(const char *var, const char *value, void *cb)
if (!strcmp(var, "color.grep"))
opt->color = git_config_colorbool(var, value);
if (!strcmp(var, "color.grep.match")) {
- if (grep_config("color.grep.matchcontext", value, cb) < 0)
+ if (grep_config("color.grep.matchcontext", value, ctx, cb) < 0)
return -1;
- if (grep_config("color.grep.matchselected", value, cb) < 0)
+ if (grep_config("color.grep.matchselected", value, ctx, cb) < 0)
return -1;
} else if (skip_prefix(var, "color.grep.", &slot)) {
int i = LOOKUP_CONFIG(color_grep_slots, slot);
diff --git a/grep.h b/grep.h
index c59592e3bd..926c0875c4 100644
--- a/grep.h
+++ b/grep.h
@@ -202,7 +202,9 @@ struct grep_opt {
.output = std_output, \
}
-int grep_config(const char *var, const char *value, void *);
+struct config_context;
+int grep_config(const char *var, const char *value,
+ const struct config_context *ctx, void *data);
void grep_init(struct grep_opt *, struct repository *repo);
void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t);
diff --git a/hash-ll.h b/hash-ll.h
index 8050925137..10d84cc208 100644
--- a/hash-ll.h
+++ b/hash-ll.h
@@ -4,7 +4,11 @@
#if defined(SHA1_APPLE)
#include <CommonCrypto/CommonDigest.h>
#elif defined(SHA1_OPENSSL)
-#include <openssl/sha.h>
+# include <openssl/sha.h>
+# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
+# define SHA1_NEEDS_CLONE_HELPER
+# include "sha1/openssl.h"
+# endif
#elif defined(SHA1_DC)
#include "sha1dc_git.h"
#else /* SHA1_BLK */
@@ -17,7 +21,11 @@
#define SHA256_NEEDS_CLONE_HELPER
#include "sha256/gcrypt.h"
#elif defined(SHA256_OPENSSL)
-#include <openssl/sha.h>
+# include <openssl/sha.h>
+# if defined(OPENSSL_API_LEVEL) && OPENSSL_API_LEVEL >= 3
+# define SHA256_NEEDS_CLONE_HELPER
+# include "sha256/openssl.h"
+# endif
#else
#include "sha256/block/sha256.h"
#endif
@@ -41,6 +49,10 @@
#define git_SHA1_Update platform_SHA1_Update
#define git_SHA1_Final platform_SHA1_Final
+#ifdef platform_SHA1_Clone
+#define git_SHA1_Clone platform_SHA1_Clone
+#endif
+
#ifndef platform_SHA256_CTX
#define platform_SHA256_CTX SHA256_CTX
#define platform_SHA256_Init SHA256_Init
@@ -63,10 +75,12 @@
#define git_SHA1_Update git_SHA1_Update_Chunked
#endif
+#ifndef SHA1_NEEDS_CLONE_HELPER
static inline void git_SHA1_Clone(git_SHA_CTX *dst, const git_SHA_CTX *src)
{
memcpy(dst, src, sizeof(*dst));
}
+#endif
#ifndef SHA256_NEEDS_CLONE_HELPER
static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *src)
@@ -270,6 +284,25 @@ static inline void oid_set_algo(struct object_id *oid, const struct git_hash_alg
oid->algo = hash_algo_by_ptr(algop);
}
+/*
+ * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
+ * for use in hash tables. Cryptographic hashes are supposed to have
+ * uniform distribution, so in contrast to `memhash()`, this just copies
+ * the first `sizeof(int)` bytes without shuffling any bits. Note that
+ * the results will be different on big-endian and little-endian
+ * platforms, so they should not be stored or transferred over the net.
+ */
+static inline unsigned int oidhash(const struct object_id *oid)
+{
+ /*
+ * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
+ * platforms that don't support unaligned reads.
+ */
+ unsigned int hash;
+ memcpy(&hash, oid->hash, sizeof(hash));
+ return hash;
+}
+
const char *empty_tree_oid_hex(void);
const char *empty_blob_oid_hex(void);
diff --git a/hash-lookup.c b/hash-lookup.c
index bb54dfde9c..9f0f95e2b9 100644
--- a/hash-lookup.c
+++ b/hash-lookup.c
@@ -1,6 +1,7 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "hash.h"
#include "hash-lookup.h"
+#include "read-cache-ll.h"
static uint32_t take2(const struct object_id *oid, size_t ofs)
{
diff --git a/hashmap.h b/hashmap.h
index 2695f3d3a6..c8216e47bb 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -1,8 +1,6 @@
#ifndef HASHMAP_H
#define HASHMAP_H
-#include "hash-ll.h"
-
/*
* Generic implementation of hash-based key-value mappings.
*
@@ -121,25 +119,6 @@ unsigned int memihash(const void *buf, size_t len);
unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len);
/*
- * Converts a cryptographic hash (e.g. SHA-1) into an int-sized hash code
- * for use in hash tables. Cryptographic hashes are supposed to have
- * uniform distribution, so in contrast to `memhash()`, this just copies
- * the first `sizeof(int)` bytes without shuffling any bits. Note that
- * the results will be different on big-endian and little-endian
- * platforms, so they should not be stored or transferred over the net.
- */
-static inline unsigned int oidhash(const struct object_id *oid)
-{
- /*
- * Equivalent to 'return *(unsigned int *)oid->hash;', but safe on
- * platforms that don't support unaligned reads.
- */
- unsigned int hash;
- memcpy(&hash, oid->hash, sizeof(hash));
- return hash;
-}
-
-/*
* struct hashmap_entry is an opaque structure representing an entry in the
* hash table.
* Ideally it should be followed by an int-sized member to prevent unused
diff --git a/help.c b/help.c
index 5d7637dce9..6d2ebfbd2a 100644
--- a/help.c
+++ b/help.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "builtin.h"
#include "exec-cmd.h"
@@ -309,7 +308,8 @@ void load_command_list(const char *prefix,
exclude_cmds(other_cmds, main_cmds);
}
-static int get_colopts(const char *var, const char *value, void *data)
+static int get_colopts(const char *var, const char *value,
+ const struct config_context *ctx UNUSED, void *data)
{
unsigned int *colopts = data;
@@ -459,7 +459,8 @@ void list_developer_interfaces_help(void)
putchar('\n');
}
-static int get_alias(const char *var, const char *value, void *data)
+static int get_alias(const char *var, const char *value,
+ const struct config_context *ctx UNUSED, void *data)
{
struct string_list *list = data;
@@ -543,6 +544,7 @@ static struct cmdnames aliases;
#define AUTOCORRECT_IMMEDIATELY (-1)
static int git_unknown_cmd_config(const char *var, const char *value,
+ const struct config_context *ctx,
void *cb UNUSED)
{
const char *p;
@@ -557,7 +559,7 @@ static int git_unknown_cmd_config(const char *var, const char *value,
} else if (!strcmp(value, "prompt")) {
autocorrect = AUTOCORRECT_PROMPT;
} else {
- int v = git_config_int(var, value);
+ int v = git_config_int(var, value, ctx->kvi);
autocorrect = (v < 0)
? AUTOCORRECT_IMMEDIATELY : v;
}
diff --git a/hex.c b/hex.c
index 7bb440e794..01f17fe5c9 100644
--- a/hex.c
+++ b/hex.c
@@ -63,7 +63,7 @@ static int get_hash_hex_algop(const char *hex, unsigned char *hash,
return 0;
}
-int get_sha1_hex(const char *hex, unsigned char *sha1)
+int get_hash_hex(const char *hex, unsigned char *sha1)
{
return get_hash_hex_algop(hex, sha1, the_hash_algo);
}
diff --git a/hex.h b/hex.h
index 7df4b3c460..87abf66602 100644
--- a/hex.h
+++ b/hex.h
@@ -20,14 +20,16 @@ static inline int hex2chr(const char *s)
}
/*
- * 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.
+ * Try to read a hash (specified by the_hash_algo) in hexadecimal
+ * format from the 40 (or whatever length the hash algorithm uses)
+ * characters starting at hex. Write the 20-byte (or the length of
+ * the hash) result to hash 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);
+int get_hash_hex(const char *hex, unsigned char *hash);
+int get_oid_hex(const char *hex, struct object_id *oid);
/* 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);
diff --git a/hook.c b/hook.c
index 3ca5e60895..f6306d72b3 100644
--- a/hook.c
+++ b/hook.c
@@ -1,4 +1,5 @@
#include "git-compat-util.h"
+#include "abspath.h"
#include "advice.h"
#include "gettext.h"
#include "hook.h"
diff --git a/http-backend.c b/http-backend.c
index ac146d85c5..ff07b87e64 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -1,9 +1,9 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "git-zlib.h"
#include "hex.h"
+#include "path.h"
#include "repository.h"
#include "refs.h"
#include "pkt-line.h"
@@ -15,10 +15,9 @@
#include "url.h"
#include "strvec.h"
#include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "protocol.h"
#include "date.h"
-#include "wrapper.h"
#include "write-or-die.h"
static const char content_type[] = "Content-Type";
@@ -559,7 +558,7 @@ static void get_info_refs(struct strbuf *hdr, char *arg UNUSED)
} else {
select_getanyfile(hdr);
- for_each_namespaced_ref(show_text_ref, &buf);
+ for_each_namespaced_ref(NULL, show_text_ref, &buf);
send_strbuf(hdr, "text/plain", &buf);
}
strbuf_release(&buf);
diff --git a/http-push.c b/http-push.c
index 29cf9db34e..a704f490fd 100644
--- a/http-push.c
+++ b/http-push.c
@@ -18,7 +18,7 @@
#include "tree.h"
#include "tree-walk.h"
#include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "commit-reach.h"
#ifdef EXPAT_NEEDS_XMLPARSE_H
@@ -783,7 +783,7 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
static void one_remote_ref(const char *refname);
static void
-xml_start_tag(void *userData, const char *name, const char **atts)
+xml_start_tag(void *userData, const char *name, const char **atts UNUSED)
{
struct xml_ctx *ctx = (struct xml_ctx *)userData;
const char *c = strchr(name, ':');
diff --git a/http-walker.c b/http-walker.c
index bba306b2d5..78d99f7c4b 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -7,7 +7,7 @@
#include "list.h"
#include "transport.h"
#include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
struct alt_base {
char *base;
diff --git a/http.c b/http.c
index b71bb1e3ad..e138b4b96f 100644
--- a/http.c
+++ b/http.c
@@ -18,7 +18,7 @@
#include "protocol.h"
#include "string-list.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
static int trace_curl_data = 1;
@@ -196,7 +196,7 @@ static inline int is_hdr_continuation(const char *ptr, const size_t size)
return size && (*ptr == ' ' || *ptr == '\t');
}
-static size_t fwrite_wwwauth(char *ptr, size_t eltsize, size_t nmemb, void *p)
+static size_t fwrite_wwwauth(char *ptr, size_t eltsize, size_t nmemb, void *p UNUSED)
{
size_t size = eltsize * nmemb;
struct strvec *values = &http_auth.wwwauth_headers;
@@ -295,7 +295,8 @@ exit:
return size;
}
-size_t fwrite_null(char *ptr, size_t eltsize, size_t nmemb, void *strbuf)
+size_t fwrite_null(char *ptr UNUSED, size_t eltsize UNUSED, size_t nmemb,
+ void *data UNUSED)
{
return nmemb;
}
@@ -363,7 +364,8 @@ static void process_curl_messages(void)
}
}
-static int http_options(const char *var, const char *value, void *cb)
+static int http_options(const char *var, const char *value,
+ const struct config_context *ctx, void *data)
{
if (!strcmp("http.version", var)) {
return git_config_string(&curl_http_version, var, value);
@@ -413,21 +415,21 @@ static int http_options(const char *var, const char *value, void *cb)
}
if (!strcmp("http.minsessions", var)) {
- min_curl_sessions = git_config_int(var, value);
+ min_curl_sessions = git_config_int(var, value, ctx->kvi);
if (min_curl_sessions > 1)
min_curl_sessions = 1;
return 0;
}
if (!strcmp("http.maxrequests", var)) {
- max_requests = git_config_int(var, value);
+ max_requests = git_config_int(var, value, ctx->kvi);
return 0;
}
if (!strcmp("http.lowspeedlimit", var)) {
- curl_low_speed_limit = (long)git_config_int(var, value);
+ curl_low_speed_limit = (long)git_config_int(var, value, ctx->kvi);
return 0;
}
if (!strcmp("http.lowspeedtime", var)) {
- curl_low_speed_time = (long)git_config_int(var, value);
+ curl_low_speed_time = (long)git_config_int(var, value, ctx->kvi);
return 0;
}
@@ -463,7 +465,7 @@ static int http_options(const char *var, const char *value, void *cb)
}
if (!strcmp("http.postbuffer", var)) {
- http_post_buffer = git_config_ssize_t(var, value);
+ http_post_buffer = git_config_ssize_t(var, value, ctx->kvi);
if (http_post_buffer < 0)
warning(_("negative value for http.postBuffer; defaulting to %d"), LARGE_PACKET_MAX);
if (http_post_buffer < LARGE_PACKET_MAX)
@@ -534,7 +536,7 @@ static int http_options(const char *var, const char *value, void *cb)
}
/* Fall back on the default ones */
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, data);
}
static int curl_empty_auth_enabled(void)
@@ -820,7 +822,9 @@ static void curl_dump_info(char *data, size_t size)
strbuf_release(&buf);
}
-static int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size, void *userp)
+static int curl_trace(CURL *handle UNUSED, curl_infotype type,
+ char *data, size_t size,
+ void *userp UNUSED)
{
const char *text;
enum { NO_FILTER = 0, DO_FILTER = 1 };
diff --git a/ident.c b/ident.c
index 8fad92d700..cc7afdbf81 100644
--- a/ident.c
+++ b/ident.c
@@ -203,7 +203,6 @@ void reset_ident_date(void)
static int crud(unsigned char c)
{
return c <= 32 ||
- c == '.' ||
c == ',' ||
c == ':' ||
c == ';' ||
@@ -671,7 +670,9 @@ static int set_ident(const char *var, const char *value)
return 0;
}
-int git_ident_config(const char *var, const char *value, void *data UNUSED)
+int git_ident_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *data UNUSED)
{
if (!strcmp(var, "user.useconfigonly")) {
ident_use_config_only = git_config_bool(var, value);
diff --git a/ident.h b/ident.h
index 96a64896a0..6a79febba1 100644
--- a/ident.h
+++ b/ident.h
@@ -62,6 +62,8 @@ 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 *);
+struct config_context;
+int git_ident_config(const char *, const char *, const struct config_context *,
+ void *);
#endif
diff --git a/imap-send.c b/imap-send.c
index 7f5426177a..06386e0b3b 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -30,7 +30,6 @@
#include "parse-options.h"
#include "setup.h"
#include "strbuf.h"
-#include "wrapper.h"
#if defined(NO_OPENSSL) && !defined(HAVE_OPENSSL_CSPRNG)
typedef void *SSL;
#endif
@@ -137,12 +136,10 @@ struct imap_store {
};
struct imap_cmd_cb {
- int (*cont)(struct imap_store *ctx, struct imap_cmd *cmd, const char *prompt);
- void (*done)(struct imap_store *ctx, struct imap_cmd *cmd, int response);
+ int (*cont)(struct imap_store *ctx, const char *prompt);
void *ctx;
char *data;
int dlen;
- int uid;
};
struct imap_cmd {
@@ -786,7 +783,7 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
if (n != (int)cmdp->cb.dlen)
return RESP_BAD;
} else if (cmdp->cb.cont) {
- if (cmdp->cb.cont(ctx, cmdp, cmd))
+ if (cmdp->cb.cont(ctx, cmd))
return RESP_BAD;
} else {
fprintf(stderr, "IMAP error: unexpected command continuation request\n");
@@ -828,8 +825,6 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
}
if ((resp2 = parse_response_code(ctx, &cmdp->cb, cmd)) > resp)
resp = resp2;
- if (cmdp->cb.done)
- cmdp->cb.done(ctx, cmdp, resp);
free(cmdp->cb.data);
free(cmdp->cmd);
free(cmdp);
@@ -917,7 +912,7 @@ static char *cram(const char *challenge_64, const char *user, const char *pass)
#endif
-static int auth_cram_md5(struct imap_store *ctx, struct imap_cmd *cmd, const char *prompt)
+static int auth_cram_md5(struct imap_store *ctx, const char *prompt)
{
int ret;
char *response;
@@ -1323,7 +1318,8 @@ static int split_msg(struct strbuf *all_msgs, struct strbuf *msg, int *ofs)
return 1;
}
-static int git_imap_config(const char *var, const char *val, void *cb)
+static int git_imap_config(const char *var, const char *val,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp("imap.sslverify", var))
@@ -1341,7 +1337,7 @@ static int git_imap_config(const char *var, const char *val, void *cb)
else if (!strcmp("imap.authmethod", var))
return git_config_string(&server.auth_method, var, val);
else if (!strcmp("imap.port", var))
- server.port = git_config_int(var, val);
+ server.port = git_config_int(var, val, ctx->kvi);
else if (!strcmp("imap.host", var)) {
if (!val) {
git_die_config("imap.host", "Missing value for 'imap.host'");
@@ -1357,7 +1353,7 @@ static int git_imap_config(const char *var, const char *val, void *cb)
server.host = xstrdup(val);
}
} else
- return git_default_config(var, val, cb);
+ return git_default_config(var, val, ctx, cb);
return 0;
}
@@ -1415,16 +1411,16 @@ static CURL *setup_curl(struct imap_server_conf *srvc, struct credential *cred)
if (!curl)
die("curl_easy_init failed");
- server_fill_credential(&server, cred);
- curl_easy_setopt(curl, CURLOPT_USERNAME, server.user);
- curl_easy_setopt(curl, CURLOPT_PASSWORD, server.pass);
+ server_fill_credential(srvc, cred);
+ curl_easy_setopt(curl, CURLOPT_USERNAME, srvc->user);
+ curl_easy_setopt(curl, CURLOPT_PASSWORD, srvc->pass);
- strbuf_addstr(&path, server.use_ssl ? "imaps://" : "imap://");
- strbuf_addstr(&path, server.host);
+ strbuf_addstr(&path, srvc->use_ssl ? "imaps://" : "imap://");
+ strbuf_addstr(&path, srvc->host);
if (!path.len || path.buf[path.len - 1] != '/')
strbuf_addch(&path, '/');
- uri_encoded_folder = curl_easy_escape(curl, server.folder, 0);
+ uri_encoded_folder = curl_easy_escape(curl, srvc->folder, 0);
if (!uri_encoded_folder)
die("failed to encode server folder");
strbuf_addstr(&path, uri_encoded_folder);
@@ -1432,25 +1428,25 @@ static CURL *setup_curl(struct imap_server_conf *srvc, struct credential *cred)
curl_easy_setopt(curl, CURLOPT_URL, path.buf);
strbuf_release(&path);
- curl_easy_setopt(curl, CURLOPT_PORT, server.port);
+ curl_easy_setopt(curl, CURLOPT_PORT, srvc->port);
- if (server.auth_method) {
+ if (srvc->auth_method) {
#ifndef GIT_CURL_HAVE_CURLOPT_LOGIN_OPTIONS
warning("No LOGIN_OPTIONS support in this cURL version");
#else
struct strbuf auth = STRBUF_INIT;
strbuf_addstr(&auth, "AUTH=");
- strbuf_addstr(&auth, server.auth_method);
+ strbuf_addstr(&auth, srvc->auth_method);
curl_easy_setopt(curl, CURLOPT_LOGIN_OPTIONS, auth.buf);
strbuf_release(&auth);
#endif
}
- if (!server.use_ssl)
+ if (!srvc->use_ssl)
curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_TRY);
- curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, server.ssl_verify);
- curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, server.ssl_verify);
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, srvc->ssl_verify);
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, srvc->ssl_verify);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, fread_buffer);
diff --git a/khash.h b/khash.h
index 56241e6a5c..ff88163177 100644
--- a/khash.h
+++ b/khash.h
@@ -26,7 +26,6 @@
#ifndef __AC_KHASH_H
#define __AC_KHASH_H
-#include "hashmap.h"
#include "hash.h"
#define AC_VERSION_KHASH_H "0.2.8"
@@ -62,7 +61,7 @@ static inline khint_t __ac_X31_hash_string(const char *s)
static const double __ac_HASH_UPPER = 0.77;
#define __KHASH_TYPE(name, khkey_t, khval_t) \
- typedef struct { \
+ typedef struct kh_##name { \
khint_t n_buckets, size, n_occupied, upper_bound; \
khint32_t *flags; \
khkey_t *keys; \
diff --git a/kwset.c b/kwset.c
index 4b14d4f86b..bbfcf815a5 100644
--- a/kwset.c
+++ b/kwset.c
@@ -49,6 +49,42 @@ static void *obstack_chunk_alloc(long size)
#define U(c) ((unsigned char) (c))
+/* For case-insensitive kwset */
+const unsigned char tolower_trans_tbl[256] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ ' ', '!', '"', '#', '$', '%', '&', 0x27,
+ '(', ')', '*', '+', ',', '-', '.', '/',
+ '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', ':', ';', '<', '=', '>', '?',
+ '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
+ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
+ 'x', 'y', 'z', '[', 0x5c, ']', '^', '_',
+ '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
+ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
+ 'x', 'y', 'z', '{', '|', '}', '~', 0x7f,
+ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
+ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
+ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+ 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
+ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
+ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
+ 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
+ 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
+ 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
+ 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
+ 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
+};
+
/* Balanced tree of edges and labels leaving a given trie node. */
struct tree
{
diff --git a/kwset.h b/kwset.h
index f50ecae573..d42a793a30 100644
--- a/kwset.h
+++ b/kwset.h
@@ -26,6 +26,8 @@
The author may be reached (Email) at the address mike@ai.mit.edu,
or (US mail) as Mike Haertel c/o Free Software Foundation. */
+extern const unsigned char tolower_trans_tbl[256];
+
struct kwsmatch
{
int index; /* Index number of matching keyword. */
diff --git a/line-log.c b/line-log.c
index 6a7ac312a4..790ab73212 100644
--- a/line-log.c
+++ b/line-log.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "line-range.h"
#include "hex.h"
#include "tag.h"
@@ -8,6 +7,7 @@
#include "diff.h"
#include "commit.h"
#include "decorate.h"
+#include "repository.h"
#include "revision.h"
#include "xdiff-interface.h"
#include "strbuf.h"
diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c
index 2a3b7881af..8a08b7af49 100644
--- a/list-objects-filter-options.c
+++ b/list-objects-filter-options.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "commit.h"
#include "config.h"
#include "gettext.h"
diff --git a/list-objects-filter-options.h b/list-objects-filter-options.h
index f620612586..55fab8563d 100644
--- a/list-objects-filter-options.h
+++ b/list-objects-filter-options.h
@@ -3,7 +3,6 @@
#include "gettext.h"
#include "object.h"
-#include "string-list.h"
#include "strbuf.h"
struct option;
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 5d270ce598..9327ccd505 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "dir.h"
#include "gettext.h"
#include "hex.h"
@@ -16,7 +15,7 @@
#include "oidmap.h"
#include "oidset.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
/* Remember to update object flag allocation in object.h */
/*
diff --git a/list-objects.c b/list-objects.c
index eecca721ac..e60a6cd5b4 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -12,7 +12,7 @@
#include "list-objects-filter.h"
#include "list-objects-filter-options.h"
#include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "trace.h"
struct traversal_context {
@@ -102,7 +102,7 @@ static void process_tree_contents(struct traversal_context *ctx,
while (tree_entry(&desc, &entry)) {
if (match != all_entries_interesting) {
match = tree_entry_interesting(ctx->revs->repo->index,
- &entry, base, 0,
+ &entry, base,
&ctx->revs->diffopt.pathspec);
if (match == all_entries_not_interesting)
break;
diff --git a/log-tree.c b/log-tree.c
index f4b22a60cc..208c69cbb7 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -5,7 +5,7 @@
#include "environment.h"
#include "hex.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "repository.h"
#include "tmp-objdir.h"
#include "commit.h"
@@ -16,6 +16,7 @@
#include "reflog-walk.h"
#include "refs.h"
#include "replace-object.h"
+#include "revision.h"
#include "string-list.h"
#include "color.h"
#include "gpg-interface.h"
@@ -25,6 +26,7 @@
#include "range-diff.h"
#include "strmap.h"
#include "tree.h"
+#include "wildmatch.h"
#include "write-or-die.h"
static struct decoration name_decoration = { "object names" };
@@ -156,7 +158,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
if (starts_with(refname, git_replace_ref_base)) {
struct object_id original_oid;
- if (!read_replace_refs)
+ if (!replace_refs_enabled(the_repository))
return 0;
if (get_oid_hex(refname + strlen(git_replace_ref_base),
&original_oid)) {
diff --git a/log-tree.h b/log-tree.h
index e7e4641cf8..bdb6432815 100644
--- a/log-tree.h
+++ b/log-tree.h
@@ -1,7 +1,7 @@
#ifndef LOG_TREE_H
#define LOG_TREE_H
-#include "revision.h"
+struct rev_info;
struct log_info {
struct commit *commit, *parent;
diff --git a/ls-refs.c b/ls-refs.c
index f385938b64..0e49b932c3 100644
--- a/ls-refs.c
+++ b/ls-refs.c
@@ -72,7 +72,7 @@ struct ls_refs_data {
unsigned symrefs;
struct strvec prefixes;
struct strbuf buf;
- struct string_list hidden_refs;
+ struct strvec hidden_refs;
unsigned unborn : 1;
};
@@ -137,6 +137,7 @@ static void send_possibly_unborn_head(struct ls_refs_data *data)
}
static int ls_refs_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb_data)
{
struct ls_refs_data *data = cb_data;
@@ -155,7 +156,7 @@ int ls_refs(struct repository *r, struct packet_reader *request)
memset(&data, 0, sizeof(data));
strvec_init(&data.prefixes);
strbuf_init(&data.buf, 0);
- string_list_init_dup(&data.hidden_refs);
+ strvec_init(&data.hidden_refs);
git_config(ls_refs_config, &data);
@@ -193,11 +194,12 @@ int ls_refs(struct repository *r, struct packet_reader *request)
strvec_push(&data.prefixes, "");
refs_for_each_fullref_in_prefixes(get_main_ref_store(r),
get_git_namespace(), data.prefixes.v,
+ hidden_refs_to_excludes(&data.hidden_refs),
send_ref, &data);
packet_fflush(stdout);
strvec_clear(&data.prefixes);
strbuf_release(&data.buf);
- string_list_clear(&data.hidden_refs, 0);
+ strvec_clear(&data.hidden_refs);
return 0;
}
diff --git a/mailinfo.c b/mailinfo.c
index 2aeb20e5e6..931505363c 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -1241,12 +1241,13 @@ int mailinfo_parse_quoted_cr_action(const char *actionstr, int *action)
return 0;
}
-static int git_mailinfo_config(const char *var, const char *value, void *mi_)
+static int git_mailinfo_config(const char *var, const char *value,
+ const struct config_context *ctx, void *mi_)
{
struct mailinfo *mi = mi_;
if (!starts_with(var, "mailinfo."))
- return git_default_config(var, value, NULL);
+ return git_default_config(var, value, ctx, NULL);
if (!strcmp(var, "mailinfo.scissors")) {
mi->use_scissors = git_config_bool(var, value);
return 0;
diff --git a/mailmap.c b/mailmap.c
index 5dc5223c43..3d6a5e9400 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -3,7 +3,7 @@
#include "string-list.h"
#include "mailmap.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "setup.h"
const char *git_mailmap_file;
diff --git a/match-trees.c b/match-trees.c
index 6bc8eb7647..0885ac681c 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -1,9 +1,10 @@
#include "git-compat-util.h"
#include "hex.h"
#include "match-trees.h"
+#include "strbuf.h"
#include "tree.h"
#include "tree-walk.h"
-#include "object-store.h"
+#include "object-store-ll.h"
static int score_missing(unsigned mode)
{
diff --git a/merge-blobs.c b/merge-blobs.c
index 5632ff6abb..9293cbf75c 100644
--- a/merge-blobs.c
+++ b/merge-blobs.c
@@ -1,10 +1,10 @@
#include "git-compat-util.h"
#include "run-command.h"
#include "xdiff-interface.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
#include "blob.h"
#include "merge-blobs.h"
-#include "object-store.h"
+#include "object-store-ll.h"
static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
{
diff --git a/ll-merge.c b/merge-ll.c
index 07ec16e8e5..8fcf2d3710 100644
--- a/ll-merge.c
+++ b/merge-ll.c
@@ -10,10 +10,9 @@
#include "attr.h"
#include "xdiff-interface.h"
#include "run-command.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
#include "quote.h"
#include "strbuf.h"
-#include "wrapper.h"
struct ll_merge_driver;
@@ -192,24 +191,15 @@ static enum ll_merge_result ll_ext_merge(const struct ll_merge_driver *fn,
const struct ll_merge_options *opts,
int marker_size)
{
- char temp[4][50];
+ char temp[3][50];
struct strbuf cmd = STRBUF_INIT;
- struct strbuf_expand_dict_entry dict[6];
- struct strbuf path_sq = STRBUF_INIT;
+ const char *format = fn->cmdline;
struct child_process child = CHILD_PROCESS_INIT;
int status, fd, i;
struct stat st;
enum ll_merge_result ret;
assert(opts);
- sq_quote_buf(&path_sq, path);
- dict[0].placeholder = "O"; dict[0].value = temp[0];
- dict[1].placeholder = "A"; dict[1].value = temp[1];
- dict[2].placeholder = "B"; dict[2].value = temp[2];
- dict[3].placeholder = "L"; dict[3].value = temp[3];
- dict[4].placeholder = "P"; dict[4].value = path_sq.buf;
- dict[5].placeholder = NULL; dict[5].value = NULL;
-
if (!fn->cmdline)
die("custom merge driver %s lacks command line.", fn->name);
@@ -218,9 +208,23 @@ static enum ll_merge_result ll_ext_merge(const struct ll_merge_driver *fn,
create_temp(orig, temp[0], sizeof(temp[0]));
create_temp(src1, temp[1], sizeof(temp[1]));
create_temp(src2, temp[2], sizeof(temp[2]));
- xsnprintf(temp[3], sizeof(temp[3]), "%d", marker_size);
- strbuf_expand(&cmd, fn->cmdline, strbuf_expand_dict_cb, &dict);
+ while (strbuf_expand_step(&cmd, &format)) {
+ if (skip_prefix(format, "%", &format))
+ strbuf_addch(&cmd, '%');
+ else if (skip_prefix(format, "O", &format))
+ strbuf_addstr(&cmd, temp[0]);
+ else if (skip_prefix(format, "A", &format))
+ strbuf_addstr(&cmd, temp[1]);
+ else if (skip_prefix(format, "B", &format))
+ strbuf_addstr(&cmd, temp[2]);
+ else if (skip_prefix(format, "L", &format))
+ strbuf_addf(&cmd, "%d", marker_size);
+ else if (skip_prefix(format, "P", &format))
+ sq_quote_buf(&cmd, path);
+ else
+ strbuf_addch(&cmd, '%');
+ }
child.use_shell = 1;
strvec_push(&child.args, cmd.buf);
@@ -242,8 +246,13 @@ static enum ll_merge_result ll_ext_merge(const struct ll_merge_driver *fn,
for (i = 0; i < 3; i++)
unlink_or_warn(temp[i]);
strbuf_release(&cmd);
- strbuf_release(&path_sq);
- ret = (status > 0) ? LL_MERGE_CONFLICT : status;
+ if (!status)
+ ret = LL_MERGE_OK;
+ else if (status <= 128)
+ ret = LL_MERGE_CONFLICT;
+ else
+ /* died due to a signal: WTERMSIG(status) + 128 */
+ ret = LL_MERGE_ERROR;
return ret;
}
@@ -254,6 +263,7 @@ static struct ll_merge_driver *ll_user_merge, **ll_user_merge_tail;
static const char *default_ll_merge;
static int read_merge_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
struct ll_merge_driver *fn;
diff --git a/ll-merge.h b/merge-ll.h
index e4a20e81a3..e4a20e81a3 100644
--- a/ll-merge.h
+++ b/merge-ll.h
diff --git a/merge-ort-wrappers.c b/merge-ort-wrappers.c
index a550753300..4acedf3c33 100644
--- a/merge-ort-wrappers.c
+++ b/merge-ort-wrappers.c
@@ -1,8 +1,9 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "gettext.h"
#include "hash.h"
#include "merge-ort.h"
#include "merge-ort-wrappers.h"
+#include "read-cache-ll.h"
#include "tree.h"
#include "commit.h"
diff --git a/merge-ort.c b/merge-ort.c
index a50b095c47..8631c99700 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -14,7 +14,7 @@
* "cale", "peedy", or "ins" instead of "ort"?)
*/
-#include "cache.h"
+#include "git-compat-util.h"
#include "merge-ort.h"
#include "alloc.h"
@@ -30,14 +30,17 @@
#include "gettext.h"
#include "hex.h"
#include "entry.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
#include "match-trees.h"
#include "mem-pool.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "oid-array.h"
+#include "path.h"
#include "promisor-remote.h"
+#include "read-cache-ll.h"
#include "revision.h"
+#include "sparse-index.h"
#include "strmap.h"
#include "submodule-config.h"
#include "submodule.h"
diff --git a/merge-recursive.c b/merge-recursive.c
index 8e87b6386d..6a4081bb0f 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -3,7 +3,7 @@
* Fredrik Kuivinen.
* The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
*/
-#include "cache.h"
+#include "git-compat-util.h"
#include "merge-recursive.h"
#include "advice.h"
@@ -20,14 +20,17 @@
#include "environment.h"
#include "gettext.h"
#include "hex.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
#include "lockfile.h"
#include "match-trees.h"
+#include "name-hash.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "path.h"
#include "repository.h"
#include "revision.h"
+#include "sparse-index.h"
#include "string-list.h"
#include "submodule-config.h"
#include "submodule.h"
@@ -35,7 +38,6 @@
#include "tag.h"
#include "tree-walk.h"
#include "unpack-trees.h"
-#include "wrapper.h"
#include "xdiff-interface.h"
struct merge_options_internal {
diff --git a/merge.c b/merge.c
index 10aaec3a6c..b60925459c 100644
--- a/merge.c
+++ b/merge.c
@@ -1,10 +1,13 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "diff.h"
#include "diffcore.h"
#include "gettext.h"
+#include "hash.h"
#include "hex.h"
#include "lockfile.h"
+#include "merge.h"
#include "commit.h"
+#include "repository.h"
#include "run-command.h"
#include "resolve-undo.h"
#include "tree.h"
diff --git a/merge.h b/merge.h
new file mode 100644
index 0000000000..21ac7ef2f1
--- /dev/null
+++ b/merge.h
@@ -0,0 +1,17 @@
+#ifndef MERGE_H
+#define MERGE_H
+
+struct commit_list;
+struct object_id;
+struct repository;
+
+int try_merge_command(struct repository *r,
+ const char *strategy, size_t xopts_nr,
+ const char **xopts, struct commit_list *common,
+ const char *head_arg, struct commit_list *remotes);
+int checkout_fast_forward(struct repository *r,
+ const struct object_id *from,
+ const struct object_id *to,
+ int overwrite_ignore);
+
+#endif /* MERGE_H */
diff --git a/midx.c b/midx.c
index b500174d1f..931f557350 100644
--- a/midx.c
+++ b/midx.c
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "csum-file.h"
#include "dir.h"
@@ -9,7 +8,7 @@
#include "lockfile.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "hash-lookup.h"
#include "midx.h"
#include "progress.h"
@@ -254,7 +253,7 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid,
if (n >= m->num_objects)
return NULL;
- oidread(oid, m->chunk_oid_lookup + m->hash_len * n);
+ oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n));
return oid;
}
@@ -271,7 +270,8 @@ off_t nth_midxed_offset(struct multi_pack_index *m, uint32_t pos)
die(_("multi-pack-index stores a 64-bit offset, but off_t is too small"));
offset32 ^= MIDX_LARGE_OFFSET_NEEDED;
- return get_be64(m->chunk_large_offsets + sizeof(uint64_t) * offset32);
+ return get_be64(m->chunk_large_offsets +
+ st_mult(sizeof(uint64_t), offset32));
}
return offset32;
@@ -445,14 +445,14 @@ static int idx_or_pack_name_cmp(const void *_va, const void *_vb)
struct write_midx_context {
struct pack_info *info;
- uint32_t nr;
- uint32_t alloc;
+ size_t nr;
+ size_t alloc;
struct multi_pack_index *m;
struct progress *progress;
unsigned pack_paths_checked;
struct pack_midx_entry *entries;
- uint32_t entries_nr;
+ size_t entries_nr;
uint32_t *pack_perm;
uint32_t *pack_order;
@@ -584,12 +584,14 @@ static void fill_pack_entry(uint32_t pack_int_id,
struct midx_fanout {
struct pack_midx_entry *entries;
- uint32_t nr;
- uint32_t alloc;
+ size_t nr, alloc;
};
-static void midx_fanout_grow(struct midx_fanout *fanout, uint32_t nr)
+static void midx_fanout_grow(struct midx_fanout *fanout, size_t nr)
{
+ if (nr < fanout->nr)
+ BUG("negative growth in midx_fanout_grow() (%"PRIuMAX" < %"PRIuMAX")",
+ (uintmax_t)nr, (uintmax_t)fanout->nr);
ALLOC_GROW(fanout->entries, nr, fanout->alloc);
}
@@ -668,17 +670,18 @@ static void midx_fanout_add_pack_fanout(struct midx_fanout *fanout,
static struct pack_midx_entry *get_sorted_entries(struct multi_pack_index *m,
struct pack_info *info,
uint32_t nr_packs,
- uint32_t *nr_objects,
+ size_t *nr_objects,
int preferred_pack)
{
uint32_t cur_fanout, cur_pack, cur_object;
- uint32_t alloc_objects, total_objects = 0;
+ size_t alloc_objects, total_objects = 0;
struct midx_fanout fanout = { 0 };
struct pack_midx_entry *deduplicated_entries = NULL;
uint32_t start_pack = m ? m->num_packs : 0;
for (cur_pack = start_pack; cur_pack < nr_packs; cur_pack++)
- total_objects += info[cur_pack].p->num_objects;
+ total_objects = st_add(total_objects,
+ info[cur_pack].p->num_objects);
/*
* As we de-duplicate by fanout value, we expect the fanout
@@ -721,7 +724,8 @@ static struct pack_midx_entry *get_sorted_entries(struct multi_pack_index *m,
&fanout.entries[cur_object].oid))
continue;
- ALLOC_GROW(deduplicated_entries, *nr_objects + 1, alloc_objects);
+ ALLOC_GROW(deduplicated_entries, st_add(*nr_objects, 1),
+ alloc_objects);
memcpy(&deduplicated_entries[*nr_objects],
&fanout.entries[cur_object],
sizeof(struct pack_midx_entry));
@@ -1496,21 +1500,22 @@ static int write_midx_internal(const char *object_dir,
add_chunk(cf, MIDX_CHUNKID_OIDFANOUT, MIDX_CHUNK_FANOUT_SIZE,
write_midx_oid_fanout);
add_chunk(cf, MIDX_CHUNKID_OIDLOOKUP,
- (size_t)ctx.entries_nr * the_hash_algo->rawsz,
+ st_mult(ctx.entries_nr, the_hash_algo->rawsz),
write_midx_oid_lookup);
add_chunk(cf, MIDX_CHUNKID_OBJECTOFFSETS,
- (size_t)ctx.entries_nr * MIDX_CHUNK_OFFSET_WIDTH,
+ st_mult(ctx.entries_nr, MIDX_CHUNK_OFFSET_WIDTH),
write_midx_object_offsets);
if (ctx.large_offsets_needed)
add_chunk(cf, MIDX_CHUNKID_LARGEOFFSETS,
- (size_t)ctx.num_large_offsets * MIDX_CHUNK_LARGE_OFFSET_WIDTH,
+ st_mult(ctx.num_large_offsets,
+ MIDX_CHUNK_LARGE_OFFSET_WIDTH),
write_midx_large_offsets);
if (flags & (MIDX_WRITE_REV_INDEX | MIDX_WRITE_BITMAP)) {
ctx.pack_order = midx_pack_order(&ctx);
add_chunk(cf, MIDX_CHUNKID_REVINDEX,
- ctx.entries_nr * sizeof(uint32_t),
+ st_mult(ctx.entries_nr, sizeof(uint32_t)),
write_midx_revindex);
}
@@ -1988,8 +1993,8 @@ static int fill_included_packs_batch(struct repository *r,
if (open_pack_index(p) || !p->num_objects)
continue;
- expected_size = (size_t)(p->pack_size
- * pack_info[i].referenced_objects);
+ expected_size = st_mult(p->pack_size,
+ pack_info[i].referenced_objects);
expected_size /= p->num_objects;
if (expected_size >= batch_size)
diff --git a/name-hash.c b/name-hash.c
index fb13716e43..251f036eef 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -5,9 +5,12 @@
*
* Copyright (C) 2008 Linus Torvalds
*/
-#include "cache.h"
+#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
+#include "name-hash.h"
+#include "object.h"
+#include "read-cache-ll.h"
#include "thread-utils.h"
#include "trace.h"
#include "trace2.h"
diff --git a/name-hash.h b/name-hash.h
new file mode 100644
index 0000000000..b1b4b0fb33
--- /dev/null
+++ b/name-hash.h
@@ -0,0 +1,16 @@
+#ifndef NAME_HASH_H
+#define NAME_HASH_H
+
+struct cache_entry;
+struct index_state;
+
+int index_dir_exists(struct index_state *istate, const char *name, int namelen);
+void adjust_dirname_case(struct index_state *istate, char *name);
+struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase);
+
+int test_lazy_init_name_hash(struct index_state *istate, int try_threaded);
+void add_name_hash(struct index_state *istate, struct cache_entry *ce);
+void remove_name_hash(struct index_state *istate, struct cache_entry *ce);
+void free_name_hash(struct index_state *istate);
+
+#endif /* NAME_HASH_H */
diff --git a/notes-cache.c b/notes-cache.c
index 14288caf98..0e1d5b1ac7 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -1,10 +1,11 @@
#include "git-compat-util.h"
#include "notes-cache.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "pretty.h"
#include "repository.h"
#include "commit.h"
#include "refs.h"
+#include "strbuf.h"
static int notes_cache_match_validity(struct repository *r,
const char *ref,
diff --git a/notes-merge.c b/notes-merge.c
index 233e49e319..8799b522a5 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -5,13 +5,14 @@
#include "refs.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "path.h"
#include "repository.h"
#include "diff.h"
#include "diffcore.h"
#include "hex.h"
#include "xdiff-interface.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
#include "dir.h"
#include "notes.h"
#include "notes-merge.h"
@@ -19,7 +20,6 @@
#include "trace.h"
#include "notes-utils.h"
#include "commit-reach.h"
-#include "wrapper.h"
struct notes_merge_pair {
struct object_id obj, base, local, remote;
diff --git a/notes-utils.c b/notes-utils.c
index 4a793eb347..97c031c26e 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -94,7 +94,9 @@ static combine_notes_fn parse_combine_notes_fn(const char *v)
return NULL;
}
-static int notes_rewrite_config(const char *k, const char *v, void *cb)
+static int notes_rewrite_config(const char *k, const char *v,
+ const struct config_context *ctx UNUSED,
+ void *cb)
{
struct notes_rewrite_cfg *c = cb;
if (starts_with(k, "notes.rewrite.") && !strcmp(k+14, c->cmd)) {
diff --git a/notes.c b/notes.c
index f51a2d3630..1ef2a331ce 100644
--- a/notes.c
+++ b/notes.c
@@ -4,7 +4,7 @@
#include "hex.h"
#include "notes.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "blob.h"
#include "tree.h"
#include "utf8.h"
@@ -974,7 +974,9 @@ void string_list_add_refs_from_colon_sep(struct string_list *list,
free(globs_copy);
}
-static int notes_display_config(const char *k, const char *v, void *cb)
+static int notes_display_config(const char *k, const char *v,
+ const struct config_context *ctx UNUSED,
+ void *cb)
{
int *load_refs = cb;
diff --git a/notes.h b/notes.h
index c1682c39a9..064fd7143a 100644
--- a/notes.h
+++ b/notes.h
@@ -256,7 +256,17 @@ void free_notes(struct notes_tree *t);
struct string_list;
struct display_notes_opt {
+ /*
+ * Less than `0` is "unset", which means that the default notes
+ * are shown iff no other notes are given. Otherwise,
+ * treat it like a boolean.
+ */
int use_default_notes;
+
+ /*
+ * A list of globs (in the same style as notes.displayRef) where
+ * notes should be loaded from.
+ */
struct string_list extra_notes_refs;
};
@@ -283,14 +293,7 @@ void disable_display_notes(struct display_notes_opt *opt, int *show_notes);
/*
* Load the notes machinery for displaying several notes trees.
*
- * If 'opt' is not NULL, then it specifies additional settings for the
- * displaying:
- *
- * - suppress_default_notes indicates that the notes from
- * core.notesRef and notes.displayRef should not be loaded.
- *
- * - extra_notes_refs may contain a list of globs (in the same style
- * as notes.displayRef) where notes should be loaded from.
+ * 'opt' may be NULL.
*/
void load_display_notes(struct display_notes_opt *opt);
diff --git a/object-file.c b/object-file.c
index 7c1af5c8db..7dc0c4bfbb 100644
--- a/object-file.c
+++ b/object-file.c
@@ -8,7 +8,6 @@
*/
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "convert.h"
#include "environment.h"
@@ -39,11 +38,11 @@
#include "object-file.h"
#include "object-store.h"
#include "oidtree.h"
+#include "path.h"
#include "promisor-remote.h"
#include "setup.h"
#include "submodule.h"
#include "fsck.h"
-#include "wrapper.h"
/* The maximum size for an object header. */
#define MAX_HEADER_LEN 32
@@ -2307,11 +2306,11 @@ int repo_has_object_file(struct repository *r,
* report the minimal fsck error here, and rely on the caller to
* give more context.
*/
-static int hash_format_check_report(struct fsck_options *opts,
- const struct object_id *oid,
- enum object_type object_type,
- enum fsck_msg_type msg_type,
- enum fsck_msg_id msg_id,
+static int hash_format_check_report(struct fsck_options *opts UNUSED,
+ const struct object_id *oid UNUSED,
+ enum object_type object_type UNUSED,
+ enum fsck_msg_type msg_type UNUSED,
+ enum fsck_msg_id msg_id UNUSED,
const char *message)
{
error(_("object fails fsck: %s"), message);
diff --git a/object-name.c b/object-name.c
index 6fc3fa595b..0bfa29dbbf 100644
--- a/object-name.c
+++ b/object-name.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "object-name.h"
#include "advice.h"
#include "config.h"
@@ -17,7 +17,8 @@
#include "oidtree.h"
#include "packfile.h"
#include "pretty.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "read-cache-ll.h"
#include "repository.h"
#include "setup.h"
#include "submodule.h"
@@ -768,6 +769,21 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
find_abbrev_len_for_pack(p, mad);
}
+void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo,
+ const struct object_id *oid, int abbrev_len)
+{
+ int r;
+ strbuf_grow(sb, GIT_MAX_HEXSZ + 1);
+ r = repo_find_unique_abbrev_r(repo, sb->buf + sb->len, oid, abbrev_len);
+ strbuf_setlen(sb, sb->len + r);
+}
+
+void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
+ int abbrev_len)
+{
+ strbuf_repo_add_unique_abbrev(sb, the_repository, oid, abbrev_len);
+}
+
int repo_find_unique_abbrev_r(struct repository *r, char *hex,
const struct object_id *oid, int len)
{
diff --git a/object-name.h b/object-name.h
index 1d63698f42..9ae5223071 100644
--- a/object-name.h
+++ b/object-name.h
@@ -40,6 +40,15 @@ struct object_context {
const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len);
int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);
+/**
+ * Add the abbreviation, as generated by repo_find_unique_abbrev(), of `sha1` to
+ * the strbuf `sb`.
+ */
+void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo,
+ const struct object_id *oid, int abbrev_len);
+void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
+ int abbrev_len);
+
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/object-store-ll.h b/object-store-ll.h
new file mode 100644
index 0000000000..26a3895c82
--- /dev/null
+++ b/object-store-ll.h
@@ -0,0 +1,533 @@
+#ifndef OBJECT_STORE_LL_H
+#define OBJECT_STORE_LL_H
+
+#include "hashmap.h"
+#include "object.h"
+#include "list.h"
+#include "thread-utils.h"
+#include "oidset.h"
+
+struct oidmap;
+struct oidtree;
+struct strbuf;
+
+struct object_directory {
+ struct object_directory *next;
+
+ /*
+ * Used to store the results of readdir(3) calls when we are OK
+ * sacrificing accuracy due to races for speed. That includes
+ * object existence with OBJECT_INFO_QUICK, as well as
+ * our search for unique abbreviated hashes. Don't use it for tasks
+ * requiring greater accuracy!
+ *
+ * Be sure to call odb_load_loose_cache() before using.
+ */
+ uint32_t loose_objects_subdir_seen[8]; /* 256 bits */
+ struct oidtree *loose_objects_cache;
+
+ /*
+ * This is a temporary object store created by the tmp_objdir
+ * facility. Disable ref updates since the objects in the store
+ * might be discarded on rollback.
+ */
+ int disable_ref_updates;
+
+ /*
+ * This object store is ephemeral, so there is no need to fsync.
+ */
+ int will_destroy;
+
+ /*
+ * Path to the alternative object store. If this is a relative path,
+ * it is relative to the current working directory.
+ */
+ char *path;
+};
+
+struct input_stream {
+ const void *(*read)(struct input_stream *, unsigned long *len);
+ void *data;
+ int is_finished;
+};
+
+void prepare_alt_odb(struct repository *r);
+int has_alt_odb(struct repository *r);
+char *compute_alternate_path(const char *path, struct strbuf *err);
+struct object_directory *find_odb(struct repository *r, const char *obj_dir);
+typedef int alt_odb_fn(struct object_directory *, void *);
+int foreach_alt_odb(alt_odb_fn, void*);
+typedef void alternate_ref_fn(const struct object_id *oid, void *);
+void for_each_alternate_ref(alternate_ref_fn, void *);
+
+/*
+ * Add the directory to the on-disk alternates file; the new entry will also
+ * take effect in the current process.
+ */
+void add_to_alternates_file(const char *dir);
+
+/*
+ * Add the directory to the in-memory list of alternates (along with any
+ * recursive alternates it points to), but do not modify the on-disk alternates
+ * file.
+ */
+void add_to_alternates_memory(const char *dir);
+
+/*
+ * Replace the current writable object directory with the specified temporary
+ * object directory; returns the former primary object directory.
+ */
+struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
+
+/*
+ * Restore a previous ODB replaced by set_temporary_main_odb.
+ */
+void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
+
+/*
+ * Populate and return the loose object cache array corresponding to the
+ * given object ID.
+ */
+struct oidtree *odb_loose_cache(struct object_directory *odb,
+ const struct object_id *oid);
+
+/* Empty the loose object cache for the specified object directory. */
+void odb_clear_loose_cache(struct object_directory *odb);
+
+/* Clear and free the specified object directory */
+void free_object_directory(struct object_directory *odb);
+
+struct packed_git {
+ struct hashmap_entry packmap_ent;
+ struct packed_git *next;
+ struct list_head mru;
+ struct pack_window *windows;
+ off_t pack_size;
+ const void *index_data;
+ size_t index_size;
+ uint32_t num_objects;
+ size_t crc_offset;
+ struct oidset bad_objects;
+ int index_version;
+ time_t mtime;
+ int pack_fd;
+ int index; /* for builtin/pack-objects.c */
+ unsigned pack_local:1,
+ pack_keep:1,
+ pack_keep_in_core:1,
+ freshened:1,
+ do_not_close:1,
+ pack_promisor:1,
+ multi_pack_index:1,
+ is_cruft:1;
+ unsigned char hash[GIT_MAX_RAWSZ];
+ struct revindex_entry *revindex;
+ const uint32_t *revindex_data;
+ const uint32_t *revindex_map;
+ size_t revindex_size;
+ /*
+ * mtimes_map points at the beginning of the memory mapped region of
+ * this pack's corresponding .mtimes file, and mtimes_size is the size
+ * of that .mtimes file
+ */
+ const uint32_t *mtimes_map;
+ size_t mtimes_size;
+ /* something like ".git/objects/pack/xxxxx.pack" */
+ char pack_name[FLEX_ARRAY]; /* more */
+};
+
+struct multi_pack_index;
+
+static inline int pack_map_entry_cmp(const void *cmp_data UNUSED,
+ const struct hashmap_entry *entry,
+ const struct hashmap_entry *entry2,
+ const void *keydata)
+{
+ const char *key = keydata;
+ const struct packed_git *pg1, *pg2;
+
+ pg1 = container_of(entry, const struct packed_git, packmap_ent);
+ pg2 = container_of(entry2, const struct packed_git, packmap_ent);
+
+ return strcmp(pg1->pack_name, key ? key : pg2->pack_name);
+}
+
+struct raw_object_store {
+ /*
+ * Set of all object directories; the main directory is first (and
+ * cannot be NULL after initialization). Subsequent directories are
+ * alternates.
+ */
+ struct object_directory *odb;
+ struct object_directory **odb_tail;
+ struct kh_odb_path_map *odb_by_path;
+
+ int loaded_alternates;
+
+ /*
+ * A list of alternate object directories loaded from the environment;
+ * this should not generally need to be accessed directly, but will
+ * populate the "odb" list when prepare_alt_odb() is run.
+ */
+ char *alternate_db;
+
+ /*
+ * Objects that should be substituted by other objects
+ * (see git-replace(1)).
+ */
+ struct oidmap *replace_map;
+ unsigned replace_map_initialized : 1;
+ pthread_mutex_t replace_mutex; /* protect object replace functions */
+
+ struct commit_graph *commit_graph;
+ unsigned commit_graph_attempted : 1; /* if loading has been attempted */
+
+ /*
+ * private data
+ *
+ * should only be accessed directly by packfile.c and midx.c
+ */
+ struct multi_pack_index *multi_pack_index;
+
+ /*
+ * private data
+ *
+ * should only be accessed directly by packfile.c
+ */
+
+ struct packed_git *packed_git;
+ /* A most-recently-used ordered version of the packed_git list. */
+ struct list_head packed_git_mru;
+
+ struct {
+ struct packed_git **packs;
+ unsigned flags;
+ } kept_pack_cache;
+
+ /*
+ * A map of packfiles to packed_git structs for tracking which
+ * packs have been loaded already.
+ */
+ struct hashmap pack_map;
+
+ /*
+ * A fast, rough count of the number of objects in the repository.
+ * These two fields are not meant for direct access. Use
+ * repo_approximate_object_count() instead.
+ */
+ unsigned long approximate_object_count;
+ unsigned approximate_object_count_valid : 1;
+
+ /*
+ * Whether packed_git has already been populated with this repository's
+ * packs.
+ */
+ unsigned packed_git_initialized : 1;
+};
+
+struct raw_object_store *raw_object_store_new(void);
+void raw_object_store_clear(struct raw_object_store *o);
+
+/*
+ * Put in `buf` the name of the file in the local object database that
+ * would be used to store a loose object with the specified oid.
+ */
+const char *loose_object_path(struct repository *r, struct strbuf *buf,
+ const struct object_id *oid);
+
+void *map_loose_object(struct repository *r, const struct object_id *oid,
+ unsigned long *size);
+
+void *repo_read_object_file(struct repository *r,
+ const struct object_id *oid,
+ enum object_type *type,
+ unsigned long *size);
+
+/* Read and unpack an object file into memory, write memory to an object file */
+int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
+
+void hash_object_file(const struct git_hash_algo *algo, const void *buf,
+ unsigned long len, enum object_type type,
+ struct object_id *oid);
+
+int write_object_file_flags(const void *buf, unsigned long len,
+ enum object_type type, struct object_id *oid,
+ unsigned flags);
+static inline int write_object_file(const void *buf, unsigned long len,
+ enum object_type type, struct object_id *oid)
+{
+ return write_object_file_flags(buf, len, type, oid, 0);
+}
+
+int write_object_file_literally(const void *buf, unsigned long len,
+ const char *type, struct object_id *oid,
+ unsigned flags);
+int stream_loose_object(struct input_stream *in_stream, size_t len,
+ struct object_id *oid);
+
+/*
+ * Add an object file to the in-memory object store, without writing it
+ * to disk.
+ *
+ * Callers are responsible for calling write_object_file to record the
+ * object in persistent storage before writing any other new objects
+ * that reference it.
+ */
+int pretend_object_file(void *, unsigned long, enum object_type,
+ struct object_id *oid);
+
+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
+ * type, and size. If the object is a blob, then "contents" may return NULL,
+ * to allow streaming of large blobs.
+ *
+ * Returns 0 on success, negative on error (details may be written to stderr).
+ */
+int read_loose_object(const char *path,
+ const struct object_id *expected_oid,
+ struct object_id *real_oid,
+ void **contents,
+ struct object_info *oi);
+
+/* Retry packed storage after checking packed and loose storage */
+#define HAS_OBJECT_RECHECK_PACKED 1
+
+/*
+ * Returns 1 if the object exists. This function will not lazily fetch objects
+ * in a partial clone.
+ */
+int has_object(struct repository *r, const struct object_id *oid,
+ unsigned flags);
+
+/*
+ * These macros and functions are deprecated. If checking existence for an
+ * object that is likely to be missing and/or whose absence is relatively
+ * inconsequential (or is consequential but the caller is prepared to handle
+ * it), use has_object(), which has better defaults (no lazy fetch in a partial
+ * clone and no rechecking of packed storage). In the unlikely event that a
+ * caller needs to assert existence of an object that it fully expects to
+ * exist, and wants to trigger a lazy fetch in a partial clone, use
+ * oid_object_info_extended() with a NULL struct object_info.
+ *
+ * These functions can be removed once all callers have migrated to
+ * has_object() and/or oid_object_info_extended().
+ */
+int repo_has_object_file(struct repository *r, const struct object_id *oid);
+int repo_has_object_file_with_flags(struct repository *r,
+ const struct object_id *oid, int flags);
+
+/*
+ * Return true iff an alternate object database has a loose object
+ * with the specified name. This function does not respect replace
+ * references.
+ */
+int has_loose_object_nonlocal(const struct object_id *);
+
+int has_loose_object(const struct object_id *);
+
+/**
+ * format_object_header() is a thin wrapper around s xsnprintf() that
+ * writes the initial "<type> <obj-len>" part of the loose object
+ * header. It returns the size that snprintf() returns + 1.
+ */
+int format_object_header(char *str, size_t size, enum object_type type,
+ size_t objsize);
+
+void assert_oid_type(const struct object_id *oid, enum object_type expect);
+
+/*
+ * Enabling the object read lock allows multiple threads to safely call the
+ * following functions in parallel: repo_read_object_file(),
+ * read_object_with_reference(), oid_object_info() and oid_object_info_extended().
+ *
+ * obj_read_lock() and obj_read_unlock() may also be used to protect other
+ * section which cannot execute in parallel with object reading. Since the used
+ * lock is a recursive mutex, these sections can even contain calls to object
+ * reading functions. However, beware that in these cases zlib inflation won't
+ * be performed in parallel, losing performance.
+ *
+ * TODO: oid_object_info_extended()'s call stack has a recursive behavior. If
+ * any of its callees end up calling it, this recursive call won't benefit from
+ * parallel inflation.
+ */
+void enable_obj_read_lock(void);
+void disable_obj_read_lock(void);
+
+extern int obj_read_use_lock;
+extern pthread_mutex_t obj_read_mutex;
+
+static inline void obj_read_lock(void)
+{
+ if(obj_read_use_lock)
+ pthread_mutex_lock(&obj_read_mutex);
+}
+
+static inline void obj_read_unlock(void)
+{
+ if(obj_read_use_lock)
+ pthread_mutex_unlock(&obj_read_mutex);
+}
+
+/*
+ * Iterate over the files in the loose-object parts of the object
+ * directory "path", triggering the following callbacks:
+ *
+ * - loose_object is called for each loose object we find.
+ *
+ * - loose_cruft is called for any files that do not appear to be
+ * loose objects. Note that we only look in the loose object
+ * directories "objects/[0-9a-f]{2}/", so we will not report
+ * "objects/foobar" as cruft.
+ *
+ * - loose_subdir is called for each top-level hashed subdirectory
+ * of the object directory (e.g., "$OBJDIR/f0"). It is called
+ * after the objects in the directory are processed.
+ *
+ * Any callback that is NULL will be ignored. Callbacks returning non-zero
+ * will end the iteration.
+ *
+ * In the "buf" variant, "path" is a strbuf which will also be used as a
+ * scratch buffer, but restored to its original contents before
+ * the function returns.
+ */
+typedef int each_loose_object_fn(const struct object_id *oid,
+ const char *path,
+ void *data);
+typedef int each_loose_cruft_fn(const char *basename,
+ const char *path,
+ void *data);
+typedef int each_loose_subdir_fn(unsigned int nr,
+ const char *path,
+ void *data);
+int for_each_file_in_obj_subdir(unsigned int subdir_nr,
+ struct strbuf *path,
+ each_loose_object_fn obj_cb,
+ each_loose_cruft_fn cruft_cb,
+ each_loose_subdir_fn subdir_cb,
+ void *data);
+int for_each_loose_file_in_objdir(const char *path,
+ each_loose_object_fn obj_cb,
+ each_loose_cruft_fn cruft_cb,
+ each_loose_subdir_fn subdir_cb,
+ void *data);
+int for_each_loose_file_in_objdir_buf(struct strbuf *path,
+ each_loose_object_fn obj_cb,
+ each_loose_cruft_fn cruft_cb,
+ each_loose_subdir_fn subdir_cb,
+ void *data);
+
+/* Flags for for_each_*_object() below. */
+enum for_each_object_flags {
+ /* Iterate only over local objects, not alternates. */
+ FOR_EACH_OBJECT_LOCAL_ONLY = (1<<0),
+
+ /* Only iterate over packs obtained from the promisor remote. */
+ FOR_EACH_OBJECT_PROMISOR_ONLY = (1<<1),
+
+ /*
+ * Visit objects within a pack in packfile order rather than .idx order
+ */
+ FOR_EACH_OBJECT_PACK_ORDER = (1<<2),
+
+ /* Only iterate over packs that are not marked as kept in-core. */
+ FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS = (1<<3),
+
+ /* Only iterate over packs that do not have .keep files. */
+ FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
+};
+
+/*
+ * Iterate over all accessible loose objects without respect to
+ * reachability. By default, this includes both local and alternate objects.
+ * The order in which objects are visited is unspecified.
+ *
+ * Any flags specific to packs are ignored.
+ */
+int for_each_loose_object(each_loose_object_fn, void *,
+ enum for_each_object_flags flags);
+
+/*
+ * Iterate over all accessible packed objects without respect to reachability.
+ * By default, this includes both local and alternate packs.
+ *
+ * Note that some objects may appear twice if they are found in multiple packs.
+ * Each pack is visited in an unspecified order. By default, objects within a
+ * pack are visited in pack-idx order (i.e., sorted by oid).
+ */
+typedef int each_packed_object_fn(const struct object_id *oid,
+ struct packed_git *pack,
+ uint32_t pos,
+ void *data);
+int for_each_object_in_pack(struct packed_git *p,
+ each_packed_object_fn, void *data,
+ enum for_each_object_flags flags);
+int for_each_packed_object(each_packed_object_fn, void *,
+ enum for_each_object_flags flags);
+
+#endif /* OBJECT_STORE_LL_H */
diff --git a/object-store.h b/object-store.h
index 12415e5ea7..1b3e3d7d01 100644
--- a/object-store.h
+++ b/object-store.h
@@ -1,537 +1,11 @@
#ifndef OBJECT_STORE_H
#define OBJECT_STORE_H
-#include "object.h"
-#include "list.h"
-#include "thread-utils.h"
#include "khash.h"
#include "dir.h"
-#include "oidset.h"
-
-struct oidmap;
-struct oidtree;
-struct strbuf;
-
-struct object_directory {
- struct object_directory *next;
-
- /*
- * Used to store the results of readdir(3) calls when we are OK
- * sacrificing accuracy due to races for speed. That includes
- * object existence with OBJECT_INFO_QUICK, as well as
- * our search for unique abbreviated hashes. Don't use it for tasks
- * requiring greater accuracy!
- *
- * Be sure to call odb_load_loose_cache() before using.
- */
- uint32_t loose_objects_subdir_seen[8]; /* 256 bits */
- struct oidtree *loose_objects_cache;
-
- /*
- * This is a temporary object store created by the tmp_objdir
- * facility. Disable ref updates since the objects in the store
- * might be discarded on rollback.
- */
- int disable_ref_updates;
-
- /*
- * This object store is ephemeral, so there is no need to fsync.
- */
- int will_destroy;
-
- /*
- * Path to the alternative object store. If this is a relative path,
- * it is relative to the current working directory.
- */
- char *path;
-};
-
-struct input_stream {
- const void *(*read)(struct input_stream *, unsigned long *len);
- void *data;
- int is_finished;
-};
+#include "object-store-ll.h"
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
struct object_directory *, 1, fspathhash, fspatheq)
-void prepare_alt_odb(struct repository *r);
-int has_alt_odb(struct repository *r);
-char *compute_alternate_path(const char *path, struct strbuf *err);
-struct object_directory *find_odb(struct repository *r, const char *obj_dir);
-typedef int alt_odb_fn(struct object_directory *, void *);
-int foreach_alt_odb(alt_odb_fn, void*);
-typedef void alternate_ref_fn(const struct object_id *oid, void *);
-void for_each_alternate_ref(alternate_ref_fn, void *);
-
-/*
- * Add the directory to the on-disk alternates file; the new entry will also
- * take effect in the current process.
- */
-void add_to_alternates_file(const char *dir);
-
-/*
- * Add the directory to the in-memory list of alternates (along with any
- * recursive alternates it points to), but do not modify the on-disk alternates
- * file.
- */
-void add_to_alternates_memory(const char *dir);
-
-/*
- * Replace the current writable object directory with the specified temporary
- * object directory; returns the former primary object directory.
- */
-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
-
-/*
- * Restore a previous ODB replaced by set_temporary_main_odb.
- */
-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
-
-/*
- * Populate and return the loose object cache array corresponding to the
- * given object ID.
- */
-struct oidtree *odb_loose_cache(struct object_directory *odb,
- const struct object_id *oid);
-
-/* Empty the loose object cache for the specified object directory. */
-void odb_clear_loose_cache(struct object_directory *odb);
-
-/* Clear and free the specified object directory */
-void free_object_directory(struct object_directory *odb);
-
-struct packed_git {
- struct hashmap_entry packmap_ent;
- struct packed_git *next;
- struct list_head mru;
- struct pack_window *windows;
- off_t pack_size;
- const void *index_data;
- size_t index_size;
- uint32_t num_objects;
- uint32_t crc_offset;
- struct oidset bad_objects;
- int index_version;
- time_t mtime;
- int pack_fd;
- int index; /* for builtin/pack-objects.c */
- unsigned pack_local:1,
- pack_keep:1,
- pack_keep_in_core:1,
- freshened:1,
- do_not_close:1,
- pack_promisor:1,
- multi_pack_index:1,
- is_cruft:1;
- unsigned char hash[GIT_MAX_RAWSZ];
- struct revindex_entry *revindex;
- const uint32_t *revindex_data;
- const uint32_t *revindex_map;
- size_t revindex_size;
- /*
- * mtimes_map points at the beginning of the memory mapped region of
- * this pack's corresponding .mtimes file, and mtimes_size is the size
- * of that .mtimes file
- */
- const uint32_t *mtimes_map;
- size_t mtimes_size;
- /* something like ".git/objects/pack/xxxxx.pack" */
- char pack_name[FLEX_ARRAY]; /* more */
-};
-
-struct multi_pack_index;
-
-static inline int pack_map_entry_cmp(const void *cmp_data UNUSED,
- const struct hashmap_entry *entry,
- const struct hashmap_entry *entry2,
- const void *keydata)
-{
- const char *key = keydata;
- const struct packed_git *pg1, *pg2;
-
- pg1 = container_of(entry, const struct packed_git, packmap_ent);
- pg2 = container_of(entry2, const struct packed_git, packmap_ent);
-
- return strcmp(pg1->pack_name, key ? key : pg2->pack_name);
-}
-
-struct raw_object_store {
- /*
- * Set of all object directories; the main directory is first (and
- * cannot be NULL after initialization). Subsequent directories are
- * alternates.
- */
- struct object_directory *odb;
- struct object_directory **odb_tail;
- kh_odb_path_map_t *odb_by_path;
-
- int loaded_alternates;
-
- /*
- * A list of alternate object directories loaded from the environment;
- * this should not generally need to be accessed directly, but will
- * populate the "odb" list when prepare_alt_odb() is run.
- */
- char *alternate_db;
-
- /*
- * Objects that should be substituted by other objects
- * (see git-replace(1)).
- */
- struct oidmap *replace_map;
- unsigned replace_map_initialized : 1;
- pthread_mutex_t replace_mutex; /* protect object replace functions */
-
- struct commit_graph *commit_graph;
- unsigned commit_graph_attempted : 1; /* if loading has been attempted */
-
- /*
- * private data
- *
- * should only be accessed directly by packfile.c and midx.c
- */
- struct multi_pack_index *multi_pack_index;
-
- /*
- * private data
- *
- * should only be accessed directly by packfile.c
- */
-
- struct packed_git *packed_git;
- /* A most-recently-used ordered version of the packed_git list. */
- struct list_head packed_git_mru;
-
- struct {
- struct packed_git **packs;
- unsigned flags;
- } kept_pack_cache;
-
- /*
- * A map of packfiles to packed_git structs for tracking which
- * packs have been loaded already.
- */
- struct hashmap pack_map;
-
- /*
- * A fast, rough count of the number of objects in the repository.
- * These two fields are not meant for direct access. Use
- * repo_approximate_object_count() instead.
- */
- unsigned long approximate_object_count;
- unsigned approximate_object_count_valid : 1;
-
- /*
- * Whether packed_git has already been populated with this repository's
- * packs.
- */
- unsigned packed_git_initialized : 1;
-};
-
-struct raw_object_store *raw_object_store_new(void);
-void raw_object_store_clear(struct raw_object_store *o);
-
-/*
- * Put in `buf` the name of the file in the local object database that
- * would be used to store a loose object with the specified oid.
- */
-const char *loose_object_path(struct repository *r, struct strbuf *buf,
- const struct object_id *oid);
-
-void *map_loose_object(struct repository *r, const struct object_id *oid,
- unsigned long *size);
-
-void *repo_read_object_file(struct repository *r,
- const struct object_id *oid,
- enum object_type *type,
- unsigned long *size);
-
-/* Read and unpack an object file into memory, write memory to an object file */
-int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
-
-void hash_object_file(const struct git_hash_algo *algo, const void *buf,
- unsigned long len, enum object_type type,
- struct object_id *oid);
-
-int write_object_file_flags(const void *buf, unsigned long len,
- enum object_type type, struct object_id *oid,
- unsigned flags);
-static inline int write_object_file(const void *buf, unsigned long len,
- enum object_type type, struct object_id *oid)
-{
- return write_object_file_flags(buf, len, type, oid, 0);
-}
-
-int write_object_file_literally(const void *buf, unsigned long len,
- const char *type, struct object_id *oid,
- unsigned flags);
-int stream_loose_object(struct input_stream *in_stream, size_t len,
- struct object_id *oid);
-
-/*
- * Add an object file to the in-memory object store, without writing it
- * to disk.
- *
- * Callers are responsible for calling write_object_file to record the
- * object in persistent storage before writing any other new objects
- * that reference it.
- */
-int pretend_object_file(void *, unsigned long, enum object_type,
- struct object_id *oid);
-
-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
- * type, and size. If the object is a blob, then "contents" may return NULL,
- * to allow streaming of large blobs.
- *
- * Returns 0 on success, negative on error (details may be written to stderr).
- */
-int read_loose_object(const char *path,
- const struct object_id *expected_oid,
- struct object_id *real_oid,
- void **contents,
- struct object_info *oi);
-
-/* Retry packed storage after checking packed and loose storage */
-#define HAS_OBJECT_RECHECK_PACKED 1
-
-/*
- * Returns 1 if the object exists. This function will not lazily fetch objects
- * in a partial clone.
- */
-int has_object(struct repository *r, const struct object_id *oid,
- unsigned flags);
-
-/*
- * These macros and functions are deprecated. If checking existence for an
- * object that is likely to be missing and/or whose absence is relatively
- * inconsequential (or is consequential but the caller is prepared to handle
- * it), use has_object(), which has better defaults (no lazy fetch in a partial
- * clone and no rechecking of packed storage). In the unlikely event that a
- * caller needs to assert existence of an object that it fully expects to
- * exist, and wants to trigger a lazy fetch in a partial clone, use
- * oid_object_info_extended() with a NULL struct object_info.
- *
- * These functions can be removed once all callers have migrated to
- * has_object() and/or oid_object_info_extended().
- */
-int repo_has_object_file(struct repository *r, const struct object_id *oid);
-int repo_has_object_file_with_flags(struct repository *r,
- const struct object_id *oid, int flags);
-
-/*
- * Return true iff an alternate object database has a loose object
- * with the specified name. This function does not respect replace
- * references.
- */
-int has_loose_object_nonlocal(const struct object_id *);
-
-int has_loose_object(const struct object_id *);
-
-/**
- * format_object_header() is a thin wrapper around s xsnprintf() that
- * writes the initial "<type> <obj-len>" part of the loose object
- * header. It returns the size that snprintf() returns + 1.
- */
-int format_object_header(char *str, size_t size, enum object_type type,
- size_t objsize);
-
-void assert_oid_type(const struct object_id *oid, enum object_type expect);
-
-/*
- * Enabling the object read lock allows multiple threads to safely call the
- * following functions in parallel: repo_read_object_file(),
- * read_object_with_reference(), oid_object_info() and oid_object_info_extended().
- *
- * obj_read_lock() and obj_read_unlock() may also be used to protect other
- * section which cannot execute in parallel with object reading. Since the used
- * lock is a recursive mutex, these sections can even contain calls to object
- * reading functions. However, beware that in these cases zlib inflation won't
- * be performed in parallel, losing performance.
- *
- * TODO: oid_object_info_extended()'s call stack has a recursive behavior. If
- * any of its callees end up calling it, this recursive call won't benefit from
- * parallel inflation.
- */
-void enable_obj_read_lock(void);
-void disable_obj_read_lock(void);
-
-extern int obj_read_use_lock;
-extern pthread_mutex_t obj_read_mutex;
-
-static inline void obj_read_lock(void)
-{
- if(obj_read_use_lock)
- pthread_mutex_lock(&obj_read_mutex);
-}
-
-static inline void obj_read_unlock(void)
-{
- if(obj_read_use_lock)
- pthread_mutex_unlock(&obj_read_mutex);
-}
-
-/*
- * Iterate over the files in the loose-object parts of the object
- * directory "path", triggering the following callbacks:
- *
- * - loose_object is called for each loose object we find.
- *
- * - loose_cruft is called for any files that do not appear to be
- * loose objects. Note that we only look in the loose object
- * directories "objects/[0-9a-f]{2}/", so we will not report
- * "objects/foobar" as cruft.
- *
- * - loose_subdir is called for each top-level hashed subdirectory
- * of the object directory (e.g., "$OBJDIR/f0"). It is called
- * after the objects in the directory are processed.
- *
- * Any callback that is NULL will be ignored. Callbacks returning non-zero
- * will end the iteration.
- *
- * In the "buf" variant, "path" is a strbuf which will also be used as a
- * scratch buffer, but restored to its original contents before
- * the function returns.
- */
-typedef int each_loose_object_fn(const struct object_id *oid,
- const char *path,
- void *data);
-typedef int each_loose_cruft_fn(const char *basename,
- const char *path,
- void *data);
-typedef int each_loose_subdir_fn(unsigned int nr,
- const char *path,
- void *data);
-int for_each_file_in_obj_subdir(unsigned int subdir_nr,
- struct strbuf *path,
- each_loose_object_fn obj_cb,
- each_loose_cruft_fn cruft_cb,
- each_loose_subdir_fn subdir_cb,
- void *data);
-int for_each_loose_file_in_objdir(const char *path,
- each_loose_object_fn obj_cb,
- each_loose_cruft_fn cruft_cb,
- each_loose_subdir_fn subdir_cb,
- void *data);
-int for_each_loose_file_in_objdir_buf(struct strbuf *path,
- each_loose_object_fn obj_cb,
- each_loose_cruft_fn cruft_cb,
- each_loose_subdir_fn subdir_cb,
- void *data);
-
-/* Flags for for_each_*_object() below. */
-enum for_each_object_flags {
- /* Iterate only over local objects, not alternates. */
- FOR_EACH_OBJECT_LOCAL_ONLY = (1<<0),
-
- /* Only iterate over packs obtained from the promisor remote. */
- FOR_EACH_OBJECT_PROMISOR_ONLY = (1<<1),
-
- /*
- * Visit objects within a pack in packfile order rather than .idx order
- */
- FOR_EACH_OBJECT_PACK_ORDER = (1<<2),
-
- /* Only iterate over packs that are not marked as kept in-core. */
- FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS = (1<<3),
-
- /* Only iterate over packs that do not have .keep files. */
- FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
-};
-
-/*
- * Iterate over all accessible loose objects without respect to
- * reachability. By default, this includes both local and alternate objects.
- * The order in which objects are visited is unspecified.
- *
- * Any flags specific to packs are ignored.
- */
-int for_each_loose_object(each_loose_object_fn, void *,
- enum for_each_object_flags flags);
-
-/*
- * Iterate over all accessible packed objects without respect to reachability.
- * By default, this includes both local and alternate packs.
- *
- * Note that some objects may appear twice if they are found in multiple packs.
- * Each pack is visited in an unspecified order. By default, objects within a
- * pack are visited in pack-idx order (i.e., sorted by oid).
- */
-typedef int each_packed_object_fn(const struct object_id *oid,
- struct packed_git *pack,
- uint32_t pos,
- void *data);
-int for_each_object_in_pack(struct packed_git *p,
- each_packed_object_fn, void *data,
- enum for_each_object_flags flags);
-int for_each_packed_object(each_packed_object_fn, void *,
- enum for_each_object_flags flags);
-
#endif /* OBJECT_STORE_H */
diff --git a/object.c b/object.c
index 6d4ef1524d..2c61e4c862 100644
--- a/object.c
+++ b/object.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
#include "object.h"
@@ -6,6 +6,7 @@
#include "object-file.h"
#include "object-store.h"
#include "blob.h"
+#include "statinfo.h"
#include "tree.h"
#include "commit.h"
#include "tag.h"
@@ -356,6 +357,12 @@ void object_list_free(struct object_list **list)
*/
static char object_array_slopbuf[1];
+void object_array_init(struct object_array *array)
+{
+ struct object_array blank = OBJECT_ARRAY_INIT;
+ memcpy(array, &blank, sizeof(*array));
+}
+
void add_object_array_with_path(struct object *obj, const char *name,
struct object_array *array,
unsigned mode, const char *path)
diff --git a/object.h b/object.h
index 5871615fee..114d45954d 100644
--- a/object.h
+++ b/object.h
@@ -58,6 +58,8 @@ struct object_array {
#define OBJECT_ARRAY_INIT { 0 }
+void object_array_init(struct object_array *array);
+
/*
* object flag allocation:
* revision.h: 0---------10 15 23------27
diff --git a/oid-array.c b/oid-array.c
index e8228c777b..8e4717746c 100644
--- a/oid-array.c
+++ b/oid-array.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "oid-array.h"
#include "hash-lookup.h"
diff --git a/oidmap.h b/oidmap.h
index c1642927fa..05c673eb7c 100644
--- a/oidmap.h
+++ b/oidmap.h
@@ -1,6 +1,7 @@
#ifndef OIDMAP_H
#define OIDMAP_H
+#include "hash-ll.h"
#include "hashmap.h"
/*
diff --git a/oidtree.c b/oidtree.c
index 7d57b7b19e..daef175dc7 100644
--- a/oidtree.c
+++ b/oidtree.c
@@ -4,7 +4,6 @@
*/
#include "git-compat-util.h"
#include "oidtree.h"
-#include "alloc.h"
#include "hash.h"
struct oidtree_iter_data {
diff --git a/oss-fuzz/fuzz-pack-idx.c b/oss-fuzz/fuzz-pack-idx.c
index 609a343ee3..3e190214d1 100644
--- a/oss-fuzz/fuzz-pack-idx.c
+++ b/oss-fuzz/fuzz-pack-idx.c
@@ -1,5 +1,5 @@
#include "git-compat-util.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "packfile.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index cdffe2ce47..f6757c3cbf 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1,9 +1,8 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "commit.h"
#include "tag.h"
#include "diff.h"
@@ -15,6 +14,7 @@
#include "pack-bitmap.h"
#include "hash-lookup.h"
#include "pack-objects.h"
+#include "path.h"
#include "commit-reach.h"
#include "prio-queue.h"
#include "trace2.h"
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 999f962602..6afc03d1e4 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "commit.h"
#include "gettext.h"
#include "hex.h"
@@ -17,7 +16,7 @@
#include "repository.h"
#include "trace2.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "list-objects-filter-options.h"
#include "midx.h"
#include "config.h"
@@ -387,9 +386,11 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
}
for (i = 0; i < bitmap_git->midx->num_packs; i++) {
- if (prepare_midx_pack(the_repository, bitmap_git->midx, i))
- die(_("could not open pack %s"),
- bitmap_git->midx->pack_names[i]);
+ if (prepare_midx_pack(the_repository, bitmap_git->midx, i)) {
+ warning(_("could not open pack %s"),
+ bitmap_git->midx->pack_names[i]);
+ goto cleanup;
+ }
}
preferred = bitmap_git->midx->packs[midx_preferred_pack(bitmap_git)];
@@ -1043,6 +1044,160 @@ static int add_commit_to_bitmap(struct bitmap_index *bitmap_git,
return 1;
}
+static struct bitmap *fill_in_bitmap(struct bitmap_index *bitmap_git,
+ struct rev_info *revs,
+ struct bitmap *base,
+ struct bitmap *seen)
+{
+ struct include_data incdata;
+ struct bitmap_show_data show_data;
+
+ if (!base)
+ base = bitmap_new();
+
+ incdata.bitmap_git = bitmap_git;
+ incdata.base = base;
+ incdata.seen = seen;
+
+ revs->include_check = should_include;
+ revs->include_check_obj = should_include_obj;
+ revs->include_check_data = &incdata;
+
+ if (prepare_revision_walk(revs))
+ die(_("revision walk setup failed"));
+
+ show_data.bitmap_git = bitmap_git;
+ show_data.base = base;
+
+ traverse_commit_list(revs, show_commit, show_object, &show_data);
+
+ revs->include_check = NULL;
+ revs->include_check_obj = NULL;
+ revs->include_check_data = NULL;
+
+ return base;
+}
+
+struct bitmap_boundary_cb {
+ struct bitmap_index *bitmap_git;
+ struct bitmap *base;
+
+ struct object_array boundary;
+};
+
+static void show_boundary_commit(struct commit *commit, void *_data)
+{
+ struct bitmap_boundary_cb *data = _data;
+
+ if (commit->object.flags & BOUNDARY)
+ add_object_array(&commit->object, "", &data->boundary);
+
+ if (commit->object.flags & UNINTERESTING) {
+ if (bitmap_walk_contains(data->bitmap_git, data->base,
+ &commit->object.oid))
+ return;
+
+ add_commit_to_bitmap(data->bitmap_git, &data->base, commit);
+ }
+}
+
+static void show_boundary_object(struct object *object,
+ const char *name, void *data)
+{
+ BUG("should not be called");
+}
+
+static struct bitmap *find_boundary_objects(struct bitmap_index *bitmap_git,
+ struct rev_info *revs,
+ struct object_list *roots)
+{
+ struct bitmap_boundary_cb cb;
+ struct object_list *root;
+ unsigned int i;
+ unsigned int tmp_blobs, tmp_trees, tmp_tags;
+ int any_missing = 0;
+
+ cb.bitmap_git = bitmap_git;
+ cb.base = bitmap_new();
+ object_array_init(&cb.boundary);
+
+ revs->ignore_missing_links = 1;
+
+ /*
+ * OR in any existing reachability bitmaps among `roots` into
+ * `cb.base`.
+ */
+ for (root = roots; root; root = root->next) {
+ struct object *object = root->item;
+ if (object->type != OBJ_COMMIT ||
+ bitmap_walk_contains(bitmap_git, cb.base, &object->oid))
+ continue;
+
+ if (add_commit_to_bitmap(bitmap_git, &cb.base,
+ (struct commit *)object))
+ continue;
+
+ any_missing = 1;
+ }
+
+ if (!any_missing)
+ goto cleanup;
+
+ tmp_blobs = revs->blob_objects;
+ tmp_trees = revs->tree_objects;
+ tmp_tags = revs->blob_objects;
+ revs->blob_objects = 0;
+ revs->tree_objects = 0;
+ revs->tag_objects = 0;
+
+ /*
+ * We didn't have complete coverage of the roots. First setup a
+ * revision walk to (a) OR in any bitmaps that are UNINTERESTING
+ * between the tips and boundary, and (b) record the boundary.
+ */
+ trace2_region_enter("pack-bitmap", "boundary-prepare", the_repository);
+ if (prepare_revision_walk(revs))
+ die("revision walk setup failed");
+ trace2_region_leave("pack-bitmap", "boundary-prepare", the_repository);
+
+ trace2_region_enter("pack-bitmap", "boundary-traverse", the_repository);
+ revs->boundary = 1;
+ traverse_commit_list_filtered(revs,
+ show_boundary_commit,
+ show_boundary_object,
+ &cb, NULL);
+ revs->boundary = 0;
+ trace2_region_leave("pack-bitmap", "boundary-traverse", the_repository);
+
+ revs->blob_objects = tmp_blobs;
+ revs->tree_objects = tmp_trees;
+ revs->tag_objects = tmp_tags;
+
+ reset_revision_walk();
+ clear_object_flags(UNINTERESTING);
+
+ /*
+ * Then add the boundary commit(s) as fill-in traversal tips.
+ */
+ trace2_region_enter("pack-bitmap", "boundary-fill-in", the_repository);
+ for (i = 0; i < cb.boundary.nr; i++) {
+ struct object *obj = cb.boundary.objects[i].item;
+ if (bitmap_walk_contains(bitmap_git, cb.base, &obj->oid))
+ obj->flags |= SEEN;
+ else
+ add_pending_object(revs, obj, "");
+ }
+ if (revs->pending.nr)
+ cb.base = fill_in_bitmap(bitmap_git, revs, cb.base, NULL);
+ trace2_region_leave("pack-bitmap", "boundary-fill-in", the_repository);
+
+cleanup:
+ object_array_clear(&cb.boundary);
+ revs->ignore_missing_links = 0;
+
+ return cb.base;
+}
+
static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
struct rev_info *revs,
struct object_list *roots,
@@ -1109,33 +1264,19 @@ static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
}
if (needs_walk) {
- struct include_data incdata;
- struct bitmap_show_data show_data;
-
- if (!base)
- base = bitmap_new();
-
- incdata.bitmap_git = bitmap_git;
- incdata.base = base;
- incdata.seen = seen;
-
- revs->include_check = should_include;
- revs->include_check_obj = should_include_obj;
- revs->include_check_data = &incdata;
-
- if (prepare_revision_walk(revs))
- die(_("revision walk setup failed"));
-
- show_data.bitmap_git = bitmap_git;
- show_data.base = base;
-
- traverse_commit_list(revs,
- show_commit, show_object,
- &show_data);
-
- revs->include_check = NULL;
- revs->include_check_obj = NULL;
- revs->include_check_data = NULL;
+ /*
+ * This fill-in traversal may walk over some objects
+ * again, since we have already traversed in order to
+ * find the boundary.
+ *
+ * But this extra walk should be extremely cheap, since
+ * all commit objects are loaded into memory, and
+ * because we skip walking to parents that are
+ * UNINTERESTING, since it will be marked in the haves
+ * bitmap already (or it has an on-disk bitmap, since
+ * OR-ing it in covers all of its ancestors).
+ */
+ base = fill_in_bitmap(bitmap_git, revs, base, seen);
}
return base;
@@ -1152,7 +1293,7 @@ static void show_extended_objects(struct bitmap_index *bitmap_git,
for (i = 0; i < eindex->count; ++i) {
struct object *obj;
- if (!bitmap_get(objects, bitmap_num_objects(bitmap_git) + i))
+ if (!bitmap_get(objects, st_add(bitmap_num_objects(bitmap_git), i)))
continue;
obj = eindex->objects[i];
@@ -1331,7 +1472,7 @@ static void filter_bitmap_exclude_type(struct bitmap_index *bitmap_git,
* them individually.
*/
for (i = 0; i < eindex->count; i++) {
- uint32_t pos = i + bitmap_num_objects(bitmap_git);
+ size_t pos = st_add(i, bitmap_num_objects(bitmap_git));
if (eindex->objects[i]->type == type &&
bitmap_get(to_filter, pos) &&
!bitmap_get(tips, pos))
@@ -1422,7 +1563,7 @@ static void filter_bitmap_blob_limit(struct bitmap_index *bitmap_git,
}
for (i = 0; i < eindex->count; i++) {
- uint32_t pos = i + bitmap_num_objects(bitmap_git);
+ size_t pos = st_add(i, bitmap_num_objects(bitmap_git));
if (eindex->objects[i]->type == OBJ_BLOB &&
bitmap_get(to_filter, pos) &&
!bitmap_get(tips, pos) &&
@@ -1528,6 +1669,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
int filter_provided_objects)
{
unsigned int i;
+ int use_boundary_traversal;
struct object_list *wants = NULL;
struct object_list *haves = NULL;
@@ -1578,13 +1720,21 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
object_list_insert(object, &wants);
}
- /*
- * if we have a HAVES list, but none of those haves is contained
- * in the packfile that has a bitmap, we don't have anything to
- * optimize here
- */
- if (haves && !in_bitmapped_pack(bitmap_git, haves))
- goto cleanup;
+ use_boundary_traversal = git_env_bool(GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL, -1);
+ if (use_boundary_traversal < 0) {
+ prepare_repo_settings(revs->repo);
+ use_boundary_traversal = revs->repo->settings.pack_use_bitmap_boundary_traversal;
+ }
+
+ if (!use_boundary_traversal) {
+ /*
+ * if we have a HAVES list, but none of those haves is contained
+ * in the packfile that has a bitmap, we don't have anything to
+ * optimize here
+ */
+ if (haves && !in_bitmapped_pack(bitmap_git, haves))
+ goto cleanup;
+ }
/* if we don't want anything, we're done here */
if (!wants)
@@ -1598,18 +1748,32 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
if (load_bitmap(revs->repo, bitmap_git) < 0)
goto cleanup;
- object_array_clear(&revs->pending);
+ if (!use_boundary_traversal)
+ object_array_clear(&revs->pending);
if (haves) {
- revs->ignore_missing_links = 1;
- haves_bitmap = find_objects(bitmap_git, revs, haves, NULL);
- reset_revision_walk();
- revs->ignore_missing_links = 0;
+ if (use_boundary_traversal) {
+ trace2_region_enter("pack-bitmap", "haves/boundary", the_repository);
+ haves_bitmap = find_boundary_objects(bitmap_git, revs, haves);
+ trace2_region_leave("pack-bitmap", "haves/boundary", the_repository);
+ } else {
+ trace2_region_enter("pack-bitmap", "haves/classic", the_repository);
+ revs->ignore_missing_links = 1;
+ haves_bitmap = find_objects(bitmap_git, revs, haves, NULL);
+ reset_revision_walk();
+ revs->ignore_missing_links = 0;
+ trace2_region_leave("pack-bitmap", "haves/classic", the_repository);
+ }
if (!haves_bitmap)
BUG("failed to perform bitmap walk");
}
+ if (use_boundary_traversal) {
+ object_array_clear(&revs->pending);
+ reset_revision_walk();
+ }
+
wants_bitmap = find_objects(bitmap_git, revs, wants, haves_bitmap);
if (!wants_bitmap)
@@ -1873,7 +2037,8 @@ static uint32_t count_object_type(struct bitmap_index *bitmap_git,
for (i = 0; i < eindex->count; ++i) {
if (eindex->objects[i]->type == type &&
- bitmap_get(objects, bitmap_num_objects(bitmap_git) + i))
+ bitmap_get(objects,
+ st_add(bitmap_num_objects(bitmap_git), i)))
count++;
}
@@ -2287,7 +2452,8 @@ static off_t get_disk_usage_for_extended(struct bitmap_index *bitmap_git)
for (i = 0; i < eindex->count; i++) {
struct object *obj = eindex->objects[i];
- if (!bitmap_get(result, bitmap_num_objects(bitmap_git) + i))
+ if (!bitmap_get(result,
+ st_add(bitmap_num_objects(bitmap_git), i)))
continue;
if (oid_object_info_extended(the_repository, &obj->oid, &oi, 0) < 0)
diff --git a/pack-bitmap.h b/pack-bitmap.h
index 84591f041b..5273a6a019 100644
--- a/pack-bitmap.h
+++ b/pack-bitmap.h
@@ -62,6 +62,10 @@ void traverse_bitmap_commit_list(struct bitmap_index *,
void test_bitmap_walk(struct rev_info *revs);
int test_bitmap_commits(struct repository *r);
int test_bitmap_hashes(struct repository *r);
+
+#define GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL \
+ "GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL"
+
struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
int filter_provided_objects);
uint32_t midx_preferred_pack(struct bitmap_index *bitmap_git);
diff --git a/pack-check.c b/pack-check.c
index 049f2f0bfc..977f619618 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -7,7 +7,7 @@
#include "progress.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
struct idx_entry {
off_t offset;
diff --git a/pack-mtimes.c b/pack-mtimes.c
index 020a37f8fe..cdf30b8d2b 100644
--- a/pack-mtimes.c
+++ b/pack-mtimes.c
@@ -2,8 +2,9 @@
#include "gettext.h"
#include "pack-mtimes.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "packfile.h"
+#include "strbuf.h"
static char *pack_mtimes_filename(struct packed_git *p)
{
diff --git a/pack-objects.c b/pack-objects.c
index ccab09fe65..1b8052bece 100644
--- a/pack-objects.c
+++ b/pack-objects.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "object.h"
#include "pack.h"
#include "pack-objects.h"
diff --git a/pack-objects.h b/pack-objects.h
index 579476687c..0d78db40cb 100644
--- a/pack-objects.h
+++ b/pack-objects.h
@@ -1,7 +1,7 @@
#ifndef PACK_OBJECTS_H
#define PACK_OBJECTS_H
-#include "object-store.h"
+#include "object-store-ll.h"
#include "thread-utils.h"
#include "pack.h"
diff --git a/pack-revindex.c b/pack-revindex.c
index 1f51b712e8..7fffcad912 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -2,8 +2,9 @@
#include "gettext.h"
#include "pack-revindex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "packfile.h"
+#include "strbuf.h"
#include "trace2.h"
#include "config.h"
#include "midx.h"
diff --git a/pack-write.c b/pack-write.c
index 3b3ce89de6..b19ddf15b2 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -10,7 +10,8 @@
#include "oidmap.h"
#include "pack-objects.h"
#include "pack-revindex.h"
-#include "wrapper.h"
+#include "path.h"
+#include "strbuf.h"
void reset_pack_idx_option(struct pack_idx_option *opts)
{
diff --git a/packfile.c b/packfile.c
index fd083c86e0..9cc0a2e37a 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
@@ -19,12 +18,11 @@
#include "tree-walk.h"
#include "tree.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "midx.h"
#include "commit-graph.h"
#include "pack-revindex.h"
#include "promisor-remote.h"
-#include "wrapper.h"
char *odb_pack_name(struct strbuf *buf,
const unsigned char *hash,
@@ -186,7 +184,7 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map,
*/
(sizeof(off_t) <= 4))
return error("pack too large for current definition of off_t in %s", path);
- p->crc_offset = 8 + 4 * 256 + nr * hashsz;
+ p->crc_offset = st_add(8 + 4 * 256, st_mult(nr, hashsz));
}
p->index_version = version;
@@ -381,7 +379,7 @@ void close_object_store(struct raw_object_store *o)
void unlink_pack_path(const char *pack_name, int force_delete)
{
- static const char *exts[] = {".pack", ".idx", ".rev", ".keep", ".bitmap", ".promisor", ".mtimes"};
+ static const char *exts[] = {".idx", ".pack", ".rev", ".keep", ".bitmap", ".promisor", ".mtimes"};
int i;
struct strbuf buf = STRBUF_INIT;
size_t plen;
@@ -753,7 +751,7 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local)
p->pack_local = local;
p->mtime = st.st_mtime;
if (path_len < the_hash_algo->hexsz ||
- get_sha1_hex(path + path_len - the_hash_algo->hexsz, p->hash))
+ get_hash_hex(path + path_len - the_hash_algo->hexsz, p->hash))
hashclr(p->hash);
return p;
}
@@ -1920,10 +1918,10 @@ int nth_packed_object_id(struct object_id *oid,
return -1;
index += 4 * 256;
if (p->index_version == 1) {
- oidread(oid, index + (hashsz + 4) * n + 4);
+ oidread(oid, index + st_add(st_mult(hashsz + 4, n), 4));
} else {
index += 8;
- oidread(oid, index + hashsz * n);
+ oidread(oid, index + st_mult(hashsz, n));
}
return 0;
}
@@ -1948,14 +1946,15 @@ off_t nth_packed_object_offset(const struct packed_git *p, uint32_t n)
const unsigned int hashsz = the_hash_algo->rawsz;
index += 4 * 256;
if (p->index_version == 1) {
- return ntohl(*((uint32_t *)(index + (hashsz + 4) * (size_t)n)));
+ return ntohl(*((uint32_t *)(index + st_mult(hashsz + 4, n))));
} else {
uint32_t off;
- index += 8 + (size_t)p->num_objects * (hashsz + 4);
- off = ntohl(*((uint32_t *)(index + 4 * n)));
+ index += st_add(8, st_mult(p->num_objects, hashsz + 4));
+ off = ntohl(*((uint32_t *)(index + st_mult(4, n))));
if (!(off & 0x80000000))
return off;
- index += (size_t)p->num_objects * 4 + (off & 0x7fffffff) * 8;
+ index += st_add(st_mult(p->num_objects, 4),
+ st_mult(off & 0x7fffffff, 8));
check_pack_index_ptr(p, index);
return get_be64(index);
}
diff --git a/pager.c b/pager.c
index 63055d0873..b8822a9381 100644
--- a/pager.c
+++ b/pager.c
@@ -43,6 +43,7 @@ static void wait_for_pager_signal(int signo)
}
static int core_pager_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *data UNUSED)
{
if (!strcmp(var, "core.pager"))
@@ -228,7 +229,9 @@ struct pager_command_config_data {
char *value;
};
-static int pager_command_config(const char *var, const char *value, void *vdata)
+static int pager_command_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *vdata)
{
struct pager_command_config_data *data = vdata;
const char *cmd;
diff --git a/parallel-checkout.c b/parallel-checkout.c
index 69d569f352..b5a714c711 100644
--- a/parallel-checkout.c
+++ b/parallel-checkout.c
@@ -1,5 +1,4 @@
-#include "cache.h"
-#include "alloc.h"
+#include "git-compat-util.h"
#include "config.h"
#include "entry.h"
#include "gettext.h"
@@ -8,13 +7,13 @@
#include "parallel-checkout.h"
#include "pkt-line.h"
#include "progress.h"
+#include "read-cache-ll.h"
#include "run-command.h"
#include "sigchain.h"
#include "streaming.h"
#include "symlinks.h"
#include "thread-utils.h"
#include "trace2.h"
-#include "wrapper.h"
struct pc_worker {
struct child_process cp;
diff --git a/parse-options.c b/parse-options.c
index f8a155ee13..87c9fae634 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1109,6 +1109,7 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
for (; opts->type != OPTION_END; opts++) {
size_t pos;
int pad;
+ const char *cp, *np;
if (opts->type == OPTION_SUBCOMMAND)
continue;
@@ -1145,7 +1146,9 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
!(opts->flags & PARSE_OPT_NOARG))
pos += usage_argh(opts, outfile);
- if (pos <= USAGE_OPTS_WIDTH)
+ if (pos == USAGE_OPTS_WIDTH + 1)
+ pad = -1;
+ else if (pos <= USAGE_OPTS_WIDTH)
pad = USAGE_OPTS_WIDTH - pos;
else {
fputc('\n', outfile);
@@ -1157,7 +1160,16 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
(const char *)opts->value);
continue;
}
- fprintf(outfile, "%*s%s\n", pad + USAGE_GAP, "", _(opts->help));
+
+ for (cp = _(opts->help); *cp; cp = np) {
+ np = strchrnul(cp, '\n');
+ fprintf(outfile,
+ "%*s%.*s\n", pad + USAGE_GAP, "",
+ (int)(np - cp), cp);
+ if (*np)
+ np++;
+ pad = USAGE_OPTS_WIDTH;
+ }
}
fputc('\n', outfile);
diff --git a/parse-options.h b/parse-options.h
index 8e48efe524..57a7fe9d91 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -581,4 +581,10 @@ int parse_opt_tracking_mode(const struct option *, const char *, int);
#define OPT_PATHSPEC_FILE_NUL(v) OPT_BOOL(0, "pathspec-file-nul", v, N_("with --pathspec-from-file, pathspec elements are separated with NUL character"))
#define OPT_AUTOSTASH(v) OPT_BOOL(0, "autostash", v, N_("automatically stash/stash pop before and after"))
+#define OPT_IPVERSION(v) \
+ OPT_SET_INT_F('4', "ipv4", (v), N_("use IPv4 addresses only"), \
+ TRANSPORT_FAMILY_IPV4, PARSE_OPT_NONEG), \
+ OPT_SET_INT_F('6', "ipv6", (v), N_("use IPv6 addresses only"), \
+ TRANSPORT_FAMILY_IPV6, PARSE_OPT_NONEG)
+
#endif
diff --git a/patch-ids.c b/patch-ids.c
index 19af7bee98..c3e1a0dd21 100644
--- a/patch-ids.c
+++ b/patch-ids.c
@@ -1,6 +1,7 @@
#include "git-compat-util.h"
#include "diff.h"
#include "commit.h"
+#include "hash.h"
#include "hash-lookup.h"
#include "hex.h"
#include "patch-ids.h"
diff --git a/path.c b/path.c
index 7c1cd8182a..67e2690efe 100644
--- a/path.c
+++ b/path.c
@@ -15,10 +15,9 @@
#include "submodule-config.h"
#include "path.h"
#include "packfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "lockfile.h"
#include "exec-cmd.h"
-#include "wrapper.h"
static int get_st_mode_bits(const char *path, int *mode)
{
@@ -1213,6 +1212,26 @@ int normalize_path_copy(char *dst, const char *src)
return normalize_path_copy_len(dst, src, NULL);
}
+int strbuf_normalize_path(struct strbuf *src)
+{
+ struct strbuf dst = STRBUF_INIT;
+
+ strbuf_grow(&dst, src->len);
+ if (normalize_path_copy(dst.buf, src->buf) < 0) {
+ strbuf_release(&dst);
+ return -1;
+ }
+
+ /*
+ * normalize_path does not tell us the new length, so we have to
+ * compute it by looking for the new NUL it placed
+ */
+ strbuf_setlen(&dst, strlen(dst.buf));
+ strbuf_swap(src, &dst);
+ strbuf_release(&dst);
+ return 0;
+}
+
/*
* path = Canonical absolute path
* prefixes = string_list containing normalized, absolute paths without
diff --git a/path.h b/path.h
index 60e83a49a9..639372edd9 100644
--- a/path.h
+++ b/path.h
@@ -191,6 +191,11 @@ const char *remove_leading_path(const char *in, const char *prefix);
const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);
int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);
int normalize_path_copy(char *dst, const char *src);
+/**
+ * Normalize in-place the path contained in the strbuf. If an error occurs,
+ * the contents of "sb" are left untouched, and -1 is returned.
+ */
+int strbuf_normalize_path(struct strbuf *src);
int longest_ancestor_length(const char *path, struct string_list *prefixes);
char *strip_path_suffix(const char *path, const char *suffix);
int daemon_avoid_alias(const char *path);
diff --git a/pathspec.c b/pathspec.c
index 6966b265d3..3a3a5724c4 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "abspath.h"
#include "config.h"
#include "dir.h"
@@ -6,11 +6,13 @@
#include "gettext.h"
#include "pathspec.h"
#include "attr.h"
+#include "read-cache.h"
#include "repository.h"
#include "setup.h"
#include "strvec.h"
#include "symlinks.h"
#include "quote.h"
+#include "wildmatch.h"
/*
* Finds which of the given pathspecs match items in the index.
@@ -531,24 +533,29 @@ static int pathspec_item_cmp(const void *a_, const void *b_)
return strcmp(a->match, b->match);
}
-static void NORETURN unsupported_magic(const char *pattern,
- unsigned magic)
+void pathspec_magic_names(unsigned magic, struct strbuf *out)
{
- struct strbuf sb = STRBUF_INIT;
int i;
for (i = 0; i < ARRAY_SIZE(pathspec_magic); i++) {
const struct pathspec_magic *m = pathspec_magic + i;
if (!(magic & m->bit))
continue;
- if (sb.len)
- strbuf_addstr(&sb, ", ");
+ if (out->len)
+ strbuf_addstr(out, ", ");
if (m->mnemonic)
- strbuf_addf(&sb, _("'%s' (mnemonic: '%c')"),
+ strbuf_addf(out, _("'%s' (mnemonic: '%c')"),
m->name, m->mnemonic);
else
- strbuf_addf(&sb, "'%s'", m->name);
+ strbuf_addf(out, "'%s'", m->name);
}
+}
+
+static void NORETURN unsupported_magic(const char *pattern,
+ unsigned magic)
+{
+ struct strbuf sb = STRBUF_INIT;
+ pathspec_magic_names(magic, &sb);
/*
* We may want to substitute "this command" with a command
* name. E.g. when "git add -p" or "git add -i" dies when running
diff --git a/pathspec.h b/pathspec.h
index a5b38e0907..fec4399bbc 100644
--- a/pathspec.h
+++ b/pathspec.h
@@ -130,6 +130,14 @@ void parse_pathspec_file(struct pathspec *pathspec,
void copy_pathspec(struct pathspec *dst, const struct pathspec *src);
void clear_pathspec(struct pathspec *);
+/*
+ * Add a human-readable string to "out" representing the PATHSPEC_* flags set
+ * in "magic". The result is suitable for error messages, but not for
+ * parsing as pathspec magic itself (you get 'icase' with quotes, not
+ * :(icase)).
+ */
+void pathspec_magic_names(unsigned magic, struct strbuf *out);
+
static inline int ps_strncmp(const struct pathspec_item *item,
const char *s1, const char *s2, size_t n)
{
diff --git a/pkt-line.c b/pkt-line.c
index 62b4208b66..af83a19f4d 100644
--- a/pkt-line.c
+++ b/pkt-line.c
@@ -5,7 +5,6 @@
#include "hex.h"
#include "run-command.h"
#include "trace.h"
-#include "wrapper.h"
#include "write-or-die.h"
char packet_buffer[LARGE_PACKET_MAX];
@@ -373,10 +372,14 @@ static int get_packet_data(int fd, char **src_buf, size_t *src_size,
return ret;
}
-int packet_length(const char lenbuf_hex[4])
+int packet_length(const char lenbuf_hex[4], size_t size)
{
- int val = hex2chr(lenbuf_hex);
- return (val < 0) ? val : (val << 8) | hex2chr(lenbuf_hex + 2);
+ if (size < 4)
+ BUG("buffer too small");
+ return hexval(lenbuf_hex[0]) << 12 |
+ hexval(lenbuf_hex[1]) << 8 |
+ hexval(lenbuf_hex[2]) << 4 |
+ hexval(lenbuf_hex[3]);
}
static char *find_packfile_uri_path(const char *buffer)
@@ -419,7 +422,7 @@ enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
return PACKET_READ_EOF;
}
- len = packet_length(linelen);
+ len = packet_length(linelen, sizeof(linelen));
if (len < 0) {
if (options & PACKET_READ_GENTLE_ON_READ_ERROR)
diff --git a/pkt-line.h b/pkt-line.h
index 7c23a4bfaf..954eec8719 100644
--- a/pkt-line.h
+++ b/pkt-line.h
@@ -94,7 +94,7 @@ int packet_read(int fd, char *buffer, unsigned size, int options);
* If lenbuf_hex contains non-hex characters, return -1. Otherwise, return the
* numeric value of the length header.
*/
-int packet_length(const char lenbuf_hex[4]);
+int packet_length(const char lenbuf_hex[4], size_t size);
/*
* Read a packetized line into a buffer like the 'packet_read()' function but
diff --git a/preload-index.c b/preload-index.c
index 7a26b08c21..e44530c80c 100644
--- a/preload-index.c
+++ b/preload-index.c
@@ -1,14 +1,16 @@
/*
* Copyright (C) 2008 Linus Torvalds
*/
-#include "cache.h"
+#include "git-compat-util.h"
#include "pathspec.h"
#include "dir.h"
#include "environment.h"
#include "fsmonitor.h"
#include "gettext.h"
#include "config.h"
+#include "preload-index.h"
#include "progress.h"
+#include "read-cache.h"
#include "thread-utils.h"
#include "repository.h"
#include "symlinks.h"
diff --git a/preload-index.h b/preload-index.h
new file mode 100644
index 0000000000..251b1ed88e
--- /dev/null
+++ b/preload-index.h
@@ -0,0 +1,15 @@
+#ifndef PRELOAD_INDEX_H
+#define PRELOAD_INDEX_H
+
+struct index_state;
+struct pathspec;
+struct repository;
+
+void preload_index(struct index_state *index,
+ const struct pathspec *pathspec,
+ unsigned int refresh_flags);
+int repo_read_index_preload(struct repository *,
+ const struct pathspec *pathspec,
+ unsigned refresh_flags);
+
+#endif /* PRELOAD_INDEX_H */
diff --git a/pretty.c b/pretty.c
index 0bb938021b..718530bbab 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1,9 +1,9 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "commit.h"
#include "environment.h"
#include "gettext.h"
+#include "hash.h"
#include "hex.h"
#include "utf8.h"
#include "diff.h"
@@ -18,6 +18,7 @@
#include "gpg-interface.h"
#include "trailer.h"
#include "run-command.h"
+#include "object-name.h"
/*
* The limit for formatting directives, which enable the caller to append
@@ -56,6 +57,7 @@ static void save_user_format(struct rev_info *rev, const char *cp, int is_tforma
}
static int git_pretty_formats_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
struct cmt_fmt_map *commit_format = NULL;
@@ -1250,6 +1252,27 @@ static int format_trailer_match_cb(const struct strbuf *key, void *ud)
return 0;
}
+static struct strbuf *expand_separator(struct strbuf *sb,
+ const char *argval, size_t arglen)
+{
+ char *fmt = xstrndup(argval, arglen);
+ const char *format = fmt;
+
+ strbuf_reset(sb);
+ while (strbuf_expand_step(sb, &format)) {
+ size_t len;
+
+ if (skip_prefix(format, "%", &format))
+ strbuf_addch(sb, '%');
+ else if ((len = strbuf_expand_literal(sb, format)))
+ format += len;
+ else
+ strbuf_addch(sb, '%');
+ }
+ free(fmt);
+ return sb;
+}
+
int format_set_trailers_options(struct process_trailer_options *opts,
struct string_list *filter_list,
struct strbuf *sepbuf,
@@ -1278,21 +1301,9 @@ int format_set_trailers_options(struct process_trailer_options *opts,
opts->filter_data = filter_list;
opts->only_trailers = 1;
} else if (match_placeholder_arg_value(*arg, "separator", arg, &argval, &arglen)) {
- char *fmt;
-
- strbuf_reset(sepbuf);
- fmt = xstrndup(argval, arglen);
- strbuf_expand(sepbuf, fmt, strbuf_expand_literal_cb, NULL);
- free(fmt);
- opts->separator = sepbuf;
+ opts->separator = expand_separator(sepbuf, argval, arglen);
} else if (match_placeholder_arg_value(*arg, "key_value_separator", arg, &argval, &arglen)) {
- char *fmt;
-
- strbuf_reset(kvsepbuf);
- fmt = xstrndup(argval, arglen);
- strbuf_expand(kvsepbuf, fmt, strbuf_expand_literal_cb, NULL);
- free(fmt);
- opts->key_value_separator = kvsepbuf;
+ opts->key_value_separator = expand_separator(kvsepbuf, argval, arglen);
} else if (!match_placeholder_bool_arg(*arg, "only", arg, &opts->only_trailers) &&
!match_placeholder_bool_arg(*arg, "unfold", arg, &opts->unfold) &&
!match_placeholder_bool_arg(*arg, "keyonly", arg, &opts->key_only) &&
@@ -1386,7 +1397,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
char **slot;
/* these are independent of the commit */
- res = strbuf_expand_literal_cb(sb, placeholder, NULL);
+ res = strbuf_expand_literal(sb, placeholder);
if (res)
return res;
@@ -1804,7 +1815,7 @@ static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */
static size_t format_commit_item(struct strbuf *sb, /* in UTF-8 */
const char *placeholder,
- void *context)
+ struct format_commit_context *context)
{
size_t consumed, orig_len;
enum {
@@ -1843,10 +1854,10 @@ static size_t format_commit_item(struct strbuf *sb, /* in UTF-8 */
}
orig_len = sb->len;
- if (((struct format_commit_context *)context)->flush_type != no_flush)
- consumed = format_and_pad_commit(sb, placeholder, context);
- else
+ if (context->flush_type == no_flush)
consumed = format_commit_one(sb, placeholder, context);
+ else
+ consumed = format_and_pad_commit(sb, placeholder, context);
if (magic == NO_MAGIC)
return consumed;
@@ -1862,41 +1873,34 @@ static size_t format_commit_item(struct strbuf *sb, /* in UTF-8 */
return consumed + 1;
}
-static size_t userformat_want_item(struct strbuf *sb UNUSED,
- const char *placeholder,
- void *context)
-{
- struct userformat_want *w = context;
-
- if (*placeholder == '+' || *placeholder == '-' || *placeholder == ' ')
- placeholder++;
-
- switch (*placeholder) {
- case 'N':
- w->notes = 1;
- break;
- case 'S':
- w->source = 1;
- break;
- case 'd':
- case 'D':
- w->decorate = 1;
- break;
- }
- return 0;
-}
-
void userformat_find_requirements(const char *fmt, struct userformat_want *w)
{
- struct strbuf dummy = STRBUF_INIT;
-
if (!fmt) {
if (!user_format)
return;
fmt = user_format;
}
- strbuf_expand(&dummy, fmt, userformat_want_item, w);
- strbuf_release(&dummy);
+ while ((fmt = strchr(fmt, '%'))) {
+ fmt++;
+ if (skip_prefix(fmt, "%", &fmt))
+ continue;
+
+ if (*fmt == '+' || *fmt == '-' || *fmt == ' ')
+ fmt++;
+
+ switch (*fmt) {
+ case 'N':
+ w->notes = 1;
+ break;
+ case 'S':
+ w->source = 1;
+ break;
+ case 'd':
+ case 'D':
+ w->decorate = 1;
+ break;
+ }
+ }
}
void repo_format_commit_message(struct repository *r,
@@ -1913,7 +1917,16 @@ void repo_format_commit_message(struct repository *r,
const char *output_enc = pretty_ctx->output_encoding;
const char *utf8 = "UTF-8";
- strbuf_expand(sb, format, format_commit_item, &context);
+ while (strbuf_expand_step(sb, &format)) {
+ size_t len;
+
+ if (skip_prefix(format, "%", &format))
+ strbuf_addch(sb, '%');
+ else if ((len = format_commit_item(sb, format, &context)))
+ format += len;
+ else
+ strbuf_addch(sb, '%');
+ }
rewrap_message_tail(sb, &context, 0, 0, 0);
/*
diff --git a/prio-queue.c b/prio-queue.c
index dc2476be53..450775a374 100644
--- a/prio-queue.c
+++ b/prio-queue.c
@@ -1,5 +1,4 @@
#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/promisor-remote.c b/promisor-remote.c
index 1adcd6fb0a..ac3aa1e365 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "promisor-remote.h"
#include "config.h"
#include "trace2.h"
@@ -100,7 +100,9 @@ static void promisor_remote_move_to_tail(struct promisor_remote_config *config,
config->promisors_tail = &r->next;
}
-static int promisor_remote_config(const char *var, const char *value, void *data)
+static int promisor_remote_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *data)
{
struct promisor_remote_config *config = data;
const char *name;
diff --git a/protocol-caps.c b/protocol-caps.c
index a90c48852e..808a68c974 100644
--- a/protocol-caps.c
+++ b/protocol-caps.c
@@ -7,7 +7,7 @@
#include "hash-ll.h"
#include "hex.h"
#include "object.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "string-list.h"
#include "strbuf.h"
diff --git a/prune-packed.c b/prune-packed.c
index 58412b4fb9..e54daf740a 100644
--- a/prune-packed.c
+++ b/prune-packed.c
@@ -1,7 +1,7 @@
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "packfile.h"
#include "progress.h"
#include "prune-packed.h"
diff --git a/quote.c b/quote.c
index 43c739671e..3c05194496 100644
--- a/quote.c
+++ b/quote.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "path.h"
#include "quote.h"
#include "strbuf.h"
diff --git a/range-diff.c b/range-diff.c
index 6a704e6f47..2e86063491 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -13,6 +13,7 @@
#include "commit.h"
#include "pager.h"
#include "pretty.h"
+#include "repository.h"
#include "userdiff.h"
#include "apply.h"
#include "revision.h"
diff --git a/reachable.c b/reachable.c
index 55bb114353..0ce8f83e56 100644
--- a/reachable.c
+++ b/reachable.c
@@ -13,9 +13,11 @@
#include "list-objects.h"
#include "packfile.h"
#include "worktree.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "pack-bitmap.h"
#include "pack-mtimes.h"
+#include "config.h"
+#include "run-command.h"
struct connectivity_progress {
struct progress *progress;
@@ -67,8 +69,77 @@ struct recent_data {
timestamp_t timestamp;
report_recent_object_fn *cb;
int ignore_in_core_kept_packs;
+
+ struct oidset extra_recent_oids;
+ int extra_recent_oids_loaded;
};
+static int run_one_gc_recent_objects_hook(struct oidset *set,
+ const char *args)
+{
+ struct child_process cmd = CHILD_PROCESS_INIT;
+ struct strbuf buf = STRBUF_INIT;
+ FILE *out;
+ int ret = 0;
+
+ cmd.use_shell = 1;
+ cmd.out = -1;
+
+ strvec_push(&cmd.args, args);
+
+ if (start_command(&cmd))
+ return -1;
+
+ out = xfdopen(cmd.out, "r");
+ while (strbuf_getline(&buf, out) != EOF) {
+ struct object_id oid;
+ const char *rest;
+
+ if (parse_oid_hex(buf.buf, &oid, &rest) || *rest) {
+ ret = error(_("invalid extra cruft tip: '%s'"), buf.buf);
+ break;
+ }
+
+ oidset_insert(set, &oid);
+ }
+
+ fclose(out);
+ ret |= finish_command(&cmd);
+
+ strbuf_release(&buf);
+ return ret;
+}
+
+static void load_gc_recent_objects(struct recent_data *data)
+{
+ const struct string_list *programs;
+ int ret = 0;
+ size_t i;
+
+ data->extra_recent_oids_loaded = 1;
+
+ if (git_config_get_string_multi("gc.recentobjectshook", &programs))
+ return;
+
+ for (i = 0; i < programs->nr; i++) {
+ ret = run_one_gc_recent_objects_hook(&data->extra_recent_oids,
+ programs->items[i].string);
+ if (ret)
+ die(_("unable to enumerate additional recent objects"));
+ }
+}
+
+static int obj_is_recent(const struct object_id *oid, timestamp_t mtime,
+ struct recent_data *data)
+{
+ if (mtime > data->timestamp)
+ return 1;
+
+ if (!data->extra_recent_oids_loaded)
+ load_gc_recent_objects(data);
+ return oidset_contains(&data->extra_recent_oids, oid);
+}
+
static void add_recent_object(const struct object_id *oid,
struct packed_git *pack,
off_t offset,
@@ -78,7 +149,7 @@ static void add_recent_object(const struct object_id *oid,
struct object *obj;
enum object_type type;
- if (mtime <= data->timestamp)
+ if (!obj_is_recent(oid, mtime, data))
return;
/*
@@ -193,16 +264,24 @@ int add_unseen_recent_objects_to_traversal(struct rev_info *revs,
data.cb = cb;
data.ignore_in_core_kept_packs = ignore_in_core_kept_packs;
+ oidset_init(&data.extra_recent_oids, 0);
+ data.extra_recent_oids_loaded = 0;
+
r = for_each_loose_object(add_recent_loose, &data,
FOR_EACH_OBJECT_LOCAL_ONLY);
if (r)
- return r;
+ goto done;
flags = FOR_EACH_OBJECT_LOCAL_ONLY | FOR_EACH_OBJECT_PACK_ORDER;
if (ignore_in_core_kept_packs)
flags |= FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS;
- return for_each_packed_object(add_recent_packed, &data, flags);
+ r = for_each_packed_object(add_recent_packed, &data, flags);
+
+done:
+ oidset_clear(&data.extra_recent_oids);
+
+ return r;
}
static int mark_object_seen(const struct object_id *oid,
diff --git a/cache.h b/read-cache-ll.h
index bdedb87e83..9a1a7edc5a 100644
--- a/cache.h
+++ b/read-cache-ll.h
@@ -1,11 +1,8 @@
-#ifndef CACHE_H
-#define CACHE_H
+#ifndef READ_CACHE_LL_H
+#define READ_CACHE_LL_H
-#include "git-compat-util.h"
-#include "strbuf.h"
+#include "hash-ll.h"
#include "hashmap.h"
-#include "pathspec.h"
-#include "object.h"
#include "statinfo.h"
/*
@@ -126,42 +123,6 @@ static inline unsigned create_ce_flags(unsigned stage)
#define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE)
#define ce_intent_to_add(ce) ((ce)->ce_flags & CE_INTENT_TO_ADD)
-static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce,
- unsigned int mode)
-{
- extern int trust_executable_bit, has_symlinks;
- if (!has_symlinks && S_ISREG(mode) &&
- ce && S_ISLNK(ce->ce_mode))
- return ce->ce_mode;
- if (!trust_executable_bit && S_ISREG(mode)) {
- if (ce && S_ISREG(ce->ce_mode))
- return ce->ce_mode;
- return create_ce_mode(0666);
- }
- return create_ce_mode(mode);
-}
-static inline int ce_to_dtype(const struct cache_entry *ce)
-{
- unsigned ce_mode = ntohl(ce->ce_mode);
- if (S_ISREG(ce_mode))
- return DT_REG;
- else if (S_ISDIR(ce_mode) || S_ISGITLINK(ce_mode))
- return DT_DIR;
- else if (S_ISLNK(ce_mode))
- return DT_LNK;
- else
- return DT_UNKNOWN;
-}
-
-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 */
@@ -245,12 +206,6 @@ struct index_state {
void index_state_init(struct index_state *istate, struct repository *r);
void release_index(struct index_state *istate);
-/* Name hashing */
-int test_lazy_init_name_hash(struct index_state *istate, int try_threaded);
-void add_name_hash(struct index_state *istate, struct cache_entry *ce);
-void remove_name_hash(struct index_state *istate, struct cache_entry *ce);
-void free_name_hash(struct index_state *istate);
-
/* Cache entry creation and cleanup */
/*
@@ -318,31 +273,14 @@ typedef int (*must_prefetch_predicate)(const struct cache_entry *);
void prefetch_cache_entries(const struct index_state *istate,
must_prefetch_predicate must_prefetch);
-#ifdef USE_THE_INDEX_VARIABLE
-extern struct index_state the_index;
-#endif
-
-#define INIT_DB_QUIET 0x0001
-#define INIT_DB_EXIST_OK 0x0002
-
-int init_db(const char *git_dir, const char *real_git_dir,
- const char *template_dir, int hash_algo,
- const char *initial_branch, unsigned int flags);
-void initialize_repository_version(int hash_algo, int reinit);
-
/* Initialize and use the cache information */
struct lock_file;
-void preload_index(struct index_state *index,
- const struct pathspec *pathspec,
- unsigned int refresh_flags);
int do_read_index(struct index_state *istate, const char *path,
int must_exist); /* for testting only! */
int read_index_from(struct index_state *, const char *path,
const char *gitdir);
int is_index_unborn(struct index_state *);
-void ensure_full_index(struct index_state *istate);
-
/* For use with `write_locked_index()`. */
#define COMMIT_LOCK (1 << 0)
#define SKIP_IF_UNCHANGED (1 << 1)
@@ -385,9 +323,6 @@ int repo_index_has_changes(struct repository *repo,
int verify_path(const char *path, unsigned mode);
int strcmp_offset(const char *s1, const char *s2, size_t *first_change);
-int index_dir_exists(struct index_state *istate, const char *name, int namelen);
-void adjust_dirname_case(struct index_state *istate, char *name);
-struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase);
/*
* Searches for an entry defined by name and namelen in the given index.
@@ -496,19 +431,6 @@ int has_racy_timestamp(struct index_state *istate);
int ie_match_stat(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
int ie_modified(struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
-/*
- * Record to sd the data from st that we use to check whether a file
- * might have changed.
- */
-void fill_stat_data(struct stat_data *sd, struct stat *st);
-
-/*
- * Return 0 if st is consistent with a file not having been changed
- * since sd was filled. If there are differences, return a
- * combination of MTIME_CHANGED, CTIME_CHANGED, OWNER_CHANGED,
- * INODE_CHANGED, and DATA_CHANGED.
- */
-int match_stat_data(const struct stat_data *sd, struct stat *st);
int match_stat_data_racy(const struct index_state *istate,
const struct stat_data *sd, struct stat *st);
@@ -547,69 +469,13 @@ void set_alternate_index_output(const char *);
extern int verify_index_checksum;
extern int verify_ce_order;
-#define MTIME_CHANGED 0x0001
-#define CTIME_CHANGED 0x0002
-#define OWNER_CHANGED 0x0004
-#define MODE_CHANGED 0x0008
-#define INODE_CHANGED 0x0010
-#define DATA_CHANGED 0x0020
-#define TYPE_CHANGED 0x0040
-
int cmp_cache_name_compare(const void *a_, const void *b_);
-/* add */
-/*
- * return 0 if success, 1 - if addition of a file failed and
- * ADD_FILES_IGNORE_ERRORS was specified in flags
- */
-int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int flags);
+int add_files_to_cache(struct repository *repo, const char *prefix,
+ const struct pathspec *pathspec, int include_sparse,
+ int flags);
-/* diff.c */
-extern int diff_auto_refresh_index;
-
-/* ls-files */
void overlay_tree_on_index(struct index_state *istate,
const char *tree_name, const char *prefix);
-/* merge.c */
-struct commit_list;
-int try_merge_command(struct repository *r,
- const char *strategy, size_t xopts_nr,
- const char **xopts, struct commit_list *common,
- const char *head_arg, struct commit_list *remotes);
-int checkout_fast_forward(struct repository *r,
- const struct object_id *from,
- const struct object_id *to,
- int overwrite_ignore);
-
-
-int sane_execvp(const char *file, char *const argv[]);
-
-/*
- * A struct to encapsulate the concept of whether a file has changed
- * since we last checked it. This uses criteria similar to those used
- * for the index.
- */
-struct stat_validity {
- struct stat_data *sd;
-};
-
-void stat_validity_clear(struct stat_validity *sv);
-
-/*
- * Returns 1 if the path is a regular file (or a symlink to a regular
- * file) and matches the saved stat_validity, 0 otherwise. A missing
- * or inaccessible file is considered a match if the struct was just
- * initialized, or if the previous update found an inaccessible file.
- */
-int stat_validity_check(struct stat_validity *sv, const char *path);
-
-/*
- * Update the stat_validity from a file opened at descriptor fd. If
- * the file is missing, inaccessible, or not a regular file, then
- * future calls to stat_validity_check will match iff one of those
- * conditions continues to be true.
- */
-void stat_validity_update(struct stat_validity *sv, int fd);
-
-#endif /* CACHE_H */
+#endif /* READ_CACHE_LL_H */
diff --git a/read-cache.c b/read-cache.c
index f4c31a68c8..080bd39713 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3,8 +3,8 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
-#include "cache.h"
-#include "alloc.h"
+#include "git-compat-util.h"
+#include "bulk-checkin.h"
#include "config.h"
#include "date.h"
#include "diff.h"
@@ -16,7 +16,7 @@
#include "refs.h"
#include "dir.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "oid-array.h"
#include "tree.h"
#include "commit.h"
@@ -24,8 +24,13 @@
#include "environment.h"
#include "gettext.h"
#include "mem-pool.h"
+#include "name-hash.h"
#include "object-name.h"
+#include "path.h"
+#include "preload-index.h"
+#include "read-cache.h"
#include "resolve-undo.h"
+#include "revision.h"
#include "run-command.h"
#include "strbuf.h"
#include "trace2.h"
@@ -40,7 +45,6 @@
#include "csum-file.h"
#include "promisor-remote.h"
#include "hook.h"
-#include "wrapper.h"
/* Mask for the name length in ce_flags in the on-disk index */
@@ -175,61 +179,6 @@ void rename_index_entry_at(struct index_state *istate, int nr, const char *new_n
add_index_entry(istate, new_entry, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
}
-void fill_stat_data(struct stat_data *sd, struct stat *st)
-{
- sd->sd_ctime.sec = (unsigned int)st->st_ctime;
- sd->sd_mtime.sec = (unsigned int)st->st_mtime;
- sd->sd_ctime.nsec = ST_CTIME_NSEC(*st);
- sd->sd_mtime.nsec = ST_MTIME_NSEC(*st);
- sd->sd_dev = st->st_dev;
- sd->sd_ino = st->st_ino;
- sd->sd_uid = st->st_uid;
- sd->sd_gid = st->st_gid;
- sd->sd_size = st->st_size;
-}
-
-int match_stat_data(const struct stat_data *sd, struct stat *st)
-{
- int changed = 0;
-
- if (sd->sd_mtime.sec != (unsigned int)st->st_mtime)
- changed |= MTIME_CHANGED;
- if (trust_ctime && check_stat &&
- sd->sd_ctime.sec != (unsigned int)st->st_ctime)
- changed |= CTIME_CHANGED;
-
-#ifdef USE_NSEC
- if (check_stat && sd->sd_mtime.nsec != ST_MTIME_NSEC(*st))
- changed |= MTIME_CHANGED;
- if (trust_ctime && check_stat &&
- sd->sd_ctime.nsec != ST_CTIME_NSEC(*st))
- changed |= CTIME_CHANGED;
-#endif
-
- if (check_stat) {
- if (sd->sd_uid != (unsigned int) st->st_uid ||
- sd->sd_gid != (unsigned int) st->st_gid)
- changed |= OWNER_CHANGED;
- if (sd->sd_ino != (unsigned int) st->st_ino)
- changed |= INODE_CHANGED;
- }
-
-#ifdef USE_STDEV
- /*
- * st_dev breaks on network filesystems where different
- * clients will have different views of what "device"
- * the filesystem is on
- */
- if (check_stat && sd->sd_dev != (unsigned int) st->st_dev)
- changed |= INODE_CHANGED;
-#endif
-
- if (sd->sd_size != (unsigned int) st->st_size)
- changed |= DATA_CHANGED;
-
- return changed;
-}
-
/*
* This only updates the "non-critical" parts of the directory
* cache, ie the parts that aren't tracked by GIT, and only used
@@ -2285,6 +2234,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
if (fd < 0) {
if (!must_exist && errno == ENOENT) {
set_new_index_sparsity(istate);
+ istate->initialized = 1;
return 0;
}
die_errno(_("%s: index file open failed"), path);
@@ -2454,12 +2404,14 @@ int read_index_from(struct index_state *istate, const char *path,
base_oid_hex = oid_to_hex(&split_index->base_oid);
base_path = xstrfmt("%s/sharedindex.%s", gitdir, base_oid_hex);
- trace2_region_enter_printf("index", "shared/do_read_index",
- the_repository, "%s", base_path);
- ret = do_read_index(split_index->base, base_path, 0);
- trace2_region_leave_printf("index", "shared/do_read_index",
- the_repository, "%s", base_path);
- if (!ret) {
+ if (file_exists(base_path)) {
+ trace2_region_enter_printf("index", "shared/do_read_index",
+ the_repository, "%s", base_path);
+
+ ret = do_read_index(split_index->base, base_path, 0);
+ trace2_region_leave_printf("index", "shared/do_read_index",
+ the_repository, "%s", base_path);
+ } else {
char *path_copy = xstrdup(path);
char *base_path2 = xstrfmt("%s/sharedindex.%s",
dirname(path_copy), base_oid_hex);
@@ -3534,35 +3486,6 @@ void *read_blob_data_from_index(struct index_state *istate,
return data;
}
-void stat_validity_clear(struct stat_validity *sv)
-{
- FREE_AND_NULL(sv->sd);
-}
-
-int stat_validity_check(struct stat_validity *sv, const char *path)
-{
- struct stat st;
-
- if (stat(path, &st) < 0)
- return sv->sd == NULL;
- if (!sv->sd)
- return 0;
- return S_ISREG(st.st_mode) && !match_stat_data(sv->sd, &st);
-}
-
-void stat_validity_update(struct stat_validity *sv, int fd)
-{
- struct stat st;
-
- if (fstat(fd, &st) < 0 || !S_ISREG(st.st_mode))
- stat_validity_clear(sv);
- else {
- if (!sv->sd)
- CALLOC_ARRAY(sv->sd, 1);
- fill_stat_data(sv->sd, &st);
- }
-}
-
void move_index_extensions(struct index_state *dst, struct index_state *src)
{
dst->untracked = src->untracked;
@@ -3806,3 +3729,240 @@ void prefetch_cache_entries(const struct index_state *istate,
to_fetch.oid, to_fetch.nr);
oid_array_clear(&to_fetch);
}
+
+static int read_one_entry_opt(struct index_state *istate,
+ const struct object_id *oid,
+ struct strbuf *base,
+ const char *pathname,
+ unsigned mode, int opt)
+{
+ int len;
+ struct cache_entry *ce;
+
+ if (S_ISDIR(mode))
+ return READ_TREE_RECURSIVE;
+
+ len = strlen(pathname);
+ ce = make_empty_cache_entry(istate, base->len + len);
+
+ ce->ce_mode = create_ce_mode(mode);
+ ce->ce_flags = create_ce_flags(1);
+ ce->ce_namelen = base->len + len;
+ memcpy(ce->name, base->buf, base->len);
+ memcpy(ce->name + base->len, pathname, len+1);
+ oidcpy(&ce->oid, oid);
+ return add_index_entry(istate, ce, opt);
+}
+
+static int read_one_entry(const struct object_id *oid, struct strbuf *base,
+ const char *pathname, unsigned mode,
+ void *context)
+{
+ struct index_state *istate = context;
+ return read_one_entry_opt(istate, oid, base, pathname,
+ mode,
+ ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
+}
+
+/*
+ * This is used when the caller knows there is no existing entries at
+ * the stage that will conflict with the entry being added.
+ */
+static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base,
+ const char *pathname, unsigned mode,
+ void *context)
+{
+ struct index_state *istate = context;
+ return read_one_entry_opt(istate, oid, base, pathname,
+ mode, ADD_CACHE_JUST_APPEND);
+}
+
+/*
+ * Read the tree specified with --with-tree option
+ * (typically, HEAD) into stage #1 and then
+ * squash them down to stage #0. This is used for
+ * --error-unmatch to list and check the path patterns
+ * that were given from the command line. We are not
+ * going to write this index out.
+ */
+void overlay_tree_on_index(struct index_state *istate,
+ const char *tree_name, const char *prefix)
+{
+ struct tree *tree;
+ struct object_id oid;
+ struct pathspec pathspec;
+ struct cache_entry *last_stage0 = NULL;
+ int i;
+ read_tree_fn_t fn = NULL;
+ int err;
+
+ if (repo_get_oid(the_repository, tree_name, &oid))
+ die("tree-ish %s not found.", tree_name);
+ tree = parse_tree_indirect(&oid);
+ if (!tree)
+ die("bad tree-ish %s", tree_name);
+
+ /* Hoist the unmerged entries up to stage #3 to make room */
+ /* TODO: audit for interaction with sparse-index. */
+ ensure_full_index(istate);
+ for (i = 0; i < istate->cache_nr; i++) {
+ struct cache_entry *ce = istate->cache[i];
+ if (!ce_stage(ce))
+ continue;
+ ce->ce_flags |= CE_STAGEMASK;
+ }
+
+ if (prefix) {
+ static const char *(matchbuf[1]);
+ matchbuf[0] = NULL;
+ parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC,
+ PATHSPEC_PREFER_CWD, prefix, matchbuf);
+ } else
+ memset(&pathspec, 0, sizeof(pathspec));
+
+ /*
+ * See if we have cache entry at the stage. If so,
+ * do it the original slow way, otherwise, append and then
+ * sort at the end.
+ */
+ for (i = 0; !fn && i < istate->cache_nr; i++) {
+ const struct cache_entry *ce = istate->cache[i];
+ if (ce_stage(ce) == 1)
+ fn = read_one_entry;
+ }
+
+ if (!fn)
+ fn = read_one_entry_quick;
+ err = read_tree(the_repository, tree, &pathspec, fn, istate);
+ clear_pathspec(&pathspec);
+ if (err)
+ die("unable to read tree entries %s", tree_name);
+
+ /*
+ * Sort the cache entry -- we need to nuke the cache tree, though.
+ */
+ if (fn == read_one_entry_quick) {
+ cache_tree_free(&istate->cache_tree);
+ QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare);
+ }
+
+ for (i = 0; i < istate->cache_nr; i++) {
+ struct cache_entry *ce = istate->cache[i];
+ switch (ce_stage(ce)) {
+ case 0:
+ last_stage0 = ce;
+ /* fallthru */
+ default:
+ continue;
+ case 1:
+ /*
+ * If there is stage #0 entry for this, we do not
+ * need to show it. We use CE_UPDATE bit to mark
+ * such an entry.
+ */
+ if (last_stage0 &&
+ !strcmp(last_stage0->name, ce->name))
+ ce->ce_flags |= CE_UPDATE;
+ }
+ }
+}
+
+struct update_callback_data {
+ struct index_state *index;
+ int include_sparse;
+ int flags;
+ int add_errors;
+};
+
+static int fix_unmerged_status(struct diff_filepair *p,
+ struct update_callback_data *data)
+{
+ if (p->status != DIFF_STATUS_UNMERGED)
+ return p->status;
+ if (!(data->flags & ADD_CACHE_IGNORE_REMOVAL) && !p->two->mode)
+ /*
+ * This is not an explicit add request, and the
+ * path is missing from the working tree (deleted)
+ */
+ return DIFF_STATUS_DELETED;
+ else
+ /*
+ * Either an explicit add request, or path exists
+ * in the working tree. An attempt to explicitly
+ * add a path that does not exist in the working tree
+ * will be caught as an error by the caller immediately.
+ */
+ return DIFF_STATUS_MODIFIED;
+}
+
+static void update_callback(struct diff_queue_struct *q,
+ struct diff_options *opt UNUSED, void *cbdata)
+{
+ int i;
+ struct update_callback_data *data = cbdata;
+
+ for (i = 0; i < q->nr; i++) {
+ struct diff_filepair *p = q->queue[i];
+ const char *path = p->one->path;
+
+ if (!data->include_sparse &&
+ !path_in_sparse_checkout(path, data->index))
+ continue;
+
+ switch (fix_unmerged_status(p, data)) {
+ default:
+ die(_("unexpected diff status %c"), p->status);
+ case DIFF_STATUS_MODIFIED:
+ case DIFF_STATUS_TYPE_CHANGED:
+ if (add_file_to_index(data->index, path, data->flags)) {
+ if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
+ die(_("updating files failed"));
+ data->add_errors++;
+ }
+ break;
+ case DIFF_STATUS_DELETED:
+ if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
+ break;
+ if (!(data->flags & ADD_CACHE_PRETEND))
+ remove_file_from_index(data->index, path);
+ if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE))
+ printf(_("remove '%s'\n"), path);
+ break;
+ }
+ }
+}
+
+int add_files_to_cache(struct repository *repo, const char *prefix,
+ const struct pathspec *pathspec, int include_sparse,
+ int flags)
+{
+ struct update_callback_data data;
+ struct rev_info rev;
+
+ memset(&data, 0, sizeof(data));
+ data.index = repo->index;
+ data.include_sparse = include_sparse;
+ data.flags = flags;
+
+ repo_init_revisions(repo, &rev, prefix);
+ setup_revisions(0, NULL, &rev, NULL);
+ if (pathspec)
+ copy_pathspec(&rev.prune_data, pathspec);
+ rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
+ rev.diffopt.format_callback = update_callback;
+ rev.diffopt.format_callback_data = &data;
+ rev.diffopt.flags.override_submodule_config = 1;
+ rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
+
+ /*
+ * Use an ODB transaction to optimize adding multiple objects.
+ * This function is invoked from commands other than 'add', which
+ * may not have their own transaction active.
+ */
+ begin_odb_transaction();
+ run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
+ end_odb_transaction();
+
+ release_revisions(&rev);
+ return !!data.add_errors;
+}
diff --git a/read-cache.h b/read-cache.h
new file mode 100644
index 0000000000..043da1f1aa
--- /dev/null
+++ b/read-cache.h
@@ -0,0 +1,45 @@
+#ifndef READ_CACHE_H
+#define READ_CACHE_H
+
+#include "read-cache-ll.h"
+#include "object.h"
+#include "pathspec.h"
+
+static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce,
+ unsigned int mode)
+{
+ extern int trust_executable_bit, has_symlinks;
+ if (!has_symlinks && S_ISREG(mode) &&
+ ce && S_ISLNK(ce->ce_mode))
+ return ce->ce_mode;
+ if (!trust_executable_bit && S_ISREG(mode)) {
+ if (ce && S_ISREG(ce->ce_mode))
+ return ce->ce_mode;
+ return create_ce_mode(0666);
+ }
+ return create_ce_mode(mode);
+}
+
+static inline int ce_to_dtype(const struct cache_entry *ce)
+{
+ unsigned ce_mode = ntohl(ce->ce_mode);
+ if (S_ISREG(ce_mode))
+ return DT_REG;
+ else if (S_ISDIR(ce_mode) || S_ISGITLINK(ce_mode))
+ return DT_DIR;
+ else if (S_ISLNK(ce_mode))
+ return DT_LNK;
+ else
+ return DT_UNKNOWN;
+}
+
+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));
+}
+
+#endif /* READ_CACHE_H */
diff --git a/rebase-interactive.c b/rebase-interactive.c
index 852a331318..d9718409b3 100644
--- a/rebase-interactive.c
+++ b/rebase-interactive.c
@@ -11,7 +11,6 @@
#include "config.h"
#include "dir.h"
#include "object-name.h"
-#include "wrapper.h"
static const char edit_todo_list_advice[] =
N_("You can fix this with 'git rebase --edit-todo' "
@@ -72,13 +71,14 @@ void append_todo_help(int command_count,
if (!edit_todo) {
strbuf_addch(buf, '\n');
- strbuf_commented_addf(buf, Q_("Rebase %s onto %s (%d command)",
- "Rebase %s onto %s (%d commands)",
- command_count),
+ strbuf_commented_addf(buf, comment_line_char,
+ Q_("Rebase %s onto %s (%d command)",
+ "Rebase %s onto %s (%d commands)",
+ command_count),
shortrevisions, shortonto, command_count);
}
- strbuf_add_commented_lines(buf, msg, strlen(msg));
+ strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_char);
if (get_missing_commit_check_level() == MISSING_COMMIT_CHECK_ERROR)
msg = _("\nDo not remove any line. Use 'drop' "
@@ -87,7 +87,7 @@ void append_todo_help(int command_count,
msg = _("\nIf you remove a line here "
"THAT COMMIT WILL BE LOST.\n");
- strbuf_add_commented_lines(buf, msg, strlen(msg));
+ strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_char);
if (edit_todo)
msg = _("\nYou are editing the todo file "
@@ -98,7 +98,7 @@ void append_todo_help(int command_count,
msg = _("\nHowever, if you remove everything, "
"the rebase will be aborted.\n\n");
- strbuf_add_commented_lines(buf, msg, strlen(msg));
+ strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_char);
}
int edit_todo_list(struct repository *r, struct todo_list *todo_list,
@@ -130,7 +130,7 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list,
if (launch_sequence_editor(todo_file, &new_todo->buf, NULL))
return -2;
- strbuf_stripspace(&new_todo->buf, 1);
+ strbuf_stripspace(&new_todo->buf, comment_line_char);
if (initial && new_todo->buf.len == 0)
return -3;
diff --git a/ref-filter.c b/ref-filter.c
index 4991cd4f7a..1bfaf20fbf 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1,14 +1,15 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
+#include "config.h"
#include "gpg-interface.h"
#include "hex.h"
#include "parse-options.h"
+#include "run-command.h"
#include "refs.h"
#include "wildmatch.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "oid-array.h"
#include "repository.h"
#include "commit.h"
@@ -146,10 +147,12 @@ enum atom_type {
ATOM_TAGGERDATE,
ATOM_CREATOR,
ATOM_CREATORDATE,
+ ATOM_DESCRIBE,
ATOM_SUBJECT,
ATOM_BODY,
ATOM_TRAILERS,
ATOM_CONTENTS,
+ ATOM_SIGNATURE,
ATOM_RAW,
ATOM_UPSTREAM,
ATOM_PUSH,
@@ -215,6 +218,11 @@ static struct used_atom {
struct email_option {
enum { EO_RAW, EO_TRIM, EO_LOCALPART } option;
} email_option;
+ struct {
+ enum { S_BARE, S_GRADE, S_SIGNER, S_KEY,
+ S_FINGERPRINT, S_PRI_KEY_FP, S_TRUST_LEVEL } option;
+ } signature;
+ const char **describe_args;
struct refname_atom refname;
char *head;
} u;
@@ -251,6 +259,110 @@ static int err_bad_arg(struct strbuf *sb, const char *name, const char *arg)
return -1;
}
+/*
+ * Parse option of name "candidate" in the option string "to_parse" of
+ * the form
+ *
+ * "candidate1[=val1],candidate2[=val2],candidate3[=val3],..."
+ *
+ * The remaining part of "to_parse" is stored in "end" (if we are
+ * parsing the last candidate, then this is NULL) and the value of
+ * the candidate is stored in "valuestart" and its length in "valuelen",
+ * that is the portion after "=". Since it is possible for a "candidate"
+ * to not have a value, in such cases, "valuestart" is set to point to
+ * NULL and "valuelen" to 0.
+ *
+ * The function returns 1 on success. It returns 0 if we don't find
+ * "candidate" in "to_parse" or we find "candidate" but it is followed
+ * by more chars (for example, "candidatefoo"), that is, we don't find
+ * an exact match.
+ *
+ * This function only does the above for one "candidate" at a time. So
+ * it has to be called each time trying to parse a "candidate" in the
+ * option string "to_parse".
+ */
+static int match_atom_arg_value(const char *to_parse, const char *candidate,
+ const char **end, const char **valuestart,
+ size_t *valuelen)
+{
+ const char *atom;
+
+ if (!skip_prefix(to_parse, candidate, &atom))
+ return 0; /* definitely not "candidate" */
+
+ if (*atom == '=') {
+ /* we just saw "candidate=" */
+ *valuestart = atom + 1;
+ atom = strchrnul(*valuestart, ',');
+ *valuelen = atom - *valuestart;
+ } else if (*atom != ',' && *atom != '\0') {
+ /* key begins with "candidate" but has more chars */
+ return 0;
+ } else {
+ /* just "candidate" without "=val" */
+ *valuestart = NULL;
+ *valuelen = 0;
+ }
+
+ /* atom points at either the ',' or NUL after this key[=val] */
+ if (*atom == ',')
+ atom++;
+ else if (*atom)
+ BUG("Why is *atom not NULL yet?");
+
+ *end = atom;
+ return 1;
+}
+
+/*
+ * Parse boolean option of name "candidate" in the option list "to_parse"
+ * of the form
+ *
+ * "candidate1[=bool1],candidate2[=bool2],candidate3[=bool3],..."
+ *
+ * The remaining part of "to_parse" is stored in "end" (if we are parsing
+ * the last candidate, then this is NULL) and the value (if given) is
+ * parsed and stored in "val", so "val" always points to either 0 or 1.
+ * If the value is not given, then "val" is set to point to 1.
+ *
+ * The boolean value is parsed using "git_parse_maybe_bool()", so the
+ * accepted values are
+ *
+ * to set true - "1", "yes", "true"
+ * to set false - "0", "no", "false"
+ *
+ * This function returns 1 on success. It returns 0 when we don't find
+ * an exact match for "candidate" or when the boolean value given is
+ * not valid.
+ */
+static int match_atom_bool_arg(const char *to_parse, const char *candidate,
+ const char **end, int *val)
+{
+ const char *argval;
+ char *strval;
+ size_t arglen;
+ int v;
+
+ if (!match_atom_arg_value(to_parse, candidate, end, &argval, &arglen))
+ return 0;
+
+ if (!argval) {
+ *val = 1;
+ return 1;
+ }
+
+ strval = xstrndup(argval, arglen);
+ v = git_parse_maybe_bool(strval);
+ free(strval);
+
+ if (v == -1)
+ return 0;
+
+ *val = v;
+
+ return 1;
+}
+
static int color_atom_parser(struct ref_format *format, struct used_atom *atom,
const char *color_value, struct strbuf *err)
{
@@ -407,8 +519,37 @@ static int subject_atom_parser(struct ref_format *format UNUSED,
return 0;
}
-static int trailers_atom_parser(struct ref_format *format UNUSED,
- struct used_atom *atom,
+static int parse_signature_option(const char *arg)
+{
+ if (!arg)
+ return S_BARE;
+ else if (!strcmp(arg, "signer"))
+ return S_SIGNER;
+ else if (!strcmp(arg, "grade"))
+ return S_GRADE;
+ else if (!strcmp(arg, "key"))
+ return S_KEY;
+ else if (!strcmp(arg, "fingerprint"))
+ return S_FINGERPRINT;
+ else if (!strcmp(arg, "primarykeyfingerprint"))
+ return S_PRI_KEY_FP;
+ else if (!strcmp(arg, "trustlevel"))
+ return S_TRUST_LEVEL;
+ return -1;
+}
+
+static int signature_atom_parser(struct ref_format *format UNUSED,
+ struct used_atom *atom,
+ const char *arg, struct strbuf *err)
+{
+ int opt = parse_signature_option(arg);
+ if (opt < 0)
+ return err_bad_arg(err, "signature", arg);
+ atom->u.signature.option = opt;
+ return 0;
+}
+
+static int trailers_atom_parser(struct ref_format *format, struct used_atom *atom,
const char *arg, struct strbuf *err)
{
atom->u.contents.trailer_opts.no_divider = 1;
@@ -462,6 +603,87 @@ static int contents_atom_parser(struct ref_format *format, struct used_atom *ato
return 0;
}
+static int describe_atom_option_parser(struct strvec *args, const char **arg,
+ struct strbuf *err)
+{
+ const char *argval;
+ size_t arglen = 0;
+ int optval = 0;
+
+ if (match_atom_bool_arg(*arg, "tags", arg, &optval)) {
+ if (!optval)
+ strvec_push(args, "--no-tags");
+ else
+ strvec_push(args, "--tags");
+ return 1;
+ }
+
+ if (match_atom_arg_value(*arg, "abbrev", arg, &argval, &arglen)) {
+ char *endptr;
+
+ if (!arglen)
+ return strbuf_addf_ret(err, -1,
+ _("argument expected for %s"),
+ "describe:abbrev");
+ if (strtol(argval, &endptr, 10) < 0)
+ return strbuf_addf_ret(err, -1,
+ _("positive value expected %s=%s"),
+ "describe:abbrev", argval);
+ if (endptr - argval != arglen)
+ return strbuf_addf_ret(err, -1,
+ _("cannot fully parse %s=%s"),
+ "describe:abbrev", argval);
+
+ strvec_pushf(args, "--abbrev=%.*s", (int)arglen, argval);
+ return 1;
+ }
+
+ if (match_atom_arg_value(*arg, "match", arg, &argval, &arglen)) {
+ if (!arglen)
+ return strbuf_addf_ret(err, -1,
+ _("value expected %s="),
+ "describe:match");
+
+ strvec_pushf(args, "--match=%.*s", (int)arglen, argval);
+ return 1;
+ }
+
+ if (match_atom_arg_value(*arg, "exclude", arg, &argval, &arglen)) {
+ if (!arglen)
+ return strbuf_addf_ret(err, -1,
+ _("value expected %s="),
+ "describe:exclude");
+
+ strvec_pushf(args, "--exclude=%.*s", (int)arglen, argval);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int describe_atom_parser(struct ref_format *format UNUSED,
+ struct used_atom *atom,
+ const char *arg, struct strbuf *err)
+{
+ struct strvec args = STRVEC_INIT;
+
+ for (;;) {
+ int found = 0;
+ const char *bad_arg = arg;
+
+ if (!arg || !*arg)
+ break;
+
+ found = describe_atom_option_parser(&args, &arg, err);
+ if (found < 0)
+ return found;
+ if (!found)
+ return err_bad_arg(err, "describe", bad_arg);
+ }
+ atom->u.describe_args = strvec_detach(&args);
+ return 0;
+}
+
static int raw_atom_parser(struct ref_format *format UNUSED,
struct used_atom *atom,
const char *arg, struct strbuf *err)
@@ -664,10 +886,12 @@ static struct {
[ATOM_TAGGERDATE] = { "taggerdate", SOURCE_OBJ, FIELD_TIME },
[ATOM_CREATOR] = { "creator", SOURCE_OBJ },
[ATOM_CREATORDATE] = { "creatordate", SOURCE_OBJ, FIELD_TIME },
+ [ATOM_DESCRIBE] = { "describe", SOURCE_OBJ, FIELD_STR, describe_atom_parser },
[ATOM_SUBJECT] = { "subject", SOURCE_OBJ, FIELD_STR, subject_atom_parser },
[ATOM_BODY] = { "body", SOURCE_OBJ, FIELD_STR, body_atom_parser },
[ATOM_TRAILERS] = { "trailers", SOURCE_OBJ, FIELD_STR, trailers_atom_parser },
[ATOM_CONTENTS] = { "contents", SOURCE_OBJ, FIELD_STR, contents_atom_parser },
+ [ATOM_SIGNATURE] = { "signature", SOURCE_OBJ, FIELD_STR, signature_atom_parser },
[ATOM_RAW] = { "raw", SOURCE_OBJ, FIELD_STR, raw_atom_parser },
[ATOM_UPSTREAM] = { "upstream", SOURCE_NONE, FIELD_STR, remote_ref_atom_parser },
[ATOM_PUSH] = { "push", SOURCE_NONE, FIELD_STR, remote_ref_atom_parser },
@@ -1405,6 +1629,92 @@ static void grab_person(const char *who, struct atom_value *val, int deref, void
}
}
+static void grab_signature(struct atom_value *val, int deref, struct object *obj)
+{
+ int i;
+ struct commit *commit = (struct commit *) obj;
+ struct signature_check sigc = { 0 };
+ int signature_checked = 0;
+
+ for (i = 0; i < used_atom_cnt; i++) {
+ struct used_atom *atom = &used_atom[i];
+ const char *name = atom->name;
+ struct atom_value *v = &val[i];
+ int opt;
+
+ if (!!deref != (*name == '*'))
+ continue;
+ if (deref)
+ name++;
+
+ if (!skip_prefix(name, "signature", &name) ||
+ (*name && *name != ':'))
+ continue;
+ if (!*name)
+ name = NULL;
+ else
+ name++;
+
+ opt = parse_signature_option(name);
+ if (opt < 0)
+ continue;
+
+ if (!signature_checked) {
+ check_commit_signature(commit, &sigc);
+ signature_checked = 1;
+ }
+
+ switch (opt) {
+ case S_BARE:
+ v->s = xstrdup(sigc.output ? sigc.output: "");
+ break;
+ case S_SIGNER:
+ v->s = xstrdup(sigc.signer ? sigc.signer : "");
+ break;
+ case S_GRADE:
+ switch (sigc.result) {
+ case 'G':
+ switch (sigc.trust_level) {
+ case TRUST_UNDEFINED:
+ case TRUST_NEVER:
+ v->s = xstrfmt("%c", (char)'U');
+ break;
+ default:
+ v->s = xstrfmt("%c", (char)'G');
+ break;
+ }
+ break;
+ case 'B':
+ case 'E':
+ case 'N':
+ case 'X':
+ case 'Y':
+ case 'R':
+ v->s = xstrfmt("%c", (char)sigc.result);
+ break;
+ }
+ break;
+ case S_KEY:
+ v->s = xstrdup(sigc.key ? sigc.key : "");
+ break;
+ case S_FINGERPRINT:
+ v->s = xstrdup(sigc.fingerprint ?
+ sigc.fingerprint : "");
+ break;
+ case S_PRI_KEY_FP:
+ v->s = xstrdup(sigc.primary_key_fingerprint ?
+ sigc.primary_key_fingerprint : "");
+ break;
+ case S_TRUST_LEVEL:
+ v->s = xstrdup(gpg_trust_level_to_str(sigc.trust_level));
+ break;
+ }
+ }
+
+ if (signature_checked)
+ signature_check_clear(&sigc);
+}
+
static void find_subpos(const char *buf,
const char **sub, size_t *sublen,
const char **body, size_t *bodylen,
@@ -1483,6 +1793,44 @@ static void append_lines(struct strbuf *out, const char *buf, unsigned long size
}
}
+static void grab_describe_values(struct atom_value *val, int deref,
+ struct object *obj)
+{
+ struct commit *commit = (struct commit *)obj;
+ int i;
+
+ for (i = 0; i < used_atom_cnt; i++) {
+ struct used_atom *atom = &used_atom[i];
+ enum atom_type type = atom->atom_type;
+ const char *name = atom->name;
+ struct atom_value *v = &val[i];
+
+ struct child_process cmd = CHILD_PROCESS_INIT;
+ struct strbuf out = STRBUF_INIT;
+ struct strbuf err = STRBUF_INIT;
+
+ if (type != ATOM_DESCRIBE)
+ continue;
+
+ if (!!deref != (*name == '*'))
+ continue;
+
+ cmd.git_cmd = 1;
+ strvec_push(&cmd.args, "describe");
+ strvec_pushv(&cmd.args, atom->u.describe_args);
+ strvec_push(&cmd.args, oid_to_hex(&commit->object.oid));
+ if (pipe_command(&cmd, NULL, 0, &out, 0, &err, 0) < 0) {
+ error(_("failed to run 'describe'"));
+ v->s = xstrdup("");
+ continue;
+ }
+ strbuf_rtrim(&out);
+ v->s = strbuf_detach(&out, NULL);
+
+ strbuf_release(&err);
+ }
+}
+
/* See grab_values */
static void grab_sub_body_contents(struct atom_value *val, int deref, struct expand_data *data)
{
@@ -1592,12 +1940,15 @@ static void grab_values(struct atom_value *val, int deref, struct object *obj, s
grab_tag_values(val, deref, obj);
grab_sub_body_contents(val, deref, data);
grab_person("tagger", val, deref, buf);
+ grab_describe_values(val, deref, obj);
break;
case OBJ_COMMIT:
grab_commit_values(val, deref, obj);
grab_sub_body_contents(val, deref, data);
grab_person("author", val, deref, buf);
grab_person("committer", val, deref, buf);
+ grab_signature(val, deref, obj);
+ grab_describe_values(val, deref, obj);
break;
case OBJ_TREE:
/* grab_tree_values(val, deref, obj, buf, sz); */
@@ -2104,12 +2455,12 @@ static int get_ref_atom_value(struct ref_array_item *ref, int atom,
* matches a pattern "refs/heads/mas") or a wildcard (e.g. the same ref
* matches "refs/heads/mas*", too).
*/
-static int match_pattern(const struct ref_filter *filter, const char *refname)
+static int match_pattern(const char **patterns, const char *refname,
+ int ignore_case)
{
- const char **patterns = filter->name_patterns;
unsigned flags = 0;
- if (filter->ignore_case)
+ if (ignore_case)
flags |= WM_CASEFOLD;
/*
@@ -2134,13 +2485,13 @@ static int match_pattern(const struct ref_filter *filter, const char *refname)
* matches a pattern "refs/heads/" but not "refs/heads/m") or a
* wildcard (e.g. the same ref matches "refs/heads/m*", too).
*/
-static int match_name_as_path(const struct ref_filter *filter, const char *refname)
+static int match_name_as_path(const char **pattern, const char *refname,
+ int ignore_case)
{
- const char **pattern = filter->name_patterns;
int namelen = strlen(refname);
unsigned flags = WM_PATHNAME;
- if (filter->ignore_case)
+ if (ignore_case)
flags |= WM_CASEFOLD;
for (; *pattern; pattern++) {
@@ -2165,8 +2516,20 @@ static int filter_pattern_match(struct ref_filter *filter, const char *refname)
if (!*filter->name_patterns)
return 1; /* No pattern always matches */
if (filter->match_as_path)
- return match_name_as_path(filter, refname);
- return match_pattern(filter, refname);
+ return match_name_as_path(filter->name_patterns, refname,
+ filter->ignore_case);
+ return match_pattern(filter->name_patterns, refname,
+ filter->ignore_case);
+}
+
+static int filter_exclude_match(struct ref_filter *filter, const char *refname)
+{
+ if (!filter->exclude.nr)
+ return 0;
+ if (filter->match_as_path)
+ return match_name_as_path(filter->exclude.v, refname,
+ filter->ignore_case);
+ return match_pattern(filter->exclude.v, refname, filter->ignore_case);
}
/*
@@ -2198,43 +2561,53 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter,
if (!filter->name_patterns[0]) {
/* no patterns; we have to look at everything */
- return for_each_fullref_in("", cb, cb_data);
+ return refs_for_each_fullref_in(get_main_ref_store(the_repository),
+ "", filter->exclude.v, cb, cb_data);
}
return refs_for_each_fullref_in_prefixes(get_main_ref_store(the_repository),
NULL, filter->name_patterns,
+ filter->exclude.v,
cb, cb_data);
}
/*
* Given a ref (oid, refname), check if the ref belongs to the array
* of oids. If the given ref is a tag, check if the given tag points
- * at one of the oids in the given oid array.
+ * at one of the oids in the given oid array. Returns non-zero if a
+ * match is found.
+ *
* NEEDSWORK:
- * 1. Only a single level of indirection is obtained, we might want to
- * change this to account for multiple levels (e.g. annotated tags
- * pointing to annotated tags pointing to a commit.)
- * 2. As the refs are cached we might know what refname peels to without
+ * As the refs are cached we might know what refname peels to without
* the need to parse the object via parse_object(). peel_ref() might be a
* more efficient alternative to obtain the pointee.
*/
-static const struct object_id *match_points_at(struct oid_array *points_at,
- const struct object_id *oid,
- const char *refname)
+static int match_points_at(struct oid_array *points_at,
+ const struct object_id *oid,
+ const char *refname)
{
- const struct object_id *tagged_oid = NULL;
struct object *obj;
if (oid_array_lookup(points_at, oid) >= 0)
- return oid;
- obj = parse_object(the_repository, oid);
+ return 1;
+ obj = parse_object_with_flags(the_repository, oid,
+ PARSE_OBJECT_SKIP_HASH_CHECK);
+ while (obj && obj->type == OBJ_TAG) {
+ struct tag *tag = (struct tag *)obj;
+
+ if (parse_tag(tag) < 0) {
+ obj = NULL;
+ break;
+ }
+
+ if (oid_array_lookup(points_at, get_tagged_oid(tag)) >= 0)
+ return 1;
+
+ obj = tag->tagged;
+ }
if (!obj)
die(_("malformed object at '%s'"), refname);
- if (obj->type == OBJ_TAG)
- tagged_oid = get_tagged_oid((struct tag *)obj);
- if (tagged_oid && oid_array_lookup(points_at, tagged_oid) >= 0)
- return tagged_oid;
- return NULL;
+ return 0;
}
/*
@@ -2336,6 +2709,9 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
if (!filter_pattern_match(filter, refname))
return 0;
+ if (filter_exclude_match(filter, refname))
+ return 0;
+
if (filter->points_at.nr && !match_points_at(&filter->points_at, oid, refname))
return 0;
@@ -2418,13 +2794,13 @@ void ref_array_clear(struct ref_array *array)
#define EXCLUDE_REACHED 0
#define INCLUDE_REACHED 1
static void reach_filter(struct ref_array *array,
- struct commit_list *check_reachable,
+ struct commit_list **check_reachable,
int include_reached)
{
int i, old_nr;
struct commit **to_clear;
- if (!check_reachable)
+ if (!*check_reachable)
return;
CALLOC_ARRAY(to_clear, array->nr);
@@ -2434,7 +2810,7 @@ static void reach_filter(struct ref_array *array,
}
tips_reachable_from_bases(the_repository,
- check_reachable,
+ *check_reachable,
to_clear, array->nr,
UNINTERESTING);
@@ -2455,8 +2831,8 @@ static void reach_filter(struct ref_array *array,
clear_commit_marks_many(old_nr, to_clear, ALL_REV_FLAGS);
- while (check_reachable) {
- struct commit *merge_commit = pop_commit(&check_reachable);
+ while (*check_reachable) {
+ struct commit *merge_commit = pop_commit(check_reachable);
clear_commit_marks(merge_commit, ALL_REV_FLAGS);
}
@@ -2553,8 +2929,8 @@ int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int
clear_contains_cache(&ref_cbdata.no_contains_cache);
/* Filters that need revision walking */
- reach_filter(array, filter->reachable_from, INCLUDE_REACHED);
- reach_filter(array, filter->unreachable_from, EXCLUDE_REACHED);
+ reach_filter(array, &filter->reachable_from, INCLUDE_REACHED);
+ reach_filter(array, &filter->unreachable_from, EXCLUDE_REACHED);
save_commit_buffer = save_commit_buffer_orig;
return ret;
@@ -2866,3 +3242,20 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
return 0;
}
+
+void ref_filter_init(struct ref_filter *filter)
+{
+ struct ref_filter blank = REF_FILTER_INIT;
+ memcpy(filter, &blank, sizeof(blank));
+}
+
+void ref_filter_clear(struct ref_filter *filter)
+{
+ strvec_clear(&filter->exclude);
+ oid_array_clear(&filter->points_at);
+ free_commit_list(filter->with_commit);
+ free_commit_list(filter->no_commit);
+ free_commit_list(filter->reachable_from);
+ free_commit_list(filter->unreachable_from);
+ ref_filter_init(filter);
+}
diff --git a/ref-filter.h b/ref-filter.h
index 430701cfb7..1524bc463a 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -6,6 +6,7 @@
#include "refs.h"
#include "commit.h"
#include "string-list.h"
+#include "strvec.h"
/* Quoting styles */
#define QUOTE_NONE 0
@@ -59,6 +60,7 @@ struct ref_array {
struct ref_filter {
const char **name_patterns;
+ struct strvec exclude;
struct oid_array points_at;
struct commit_list *with_commit;
struct commit_list *no_commit;
@@ -92,6 +94,10 @@ struct ref_format {
struct string_list bases;
};
+#define REF_FILTER_INIT { \
+ .points_at = OID_ARRAY_INIT, \
+ .exclude = STRVEC_INIT, \
+}
#define REF_FORMAT_INIT { \
.use_color = -1, \
.bases = STRING_LIST_INIT_DUP, \
@@ -109,6 +115,9 @@ struct ref_format {
#define OPT_REF_SORT(var) \
OPT_STRING_LIST(0, "sort", (var), \
N_("key"), N_("field name to sort on"))
+#define OPT_REF_FILTER_EXCLUDE(var) \
+ OPT_STRVEC(0, "exclude", &(var)->exclude, \
+ N_("pattern"), N_("exclude refs which match pattern"))
/*
* API for filtering a set of refs. Based on the type of refs the user
@@ -167,4 +176,7 @@ void filter_ahead_behind(struct repository *r,
struct ref_format *format,
struct ref_array *array);
+void ref_filter_init(struct ref_filter *filter);
+void ref_filter_clear(struct ref_filter *filter);
+
#endif /* REF_FILTER_H */
diff --git a/reflog-walk.c b/reflog-walk.c
index 4ba1a10c82..d216f6f966 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -1,8 +1,8 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "commit.h"
#include "refs.h"
#include "diff.h"
+#include "repository.h"
#include "revision.h"
#include "string-list.h"
#include "reflog-walk.h"
diff --git a/reflog.c b/reflog.c
index ee1bf5d032..9ad50e7d93 100644
--- a/reflog.c
+++ b/reflog.c
@@ -1,6 +1,6 @@
#include "git-compat-util.h"
#include "gettext.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "reflog.h"
#include "refs.h"
#include "revision.h"
diff --git a/refs.c b/refs.c
index d2a98e1c21..fcae5dddc6 100644
--- a/refs.c
+++ b/refs.c
@@ -4,7 +4,6 @@
#include "git-compat-util.h"
#include "advice.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "hashmap.h"
@@ -17,8 +16,9 @@
#include "run-command.h"
#include "hook.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "object.h"
+#include "path.h"
#include "tag.h"
#include "submodule.h"
#include "worktree.h"
@@ -28,7 +28,7 @@
#include "sigchain.h"
#include "date.h"
#include "commit.h"
-#include "wrapper.h"
+#include "wildmatch.h"
/*
* List of all available backends
@@ -375,8 +375,8 @@ char *resolve_refdup(const char *refname, int resolve_flags,
oid, flags);
}
-/* The argument to filter_refs */
-struct ref_filter {
+/* The argument to for_each_filter_refs */
+struct for_each_ref_filter {
const char *pattern;
const char *prefix;
each_ref_fn *fn;
@@ -409,10 +409,11 @@ int ref_exists(const char *refname)
return refs_ref_exists(get_main_ref_store(the_repository), refname);
}
-static int filter_refs(const char *refname, const struct object_id *oid,
- int flags, void *data)
+static int for_each_filter_refs(const char *refname,
+ const struct object_id *oid,
+ int flags, void *data)
{
- struct ref_filter *filter = (struct ref_filter *)data;
+ struct for_each_ref_filter *filter = data;
if (wildmatch(filter->pattern, refname, 0))
return 0;
@@ -569,7 +570,7 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
const char *prefix, void *cb_data)
{
struct strbuf real_pattern = STRBUF_INIT;
- struct ref_filter filter;
+ struct for_each_ref_filter filter;
int ret;
if (!prefix && !starts_with(pattern, "refs/"))
@@ -589,7 +590,7 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
filter.prefix = prefix;
filter.fn = fn;
filter.cb_data = cb_data;
- ret = for_each_ref(filter_refs, &filter);
+ ret = for_each_ref(for_each_filter_refs, &filter);
strbuf_release(&real_pattern);
return ret;
@@ -1426,7 +1427,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
}
int parse_hide_refs_config(const char *var, const char *value, const char *section,
- struct string_list *hide_refs)
+ struct strvec *hide_refs)
{
const char *key;
if (!strcmp("transfer.hiderefs", var) ||
@@ -1437,22 +1438,23 @@ int parse_hide_refs_config(const char *var, const char *value, const char *secti
if (!value)
return config_error_nonbool(var);
- ref = xstrdup(value);
+
+ /* drop const to remove trailing '/' characters */
+ ref = (char *)strvec_push(hide_refs, value);
len = strlen(ref);
while (len && ref[len - 1] == '/')
ref[--len] = '\0';
- string_list_append_nodup(hide_refs, ref);
}
return 0;
}
int ref_is_hidden(const char *refname, const char *refname_full,
- const struct string_list *hide_refs)
+ const struct strvec *hide_refs)
{
int i;
for (i = hide_refs->nr - 1; i >= 0; i--) {
- const char *match = hide_refs->items[i].string;
+ const char *match = hide_refs->v[i];
const char *subject;
int neg = 0;
const char *p;
@@ -1478,6 +1480,30 @@ int ref_is_hidden(const char *refname, const char *refname_full,
return 0;
}
+const char **hidden_refs_to_excludes(const struct strvec *hide_refs)
+{
+ const char **pattern;
+ for (pattern = hide_refs->v; *pattern; pattern++) {
+ /*
+ * We can't feed any excludes from hidden refs config
+ * sections, since later rules may override previous
+ * ones. For example, with rules "refs/foo" and
+ * "!refs/foo/bar", we should show "refs/foo/bar" (and
+ * everything underneath it), but the earlier exclusion
+ * would cause us to skip all of "refs/foo". We
+ * likewise don't implement the namespace stripping
+ * required for '^' rules.
+ *
+ * Both are possible to do, but complicated, so avoid
+ * populating the jump list at all if we see either of
+ * these patterns.
+ */
+ if (**pattern == '!' || **pattern == '^')
+ return NULL;
+ }
+ return hide_refs->v;
+}
+
const char *find_descendant_ref(const char *dirname,
const struct string_list *extras,
const struct string_list *skip)
@@ -1525,7 +1551,9 @@ int head_ref(each_ref_fn fn, void *cb_data)
struct ref_iterator *refs_ref_iterator_begin(
struct ref_store *refs,
- const char *prefix, int trim,
+ const char *prefix,
+ const char **exclude_patterns,
+ int trim,
enum do_for_each_ref_flags flags)
{
struct ref_iterator *iter;
@@ -1541,8 +1569,7 @@ struct ref_iterator *refs_ref_iterator_begin(
}
}
- iter = refs->be->iterator_begin(refs, prefix, flags);
-
+ iter = refs->be->iterator_begin(refs, prefix, exclude_patterns, flags);
/*
* `iterator_begin()` already takes care of prefix, but we
* might need to do some trimming:
@@ -1576,7 +1603,7 @@ static int do_for_each_repo_ref(struct repository *r, const char *prefix,
if (!refs)
return 0;
- iter = refs_ref_iterator_begin(refs, prefix, trim, flags);
+ iter = refs_ref_iterator_begin(refs, prefix, NULL, trim, flags);
return do_for_each_repo_ref_iterator(r, iter, fn, cb_data);
}
@@ -1586,7 +1613,7 @@ struct do_for_each_ref_help {
void *cb_data;
};
-static int do_for_each_ref_helper(struct repository *r,
+static int do_for_each_ref_helper(struct repository *r UNUSED,
const char *refname,
const struct object_id *oid,
int flags,
@@ -1598,6 +1625,7 @@ static int do_for_each_ref_helper(struct repository *r,
}
static int do_for_each_ref(struct ref_store *refs, const char *prefix,
+ const char **exclude_patterns,
each_ref_fn fn, int trim,
enum do_for_each_ref_flags flags, void *cb_data)
{
@@ -1607,7 +1635,8 @@ static int do_for_each_ref(struct ref_store *refs, const char *prefix,
if (!refs)
return 0;
- iter = refs_ref_iterator_begin(refs, prefix, trim, flags);
+ iter = refs_ref_iterator_begin(refs, prefix, exclude_patterns, trim,
+ flags);
return do_for_each_repo_ref_iterator(the_repository, iter,
do_for_each_ref_helper, &hp);
@@ -1615,7 +1644,7 @@ static int do_for_each_ref(struct ref_store *refs, const char *prefix,
int refs_for_each_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
{
- return do_for_each_ref(refs, "", fn, 0, 0, cb_data);
+ return do_for_each_ref(refs, "", NULL, fn, 0, 0, cb_data);
}
int for_each_ref(each_ref_fn fn, void *cb_data)
@@ -1626,7 +1655,7 @@ int for_each_ref(each_ref_fn fn, void *cb_data)
int refs_for_each_ref_in(struct ref_store *refs, const char *prefix,
each_ref_fn fn, void *cb_data)
{
- return do_for_each_ref(refs, prefix, fn, strlen(prefix), 0, cb_data);
+ return do_for_each_ref(refs, prefix, NULL, fn, strlen(prefix), 0, cb_data);
}
int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
@@ -1637,13 +1666,14 @@ int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data)
{
return do_for_each_ref(get_main_ref_store(the_repository),
- prefix, fn, 0, 0, cb_data);
+ prefix, NULL, fn, 0, 0, cb_data);
}
int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
+ const char **exclude_patterns,
each_ref_fn fn, void *cb_data)
{
- return do_for_each_ref(refs, prefix, fn, 0, 0, cb_data);
+ return do_for_each_ref(refs, prefix, exclude_patterns, fn, 0, 0, cb_data);
}
int for_each_replace_ref(struct repository *r, each_repo_ref_fn fn, void *cb_data)
@@ -1654,20 +1684,21 @@ int for_each_replace_ref(struct repository *r, each_repo_ref_fn fn, void *cb_dat
DO_FOR_EACH_INCLUDE_BROKEN, cb_data);
}
-int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)
+int for_each_namespaced_ref(const char **exclude_patterns,
+ each_ref_fn fn, void *cb_data)
{
struct strbuf buf = STRBUF_INIT;
int ret;
strbuf_addf(&buf, "%srefs/", get_git_namespace());
ret = do_for_each_ref(get_main_ref_store(the_repository),
- buf.buf, fn, 0, 0, cb_data);
+ buf.buf, exclude_patterns, fn, 0, 0, cb_data);
strbuf_release(&buf);
return ret;
}
int refs_for_each_rawref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
{
- return do_for_each_ref(refs, "", fn, 0,
+ return do_for_each_ref(refs, "", NULL, fn, 0,
DO_FOR_EACH_INCLUDE_BROKEN, cb_data);
}
@@ -1737,6 +1768,7 @@ static void find_longest_prefixes(struct string_list *out,
int refs_for_each_fullref_in_prefixes(struct ref_store *ref_store,
const char *namespace,
const char **patterns,
+ const char **exclude_patterns,
each_ref_fn fn, void *cb_data)
{
struct string_list prefixes = STRING_LIST_INIT_DUP;
@@ -1752,7 +1784,8 @@ int refs_for_each_fullref_in_prefixes(struct ref_store *ref_store,
for_each_string_list_item(prefix, &prefixes) {
strbuf_addstr(&buf, prefix->string);
- ret = refs_for_each_fullref_in(ref_store, buf.buf, fn, cb_data);
+ ret = refs_for_each_fullref_in(ref_store, buf.buf,
+ exclude_patterns, fn, cb_data);
if (ret)
break;
strbuf_setlen(&buf, namespace_len);
@@ -2132,9 +2165,9 @@ void base_ref_store_init(struct ref_store *refs, struct repository *repo,
}
/* backend functions */
-int refs_pack_refs(struct ref_store *refs, unsigned int flags)
+int refs_pack_refs(struct ref_store *refs, struct pack_refs_opts *opts)
{
- return refs->be->pack_refs(refs, flags);
+ return refs->be->pack_refs(refs, opts);
}
int peel_iterated_oid(const struct object_id *base, struct object_id *peeled)
@@ -2407,7 +2440,7 @@ int refs_verify_refname_available(struct ref_store *refs,
strbuf_addstr(&dirname, refname + dirname.len);
strbuf_addch(&dirname, '/');
- iter = refs_ref_iterator_begin(refs, dirname.buf, 0,
+ iter = refs_ref_iterator_begin(refs, dirname.buf, NULL, 0,
DO_FOR_EACH_INCLUDE_BROKEN);
while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
if (skip &&
diff --git a/refs.h b/refs.h
index 123cfa4424..23211a5ea1 100644
--- a/refs.h
+++ b/refs.h
@@ -63,6 +63,12 @@ struct worktree;
#define RESOLVE_REF_NO_RECURSE 0x02
#define RESOLVE_REF_ALLOW_BAD_NAME 0x04
+struct pack_refs_opts {
+ unsigned int flags;
+ struct ref_exclusions *exclusions;
+ struct string_list *includes;
+};
+
const char *refs_resolve_ref_unsafe(struct ref_store *refs,
const char *refname,
int resolve_flags,
@@ -337,7 +343,12 @@ int for_each_ref(each_ref_fn fn, void *cb_data);
*/
int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data);
+/*
+ * references matching any pattern in "exclude_patterns" are omitted from the
+ * result set on a best-effort basis.
+ */
int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
+ const char **exclude_patterns,
each_ref_fn fn, void *cb_data);
int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data);
@@ -345,10 +356,15 @@ int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data);
* iterate all refs in "patterns" by partitioning patterns into disjoint sets
* and iterating the longest-common prefix of each set.
*
+ * references matching any pattern in "exclude_patterns" are omitted from the
+ * result set on a best-effort basis.
+ *
* callers should be prepared to ignore references that they did not ask for.
*/
int refs_for_each_fullref_in_prefixes(struct ref_store *refs,
- const char *namespace, const char **patterns,
+ const char *namespace,
+ const char **patterns,
+ const char **exclude_patterns,
each_ref_fn fn, void *cb_data);
/**
@@ -366,7 +382,12 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
const char *prefix, void *cb_data);
int head_ref_namespaced(each_ref_fn fn, void *cb_data);
-int for_each_namespaced_ref(each_ref_fn fn, void *cb_data);
+/*
+ * references matching any pattern in "exclude_patterns" are omitted from the
+ * result set on a best-effort basis.
+ */
+int for_each_namespaced_ref(const char **exclude_patterns,
+ each_ref_fn fn, void *cb_data);
/* can be used to learn about broken ref and symref */
int refs_for_each_rawref(struct ref_store *refs, each_ref_fn fn, void *cb_data);
@@ -405,7 +426,7 @@ void warn_dangling_symrefs(FILE *fp, const char *msg_fmt,
* Write a packed-refs file for the current repository.
* flags: Combination of the above PACK_REFS_* flags.
*/
-int refs_pack_refs(struct ref_store *refs, unsigned int flags);
+int refs_pack_refs(struct ref_store *refs, struct pack_refs_opts *opts);
/*
* Setup reflog before using. Fill in err and return -1 on failure.
@@ -804,7 +825,7 @@ int update_ref(const char *msg, const char *refname,
unsigned int flags, enum action_on_err onerr);
int parse_hide_refs_config(const char *var, const char *value, const char *,
- struct string_list *);
+ struct strvec *);
/*
* Check whether a ref is hidden. If no namespace is set, both the first and
@@ -814,7 +835,13 @@ int parse_hide_refs_config(const char *var, const char *value, const char *,
* the ref is outside that namespace, the first parameter is NULL. The second
* parameter always points to the full ref name.
*/
-int ref_is_hidden(const char *, const char *, const struct string_list *);
+int ref_is_hidden(const char *, const char *, const struct strvec *);
+
+/*
+ * Returns an array of patterns to use as excluded_patterns, if none of the
+ * hidden references use the token '!' or '^'.
+ */
+const char **hidden_refs_to_excludes(const struct strvec *hide_refs);
/* Is this a per-worktree ref living in the refs/ namespace? */
int is_per_worktree_ref(const char *refname);
diff --git a/refs/debug.c b/refs/debug.c
index 6f11e6de46..b7ffc4ce67 100644
--- a/refs/debug.c
+++ b/refs/debug.c
@@ -123,10 +123,10 @@ static int debug_initial_transaction_commit(struct ref_store *refs,
return res;
}
-static int debug_pack_refs(struct ref_store *ref_store, unsigned int flags)
+static int debug_pack_refs(struct ref_store *ref_store, struct pack_refs_opts *opts)
{
struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;
- int res = drefs->refs->be->pack_refs(drefs->refs, flags);
+ int res = drefs->refs->be->pack_refs(drefs->refs, opts);
trace_printf_key(&trace_refs, "pack_refs: %d\n", res);
return res;
}
@@ -229,11 +229,12 @@ static struct ref_iterator_vtable debug_ref_iterator_vtable = {
static struct ref_iterator *
debug_ref_iterator_begin(struct ref_store *ref_store, const char *prefix,
- unsigned int flags)
+ const char **exclude_patterns, unsigned int flags)
{
struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;
struct ref_iterator *res =
- drefs->refs->be->iterator_begin(drefs->refs, prefix, flags);
+ drefs->refs->be->iterator_begin(drefs->refs, prefix,
+ exclude_patterns, flags);
struct debug_ref_iterator *diter = xcalloc(1, sizeof(*diter));
base_ref_iterator_init(&diter->base, &debug_ref_iterator_vtable, 1);
diter->iter = res;
diff --git a/refs/files-backend.c b/refs/files-backend.c
index bca7b851c5..341354182b 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1,4 +1,4 @@
-#include "../cache.h"
+#include "../git-compat-util.h"
#include "../config.h"
#include "../copy.h"
#include "../environment.h"
@@ -15,12 +15,15 @@
#include "../lockfile.h"
#include "../object.h"
#include "../object-file.h"
+#include "../path.h"
#include "../dir.h"
#include "../chdir-notify.h"
#include "../setup.h"
#include "../worktree.h"
#include "../wrapper.h"
#include "../write-or-die.h"
+#include "../revision.h"
+#include <wildmatch.h>
/*
* This backend uses the following flags in `ref_update::flags` for
@@ -829,7 +832,8 @@ static struct ref_iterator_vtable files_ref_iterator_vtable = {
static struct ref_iterator *files_ref_iterator_begin(
struct ref_store *ref_store,
- const char *prefix, unsigned int flags)
+ const char *prefix, const char **exclude_patterns,
+ unsigned int flags)
{
struct files_ref_store *refs;
struct ref_iterator *loose_iter, *packed_iter, *overlay_iter;
@@ -874,7 +878,7 @@ static struct ref_iterator *files_ref_iterator_begin(
* the packed and loose references.
*/
packed_iter = refs_ref_iterator_begin(
- refs->packed_ref_store, prefix, 0,
+ refs->packed_ref_store, prefix, exclude_patterns, 0,
DO_FOR_EACH_INCLUDE_BROKEN);
overlay_iter = overlay_ref_iterator_begin(loose_iter, packed_iter);
@@ -1175,17 +1179,15 @@ static void prune_refs(struct files_ref_store *refs, struct ref_to_prune **refs_
*/
static int should_pack_ref(const char *refname,
const struct object_id *oid, unsigned int ref_flags,
- unsigned int pack_flags)
+ struct pack_refs_opts *opts)
{
+ struct string_list_item *item;
+
/* Do not pack per-worktree refs: */
if (parse_worktree_ref(refname, NULL, NULL, NULL) !=
REF_WORKTREE_SHARED)
return 0;
- /* Do not pack non-tags unless PACK_REFS_ALL is set: */
- if (!(pack_flags & PACK_REFS_ALL) && !starts_with(refname, "refs/tags/"))
- return 0;
-
/* Do not pack symbolic refs: */
if (ref_flags & REF_ISSYMREF)
return 0;
@@ -1194,10 +1196,18 @@ static int should_pack_ref(const char *refname,
if (!ref_resolves_to_object(refname, the_repository, oid, ref_flags))
return 0;
- return 1;
+ if (ref_excluded(opts->exclusions, refname))
+ return 0;
+
+ for_each_string_list_item(item, opts->includes)
+ if (!wildmatch(item->string, refname, 0))
+ return 1;
+
+ return 0;
}
-static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
+static int files_pack_refs(struct ref_store *ref_store,
+ struct pack_refs_opts *opts)
{
struct files_ref_store *refs =
files_downcast(ref_store, REF_STORE_WRITE | REF_STORE_ODB,
@@ -1222,8 +1232,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
* in the packed ref cache. If the reference should be
* pruned, also add it to refs_to_prune.
*/
- if (!should_pack_ref(iter->refname, iter->oid, iter->flags,
- flags))
+ if (!should_pack_ref(iter->refname, iter->oid, iter->flags, opts))
continue;
/*
@@ -1237,7 +1246,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
iter->refname, err.buf);
/* Schedule the loose reference for pruning if requested. */
- if ((flags & PACK_REFS_PRUNE)) {
+ if ((opts->flags & PACK_REFS_PRUNE)) {
struct ref_to_prune *n;
FLEX_ALLOC_STR(n, name, iter->refname);
oidcpy(&n->oid, iter->oid);
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index 5b412a133b..59c78d7941 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -1,4 +1,4 @@
-#include "../cache.h"
+#include "../git-compat-util.h"
#include "../alloc.h"
#include "../config.h"
#include "../gettext.h"
@@ -10,8 +10,10 @@
#include "../iterator.h"
#include "../lockfile.h"
#include "../chdir-notify.h"
+#include "../statinfo.h"
#include "../wrapper.h"
#include "../write-or-die.h"
+#include "../trace2.h"
enum mmap_strategy {
/*
@@ -303,7 +305,8 @@ static int cmp_packed_ref_records(const void *v1, const void *v2)
* Compare a snapshot record at `rec` to the specified NUL-terminated
* refname.
*/
-static int cmp_record_to_refname(const char *rec, const char *refname)
+static int cmp_record_to_refname(const char *rec, const char *refname,
+ int start)
{
const char *r1 = rec + the_hash_algo->hexsz + 1;
const char *r2 = refname;
@@ -312,7 +315,7 @@ static int cmp_record_to_refname(const char *rec, const char *refname)
if (*r1 == '\n')
return *r2 ? -1 : 0;
if (!*r2)
- return 1;
+ return start ? 1 : -1;
if (*r1 != *r2)
return (unsigned char)*r1 < (unsigned char)*r2 ? -1 : +1;
r1++;
@@ -527,22 +530,9 @@ static int load_contents(struct snapshot *snapshot)
return 1;
}
-/*
- * Find the place in `snapshot->buf` where the start of the record for
- * `refname` starts. If `mustexist` is true and the reference doesn't
- * exist, then return NULL. If `mustexist` is false and the reference
- * doesn't exist, then return the point where that reference would be
- * inserted, or `snapshot->eof` (which might be NULL) if it would be
- * inserted at the end of the file. In the latter mode, `refname`
- * doesn't have to be a proper reference name; for example, one could
- * search for "refs/replace/" to find the start of any replace
- * references.
- *
- * The record is sought using a binary search, so `snapshot->buf` must
- * be sorted.
- */
-static const char *find_reference_location(struct snapshot *snapshot,
- const char *refname, int mustexist)
+static const char *find_reference_location_1(struct snapshot *snapshot,
+ const char *refname, int mustexist,
+ int start)
{
/*
* This is not *quite* a garden-variety binary search, because
@@ -572,7 +562,7 @@ static const char *find_reference_location(struct snapshot *snapshot,
mid = lo + (hi - lo) / 2;
rec = find_start_of_record(lo, mid);
- cmp = cmp_record_to_refname(rec, refname);
+ cmp = cmp_record_to_refname(rec, refname, start);
if (cmp < 0) {
lo = find_end_of_record(mid, hi);
} else if (cmp > 0) {
@@ -589,6 +579,41 @@ static const char *find_reference_location(struct snapshot *snapshot,
}
/*
+ * Find the place in `snapshot->buf` where the start of the record for
+ * `refname` starts. If `mustexist` is true and the reference doesn't
+ * exist, then return NULL. If `mustexist` is false and the reference
+ * doesn't exist, then return the point where that reference would be
+ * inserted, or `snapshot->eof` (which might be NULL) if it would be
+ * inserted at the end of the file. In the latter mode, `refname`
+ * doesn't have to be a proper reference name; for example, one could
+ * search for "refs/replace/" to find the start of any replace
+ * references.
+ *
+ * The record is sought using a binary search, so `snapshot->buf` must
+ * be sorted.
+ */
+static const char *find_reference_location(struct snapshot *snapshot,
+ const char *refname, int mustexist)
+{
+ return find_reference_location_1(snapshot, refname, mustexist, 1);
+}
+
+/*
+ * Find the place in `snapshot->buf` after the end of the record for
+ * `refname`. In other words, find the location of first thing *after*
+ * `refname`.
+ *
+ * Other semantics are identical to the ones in
+ * `find_reference_location()`.
+ */
+static const char *find_reference_location_end(struct snapshot *snapshot,
+ const char *refname,
+ int mustexist)
+{
+ return find_reference_location_1(snapshot, refname, mustexist, 0);
+}
+
+/*
* Create a newly-allocated `snapshot` of the `packed-refs` file in
* its current state and return it. The return value will already have
* its reference count incremented.
@@ -779,6 +804,13 @@ struct packed_ref_iterator {
/* The end of the part of the buffer that will be iterated over: */
const char *eof;
+ struct jump_list_entry {
+ const char *start;
+ const char *end;
+ } *jump;
+ size_t jump_nr, jump_alloc;
+ size_t jump_cur;
+
/* Scratch space for current values: */
struct object_id oid, peeled;
struct strbuf refname_buf;
@@ -796,14 +828,36 @@ struct packed_ref_iterator {
*/
static int next_record(struct packed_ref_iterator *iter)
{
- const char *p = iter->pos, *eol;
+ const char *p, *eol;
strbuf_reset(&iter->refname_buf);
+ /*
+ * If iter->pos is contained within a skipped region, jump past
+ * it.
+ *
+ * Note that each skipped region is considered at most once,
+ * since they are ordered based on their starting position.
+ */
+ while (iter->jump_cur < iter->jump_nr) {
+ struct jump_list_entry *curr = &iter->jump[iter->jump_cur];
+ if (iter->pos < curr->start)
+ break; /* not to the next jump yet */
+
+ iter->jump_cur++;
+ if (iter->pos < curr->end) {
+ iter->pos = curr->end;
+ trace2_counter_add(TRACE2_COUNTER_ID_PACKED_REFS_JUMPS, 1);
+ /* jumps are coalesced, so only one jump is necessary */
+ break;
+ }
+ }
+
if (iter->pos == iter->eof)
return ITER_DONE;
iter->base.flags = REF_ISPACKED;
+ p = iter->pos;
if (iter->eof - p < the_hash_algo->hexsz + 2 ||
parse_oid_hex(p, &iter->oid, &p) ||
@@ -911,6 +965,7 @@ static int packed_ref_iterator_abort(struct ref_iterator *ref_iterator)
int ok = ITER_DONE;
strbuf_release(&iter->refname_buf);
+ free(iter->jump);
release_snapshot(iter->snapshot);
base_ref_iterator_free(ref_iterator);
return ok;
@@ -922,9 +977,112 @@ static struct ref_iterator_vtable packed_ref_iterator_vtable = {
.abort = packed_ref_iterator_abort
};
+static int jump_list_entry_cmp(const void *va, const void *vb)
+{
+ const struct jump_list_entry *a = va;
+ const struct jump_list_entry *b = vb;
+
+ if (a->start < b->start)
+ return -1;
+ if (a->start > b->start)
+ return 1;
+ return 0;
+}
+
+static int has_glob_special(const char *str)
+{
+ const char *p;
+ for (p = str; *p; p++) {
+ if (is_glob_special(*p))
+ return 1;
+ }
+ return 0;
+}
+
+static void populate_excluded_jump_list(struct packed_ref_iterator *iter,
+ struct snapshot *snapshot,
+ const char **excluded_patterns)
+{
+ size_t i, j;
+ const char **pattern;
+ struct jump_list_entry *last_disjoint;
+
+ if (!excluded_patterns)
+ return;
+
+ for (pattern = excluded_patterns; *pattern; pattern++) {
+ struct jump_list_entry *e;
+ const char *start, *end;
+
+ /*
+ * We can't feed any excludes with globs in them to the
+ * refs machinery. It only understands prefix matching.
+ * We likewise can't even feed the string leading up to
+ * the first meta-character, as something like "foo[a]"
+ * should not exclude "foobar" (but the prefix "foo"
+ * would match that and mark it for exclusion).
+ */
+ if (has_glob_special(*pattern))
+ continue;
+
+ start = find_reference_location(snapshot, *pattern, 0);
+ end = find_reference_location_end(snapshot, *pattern, 0);
+
+ if (start == end)
+ continue; /* nothing to jump over */
+
+ ALLOC_GROW(iter->jump, iter->jump_nr + 1, iter->jump_alloc);
+
+ e = &iter->jump[iter->jump_nr++];
+ e->start = start;
+ e->end = end;
+ }
+
+ if (!iter->jump_nr) {
+ /*
+ * Every entry in exclude_patterns has a meta-character,
+ * nothing to do here.
+ */
+ return;
+ }
+
+ QSORT(iter->jump, iter->jump_nr, jump_list_entry_cmp);
+
+ /*
+ * As an optimization, merge adjacent entries in the jump list
+ * to jump forwards as far as possible when entering a skipped
+ * region.
+ *
+ * For example, if we have two skipped regions:
+ *
+ * [[A, B], [B, C]]
+ *
+ * we want to combine that into a single entry jumping from A to
+ * C.
+ */
+ last_disjoint = iter->jump;
+
+ for (i = 1, j = 1; i < iter->jump_nr; i++) {
+ struct jump_list_entry *ours = &iter->jump[i];
+ if (ours->start <= last_disjoint->end) {
+ /* overlapping regions extend the previous one */
+ last_disjoint->end = last_disjoint->end > ours->end
+ ? last_disjoint->end : ours->end;
+ } else {
+ /* otherwise, insert a new region */
+ iter->jump[j++] = *ours;
+ last_disjoint = ours;
+ }
+ }
+
+ iter->jump_nr = j;
+ iter->jump_cur = 0;
+}
+
static struct ref_iterator *packed_ref_iterator_begin(
struct ref_store *ref_store,
- const char *prefix, unsigned int flags)
+ const char *prefix, const char **exclude_patterns,
+ unsigned int flags)
{
struct packed_ref_store *refs;
struct snapshot *snapshot;
@@ -956,6 +1114,9 @@ static struct ref_iterator *packed_ref_iterator_begin(
ref_iterator = &iter->base;
base_ref_iterator_init(ref_iterator, &packed_ref_iterator_vtable, 1);
+ if (exclude_patterns)
+ populate_excluded_jump_list(iter, snapshot, exclude_patterns);
+
iter->snapshot = snapshot;
acquire_snapshot(snapshot);
@@ -1149,7 +1310,7 @@ static int write_with_updates(struct packed_ref_store *refs,
* list of refs is exhausted, set iter to NULL. When the list
* of updates is exhausted, leave i set to updates->nr.
*/
- iter = packed_ref_iterator_begin(&refs->base, "",
+ iter = packed_ref_iterator_begin(&refs->base, "", NULL,
DO_FOR_EACH_INCLUDE_BROKEN);
if ((ok = ref_iterator_advance(iter)) != ITER_OK)
iter = NULL;
@@ -1577,7 +1738,7 @@ static int packed_delete_refs(struct ref_store *ref_store, const char *msg,
}
static int packed_pack_refs(struct ref_store *ref_store UNUSED,
- unsigned int flags UNUSED)
+ struct pack_refs_opts *pack_opts UNUSED)
{
/*
* Packed refs are already packed. It might be that loose refs
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index a85d113123..9db8aec4da 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -367,8 +367,8 @@ int is_empty_ref_iterator(struct ref_iterator *ref_iterator);
*/
struct ref_iterator *refs_ref_iterator_begin(
struct ref_store *refs,
- const char *prefix, int trim,
- enum do_for_each_ref_flags flags);
+ const char *prefix, const char **exclude_patterns,
+ int trim, enum do_for_each_ref_flags flags);
/*
* A callback function used to instruct merge_ref_iterator how to
@@ -547,7 +547,8 @@ typedef int ref_transaction_commit_fn(struct ref_store *refs,
struct ref_transaction *transaction,
struct strbuf *err);
-typedef int pack_refs_fn(struct ref_store *ref_store, unsigned int flags);
+typedef int pack_refs_fn(struct ref_store *ref_store,
+ struct pack_refs_opts *opts);
typedef int create_symref_fn(struct ref_store *ref_store,
const char *ref_target,
const char *refs_heads_master,
@@ -570,7 +571,8 @@ typedef int copy_ref_fn(struct ref_store *ref_store,
*/
typedef struct ref_iterator *ref_iterator_begin_fn(
struct ref_store *ref_store,
- const char *prefix, unsigned int flags);
+ const char *prefix, const char **exclude_patterns,
+ unsigned int flags);
/* reflog functions */
diff --git a/refspec.c b/refspec.c
index 57f6c2aaf9..d60932f4de 100644
--- a/refspec.c
+++ b/refspec.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "gettext.h"
#include "hash.h"
#include "hex.h"
diff --git a/remote-curl.c b/remote-curl.c
index acf7b2bb40..ef05752ca5 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
@@ -763,7 +762,8 @@ static void check_pktline(struct check_pktline_state *state, const char *ptr, si
size -= digits_remaining;
if (state->len_filled == 4) {
- state->remaining = packet_length(state->len_buf);
+ state->remaining = packet_length(state->len_buf,
+ sizeof(state->len_buf));
if (state->remaining < 0) {
die(_("remote-curl: bad line length character: %.4s"), state->len_buf);
} else if (state->remaining == 2) {
diff --git a/remote.c b/remote.c
index 0764fca0db..abb24822be 100644
--- a/remote.c
+++ b/remote.c
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
@@ -10,7 +9,8 @@
#include "refs.h"
#include "refspec.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "path.h"
#include "commit.h"
#include "diff.h"
#include "revision.h"
@@ -349,7 +349,8 @@ static void read_branches_file(struct remote_state *remote_state,
remote->fetch_tags = 1; /* always auto-follow */
}
-static int handle_config(const char *key, const char *value, void *cb)
+static int handle_config(const char *key, const char *value,
+ const struct config_context *ctx, void *cb)
{
const char *name;
size_t namelen;
@@ -357,6 +358,7 @@ static int handle_config(const char *key, const char *value, void *cb)
struct remote *remote;
struct branch *branch;
struct remote_state *remote_state = cb;
+ const struct key_value_info *kvi = ctx->kvi;
if (parse_config_key(key, "branch", &name, &namelen, &subkey) >= 0) {
/* There is no subsection. */
@@ -414,8 +416,8 @@ static int handle_config(const char *key, const char *value, void *cb)
}
remote = make_remote(remote_state, name, namelen);
remote->origin = REMOTE_CONFIG;
- if (current_config_scope() == CONFIG_SCOPE_LOCAL ||
- current_config_scope() == CONFIG_SCOPE_WORKTREE)
+ if (kvi->scope == CONFIG_SCOPE_LOCAL ||
+ kvi->scope == CONFIG_SCOPE_WORKTREE)
remote->configured_in_repo = 1;
if (!strcmp(subkey, "mirror"))
remote->mirror = git_config_bool(key, value);
@@ -890,7 +892,7 @@ static int query_matches_negative_refspec(struct refspec *rs, struct refspec_ite
{
int i, matched_negative = 0;
int find_src = !query->src;
- struct string_list reversed = STRING_LIST_INIT_NODUP;
+ struct string_list reversed = STRING_LIST_INIT_DUP;
const char *needle = find_src ? query->dst : query->src;
/*
@@ -2257,7 +2259,8 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
* Return true when there is anything to report, otherwise false.
*/
int format_tracking_info(struct branch *branch, struct strbuf *sb,
- enum ahead_behind_flags abf)
+ enum ahead_behind_flags abf,
+ int show_divergence_advice)
{
int ours, theirs, sti;
const char *full_base;
@@ -2320,9 +2323,10 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
"respectively.\n",
ours + theirs),
base, ours, theirs);
- if (advice_enabled(ADVICE_STATUS_HINTS))
+ if (show_divergence_advice &&
+ advice_enabled(ADVICE_STATUS_HINTS))
strbuf_addstr(sb,
- _(" (use \"git pull\" to merge the remote branch into yours)\n"));
+ _(" (use \"git pull\" if you want to integrate the remote branch with yours)\n"));
}
free(base);
return 1;
diff --git a/remote.h b/remote.h
index 73638cefeb..cdc8b1db42 100644
--- a/remote.h
+++ b/remote.h
@@ -1,6 +1,7 @@
#ifndef REMOTE_H
#define REMOTE_H
+#include "hash-ll.h"
#include "hashmap.h"
#include "refspec.h"
@@ -379,7 +380,8 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
const char **upstream_name, int for_push,
enum ahead_behind_flags abf);
int format_tracking_info(struct branch *branch, struct strbuf *sb,
- enum ahead_behind_flags abf);
+ enum ahead_behind_flags abf,
+ int show_divergence_advice);
struct ref *get_local_heads(void);
/*
diff --git a/replace-object.c b/replace-object.c
index e98825d585..523215589d 100644
--- a/replace-object.c
+++ b/replace-object.c
@@ -2,7 +2,7 @@
#include "gettext.h"
#include "hex.h"
#include "oidmap.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "replace-object.h"
#include "refs.h"
#include "repository.h"
@@ -64,7 +64,7 @@ void prepare_replace_object(struct repository *r)
* replacement object's name (replaced recursively, if necessary).
* The return value is either oid or a pointer to a
* permanently-allocated value. This function always respects replace
- * references, regardless of the value of read_replace_refs.
+ * references, regardless of the value of r->settings.read_replace_refs.
*/
const struct object_id *do_lookup_replace_object(struct repository *r,
const struct object_id *oid)
@@ -84,3 +84,29 @@ const struct object_id *do_lookup_replace_object(struct repository *r,
}
die(_("replace depth too high for object %s"), oid_to_hex(oid));
}
+
+/*
+ * This indicator determines whether replace references should be
+ * respected process-wide, regardless of which repository is being
+ * using at the time.
+ */
+static int read_replace_refs = 1;
+
+void disable_replace_refs(void)
+{
+ read_replace_refs = 0;
+}
+
+int replace_refs_enabled(struct repository *r)
+{
+ if (!read_replace_refs)
+ return 0;
+
+ if (r->gitdir) {
+ prepare_repo_settings(r);
+ return r->settings.read_replace_refs;
+ }
+
+ /* repository has no objects or refs. */
+ return 0;
+}
diff --git a/replace-object.h b/replace-object.h
index 500482b02b..66c41b938b 100644
--- a/replace-object.h
+++ b/replace-object.h
@@ -3,15 +3,7 @@
#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;
+#include "object-store-ll.h"
struct replace_object {
struct oidmap_entry original;
@@ -28,6 +20,18 @@ const struct object_id *do_lookup_replace_object(struct repository *r,
const struct object_id *oid);
/*
+ * Some commands disable replace-refs unconditionally, and otherwise each
+ * repository could alter the core.useReplaceRefs config value.
+ *
+ * Return 1 if and only if all of the following are true:
+ *
+ * a. disable_replace_refs() has not been called.
+ * b. GIT_NO_REPLACE_OBJECTS is unset or zero.
+ * c. the given repository does not have core.useReplaceRefs=false.
+ */
+int replace_refs_enabled(struct repository *r);
+
+/*
* If object sha1 should be replaced, return the replacement object's
* name (replaced recursively, if necessary). The return value is
* either sha1 or a pointer to a permanently-allocated value. When
@@ -41,11 +45,19 @@ const struct object_id *do_lookup_replace_object(struct repository *r,
static inline const struct object_id *lookup_replace_object(struct repository *r,
const struct object_id *oid)
{
- if (!read_replace_refs ||
+ if (!replace_refs_enabled(r) ||
(r->objects->replace_map_initialized &&
r->objects->replace_map->map.tablesize == 0))
return oid;
return do_lookup_replace_object(r, oid);
}
+/*
+ * Some commands override config and environment settings for using
+ * replace references. Use this method to disable the setting and ensure
+ * those other settings will not override this choice. This applies
+ * globally to all in-process repositories.
+ */
+void disable_replace_refs(void);
+
#endif /* REPLACE_OBJECT_H */
diff --git a/repo-settings.c b/repo-settings.c
index d220c5dd9f..525f69c0c7 100644
--- a/repo-settings.c
+++ b/repo-settings.c
@@ -41,8 +41,10 @@ void prepare_repo_settings(struct repository *r)
repo_cfg_bool(r, "feature.experimental", &experimental, 0);
/* Defaults modified by feature.* */
- if (experimental)
+ if (experimental) {
r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
+ r->settings.pack_use_bitmap_boundary_traversal = 1;
+ }
if (manyfiles) {
r->settings.index_version = 4;
r->settings.index_skip_hash = 1;
@@ -62,6 +64,10 @@ void prepare_repo_settings(struct repository *r)
repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0);
repo_cfg_bool(r, "index.skiphash", &r->settings.index_skip_hash, r->settings.index_skip_hash);
repo_cfg_bool(r, "pack.readreverseindex", &r->settings.pack_read_reverse_index, 1);
+ repo_cfg_bool(r, "pack.usebitmapboundarytraversal",
+ &r->settings.pack_use_bitmap_boundary_traversal,
+ r->settings.pack_use_bitmap_boundary_traversal);
+ repo_cfg_bool(r, "core.usereplacerefs", &r->settings.read_replace_refs, 1);
/*
* The GIT_TEST_MULTI_PACK_INDEX variable is special in that
diff --git a/repository.c b/repository.c
index c53e480e32..a7679ceeaa 100644
--- a/repository.c
+++ b/repository.c
@@ -3,13 +3,15 @@
* declaration matches the definition in this file.
*/
#define USE_THE_INDEX_VARIABLE
-#include "cache.h"
+#include "git-compat-util.h"
#include "abspath.h"
#include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "config.h"
#include "object.h"
#include "lockfile.h"
+#include "path.h"
+#include "read-cache-ll.h"
#include "remote.h"
#include "setup.h"
#include "submodule-config.h"
@@ -182,6 +184,7 @@ int repo_init(struct repository *repo,
goto error;
repo_set_hash_algo(repo, format.hash_algo);
+ repo->repository_format_worktree_config = format.worktree_config;
/* take ownership of format.partial_clone */
repo->repository_format_partial_clone = format.partial_clone;
diff --git a/repository.h b/repository.h
index 1a13ff2867..5f18486f64 100644
--- a/repository.h
+++ b/repository.h
@@ -1,8 +1,6 @@
#ifndef REPOSITORY_H
#define REPOSITORY_H
-#include "path.h"
-
struct config_set;
struct fsmonitor_settings;
struct git_hash_algo;
@@ -37,6 +35,16 @@ struct repo_settings {
int command_requires_full_index;
int sparse_index;
int pack_read_reverse_index;
+ int pack_use_bitmap_boundary_traversal;
+
+ /*
+ * Does this repository have core.useReplaceRefs=true (on by
+ * default)? This provides a repository-scoped version of this
+ * config, though it could be disabled process-wide via some Git
+ * builtins or the --no-replace-objects option. See
+ * replace_refs_enabled() for more details.
+ */
+ int read_replace_refs;
struct fsmonitor_settings *fsmonitor; /* lazily loaded */
@@ -163,12 +171,16 @@ struct repository {
struct promisor_remote_config *promisor_remote_config;
/* Configurations */
+ int repository_format_worktree_config;
/* Indicate if a repository has a different 'commondir' from 'gitdir' */
unsigned different_commondir:1;
};
extern struct repository *the_repository;
+#ifdef USE_THE_INDEX_VARIABLE
+extern struct index_state the_index;
+#endif
/*
* Define a custom repository layout. Any field can be NULL, which
@@ -220,9 +232,6 @@ int repo_hold_locked_index(struct repository *repo,
struct lock_file *lf,
int flags);
-int repo_read_index_preload(struct repository *,
- const struct pathspec *pathspec,
- unsigned refresh_flags);
int repo_read_index_unmerged(struct repository *);
/*
* Opportunistically update the index but do not complain if we can't.
diff --git a/rerere.c b/rerere.c
index e968d413d6..725c1b6a95 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1,24 +1,24 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "copy.h"
#include "gettext.h"
#include "hex.h"
#include "lockfile.h"
#include "string-list.h"
+#include "read-cache-ll.h"
#include "rerere.h"
#include "xdiff-interface.h"
#include "dir.h"
#include "resolve-undo.h"
-#include "ll-merge.h"
+#include "merge-ll.h"
#include "attr.h"
+#include "path.h"
#include "pathspec.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "hash-lookup.h"
#include "strmap.h"
-#include "wrapper.h"
#define RESOLVED 0
#define PUNTED 1
@@ -204,7 +204,7 @@ static void read_rr(struct repository *r, struct string_list *rr)
const unsigned hexsz = the_hash_algo->hexsz;
/* There has to be the hash, tab, path and then NUL */
- if (buf.len < hexsz + 2 || get_sha1_hex(buf.buf, hash))
+ if (buf.len < hexsz + 2 || get_hash_hex(buf.buf, hash))
die(_("corrupt MERGE_RR"));
if (buf.buf[hexsz] != '.') {
diff --git a/resolve-undo.c b/resolve-undo.c
index 70a6db526d..7817f5d6db 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -1,7 +1,9 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "dir.h"
#include "hash.h"
+#include "read-cache.h"
#include "resolve-undo.h"
+#include "sparse-index.h"
#include "string-list.h"
/* The only error case is to run out of memory in string-list */
diff --git a/revision.c b/revision.c
index b33cc1d106..2f4c53ea20 100644
--- a/revision.c
+++ b/revision.c
@@ -1,12 +1,11 @@
-#include "cache.h"
-#include "alloc.h"
+#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
#include "object-name.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "tag.h"
#include "blob.h"
#include "tree.h"
@@ -31,7 +30,9 @@
#include "bisect.h"
#include "packfile.h"
#include "worktree.h"
+#include "read-cache.h"
#include "setup.h"
+#include "sparse-index.h"
#include "strvec.h"
#include "trace2.h"
#include "commit-reach.h"
@@ -44,6 +45,7 @@
#include "list-objects-filter-options.h"
#include "resolve-undo.h"
#include "parse-options.h"
+#include "wildmatch.h"
volatile show_early_output_fn_t show_early_output;
@@ -1558,7 +1560,7 @@ void init_ref_exclusions(struct ref_exclusions *exclusions)
void clear_ref_exclusions(struct ref_exclusions *exclusions)
{
string_list_clear(&exclusions->excluded_refs, 0);
- string_list_clear(&exclusions->hidden_refs, 0);
+ strvec_clear(&exclusions->hidden_refs);
exclusions->hidden_refs_configured = 0;
}
@@ -1572,7 +1574,9 @@ struct exclude_hidden_refs_cb {
const char *section;
};
-static int hide_refs_config(const char *var, const char *value, void *cb_data)
+static int hide_refs_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb_data)
{
struct exclude_hidden_refs_cb *cb = cb_data;
cb->exclusions->hidden_refs_configured = 1;
@@ -2195,39 +2199,6 @@ static void read_pathspec_from_stdin(struct strbuf *sb,
strvec_push(prune, sb->buf);
}
-static void read_revisions_from_stdin(struct rev_info *revs,
- struct strvec *prune)
-{
- struct strbuf sb;
- int seen_dashdash = 0;
- int save_warning;
-
- save_warning = warn_on_object_refname_ambiguity;
- warn_on_object_refname_ambiguity = 0;
-
- strbuf_init(&sb, 1000);
- while (strbuf_getline(&sb, stdin) != EOF) {
- int len = sb.len;
- if (!len)
- break;
- if (sb.buf[0] == '-') {
- if (len == 2 && sb.buf[1] == '-') {
- seen_dashdash = 1;
- break;
- }
- die("options not supported in --stdin mode");
- }
- if (handle_revision_arg(sb.buf, revs, 0,
- REVARG_CANNOT_BE_FILENAME))
- die("bad revision '%s'", sb.buf);
- }
- if (seen_dashdash)
- read_pathspec_from_stdin(&sb, prune);
-
- strbuf_release(&sb);
- warn_on_object_refname_ambiguity = save_warning;
-}
-
static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token what)
{
append_grep_pattern(&revs->grep_filter, ptn, "command line", 0, what);
@@ -2670,7 +2641,7 @@ static int for_each_bisect_ref(struct ref_store *refs, each_ref_fn fn,
struct strbuf bisect_refs = STRBUF_INIT;
int status;
strbuf_addf(&bisect_refs, "refs/bisect/%s", term);
- status = refs_for_each_fullref_in(refs, bisect_refs.buf, fn, cb_data);
+ status = refs_for_each_fullref_in(refs, bisect_refs.buf, NULL, fn, cb_data);
strbuf_release(&bisect_refs);
return status;
}
@@ -2816,6 +2787,53 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
return 1;
}
+static void read_revisions_from_stdin(struct rev_info *revs,
+ struct strvec *prune,
+ int *flags)
+{
+ struct strbuf sb;
+ int seen_dashdash = 0;
+ int seen_end_of_options = 0;
+ int save_warning;
+
+ save_warning = warn_on_object_refname_ambiguity;
+ warn_on_object_refname_ambiguity = 0;
+
+ strbuf_init(&sb, 1000);
+ while (strbuf_getline(&sb, stdin) != EOF) {
+ if (!sb.len)
+ break;
+
+ if (!strcmp(sb.buf, "--")) {
+ seen_dashdash = 1;
+ break;
+ }
+
+ if (!seen_end_of_options && sb.buf[0] == '-') {
+ const char *argv[] = { sb.buf, NULL };
+
+ if (!strcmp(sb.buf, "--end-of-options")) {
+ seen_end_of_options = 1;
+ continue;
+ }
+
+ if (handle_revision_pseudo_opt(revs, argv, flags) > 0)
+ continue;
+
+ die(_("invalid option '%s' in --stdin mode"), sb.buf);
+ }
+
+ if (handle_revision_arg(sb.buf, revs, 0,
+ REVARG_CANNOT_BE_FILENAME))
+ die("bad revision '%s'", sb.buf);
+ }
+ if (seen_dashdash)
+ read_pathspec_from_stdin(&sb, prune);
+
+ strbuf_release(&sb);
+ warn_on_object_refname_ambiguity = save_warning;
+}
+
static void NORETURN diagnose_missing_default(const char *def)
{
int flags;
@@ -2888,7 +2906,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
}
if (revs->read_from_stdin++)
die("--stdin given twice?");
- read_revisions_from_stdin(revs, &prune_data);
+ read_revisions_from_stdin(revs, &prune_data, &flags);
continue;
}
@@ -2952,7 +2970,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
if (!revs->def)
revs->def = opt ? opt->def : NULL;
if (opt && opt->tweak)
- opt->tweak(revs, opt);
+ opt->tweak(revs);
if (revs->show_merge)
prepare_show_merge(revs);
if (revs->def && !revs->pending.nr && !revs->rev_input_given) {
diff --git a/revision.h b/revision.h
index 31828748dc..82ab400139 100644
--- a/revision.h
+++ b/revision.h
@@ -10,6 +10,7 @@
#include "decorate.h"
#include "ident.h"
#include "list-objects-filter-options.h"
+#include "strvec.h"
/**
* The revision walking API offers functions to build a list of revisions
@@ -87,7 +88,7 @@ struct rev_cmdline_info {
struct ref_exclusions {
/*
* Excluded refs is a list of wildmatch patterns. If any of the
- * patterns matches, the reference will be excluded.
+ * patterns match, the reference will be excluded.
*/
struct string_list excluded_refs;
@@ -95,7 +96,7 @@ struct ref_exclusions {
* Hidden refs is a list of patterns that is to be hidden via
* `ref_is_hidden()`.
*/
- struct string_list hidden_refs;
+ struct strvec hidden_refs;
/*
* Indicates whether hidden refs have been configured. This is to
@@ -110,7 +111,7 @@ struct ref_exclusions {
*/
#define REF_EXCLUSIONS_INIT { \
.excluded_refs = STRING_LIST_INIT_DUP, \
- .hidden_refs = STRING_LIST_INIT_DUP, \
+ .hidden_refs = STRVEC_INIT, \
}
struct oidset;
@@ -428,7 +429,7 @@ void repo_init_revisions(struct repository *r,
*/
struct setup_revision_opt {
const char *def;
- void (*tweak)(struct rev_info *, struct setup_revision_opt *);
+ void (*tweak)(struct rev_info *);
unsigned int assume_dashdash:1,
allow_exclude_promisor_objects:1,
free_removed_argv_elements:1;
diff --git a/run-command.c b/run-command.c
index 60c9419866..a558042c87 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "run-command.h"
#include "environment.h"
#include "exec-cmd.h"
@@ -170,6 +170,7 @@ int is_executable(const char *name)
return st.st_mode & S_IXUSR;
}
+#ifndef locate_in_PATH
/*
* Search $PATH for a command. This emulates the path search that
* execvp would perform, without actually executing the command so it
@@ -218,6 +219,7 @@ static char *locate_in_PATH(const char *file)
strbuf_release(&buf);
return NULL;
}
+#endif
int exists_in_PATH(const char *command)
{
@@ -307,7 +309,6 @@ enum child_errcode {
CHILD_ERR_DUP2,
CHILD_ERR_CLOSE,
CHILD_ERR_SIGPROCMASK,
- CHILD_ERR_ENOENT,
CHILD_ERR_SILENT,
CHILD_ERR_ERRNO
};
@@ -390,9 +391,6 @@ static void child_err_spew(struct child_process *cmd, struct child_err *cerr)
case CHILD_ERR_SIGPROCMASK:
error_errno("sigprocmask failed restoring signals");
break;
- case CHILD_ERR_ENOENT:
- error_errno("cannot run %s", cmd->args.v[0]);
- break;
case CHILD_ERR_SILENT:
break;
case CHILD_ERR_ERRNO:
@@ -846,13 +844,9 @@ fail_pipe:
execve(argv.v[0], (char *const *) argv.v,
(char *const *) childenv);
- if (errno == ENOENT) {
- if (cmd->silent_exec_failure)
- child_die(CHILD_ERR_SILENT);
- child_die(CHILD_ERR_ENOENT);
- } else {
- child_die(CHILD_ERR_ERRNO);
- }
+ if (cmd->silent_exec_failure && errno == ENOENT)
+ child_die(CHILD_ERR_SILENT);
+ child_die(CHILD_ERR_ERRNO);
}
atfork_parent(&as);
if (cmd->pid < 0)
diff --git a/run-command.h b/run-command.h
index 072db56a4d..1f22cc3827 100644
--- a/run-command.h
+++ b/run-command.h
@@ -503,7 +503,7 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts);
* exception of GIT_CONFIG_PARAMETERS and GIT_CONFIG_COUNT (which cause the
* corresponding environment variables to be unset in the subprocess) and adds
* an environment variable pointing to new_git_dir. See local_repo_env in
- * cache.h for more information.
+ * environment.h for more information.
*/
void prepare_other_repo_env(struct strvec *env, const char *new_git_dir);
@@ -564,4 +564,6 @@ enum start_bg_result start_bg_command(struct child_process *cmd,
void *cb_data,
unsigned int timeout_sec);
+int sane_execvp(const char *file, char *const argv[]);
+
#endif
diff --git a/sane-ctype.h b/sane-ctype.h
new file mode 100644
index 0000000000..cbea1b299b
--- /dev/null
+++ b/sane-ctype.h
@@ -0,0 +1,66 @@
+#ifndef SANE_CTYPE_H
+#define SANE_CTYPE_H
+
+/* Sane ctype - no locale, and works with signed chars */
+#undef isascii
+#undef isspace
+#undef isdigit
+#undef isalpha
+#undef isalnum
+#undef isprint
+#undef islower
+#undef isupper
+#undef tolower
+#undef toupper
+#undef iscntrl
+#undef ispunct
+#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
+#define GIT_GLOB_SPECIAL 0x08
+#define GIT_REGEX_SPECIAL 0x10
+#define GIT_PATHSPEC_MAGIC 0x20
+#define GIT_CNTRL 0x40
+#define GIT_PUNCT 0x80
+#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
+#define isascii(x) (((x) & ~0x7f) == 0)
+#define isspace(x) sane_istest(x,GIT_SPACE)
+#define isdigit(x) sane_istest(x,GIT_DIGIT)
+#define isalpha(x) sane_istest(x,GIT_ALPHA)
+#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
+#define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)
+#define islower(x) sane_iscase(x, 1)
+#define isupper(x) sane_iscase(x, 0)
+#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)
+#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)
+#define iscntrl(x) (sane_istest(x,GIT_CNTRL))
+#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \
+ GIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)
+#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)
+#define tolower(x) sane_case((unsigned char)(x), 0x20)
+#define toupper(x) sane_case((unsigned char)(x), 0)
+#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)
+
+static inline int sane_case(int x, int high)
+{
+ if (sane_istest(x, GIT_ALPHA))
+ x = (x & ~0x20) | high;
+ return x;
+}
+
+static inline int sane_iscase(int x, int is_lower)
+{
+ if (!sane_istest(x, GIT_ALPHA))
+ return 0;
+
+ if (is_lower)
+ return (x & 0x20) != 0;
+ else
+ return (x & 0x20) == 0;
+}
+
+#endif
diff --git a/scalar.c b/scalar.c
index 1326e1f608..df7358f481 100644
--- a/scalar.c
+++ b/scalar.c
@@ -594,7 +594,9 @@ static int cmd_register(int argc, const char **argv)
return register_dir();
}
-static int get_scalar_repos(const char *key, const char *value, void *data)
+static int get_scalar_repos(const char *key, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *data)
{
struct string_list *list = data;
diff --git a/send-pack.c b/send-pack.c
index 0c7ccaef68..89aca9d829 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -5,7 +5,7 @@
#include "gettext.h"
#include "hex.h"
#include "refs.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "pkt-line.h"
#include "sideband.h"
#include "run-command.h"
@@ -15,7 +15,6 @@
#include "quote.h"
#include "transport.h"
#include "version.h"
-#include "wrapper.h"
#include "oid-array.h"
#include "gpg-interface.h"
#include "shallow.h"
diff --git a/sequencer.c b/sequencer.c
index af271ab6fb..5e0c15a16b 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,7 +1,6 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"
-#include "alloc.h"
#include "config.h"
#include "copy.h"
#include "environment.h"
@@ -11,7 +10,7 @@
#include "dir.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "object.h"
#include "pager.h"
#include "commit.h"
@@ -23,11 +22,14 @@
#include "utf8.h"
#include "cache-tree.h"
#include "diff.h"
+#include "path.h"
#include "revision.h"
#include "rerere.h"
+#include "merge.h"
#include "merge-ort.h"
#include "merge-ort-wrappers.h"
#include "refs.h"
+#include "sparse-index.h"
#include "strvec.h"
#include "quote.h"
#include "trailer.h"
@@ -46,7 +48,6 @@
#include "rebase-interactive.h"
#include "reset.h"
#include "branch.h"
-#include "wrapper.h"
#define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
@@ -219,7 +220,8 @@ static struct update_ref_record *init_update_ref_record(const char *ref)
return rec;
}
-static int git_sequencer_config(const char *k, const char *v, void *cb)
+static int git_sequencer_config(const char *k, const char *v,
+ const struct config_context *ctx, void *cb)
{
struct replay_opts *opts = cb;
int status;
@@ -274,7 +276,7 @@ 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);
- return git_diff_basic_config(k, v, NULL);
+ return git_diff_basic_config(k, v, ctx, NULL);
}
void sequencer_init_config(struct replay_opts *opts)
@@ -660,11 +662,12 @@ void append_conflicts_hint(struct index_state *istate,
}
strbuf_addch(msgbuf, '\n');
- strbuf_commented_addf(msgbuf, "Conflicts:\n");
+ strbuf_commented_addf(msgbuf, comment_line_char, "Conflicts:\n");
for (i = 0; i < istate->cache_nr;) {
const struct cache_entry *ce = istate->cache[i++];
if (ce_stage(ce)) {
- strbuf_commented_addf(msgbuf, "\t%s\n", ce->name);
+ strbuf_commented_addf(msgbuf, comment_line_char,
+ "\t%s\n", ce->name);
while (i < istate->cache_nr &&
!strcmp(ce->name, istate->cache[i]->name))
i++;
@@ -1143,7 +1146,8 @@ void cleanup_message(struct strbuf *msgbuf,
cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS)
strbuf_setlen(msgbuf, wt_status_locate_end(msgbuf->buf, msgbuf->len));
if (cleanup_mode != COMMIT_MSG_CLEANUP_NONE)
- strbuf_stripspace(msgbuf, cleanup_mode == COMMIT_MSG_CLEANUP_ALL);
+ strbuf_stripspace(msgbuf,
+ cleanup_mode == COMMIT_MSG_CLEANUP_ALL ? comment_line_char : '\0');
}
/*
@@ -1174,7 +1178,8 @@ int template_untouched(const struct strbuf *sb, const char *template_file,
if (!template_file || strbuf_read_file(&tmpl, template_file, 0) <= 0)
return 0;
- strbuf_stripspace(&tmpl, cleanup_mode == COMMIT_MSG_CLEANUP_ALL);
+ strbuf_stripspace(&tmpl,
+ cleanup_mode == COMMIT_MSG_CLEANUP_ALL ? comment_line_char : '\0');
if (!skip_prefix(sb->buf, tmpl.buf, &start))
start = sb->buf;
strbuf_release(&tmpl);
@@ -1546,7 +1551,8 @@ static int try_to_commit(struct repository *r,
cleanup = opts->default_msg_cleanup;
if (cleanup != COMMIT_MSG_CLEANUP_NONE)
- strbuf_stripspace(msg, cleanup == COMMIT_MSG_CLEANUP_ALL);
+ strbuf_stripspace(msg,
+ cleanup == COMMIT_MSG_CLEANUP_ALL ? comment_line_char : '\0');
if ((flags & EDIT_MSG) && message_is_empty(msg, cleanup)) {
res = 1; /* run 'git commit' to display error message */
goto out;
@@ -1840,7 +1846,7 @@ static void add_commented_lines(struct strbuf *buf, const void *str, size_t len)
s += count;
len -= count;
}
- strbuf_add_commented_lines(buf, s, len);
+ strbuf_add_commented_lines(buf, s, len, comment_line_char);
}
/* Does the current fixup chain contain a squash command? */
@@ -1939,7 +1945,7 @@ static int append_squash_message(struct strbuf *buf, const char *body,
strbuf_addf(buf, _(nth_commit_msg_fmt),
++opts->current_fixup_count + 1);
strbuf_addstr(buf, "\n\n");
- strbuf_add_commented_lines(buf, body, commented_len);
+ strbuf_add_commented_lines(buf, body, commented_len, comment_line_char);
/* buf->buf may be reallocated so store an offset into the buffer */
fixup_off = buf->len;
strbuf_addstr(buf, body + commented_len);
@@ -2029,7 +2035,8 @@ static int update_squash_messages(struct repository *r,
_(first_commit_msg_str));
strbuf_addstr(&buf, "\n\n");
if (is_fixup_flag(command, flag))
- strbuf_add_commented_lines(&buf, body, strlen(body));
+ strbuf_add_commented_lines(&buf, body, strlen(body),
+ comment_line_char);
else
strbuf_addstr(&buf, body);
@@ -2048,7 +2055,8 @@ static int update_squash_messages(struct repository *r,
strbuf_addf(&buf, _(skip_nth_commit_msg_fmt),
++opts->current_fixup_count + 1);
strbuf_addstr(&buf, "\n\n");
- strbuf_add_commented_lines(&buf, body, strlen(body));
+ strbuf_add_commented_lines(&buf, body, strlen(body),
+ comment_line_char);
} else
return error(_("unknown command: %d"), command);
repo_unuse_commit_buffer(r, commit, message);
@@ -2694,7 +2702,7 @@ int todo_list_parse_insn_buffer(struct repository *r, char *buf,
if (fixup_okay)
; /* do nothing */
else if (is_fixup(item->command))
- return error(_("cannot '%s' without a previous commit"),
+ res = error(_("cannot '%s' without a previous commit"),
command_to_string(item->command));
else if (!is_noop(item->command))
fixup_okay = 1;
@@ -2881,7 +2889,9 @@ static int git_config_string_dup(char **dest,
return 0;
}
-static int populate_opts_cb(const char *key, const char *value, void *data)
+static int populate_opts_cb(const char *key, const char *value,
+ const struct config_context *ctx,
+ void *data)
{
struct replay_opts *opts = data;
int error_flag = 1;
@@ -2889,26 +2899,26 @@ static int populate_opts_cb(const char *key, const char *value, void *data)
if (!value)
error_flag = 0;
else if (!strcmp(key, "options.no-commit"))
- opts->no_commit = git_config_bool_or_int(key, value, &error_flag);
+ opts->no_commit = git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
else if (!strcmp(key, "options.edit"))
- opts->edit = git_config_bool_or_int(key, value, &error_flag);
+ opts->edit = git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
else if (!strcmp(key, "options.allow-empty"))
opts->allow_empty =
- git_config_bool_or_int(key, value, &error_flag);
+ git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
else if (!strcmp(key, "options.allow-empty-message"))
opts->allow_empty_message =
- git_config_bool_or_int(key, value, &error_flag);
+ git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
else if (!strcmp(key, "options.keep-redundant-commits"))
opts->keep_redundant_commits =
- git_config_bool_or_int(key, value, &error_flag);
+ git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
else if (!strcmp(key, "options.signoff"))
- opts->signoff = git_config_bool_or_int(key, value, &error_flag);
+ opts->signoff = git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
else if (!strcmp(key, "options.record-origin"))
- opts->record_origin = git_config_bool_or_int(key, value, &error_flag);
+ opts->record_origin = git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
else if (!strcmp(key, "options.allow-ff"))
- opts->allow_ff = git_config_bool_or_int(key, value, &error_flag);
+ opts->allow_ff = git_config_bool_or_int(key, value, ctx->kvi, &error_flag);
else if (!strcmp(key, "options.mainline"))
- opts->mainline = git_config_int(key, value);
+ opts->mainline = git_config_int(key, value, ctx->kvi);
else if (!strcmp(key, "options.strategy"))
git_config_string_dup(&opts->strategy, key, value);
else if (!strcmp(key, "options.gpg-sign"))
@@ -2917,7 +2927,7 @@ static int populate_opts_cb(const char *key, const char *value, void *data)
strvec_push(&opts->xopts, value);
} else if (!strcmp(key, "options.allow-rerere-auto"))
opts->allow_rerere_auto =
- git_config_bool_or_int(key, value, &error_flag) ?
+ git_config_bool_or_int(key, value, ctx->kvi, &error_flag) ?
RERERE_AUTOUPDATE : RERERE_NOAUTOUPDATE;
else if (!strcmp(key, "options.default-msg-cleanup")) {
opts->explicit_cleanup = 1;
diff --git a/serve.c b/serve.c
index 5329c91011..a1d71134d4 100644
--- a/serve.c
+++ b/serve.c
@@ -1,6 +1,7 @@
#include "git-compat-util.h"
#include "repository.h"
#include "config.h"
+#include "hash-ll.h"
#include "pkt-line.h"
#include "version.h"
#include "ls-refs.h"
diff --git a/server-info.c b/server-info.c
index 55aa04f00a..e2fe0f9143 100644
--- a/server-info.c
+++ b/server-info.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "dir.h"
#include "environment.h"
#include "hex.h"
@@ -9,11 +8,11 @@
#include "commit.h"
#include "tag.h"
#include "packfile.h"
+#include "path.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "server-info.h"
#include "strbuf.h"
-#include "wrapper.h"
struct update_info_ctx {
FILE *cur_fp;
diff --git a/setup.c b/setup.c
index 458582207e..18927a847b 100644
--- a/setup.c
+++ b/setup.c
@@ -1,18 +1,22 @@
#include "git-compat-util.h"
#include "abspath.h"
+#include "copy.h"
#include "environment.h"
+#include "exec-cmd.h"
#include "gettext.h"
#include "object-name.h"
+#include "refs.h"
#include "repository.h"
#include "config.h"
#include "dir.h"
#include "setup.h"
#include "string-list.h"
#include "chdir-notify.h"
+#include "path.h"
#include "promisor-remote.h"
#include "quote.h"
#include "trace2.h"
-#include "wrapper.h"
+#include "worktree.h"
static int inside_git_dir = -1;
static int inside_work_tree = -1;
@@ -517,7 +521,9 @@ no_prevention_needed:
startup_info->original_cwd = NULL;
}
-static int read_worktree_config(const char *var, const char *value, void *vdata)
+static int read_worktree_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *vdata)
{
struct repository_format *data = vdata;
@@ -588,13 +594,14 @@ static enum extension_result handle_extension(const char *var,
return EXTENSION_UNKNOWN;
}
-static int check_repo_format(const char *var, const char *value, void *vdata)
+static int check_repo_format(const char *var, const char *value,
+ const struct config_context *ctx, void *vdata)
{
struct repository_format *data = vdata;
const char *ext;
if (strcmp(var, "core.repositoryformatversion") == 0)
- data->version = git_config_int(var, value);
+ data->version = git_config_int(var, value, ctx->kvi);
else if (skip_prefix(var, "extensions.", &ext)) {
switch (handle_extension_v0(var, value, ext, data)) {
case EXTENSION_ERROR:
@@ -617,7 +624,7 @@ static int check_repo_format(const char *var, const char *value, void *vdata)
}
}
- return read_worktree_config(var, value, vdata);
+ return read_worktree_config(var, value, ctx, vdata);
}
static int check_repository_format_gently(const char *gitdir, struct repository_format *candidate, int *nongit_ok)
@@ -650,11 +657,10 @@ static int check_repository_format_gently(const char *gitdir, struct repository_
}
repository_format_precious_objects = candidate->precious_objects;
- repository_format_worktree_config = candidate->worktree_config;
string_list_clear(&candidate->unknown_extensions, 0);
string_list_clear(&candidate->v1_only_extensions, 0);
- if (repository_format_worktree_config) {
+ if (candidate->worktree_config) {
/*
* pick up core.bare and core.worktree from per-worktree
* config if present
@@ -1116,7 +1122,8 @@ struct safe_directory_data {
int is_safe;
};
-static int safe_directory_cb(const char *key, const char *value, void *d)
+static int safe_directory_cb(const char *key, const char *value,
+ const struct config_context *ctx UNUSED, void *d)
{
struct safe_directory_data *data = d;
@@ -1172,7 +1179,9 @@ static int ensure_valid_ownership(const char *gitfile,
return data.is_safe;
}
-static int allowed_bare_repo_cb(const char *key, const char *value, void *d)
+static int allowed_bare_repo_cb(const char *key, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *d)
{
enum allowed_bare_repo *allowed_bare_repo = d;
@@ -1423,11 +1432,6 @@ int discover_git_directory(struct strbuf *commondir,
return -1;
}
- /* take ownership of candidate.partial_clone */
- the_repository->repository_format_partial_clone =
- candidate.partial_clone;
- candidate.partial_clone = NULL;
-
clear_repository_format(&candidate);
return 0;
}
@@ -1560,6 +1564,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
}
if (startup_info->have_repository) {
repo_set_hash_algo(the_repository, repo_fmt.hash_algo);
+ the_repository->repository_format_worktree_config =
+ repo_fmt.worktree_config;
/* take ownership of repo_fmt.partial_clone */
the_repository->repository_format_partial_clone =
repo_fmt.partial_clone;
@@ -1651,6 +1657,8 @@ void check_repository_format(struct repository_format *fmt)
check_repository_format_gently(get_git_dir(), fmt, NULL);
startup_info->have_repository = 1;
repo_set_hash_algo(the_repository, fmt->hash_algo);
+ the_repository->repository_format_worktree_config =
+ fmt->worktree_config;
the_repository->repository_format_partial_clone =
xstrdup_or_null(fmt->partial_clone);
clear_repository_format(&repo_fmt);
@@ -1707,3 +1715,491 @@ int daemonize(void)
return 0;
#endif
}
+
+#ifdef NO_TRUSTABLE_FILEMODE
+#define TEST_FILEMODE 0
+#else
+#define TEST_FILEMODE 1
+#endif
+
+#define GIT_DEFAULT_HASH_ENVIRONMENT "GIT_DEFAULT_HASH"
+
+static void copy_templates_1(struct strbuf *path, struct strbuf *template_path,
+ DIR *dir)
+{
+ size_t path_baselen = path->len;
+ size_t template_baselen = template_path->len;
+ struct dirent *de;
+
+ /* Note: if ".git/hooks" file exists in the repository being
+ * re-initialized, /etc/core-git/templates/hooks/update would
+ * cause "git init" to fail here. I think this is sane but
+ * it means that the set of templates we ship by default, along
+ * with the way the namespace under .git/ is organized, should
+ * be really carefully chosen.
+ */
+ safe_create_dir(path->buf, 1);
+ while ((de = readdir(dir)) != NULL) {
+ struct stat st_git, st_template;
+ int exists = 0;
+
+ strbuf_setlen(path, path_baselen);
+ strbuf_setlen(template_path, template_baselen);
+
+ if (de->d_name[0] == '.')
+ continue;
+ strbuf_addstr(path, de->d_name);
+ strbuf_addstr(template_path, de->d_name);
+ if (lstat(path->buf, &st_git)) {
+ if (errno != ENOENT)
+ die_errno(_("cannot stat '%s'"), path->buf);
+ }
+ else
+ exists = 1;
+
+ if (lstat(template_path->buf, &st_template))
+ die_errno(_("cannot stat template '%s'"), template_path->buf);
+
+ if (S_ISDIR(st_template.st_mode)) {
+ DIR *subdir = opendir(template_path->buf);
+ if (!subdir)
+ die_errno(_("cannot opendir '%s'"), template_path->buf);
+ strbuf_addch(path, '/');
+ strbuf_addch(template_path, '/');
+ copy_templates_1(path, template_path, subdir);
+ closedir(subdir);
+ }
+ else if (exists)
+ continue;
+ else if (S_ISLNK(st_template.st_mode)) {
+ struct strbuf lnk = STRBUF_INIT;
+ if (strbuf_readlink(&lnk, template_path->buf,
+ st_template.st_size) < 0)
+ die_errno(_("cannot readlink '%s'"), template_path->buf);
+ if (symlink(lnk.buf, path->buf))
+ die_errno(_("cannot symlink '%s' '%s'"),
+ lnk.buf, path->buf);
+ strbuf_release(&lnk);
+ }
+ else if (S_ISREG(st_template.st_mode)) {
+ if (copy_file(path->buf, template_path->buf, st_template.st_mode))
+ die_errno(_("cannot copy '%s' to '%s'"),
+ template_path->buf, path->buf);
+ }
+ else
+ error(_("ignoring template %s"), template_path->buf);
+ }
+}
+
+static void copy_templates(const char *template_dir, const char *init_template_dir)
+{
+ struct strbuf path = STRBUF_INIT;
+ struct strbuf template_path = STRBUF_INIT;
+ size_t template_len;
+ struct repository_format template_format = REPOSITORY_FORMAT_INIT;
+ struct strbuf err = STRBUF_INIT;
+ DIR *dir;
+ char *to_free = NULL;
+
+ if (!template_dir)
+ template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
+ if (!template_dir)
+ template_dir = init_template_dir;
+ if (!template_dir)
+ template_dir = to_free = system_path(DEFAULT_GIT_TEMPLATE_DIR);
+ if (!template_dir[0]) {
+ free(to_free);
+ return;
+ }
+
+ strbuf_addstr(&template_path, template_dir);
+ strbuf_complete(&template_path, '/');
+ template_len = template_path.len;
+
+ dir = opendir(template_path.buf);
+ if (!dir) {
+ warning(_("templates not found in %s"), template_dir);
+ goto free_return;
+ }
+
+ /* Make sure that template is from the correct vintage */
+ strbuf_addstr(&template_path, "config");
+ read_repository_format(&template_format, template_path.buf);
+ strbuf_setlen(&template_path, template_len);
+
+ /*
+ * No mention of version at all is OK, but anything else should be
+ * verified.
+ */
+ if (template_format.version >= 0 &&
+ verify_repository_format(&template_format, &err) < 0) {
+ warning(_("not copying templates from '%s': %s"),
+ template_dir, err.buf);
+ strbuf_release(&err);
+ goto close_free_return;
+ }
+
+ strbuf_addstr(&path, get_git_common_dir());
+ strbuf_complete(&path, '/');
+ copy_templates_1(&path, &template_path, dir);
+close_free_return:
+ closedir(dir);
+free_return:
+ free(to_free);
+ strbuf_release(&path);
+ strbuf_release(&template_path);
+ clear_repository_format(&template_format);
+}
+
+/*
+ * If the git_dir is not directly inside the working tree, then git will not
+ * find it by default, and we need to set the worktree explicitly.
+ */
+static int needs_work_tree_config(const char *git_dir, const char *work_tree)
+{
+ if (!strcmp(work_tree, "/") && !strcmp(git_dir, "/.git"))
+ return 0;
+ if (skip_prefix(git_dir, work_tree, &git_dir) &&
+ !strcmp(git_dir, "/.git"))
+ return 0;
+ return 1;
+}
+
+void initialize_repository_version(int hash_algo, int reinit)
+{
+ char repo_version_string[10];
+ int repo_version = GIT_REPO_VERSION;
+
+ if (hash_algo != GIT_HASH_SHA1)
+ repo_version = GIT_REPO_VERSION_READ;
+
+ /* This forces creation of new config file */
+ xsnprintf(repo_version_string, sizeof(repo_version_string),
+ "%d", repo_version);
+ git_config_set("core.repositoryformatversion", repo_version_string);
+
+ if (hash_algo != GIT_HASH_SHA1)
+ git_config_set("extensions.objectformat",
+ hash_algos[hash_algo].name);
+ else if (reinit)
+ git_config_set_gently("extensions.objectformat", NULL);
+}
+
+static int create_default_files(const char *template_path,
+ const char *original_git_dir,
+ const char *initial_branch,
+ const struct repository_format *fmt,
+ int prev_bare_repository,
+ int init_shared_repository,
+ int quiet)
+{
+ struct stat st1;
+ struct strbuf buf = STRBUF_INIT;
+ char *path;
+ char junk[2];
+ int reinit;
+ int filemode;
+ struct strbuf err = STRBUF_INIT;
+ const char *init_template_dir = NULL;
+ const char *work_tree = get_git_work_tree();
+
+ /*
+ * First copy the templates -- we might have the default
+ * config file there, in which case we would want to read
+ * from it after installing.
+ *
+ * Before reading that config, we also need to clear out any cached
+ * values (since we've just potentially changed what's available on
+ * disk).
+ */
+ git_config_get_pathname("init.templatedir", &init_template_dir);
+ copy_templates(template_path, init_template_dir);
+ free((char *)init_template_dir);
+ git_config_clear();
+ reset_shared_repository();
+ git_config(git_default_config, NULL);
+
+ /*
+ * We must make sure command-line options continue to override any
+ * values we might have just re-read from the config.
+ */
+ if (init_shared_repository != -1)
+ set_shared_repository(init_shared_repository);
+ /*
+ * TODO: heed core.bare from config file in templates if no
+ * command-line override given
+ */
+ is_bare_repository_cfg = prev_bare_repository || !work_tree;
+ /* TODO (continued):
+ *
+ * Unfortunately, the line above is equivalent to
+ * is_bare_repository_cfg = !work_tree;
+ * which ignores the config entirely even if no `--[no-]bare`
+ * command line option was present.
+ *
+ * To see why, note that before this function, there was this call:
+ * prev_bare_repository = is_bare_repository()
+ * expanding the right hand side:
+ * = is_bare_repository_cfg && !get_git_work_tree()
+ * = is_bare_repository_cfg && !work_tree
+ * note that the last simplification above is valid because nothing
+ * calls repo_init() or set_git_work_tree() between any of the
+ * relevant calls in the code, and thus the !get_git_work_tree()
+ * calls will return the same result each time. So, what we are
+ * interested in computing is the right hand side of the line of
+ * code just above this comment:
+ * prev_bare_repository || !work_tree
+ * = is_bare_repository_cfg && !work_tree || !work_tree
+ * = !work_tree
+ * because "A && !B || !B == !B" for all boolean values of A & B.
+ */
+
+ /*
+ * We would have created the above under user's umask -- under
+ * shared-repository settings, we would need to fix them up.
+ */
+ if (get_shared_repository()) {
+ adjust_shared_perm(get_git_dir());
+ }
+
+ /*
+ * We need to create a "refs" dir in any case so that older
+ * versions of git can tell that this is a repository.
+ */
+ safe_create_dir(git_path("refs"), 1);
+ adjust_shared_perm(git_path("refs"));
+
+ if (refs_init_db(&err))
+ die("failed to set up refs db: %s", err.buf);
+
+ /*
+ * Point the HEAD symref to the initial branch with if HEAD does
+ * not yet exist.
+ */
+ path = git_path_buf(&buf, "HEAD");
+ reinit = (!access(path, R_OK)
+ || readlink(path, junk, sizeof(junk)-1) != -1);
+ if (!reinit) {
+ char *ref;
+
+ if (!initial_branch)
+ initial_branch = git_default_branch_name(quiet);
+
+ ref = xstrfmt("refs/heads/%s", initial_branch);
+ if (check_refname_format(ref, 0) < 0)
+ die(_("invalid initial branch name: '%s'"),
+ initial_branch);
+
+ if (create_symref("HEAD", ref, NULL) < 0)
+ exit(1);
+ free(ref);
+ }
+
+ initialize_repository_version(fmt->hash_algo, 0);
+
+ /* Check filemode trustability */
+ path = git_path_buf(&buf, "config");
+ filemode = TEST_FILEMODE;
+ if (TEST_FILEMODE && !lstat(path, &st1)) {
+ struct stat st2;
+ filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
+ !lstat(path, &st2) &&
+ st1.st_mode != st2.st_mode &&
+ !chmod(path, st1.st_mode));
+ if (filemode && !reinit && (st1.st_mode & S_IXUSR))
+ filemode = 0;
+ }
+ git_config_set("core.filemode", filemode ? "true" : "false");
+
+ if (is_bare_repository())
+ git_config_set("core.bare", "true");
+ else {
+ git_config_set("core.bare", "false");
+ /* allow template config file to override the default */
+ if (log_all_ref_updates == LOG_REFS_UNSET)
+ git_config_set("core.logallrefupdates", "true");
+ if (needs_work_tree_config(original_git_dir, work_tree))
+ git_config_set("core.worktree", work_tree);
+ }
+
+ if (!reinit) {
+ /* Check if symlink is supported in the work tree */
+ path = git_path_buf(&buf, "tXXXXXX");
+ if (!close(xmkstemp(path)) &&
+ !unlink(path) &&
+ !symlink("testing", path) &&
+ !lstat(path, &st1) &&
+ S_ISLNK(st1.st_mode))
+ unlink(path); /* good */
+ else
+ git_config_set("core.symlinks", "false");
+
+ /* Check if the filesystem is case-insensitive */
+ path = git_path_buf(&buf, "CoNfIg");
+ if (!access(path, F_OK))
+ git_config_set("core.ignorecase", "true");
+ probe_utf8_pathname_composition();
+ }
+
+ strbuf_release(&buf);
+ return reinit;
+}
+
+static void create_object_directory(void)
+{
+ struct strbuf path = STRBUF_INIT;
+ size_t baselen;
+
+ strbuf_addstr(&path, get_object_directory());
+ baselen = path.len;
+
+ safe_create_dir(path.buf, 1);
+
+ strbuf_setlen(&path, baselen);
+ strbuf_addstr(&path, "/pack");
+ safe_create_dir(path.buf, 1);
+
+ strbuf_setlen(&path, baselen);
+ strbuf_addstr(&path, "/info");
+ safe_create_dir(path.buf, 1);
+
+ strbuf_release(&path);
+}
+
+static void separate_git_dir(const char *git_dir, const char *git_link)
+{
+ struct stat st;
+
+ if (!stat(git_link, &st)) {
+ const char *src;
+
+ if (S_ISREG(st.st_mode))
+ src = read_gitfile(git_link);
+ else if (S_ISDIR(st.st_mode))
+ src = git_link;
+ else
+ die(_("unable to handle file type %d"), (int)st.st_mode);
+
+ if (rename(src, git_dir))
+ die_errno(_("unable to move %s to %s"), src, git_dir);
+ repair_worktrees(NULL, NULL);
+ }
+
+ write_file(git_link, "gitdir: %s", git_dir);
+}
+
+static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash)
+{
+ const char *env = getenv(GIT_DEFAULT_HASH_ENVIRONMENT);
+ /*
+ * If we already have an initialized repo, don't allow the user to
+ * specify a different algorithm, as that could cause corruption.
+ * Otherwise, if the user has specified one on the command line, use it.
+ */
+ if (repo_fmt->version >= 0 && hash != GIT_HASH_UNKNOWN && hash != repo_fmt->hash_algo)
+ die(_("attempt to reinitialize repository with different hash"));
+ else if (hash != GIT_HASH_UNKNOWN)
+ repo_fmt->hash_algo = hash;
+ else if (env) {
+ int env_algo = hash_algo_by_name(env);
+ if (env_algo == GIT_HASH_UNKNOWN)
+ die(_("unknown hash algorithm '%s'"), env);
+ repo_fmt->hash_algo = env_algo;
+ }
+}
+
+int init_db(const char *git_dir, const char *real_git_dir,
+ const char *template_dir, int hash, const char *initial_branch,
+ int init_shared_repository, unsigned int flags)
+{
+ int reinit;
+ int exist_ok = flags & INIT_DB_EXIST_OK;
+ char *original_git_dir = real_pathdup(git_dir, 1);
+ struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT;
+ int prev_bare_repository;
+
+ if (real_git_dir) {
+ struct stat st;
+
+ if (!exist_ok && !stat(git_dir, &st))
+ die(_("%s already exists"), git_dir);
+
+ if (!exist_ok && !stat(real_git_dir, &st))
+ die(_("%s already exists"), real_git_dir);
+
+ set_git_dir(real_git_dir, 1);
+ git_dir = get_git_dir();
+ separate_git_dir(git_dir, original_git_dir);
+ }
+ else {
+ set_git_dir(git_dir, 1);
+ git_dir = get_git_dir();
+ }
+ startup_info->have_repository = 1;
+
+ /* Ensure `core.hidedotfiles` is processed */
+ git_config(platform_core_config, NULL);
+
+ safe_create_dir(git_dir, 0);
+
+ prev_bare_repository = is_bare_repository();
+
+ /* Check to see if the repository version is right.
+ * Note that a newly created repository does not have
+ * config file, so this will not fail. What we are catching
+ * is an attempt to reinitialize new repository with an old tool.
+ */
+ check_repository_format(&repo_fmt);
+
+ validate_hash_algorithm(&repo_fmt, hash);
+
+ reinit = create_default_files(template_dir, original_git_dir,
+ initial_branch, &repo_fmt,
+ prev_bare_repository,
+ init_shared_repository,
+ flags & INIT_DB_QUIET);
+ if (reinit && initial_branch)
+ warning(_("re-init: ignored --initial-branch=%s"),
+ initial_branch);
+
+ create_object_directory();
+
+ if (get_shared_repository()) {
+ char buf[10];
+ /* We do not spell "group" and such, so that
+ * the configuration can be read by older version
+ * of git. Note, we use octal numbers for new share modes,
+ * and compatibility values for PERM_GROUP and
+ * PERM_EVERYBODY.
+ */
+ if (get_shared_repository() < 0)
+ /* force to the mode value */
+ xsnprintf(buf, sizeof(buf), "0%o", -get_shared_repository());
+ else if (get_shared_repository() == PERM_GROUP)
+ xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP);
+ else if (get_shared_repository() == PERM_EVERYBODY)
+ xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
+ else
+ BUG("invalid value for shared_repository");
+ git_config_set("core.sharedrepository", buf);
+ git_config_set("receive.denyNonFastforwards", "true");
+ }
+
+ if (!(flags & INIT_DB_QUIET)) {
+ int len = strlen(git_dir);
+
+ if (reinit)
+ printf(get_shared_repository()
+ ? _("Reinitialized existing shared Git repository in %s%s\n")
+ : _("Reinitialized existing Git repository in %s%s\n"),
+ git_dir, len && git_dir[len-1] != '/' ? "/" : "");
+ else
+ printf(get_shared_repository()
+ ? _("Initialized empty shared Git repository in %s%s\n")
+ : _("Initialized empty Git repository in %s%s\n"),
+ git_dir, len && git_dir[len-1] != '/' ? "/" : "");
+ }
+
+ free(original_git_dir);
+ return 0;
+}
diff --git a/setup.h b/setup.h
index 4c1ca9d0c9..58fd2605dd 100644
--- a/setup.h
+++ b/setup.h
@@ -140,6 +140,15 @@ int verify_repository_format(const struct repository_format *format,
*/
void check_repository_format(struct repository_format *fmt);
+#define INIT_DB_QUIET 0x0001
+#define INIT_DB_EXIST_OK 0x0002
+
+int init_db(const char *git_dir, const char *real_git_dir,
+ const char *template_dir, int hash_algo,
+ const char *initial_branch, int init_shared_repository,
+ unsigned int flags);
+void initialize_repository_version(int hash_algo, int reinit);
+
/*
* NOTE NOTE NOTE!!
*
diff --git a/sha1/openssl.h b/sha1/openssl.h
new file mode 100644
index 0000000000..006c1f4ba5
--- /dev/null
+++ b/sha1/openssl.h
@@ -0,0 +1,49 @@
+/* wrappers for the EVP API of OpenSSL 3+ */
+#ifndef SHA1_OPENSSL_H
+#define SHA1_OPENSSL_H
+#include <openssl/evp.h>
+
+struct openssl_SHA1_CTX {
+ EVP_MD_CTX *ectx;
+};
+
+typedef struct openssl_SHA1_CTX openssl_SHA1_CTX;
+
+static inline void openssl_SHA1_Init(struct openssl_SHA1_CTX *ctx)
+{
+ const EVP_MD *type = EVP_sha1();
+
+ ctx->ectx = EVP_MD_CTX_new();
+ if (!ctx->ectx)
+ die("EVP_MD_CTX_new: out of memory");
+
+ EVP_DigestInit_ex(ctx->ectx, type, NULL);
+}
+
+static inline void openssl_SHA1_Update(struct openssl_SHA1_CTX *ctx,
+ const void *data,
+ size_t len)
+{
+ EVP_DigestUpdate(ctx->ectx, data, len);
+}
+
+static inline void openssl_SHA1_Final(unsigned char *digest,
+ struct openssl_SHA1_CTX *ctx)
+{
+ EVP_DigestFinal_ex(ctx->ectx, digest, NULL);
+ EVP_MD_CTX_free(ctx->ectx);
+}
+
+static inline void openssl_SHA1_Clone(struct openssl_SHA1_CTX *dst,
+ const struct openssl_SHA1_CTX *src)
+{
+ EVP_MD_CTX_copy_ex(dst->ectx, src->ectx);
+}
+
+#define platform_SHA_CTX openssl_SHA1_CTX
+#define platform_SHA1_Init openssl_SHA1_Init
+#define platform_SHA1_Clone openssl_SHA1_Clone
+#define platform_SHA1_Update openssl_SHA1_Update
+#define platform_SHA1_Final openssl_SHA1_Final
+
+#endif /* SHA1_OPENSSL_H */
diff --git a/sha256/gcrypt.h b/sha256/gcrypt.h
index 501da5ed91..17a90f1052 100644
--- a/sha256/gcrypt.h
+++ b/sha256/gcrypt.h
@@ -7,22 +7,25 @@
typedef gcry_md_hd_t gcrypt_SHA256_CTX;
-inline void gcrypt_SHA256_Init(gcrypt_SHA256_CTX *ctx)
+static inline void gcrypt_SHA256_Init(gcrypt_SHA256_CTX *ctx)
{
- gcry_md_open(ctx, GCRY_MD_SHA256, 0);
+ gcry_error_t err = gcry_md_open(ctx, GCRY_MD_SHA256, 0);
+ if (err)
+ die("gcry_md_open: %s", gcry_strerror(err));
}
-inline void gcrypt_SHA256_Update(gcrypt_SHA256_CTX *ctx, const void *data, size_t len)
+static inline void gcrypt_SHA256_Update(gcrypt_SHA256_CTX *ctx, const void *data, size_t len)
{
gcry_md_write(*ctx, data, len);
}
-inline void gcrypt_SHA256_Final(unsigned char *digest, gcrypt_SHA256_CTX *ctx)
+static inline void gcrypt_SHA256_Final(unsigned char *digest, gcrypt_SHA256_CTX *ctx)
{
memcpy(digest, gcry_md_read(*ctx, GCRY_MD_SHA256), SHA256_DIGEST_SIZE);
+ gcry_md_close(*ctx);
}
-inline void gcrypt_SHA256_Clone(gcrypt_SHA256_CTX *dst, const gcrypt_SHA256_CTX *src)
+static inline void gcrypt_SHA256_Clone(gcrypt_SHA256_CTX *dst, const gcrypt_SHA256_CTX *src)
{
gcry_md_copy(dst, *src);
}
diff --git a/sha256/openssl.h b/sha256/openssl.h
new file mode 100644
index 0000000000..c1083d9491
--- /dev/null
+++ b/sha256/openssl.h
@@ -0,0 +1,49 @@
+/* wrappers for the EVP API of OpenSSL 3+ */
+#ifndef SHA256_OPENSSL_H
+#define SHA256_OPENSSL_H
+#include <openssl/evp.h>
+
+struct openssl_SHA256_CTX {
+ EVP_MD_CTX *ectx;
+};
+
+typedef struct openssl_SHA256_CTX openssl_SHA256_CTX;
+
+static inline void openssl_SHA256_Init(struct openssl_SHA256_CTX *ctx)
+{
+ const EVP_MD *type = EVP_sha256();
+
+ ctx->ectx = EVP_MD_CTX_new();
+ if (!ctx->ectx)
+ die("EVP_MD_CTX_new: out of memory");
+
+ EVP_DigestInit_ex(ctx->ectx, type, NULL);
+}
+
+static inline void openssl_SHA256_Update(struct openssl_SHA256_CTX *ctx,
+ const void *data,
+ size_t len)
+{
+ EVP_DigestUpdate(ctx->ectx, data, len);
+}
+
+static inline void openssl_SHA256_Final(unsigned char *digest,
+ struct openssl_SHA256_CTX *ctx)
+{
+ EVP_DigestFinal_ex(ctx->ectx, digest, NULL);
+ EVP_MD_CTX_free(ctx->ectx);
+}
+
+static inline void openssl_SHA256_Clone(struct openssl_SHA256_CTX *dst,
+ const struct openssl_SHA256_CTX *src)
+{
+ EVP_MD_CTX_copy_ex(dst->ectx, src->ectx);
+}
+
+#define platform_SHA256_CTX openssl_SHA256_CTX
+#define platform_SHA256_Init openssl_SHA256_Init
+#define platform_SHA256_Clone openssl_SHA256_Clone
+#define platform_SHA256_Update openssl_SHA256_Update
+#define platform_SHA256_Final openssl_SHA256_Final
+
+#endif /* SHA256_OPENSSL_H */
diff --git a/shallow.c b/shallow.c
index 128f56179e..5413719fd4 100644
--- a/shallow.c
+++ b/shallow.c
@@ -1,24 +1,24 @@
-#include "cache.h"
-#include "alloc.h"
+#include "git-compat-util.h"
#include "hex.h"
#include "repository.h"
#include "tempfile.h"
#include "lockfile.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "commit.h"
#include "tag.h"
#include "pkt-line.h"
#include "remote.h"
#include "refs.h"
#include "oid-array.h"
+#include "path.h"
#include "diff.h"
#include "revision.h"
#include "commit-slab.h"
#include "list-objects.h"
#include "commit-reach.h"
#include "shallow.h"
+#include "statinfo.h"
#include "trace.h"
-#include "wrapper.h"
void set_alternate_shallow_file(struct repository *r, const char *path, int override)
{
diff --git a/sigchain.c b/sigchain.c
index ee778c0580..66123bdbab 100644
--- a/sigchain.c
+++ b/sigchain.c
@@ -1,5 +1,4 @@
#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 886054729e..1fdb07a9e6 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -1,7 +1,8 @@
-#include "cache.h"
-#include "alloc.h"
+#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
+#include "name-hash.h"
+#include "read-cache-ll.h"
#include "repository.h"
#include "sparse-index.h"
#include "tree.h"
@@ -10,7 +11,7 @@
#include "cache-tree.h"
#include "config.h"
#include "dir.h"
-#include "fsmonitor.h"
+#include "fsmonitor-ll.h"
struct modify_index_context {
struct index_state *write;
diff --git a/sparse-index.h b/sparse-index.h
index 59a92d819e..a16f3e67d7 100644
--- a/sparse-index.h
+++ b/sparse-index.h
@@ -37,4 +37,6 @@ struct pattern_list;
*/
void expand_index(struct index_state *istate, struct pattern_list *pl);
+void ensure_full_index(struct index_state *istate);
+
#endif
diff --git a/split-index.c b/split-index.c
index 40e54760b3..8c38687c04 100644
--- a/split-index.c
+++ b/split-index.c
@@ -1,8 +1,8 @@
-#include "cache.h"
-#include "alloc.h"
+#include "git-compat-util.h"
#include "gettext.h"
#include "hash.h"
#include "mem-pool.h"
+#include "read-cache-ll.h"
#include "split-index.h"
#include "strbuf.h"
#include "ewah/ewok.h"
diff --git a/statinfo.c b/statinfo.c
new file mode 100644
index 0000000000..17bb8966c3
--- /dev/null
+++ b/statinfo.c
@@ -0,0 +1,87 @@
+#include "git-compat-util.h"
+#include "environment.h"
+#include "statinfo.h"
+
+void fill_stat_data(struct stat_data *sd, struct stat *st)
+{
+ sd->sd_ctime.sec = (unsigned int)st->st_ctime;
+ sd->sd_mtime.sec = (unsigned int)st->st_mtime;
+ sd->sd_ctime.nsec = ST_CTIME_NSEC(*st);
+ sd->sd_mtime.nsec = ST_MTIME_NSEC(*st);
+ sd->sd_dev = st->st_dev;
+ sd->sd_ino = st->st_ino;
+ sd->sd_uid = st->st_uid;
+ sd->sd_gid = st->st_gid;
+ sd->sd_size = st->st_size;
+}
+
+int match_stat_data(const struct stat_data *sd, struct stat *st)
+{
+ int changed = 0;
+
+ if (sd->sd_mtime.sec != (unsigned int)st->st_mtime)
+ changed |= MTIME_CHANGED;
+ if (trust_ctime && check_stat &&
+ sd->sd_ctime.sec != (unsigned int)st->st_ctime)
+ changed |= CTIME_CHANGED;
+
+#ifdef USE_NSEC
+ if (check_stat && sd->sd_mtime.nsec != ST_MTIME_NSEC(*st))
+ changed |= MTIME_CHANGED;
+ if (trust_ctime && check_stat &&
+ sd->sd_ctime.nsec != ST_CTIME_NSEC(*st))
+ changed |= CTIME_CHANGED;
+#endif
+
+ if (check_stat) {
+ if (sd->sd_uid != (unsigned int) st->st_uid ||
+ sd->sd_gid != (unsigned int) st->st_gid)
+ changed |= OWNER_CHANGED;
+ if (sd->sd_ino != (unsigned int) st->st_ino)
+ changed |= INODE_CHANGED;
+ }
+
+#ifdef USE_STDEV
+ /*
+ * st_dev breaks on network filesystems where different
+ * clients will have different views of what "device"
+ * the filesystem is on
+ */
+ if (check_stat && sd->sd_dev != (unsigned int) st->st_dev)
+ changed |= INODE_CHANGED;
+#endif
+
+ if (sd->sd_size != (unsigned int) st->st_size)
+ changed |= DATA_CHANGED;
+
+ return changed;
+}
+
+void stat_validity_clear(struct stat_validity *sv)
+{
+ FREE_AND_NULL(sv->sd);
+}
+
+int stat_validity_check(struct stat_validity *sv, const char *path)
+{
+ struct stat st;
+
+ if (stat(path, &st) < 0)
+ return sv->sd == NULL;
+ if (!sv->sd)
+ return 0;
+ return S_ISREG(st.st_mode) && !match_stat_data(sv->sd, &st);
+}
+
+void stat_validity_update(struct stat_validity *sv, int fd)
+{
+ struct stat st;
+
+ if (fstat(fd, &st) < 0 || !S_ISREG(st.st_mode))
+ stat_validity_clear(sv);
+ else {
+ if (!sv->sd)
+ CALLOC_ARRAY(sv->sd, 1);
+ fill_stat_data(sv->sd, &st);
+ }
+}
diff --git a/statinfo.h b/statinfo.h
index e49e3054ea..700f502ac0 100644
--- a/statinfo.h
+++ b/statinfo.h
@@ -1,6 +1,8 @@
#ifndef STATINFO_H
#define STATINFO_H
+struct index_state;
+
/*
* The "cache_time" is just the low 32 bits of the
* time. It doesn't matter if it overflows - we only
@@ -21,4 +23,67 @@ struct stat_data {
unsigned int sd_size;
};
+/*
+ * A struct to encapsulate the concept of whether a file has changed
+ * since we last checked it. This uses criteria similar to those used
+ * for the index.
+ */
+struct stat_validity {
+ struct stat_data *sd;
+};
+
+#define MTIME_CHANGED 0x0001
+#define CTIME_CHANGED 0x0002
+#define OWNER_CHANGED 0x0004
+#define MODE_CHANGED 0x0008
+#define INODE_CHANGED 0x0010
+#define DATA_CHANGED 0x0020
+#define TYPE_CHANGED 0x0040
+
+/*
+ * Record to sd the data from st that we use to check whether a file
+ * might have changed.
+ */
+void fill_stat_data(struct stat_data *sd, struct stat *st);
+
+/*
+ * Return 0 if st is consistent with a file not having been changed
+ * since sd was filled. If there are differences, return a
+ * combination of MTIME_CHANGED, CTIME_CHANGED, OWNER_CHANGED,
+ * INODE_CHANGED, and DATA_CHANGED.
+ */
+int match_stat_data(const struct stat_data *sd, struct stat *st);
+
+void stat_validity_clear(struct stat_validity *sv);
+
+/*
+ * Returns 1 if the path is a regular file (or a symlink to a regular
+ * file) and matches the saved stat_validity, 0 otherwise. A missing
+ * or inaccessible file is considered a match if the struct was just
+ * initialized, or if the previous update found an inaccessible file.
+ */
+int stat_validity_check(struct stat_validity *sv, const char *path);
+
+/*
+ * Update the stat_validity from a file opened at descriptor fd. If
+ * the file is missing, inaccessible, or not a regular file, then
+ * future calls to stat_validity_check will match iff one of those
+ * conditions continues to be true.
+ */
+void stat_validity_update(struct stat_validity *sv, int fd);
+
+#if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT)
+#define DTYPE(de) ((de)->d_type)
+#else
+#undef DT_UNKNOWN
+#undef DT_DIR
+#undef DT_REG
+#undef DT_LNK
+#define DT_UNKNOWN 0
+#define DT_DIR 1
+#define DT_REG 2
+#define DT_LNK 3
+#define DTYPE(de) DT_UNKNOWN
+#endif
+
#endif
diff --git a/strbuf.c b/strbuf.c
index 08eec8f1d8..4c9ac6dc5e 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -1,16 +1,10 @@
#include "git-compat-util.h"
-#include "abspath.h"
-#include "alloc.h"
-#include "environment.h"
#include "gettext.h"
#include "hex.h"
-#include "object-name.h"
-#include "refs.h"
-#include "repository.h"
+#include "strbuf.h"
#include "string-list.h"
#include "utf8.h"
#include "date.h"
-#include "wrapper.h"
int starts_with(const char *str, const char *prefix)
{
@@ -365,7 +359,8 @@ static void add_lines(struct strbuf *out,
strbuf_complete_line(out);
}
-void strbuf_add_commented_lines(struct strbuf *out, const char *buf, size_t size)
+void strbuf_add_commented_lines(struct strbuf *out, const char *buf,
+ size_t size, char comment_line_char)
{
static char prefix1[3];
static char prefix2[2];
@@ -377,7 +372,8 @@ void strbuf_add_commented_lines(struct strbuf *out, const char *buf, size_t size
add_lines(out, prefix1, prefix2, buf, size);
}
-void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...)
+void strbuf_commented_addf(struct strbuf *sb, char comment_line_char,
+ const char *fmt, ...)
{
va_list params;
struct strbuf buf = STRBUF_INIT;
@@ -387,7 +383,7 @@ void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...)
strbuf_vaddf(&buf, fmt, params);
va_end(params);
- strbuf_add_commented_lines(sb, buf.buf, buf.len);
+ strbuf_add_commented_lines(sb, buf.buf, buf.len, comment_line_char);
if (incomplete_line)
sb->buf[--sb->len] = '\0';
@@ -415,36 +411,19 @@ void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap)
strbuf_setlen(sb, sb->len + len);
}
-void strbuf_expand(struct strbuf *sb, const char *format, expand_fn_t fn,
- void *context)
+int strbuf_expand_step(struct strbuf *sb, const char **formatp)
{
- for (;;) {
- const char *percent;
- size_t consumed;
-
- percent = strchrnul(format, '%');
- strbuf_add(sb, format, percent - format);
- if (!*percent)
- break;
- format = percent + 1;
+ const char *format = *formatp;
+ const char *percent = strchrnul(format, '%');
- if (*format == '%') {
- strbuf_addch(sb, '%');
- format++;
- continue;
- }
-
- consumed = fn(sb, format, context);
- if (consumed)
- format += consumed;
- else
- strbuf_addch(sb, '%');
- }
+ strbuf_add(sb, format, percent - format);
+ if (!*percent)
+ return 0;
+ *formatp = percent + 1;
+ return 1;
}
-size_t strbuf_expand_literal_cb(struct strbuf *sb,
- const char *placeholder,
- void *context UNUSED)
+size_t strbuf_expand_literal(struct strbuf *sb, const char *placeholder)
{
int ch;
@@ -463,22 +442,6 @@ size_t strbuf_expand_literal_cb(struct strbuf *sb,
return 0;
}
-size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder,
- void *context)
-{
- struct strbuf_expand_dict_entry *e = context;
- size_t len;
-
- for (; e->placeholder && (len = strlen(e->placeholder)); e++) {
- if (!strncmp(placeholder, e->placeholder, len)) {
- if (e->value)
- strbuf_addstr(sb, e->value);
- return len;
- }
- }
- return 0;
-}
-
void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *src)
{
size_t i, len = src->len;
@@ -721,11 +684,11 @@ static int strbuf_getdelim(struct strbuf *sb, FILE *fp, int term)
return 0;
}
-int strbuf_getline(struct strbuf *sb, FILE *fp)
+int strbuf_getdelim_strip_crlf(struct strbuf *sb, FILE *fp, int term)
{
- if (strbuf_getwholeline(sb, fp, '\n'))
+ if (strbuf_getwholeline(sb, fp, term))
return EOF;
- if (sb->buf[sb->len - 1] == '\n') {
+ if (term == '\n' && sb->buf[sb->len - 1] == '\n') {
strbuf_setlen(sb, sb->len - 1);
if (sb->len && sb->buf[sb->len - 1] == '\r')
strbuf_setlen(sb, sb->len - 1);
@@ -733,6 +696,11 @@ int strbuf_getline(struct strbuf *sb, FILE *fp)
return 0;
}
+int strbuf_getline(struct strbuf *sb, FILE *fp)
+{
+ return strbuf_getdelim_strip_crlf(sb, fp, '\n');
+}
+
int strbuf_getline_lf(struct strbuf *sb, FILE *fp)
{
return strbuf_getdelim(sb, fp, '\n');
@@ -811,25 +779,6 @@ void strbuf_addstr_xml_quoted(struct strbuf *buf, const char *s)
}
}
-int is_rfc3986_reserved_or_unreserved(char ch)
-{
- if (is_rfc3986_unreserved(ch))
- return 1;
- switch (ch) {
- case '!': case '*': case '\'': case '(': case ')': case ';':
- case ':': case '@': case '&': case '=': case '+': case '$':
- case ',': case '/': case '?': case '#': case '[': case ']':
- return 1;
- }
- return 0;
-}
-
-int is_rfc3986_unreserved(char ch)
-{
- return isalnum(ch) ||
- ch == '-' || ch == '_' || ch == '.' || ch == '~';
-}
-
static void strbuf_add_urlencode(struct strbuf *sb, const char *s, size_t len,
char_predicate allow_unencoded_fn)
{
@@ -900,42 +849,6 @@ void strbuf_humanise_rate(struct strbuf *buf, off_t bytes)
strbuf_humanise(buf, bytes, 1);
}
-void strbuf_add_absolute_path(struct strbuf *sb, const char *path)
-{
- if (!*path)
- die("The empty string is not a valid path");
- if (!is_absolute_path(path)) {
- struct stat cwd_stat, pwd_stat;
- size_t orig_len = sb->len;
- char *cwd = xgetcwd();
- char *pwd = getenv("PWD");
- if (pwd && strcmp(pwd, cwd) &&
- !stat(cwd, &cwd_stat) &&
- (cwd_stat.st_dev || cwd_stat.st_ino) &&
- !stat(pwd, &pwd_stat) &&
- pwd_stat.st_dev == cwd_stat.st_dev &&
- pwd_stat.st_ino == cwd_stat.st_ino)
- strbuf_addstr(sb, pwd);
- else
- strbuf_addstr(sb, cwd);
- if (sb->len > orig_len && !is_dir_sep(sb->buf[sb->len - 1]))
- strbuf_addch(sb, '/');
- free(cwd);
- }
- strbuf_addstr(sb, path);
-}
-
-void strbuf_add_real_path(struct strbuf *sb, const char *path)
-{
- if (sb->len) {
- struct strbuf resolved = STRBUF_INIT;
- strbuf_realpath(&resolved, path, 1);
- strbuf_addbuf(sb, &resolved);
- strbuf_release(&resolved);
- } else
- strbuf_realpath(sb, path, 1);
-}
-
int printf_ln(const char *fmt, ...)
{
int ret;
@@ -1022,37 +935,20 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
* we want for %z, but the computation for %s has to convert to number
* of seconds.
*/
- for (;;) {
- const char *percent = strchrnul(fmt, '%');
- strbuf_add(&munged_fmt, fmt, percent - fmt);
- if (!*percent)
- break;
- fmt = percent + 1;
- switch (*fmt) {
- case '%':
+ while (strbuf_expand_step(&munged_fmt, &fmt)) {
+ if (skip_prefix(fmt, "%", &fmt))
strbuf_addstr(&munged_fmt, "%%");
- fmt++;
- break;
- case 's':
+ else if (skip_prefix(fmt, "s", &fmt))
strbuf_addf(&munged_fmt, "%"PRItime,
(timestamp_t)tm_to_time_t(tm) -
3600 * (tz_offset / 100) -
60 * (tz_offset % 100));
- fmt++;
- break;
- case 'z':
+ else if (skip_prefix(fmt, "z", &fmt))
strbuf_addf(&munged_fmt, "%+05d", tz_offset);
- fmt++;
- break;
- case 'Z':
- if (suppress_tz_name) {
- fmt++;
- break;
- }
- /* FALLTHROUGH */
- default:
+ else if (suppress_tz_name && skip_prefix(fmt, "Z", &fmt))
+ ; /* nothing */
+ else
strbuf_addch(&munged_fmt, '%');
- }
}
fmt = munged_fmt.buf;
@@ -1080,21 +976,6 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
strbuf_setlen(sb, sb->len + len);
}
-void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo,
- const struct object_id *oid, int abbrev_len)
-{
- int r;
- strbuf_grow(sb, GIT_MAX_HEXSZ + 1);
- r = repo_find_unique_abbrev_r(repo, sb->buf + sb->len, oid, abbrev_len);
- strbuf_setlen(sb, sb->len + r);
-}
-
-void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
- int abbrev_len)
-{
- strbuf_repo_add_unique_abbrev(sb, the_repository, oid, abbrev_len);
-}
-
/*
* Returns the length of a line, without trailing spaces.
*
@@ -1124,10 +1005,10 @@ static size_t cleanup(char *line, size_t len)
*
* If last line does not have a newline at the end, one is added.
*
- * Enable skip_comments to skip every line starting with comment
- * character.
+ * Pass a non-NUL comment_line_char to skip every line starting
+ * with it.
*/
-void strbuf_stripspace(struct strbuf *sb, int skip_comments)
+void strbuf_stripspace(struct strbuf *sb, char comment_line_char)
{
size_t empties = 0;
size_t i, j, len, newlen;
@@ -1140,7 +1021,8 @@ void strbuf_stripspace(struct strbuf *sb, int skip_comments)
eol = memchr(sb->buf + i, '\n', sb->len - i);
len = eol ? eol - (sb->buf + i) + 1 : sb->len - i;
- if (skip_comments && len && sb->buf[i] == comment_line_char) {
+ if (comment_line_char && len &&
+ sb->buf[i] == comment_line_char) {
newlen = 0;
continue;
}
@@ -1161,26 +1043,6 @@ void strbuf_stripspace(struct strbuf *sb, int skip_comments)
strbuf_setlen(sb, j);
}
-int strbuf_normalize_path(struct strbuf *src)
-{
- struct strbuf dst = STRBUF_INIT;
-
- strbuf_grow(&dst, src->len);
- if (normalize_path_copy(dst.buf, src->buf) < 0) {
- strbuf_release(&dst);
- return -1;
- }
-
- /*
- * normalize_path does not tell us the new length, so we have to
- * compute it by looking for the new NUL it placed
- */
- strbuf_setlen(&dst, strlen(dst.buf));
- strbuf_swap(src, &dst);
- strbuf_release(&dst);
- return 0;
-}
-
void strbuf_strip_file_from_path(struct strbuf *sb)
{
char *path_sep = find_last_dir_sep(sb->buf);
diff --git a/strbuf.h b/strbuf.h
index 3dfeadb44c..fd43c46433 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -1,6 +1,14 @@
#ifndef STRBUF_H
#define STRBUF_H
+/*
+ * NOTE FOR STRBUF DEVELOPERS
+ *
+ * strbuf is a low-level primitive; as such it should interact only
+ * with other low-level primitives. Do not introduce new functions
+ * which interact with higher-level APIs.
+ */
+
struct string_list;
/**
@@ -72,10 +80,6 @@ struct strbuf {
extern char strbuf_slopbuf[];
#define STRBUF_INIT { .buf = strbuf_slopbuf }
-/*
- * Predeclare this here, since cache.h includes this file before it defines the
- * struct.
- */
struct object_id;
/**
@@ -283,7 +287,8 @@ void strbuf_splice(struct strbuf *sb, size_t pos, size_t len,
* by a comment character and a blank.
*/
void strbuf_add_commented_lines(struct strbuf *out,
- const char *buf, size_t size);
+ const char *buf, size_t size,
+ char comment_line_char);
/**
@@ -318,58 +323,19 @@ const char *strbuf_join_argv(struct strbuf *buf, int argc,
const char **argv, char delim);
/**
- * This function can be used to expand a format string containing
- * placeholders. To that end, it parses the string and calls the specified
- * function for every percent sign found.
- *
- * The callback function is given a pointer to the character after the `%`
- * and a pointer to the struct strbuf. It is expected to add the expanded
- * version of the placeholder to the strbuf, e.g. to add a newline
- * character if the letter `n` appears after a `%`. The function returns
- * the length of the placeholder recognized and `strbuf_expand()` skips
- * over it.
- *
- * The format `%%` is automatically expanded to a single `%` as a quoting
- * mechanism; callers do not need to handle the `%` placeholder themselves,
- * and the callback function will not be invoked for this placeholder.
- *
- * All other characters (non-percent and not skipped ones) are copied
- * verbatim to the strbuf. If the callback returned zero, meaning that the
- * placeholder is unknown, then the percent sign is copied, too.
- *
- * In order to facilitate caching and to make it possible to give
- * parameters to the callback, `strbuf_expand()` passes a context
- * pointer with any kind of data.
+ * Used with `strbuf_expand_step` to expand the literals %n and %x
+ * followed by two hexadecimal digits. Returns the number of recognized
+ * characters.
*/
-typedef size_t (*expand_fn_t) (struct strbuf *sb,
- const char *placeholder,
- void *context);
-void strbuf_expand(struct strbuf *sb,
- const char *format,
- expand_fn_t fn,
- void *context);
+size_t strbuf_expand_literal(struct strbuf *sb, const char *placeholder);
/**
- * Used as callback for `strbuf_expand` to only expand literals
- * (i.e. %n and %xNN). The context argument is ignored.
+ * If the string pointed to by `formatp` contains a percent sign ("%"),
+ * advance it to point to the character following the next one and
+ * return 1, otherwise return 0. Append the substring before that
+ * percent sign to `sb`, or the whole string if there is none.
*/
-size_t strbuf_expand_literal_cb(struct strbuf *sb,
- const char *placeholder,
- void *context);
-
-/**
- * Used as callback for `strbuf_expand()`, expects an array of
- * struct strbuf_expand_dict_entry as context, i.e. pairs of
- * placeholder and replacement string. The array needs to be
- * terminated by an entry with placeholder set to NULL.
- */
-struct strbuf_expand_dict_entry {
- const char *placeholder;
- const char *value;
-};
-size_t strbuf_expand_dict_cb(struct strbuf *sb,
- const char *placeholder,
- void *context);
+int strbuf_expand_step(struct strbuf *sb, const char **formatp);
/**
* Append the contents of one strbuf to another, quoting any
@@ -412,8 +378,8 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
* Add a formatted string prepended by a comment character and a
* blank to the buffer.
*/
-__attribute__((format (printf, 2, 3)))
-void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...);
+__attribute__((format (printf, 3, 4)))
+void strbuf_commented_addf(struct strbuf *sb, char comment_line_char, const char *fmt, ...);
__attribute__((format (printf,2,0)))
void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap);
@@ -476,6 +442,18 @@ int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint);
ssize_t strbuf_write(struct strbuf *sb, FILE *stream);
/**
+ * Read from a FILE * until the specified terminator is encountered,
+ * overwriting the existing contents of the strbuf.
+ *
+ * Reading stops after the terminator or at EOF. The terminator is
+ * removed from the buffer before returning. If the terminator is LF
+ * and if it is preceded by a CR, then the whole CRLF is stripped.
+ * Returns 0 unless there was nothing left before EOF, in which case
+ * it returns `EOF`.
+ */
+int strbuf_getdelim_strip_crlf(struct strbuf *sb, FILE *fp, int term);
+
+/**
* Read a line from a FILE *, overwriting the existing contents of
* the strbuf. The strbuf_getline*() family of functions share
* this signature, but have different line termination conventions.
@@ -528,28 +506,6 @@ int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term);
int strbuf_getcwd(struct strbuf *sb);
/**
- * Add a path to a buffer, converting a relative path to an
- * absolute one in the process. Symbolic links are not
- * resolved.
- */
-void strbuf_add_absolute_path(struct strbuf *sb, const char *path);
-
-/**
- * Canonize `path` (make it absolute, resolve symlinks, remove extra
- * slashes) and append it to `sb`. Die with an informative error
- * message if there is a problem.
- *
- * The directory part of `path` (i.e., everything up to the last
- * dir_sep) must denote a valid, existing directory, but the last
- * component need not exist.
- *
- * Callers that don't mind links should use the more lightweight
- * strbuf_add_absolute_path() instead.
- */
-void strbuf_add_real_path(struct strbuf *sb, const char *path);
-
-
-/**
* Normalize in-place the path contained in the strbuf. See
* normalize_path_copy() for details. If an error occurs, the contents of "sb"
* are left untouched, and -1 is returned.
@@ -557,10 +513,11 @@ void strbuf_add_real_path(struct strbuf *sb, const char *path);
int strbuf_normalize_path(struct strbuf *sb);
/**
- * Strip whitespace from a buffer. The second parameter controls if
- * comments are considered contents to be removed or not.
+ * Strip whitespace from a buffer. If comment_line_char is non-NUL,
+ * then lines beginning with that character are considered comments,
+ * thus removed.
*/
-void strbuf_stripspace(struct strbuf *buf, int skip_comments);
+void strbuf_stripspace(struct strbuf *buf, char comment_line_char);
static inline int strbuf_strip_suffix(struct strbuf *sb, const char *suffix)
{
@@ -630,16 +587,6 @@ void strbuf_add_separated_string_list(struct strbuf *str,
*/
void strbuf_list_free(struct strbuf **list);
-/**
- * Add the abbreviation, as generated by repo_find_unique_abbrev(), of `sha1` to
- * the strbuf `sb`.
- */
-struct repository;
-void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo,
- const struct object_id *oid, int abbrev_len);
-void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
- int abbrev_len);
-
/*
* Remove the filename from the provided path string. If the path
* contains a trailing separator, then the path is considered a directory
@@ -704,9 +651,6 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name);
typedef int (*char_predicate)(char ch);
-int is_rfc3986_unreserved(char ch);
-int is_rfc3986_reserved_or_unreserved(char ch);
-
void strbuf_addstr_urlencode(struct strbuf *sb, const char *name,
char_predicate allow_unencoded_fn);
@@ -727,4 +671,36 @@ char *xstrvfmt(const char *fmt, va_list ap);
__attribute__((format (printf, 1, 2)))
char *xstrfmt(const char *fmt, ...);
+int starts_with(const char *str, const char *prefix);
+int istarts_with(const char *str, const char *prefix);
+
+/*
+ * If the string "str" is the same as the string in "prefix", then the "arg"
+ * parameter is set to the "def" parameter and 1 is returned.
+ * If the string "str" begins with the string found in "prefix" and then a
+ * "=" sign, then the "arg" parameter is set to "str + strlen(prefix) + 1"
+ * (i.e., to the point in the string right after the prefix and the "=" sign),
+ * and 1 is returned.
+ *
+ * Otherwise, return 0 and leave "arg" untouched.
+ *
+ * When we accept both a "--key" and a "--key=<val>" option, this function
+ * can be used instead of !strcmp(arg, "--key") and then
+ * skip_prefix(arg, "--key=", &arg) to parse such an option.
+ */
+int skip_to_optional_arg_default(const char *str, const char *prefix,
+ const char **arg, const char *def);
+
+static inline int skip_to_optional_arg(const char *str, const char *prefix,
+ const char **arg)
+{
+ return skip_to_optional_arg_default(str, prefix, arg, "");
+}
+
+static inline int ends_with(const char *str, const char *suffix)
+{
+ size_t len;
+ return strip_suffix(str, suffix, &len);
+}
+
#endif /* STRBUF_H */
diff --git a/streaming.c b/streaming.c
index 21e39585e8..10adf625b2 100644
--- a/streaming.c
+++ b/streaming.c
@@ -7,10 +7,9 @@
#include "streaming.h"
#include "repository.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "replace-object.h"
#include "packfile.h"
-#include "wrapper.h"
typedef int (*open_istream_fn)(struct git_istream *,
struct repository *,
diff --git a/string-list.c b/string-list.c
index 0f8ac117fd..954569f381 100644
--- a/string-list.c
+++ b/string-list.c
@@ -1,6 +1,5 @@
#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 17d54b6c3b..89dc9e7e75 100644
--- a/strvec.c
+++ b/strvec.c
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "strvec.h"
-#include "alloc.h"
#include "hex.h"
#include "strbuf.h"
diff --git a/submodule-config.c b/submodule-config.c
index 58dfbde9ae..6a48fd12f6 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -1,16 +1,16 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "dir.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
+#include "path.h"
#include "repository.h"
#include "config.h"
#include "submodule-config.h"
#include "submodule.h"
#include "strbuf.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "parse-options.h"
#include "thread-utils.h"
#include "tree-walk.h"
@@ -304,9 +304,10 @@ static int parse_fetch_recurse(const char *opt, const char *arg,
}
}
-int parse_submodule_fetchjobs(const char *var, const char *value)
+int parse_submodule_fetchjobs(const char *var, const char *value,
+ const struct key_value_info *kvi)
{
- int fetchjobs = git_config_int(var, value);
+ int fetchjobs = git_config_int(var, value, kvi);
if (fetchjobs < 0)
die(_("negative values not allowed for submodule.fetchJobs"));
if (!fetchjobs)
@@ -426,7 +427,8 @@ struct parse_config_parameter {
* config store (.git/config, etc). Callers are responsible for
* checking for overrides in the main config store when appropriate.
*/
-static int parse_config(const char *var, const char *value, void *data)
+static int parse_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED, void *data)
{
struct parse_config_parameter *me = data;
struct submodule *submodule;
@@ -605,7 +607,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
parameter.gitmodules_oid = &oid;
parameter.overwrite = 0;
git_config_from_mem(parse_config, CONFIG_ORIGIN_SUBMODULE_BLOB, rev.buf,
- config, config_size, &parameter, NULL);
+ config, config_size, &parameter, CONFIG_SCOPE_UNKNOWN, NULL);
strbuf_release(&rev);
free(config);
@@ -659,7 +661,6 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
config_source.file = file;
} else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 ||
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
- config_source.repo = repo;
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
if (repo != the_repository)
add_submodule_odb_by_path(repo->objects->odb->path);
@@ -667,7 +668,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
goto out;
}
- config_with_options(fn, data, &config_source, &opts);
+ config_with_options(fn, data, &config_source, repo, &opts);
out:
free(oidstr);
@@ -675,7 +676,8 @@ out:
}
}
-static int gitmodules_cb(const char *var, const char *value, void *data)
+static int gitmodules_cb(const char *var, const char *value,
+ const struct config_context *ctx, void *data)
{
struct repository *repo = data;
struct parse_config_parameter parameter;
@@ -685,7 +687,7 @@ static int gitmodules_cb(const char *var, const char *value, void *data)
parameter.gitmodules_oid = null_oid();
parameter.overwrite = 1;
- return parse_config(var, value, &parameter);
+ return parse_config(var, value, ctx, &parameter);
}
void repo_read_gitmodules(struct repository *repo, int skip_if_read)
@@ -713,7 +715,8 @@ void gitmodules_config_oid(const struct object_id *commit_oid)
if (gitmodule_oid_from_commit(commit_oid, &oid, &rev)) {
git_config_from_blob_oid(gitmodules_cb, rev.buf,
- the_repository, &oid, the_repository);
+ the_repository, &oid, the_repository,
+ CONFIG_SCOPE_UNKNOWN);
}
strbuf_release(&rev);
@@ -802,7 +805,9 @@ void submodule_free(struct repository *r)
submodule_cache_clear(r->submodule_cache);
}
-static int config_print_callback(const char *var, const char *value, void *cb_data)
+static int config_print_callback(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb_data)
{
char *wanted_key = cb_data;
@@ -844,13 +849,15 @@ struct fetch_config {
int *recurse_submodules;
};
-static int gitmodules_fetch_config(const char *var, const char *value, void *cb)
+static int gitmodules_fetch_config(const char *var, const char *value,
+ const struct config_context *ctx,
+ void *cb)
{
struct fetch_config *config = cb;
if (!strcmp(var, "submodule.fetchjobs")) {
if (config->max_children)
*(config->max_children) =
- parse_submodule_fetchjobs(var, value);
+ parse_submodule_fetchjobs(var, value, ctx->kvi);
return 0;
} else if (!strcmp(var, "fetch.recursesubmodules")) {
if (config->recurse_submodules)
@@ -872,11 +879,12 @@ void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules)
}
static int gitmodules_update_clone_config(const char *var, const char *value,
+ const struct config_context *ctx,
void *cb)
{
int *max_jobs = cb;
if (!strcmp(var, "submodule.fetchjobs"))
- *max_jobs = parse_submodule_fetchjobs(var, value);
+ *max_jobs = parse_submodule_fetchjobs(var, value, ctx->kvi);
return 0;
}
diff --git a/submodule-config.h b/submodule-config.h
index c2045875bb..2a37689cc2 100644
--- a/submodule-config.h
+++ b/submodule-config.h
@@ -50,7 +50,8 @@ struct repository;
void submodule_cache_free(struct submodule_cache *cache);
-int parse_submodule_fetchjobs(const char *var, const char *value);
+int parse_submodule_fetchjobs(const char *var, const char *value,
+ const struct key_value_info *kvi);
int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg);
struct option;
int option_fetch_parse_recurse_submodules(const struct option *opt,
diff --git a/submodule.c b/submodule.c
index 2e78f51349..e603a19a87 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1,6 +1,5 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "repository.h"
#include "config.h"
#include "submodule-config.h"
@@ -20,14 +19,16 @@
#include "strvec.h"
#include "blob.h"
#include "thread-utils.h"
+#include "path.h"
#include "quote.h"
#include "remote.h"
#include "worktree.h"
#include "parse-options.h"
#include "object-file.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "commit-reach.h"
+#include "read-cache-ll.h"
#include "setup.h"
#include "shallow.h"
#include "trace2.h"
diff --git a/t/README b/t/README
index bdfac4cceb..6108085989 100644
--- a/t/README
+++ b/t/README
@@ -442,6 +442,10 @@ GIT_TEST_INDEX_VERSION=<n> exercises the index read/write code path
for the index version specified. Can be set to any valid version
(currently 2, 3, or 4).
+GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL=<boolean> if enabled will
+use the boundary-based bitmap traversal algorithm. See the documentation
+of `pack.useBitmapBoundaryTraversal` for more details.
+
GIT_TEST_PACK_SPARSE=<boolean> if disabled will default the pack-objects
builtin to use the non-sparse object walk. This can still be overridden by
the --sparse command-line argument.
@@ -1098,6 +1102,12 @@ see test-lib-functions.sh for the full list and their options.
the symbolic link in the file system and a part that does; then only
the latter part need be protected by a SYMLINKS prerequisite (see below).
+ - test_path_is_executable
+
+ This tests whether a file is executable and prints an error message
+ if not. This must be used only under the POSIXPERM prerequisite
+ (see below).
+
- test_oid_init
This function loads facts and useful object IDs related to the hash
diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh
index 2ef70235b1..5e21e84f38 100644
--- a/t/annotate-tests.sh
+++ b/t/annotate-tests.sh
@@ -83,6 +83,15 @@ test_expect_success 'blame with --contents' '
check_count --contents=file A 2
'
+test_expect_success 'blame with --contents in a bare repo' '
+ git clone --bare . bare-contents.git &&
+ (
+ cd bare-contents.git &&
+ echo "1A quick brown fox jumps over the" >contents &&
+ check_count --contents=contents A 1
+ )
+'
+
test_expect_success 'blame with --contents changed' '
echo "1A quick brown fox jumps over the" >contents &&
echo "another lazy dog" >>contents &&
diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c
index 9507b356e2..e7236392c8 100644
--- a/t/helper/test-cache-tree.c
+++ b/t/helper/test-cache-tree.c
@@ -1,11 +1,11 @@
#define USE_THE_INDEX_VARIABLE
#include "test-tool.h"
-#include "cache.h"
#include "gettext.h"
#include "hex.h"
#include "tree.h"
#include "cache-tree.h"
#include "parse-options.h"
+#include "read-cache-ll.h"
#include "repository.h"
#include "setup.h"
diff --git a/t/helper/test-config.c b/t/helper/test-config.c
index ad78fc1768..ed444ca4c2 100644
--- a/t/helper/test-config.c
+++ b/t/helper/test-config.c
@@ -42,8 +42,11 @@
*
*/
-static int iterate_cb(const char *var, const char *value, void *data UNUSED)
+static int iterate_cb(const char *var, const char *value,
+ const struct config_context *ctx,
+ void *data UNUSED)
{
+ const struct key_value_info *kvi = ctx->kvi;
static int nr;
if (nr++)
@@ -51,26 +54,29 @@ static int iterate_cb(const char *var, const char *value, void *data UNUSED)
printf("key=%s\n", var);
printf("value=%s\n", value ? value : "(null)");
- printf("origin=%s\n", current_config_origin_type());
- printf("name=%s\n", current_config_name());
- printf("lno=%d\n", current_config_line());
- printf("scope=%s\n", config_scope_name(current_config_scope()));
+ printf("origin=%s\n", config_origin_type_name(kvi->origin_type));
+ printf("name=%s\n", kvi->filename ? kvi->filename : "");
+ printf("lno=%d\n", kvi->linenr);
+ printf("scope=%s\n", config_scope_name(kvi->scope));
return 0;
}
-static int parse_int_cb(const char *var, const char *value, void *data)
+static int parse_int_cb(const char *var, const char *value,
+ const struct config_context *ctx, void *data)
{
const char *key_to_match = data;
if (!strcmp(key_to_match, var)) {
- int parsed = git_config_int(value, value);
+ int parsed = git_config_int(value, value, ctx->kvi);
printf("%d\n", parsed);
}
return 0;
}
-static int early_config_cb(const char *var, const char *value, void *vdata)
+static int early_config_cb(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *vdata)
{
const char *key = vdata;
@@ -176,7 +182,7 @@ int cmd__config(int argc, const char **argv)
goto exit2;
}
}
- if (!git_configset_get_value(&cs, argv[2], &v)) {
+ if (!git_configset_get_value(&cs, argv[2], &v, NULL)) {
if (!v)
printf("(NULL)\n");
else
diff --git a/t/helper/test-delta.c b/t/helper/test-delta.c
index e7d134ec25..6bc787a474 100644
--- a/t/helper/test-delta.c
+++ b/t/helper/test-delta.c
@@ -11,7 +11,6 @@
#include "test-tool.h"
#include "git-compat-util.h"
#include "delta.h"
-#include "wrapper.h"
static const char usage_str[] =
"test-tool delta (-d|-p) <from_file> <data_file> <out_file>";
diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c
index f22f7bd84a..c38f546e4f 100644
--- a/t/helper/test-dump-cache-tree.c
+++ b/t/helper/test-dump-cache-tree.c
@@ -1,10 +1,10 @@
#define USE_THE_INDEX_VARIABLE
#include "test-tool.h"
-#include "cache.h"
#include "hash.h"
#include "hex.h"
#include "tree.h"
#include "cache-tree.h"
+#include "read-cache-ll.h"
#include "repository.h"
#include "setup.h"
diff --git a/t/helper/test-dump-fsmonitor.c b/t/helper/test-dump-fsmonitor.c
index 9a098a25cb..4f215fea02 100644
--- a/t/helper/test-dump-fsmonitor.c
+++ b/t/helper/test-dump-fsmonitor.c
@@ -1,5 +1,5 @@
#include "test-tool.h"
-#include "cache.h"
+#include "read-cache-ll.h"
#include "repository.h"
#include "setup.h"
diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c
index d1badd7112..f29d18ef94 100644
--- a/t/helper/test-dump-split-index.c
+++ b/t/helper/test-dump-split-index.c
@@ -1,12 +1,13 @@
#define USE_THE_INDEX_VARIABLE
#include "test-tool.h"
-#include "cache.h"
#include "hex.h"
+#include "read-cache-ll.h"
+#include "repository.h"
#include "setup.h"
#include "split-index.h"
#include "ewah/ewok.h"
-static void show_bit(size_t pos, void *data)
+static void show_bit(size_t pos, void *data UNUSED)
{
printf(" %d", (int)pos);
}
diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c
index df70be549f..b4af9712fe 100644
--- a/t/helper/test-dump-untracked-cache.c
+++ b/t/helper/test-dump-untracked-cache.c
@@ -1,8 +1,8 @@
#define USE_THE_INDEX_VARIABLE
#include "test-tool.h"
-#include "cache.h"
#include "dir.h"
#include "hex.h"
+#include "read-cache-ll.h"
#include "repository.h"
#include "setup.h"
diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c
index d1d63feaa9..cac20a72b3 100644
--- a/t/helper/test-fast-rebase.c
+++ b/t/helper/test-fast-rebase.c
@@ -12,15 +12,16 @@
#define USE_THE_INDEX_VARIABLE
#include "test-tool.h"
-#include "cache.h"
#include "cache-tree.h"
#include "commit.h"
#include "environment.h"
#include "gettext.h"
+#include "hash.h"
#include "hex.h"
#include "lockfile.h"
#include "merge-ort.h"
#include "object-name.h"
+#include "read-cache-ll.h"
#include "refs.h"
#include "revision.h"
#include "sequencer.h"
diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c
index 9f18c685b7..8280984d08 100644
--- a/t/helper/test-fsmonitor-client.c
+++ b/t/helper/test-fsmonitor-client.c
@@ -4,14 +4,13 @@
*/
#include "test-tool.h"
-#include "cache.h"
#include "parse-options.h"
#include "fsmonitor-ipc.h"
+#include "read-cache-ll.h"
#include "repository.h"
#include "setup.h"
#include "thread-utils.h"
#include "trace2.h"
-#include "wrapper.h"
#ifndef HAVE_FSMONITOR_DAEMON_BACKEND
int cmd__fsmonitor_client(int argc UNUSED, const char **argv UNUSED)
diff --git a/t/helper/test-hash-speed.c b/t/helper/test-hash-speed.c
index f40d9ad0c2..b235da594f 100644
--- a/t/helper/test-hash-speed.c
+++ b/t/helper/test-hash-speed.c
@@ -1,5 +1,5 @@
#include "test-tool.h"
-#include "cache.h"
+#include "hash-ll.h"
#define NUM_SECONDS 3
diff --git a/t/helper/test-index-version.c b/t/helper/test-index-version.c
index a06c45c1f8..f3c2dbe0a2 100644
--- a/t/helper/test-index-version.c
+++ b/t/helper/test-index-version.c
@@ -1,5 +1,5 @@
#include "test-tool.h"
-#include "cache.h"
+#include "read-cache-ll.h"
int cmd__index_version(int argc UNUSED, const char **argv UNUSED)
{
diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c
index b83a75d19f..187a115d57 100644
--- a/t/helper/test-lazy-init-name-hash.c
+++ b/t/helper/test-lazy-init-name-hash.c
@@ -1,8 +1,9 @@
#define USE_THE_INDEX_VARIABLE
#include "test-tool.h"
-#include "cache.h"
#include "environment.h"
+#include "name-hash.h"
#include "parse-options.h"
+#include "read-cache-ll.h"
#include "repository.h"
#include "setup.h"
#include "trace.h"
diff --git a/t/helper/test-oid-array.c b/t/helper/test-oid-array.c
index eef68833b7..aafe398ef0 100644
--- a/t/helper/test-oid-array.c
+++ b/t/helper/test-oid-array.c
@@ -4,7 +4,7 @@
#include "setup.h"
#include "strbuf.h"
-static int print_oid(const struct object_id *oid, void *data)
+static int print_oid(const struct object_id *oid, void *data UNUSED)
{
puts(oid_to_hex(oid));
return 0;
diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c
index 0f3fbeec53..67a964ef90 100644
--- a/t/helper/test-pack-mtimes.c
+++ b/t/helper/test-pack-mtimes.c
@@ -1,7 +1,7 @@
#include "test-tool.h"
#include "hex.h"
#include "strbuf.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "packfile.h"
#include "pack-mtimes.h"
#include "setup.h"
diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c
index 00fa281a9c..a4f6e24b0c 100644
--- a/t/helper/test-parse-options.c
+++ b/t/helper/test-parse-options.c
@@ -133,6 +133,8 @@ int cmd__parse_options(int argc, const char **argv)
OPT_STRING(0, "st", &string, "st", "get another string (pervert ordering)"),
OPT_STRING('o', NULL, &string, "str", "get another string"),
OPT_NOOP_NOARG(0, "obsolete"),
+ OPT_SET_INT_F(0, "longhelp", &integer, "help text of this entry\n"
+ "spans multiple lines", 0, PARSE_OPT_NONEG),
OPT_STRING_LIST(0, "list", &list, "str", "add str to list"),
OPT_GROUP("Magic arguments"),
OPT_NUMBER_CALLBACK(&integer, "set integer to NUM",
diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c
index 362bd64a4c..910a128614 100644
--- a/t/helper/test-partial-clone.c
+++ b/t/helper/test-partial-clone.c
@@ -1,7 +1,7 @@
#include "test-tool.h"
#include "hex.h"
#include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "setup.h"
/*
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index 2ef53d5f7a..70396fa384 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -1,8 +1,8 @@
#include "test-tool.h"
-#include "cache.h"
#include "abspath.h"
#include "environment.h"
#include "path.h"
+#include "read-cache-ll.h"
#include "setup.h"
#include "string-list.h"
#include "trace.h"
diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c
index 5b6f217441..3e173399a0 100644
--- a/t/helper/test-reach.c
+++ b/t/helper/test-reach.c
@@ -1,5 +1,4 @@
#include "test-tool.h"
-#include "alloc.h"
#include "commit.h"
#include "commit-reach.h"
#include "config.h"
@@ -139,7 +138,7 @@ int cmd__reach(int ac, const char **av)
printf("%s(X,_,_,0,0):%d\n", av[1], can_all_from_reach_with_flag(&X_obj, 2, 4, 0, 0));
} else if (!strcmp(av[1], "commit_contains")) {
- struct ref_filter filter;
+ struct ref_filter filter = REF_FILTER_INIT;
struct contains_cache cache;
init_contains_cache(&cache);
diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index c1ae276395..1acd362346 100644
--- a/t/helper/test-read-cache.c
+++ b/t/helper/test-read-cache.c
@@ -1,10 +1,9 @@
#define USE_THE_INDEX_VARIABLE
#include "test-tool.h"
-#include "cache.h"
#include "config.h"
+#include "read-cache-ll.h"
#include "repository.h"
#include "setup.h"
-#include "wrapper.h"
int cmd__read_cache(int argc, const char **argv)
{
diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 3ac496e27e..8c7a83f578 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -1,7 +1,7 @@
#include "test-tool.h"
#include "commit-graph.h"
#include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "bloom.h"
#include "setup.h"
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index 211addaa00..e9a444ddba 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -2,7 +2,7 @@
#include "hex.h"
#include "midx.h"
#include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "pack-bitmap.h"
#include "packfile.h"
#include "setup.h"
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 6d8f844e9c..48552e6a9e 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -3,8 +3,11 @@
#include "refs.h"
#include "setup.h"
#include "worktree.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "path.h"
#include "repository.h"
+#include "strbuf.h"
+#include "revision.h"
struct flag_definition {
const char *name;
@@ -116,8 +119,16 @@ static struct flag_definition pack_flags[] = { FLAG_DEF(PACK_REFS_PRUNE),
static int cmd_pack_refs(struct ref_store *refs, const char **argv)
{
unsigned int flags = arg_flags(*argv++, "flags", pack_flags);
+ static struct ref_exclusions exclusions = REF_EXCLUSIONS_INIT;
+ static struct string_list included_refs = STRING_LIST_INIT_NODUP;
+ struct pack_refs_opts pack_opts = { .flags = flags,
+ .exclusions = &exclusions,
+ .includes = &included_refs };
- return refs_pack_refs(refs, flags);
+ if (pack_opts.flags & PACK_REFS_ALL)
+ string_list_append(pack_opts.includes, "*");
+
+ return refs_pack_refs(refs, &pack_opts);
}
static int cmd_create_symref(struct ref_store *refs, const char **argv)
@@ -175,6 +186,15 @@ static int cmd_for_each_ref(struct ref_store *refs, const char **argv)
return refs_for_each_ref_in(refs, prefix, each_ref, NULL);
}
+static int cmd_for_each_ref__exclude(struct ref_store *refs, const char **argv)
+{
+ const char *prefix = notnull(*argv++, "prefix");
+ const char **exclude_patterns = argv;
+
+ return refs_for_each_fullref_in(refs, prefix, exclude_patterns, each_ref,
+ NULL);
+}
+
static int cmd_resolve_ref(struct ref_store *refs, const char **argv)
{
struct object_id oid = *null_oid();
@@ -257,11 +277,6 @@ static int cmd_delete_reflog(struct ref_store *refs, const char **argv)
return refs_delete_reflog(refs, refname);
}
-static int cmd_reflog_expire(struct ref_store *refs, const char **argv)
-{
- die("not supported yet");
-}
-
static int cmd_delete_ref(struct ref_store *refs, const char **argv)
{
const char *msg = notnull(*argv++, "msg");
@@ -307,6 +322,7 @@ static struct command commands[] = {
{ "delete-refs", cmd_delete_refs },
{ "rename-ref", cmd_rename_ref },
{ "for-each-ref", cmd_for_each_ref },
+ { "for-each-ref--exclude", cmd_for_each_ref__exclude },
{ "resolve-ref", cmd_resolve_ref },
{ "verify-ref", cmd_verify_ref },
{ "for-each-reflog", cmd_for_each_reflog },
@@ -315,7 +331,6 @@ static struct command commands[] = {
{ "reflog-exists", cmd_reflog_exists },
{ "create-reflog", cmd_create_reflog },
{ "delete-reflog", cmd_delete_reflog },
- { "reflog-expire", cmd_reflog_expire },
/*
* backend transaction functions can't be tested separately
*/
diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c
index bafd2a5bf9..4cd8a952e5 100644
--- a/t/helper/test-repository.c
+++ b/t/helper/test-repository.c
@@ -4,7 +4,7 @@
#include "config.h"
#include "environment.h"
#include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "object.h"
#include "repository.h"
#include "setup.h"
diff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c
index 0c62b9de18..f346951bc2 100644
--- a/t/helper/test-revision-walking.c
+++ b/t/helper/test-revision-walking.c
@@ -11,6 +11,7 @@
#include "test-tool.h"
#include "commit.h"
#include "diff.h"
+#include "repository.h"
#include "revision.h"
#include "setup.h"
diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c
index 6e17f50d22..0a816a96e2 100644
--- a/t/helper/test-scrap-cache-tree.c
+++ b/t/helper/test-scrap-cache-tree.c
@@ -1,7 +1,7 @@
#define USE_THE_INDEX_VARIABLE
#include "test-tool.h"
-#include "cache.h"
#include "lockfile.h"
+#include "read-cache-ll.h"
#include "repository.h"
#include "setup.h"
#include "tree.h"
diff --git a/t/helper/test-sha1.c b/t/helper/test-sha1.c
index 71fe5c6145..dcb7f6c003 100644
--- a/t/helper/test-sha1.c
+++ b/t/helper/test-sha1.c
@@ -1,5 +1,5 @@
#include "test-tool.h"
-#include "cache.h"
+#include "hash-ll.h"
int cmd__sha1(int ac, const char **av)
{
diff --git a/t/helper/test-sha256.c b/t/helper/test-sha256.c
index 0ac6a99d5f..08cf149001 100644
--- a/t/helper/test-sha256.c
+++ b/t/helper/test-sha256.c
@@ -1,5 +1,5 @@
#include "test-tool.h"
-#include "cache.h"
+#include "hash-ll.h"
int cmd__sha256(int ac, const char **av)
{
diff --git a/t/helper/test-strcmp-offset.c b/t/helper/test-strcmp-offset.c
index 96b9a5b529..d8473cf2fc 100644
--- a/t/helper/test-strcmp-offset.c
+++ b/t/helper/test-strcmp-offset.c
@@ -1,5 +1,5 @@
#include "test-tool.h"
-#include "cache.h"
+#include "read-cache-ll.h"
int cmd__strcmp_offset(int argc UNUSED, const char **argv)
{
diff --git a/t/helper/test-userdiff.c b/t/helper/test-userdiff.c
index 680124a676..0ce31ce59f 100644
--- a/t/helper/test-userdiff.c
+++ b/t/helper/test-userdiff.c
@@ -12,7 +12,9 @@ static int driver_cb(struct userdiff_driver *driver,
return 0;
}
-static int cmd__userdiff_config(const char *var, const char *value, void *cb UNUSED)
+static int cmd__userdiff_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb UNUSED)
{
if (userdiff_config(var, value) < 0)
return -1;
diff --git a/t/helper/test-wildmatch.c b/t/helper/test-wildmatch.c
index a95bb4da9b..b4ff5f986a 100644
--- a/t/helper/test-wildmatch.c
+++ b/t/helper/test-wildmatch.c
@@ -1,4 +1,5 @@
#include "test-tool.h"
+#include "wildmatch.h"
int cmd__wildmatch(int argc, const char **argv)
{
diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c
index eace08072d..f084034d38 100644
--- a/t/helper/test-write-cache.c
+++ b/t/helper/test-write-cache.c
@@ -1,7 +1,7 @@
#define USE_THE_INDEX_VARIABLE
#include "test-tool.h"
-#include "cache.h"
#include "lockfile.h"
+#include "read-cache-ll.h"
#include "repository.h"
#include "setup.h"
diff --git a/t/lib-commit-graph.sh b/t/lib-commit-graph.sh
index 5d79e1a4e9..89b26676fb 100755
--- a/t/lib-commit-graph.sh
+++ b/t/lib-commit-graph.sh
@@ -14,24 +14,37 @@ graph_git_two_modes() {
test_cmp expect output
}
+# graph_git_behavior <name> <directory> <branch> <compare>
+#
+# Ensures that a handful of traversal operations produce the same
+# results with and without the commit-graph in use.
+#
+# NOTE: it is a bug to call this function with <directory> containing
+# any characters in $IFS.
graph_git_behavior() {
MSG=$1
DIR=$2
BRANCH=$3
COMPARE=$4
test_expect_success "check normal git operations: $MSG" '
- cd "$TRASH_DIRECTORY/$DIR" &&
- graph_git_two_modes "log --oneline $BRANCH" &&
- graph_git_two_modes "log --topo-order $BRANCH" &&
- graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
- graph_git_two_modes "branch -vv" &&
- graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
+ graph_git_two_modes "${DIR:+-C $DIR} log --oneline $BRANCH" &&
+ graph_git_two_modes "${DIR:+-C $DIR} log --topo-order $BRANCH" &&
+ graph_git_two_modes "${DIR:+-C $DIR} log --graph $COMPARE..$BRANCH" &&
+ graph_git_two_modes "${DIR:+-C $DIR} branch -vv" &&
+ graph_git_two_modes "${DIR:+-C $DIR} merge-base -a $BRANCH $COMPARE"
'
}
graph_read_expect() {
OPTIONAL=""
NUM_CHUNKS=3
+ DIR="."
+ if test "$1" = -C
+ then
+ shift
+ DIR="$1"
+ shift
+ fi
if test -n "$2"
then
OPTIONAL=" $2"
@@ -47,12 +60,15 @@ graph_read_expect() {
then
OPTIONS=" read_generation_data"
fi
- cat >expect <<- EOF
+ cat >"$DIR/expect" <<-EOF
header: 43475048 1 $(test_oid oid_version) $NUM_CHUNKS 0
num_commits: $1
chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
options:$OPTIONS
EOF
- test-tool read-graph >output &&
- test_cmp expect output
+ (
+ cd "$DIR" &&
+ test-tool read-graph >output &&
+ test_cmp expect output
+ )
}
diff --git a/t/lib-credential.sh b/t/lib-credential.sh
index f1ab92ba35..032b2d8fcc 100644
--- a/t/lib-credential.sh
+++ b/t/lib-credential.sh
@@ -44,6 +44,10 @@ helper_test_clean() {
reject $1 https example.com user1
reject $1 https example.com user2
reject $1 https example.com user4
+ reject $1 https example.com user-distinct-pass
+ reject $1 https example.com user-overwrite
+ reject $1 https example.com user-erase1
+ reject $1 https example.com user-erase2
reject $1 http path.tld user
reject $1 https timeout.tld user
reject $1 https sso.tld
@@ -167,6 +171,49 @@ helper_test() {
EOF
'
+ test_expect_success "helper ($HELPER) overwrites on store" '
+ check approve $HELPER <<-\EOF &&
+ protocol=https
+ host=example.com
+ username=user-overwrite
+ password=pass1
+ EOF
+ check approve $HELPER <<-\EOF &&
+ protocol=https
+ host=example.com
+ username=user-overwrite
+ password=pass2
+ EOF
+ check fill $HELPER <<-\EOF &&
+ protocol=https
+ host=example.com
+ username=user-overwrite
+ --
+ protocol=https
+ host=example.com
+ username=user-overwrite
+ password=pass2
+ EOF
+ check reject $HELPER <<-\EOF &&
+ protocol=https
+ host=example.com
+ username=user-overwrite
+ password=pass2
+ EOF
+ check fill $HELPER <<-\EOF
+ protocol=https
+ host=example.com
+ username=user-overwrite
+ --
+ protocol=https
+ host=example.com
+ username=user-overwrite
+ password=askpass-password
+ --
+ askpass: Password for '\''https://user-overwrite@example.com'\'':
+ EOF
+ '
+
test_expect_success "helper ($HELPER) can forget host" '
check reject $HELPER <<-\EOF &&
protocol=https
@@ -221,6 +268,31 @@ helper_test() {
EOF
'
+ test_expect_success "helper ($HELPER) does not erase a password distinct from input" '
+ check approve $HELPER <<-\EOF &&
+ protocol=https
+ host=example.com
+ username=user-distinct-pass
+ password=pass1
+ EOF
+ check reject $HELPER <<-\EOF &&
+ protocol=https
+ host=example.com
+ username=user-distinct-pass
+ password=pass2
+ EOF
+ check fill $HELPER <<-\EOF
+ protocol=https
+ host=example.com
+ username=user-distinct-pass
+ --
+ protocol=https
+ host=example.com
+ username=user-distinct-pass
+ password=pass1
+ EOF
+ '
+
test_expect_success "helper ($HELPER) can forget user" '
check reject $HELPER <<-\EOF &&
protocol=https
@@ -272,6 +344,37 @@ helper_test() {
EOF
'
+ test_expect_success "helper ($HELPER) erases all matching credentials" '
+ check approve $HELPER <<-\EOF &&
+ protocol=https
+ host=example.com
+ username=user-erase1
+ password=pass1
+ EOF
+ check approve $HELPER <<-\EOF &&
+ protocol=https
+ host=example.com
+ username=user-erase2
+ password=pass1
+ EOF
+ check reject $HELPER <<-\EOF &&
+ protocol=https
+ host=example.com
+ EOF
+ check fill $HELPER <<-\EOF
+ protocol=https
+ host=example.com
+ --
+ protocol=https
+ host=example.com
+ username=askpass-username
+ password=askpass-password
+ --
+ askpass: Username for '\''https://example.com'\'':
+ askpass: Password for '\''https://askpass-username@example.com'\'':
+ EOF
+ '
+
: ${GIT_TEST_LONG_CRED_BUFFER:=1024}
# 23 bytes accounts for "wwwauth[]=basic realm=" plus NUL
LONG_VALUE_LEN=$((GIT_TEST_LONG_CRED_BUFFER - 23))
diff --git a/t/lib-gpg.sh b/t/lib-gpg.sh
index 114785586a..4eebd9c2b5 100644
--- a/t/lib-gpg.sh
+++ b/t/lib-gpg.sh
@@ -51,6 +51,27 @@ test_lazy_prereq GPG '
esac
'
+test_lazy_prereq GPG2 '
+ gpg_version=$(gpg --version 2>&1)
+ test $? != 127 || exit 1
+
+ case "$gpg_version" in
+ "gpg (GnuPG) "[01].*)
+ say "This test requires a GPG version >= v2.0.0"
+ exit 1
+ ;;
+ *)
+ (gpgconf --kill all || : ) &&
+ gpg --homedir "${GNUPGHOME}" --import \
+ "$TEST_DIRECTORY"/lib-gpg/keyring.gpg &&
+ gpg --homedir "${GNUPGHOME}" --import-ownertrust \
+ "$TEST_DIRECTORY"/lib-gpg/ownertrust &&
+ gpg --homedir "${GNUPGHOME}" </dev/null >/dev/null \
+ --sign -u committer@example.com
+ ;;
+ esac
+'
+
test_lazy_prereq GPGSM '
test_have_prereq GPG &&
# Available key info:
@@ -135,8 +156,9 @@ test_lazy_prereq GPGSSH '
'
test_lazy_prereq GPGSSH_VERIFYTIME '
+ test_have_prereq GPGSSH &&
# Check if ssh-keygen has a verify-time option by passing an invalid date to it
- ssh-keygen -Overify-time=INVALID -Y check-novalidate -s doesnotmatter 2>&1 | grep -q -F "Invalid \"verify-time\"" &&
+ ssh-keygen -Overify-time=INVALID -Y check-novalidate -n "git" -s doesnotmatter 2>&1 | grep -q -F "Invalid \"verify-time\"" &&
# Set up keys with key lifetimes
ssh-keygen -t ed25519 -N "" -C "timeboxed valid key" -f "${GPGSSH_KEY_TIMEBOXEDVALID}" >/dev/null &&
diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh
index 901cc493ef..96ed3e1d69 100755
--- a/t/perf/p2000-sparse-operations.sh
+++ b/t/perf/p2000-sparse-operations.sh
@@ -131,5 +131,8 @@ test_perf_on_all git describe --dirty
test_perf_on_all 'echo >>new && git describe --dirty'
test_perf_on_all git diff-files
test_perf_on_all git diff-files -- $SPARSE_CONE/a
+test_perf_on_all git diff-tree HEAD
+test_perf_on_all git diff-tree HEAD -- $SPARSE_CONE/a
+test_perf_on_all "git worktree add ../temp && git worktree remove ../temp"
test_done
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 8ea31d187a..6e300be2ac 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -1014,7 +1014,7 @@ test_expect_success 'validate object ID for a known tree' '
'
test_expect_success 'showing tree with git ls-tree' '
- git ls-tree $tree >current
+ git ls-tree $tree >current
'
test_expect_success 'git ls-tree output for a known tree' '
diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh
index eeb8539c1b..8cb597f99c 100755
--- a/t/t0007-git-var.sh
+++ b/t/t0007-git-var.sh
@@ -147,6 +147,84 @@ test_expect_success 'get GIT_SEQUENCE_EDITOR with configuration and environment
)
'
+test_expect_success POSIXPERM 'GIT_SHELL_PATH points to a valid executable' '
+ shellpath=$(git var GIT_SHELL_PATH) &&
+ test_path_is_executable "$shellpath"
+'
+
+# We know in this environment that our shell will be one of a few fixed values
+# that all end in "sh".
+test_expect_success MINGW 'GIT_SHELL_PATH points to a suitable shell' '
+ shellpath=$(git var GIT_SHELL_PATH) &&
+ case "$shellpath" in
+ *sh) ;;
+ *) return 1;;
+ esac
+'
+
+test_expect_success 'GIT_ATTR_SYSTEM produces expected output' '
+ test_must_fail env GIT_ATTR_NOSYSTEM=1 git var GIT_ATTR_SYSTEM &&
+ (
+ sane_unset GIT_ATTR_NOSYSTEM &&
+ systempath=$(git var GIT_ATTR_SYSTEM) &&
+ test "$systempath" != ""
+ )
+'
+
+test_expect_success 'GIT_ATTR_GLOBAL points to the correct location' '
+ TRASHDIR="$(test-tool path-utils normalize_path_copy "$(pwd)")" &&
+ globalpath=$(XDG_CONFIG_HOME="$TRASHDIR/.config" git var GIT_ATTR_GLOBAL) &&
+ test "$globalpath" = "$TRASHDIR/.config/git/attributes" &&
+ (
+ sane_unset XDG_CONFIG_HOME &&
+ globalpath=$(HOME="$TRASHDIR" git var GIT_ATTR_GLOBAL) &&
+ test "$globalpath" = "$TRASHDIR/.config/git/attributes"
+ )
+'
+
+test_expect_success 'GIT_CONFIG_SYSTEM points to the correct location' '
+ TRASHDIR="$(test-tool path-utils normalize_path_copy "$(pwd)")" &&
+ test_must_fail env GIT_CONFIG_NOSYSTEM=1 git var GIT_CONFIG_SYSTEM &&
+ (
+ sane_unset GIT_CONFIG_NOSYSTEM &&
+ systempath=$(git var GIT_CONFIG_SYSTEM) &&
+ test "$systempath" != "" &&
+ systempath=$(GIT_CONFIG_SYSTEM=/dev/null git var GIT_CONFIG_SYSTEM) &&
+ if test_have_prereq MINGW
+ then
+ test "$systempath" = "nul"
+ else
+ test "$systempath" = "/dev/null"
+ fi &&
+ systempath=$(GIT_CONFIG_SYSTEM="$TRASHDIR/gitconfig" git var GIT_CONFIG_SYSTEM) &&
+ test "$systempath" = "$TRASHDIR/gitconfig"
+ )
+'
+
+test_expect_success 'GIT_CONFIG_GLOBAL points to the correct location' '
+ TRASHDIR="$(test-tool path-utils normalize_path_copy "$(pwd)")" &&
+ HOME="$TRASHDIR" XDG_CONFIG_HOME="$TRASHDIR/foo" git var GIT_CONFIG_GLOBAL >actual &&
+ echo "$TRASHDIR/foo/git/config" >expected &&
+ echo "$TRASHDIR/.gitconfig" >>expected &&
+ test_cmp expected actual &&
+ (
+ sane_unset XDG_CONFIG_HOME &&
+ HOME="$TRASHDIR" git var GIT_CONFIG_GLOBAL >actual &&
+ echo "$TRASHDIR/.config/git/config" >expected &&
+ echo "$TRASHDIR/.gitconfig" >>expected &&
+ test_cmp expected actual &&
+ globalpath=$(GIT_CONFIG_GLOBAL=/dev/null git var GIT_CONFIG_GLOBAL) &&
+ if test_have_prereq MINGW
+ then
+ test "$globalpath" = "nul"
+ else
+ test "$globalpath" = "/dev/null"
+ fi &&
+ globalpath=$(GIT_CONFIG_GLOBAL="$TRASHDIR/gitconfig" git var GIT_CONFIG_GLOBAL) &&
+ test "$globalpath" = "$TRASHDIR/gitconfig"
+ )
+'
+
# For git var -l, we check only a representative variable;
# testing the whole output would make our test too brittle with
# respect to unrelated changes in the test suite's environment.
@@ -164,6 +242,28 @@ test_expect_success 'git var -l lists config' '
test_cmp expect actual.bare
'
+test_expect_success 'git var -l lists multiple global configs' '
+ TRASHDIR="$(test-tool path-utils normalize_path_copy "$(pwd)")" &&
+ HOME="$TRASHDIR" XDG_CONFIG_HOME="$TRASHDIR/foo" git var -l >actual &&
+ grep "^GIT_CONFIG_GLOBAL=" actual >filtered &&
+ echo "GIT_CONFIG_GLOBAL=$TRASHDIR/foo/git/config" >expected &&
+ echo "GIT_CONFIG_GLOBAL=$TRASHDIR/.gitconfig" >>expected &&
+ test_cmp expected filtered
+'
+
+test_expect_success 'git var -l does not split multiline editors' '
+ (
+ GIT_EDITOR="!f() {
+ echo Hello!
+ }; f" &&
+ export GIT_EDITOR &&
+ echo "GIT_EDITOR=$GIT_EDITOR" >expected &&
+ git var -l >var &&
+ sed -n -e "/^GIT_EDITOR/,\$p" var | head -n 3 >actual &&
+ test_cmp expected actual
+ )
+'
+
test_expect_success 'listing and asking for variables are exclusive' '
test_must_fail git var -l GIT_COMMITTER_IDENT
'
diff --git a/t/t0030-stripspace.sh b/t/t0030-stripspace.sh
index 0a5713c524..d1b3be8725 100755
--- a/t/t0030-stripspace.sh
+++ b/t/t0030-stripspace.sh
@@ -17,396 +17,378 @@ printf_git_stripspace () {
printf "$1" | git stripspace
}
-test_expect_success \
- 'long lines without spaces should be unchanged' '
- echo "$ttt" >expect &&
- git stripspace <expect >actual &&
- test_cmp expect actual &&
-
- echo "$ttt$ttt" >expect &&
- git stripspace <expect >actual &&
- test_cmp expect actual &&
-
- echo "$ttt$ttt$ttt" >expect &&
- git stripspace <expect >actual &&
- test_cmp expect actual &&
-
- echo "$ttt$ttt$ttt$ttt" >expect &&
- git stripspace <expect >actual &&
- test_cmp expect actual
+test_expect_success 'long lines without spaces should be unchanged' '
+ echo "$ttt" >expect &&
+ git stripspace <expect >actual &&
+ test_cmp expect actual &&
+
+ echo "$ttt$ttt" >expect &&
+ git stripspace <expect >actual &&
+ test_cmp expect actual &&
+
+ echo "$ttt$ttt$ttt" >expect &&
+ git stripspace <expect >actual &&
+ test_cmp expect actual &&
+
+ echo "$ttt$ttt$ttt$ttt" >expect &&
+ git stripspace <expect >actual &&
+ test_cmp expect actual
'
-test_expect_success \
- 'lines with spaces at the beginning should be unchanged' '
- echo "$sss$ttt" >expect &&
- git stripspace <expect >actual &&
- test_cmp expect actual &&
+test_expect_success 'lines with spaces at the beginning should be unchanged' '
+ echo "$sss$ttt" >expect &&
+ git stripspace <expect >actual &&
+ test_cmp expect actual &&
- echo "$sss$sss$ttt" >expect &&
- git stripspace <expect >actual &&
- test_cmp expect actual &&
+ echo "$sss$sss$ttt" >expect &&
+ git stripspace <expect >actual &&
+ test_cmp expect actual &&
- echo "$sss$sss$sss$ttt" >expect &&
- git stripspace <expect >actual &&
- test_cmp expect actual
+ echo "$sss$sss$sss$ttt" >expect &&
+ git stripspace <expect >actual &&
+ test_cmp expect actual
'
-test_expect_success \
- 'lines with intermediate spaces should be unchanged' '
- echo "$ttt$sss$ttt" >expect &&
- git stripspace <expect >actual &&
- test_cmp expect actual &&
+test_expect_success 'lines with intermediate spaces should be unchanged' '
+ echo "$ttt$sss$ttt" >expect &&
+ git stripspace <expect >actual &&
+ test_cmp expect actual &&
- echo "$ttt$sss$sss$ttt" >expect &&
- git stripspace <expect >actual &&
- test_cmp expect actual
+ echo "$ttt$sss$sss$ttt" >expect &&
+ git stripspace <expect >actual &&
+ test_cmp expect actual
'
-test_expect_success \
- 'consecutive blank lines should be unified' '
- printf "$ttt\n\n$ttt\n" > expect &&
- printf "$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+test_expect_success 'consecutive blank lines should be unified' '
+ printf "$ttt\n\n$ttt\n" > expect &&
+ printf "$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt$ttt\n\n$ttt\n" > expect &&
- printf "$ttt$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt$ttt\n\n$ttt\n" > expect &&
+ printf "$ttt$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt$ttt$ttt\n\n$ttt\n" > expect &&
- printf "$ttt$ttt$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt$ttt$ttt\n\n$ttt\n" > expect &&
+ printf "$ttt$ttt$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n\n$ttt\n" > expect &&
- printf "$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n\n$ttt\n" > expect &&
+ printf "$ttt\n\n\n\n\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n\n$ttt$ttt\n" > expect &&
- printf "$ttt\n\n\n\n\n$ttt$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n\n$ttt$ttt\n" > expect &&
+ printf "$ttt\n\n\n\n\n$ttt$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n\n$ttt$ttt$ttt\n" > expect &&
- printf "$ttt\n\n\n\n\n$ttt$ttt$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n\n$ttt$ttt$ttt\n" > expect &&
+ printf "$ttt\n\n\n\n\n$ttt$ttt$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n\n$ttt\n" > expect &&
- printf "$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n\n$ttt\n" > expect &&
+ printf "$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt$ttt\n\n$ttt\n" > expect &&
- printf "$ttt$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt$ttt\n\n$ttt\n" > expect &&
+ printf "$ttt$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt$ttt$ttt\n\n$ttt\n" > expect &&
- printf "$ttt$ttt$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt$ttt$ttt\n\n$ttt\n" > expect &&
+ printf "$ttt$ttt$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n\n$ttt\n" > expect &&
- printf "$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n\n$ttt\n" > expect &&
+ printf "$ttt\n\t\n \n\n \t\t\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n\n$ttt$ttt\n" > expect &&
- printf "$ttt\n\t\n \n\n \t\t\n$ttt$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n\n$ttt$ttt\n" > expect &&
+ printf "$ttt\n\t\n \n\n \t\t\n$ttt$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n\n$ttt$ttt$ttt\n" > expect &&
- printf "$ttt\n\t\n \n\n \t\t\n$ttt$ttt$ttt\n" | git stripspace >actual &&
- test_cmp expect actual
+ printf "$ttt\n\n$ttt$ttt$ttt\n" > expect &&
+ printf "$ttt\n\t\n \n\n \t\t\n$ttt$ttt$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual
'
-test_expect_success \
- 'only consecutive blank lines should be completely removed' '
+test_expect_success 'only consecutive blank lines should be completely removed' '
+ printf "\n" | git stripspace >actual &&
+ test_must_be_empty actual &&
- printf "\n" | git stripspace >actual &&
- test_must_be_empty actual &&
+ printf "\n\n\n" | git stripspace >actual &&
+ test_must_be_empty actual &&
- printf "\n\n\n" | git stripspace >actual &&
- test_must_be_empty actual &&
+ printf "$sss\n$sss\n$sss\n" | git stripspace >actual &&
+ test_must_be_empty actual &&
- printf "$sss\n$sss\n$sss\n" | git stripspace >actual &&
- test_must_be_empty actual &&
+ printf "$sss$sss\n$sss\n\n" | git stripspace >actual &&
+ test_must_be_empty actual &&
- printf "$sss$sss\n$sss\n\n" | git stripspace >actual &&
- test_must_be_empty actual &&
+ printf "\n$sss\n$sss$sss\n" | git stripspace >actual &&
+ test_must_be_empty actual &&
- printf "\n$sss\n$sss$sss\n" | git stripspace >actual &&
- test_must_be_empty actual &&
+ printf "$sss$sss$sss$sss\n\n\n" | git stripspace >actual &&
+ test_must_be_empty actual &&
- printf "$sss$sss$sss$sss\n\n\n" | git stripspace >actual &&
- test_must_be_empty actual &&
+ printf "\n$sss$sss$sss$sss\n\n" | git stripspace >actual &&
+ test_must_be_empty actual &&
- printf "\n$sss$sss$sss$sss\n\n" | git stripspace >actual &&
- test_must_be_empty actual &&
-
- printf "\n\n$sss$sss$sss$sss\n" | git stripspace >actual &&
- test_must_be_empty actual
+ printf "\n\n$sss$sss$sss$sss\n" | git stripspace >actual &&
+ test_must_be_empty actual
'
-test_expect_success \
- 'consecutive blank lines at the beginning should be removed' '
- printf "$ttt\n" > expect &&
- printf "\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+test_expect_success 'consecutive blank lines at the beginning should be removed' '
+ printf "$ttt\n" > expect &&
+ printf "\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n" > expect &&
- printf "\n\n\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n" > expect &&
+ printf "\n\n\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt$ttt\n" > expect &&
- printf "\n\n\n$ttt$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt$ttt\n" > expect &&
+ printf "\n\n\n$ttt$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt$ttt$ttt\n" > expect &&
- printf "\n\n\n$ttt$ttt$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt$ttt$ttt\n" > expect &&
+ printf "\n\n\n$ttt$ttt$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt$ttt$ttt$ttt\n" > expect &&
- printf "\n\n\n$ttt$ttt$ttt$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt$ttt$ttt$ttt\n" > expect &&
+ printf "\n\n\n$ttt$ttt$ttt$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n" > expect &&
+ printf "$ttt\n" > expect &&
- printf "$sss\n$sss\n$sss\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$sss\n$sss\n$sss\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "\n$sss\n$sss$sss\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "\n$sss\n$sss$sss\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$sss$sss\n$sss\n\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$sss$sss\n$sss\n\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$sss$sss$sss\n\n\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$sss$sss$sss\n\n\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "\n$sss$sss$sss\n\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "\n$sss$sss$sss\n\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "\n\n$sss$sss$sss\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual
+ printf "\n\n$sss$sss$sss\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual
'
-test_expect_success \
- 'consecutive blank lines at the end should be removed' '
- printf "$ttt\n" > expect &&
- printf "$ttt\n\n" | git stripspace >actual &&
- test_cmp expect actual &&
+test_expect_success 'consecutive blank lines at the end should be removed' '
+ printf "$ttt\n" > expect &&
+ printf "$ttt\n\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n" > expect &&
- printf "$ttt\n\n\n\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n" > expect &&
+ printf "$ttt\n\n\n\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt$ttt\n" > expect &&
- printf "$ttt$ttt\n\n\n\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt$ttt\n" > expect &&
+ printf "$ttt$ttt\n\n\n\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt$ttt$ttt\n" > expect &&
- printf "$ttt$ttt$ttt\n\n\n\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt$ttt$ttt\n" > expect &&
+ printf "$ttt$ttt$ttt\n\n\n\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt$ttt$ttt$ttt\n" > expect &&
- printf "$ttt$ttt$ttt$ttt\n\n\n\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt$ttt$ttt$ttt\n" > expect &&
+ printf "$ttt$ttt$ttt$ttt\n\n\n\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n" > expect &&
+ printf "$ttt\n" > expect &&
- printf "$ttt\n$sss\n$sss\n$sss\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n$sss\n$sss\n$sss\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n\n$sss\n$sss$sss\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n\n$sss\n$sss$sss\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n$sss$sss\n$sss\n\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n$sss$sss\n$sss\n\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n$sss$sss$sss\n\n\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n$sss$sss$sss\n\n\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n\n$sss$sss$sss\n\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n\n$sss$sss$sss\n\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n\n\n$sss$sss$sss\n" | git stripspace >actual &&
- test_cmp expect actual
+ printf "$ttt\n\n\n$sss$sss$sss\n" | git stripspace >actual &&
+ test_cmp expect actual
'
-test_expect_success \
- 'text without newline at end should end with newline' '
- test_stdout_line_count -gt 0 printf_git_stripspace "$ttt" &&
- test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt" &&
- test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt" &&
- test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt$ttt"
+test_expect_success 'text without newline at end should end with newline' '
+ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt" &&
+ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt" &&
+ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt" &&
+ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt$ttt"
'
# text plus spaces at the end:
-test_expect_success \
- 'text plus spaces without newline at end should end with newline' '
- test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss" &&
- test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$sss" &&
- test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt$sss" &&
- test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss$sss" &&
- test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$sss$sss" &&
- test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss$sss$sss"
+test_expect_success 'text plus spaces without newline at end should end with newline' '
+ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss" &&
+ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$sss" &&
+ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt$sss" &&
+ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss$sss" &&
+ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$sss$sss" &&
+ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss$sss$sss"
'
-test_expect_success \
- 'text plus spaces without newline at end should not show spaces' '
- printf "$ttt$sss" | git stripspace >tmp &&
- ! grep " " tmp >/dev/null &&
- printf "$ttt$ttt$sss" | git stripspace >tmp &&
- ! grep " " tmp >/dev/null &&
- printf "$ttt$ttt$ttt$sss" | git stripspace >tmp &&
- ! grep " " tmp >/dev/null &&
- printf "$ttt$sss$sss" | git stripspace >tmp &&
- ! grep " " tmp >/dev/null &&
- printf "$ttt$ttt$sss$sss" | git stripspace >tmp &&
- ! grep " " tmp >/dev/null &&
- printf "$ttt$sss$sss$sss" | git stripspace >tmp &&
- ! grep " " tmp >/dev/null
+test_expect_success 'text plus spaces without newline at end should not show spaces' '
+ printf "$ttt$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
+ printf "$ttt$ttt$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
+ printf "$ttt$ttt$ttt$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
+ printf "$ttt$sss$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
+ printf "$ttt$ttt$sss$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
+ printf "$ttt$sss$sss$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null
'
-test_expect_success \
- 'text plus spaces without newline should show the correct lines' '
- printf "$ttt\n" >expect &&
- printf "$ttt$sss" | git stripspace >actual &&
- test_cmp expect actual &&
+test_expect_success 'text plus spaces without newline should show the correct lines' '
+ printf "$ttt\n" >expect &&
+ printf "$ttt$sss" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n" >expect &&
- printf "$ttt$sss$sss" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n" >expect &&
+ printf "$ttt$sss$sss" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n" >expect &&
- printf "$ttt$sss$sss$sss" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n" >expect &&
+ printf "$ttt$sss$sss$sss" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt$ttt\n" >expect &&
- printf "$ttt$ttt$sss" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt$ttt\n" >expect &&
+ printf "$ttt$ttt$sss" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt$ttt\n" >expect &&
- printf "$ttt$ttt$sss$sss" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt$ttt\n" >expect &&
+ printf "$ttt$ttt$sss$sss" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt$ttt$ttt\n" >expect &&
- printf "$ttt$ttt$ttt$sss" | git stripspace >actual &&
- test_cmp expect actual
+ printf "$ttt$ttt$ttt\n" >expect &&
+ printf "$ttt$ttt$ttt$sss" | git stripspace >actual &&
+ test_cmp expect actual
'
-test_expect_success \
- 'text plus spaces at end should not show spaces' '
- echo "$ttt$sss" | git stripspace >tmp &&
- ! grep " " tmp >/dev/null &&
- echo "$ttt$ttt$sss" | git stripspace >tmp &&
- ! grep " " tmp >/dev/null &&
- echo "$ttt$ttt$ttt$sss" | git stripspace >tmp &&
- ! grep " " tmp >/dev/null &&
- echo "$ttt$sss$sss" | git stripspace >tmp &&
- ! grep " " tmp >/dev/null &&
- echo "$ttt$ttt$sss$sss" | git stripspace >tmp &&
- ! grep " " tmp >/dev/null &&
- echo "$ttt$sss$sss$sss" | git stripspace >tmp &&
- ! grep " " tmp >/dev/null
+test_expect_success 'text plus spaces at end should not show spaces' '
+ echo "$ttt$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
+ echo "$ttt$ttt$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
+ echo "$ttt$ttt$ttt$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
+ echo "$ttt$sss$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
+ echo "$ttt$ttt$sss$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
+ echo "$ttt$sss$sss$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null
'
-test_expect_success \
- 'text plus spaces at end should be cleaned and newline must remain' '
- echo "$ttt" >expect &&
- echo "$ttt$sss" | git stripspace >actual &&
- test_cmp expect actual &&
+test_expect_success 'text plus spaces at end should be cleaned and newline must remain' '
+ echo "$ttt" >expect &&
+ echo "$ttt$sss" | git stripspace >actual &&
+ test_cmp expect actual &&
- echo "$ttt" >expect &&
- echo "$ttt$sss$sss" | git stripspace >actual &&
- test_cmp expect actual &&
+ echo "$ttt" >expect &&
+ echo "$ttt$sss$sss" | git stripspace >actual &&
+ test_cmp expect actual &&
- echo "$ttt" >expect &&
- echo "$ttt$sss$sss$sss" | git stripspace >actual &&
- test_cmp expect actual &&
+ echo "$ttt" >expect &&
+ echo "$ttt$sss$sss$sss" | git stripspace >actual &&
+ test_cmp expect actual &&
- echo "$ttt$ttt" >expect &&
- echo "$ttt$ttt$sss" | git stripspace >actual &&
- test_cmp expect actual &&
+ echo "$ttt$ttt" >expect &&
+ echo "$ttt$ttt$sss" | git stripspace >actual &&
+ test_cmp expect actual &&
- echo "$ttt$ttt" >expect &&
- echo "$ttt$ttt$sss$sss" | git stripspace >actual &&
- test_cmp expect actual &&
+ echo "$ttt$ttt" >expect &&
+ echo "$ttt$ttt$sss$sss" | git stripspace >actual &&
+ test_cmp expect actual &&
- echo "$ttt$ttt$ttt" >expect &&
- echo "$ttt$ttt$ttt$sss" | git stripspace >actual &&
- test_cmp expect actual
+ echo "$ttt$ttt$ttt" >expect &&
+ echo "$ttt$ttt$ttt$sss" | git stripspace >actual &&
+ test_cmp expect actual
'
# spaces only:
-test_expect_success \
- 'spaces with newline at end should be replaced with empty string' '
- echo | git stripspace >actual &&
- test_must_be_empty actual &&
+test_expect_success 'spaces with newline at end should be replaced with empty string' '
+ echo | git stripspace >actual &&
+ test_must_be_empty actual &&
- echo "$sss" | git stripspace >actual &&
- test_must_be_empty actual &&
+ echo "$sss" | git stripspace >actual &&
+ test_must_be_empty actual &&
- echo "$sss$sss" | git stripspace >actual &&
- test_must_be_empty actual &&
+ echo "$sss$sss" | git stripspace >actual &&
+ test_must_be_empty actual &&
- echo "$sss$sss$sss" | git stripspace >actual &&
- test_must_be_empty actual &&
+ echo "$sss$sss$sss" | git stripspace >actual &&
+ test_must_be_empty actual &&
- echo "$sss$sss$sss$sss" | git stripspace >actual &&
- test_must_be_empty actual
+ echo "$sss$sss$sss$sss" | git stripspace >actual &&
+ test_must_be_empty actual
'
-test_expect_success \
- 'spaces without newline at end should not show spaces' '
- printf "" | git stripspace >tmp &&
- ! grep " " tmp >/dev/null &&
- printf "$sss" | git stripspace >tmp &&
- ! grep " " tmp >/dev/null &&
- printf "$sss$sss" | git stripspace >tmp &&
- ! grep " " tmp >/dev/null &&
- printf "$sss$sss$sss" | git stripspace >tmp &&
- ! grep " " tmp >/dev/null &&
- printf "$sss$sss$sss$sss" | git stripspace >tmp &&
- ! grep " " tmp >/dev/null
+test_expect_success 'spaces without newline at end should not show spaces' '
+ printf "" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
+ printf "$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
+ printf "$sss$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
+ printf "$sss$sss$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
+ printf "$sss$sss$sss$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null
'
-test_expect_success \
- 'spaces without newline at end should be replaced with empty string' '
- printf "" | git stripspace >actual &&
- test_must_be_empty actual &&
+test_expect_success 'spaces without newline at end should be replaced with empty string' '
+ printf "" | git stripspace >actual &&
+ test_must_be_empty actual &&
- printf "$sss$sss" | git stripspace >actual &&
- test_must_be_empty actual &&
+ printf "$sss$sss" | git stripspace >actual &&
+ test_must_be_empty actual &&
- printf "$sss$sss$sss" | git stripspace >actual &&
- test_must_be_empty actual &&
+ printf "$sss$sss$sss" | git stripspace >actual &&
+ test_must_be_empty actual &&
- printf "$sss$sss$sss$sss" | git stripspace >actual &&
- test_must_be_empty actual
+ printf "$sss$sss$sss$sss" | git stripspace >actual &&
+ test_must_be_empty actual
'
-test_expect_success \
- 'consecutive text lines should be unchanged' '
- printf "$ttt$ttt\n$ttt\n" >expect &&
- printf "$ttt$ttt\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+test_expect_success 'consecutive text lines should be unchanged' '
+ printf "$ttt$ttt\n$ttt\n" >expect &&
+ printf "$ttt$ttt\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n$ttt$ttt\n$ttt\n" >expect &&
- printf "$ttt\n$ttt$ttt\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n$ttt$ttt\n$ttt\n" >expect &&
+ printf "$ttt\n$ttt$ttt\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n$ttt\n$ttt\n$ttt$ttt\n" >expect &&
- printf "$ttt\n$ttt\n$ttt\n$ttt$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n$ttt\n$ttt\n$ttt$ttt\n" >expect &&
+ printf "$ttt\n$ttt\n$ttt\n$ttt$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n$ttt\n\n$ttt$ttt\n$ttt\n" >expect &&
- printf "$ttt\n$ttt\n\n$ttt$ttt\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt\n$ttt\n\n$ttt$ttt\n$ttt\n" >expect &&
+ printf "$ttt\n$ttt\n\n$ttt$ttt\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt$ttt\n\n$ttt\n$ttt$ttt\n" >expect &&
- printf "$ttt$ttt\n\n$ttt\n$ttt$ttt\n" | git stripspace >actual &&
- test_cmp expect actual &&
+ printf "$ttt$ttt\n\n$ttt\n$ttt$ttt\n" >expect &&
+ printf "$ttt$ttt\n\n$ttt\n$ttt$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual &&
- printf "$ttt\n$ttt$ttt\n\n$ttt\n" >expect &&
- printf "$ttt\n$ttt$ttt\n\n$ttt\n" | git stripspace >actual &&
- test_cmp expect actual
+ printf "$ttt\n$ttt$ttt\n\n$ttt\n" >expect &&
+ printf "$ttt\n$ttt$ttt\n\n$ttt\n" | git stripspace >actual &&
+ test_cmp expect actual
'
test_expect_success 'strip comments, too' '
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index 7d7ecfd571..e19a199636 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -30,11 +30,12 @@ usage: test-tool parse-options <options>
-F, --file <file> set file to <file>
String options
- -s, --string <string>
- get a string
+ -s, --string <string> get a string
--string2 <str> get another string
--st <st> get another string (pervert ordering)
-o <str> get another string
+ --longhelp help text of this entry
+ spans multiple lines
--list <str> add str to list
Magic arguments
diff --git a/t/t0041-usage.sh b/t/t0041-usage.sh
index c4fc34eb18..9ea974b0c6 100755
--- a/t/t0041-usage.sh
+++ b/t/t0041-usage.sh
@@ -5,6 +5,7 @@ test_description='Test commands behavior when given invalid argument value'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup ' '
diff --git a/t/t0091-bugreport.sh b/t/t0091-bugreport.sh
index b6d2f591ac..f6998269be 100755
--- a/t/t0091-bugreport.sh
+++ b/t/t0091-bugreport.sh
@@ -5,29 +5,50 @@ test_description='git bugreport'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
-# Headers "[System Info]" will be followed by a non-empty line if we put some
-# information there; we can make sure all our headers were followed by some
-# information to check if the command was successful.
-HEADER_PATTERN="^\[.*\]$"
-
-check_all_headers_populated () {
- while read -r line
- do
- if test "$(grep "$HEADER_PATTERN" "$line")"
- then
- echo "$line"
- read -r nextline
- if test -z "$nextline"; then
- return 1;
- fi
- fi
- done
-}
-
-test_expect_success 'creates a report with content in the right places' '
- test_when_finished rm git-bugreport-check-headers.txt &&
- git bugreport -s check-headers &&
- check_all_headers_populated <git-bugreport-check-headers.txt
+test_expect_success 'create a report' '
+ git bugreport -s format &&
+ test_file_not_empty git-bugreport-format.txt
+'
+
+test_expect_success 'report contains wanted template (before first section)' '
+ sed -ne "/^\[/q;p" git-bugreport-format.txt >actual &&
+ cat >expect <<-\EOF &&
+ Thank you for filling out a Git bug report!
+ Please answer the following questions to help us understand your issue.
+
+ What did you do before the bug happened? (Steps to reproduce your issue)
+
+ What did you expect to happen? (Expected behavior)
+
+ What happened instead? (Actual behavior)
+
+ What'\''s different between what you expected and what actually happened?
+
+ Anything else you want to add:
+
+ Please review the rest of the bug report below.
+ You can delete any lines you don'\''t wish to share.
+
+
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'sanity check "System Info" section' '
+ test_when_finished rm -f git-bugreport-format.txt &&
+
+ sed -ne "/^\[System Info\]$/,/^$/p" <git-bugreport-format.txt >system &&
+
+ # The beginning should match "git version --build-info" verbatim,
+ # but rather than checking bit-for-bit equality, just test some basics.
+ grep "git version [0-9]." system &&
+ grep "shell-path: ." system &&
+
+ # After the version, there should be some more info.
+ # This is bound to differ from environment to environment,
+ # so we just do some rather high-level checks.
+ grep "uname: ." system &&
+ grep "compiler info: ." system
'
test_expect_success 'dies if file with same name as report already exists' '
diff --git a/t/t0211-trace2-perf.sh b/t/t0211-trace2-perf.sh
index b4e9135118..cfba686132 100755
--- a/t/t0211-trace2-perf.sh
+++ b/t/t0211-trace2-perf.sh
@@ -203,7 +203,7 @@ test_expect_success 'stopwatch timer test/test1' '
have_timer_event "main" "timer" "test" "test1" 5 actual
'
-test_expect_success PTHREAD 'stopwatch timer test/test2' '
+test_expect_success PTHREADS 'stopwatch timer test/test2' '
test_when_finished "rm trace.perf actual" &&
test_config_global trace2.perfBrief 1 &&
test_config_global trace2.perfTarget "$(pwd)/trace.perf" &&
@@ -249,7 +249,7 @@ test_expect_success 'global counter test/test1' '
have_counter_event "main" "counter" "test" "test1" 15 actual
'
-test_expect_success PTHREAD 'global counter test/test2' '
+test_expect_success PTHREADS 'global counter test/test2' '
test_when_finished "rm trace.perf actual" &&
test_config_global trace2.perfBrief 1 &&
test_config_global trace2.perfTarget "$(pwd)/trace.perf" &&
diff --git a/t/t1001-read-tree-m-2way.sh b/t/t1001-read-tree-m-2way.sh
index 3fb1b0c162..88c524f655 100755
--- a/t/t1001-read-tree-m-2way.sh
+++ b/t/t1001-read-tree-m-2way.sh
@@ -26,7 +26,7 @@ TEST_PASSES_SANITIZE_LEAK=true
. "$TEST_DIRECTORY"/lib-read-tree.sh
read_tree_twoway () {
- git read-tree -m "$1" "$2" && git ls-files --stage
+ git read-tree -m "$1" "$2" && git ls-files --stage
}
compare_change () {
diff --git a/t/t1002-read-tree-m-u-2way.sh b/t/t1002-read-tree-m-u-2way.sh
index cdc077ce12..a7c2ed0d7c 100755
--- a/t/t1002-read-tree-m-u-2way.sh
+++ b/t/t1002-read-tree-m-u-2way.sh
@@ -37,315 +37,312 @@ check_cache_at () {
esac
}
-test_expect_success \
- setup \
- 'echo frotz >frotz &&
- echo nitfol >nitfol &&
- echo bozbar >bozbar &&
- echo rezrov >rezrov &&
- git update-index --add nitfol bozbar rezrov &&
- treeH=$(git write-tree) &&
- echo treeH $treeH &&
- git ls-tree $treeH &&
-
- echo gnusto >bozbar &&
- git update-index --add frotz bozbar --force-remove rezrov &&
- git ls-files --stage >M.out &&
- treeM=$(git write-tree) &&
- echo treeM $treeM &&
- git ls-tree $treeM &&
- cp bozbar bozbar.M &&
- cp frotz frotz.M &&
- cp nitfol nitfol.M &&
- git diff-tree $treeH $treeM'
-
-test_expect_success \
- '1, 2, 3 - no carry forward' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- read_tree_u_must_succeed -m -u $treeH $treeM &&
- git ls-files --stage >1-3.out &&
- cmp M.out 1-3.out &&
- test_cmp bozbar.M bozbar &&
- test_cmp frotz.M frotz &&
- test_cmp nitfol.M nitfol &&
- check_cache_at bozbar clean &&
- check_cache_at frotz clean &&
- check_cache_at nitfol clean'
-
-test_expect_success \
- '4 - carry forward local addition.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- echo "+100644 X 0 yomin" >expected &&
- echo yomin >yomin &&
- git update-index --add yomin &&
- read_tree_u_must_succeed -m -u $treeH $treeM &&
- git ls-files --stage >4.out &&
- test_might_fail git diff -U0 --no-index M.out 4.out >4diff.out &&
- compare_change 4diff.out expected &&
- check_cache_at yomin clean &&
- test_cmp bozbar.M bozbar &&
- test_cmp frotz.M frotz &&
- test_cmp nitfol.M nitfol &&
- echo yomin >yomin1 &&
- diff yomin yomin1 &&
- rm -f yomin1'
-
-test_expect_success \
- '5 - carry forward local addition.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- read_tree_u_must_succeed -m -u $treeH &&
- echo yomin >yomin &&
- git update-index --add yomin &&
- echo yomin yomin >yomin &&
- read_tree_u_must_succeed -m -u $treeH $treeM &&
- git ls-files --stage >5.out &&
- test_might_fail git diff -U0 --no-index M.out 5.out >5diff.out &&
- compare_change 5diff.out expected &&
- check_cache_at yomin dirty &&
- test_cmp bozbar.M bozbar &&
- test_cmp frotz.M frotz &&
- test_cmp nitfol.M nitfol &&
- : dirty index should have prevented -u from checking it out. &&
- echo yomin yomin >yomin1 &&
- diff yomin yomin1 &&
- rm -f yomin1'
-
-test_expect_success \
- '6 - local addition already has the same.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- echo frotz >frotz &&
- git update-index --add frotz &&
- read_tree_u_must_succeed -m -u $treeH $treeM &&
- git ls-files --stage >6.out &&
- test_cmp M.out 6.out &&
- check_cache_at frotz clean &&
- test_cmp bozbar.M bozbar &&
- test_cmp frotz.M frotz &&
- test_cmp nitfol.M nitfol &&
- echo frotz >frotz1 &&
- diff frotz frotz1 &&
- rm -f frotz1'
-
-test_expect_success \
- '7 - local addition already has the same.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- echo frotz >frotz &&
- git update-index --add frotz &&
- echo frotz frotz >frotz &&
- read_tree_u_must_succeed -m -u $treeH $treeM &&
- git ls-files --stage >7.out &&
- test_cmp M.out 7.out &&
- check_cache_at frotz dirty &&
- test_cmp bozbar.M bozbar &&
- test_cmp nitfol.M nitfol &&
- : dirty index should have prevented -u from checking it out. &&
- echo frotz frotz >frotz1 &&
- diff frotz frotz1 &&
- rm -f frotz1'
-
-test_expect_success \
- '8 - conflicting addition.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- echo frotz frotz >frotz &&
- git update-index --add frotz &&
- ! read_tree_u_must_succeed -m -u $treeH $treeM'
-
-test_expect_success \
- '9 - conflicting addition.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- echo frotz frotz >frotz &&
- git update-index --add frotz &&
- echo frotz >frotz &&
- ! read_tree_u_must_succeed -m -u $treeH $treeM'
-
-test_expect_success \
- '10 - path removed.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- echo rezrov >rezrov &&
- git update-index --add rezrov &&
- read_tree_u_must_succeed -m -u $treeH $treeM &&
- git ls-files --stage >10.out &&
- cmp M.out 10.out &&
- test_cmp bozbar.M bozbar &&
- test_cmp frotz.M frotz &&
- test_cmp nitfol.M nitfol
+test_expect_success setup '
+ echo frotz >frotz &&
+ echo nitfol >nitfol &&
+ echo bozbar >bozbar &&
+ echo rezrov >rezrov &&
+ git update-index --add nitfol bozbar rezrov &&
+ treeH=$(git write-tree) &&
+ echo treeH $treeH &&
+ git ls-tree $treeH &&
+
+ echo gnusto >bozbar &&
+ git update-index --add frotz bozbar --force-remove rezrov &&
+ git ls-files --stage >M.out &&
+ treeM=$(git write-tree) &&
+ echo treeM $treeM &&
+ git ls-tree $treeM &&
+ cp bozbar bozbar.M &&
+ cp frotz frotz.M &&
+ cp nitfol nitfol.M &&
+ git diff-tree $treeH $treeM
'
-test_expect_success \
- '11 - dirty path removed.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- echo rezrov >rezrov &&
- git update-index --add rezrov &&
- echo rezrov rezrov >rezrov &&
- ! read_tree_u_must_succeed -m -u $treeH $treeM'
-
-test_expect_success \
- '12 - unmatching local changes being removed.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- echo rezrov rezrov >rezrov &&
- git update-index --add rezrov &&
- ! read_tree_u_must_succeed -m -u $treeH $treeM'
-
-test_expect_success \
- '13 - unmatching local changes being removed.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- echo rezrov rezrov >rezrov &&
- git update-index --add rezrov &&
- echo rezrov >rezrov &&
- ! read_tree_u_must_succeed -m -u $treeH $treeM'
+test_expect_success '1, 2, 3 - no carry forward' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ read_tree_u_must_succeed -m -u $treeH $treeM &&
+ git ls-files --stage >1-3.out &&
+ cmp M.out 1-3.out &&
+ test_cmp bozbar.M bozbar &&
+ test_cmp frotz.M frotz &&
+ test_cmp nitfol.M nitfol &&
+ check_cache_at bozbar clean &&
+ check_cache_at frotz clean &&
+ check_cache_at nitfol clean
+'
+
+test_expect_success '4 - carry forward local addition.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ echo "+100644 X 0 yomin" >expected &&
+ echo yomin >yomin &&
+ git update-index --add yomin &&
+ read_tree_u_must_succeed -m -u $treeH $treeM &&
+ git ls-files --stage >4.out &&
+ test_might_fail git diff -U0 --no-index M.out 4.out >4diff.out &&
+ compare_change 4diff.out expected &&
+ check_cache_at yomin clean &&
+ test_cmp bozbar.M bozbar &&
+ test_cmp frotz.M frotz &&
+ test_cmp nitfol.M nitfol &&
+ echo yomin >yomin1 &&
+ diff yomin yomin1 &&
+ rm -f yomin1
+'
+
+test_expect_success '5 - carry forward local addition.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ read_tree_u_must_succeed -m -u $treeH &&
+ echo yomin >yomin &&
+ git update-index --add yomin &&
+ echo yomin yomin >yomin &&
+ read_tree_u_must_succeed -m -u $treeH $treeM &&
+ git ls-files --stage >5.out &&
+ test_might_fail git diff -U0 --no-index M.out 5.out >5diff.out &&
+ compare_change 5diff.out expected &&
+ check_cache_at yomin dirty &&
+ test_cmp bozbar.M bozbar &&
+ test_cmp frotz.M frotz &&
+ test_cmp nitfol.M nitfol &&
+ : dirty index should have prevented -u from checking it out. &&
+ echo yomin yomin >yomin1 &&
+ diff yomin yomin1 &&
+ rm -f yomin1
+'
+
+test_expect_success '6 - local addition already has the same.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ echo frotz >frotz &&
+ git update-index --add frotz &&
+ read_tree_u_must_succeed -m -u $treeH $treeM &&
+ git ls-files --stage >6.out &&
+ test_cmp M.out 6.out &&
+ check_cache_at frotz clean &&
+ test_cmp bozbar.M bozbar &&
+ test_cmp frotz.M frotz &&
+ test_cmp nitfol.M nitfol &&
+ echo frotz >frotz1 &&
+ diff frotz frotz1 &&
+ rm -f frotz1
+'
+
+test_expect_success '7 - local addition already has the same.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ echo frotz >frotz &&
+ git update-index --add frotz &&
+ echo frotz frotz >frotz &&
+ read_tree_u_must_succeed -m -u $treeH $treeM &&
+ git ls-files --stage >7.out &&
+ test_cmp M.out 7.out &&
+ check_cache_at frotz dirty &&
+ test_cmp bozbar.M bozbar &&
+ test_cmp nitfol.M nitfol &&
+ : dirty index should have prevented -u from checking it out. &&
+ echo frotz frotz >frotz1 &&
+ diff frotz frotz1 &&
+ rm -f frotz1
+'
+
+test_expect_success '8 - conflicting addition.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ echo frotz frotz >frotz &&
+ git update-index --add frotz &&
+ ! read_tree_u_must_succeed -m -u $treeH $treeM
+'
+
+test_expect_success '9 - conflicting addition.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ echo frotz frotz >frotz &&
+ git update-index --add frotz &&
+ echo frotz >frotz &&
+ ! read_tree_u_must_succeed -m -u $treeH $treeM
+'
+
+test_expect_success '10 - path removed.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ echo rezrov >rezrov &&
+ git update-index --add rezrov &&
+ read_tree_u_must_succeed -m -u $treeH $treeM &&
+ git ls-files --stage >10.out &&
+ cmp M.out 10.out &&
+ test_cmp bozbar.M bozbar &&
+ test_cmp frotz.M frotz &&
+ test_cmp nitfol.M nitfol
+'
+
+test_expect_success '11 - dirty path removed.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ echo rezrov >rezrov &&
+ git update-index --add rezrov &&
+ echo rezrov rezrov >rezrov &&
+ ! read_tree_u_must_succeed -m -u $treeH $treeM
+'
+
+test_expect_success '12 - unmatching local changes being removed.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ echo rezrov rezrov >rezrov &&
+ git update-index --add rezrov &&
+ ! read_tree_u_must_succeed -m -u $treeH $treeM
+'
+
+test_expect_success '13 - unmatching local changes being removed.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ echo rezrov rezrov >rezrov &&
+ git update-index --add rezrov &&
+ echo rezrov >rezrov &&
+ ! read_tree_u_must_succeed -m -u $treeH $treeM
+'
cat >expected <<EOF
-100644 X 0 nitfol
+100644 X 0 nitfol
EOF
-test_expect_success \
- '14 - unchanged in two heads.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- echo nitfol nitfol >nitfol &&
- git update-index --add nitfol &&
- read_tree_u_must_succeed -m -u $treeH $treeM &&
- git ls-files --stage >14.out &&
- test_must_fail git diff -U0 --no-index M.out 14.out >14diff.out &&
- compare_change 14diff.out expected &&
- test_cmp bozbar.M bozbar &&
- test_cmp frotz.M frotz &&
- check_cache_at nitfol clean &&
- echo nitfol nitfol >nitfol1 &&
- diff nitfol nitfol1 &&
- rm -f nitfol1'
-
-test_expect_success \
- '15 - unchanged in two heads.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- echo nitfol nitfol >nitfol &&
- git update-index --add nitfol &&
- echo nitfol nitfol nitfol >nitfol &&
- read_tree_u_must_succeed -m -u $treeH $treeM &&
- git ls-files --stage >15.out &&
- test_must_fail git diff -U0 --no-index M.out 15.out >15diff.out &&
- compare_change 15diff.out expected &&
- check_cache_at nitfol dirty &&
- test_cmp bozbar.M bozbar &&
- test_cmp frotz.M frotz &&
- echo nitfol nitfol nitfol >nitfol1 &&
- diff nitfol nitfol1 &&
- rm -f nitfol1'
-
-test_expect_success \
- '16 - conflicting local change.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- echo bozbar bozbar >bozbar &&
- git update-index --add bozbar &&
- ! read_tree_u_must_succeed -m -u $treeH $treeM'
-
-test_expect_success \
- '17 - conflicting local change.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- echo bozbar bozbar >bozbar &&
- git update-index --add bozbar &&
- echo bozbar bozbar bozbar >bozbar &&
- ! read_tree_u_must_succeed -m -u $treeH $treeM'
-
-test_expect_success \
- '18 - local change already having a good result.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- echo gnusto >bozbar &&
- git update-index --add bozbar &&
- read_tree_u_must_succeed -m -u $treeH $treeM &&
- git ls-files --stage >18.out &&
- test_cmp M.out 18.out &&
- check_cache_at bozbar clean &&
- test_cmp bozbar.M bozbar &&
- test_cmp frotz.M frotz &&
- test_cmp nitfol.M nitfol
+test_expect_success '14 - unchanged in two heads.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ echo nitfol nitfol >nitfol &&
+ git update-index --add nitfol &&
+ read_tree_u_must_succeed -m -u $treeH $treeM &&
+ git ls-files --stage >14.out &&
+ test_must_fail git diff -U0 --no-index M.out 14.out >14diff.out &&
+ compare_change 14diff.out expected &&
+ test_cmp bozbar.M bozbar &&
+ test_cmp frotz.M frotz &&
+ check_cache_at nitfol clean &&
+ echo nitfol nitfol >nitfol1 &&
+ diff nitfol nitfol1 &&
+ rm -f nitfol1
'
-test_expect_success \
- '19 - local change already having a good result, further modified.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- echo gnusto >bozbar &&
- git update-index --add bozbar &&
- echo gnusto gnusto >bozbar &&
- read_tree_u_must_succeed -m -u $treeH $treeM &&
- git ls-files --stage >19.out &&
- test_cmp M.out 19.out &&
- check_cache_at bozbar dirty &&
- test_cmp frotz.M frotz &&
- test_cmp nitfol.M nitfol &&
- echo gnusto gnusto >bozbar1 &&
- diff bozbar bozbar1 &&
- rm -f bozbar1'
-
-test_expect_success \
- '20 - no local change, use new tree.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- echo bozbar >bozbar &&
- git update-index --add bozbar &&
- read_tree_u_must_succeed -m -u $treeH $treeM &&
- git ls-files --stage >20.out &&
- test_cmp M.out 20.out &&
- check_cache_at bozbar clean &&
- test_cmp bozbar.M bozbar &&
- test_cmp frotz.M frotz &&
- test_cmp nitfol.M nitfol
+test_expect_success '15 - unchanged in two heads.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ echo nitfol nitfol >nitfol &&
+ git update-index --add nitfol &&
+ echo nitfol nitfol nitfol >nitfol &&
+ read_tree_u_must_succeed -m -u $treeH $treeM &&
+ git ls-files --stage >15.out &&
+ test_must_fail git diff -U0 --no-index M.out 15.out >15diff.out &&
+ compare_change 15diff.out expected &&
+ check_cache_at nitfol dirty &&
+ test_cmp bozbar.M bozbar &&
+ test_cmp frotz.M frotz &&
+ echo nitfol nitfol nitfol >nitfol1 &&
+ diff nitfol nitfol1 &&
+ rm -f nitfol1
'
-test_expect_success \
- '21 - no local change, dirty cache.' \
- 'rm -f .git/index nitfol bozbar rezrov frotz &&
- read_tree_u_must_succeed --reset -u $treeH &&
- echo bozbar >bozbar &&
- git update-index --add bozbar &&
- echo gnusto gnusto >bozbar &&
- ! read_tree_u_must_succeed -m -u $treeH $treeM'
+test_expect_success '16 - conflicting local change.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ echo bozbar bozbar >bozbar &&
+ git update-index --add bozbar &&
+ ! read_tree_u_must_succeed -m -u $treeH $treeM
+'
+
+test_expect_success '17 - conflicting local change.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ echo bozbar bozbar >bozbar &&
+ git update-index --add bozbar &&
+ echo bozbar bozbar bozbar >bozbar &&
+ ! read_tree_u_must_succeed -m -u $treeH $treeM
+'
+
+test_expect_success '18 - local change already having a good result.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ echo gnusto >bozbar &&
+ git update-index --add bozbar &&
+ read_tree_u_must_succeed -m -u $treeH $treeM &&
+ git ls-files --stage >18.out &&
+ test_cmp M.out 18.out &&
+ check_cache_at bozbar clean &&
+ test_cmp bozbar.M bozbar &&
+ test_cmp frotz.M frotz &&
+ test_cmp nitfol.M nitfol
+'
+
+test_expect_success '19 - local change already having a good result, further modified.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ echo gnusto >bozbar &&
+ git update-index --add bozbar &&
+ echo gnusto gnusto >bozbar &&
+ read_tree_u_must_succeed -m -u $treeH $treeM &&
+ git ls-files --stage >19.out &&
+ test_cmp M.out 19.out &&
+ check_cache_at bozbar dirty &&
+ test_cmp frotz.M frotz &&
+ test_cmp nitfol.M nitfol &&
+ echo gnusto gnusto >bozbar1 &&
+ diff bozbar bozbar1 &&
+ rm -f bozbar1
+'
+
+test_expect_success '20 - no local change, use new tree.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ echo bozbar >bozbar &&
+ git update-index --add bozbar &&
+ read_tree_u_must_succeed -m -u $treeH $treeM &&
+ git ls-files --stage >20.out &&
+ test_cmp M.out 20.out &&
+ check_cache_at bozbar clean &&
+ test_cmp bozbar.M bozbar &&
+ test_cmp frotz.M frotz &&
+ test_cmp nitfol.M nitfol
+'
+
+test_expect_success '21 - no local change, dirty cache.' '
+ rm -f .git/index nitfol bozbar rezrov frotz &&
+ read_tree_u_must_succeed --reset -u $treeH &&
+ echo bozbar >bozbar &&
+ git update-index --add bozbar &&
+ echo gnusto gnusto >bozbar &&
+ ! read_tree_u_must_succeed -m -u $treeH $treeM
+'
# Also make sure we did not break DF vs DF/DF case.
-test_expect_success \
- 'DF vs DF/DF case setup.' \
- 'rm -f .git/index &&
- echo DF >DF &&
- git update-index --add DF &&
- treeDF=$(git write-tree) &&
- echo treeDF $treeDF &&
- git ls-tree $treeDF &&
-
- rm -f DF &&
- mkdir DF &&
- echo DF/DF >DF/DF &&
- git update-index --add --remove DF DF/DF &&
- treeDFDF=$(git write-tree) &&
- echo treeDFDF $treeDFDF &&
- git ls-tree $treeDFDF &&
- git ls-files --stage >DFDF.out'
-
-test_expect_success \
- 'DF vs DF/DF case test.' \
- 'rm -f .git/index &&
- rm -fr DF &&
- echo DF >DF &&
- git update-index --add DF &&
- read_tree_u_must_succeed -m -u $treeDF $treeDFDF &&
- git ls-files --stage >DFDFcheck.out &&
- test_cmp DFDF.out DFDFcheck.out &&
- check_cache_at DF/DF clean'
+test_expect_success 'DF vs DF/DF case setup.' '
+ rm -f .git/index &&
+ echo DF >DF &&
+ git update-index --add DF &&
+ treeDF=$(git write-tree) &&
+ echo treeDF $treeDF &&
+ git ls-tree $treeDF &&
+
+ rm -f DF &&
+ mkdir DF &&
+ echo DF/DF >DF/DF &&
+ git update-index --add --remove DF DF/DF &&
+ treeDFDF=$(git write-tree) &&
+ echo treeDFDF $treeDFDF &&
+ git ls-tree $treeDFDF &&
+ git ls-files --stage >DFDF.out
+'
+
+test_expect_success 'DF vs DF/DF case test.' '
+ rm -f .git/index &&
+ rm -fr DF &&
+ echo DF >DF &&
+ git update-index --add DF &&
+ read_tree_u_must_succeed -m -u $treeDF $treeDFDF &&
+ git ls-files --stage >DFDFcheck.out &&
+ test_cmp DFDF.out DFDFcheck.out &&
+ check_cache_at DF/DF clean
+'
test_done
diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
index 8eac74b59c..d73a0be1b9 100755
--- a/t/t1006-cat-file.sh
+++ b/t/t1006-cat-file.sh
@@ -89,7 +89,8 @@ done
for opt in --buffer \
--follow-symlinks \
--batch-all-objects \
- -z
+ -z \
+ -Z
do
test_expect_success "usage: bad option combination: $opt without batch mode" '
test_incompatible_usage git cat-file $opt &&
@@ -109,26 +110,12 @@ strlen () {
echo_without_newline "$1" | wc -c | sed -e 's/^ *//'
}
-maybe_remove_timestamp () {
- if test -z "$2"; then
- echo_without_newline "$1"
- else
- echo_without_newline "$(printf '%s\n' "$1" | remove_timestamp)"
- fi
-}
-
-remove_timestamp () {
- sed -e 's/ [0-9][0-9]* [-+][0-9][0-9][0-9][0-9]$//'
-}
-
-
run_tests () {
type=$1
sha1=$2
size=$3
content=$4
pretty_content=$5
- no_ts=$6
batch_output="$sha1 $type $size
$content"
@@ -163,21 +150,21 @@ $content"
test -z "$content" ||
test_expect_success "Content of $type is correct" '
- maybe_remove_timestamp "$content" $no_ts >expect &&
- maybe_remove_timestamp "$(git cat-file $type $sha1)" $no_ts >actual &&
+ echo_without_newline "$content" >expect &&
+ git cat-file $type $sha1 >actual &&
test_cmp expect actual
'
test_expect_success "Pretty content of $type is correct" '
- maybe_remove_timestamp "$pretty_content" $no_ts >expect &&
- maybe_remove_timestamp "$(git cat-file -p $sha1)" $no_ts >actual &&
+ echo_without_newline "$pretty_content" >expect &&
+ git cat-file -p $sha1 >actual &&
test_cmp expect actual
'
test -z "$content" ||
test_expect_success "--batch output of $type is correct" '
- maybe_remove_timestamp "$batch_output" $no_ts >expect &&
- maybe_remove_timestamp "$(echo $sha1 | git cat-file --batch)" $no_ts >actual &&
+ echo "$batch_output" >expect &&
+ echo $sha1 | git cat-file --batch >actual &&
test_cmp expect actual
'
@@ -191,9 +178,8 @@ $content"
do
test -z "$content" ||
test_expect_success "--batch-command $opt output of $type content is correct" '
- maybe_remove_timestamp "$batch_output" $no_ts >expect &&
- maybe_remove_timestamp "$(test_write_lines "contents $sha1" |
- git cat-file --batch-command $opt)" $no_ts >actual &&
+ echo "$batch_output" >expect &&
+ test_write_lines "contents $sha1" | git cat-file --batch-command $opt >actual &&
test_cmp expect actual
'
@@ -228,10 +214,9 @@ $content"
test_expect_success "--batch without type ($type)" '
{
echo "$size" &&
- maybe_remove_timestamp "$content" $no_ts
+ echo "$content"
} >expect &&
- echo $sha1 | git cat-file --batch="%(objectsize)" >actual.full &&
- maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual &&
+ echo $sha1 | git cat-file --batch="%(objectsize)" >actual &&
test_cmp expect actual
'
@@ -239,10 +224,9 @@ $content"
test_expect_success "--batch without size ($type)" '
{
echo "$type" &&
- maybe_remove_timestamp "$content" $no_ts
+ echo "$content"
} >expect &&
- echo $sha1 | git cat-file --batch="%(objecttype)" >actual.full &&
- maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual &&
+ echo $sha1 | git cat-file --batch="%(objecttype)" >actual &&
test_cmp expect actual
'
}
@@ -284,7 +268,7 @@ test_expect_success '--batch-check without %(rest) considers whole line' '
tree_sha1=$(git write-tree)
tree_size=$(($(test_oid rawsz) + 13))
-tree_pretty_content="100644 blob $hello_sha1 hello"
+tree_pretty_content="100644 blob $hello_sha1 hello${LF}"
run_tests 'tree' $tree_sha1 $tree_size "" "$tree_pretty_content"
@@ -292,12 +276,12 @@ commit_message="Initial commit"
commit_sha1=$(echo_without_newline "$commit_message" | git commit-tree $tree_sha1)
commit_size=$(($(test_oid hexsz) + 137))
commit_content="tree $tree_sha1
-author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 0 +0000
-committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 0 +0000
+author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
$commit_message"
-run_tests 'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content" 1
+run_tests 'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content"
tag_header_without_timestamp="object $hello_sha1
type blob
@@ -311,11 +295,13 @@ $tag_description"
tag_sha1=$(echo_without_newline "$tag_content" | git hash-object -t tag --stdin -w)
tag_size=$(strlen "$tag_content")
-run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content" 1
+run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content"
-test_expect_success \
- "Reach a blob from a tag pointing to it" \
- "test '$hello_content' = \"\$(git cat-file blob $tag_sha1)\""
+test_expect_success "Reach a blob from a tag pointing to it" '
+ echo_without_newline "$hello_content" >expect &&
+ git cat-file blob $tag_sha1 >actual &&
+ test_cmp expect actual
+'
for batch in batch batch-check batch-command
do
@@ -351,30 +337,47 @@ do
done
test_expect_success "--batch-check for a non-existent named object" '
- test "foobar42 missing
-foobar84 missing" = \
- "$( ( echo foobar42 && echo_without_newline foobar84 ) | git cat-file --batch-check)"
+ cat >expect <<-EOF &&
+ foobar42 missing
+ foobar84 missing
+ EOF
+
+ printf "foobar42\nfoobar84" >in &&
+ git cat-file --batch-check <in >actual &&
+ test_cmp expect actual
'
test_expect_success "--batch-check for a non-existent hash" '
- test "0000000000000000000000000000000000000042 missing
-0000000000000000000000000000000000000084 missing" = \
- "$( ( echo 0000000000000000000000000000000000000042 &&
- echo_without_newline 0000000000000000000000000000000000000084 ) |
- git cat-file --batch-check)"
+ cat >expect <<-EOF &&
+ 0000000000000000000000000000000000000042 missing
+ 0000000000000000000000000000000000000084 missing
+ EOF
+
+ printf "0000000000000000000000000000000000000042\n0000000000000000000000000000000000000084" >in &&
+ git cat-file --batch-check <in >actual &&
+ test_cmp expect actual
'
test_expect_success "--batch for an existent and a non-existent hash" '
- test "$tag_sha1 tag $tag_size
-$tag_content
-0000000000000000000000000000000000000000 missing" = \
- "$( ( echo $tag_sha1 &&
- echo_without_newline 0000000000000000000000000000000000000000 ) |
- git cat-file --batch)"
+ cat >expect <<-EOF &&
+ $tag_sha1 tag $tag_size
+ $tag_content
+ 0000000000000000000000000000000000000000 missing
+ EOF
+
+ printf "$tag_sha1\n0000000000000000000000000000000000000000" >in &&
+ git cat-file --batch <in >actual &&
+ test_cmp expect actual
'
test_expect_success "--batch-check for an empty line" '
- test " missing" = "$(echo | git cat-file --batch-check)"
+ cat >expect <<-EOF &&
+ missing
+ EOF
+
+ echo >in &&
+ git cat-file --batch-check <in >actual &&
+ test_cmp expect actual
'
test_expect_success 'empty --batch-check notices missing object' '
@@ -390,23 +393,34 @@ deadbeef
"
-batch_output="$hello_sha1 blob $hello_size
-$hello_content
-$commit_sha1 commit $commit_size
-$commit_content
-$tag_sha1 tag $tag_size
-$tag_content
-deadbeef missing
- missing"
+printf "%s\0" \
+ "$hello_sha1 blob $hello_size" \
+ "$hello_content" \
+ "$commit_sha1 commit $commit_size" \
+ "$commit_content" \
+ "$tag_sha1 tag $tag_size" \
+ "$tag_content" \
+ "deadbeef missing" \
+ " missing" >batch_output
test_expect_success '--batch with multiple sha1s gives correct format' '
- test "$(maybe_remove_timestamp "$batch_output" 1)" = "$(maybe_remove_timestamp "$(echo_without_newline "$batch_input" | git cat-file --batch)" 1)"
+ tr "\0" "\n" <batch_output >expect &&
+ echo_without_newline "$batch_input" >in &&
+ git cat-file --batch <in >actual &&
+ test_cmp expect actual
'
test_expect_success '--batch, -z with multiple sha1s gives correct format' '
echo_without_newline_nul "$batch_input" >in &&
- test "$(maybe_remove_timestamp "$batch_output" 1)" = \
- "$(maybe_remove_timestamp "$(git cat-file --batch -z <in)" 1)"
+ tr "\0" "\n" <batch_output >expect &&
+ git cat-file --batch -z <in >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '--batch, -Z with multiple sha1s gives correct format' '
+ echo_without_newline_nul "$batch_input" >in &&
+ git cat-file --batch -Z <in >actual &&
+ test_cmp batch_output actual
'
batch_check_input="$hello_sha1
@@ -417,36 +431,55 @@ deadbeef
"
-batch_check_output="$hello_sha1 blob $hello_size
-$tree_sha1 tree $tree_size
-$commit_sha1 commit $commit_size
-$tag_sha1 tag $tag_size
-deadbeef missing
- missing"
+printf "%s\0" \
+ "$hello_sha1 blob $hello_size" \
+ "$tree_sha1 tree $tree_size" \
+ "$commit_sha1 commit $commit_size" \
+ "$tag_sha1 tag $tag_size" \
+ "deadbeef missing" \
+ " missing" >batch_check_output
test_expect_success "--batch-check with multiple sha1s gives correct format" '
- test "$batch_check_output" = \
- "$(echo_without_newline "$batch_check_input" | git cat-file --batch-check)"
+ tr "\0" "\n" <batch_check_output >expect &&
+ echo_without_newline "$batch_check_input" >in &&
+ git cat-file --batch-check <in >actual &&
+ test_cmp expect actual
'
test_expect_success "--batch-check, -z with multiple sha1s gives correct format" '
- echo_without_newline_nul "$batch_check_input" >in &&
- test "$batch_check_output" = "$(git cat-file --batch-check -z <in)"
+ tr "\0" "\n" <batch_check_output >expect &&
+ echo_without_newline_nul "$batch_check_input" >in &&
+ git cat-file --batch-check -z <in >actual &&
+ test_cmp expect actual
'
-test_expect_success FUNNYNAMES '--batch-check, -z with newline in input' '
+test_expect_success "--batch-check, -Z with multiple sha1s gives correct format" '
+ echo_without_newline_nul "$batch_check_input" >in &&
+ git cat-file --batch-check -Z <in >actual &&
+ test_cmp batch_check_output actual
+'
+
+test_expect_success FUNNYNAMES 'setup with newline in input' '
touch -- "newline${LF}embedded" &&
git add -- "newline${LF}embedded" &&
git commit -m "file with newline embedded" &&
test_tick &&
- printf "HEAD:newline${LF}embedded" >in &&
- git cat-file --batch-check -z <in >actual &&
+ printf "HEAD:newline${LF}embedded" >in
+'
+test_expect_success FUNNYNAMES '--batch-check, -z with newline in input' '
+ git cat-file --batch-check -z <in >actual &&
echo "$(git rev-parse "HEAD:newline${LF}embedded") blob 0" >expect &&
test_cmp expect actual
'
+test_expect_success FUNNYNAMES '--batch-check, -Z with newline in input' '
+ git cat-file --batch-check -Z <in >actual &&
+ printf "%s\0" "$(git rev-parse "HEAD:newline${LF}embedded") blob 0" >expect &&
+ test_cmp expect actual
+'
+
batch_command_multiple_info="info $hello_sha1
info $tree_sha1
info $commit_sha1
@@ -470,7 +503,13 @@ test_expect_success '--batch-command with multiple info calls gives correct form
echo "$batch_command_multiple_info" | tr "\n" "\0" >in &&
git cat-file --batch-command --buffer -z <in >actual &&
- test_cmp expect actual
+ test_cmp expect actual &&
+
+ echo "$batch_command_multiple_info" | tr "\n" "\0" >in &&
+ tr "\n" "\0" <expect >expect_nul &&
+ git cat-file --batch-command --buffer -Z <in >actual &&
+
+ test_cmp expect_nul actual
'
batch_command_multiple_contents="contents $hello_sha1
@@ -480,27 +519,30 @@ contents deadbeef
flush"
test_expect_success '--batch-command with multiple command calls gives correct format' '
- remove_timestamp >expect <<-EOF &&
- $hello_sha1 blob $hello_size
- $hello_content
- $commit_sha1 commit $commit_size
- $commit_content
- $tag_sha1 tag $tag_size
- $tag_content
- deadbeef missing
- EOF
+ printf "%s\0" \
+ "$hello_sha1 blob $hello_size" \
+ "$hello_content" \
+ "$commit_sha1 commit $commit_size" \
+ "$commit_content" \
+ "$tag_sha1 tag $tag_size" \
+ "$tag_content" \
+ "deadbeef missing" >expect_nul &&
+ tr "\0" "\n" <expect_nul >expect &&
echo "$batch_command_multiple_contents" >in &&
- git cat-file --batch-command --buffer <in >actual_raw &&
+ git cat-file --batch-command --buffer <in >actual &&
- remove_timestamp <actual_raw >actual &&
test_cmp expect actual &&
echo "$batch_command_multiple_contents" | tr "\n" "\0" >in &&
- git cat-file --batch-command --buffer -z <in >actual_raw &&
+ git cat-file --batch-command --buffer -z <in >actual &&
- remove_timestamp <actual_raw >actual &&
- test_cmp expect actual
+ test_cmp expect actual &&
+
+ echo "$batch_command_multiple_contents" | tr "\n" "\0" >in &&
+ git cat-file --batch-command --buffer -Z <in >actual &&
+
+ test_cmp expect_nul actual
'
test_expect_success 'setup blobs which are likely to delta' '
@@ -840,6 +882,13 @@ test_expect_success 'git cat-file --batch-check --follow-symlinks works for brok
test_cmp expect actual
'
+test_expect_success 'git cat-file --batch-check --follow-symlinks -Z works for broken in-repo, same-dir links' '
+ printf "HEAD:broken-same-dir-link\0" >in &&
+ printf "dangling 25\0HEAD:broken-same-dir-link\0" >expect &&
+ git cat-file --batch-check --follow-symlinks -Z <in >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'git cat-file --batch-check --follow-symlinks works for same-dir links-to-links' '
echo HEAD:link-to-link | git cat-file --batch-check --follow-symlinks >actual &&
test_cmp found actual
@@ -854,6 +903,15 @@ test_expect_success 'git cat-file --batch-check --follow-symlinks works for pare
test_cmp expect actual
'
+test_expect_success 'git cat-file --batch-check --follow-symlinks -Z works for parent-dir links' '
+ echo HEAD:dir/parent-dir-link | git cat-file --batch-check --follow-symlinks >actual &&
+ test_cmp found actual &&
+ printf "notdir 29\0HEAD:dir/parent-dir-link/nope\0" >expect &&
+ printf "HEAD:dir/parent-dir-link/nope\0" >in &&
+ git cat-file --batch-check --follow-symlinks -Z <in >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'git cat-file --batch-check --follow-symlinks works for .. links' '
echo dangling 22 >expect &&
echo HEAD:dir/link-dir/nope >>expect &&
@@ -968,6 +1026,13 @@ test_expect_success 'git cat-file --batch-check --follow-symlink breaks loops' '
test_cmp expect actual
'
+test_expect_success 'git cat-file --batch-check --follow-symlink -Z breaks loops' '
+ printf "loop 10\0HEAD:loop1\0" >expect &&
+ printf "HEAD:loop1\0" >in &&
+ git cat-file --batch-check --follow-symlinks -Z <in >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'git cat-file --batch --follow-symlink returns correct sha and mode' '
echo HEAD:morx | git cat-file --batch >expect &&
echo HEAD:morx | git cat-file --batch --follow-symlinks >actual &&
diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
index a63d0cc222..8a95adf4b5 100755
--- a/t/t1092-sparse-checkout-compatibility.sh
+++ b/t/t1092-sparse-checkout-compatibility.sh
@@ -2180,4 +2180,83 @@ test_expect_success 'sparse index is not expanded: diff-files' '
ensure_not_expanded diff-files -- "deep/*"
'
+test_expect_success 'diff-tree' '
+ init_repos &&
+
+ # Test change inside sparse cone
+ tree1=$(git -C sparse-index rev-parse HEAD^{tree}) &&
+ tree2=$(git -C sparse-index rev-parse update-deep^{tree}) &&
+ test_all_match git diff-tree $tree1 $tree2 &&
+ test_all_match git diff-tree $tree1 $tree2 -- deep/a &&
+ test_all_match git diff-tree HEAD update-deep &&
+ test_all_match git diff-tree HEAD update-deep -- deep/a &&
+
+ # Test change outside sparse cone
+ tree3=$(git -C sparse-index rev-parse update-folder1^{tree}) &&
+ test_all_match git diff-tree $tree1 $tree3 &&
+ test_all_match git diff-tree $tree1 $tree3 -- folder1/a &&
+ test_all_match git diff-tree HEAD update-folder1 &&
+ test_all_match git diff-tree HEAD update-folder1 -- folder1/a &&
+
+ # Check that SKIP_WORKTREE files are not materialized
+ test_path_is_missing sparse-checkout/folder1/a &&
+ test_path_is_missing sparse-index/folder1/a &&
+ test_path_is_missing sparse-checkout/folder2/a &&
+ test_path_is_missing sparse-index/folder2/a
+'
+
+test_expect_success 'sparse-index is not expanded: diff-tree' '
+ init_repos &&
+
+ tree1=$(git -C sparse-index rev-parse HEAD^{tree}) &&
+ tree2=$(git -C sparse-index rev-parse update-deep^{tree}) &&
+ tree3=$(git -C sparse-index rev-parse update-folder1^{tree}) &&
+
+ ensure_not_expanded diff-tree $tree1 $tree2 &&
+ ensure_not_expanded diff-tree $tree1 $tree2 -- deep/a &&
+ ensure_not_expanded diff-tree HEAD update-deep &&
+ ensure_not_expanded diff-tree HEAD update-deep -- deep/a &&
+ ensure_not_expanded diff-tree $tree1 $tree3 &&
+ ensure_not_expanded diff-tree $tree1 $tree3 -- folder1/a &&
+ ensure_not_expanded diff-tree HEAD update-folder1 &&
+ ensure_not_expanded diff-tree HEAD update-folder1 -- folder1/a
+'
+
+test_expect_success 'worktree' '
+ init_repos &&
+
+ write_script edit-contents <<-\EOF &&
+ echo text >>"$1"
+ EOF
+
+ for repo in full-checkout sparse-checkout sparse-index
+ do
+ worktree=${repo}-wt &&
+ git -C $repo worktree add ../$worktree &&
+
+ # Compare worktree content with "ls"
+ (cd $repo && ls) >worktree_contents &&
+ (cd $worktree && ls) >new_worktree_contents &&
+ test_cmp worktree_contents new_worktree_contents &&
+
+ # Compare index content with "ls-files --sparse"
+ git -C $repo ls-files --sparse >index_contents &&
+ git -C $worktree ls-files --sparse >new_index_contents &&
+ test_cmp index_contents new_index_contents &&
+
+ git -C $repo worktree remove ../$worktree || return 1
+ done &&
+
+ test_all_match git worktree add .worktrees/hotfix &&
+ run_on_all ../edit-contents .worktrees/hotfix/deep/a &&
+ test_all_match test_must_fail git worktree remove .worktrees/hotfix
+'
+
+test_expect_success 'worktree is not expanded' '
+ init_repos &&
+
+ ensure_not_expanded worktree add .worktrees/hotfix &&
+ ensure_not_expanded worktree remove .worktrees/hotfix
+'
+
test_done
diff --git a/t/t1300-config.sh b/t/t1300-config.sh
index 86bfbc2b36..387d336c91 100755
--- a/t/t1300-config.sh
+++ b/t/t1300-config.sh
@@ -1668,6 +1668,21 @@ test_expect_success 'urlmatch' '
test_cmp expect actual
'
+test_expect_success 'urlmatch with --show-scope' '
+ cat >.git/config <<-\EOF &&
+ [http "https://weak.example.com"]
+ sslVerify = false
+ cookieFile = /tmp/cookie.txt
+ EOF
+
+ cat >expect <<-EOF &&
+ local http.cookiefile /tmp/cookie.txt
+ local http.sslverify false
+ EOF
+ git config --get-urlmatch --show-scope HTTP https://weak.example.com >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'urlmatch favors more specific URLs' '
cat >.git/config <<-\EOF &&
[http "https://example.com/"]
@@ -2055,6 +2070,12 @@ test_expect_success '--show-origin blob ref' '
test_cmp expect output
'
+test_expect_success '--show-origin with --default' '
+ git config --show-origin --default foo some.key >actual &&
+ echo "command line: foo" >expect &&
+ test_cmp expect actual
+'
+
test_expect_success '--show-scope with --list' '
cat >expect <<-EOF &&
global user.global=true
@@ -2123,6 +2144,12 @@ test_expect_success '--show-scope with --show-origin' '
test_cmp expect output
'
+test_expect_success '--show-scope with --default' '
+ git config --show-scope --default foo some.key >actual &&
+ echo "command foo" >expect &&
+ test_cmp expect actual
+'
+
test_expect_success 'override global and system config' '
test_when_finished rm -f \"\$HOME\"/.gitconfig &&
cat >"$HOME"/.gitconfig <<-EOF &&
diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh
index ae5cd3f5a0..e5a0d65caa 100755
--- a/t/t1301-shared-repo.sh
+++ b/t/t1301-shared-repo.sh
@@ -52,6 +52,28 @@ test_expect_success 'shared=all' '
test 2 = $(git config core.sharedrepository)
'
+test_expect_failure 'template can set core.bare' '
+ test_when_finished "rm -rf subdir" &&
+ test_when_finished "rm -rf templates" &&
+ test_config core.bare true &&
+ umask 0022 &&
+ mkdir -p templates/ &&
+ cp .git/config templates/config &&
+ git init --template=templates subdir &&
+ test_path_exists subdir/HEAD
+'
+
+test_expect_success 'template can set core.bare but overridden by command line' '
+ test_when_finished "rm -rf subdir" &&
+ test_when_finished "rm -rf templates" &&
+ test_config core.bare true &&
+ umask 0022 &&
+ mkdir -p templates/ &&
+ cp .git/config templates/config &&
+ git init --no-bare --template=templates subdir &&
+ test_path_exists subdir/.git/HEAD
+'
+
test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository' '
: > a1 &&
git add a1 &&
diff --git a/t/t1419-exclude-refs.sh b/t/t1419-exclude-refs.sh
new file mode 100755
index 0000000000..5d8c86b657
--- /dev/null
+++ b/t/t1419-exclude-refs.sh
@@ -0,0 +1,122 @@
+#!/bin/sh
+
+test_description='test exclude_patterns functionality in main ref store'
+
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
+TEST_PASSES_SANITIZE_LEAK=true
+. ./test-lib.sh
+
+for_each_ref__exclude () {
+ GIT_TRACE2_PERF=1 test-tool ref-store main \
+ for-each-ref--exclude "$@" >actual.raw
+ cut -d ' ' -f 2 actual.raw
+}
+
+for_each_ref () {
+ git for-each-ref --format='%(refname)' "$@"
+}
+
+assert_jumps () {
+ local nr="$1"
+ local trace="$2"
+
+ grep -q "name:jumps_made value:$nr$" $trace
+}
+
+assert_no_jumps () {
+ ! assert_jumps ".*" "$1"
+}
+
+test_expect_success 'setup' '
+ test_commit --no-tag base &&
+ base="$(git rev-parse HEAD)" &&
+
+ for name in foo bar baz quux
+ do
+ for i in 1 2 3
+ do
+ echo "create refs/heads/$name/$i $base" || return 1
+ done || return 1
+ done >in &&
+ echo "delete refs/heads/main" >>in &&
+
+ git update-ref --stdin <in &&
+ git pack-refs --all
+'
+
+test_expect_success 'excluded region in middle' '
+ for_each_ref__exclude refs/heads refs/heads/foo >actual 2>perf &&
+ for_each_ref refs/heads/bar refs/heads/baz refs/heads/quux >expect &&
+
+ test_cmp expect actual &&
+ assert_jumps 1 perf
+'
+
+test_expect_success 'excluded region at beginning' '
+ for_each_ref__exclude refs/heads refs/heads/bar >actual 2>perf &&
+ for_each_ref refs/heads/baz refs/heads/foo refs/heads/quux >expect &&
+
+ test_cmp expect actual &&
+ assert_jumps 1 perf
+'
+
+test_expect_success 'excluded region at end' '
+ for_each_ref__exclude refs/heads refs/heads/quux >actual 2>perf &&
+ for_each_ref refs/heads/foo refs/heads/bar refs/heads/baz >expect &&
+
+ test_cmp expect actual &&
+ assert_jumps 1 perf
+'
+
+test_expect_success 'disjoint excluded regions' '
+ for_each_ref__exclude refs/heads refs/heads/bar refs/heads/quux >actual 2>perf &&
+ for_each_ref refs/heads/baz refs/heads/foo >expect &&
+
+ test_cmp expect actual &&
+ assert_jumps 2 perf
+'
+
+test_expect_success 'adjacent, non-overlapping excluded regions' '
+ for_each_ref__exclude refs/heads refs/heads/bar refs/heads/baz >actual 2>perf &&
+ for_each_ref refs/heads/foo refs/heads/quux >expect &&
+
+ test_cmp expect actual &&
+ assert_jumps 1 perf
+'
+
+test_expect_success 'overlapping excluded regions' '
+ for_each_ref__exclude refs/heads refs/heads/ba refs/heads/baz >actual 2>perf &&
+ for_each_ref refs/heads/foo refs/heads/quux >expect &&
+
+ test_cmp expect actual &&
+ assert_jumps 1 perf
+'
+
+test_expect_success 'several overlapping excluded regions' '
+ for_each_ref__exclude refs/heads \
+ refs/heads/bar refs/heads/baz refs/heads/foo >actual 2>perf &&
+ for_each_ref refs/heads/quux >expect &&
+
+ test_cmp expect actual &&
+ assert_jumps 1 perf
+'
+
+test_expect_success 'non-matching excluded section' '
+ for_each_ref__exclude refs/heads refs/heads/does/not/exist >actual 2>perf &&
+ for_each_ref >expect &&
+
+ test_cmp expect actual &&
+ assert_no_jumps perf
+'
+
+test_expect_success 'meta-characters are discarded' '
+ for_each_ref__exclude refs/heads "refs/heads/ba*" >actual 2>perf &&
+ for_each_ref >expect &&
+
+ test_cmp expect actual &&
+ assert_no_jumps perf
+'
+
+test_done
diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh
index 8c442adb1a..5805d47eb9 100755
--- a/t/t1450-fsck.sh
+++ b/t/t1450-fsck.sh
@@ -1036,9 +1036,9 @@ test_expect_success 'fsck detects problems in worktree index' '
test_cmp expect actual
'
-test_expect_success 'fsck reports problems in main index without filename' '
+test_expect_success 'fsck reports problems in current worktree 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 &&
+ echo "this object will be removed to break current worktree index" >file &&
git add file &&
blob=$(git rev-parse :file) &&
remove_object $blob &&
diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh
index cb9ef7e329..b9af6b3ac0 100755
--- a/t/t1507-rev-parse-upstream.sh
+++ b/t/t1507-rev-parse-upstream.sh
@@ -5,6 +5,7 @@ test_description='test <branch>@{upstream} syntax'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
diff --git a/t/t1508-at-combinations.sh b/t/t1508-at-combinations.sh
index 87a4286414..e841309d0e 100755
--- a/t/t1508-at-combinations.sh
+++ b/t/t1508-at-combinations.sh
@@ -4,6 +4,7 @@ test_description='test various @{X} syntax combinations together'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
check() {
diff --git a/t/t1514-rev-parse-push.sh b/t/t1514-rev-parse-push.sh
index d868a08110..a835a196aa 100755
--- a/t/t1514-rev-parse-push.sh
+++ b/t/t1514-rev-parse-push.sh
@@ -4,6 +4,7 @@ test_description='test <branch>@{push} syntax'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
resolve () {
diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh
index 3506f627b6..8b0234cf2d 100755
--- a/t/t1800-hook.sh
+++ b/t/t1800-hook.sh
@@ -156,25 +156,15 @@ test_expect_success 'git hook run a hook with a bad shebang' '
mkdir bad-hooks &&
write_script bad-hooks/test-hook "/bad/path/no/spaces" </dev/null &&
- # TODO: We should emit the same (or at least a more similar)
- # error on MINGW (essentially Git for Windows) and all other
- # platforms.. See the OS-specific code in start_command()
- if test_have_prereq !MINGW
- then
- cat >expect <<-\EOF
- fatal: cannot run bad-hooks/test-hook: ...
- EOF
- else
- cat >expect <<-\EOF
- error: cannot spawn bad-hooks/test-hook: ...
- EOF
- fi &&
test_expect_code 1 git \
-c core.hooksPath=bad-hooks \
hook run test-hook >out 2>err &&
test_must_be_empty out &&
- sed -e "s/test-hook: .*/test-hook: .../" <err >actual &&
- test_cmp expect actual
+
+ # TODO: We should emit the same (or at least a more similar)
+ # error on MINGW (essentially Git for Windows) and all other
+ # platforms.. See the OS-specific code in start_command()
+ grep -E "^(error|fatal): cannot (exec|spawn) .*bad-hooks/test-hook" err
'
test_expect_success 'stdin to hooks' '
diff --git a/t/t2027-checkout-track.sh b/t/t2027-checkout-track.sh
index dca35aa3e3..a8bbc60954 100755
--- a/t/t2027-checkout-track.sh
+++ b/t/t2027-checkout-track.sh
@@ -5,6 +5,7 @@ test_description='tests for git branch --track'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh
index be394f1131..c01492f33f 100755
--- a/t/t2200-add-update.sh
+++ b/t/t2200-add-update.sh
@@ -197,4 +197,15 @@ test_expect_success '"add -u non-existent" should fail' '
! grep "non-existent" actual
'
+test_expect_success '"commit -a" implies "add -u" if index becomes empty' '
+ git rm -rf \* &&
+ git commit -m clean-slate &&
+ test_commit file1 &&
+ rm file1.t &&
+ test_tick &&
+ git commit -a -m remove &&
+ git ls-tree HEAD: >out &&
+ test_must_be_empty out
+'
+
test_done
diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh
index d587e0b20d..051363acbb 100755
--- a/t/t2400-worktree-add.sh
+++ b/t/t2400-worktree-add.sh
@@ -298,17 +298,24 @@ test_expect_success '"add" no auto-vivify with --detach and <branch> omitted' '
test_must_fail git -C mish/mash symbolic-ref HEAD
'
-test_expect_success '"add" -b/-B mutually exclusive' '
- test_must_fail git worktree add -b poodle -B poodle bamboo main
-'
-
-test_expect_success '"add" -b/--detach mutually exclusive' '
- test_must_fail git worktree add -b poodle --detach bamboo main
-'
+# Helper function to test mutually exclusive options.
+#
+# Note: Quoted arguments containing spaces are not supported.
+test_wt_add_excl () {
+ local opts="$*" &&
+ test_expect_success "'worktree add' with '$opts' has mutually exclusive options" '
+ test_must_fail git worktree add $opts 2>actual &&
+ grep -E "fatal:( options)? .* cannot be used together" actual
+ '
+}
-test_expect_success '"add" -B/--detach mutually exclusive' '
- test_must_fail git worktree add -B poodle --detach bamboo main
-'
+test_wt_add_excl -b poodle -B poodle bamboo main
+test_wt_add_excl -b poodle --detach bamboo main
+test_wt_add_excl -B poodle --detach bamboo main
+test_wt_add_excl --orphan --detach bamboo
+test_wt_add_excl --orphan --no-checkout bamboo
+test_wt_add_excl --orphan bamboo main
+test_wt_add_excl --orphan -b bamboo wtdir/ main
test_expect_success '"add -B" fails if the branch is checked out' '
git rev-parse newmain >before &&
@@ -326,10 +333,111 @@ test_expect_success 'add -B' '
'
test_expect_success 'add --quiet' '
+ test_when_finished "git worktree remove -f -f another-worktree" &&
git worktree add --quiet another-worktree main 2>actual &&
test_must_be_empty actual
'
+test_expect_success 'add --quiet -b' '
+ test_when_finished "git branch -D quietnewbranch" &&
+ test_when_finished "git worktree remove -f -f another-worktree" &&
+ git worktree add --quiet -b quietnewbranch another-worktree 2>actual &&
+ test_must_be_empty actual
+'
+
+test_expect_success '"add --orphan"' '
+ test_when_finished "git worktree remove -f -f orphandir" &&
+ git worktree add --orphan -b neworphan orphandir &&
+ echo refs/heads/neworphan >expected &&
+ git -C orphandir symbolic-ref HEAD >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success '"add --orphan (no -b)"' '
+ test_when_finished "git worktree remove -f -f neworphan" &&
+ git worktree add --orphan neworphan &&
+ echo refs/heads/neworphan >expected &&
+ git -C neworphan symbolic-ref HEAD >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success '"add --orphan --quiet"' '
+ test_when_finished "git worktree remove -f -f orphandir" &&
+ git worktree add --quiet --orphan -b neworphan orphandir 2>log.actual &&
+ test_must_be_empty log.actual &&
+ echo refs/heads/neworphan >expected &&
+ git -C orphandir symbolic-ref HEAD >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success '"add --orphan" fails if the branch already exists' '
+ test_when_finished "git branch -D existingbranch" &&
+ git worktree add -b existingbranch orphandir main &&
+ git worktree remove orphandir &&
+ test_must_fail git worktree add --orphan -b existingbranch orphandir
+'
+
+test_expect_success '"add --orphan" with empty repository' '
+ test_when_finished "rm -rf empty_repo" &&
+ echo refs/heads/newbranch >expected &&
+ GIT_DIR="empty_repo" git init --bare &&
+ git -C empty_repo worktree add --orphan -b newbranch worktreedir &&
+ git -C empty_repo/worktreedir symbolic-ref HEAD >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success '"add" worktree with orphan branch and lock' '
+ git worktree add --lock --orphan -b orphanbr orphan-with-lock &&
+ test_when_finished "git worktree unlock orphan-with-lock || :" &&
+ test -f .git/worktrees/orphan-with-lock/locked
+'
+
+test_expect_success '"add" worktree with orphan branch, lock, and reason' '
+ lock_reason="why not" &&
+ git worktree add --detach --lock --reason "$lock_reason" orphan-with-lock-reason main &&
+ test_when_finished "git worktree unlock orphan-with-lock-reason || :" &&
+ test -f .git/worktrees/orphan-with-lock-reason/locked &&
+ echo "$lock_reason" >expect &&
+ test_cmp expect .git/worktrees/orphan-with-lock-reason/locked
+'
+
+# Note: Quoted arguments containing spaces are not supported.
+test_wt_add_orphan_hint () {
+ local context="$1" &&
+ local use_branch=$2 &&
+ shift 2 &&
+ local opts="$*" &&
+ test_expect_success "'worktree add' show orphan hint in bad/orphan HEAD w/ $context" '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (cd repo && test_commit commit) &&
+ git -C repo switch --orphan noref &&
+ test_must_fail git -C repo worktree add $opts foobar/ 2>actual &&
+ ! grep "error: unknown switch" actual &&
+ grep "hint: If you meant to create a worktree containing a new orphan branch" actual &&
+ if [ $use_branch -eq 1 ]
+ then
+ grep -E "^hint: +git worktree add --orphan -b [^ ]+ [^ ]+$" actual
+ else
+ grep -E "^hint: +git worktree add --orphan [^ ]+$" actual
+ fi
+
+ '
+}
+
+test_wt_add_orphan_hint 'no opts' 0
+test_wt_add_orphan_hint '-b' 1 -b foobar_branch
+test_wt_add_orphan_hint '-B' 1 -B foobar_branch
+
+test_expect_success "'worktree add' doesn't show orphan hint in bad/orphan HEAD w/ --quiet" '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (cd repo && test_commit commit) &&
+ test_must_fail git -C repo worktree add --quiet foobar_branch foobar/ 2>actual &&
+ ! grep "error: unknown switch" actual &&
+ ! grep "hint: If you meant to create a worktree containing a new orphan branch" actual
+'
+
test_expect_success 'local clone from linked checkout' '
git clone --local here here-clone &&
( cd here-clone && git fsck )
@@ -446,6 +554,14 @@ setup_remote_repo () {
)
}
+test_expect_success '"add" <path> <remote/branch> w/ no HEAD' '
+ test_when_finished rm -rf repo_upstream repo_local foo &&
+ setup_remote_repo repo_upstream repo_local &&
+ git -C repo_local config --bool core.bare true &&
+ git -C repo_local branch -D main &&
+ git -C repo_local worktree add ./foo repo_upstream/foo
+'
+
test_expect_success '--no-track avoids setting up tracking' '
test_when_finished rm -rf repo_upstream repo_local foo &&
setup_remote_repo repo_upstream repo_local &&
@@ -528,6 +644,35 @@ test_expect_success 'git worktree add --guess-remote sets up tracking' '
test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo
)
'
+test_expect_success 'git worktree add --guess-remote sets up tracking (quiet)' '
+ test_when_finished rm -rf repo_a repo_b foo &&
+ setup_remote_repo repo_a repo_b &&
+ (
+ cd repo_b &&
+ git worktree add --quiet --guess-remote ../foo 2>actual &&
+ test_must_be_empty actual
+ ) &&
+ (
+ cd foo &&
+ test_branch_upstream foo repo_a foo &&
+ test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo
+ )
+'
+
+test_expect_success 'git worktree --no-guess-remote (quiet)' '
+ test_when_finished rm -rf repo_a repo_b foo &&
+ setup_remote_repo repo_a repo_b &&
+ (
+ cd repo_b &&
+ git worktree add --quiet --no-guess-remote ../foo
+ ) &&
+ (
+ cd foo &&
+ test_must_fail git config "branch.foo.remote" &&
+ test_must_fail git config "branch.foo.merge" &&
+ test_cmp_rev ! refs/remotes/repo_a/foo refs/heads/foo
+ )
+'
test_expect_success 'git worktree add with worktree.guessRemote sets up tracking' '
test_when_finished rm -rf repo_a repo_b foo &&
@@ -560,6 +705,348 @@ test_expect_success 'git worktree --no-guess-remote option overrides config' '
)
'
+test_dwim_orphan () {
+ local info_text="No possible source branch, inferring '--orphan'" &&
+ local fetch_error_text="fatal: No local or remote refs exist despite at least one remote" &&
+ local orphan_hint="hint: If you meant to create a worktree containing a new orphan branch" &&
+ local invalid_ref_regex="^fatal: invalid reference: " &&
+ local bad_combo_regex="^fatal: '[-a-z]*' and '[-a-z]*' cannot be used together" &&
+
+ local git_ns="repo" &&
+ local dashc_args="-C $git_ns" &&
+ local use_cd=0 &&
+
+ local bad_head=0 &&
+ local empty_repo=1 &&
+ local local_ref=0 &&
+ local use_quiet=0 &&
+ local remote=0 &&
+ local remote_ref=0 &&
+ local use_detach=0 &&
+ local use_new_branch=0 &&
+
+ local outcome="$1" &&
+ local outcome_text &&
+ local success &&
+ shift &&
+ local args="" &&
+ local context="" &&
+ case "$outcome" in
+ "infer")
+ success=1 &&
+ outcome_text='"add" DWIM infer --orphan'
+ ;;
+ "no_infer")
+ success=1 &&
+ outcome_text='"add" DWIM doesnt infer --orphan'
+ ;;
+ "fetch_error")
+ success=0 &&
+ outcome_text='"add" error need fetch'
+ ;;
+ "fatal_orphan_bad_combo")
+ success=0 &&
+ outcome_text='"add" error inferred "--orphan" gives illegal opts combo'
+ ;;
+ "warn_bad_head")
+ success=0 &&
+ outcome_text='"add" error, warn on bad HEAD, hint use orphan'
+ ;;
+ *)
+ echo "test_dwim_orphan(): invalid outcome: '$outcome'" >&2 &&
+ return 1
+ ;;
+ esac &&
+ while [ $# -gt 0 ]
+ do
+ case "$1" in
+ # How and from where to create the worktree
+ "-C_repo")
+ use_cd=0 &&
+ git_ns="repo" &&
+ dashc_args="-C $git_ns" &&
+ context="$context, 'git -C repo'"
+ ;;
+ "-C_wt")
+ use_cd=0 &&
+ git_ns="wt" &&
+ dashc_args="-C $git_ns" &&
+ context="$context, 'git -C wt'"
+ ;;
+ "cd_repo")
+ use_cd=1 &&
+ git_ns="repo" &&
+ dashc_args="" &&
+ context="$context, 'cd repo && git'"
+ ;;
+ "cd_wt")
+ use_cd=1 &&
+ git_ns="wt" &&
+ dashc_args="" &&
+ context="$context, 'cd wt && git'"
+ ;;
+
+ # Bypass the "pull first" warning
+ "force")
+ args="$args --force" &&
+ context="$context, --force"
+ ;;
+
+ # Try to use remote refs when DWIM
+ "guess_remote")
+ args="$args --guess-remote" &&
+ context="$context, --guess-remote"
+ ;;
+ "no_guess_remote")
+ args="$args --no-guess-remote" &&
+ context="$context, --no-guess-remote"
+ ;;
+
+ # Whether there is at least one local branch present
+ "local_ref")
+ empty_repo=0 &&
+ local_ref=1 &&
+ context="$context, >=1 local branches"
+ ;;
+ "no_local_ref")
+ empty_repo=0 &&
+ context="$context, 0 local branches"
+ ;;
+
+ # Whether the HEAD points at a valid ref (skip this opt when no refs)
+ "good_head")
+ # requires: local_ref
+ context="$context, valid HEAD"
+ ;;
+ "bad_head")
+ bad_head=1 &&
+ context="$context, invalid (or orphan) HEAD"
+ ;;
+
+ # Whether the code path is tested with the base add command, -b, or --detach
+ "no_-b")
+ use_new_branch=0 &&
+ context="$context, no --branch"
+ ;;
+ "-b")
+ use_new_branch=1 &&
+ context="$context, --branch"
+ ;;
+ "detach")
+ use_detach=1 &&
+ context="$context, --detach"
+ ;;
+
+ # Whether to check that all output is suppressed (except errors)
+ # or that the output is as expected
+ "quiet")
+ use_quiet=1 &&
+ args="$args --quiet" &&
+ context="$context, --quiet"
+ ;;
+ "no_quiet")
+ use_quiet=0 &&
+ context="$context, no --quiet (expect output)"
+ ;;
+
+ # Whether there is at least one remote attached to the repo
+ "remote")
+ empty_repo=0 &&
+ remote=1 &&
+ context="$context, >=1 remotes"
+ ;;
+ "no_remote")
+ empty_repo=0 &&
+ remote=0 &&
+ context="$context, 0 remotes"
+ ;;
+
+ # Whether there is at least one valid remote ref
+ "remote_ref")
+ # requires: remote
+ empty_repo=0 &&
+ remote_ref=1 &&
+ context="$context, >=1 fetched remote branches"
+ ;;
+ "no_remote_ref")
+ empty_repo=0 &&
+ remote_ref=0 &&
+ context="$context, 0 fetched remote branches"
+ ;;
+
+ # Options or flags that become illegal when --orphan is inferred
+ "no_checkout")
+ args="$args --no-checkout" &&
+ context="$context, --no-checkout"
+ ;;
+ "track")
+ args="$args --track" &&
+ context="$context, --track"
+ ;;
+
+ # All other options are illegal
+ *)
+ echo "test_dwim_orphan(): invalid arg: '$1'" >&2 &&
+ return 1
+ ;;
+ esac &&
+ shift
+ done &&
+ context="${context#', '}" &&
+ if [ $use_new_branch -eq 1 ]
+ then
+ args="$args -b foo"
+ elif [ $use_detach -eq 1 ]
+ then
+ args="$args --detach"
+ else
+ context="DWIM (no --branch), $context"
+ fi &&
+ if [ $empty_repo -eq 1 ]
+ then
+ context="empty repo, $context"
+ fi &&
+ args="$args ../foo" &&
+ context="${context%', '}" &&
+ test_expect_success "$outcome_text w/ $context" '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ if [ $local_ref -eq 1 ] && [ "$git_ns" = "repo" ]
+ then
+ (cd repo && test_commit commit) &&
+ if [ $bad_head -eq 1 ]
+ then
+ git -C repo symbolic-ref HEAD refs/heads/badbranch
+ fi
+ elif [ $local_ref -eq 1 ] && [ "$git_ns" = "wt" ]
+ then
+ test_when_finished "git -C repo worktree remove -f ../wt" &&
+ git -C repo worktree add --orphan -b main ../wt &&
+ (cd wt && test_commit commit) &&
+ if [ $bad_head -eq 1 ]
+ then
+ git -C wt symbolic-ref HEAD refs/heads/badbranch
+ fi
+ elif [ $local_ref -eq 0 ] && [ "$git_ns" = "wt" ]
+ then
+ test_when_finished "git -C repo worktree remove -f ../wt" &&
+ git -C repo worktree add --orphan -b orphanbranch ../wt
+ fi &&
+
+ if [ $remote -eq 1 ]
+ then
+ test_when_finished "rm -rf upstream" &&
+ git init upstream &&
+ (cd upstream && test_commit commit) &&
+ git -C upstream switch -c foo &&
+ git -C repo remote add upstream ../upstream
+ fi &&
+
+ if [ $remote_ref -eq 1 ]
+ then
+ git -C repo fetch
+ fi &&
+ if [ $success -eq 1 ]
+ then
+ test_when_finished git -C repo worktree remove ../foo
+ fi &&
+ (
+ if [ $use_cd -eq 1 ]
+ then
+ cd $git_ns
+ fi &&
+ if [ "$outcome" = "infer" ]
+ then
+ git $dashc_args worktree add $args 2>actual &&
+ if [ $use_quiet -eq 1 ]
+ then
+ test_must_be_empty actual
+ else
+ grep "$info_text" actual
+ fi
+ elif [ "$outcome" = "no_infer" ]
+ then
+ git $dashc_args worktree add $args 2>actual &&
+ if [ $use_quiet -eq 1 ]
+ then
+ test_must_be_empty actual
+ else
+ ! grep "$info_text" actual
+ fi
+ elif [ "$outcome" = "fetch_error" ]
+ then
+ test_must_fail git $dashc_args worktree add $args 2>actual &&
+ grep "$fetch_error_text" actual
+ elif [ "$outcome" = "fatal_orphan_bad_combo" ]
+ then
+ test_must_fail git $dashc_args worktree add $args 2>actual &&
+ if [ $use_quiet -eq 1 ]
+ then
+ ! grep "$info_text" actual
+ else
+ grep "$info_text" actual
+ fi &&
+ grep "$bad_combo_regex" actual
+ elif [ "$outcome" = "warn_bad_head" ]
+ then
+ test_must_fail git $dashc_args worktree add $args 2>actual &&
+ if [ $use_quiet -eq 1 ]
+ then
+ grep "$invalid_ref_regex" actual &&
+ ! grep "$orphan_hint" actual
+ else
+ headpath=$(git $dashc_args rev-parse --path-format=absolute --git-path HEAD) &&
+ headcontents=$(cat "$headpath") &&
+ grep "HEAD points to an invalid (or orphaned) reference" actual &&
+ grep "HEAD path: .$headpath." actual &&
+ grep "HEAD contents: .$headcontents." actual &&
+ grep "$orphan_hint" actual &&
+ ! grep "$info_text" actual
+ fi &&
+ grep "$invalid_ref_regex" actual
+ else
+ # Unreachable
+ false
+ fi
+ ) &&
+ if [ $success -ne 1 ]
+ then
+ test_path_is_missing foo
+ fi
+ '
+}
+
+for quiet_mode in "no_quiet" "quiet"
+do
+ for changedir_type in "cd_repo" "cd_wt" "-C_repo" "-C_wt"
+ do
+ dwim_test_args="$quiet_mode $changedir_type"
+ test_dwim_orphan 'infer' $dwim_test_args no_-b
+ test_dwim_orphan 'no_infer' $dwim_test_args no_-b local_ref good_head
+ test_dwim_orphan 'infer' $dwim_test_args no_-b no_local_ref no_remote no_remote_ref no_guess_remote
+ test_dwim_orphan 'infer' $dwim_test_args no_-b no_local_ref remote no_remote_ref no_guess_remote
+ test_dwim_orphan 'fetch_error' $dwim_test_args no_-b no_local_ref remote no_remote_ref guess_remote
+ test_dwim_orphan 'infer' $dwim_test_args no_-b no_local_ref remote no_remote_ref guess_remote force
+ test_dwim_orphan 'no_infer' $dwim_test_args no_-b no_local_ref remote remote_ref guess_remote
+
+ test_dwim_orphan 'infer' $dwim_test_args -b
+ test_dwim_orphan 'no_infer' $dwim_test_args -b local_ref good_head
+ test_dwim_orphan 'infer' $dwim_test_args -b no_local_ref no_remote no_remote_ref no_guess_remote
+ test_dwim_orphan 'infer' $dwim_test_args -b no_local_ref remote no_remote_ref no_guess_remote
+ test_dwim_orphan 'infer' $dwim_test_args -b no_local_ref remote no_remote_ref guess_remote
+ test_dwim_orphan 'infer' $dwim_test_args -b no_local_ref remote remote_ref guess_remote
+
+ test_dwim_orphan 'warn_bad_head' $dwim_test_args no_-b local_ref bad_head
+ test_dwim_orphan 'warn_bad_head' $dwim_test_args -b local_ref bad_head
+ test_dwim_orphan 'warn_bad_head' $dwim_test_args detach local_ref bad_head
+ done
+
+ test_dwim_orphan 'fatal_orphan_bad_combo' $quiet_mode no_-b no_checkout
+ test_dwim_orphan 'fatal_orphan_bad_combo' $quiet_mode no_-b track
+ test_dwim_orphan 'fatal_orphan_bad_combo' $quiet_mode -b no_checkout
+ test_dwim_orphan 'fatal_orphan_bad_combo' $quiet_mode -b track
+done
+
post_checkout_hook () {
test_when_finished "rm -rf .git/hooks" &&
mkdir .git/hooks &&
diff --git a/t/t2407-worktree-heads.sh b/t/t2407-worktree-heads.sh
index 019a40df2c..469443d8ae 100755
--- a/t/t2407-worktree-heads.sh
+++ b/t/t2407-worktree-heads.sh
@@ -58,7 +58,7 @@ test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in bisect' '
git -C wt-4 bisect good wt-1 &&
test_must_fail git branch -f wt-4 HEAD 2>err &&
- grep "cannot force update the branch '\''wt-4'\'' checked out at.*wt-4" err
+ grep "cannot force update the branch '\''wt-4'\'' used by worktree at.*wt-4" err
'
test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase (apply)' '
@@ -68,7 +68,7 @@ test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase (app
test_must_fail git -C wt-2 rebase --apply conflict-2 &&
test_must_fail git branch -f wt-2 HEAD 2>err &&
- grep "cannot force update the branch '\''wt-2'\'' checked out at.*wt-2" err
+ grep "cannot force update the branch '\''wt-2'\'' used by worktree at.*wt-2" err
'
test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase (merge)' '
@@ -78,7 +78,7 @@ test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase (mer
test_must_fail git -C wt-2 rebase conflict-2 &&
test_must_fail git branch -f wt-2 HEAD 2>err &&
- grep "cannot force update the branch '\''wt-2'\'' checked out at.*wt-2" err
+ grep "cannot force update the branch '\''wt-2'\'' used by worktree at.*wt-2" err
'
test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase with --update-refs' '
@@ -90,7 +90,7 @@ test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase with
for i in 3 4
do
test_must_fail git branch -f can-be-updated HEAD 2>err &&
- grep "cannot force update the branch '\''can-be-updated'\'' checked out at.*wt-3" err ||
+ grep "cannot force update the branch '\''can-be-updated'\'' used by worktree at.*wt-3" err ||
return 1
done
'
@@ -150,7 +150,7 @@ test_expect_success 'refuse to overwrite when in error states' '
for i in 1 2
do
test_must_fail git branch -f fake-$i HEAD 2>err &&
- grep "cannot force update the branch '\''fake-$i'\'' checked out at" err ||
+ grep "cannot force update the branch '\''fake-$i'\'' used by worktree at" err ||
return 1
done
'
diff --git a/t/t3007-ls-files-recurse-submodules.sh b/t/t3007-ls-files-recurse-submodules.sh
index dd7770e85d..7308a3d4e2 100755
--- a/t/t3007-ls-files-recurse-submodules.sh
+++ b/t/t3007-ls-files-recurse-submodules.sh
@@ -299,6 +299,39 @@ test_expect_success '--recurse-submodules does not support --error-unmatch' '
test_i18ngrep "does not support --error-unmatch" actual
'
+test_expect_success '--recurse-submodules parses submodule repo config' '
+ test_config -C submodule index.sparse "invalid non-boolean value" &&
+ test_must_fail git ls-files --recurse-submodules 2>err &&
+ grep "bad boolean config value" err
+'
+
+test_expect_success '--recurse-submodules parses submodule worktree config' '
+ test_config -C submodule extensions.worktreeConfig true &&
+ test_config -C submodule --worktree index.sparse "invalid non-boolean value" &&
+
+ test_must_fail git ls-files --recurse-submodules 2>err &&
+ grep "bad boolean config value" err
+'
+
+test_expect_success '--recurse-submodules submodules ignore super project worktreeConfig extension' '
+ # Enable worktree config in both super project & submodule, set an
+ # invalid config in the submodule worktree config
+ test_config extensions.worktreeConfig true &&
+ test_config -C submodule extensions.worktreeConfig true &&
+ test_config -C submodule --worktree index.sparse "invalid non-boolean value" &&
+
+ # Now, disable the worktree config in the submodule. Note that we need
+ # to manually re-enable extensions.worktreeConfig when the test is
+ # finished, otherwise the test_unconfig of index.sparse will not work.
+ test_unconfig -C submodule extensions.worktreeConfig &&
+ test_when_finished "git -C submodule config extensions.worktreeConfig true" &&
+
+ # With extensions.worktreeConfig disabled in the submodule, the invalid
+ # worktree config is not picked up.
+ git ls-files --recurse-submodules 2>err &&
+ ! grep "bad boolean config value" err
+'
+
test_incompatible_with_recurse_submodules () {
test_expect_success "--recurse-submodules and $1 are incompatible" "
test_must_fail git ls-files --recurse-submodules $1 2>actual &&
diff --git a/t/t3013-ls-files-format.sh b/t/t3013-ls-files-format.sh
index ef6fb53f7f..6e6ea0b6f3 100755
--- a/t/t3013-ls-files-format.sh
+++ b/t/t3013-ls-files-format.sh
@@ -38,6 +38,41 @@ test_expect_success 'git ls-files --format objectname v.s. -s' '
test_cmp expect actual
'
+test_expect_success 'git ls-files --format objecttype' '
+ git ls-files --format="%(objectname)" o1.txt o4.txt o6.txt >objectname &&
+ git cat-file --batch-check="%(objecttype)" >expect <objectname &&
+ git ls-files --format="%(objecttype)" o1.txt o4.txt o6.txt >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git ls-files --format objectsize' '
+ cat>expect <<-\EOF &&
+26
+29
+27
+26
+-
+26
+ EOF
+ git ls-files --format="%(objectsize)" >actual &&
+
+ test_cmp expect actual
+'
+
+test_expect_success 'git ls-files --format objectsize:padded' '
+ cat>expect <<-\EOF &&
+ 26
+ 29
+ 27
+ 26
+ -
+ 26
+ EOF
+ git ls-files --format="%(objectsize:padded)" >actual &&
+
+ test_cmp expect actual
+'
+
test_expect_success 'git ls-files --format v.s. --eol' '
git ls-files --eol >tmp &&
sed -e "s/ / /g" -e "s/ */ /g" tmp >expect 2>err &&
diff --git a/t/t3101-ls-tree-dirname.sh b/t/t3101-ls-tree-dirname.sh
index 217006d1bf..5af2dac0e4 100755
--- a/t/t3101-ls-tree-dirname.sh
+++ b/t/t3101-ls-tree-dirname.sh
@@ -154,6 +154,14 @@ EOF
test_output
'
+test_expect_success 'ls-tree --no-full-name' '
+ git -C path0 ls-tree --no-full-name $tree a >current &&
+ cat >expected <<-EOF &&
+ 040000 tree X a
+ EOF
+ test_output
+'
+
test_expect_success 'ls-tree --full-tree' '
(
cd path1/b/c &&
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 98b6c8ac34..daf1666df7 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -8,6 +8,7 @@ test_description='git branch assorted tests'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-rebase.sh
diff --git a/t/t3202-show-branch.sh b/t/t3202-show-branch.sh
index be20ebe1d5..b17f388f56 100755
--- a/t/t3202-show-branch.sh
+++ b/t/t3202-show-branch.sh
@@ -119,6 +119,22 @@ test_expect_success 'show branch --remotes' '
test_must_be_empty actual.out
'
+test_expect_success 'show-branch --sparse' '
+ test_when_finished "git checkout branch10 && git branch -D branchA" &&
+ git checkout -b branchA branch10 &&
+ git merge -s ours -m "merge 1 and 10 to make A" branch1 &&
+ git commit --allow-empty -m "another" &&
+
+ git show-branch --sparse >out &&
+ grep "merge 1 and 10 to make A" out &&
+
+ git show-branch >out &&
+ ! grep "merge 1 and 10 to make A" out &&
+
+ git show-branch --no-sparse >out &&
+ ! grep "merge 1 and 10 to make A" out
+'
+
test_expect_success 'setup show branch --list' '
sed "s/^> //" >expect <<-\EOF
> [branch1] branch1
@@ -197,6 +213,15 @@ done <<\EOF
--reflog --current
EOF
+# unnegatable options
+for opt in topo-order date-order reflog
+do
+ test_expect_success "show-branch --no-$opt (should fail)" '
+ test_must_fail git show-branch --no-$opt 2>err &&
+ grep "unknown option .no-$opt." err
+ '
+done
+
test_expect_success 'error descriptions on non-existent branch' '
cat >expect <<-EOF &&
error: No branch named '\''non-existent'\'.'
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index 93f8295339..758963b189 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -55,9 +55,17 @@ cat >expect <<'EOF'
EOF
test_expect_success 'git branch -r shows remote branches' '
git branch -r >actual &&
+ test_cmp expect actual &&
+
+ git branch --remotes >actual &&
test_cmp expect actual
'
+test_expect_success 'git branch --no-remotes is rejected' '
+ test_must_fail git branch --no-remotes 2>err &&
+ grep "unknown option .no-remotes." err
+'
+
cat >expect <<'EOF'
branch-one
branch-two
@@ -68,9 +76,17 @@ cat >expect <<'EOF'
EOF
test_expect_success 'git branch -a shows local and remote branches' '
git branch -a >actual &&
+ test_cmp expect actual &&
+
+ git branch --all >actual &&
test_cmp expect actual
'
+test_expect_success 'git branch --no-all is rejected' '
+ test_must_fail git branch --no-all 2>err &&
+ grep "unknown option .no-all." err
+'
+
cat >expect <<'EOF'
two
one
diff --git a/t/t3204-branch-name-interpretation.sh b/t/t3204-branch-name-interpretation.sh
index 3399344f25..594e3e43e1 100755
--- a/t/t3204-branch-name-interpretation.sh
+++ b/t/t3204-branch-name-interpretation.sh
@@ -9,6 +9,7 @@ This script aims to check the behavior of those corner cases.
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
expect_branch() {
diff --git a/t/t3210-pack-refs.sh b/t/t3210-pack-refs.sh
index 07a0ff93de..7326adb70f 100755
--- a/t/t3210-pack-refs.sh
+++ b/t/t3210-pack-refs.sh
@@ -19,101 +19,138 @@ test_expect_success 'enable reflogs' '
git config core.logallrefupdates true
'
-test_expect_success \
- 'prepare a trivial repository' \
- 'echo Hello > A &&
- git update-index --add A &&
- git commit -m "Initial commit." &&
- HEAD=$(git rev-parse --verify HEAD)'
+test_expect_success 'prepare a trivial repository' '
+ echo Hello > A &&
+ git update-index --add A &&
+ git commit -m "Initial commit." &&
+ HEAD=$(git rev-parse --verify HEAD)
+'
SHA1=
-test_expect_success \
- 'see if git show-ref works as expected' \
- 'git branch a &&
- SHA1=$(cat .git/refs/heads/a) &&
- echo "$SHA1 refs/heads/a" >expect &&
- git show-ref a >result &&
- test_cmp expect result'
-
-test_expect_success \
- 'see if a branch still exists when packed' \
- 'git branch b &&
- git pack-refs --all &&
- rm -f .git/refs/heads/b &&
- echo "$SHA1 refs/heads/b" >expect &&
- git show-ref b >result &&
- test_cmp expect result'
+test_expect_success 'see if git show-ref works as expected' '
+ git branch a &&
+ SHA1=$(cat .git/refs/heads/a) &&
+ echo "$SHA1 refs/heads/a" >expect &&
+ git show-ref a >result &&
+ test_cmp expect result
+'
+
+test_expect_success 'see if a branch still exists when packed' '
+ git branch b &&
+ git pack-refs --all &&
+ rm -f .git/refs/heads/b &&
+ echo "$SHA1 refs/heads/b" >expect &&
+ git show-ref b >result &&
+ test_cmp expect result
+'
test_expect_success 'git branch c/d should barf if branch c exists' '
- git branch c &&
- git pack-refs --all &&
- rm -f .git/refs/heads/c &&
- test_must_fail git branch c/d
+ git branch c &&
+ git pack-refs --all &&
+ rm -f .git/refs/heads/c &&
+ test_must_fail git branch c/d
'
-test_expect_success \
- 'see if a branch still exists after git pack-refs --prune' \
- 'git branch e &&
- git pack-refs --all --prune &&
- echo "$SHA1 refs/heads/e" >expect &&
- git show-ref e >result &&
- test_cmp expect result'
+test_expect_success 'see if a branch still exists after git pack-refs --prune' '
+ git branch e &&
+ git pack-refs --all --prune &&
+ echo "$SHA1 refs/heads/e" >expect &&
+ git show-ref e >result &&
+ test_cmp expect result
+'
test_expect_success 'see if git pack-refs --prune remove ref files' '
- git branch f &&
- git pack-refs --all --prune &&
- ! test -f .git/refs/heads/f
+ git branch f &&
+ git pack-refs --all --prune &&
+ ! test -f .git/refs/heads/f
'
test_expect_success 'see if git pack-refs --prune removes empty dirs' '
- git branch r/s/t &&
- git pack-refs --all --prune &&
- ! test -e .git/refs/heads/r
+ git branch r/s/t &&
+ git pack-refs --all --prune &&
+ ! test -e .git/refs/heads/r
'
-test_expect_success \
- 'git branch g should work when git branch g/h has been deleted' \
- 'git branch g/h &&
- git pack-refs --all --prune &&
- git branch -d g/h &&
- git branch g &&
- git pack-refs --all &&
- git branch -d g'
+test_expect_success 'git branch g should work when git branch g/h has been deleted' '
+ git branch g/h &&
+ git pack-refs --all --prune &&
+ git branch -d g/h &&
+ git branch g &&
+ git pack-refs --all &&
+ git branch -d g
+'
test_expect_success 'git branch i/j/k should barf if branch i exists' '
- git branch i &&
- git pack-refs --all --prune &&
- test_must_fail git branch i/j/k
+ git branch i &&
+ git pack-refs --all --prune &&
+ test_must_fail git branch i/j/k
+'
+
+test_expect_success 'test git branch k after branch k/l/m and k/lm have been deleted' '
+ git branch k/l &&
+ git branch k/lm &&
+ git branch -d k/l &&
+ git branch k/l/m &&
+ git branch -d k/l/m &&
+ git branch -d k/lm &&
+ git branch k
'
-test_expect_success \
- 'test git branch k after branch k/l/m and k/lm have been deleted' \
- 'git branch k/l &&
- git branch k/lm &&
- git branch -d k/l &&
- git branch k/l/m &&
- git branch -d k/l/m &&
- git branch -d k/lm &&
- git branch k'
-
-test_expect_success \
- 'test git branch n after some branch deletion and pruning' \
- 'git branch n/o &&
- git branch n/op &&
- git branch -d n/o &&
- git branch n/o/p &&
- git branch -d n/op &&
- git pack-refs --all --prune &&
- git branch -d n/o/p &&
- git branch n'
-
-test_expect_success \
- 'see if up-to-date packed refs are preserved' \
- 'git branch q &&
- git pack-refs --all --prune &&
- git update-ref refs/heads/q refs/heads/q &&
- ! test -f .git/refs/heads/q'
+test_expect_success 'test git branch n after some branch deletion and pruning' '
+ git branch n/o &&
+ git branch n/op &&
+ git branch -d n/o &&
+ git branch n/o/p &&
+ git branch -d n/op &&
+ git pack-refs --all --prune &&
+ git branch -d n/o/p &&
+ git branch n
+'
+
+test_expect_success 'test excluded refs are not packed' '
+ git branch dont_pack1 &&
+ git branch dont_pack2 &&
+ git branch pack_this &&
+ git pack-refs --all --exclude "refs/heads/dont_pack*" &&
+ test -f .git/refs/heads/dont_pack1 &&
+ test -f .git/refs/heads/dont_pack2 &&
+ ! test -f .git/refs/heads/pack_this'
+
+test_expect_success 'test --no-exclude refs clears excluded refs' '
+ git branch dont_pack3 &&
+ git branch dont_pack4 &&
+ git pack-refs --all --exclude "refs/heads/dont_pack*" --no-exclude &&
+ ! test -f .git/refs/heads/dont_pack3 &&
+ ! test -f .git/refs/heads/dont_pack4'
+
+test_expect_success 'test only included refs are packed' '
+ git branch pack_this1 &&
+ git branch pack_this2 &&
+ git tag dont_pack5 &&
+ git pack-refs --include "refs/heads/pack_this*" &&
+ test -f .git/refs/tags/dont_pack5 &&
+ ! test -f .git/refs/heads/pack_this1 &&
+ ! test -f .git/refs/heads/pack_this2'
+
+test_expect_success 'test --no-include refs clears included refs' '
+ git branch pack1 &&
+ git branch pack2 &&
+ git pack-refs --include "refs/heads/pack*" --no-include &&
+ test -f .git/refs/heads/pack1 &&
+ test -f .git/refs/heads/pack2'
+
+test_expect_success 'test --exclude takes precedence over --include' '
+ git branch dont_pack5 &&
+ git pack-refs --include "refs/heads/pack*" --exclude "refs/heads/pack*" &&
+ test -f .git/refs/heads/dont_pack5'
+
+test_expect_success 'see if up-to-date packed refs are preserved' '
+ git branch q &&
+ git pack-refs --all --prune &&
+ git update-ref refs/heads/q refs/heads/q &&
+ ! test -f .git/refs/heads/q
+'
test_expect_success 'pack, prune and repack' '
git tag foo &&
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index 3288aaec7d..d734000d2f 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -362,6 +362,7 @@ test_expect_success 'do not create empty note with -m ""' '
'
test_expect_success 'create note with combination of -m and -F' '
+ test_when_finished git notes remove HEAD &&
cat >expect-combine_m_and_F <<-EOF &&
foo
@@ -380,6 +381,41 @@ test_expect_success 'create note with combination of -m and -F' '
test_cmp expect-combine_m_and_F actual
'
+test_expect_success 'create note with combination of -m and -F and --separator' '
+ test_when_finished git notes remove HEAD &&
+ cat >expect-combine_m_and_F <<-\EOF &&
+ foo
+ -------
+ xyzzy
+ -------
+ bar
+ -------
+ zyxxy
+ -------
+ baz
+ EOF
+ echo "xyzzy" >note_a &&
+ echo "zyxxy" >note_b &&
+ git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" --separator="-------" &&
+ git notes show >actual &&
+ test_cmp expect-combine_m_and_F actual
+'
+
+test_expect_success 'create note with combination of -m and -F and --no-separator' '
+ cat >expect-combine_m_and_F <<-\EOF &&
+ foo
+ xyzzy
+ bar
+ zyxxy
+ baz
+ EOF
+ echo "xyzzy" >note_a &&
+ echo "zyxxy" >note_b &&
+ git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" --no-separator &&
+ git notes show >actual &&
+ test_cmp expect-combine_m_and_F actual
+'
+
test_expect_success 'remove note with "git notes remove"' '
git notes remove HEAD^ &&
git notes remove &&
@@ -521,6 +557,112 @@ test_expect_success 'listing non-existing notes fails' '
test_must_be_empty actual
'
+test_expect_success 'append: specify a separator with an empty arg' '
+ test_when_finished git notes remove HEAD &&
+ cat >expect <<-\EOF &&
+ notes-1
+
+ notes-2
+ EOF
+
+ git notes add -m "notes-1" &&
+ git notes append --separator="" -m "notes-2" &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'append: specify a separator without arg' '
+ test_when_finished git notes remove HEAD &&
+ cat >expect <<-\EOF &&
+ notes-1
+
+ notes-2
+ EOF
+
+ git notes add -m "notes-1" &&
+ git notes append --separator -m "notes-2" &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'append: specify as --no-separator' '
+ test_when_finished git notes remove HEAD &&
+ cat >expect <<-\EOF &&
+ notes-1
+ notes-2
+ EOF
+
+ git notes add -m "notes-1" &&
+ git notes append --no-separator -m "notes-2" &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'append: specify separator with line break' '
+ test_when_finished git notes remove HEAD &&
+ cat >expect <<-\EOF &&
+ notes-1
+ -------
+ notes-2
+ EOF
+
+ git notes add -m "notes-1" &&
+ git notes append --separator="-------$LF" -m "notes-2" &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'append: specify separator without line break' '
+ test_when_finished git notes remove HEAD &&
+ cat >expect <<-\EOF &&
+ notes-1
+ -------
+ notes-2
+ EOF
+
+ git notes add -m "notes-1" &&
+ git notes append --separator="-------" -m "notes-2" &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'append: specify separator with multiple messages' '
+ test_when_finished git notes remove HEAD &&
+ cat >expect <<-\EOF &&
+ notes-1
+ -------
+ notes-2
+ -------
+ notes-3
+ EOF
+
+ git notes add -m "notes-1" &&
+ git notes append --separator="-------" -m "notes-2" -m "notes-3" &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'append note with combination of -m and -F and --separator' '
+ test_when_finished git notes remove HEAD &&
+ cat >expect-combine_m_and_F <<-\EOF &&
+ m-notes-1
+ -------
+ f-notes-1
+ -------
+ m-notes-2
+ -------
+ f-notes-2
+ -------
+ m-notes-3
+ EOF
+
+ echo "f-notes-1" >note_a &&
+ echo "f-notes-2" >note_b &&
+ git notes append -m "m-notes-1" -F note_a -m "m-notes-2" -F note_b -m "m-notes-3" --separator="-------" &&
+ git notes show >actual &&
+ test_cmp expect-combine_m_and_F actual
+'
+
test_expect_success 'append to existing note with "git notes append"' '
cat >expect <<-EOF &&
Initial set of notes
@@ -818,6 +960,33 @@ test_expect_success 'create note from blob with "git notes add -C" reuses blob i
test_cmp blob actual
'
+test_expect_success 'create note from blob with "-C", also specify "-m", "-F" and "--separator"' '
+ # 8th will be reuseed in following tests, so rollback when the test is done
+ test_when_finished "git notes remove && git notes add -C $(cat blob)" &&
+ commit=$(git rev-parse HEAD) &&
+ cat >expect <<-EOF &&
+ commit $commit
+ Author: A U Thor <author@example.com>
+ Date: Thu Apr 7 15:20:13 2005 -0700
+
+ ${indent}8th
+
+ Notes:
+ ${indent}This is a blob object
+ ${indent}-------
+ ${indent}This is created by -m
+ ${indent}-------
+ ${indent}This is created by -F
+ EOF
+
+ git notes remove &&
+ echo "This is a blob object" | git hash-object -w --stdin >blob &&
+ echo "This is created by -F" >note_a &&
+ git notes add -C $(cat blob) -m "This is created by -m" -F note_a --separator="-------" &&
+ git log -1 >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'create note from other note with "git notes add -c"' '
test_commit 9th &&
commit=$(git rev-parse HEAD) &&
diff --git a/t/t3321-notes-stripspace.sh b/t/t3321-notes-stripspace.sh
new file mode 100755
index 0000000000..028d825e8f
--- /dev/null
+++ b/t/t3321-notes-stripspace.sh
@@ -0,0 +1,577 @@
+#!/bin/sh
+#
+# Copyright (c) 2023 Teng Long
+#
+
+test_description='Test commit notes with stripspace behavior'
+
+. ./test-lib.sh
+
+MULTI_LF="$LF$LF$LF"
+write_script fake_editor <<\EOF
+echo "$MSG" >"$1"
+echo "$MSG" >&2
+EOF
+GIT_EDITOR=./fake_editor
+export GIT_EDITOR
+
+test_expect_success 'setup the commit' '
+ test_commit 1st
+'
+
+test_expect_success 'add note by editor' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ first-line
+
+ second-line
+ EOF
+
+ MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'add note by specifying single "-m", "--stripspace" is the default behavior' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ first-line
+
+ second-line
+ EOF
+
+ git notes add -m "${LF}first-line${MULTI_LF}second-line${LF}" &&
+ git notes show >actual &&
+ test_cmp expect actual &&
+ git notes remove &&
+ git notes add --stripspace -m "${LF}first-line${MULTI_LF}second-line${LF}" &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'add note by specifying single "-m" and "--no-stripspace" ' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ ${LF}first-line${MULTI_LF}second-line
+ EOF
+
+ git notes add --no-stripspace \
+ -m "${LF}first-line${MULTI_LF}second-line${LF}" &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'add note by specifying multiple "-m", "--stripspace" is the default behavior' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ first-line
+
+ second-line
+ EOF
+
+ git notes add -m "${LF}" \
+ -m "first-line" \
+ -m "${MULTI_LF}" \
+ -m "second-line" \
+ -m "${LF}" &&
+ git notes show >actual &&
+ test_cmp expect actual &&
+ git notes remove &&
+ git notes add --stripspace -m "${LF}" \
+ -m "first-line" \
+ -m "${MULTI_LF}" \
+ -m "second-line" \
+ -m "${LF}" &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'add notes by specifying multiple "-m" and "--no-stripspace"' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ ${LF}
+ first-line
+ ${MULTI_LF}
+ second-line${LF}
+ EOF
+
+ git notes add --no-stripspace \
+ -m "${LF}" \
+ -m "first-line" \
+ -m "${MULTI_LF}" \
+ -m "second-line" \
+ -m "${LF}" &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'add note by specifying single "-F", "--stripspace" is the default behavior' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ first-line
+
+ second-line
+ EOF
+
+ cat >note-file <<-EOF &&
+ ${LF}
+ first-line
+ ${MULTI_LF}
+ second-line
+ ${LF}
+ EOF
+
+ git notes add -F note-file &&
+ git notes show >actual &&
+ test_cmp expect actual &&
+ git notes remove &&
+ git notes add --stripspace -F note-file &&
+ git notes show >actual
+'
+
+test_expect_success 'add note by specifying single "-F" and "--no-stripspace"' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ ${LF}
+ first-line
+ ${MULTI_LF}
+ second-line
+ ${LF}
+ EOF
+
+ cat >note-file <<-EOF &&
+ ${LF}
+ first-line
+ ${MULTI_LF}
+ second-line
+ ${LF}
+ EOF
+
+ git notes add --no-stripspace -F note-file &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'add note by specifying multiple "-F", "--stripspace" is the default behavior' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ file-1-first-line
+
+ file-1-second-line
+
+ file-2-first-line
+
+ file-2-second-line
+ EOF
+
+ cat >note-file-1 <<-EOF &&
+ ${LF}
+ file-1-first-line
+ ${MULTI_LF}
+ file-1-second-line
+ ${LF}
+ EOF
+
+ cat >note-file-2 <<-EOF &&
+ ${LF}
+ file-2-first-line
+ ${MULTI_LF}
+ file-2-second-line
+ ${LF}
+ EOF
+
+ git notes add -F note-file-1 -F note-file-2 &&
+ git notes show >actual &&
+ test_cmp expect actual &&
+ git notes remove &&
+ git notes add --stripspace -F note-file-1 -F note-file-2 &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'add note by specifying multiple "-F" with "--no-stripspace"' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ ${LF}
+ file-1-first-line
+ ${MULTI_LF}
+ file-1-second-line
+ ${LF}
+
+ ${LF}
+ file-2-first-line
+ ${MULTI_LF}
+ file-2-second-line
+ ${LF}
+ EOF
+
+ cat >note-file-1 <<-EOF &&
+ ${LF}
+ file-1-first-line
+ ${MULTI_LF}
+ file-1-second-line
+ ${LF}
+ EOF
+
+ cat >note-file-2 <<-EOF &&
+ ${LF}
+ file-2-first-line
+ ${MULTI_LF}
+ file-2-second-line
+ ${LF}
+ EOF
+
+ git notes add --no-stripspace -F note-file-1 -F note-file-2 &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'append note by editor' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ first-line
+
+ second-line
+ EOF
+
+ git notes add -m "first-line" &&
+ MSG="${MULTI_LF}second-line${LF}" git notes append &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'append note by specifying single "-m"' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ first-line
+
+ second-line
+ EOF
+
+ git notes add -m "${LF}first-line" &&
+ git notes append -m "${MULTI_LF}second-line${LF}" &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'append note by specifying multiple "-m"' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ first-line
+
+ second-line
+ EOF
+
+ git notes add -m "${LF}first-line" &&
+ git notes append -m "${MULTI_LF}" \
+ -m "second-line" \
+ -m "${LF}" &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'add note by specifying single "-F"' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ first-line
+
+ second-line
+ EOF
+
+ cat >note-file <<-EOF &&
+ ${LF}
+ first-line
+ ${MULTI_LF}
+ second-line
+ ${LF}
+ EOF
+
+ git notes add -F note-file &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'add notes by specifying multiple "-F"' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ file-1-first-line
+
+ file-1-second-line
+
+ file-2-first-line
+
+ file-2-second-line
+ EOF
+
+ cat >note-file-1 <<-EOF &&
+ ${LF}
+ file-1-first-line
+ ${MULTI_LF}
+ file-1-second-line
+ ${LF}
+ EOF
+
+ cat >note-file-2 <<-EOF &&
+ ${LF}
+ file-2-first-line
+ ${MULTI_LF}
+ file-2-second-line
+ ${LF}
+ EOF
+
+ git notes add -F note-file-1 -F note-file-2 &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'append note by specifying single "-F"' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ initial-line
+
+ first-line
+
+ second-line
+ EOF
+
+ cat >note-file <<-EOF &&
+ ${LF}
+ first-line
+ ${MULTI_LF}
+ second-line
+ ${LF}
+ EOF
+
+ git notes add -m "initial-line" &&
+ git notes append -F note-file &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'append notes by specifying multiple "-F"' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ initial-line
+
+ file-1-first-line
+
+ file-1-second-line
+
+ file-2-first-line
+
+ file-2-second-line
+ EOF
+
+ cat >note-file-1 <<-EOF &&
+ ${LF}
+ file-1-first-line
+ ${MULTI_LF}
+ file-1-second-line
+ ${LF}
+ EOF
+
+ cat >note-file-2 <<-EOF &&
+ ${LF}
+ file-2-first-line
+ ${MULTI_LF}
+ file-2-second-line
+ ${LF}
+ EOF
+
+ git notes add -m "initial-line" &&
+ git notes append -F note-file-1 -F note-file-2 &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'append note by specifying multiple "-F" with "--no-stripspace"' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ initial-line
+ ${LF}${LF}
+ file-1-first-line
+ ${MULTI_LF}
+ file-1-second-line
+ ${LF}
+
+ ${LF}
+ file-2-first-line
+ ${MULTI_LF}
+ file-2-second-line
+ ${LF}
+ EOF
+
+ cat >note-file-1 <<-EOF &&
+ ${LF}
+ file-1-first-line
+ ${MULTI_LF}
+ file-1-second-line
+ ${LF}
+ EOF
+
+ cat >note-file-2 <<-EOF &&
+ ${LF}
+ file-2-first-line
+ ${MULTI_LF}
+ file-2-second-line
+ ${LF}
+ EOF
+
+ git notes add -m "initial-line" &&
+ git notes append --no-stripspace -F note-file-1 -F note-file-2 &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'add notes with empty messages' '
+ rev=$(git rev-parse HEAD) &&
+ git notes add -m "${LF}" \
+ -m "${MULTI_LF}" \
+ -m "${LF}" >actual 2>&1 &&
+ test_i18ngrep "Removing note for object" actual
+'
+
+test_expect_success 'add note by specifying "-C", "--no-stripspace" is the default behavior' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ ${LF}
+ first-line
+ ${MULTI_LF}
+ second-line
+ ${LF}
+ EOF
+
+ cat expect | git hash-object -w --stdin >blob &&
+ git notes add -C $(cat blob) &&
+ git notes show >actual &&
+ test_cmp expect actual &&
+ git notes remove &&
+ git notes add --no-stripspace -C $(cat blob) &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'reuse note by specifying "-C" and "--stripspace"' '
+ test_when_finished "git notes remove" &&
+ cat >data <<-EOF &&
+ ${LF}
+ first-line
+ ${MULTI_LF}
+ second-line
+ ${LF}
+ EOF
+
+ cat >expect <<-EOF &&
+ first-line
+
+ second-line
+ EOF
+
+ cat data | git hash-object -w --stdin >blob &&
+ git notes add --stripspace -C $(cat blob) &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'reuse with "-C" and add note with "-m", "-m" will stripspace all together' '
+ test_when_finished "git notes remove" &&
+ cat >data <<-EOF &&
+ ${LF}
+ first-line
+ ${MULTI_LF}
+ second-line
+ ${LF}
+ EOF
+
+ cat >expect <<-EOF &&
+ first-line
+
+ second-line
+
+ third-line
+ EOF
+
+ cat data | git hash-object -w --stdin >blob &&
+ git notes add -C $(cat blob) -m "third-line" &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'add note with "-m" and reuse note with "-C", "-C" will not stripspace all together' '
+ test_when_finished "git notes remove" &&
+ cat >data <<-EOF &&
+
+ second-line
+ EOF
+
+ cat >expect <<-EOF &&
+ first-line
+ ${LF}
+ second-line
+ EOF
+
+ cat data | git hash-object -w --stdin >blob &&
+ git notes add -m "first-line" -C $(cat blob) &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'add note by specifying "-c", "--stripspace" is the default behavior' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ first-line
+
+ second-line
+ EOF
+
+ echo "initial-line" | git hash-object -w --stdin >blob &&
+ MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add -c $(cat blob) &&
+ git notes show >actual &&
+ test_cmp expect actual &&
+ git notes remove &&
+ MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add --stripspace -c $(cat blob) &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'add note by specifying "-c" with "--no-stripspace"' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ ${LF}first-line${MULTI_LF}second-line${LF}
+ EOF
+
+ echo "initial-line" | git hash-object -w --stdin >blob &&
+ MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add --no-stripspace -c $(cat blob) &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'edit note by specifying "-c", "--stripspace" is the default behavior' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ first-line
+
+ second-line
+ EOF
+
+ MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes edit &&
+ git notes show >actual &&
+ test_cmp expect actual &&
+ git notes remove &&
+ MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes edit --stripspace &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'edit note by specifying "-c" with "--no-stripspace"' '
+ test_when_finished "git notes remove" &&
+ cat >expect <<-EOF &&
+ ${LF}first-line${MULTI_LF}second-line${LF}
+ EOF
+
+ MSG="${LF}first-line${MULTI_LF}second-line${LF}" git notes add --no-stripspace &&
+ git notes show >actual &&
+ test_cmp expect actual
+'
+
+test_done
diff --git a/t/t3402-rebase-merge.sh b/t/t3402-rebase-merge.sh
index 79b0640c00..e9e03ca4b5 100755
--- a/t/t3402-rebase-merge.sh
+++ b/t/t3402-rebase-merge.sh
@@ -8,6 +8,7 @@ test_description='git rebase --merge test'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
T="A quick brown fox
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index ff0afad63e..96a56aafbe 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1596,6 +1596,32 @@ test_expect_success 'static check of bad command' '
test C = $(git cat-file commit HEAD^ | sed -ne \$p)
'
+test_expect_success 'the first command cannot be a fixup' '
+ rebase_setup_and_clean fixup-first &&
+
+ cat >orig <<-EOF &&
+ fixup $(git log -1 --format="%h %s" B)
+ pick $(git log -1 --format="%h %s" C)
+ EOF
+
+ (
+ set_replace_editor orig &&
+ test_must_fail git rebase -i A 2>actual
+ ) &&
+ grep "cannot .fixup. without a previous commit" actual &&
+ grep "You can fix this with .git rebase --edit-todo.." actual &&
+ # verify that the todo list has not been truncated
+ grep -v "^#" .git/rebase-merge/git-rebase-todo >actual &&
+ test_cmp orig actual &&
+
+ test_must_fail git rebase --edit-todo 2>actual &&
+ grep "cannot .fixup. without a previous commit" actual &&
+ grep "You can fix this with .git rebase --edit-todo.." actual &&
+ # verify that the todo list has not been truncated
+ grep -v "^#" .git/rebase-merge/git-rebase-todo >actual &&
+ test_cmp orig actual
+'
+
test_expect_success 'tabs and spaces are accepted in the todolist' '
rebase_setup_and_clean indented-comment &&
write_script add-indent.sh <<-\EOF &&
diff --git a/t/t3500-cherry.sh b/t/t3500-cherry.sh
index 0458a58b4b..78c3eac54b 100755
--- a/t/t3500-cherry.sh
+++ b/t/t3500-cherry.sh
@@ -16,46 +16,43 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
GIT_AUTHOR_EMAIL=bogus_email_address
export GIT_AUTHOR_EMAIL
-test_expect_success \
- 'prepare repository with topic branch, and check cherry finds the 2 patches from there' \
- 'echo First > A &&
- git update-index --add A &&
- test_tick &&
- git commit -m "Add A." &&
-
- git checkout -b my-topic-branch &&
-
- echo Second > B &&
- git update-index --add B &&
- test_tick &&
- git commit -m "Add B." &&
-
- echo AnotherSecond > C &&
- git update-index --add C &&
- test_tick &&
- git commit -m "Add C." &&
-
- git checkout -f main &&
- rm -f B C &&
-
- echo Third >> A &&
- git update-index A &&
- test_tick &&
- git commit -m "Modify A." &&
-
- expr "$(echo $(git cherry main my-topic-branch) )" : "+ [^ ]* + .*"
+test_expect_success 'prepare repository with topic branch, and check cherry finds the 2 patches from there' '
+ echo First > A &&
+ git update-index --add A &&
+ test_tick &&
+ git commit -m "Add A." &&
+
+ git checkout -b my-topic-branch &&
+
+ echo Second > B &&
+ git update-index --add B &&
+ test_tick &&
+ git commit -m "Add B." &&
+
+ echo AnotherSecond > C &&
+ git update-index --add C &&
+ test_tick &&
+ git commit -m "Add C." &&
+
+ git checkout -f main &&
+ rm -f B C &&
+
+ echo Third >> A &&
+ git update-index A &&
+ test_tick &&
+ git commit -m "Modify A." &&
+
+ expr "$(echo $(git cherry main my-topic-branch) )" : "+ [^ ]* + .*"
'
-test_expect_success \
- 'check that cherry with limit returns only the top patch'\
- 'expr "$(echo $(git cherry main my-topic-branch my-topic-branch^1) )" : "+ [^ ]*"
+test_expect_success 'check that cherry with limit returns only the top patch' '
+ expr "$(echo $(git cherry main my-topic-branch my-topic-branch^1) )" : "+ [^ ]*"
'
-test_expect_success \
- 'cherry-pick one of the 2 patches, and check cherry recognized one and only one as new' \
- 'git cherry-pick my-topic-branch^0 &&
- echo $(git cherry main my-topic-branch) &&
- expr "$(echo $(git cherry main my-topic-branch) )" : "+ [^ ]* - .*"
+test_expect_success 'cherry-pick one of the 2 patches, and check cherry recognized one and only one as new' '
+ git cherry-pick my-topic-branch^0 &&
+ echo $(git cherry main my-topic-branch) &&
+ expr "$(echo $(git cherry main my-topic-branch) )" : "+ [^ ]* - .*"
'
test_expect_success 'cherry ignores whitespace' '
diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index 82dd768944..7623689da2 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -24,17 +24,17 @@ test_mode_in_index () {
esac
}
-test_expect_success \
- 'Test of git add' \
- 'touch foo && git add foo'
+test_expect_success 'Test of git add' '
+ touch foo && git add foo
+'
-test_expect_success \
- 'Post-check that foo is in the index' \
- 'git ls-files foo | grep foo'
+test_expect_success 'Post-check that foo is in the index' '
+ git ls-files foo | grep foo
+'
-test_expect_success \
- 'Test that "git add -- -q" works' \
- 'touch -- -q && git add -- -q'
+test_expect_success 'Test that "git add -- -q" works' '
+ touch -- -q && git add -- -q
+'
BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch'
@@ -284,14 +284,14 @@ test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors = false)' '
rm -f foo2
test_expect_success POSIXPERM,SANITY '--no-ignore-errors overrides config' '
- git config add.ignore-errors 1 &&
- git reset --hard &&
- date >foo1 &&
- date >foo2 &&
- chmod 0 foo2 &&
- test_must_fail git add --verbose --no-ignore-errors . &&
- ! ( git ls-files foo1 | grep foo1 ) &&
- git config add.ignore-errors 0
+ git config add.ignore-errors 1 &&
+ git reset --hard &&
+ date >foo1 &&
+ date >foo2 &&
+ chmod 0 foo2 &&
+ test_must_fail git add --verbose --no-ignore-errors . &&
+ ! ( git ls-files foo1 | grep foo1 ) &&
+ git config add.ignore-errors 0
'
rm -f foo2
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 3982b6b49d..34aabb7f5f 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -734,6 +734,44 @@ test_expect_success 'colors can be overridden' '
test_cmp expect actual
'
+test_expect_success 'brackets appear without color' '
+ git reset --hard &&
+ test_when_finished "git rm -f bracket-test" &&
+ test_write_lines context old more-context >bracket-test &&
+ git add bracket-test &&
+ test_write_lines context new more-context another-one >bracket-test &&
+
+ test_write_lines quit >input &&
+ git add -i >actual <input &&
+
+ sed "s/^|//" >expect <<-\EOF &&
+ | staged unstaged path
+ | 1: +3/-0 +2/-1 bracket-test
+ |
+ |*** Commands ***
+ | 1: [s]tatus 2: [u]pdate 3: [r]evert 4: [a]dd untracked
+ | 5: [p]atch 6: [d]iff 7: [q]uit 8: [h]elp
+ |What now> Bye.
+ EOF
+
+ test_cmp expect actual
+'
+
+test_expect_success 'colors can be skipped with color.ui=false' '
+ git reset --hard &&
+ test_when_finished "git rm -f color-test" &&
+ test_write_lines context old more-context >color-test &&
+ git add color-test &&
+ test_write_lines context new more-context another-one >color-test &&
+
+ test_write_lines help quit >input &&
+ force_color git \
+ -c color.ui=false \
+ add -i >actual.raw <input &&
+ test_decode_color <actual.raw >actual &&
+ test_cmp actual.raw actual
+'
+
test_expect_success 'colorized diffs respect diff.wsErrorHighlight' '
git reset --hard &&
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 376cc8f4ab..0b3dfeaea2 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -1211,19 +1211,19 @@ test_expect_success 'stash with file including $IFS character' '
'
test_expect_success 'stash with pathspec matching multiple paths' '
- echo original >file &&
- echo original >other-file &&
- git commit -m "two" file other-file &&
- echo modified >file &&
- echo modified >other-file &&
- git stash push -- "*file" &&
- echo original >expect &&
- test_cmp expect file &&
- test_cmp expect other-file &&
- git stash pop &&
- echo modified >expect &&
- test_cmp expect file &&
- test_cmp expect other-file
+ echo original >file &&
+ echo original >other-file &&
+ git commit -m "two" file other-file &&
+ echo modified >file &&
+ echo modified >other-file &&
+ git stash push -- "*file" &&
+ echo original >expect &&
+ test_cmp expect file &&
+ test_cmp expect other-file &&
+ git stash pop &&
+ echo modified >expect &&
+ test_cmp expect file &&
+ test_cmp expect other-file
'
test_expect_success 'stash push -p with pathspec shows no changes only once' '
diff --git a/t/t4000-diff-format.sh b/t/t4000-diff-format.sh
index bfcaae390f..8d50331b8c 100755
--- a/t/t4000-diff-format.sh
+++ b/t/t4000-diff-format.sh
@@ -5,6 +5,9 @@
test_description='Test built-in diff output engine.
+We happen to know that all diff plumbing and diff Porcelain share the
+same command line parser, so testing one should be sufficient; pick
+diff-files as a representative.
'
TEST_PASSES_SANITIZE_LEAK=true
@@ -16,9 +19,11 @@ Line 2
line 3'
cat path0 >path1
chmod +x path1
+mkdir path2
+>path2/path3
test_expect_success 'update-index --add two files with and without +x.' '
- git update-index --add path0 path1
+ git update-index --add path0 path1 path2/path3
'
mv path0 path0-
@@ -91,4 +96,31 @@ test_expect_success 'git diff-files --patch --no-patch does not show the patch'
test_must_be_empty err
'
+
+# Smudge path2/path3 so that dirstat has something to show
+date >path2/path3
+
+for format in stat raw numstat shortstat summary \
+ dirstat cumulative dirstat-by-file \
+ patch-with-raw patch-with-stat compact-summary
+do
+ test_expect_success "--no-patch in 'git diff-files --no-patch --$format' is a no-op" '
+ git diff-files --no-patch "--$format" >actual &&
+ git diff-files "--$format" >expect &&
+ test_cmp expect actual
+ '
+
+ test_expect_success "--no-patch clears all previous ones" '
+ git diff-files --$format -s -p >actual &&
+ git diff-files -p >expect &&
+ test_cmp expect actual
+ '
+
+ test_expect_success "--no-patch in 'git diff --no-patch --$format' is a no-op" '
+ git diff --no-patch "--$format" >actual &&
+ git diff "--$format" >expect &&
+ test_cmp expect actual
+ '
+done
+
test_done
diff --git a/t/t4002-diff-basic.sh b/t/t4002-diff-basic.sh
index ea52e5b91b..7afc883ec3 100755
--- a/t/t4002-diff-basic.sh
+++ b/t/t4002-diff-basic.sh
@@ -284,132 +284,131 @@ cmp_diff_files_output () {
test_cmp "$1" .test-tmp
}
-test_expect_success \
- 'diff-tree of known trees.' \
- 'git diff-tree $tree_O $tree_A >.test-a &&
- cmp -s .test-a .test-plain-OA'
-
-test_expect_success \
- 'diff-tree of known trees.' \
- 'git diff-tree -r $tree_O $tree_A >.test-a &&
- cmp -s .test-a .test-recursive-OA'
-
-test_expect_success \
- 'diff-tree of known trees.' \
- 'git diff-tree $tree_O $tree_B >.test-a &&
- cmp -s .test-a .test-plain-OB'
-
-test_expect_success \
- 'diff-tree of known trees.' \
- 'git diff-tree -r $tree_O $tree_B >.test-a &&
- cmp -s .test-a .test-recursive-OB'
-
-test_expect_success \
- 'diff-tree of known trees.' \
- 'git diff-tree $tree_A $tree_B >.test-a &&
- cmp -s .test-a .test-plain-AB'
-
-test_expect_success \
- 'diff-tree of known trees.' \
- 'git diff-tree -r $tree_A $tree_B >.test-a &&
- cmp -s .test-a .test-recursive-AB'
-
-test_expect_success \
- 'diff-tree --stdin of known trees.' \
- 'echo $tree_A $tree_B | git diff-tree --stdin > .test-a &&
- echo $tree_A $tree_B > .test-plain-ABx &&
- cat .test-plain-AB >> .test-plain-ABx &&
- cmp -s .test-a .test-plain-ABx'
-
-test_expect_success \
- 'diff-tree --stdin of known trees.' \
- 'echo $tree_A $tree_B | git diff-tree -r --stdin > .test-a &&
- echo $tree_A $tree_B > .test-recursive-ABx &&
- cat .test-recursive-AB >> .test-recursive-ABx &&
- cmp -s .test-a .test-recursive-ABx'
-
-test_expect_success \
- 'diff-cache O with A in cache' \
- 'git read-tree $tree_A &&
- git diff-index --cached $tree_O >.test-a &&
- cmp -s .test-a .test-recursive-OA'
-
-test_expect_success \
- 'diff-cache O with B in cache' \
- 'git read-tree $tree_B &&
- git diff-index --cached $tree_O >.test-a &&
- cmp -s .test-a .test-recursive-OB'
-
-test_expect_success \
- 'diff-cache A with B in cache' \
- 'git read-tree $tree_B &&
- git diff-index --cached $tree_A >.test-a &&
- cmp -s .test-a .test-recursive-AB'
-
-test_expect_success \
- 'diff-files with O in cache and A checked out' \
- 'rm -fr Z [A-Z][A-Z] &&
- git read-tree $tree_A &&
- git checkout-index -f -a &&
- git read-tree --reset $tree_O &&
- test_must_fail git update-index --refresh -q &&
- git diff-files >.test-a &&
- cmp_diff_files_output .test-a .test-recursive-OA'
-
-test_expect_success \
- 'diff-files with O in cache and B checked out' \
- 'rm -fr Z [A-Z][A-Z] &&
- git read-tree $tree_B &&
- git checkout-index -f -a &&
- git read-tree --reset $tree_O &&
- test_must_fail git update-index --refresh -q &&
- git diff-files >.test-a &&
- cmp_diff_files_output .test-a .test-recursive-OB'
-
-test_expect_success \
- 'diff-files with A in cache and B checked out' \
- 'rm -fr Z [A-Z][A-Z] &&
- git read-tree $tree_B &&
- git checkout-index -f -a &&
- git read-tree --reset $tree_A &&
- test_must_fail git update-index --refresh -q &&
- git diff-files >.test-a &&
- cmp_diff_files_output .test-a .test-recursive-AB'
+test_expect_success 'diff-tree of known trees.' '
+ git diff-tree $tree_O $tree_A >.test-a &&
+ cmp -s .test-a .test-plain-OA
+'
+
+test_expect_success 'diff-tree of known trees.' '
+ git diff-tree -r $tree_O $tree_A >.test-a &&
+ cmp -s .test-a .test-recursive-OA
+'
+
+test_expect_success 'diff-tree of known trees.' '
+ git diff-tree $tree_O $tree_B >.test-a &&
+ cmp -s .test-a .test-plain-OB
+'
+
+test_expect_success 'diff-tree of known trees.' '
+ git diff-tree -r $tree_O $tree_B >.test-a &&
+ cmp -s .test-a .test-recursive-OB
+'
+
+test_expect_success 'diff-tree of known trees.' '
+ git diff-tree $tree_A $tree_B >.test-a &&
+ cmp -s .test-a .test-plain-AB
+'
+
+test_expect_success 'diff-tree of known trees.' '
+ git diff-tree -r $tree_A $tree_B >.test-a &&
+ cmp -s .test-a .test-recursive-AB
+'
+
+test_expect_success 'diff-tree --stdin of known trees.' '
+ echo $tree_A $tree_B | git diff-tree --stdin > .test-a &&
+ echo $tree_A $tree_B > .test-plain-ABx &&
+ cat .test-plain-AB >> .test-plain-ABx &&
+ cmp -s .test-a .test-plain-ABx
+'
+
+test_expect_success 'diff-tree --stdin of known trees.' '
+ echo $tree_A $tree_B | git diff-tree -r --stdin > .test-a &&
+ echo $tree_A $tree_B > .test-recursive-ABx &&
+ cat .test-recursive-AB >> .test-recursive-ABx &&
+ cmp -s .test-a .test-recursive-ABx
+'
+
+test_expect_success 'diff-cache O with A in cache' '
+ git read-tree $tree_A &&
+ git diff-index --cached $tree_O >.test-a &&
+ cmp -s .test-a .test-recursive-OA
+'
+
+test_expect_success 'diff-cache O with B in cache' '
+ git read-tree $tree_B &&
+ git diff-index --cached $tree_O >.test-a &&
+ cmp -s .test-a .test-recursive-OB
+'
+
+test_expect_success 'diff-cache A with B in cache' '
+ git read-tree $tree_B &&
+ git diff-index --cached $tree_A >.test-a &&
+ cmp -s .test-a .test-recursive-AB
+'
+
+test_expect_success 'diff-files with O in cache and A checked out' '
+ rm -fr Z [A-Z][A-Z] &&
+ git read-tree $tree_A &&
+ git checkout-index -f -a &&
+ git read-tree --reset $tree_O &&
+ test_must_fail git update-index --refresh -q &&
+ git diff-files >.test-a &&
+ cmp_diff_files_output .test-a .test-recursive-OA
+'
+
+test_expect_success 'diff-files with O in cache and B checked out' '
+ rm -fr Z [A-Z][A-Z] &&
+ git read-tree $tree_B &&
+ git checkout-index -f -a &&
+ git read-tree --reset $tree_O &&
+ test_must_fail git update-index --refresh -q &&
+ git diff-files >.test-a &&
+ cmp_diff_files_output .test-a .test-recursive-OB
+'
+
+test_expect_success 'diff-files with A in cache and B checked out' '
+ rm -fr Z [A-Z][A-Z] &&
+ git read-tree $tree_B &&
+ git checkout-index -f -a &&
+ git read-tree --reset $tree_A &&
+ test_must_fail git update-index --refresh -q &&
+ git diff-files >.test-a &&
+ cmp_diff_files_output .test-a .test-recursive-AB
+'
################################################################
# Now we have established the baseline, we do not have to
# rely on individual object ID values that much.
-test_expect_success \
- 'diff-tree O A == diff-tree -R A O' \
- 'git diff-tree $tree_O $tree_A >.test-a &&
- git diff-tree -R $tree_A $tree_O >.test-b &&
- cmp -s .test-a .test-b'
-
-test_expect_success \
- 'diff-tree -r O A == diff-tree -r -R A O' \
- 'git diff-tree -r $tree_O $tree_A >.test-a &&
- git diff-tree -r -R $tree_A $tree_O >.test-b &&
- cmp -s .test-a .test-b'
-
-test_expect_success \
- 'diff-tree B A == diff-tree -R A B' \
- 'git diff-tree $tree_B $tree_A >.test-a &&
- git diff-tree -R $tree_A $tree_B >.test-b &&
- cmp -s .test-a .test-b'
-
-test_expect_success \
- 'diff-tree -r B A == diff-tree -r -R A B' \
- 'git diff-tree -r $tree_B $tree_A >.test-a &&
- git diff-tree -r -R $tree_A $tree_B >.test-b &&
- cmp -s .test-a .test-b'
-
-test_expect_success \
- 'diff can read from stdin' \
- 'test_must_fail git diff --no-index -- MN - < NN |
- grep -v "^index" | sed "s#/-#/NN#" >.test-a &&
- test_must_fail git diff --no-index -- MN NN |
- grep -v "^index" >.test-b &&
- test_cmp .test-a .test-b'
+test_expect_success 'diff-tree O A == diff-tree -R A O' '
+ git diff-tree $tree_O $tree_A >.test-a &&
+ git diff-tree -R $tree_A $tree_O >.test-b &&
+ cmp -s .test-a .test-b
+'
+
+test_expect_success 'diff-tree -r O A == diff-tree -r -R A O' '
+ git diff-tree -r $tree_O $tree_A >.test-a &&
+ git diff-tree -r -R $tree_A $tree_O >.test-b &&
+ cmp -s .test-a .test-b
+'
+
+test_expect_success 'diff-tree B A == diff-tree -R A B' '
+ git diff-tree $tree_B $tree_A >.test-a &&
+ git diff-tree -R $tree_A $tree_B >.test-b &&
+ cmp -s .test-a .test-b
+'
+
+test_expect_success 'diff-tree -r B A == diff-tree -r -R A B' '
+ git diff-tree -r $tree_B $tree_A >.test-a &&
+ git diff-tree -r -R $tree_A $tree_B >.test-b &&
+ cmp -s .test-a .test-b'
+
+test_expect_success 'diff can read from stdin' '
+ test_must_fail git diff --no-index -- MN - < NN |
+ grep -v "^index" | sed "s#/-#/NN#" >.test-a &&
+ test_must_fail git diff --no-index -- MN NN |
+ grep -v "^index" >.test-b &&
+ test_cmp .test-a .test-b
+'
test_done
diff --git a/t/t4003-diff-rename-1.sh b/t/t4003-diff-rename-1.sh
index 181e9683a7..ebe091828c 100755
--- a/t/t4003-diff-rename-1.sh
+++ b/t/t4003-diff-rename-1.sh
@@ -11,20 +11,20 @@ TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash
-test_expect_success \
- 'prepare reference tree' \
- 'COPYING_test_data >COPYING &&
- echo frotz >rezrov &&
- git update-index --add COPYING rezrov &&
- tree=$(git write-tree) &&
- echo $tree'
-
-test_expect_success \
- 'prepare work tree' \
- 'sed -e 's/HOWEVER/However/' <COPYING >COPYING.1 &&
- sed -e 's/GPL/G.P.L/g' <COPYING >COPYING.2 &&
- rm -f COPYING &&
- git update-index --add --remove COPYING COPYING.?'
+test_expect_success 'prepare reference tree' '
+ COPYING_test_data >COPYING &&
+ echo frotz >rezrov &&
+ git update-index --add COPYING rezrov &&
+ tree=$(git write-tree) &&
+ echo $tree
+'
+
+test_expect_success 'prepare work tree' '
+ sed -e 's/HOWEVER/However/' <COPYING >COPYING.1 &&
+ sed -e 's/GPL/G.P.L/g' <COPYING >COPYING.2 &&
+ rm -f COPYING &&
+ git update-index --add --remove COPYING COPYING.?
+'
# tree has COPYING and rezrov. work tree has COPYING.1 and COPYING.2,
# both are slightly edited, and unchanged rezrov. So we say you
@@ -57,14 +57,14 @@ rename to COPYING.2
+ This file is licensed under the G.P.L v2, or a later version
EOF
-test_expect_success \
- 'validate output from rename/copy detection (#1)' \
- 'compare_diff_patch current expected'
+test_expect_success 'validate output from rename/copy detection (#1)' '
+ compare_diff_patch current expected
+'
-test_expect_success \
- 'prepare work tree again' \
- 'mv COPYING.2 COPYING &&
- git update-index --add --remove COPYING COPYING.1 COPYING.2'
+test_expect_success 'prepare work tree again' '
+ mv COPYING.2 COPYING &&
+ git update-index --add --remove COPYING COPYING.1 COPYING.2
+'
# tree has COPYING and rezrov. work tree has COPYING and COPYING.1,
# both are slightly edited, and unchanged rezrov. So we say you
@@ -95,14 +95,14 @@ copy to COPYING.1
+ However, in order to allow a migration to GPLv3 if that seems like
EOF
-test_expect_success \
- 'validate output from rename/copy detection (#2)' \
- 'compare_diff_patch current expected'
+test_expect_success 'validate output from rename/copy detection (#2)' '
+ compare_diff_patch current expected
+'
-test_expect_success \
- 'prepare work tree once again' \
- 'COPYING_test_data >COPYING &&
- git update-index --add --remove COPYING COPYING.1'
+test_expect_success 'prepare work tree once again' '
+ COPYING_test_data >COPYING &&
+ git update-index --add --remove COPYING COPYING.1
+'
# tree has COPYING and rezrov. work tree has COPYING and COPYING.1,
# but COPYING is not edited. We say you copy-and-edit COPYING.1; this
@@ -123,8 +123,8 @@ copy to COPYING.1
+ However, in order to allow a migration to GPLv3 if that seems like
EOF
-test_expect_success \
- 'validate output from rename/copy detection (#3)' \
- 'compare_diff_patch current expected'
+test_expect_success 'validate output from rename/copy detection (#3)' '
+ compare_diff_patch current expected
+'
test_done
diff --git a/t/t4004-diff-rename-symlink.sh b/t/t4004-diff-rename-symlink.sh
index 8def4d4aee..1d70d4d221 100755
--- a/t/t4004-diff-rename-symlink.sh
+++ b/t/t4004-diff-rename-symlink.sh
@@ -14,21 +14,21 @@ TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-diff.sh
-test_expect_success SYMLINKS \
- 'prepare reference tree' \
- 'echo xyzzy | tr -d '\\\\'012 >yomin &&
- ln -s xyzzy frotz &&
- git update-index --add frotz yomin &&
- tree=$(git write-tree) &&
- echo $tree'
+test_expect_success SYMLINKS 'prepare reference tree' '
+ echo xyzzy | tr -d '\\\\'012 >yomin &&
+ ln -s xyzzy frotz &&
+ git update-index --add frotz yomin &&
+ tree=$(git write-tree) &&
+ echo $tree
+'
-test_expect_success SYMLINKS \
- 'prepare work tree' \
- 'mv frotz rezrov &&
- rm -f yomin &&
- ln -s xyzzy nitfol &&
- ln -s xzzzy bozbar &&
- git update-index --add --remove frotz rezrov nitfol bozbar yomin'
+test_expect_success SYMLINKS 'prepare work tree' '
+ mv frotz rezrov &&
+ rm -f yomin &&
+ ln -s xyzzy nitfol &&
+ ln -s xzzzy bozbar &&
+ git update-index --add --remove frotz rezrov nitfol bozbar yomin
+'
# tree has frotz pointing at xyzzy, and yomin that contains xyzzy to
# confuse things. work tree has rezrov (xyzzy) nitfol (xyzzy) and
@@ -36,9 +36,9 @@ test_expect_success SYMLINKS \
# rezrov and nitfol are rename/copy of frotz and bozbar should be
# a new creation.
-test_expect_success SYMLINKS 'setup diff output' "
- GIT_DIFF_OPTS=--unified=0 git diff-index -C -p $tree >current &&
- cat >expected <<\EOF
+test_expect_success SYMLINKS 'setup diff output' '
+ GIT_DIFF_OPTS=--unified=0 git diff-index -C -p $tree >current &&
+ cat >expected <<\EOF
diff --git a/bozbar b/bozbar
new file mode 120000
--- /dev/null
@@ -62,10 +62,10 @@ deleted file mode 100644
-xyzzy
\ No newline at end of file
EOF
-"
+'
-test_expect_success SYMLINKS \
- 'validate diff output' \
- 'compare_diff_patch current expected'
+test_expect_success SYMLINKS 'validate diff output' '
+ compare_diff_patch current expected
+'
test_done
diff --git a/t/t4053-diff-no-index.sh b/t/t4053-diff-no-index.sh
index 4e9fa0403d..a28b9ff243 100755
--- a/t/t4053-diff-no-index.sh
+++ b/t/t4053-diff-no-index.sh
@@ -205,4 +205,68 @@ test_expect_success POSIXPERM,SYMLINKS 'diff --no-index normalizes: mode not lik
test_cmp expected actual
'
+test_expect_success "diff --no-index treats '-' as stdin" '
+ cat >expect <<-EOF &&
+ diff --git a/- b/a/1
+ index $ZERO_OID..$(git hash-object --stdin <a/1) 100644
+ --- a/-
+ +++ b/a/1
+ @@ -1 +1 @@
+ -x
+ +1
+ EOF
+
+ test_write_lines x | test_expect_code 1 \
+ git -c core.abbrev=no diff --no-index -- - a/1 >actual &&
+ test_cmp expect actual &&
+
+ test_write_lines 1 | git diff --no-index -- a/1 - >actual &&
+ test_must_be_empty actual
+'
+
+test_expect_success 'diff --no-index refuses to diff stdin and a directory' '
+ test_must_fail git diff --no-index -- - a </dev/null 2>err &&
+ grep "fatal: cannot compare stdin to a directory" err
+'
+
+test_expect_success PIPE 'diff --no-index refuses to diff a named pipe and a directory' '
+ test_when_finished "rm -f pipe" &&
+ mkfifo pipe &&
+ {
+ (>pipe) &
+ } &&
+ test_when_finished "kill $!" &&
+ test_must_fail git diff --no-index -- pipe a 2>err &&
+ grep "fatal: cannot compare a named pipe to a directory" err
+'
+
+test_expect_success PIPE,SYMLINKS 'diff --no-index reads from pipes' '
+ test_when_finished "rm -f old new new-link" &&
+ mkfifo old &&
+ mkfifo new &&
+ ln -s new new-link &&
+ {
+ (test_write_lines a b c >old) &
+ } &&
+ test_when_finished "! kill $!" &&
+ {
+ (test_write_lines a x c >new) &
+ } &&
+ test_when_finished "! kill $!" &&
+
+ cat >expect <<-EOF &&
+ diff --git a/old b/new-link
+ --- a/old
+ +++ b/new-link
+ @@ -1,3 +1,3 @@
+ a
+ -b
+ +x
+ c
+ EOF
+
+ test_expect_code 1 git diff --no-index old new-link >actual &&
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/t4141-apply-too-large.sh b/t/t4141-apply-too-large.sh
index 58742d4fc5..20cc1209f6 100755
--- a/t/t4141-apply-too-large.sh
+++ b/t/t4141-apply-too-large.sh
@@ -17,7 +17,7 @@ test_expect_success EXPENSIVE 'git apply rejects patches that are too large' '
EOF
test-tool genzeros
} | test_copy_bytes $sz | test_must_fail git apply 2>err &&
- grep "git apply: failed to read" err
+ grep "patch too large" err
'
test_done
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index ae73aef922..af4a123cd2 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -187,6 +187,21 @@ test_expect_success 'git config log.follow does not die with no paths' '
git log --
'
+test_expect_success 'git log --follow rejects unsupported pathspec magic' '
+ test_must_fail git log --follow ":(top,glob,icase)ichi" 2>stderr &&
+ # check full error message; we want to be sure we mention both
+ # of the rejected types (glob,icase), but not the allowed one (top)
+ echo "fatal: pathspec magic not supported by --follow: ${SQ}glob${SQ}, ${SQ}icase${SQ}" >expect &&
+ test_cmp expect stderr
+'
+
+test_expect_success 'log.follow disabled with unsupported pathspec magic' '
+ test_config log.follow true &&
+ git log --format=%s ":(glob,icase)ichi" >actual &&
+ echo third >expect &&
+ test_cmp expect actual
+'
+
test_expect_success 'git config log.follow is overridden by --no-follow' '
test_config log.follow true &&
git log --no-follow --pretty="format:%s" ichi >actual &&
@@ -2343,10 +2358,10 @@ test_expect_success 'log --decorate does not include things outside filter' '
'
test_expect_success 'log --end-of-options' '
- git update-ref refs/heads/--source HEAD &&
- git log --end-of-options --source >actual &&
- git log >expect &&
- test_cmp expect actual
+ git update-ref refs/heads/--source HEAD &&
+ git log --end-of-options --source >actual &&
+ git log >expect &&
+ test_cmp expect actual
'
test_expect_success 'set up commits with different authors' '
diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh
index fa7f987284..2016132f51 100755
--- a/t/t4203-mailmap.sh
+++ b/t/t4203-mailmap.sh
@@ -466,7 +466,7 @@ test_expect_success 'gitmailmap(5) example output: example #1' '
Author Jane Doe <jane@laptop.(none)> maps to Jane Doe <jane@laptop.(none)>
Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
- Author Jane D <jane@desktop.(none)> maps to Jane Doe <jane@desktop.(none)>
+ Author Jane D. <jane@desktop.(none)> maps to Jane Doe <jane@desktop.(none)>
Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
EOF
git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
@@ -494,7 +494,7 @@ test_expect_success 'gitmailmap(5) example output: example #2' '
Author Jane Doe <jane@laptop.(none)> maps to Jane Doe <jane@example.com>
Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
- Author Jane D <jane@desktop.(none)> maps to Jane Doe <jane@example.com>
+ Author Jane D. <jane@desktop.(none)> maps to Jane Doe <jane@example.com>
Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
EOF
git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index 4cf8a77667..dd9035aa38 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -1012,10 +1012,25 @@ test_expect_success '%(describe:tags) vs git describe --tags' '
test_expect_success '%(describe:abbrev=...) vs git describe --abbrev=...' '
test_when_finished "git tag -d tagname" &&
+
+ # Case 1: We have commits between HEAD and the most recent tag
+ # reachable from it
+ test_commit --no-tag file &&
+ git describe --abbrev=15 >expect &&
+ git log -1 --format="%(describe:abbrev=15)" >actual &&
+ test_cmp expect actual &&
+
+ # Make sure the hash used is at least 15 digits long
+ sed -e "s/^.*-g\([0-9a-f]*\)$/\1/" <actual >hexpart &&
+ test 16 -le $(wc -c <hexpart) &&
+
+ # Case 2: We have a tag at HEAD, describe directly gives the
+ # name of the tag
git tag -a -m tagged tagname &&
git describe --abbrev=15 >expect &&
git log -1 --format="%(describe:abbrev=15)" >actual &&
- test_cmp expect actual
+ test_cmp expect actual &&
+ test tagname = $(cat actual)
'
test_expect_success 'log --pretty with space stealing' '
diff --git a/t/t4206-log-follow-harder-copies.sh b/t/t4206-log-follow-harder-copies.sh
index 33ecf82c7f..9167b0351f 100755
--- a/t/t4206-log-follow-harder-copies.sh
+++ b/t/t4206-log-follow-harder-copies.sh
@@ -16,29 +16,29 @@ Line 2
Line 3
'
-test_expect_success \
- 'add a file path0 and commit.' \
- 'git add path0 &&
- git commit -m "Add path0"'
+test_expect_success 'add a file path0 and commit.' '
+ git add path0 &&
+ git commit -m "Add path0"
+'
echo >path0 'New line 1
New line 2
New line 3
'
-test_expect_success \
- 'Change path0.' \
- 'git add path0 &&
- git commit -m "Change path0"'
+test_expect_success 'Change path0.' '
+ git add path0 &&
+ git commit -m "Change path0"
+'
cat <path0 >path1
-test_expect_success \
- 'copy path0 to path1.' \
- 'git add path1 &&
- git commit -m "Copy path1 from path0"'
+test_expect_success 'copy path0 to path1.' '
+ git add path1 &&
+ git commit -m "Copy path1 from path0"
+'
-test_expect_success \
- 'find the copy path0 -> path1 harder' \
- 'git log --follow --name-status --pretty="format:%s" path1 > current'
+test_expect_success 'find the copy path0 -> path1 harder' '
+ git log --follow --name-status --pretty="format:%s" path1 > current
+'
cat >expected <<\EOF
Copy path1 from path0
@@ -51,8 +51,8 @@ Add path0
A path0
EOF
-test_expect_success \
- 'validate the output.' \
- 'compare_diff_patch current expected'
+test_expect_success 'validate the output.' '
+ compare_diff_patch current expected
+'
test_done
diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh
index d2ce236d61..745089479c 100755
--- a/t/t5300-pack-object.sh
+++ b/t/t5300-pack-object.sh
@@ -208,7 +208,7 @@ test_expect_success 'unpack with OFS_DELTA' '
'
test_expect_success 'unpack with OFS_DELTA (core.fsyncmethod=batch)' '
- check_unpack test-3-${packname_3} obj-list "$BATCH_CONFIGURATION"
+ check_unpack test-3-${packname_3} obj-list "$BATCH_CONFIGURATION"
'
test_expect_success 'compare delta flavors' '
@@ -263,97 +263,97 @@ test_expect_success 'survive missing objects/pack directory' '
)
'
-test_expect_success \
- 'verify pack' \
- 'git verify-pack test-1-${packname_1}.idx \
- test-2-${packname_2}.idx \
- test-3-${packname_3}.idx'
-
-test_expect_success \
- 'verify pack -v' \
- 'git verify-pack -v test-1-${packname_1}.idx \
- test-2-${packname_2}.idx \
- test-3-${packname_3}.idx'
-
-test_expect_success \
- 'verify-pack catches mismatched .idx and .pack files' \
- 'cat test-1-${packname_1}.idx >test-3.idx &&
- cat test-2-${packname_2}.pack >test-3.pack &&
- if git verify-pack test-3.idx
- then false
- else :;
- fi'
-
-test_expect_success \
- 'verify-pack catches a corrupted pack signature' \
- 'cat test-1-${packname_1}.pack >test-3.pack &&
- echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=2 &&
- if git verify-pack test-3.idx
- then false
- else :;
- fi'
-
-test_expect_success \
- 'verify-pack catches a corrupted pack version' \
- 'cat test-1-${packname_1}.pack >test-3.pack &&
- echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=7 &&
- if git verify-pack test-3.idx
- then false
- else :;
- fi'
-
-test_expect_success \
- 'verify-pack catches a corrupted type/size of the 1st packed object data' \
- 'cat test-1-${packname_1}.pack >test-3.pack &&
- echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=12 &&
- if git verify-pack test-3.idx
- then false
- else :;
- fi'
-
-test_expect_success \
- 'verify-pack catches a corrupted sum of the index file itself' \
- 'l=$(wc -c <test-3.idx) &&
- l=$(expr $l - 20) &&
- cat test-1-${packname_1}.pack >test-3.pack &&
- printf "%20s" "" | dd of=test-3.idx count=20 bs=1 conv=notrunc seek=$l &&
- if git verify-pack test-3.pack
- then false
- else :;
- fi'
-
-test_expect_success \
- 'build pack index for an existing pack' \
- 'cat test-1-${packname_1}.pack >test-3.pack &&
- git index-pack -o tmp.idx test-3.pack &&
- cmp tmp.idx test-1-${packname_1}.idx &&
-
- git index-pack --promisor=message test-3.pack &&
- cmp test-3.idx test-1-${packname_1}.idx &&
- echo message >expect &&
- test_cmp expect test-3.promisor &&
-
- cat test-2-${packname_2}.pack >test-3.pack &&
- git index-pack -o tmp.idx test-2-${packname_2}.pack &&
- cmp tmp.idx test-2-${packname_2}.idx &&
-
- git index-pack test-3.pack &&
- cmp test-3.idx test-2-${packname_2}.idx &&
-
- cat test-3-${packname_3}.pack >test-3.pack &&
- git index-pack -o tmp.idx test-3-${packname_3}.pack &&
- cmp tmp.idx test-3-${packname_3}.idx &&
-
- git index-pack test-3.pack &&
- cmp test-3.idx test-3-${packname_3}.idx &&
-
- cat test-1-${packname_1}.pack >test-4.pack &&
- rm -f test-4.keep &&
- git index-pack --keep=why test-4.pack &&
- cmp test-1-${packname_1}.idx test-4.idx &&
- test -f test-4.keep &&
-
- :'
+test_expect_success 'verify pack' '
+ git verify-pack test-1-${packname_1}.idx \
+ test-2-${packname_2}.idx \
+ test-3-${packname_3}.idx
+'
+
+test_expect_success 'verify pack -v' '
+ git verify-pack -v test-1-${packname_1}.idx \
+ test-2-${packname_2}.idx \
+ test-3-${packname_3}.idx
+'
+
+test_expect_success 'verify-pack catches mismatched .idx and .pack files' '
+ cat test-1-${packname_1}.idx >test-3.idx &&
+ cat test-2-${packname_2}.pack >test-3.pack &&
+ if git verify-pack test-3.idx
+ then false
+ else :;
+ fi
+'
+
+test_expect_success 'verify-pack catches a corrupted pack signature' '
+ cat test-1-${packname_1}.pack >test-3.pack &&
+ echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=2 &&
+ if git verify-pack test-3.idx
+ then false
+ else :;
+ fi
+'
+
+test_expect_success 'verify-pack catches a corrupted pack version' '
+ cat test-1-${packname_1}.pack >test-3.pack &&
+ echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=7 &&
+ if git verify-pack test-3.idx
+ then false
+ else :;
+ fi
+'
+
+test_expect_success 'verify-pack catches a corrupted type/size of the 1st packed object data' '
+ cat test-1-${packname_1}.pack >test-3.pack &&
+ echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=12 &&
+ if git verify-pack test-3.idx
+ then false
+ else :;
+ fi
+'
+
+test_expect_success 'verify-pack catches a corrupted sum of the index file itself' '
+ l=$(wc -c <test-3.idx) &&
+ l=$(expr $l - 20) &&
+ cat test-1-${packname_1}.pack >test-3.pack &&
+ printf "%20s" "" | dd of=test-3.idx count=20 bs=1 conv=notrunc seek=$l &&
+ if git verify-pack test-3.pack
+ then false
+ else :;
+ fi
+'
+
+test_expect_success 'build pack index for an existing pack' '
+ cat test-1-${packname_1}.pack >test-3.pack &&
+ git index-pack -o tmp.idx test-3.pack &&
+ cmp tmp.idx test-1-${packname_1}.idx &&
+
+ git index-pack --promisor=message test-3.pack &&
+ cmp test-3.idx test-1-${packname_1}.idx &&
+ echo message >expect &&
+ test_cmp expect test-3.promisor &&
+
+ cat test-2-${packname_2}.pack >test-3.pack &&
+ git index-pack -o tmp.idx test-2-${packname_2}.pack &&
+ cmp tmp.idx test-2-${packname_2}.idx &&
+
+ git index-pack test-3.pack &&
+ cmp test-3.idx test-2-${packname_2}.idx &&
+
+ cat test-3-${packname_3}.pack >test-3.pack &&
+ git index-pack -o tmp.idx test-3-${packname_3}.pack &&
+ cmp tmp.idx test-3-${packname_3}.idx &&
+
+ git index-pack test-3.pack &&
+ cmp test-3.idx test-3-${packname_3}.idx &&
+
+ cat test-1-${packname_1}.pack >test-4.pack &&
+ rm -f test-4.keep &&
+ git index-pack --keep=why test-4.pack &&
+ cmp test-1-${packname_1}.idx test-4.idx &&
+ test -f test-4.keep &&
+
+ :
+'
test_expect_success 'unpacking with --strict' '
diff --git a/t/t5301-sliding-window.sh b/t/t5301-sliding-window.sh
index 3ccaaeb397..226490d60d 100755
--- a/t/t5301-sliding-window.sh
+++ b/t/t5301-sliding-window.sh
@@ -8,55 +8,55 @@ test_description='mmap sliding window tests'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
-test_expect_success \
- 'setup' \
- 'rm -f .git/index* &&
- for i in a b c
- do
- echo $i >$i &&
- test-tool genrandom "$i" 32768 >>$i &&
- git update-index --add $i || return 1
- done &&
- echo d >d && cat c >>d && git update-index --add d &&
- tree=$(git write-tree) &&
- commit1=$(git commit-tree $tree </dev/null) &&
- git update-ref HEAD $commit1 &&
- git repack -a -d &&
- test "$(git count-objects)" = "0 objects, 0 kilobytes" &&
- pack1=$(ls .git/objects/pack/*.pack) &&
- test -f "$pack1"'
-
-test_expect_success \
- 'verify-pack -v, defaults' \
- 'git verify-pack -v "$pack1"'
-
-test_expect_success \
- 'verify-pack -v, packedGitWindowSize == 1 page' \
- 'git config core.packedGitWindowSize 512 &&
- git verify-pack -v "$pack1"'
-
-test_expect_success \
- 'verify-pack -v, packedGit{WindowSize,Limit} == 1 page' \
- 'git config core.packedGitWindowSize 512 &&
- git config core.packedGitLimit 512 &&
- git verify-pack -v "$pack1"'
-
-test_expect_success \
- 'repack -a -d, packedGit{WindowSize,Limit} == 1 page' \
- 'git config core.packedGitWindowSize 512 &&
- git config core.packedGitLimit 512 &&
- commit2=$(git commit-tree $tree -p $commit1 </dev/null) &&
- git update-ref HEAD $commit2 &&
- git repack -a -d &&
- test "$(git count-objects)" = "0 objects, 0 kilobytes" &&
- pack2=$(ls .git/objects/pack/*.pack) &&
- test -f "$pack2" &&
- test "$pack1" \!= "$pack2"'
-
-test_expect_success \
- 'verify-pack -v, defaults' \
- 'git config --unset core.packedGitWindowSize &&
- git config --unset core.packedGitLimit &&
- git verify-pack -v "$pack2"'
+test_expect_success 'setup' '
+ rm -f .git/index* &&
+ for i in a b c
+ do
+ echo $i >$i &&
+ test-tool genrandom "$i" 32768 >>$i &&
+ git update-index --add $i || return 1
+ done &&
+ echo d >d && cat c >>d && git update-index --add d &&
+ tree=$(git write-tree) &&
+ commit1=$(git commit-tree $tree </dev/null) &&
+ git update-ref HEAD $commit1 &&
+ git repack -a -d &&
+ test "$(git count-objects)" = "0 objects, 0 kilobytes" &&
+ pack1=$(ls .git/objects/pack/*.pack) &&
+ test -f "$pack1"
+'
+
+test_expect_success 'verify-pack -v, defaults' '
+ git verify-pack -v "$pack1"
+'
+
+test_expect_success 'verify-pack -v, packedGitWindowSize == 1 page' '
+ git config core.packedGitWindowSize 512 &&
+ git verify-pack -v "$pack1"
+'
+
+test_expect_success 'verify-pack -v, packedGit{WindowSize,Limit} == 1 page' '
+ git config core.packedGitWindowSize 512 &&
+ git config core.packedGitLimit 512 &&
+ git verify-pack -v "$pack1"
+'
+
+test_expect_success 'repack -a -d, packedGit{WindowSize,Limit} == 1 page' '
+ git config core.packedGitWindowSize 512 &&
+ git config core.packedGitLimit 512 &&
+ commit2=$(git commit-tree $tree -p $commit1 </dev/null) &&
+ git update-ref HEAD $commit2 &&
+ git repack -a -d &&
+ test "$(git count-objects)" = "0 objects, 0 kilobytes" &&
+ pack2=$(ls .git/objects/pack/*.pack) &&
+ test -f "$pack2" &&
+ test "$pack1" \!= "$pack2"
+'
+
+test_expect_success 'verify-pack -v, defaults' '
+ git config --unset core.packedGitWindowSize &&
+ git config --unset core.packedGitLimit &&
+ git verify-pack -v "$pack2"
+'
test_done
diff --git a/t/t5303-pack-corruption-resilience.sh b/t/t5303-pack-corruption-resilience.sh
index 2926e8dfc4..61469ef4a6 100755
--- a/t/t5303-pack-corruption-resilience.sh
+++ b/t/t5303-pack-corruption-resilience.sh
@@ -59,304 +59,304 @@ do_corrupt_object() {
printf '\0' > zero
-test_expect_success \
- 'initial setup validation' \
- 'create_test_files &&
- create_new_pack &&
- git prune-packed &&
- git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- 'create corruption in header of first object' \
- 'do_corrupt_object $blob_1 0 < zero &&
- test_must_fail git cat-file blob $blob_1 > /dev/null &&
- test_must_fail git cat-file blob $blob_2 > /dev/null &&
- test_must_fail git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- '... but having a loose copy allows for full recovery' \
- 'mv ${pack}.idx tmp &&
- git hash-object -t blob -w file_1 &&
- mv tmp ${pack}.idx &&
- git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- '... and loose copy of first delta allows for partial recovery' \
- 'git prune-packed &&
- test_must_fail git cat-file blob $blob_2 > /dev/null &&
- mv ${pack}.idx tmp &&
- git hash-object -t blob -w file_2 &&
- mv tmp ${pack}.idx &&
- test_must_fail git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- 'create corruption in data of first object' \
- 'create_new_pack &&
- git prune-packed &&
- chmod +w ${pack}.pack &&
- perl -i.bak -pe "s/ base /abcdef/" ${pack}.pack &&
- test_must_fail git cat-file blob $blob_1 > /dev/null &&
- test_must_fail git cat-file blob $blob_2 > /dev/null &&
- test_must_fail git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- '... but having a loose copy allows for full recovery' \
- 'mv ${pack}.idx tmp &&
- git hash-object -t blob -w file_1 &&
- mv tmp ${pack}.idx &&
- git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- '... and loose copy of second object allows for partial recovery' \
- 'git prune-packed &&
- test_must_fail git cat-file blob $blob_2 > /dev/null &&
- mv ${pack}.idx tmp &&
- git hash-object -t blob -w file_2 &&
- mv tmp ${pack}.idx &&
- test_must_fail git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- 'create corruption in header of first delta' \
- 'create_new_pack &&
- git prune-packed &&
- do_corrupt_object $blob_2 0 < zero &&
- git cat-file blob $blob_1 > /dev/null &&
- test_must_fail git cat-file blob $blob_2 > /dev/null &&
- test_must_fail git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- '... but having a loose copy allows for full recovery' \
- 'mv ${pack}.idx tmp &&
- git hash-object -t blob -w file_2 &&
- mv tmp ${pack}.idx &&
- git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- '... and then a repack "clears" the corruption' \
- 'do_repack &&
- git prune-packed &&
- git verify-pack ${pack}.pack &&
- git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- 'create corruption in data of first delta' \
- 'create_new_pack &&
- git prune-packed &&
- chmod +w ${pack}.pack &&
- perl -i.bak -pe "s/ delta1 /abcdefgh/" ${pack}.pack &&
- git cat-file blob $blob_1 > /dev/null &&
- test_must_fail git cat-file blob $blob_2 > /dev/null &&
- test_must_fail git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- '... but having a loose copy allows for full recovery' \
- 'mv ${pack}.idx tmp &&
- git hash-object -t blob -w file_2 &&
- mv tmp ${pack}.idx &&
- git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- '... and then a repack "clears" the corruption' \
- 'do_repack &&
- git prune-packed &&
- git verify-pack ${pack}.pack &&
- git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- 'corruption in delta base reference of first delta (OBJ_REF_DELTA)' \
- 'create_new_pack &&
- git prune-packed &&
- do_corrupt_object $blob_2 2 < zero &&
- git cat-file blob $blob_1 > /dev/null &&
- test_must_fail git cat-file blob $blob_2 > /dev/null &&
- test_must_fail git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- '... but having a loose copy allows for full recovery' \
- 'mv ${pack}.idx tmp &&
- git hash-object -t blob -w file_2 &&
- mv tmp ${pack}.idx &&
- git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- '... and then a repack "clears" the corruption' \
- 'do_repack &&
- git prune-packed &&
- git verify-pack ${pack}.pack &&
- git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- 'corruption #0 in delta base reference of first delta (OBJ_OFS_DELTA)' \
- 'create_new_pack --delta-base-offset &&
- git prune-packed &&
- do_corrupt_object $blob_2 2 < zero &&
- git cat-file blob $blob_1 > /dev/null &&
- test_must_fail git cat-file blob $blob_2 > /dev/null &&
- test_must_fail git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- '... but having a loose copy allows for full recovery' \
- 'mv ${pack}.idx tmp &&
- git hash-object -t blob -w file_2 &&
- mv tmp ${pack}.idx &&
- git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- '... and then a repack "clears" the corruption' \
- 'do_repack --delta-base-offset &&
- git prune-packed &&
- git verify-pack ${pack}.pack &&
- git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- 'corruption #1 in delta base reference of first delta (OBJ_OFS_DELTA)' \
- 'create_new_pack --delta-base-offset &&
- git prune-packed &&
- printf "\001" | do_corrupt_object $blob_2 2 &&
- git cat-file blob $blob_1 > /dev/null &&
- test_must_fail git cat-file blob $blob_2 > /dev/null &&
- test_must_fail git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- '... but having a loose copy allows for full recovery' \
- 'mv ${pack}.idx tmp &&
- git hash-object -t blob -w file_2 &&
- mv tmp ${pack}.idx &&
- git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- '... and then a repack "clears" the corruption' \
- 'do_repack --delta-base-offset &&
- git prune-packed &&
- git verify-pack ${pack}.pack &&
- git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- '... and a redundant pack allows for full recovery too' \
- 'do_corrupt_object $blob_2 2 < zero &&
- git cat-file blob $blob_1 > /dev/null &&
- test_must_fail git cat-file blob $blob_2 > /dev/null &&
- test_must_fail git cat-file blob $blob_3 > /dev/null &&
- mv ${pack}.idx tmp &&
- git hash-object -t blob -w file_1 &&
- git hash-object -t blob -w file_2 &&
- printf "$blob_1\n$blob_2\n" | git pack-objects .git/objects/pack/pack &&
- git prune-packed &&
- mv tmp ${pack}.idx &&
- git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- 'corruption of delta base reference pointing to wrong object' \
- 'create_new_pack --delta-base-offset &&
- git prune-packed &&
- printf "\220\033" | do_corrupt_object $blob_3 2 &&
- git cat-file blob $blob_1 >/dev/null &&
- git cat-file blob $blob_2 >/dev/null &&
- test_must_fail git cat-file blob $blob_3 >/dev/null'
-
-test_expect_success \
- '... but having a loose copy allows for full recovery' \
- 'mv ${pack}.idx tmp &&
- git hash-object -t blob -w file_3 &&
- mv tmp ${pack}.idx &&
- git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- '... and then a repack "clears" the corruption' \
- 'do_repack --delta-base-offset --no-reuse-delta &&
- git prune-packed &&
- git verify-pack ${pack}.pack &&
- git cat-file blob $blob_1 > /dev/null &&
- git cat-file blob $blob_2 > /dev/null &&
- git cat-file blob $blob_3 > /dev/null'
-
-test_expect_success \
- 'corrupting header to have too small output buffer fails unpack' \
- 'create_new_pack &&
- git prune-packed &&
- printf "\262\001" | do_corrupt_object $blob_1 0 &&
- test_must_fail git cat-file blob $blob_1 > /dev/null &&
- test_must_fail git cat-file blob $blob_2 > /dev/null &&
- test_must_fail git cat-file blob $blob_3 > /dev/null'
+test_expect_success 'initial setup validation' '
+ create_test_files &&
+ create_new_pack &&
+ git prune-packed &&
+ git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success 'create corruption in header of first object' '
+ do_corrupt_object $blob_1 0 < zero &&
+ test_must_fail git cat-file blob $blob_1 > /dev/null &&
+ test_must_fail git cat-file blob $blob_2 > /dev/null &&
+ test_must_fail git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success '... but having a loose copy allows for full recovery' '
+ mv ${pack}.idx tmp &&
+ git hash-object -t blob -w file_1 &&
+ mv tmp ${pack}.idx &&
+ git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success '... and loose copy of first delta allows for partial recovery' '
+ git prune-packed &&
+ test_must_fail git cat-file blob $blob_2 > /dev/null &&
+ mv ${pack}.idx tmp &&
+ git hash-object -t blob -w file_2 &&
+ mv tmp ${pack}.idx &&
+ test_must_fail git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success 'create corruption in data of first object' '
+ create_new_pack &&
+ git prune-packed &&
+ chmod +w ${pack}.pack &&
+ perl -i.bak -pe "s/ base /abcdef/" ${pack}.pack &&
+ test_must_fail git cat-file blob $blob_1 > /dev/null &&
+ test_must_fail git cat-file blob $blob_2 > /dev/null &&
+ test_must_fail git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success '... but having a loose copy allows for full recovery' '
+ mv ${pack}.idx tmp &&
+ git hash-object -t blob -w file_1 &&
+ mv tmp ${pack}.idx &&
+ git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success '... and loose copy of second object allows for partial recovery' '
+ git prune-packed &&
+ test_must_fail git cat-file blob $blob_2 > /dev/null &&
+ mv ${pack}.idx tmp &&
+ git hash-object -t blob -w file_2 &&
+ mv tmp ${pack}.idx &&
+ test_must_fail git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success 'create corruption in header of first delta' '
+ create_new_pack &&
+ git prune-packed &&
+ do_corrupt_object $blob_2 0 < zero &&
+ git cat-file blob $blob_1 > /dev/null &&
+ test_must_fail git cat-file blob $blob_2 > /dev/null &&
+ test_must_fail git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success '... but having a loose copy allows for full recovery' '
+ mv ${pack}.idx tmp &&
+ git hash-object -t blob -w file_2 &&
+ mv tmp ${pack}.idx &&
+ git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success '... and then a repack "clears" the corruption' '
+ do_repack &&
+ git prune-packed &&
+ git verify-pack ${pack}.pack &&
+ git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success 'create corruption in data of first delta' '
+ create_new_pack &&
+ git prune-packed &&
+ chmod +w ${pack}.pack &&
+ perl -i.bak -pe "s/ delta1 /abcdefgh/" ${pack}.pack &&
+ git cat-file blob $blob_1 > /dev/null &&
+ test_must_fail git cat-file blob $blob_2 > /dev/null &&
+ test_must_fail git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success '... but having a loose copy allows for full recovery' '
+ mv ${pack}.idx tmp &&
+ git hash-object -t blob -w file_2 &&
+ mv tmp ${pack}.idx &&
+ git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success '... and then a repack "clears" the corruption' '
+ do_repack &&
+ git prune-packed &&
+ git verify-pack ${pack}.pack &&
+ git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success 'corruption in delta base reference of first delta (OBJ_REF_DELTA)' '
+ create_new_pack &&
+ git prune-packed &&
+ do_corrupt_object $blob_2 2 < zero &&
+ git cat-file blob $blob_1 > /dev/null &&
+ test_must_fail git cat-file blob $blob_2 > /dev/null &&
+ test_must_fail git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success '... but having a loose copy allows for full recovery' '
+ mv ${pack}.idx tmp &&
+ git hash-object -t blob -w file_2 &&
+ mv tmp ${pack}.idx &&
+ git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success '... and then a repack "clears" the corruption' '
+ do_repack &&
+ git prune-packed &&
+ git verify-pack ${pack}.pack &&
+ git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success 'corruption #0 in delta base reference of first delta (OBJ_OFS_DELTA)' '
+ create_new_pack --delta-base-offset &&
+ git prune-packed &&
+ do_corrupt_object $blob_2 2 < zero &&
+ git cat-file blob $blob_1 > /dev/null &&
+ test_must_fail git cat-file blob $blob_2 > /dev/null &&
+ test_must_fail git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success '... but having a loose copy allows for full recovery' '
+ mv ${pack}.idx tmp &&
+ git hash-object -t blob -w file_2 &&
+ mv tmp ${pack}.idx &&
+ git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success '... and then a repack "clears" the corruption' '
+ do_repack --delta-base-offset &&
+ git prune-packed &&
+ git verify-pack ${pack}.pack &&
+ git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success 'corruption #1 in delta base reference of first delta (OBJ_OFS_DELTA)' '
+ create_new_pack --delta-base-offset &&
+ git prune-packed &&
+ printf "\001" | do_corrupt_object $blob_2 2 &&
+ git cat-file blob $blob_1 > /dev/null &&
+ test_must_fail git cat-file blob $blob_2 > /dev/null &&
+ test_must_fail git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success '... but having a loose copy allows for full recovery' '
+ mv ${pack}.idx tmp &&
+ git hash-object -t blob -w file_2 &&
+ mv tmp ${pack}.idx &&
+ git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success '... and then a repack "clears" the corruption' '
+ do_repack --delta-base-offset &&
+ git prune-packed &&
+ git verify-pack ${pack}.pack &&
+ git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success '... and a redundant pack allows for full recovery too' '
+ do_corrupt_object $blob_2 2 < zero &&
+ git cat-file blob $blob_1 > /dev/null &&
+ test_must_fail git cat-file blob $blob_2 > /dev/null &&
+ test_must_fail git cat-file blob $blob_3 > /dev/null &&
+ mv ${pack}.idx tmp &&
+ git hash-object -t blob -w file_1 &&
+ git hash-object -t blob -w file_2 &&
+ printf "$blob_1\n$blob_2\n" | git pack-objects .git/objects/pack/pack &&
+ git prune-packed &&
+ mv tmp ${pack}.idx &&
+ git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success 'corruption of delta base reference pointing to wrong object' '
+ create_new_pack --delta-base-offset &&
+ git prune-packed &&
+ printf "\220\033" | do_corrupt_object $blob_3 2 &&
+ git cat-file blob $blob_1 >/dev/null &&
+ git cat-file blob $blob_2 >/dev/null &&
+ test_must_fail git cat-file blob $blob_3 >/dev/null
+'
+
+test_expect_success '... but having a loose copy allows for full recovery' '
+ mv ${pack}.idx tmp &&
+ git hash-object -t blob -w file_3 &&
+ mv tmp ${pack}.idx &&
+ git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success '... and then a repack "clears" the corruption' '
+ do_repack --delta-base-offset --no-reuse-delta &&
+ git prune-packed &&
+ git verify-pack ${pack}.pack &&
+ git cat-file blob $blob_1 > /dev/null &&
+ git cat-file blob $blob_2 > /dev/null &&
+ git cat-file blob $blob_3 > /dev/null
+'
+
+test_expect_success 'corrupting header to have too small output buffer fails unpack' '
+ create_new_pack &&
+ git prune-packed &&
+ printf "\262\001" | do_corrupt_object $blob_1 0 &&
+ test_must_fail git cat-file blob $blob_1 > /dev/null &&
+ test_must_fail git cat-file blob $blob_2 > /dev/null &&
+ test_must_fail git cat-file blob $blob_3 > /dev/null
+'
# \0 - empty base
# \1 - one byte in result
# \1 - one literal byte (X)
-test_expect_success \
- 'apply good minimal delta' \
- 'printf "\0\1\1X" > minimal_delta &&
- test-tool delta -p /dev/null minimal_delta /dev/null'
+test_expect_success 'apply good minimal delta' '
+ printf "\0\1\1X" > minimal_delta &&
+ test-tool delta -p /dev/null minimal_delta /dev/null
+'
# \0 - empty base
# \1 - 1 byte in result
# \2 - two literal bytes (one too many)
-test_expect_success \
- 'apply delta with too many literal bytes' \
- 'printf "\0\1\2XX" > too_big_literal &&
- test_must_fail test-tool delta -p /dev/null too_big_literal /dev/null'
+test_expect_success 'apply delta with too many literal bytes' '
+ printf "\0\1\2XX" > too_big_literal &&
+ test_must_fail test-tool delta -p /dev/null too_big_literal /dev/null
+'
# \4 - four bytes in base
# \1 - one byte in result
# \221 - copy, one byte offset, one byte size
# \0 - copy from offset 0
# \2 - copy two bytes (one too many)
-test_expect_success \
- 'apply delta with too many copied bytes' \
- 'printf "\4\1\221\0\2" > too_big_copy &&
- printf base >base &&
- test_must_fail test-tool delta -p base too_big_copy /dev/null'
+test_expect_success 'apply delta with too many copied bytes' '
+ printf "\4\1\221\0\2" > too_big_copy &&
+ printf base >base &&
+ test_must_fail test-tool delta -p base too_big_copy /dev/null
+'
# \0 - empty base
# \2 - two bytes in result
# \2 - two literal bytes (we are short one)
-test_expect_success \
- 'apply delta with too few literal bytes' \
- 'printf "\0\2\2X" > truncated_delta &&
- test_must_fail test-tool delta -p /dev/null truncated_delta /dev/null'
+test_expect_success 'apply delta with too few literal bytes' '
+ printf "\0\2\2X" > truncated_delta &&
+ test_must_fail test-tool delta -p /dev/null truncated_delta /dev/null
+'
# \0 - empty base
# \1 - one byte in result
# \221 - copy, one byte offset, one byte size
# \0 - copy from offset 0
# \1 - copy one byte (we are short one)
-test_expect_success \
- 'apply delta with too few bytes in base' \
- 'printf "\0\1\221\0\1" > truncated_base &&
- test_must_fail test-tool delta -p /dev/null truncated_base /dev/null'
+test_expect_success 'apply delta with too few bytes in base' '
+ printf "\0\1\221\0\1" > truncated_base &&
+ test_must_fail test-tool delta -p /dev/null truncated_base /dev/null
+'
# \4 - four bytes in base
# \2 - two bytes in result
@@ -366,20 +366,20 @@ test_expect_success \
#
# Note that the literal byte is necessary to get past the uninteresting minimum
# delta size check.
-test_expect_success \
- 'apply delta with truncated copy parameters' \
- 'printf "\4\2\1X\221" > truncated_copy_delta &&
- printf base >base &&
- test_must_fail test-tool delta -p base truncated_copy_delta /dev/null'
+test_expect_success 'apply delta with truncated copy parameters' '
+ printf "\4\2\1X\221" > truncated_copy_delta &&
+ printf base >base &&
+ test_must_fail test-tool delta -p base truncated_copy_delta /dev/null
+'
# \0 - empty base
# \1 - one byte in result
# \1 - one literal byte (X)
# \1 - trailing garbage command
-test_expect_success \
- 'apply delta with trailing garbage literal' \
- 'printf "\0\1\1X\1" > tail_garbage_literal &&
- test_must_fail test-tool delta -p /dev/null tail_garbage_literal /dev/null'
+test_expect_success 'apply delta with trailing garbage literal' '
+ printf "\0\1\1X\1" > tail_garbage_literal &&
+ test_must_fail test-tool delta -p /dev/null tail_garbage_literal /dev/null
+'
# \4 - four bytes in base
# \1 - one byte in result
@@ -387,19 +387,19 @@ test_expect_success \
# \221 - copy, one byte offset, one byte size
# \0 - copy from offset 0
# \1 - copy 1 byte
-test_expect_success \
- 'apply delta with trailing garbage copy' \
- 'printf "\4\1\1X\221\0\1" > tail_garbage_copy &&
- printf base >base &&
- test_must_fail test-tool delta -p /dev/null tail_garbage_copy /dev/null'
+test_expect_success 'apply delta with trailing garbage copy' '
+ printf "\4\1\1X\221\0\1" > tail_garbage_copy &&
+ printf base >base &&
+ test_must_fail test-tool delta -p /dev/null tail_garbage_copy /dev/null
+'
# \0 - empty base
# \1 - one byte in result
# \1 - one literal byte (X)
# \0 - bogus opcode
-test_expect_success \
- 'apply delta with trailing garbage opcode' \
- 'printf "\0\1\1X\0" > tail_garbage_opcode &&
- test_must_fail test-tool delta -p /dev/null tail_garbage_opcode /dev/null'
+test_expect_success 'apply delta with trailing garbage opcode' '
+ printf "\0\1\1X\0" > tail_garbage_opcode &&
+ test_must_fail test-tool delta -p /dev/null tail_garbage_opcode /dev/null
+'
test_done
diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh
index f367327441..b4df545e5a 100755
--- a/t/t5304-prune.sh
+++ b/t/t5304-prune.sh
@@ -350,4 +350,18 @@ test_expect_success 'old reachable-from-recent retained with bitmaps' '
test_must_fail git cat-file -e $to_drop
'
+test_expect_success 'gc.recentObjectsHook' '
+ add_blob &&
+ test-tool chmtime =-86500 $BLOB_FILE &&
+
+ write_script precious-objects <<-EOF &&
+ echo $BLOB
+ EOF
+ test_config gc.recentObjectsHook ./precious-objects &&
+
+ git prune --expire=now &&
+
+ git cat-file -p $BLOB
+'
+
test_done
diff --git a/t/t5306-pack-nobase.sh b/t/t5306-pack-nobase.sh
index 846c5ca7d3..0d50c6b4bc 100755
--- a/t/t5306-pack-nobase.sh
+++ b/t/t5306-pack-nobase.sh
@@ -12,18 +12,17 @@ TEST_PASSES_SANITIZE_LEAK=true
# Create A-B chain
#
-test_expect_success \
- 'setup base' \
- 'test_write_lines a b c d e f g h i >text &&
- echo side >side &&
- git update-index --add text side &&
- A=$(echo A | git commit-tree $(git write-tree)) &&
+test_expect_success 'setup base' '
+ test_write_lines a b c d e f g h i >text &&
+ echo side >side &&
+ git update-index --add text side &&
+ A=$(echo A | git commit-tree $(git write-tree)) &&
- echo m >>text &&
- git update-index text &&
- B=$(echo B | git commit-tree $(git write-tree) -p $A) &&
- git update-ref HEAD $B
- '
+ echo m >>text &&
+ git update-index text &&
+ B=$(echo B | git commit-tree $(git write-tree) -p $A) &&
+ git update-ref HEAD $B
+'
# Create repository with C whose parent is B.
# Repository contains C, C^{tree}, C:text, B, B^{tree}.
@@ -31,52 +30,49 @@ test_expect_success \
# Repository is missing A (parent of B).
# Repository is missing A:side.
#
-test_expect_success \
- 'setup patch_clone' \
- 'base_objects=$(pwd)/.git/objects &&
- (mkdir patch_clone &&
- cd patch_clone &&
- git init &&
- echo "$base_objects" >.git/objects/info/alternates &&
- echo q >>text &&
- git read-tree $B &&
- git update-index text &&
- git update-ref HEAD $(echo C | git commit-tree $(git write-tree) -p $B) &&
- rm .git/objects/info/alternates &&
+test_expect_success 'setup patch_clone' '
+ base_objects=$(pwd)/.git/objects &&
+ (mkdir patch_clone &&
+ cd patch_clone &&
+ git init &&
+ echo "$base_objects" >.git/objects/info/alternates &&
+ echo q >>text &&
+ git read-tree $B &&
+ git update-index text &&
+ git update-ref HEAD $(echo C | git commit-tree $(git write-tree) -p $B) &&
+ rm .git/objects/info/alternates &&
- git --git-dir=../.git cat-file commit $B |
- git hash-object -t commit -w --stdin &&
+ git --git-dir=../.git cat-file commit $B |
+ git hash-object -t commit -w --stdin &&
- git --git-dir=../.git cat-file tree "$B^{tree}" |
- git hash-object -t tree -w --stdin
- ) &&
- C=$(git --git-dir=patch_clone/.git rev-parse HEAD)
- '
+ git --git-dir=../.git cat-file tree "$B^{tree}" |
+ git hash-object -t tree -w --stdin
+ ) &&
+ C=$(git --git-dir=patch_clone/.git rev-parse HEAD)
+'
# Clone patch_clone indirectly by cloning base and fetching.
#
-test_expect_success \
- 'indirectly clone patch_clone' \
- '(mkdir user_clone &&
- cd user_clone &&
- git init &&
- git pull ../.git &&
- test $(git rev-parse HEAD) = $B &&
+test_expect_success 'indirectly clone patch_clone' '
+ (mkdir user_clone &&
+ cd user_clone &&
+ git init &&
+ git pull ../.git &&
+ test $(git rev-parse HEAD) = $B &&
- git pull ../patch_clone/.git &&
- test $(git rev-parse HEAD) = $C
- )
- '
+ git pull ../patch_clone/.git &&
+ test $(git rev-parse HEAD) = $C
+ )
+'
# Cloning the patch_clone directly should fail.
#
-test_expect_success \
- 'clone of patch_clone is incomplete' \
- '(mkdir user_direct &&
- cd user_direct &&
- git init &&
- test_must_fail git fetch ../patch_clone/.git
- )
- '
+test_expect_success 'clone of patch_clone is incomplete' '
+ (mkdir user_direct &&
+ cd user_direct &&
+ git init &&
+ test_must_fail git fetch ../patch_clone/.git
+ )
+'
test_done
diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh
index 526a5a506e..78c1c6c923 100755
--- a/t/t5310-pack-bitmaps.sh
+++ b/t/t5310-pack-bitmaps.sh
@@ -9,6 +9,10 @@ test_description='exercise basic bitmap functionality'
# their place.
GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0
+# Likewise, allow individual tests to control whether or not they use
+# the boundary-based traversal.
+sane_unset GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL
+
objpath () {
echo ".git/objects/$(echo "$1" | sed -e 's|\(..\)|\1/|')"
}
@@ -457,6 +461,13 @@ test_bitmap_cases () {
test_bitmap_cases
+GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL=1
+export GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL
+
+test_bitmap_cases
+
+sane_unset GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL
+
test_expect_success 'incremental repack fails when bitmaps are requested' '
test_commit more-1 &&
test_must_fail git repack -d 2>err &&
@@ -468,6 +479,33 @@ test_expect_success 'incremental repack can disable bitmaps' '
git repack -d --no-write-bitmap-index
'
+test_expect_success 'boundary-based traversal is used when requested' '
+ git repack -a -d --write-bitmap-index &&
+
+ for argv in \
+ "git -c pack.useBitmapBoundaryTraversal=true" \
+ "git -c feature.experimental=true" \
+ "GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL=1 git"
+ do
+ eval "GIT_TRACE2_EVENT=1 $argv rev-list --objects \
+ --use-bitmap-index second..other 2>perf" &&
+ grep "\"region_enter\".*\"label\":\"haves/boundary\"" perf ||
+ return 1
+ done &&
+
+ for argv in \
+ "git -c pack.useBitmapBoundaryTraversal=false" \
+ "git -c feature.experimental=true -c pack.useBitmapBoundaryTraversal=false" \
+ "GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL=0 git -c pack.useBitmapBoundaryTraversal=true" \
+ "GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL=0 git -c feature.experimental=true"
+ do
+ eval "GIT_TRACE2_EVENT=1 $argv rev-list --objects \
+ --use-bitmap-index second..other 2>perf" &&
+ grep "\"region_enter\".*\"label\":\"haves/classic\"" perf ||
+ return 1
+ done
+'
+
test_bitmap_cases "pack.writeBitmapLookupTable"
test_expect_success 'verify writing bitmap lookup table when enabled' '
diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh
index b6e1211578..4df76173a8 100755
--- a/t/t5318-commit-graph.sh
+++ b/t/t5318-commit-graph.sh
@@ -24,12 +24,10 @@ test_expect_success 'usage shown with an error on unknown sub-command' '
test_cmp expect actual
'
+objdir=".git/objects"
+
test_expect_success 'setup full repo' '
- mkdir full &&
- cd "$TRASH_DIRECTORY/full" &&
- git init &&
- git config core.commitGraph true &&
- objdir=".git/objects"
+ git init full
'
test_expect_success POSIXPERM 'tweak umask for modebit tests' '
@@ -37,31 +35,28 @@ test_expect_success POSIXPERM 'tweak umask for modebit tests' '
'
test_expect_success 'verify graph with no graph file' '
- cd "$TRASH_DIRECTORY/full" &&
- git commit-graph verify
+ git -C full commit-graph verify
'
test_expect_success 'write graph with no packs' '
- cd "$TRASH_DIRECTORY/full" &&
- git commit-graph write --object-dir $objdir &&
- test_path_is_missing $objdir/info/commit-graph
+ git -C full commit-graph write --object-dir $objdir &&
+ test_path_is_missing full/$objdir/info/commit-graph
'
test_expect_success 'exit with correct error on bad input to --stdin-packs' '
- cd "$TRASH_DIRECTORY/full" &&
echo doesnotexist >in &&
- test_expect_code 1 git commit-graph write --stdin-packs <in 2>stderr &&
+ test_expect_code 1 git -C full commit-graph write --stdin-packs \
+ <in 2>stderr &&
test_i18ngrep "error adding pack" stderr
'
test_expect_success 'create commits and repack' '
- cd "$TRASH_DIRECTORY/full" &&
for i in $(test_seq 3)
do
- test_commit $i &&
- git branch commits/$i || return 1
+ test_commit -C full $i &&
+ git -C full branch commits/$i || return 1
done &&
- git repack
+ git -C full repack
'
. "$TEST_DIRECTORY"/lib-commit-graph.sh
@@ -69,117 +64,106 @@ test_expect_success 'create commits and repack' '
graph_git_behavior 'no graph' full commits/3 commits/1
test_expect_success 'exit with correct error on bad input to --stdin-commits' '
- cd "$TRASH_DIRECTORY/full" &&
# invalid, non-hex OID
- echo HEAD >in &&
- test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr &&
+ echo HEAD | test_expect_code 1 git -C full commit-graph write \
+ --stdin-commits 2>stderr &&
test_i18ngrep "unexpected non-hex object ID: HEAD" stderr &&
# non-existent OID
- echo $ZERO_OID >in &&
- test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr &&
+ echo $ZERO_OID | test_expect_code 1 git -C full commit-graph write \
+ --stdin-commits 2>stderr &&
test_i18ngrep "invalid object" stderr &&
# valid commit and tree OID
- git rev-parse HEAD HEAD^{tree} >in &&
- git commit-graph write --stdin-commits <in &&
- graph_read_expect 3 generation_data
+ git -C full rev-parse HEAD HEAD^{tree} >in &&
+ git -C full commit-graph write --stdin-commits <in &&
+ graph_read_expect -C full 3 generation_data
'
test_expect_success 'write graph' '
- cd "$TRASH_DIRECTORY/full" &&
- git commit-graph write &&
- test_path_is_file $objdir/info/commit-graph &&
- graph_read_expect "3" generation_data
+ git -C full commit-graph write &&
+ test_path_is_file full/$objdir/info/commit-graph &&
+ graph_read_expect -C full 3 generation_data
'
test_expect_success POSIXPERM 'write graph has correct permissions' '
- test_path_is_file $objdir/info/commit-graph &&
+ test_path_is_file full/$objdir/info/commit-graph &&
echo "-r--r--r--" >expect &&
- test_modebits $objdir/info/commit-graph >actual &&
+ test_modebits full/$objdir/info/commit-graph >actual &&
test_cmp expect actual
'
graph_git_behavior 'graph exists' full commits/3 commits/1
test_expect_success 'Add more commits' '
- cd "$TRASH_DIRECTORY/full" &&
- git reset --hard commits/1 &&
+ git -C full reset --hard commits/1 &&
for i in $(test_seq 4 5)
do
- test_commit $i &&
- git branch commits/$i || return 1
+ test_commit -C full $i &&
+ git -C full branch commits/$i || return 1
done &&
- git reset --hard commits/2 &&
+ git -C full reset --hard commits/2 &&
for i in $(test_seq 6 7)
do
- test_commit $i &&
- git branch commits/$i || return 1
+ test_commit -C full $i &&
+ git -C full branch commits/$i || return 1
done &&
- git reset --hard commits/2 &&
- git merge commits/4 &&
- git branch merge/1 &&
- git reset --hard commits/4 &&
- git merge commits/6 &&
- git branch merge/2 &&
- git reset --hard commits/3 &&
- git merge commits/5 commits/7 &&
- git branch merge/3 &&
- git repack
+ git -C full reset --hard commits/2 &&
+ git -C full merge commits/4 &&
+ git -C full branch merge/1 &&
+ git -C full reset --hard commits/4 &&
+ git -C full merge commits/6 &&
+ git -C full branch merge/2 &&
+ git -C full reset --hard commits/3 &&
+ git -C full merge commits/5 commits/7 &&
+ git -C full branch merge/3 &&
+ git -C full repack
'
test_expect_success 'commit-graph write progress off for redirected stderr' '
- cd "$TRASH_DIRECTORY/full" &&
- git commit-graph write 2>err &&
+ git -C full commit-graph write 2>err &&
test_must_be_empty err
'
test_expect_success 'commit-graph write force progress on for stderr' '
- cd "$TRASH_DIRECTORY/full" &&
- GIT_PROGRESS_DELAY=0 git commit-graph write --progress 2>err &&
+ GIT_PROGRESS_DELAY=0 git -C full commit-graph write --progress 2>err &&
test_file_not_empty err
'
test_expect_success 'commit-graph write with the --no-progress option' '
- cd "$TRASH_DIRECTORY/full" &&
- git commit-graph write --no-progress 2>err &&
+ git -C full commit-graph write --no-progress 2>err &&
test_must_be_empty err
'
test_expect_success 'commit-graph write --stdin-commits progress off for redirected stderr' '
- cd "$TRASH_DIRECTORY/full" &&
- git rev-parse commits/5 >in &&
- git commit-graph write --stdin-commits <in 2>err &&
+ git -C full rev-parse commits/5 >in &&
+ git -C full commit-graph write --stdin-commits <in 2>err &&
test_must_be_empty err
'
test_expect_success 'commit-graph write --stdin-commits force progress on for stderr' '
- cd "$TRASH_DIRECTORY/full" &&
- git rev-parse commits/5 >in &&
- GIT_PROGRESS_DELAY=0 git commit-graph write --stdin-commits --progress <in 2>err &&
+ git -C full rev-parse commits/5 >in &&
+ GIT_PROGRESS_DELAY=0 git -C full commit-graph write --stdin-commits \
+ --progress <in 2>err &&
test_i18ngrep "Collecting commits from input" err
'
test_expect_success 'commit-graph write --stdin-commits with the --no-progress option' '
- cd "$TRASH_DIRECTORY/full" &&
- git rev-parse commits/5 >in &&
- git commit-graph write --stdin-commits --no-progress <in 2>err &&
+ git -C full rev-parse commits/5 >in &&
+ git -C full commit-graph write --stdin-commits --no-progress <in 2>err &&
test_must_be_empty err
'
test_expect_success 'commit-graph verify progress off for redirected stderr' '
- cd "$TRASH_DIRECTORY/full" &&
- git commit-graph verify 2>err &&
+ git -C full commit-graph verify 2>err &&
test_must_be_empty err
'
test_expect_success 'commit-graph verify force progress on for stderr' '
- cd "$TRASH_DIRECTORY/full" &&
- GIT_PROGRESS_DELAY=0 git commit-graph verify --progress 2>err &&
+ GIT_PROGRESS_DELAY=0 git -C full commit-graph verify --progress 2>err &&
test_file_not_empty err
'
test_expect_success 'commit-graph verify with the --no-progress option' '
- cd "$TRASH_DIRECTORY/full" &&
- git commit-graph verify --no-progress 2>err &&
+ git -C full commit-graph verify --no-progress 2>err &&
test_must_be_empty err
'
@@ -194,10 +178,9 @@ test_expect_success 'commit-graph verify with the --no-progress option' '
# 1
test_expect_success 'write graph with merges' '
- cd "$TRASH_DIRECTORY/full" &&
- git commit-graph write &&
- test_path_is_file $objdir/info/commit-graph &&
- graph_read_expect "10" "generation_data extra_edges"
+ git -C full commit-graph write &&
+ test_path_is_file full/$objdir/info/commit-graph &&
+ graph_read_expect -C full 10 "generation_data extra_edges"
'
graph_git_behavior 'merge 1 vs 2' full merge/1 merge/2
@@ -205,12 +188,11 @@ graph_git_behavior 'merge 1 vs 3' full merge/1 merge/3
graph_git_behavior 'merge 2 vs 3' full merge/2 merge/3
test_expect_success 'Add one more commit' '
- cd "$TRASH_DIRECTORY/full" &&
- test_commit 8 &&
- git branch commits/8 &&
- ls $objdir/pack | grep idx >existing-idx &&
- git repack &&
- ls $objdir/pack| grep idx | grep -v -f existing-idx >new-idx
+ test_commit -C full 8 &&
+ git -C full branch commits/8 &&
+ ls full/$objdir/pack | grep idx >existing-idx &&
+ git -C full repack &&
+ ls full/$objdir/pack| grep idx | grep -v -f existing-idx >new-idx
'
# Current graph structure:
@@ -229,114 +211,101 @@ graph_git_behavior 'mixed mode, commit 8 vs merge 1' full commits/8 merge/1
graph_git_behavior 'mixed mode, commit 8 vs merge 2' full commits/8 merge/2
test_expect_success 'write graph with new commit' '
- cd "$TRASH_DIRECTORY/full" &&
- git commit-graph write &&
- test_path_is_file $objdir/info/commit-graph &&
- graph_read_expect "11" "generation_data extra_edges"
+ git -C full commit-graph write &&
+ test_path_is_file full/$objdir/info/commit-graph &&
+ graph_read_expect -C full 11 "generation_data extra_edges"
'
graph_git_behavior 'full graph, commit 8 vs merge 1' full commits/8 merge/1
graph_git_behavior 'full graph, commit 8 vs merge 2' full commits/8 merge/2
test_expect_success 'write graph with nothing new' '
- cd "$TRASH_DIRECTORY/full" &&
- git commit-graph write &&
- test_path_is_file $objdir/info/commit-graph &&
- graph_read_expect "11" "generation_data extra_edges"
+ git -C full commit-graph write &&
+ test_path_is_file full/$objdir/info/commit-graph &&
+ graph_read_expect -C full 11 "generation_data extra_edges"
'
graph_git_behavior 'cleared graph, commit 8 vs merge 1' full commits/8 merge/1
graph_git_behavior 'cleared graph, commit 8 vs merge 2' full commits/8 merge/2
test_expect_success 'build graph from latest pack with closure' '
- cd "$TRASH_DIRECTORY/full" &&
- cat new-idx | git commit-graph write --stdin-packs &&
- test_path_is_file $objdir/info/commit-graph &&
- graph_read_expect "9" "generation_data extra_edges"
+ git -C full commit-graph write --stdin-packs <new-idx &&
+ test_path_is_file full/$objdir/info/commit-graph &&
+ graph_read_expect -C full 9 "generation_data extra_edges"
'
graph_git_behavior 'graph from pack, commit 8 vs merge 1' full commits/8 merge/1
graph_git_behavior 'graph from pack, commit 8 vs merge 2' full commits/8 merge/2
test_expect_success 'build graph from commits with closure' '
- cd "$TRASH_DIRECTORY/full" &&
- git tag -a -m "merge" tag/merge merge/2 &&
- git rev-parse tag/merge >commits-in &&
- git rev-parse merge/1 >>commits-in &&
- cat commits-in | git commit-graph write --stdin-commits &&
- test_path_is_file $objdir/info/commit-graph &&
- graph_read_expect "6" "generation_data"
+ git -C full tag -a -m "merge" tag/merge merge/2 &&
+ git -C full rev-parse tag/merge >commits-in &&
+ git -C full rev-parse merge/1 >>commits-in &&
+ git -C full commit-graph write --stdin-commits <commits-in &&
+ test_path_is_file full/$objdir/info/commit-graph &&
+ graph_read_expect -C full 6 "generation_data"
'
graph_git_behavior 'graph from commits, commit 8 vs merge 1' full commits/8 merge/1
graph_git_behavior 'graph from commits, commit 8 vs merge 2' full commits/8 merge/2
test_expect_success 'build graph from commits with append' '
- cd "$TRASH_DIRECTORY/full" &&
- git rev-parse merge/3 | git commit-graph write --stdin-commits --append &&
- test_path_is_file $objdir/info/commit-graph &&
- graph_read_expect "10" "generation_data extra_edges"
+ git -C full rev-parse merge/3 >in &&
+ git -C full commit-graph write --stdin-commits --append <in &&
+ test_path_is_file full/$objdir/info/commit-graph &&
+ graph_read_expect -C full 10 "generation_data extra_edges"
'
graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
test_expect_success 'build graph using --reachable' '
- cd "$TRASH_DIRECTORY/full" &&
- git commit-graph write --reachable &&
- test_path_is_file $objdir/info/commit-graph &&
- graph_read_expect "11" "generation_data extra_edges"
+ git -C full commit-graph write --reachable &&
+ test_path_is_file full/$objdir/info/commit-graph &&
+ graph_read_expect -C full 11 "generation_data extra_edges"
'
graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
test_expect_success 'setup bare repo' '
- cd "$TRASH_DIRECTORY" &&
- git clone --bare --no-local full bare &&
- cd bare &&
- git config core.commitGraph true &&
- baredir="./objects"
+ git clone --bare --no-local full bare
'
graph_git_behavior 'bare repo, commit 8 vs merge 1' bare commits/8 merge/1
graph_git_behavior 'bare repo, commit 8 vs merge 2' bare commits/8 merge/2
test_expect_success 'write graph in bare repo' '
- cd "$TRASH_DIRECTORY/bare" &&
- git commit-graph write &&
- test_path_is_file $baredir/info/commit-graph &&
- graph_read_expect "11" "generation_data extra_edges"
+ git -C bare commit-graph write &&
+ test_path_is_file bare/objects/info/commit-graph &&
+ graph_read_expect -C bare 11 "generation_data extra_edges"
'
graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1
graph_git_behavior 'bare repo with graph, commit 8 vs merge 2' bare commits/8 merge/2
test_expect_success 'perform fast-forward merge in full repo' '
- cd "$TRASH_DIRECTORY/full" &&
- git checkout -b merge-5-to-8 commits/5 &&
- git merge commits/8 &&
- git show-ref -s merge-5-to-8 >output &&
- git show-ref -s commits/8 >expect &&
+ git -C full checkout -b merge-5-to-8 commits/5 &&
+ git -C full merge commits/8 &&
+ git -C full show-ref -s merge-5-to-8 >output &&
+ git -C full show-ref -s commits/8 >expect &&
test_cmp expect output
'
test_expect_success 'check that gc computes commit-graph' '
- cd "$TRASH_DIRECTORY/full" &&
- git commit --allow-empty -m "blank" &&
- git commit-graph write --reachable &&
- cp $objdir/info/commit-graph commit-graph-before-gc &&
- git reset --hard HEAD~1 &&
- git config gc.writeCommitGraph true &&
- git gc &&
- cp $objdir/info/commit-graph commit-graph-after-gc &&
+ test_commit -C full --no-tag blank &&
+ git -C full commit-graph write --reachable &&
+ cp full/$objdir/info/commit-graph commit-graph-before-gc &&
+ git -C full reset --hard HEAD~1 &&
+ test_config -C full gc.writeCommitGraph true &&
+ git -C full gc &&
+ cp full/$objdir/info/commit-graph commit-graph-after-gc &&
! test_cmp_bin commit-graph-before-gc commit-graph-after-gc &&
- git commit-graph write --reachable &&
- test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph
+ git -C full commit-graph write --reachable &&
+ test_cmp_bin commit-graph-after-gc full/$objdir/info/commit-graph
'
test_expect_success 'replace-objects invalidates commit-graph' '
- cd "$TRASH_DIRECTORY" &&
test_when_finished rm -rf replace &&
git clone full replace &&
(
@@ -359,7 +328,6 @@ test_expect_success 'replace-objects invalidates commit-graph' '
'
test_expect_success 'commit grafts invalidate commit-graph' '
- cd "$TRASH_DIRECTORY" &&
test_when_finished rm -rf graft &&
git clone --template= full graft &&
(
@@ -384,7 +352,6 @@ test_expect_success 'commit grafts invalidate commit-graph' '
'
test_expect_success 'replace-objects invalidates commit-graph' '
- cd "$TRASH_DIRECTORY" &&
test_when_finished rm -rf shallow &&
git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow &&
(
@@ -427,24 +394,25 @@ test_expect_success 'warn on improper hash version' '
'
test_expect_success TIME_IS_64BIT,TIME_T_IS_64BIT 'lower layers have overflow chunk' '
- cd "$TRASH_DIRECTORY/full" &&
UNIX_EPOCH_ZERO="@0 +0000" &&
FUTURE_DATE="@4147483646 +0000" &&
- rm -f .git/objects/info/commit-graph &&
- test_commit --date "$FUTURE_DATE" future-1 &&
- test_commit --date "$UNIX_EPOCH_ZERO" old-1 &&
- git commit-graph write --reachable &&
- test_commit --date "$FUTURE_DATE" future-2 &&
- test_commit --date "$UNIX_EPOCH_ZERO" old-2 &&
- git commit-graph write --reachable --split=no-merge &&
- test_commit extra &&
- git commit-graph write --reachable --split=no-merge &&
- git commit-graph write --reachable &&
- graph_read_expect 16 "generation_data generation_data_overflow extra_edges" &&
- mv .git/objects/info/commit-graph commit-graph-upgraded &&
- git commit-graph write --reachable &&
- graph_read_expect 16 "generation_data generation_data_overflow extra_edges" &&
- test_cmp .git/objects/info/commit-graph commit-graph-upgraded
+ rm -f full/.git/objects/info/commit-graph &&
+ test_commit -C full --date "$FUTURE_DATE" future-1 &&
+ test_commit -C full --date "$UNIX_EPOCH_ZERO" old-1 &&
+ git -C full commit-graph write --reachable &&
+ test_commit -C full --date "$FUTURE_DATE" future-2 &&
+ test_commit -C full --date "$UNIX_EPOCH_ZERO" old-2 &&
+ git -C full commit-graph write --reachable --split=no-merge &&
+ test_commit -C full extra &&
+ git -C full commit-graph write --reachable --split=no-merge &&
+ git -C full commit-graph write --reachable &&
+ graph_read_expect -C full 16 \
+ "generation_data generation_data_overflow extra_edges" &&
+ mv full/.git/objects/info/commit-graph commit-graph-upgraded &&
+ git -C full commit-graph write --reachable &&
+ graph_read_expect -C full 16 \
+ "generation_data generation_data_overflow extra_edges" &&
+ test_cmp full/.git/objects/info/commit-graph commit-graph-upgraded
'
# the verify tests below expect the commit-graph to contain
@@ -454,10 +422,11 @@ test_expect_success TIME_IS_64BIT,TIME_T_IS_64BIT 'lower layers have overflow ch
# and the tests will likely break.
test_expect_success 'git commit-graph verify' '
- cd "$TRASH_DIRECTORY/full" &&
- git rev-parse commits/8 | git -c commitGraph.generationVersion=1 commit-graph write --stdin-commits &&
- git commit-graph verify >output &&
- graph_read_expect 9 extra_edges 1
+ git -C full rev-parse commits/8 >in &&
+ git -C full -c commitGraph.generationVersion=1 commit-graph write \
+ --stdin-commits <in &&
+ git -C full commit-graph verify >output &&
+ graph_read_expect -C full 9 extra_edges 1
'
NUM_COMMITS=9
@@ -495,25 +464,24 @@ GRAPH_BYTE_OCTOPUS=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4))
GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES))
corrupt_graph_setup() {
- cd "$TRASH_DIRECTORY/full" &&
- test_when_finished mv commit-graph-backup $objdir/info/commit-graph &&
- cp $objdir/info/commit-graph commit-graph-backup &&
- chmod u+w $objdir/info/commit-graph
+ test_when_finished mv commit-graph-backup full/$objdir/info/commit-graph &&
+ cp full/$objdir/info/commit-graph commit-graph-backup &&
+ chmod u+w full/$objdir/info/commit-graph
}
corrupt_graph_verify() {
grepstr=$1
- test_must_fail git commit-graph verify 2>test_err &&
+ test_must_fail git -C full commit-graph verify 2>test_err &&
grep -v "^+" test_err >err &&
test_i18ngrep "$grepstr" err &&
if test "$2" != "no-copy"
then
- cp $objdir/info/commit-graph commit-graph-pre-write-test
+ cp full/$objdir/info/commit-graph commit-graph-pre-write-test
fi &&
- git status --short &&
- GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE=true git commit-graph write &&
- chmod u+w $objdir/info/commit-graph &&
- git commit-graph verify
+ git -C full status --short &&
+ GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE=true git -C full commit-graph write &&
+ chmod u+w full/$objdir/info/commit-graph &&
+ git -C full commit-graph verify
}
# usage: corrupt_graph_and_verify <position> <data> <string> [<zero_pos>]
@@ -527,24 +495,24 @@ corrupt_graph_and_verify() {
data="${2:-\0}"
grepstr=$3
corrupt_graph_setup &&
- orig_size=$(wc -c < $objdir/info/commit-graph) &&
+ orig_size=$(wc -c <full/$objdir/info/commit-graph) &&
zero_pos=${4:-${orig_size}} &&
- printf "$data" | dd of="$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc &&
- dd of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" if=/dev/null &&
- test-tool genzeros $(($orig_size - $zero_pos)) >>"$objdir/info/commit-graph" &&
+ printf "$data" | dd of="full/$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc &&
+ dd of="full/$objdir/info/commit-graph" bs=1 seek="$zero_pos" if=/dev/null &&
+ test-tool genzeros $(($orig_size - $zero_pos)) >>"full/$objdir/info/commit-graph" &&
corrupt_graph_verify "$grepstr"
}
test_expect_success POSIXPERM,SANITY 'detect permission problem' '
corrupt_graph_setup &&
- chmod 000 $objdir/info/commit-graph &&
+ chmod 000 full/$objdir/info/commit-graph &&
corrupt_graph_verify "Could not open" "no-copy"
'
test_expect_success 'detect too small' '
corrupt_graph_setup &&
- echo "a small graph" >$objdir/info/commit-graph &&
+ echo "a small graph" >full/$objdir/info/commit-graph &&
corrupt_graph_verify "too small"
'
@@ -655,33 +623,40 @@ test_expect_success 'detect incorrect chunk count' '
'
test_expect_success 'git fsck (checks commit-graph when config set to true)' '
- cd "$TRASH_DIRECTORY/full" &&
- git fsck &&
+ git -C full fsck &&
corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
"incorrect checksum" &&
- cp commit-graph-pre-write-test $objdir/info/commit-graph &&
- test_must_fail git -c core.commitGraph=true fsck
+ cp commit-graph-pre-write-test full/$objdir/info/commit-graph &&
+ test_must_fail git -C full -c core.commitGraph=true fsck
'
test_expect_success 'git fsck (ignores commit-graph when config set to false)' '
- cd "$TRASH_DIRECTORY/full" &&
- git fsck &&
+ git -C full fsck &&
corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
"incorrect checksum" &&
- cp commit-graph-pre-write-test $objdir/info/commit-graph &&
- git -c core.commitGraph=false fsck
+ cp commit-graph-pre-write-test full/$objdir/info/commit-graph &&
+ git -C full -c core.commitGraph=false fsck
'
test_expect_success 'git fsck (checks commit-graph when config unset)' '
- cd "$TRASH_DIRECTORY/full" &&
- test_when_finished "git config core.commitGraph true" &&
+ test_when_finished "git -C full config core.commitGraph true" &&
- git fsck &&
+ git -C full fsck &&
corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
"incorrect checksum" &&
- test_unconfig core.commitGraph &&
- cp commit-graph-pre-write-test $objdir/info/commit-graph &&
- test_must_fail git fsck
+ test_unconfig -C full core.commitGraph &&
+ cp commit-graph-pre-write-test full/$objdir/info/commit-graph &&
+ test_must_fail git -C full fsck
+'
+
+test_expect_success 'git fsck shows commit-graph output with --progress' '
+ git -C "$TRASH_DIRECTORY/full" fsck --progress 2>err &&
+ grep "Verifying commits in commit graph" err
+'
+
+test_expect_success 'git fsck suppresses commit-graph output with --no-progress' '
+ git -C "$TRASH_DIRECTORY/full" fsck --no-progress 2>err &&
+ ! grep "Verifying commits in commit graph" err
'
test_expect_success 'setup non-the_repository tests' '
@@ -782,32 +757,33 @@ test_expect_success 'corrupt commit-graph write (missing tree)' '
#
test_expect_success 'set up and verify repo with generation data overflow chunk' '
- objdir=".git/objects" &&
UNIX_EPOCH_ZERO="@0 +0000" &&
FUTURE_DATE="@2147483646 +0000" &&
- cd "$TRASH_DIRECTORY" &&
- mkdir repo &&
- cd repo &&
- git init &&
- test_commit --date "$UNIX_EPOCH_ZERO" 1 &&
- test_commit 2 &&
- test_commit --date "$UNIX_EPOCH_ZERO" 3 &&
- git commit-graph write --reachable &&
- graph_read_expect 3 generation_data &&
- test_commit --date "$FUTURE_DATE" 4 &&
- test_commit 5 &&
- test_commit --date "$UNIX_EPOCH_ZERO" 6 &&
- git branch left &&
- git reset --hard 3 &&
- test_commit 7 &&
- test_commit --date "$FUTURE_DATE" 8 &&
- test_commit 9 &&
- git branch right &&
- git reset --hard 3 &&
- test_merge M left right &&
- git commit-graph write --reachable &&
- graph_read_expect 10 "generation_data generation_data_overflow" &&
- git commit-graph verify
+
+ git init repo &&
+ (
+ cd repo &&
+
+ test_commit --date "$UNIX_EPOCH_ZERO" 1 &&
+ test_commit 2 &&
+ test_commit --date "$UNIX_EPOCH_ZERO" 3 &&
+ git commit-graph write --reachable &&
+ graph_read_expect 3 generation_data &&
+ test_commit --date "$FUTURE_DATE" 4 &&
+ test_commit 5 &&
+ test_commit --date "$UNIX_EPOCH_ZERO" 6 &&
+ git branch left &&
+ git reset --hard 3 &&
+ test_commit 7 &&
+ test_commit --date "$FUTURE_DATE" 8 &&
+ test_commit 9 &&
+ git branch right &&
+ git reset --hard 3 &&
+ test_merge M left right &&
+ git commit-graph write --reachable &&
+ graph_read_expect 10 "generation_data generation_data_overflow" &&
+ git commit-graph verify
+ )
'
graph_git_behavior 'generation data overflow chunk repo' repo left right
diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh
index 0883c7c6bd..1bcc02004d 100755
--- a/t/t5319-multi-pack-index.sh
+++ b/t/t5319-multi-pack-index.sh
@@ -485,6 +485,18 @@ test_expect_success 'git-fsck incorrect offset' '
git -c core.multiPackIndex=false fsck
'
+test_expect_success 'git fsck shows MIDX output with --progress' '
+ git fsck --progress 2>err &&
+ grep "Verifying OID order in multi-pack-index" err &&
+ grep "Verifying object offsets" err
+'
+
+test_expect_success 'git fsck suppresses MIDX output with --no-progress' '
+ git fsck --no-progress 2>err &&
+ ! grep "Verifying OID order in multi-pack-index" err &&
+ ! grep "Verifying object offsets" err
+'
+
test_expect_success 'corrupt MIDX is not reused' '
corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
"incorrect object offset" &&
diff --git a/t/t5324-split-commit-graph.sh b/t/t5324-split-commit-graph.sh
index 669ddc645f..36c4141e67 100755
--- a/t/t5324-split-commit-graph.sh
+++ b/t/t5324-split-commit-graph.sh
@@ -351,7 +351,8 @@ test_expect_success 'add octopus merge' '
git branch merge/octopus &&
git commit-graph write --reachable --split &&
git commit-graph verify --progress 2>err &&
- test_line_count = 3 err &&
+ test_line_count = 1 err &&
+ grep "Verifying commits in commit graph: 100% (18/18)" err &&
test_i18ngrep ! warning err &&
test_line_count = 3 $graphdir/commit-graph-chain
'
diff --git a/t/t5326-multi-pack-bitmaps.sh b/t/t5326-multi-pack-bitmaps.sh
index f771c442d4..70d1b58709 100755
--- a/t/t5326-multi-pack-bitmaps.sh
+++ b/t/t5326-multi-pack-bitmaps.sh
@@ -478,4 +478,39 @@ test_expect_success 'git fsck correctly identifies good and bad bitmaps' '
grep "bitmap file '\''$packbitmap'\'' has invalid checksum" err
'
+test_expect_success 'corrupt MIDX with bitmap causes fallback' '
+ git init corrupt-midx-bitmap &&
+ (
+ cd corrupt-midx-bitmap &&
+
+ test_commit first &&
+ git repack -d &&
+ test_commit second &&
+ git repack -d &&
+
+ git multi-pack-index write --bitmap &&
+ checksum=$(midx_checksum $objdir) &&
+ for f in $midx $midx-$checksum.bitmap
+ do
+ mv $f $f.bak || return 1
+ done &&
+
+ # pack everything together, invalidating the MIDX
+ git repack -ad &&
+ # then restore the now-stale MIDX
+ for f in $midx $midx-$checksum.bitmap
+ do
+ mv $f.bak $f || return 1
+ done &&
+
+ git rev-list --count --objects --use-bitmap-index HEAD >out 2>err &&
+ # should attempt opening the broken pack twice (once
+ # from the attempt to load it via the stale bitmap, and
+ # again when attempting to load it from the stale MIDX)
+ # before falling back to the non-MIDX case
+ test 2 -eq $(grep -c "could not open pack" err) &&
+ test 6 -eq $(cat out)
+ )
+'
+
test_done
diff --git a/t/t5328-commit-graph-64bit-time.sh b/t/t5328-commit-graph-64bit-time.sh
index 57e4d9c699..e9c521c061 100755
--- a/t/t5328-commit-graph-64bit-time.sh
+++ b/t/t5328-commit-graph-64bit-time.sh
@@ -37,39 +37,39 @@ test_expect_success 'lower layers have overflow chunk' '
graph_git_behavior 'overflow' '' HEAD~2 HEAD
test_expect_success 'set up and verify repo with generation data overflow chunk' '
- mkdir repo &&
- cd repo &&
- git init &&
- test_commit --date "$UNIX_EPOCH_ZERO" 1 &&
- test_commit 2 &&
- test_commit --date "$UNIX_EPOCH_ZERO" 3 &&
- git commit-graph write --reachable &&
- graph_read_expect 3 generation_data &&
- test_commit --date "$FUTURE_DATE" 4 &&
- test_commit 5 &&
- test_commit --date "$UNIX_EPOCH_ZERO" 6 &&
- git branch left &&
- git reset --hard 3 &&
- test_commit 7 &&
- test_commit --date "$FUTURE_DATE" 8 &&
- test_commit 9 &&
- git branch right &&
- git reset --hard 3 &&
- test_merge M left right &&
- git commit-graph write --reachable &&
- graph_read_expect 10 "generation_data generation_data_overflow" &&
- git commit-graph verify
+ git init repo &&
+ (
+ cd repo &&
+ test_commit --date "$UNIX_EPOCH_ZERO" 1 &&
+ test_commit 2 &&
+ test_commit --date "$UNIX_EPOCH_ZERO" 3 &&
+ git commit-graph write --reachable &&
+ graph_read_expect 3 generation_data &&
+ test_commit --date "$FUTURE_DATE" 4 &&
+ test_commit 5 &&
+ test_commit --date "$UNIX_EPOCH_ZERO" 6 &&
+ git branch left &&
+ git reset --hard 3 &&
+ test_commit 7 &&
+ test_commit --date "$FUTURE_DATE" 8 &&
+ test_commit 9 &&
+ git branch right &&
+ git reset --hard 3 &&
+ test_merge M left right &&
+ git commit-graph write --reachable &&
+ graph_read_expect 10 "generation_data generation_data_overflow" &&
+ git commit-graph verify
+ )
'
graph_git_behavior 'overflow 2' repo left right
test_expect_success 'single commit with generation data exceeding UINT32_MAX' '
git init repo-uint32-max &&
- cd repo-uint32-max &&
- test_commit --date "@4294967297 +0000" 1 &&
- git commit-graph write --reachable &&
- graph_read_expect 1 "generation_data" &&
- git commit-graph verify
+ test_commit -C repo-uint32-max --date "@4294967297 +0000" 1 &&
+ git -C repo-uint32-max commit-graph write --reachable &&
+ graph_read_expect -C repo-uint32-max 1 "generation_data" &&
+ git -C repo-uint32-max commit-graph verify
'
test_done
diff --git a/t/t5329-pack-objects-cruft.sh b/t/t5329-pack-objects-cruft.sh
index 303f7a5d84..45667d4999 100755
--- a/t/t5329-pack-objects-cruft.sh
+++ b/t/t5329-pack-objects-cruft.sh
@@ -739,4 +739,175 @@ test_expect_success 'cruft objects are freshend via loose' '
)
'
+test_expect_success 'gc.recentObjectsHook' '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+
+ # Create a handful of objects.
+ #
+ # - one reachable commit, "base", designated for the reachable
+ # pack
+ # - one unreachable commit, "cruft.discard", which is marked
+ # for deletion
+ # - one unreachable commit, "cruft.old", which would be marked
+ # for deletion, but is rescued as an extra cruft tip
+ # - one unreachable commit, "cruft.new", which is not marked
+ # for deletion
+ test_commit base &&
+ git branch -M main &&
+
+ git checkout --orphan discard &&
+ git rm -fr . &&
+ test_commit --no-tag cruft.discard &&
+
+ git checkout --orphan old &&
+ git rm -fr . &&
+ test_commit --no-tag cruft.old &&
+ cruft_old="$(git rev-parse HEAD)" &&
+
+ git checkout --orphan new &&
+ git rm -fr . &&
+ test_commit --no-tag cruft.new &&
+ cruft_new="$(git rev-parse HEAD)" &&
+
+ git checkout main &&
+ git branch -D discard old new &&
+ git reflog expire --all --expire=all &&
+
+ # mark cruft.old with an mtime that is many minutes
+ # older than the expiration period, and mark cruft.new
+ # with an mtime that is in the future (and thus not
+ # eligible for pruning).
+ test-tool chmtime -2000 "$objdir/$(test_oid_to_path $cruft_old)" &&
+ test-tool chmtime +1000 "$objdir/$(test_oid_to_path $cruft_new)" &&
+
+ # Write the list of cruft objects we expect to
+ # accumulate, which is comprised of everything reachable
+ # from cruft.old and cruft.new, but not cruft.discard.
+ git rev-list --objects --no-object-names \
+ $cruft_old $cruft_new >cruft.raw &&
+ sort cruft.raw >cruft.expect &&
+
+ # Write the script to list extra tips, which are limited
+ # to cruft.old, in this case.
+ write_script extra-tips <<-EOF &&
+ echo $cruft_old
+ EOF
+ git config gc.recentObjectsHook ./extra-tips &&
+
+ git repack --cruft --cruft-expiration=now -d &&
+
+ mtimes="$(ls .git/objects/pack/pack-*.mtimes)" &&
+ git show-index <${mtimes%.mtimes}.idx >cruft &&
+ cut -d" " -f2 cruft | sort >cruft.actual &&
+ test_cmp cruft.expect cruft.actual &&
+
+ # Ensure that the "old" objects are removed after
+ # dropping the gc.recentObjectsHook hook.
+ git config --unset gc.recentObjectsHook &&
+ git repack --cruft --cruft-expiration=now -d &&
+
+ mtimes="$(ls .git/objects/pack/pack-*.mtimes)" &&
+ git show-index <${mtimes%.mtimes}.idx >cruft &&
+ cut -d" " -f2 cruft | sort >cruft.actual &&
+
+ git rev-list --objects --no-object-names $cruft_new >cruft.raw &&
+ cp cruft.expect cruft.old &&
+ sort cruft.raw >cruft.expect &&
+ test_cmp cruft.expect cruft.actual &&
+
+ # ensure objects which are no longer in the cruft pack were
+ # removed from the repository
+ for object in $(comm -13 cruft.expect cruft.old)
+ do
+ test_must_fail git cat-file -t $object || return 1
+ done
+ )
+'
+
+test_expect_success 'multi-valued gc.recentObjectsHook' '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+
+ test_commit base &&
+ git branch -M main &&
+
+ git checkout --orphan cruft.a &&
+ git rm -fr . &&
+ test_commit --no-tag cruft.a &&
+ cruft_a="$(git rev-parse HEAD)" &&
+
+ git checkout --orphan cruft.b &&
+ git rm -fr . &&
+ test_commit --no-tag cruft.b &&
+ cruft_b="$(git rev-parse HEAD)" &&
+
+ git checkout main &&
+ git branch -D cruft.a cruft.b &&
+ git reflog expire --all --expire=all &&
+
+ echo "echo $cruft_a" | write_script extra-tips.a &&
+ echo "echo $cruft_b" | write_script extra-tips.b &&
+ echo "false" | write_script extra-tips.c &&
+
+ git rev-list --objects --no-object-names $cruft_a $cruft_b \
+ >cruft.raw &&
+ sort cruft.raw >cruft.expect &&
+
+ # ensure that each extra cruft tip is saved by its
+ # respective hook
+ git config --add gc.recentObjectsHook ./extra-tips.a &&
+ git config --add gc.recentObjectsHook ./extra-tips.b &&
+ git repack --cruft --cruft-expiration=now -d &&
+
+ mtimes="$(ls .git/objects/pack/pack-*.mtimes)" &&
+ git show-index <${mtimes%.mtimes}.idx >cruft &&
+ cut -d" " -f2 cruft | sort >cruft.actual &&
+ test_cmp cruft.expect cruft.actual &&
+
+ # ensure that a dirty exit halts cruft pack generation
+ git config --add gc.recentObjectsHook ./extra-tips.c &&
+ test_must_fail git repack --cruft --cruft-expiration=now -d 2>err &&
+ grep "unable to enumerate additional recent objects" err &&
+
+ # and that the existing cruft pack is left alone
+ test_path_is_file "$mtimes"
+ )
+'
+
+test_expect_success 'additional cruft blobs via gc.recentObjectsHook' '
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
+ cd repo &&
+
+ test_commit base &&
+
+ blob=$(echo "unreachable" | git hash-object -w --stdin) &&
+
+ # mark the unreachable blob we wrote above as having
+ # aged out of the retention period
+ test-tool chmtime -2000 "$objdir/$(test_oid_to_path $blob)" &&
+
+ # Write the script to list extra tips, which is just the
+ # extra blob as above.
+ write_script extra-tips <<-EOF &&
+ echo $blob
+ EOF
+ git config gc.recentObjectsHook ./extra-tips &&
+
+ git repack --cruft --cruft-expiration=now -d &&
+
+ mtimes="$(ls .git/objects/pack/pack-*.mtimes)" &&
+ git show-index <${mtimes%.mtimes}.idx >cruft &&
+ cut -d" " -f2 cruft >actual &&
+ echo $blob >expect &&
+ test_cmp expect actual
+ )
+'
+
test_done
diff --git a/t/t5351-unpack-large-objects.sh b/t/t5351-unpack-large-objects.sh
index 8c8af99b84..43cbcd5d49 100755
--- a/t/t5351-unpack-large-objects.sh
+++ b/t/t5351-unpack-large-objects.sh
@@ -55,7 +55,7 @@ check_fsync_events () {
cat >expect &&
sed -n \
- -e '/^{"event":"data",.*"category":"fsync",/ {
+ -e '/^{"event":"counter",.*"category":"fsync",/ {
s/.*"category":"fsync",//;
s/}$//;
p;
@@ -78,8 +78,8 @@ test_expect_success 'unpack big object in stream (core.fsyncmethod=batch)' '
flush_count=1
fi &&
check_fsync_events trace2.txt <<-EOF &&
- "key":"fsync/writeout-only","value":"6"
- "key":"fsync/hardware-flush","value":"$flush_count"
+ "name":"writeout-only","count":6
+ "name":"hardware-flush","count":$flush_count
EOF
test_dir_is_empty dest.git/objects/pack &&
diff --git a/t/t5404-tracking-branches.sh b/t/t5404-tracking-branches.sh
index cc07889667..51737eeafe 100755
--- a/t/t5404-tracking-branches.sh
+++ b/t/t5404-tracking-branches.sh
@@ -5,6 +5,7 @@ test_description='tracking branch update checks for git push'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 19ebefa5ac..87163d7745 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -120,6 +120,17 @@ test_expect_success setup '
'
+for cmd in push fetch
+do
+ for opt in ipv4 ipv6
+ do
+ test_expect_success "reject 'git $cmd --no-$opt'" '
+ test_must_fail git $cmd --no-$opt 2>err &&
+ grep "unknown option .no-$opt" err
+ '
+ done
+done
+
test_expect_success 'fetch without wildcard' '
mk_empty testrepo &&
(
diff --git a/t/t5517-push-mirror.sh b/t/t5517-push-mirror.sh
index a448e169bd..6d4944a728 100755
--- a/t/t5517-push-mirror.sh
+++ b/t/t5517-push-mirror.sh
@@ -5,6 +5,7 @@ test_description='pushing to a mirror repository'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
D=$(pwd)
diff --git a/t/t5525-fetch-tagopt.sh b/t/t5525-fetch-tagopt.sh
index 45815f7378..3a28f1ded5 100755
--- a/t/t5525-fetch-tagopt.sh
+++ b/t/t5525-fetch-tagopt.sh
@@ -2,6 +2,7 @@
test_description='tagopt variable affects "git fetch" and is overridden by commandline.'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
setup_clone () {
diff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh
index 27f9f77638..5890319b97 100755
--- a/t/t5606-clone-options.sh
+++ b/t/t5606-clone-options.sh
@@ -120,6 +120,16 @@ test_expect_success 'prefers -c config over --template config' '
'
+test_expect_failure 'prefers --template config even for core.bare' '
+
+ template="$TRASH_DIRECTORY/template-with-bare-config" &&
+ mkdir "$template" &&
+ git config --file "$template/config" core.bare true &&
+ git clone "--template=$template" parent clone-bare-config &&
+ test "$(git -C clone-bare-config config --local core.bare)" = "true" &&
+ test_path_is_file clone-bare-config/HEAD
+'
+
test_expect_success 'prefers config "clone.defaultRemoteName" over default' '
test_config_global clone.defaultRemoteName from_config &&
diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh
index f519d2a87a..8759fc2853 100755
--- a/t/t5616-partial-clone.sh
+++ b/t/t5616-partial-clone.sh
@@ -257,8 +257,8 @@ test_expect_success 'partial clone with transfer.fsckobjects=1 works with submod
test_commit -C submodule mycommit &&
test_create_repo src_with_sub &&
- test_config -C src_with_sub uploadpack.allowfilter 1 &&
- test_config -C src_with_sub uploadpack.allowanysha1inwant 1 &&
+ git -C src_with_sub config uploadpack.allowfilter 1 &&
+ git -C src_with_sub config uploadpack.allowanysha1inwant 1 &&
test_config_global protocol.file.allow always &&
@@ -270,6 +270,12 @@ test_expect_success 'partial clone with transfer.fsckobjects=1 works with submod
test_when_finished rm -rf dst
'
+test_expect_success 'lazily fetched .gitmodules works' '
+ git clone --filter="blob:none" --no-checkout "file://$(pwd)/src_with_sub" dst &&
+ git -C dst fetch &&
+ test_when_finished rm -rf dst
+'
+
test_expect_success 'partial clone with transfer.fsckobjects=1 uses index-pack --fsck-objects' '
git init src &&
test_commit -C src x &&
diff --git a/t/t6017-rev-list-stdin.sh b/t/t6017-rev-list-stdin.sh
index 05162512a0..a57f1ae2ba 100755
--- a/t/t6017-rev-list-stdin.sh
+++ b/t/t6017-rev-list-stdin.sh
@@ -48,7 +48,9 @@ test_expect_success setup '
git add file-$i &&
test_tick &&
git commit -m side-$i || exit
- done
+ done &&
+
+ git update-ref refs/heads/-dashed-branch HEAD
)
'
@@ -60,6 +62,12 @@ check side-1 ^side-7 -- file-2
check side-3 ^side-4 -- file-3
check side-3 ^side-2
check side-3 ^side-2 -- file-1
+check --all
+check --all --not --branches
+check --glob=refs/heads
+check --glob=refs/heads --
+check --glob=refs/heads -- file-1
+check --end-of-options -dashed-branch
test_expect_success 'not only --stdin' '
cat >expect <<-EOF &&
@@ -78,4 +86,45 @@ test_expect_success 'not only --stdin' '
test_cmp expect actual
'
+test_expect_success 'pseudo-opt with missing value' '
+ cat >input <<-EOF &&
+ --glob
+ refs/heads
+ EOF
+
+ cat >expect <<-EOF &&
+ fatal: Option ${SQ}--glob${SQ} requires a value
+ EOF
+
+ test_must_fail git rev-list --stdin <input 2>error &&
+ test_cmp expect error
+'
+
+test_expect_success 'pseudo-opt with invalid value' '
+ cat >input <<-EOF &&
+ --no-walk=garbage
+ EOF
+
+ cat >expect <<-EOF &&
+ error: invalid argument to --no-walk
+ fatal: invalid option ${SQ}--no-walk=garbage${SQ} in --stdin mode
+ EOF
+
+ test_must_fail git rev-list --stdin <input 2>error &&
+ test_cmp expect error
+'
+
+test_expect_success 'unknown option without --end-of-options' '
+ cat >input <<-EOF &&
+ -dashed-branch
+ EOF
+
+ cat >expect <<-EOF &&
+ fatal: invalid option ${SQ}-dashed-branch${SQ} in --stdin mode
+ EOF
+
+ test_must_fail git rev-list --stdin <input 2>error &&
+ test_cmp expect error
+'
+
test_done
diff --git a/t/t6020-bundle-misc.sh b/t/t6020-bundle-misc.sh
index dface8bcfe..3e6bcbf30c 100755
--- a/t/t6020-bundle-misc.sh
+++ b/t/t6020-bundle-misc.sh
@@ -619,6 +619,12 @@ test_expect_success TTY 'create --quiet disables all bundle progress' '
test_must_be_empty err
'
+test_expect_success 'bundle progress with --no-quiet' '
+ GIT_PROGRESS_DELAY=0 \
+ git bundle create --no-quiet out.bundle --all 2>err &&
+ grep "%" err
+'
+
test_expect_success 'read bundle over stdin' '
git bundle create some.bundle HEAD &&
diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh
index a313849406..7ddbd96e58 100755
--- a/t/t6040-tracking-info.sh
+++ b/t/t6040-tracking-info.sh
@@ -5,6 +5,7 @@ test_description='remote tracking stats'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
advance () {
diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh
index 2500acc2ef..c9925edf20 100755
--- a/t/t6050-replace.sh
+++ b/t/t6050-replace.sh
@@ -62,59 +62,59 @@ HASH6=
HASH7=
test_expect_success 'set up buggy branch' '
- echo "line 1" >>hello &&
- echo "line 2" >>hello &&
- echo "line 3" >>hello &&
- echo "line 4" >>hello &&
- add_and_commit_file hello "4 lines" &&
- HASH1=$(git rev-parse --verify HEAD) &&
- echo "line BUG" >>hello &&
- echo "line 6" >>hello &&
- echo "line 7" >>hello &&
- echo "line 8" >>hello &&
- add_and_commit_file hello "4 more lines with a BUG" &&
- HASH2=$(git rev-parse --verify HEAD) &&
- echo "line 9" >>hello &&
- echo "line 10" >>hello &&
- add_and_commit_file hello "2 more lines" &&
- HASH3=$(git rev-parse --verify HEAD) &&
- echo "line 11" >>hello &&
- add_and_commit_file hello "1 more line" &&
- HASH4=$(git rev-parse --verify HEAD) &&
- sed -e "s/BUG/5/" hello >hello.new &&
- mv hello.new hello &&
- add_and_commit_file hello "BUG fixed" &&
- HASH5=$(git rev-parse --verify HEAD) &&
- echo "line 12" >>hello &&
- echo "line 13" >>hello &&
- add_and_commit_file hello "2 more lines" &&
- HASH6=$(git rev-parse --verify HEAD) &&
- echo "line 14" >>hello &&
- echo "line 15" >>hello &&
- echo "line 16" >>hello &&
- add_and_commit_file hello "again 3 more lines" &&
- HASH7=$(git rev-parse --verify HEAD)
+ echo "line 1" >>hello &&
+ echo "line 2" >>hello &&
+ echo "line 3" >>hello &&
+ echo "line 4" >>hello &&
+ add_and_commit_file hello "4 lines" &&
+ HASH1=$(git rev-parse --verify HEAD) &&
+ echo "line BUG" >>hello &&
+ echo "line 6" >>hello &&
+ echo "line 7" >>hello &&
+ echo "line 8" >>hello &&
+ add_and_commit_file hello "4 more lines with a BUG" &&
+ HASH2=$(git rev-parse --verify HEAD) &&
+ echo "line 9" >>hello &&
+ echo "line 10" >>hello &&
+ add_and_commit_file hello "2 more lines" &&
+ HASH3=$(git rev-parse --verify HEAD) &&
+ echo "line 11" >>hello &&
+ add_and_commit_file hello "1 more line" &&
+ HASH4=$(git rev-parse --verify HEAD) &&
+ sed -e "s/BUG/5/" hello >hello.new &&
+ mv hello.new hello &&
+ add_and_commit_file hello "BUG fixed" &&
+ HASH5=$(git rev-parse --verify HEAD) &&
+ echo "line 12" >>hello &&
+ echo "line 13" >>hello &&
+ add_and_commit_file hello "2 more lines" &&
+ HASH6=$(git rev-parse --verify HEAD) &&
+ echo "line 14" >>hello &&
+ echo "line 15" >>hello &&
+ echo "line 16" >>hello &&
+ add_and_commit_file hello "again 3 more lines" &&
+ HASH7=$(git rev-parse --verify HEAD)
'
test_expect_success 'replace the author' '
- git cat-file commit $HASH2 | grep "author A U Thor" &&
- R=$(git cat-file commit $HASH2 | sed -e "s/A U/O/" | git hash-object -t commit --stdin -w) &&
- git cat-file commit $R | grep "author O Thor" &&
- git update-ref refs/replace/$HASH2 $R &&
- git show HEAD~5 | grep "O Thor" &&
- git show $HASH2 | grep "O Thor"
+ git cat-file commit $HASH2 | grep "author A U Thor" &&
+ R=$(git cat-file commit $HASH2 | sed -e "s/A U/O/" | git hash-object -t commit --stdin -w) &&
+ git cat-file commit $R | grep "author O Thor" &&
+ git update-ref refs/replace/$HASH2 $R &&
+ git show HEAD~5 | grep "O Thor" &&
+ git show $HASH2 | grep "O Thor"
'
test_expect_success 'test --no-replace-objects option' '
- git cat-file commit $HASH2 | grep "author O Thor" &&
- git --no-replace-objects cat-file commit $HASH2 | grep "author A U Thor" &&
- git show $HASH2 | grep "O Thor" &&
- git --no-replace-objects show $HASH2 | grep "A U Thor"
+ git cat-file commit $HASH2 | grep "author O Thor" &&
+ git --no-replace-objects cat-file commit $HASH2 | grep "author A U Thor" &&
+ git show $HASH2 | grep "O Thor" &&
+ git --no-replace-objects show $HASH2 | grep "A U Thor"
'
test_expect_success 'test GIT_NO_REPLACE_OBJECTS env variable' '
- GIT_NO_REPLACE_OBJECTS=1 git cat-file commit $HASH2 | grep "author A U Thor" &&
- GIT_NO_REPLACE_OBJECTS=1 git show $HASH2 | grep "A U Thor"
+ GIT_NO_REPLACE_OBJECTS=1 git cat-file commit $HASH2 | grep "author A U Thor" &&
+ GIT_NO_REPLACE_OBJECTS=1 git show $HASH2 | grep "A U Thor"
'
test_expect_success 'test core.usereplacerefs config option' '
@@ -132,64 +132,64 @@ tagger T A Gger <> 0 +0000
EOF
test_expect_success 'tag replaced commit' '
- git update-ref refs/tags/mytag $(git mktag <tag.sig)
+ git update-ref refs/tags/mytag $(git mktag <tag.sig)
'
test_expect_success '"git fsck" works' '
- git fsck main >fsck_main.out &&
- test_i18ngrep "dangling commit $R" fsck_main.out &&
- test_i18ngrep "dangling tag $(git show-ref -s refs/tags/mytag)" fsck_main.out &&
- test -z "$(git fsck)"
+ git fsck main >fsck_main.out &&
+ test_i18ngrep "dangling commit $R" fsck_main.out &&
+ test_i18ngrep "dangling tag $(git show-ref -s refs/tags/mytag)" fsck_main.out &&
+ test -z "$(git fsck)"
'
test_expect_success 'repack, clone and fetch work' '
- git repack -a -d &&
- git clone --no-hardlinks . clone_dir &&
- (
- cd clone_dir &&
- git show HEAD~5 | grep "A U Thor" &&
- git show $HASH2 | grep "A U Thor" &&
- git cat-file commit $R &&
- git repack -a -d &&
- test_must_fail git cat-file commit $R &&
- git fetch ../ "refs/replace/*:refs/replace/*" &&
- git show HEAD~5 | grep "O Thor" &&
- git show $HASH2 | grep "O Thor" &&
- git cat-file commit $R
- )
+ git repack -a -d &&
+ git clone --no-hardlinks . clone_dir &&
+ (
+ cd clone_dir &&
+ git show HEAD~5 | grep "A U Thor" &&
+ git show $HASH2 | grep "A U Thor" &&
+ git cat-file commit $R &&
+ git repack -a -d &&
+ test_must_fail git cat-file commit $R &&
+ git fetch ../ "refs/replace/*:refs/replace/*" &&
+ git show HEAD~5 | grep "O Thor" &&
+ git show $HASH2 | grep "O Thor" &&
+ git cat-file commit $R
+ )
'
test_expect_success '"git replace" listing and deleting' '
- test "$HASH2" = "$(git replace -l)" &&
- test "$HASH2" = "$(git replace)" &&
- aa=${HASH2%??????????????????????????????????????} &&
- test "$HASH2" = "$(git replace --list "$aa*")" &&
- test_must_fail git replace -d $R &&
- test_must_fail git replace --delete &&
- test_must_fail git replace -l -d $HASH2 &&
- git replace -d $HASH2 &&
- git show $HASH2 | grep "A U Thor" &&
- test -z "$(git replace -l)"
+ test "$HASH2" = "$(git replace -l)" &&
+ test "$HASH2" = "$(git replace)" &&
+ aa=${HASH2%??????????????????????????????????????} &&
+ test "$HASH2" = "$(git replace --list "$aa*")" &&
+ test_must_fail git replace -d $R &&
+ test_must_fail git replace --delete &&
+ test_must_fail git replace -l -d $HASH2 &&
+ git replace -d $HASH2 &&
+ git show $HASH2 | grep "A U Thor" &&
+ test -z "$(git replace -l)"
'
test_expect_success '"git replace" replacing' '
- git replace $HASH2 $R &&
- git show $HASH2 | grep "O Thor" &&
- test_must_fail git replace $HASH2 $R &&
- git replace -f $HASH2 $R &&
- test_must_fail git replace -f &&
- test "$HASH2" = "$(git replace)"
+ git replace $HASH2 $R &&
+ git show $HASH2 | grep "O Thor" &&
+ test_must_fail git replace $HASH2 $R &&
+ git replace -f $HASH2 $R &&
+ test_must_fail git replace -f &&
+ test "$HASH2" = "$(git replace)"
'
test_expect_success '"git replace" resolves sha1' '
- SHORTHASH2=$(git rev-parse --short=8 $HASH2) &&
- git replace -d $SHORTHASH2 &&
- git replace $SHORTHASH2 $R &&
- git show $HASH2 | grep "O Thor" &&
- test_must_fail git replace $HASH2 $R &&
- git replace -f $HASH2 $R &&
- test_must_fail git replace --force &&
- test "$HASH2" = "$(git replace)"
+ SHORTHASH2=$(git rev-parse --short=8 $HASH2) &&
+ git replace -d $SHORTHASH2 &&
+ git replace $SHORTHASH2 $R &&
+ git show $HASH2 | grep "O Thor" &&
+ test_must_fail git replace $HASH2 $R &&
+ git replace -f $HASH2 $R &&
+ test_must_fail git replace --force &&
+ test "$HASH2" = "$(git replace)"
'
# This creates a side branch where the bug in H2
@@ -207,79 +207,79 @@ test_expect_success '"git replace" resolves sha1' '
# Then we replace H6 with P6.
#
test_expect_success 'create parallel branch without the bug' '
- git replace -d $HASH2 &&
- git show $HASH2 | grep "A U Thor" &&
- git checkout $HASH1 &&
- git cherry-pick $HASH2 &&
- git show $HASH5 | git apply &&
- git commit --amend -m "hello: 4 more lines WITHOUT the bug" hello &&
- PARA2=$(git rev-parse --verify HEAD) &&
- git cherry-pick $HASH3 &&
- PARA3=$(git rev-parse --verify HEAD) &&
- git cherry-pick $HASH4 &&
- PARA4=$(git rev-parse --verify HEAD) &&
- git cherry-pick $HASH6 &&
- PARA6=$(git rev-parse --verify HEAD) &&
- git replace $HASH6 $PARA6 &&
- git checkout main &&
- cur=$(git rev-parse --verify HEAD) &&
- test "$cur" = "$HASH7" &&
- git log --pretty=oneline | grep $PARA2 &&
- git remote add cloned ./clone_dir
+ git replace -d $HASH2 &&
+ git show $HASH2 | grep "A U Thor" &&
+ git checkout $HASH1 &&
+ git cherry-pick $HASH2 &&
+ git show $HASH5 | git apply &&
+ git commit --amend -m "hello: 4 more lines WITHOUT the bug" hello &&
+ PARA2=$(git rev-parse --verify HEAD) &&
+ git cherry-pick $HASH3 &&
+ PARA3=$(git rev-parse --verify HEAD) &&
+ git cherry-pick $HASH4 &&
+ PARA4=$(git rev-parse --verify HEAD) &&
+ git cherry-pick $HASH6 &&
+ PARA6=$(git rev-parse --verify HEAD) &&
+ git replace $HASH6 $PARA6 &&
+ git checkout main &&
+ cur=$(git rev-parse --verify HEAD) &&
+ test "$cur" = "$HASH7" &&
+ git log --pretty=oneline | grep $PARA2 &&
+ git remote add cloned ./clone_dir
'
test_expect_success 'push to cloned repo' '
- git push cloned $HASH6^:refs/heads/parallel &&
- (
- cd clone_dir &&
- git checkout parallel &&
- git log --pretty=oneline | grep $PARA2
- )
+ git push cloned $HASH6^:refs/heads/parallel &&
+ (
+ cd clone_dir &&
+ git checkout parallel &&
+ git log --pretty=oneline | grep $PARA2
+ )
'
test_expect_success 'push branch with replacement' '
- git cat-file commit $PARA3 | grep "author A U Thor" &&
- S=$(git cat-file commit $PARA3 | sed -e "s/A U/O/" | git hash-object -t commit --stdin -w) &&
- git cat-file commit $S | grep "author O Thor" &&
- git replace $PARA3 $S &&
- git show $HASH6~2 | grep "O Thor" &&
- git show $PARA3 | grep "O Thor" &&
- git push cloned $HASH6^:refs/heads/parallel2 &&
- (
- cd clone_dir &&
- git checkout parallel2 &&
- git log --pretty=oneline | grep $PARA3 &&
- git show $PARA3 | grep "A U Thor"
- )
+ git cat-file commit $PARA3 | grep "author A U Thor" &&
+ S=$(git cat-file commit $PARA3 | sed -e "s/A U/O/" | git hash-object -t commit --stdin -w) &&
+ git cat-file commit $S | grep "author O Thor" &&
+ git replace $PARA3 $S &&
+ git show $HASH6~2 | grep "O Thor" &&
+ git show $PARA3 | grep "O Thor" &&
+ git push cloned $HASH6^:refs/heads/parallel2 &&
+ (
+ cd clone_dir &&
+ git checkout parallel2 &&
+ git log --pretty=oneline | grep $PARA3 &&
+ git show $PARA3 | grep "A U Thor"
+ )
'
test_expect_success 'fetch branch with replacement' '
- git branch tofetch $HASH6 &&
- (
- cd clone_dir &&
- git fetch origin refs/heads/tofetch:refs/heads/parallel3 &&
- git log --pretty=oneline parallel3 >output.txt &&
- ! grep $PARA3 output.txt &&
- git show $PARA3 >para3.txt &&
- grep "A U Thor" para3.txt &&
- git fetch origin "refs/replace/*:refs/replace/*" &&
- git log --pretty=oneline parallel3 >output.txt &&
- grep $PARA3 output.txt &&
- git show $PARA3 >para3.txt &&
- grep "O Thor" para3.txt
- )
+ git branch tofetch $HASH6 &&
+ (
+ cd clone_dir &&
+ git fetch origin refs/heads/tofetch:refs/heads/parallel3 &&
+ git log --pretty=oneline parallel3 >output.txt &&
+ ! grep $PARA3 output.txt &&
+ git show $PARA3 >para3.txt &&
+ grep "A U Thor" para3.txt &&
+ git fetch origin "refs/replace/*:refs/replace/*" &&
+ git log --pretty=oneline parallel3 >output.txt &&
+ grep $PARA3 output.txt &&
+ git show $PARA3 >para3.txt &&
+ grep "O Thor" para3.txt
+ )
'
test_expect_success 'bisect and replacements' '
- git bisect start $HASH7 $HASH1 &&
- test "$PARA3" = "$(git rev-parse --verify HEAD)" &&
- git bisect reset &&
- GIT_NO_REPLACE_OBJECTS=1 git bisect start $HASH7 $HASH1 &&
- test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
- git bisect reset &&
- git --no-replace-objects bisect start $HASH7 $HASH1 &&
- test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
- git bisect reset
+ git bisect start $HASH7 $HASH1 &&
+ test "$PARA3" = "$(git rev-parse --verify HEAD)" &&
+ git bisect reset &&
+ GIT_NO_REPLACE_OBJECTS=1 git bisect start $HASH7 $HASH1 &&
+ test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
+ git bisect reset &&
+ git --no-replace-objects bisect start $HASH7 $HASH1 &&
+ test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
+ git bisect reset
'
test_expect_success 'index-pack and replacements' '
diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
index c9afcef201..0a5c487540 100755
--- a/t/t6120-describe.sh
+++ b/t/t6120-describe.sh
@@ -85,6 +85,7 @@ check_describe e-1-gHASH --tags HEAD^^
check_describe c-2-gHASH --tags HEAD^^2
check_describe B --tags HEAD^^2^
check_describe e --tags HEAD^^^
+check_describe e --tags --exact-match HEAD^^^
check_describe heads/main --all HEAD
check_describe tags/c-6-gHASH --all HEAD^
@@ -96,6 +97,13 @@ check_describe A-3-gHASH --long HEAD^^2
check_describe c-7-gHASH --tags
check_describe e-3-gHASH --first-parent --tags
+check_describe c-7-gHASH --tags --no-exact-match HEAD
+check_describe e-3-gHASH --first-parent --tags --no-exact-match HEAD
+
+test_expect_success '--exact-match failure' '
+ test_must_fail git describe --exact-match HEAD 2>err
+'
+
test_expect_success 'describe --contains defaults to HEAD without commit-ish' '
echo "A^0" >expect &&
git checkout A &&
diff --git a/t/t6135-pathspec-with-attrs.sh b/t/t6135-pathspec-with-attrs.sh
index 457cc167c7..f70c395e75 100755
--- a/t/t6135-pathspec-with-attrs.sh
+++ b/t/t6135-pathspec-with-attrs.sh
@@ -65,7 +65,8 @@ test_expect_success 'setup .gitattributes' '
fileValue label=foo
fileWrongLabel label☺
EOF
- git add .gitattributes &&
+ echo fileSetLabel label1 >sub/.gitattributes &&
+ git add .gitattributes sub/.gitattributes &&
git commit -m "add attributes"
'
@@ -78,7 +79,17 @@ test_expect_success 'check specific set attr' '
test_cmp expect actual
'
-test_expect_success 'check specific set attr (2)' '
+test_expect_success 'check set attr with pathspec pattern' '
+ echo sub/fileSetLabel >expect &&
+
+ git ls-files ":(attr:label)sub" >actual &&
+ test_cmp expect actual &&
+
+ git ls-files ":(attr:label)sub/" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'check specific set attr in tree-ish' '
cat <<-\EOF >expect &&
HEAD:fileSetLabel
HEAD:sub/fileSetLabel
@@ -87,6 +98,16 @@ test_expect_success 'check specific set attr (2)' '
test_cmp expect actual
'
+test_expect_success 'check specific set attr with pathspec pattern in tree-ish' '
+ echo HEAD:sub/fileSetLabel >expect &&
+
+ git grep -l content HEAD ":(attr:label)sub" >actual &&
+ test_cmp expect actual &&
+
+ git grep -l content HEAD ":(attr:label)sub/" >actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'check specific unset attr' '
cat <<-\EOF >expect &&
fileUnsetLabel
@@ -137,6 +158,7 @@ test_expect_success 'check unspecified attr' '
fileC
fileNoLabel
fileWrongLabel
+ sub/.gitattributes
sub/fileA
sub/fileAB
sub/fileAC
@@ -161,6 +183,7 @@ test_expect_success 'check unspecified attr (2)' '
HEAD:fileC
HEAD:fileNoLabel
HEAD:fileWrongLabel
+ HEAD:sub/.gitattributes
HEAD:sub/fileA
HEAD:sub/fileAB
HEAD:sub/fileAC
@@ -180,6 +203,7 @@ test_expect_success 'check multiple unspecified attr' '
fileC
fileNoLabel
fileWrongLabel
+ sub/.gitattributes
sub/fileC
sub/fileNoLabel
sub/fileWrongLabel
@@ -253,4 +277,22 @@ test_expect_success 'backslash cannot be used as a value' '
test_i18ngrep "for value matching" actual
'
+test_expect_success 'reading from .gitattributes in a subdirectory (1)' '
+ git ls-files ":(attr:label1)" >actual &&
+ test_write_lines "sub/fileSetLabel" >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'reading from .gitattributes in a subdirectory (2)' '
+ git ls-files ":(attr:label1)sub" >actual &&
+ test_write_lines "sub/fileSetLabel" >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'reading from .gitattributes in a subdirectory (3)' '
+ git ls-files ":(attr:label1)sub/" >actual &&
+ test_write_lines "sub/fileSetLabel" >expect &&
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 5c00607608..5b434ab451 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -6,6 +6,7 @@
test_description='for-each-ref test'
. ./test-lib.sh
+GNUPGHOME_NOT_USED=$GNUPGHOME
. "$TEST_DIRECTORY"/lib-gpg.sh
. "$TEST_DIRECTORY"/lib-terminal.sh
@@ -448,6 +449,41 @@ test_expect_success 'exercise glob patterns with prefixes' '
'
cat >expected <<\EOF
+refs/tags/bar
+refs/tags/baz
+refs/tags/testtag
+EOF
+
+test_expect_success 'exercise patterns with prefix exclusions' '
+ for tag in foo/one foo/two foo/three bar baz
+ do
+ git tag "$tag" || return 1
+ done &&
+ test_when_finished "git tag -d foo/one foo/two foo/three bar baz" &&
+ git for-each-ref --format="%(refname)" \
+ refs/tags/ --exclude=refs/tags/foo >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<\EOF
+refs/tags/bar
+refs/tags/baz
+refs/tags/foo/one
+refs/tags/testtag
+EOF
+
+test_expect_success 'exercise patterns with pattern exclusions' '
+ for tag in foo/one foo/two foo/three bar baz
+ do
+ git tag "$tag" || return 1
+ done &&
+ test_when_finished "git tag -d foo/one foo/two foo/three bar baz" &&
+ git for-each-ref --format="%(refname)" \
+ refs/tags/ --exclude="refs/tags/foo/t*" >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<\EOF
'refs/heads/main'
'refs/remotes/origin/main'
'refs/tags/testtag'
@@ -561,6 +597,144 @@ test_expect_success 'color.ui=always does not override tty check' '
test_cmp expected.bare actual
'
+test_expect_success 'setup for describe atom tests' '
+ git init -b master describe-repo &&
+ (
+ cd describe-repo &&
+
+ test_commit --no-tag one &&
+ git tag tagone &&
+
+ test_commit --no-tag two &&
+ git tag -a -m "tag two" tagtwo
+ )
+'
+
+test_expect_success 'describe atom vs git describe' '
+ (
+ cd describe-repo &&
+
+ git for-each-ref --format="%(objectname)" \
+ refs/tags/ >obj &&
+ while read hash
+ do
+ if desc=$(git describe $hash)
+ then
+ : >expect-contains-good
+ else
+ : >expect-contains-bad
+ fi &&
+ echo "$hash $desc" || return 1
+ done <obj >expect &&
+ test_path_exists expect-contains-good &&
+ test_path_exists expect-contains-bad &&
+
+ git for-each-ref --format="%(objectname) %(describe)" \
+ refs/tags/ >actual 2>err &&
+ test_cmp expect actual &&
+ test_must_be_empty err
+ )
+'
+
+test_expect_success 'describe:tags vs describe --tags' '
+ (
+ cd describe-repo &&
+ git describe --tags >expect &&
+ git for-each-ref --format="%(describe:tags)" \
+ refs/heads/master >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'describe:abbrev=... vs describe --abbrev=...' '
+ (
+ cd describe-repo &&
+
+ # Case 1: We have commits between HEAD and the most
+ # recent tag reachable from it
+ test_commit --no-tag file &&
+ git describe --abbrev=14 >expect &&
+ git for-each-ref --format="%(describe:abbrev=14)" \
+ refs/heads/master >actual &&
+ test_cmp expect actual &&
+
+ # Make sure the hash used is atleast 14 digits long
+ sed -e "s/^.*-g\([0-9a-f]*\)$/\1/" <actual >hexpart &&
+ test 15 -le $(wc -c <hexpart) &&
+
+ # Case 2: We have a tag at HEAD, describe directly gives
+ # the name of the tag
+ git tag -a -m tagged tagname &&
+ git describe --abbrev=14 >expect &&
+ git for-each-ref --format="%(describe:abbrev=14)" \
+ refs/heads/master >actual &&
+ test_cmp expect actual &&
+ test tagname = $(cat actual)
+ )
+'
+
+test_expect_success 'describe:match=... vs describe --match ...' '
+ (
+ cd describe-repo &&
+ git tag -a -m "tag foo" tag-foo &&
+ git describe --match "*-foo" >expect &&
+ git for-each-ref --format="%(describe:match="*-foo")" \
+ refs/heads/master >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'describe:exclude:... vs describe --exclude ...' '
+ (
+ cd describe-repo &&
+ git tag -a -m "tag bar" tag-bar &&
+ git describe --exclude "*-bar" >expect &&
+ git for-each-ref --format="%(describe:exclude="*-bar")" \
+ refs/heads/master >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'deref with describe atom' '
+ (
+ cd describe-repo &&
+ cat >expect <<-\EOF &&
+
+ tagname
+ tagname
+ tagname
+
+ tagtwo
+ EOF
+ git for-each-ref --format="%(*describe)" >actual &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success 'err on bad describe atom arg' '
+ (
+ cd describe-repo &&
+
+ # The bad arg is the only arg passed to describe atom
+ cat >expect <<-\EOF &&
+ fatal: unrecognized %(describe) argument: baz
+ EOF
+ test_must_fail git for-each-ref --format="%(describe:baz)" \
+ refs/heads/master 2>actual &&
+ test_cmp expect actual &&
+
+ # The bad arg is in the middle of the option string
+ # passed to the describe atom
+ cat >expect <<-\EOF &&
+ fatal: unrecognized %(describe) argument: qux=1,abbrev=14
+ EOF
+ test_must_fail git for-each-ref \
+ --format="%(describe:tags,qux=1,abbrev=14)" \
+ ref/heads/master 2>actual &&
+ test_cmp expect actual
+ )
+'
+
cat >expected <<\EOF
heads/main
tags/main
@@ -1522,4 +1696,195 @@ test_expect_success 'git for-each-ref with non-existing refs' '
test_must_be_empty actual
'
+GRADE_FORMAT="%(signature:grade)%0a%(signature:key)%0a%(signature:signer)%0a%(signature:fingerprint)%0a%(signature:primarykeyfingerprint)"
+TRUSTLEVEL_FORMAT="%(signature:trustlevel)%0a%(signature:key)%0a%(signature:signer)%0a%(signature:fingerprint)%0a%(signature:primarykeyfingerprint)"
+
+test_expect_success GPG 'setup for signature atom using gpg' '
+ git checkout -b signed &&
+
+ test_when_finished "test_unconfig commit.gpgSign" &&
+
+ echo "1" >file &&
+ git add file &&
+ test_tick &&
+ git commit -S -m "file: 1" &&
+ git tag first-signed &&
+
+ echo "2" >file &&
+ test_tick &&
+ git commit -a -m "file: 2" &&
+ git tag second-unsigned &&
+
+ git config commit.gpgSign 1 &&
+ echo "3" >file &&
+ test_tick &&
+ git commit -a --no-gpg-sign -m "file: 3" &&
+ git tag third-unsigned &&
+
+ test_tick &&
+ git rebase -f HEAD^^ && git tag second-signed HEAD^ &&
+ git tag third-signed &&
+
+ echo "4" >file &&
+ test_tick &&
+ git commit -a -SB7227189 -m "file: 4" &&
+ git tag fourth-signed &&
+
+ echo "5" >file &&
+ test_tick &&
+ git commit -a --no-gpg-sign -m "file: 5" &&
+ git tag fifth-unsigned &&
+
+ echo "6" >file &&
+ test_tick &&
+ git commit -a --no-gpg-sign -m "file: 6" &&
+
+ test_tick &&
+ git rebase -f HEAD^^ &&
+ git tag fifth-signed HEAD^ &&
+ git tag sixth-signed &&
+
+ echo "7" >file &&
+ test_tick &&
+ git commit -a --no-gpg-sign -m "file: 7" &&
+ git tag seventh-unsigned
+'
+
+test_expect_success GPGSSH 'setup for signature atom using ssh' '
+ test_when_finished "test_unconfig gpg.format user.signingkey" &&
+
+ test_config gpg.format ssh &&
+ test_config user.signingkey "${GPGSSH_KEY_PRIMARY}" &&
+ echo "8" >file &&
+ test_tick &&
+ git add file &&
+ git commit -S -m "file: 8" &&
+ git tag eighth-signed-ssh
+'
+
+test_expect_success GPG2 'bare signature atom' '
+ git verify-commit first-signed 2>out.raw &&
+ grep -Ev "checking the trustdb|PGP trust model" out.raw >out &&
+ head -3 out >expect &&
+ tail -1 out >>expect &&
+ echo >>expect &&
+ git for-each-ref refs/tags/first-signed \
+ --format="%(signature)" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success GPG 'show good signature with custom format' '
+ git verify-commit first-signed &&
+ cat >expect <<-\EOF &&
+ G
+ 13B6F51ECDDE430D
+ C O Mitter <committer@example.com>
+ 73D758744BE721698EC54E8713B6F51ECDDE430D
+ 73D758744BE721698EC54E8713B6F51ECDDE430D
+ EOF
+ git for-each-ref refs/tags/first-signed \
+ --format="$GRADE_FORMAT" >actual &&
+ test_cmp expect actual
+'
+test_expect_success GPGSSH 'show good signature with custom format
+ with ssh' '
+ test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
+ FINGERPRINT=$(ssh-keygen -lf "${GPGSSH_KEY_PRIMARY}" | awk "{print \$2;}") &&
+ cat >expect.tmpl <<-\EOF &&
+ G
+ FINGERPRINT
+ principal with number 1
+ FINGERPRINT
+
+ EOF
+ sed "s|FINGERPRINT|$FINGERPRINT|g" expect.tmpl >expect &&
+ git for-each-ref refs/tags/eighth-signed-ssh \
+ --format="$GRADE_FORMAT" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success GPG 'signature atom with grade option and bad signature' '
+ git cat-file commit third-signed >raw &&
+ sed -e "s/^file: 3/file: 3 forged/" raw >forged1 &&
+ FORGED1=$(git hash-object -w -t commit forged1) &&
+ git update-ref refs/tags/third-signed "$FORGED1" &&
+ test_must_fail git verify-commit "$FORGED1" &&
+
+ cat >expect <<-\EOF &&
+ B
+ 13B6F51ECDDE430D
+ C O Mitter <committer@example.com>
+
+
+ EOF
+ git for-each-ref refs/tags/third-signed \
+ --format="$GRADE_FORMAT" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success GPG 'show untrusted signature with custom format' '
+ cat >expect <<-\EOF &&
+ U
+ 65A0EEA02E30CAD7
+ Eris Discordia <discord@example.net>
+ F8364A59E07FFE9F4D63005A65A0EEA02E30CAD7
+ D4BE22311AD3131E5EDA29A461092E85B7227189
+ EOF
+ git for-each-ref refs/tags/fourth-signed \
+ --format="$GRADE_FORMAT" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success GPG 'show untrusted signature with undefined trust level' '
+ cat >expect <<-\EOF &&
+ undefined
+ 65A0EEA02E30CAD7
+ Eris Discordia <discord@example.net>
+ F8364A59E07FFE9F4D63005A65A0EEA02E30CAD7
+ D4BE22311AD3131E5EDA29A461092E85B7227189
+ EOF
+ git for-each-ref refs/tags/fourth-signed \
+ --format="$TRUSTLEVEL_FORMAT" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success GPG 'show untrusted signature with ultimate trust level' '
+ cat >expect <<-\EOF &&
+ ultimate
+ 13B6F51ECDDE430D
+ C O Mitter <committer@example.com>
+ 73D758744BE721698EC54E8713B6F51ECDDE430D
+ 73D758744BE721698EC54E8713B6F51ECDDE430D
+ EOF
+ git for-each-ref refs/tags/sixth-signed \
+ --format="$TRUSTLEVEL_FORMAT" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success GPG 'show unknown signature with custom format' '
+ cat >expect <<-\EOF &&
+ E
+ 13B6F51ECDDE430D
+
+
+
+ EOF
+ GNUPGHOME="$GNUPGHOME_NOT_USED" git for-each-ref \
+ refs/tags/sixth-signed --format="$GRADE_FORMAT" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success GPG 'show lack of signature with custom format' '
+ cat >expect <<-\EOF &&
+ N
+
+
+
+
+ EOF
+ git for-each-ref refs/tags/seventh-unsigned \
+ --format="$GRADE_FORMAT" >actual &&
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/t6302-for-each-ref-filter.sh b/t/t6302-for-each-ref-filter.sh
index 1ce5f490e9..af223e44d6 100755
--- a/t/t6302-for-each-ref-filter.sh
+++ b/t/t6302-for-each-ref-filter.sh
@@ -45,6 +45,8 @@ test_expect_success 'check signed tags with --points-at' '
sed -e "s/Z$//" >expect <<-\EOF &&
refs/heads/side Z
refs/tags/annotated-tag four
+ refs/tags/doubly-annotated-tag An annotated tag
+ refs/tags/doubly-signed-tag A signed tag
refs/tags/four Z
refs/tags/signed-tag four
EOF
diff --git a/t/t6406-merge-attr.sh b/t/t6406-merge-attr.sh
index 5e4e4dd6d9..9677180a5b 100755
--- a/t/t6406-merge-attr.sh
+++ b/t/t6406-merge-attr.sh
@@ -56,6 +56,12 @@ test_expect_success setup '
) >"$ours+"
cat "$ours+" >"$ours"
rm -f "$ours+"
+
+ if test -f ./please-abort
+ then
+ echo >>./please-abort killing myself
+ kill -9 $$
+ fi
exit "$exit"
EOF
chmod +x ./custom-merge
@@ -162,6 +168,23 @@ test_expect_success 'custom merge backend' '
rm -f $o $a $b
'
+test_expect_success !WINDOWS 'custom merge driver that is killed with a signal' '
+ test_when_finished "rm -f output please-abort" &&
+
+ git reset --hard anchor &&
+ git config --replace-all \
+ merge.custom.driver "./custom-merge %O %A %B 0 %P" &&
+ git config --replace-all \
+ merge.custom.name "custom merge driver for testing" &&
+
+ >./please-abort &&
+ echo "* merge=custom" >.gitattributes &&
+ test_must_fail git merge main &&
+ git ls-files -u >output &&
+ git diff --name-only HEAD >>output &&
+ test_must_be_empty output
+'
+
test_expect_success 'up-to-date merge without common ancestor' '
git init repo1 &&
git init repo2 &&
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index 0fe6ba93a2..e689db4292 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -2188,4 +2188,23 @@ test_expect_success 'Does --[no-]contains stop at commits? Yes!' '
test_cmp expected actual
'
+test_expect_success 'If tag is created then tag message file is unlinked' '
+ test_when_finished "git tag -d foo" &&
+ write_script fakeeditor <<-\EOF &&
+ echo Message >.git/TAG_EDITMSG
+ EOF
+ GIT_EDITOR=./fakeeditor git tag -a foo &&
+ test_path_is_missing .git/TAG_EDITMSG
+'
+
+test_expect_success 'If tag cannot be created then tag message file is not unlinked' '
+ test_when_finished "git tag -d foo/bar && rm .git/TAG_EDITMSG" &&
+ write_script fakeeditor <<-\EOF &&
+ echo Message >.git/TAG_EDITMSG
+ EOF
+ git tag foo/bar &&
+ test_must_fail env GIT_EDITOR=./fakeeditor git tag -a foo &&
+ test_path_exists .git/TAG_EDITMSG
+'
+
test_done
diff --git a/t/t7101-reset-empty-subdirs.sh b/t/t7101-reset-empty-subdirs.sh
index 638bb04e21..89cf98b30c 100755
--- a/t/t7101-reset-empty-subdirs.sh
+++ b/t/t7101-reset-empty-subdirs.sh
@@ -10,57 +10,57 @@ TEST_PASSES_SANITIZE_LEAK=true
. "$TEST_DIRECTORY"/lib-diff-data.sh
test_expect_success 'creating initial files' '
- mkdir path0 &&
- COPYING_test_data >path0/COPYING &&
- git add path0/COPYING &&
- git commit -m add -a
+ mkdir path0 &&
+ COPYING_test_data >path0/COPYING &&
+ git add path0/COPYING &&
+ git commit -m add -a
'
test_expect_success 'creating second files' '
- mkdir path1 &&
- mkdir path1/path2 &&
- COPYING_test_data >path1/path2/COPYING &&
- COPYING_test_data >path1/COPYING &&
- COPYING_test_data >COPYING &&
- COPYING_test_data >path0/COPYING-TOO &&
- git add path1/path2/COPYING &&
- git add path1/COPYING &&
- git add COPYING &&
- git add path0/COPYING-TOO &&
- git commit -m change -a
+ mkdir path1 &&
+ mkdir path1/path2 &&
+ COPYING_test_data >path1/path2/COPYING &&
+ COPYING_test_data >path1/COPYING &&
+ COPYING_test_data >COPYING &&
+ COPYING_test_data >path0/COPYING-TOO &&
+ git add path1/path2/COPYING &&
+ git add path1/COPYING &&
+ git add COPYING &&
+ git add path0/COPYING-TOO &&
+ git commit -m change -a
'
test_expect_success 'resetting tree HEAD^' '
- git reset --hard HEAD^
+ git reset --hard HEAD^
'
test_expect_success 'checking initial files exist after rewind' '
- test -d path0 &&
- test -f path0/COPYING
+ test -d path0 &&
+ test -f path0/COPYING
'
test_expect_success 'checking lack of path1/path2/COPYING' '
- ! test -f path1/path2/COPYING
+ ! test -f path1/path2/COPYING
'
test_expect_success 'checking lack of path1/COPYING' '
- ! test -f path1/COPYING
+ ! test -f path1/COPYING
'
test_expect_success 'checking lack of COPYING' '
- ! test -f COPYING
+ ! test -f COPYING
'
test_expect_success 'checking checking lack of path1/COPYING-TOO' '
- ! test -f path0/COPYING-TOO
+ ! test -f path0/COPYING-TOO
'
test_expect_success 'checking lack of path1/path2' '
- ! test -d path1/path2
+ ! test -d path1/path2
'
test_expect_success 'checking lack of path1' '
- ! test -d path1
+ ! test -d path1
'
test_done
diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh
index 22477f3a31..4287863ae6 100755
--- a/t/t7102-reset.sh
+++ b/t/t7102-reset.sh
@@ -71,6 +71,16 @@ check_changes () {
done | test_cmp .cat_expect -
}
+# no negated form for various type of resets
+for opt in soft mixed hard merge keep
+do
+ test_expect_success "no 'git reset --no-$opt'" '
+ test_when_finished "rm -f err" &&
+ test_must_fail git reset --no-$opt 2>err &&
+ grep "error: unknown option .no-$opt." err
+ '
+done
+
test_expect_success 'reset --hard message' '
hex=$(git log -1 --format="%h") &&
git reset --hard >.actual &&
diff --git a/t/t7110-reset-merge.sh b/t/t7110-reset-merge.sh
index eb881be95b..772480a345 100755
--- a/t/t7110-reset-merge.sh
+++ b/t/t7110-reset-merge.sh
@@ -9,17 +9,17 @@ TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success setup '
- printf "line %d\n" 1 2 3 >file1 &&
- cat file1 >file2 &&
- git add file1 file2 &&
- test_tick &&
- git commit -m "Initial commit" &&
- git tag initial &&
- echo line 4 >>file1 &&
- cat file1 >file2 &&
- test_tick &&
- git commit -m "add line 4 to file1" file1 &&
- git tag second
+ printf "line %d\n" 1 2 3 >file1 &&
+ cat file1 >file2 &&
+ git add file1 file2 &&
+ test_tick &&
+ git commit -m "Initial commit" &&
+ git tag initial &&
+ echo line 4 >>file1 &&
+ cat file1 >file2 &&
+ test_tick &&
+ git commit -m "add line 4 to file1" file1 &&
+ git tag second
'
# The next test will test the following:
@@ -29,19 +29,19 @@ test_expect_success setup '
# file1: C C C D --merge D D D
# file2: C D D D --merge C D D
test_expect_success 'reset --merge is ok with changes in file it does not touch' '
- git reset --merge HEAD^ &&
- ! grep 4 file1 &&
- grep 4 file2 &&
- test "$(git rev-parse HEAD)" = "$(git rev-parse initial)" &&
- test -z "$(git diff --cached)"
+ git reset --merge HEAD^ &&
+ ! grep 4 file1 &&
+ grep 4 file2 &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse initial)" &&
+ test -z "$(git diff --cached)"
'
test_expect_success 'reset --merge is ok when switching back' '
- git reset --merge second &&
- grep 4 file1 &&
- grep 4 file2 &&
- test "$(git rev-parse HEAD)" = "$(git rev-parse second)" &&
- test -z "$(git diff --cached)"
+ git reset --merge second &&
+ grep 4 file1 &&
+ grep 4 file2 &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse second)" &&
+ test -z "$(git diff --cached)"
'
# The next test will test the following:
@@ -51,21 +51,21 @@ test_expect_success 'reset --merge is ok when switching back' '
# file1: C C C D --keep D D D
# file2: C D D D --keep C D D
test_expect_success 'reset --keep is ok with changes in file it does not touch' '
- git reset --hard second &&
- cat file1 >file2 &&
- git reset --keep HEAD^ &&
- ! grep 4 file1 &&
- grep 4 file2 &&
- test "$(git rev-parse HEAD)" = "$(git rev-parse initial)" &&
- test -z "$(git diff --cached)"
+ git reset --hard second &&
+ cat file1 >file2 &&
+ git reset --keep HEAD^ &&
+ ! grep 4 file1 &&
+ grep 4 file2 &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse initial)" &&
+ test -z "$(git diff --cached)"
'
test_expect_success 'reset --keep is ok when switching back' '
- git reset --keep second &&
- grep 4 file1 &&
- grep 4 file2 &&
- test "$(git rev-parse HEAD)" = "$(git rev-parse second)" &&
- test -z "$(git diff --cached)"
+ git reset --keep second &&
+ grep 4 file1 &&
+ grep 4 file2 &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse second)" &&
+ test -z "$(git diff --cached)"
'
# The next test will test the following:
@@ -75,28 +75,28 @@ test_expect_success 'reset --keep is ok when switching back' '
# file1: B B C D --merge D D D
# file2: C D D D --merge C D D
test_expect_success 'reset --merge discards changes added to index (1)' '
- git reset --hard second &&
- cat file1 >file2 &&
- echo "line 5" >> file1 &&
- git add file1 &&
- git reset --merge HEAD^ &&
- ! grep 4 file1 &&
- ! grep 5 file1 &&
- grep 4 file2 &&
- test "$(git rev-parse HEAD)" = "$(git rev-parse initial)" &&
- test -z "$(git diff --cached)"
+ git reset --hard second &&
+ cat file1 >file2 &&
+ echo "line 5" >> file1 &&
+ git add file1 &&
+ git reset --merge HEAD^ &&
+ ! grep 4 file1 &&
+ ! grep 5 file1 &&
+ grep 4 file2 &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse initial)" &&
+ test -z "$(git diff --cached)"
'
test_expect_success 'reset --merge is ok again when switching back (1)' '
- git reset --hard initial &&
- echo "line 5" >> file2 &&
- git add file2 &&
- git reset --merge second &&
- ! grep 4 file2 &&
- ! grep 5 file1 &&
- grep 4 file1 &&
- test "$(git rev-parse HEAD)" = "$(git rev-parse second)" &&
- test -z "$(git diff --cached)"
+ git reset --hard initial &&
+ echo "line 5" >> file2 &&
+ git add file2 &&
+ git reset --merge second &&
+ ! grep 4 file2 &&
+ ! grep 5 file1 &&
+ grep 4 file1 &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse second)" &&
+ test -z "$(git diff --cached)"
'
# The next test will test the following:
@@ -105,10 +105,10 @@ test_expect_success 'reset --merge is ok again when switching back (1)' '
# ----------------------------------------------------
# file1: B B C D --keep (disallowed)
test_expect_success 'reset --keep fails with changes in index in files it touches' '
- git reset --hard second &&
- echo "line 5" >> file1 &&
- git add file1 &&
- test_must_fail git reset --keep HEAD^
+ git reset --hard second &&
+ echo "line 5" >> file1 &&
+ git add file1 &&
+ test_must_fail git reset --keep HEAD^
'
# The next test will test the following:
@@ -118,23 +118,23 @@ test_expect_success 'reset --keep fails with changes in index in files it touche
# file1: C C C D --merge D D D
# file2: C C D D --merge D D D
test_expect_success 'reset --merge discards changes added to index (2)' '
- git reset --hard second &&
- echo "line 4" >> file2 &&
- git add file2 &&
- git reset --merge HEAD^ &&
- ! grep 4 file2 &&
- test "$(git rev-parse HEAD)" = "$(git rev-parse initial)" &&
- test -z "$(git diff)" &&
- test -z "$(git diff --cached)"
+ git reset --hard second &&
+ echo "line 4" >> file2 &&
+ git add file2 &&
+ git reset --merge HEAD^ &&
+ ! grep 4 file2 &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse initial)" &&
+ test -z "$(git diff)" &&
+ test -z "$(git diff --cached)"
'
test_expect_success 'reset --merge is ok again when switching back (2)' '
- git reset --hard initial &&
- git reset --merge second &&
- ! grep 4 file2 &&
- grep 4 file1 &&
- test "$(git rev-parse HEAD)" = "$(git rev-parse second)" &&
- test -z "$(git diff --cached)"
+ git reset --hard initial &&
+ git reset --merge second &&
+ ! grep 4 file2 &&
+ grep 4 file1 &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse second)" &&
+ test -z "$(git diff --cached)"
'
# The next test will test the following:
@@ -144,21 +144,21 @@ test_expect_success 'reset --merge is ok again when switching back (2)' '
# file1: C C C D --keep D D D
# file2: C C D D --keep C D D
test_expect_success 'reset --keep keeps changes it does not touch' '
- git reset --hard second &&
- echo "line 4" >> file2 &&
- git add file2 &&
- git reset --keep HEAD^ &&
- grep 4 file2 &&
- test "$(git rev-parse HEAD)" = "$(git rev-parse initial)" &&
- test -z "$(git diff --cached)"
+ git reset --hard second &&
+ echo "line 4" >> file2 &&
+ git add file2 &&
+ git reset --keep HEAD^ &&
+ grep 4 file2 &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse initial)" &&
+ test -z "$(git diff --cached)"
'
test_expect_success 'reset --keep keeps changes when switching back' '
- git reset --keep second &&
- grep 4 file2 &&
- grep 4 file1 &&
- test "$(git rev-parse HEAD)" = "$(git rev-parse second)" &&
- test -z "$(git diff --cached)"
+ git reset --keep second &&
+ grep 4 file2 &&
+ grep 4 file1 &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse second)" &&
+ test -z "$(git diff --cached)"
'
# The next test will test the following:
@@ -167,14 +167,14 @@ test_expect_success 'reset --keep keeps changes when switching back' '
# ----------------------------------------------------
# file1: A B B C --merge (disallowed)
test_expect_success 'reset --merge fails with changes in file it touches' '
- git reset --hard second &&
- echo "line 5" >> file1 &&
- test_tick &&
- git commit -m "add line 5" file1 &&
- sed -e "s/line 1/changed line 1/" <file1 >file3 &&
- mv file3 file1 &&
- test_must_fail git reset --merge HEAD^ 2>err.log &&
- grep file1 err.log | grep "not uptodate"
+ git reset --hard second &&
+ echo "line 5" >> file1 &&
+ test_tick &&
+ git commit -m "add line 5" file1 &&
+ sed -e "s/line 1/changed line 1/" <file1 >file3 &&
+ mv file3 file1 &&
+ test_must_fail git reset --merge HEAD^ 2>err.log &&
+ grep file1 err.log | grep "not uptodate"
'
# The next test will test the following:
@@ -183,36 +183,36 @@ test_expect_success 'reset --merge fails with changes in file it touches' '
# ----------------------------------------------------
# file1: A B B C --keep (disallowed)
test_expect_success 'reset --keep fails with changes in file it touches' '
- git reset --hard second &&
- echo "line 5" >> file1 &&
- test_tick &&
- git commit -m "add line 5" file1 &&
- sed -e "s/line 1/changed line 1/" <file1 >file3 &&
- mv file3 file1 &&
- test_must_fail git reset --keep HEAD^ 2>err.log &&
- grep file1 err.log | grep "not uptodate"
+ git reset --hard second &&
+ echo "line 5" >> file1 &&
+ test_tick &&
+ git commit -m "add line 5" file1 &&
+ sed -e "s/line 1/changed line 1/" <file1 >file3 &&
+ mv file3 file1 &&
+ test_must_fail git reset --keep HEAD^ 2>err.log &&
+ grep file1 err.log | grep "not uptodate"
'
test_expect_success 'setup 3 different branches' '
- git reset --hard second &&
- git branch branch1 &&
- git branch branch2 &&
- git branch branch3 &&
- git checkout branch1 &&
- echo "line 5 in branch1" >> file1 &&
- test_tick &&
- git commit -a -m "change in branch1" &&
- git checkout branch2 &&
- echo "line 5 in branch2" >> file1 &&
- test_tick &&
- git commit -a -m "change in branch2" &&
- git tag third &&
- git checkout branch3 &&
- echo a new file >file3 &&
- rm -f file1 &&
- git add file3 &&
- test_tick &&
- git commit -a -m "change in branch3"
+ git reset --hard second &&
+ git branch branch1 &&
+ git branch branch2 &&
+ git branch branch3 &&
+ git checkout branch1 &&
+ echo "line 5 in branch1" >> file1 &&
+ test_tick &&
+ git commit -a -m "change in branch1" &&
+ git checkout branch2 &&
+ echo "line 5 in branch2" >> file1 &&
+ test_tick &&
+ git commit -a -m "change in branch2" &&
+ git tag third &&
+ git checkout branch3 &&
+ echo a new file >file3 &&
+ rm -f file1 &&
+ git add file3 &&
+ test_tick &&
+ git commit -a -m "change in branch3"
'
# The next test will test the following:
@@ -221,12 +221,12 @@ test_expect_success 'setup 3 different branches' '
# ----------------------------------------------------
# file1: X U B C --merge C C C
test_expect_success '"reset --merge HEAD^" is ok with pending merge' '
- git checkout third &&
- test_must_fail git merge branch1 &&
- git reset --merge HEAD^ &&
- test "$(git rev-parse HEAD)" = "$(git rev-parse second)" &&
- test -z "$(git diff --cached)" &&
- test -z "$(git diff)"
+ git checkout third &&
+ test_must_fail git merge branch1 &&
+ git reset --merge HEAD^ &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse second)" &&
+ test -z "$(git diff --cached)" &&
+ test -z "$(git diff)"
'
# The next test will test the following:
@@ -235,10 +235,10 @@ test_expect_success '"reset --merge HEAD^" is ok with pending merge' '
# ----------------------------------------------------
# file1: X U B C --keep (disallowed)
test_expect_success '"reset --keep HEAD^" fails with pending merge' '
- git reset --hard third &&
- test_must_fail git merge branch1 &&
- test_must_fail git reset --keep HEAD^ 2>err.log &&
- test_i18ngrep "middle of a merge" err.log
+ git reset --hard third &&
+ test_must_fail git merge branch1 &&
+ test_must_fail git reset --keep HEAD^ 2>err.log &&
+ test_i18ngrep "middle of a merge" err.log
'
# The next test will test the following:
@@ -247,12 +247,12 @@ test_expect_success '"reset --keep HEAD^" fails with pending merge' '
# ----------------------------------------------------
# file1: X U B B --merge B B B
test_expect_success '"reset --merge HEAD" is ok with pending merge' '
- git reset --hard third &&
- test_must_fail git merge branch1 &&
- git reset --merge HEAD &&
- test "$(git rev-parse HEAD)" = "$(git rev-parse third)" &&
- test -z "$(git diff --cached)" &&
- test -z "$(git diff)"
+ git reset --hard third &&
+ test_must_fail git merge branch1 &&
+ git reset --merge HEAD &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse third)" &&
+ test -z "$(git diff --cached)" &&
+ test -z "$(git diff)"
'
# The next test will test the following:
@@ -261,36 +261,36 @@ test_expect_success '"reset --merge HEAD" is ok with pending merge' '
# ----------------------------------------------------
# file1: X U B B --keep (disallowed)
test_expect_success '"reset --keep HEAD" fails with pending merge' '
- git reset --hard third &&
- test_must_fail git merge branch1 &&
- test_must_fail git reset --keep HEAD 2>err.log &&
- test_i18ngrep "middle of a merge" err.log
+ git reset --hard third &&
+ test_must_fail git merge branch1 &&
+ test_must_fail git reset --keep HEAD 2>err.log &&
+ test_i18ngrep "middle of a merge" err.log
'
test_expect_success '--merge is ok with added/deleted merge' '
- git reset --hard third &&
- rm -f file2 &&
- test_must_fail git merge branch3 &&
- ! test -f file2 &&
- test -f file3 &&
- git diff --exit-code file3 &&
- git diff --exit-code branch3 file3 &&
- git reset --merge HEAD &&
- ! test -f file3 &&
- ! test -f file2 &&
- git diff --exit-code --cached
+ git reset --hard third &&
+ rm -f file2 &&
+ test_must_fail git merge branch3 &&
+ ! test -f file2 &&
+ test -f file3 &&
+ git diff --exit-code file3 &&
+ git diff --exit-code branch3 file3 &&
+ git reset --merge HEAD &&
+ ! test -f file3 &&
+ ! test -f file2 &&
+ git diff --exit-code --cached
'
test_expect_success '--keep fails with added/deleted merge' '
- git reset --hard third &&
- rm -f file2 &&
- test_must_fail git merge branch3 &&
- ! test -f file2 &&
- test -f file3 &&
- git diff --exit-code file3 &&
- git diff --exit-code branch3 file3 &&
- test_must_fail git reset --keep HEAD 2>err.log &&
- test_i18ngrep "middle of a merge" err.log
+ git reset --hard third &&
+ rm -f file2 &&
+ test_must_fail git merge branch3 &&
+ ! test -f file2 &&
+ test -f file3 &&
+ git diff --exit-code file3 &&
+ git diff --exit-code branch3 file3 &&
+ test_must_fail git reset --keep HEAD 2>err.log &&
+ test_i18ngrep "middle of a merge" err.log
'
test_done
diff --git a/t/t7111-reset-table.sh b/t/t7111-reset-table.sh
index 78f25c1c7e..01b7c3503c 100755
--- a/t/t7111-reset-table.sh
+++ b/t/t7111-reset-table.sh
@@ -10,9 +10,9 @@ TEST_PASSES_SANITIZE_LEAK=true
test_expect_success 'creating initial commits' '
- test_commit E file1 &&
- test_commit D file1 &&
- test_commit C file1
+ test_commit E file1 &&
+ test_commit D file1 &&
+ test_commit C file1
'
while read W1 I1 H1 T opt W2 I2 H2
@@ -74,13 +74,13 @@ B C C C keep B C C
EOF
test_expect_success 'setting up branches to test with unmerged entries' '
- git reset --hard C &&
- git branch branch1 &&
- git branch branch2 &&
- git checkout branch1 &&
- test_commit B1 file1 &&
- git checkout branch2 &&
- test_commit B file1
+ git reset --hard C &&
+ git branch branch1 &&
+ git branch branch2 &&
+ git checkout branch1 &&
+ test_commit B1 file1 &&
+ git checkout branch2 &&
+ test_commit B file1
'
while read W1 I1 H1 T opt W2 I2 H2
diff --git a/t/t7201-co.sh b/t/t7201-co.sh
index 61ad47b0c1..35b9e6ed6b 100755
--- a/t/t7201-co.sh
+++ b/t/t7201-co.sh
@@ -372,75 +372,75 @@ test_expect_success 'checkout specific path while in subdirectory' '
'
test_expect_success 'checkout w/--track sets up tracking' '
- git config branch.autosetupmerge false &&
- git checkout main &&
- git checkout --track -b track1 &&
- test "$(git config branch.track1.remote)" &&
- test "$(git config branch.track1.merge)"
+ git config branch.autosetupmerge false &&
+ git checkout main &&
+ git checkout --track -b track1 &&
+ test "$(git config branch.track1.remote)" &&
+ test "$(git config branch.track1.merge)"
'
test_expect_success 'checkout w/autosetupmerge=always sets up tracking' '
- test_when_finished git config branch.autosetupmerge false &&
- git config branch.autosetupmerge always &&
- git checkout main &&
- git checkout -b track2 &&
- test "$(git config branch.track2.remote)" &&
- test "$(git config branch.track2.merge)"
+ test_when_finished git config branch.autosetupmerge false &&
+ git config branch.autosetupmerge always &&
+ git checkout main &&
+ git checkout -b track2 &&
+ test "$(git config branch.track2.remote)" &&
+ test "$(git config branch.track2.merge)"
'
test_expect_success 'checkout w/--track from non-branch HEAD fails' '
- git checkout main^0 &&
- test_must_fail git symbolic-ref HEAD &&
- test_must_fail git checkout --track -b track &&
- test_must_fail git rev-parse --verify track &&
- test_must_fail git symbolic-ref HEAD &&
- test "z$(git rev-parse main^0)" = "z$(git rev-parse HEAD)"
+ git checkout main^0 &&
+ test_must_fail git symbolic-ref HEAD &&
+ test_must_fail git checkout --track -b track &&
+ test_must_fail git rev-parse --verify track &&
+ test_must_fail git symbolic-ref HEAD &&
+ test "z$(git rev-parse main^0)" = "z$(git rev-parse HEAD)"
'
test_expect_success 'checkout w/--track from tag fails' '
- git checkout main^0 &&
- test_must_fail git symbolic-ref HEAD &&
- test_must_fail git checkout --track -b track frotz &&
- test_must_fail git rev-parse --verify track &&
- test_must_fail git symbolic-ref HEAD &&
- test "z$(git rev-parse main^0)" = "z$(git rev-parse HEAD)"
+ git checkout main^0 &&
+ test_must_fail git symbolic-ref HEAD &&
+ test_must_fail git checkout --track -b track frotz &&
+ test_must_fail git rev-parse --verify track &&
+ test_must_fail git symbolic-ref HEAD &&
+ test "z$(git rev-parse main^0)" = "z$(git rev-parse HEAD)"
'
test_expect_success 'detach a symbolic link HEAD' '
- git checkout main &&
- git config --bool core.prefersymlinkrefs yes &&
- git checkout side &&
- git checkout main &&
- it=$(git symbolic-ref HEAD) &&
- test "z$it" = zrefs/heads/main &&
- here=$(git rev-parse --verify refs/heads/main) &&
- git checkout side^ &&
- test "z$(git rev-parse --verify refs/heads/main)" = "z$here"
+ git checkout main &&
+ git config --bool core.prefersymlinkrefs yes &&
+ git checkout side &&
+ git checkout main &&
+ it=$(git symbolic-ref HEAD) &&
+ test "z$it" = zrefs/heads/main &&
+ here=$(git rev-parse --verify refs/heads/main) &&
+ git checkout side^ &&
+ test "z$(git rev-parse --verify refs/heads/main)" = "z$here"
'
test_expect_success 'checkout with --track fakes a sensible -b <name>' '
- git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" &&
- git update-ref refs/remotes/origin/koala/bear renamer &&
+ git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" &&
+ git update-ref refs/remotes/origin/koala/bear renamer &&
- git checkout --track origin/koala/bear &&
- test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" &&
- test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" &&
+ git checkout --track origin/koala/bear &&
+ test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" &&
- git checkout main && git branch -D koala/bear &&
+ git checkout main && git branch -D koala/bear &&
- git checkout --track refs/remotes/origin/koala/bear &&
- test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" &&
- test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" &&
+ git checkout --track refs/remotes/origin/koala/bear &&
+ test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" &&
- git checkout main && git branch -D koala/bear &&
+ git checkout main && git branch -D koala/bear &&
- git checkout --track remotes/origin/koala/bear &&
- test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" &&
- test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)"
+ git checkout --track remotes/origin/koala/bear &&
+ test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" &&
+ test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)"
'
test_expect_success 'checkout with --track, but without -b, fails with too short tracked name' '
- test_must_fail git checkout --track renamer
+ test_must_fail git checkout --track renamer
'
setup_conflicting_index () {
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index eae6a46ef3..d9fbabb2b9 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -1351,6 +1351,22 @@ test_expect_success 'clone active submodule without submodule url set' '
)
'
+test_expect_success 'update submodules without url set in .gitconfig' '
+ test_when_finished "rm -rf multisuper_clone" &&
+ git clone file://"$pwd"/multisuper multisuper_clone &&
+
+ git -C multisuper_clone submodule init &&
+ for s in sub0 sub1 sub2 sub3
+ do
+ key=submodule.$s.url &&
+ git -C multisuper_clone config --local --unset $key &&
+ git -C multisuper_clone config --file .gitmodules --unset $key || return 1
+ done &&
+
+ test_must_fail git -C multisuper_clone submodule update 2>err &&
+ grep "cannot clone submodule .sub[0-3]. without a URL" err
+'
+
test_expect_success 'clone --recurse-submodules with a pathspec works' '
test_when_finished "rm -rf multisuper_clone" &&
cat >expected <<-\EOF &&
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index f094e3d7f3..00651c25cb 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -1179,4 +1179,27 @@ test_expect_success 'submodule update --recursive skip submodules with strategy=
test_cmp expect.err actual.err
'
+add_submodule_commit_and_validate () {
+ HASH=$(git rev-parse HEAD) &&
+ git update-index --add --cacheinfo 160000,$HASH,sub &&
+ git commit -m "create submodule" &&
+ echo "160000 commit $HASH sub" >expect &&
+ git ls-tree HEAD -- sub >actual &&
+ test_cmp expect actual
+}
+
+test_expect_success 'commit with staged submodule change' '
+ add_submodule_commit_and_validate
+'
+
+test_expect_success 'commit with staged submodule change with ignoreSubmodules dirty' '
+ test_config diff.ignoreSubmodules dirty &&
+ add_submodule_commit_and_validate
+'
+
+test_expect_success 'commit with staged submodule change with ignoreSubmodules all' '
+ test_config diff.ignoreSubmodules all &&
+ add_submodule_commit_and_validate
+'
+
test_done
diff --git a/t/t7502-commit-porcelain.sh b/t/t7502-commit-porcelain.sh
index 38a532d81c..b5bf7de7cd 100755
--- a/t/t7502-commit-porcelain.sh
+++ b/t/t7502-commit-porcelain.sh
@@ -466,6 +466,25 @@ test_expect_success 'commit --trailer with -c and command' '
test_cmp expected actual
'
+test_expect_success 'commit --trailer not confused by --- separator' '
+ cat >msg <<-\EOF &&
+ subject
+
+ body with dashes
+ ---
+ in it
+ EOF
+ git commit --allow-empty --trailer="my-trailer: value" -F msg &&
+ {
+ cat msg &&
+ echo &&
+ echo "my-trailer: value"
+ } >expected &&
+ git cat-file commit HEAD >commit.msg &&
+ sed -e "1,/^\$/d" commit.msg >actual &&
+ test_cmp expected actual
+'
+
test_expect_success 'multiple -m' '
>negative &&
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index aed07c5b62..6928fd89f5 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -5,6 +5,7 @@
test_description='git status'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-terminal.sh
@@ -91,7 +92,7 @@ test_expect_success 'status --column' '
# On branch main
# Your branch and '\''upstream'\'' have diverged,
# and have 1 and 2 different commits each, respectively.
-# (use "git pull" to merge the remote branch into yours)
+# (use "git pull" if you want to integrate the remote branch with yours)
#
# Changes to be committed:
# (use "git restore --staged <file>..." to unstage)
@@ -122,7 +123,7 @@ cat >expect <<\EOF
# On branch main
# Your branch and 'upstream' have diverged,
# and have 1 and 2 different commits each, respectively.
-# (use "git pull" to merge the remote branch into yours)
+# (use "git pull" if you want to integrate the remote branch with yours)
#
# Changes to be committed:
# (use "git restore --staged <file>..." to unstage)
@@ -269,7 +270,7 @@ test_expect_success 'status with gitignore' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
+ (use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@@ -334,7 +335,7 @@ test_expect_success 'status with gitignore (nothing untracked)' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
+ (use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@@ -404,7 +405,7 @@ test_expect_success 'status -uno' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
+ (use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@@ -466,7 +467,7 @@ test_expect_success 'status -unormal' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
+ (use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@@ -521,7 +522,7 @@ test_expect_success 'status -uall' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
+ (use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@@ -581,7 +582,7 @@ test_expect_success 'status with relative paths' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
+ (use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@@ -649,7 +650,7 @@ test_expect_success TTY 'status with color.ui' '
On branch <GREEN>main<RESET>
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
+ (use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@@ -772,7 +773,7 @@ test_expect_success 'status without relative paths' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
+ (use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@@ -846,7 +847,6 @@ test_expect_success 'dry-run of partial commit excluding new file in index' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@@ -900,7 +900,7 @@ test_expect_success 'status submodule summary is disabled by default' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
+ (use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@@ -957,7 +957,7 @@ test_expect_success 'status submodule summary' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
+ (use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@@ -1012,11 +1012,11 @@ test_expect_success 'status -s submodule summary' '
'
test_expect_success 'status submodule summary (clean submodule): commit' '
- cat >expect <<EOF &&
+ cat >expect-status <<EOF &&
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
+ (use "git pull" if you want to integrate the remote branch with yours)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
@@ -1032,12 +1032,13 @@ Untracked files:
no changes added to commit (use "git add" and/or "git commit -a")
EOF
+ sed "/git pull/d" expect-status > expect-commit &&
git commit -m "commit submodule" &&
git config status.submodulesummary 10 &&
test_must_fail git commit --dry-run >output &&
- test_cmp expect output &&
+ test_cmp expect-commit output &&
git status >output &&
- test_cmp expect output
+ test_cmp expect-status output
'
cat >expect <<EOF
@@ -1064,7 +1065,6 @@ test_expect_success 'commit --dry-run submodule summary (--amend)' '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git restore --source=HEAD^1 --staged <file>..." to unstage)
@@ -1116,7 +1116,7 @@ test_expect_success '--ignore-submodules=untracked suppresses submodules with un
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
+ (use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@@ -1225,7 +1225,7 @@ test_expect_success "--ignore-submodules=untracked doesn't suppress submodules w
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
+ (use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@@ -1282,7 +1282,7 @@ test_expect_success "--ignore-submodules=untracked doesn't suppress submodule su
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
+ (use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@@ -1363,7 +1363,7 @@ cat > expect << EOF
; On branch main
; Your branch and 'upstream' have diverged,
; and have 2 and 2 different commits each, respectively.
-; (use "git pull" to merge the remote branch into yours)
+; (use "git pull" if you want to integrate the remote branch with yours)
;
; Changes to be committed:
; (use "git restore --staged <file>..." to unstage)
@@ -1411,7 +1411,7 @@ test_expect_success "--ignore-submodules=all suppresses submodule summary" '
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
+ (use "git pull" if you want to integrate the remote branch with yours)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
@@ -1437,7 +1437,7 @@ test_expect_success '.gitmodules ignore=all suppresses unstaged submodule summar
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
+ (use "git pull" if you want to integrate the remote branch with yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
@@ -1519,8 +1519,8 @@ test_expect_success '"status.branch=true" weaker than "--no-branch"' '
'
test_expect_success '"status.branch=true" weaker than "--porcelain"' '
- git -c status.branch=true status --porcelain >actual &&
- test_cmp expected_nobranch actual
+ git -c status.branch=true status --porcelain >actual &&
+ test_cmp expected_nobranch actual
'
test_expect_success '"status.branch=false" same as "--no-branch"' '
@@ -1557,7 +1557,6 @@ test_expect_success 'git commit --dry-run will show a staged but ignored submodu
On branch main
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
- (use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
diff --git a/t/t7510-signed-commit.sh b/t/t7510-signed-commit.sh
index ccbc416402..0d2dd29fe6 100755
--- a/t/t7510-signed-commit.sh
+++ b/t/t7510-signed-commit.sh
@@ -218,6 +218,13 @@ test_expect_success GPG 'amending already signed commit' '
! grep "BAD signature from" actual
'
+test_expect_success GPG2 'bare signature' '
+ git verify-commit fifth-signed 2>expect &&
+ echo >>expect &&
+ git log -1 --format="%GG" fifth-signed >actual &&
+ test_cmp expect actual
+'
+
test_expect_success GPG 'show good signature with custom format' '
cat >expect <<-\EOF &&
G
diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh
index 2f16d5787e..c2ab8a444a 100755
--- a/t/t7512-status-help.sh
+++ b/t/t7512-status-help.sh
@@ -774,6 +774,28 @@ EOF
test_cmp expected actual
'
+test_expect_success 'status when cherry-picking multiple commits' '
+ git reset --hard cherry_branch &&
+ test_when_finished "git cherry-pick --abort" &&
+ test_must_fail git cherry-pick cherry_branch_second one_cherry &&
+ TO_CHERRY_PICK=$(git rev-parse --short CHERRY_PICK_HEAD) &&
+ cat >expected <<EOF &&
+On branch cherry_branch
+You are currently cherry-picking commit $TO_CHERRY_PICK.
+ (fix conflicts and run "git cherry-pick --continue")
+ (use "git cherry-pick --skip" to skip this patch)
+ (use "git cherry-pick --abort" to cancel the cherry-pick operation)
+
+Unmerged paths:
+ (use "git add <file>..." to mark resolution)
+ both modified: main.txt
+
+no changes added to commit (use "git add" and/or "git commit -a")
+EOF
+ git status --untracked-files=no >actual &&
+ test_cmp expected actual
+'
+
test_expect_success 'status when cherry-picking after committing conflict resolution' '
git reset --hard cherry_branch &&
test_when_finished "git cherry-pick --abort" &&
diff --git a/t/t7518-ident-corner-cases.sh b/t/t7518-ident-corner-cases.sh
index fffdb6ff2e..9ab2ae2f3b 100755
--- a/t/t7518-ident-corner-cases.sh
+++ b/t/t7518-ident-corner-cases.sh
@@ -20,10 +20,19 @@ test_expect_success 'empty name and missing email' '
'
test_expect_success 'commit rejects all-crud name' '
- test_must_fail env GIT_AUTHOR_NAME=" .;<>" \
+ test_must_fail env GIT_AUTHOR_NAME=" ,;<>" \
git commit --allow-empty -m foo
'
+test_expect_success 'commit does not strip trailing dot' '
+ author_name="Pat Doe Jr." &&
+ env GIT_AUTHOR_NAME="$author_name" \
+ git commit --allow-empty -m foo &&
+ git log -1 --format=%an >actual &&
+ echo "$author_name" >expected &&
+ test_cmp actual expected
+'
+
# We must test the actual error message here, as an unwanted
# auto-detection could fail for other reasons.
test_expect_success 'empty configured name does not auto-detect' '
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index 060e145957..fdc607277c 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -639,41 +639,41 @@ test_expect_success 'merge log message' '
test_debug 'git log --graph --decorate --oneline --all'
test_expect_success 'merge c1 with c0, c2, c0, and c1' '
- git reset --hard c1 &&
- test_tick &&
- git merge c0 c2 c0 c1 &&
- verify_merge file result.1-5 &&
- verify_parents $c1 $c2
+ git reset --hard c1 &&
+ test_tick &&
+ git merge c0 c2 c0 c1 &&
+ verify_merge file result.1-5 &&
+ verify_parents $c1 $c2
'
test_debug 'git log --graph --decorate --oneline --all'
test_expect_success 'merge c1 with c0, c2, c0, and c1' '
- git reset --hard c1 &&
- test_tick &&
- git merge c0 c2 c0 c1 &&
- verify_merge file result.1-5 &&
- verify_parents $c1 $c2
+ git reset --hard c1 &&
+ test_tick &&
+ git merge c0 c2 c0 c1 &&
+ verify_merge file result.1-5 &&
+ verify_parents $c1 $c2
'
test_debug 'git log --graph --decorate --oneline --all'
test_expect_success 'merge c1 with c1 and c2' '
- git reset --hard c1 &&
- test_tick &&
- git merge c1 c2 &&
- verify_merge file result.1-5 &&
- verify_parents $c1 $c2
+ git reset --hard c1 &&
+ test_tick &&
+ git merge c1 c2 &&
+ verify_merge file result.1-5 &&
+ verify_parents $c1 $c2
'
test_debug 'git log --graph --decorate --oneline --all'
test_expect_success 'merge fast-forward in a dirty tree' '
- git reset --hard c0 &&
- mv file file1 &&
- cat file1 >file &&
- rm -f file1 &&
- git merge c2
+ git reset --hard c0 &&
+ mv file file1 &&
+ cat file1 >file &&
+ rm -f file1 &&
+ git merge c2
'
test_debug 'git log --graph --decorate --oneline --all'
diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index faa739eeb9..27b66807cd 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -10,6 +10,10 @@ test_description='git repack works correctly'
commit_and_pack () {
test_commit "$@" 1>&2 &&
incrpackid=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
+ # Remove any loose object(s) created by test_commit, since they have
+ # already been packed. Leaving these around can create subtly different
+ # packs with `pack-objects`'s `--unpacked` option.
+ git prune-packed 1>&2 &&
echo pack-${incrpackid}.pack
}
@@ -209,6 +213,8 @@ test_expect_success 'repack --keep-pack' '
test_create_repo keep-pack &&
(
cd keep-pack &&
+ # avoid producing different packs due to delta/base choices
+ git config pack.window 0 &&
P1=$(commit_and_pack 1) &&
P2=$(commit_and_pack 2) &&
P3=$(commit_and_pack 3) &&
@@ -220,10 +226,61 @@ test_expect_success 'repack --keep-pack' '
grep -q $P1 new-counts &&
grep -q $P4 new-counts &&
test_line_count = 3 new-counts &&
+ git fsck &&
+
+ P5=$(commit_and_pack --no-tag 5) &&
+ git reset --hard HEAD^ &&
+ git reflog expire --all --expire=all &&
+ rm -f ".git/objects/pack/${P5%.pack}.idx" &&
+ rm -f ".git/objects/info/commit-graph" &&
+ for from in $(find .git/objects/pack -type f -name "${P5%.pack}.*")
+ do
+ to="$(dirname "$from")/.tmp-1234-$(basename "$from")" &&
+ mv "$from" "$to" || return 1
+ done &&
+
+ # A .idx file without a .pack should not stop us from
+ # repacking what we can.
+ touch .git/objects/pack/pack-does-not-exist.idx &&
+
+ git repack --cruft -d --keep-pack $P1 --keep-pack $P4 &&
+
+ ls .git/objects/pack/*.pack >newer-counts &&
+ test_cmp new-counts newer-counts &&
git fsck
)
'
+test_expect_success 'repacking fails when missing .pack actually means missing objects' '
+ test_create_repo idx-without-pack &&
+ (
+ cd idx-without-pack &&
+
+ # Avoid producing different packs due to delta/base choices
+ git config pack.window 0 &&
+ P1=$(commit_and_pack 1) &&
+ P2=$(commit_and_pack 2) &&
+ P3=$(commit_and_pack 3) &&
+ P4=$(commit_and_pack 4) &&
+ ls .git/objects/pack/*.pack >old-counts &&
+ test_line_count = 4 old-counts &&
+
+ # Remove one .pack file
+ rm .git/objects/pack/$P2 &&
+
+ ls .git/objects/pack/*.pack >before-pack-dir &&
+
+ test_must_fail git fsck &&
+ test_must_fail git repack --cruft -d 2>err &&
+ grep "bad object" err &&
+
+ # Before failing, the repack did not modify the
+ # pack directory.
+ ls .git/objects/pack/*.pack >after-pack-dir &&
+ test_cmp before-pack-dir after-pack-dir
+ )
+'
+
test_expect_success 'bitmaps are created by default in bare repos' '
git clone --bare .git bare.git &&
rm -f bare.git/objects/pack/*.bitmap &&
@@ -460,10 +517,10 @@ test_expect_success '--write-midx -b packs non-kept objects' '
'
test_expect_success '--write-midx removes stale pack-based bitmaps' '
- rm -fr repo &&
- git init repo &&
- test_when_finished "rm -fr repo" &&
- (
+ rm -fr repo &&
+ git init repo &&
+ test_when_finished "rm -fr repo" &&
+ (
cd repo &&
test_commit base &&
GIT_TEST_MULTI_PACK_INDEX=0 git repack -Ab &&
@@ -477,7 +534,7 @@ test_expect_success '--write-midx removes stale pack-based bitmaps' '
test_path_is_file $midx &&
test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
test_path_is_missing $pack_bitmap
- )
+ )
'
test_expect_success '--write-midx with --pack-kept-objects' '
diff --git a/t/t7701-repack-unpack-unreachable.sh b/t/t7701-repack-unpack-unreachable.sh
index ebb267855f..fe6c3e77a3 100755
--- a/t/t7701-repack-unpack-unreachable.sh
+++ b/t/t7701-repack-unpack-unreachable.sh
@@ -113,6 +113,48 @@ test_expect_success 'do not bother loosening old objects' '
test_must_fail git cat-file -p $obj2
'
+test_expect_success 'gc.recentObjectsHook' '
+ obj1=$(echo one | git hash-object -w --stdin) &&
+ obj2=$(echo two | git hash-object -w --stdin) &&
+ obj3=$(echo three | git hash-object -w --stdin) &&
+ pack1=$(echo $obj1 | git pack-objects .git/objects/pack/pack) &&
+ pack2=$(echo $obj2 | git pack-objects .git/objects/pack/pack) &&
+ pack3=$(echo $obj3 | git pack-objects .git/objects/pack/pack) &&
+ git prune-packed &&
+
+ git cat-file -p $obj1 &&
+ git cat-file -p $obj2 &&
+ git cat-file -p $obj3 &&
+
+ # make an unreachable annotated tag object to ensure we rescue objects
+ # which are reachable from non-pruned unreachable objects
+ obj2_tag="$(git mktag <<-EOF
+ object $obj2
+ type blob
+ tag obj2-tag
+ tagger T A Gger <tagger@example.com> 1234567890 -0000
+ EOF
+ )" &&
+
+ obj2_tag_pack="$(echo $obj2_tag | git pack-objects .git/objects/pack/pack)" &&
+ git prune-packed &&
+
+ write_script precious-objects <<-EOF &&
+ echo $obj2_tag
+ EOF
+ git config gc.recentObjectsHook ./precious-objects &&
+
+ test-tool chmtime =-86400 .git/objects/pack/pack-$pack2.pack &&
+ test-tool chmtime =-86400 .git/objects/pack/pack-$pack3.pack &&
+ test-tool chmtime =-86400 .git/objects/pack/pack-$obj2_tag_pack.pack &&
+ git repack -A -d --unpack-unreachable=1.hour.ago &&
+
+ git cat-file -p $obj1 &&
+ git cat-file -p $obj2 &&
+ git cat-file -p $obj2_tag &&
+ test_must_fail git cat-file -p $obj3
+'
+
test_expect_success 'keep packed objects found only in index' '
echo my-unique-content >file &&
git add file &&
diff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh
index 8143817b19..d37c83b464 100755
--- a/t/t7814-grep-recurse-submodules.sh
+++ b/t/t7814-grep-recurse-submodules.sh
@@ -594,4 +594,44 @@ test_expect_success 'grep partially-cloned submodule' '
)
'
+test_expect_success 'check scope of core.useReplaceRefs' '
+ git init base &&
+ git init base/sub &&
+
+ echo A >base/a &&
+ echo B >base/b &&
+ echo C >base/sub/c &&
+ echo D >base/sub/d &&
+
+ git -C base/sub add c d &&
+ git -C base/sub commit -m "Add files" &&
+
+ git -C base submodule add ./sub &&
+ git -C base add a b sub &&
+ git -C base commit -m "Add files and submodule" &&
+
+ A=$(git -C base rev-parse HEAD:a) &&
+ B=$(git -C base rev-parse HEAD:b) &&
+ C=$(git -C base/sub rev-parse HEAD:c) &&
+ D=$(git -C base/sub rev-parse HEAD:d) &&
+
+ git -C base replace $A $B &&
+ git -C base/sub replace $C $D &&
+
+ test_must_fail git -C base grep --cached --recurse-submodules A &&
+ test_must_fail git -C base grep --cached --recurse-submodules C &&
+
+ git -C base config core.useReplaceRefs false &&
+ git -C base grep --recurse-submodules A &&
+ test_must_fail git -C base grep --cached --recurse-submodules C &&
+
+ git -C base/sub config core.useReplaceRefs false &&
+ git -C base grep --cached --recurse-submodules A &&
+ git -C base grep --cached --recurse-submodules C &&
+
+ git -C base config --unset core.useReplaceRefs &&
+ test_must_fail git -C base grep --cached --recurse-submodules A &&
+ git -C base grep --cached --recurse-submodules C
+'
+
test_done
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 22fc908024..48bf0af2ee 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -4,7 +4,7 @@ test_description='git send-email'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
-# no longer TEST_PASSES_SANITIZE_LEAK=true - format-patch --thread leaks
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
# May be altered later in the test
diff --git a/t/t9100-git-svn-basic.sh b/t/t9100-git-svn-basic.sh
index fea41b3c36..af28b01fef 100755
--- a/t/t9100-git-svn-basic.sh
+++ b/t/t9100-git-svn-basic.sh
@@ -21,7 +21,7 @@ test_expect_success 'git svn help works anywhere' '
'
test_expect_success \
- 'initialize git svn' '
+ 'initialize git svn' '
mkdir import &&
(
cd import &&
@@ -38,9 +38,9 @@ test_expect_success \
rm -rf import &&
git svn init "$svnrepo"'
-test_expect_success \
- 'import an SVN revision into git' \
- 'git svn fetch'
+test_expect_success 'import an SVN revision into git' '
+ git svn fetch
+'
test_expect_success "checkout from svn" 'svn co "$svnrepo" "$SVN_TREE"'
@@ -233,27 +233,26 @@ test_expect_success POSIXPERM,SYMLINKS "$name" '
'
test_expect_success 'exit if remote refs are ambigious' '
- git config --add svn-remote.svn.fetch \
+ git config --add svn-remote.svn.fetch \
bar:refs/remotes/git-svn &&
test_must_fail git svn migrate
'
test_expect_success 'exit if init-ing a would clobber a URL' '
- svnadmin create "${PWD}/svnrepo2" &&
- svn mkdir -m "mkdir bar" "${svnrepo}2/bar" &&
- git config --unset svn-remote.svn.fetch \
+ svnadmin create "${PWD}/svnrepo2" &&
+ svn mkdir -m "mkdir bar" "${svnrepo}2/bar" &&
+ git config --unset svn-remote.svn.fetch \
"^bar:refs/remotes/git-svn$" &&
test_must_fail git svn init "${svnrepo}2/bar"
'
-test_expect_success \
- 'init allows us to connect to another directory in the same repo' '
- git svn init --minimize-url -i bar "$svnrepo/bar" &&
- git config --get svn-remote.svn.fetch \
- "^bar:refs/remotes/bar$" &&
- git config --get svn-remote.svn.fetch \
- "^:refs/remotes/git-svn$"
- '
+test_expect_success 'init allows us to connect to another directory in the same repo' '
+ git svn init --minimize-url -i bar "$svnrepo/bar" &&
+ git config --get svn-remote.svn.fetch \
+ "^bar:refs/remotes/bar$" &&
+ git config --get svn-remote.svn.fetch \
+ "^:refs/remotes/git-svn$"
+'
test_expect_success 'dcommit $rev does not clobber current branch' '
git svn fetch -i bar &&
diff --git a/t/t9104-git-svn-follow-parent.sh b/t/t9104-git-svn-follow-parent.sh
index 85d735861f..b5845e28fe 100755
--- a/t/t9104-git-svn-follow-parent.sh
+++ b/t/t9104-git-svn-follow-parent.sh
@@ -41,51 +41,51 @@ test_expect_success 'init and fetch a moved directory' '
'
test_expect_success 'init and fetch from one svn-remote' '
- git config svn-remote.svn.url "$svnrepo" &&
- git config --add svn-remote.svn.fetch \
- trunk:refs/remotes/svn/trunk &&
- git config --add svn-remote.svn.fetch \
- thunk:refs/remotes/svn/thunk &&
- git svn fetch -i svn/thunk &&
+ git config svn-remote.svn.url "$svnrepo" &&
+ git config --add svn-remote.svn.fetch \
+ trunk:refs/remotes/svn/trunk &&
+ git config --add svn-remote.svn.fetch \
+ thunk:refs/remotes/svn/thunk &&
+ git svn fetch -i svn/thunk &&
test "$(git rev-parse --verify refs/remotes/svn/trunk)" \
- = "$(git rev-parse --verify refs/remotes/svn/thunk~1)" &&
+ = "$(git rev-parse --verify refs/remotes/svn/thunk~1)" &&
git cat-file blob refs/remotes/svn/thunk:readme >actual &&
test "$(sed -n -e "3p" actual)" = goodbye
- '
+'
test_expect_success 'follow deleted parent' '
- (svn_cmd cp -m "resurrecting trunk as junk" \
- "$svnrepo"/trunk@2 "$svnrepo"/junk ||
- svn cp -m "resurrecting trunk as junk" \
- -r2 "$svnrepo"/trunk "$svnrepo"/junk) &&
- git config --add svn-remote.svn.fetch \
- junk:refs/remotes/svn/junk &&
- git svn fetch -i svn/thunk &&
- git svn fetch -i svn/junk &&
+ (svn_cmd cp -m "resurrecting trunk as junk" \
+ "$svnrepo"/trunk@2 "$svnrepo"/junk ||
+ svn cp -m "resurrecting trunk as junk" \
+ -r2 "$svnrepo"/trunk "$svnrepo"/junk) &&
+ git config --add svn-remote.svn.fetch \
+ junk:refs/remotes/svn/junk &&
+ git svn fetch -i svn/thunk &&
+ git svn fetch -i svn/junk &&
test -z "$(git diff svn/junk svn/trunk)" &&
test "$(git merge-base svn/junk svn/trunk)" \
- = "$(git rev-parse svn/trunk)"
- '
+ = "$(git rev-parse svn/trunk)"
+'
test_expect_success 'follow larger parent' '
- mkdir -p import/trunk/thunk/bump/thud &&
- echo hi > import/trunk/thunk/bump/thud/file &&
- svn import -m "import a larger parent" import "$svnrepo"/larger-parent &&
- svn cp -m "hi" "$svnrepo"/larger-parent "$svnrepo"/another-larger &&
- git svn init --minimize-url -i larger \
- "$svnrepo"/larger-parent/trunk/thunk/bump/thud &&
- git svn fetch -i larger &&
+ mkdir -p import/trunk/thunk/bump/thud &&
+ echo hi > import/trunk/thunk/bump/thud/file &&
+ svn import -m "import a larger parent" import "$svnrepo"/larger-parent &&
+ svn cp -m "hi" "$svnrepo"/larger-parent "$svnrepo"/another-larger &&
+ git svn init --minimize-url -i larger \
+ "$svnrepo"/larger-parent/trunk/thunk/bump/thud &&
+ git svn fetch -i larger &&
git svn init --minimize-url -i larger-parent \
- "$svnrepo"/another-larger/trunk/thunk/bump/thud &&
+ "$svnrepo"/another-larger/trunk/thunk/bump/thud &&
git svn fetch -i larger-parent &&
- git rev-parse --verify refs/remotes/larger &&
- git rev-parse --verify \
- refs/remotes/larger-parent &&
+ git rev-parse --verify refs/remotes/larger &&
+ git rev-parse --verify \
+ refs/remotes/larger-parent &&
test "$(git merge-base \
refs/remotes/larger-parent \
refs/remotes/larger)" = \
- "$(git rev-parse refs/remotes/larger)"
- '
+ "$(git rev-parse refs/remotes/larger)"
+'
test_expect_success 'follow higher-level parent' '
svn mkdir -m "follow higher-level parent" "$svnrepo"/blob &&
diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh
index c5946cb0b8..a44eabf0d8 100755
--- a/t/t9200-git-cvsexportcommit.sh
+++ b/t/t9200-git-cvsexportcommit.sh
@@ -50,56 +50,56 @@ check_entries () {
fi
}
-test_expect_success \
- 'New file' \
- 'mkdir A B C D E F &&
- echo hello1 >A/newfile1.txt &&
- echo hello2 >B/newfile2.txt &&
- cp "$TEST_DIRECTORY"/test-binary-1.png C/newfile3.png &&
- cp "$TEST_DIRECTORY"/test-binary-1.png D/newfile4.png &&
- git add A/newfile1.txt &&
- git add B/newfile2.txt &&
- git add C/newfile3.png &&
- git add D/newfile4.png &&
- git commit -a -m "Test: New file" &&
- id=$(git rev-list --max-count=1 HEAD) &&
- (cd "$CVSWORK" &&
- git cvsexportcommit -c $id &&
- check_entries A "newfile1.txt/1.1/" &&
- check_entries B "newfile2.txt/1.1/" &&
- check_entries C "newfile3.png/1.1/-kb" &&
- check_entries D "newfile4.png/1.1/-kb" &&
- test_cmp A/newfile1.txt ../A/newfile1.txt &&
- test_cmp B/newfile2.txt ../B/newfile2.txt &&
- test_cmp C/newfile3.png ../C/newfile3.png &&
- test_cmp D/newfile4.png ../D/newfile4.png
- )'
+test_expect_success 'New file' '
+ mkdir A B C D E F &&
+ echo hello1 >A/newfile1.txt &&
+ echo hello2 >B/newfile2.txt &&
+ cp "$TEST_DIRECTORY"/test-binary-1.png C/newfile3.png &&
+ cp "$TEST_DIRECTORY"/test-binary-1.png D/newfile4.png &&
+ git add A/newfile1.txt &&
+ git add B/newfile2.txt &&
+ git add C/newfile3.png &&
+ git add D/newfile4.png &&
+ git commit -a -m "Test: New file" &&
+ id=$(git rev-list --max-count=1 HEAD) &&
+ (cd "$CVSWORK" &&
+ git cvsexportcommit -c $id &&
+ check_entries A "newfile1.txt/1.1/" &&
+ check_entries B "newfile2.txt/1.1/" &&
+ check_entries C "newfile3.png/1.1/-kb" &&
+ check_entries D "newfile4.png/1.1/-kb" &&
+ test_cmp A/newfile1.txt ../A/newfile1.txt &&
+ test_cmp B/newfile2.txt ../B/newfile2.txt &&
+ test_cmp C/newfile3.png ../C/newfile3.png &&
+ test_cmp D/newfile4.png ../D/newfile4.png
+ )
+'
-test_expect_success \
- 'Remove two files, add two and update two' \
- 'echo Hello1 >>A/newfile1.txt &&
- rm -f B/newfile2.txt &&
- rm -f C/newfile3.png &&
- echo Hello5 >E/newfile5.txt &&
- cp "$TEST_DIRECTORY"/test-binary-2.png D/newfile4.png &&
- cp "$TEST_DIRECTORY"/test-binary-1.png F/newfile6.png &&
- git add E/newfile5.txt &&
- git add F/newfile6.png &&
- git commit -a -m "Test: Remove, add and update" &&
- id=$(git rev-list --max-count=1 HEAD) &&
- (cd "$CVSWORK" &&
- git cvsexportcommit -c $id &&
- check_entries A "newfile1.txt/1.2/" &&
- check_entries B "" &&
- check_entries C "" &&
- check_entries D "newfile4.png/1.2/-kb" &&
- check_entries E "newfile5.txt/1.1/" &&
- check_entries F "newfile6.png/1.1/-kb" &&
- test_cmp A/newfile1.txt ../A/newfile1.txt &&
- test_cmp D/newfile4.png ../D/newfile4.png &&
- test_cmp E/newfile5.txt ../E/newfile5.txt &&
- test_cmp F/newfile6.png ../F/newfile6.png
- )'
+test_expect_success 'Remove two files, add two and update two' '
+ echo Hello1 >>A/newfile1.txt &&
+ rm -f B/newfile2.txt &&
+ rm -f C/newfile3.png &&
+ echo Hello5 >E/newfile5.txt &&
+ cp "$TEST_DIRECTORY"/test-binary-2.png D/newfile4.png &&
+ cp "$TEST_DIRECTORY"/test-binary-1.png F/newfile6.png &&
+ git add E/newfile5.txt &&
+ git add F/newfile6.png &&
+ git commit -a -m "Test: Remove, add and update" &&
+ id=$(git rev-list --max-count=1 HEAD) &&
+ (cd "$CVSWORK" &&
+ git cvsexportcommit -c $id &&
+ check_entries A "newfile1.txt/1.2/" &&
+ check_entries B "" &&
+ check_entries C "" &&
+ check_entries D "newfile4.png/1.2/-kb" &&
+ check_entries E "newfile5.txt/1.1/" &&
+ check_entries F "newfile6.png/1.1/-kb" &&
+ test_cmp A/newfile1.txt ../A/newfile1.txt &&
+ test_cmp D/newfile4.png ../D/newfile4.png &&
+ test_cmp E/newfile5.txt ../E/newfile5.txt &&
+ test_cmp F/newfile6.png ../F/newfile6.png
+ )
+'
# Should fail (but only on the git cvsexportcommit stage)
test_expect_success \
@@ -129,67 +129,67 @@ test_expect_success \
# This test is here because a patch for only binary files will
# fail with gnu patch, so cvsexportcommit must handle that.
-test_expect_success \
- 'Remove only binary files' \
- 'git reset --hard HEAD^^ &&
- rm -f D/newfile4.png &&
- git commit -a -m "test: remove only a binary file" &&
- id=$(git rev-list --max-count=1 HEAD) &&
- (cd "$CVSWORK" &&
- git cvsexportcommit -c $id &&
- check_entries A "newfile1.txt/1.2/" &&
- check_entries B "" &&
- check_entries C "" &&
- check_entries D "" &&
- check_entries E "newfile5.txt/1.1/" &&
- check_entries F "newfile6.png/1.1/-kb" &&
- test_cmp A/newfile1.txt ../A/newfile1.txt &&
- test_cmp E/newfile5.txt ../E/newfile5.txt &&
- test_cmp F/newfile6.png ../F/newfile6.png
- )'
+test_expect_success 'Remove only binary files' '
+ git reset --hard HEAD^^ &&
+ rm -f D/newfile4.png &&
+ git commit -a -m "test: remove only a binary file" &&
+ id=$(git rev-list --max-count=1 HEAD) &&
+ (cd "$CVSWORK" &&
+ git cvsexportcommit -c $id &&
+ check_entries A "newfile1.txt/1.2/" &&
+ check_entries B "" &&
+ check_entries C "" &&
+ check_entries D "" &&
+ check_entries E "newfile5.txt/1.1/" &&
+ check_entries F "newfile6.png/1.1/-kb" &&
+ test_cmp A/newfile1.txt ../A/newfile1.txt &&
+ test_cmp E/newfile5.txt ../E/newfile5.txt &&
+ test_cmp F/newfile6.png ../F/newfile6.png
+ )
+'
-test_expect_success \
- 'Remove only a text file' \
- 'rm -f A/newfile1.txt &&
- git commit -a -m "test: remove only a binary file" &&
- id=$(git rev-list --max-count=1 HEAD) &&
- (cd "$CVSWORK" &&
- git cvsexportcommit -c $id &&
- check_entries A "" &&
- check_entries B "" &&
- check_entries C "" &&
- check_entries D "" &&
- check_entries E "newfile5.txt/1.1/" &&
- check_entries F "newfile6.png/1.1/-kb" &&
- test_cmp E/newfile5.txt ../E/newfile5.txt &&
- test_cmp F/newfile6.png ../F/newfile6.png
- )'
+test_expect_success 'Remove only a text file' '
+ rm -f A/newfile1.txt &&
+ git commit -a -m "test: remove only a binary file" &&
+ id=$(git rev-list --max-count=1 HEAD) &&
+ (cd "$CVSWORK" &&
+ git cvsexportcommit -c $id &&
+ check_entries A "" &&
+ check_entries B "" &&
+ check_entries C "" &&
+ check_entries D "" &&
+ check_entries E "newfile5.txt/1.1/" &&
+ check_entries F "newfile6.png/1.1/-kb" &&
+ test_cmp E/newfile5.txt ../E/newfile5.txt &&
+ test_cmp F/newfile6.png ../F/newfile6.png
+ )
+'
-test_expect_success \
- 'New file with spaces in file name' \
- 'mkdir "G g" &&
- echo ok then >"G g/with spaces.txt" &&
- git add "G g/with spaces.txt" && \
- cp "$TEST_DIRECTORY"/test-binary-1.png "G g/with spaces.png" && \
- git add "G g/with spaces.png" &&
- git commit -a -m "With spaces" &&
- id=$(git rev-list --max-count=1 HEAD) &&
- (cd "$CVSWORK" &&
- git cvsexportcommit -c $id &&
- check_entries "G g" "with spaces.png/1.1/-kb|with spaces.txt/1.1/"
- )'
+test_expect_success 'New file with spaces in file name' '
+ mkdir "G g" &&
+ echo ok then >"G g/with spaces.txt" &&
+ git add "G g/with spaces.txt" && \
+ cp "$TEST_DIRECTORY"/test-binary-1.png "G g/with spaces.png" && \
+ git add "G g/with spaces.png" &&
+ git commit -a -m "With spaces" &&
+ id=$(git rev-list --max-count=1 HEAD) &&
+ (cd "$CVSWORK" &&
+ git cvsexportcommit -c $id &&
+ check_entries "G g" "with spaces.png/1.1/-kb|with spaces.txt/1.1/"
+ )
+'
-test_expect_success \
- 'Update file with spaces in file name' \
- 'echo Ok then >>"G g/with spaces.txt" &&
- cat "$TEST_DIRECTORY"/test-binary-1.png >>"G g/with spaces.png" && \
- git add "G g/with spaces.png" &&
- git commit -a -m "Update with spaces" &&
- id=$(git rev-list --max-count=1 HEAD) &&
- (cd "$CVSWORK" &&
- git cvsexportcommit -c $id &&
- check_entries "G g" "with spaces.png/1.2/-kb|with spaces.txt/1.2/"
- )'
+test_expect_success 'Update file with spaces in file name' '
+ echo Ok then >>"G g/with spaces.txt" &&
+ cat "$TEST_DIRECTORY"/test-binary-1.png >>"G g/with spaces.png" && \
+ git add "G g/with spaces.png" &&
+ git commit -a -m "Update with spaces" &&
+ id=$(git rev-list --max-count=1 HEAD) &&
+ (cd "$CVSWORK" &&
+ git cvsexportcommit -c $id &&
+ check_entries "G g" "with spaces.png/1.2/-kb|with spaces.txt/1.2/"
+ )
+'
# Some filesystems mangle pathnames with UTF-8 characters --
# check and skip
@@ -202,68 +202,68 @@ if p="Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö" &&
then
# This test contains UTF-8 characters
-test_expect_success !MINGW \
- 'File with non-ascii file name' \
- 'mkdir -p Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö &&
- echo Foo >Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.txt &&
- git add Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.txt &&
- cp "$TEST_DIRECTORY"/test-binary-1.png Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.png &&
- git add Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.png &&
- git commit -a -m "Går det så går det" && \
- id=$(git rev-list --max-count=1 HEAD) &&
- (cd "$CVSWORK" &&
- git cvsexportcommit -v -c $id &&
- check_entries \
- "Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö" \
- "gårdetsågårdet.png/1.1/-kb|gårdetsågårdet.txt/1.1/"
- )'
+test_expect_success !MINGW 'File with non-ascii file name' '
+ mkdir -p Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö &&
+ echo Foo >Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.txt &&
+ git add Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.txt &&
+ cp "$TEST_DIRECTORY"/test-binary-1.png Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.png &&
+ git add Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.png &&
+ git commit -a -m "Går det så går det" && \
+ id=$(git rev-list --max-count=1 HEAD) &&
+ (cd "$CVSWORK" &&
+ git cvsexportcommit -v -c $id &&
+ check_entries \
+ "Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö" \
+ "gårdetsågårdet.png/1.1/-kb|gårdetsågårdet.txt/1.1/"
+ )
+'
fi
rm -fr tst
-test_expect_success \
- 'Mismatching patch should fail' \
- 'date >>"E/newfile5.txt" &&
- git add "E/newfile5.txt" &&
- git commit -a -m "Update one" &&
- date >>"E/newfile5.txt" &&
- git add "E/newfile5.txt" &&
- git commit -a -m "Update two" &&
- id=$(git rev-list --max-count=1 HEAD) &&
- (cd "$CVSWORK" &&
- test_must_fail git cvsexportcommit -c $id
- )'
-
-test_expect_success FILEMODE \
- 'Retain execute bit' \
- 'mkdir G &&
- echo executeon >G/on &&
- chmod +x G/on &&
- echo executeoff >G/off &&
- git add G/on &&
- git add G/off &&
- git commit -a -m "Execute test" &&
- (cd "$CVSWORK" &&
- git cvsexportcommit -c HEAD &&
- test -x G/on &&
- ! test -x G/off
- )'
+test_expect_success 'Mismatching patch should fail' '
+ date >>"E/newfile5.txt" &&
+ git add "E/newfile5.txt" &&
+ git commit -a -m "Update one" &&
+ date >>"E/newfile5.txt" &&
+ git add "E/newfile5.txt" &&
+ git commit -a -m "Update two" &&
+ id=$(git rev-list --max-count=1 HEAD) &&
+ (cd "$CVSWORK" &&
+ test_must_fail git cvsexportcommit -c $id
+ )
+'
+
+test_expect_success FILEMODE 'Retain execute bit' '
+ mkdir G &&
+ echo executeon >G/on &&
+ chmod +x G/on &&
+ echo executeoff >G/off &&
+ git add G/on &&
+ git add G/off &&
+ git commit -a -m "Execute test" &&
+ (cd "$CVSWORK" &&
+ git cvsexportcommit -c HEAD &&
+ test -x G/on &&
+ ! test -x G/off
+ )
+'
test_expect_success '-w option should work with relative GIT_DIR' '
- mkdir W &&
- echo foobar >W/file1.txt &&
- echo bazzle >W/file2.txt &&
- git add W/file1.txt &&
- git add W/file2.txt &&
- git commit -m "More updates" &&
- id=$(git rev-list --max-count=1 HEAD) &&
- (cd "$GIT_DIR" &&
- GIT_DIR=. git cvsexportcommit -w "$CVSWORK" -c $id &&
- check_entries "$CVSWORK/W" "file1.txt/1.1/|file2.txt/1.1/" &&
- test_cmp "$CVSWORK/W/file1.txt" ../W/file1.txt &&
- test_cmp "$CVSWORK/W/file2.txt" ../W/file2.txt
- )
+ mkdir W &&
+ echo foobar >W/file1.txt &&
+ echo bazzle >W/file2.txt &&
+ git add W/file1.txt &&
+ git add W/file2.txt &&
+ git commit -m "More updates" &&
+ id=$(git rev-list --max-count=1 HEAD) &&
+ (cd "$GIT_DIR" &&
+ GIT_DIR=. git cvsexportcommit -w "$CVSWORK" -c $id &&
+ check_entries "$CVSWORK/W" "file1.txt/1.1/|file2.txt/1.1/" &&
+ test_cmp "$CVSWORK/W/file1.txt" ../W/file1.txt &&
+ test_cmp "$CVSWORK/W/file2.txt" ../W/file2.txt
+ )
'
test_expect_success 'check files before directories' '
@@ -290,21 +290,20 @@ test_expect_success 'check files before directories' '
'
test_expect_success 're-commit a removed filename which remains in CVS attic' '
-
- (cd "$CVSWORK" &&
- echo >attic_gremlin &&
- cvs -Q add attic_gremlin &&
- cvs -Q ci -m "added attic_gremlin" &&
- rm attic_gremlin &&
- cvs -Q rm attic_gremlin &&
- cvs -Q ci -m "removed attic_gremlin") &&
-
- echo > attic_gremlin &&
- git add attic_gremlin &&
- git commit -m "Added attic_gremlin" &&
+ (cd "$CVSWORK" &&
+ echo >attic_gremlin &&
+ cvs -Q add attic_gremlin &&
+ cvs -Q ci -m "added attic_gremlin" &&
+ rm attic_gremlin &&
+ cvs -Q rm attic_gremlin &&
+ cvs -Q ci -m "removed attic_gremlin") &&
+
+ echo > attic_gremlin &&
+ git add attic_gremlin &&
+ git commit -m "Added attic_gremlin" &&
git cvsexportcommit -w "$CVSWORK" -c HEAD &&
- (cd "$CVSWORK" && cvs -Q update -d) &&
- test -f "$CVSWORK/attic_gremlin"
+ (cd "$CVSWORK" && cvs -Q update -d) &&
+ test -f "$CVSWORK/attic_gremlin"
'
# the state of the CVS sandbox may be indeterminate for ' space'
diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh
index 379b19f2f8..003c0b61d0 100755
--- a/t/t9400-git-cvsserver-server.sh
+++ b/t/t9400-git-cvsserver-server.sh
@@ -66,10 +66,11 @@ test_expect_success 'setup' '
# note that cvs doesn't accept absolute pathnames
# as argument to co -d
-test_expect_success 'basic checkout' \
- 'GIT_CONFIG="$git_config" cvs -Q co -d cvswork main &&
- test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | head -n 1))" = "empty/1.1/" &&
- test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | sed -ne \$p))" = "secondrootfile/1.1/"'
+test_expect_success 'basic checkout' '
+ GIT_CONFIG="$git_config" cvs -Q co -d cvswork main &&
+ test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | head -n 1))" = "empty/1.1/" &&
+ test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | sed -ne \$p))" = "secondrootfile/1.1/"
+'
#------------------------
# PSERVER AUTHENTICATION
@@ -115,35 +116,40 @@ Ah<Z:yZZ30 e
END VERIFICATION REQUEST
EOF
-test_expect_success 'pserver authentication' \
- 'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
- sed -ne \$p log | grep "^I LOVE YOU\$"'
+test_expect_success 'pserver authentication' '
+ cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
+ sed -ne \$p log | grep "^I LOVE YOU\$"
+'
-test_expect_success 'pserver authentication failure (non-anonymous user)' \
- 'if cat request-git | git-cvsserver pserver >log 2>&1
- then
- false
- else
- true
- fi &&
- sed -ne \$p log | grep "^I HATE YOU\$"'
+test_expect_success 'pserver authentication failure (non-anonymous user)' '
+ if cat request-git | git-cvsserver pserver >log 2>&1
+ then
+ false
+ else
+ true
+ fi &&
+ sed -ne \$p log | grep "^I HATE YOU\$"
+'
-test_expect_success 'pserver authentication success (non-anonymous user with password)' \
- 'cat login-git-ok | git-cvsserver pserver >log 2>&1 &&
- sed -ne \$p log | grep "^I LOVE YOU\$"'
+test_expect_success 'pserver authentication success (non-anonymous user with password)' '
+ cat login-git-ok | git-cvsserver pserver >log 2>&1 &&
+ sed -ne \$p log | grep "^I LOVE YOU\$"
+'
-test_expect_success 'pserver authentication (login)' \
- 'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
- sed -ne \$p log | grep "^I LOVE YOU\$"'
+test_expect_success 'pserver authentication (login)' '
+ cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
+ sed -ne \$p log | grep "^I LOVE YOU\$"
+'
-test_expect_success 'pserver authentication failure (login/non-anonymous user)' \
- 'if cat login-git | git-cvsserver pserver >log 2>&1
- then
- false
- else
- true
- fi &&
- sed -ne \$p log | grep "^I HATE YOU\$"'
+test_expect_success 'pserver authentication failure (login/non-anonymous user)' '
+ if cat login-git | git-cvsserver pserver >log 2>&1
+ then
+ false
+ else
+ true
+ fi &&
+ sed -ne \$p log | grep "^I HATE YOU\$"
+'
# misuse pserver authentication for testing of req_Root
@@ -165,36 +171,40 @@ END AUTH REQUEST
Root $WORKDIR
EOF
-test_expect_success 'req_Root failure (relative pathname)' \
- 'if cat request-relative | git-cvsserver pserver >log 2>&1
- then
- echo unexpected success
- false
- else
- true
- fi &&
- tail log | grep "^error 1 Root must be an absolute pathname$"'
+test_expect_success 'req_Root failure (relative pathname)' '
+ if cat request-relative | git-cvsserver pserver >log 2>&1
+ then
+ echo unexpected success
+ false
+ else
+ true
+ fi &&
+ tail log | grep "^error 1 Root must be an absolute pathname$"
+'
-test_expect_success 'req_Root failure (conflicting roots)' \
- 'cat request-conflict | git-cvsserver pserver >log 2>&1 &&
- tail log | grep "^error 1 Conflicting roots specified$"'
+test_expect_success 'req_Root failure (conflicting roots)' '
+ cat request-conflict | git-cvsserver pserver >log 2>&1 &&
+ tail log | grep "^error 1 Conflicting roots specified$"
+'
-test_expect_success 'req_Root (strict paths)' \
- 'cat request-anonymous | git-cvsserver --strict-paths pserver "$SERVERDIR" >log 2>&1 &&
- sed -ne \$p log | grep "^I LOVE YOU\$"'
+test_expect_success 'req_Root (strict paths)' '
+ cat request-anonymous | git-cvsserver --strict-paths pserver "$SERVERDIR" >log 2>&1 &&
+ sed -ne \$p log | grep "^I LOVE YOU\$"
+'
test_expect_success 'req_Root failure (strict-paths)' '
- ! cat request-anonymous |
- git-cvsserver --strict-paths pserver "$WORKDIR" >log 2>&1
+ ! cat request-anonymous |
+ git-cvsserver --strict-paths pserver "$WORKDIR" >log 2>&1
'
-test_expect_success 'req_Root (w/o strict-paths)' \
- 'cat request-anonymous | git-cvsserver pserver "$WORKDIR/" >log 2>&1 &&
- sed -ne \$p log | grep "^I LOVE YOU\$"'
+test_expect_success 'req_Root (w/o strict-paths)' '
+ cat request-anonymous | git-cvsserver pserver "$WORKDIR/" >log 2>&1 &&
+ sed -ne \$p log | grep "^I LOVE YOU\$"
+'
test_expect_success 'req_Root failure (w/o strict-paths)' '
- ! cat request-anonymous |
- git-cvsserver pserver "$WORKDIR/gitcvs" >log 2>&1
+ ! cat request-anonymous |
+ git-cvsserver pserver "$WORKDIR/gitcvs" >log 2>&1
'
cat >request-base <<EOF
@@ -206,27 +216,30 @@ END AUTH REQUEST
Root /gitcvs.git
EOF
-test_expect_success 'req_Root (base-path)' \
- 'cat request-base | git-cvsserver --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
- sed -ne \$p log | grep "^I LOVE YOU\$"'
+test_expect_success 'req_Root (base-path)' '
+ cat request-base | git-cvsserver --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
+ sed -ne \$p log | grep "^I LOVE YOU\$"
+'
test_expect_success 'req_Root failure (base-path)' '
- ! cat request-anonymous |
- git-cvsserver --strict-paths --base-path "$WORKDIR" pserver "$SERVERDIR" >log 2>&1
+ ! cat request-anonymous |
+ git-cvsserver --strict-paths --base-path "$WORKDIR" pserver "$SERVERDIR" >log 2>&1
'
GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false || exit 1
-test_expect_success 'req_Root (export-all)' \
- 'cat request-anonymous | git-cvsserver --export-all pserver "$WORKDIR" >log 2>&1 &&
- sed -ne \$p log | grep "^I LOVE YOU\$"'
+test_expect_success 'req_Root (export-all)' '
+ cat request-anonymous | git-cvsserver --export-all pserver "$WORKDIR" >log 2>&1 &&
+ sed -ne \$p log | grep "^I LOVE YOU\$"
+'
-test_expect_success 'req_Root failure (export-all w/o directory list)' \
- '! (cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 || false)'
+test_expect_success 'req_Root failure (export-all w/o directory list)' '
+ ! (cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 || false)'
-test_expect_success 'req_Root (everything together)' \
- 'cat request-base | git-cvsserver --export-all --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
- sed -ne \$p log | grep "^I LOVE YOU\$"'
+test_expect_success 'req_Root (everything together)' '
+ cat request-base | git-cvsserver --export-all --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
+ sed -ne \$p log | grep "^I LOVE YOU\$"
+'
GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true || exit 1
@@ -247,45 +260,49 @@ test_expect_success 'gitcvs.enabled = false' \
test ! -d cvswork2'
rm -fr cvswork2
-test_expect_success 'gitcvs.ext.enabled = true' \
- 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
- GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
- GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
- test_cmp cvswork cvswork2'
+test_expect_success 'gitcvs.ext.enabled = true' '
+ GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
+ GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
+ GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
+ test_cmp cvswork cvswork2
+'
rm -fr cvswork2
-test_expect_success 'gitcvs.ext.enabled = false' \
- 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
- GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
- if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1
- then
- echo unexpected cvs success
- false
- else
- true
- fi &&
- grep "GITCVS emulation disabled" cvs.log &&
- test ! -d cvswork2'
+test_expect_success 'gitcvs.ext.enabled = false' '
+ GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
+ GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
+ if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1
+ then
+ echo unexpected cvs success
+ false
+ else
+ true
+ fi &&
+ grep "GITCVS emulation disabled" cvs.log &&
+ test ! -d cvswork2
+'
rm -fr cvswork2
-test_expect_success 'gitcvs.dbname' \
- 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
- GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
- GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
- test_cmp cvswork cvswork2 &&
- test -f "$SERVERDIR/gitcvs.ext.main.sqlite" &&
- cmp "$SERVERDIR/gitcvs.main.sqlite" "$SERVERDIR/gitcvs.ext.main.sqlite"'
+test_expect_success 'gitcvs.dbname' '
+ GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
+ GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
+ GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
+ test_cmp cvswork cvswork2 &&
+ test -f "$SERVERDIR/gitcvs.ext.main.sqlite" &&
+ cmp "$SERVERDIR/gitcvs.main.sqlite" "$SERVERDIR/gitcvs.ext.main.sqlite"
+'
rm -fr cvswork2
-test_expect_success 'gitcvs.ext.dbname' \
- 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
- GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
- GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
- GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
- test_cmp cvswork cvswork2 &&
- test -f "$SERVERDIR/gitcvs1.ext.main.sqlite" &&
- test ! -f "$SERVERDIR/gitcvs2.ext.main.sqlite" &&
- cmp "$SERVERDIR/gitcvs.main.sqlite" "$SERVERDIR/gitcvs1.ext.main.sqlite"'
+test_expect_success 'gitcvs.ext.dbname' '
+ GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
+ GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
+ GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
+ GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
+ test_cmp cvswork cvswork2 &&
+ test -f "$SERVERDIR/gitcvs1.ext.main.sqlite" &&
+ test ! -f "$SERVERDIR/gitcvs2.ext.main.sqlite" &&
+ cmp "$SERVERDIR/gitcvs.main.sqlite" "$SERVERDIR/gitcvs1.ext.main.sqlite"
+'
#------------
@@ -299,109 +316,115 @@ GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
exit 1
-test_expect_success 'cvs update (create new file)' \
- 'echo testfile1 >testfile1 &&
- git add testfile1 &&
- git commit -q -m "Add testfile1" &&
- git push gitcvs.git >/dev/null &&
- cd cvswork &&
- GIT_CONFIG="$git_config" cvs -Q update &&
- test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
- test_cmp testfile1 ../testfile1'
+test_expect_success 'cvs update (create new file)' '
+ echo testfile1 >testfile1 &&
+ git add testfile1 &&
+ git commit -q -m "Add testfile1" &&
+ git push gitcvs.git >/dev/null &&
+ cd cvswork &&
+ GIT_CONFIG="$git_config" cvs -Q update &&
+ test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
+ test_cmp testfile1 ../testfile1
+'
cd "$WORKDIR"
-test_expect_success 'cvs update (update existing file)' \
- 'echo line 2 >>testfile1 &&
- git add testfile1 &&
- git commit -q -m "Append to testfile1" &&
- git push gitcvs.git >/dev/null &&
- cd cvswork &&
- GIT_CONFIG="$git_config" cvs -Q update &&
- test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
- test_cmp testfile1 ../testfile1'
+test_expect_success 'cvs update (update existing file)' '
+ echo line 2 >>testfile1 &&
+ git add testfile1 &&
+ git commit -q -m "Append to testfile1" &&
+ git push gitcvs.git >/dev/null &&
+ cd cvswork &&
+ GIT_CONFIG="$git_config" cvs -Q update &&
+ test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
+ test_cmp testfile1 ../testfile1
+'
cd "$WORKDIR"
#TODO: cvsserver doesn't support update w/o -d
test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" '
- mkdir test &&
- echo >test/empty &&
- git add test &&
- git commit -q -m "Single Subdirectory" &&
- git push gitcvs.git >/dev/null &&
- cd cvswork &&
- GIT_CONFIG="$git_config" cvs -Q update &&
- test ! -d test
+ mkdir test &&
+ echo >test/empty &&
+ git add test &&
+ git commit -q -m "Single Subdirectory" &&
+ git push gitcvs.git >/dev/null &&
+ cd cvswork &&
+ GIT_CONFIG="$git_config" cvs -Q update &&
+ test ! -d test
'
cd "$WORKDIR"
-test_expect_success 'cvs update (subdirectories)' \
- '(for dir in A A/B A/B/C A/D E; do
- mkdir $dir &&
- echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
- git add $dir || exit 1
- done) &&
- git commit -q -m "deep sub directory structure" &&
- git push gitcvs.git >/dev/null &&
- cd cvswork &&
- GIT_CONFIG="$git_config" cvs -Q update -d &&
- (for dir in A A/B A/B/C A/D E; do
- filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
- if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
- test_cmp "$dir/$filename" "../$dir/$filename"; then
- :
- else
- exit 1
- fi
- done)'
+test_expect_success 'cvs update (subdirectories)' '
+ (for dir in A A/B A/B/C A/D E; do
+ mkdir $dir &&
+ echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
+ git add $dir || exit 1
+ done) &&
+ git commit -q -m "deep sub directory structure" &&
+ git push gitcvs.git >/dev/null &&
+ cd cvswork &&
+ GIT_CONFIG="$git_config" cvs -Q update -d &&
+ (for dir in A A/B A/B/C A/D E; do
+ filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
+ if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
+ test_cmp "$dir/$filename" "../$dir/$filename"; then
+ :
+ else
+ exit 1
+ fi
+ done)
+'
cd "$WORKDIR"
-test_expect_success 'cvs update (delete file)' \
- 'git rm testfile1 &&
- git commit -q -m "Remove testfile1" &&
- git push gitcvs.git >/dev/null &&
- cd cvswork &&
- GIT_CONFIG="$git_config" cvs -Q update &&
- test -z "$(grep testfile1 CVS/Entries)" &&
- test ! -f testfile1'
+test_expect_success 'cvs update (delete file)' '
+ git rm testfile1 &&
+ git commit -q -m "Remove testfile1" &&
+ git push gitcvs.git >/dev/null &&
+ cd cvswork &&
+ GIT_CONFIG="$git_config" cvs -Q update &&
+ test -z "$(grep testfile1 CVS/Entries)" &&
+ test ! -f testfile1
+'
cd "$WORKDIR"
-test_expect_success 'cvs update (re-add deleted file)' \
- 'echo readded testfile >testfile1 &&
- git add testfile1 &&
- git commit -q -m "Re-Add testfile1" &&
- git push gitcvs.git >/dev/null &&
- cd cvswork &&
- GIT_CONFIG="$git_config" cvs -Q update &&
- test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
- test_cmp testfile1 ../testfile1'
+test_expect_success 'cvs update (re-add deleted file)' '
+ echo readded testfile >testfile1 &&
+ git add testfile1 &&
+ git commit -q -m "Re-Add testfile1" &&
+ git push gitcvs.git >/dev/null &&
+ cd cvswork &&
+ GIT_CONFIG="$git_config" cvs -Q update &&
+ test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
+ test_cmp testfile1 ../testfile1
+'
cd "$WORKDIR"
-test_expect_success 'cvs update (merge)' \
- 'echo Line 0 >expected &&
- for i in 1 2 3 4 5 6 7
- do
- echo Line $i >>merge &&
- echo Line $i >>expected || return 1
- done &&
- echo Line 8 >>expected &&
- git add merge &&
- git commit -q -m "Merge test (pre-merge)" &&
- git push gitcvs.git >/dev/null &&
- cd cvswork &&
- GIT_CONFIG="$git_config" cvs -Q update &&
- test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
- test_cmp merge ../merge &&
- ( echo Line 0 && cat merge ) >merge.tmp &&
- mv merge.tmp merge &&
- cd "$WORKDIR" &&
- echo Line 8 >>merge &&
- git add merge &&
- git commit -q -m "Merge test (merge)" &&
- git push gitcvs.git >/dev/null &&
- cd cvswork &&
- sleep 1 && touch merge &&
- GIT_CONFIG="$git_config" cvs -Q update &&
- test_cmp merge ../expected'
+test_expect_success 'cvs update (merge)' '
+ echo Line 0 >expected &&
+ for i in 1 2 3 4 5 6 7
+ do
+ echo Line $i >>merge &&
+ echo Line $i >>expected || return 1
+ done &&
+ echo Line 8 >>expected &&
+ git add merge &&
+ git commit -q -m "Merge test (pre-merge)" &&
+ git push gitcvs.git >/dev/null &&
+ cd cvswork &&
+ GIT_CONFIG="$git_config" cvs -Q update &&
+ test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
+ test_cmp merge ../merge &&
+ ( echo Line 0 && cat merge ) >merge.tmp &&
+ mv merge.tmp merge &&
+ cd "$WORKDIR" &&
+ echo Line 8 >>merge &&
+ git add merge &&
+ git commit -q -m "Merge test (merge)" &&
+ git push gitcvs.git >/dev/null &&
+ cd cvswork &&
+ sleep 1 && touch merge &&
+ GIT_CONFIG="$git_config" cvs -Q update &&
+ test_cmp merge ../expected
+'
cd "$WORKDIR"
@@ -418,55 +441,58 @@ do
echo Line $i >>expected.C
done
-test_expect_success 'cvs update (conflict merge)' \
- '( echo LINE 0 && cat merge ) >merge.tmp &&
- mv merge.tmp merge &&
- git add merge &&
- git commit -q -m "Merge test (conflict)" &&
- git push gitcvs.git >/dev/null &&
- cd cvswork &&
- GIT_CONFIG="$git_config" cvs -Q update &&
- test_cmp merge ../expected.C'
+test_expect_success 'cvs update (conflict merge)' '
+ ( echo LINE 0 && cat merge ) >merge.tmp &&
+ mv merge.tmp merge &&
+ git add merge &&
+ git commit -q -m "Merge test (conflict)" &&
+ git push gitcvs.git >/dev/null &&
+ cd cvswork &&
+ GIT_CONFIG="$git_config" cvs -Q update &&
+ test_cmp merge ../expected.C
+'
cd "$WORKDIR"
-test_expect_success 'cvs update (-C)' \
- 'cd cvswork &&
- GIT_CONFIG="$git_config" cvs -Q update -C &&
- test_cmp merge ../merge'
+test_expect_success 'cvs update (-C)' '
+ cd cvswork &&
+ GIT_CONFIG="$git_config" cvs -Q update -C &&
+ test_cmp merge ../merge
+'
cd "$WORKDIR"
-test_expect_success 'cvs update (merge no-op)' \
- 'echo Line 9 >>merge &&
- cp merge cvswork/merge &&
- git add merge &&
- git commit -q -m "Merge test (no-op)" &&
- git push gitcvs.git >/dev/null &&
- cd cvswork &&
- sleep 1 && touch merge &&
- GIT_CONFIG="$git_config" cvs -Q update &&
- test_cmp merge ../merge'
+test_expect_success 'cvs update (merge no-op)' '
+ echo Line 9 >>merge &&
+ cp merge cvswork/merge &&
+ git add merge &&
+ git commit -q -m "Merge test (no-op)" &&
+ git push gitcvs.git >/dev/null &&
+ cd cvswork &&
+ sleep 1 && touch merge &&
+ GIT_CONFIG="$git_config" cvs -Q update &&
+ test_cmp merge ../merge
+'
cd "$WORKDIR"
test_expect_success 'cvs update (-p)' '
- touch really-empty &&
- echo Line 1 > no-lf &&
- printf "Line 2" >> no-lf &&
- git add really-empty no-lf &&
- git commit -q -m "Update -p test" &&
- git push gitcvs.git >/dev/null &&
- cd cvswork &&
- GIT_CONFIG="$git_config" cvs update &&
- for i in merge no-lf empty really-empty; do
- GIT_CONFIG="$git_config" cvs update -p "$i" >$i.out &&
- test_cmp $i.out ../$i || return 1
- done
+ touch really-empty &&
+ echo Line 1 > no-lf &&
+ printf "Line 2" >> no-lf &&
+ git add really-empty no-lf &&
+ git commit -q -m "Update -p test" &&
+ git push gitcvs.git >/dev/null &&
+ cd cvswork &&
+ GIT_CONFIG="$git_config" cvs update &&
+ for i in merge no-lf empty really-empty; do
+ GIT_CONFIG="$git_config" cvs update -p "$i" >$i.out &&
+ test_cmp $i.out ../$i || return 1
+ done
'
cd "$WORKDIR"
test_expect_success 'cvs update (module list supports packed refs)' '
- GIT_DIR="$SERVERDIR" git pack-refs --all &&
- GIT_CONFIG="$git_config" cvs -n up -d 2> out &&
- grep "cvs update: New directory \`main'\''" < out
+ GIT_DIR="$SERVERDIR" git pack-refs --all &&
+ GIT_CONFIG="$git_config" cvs -n up -d 2> out &&
+ grep "cvs update: New directory \`main'\''" < out
'
#------------
@@ -475,30 +501,30 @@ test_expect_success 'cvs update (module list supports packed refs)' '
cd "$WORKDIR"
test_expect_success 'cvs status' '
- mkdir status.dir &&
- echo Line > status.dir/status.file &&
- echo Line > status.file &&
- git add status.dir status.file &&
- git commit -q -m "Status test" &&
- git push gitcvs.git >/dev/null &&
- cd cvswork &&
- GIT_CONFIG="$git_config" cvs update &&
- GIT_CONFIG="$git_config" cvs status | grep "^File: status.file" >../out &&
- test_line_count = 2 ../out
+ mkdir status.dir &&
+ echo Line > status.dir/status.file &&
+ echo Line > status.file &&
+ git add status.dir status.file &&
+ git commit -q -m "Status test" &&
+ git push gitcvs.git >/dev/null &&
+ cd cvswork &&
+ GIT_CONFIG="$git_config" cvs update &&
+ GIT_CONFIG="$git_config" cvs status | grep "^File: status.file" >../out &&
+ test_line_count = 2 ../out
'
cd "$WORKDIR"
test_expect_success 'cvs status (nonrecursive)' '
- cd cvswork &&
- GIT_CONFIG="$git_config" cvs status -l | grep "^File: status.file" >../out &&
- test_line_count = 1 ../out
+ cd cvswork &&
+ GIT_CONFIG="$git_config" cvs status -l | grep "^File: status.file" >../out &&
+ test_line_count = 1 ../out
'
cd "$WORKDIR"
test_expect_success 'cvs status (no subdirs in header)' '
- cd cvswork &&
- GIT_CONFIG="$git_config" cvs status | grep ^File: >../out &&
- ! grep / <../out
+ cd cvswork &&
+ GIT_CONFIG="$git_config" cvs status | grep ^File: >../out &&
+ ! grep / <../out
'
#------------
@@ -507,9 +533,9 @@ test_expect_success 'cvs status (no subdirs in header)' '
cd "$WORKDIR"
test_expect_success 'cvs co -c (shows module database)' '
- GIT_CONFIG="$git_config" cvs co -c > out &&
- grep "^main[ ][ ]*main$" <out &&
- ! grep -v "^main[ ][ ]*main$" <out
+ GIT_CONFIG="$git_config" cvs co -c > out &&
+ grep "^main[ ][ ]*main$" <out &&
+ ! grep -v "^main[ ][ ]*main$" <out
'
#------------
@@ -575,11 +601,11 @@ expectStat="$?"
cd "$WORKDIR"
test_expect_success 'cvs log' '
- cd cvswork &&
- test x"$expectStat" = x"0" &&
- GIT_CONFIG="$git_config" cvs log merge >../out &&
- sed -e "s%2[0-9][0-9][0-9]/[01][0-9]/[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]%__DATE__%" ../out > ../actual &&
- test_cmp ../expect ../actual
+ cd cvswork &&
+ test x"$expectStat" = x"0" &&
+ GIT_CONFIG="$git_config" cvs log merge >../out &&
+sed -e "s%2[0-9][0-9][0-9]/[01][0-9]/[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]%__DATE__%" ../out > ../actual &&
+ test_cmp ../expect ../actual
'
#------------
@@ -588,11 +614,11 @@ test_expect_success 'cvs log' '
cd "$WORKDIR"
test_expect_success 'cvs annotate' '
- cd cvswork &&
- GIT_CONFIG="$git_config" cvs annotate merge >../out &&
- sed -e "s/ .*//" ../out >../actual &&
- printf "1.%d\n" 3 1 1 1 1 1 1 1 2 4 >../expect &&
- test_cmp ../expect ../actual
+ cd cvswork &&
+ GIT_CONFIG="$git_config" cvs annotate merge >../out &&
+ sed -e "s/ .*//" ../out >../actual &&
+ printf "1.%d\n" 3 1 1 1 1 1 1 1 2 4 >../expect &&
+ test_cmp ../expect ../actual
'
#------------
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index d8a52334ee..2f8868caa1 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -542,8 +542,17 @@ test_config () {
config_dir=$1
shift
fi
- test_when_finished "test_unconfig ${config_dir:+-C '$config_dir'} '$1'" &&
- git ${config_dir:+-C "$config_dir"} config "$@"
+
+ # If --worktree is provided, use it to configure/unconfigure
+ is_worktree=
+ if test "$1" = --worktree
+ then
+ is_worktree=1
+ shift
+ fi
+
+ test_when_finished "test_unconfig ${config_dir:+-C '$config_dir'} ${is_worktree:+--worktree} '$1'" &&
+ git ${config_dir:+-C "$config_dir"} config ${is_worktree:+--worktree} "$@"
}
test_config_global () {
@@ -901,6 +910,15 @@ test_path_is_symlink () {
fi
}
+test_path_is_executable () {
+ test "$#" -ne 1 && BUG "1 param"
+ if ! test -x "$1"
+ then
+ echo "$1 is not executable"
+ false
+ fi
+}
+
# Check if the directory exists and is empty as expected, barf otherwise.
test_dir_is_empty () {
test "$#" -ne 1 && BUG "1 param"
diff --git a/tag.c b/tag.c
index 96dbd5b2d5..fc3834db46 100644
--- a/tag.c
+++ b/tag.c
@@ -2,7 +2,7 @@
#include "environment.h"
#include "tag.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "commit.h"
#include "tree.h"
#include "blob.h"
@@ -10,7 +10,6 @@
#include "gpg-interface.h"
#include "hex.h"
#include "packfile.h"
-#include "wrapper.h"
const char *tag_type = "tag";
diff --git a/tempfile.c b/tempfile.c
index 50c377134c..ecdebf1afb 100644
--- a/tempfile.c
+++ b/tempfile.c
@@ -43,10 +43,10 @@
*/
#include "git-compat-util.h"
+#include "abspath.h"
#include "path.h"
#include "tempfile.h"
#include "sigchain.h"
-#include "wrapper.h"
static VOLATILE_LIST_HEAD(tempfile_list);
diff --git a/tmp-objdir.c b/tmp-objdir.c
index c33a554f92..5f9074ad1c 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -5,12 +5,13 @@
#include "dir.h"
#include "environment.h"
#include "object-file.h"
+#include "path.h"
#include "sigchain.h"
#include "string-list.h"
#include "strbuf.h"
#include "strvec.h"
#include "quote.h"
-#include "object-store.h"
+#include "object-store-ll.h"
struct tmp_objdir {
struct strbuf path;
diff --git a/trace.c b/trace.c
index 592c141d78..971a68abe8 100644
--- a/trace.c
+++ b/trace.c
@@ -27,7 +27,6 @@
#include "quote.h"
#include "setup.h"
#include "trace.h"
-#include "wrapper.h"
struct trace_key trace_default_key = { "GIT_TRACE", 0, 0, 0 };
struct trace_key trace_perf_key = TRACE_KEY_INIT(PERFORMANCE);
diff --git a/trace2.c b/trace2.c
index 0efc4e7b95..6dc74dff4c 100644
--- a/trace2.c
+++ b/trace2.c
@@ -276,7 +276,6 @@ void trace2_cmd_exit_fl(const char *file, int line, int code)
if (!trace2_enabled)
return;
- trace_git_fsync_stats();
trace2_collect_process_info(TRACE2_PROCESS_INFO_EXIT);
tr2main_exit_code = code;
@@ -634,7 +633,7 @@ void trace2_thread_exit_fl(const char *file, int line)
}
void trace2_def_param_fl(const char *file, int line, const char *param,
- const char *value)
+ const char *value, const struct key_value_info *kvi)
{
struct tr2_tgt *tgt_j;
int j;
@@ -644,7 +643,7 @@ void trace2_def_param_fl(const char *file, int line, const char *param,
for_each_wanted_builtin (j, tgt_j)
if (tgt_j->pfn_param_fl)
- tgt_j->pfn_param_fl(file, line, param, value);
+ tgt_j->pfn_param_fl(file, line, param, value, kvi);
}
void trace2_def_repo_fl(const char *file, int line, struct repository *repo)
diff --git a/trace2.h b/trace2.h
index 4ced30c0db..40d8c2e02a 100644
--- a/trace2.h
+++ b/trace2.h
@@ -325,6 +325,7 @@ void trace2_thread_exit_fl(const char *file, int line);
#define trace2_thread_exit() trace2_thread_exit_fl(__FILE__, __LINE__)
+struct key_value_info;
/*
* Emits a "def_param" message containing a key/value pair.
*
@@ -334,7 +335,7 @@ void trace2_thread_exit_fl(const char *file, int line);
* `core.abbrev`, `status.showUntrackedFiles`, or `--no-ahead-behind`.
*/
void trace2_def_param_fl(const char *file, int line, const char *param,
- const char *value);
+ const char *value, const struct key_value_info *kvi);
#define trace2_def_param(param, value) \
trace2_def_param_fl(__FILE__, __LINE__, (param), (value))
@@ -540,7 +541,7 @@ void trace2_timer_stop(enum trace2_timer_id tid);
* elsewhere as array indexes).
*
* Any values added to this enum be also be added to the
- * `tr2_counter_metadata[]` in `trace2/tr2_tr2_ctr.c`.
+ * `tr2_counter_metadata[]` in `trace2/tr2_ctr.c`.
*/
enum trace2_counter_id {
/*
@@ -551,6 +552,12 @@ enum trace2_counter_id {
TRACE2_COUNTER_ID_TEST1 = 0, /* emits summary event only */
TRACE2_COUNTER_ID_TEST2, /* emits summary and thread events */
+ TRACE2_COUNTER_ID_PACKED_REFS_JUMPS, /* counts number of jumps */
+
+ /* counts number of fsyncs */
+ TRACE2_COUNTER_ID_FSYNC_WRITEOUT_ONLY,
+ TRACE2_COUNTER_ID_FSYNC_HARDWARE_FLUSH,
+
/* Add additional counter definitions before here. */
TRACE2_NUMBER_OF_COUNTERS
};
diff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c
index 78cfc15d52..d96d908bb9 100644
--- a/trace2/tr2_cfg.c
+++ b/trace2/tr2_cfg.c
@@ -4,6 +4,7 @@
#include "trace2.h"
#include "trace2/tr2_cfg.h"
#include "trace2/tr2_sysenv.h"
+#include "wildmatch.h"
static struct strbuf **tr2_cfg_patterns;
static int tr2_cfg_count_patterns;
@@ -99,7 +100,8 @@ struct tr2_cfg_data {
/*
* See if the given config key matches any of our patterns of interest.
*/
-static int tr2_cfg_cb(const char *key, const char *value, void *d)
+static int tr2_cfg_cb(const char *key, const char *value,
+ const struct config_context *ctx, void *d)
{
struct strbuf **s;
struct tr2_cfg_data *data = (struct tr2_cfg_data *)d;
@@ -108,7 +110,8 @@ static int tr2_cfg_cb(const char *key, const char *value, void *d)
struct strbuf *buf = *s;
int wm = wildmatch(buf->buf, key, WM_CASEFOLD);
if (wm == WM_MATCH) {
- trace2_def_param_fl(data->file, data->line, key, value);
+ trace2_def_param_fl(data->file, data->line, key, value,
+ ctx->kvi);
return 0;
}
}
@@ -126,8 +129,10 @@ void tr2_cfg_list_config_fl(const char *file, int line)
void tr2_list_env_vars_fl(const char *file, int line)
{
+ struct key_value_info kvi = KVI_INIT;
struct strbuf **s;
+ kvi_from_param(&kvi);
if (tr2_load_env_vars() <= 0)
return;
@@ -135,15 +140,19 @@ void tr2_list_env_vars_fl(const char *file, int line)
struct strbuf *buf = *s;
const char *val = getenv(buf->buf);
if (val && *val)
- trace2_def_param_fl(file, line, buf->buf, val);
+ trace2_def_param_fl(file, line, buf->buf, val, &kvi);
}
}
void tr2_cfg_set_fl(const char *file, int line, const char *key,
const char *value)
{
+ struct key_value_info kvi = KVI_INIT;
+ struct config_context ctx = {
+ .kvi = &kvi,
+ };
struct tr2_cfg_data data = { file, line };
if (tr2_cfg_load_patterns() > 0)
- tr2_cfg_cb(key, value, &data);
+ tr2_cfg_cb(key, value, &ctx, &data);
}
diff --git a/trace2/tr2_ctr.c b/trace2/tr2_ctr.c
index b342d3b1a3..87cf9034fb 100644
--- a/trace2/tr2_ctr.c
+++ b/trace2/tr2_ctr.c
@@ -27,6 +27,21 @@ static struct tr2_counter_metadata tr2_counter_metadata[TRACE2_NUMBER_OF_COUNTER
.name = "test2",
.want_per_thread_events = 1,
},
+ [TRACE2_COUNTER_ID_PACKED_REFS_JUMPS] = {
+ .category = "packed-refs",
+ .name = "jumps_made",
+ .want_per_thread_events = 0,
+ },
+ [TRACE2_COUNTER_ID_FSYNC_WRITEOUT_ONLY] = {
+ .category = "fsync",
+ .name = "writeout-only",
+ .want_per_thread_events = 0,
+ },
+ [TRACE2_COUNTER_ID_FSYNC_HARDWARE_FLUSH] = {
+ .category = "fsync",
+ .name = "hardware-flush",
+ .want_per_thread_events = 0,
+ },
/* Add additional metadata before here. */
};
diff --git a/trace2/tr2_sysenv.c b/trace2/tr2_sysenv.c
index 069786cb92..f26ec95ab4 100644
--- a/trace2/tr2_sysenv.c
+++ b/trace2/tr2_sysenv.c
@@ -57,7 +57,8 @@ static struct tr2_sysenv_entry tr2_sysenv_settings[] = {
};
/* clang-format on */
-static int tr2_sysenv_cb(const char *key, const char *value, void *d)
+static int tr2_sysenv_cb(const char *key, const char *value,
+ const struct config_context *ctx UNUSED, void *d)
{
int k;
diff --git a/trace2/tr2_tgt.h b/trace2/tr2_tgt.h
index bf8745c4f0..1f626cffea 100644
--- a/trace2/tr2_tgt.h
+++ b/trace2/tr2_tgt.h
@@ -69,8 +69,10 @@ typedef void(tr2_tgt_evt_exec_result_fl_t)(const char *file, int line,
uint64_t us_elapsed_absolute,
int exec_id, int code);
+struct key_value_info;
typedef void(tr2_tgt_evt_param_fl_t)(const char *file, int line,
- const char *param, const char *value);
+ const char *param, const char *value,
+ const struct key_value_info *kvi);
typedef void(tr2_tgt_evt_repo_fl_t)(const char *file, int line,
const struct repository *repo);
diff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c
index 2af53e5d4d..53091781ec 100644
--- a/trace2/tr2_tgt_event.c
+++ b/trace2/tr2_tgt_event.c
@@ -477,11 +477,11 @@ static void fn_exec_result_fl(const char *file, int line,
}
static void fn_param_fl(const char *file, int line, const char *param,
- const char *value)
+ const char *value, const struct key_value_info *kvi)
{
const char *event_name = "def_param";
struct json_writer jw = JSON_WRITER_INIT;
- enum config_scope scope = current_config_scope();
+ enum config_scope scope = kvi->scope;
const char *scope_name = config_scope_name(scope);
jw_object_begin(&jw, 0);
diff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c
index 1ebfb464d5..d25ea13164 100644
--- a/trace2/tr2_tgt_normal.c
+++ b/trace2/tr2_tgt_normal.c
@@ -297,10 +297,10 @@ static void fn_exec_result_fl(const char *file, int line,
}
static void fn_param_fl(const char *file, int line, const char *param,
- const char *value)
+ const char *value, const struct key_value_info *kvi)
{
struct strbuf buf_payload = STRBUF_INIT;
- enum config_scope scope = current_config_scope();
+ enum config_scope scope = kvi->scope;
const char *scope_name = config_scope_name(scope);
strbuf_addf(&buf_payload, "def_param scope:%s %s=%s", scope_name, param,
diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c
index 328e483a05..a6f9a8a193 100644
--- a/trace2/tr2_tgt_perf.c
+++ b/trace2/tr2_tgt_perf.c
@@ -439,12 +439,12 @@ static void fn_exec_result_fl(const char *file, int line,
}
static void fn_param_fl(const char *file, int line, const char *param,
- const char *value)
+ const char *value, const struct key_value_info *kvi)
{
const char *event_name = "def_param";
struct strbuf buf_payload = STRBUF_INIT;
struct strbuf scope_payload = STRBUF_INIT;
- enum config_scope scope = current_config_scope();
+ enum config_scope scope = kvi->scope;
const char *scope_name = config_scope_name(scope);
strbuf_addf(&buf_payload, "%s:%s", param, value);
diff --git a/trace2/tr2_tls.c b/trace2/tr2_tls.c
index 9f46ae12f5..601c9e5036 100644
--- a/trace2/tr2_tls.c
+++ b/trace2/tr2_tls.c
@@ -1,5 +1,4 @@
#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 a2c3ed6f28..f408f9b058 100644
--- a/trailer.c
+++ b/trailer.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
@@ -482,6 +481,7 @@ static struct {
};
static int git_trailer_default_config(const char *conf_key, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
const char *trailer_item, *variable_name;
@@ -514,6 +514,7 @@ static int git_trailer_default_config(const char *conf_key, const char *value,
}
static int git_trailer_config(const char *conf_key, const char *value,
+ const struct config_context *ctx UNUSED,
void *cb UNUSED)
{
const char *trailer_item, *variable_name;
diff --git a/transport-helper.c b/transport-helper.c
index 6b816940dc..49811ef176 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -8,6 +8,7 @@
#include "gettext.h"
#include "hex.h"
#include "object-name.h"
+#include "repository.h"
#include "revision.h"
#include "remote.h"
#include "string-list.h"
@@ -18,7 +19,6 @@
#include "refspec.h"
#include "transport-internal.h"
#include "protocol.h"
-#include "wrapper.h"
static int debug;
diff --git a/transport.c b/transport.c
index 67afdae57c..219af8fd50 100644
--- a/transport.c
+++ b/transport.c
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "advice.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "hex.h"
@@ -27,10 +26,9 @@
#include "transport-internal.h"
#include "protocol.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "color.h"
#include "bundle-uri.h"
-#include "wrapper.h"
static int transport_use_color = -1;
static char transport_colors[][COLOR_MAXLEN] = {
diff --git a/tree-diff.c b/tree-diff.c
index 20bb15f38d..8fc159b86e 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -4,6 +4,7 @@
#include "git-compat-util.h"
#include "diff.h"
#include "diffcore.h"
+#include "hash.h"
#include "tree.h"
#include "tree-walk.h"
@@ -316,7 +317,7 @@ static void skip_uninteresting(struct tree_desc *t, struct strbuf *base,
while (t->size) {
match = tree_entry_interesting(opt->repo->index, &t->entry,
- base, 0, &opt->pathspec);
+ base, &opt->pathspec);
if (match) {
if (match == all_entries_not_interesting)
t->size = 0;
diff --git a/tree-walk.c b/tree-walk.c
index d3c48e06df..29ead71be1 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -1,11 +1,10 @@
#include "git-compat-util.h"
#include "tree-walk.h"
-#include "alloc.h"
#include "dir.h"
#include "gettext.h"
#include "hex.h"
#include "object-file.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "trace2.h"
#include "tree.h"
#include "pathspec.h"
@@ -435,7 +434,7 @@ static inline int prune_traversal(struct index_state *istate,
if (still_interesting < 0)
return still_interesting;
return tree_entry_interesting(istate, e, base,
- 0, info->pathspec);
+ info->pathspec);
}
int traverse_trees(struct index_state *istate,
@@ -1016,17 +1015,17 @@ static int match_wildcard_base(const struct pathspec_item *item,
/*
* Is a tree entry interesting given the pathspec we have?
*
- * Pre-condition: either baselen == base_offset (i.e. empty path)
+ * Pre-condition: either baselen == 0 (i.e. empty path)
* or base[baselen-1] == '/' (i.e. with trailing slash).
*/
static enum interesting do_match(struct index_state *istate,
const struct name_entry *entry,
- struct strbuf *base, int base_offset,
+ struct strbuf *base,
const struct pathspec *ps,
int exclude)
{
int i;
- int pathlen, baselen = base->len - base_offset;
+ int pathlen, baselen = base->len;
enum interesting never_interesting = ps->has_wildcard ?
entry_not_interesting : all_entries_not_interesting;
@@ -1044,7 +1043,7 @@ static enum interesting do_match(struct index_state *istate,
!(ps->magic & PATHSPEC_MAXDEPTH) ||
ps->max_depth == -1)
return all_entries_interesting;
- return within_depth(base->buf + base_offset, baselen,
+ return within_depth(base->buf, baselen,
!!S_ISDIR(entry->mode),
ps->max_depth) ?
entry_interesting : entry_not_interesting;
@@ -1055,7 +1054,7 @@ static enum interesting do_match(struct index_state *istate,
for (i = ps->nr - 1; i >= 0; i--) {
const struct pathspec_item *item = ps->items+i;
const char *match = item->match;
- const char *base_str = base->buf + base_offset;
+ const char *base_str = base->buf;
int matchlen = item->len, matched = 0;
if ((!exclude && item->magic & PATHSPEC_EXCLUDE) ||
@@ -1148,9 +1147,9 @@ match_wildcards:
strbuf_add(base, entry->path, pathlen);
- if (!git_fnmatch(item, match, base->buf + base_offset,
+ if (!git_fnmatch(item, match, base->buf,
item->nowildcard_len)) {
- strbuf_setlen(base, base_offset + baselen);
+ strbuf_setlen(base, baselen);
goto interesting;
}
@@ -1162,13 +1161,13 @@ match_wildcards:
* be performed in the submodule itself.
*/
if (ps->recurse_submodules && S_ISGITLINK(entry->mode) &&
- !ps_strncmp(item, match, base->buf + base_offset,
+ !ps_strncmp(item, match, base->buf,
item->nowildcard_len)) {
- strbuf_setlen(base, base_offset + baselen);
+ strbuf_setlen(base, baselen);
goto interesting;
}
- strbuf_setlen(base, base_offset + baselen);
+ strbuf_setlen(base, baselen);
/*
* Match all directories. We'll try to match files
@@ -1204,9 +1203,9 @@ interesting:
return entry_interesting;
strbuf_add(base, entry->path, pathlen);
- ret = match_pathspec_attrs(istate, base->buf + base_offset,
- base->len - base_offset, item);
- strbuf_setlen(base, base_offset + baselen);
+ ret = match_pathspec_attrs(istate, base->buf,
+ base->len, item);
+ strbuf_setlen(base, baselen);
if (!ret)
continue;
}
@@ -1218,16 +1217,16 @@ interesting:
/*
* Is a tree entry interesting given the pathspec we have?
*
- * Pre-condition: either baselen == base_offset (i.e. empty path)
+ * Pre-condition: either baselen == 0 (i.e. empty path)
* or base[baselen-1] == '/' (i.e. with trailing slash).
*/
enum interesting tree_entry_interesting(struct index_state *istate,
const struct name_entry *entry,
- struct strbuf *base, int base_offset,
+ struct strbuf *base,
const struct pathspec *ps)
{
enum interesting positive, negative;
- positive = do_match(istate, entry, base, base_offset, ps, 0);
+ positive = do_match(istate, entry, base, ps, 0);
/*
* case | entry | positive | negative | result
@@ -1264,7 +1263,7 @@ enum interesting tree_entry_interesting(struct index_state *istate,
positive <= entry_not_interesting) /* #1, #2, #11, #12 */
return positive;
- negative = do_match(istate, entry, base, base_offset, ps, 1);
+ negative = do_match(istate, entry, base, ps, 1);
/* #8, #18 */
if (positive == all_entries_interesting &&
diff --git a/tree-walk.h b/tree-walk.h
index 01a9d8eb44..74cdceb3fe 100644
--- a/tree-walk.h
+++ b/tree-walk.h
@@ -224,7 +224,7 @@ enum interesting {
enum interesting tree_entry_interesting(struct index_state *istate,
const struct name_entry *,
- struct strbuf *, int,
+ struct strbuf *,
const struct pathspec *ps);
#endif
diff --git a/tree.c b/tree.c
index 0dd2029a8a..c745462f96 100644
--- a/tree.c
+++ b/tree.c
@@ -3,7 +3,7 @@
#include "hex.h"
#include "tree.h"
#include "object-name.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "blob.h"
#include "commit.h"
#include "tag.h"
@@ -32,7 +32,7 @@ int read_tree_at(struct repository *r,
while (tree_entry(&desc, &entry)) {
if (retval != all_entries_interesting) {
retval = tree_entry_interesting(r->index, &entry,
- base, 0, pathspec);
+ base, pathspec);
if (retval == all_entries_not_interesting)
break;
if (retval == entry_not_interesting)
diff --git a/unpack-trees.c b/unpack-trees.c
index e8c32a40dc..87517364dc 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "advice.h"
#include "strvec.h"
#include "repository.h"
@@ -7,6 +7,7 @@
#include "environment.h"
#include "gettext.h"
#include "hex.h"
+#include "name-hash.h"
#include "tree.h"
#include "tree-walk.h"
#include "cache-tree.h"
@@ -14,6 +15,7 @@
#include "progress.h"
#include "refs.h"
#include "attr.h"
+#include "read-cache.h"
#include "split-index.h"
#include "sparse-index.h"
#include "submodule.h"
@@ -21,7 +23,7 @@
#include "symlinks.h"
#include "trace2.h"
#include "fsmonitor.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "promisor-remote.h"
#include "entry.h"
#include "parallel-checkout.h"
diff --git a/unpack-trees.h b/unpack-trees.h
index 30622aeebf..9b827c307f 100644
--- a/unpack-trees.h
+++ b/unpack-trees.h
@@ -1,8 +1,8 @@
#ifndef UNPACK_TREES_H
#define UNPACK_TREES_H
-#include "cache.h"
#include "convert.h"
+#include "read-cache-ll.h"
#include "strvec.h"
#include "string-list.h"
#include "tree-walk.h"
diff --git a/upload-pack.c b/upload-pack.c
index d3312006a3..94751477ab 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -7,7 +7,7 @@
#include "pkt-line.h"
#include "sideband.h"
#include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "oid-array.h"
#include "tag.h"
#include "object.h"
@@ -32,7 +32,6 @@
#include "commit-graph.h"
#include "commit-reach.h"
#include "shallow.h"
-#include "wrapper.h"
#include "write-or-die.h"
/* Remember to update object flag allocation in object.h */
@@ -69,7 +68,7 @@ struct upload_pack_data {
struct object_array have_obj;
struct oid_array haves; /* v2 only */
struct string_list wanted_refs; /* v2 only */
- struct string_list hidden_refs;
+ struct strvec hidden_refs;
struct object_array shallows;
struct string_list deepen_not;
@@ -127,7 +126,7 @@ static void upload_pack_data_init(struct upload_pack_data *data)
{
struct string_list symref = STRING_LIST_INIT_DUP;
struct string_list wanted_refs = STRING_LIST_INIT_DUP;
- struct string_list hidden_refs = STRING_LIST_INIT_DUP;
+ struct strvec hidden_refs = STRVEC_INIT;
struct object_array want_obj = OBJECT_ARRAY_INIT;
struct object_array have_obj = OBJECT_ARRAY_INIT;
struct oid_array haves = OID_ARRAY_INIT;
@@ -162,7 +161,7 @@ static void upload_pack_data_clear(struct upload_pack_data *data)
{
string_list_clear(&data->symref, 1);
string_list_clear(&data->wanted_refs, 1);
- string_list_clear(&data->hidden_refs, 0);
+ strvec_clear(&data->hidden_refs);
object_array_clear(&data->want_obj);
object_array_clear(&data->have_obj);
oid_array_clear(&data->haves);
@@ -602,11 +601,36 @@ static int get_common_commits(struct upload_pack_data *data,
}
}
+static int allow_hidden_refs(enum allow_uor allow_uor)
+{
+ if ((allow_uor & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1)
+ return 1;
+ return !(allow_uor & (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1));
+}
+
+static void for_each_namespaced_ref_1(each_ref_fn fn,
+ struct upload_pack_data *data)
+{
+ const char **excludes = NULL;
+ /*
+ * If `data->allow_uor` allows fetching hidden refs, we need to
+ * mark all references (including hidden ones), to check in
+ * `is_our_ref()` below.
+ *
+ * Otherwise, we only care about whether each reference's object
+ * has the OUR_REF bit set or not, so do not need to visit
+ * hidden references.
+ */
+ if (allow_hidden_refs(data->allow_uor))
+ excludes = hidden_refs_to_excludes(&data->hidden_refs);
+
+ for_each_namespaced_ref(excludes, fn, data);
+}
+
+
static int is_our_ref(struct object *o, enum allow_uor allow_uor)
{
- int allow_hidden_ref = (allow_uor &
- (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1));
- return o->flags & ((allow_hidden_ref ? HIDDEN_REF : 0) | OUR_REF);
+ return o->flags & ((allow_hidden_refs(allow_uor) ? 0 : HIDDEN_REF) | OUR_REF);
}
/*
@@ -855,7 +879,7 @@ static void deepen(struct upload_pack_data *data, int depth)
* marked with OUR_REF.
*/
head_ref_namespaced(check_ref, data);
- for_each_namespaced_ref(check_ref, data);
+ for_each_namespaced_ref_1(check_ref, data);
get_reachable_list(data, &reachable_shallows);
result = get_shallow_commits(&reachable_shallows,
@@ -1170,7 +1194,7 @@ static void receive_needs(struct upload_pack_data *data,
/* return non-zero if the ref is hidden, otherwise 0 */
static int mark_our_ref(const char *refname, const char *refname_full,
- const struct object_id *oid, const struct string_list *hidden_refs)
+ const struct object_id *oid, const struct strvec *hidden_refs)
{
struct object *o = lookup_unknown_object(the_repository, oid);
@@ -1275,7 +1299,8 @@ static int find_symref(const char *refname,
}
static int parse_object_filter_config(const char *var, const char *value,
- struct upload_pack_data *data)
+ const struct key_value_info *kvi,
+ struct upload_pack_data *data)
{
struct strbuf buf = STRBUF_INIT;
const char *sub, *key;
@@ -1302,14 +1327,17 @@ static int parse_object_filter_config(const char *var, const char *value,
}
string_list_insert(&data->allowed_filters, buf.buf)->util =
(void *)(intptr_t)1;
- data->tree_filter_max_depth = git_config_ulong(var, value);
+ data->tree_filter_max_depth = git_config_ulong(var, value,
+ kvi);
}
strbuf_release(&buf);
return 0;
}
-static int upload_pack_config(const char *var, const char *value, void *cb_data)
+static int upload_pack_config(const char *var, const char *value,
+ const struct config_context *ctx,
+ void *cb_data)
{
struct upload_pack_data *data = cb_data;
@@ -1329,7 +1357,7 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
else
data->allow_uor &= ~ALLOW_ANY_SHA1;
} else if (!strcmp("uploadpack.keepalive", var)) {
- data->keepalive = git_config_int(var, value);
+ data->keepalive = git_config_int(var, value, ctx->kvi);
if (!data->keepalive)
data->keepalive = -1;
} else if (!strcmp("uploadpack.allowfilter", var)) {
@@ -1344,13 +1372,15 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
data->advertise_sid = git_config_bool(var, value);
}
- if (parse_object_filter_config(var, value, data) < 0)
+ if (parse_object_filter_config(var, value, ctx->kvi, data) < 0)
return -1;
return parse_hide_refs_config(var, value, "uploadpack", &data->hidden_refs);
}
-static int upload_pack_protected_config(const char *var, const char *value, void *cb_data)
+static int upload_pack_protected_config(const char *var, const char *value,
+ const struct config_context *ctx UNUSED,
+ void *cb_data)
{
struct upload_pack_data *data = cb_data;
@@ -1386,7 +1416,7 @@ void upload_pack(const int advertise_refs, const int stateless_rpc,
if (advertise_refs)
data.no_done = 1;
head_ref_namespaced(send_ref, &data);
- for_each_namespaced_ref(send_ref, &data);
+ for_each_namespaced_ref_1(send_ref, &data);
if (!data.sent_capabilities) {
const char *refname = "capabilities^{}";
write_v0_ref(&data, refname, refname, null_oid());
@@ -1400,7 +1430,7 @@ void upload_pack(const int advertise_refs, const int stateless_rpc,
packet_flush(1);
} else {
head_ref_namespaced(check_ref, &data);
- for_each_namespaced_ref(check_ref, &data);
+ for_each_namespaced_ref_1(check_ref, &data);
}
if (!advertise_refs) {
@@ -1465,7 +1495,7 @@ static int parse_want(struct packet_writer *writer, const char *line,
static int parse_want_ref(struct packet_writer *writer, const char *line,
struct string_list *wanted_refs,
- struct string_list *hidden_refs,
+ struct strvec *hidden_refs,
struct object_array *want_obj)
{
const char *refname_nons;
diff --git a/urlmatch.c b/urlmatch.c
index eba0bdd77f..1c45f23adf 100644
--- a/urlmatch.c
+++ b/urlmatch.c
@@ -551,7 +551,8 @@ static int cmp_matches(const struct urlmatch_item *a,
return 0;
}
-int urlmatch_config_entry(const char *var, const char *value, void *cb)
+int urlmatch_config_entry(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
struct string_list_item *item;
struct urlmatch_config *collect = cb;
@@ -565,7 +566,7 @@ int urlmatch_config_entry(const char *var, const char *value, void *cb)
if (!skip_prefix(var, collect->section, &key) || *(key++) != '.') {
if (collect->cascade_fn)
- return collect->cascade_fn(var, value, cb);
+ return collect->cascade_fn(var, value, ctx, cb);
return 0; /* not interested */
}
dot = strrchr(key, '.');
@@ -609,7 +610,7 @@ int urlmatch_config_entry(const char *var, const char *value, void *cb)
strbuf_addstr(&synthkey, collect->section);
strbuf_addch(&synthkey, '.');
strbuf_addstr(&synthkey, key);
- retval = collect->collect_fn(synthkey.buf, value, collect->cb);
+ retval = collect->collect_fn(synthkey.buf, value, ctx, collect->cb);
strbuf_release(&synthkey);
return retval;
diff --git a/urlmatch.h b/urlmatch.h
index 9f40b00bfb..5ba85cea13 100644
--- a/urlmatch.h
+++ b/urlmatch.h
@@ -2,6 +2,7 @@
#define URL_MATCH_H
#include "string-list.h"
+#include "config.h"
struct url_info {
/* normalized url on success, must be freed, otherwise NULL */
@@ -48,8 +49,8 @@ struct urlmatch_config {
const char *key;
void *cb;
- int (*collect_fn)(const char *var, const char *value, void *cb);
- int (*cascade_fn)(const char *var, const char *value, void *cb);
+ config_fn_t collect_fn;
+ config_fn_t cascade_fn;
/*
* Compare the two matches, the one just discovered and the existing
* best match and return a negative value if the found item is to be
@@ -70,7 +71,8 @@ struct urlmatch_config {
.vars = STRING_LIST_INIT_DUP, \
}
-int urlmatch_config_entry(const char *var, const char *value, void *cb);
+int urlmatch_config_entry(const char *var, const char *value,
+ const struct config_context *ctx, void *cb);
void urlmatch_config_release(struct urlmatch_config *config);
#endif /* URL_MATCH_H */
diff --git a/usage.c b/usage.c
index 46d99f8bd4..09f0ed509b 100644
--- a/usage.c
+++ b/usage.c
@@ -6,7 +6,6 @@
#include "git-compat-util.h"
#include "gettext.h"
#include "trace2.h"
-#include "wrapper.h"
static void vreportf(const char *prefix, const char *err, va_list params)
{
diff --git a/userdiff.c b/userdiff.c
index 664c7c1402..e399543823 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "userdiff.h"
#include "attr.h"
diff --git a/versioncmp.c b/versioncmp.c
index 74cc7c43f0..45e676cbca 100644
--- a/versioncmp.c
+++ b/versioncmp.c
@@ -1,5 +1,6 @@
#include "git-compat-util.h"
#include "config.h"
+#include "strbuf.h"
#include "string-list.h"
#include "versioncmp.h"
diff --git a/walker.c b/walker.c
index 24ff7dfdc2..65002a7220 100644
--- a/walker.c
+++ b/walker.c
@@ -3,8 +3,9 @@
#include "hex.h"
#include "walker.h"
#include "repository.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#include "commit.h"
+#include "strbuf.h"
#include "tree.h"
#include "tree-walk.h"
#include "tag.h"
diff --git a/worktree.c b/worktree.c
index b5ee71c5eb..b8cf29e6a1 100644
--- a/worktree.c
+++ b/worktree.c
@@ -1,8 +1,8 @@
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
+#include "path.h"
#include "repository.h"
#include "refs.h"
#include "setup.h"
@@ -11,7 +11,6 @@
#include "dir.h"
#include "wt-status.h"
#include "config.h"
-#include "wrapper.h"
void free_worktrees(struct worktree **worktrees)
{
@@ -806,7 +805,7 @@ int init_worktree_config(struct repository *r)
* If the extension is already enabled, then we can skip the
* upgrade process.
*/
- if (repository_format_worktree_config)
+ if (r->repository_format_worktree_config)
return 0;
if ((res = git_config_set_gently("extensions.worktreeConfig", "true")))
return error(_("failed to set extensions.worktreeConfig setting"));
@@ -835,7 +834,7 @@ int init_worktree_config(struct repository *r)
* Relocate that value to avoid breaking all worktrees with this
* upgrade to worktree config.
*/
- if (!git_configset_get_value(&cs, "core.worktree", &core_worktree)) {
+ if (!git_configset_get_value(&cs, "core.worktree", &core_worktree, NULL)) {
if ((res = move_config_setting("core.worktree", core_worktree,
common_config_file,
main_worktree_file)))
@@ -846,7 +845,7 @@ int init_worktree_config(struct repository *r)
* Ensure that we use worktree config for the remaining lifetime
* of the current process.
*/
- repository_format_worktree_config = 1;
+ r->repository_format_worktree_config = 1;
cleanup:
git_configset_clear(&cs);
diff --git a/wrapper.c b/wrapper.c
index 67f5f5dbe1..5160c9e28d 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -9,15 +9,11 @@
#include "repository.h"
#include "strbuf.h"
#include "trace2.h"
-#include "wrapper.h"
-
-static intmax_t count_fsync_writeout_only;
-static intmax_t count_fsync_hardware_flush;
#ifdef HAVE_RTLGENRANDOM
/* This is required to get access to RtlGenRandom. */
#define SystemFunction036 NTAPI SystemFunction036
-#include <NTSecAPI.h>
+#include <ntsecapi.h>
#undef SystemFunction036
#endif
@@ -552,7 +548,7 @@ int git_fsync(int fd, enum fsync_action action)
{
switch (action) {
case FSYNC_WRITEOUT_ONLY:
- count_fsync_writeout_only += 1;
+ trace2_counter_add(TRACE2_COUNTER_ID_FSYNC_WRITEOUT_ONLY, 1);
#ifdef __APPLE__
/*
@@ -584,7 +580,7 @@ int git_fsync(int fd, enum fsync_action action)
return -1;
case FSYNC_HARDWARE_FLUSH:
- count_fsync_hardware_flush += 1;
+ trace2_counter_add(TRACE2_COUNTER_ID_FSYNC_HARDWARE_FLUSH, 1);
/*
* On macOS, a special fcntl is required to really flush the
@@ -601,18 +597,6 @@ int git_fsync(int fd, enum fsync_action action)
}
}
-static void log_trace_fsync_if(const char *key, intmax_t value)
-{
- if (value)
- trace2_data_intmax("fsync", the_repository, key, value);
-}
-
-void trace_git_fsync_stats(void)
-{
- log_trace_fsync_if("fsync/writeout-only", count_fsync_writeout_only);
- log_trace_fsync_if("fsync/hardware-flush", count_fsync_hardware_flush);
-}
-
static int warn_if_unremovable(const char *op, const char *file, int rc)
{
int err;
diff --git a/wrapper.h b/wrapper.h
index f0c7d0616d..79a9c1b507 100644
--- a/wrapper.h
+++ b/wrapper.h
@@ -1,6 +1,42 @@
#ifndef WRAPPER_H
#define WRAPPER_H
+char *xstrdup(const char *str);
+void *xmalloc(size_t size);
+void *xmallocz(size_t size);
+void *xmallocz_gently(size_t size);
+void *xmemdupz(const void *data, size_t len);
+char *xstrndup(const char *str, size_t len);
+void *xrealloc(void *ptr, size_t size);
+void *xcalloc(size_t nmemb, size_t size);
+void xsetenv(const char *name, const char *value, int overwrite);
+void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
+const char *mmap_os_err(void);
+void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset);
+int xopen(const char *path, int flags, ...);
+ssize_t xread(int fd, void *buf, size_t len);
+ssize_t xwrite(int fd, const void *buf, size_t len);
+ssize_t xpread(int fd, void *buf, size_t len, off_t offset);
+int xdup(int fd);
+FILE *xfopen(const char *path, const char *mode);
+FILE *xfdopen(int fd, const char *mode);
+int xmkstemp(char *temp_filename);
+int xmkstemp_mode(char *temp_filename, int mode);
+char *xgetcwd(void);
+FILE *fopen_for_writing(const char *path);
+FILE *fopen_or_warn(const char *path, const char *mode);
+
+/*
+ * Like strncmp, but only return zero if s is NUL-terminated and exactly len
+ * characters long. If it is not, consider it greater than t.
+ */
+int xstrncmpz(const char *s, const char *t, size_t len);
+
+__attribute__((format (printf, 3, 4)))
+int xsnprintf(char *dst, size_t max, const char *fmt, ...);
+
+int xgethostname(char *buf, size_t len);
+
/* set default permissions by passing mode arguments to open(2) */
int git_mkstemps_mode(char *pattern, int suffix_len, int mode);
int git_mkstemp_mode(char *pattern, int mode);
@@ -33,4 +69,74 @@ void write_file(const char *path, const char *fmt, ...);
/* Return 1 if the file is empty or does not exists, 0 otherwise. */
int is_empty_or_missing_file(const char *filename);
+enum fsync_action {
+ FSYNC_WRITEOUT_ONLY,
+ FSYNC_HARDWARE_FLUSH
+};
+
+/*
+ * Issues an fsync against the specified file according to the specified mode.
+ *
+ * FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating
+ * systems to flush the OS cache without issuing a flush command to the storage
+ * controller. If those interfaces are unavailable, the function fails with
+ * ENOSYS.
+ *
+ * FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that
+ * changes are durable. It is not expected to fail.
+ */
+int git_fsync(int fd, enum fsync_action action);
+
+/*
+ * Preserves errno, prints a message, but gives no warning for ENOENT.
+ * Returns 0 on success, which includes trying to unlink an object that does
+ * not exist.
+ */
+int unlink_or_warn(const char *path);
+ /*
+ * Tries to unlink file. Returns 0 if unlink succeeded
+ * or the file already didn't exist. Returns -1 and
+ * appends a message to err suitable for
+ * 'error("%s", err->buf)' on error.
+ */
+int unlink_or_msg(const char *file, struct strbuf *err);
+/*
+ * Preserves errno, prints a message, but gives no warning for ENOENT.
+ * Returns 0 on success, which includes trying to remove a directory that does
+ * not exist.
+ */
+int rmdir_or_warn(const char *path);
+/*
+ * Calls the correct function out of {unlink,rmdir}_or_warn based on
+ * the supplied file mode.
+ */
+int remove_or_warn(unsigned int mode, const char *path);
+
+/*
+ * Call access(2), but warn for any error except "missing file"
+ * (ENOENT or ENOTDIR).
+ */
+#define ACCESS_EACCES_OK (1U << 0)
+int access_or_warn(const char *path, int mode, unsigned flag);
+int access_or_die(const char *path, int mode, unsigned flag);
+
+/* Warn on an inaccessible file if errno indicates this is an error */
+int warn_on_fopen_errors(const char *path);
+
+/*
+ * Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent
+ * may be racy. Do not use this as protection against an attacker who can
+ * simultaneously create paths.
+ */
+int open_nofollow(const char *path, int flags);
+
+void sleep_millisec(int millisec);
+
+/*
+ * Generate len bytes from the system cryptographically secure PRNG.
+ * Returns 0 on success and -1 on error, setting errno. The inability to
+ * satisfy the full request is an error.
+ */
+int csprng_bytes(void *buf, size_t len);
+
#endif /* WRAPPER_H */
diff --git a/write-or-die.c b/write-or-die.c
index cc9e0787a1..d8355c0c3e 100644
--- a/write-or-die.c
+++ b/write-or-die.c
@@ -1,7 +1,6 @@
#include "git-compat-util.h"
#include "config.h"
#include "run-command.h"
-#include "wrapper.h"
#include "write-or-die.h"
/*
diff --git a/wt-status.c b/wt-status.c
index 068b76ef6d..5b1378965c 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1,4 +1,4 @@
-#include "cache.h"
+#include "git-compat-util.h"
#include "advice.h"
#include "wt-status.h"
#include "object.h"
@@ -7,8 +7,10 @@
#include "diff.h"
#include "environment.h"
#include "gettext.h"
+#include "hash.h"
#include "hex.h"
#include "object-name.h"
+#include "path.h"
#include "revision.h"
#include "diffcore.h"
#include "quote.h"
@@ -18,6 +20,7 @@
#include "refs.h"
#include "submodule.h"
#include "column.h"
+#include "read-cache.h"
#include "setup.h"
#include "strbuf.h"
#include "trace.h"
@@ -1024,7 +1027,7 @@ static void wt_longstatus_print_submodule_summary(struct wt_status *s, int uncom
if (s->display_comment_prefix) {
size_t len;
summary_content = strbuf_detach(&summary, &len);
- strbuf_add_commented_lines(&summary, summary_content, len);
+ strbuf_add_commented_lines(&summary, summary_content, len, comment_line_char);
free(summary_content);
}
@@ -1099,8 +1102,8 @@ void wt_status_append_cut_line(struct strbuf *buf)
{
const char *explanation = _("Do not modify or remove the line above.\nEverything below it will be ignored.");
- strbuf_commented_addf(buf, "%s", cut_line);
- strbuf_add_commented_lines(buf, explanation, strlen(explanation));
+ strbuf_commented_addf(buf, comment_line_char, "%s", cut_line);
+ strbuf_add_commented_lines(buf, explanation, strlen(explanation), comment_line_char);
}
void wt_status_add_cut_line(FILE *fp)
@@ -1183,7 +1186,8 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
t_begin = getnanotime();
- if (!format_tracking_info(branch, &sb, s->ahead_behind_flags))
+ if (!format_tracking_info(branch, &sb, s->ahead_behind_flags,
+ !s->commit_template))
return;
if (advice_enabled(ADVICE_STATUS_AHEAD_BEHIND_WARNING) &&
@@ -1790,10 +1794,10 @@ void wt_status_get_state(struct repository *r,
oidcpy(&state->revert_head_oid, &oid);
}
if (!sequencer_get_last_command(r, &action)) {
- if (action == REPLAY_PICK) {
+ if (action == REPLAY_PICK && !state->cherry_pick_in_progress) {
state->cherry_pick_in_progress = 1;
oidcpy(&state->cherry_pick_head_oid, null_oid());
- } else {
+ } else if (action == REPLAY_REVERT && !state->revert_in_progress) {
state->revert_in_progress = 1;
oidcpy(&state->revert_head_oid, null_oid());
}
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 0460e03f5e..adcea109fa 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -1,7 +1,8 @@
#include "git-compat-util.h"
#include "config.h"
#include "hex.h"
-#include "object-store.h"
+#include "object-store-ll.h"
+#include "strbuf.h"
#include "xdiff-interface.h"
#include "xdiff/xtypes.h"
#include "xdiff/xdiffi.h"
@@ -307,7 +308,8 @@ int xdiff_compare_lines(const char *l1, long s1,
int git_xmerge_style = -1;
-int git_xmerge_config(const char *var, const char *value, void *cb)
+int git_xmerge_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb)
{
if (!strcmp(var, "merge.conflictstyle")) {
if (!value)
@@ -327,5 +329,5 @@ int git_xmerge_config(const char *var, const char *value, void *cb)
value, var);
return 0;
}
- return git_default_config(var, value, cb);
+ return git_default_config(var, value, ctx, cb);
}
diff --git a/xdiff-interface.h b/xdiff-interface.h
index 733c364d26..e6f80df046 100644
--- a/xdiff-interface.h
+++ b/xdiff-interface.h
@@ -50,7 +50,9 @@ int buffer_is_binary(const char *ptr, unsigned long size);
void xdiff_set_find_func(xdemitconf_t *xecfg, const char *line, int cflags);
void xdiff_clear_find_func(xdemitconf_t *xecfg);
-int git_xmerge_config(const char *var, const char *value, void *cb);
+struct config_context;
+int git_xmerge_config(const char *var, const char *value,
+ const struct config_context *ctx, void *cb);
extern int git_xmerge_style;
/*