diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 65af8d82ce..ad0e1905a5 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -448,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 "builtin.h", + approved headers currently include "cache.h", "builtin.h", "t/helper/test-tool.h", "xdiff/xinclude.h", or "reftable/system.h"). You do not have to include more than one of these. diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt index 200e628e30..eee513e86f 100644 --- a/Documentation/MyFirstObjectWalk.txt +++ b/Documentation/MyFirstObjectWalk.txt @@ -124,7 +124,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 `alloc.h` - this variable is +`alloc` is used by the `ALLOC_GROW` macro. Check `cache.h` - this variable is used to track the allocated size of the list. Per entry, we find: diff --git a/Documentation/technical/api-merge.txt b/Documentation/technical/api-merge.txt index c2ba01828c..487d4d83ff 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 merge-ll.h for details. +Check ll-merge.h for details. Low-level (single file) merge ----------------------------- -Check merge-ll.h for details. +Check ll-merge.h for details. diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index 4281396093..aa385137ad 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -4129,11 +4129,13 @@ 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 <>. -Also, we do not call it "cache" any more, but rather "index"; however, -the file is still called `read-cache.h`. +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. If you grasp the ideas in that initial commit, you should check out a -more recent version and skim `read-cache-ll.h`, `object.h` and `commit.h`. +more recent version and skim `cache.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 @@ -4144,11 +4146,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 `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). +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). Now is a good point to take a break to let this information sink in. diff --git a/Makefile b/Makefile index 045e2187c4..e440728c24 100644 --- a/Makefile +++ b/Makefile @@ -1051,6 +1051,7 @@ 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 @@ -1059,7 +1060,6 @@ 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,7 +1142,6 @@ 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 @@ -1952,7 +1951,7 @@ endif BASIC_CFLAGS += \ -DSHA1DC_NO_STANDARD_INCLUDES \ -DSHA1DC_INIT_SAFE_HASH_DEFAULT=0 \ - -DSHA1DC_CUSTOM_INCLUDE_SHA1_C="\"git-compat-util.h\"" \ + -DSHA1DC_CUSTOM_INCLUDE_SHA1_C="\"cache.h\"" \ -DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="\"git-compat-util.h\"" endif endif diff --git a/add-interactive.c b/add-interactive.c index add9a1ad43..de877ca052 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -1,14 +1,10 @@ -#include "git-compat-util.h" +#include "cache.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 53e3248295..8d770d203f 100644 --- a/add-patch.c +++ b/add-patch.c @@ -1,4 +1,4 @@ -#include "git-compat-util.h" +#include "cache.h" #include "add-interactive.h" #include "advice.h" #include "alloc.h" @@ -6,8 +6,6 @@ #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" diff --git a/apply.c b/apply.c index 8bd0109fcc..6212ab3a1b 100644 --- a/apply.c +++ b/apply.c @@ -7,12 +7,12 @@ * */ -#include "git-compat-util.h" +#include "cache.h" #include "abspath.h" #include "alloc.h" #include "base85.h" #include "config.h" -#include "object-store-ll.h" +#include "object-store.h" #include "blob.h" #include "delta.h" #include "diff.h" @@ -21,21 +21,17 @@ #include "gettext.h" #include "hex.h" #include "xdiff-interface.h" -#include "merge-ll.h" +#include "ll-merge.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" diff --git a/archive-tar.c b/archive-tar.c index fc06ff4c5d..4cd81d8161 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -9,7 +9,7 @@ #include "hex.h" #include "tar.h" #include "archive.h" -#include "object-store-ll.h" +#include "object-store.h" #include "streaming.h" #include "run-command.h" #include "write-or-die.h" diff --git a/archive-zip.c b/archive-zip.c index b438264096..d0d065a312 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-ll.h" +#include "object-store.h" #include "userdiff.h" #include "write-or-die.h" #include "xdiff-interface.h" diff --git a/archive.c b/archive.c index 1817cca9f4..2ea9cbef92 100644 --- a/archive.c +++ b/archive.c @@ -6,11 +6,10 @@ #include "environment.h" #include "gettext.h" #include "hex.h" -#include "path.h" #include "pretty.h" #include "setup.h" #include "refs.h" -#include "object-store-ll.h" +#include "object-store.h" #include "commit.h" #include "tree.h" #include "tree-walk.h" diff --git a/attr.c b/attr.c index 7d39ac4a29..d45d34058d 100644 --- a/attr.c +++ b/attr.c @@ -6,7 +6,7 @@ * an insanely large number of attributes. */ -#include "git-compat-util.h" +#include "cache.h" #include "alloc.h" #include "config.h" #include "environment.h" @@ -14,12 +14,10 @@ #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-ll.h" +#include "object-store.h" #include "setup.h" #include "thread-utils.h" #include "tree-walk.h" diff --git a/bisect.c b/bisect.c index 1be8e0a271..8d5f8e5885 100644 --- a/bisect.c +++ b/bisect.c @@ -18,8 +18,7 @@ #include "commit-slab.h" #include "commit-reach.h" #include "object-name.h" -#include "object-store-ll.h" -#include "path.h" +#include "object-store.h" #include "dir.h" static struct oid_array good_revs; diff --git a/blame.c b/blame.c index d12bd9f97b..b830654062 100644 --- a/blame.c +++ b/blame.c @@ -1,6 +1,6 @@ -#include "git-compat-util.h" +#include "cache.h" #include "refs.h" -#include "object-store-ll.h" +#include "object-store.h" #include "cache-tree.h" #include "mergesort.h" #include "convert.h" @@ -8,8 +8,6 @@ #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" diff --git a/blame.h b/blame.h index 31ddc85f19..b60d1d81e3 100644 --- a/blame.h +++ b/blame.h @@ -2,7 +2,6 @@ #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 cdf70b0ef0..d88f50a48a 100644 --- a/branch.c +++ b/branch.c @@ -6,7 +6,6 @@ #include "gettext.h" #include "hex.h" #include "object-name.h" -#include "path.h" #include "refs.h" #include "refspec.h" #include "remote.h" diff --git a/builtin.h b/builtin.h index d560baa661..cb0db67681 100644 --- a/builtin.h +++ b/builtin.h @@ -2,6 +2,9 @@ #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 b75c59d5a0..6137e7b4ad 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -4,9 +4,10 @@ * Copyright (C) 2006 Linus Torvalds */ #define USE_THE_INDEX_VARIABLE -#include "builtin.h" +#include "cache.h" #include "advice.h" #include "config.h" +#include "builtin.h" #include "lockfile.h" #include "editor.h" #include "dir.h" @@ -16,12 +17,8 @@ #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" @@ -39,6 +36,11 @@ 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; @@ -67,6 +69,95 @@ 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; @@ -549,9 +640,7 @@ 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(the_repository, prefix, - &pathspec, include_sparse, - flags); + exit_status |= add_files_to_cache(prefix, &pathspec, flags); if (add_new_files) exit_status |= add_files(&dir, flags); diff --git a/builtin/am.c b/builtin/am.c index a78daa6971..5c83f2e003 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -4,10 +4,11 @@ * Based on git-am.sh by Junio C Hamano. */ #define USE_THE_INDEX_VARIABLE -#include "builtin.h" +#include "cache.h" #include "abspath.h" #include "advice.h" #include "config.h" +#include "builtin.h" #include "editor.h" #include "environment.h" #include "exec-cmd.h" @@ -28,7 +29,6 @@ #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,7 +41,6 @@ #include "string-list.h" #include "packfile.h" #include "pager.h" -#include "path.h" #include "repository.h" #include "pretty.h" #include "wrapper.h" diff --git a/builtin/apply.c b/builtin/apply.c index c18b7ea5d3..e3ff02a09e 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -1,3 +1,4 @@ +#include "cache.h" #include "builtin.h" #include "gettext.h" #include "parse-options.h" diff --git a/builtin/archive.c b/builtin/archive.c index 90761fdfee..b0eaa3c14a 100644 --- a/builtin/archive.c +++ b/builtin/archive.c @@ -2,6 +2,7 @@ * 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 6478df3489..4812450c39 100644 --- a/builtin/bisect.c +++ b/builtin/bisect.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "cache.h" #include "copy.h" #include "environment.h" #include "gettext.h" @@ -11,7 +12,6 @@ #include "strvec.h" #include "run-command.h" #include "oid-array.h" -#include "path.h" #include "prompt.h" #include "quote.h" #include "revision.h" diff --git a/builtin/blame.c b/builtin/blame.c index e811e7fbfb..2df6039a6e 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -29,7 +29,7 @@ #include "dir.h" #include "progress.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" #include "pager.h" #include "blame.h" #include "refs.h" diff --git a/builtin/branch.c b/builtin/branch.c index b57e4c6e61..075e580d22 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -5,20 +5,20 @@ * Based on git-branch.sh by Junio C Hamano. */ -#include "builtin.h" +#include "cache.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" diff --git a/builtin/bundle.c b/builtin/bundle.c index 3f63631c03..44113389d7 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -6,6 +6,7 @@ #include "parse-options.h" #include "pkt-line.h" #include "repository.h" +#include "cache.h" #include "bundle.h" /* diff --git a/builtin/cat-file.c b/builtin/cat-file.c index ab8ac105e3..7ff56d5a78 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -4,10 +4,11 @@ * Copyright (C) Linus Torvalds, 2005 */ #define USE_THE_INDEX_VARIABLE -#include "builtin.h" +#include "cache.h" #include "alloc.h" #include "config.h" #include "convert.h" +#include "builtin.h" #include "diff.h" #include "environment.h" #include "gettext.h" @@ -21,7 +22,7 @@ #include "packfile.h" #include "object-file.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" #include "replace-object.h" #include "promisor-remote.h" #include "mailmap.h" diff --git a/builtin/check-attr.c b/builtin/check-attr.c index b22ff748c3..e27b86d150 100644 --- a/builtin/check-attr.c +++ b/builtin/check-attr.c @@ -1,5 +1,6 @@ #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 906cd96753..e4b78782a3 100644 --- a/builtin/check-ignore.c +++ b/builtin/check-ignore.c @@ -1,5 +1,6 @@ #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 b8a05b8e07..002d2941e9 100644 --- a/builtin/check-mailmap.c +++ b/builtin/check-mailmap.c @@ -4,7 +4,6 @@ #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 5eb6bdc3f6..57f0505070 100644 --- a/builtin/check-ref-format.c +++ b/builtin/check-ref-format.c @@ -2,8 +2,9 @@ * GIT - The information manager from hell */ -#include "builtin.h" +#include "cache.h" #include "refs.h" +#include "builtin.h" #include "setup.h" #include "strbuf.h" diff --git a/builtin/checkout--worker.c b/builtin/checkout--worker.c index c655dc4b13..2120dd1d30 100644 --- a/builtin/checkout--worker.c +++ b/builtin/checkout--worker.c @@ -6,7 +6,6 @@ #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 f62f13f2b5..9375a05539 100644 --- a/builtin/checkout-index.c +++ b/builtin/checkout-index.c @@ -16,9 +16,7 @@ #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 fd6ee8c272..715eeb5048 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -13,16 +13,13 @@ #include "gettext.h" #include "hex.h" #include "hook.h" -#include "merge-ll.h" +#include "ll-merge.h" #include "lockfile.h" #include "mem-pool.h" #include "merge-recursive.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.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" @@ -864,7 +861,7 @@ static int merge_working_tree(const struct checkout_opts *opts, * entries in the index. */ - add_files_to_cache(the_repository, NULL, NULL, 0, 0); + add_files_to_cache(NULL, NULL, 0); init_merge_options(&o, the_repository); o.verbosity = 0; work = write_in_core_index_as_tree(the_repository); diff --git a/builtin/clean.c b/builtin/clean.c index 1bb6b7965c..78852d28ce 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -9,12 +9,11 @@ #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" diff --git a/builtin/clone.c b/builtin/clone.c index 687a686269..15f9912b4c 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-ll.h" +#include "object-store.h" #include "tree.h" #include "tree-walk.h" #include "unpack-trees.h" @@ -39,7 +39,6 @@ #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" @@ -931,7 +930,6 @@ 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; @@ -1099,7 +1097,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, - do_not_override_repo_unix_permissions, INIT_DB_QUIET); + INIT_DB_QUIET); if (real_git_dir) { free((char *)git_dir); diff --git a/builtin/column.c b/builtin/column.c index ce13ff0baa..de623a16c2 100644 --- a/builtin/column.c +++ b/builtin/column.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "cache.h" #include "config.h" #include "gettext.h" #include "strbuf.h" diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 73dbcf9d20..dd732b3534 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -1,5 +1,4 @@ #include "builtin.h" -#include "commit.h" #include "config.h" #include "dir.h" #include "environment.h" @@ -9,7 +8,7 @@ #include "parse-options.h" #include "repository.h" #include "commit-graph.h" -#include "object-store-ll.h" +#include "object-store.h" #include "progress.h" #include "replace-object.h" #include "tag.h" diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index 02625e7176..d1d251c3de 100644 --- a/builtin/commit-tree.c +++ b/builtin/commit-tree.c @@ -3,15 +3,16 @@ * * Copyright (C) Linus Torvalds, 2005 */ -#include "builtin.h" +#include "cache.h" #include "config.h" #include "gettext.h" #include "hex.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.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 a9e8c62c85..65a5c0e29d 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -6,7 +6,7 @@ */ #define USE_THE_INDEX_VARIABLE -#include "builtin.h" +#include "cache.h" #include "advice.h" #include "config.h" #include "lockfile.h" @@ -15,6 +15,7 @@ #include "dir.h" #include "editor.h" #include "environment.h" +#include "builtin.h" #include "diff.h" #include "diffcore.h" #include "commit.h" @@ -29,9 +30,6 @@ #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" @@ -40,7 +38,6 @@ #include "gpg-interface.h" #include "column.h" #include "sequencer.h" -#include "sparse-index.h" #include "mailmap.h" #include "help.h" #include "commit-reach.h" @@ -450,8 +447,7 @@ 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(the_repository, also ? prefix : NULL, - &pathspec, 0, 0); + add_files_to_cache(also ? prefix : NULL, &pathspec, 0); refresh_cache_or_die(refresh_flags); cache_tree_update(&the_index, WRITE_TREE_SILENT); if (write_locked_index(&the_index, &index_lock, 0)) diff --git a/builtin/config.c b/builtin/config.c index 6599f88b24..d40fddb042 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -13,7 +13,6 @@ #include "path.h" #include "quote.h" #include "setup.h" -#include "strbuf.h" #include "worktree.h" #include "wrapper.h" diff --git a/builtin/count-objects.c b/builtin/count-objects.c index 97cdfb0ac5..f3d8f1bcbb 100644 --- a/builtin/count-objects.c +++ b/builtin/count-objects.c @@ -4,17 +4,17 @@ * Copyright (c) 2006 Junio C Hamano */ -#include "builtin.h" +#include "cache.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-ll.h" +#include "object-store.h" static unsigned long garbage; static off_t size_garbage; diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c index ff3a47badb..0ffacfdd83 100644 --- a/builtin/credential-cache.c +++ b/builtin/credential-cache.c @@ -2,7 +2,6 @@ #include "gettext.h" #include "parse-options.h" #include "path.h" -#include "strbuf.h" #include "wrapper.h" #include "write-or-die.h" diff --git a/builtin/describe.c b/builtin/describe.c index 7ce23e1b8e..55b4baaa22 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -1,5 +1,5 @@ #define USE_THE_INDEX_VARIABLE -#include "builtin.h" +#include "cache.h" #include "config.h" #include "environment.h" #include "gettext.h" @@ -9,20 +9,19 @@ #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-ll.h" +#include "object-store.h" #include "list-objects.h" #include "commit-slab.h" -#include "wildmatch.h" #define MAX_TAGS (FLAG_BITS - 1) diff --git a/builtin/diff-files.c b/builtin/diff-files.c index 50330b8dd2..360464e6ef 100644 --- a/builtin/diff-files.c +++ b/builtin/diff-files.c @@ -3,14 +3,13 @@ * * Copyright (C) Linus Torvalds, 2005 */ -#include "builtin.h" +#include "cache.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 9db7139b83..b9a19bb7d3 100644 --- a/builtin/diff-index.c +++ b/builtin/diff-index.c @@ -1,13 +1,11 @@ -#include "builtin.h" +#include "cache.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 d62caa6c8b..c0540317fb 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -1,15 +1,14 @@ #define USE_THE_INDEX_VARIABLE -#include "builtin.h" +#include "cache.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; diff --git a/builtin/diff.c b/builtin/diff.c index b19530c996..7b64659fe7 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 "builtin.h" +#include "cache.h" #include "config.h" #include "ewah/ewok.h" #include "lockfile.h" @@ -16,10 +16,9 @@ #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 e2c9ab7d5d..0049342f5c 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -12,23 +12,22 @@ * Copyright (C) 2016 Johannes Schindelin */ #define USE_THE_INDEX_VARIABLE -#include "builtin.h" +#include "cache.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-ll.h" +#include "object-store.h" #include "dir.h" #include "entry.h" #include "setup.h" diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 56dc69fac1..9a95f6a1a8 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -4,13 +4,14 @@ * 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-ll.h" +#include "object-store.h" #include "commit.h" #include "object.h" #include "tag.h" diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 2ee19c7373..bbd9b2b3e7 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "abspath.h" +#include "cache.h" #include "environment.h" #include "gettext.h" #include "hex.h" @@ -12,7 +13,6 @@ #include "commit.h" #include "delta.h" #include "pack.h" -#include "path.h" #include "refs.h" #include "csum-file.h" #include "quote.h" @@ -21,7 +21,7 @@ #include "packfile.h" #include "object-file.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" #include "mem-pool.h" #include "commit-reach.h" #include "khash.h" diff --git a/builtin/fetch.c b/builtin/fetch.c index 951a23d733..e3871048cf 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1,7 +1,7 @@ /* * "git fetch" */ -#include "builtin.h" +#include "cache.h" #include "advice.h" #include "config.h" #include "gettext.h" @@ -11,10 +11,11 @@ #include "refs.h" #include "refspec.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" #include "oidset.h" #include "oid-array.h" #include "commit.h" +#include "builtin.h" #include "string-list.h" #include "remote.h" #include "transport.h" @@ -28,7 +29,6 @@ #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" diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index 15409337f8..695fc8f4a5 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" diff --git a/builtin/for-each-repo.c b/builtin/for-each-repo.c index 28186b30f5..37daf7bec1 100644 --- a/builtin/for-each-repo.c +++ b/builtin/for-each-repo.c @@ -1,5 +1,6 @@ -#include "builtin.h" +#include "cache.h" #include "config.h" +#include "builtin.h" #include "gettext.h" #include "parse-options.h" #include "path.h" diff --git a/builtin/fsck.c b/builtin/fsck.c index fa26462337..d9aa4db828 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "cache.h" #include "gettext.h" #include "hex.h" #include "repository.h" @@ -20,13 +21,10 @@ #include "packfile.h" #include "object-file.h" #include "object-name.h" -#include "object-store-ll.h" -#include "path.h" -#include "read-cache-ll.h" +#include "object-store.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" diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c index 74d1d6a585..f6dd9a784c 100644 --- a/builtin/fsmonitor--daemon.c +++ b/builtin/fsmonitor--daemon.c @@ -5,17 +5,15 @@ #include "environment.h" #include "gettext.h" #include "parse-options.h" -#include "fsmonitor-ll.h" +#include "fsmonitor.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[] = { diff --git a/builtin/gc.c b/builtin/gc.c index 91eec7703a..f3942188a6 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -27,10 +27,9 @@ #include "commit-graph.h" #include "packfile.h" #include "object-file.h" -#include "object-store-ll.h" +#include "object-store.h" #include "pack.h" #include "pack-objects.h" -#include "path.h" #include "blob.h" #include "tree.h" #include "promisor-remote.h" diff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c index 9303e386cc..564cfcac4f 100644 --- a/builtin/get-tar-commit-id.c +++ b/builtin/get-tar-commit-id.c @@ -1,9 +1,10 @@ /* * Copyright (c) 2005, 2006 Rene Scharfe */ -#include "builtin.h" +#include "cache.h" #include "commit.h" #include "tar.h" +#include "builtin.h" #include "quote.h" #include "wrapper.h" diff --git a/builtin/grep.c b/builtin/grep.c index 72e70b3a48..b86c754def 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -3,7 +3,7 @@ * * Copyright (c) 2006 Junio C Hamano */ -#include "builtin.h" +#include "cache.h" #include "alloc.h" #include "gettext.h" #include "hex.h" @@ -14,6 +14,7 @@ #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" @@ -27,11 +28,9 @@ #include "submodule-config.h" #include "object-file.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.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; diff --git a/builtin/hash-object.c b/builtin/hash-object.c index 5ffec99dce..a380121166 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -10,13 +10,12 @@ #include "gettext.h" #include "hex.h" #include "object-file.h" -#include "object-store-ll.h" +#include "object-store.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 e93533fb09..d3cf4af3f6 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -1,8 +1,9 @@ /* * Builtin help command */ -#include "builtin.h" +#include "cache.h" #include "config.h" +#include "builtin.h" #include "exec-cmd.h" #include "gettext.h" #include "pager.h" diff --git a/builtin/hook.c b/builtin/hook.c index 09b51a6487..88051795c7 100644 --- a/builtin/hook.c +++ b/builtin/hook.c @@ -1,3 +1,4 @@ +#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 c1250b070f..d0d8067510 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -14,13 +14,12 @@ #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-ll.h" +#include "object-store.h" #include "oid-array.h" #include "replace-object.h" #include "promisor-remote.h" diff --git a/builtin/init-db.c b/builtin/init-db.c index 0d8bd4d721..aef4036105 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -3,18 +3,485 @@ * * Copyright (C) Linus Torvalds, 2005 */ -#include "builtin.h" +#include "cache.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 "strbuf.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; +} + static int guess_repository_type(const char *git_dir) { const char *slash; @@ -79,7 +546,6 @@ 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")), @@ -237,5 +703,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, init_shared_repository, flags); + initial_branch, flags); } diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index c5e8345265..107ac28f0e 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -5,6 +5,7 @@ * */ +#include "cache.h" #include "builtin.h" #include "gettext.h" #include "parse-options.h" diff --git a/builtin/log.c b/builtin/log.c index 89442dceda..c85f13a5d5 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -14,7 +14,7 @@ #include "refs.h" #include "object-file.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" #include "pager.h" #include "color.h" #include "commit.h" diff --git a/builtin/ls-files.c b/builtin/ls-files.c index c1ff79c559..72012c0f0f 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -5,12 +5,13 @@ * * Copyright (C) Linus Torvalds, 2005 */ -#include "builtin.h" +#include "cache.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" @@ -19,12 +20,9 @@ #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" @@ -545,6 +543,143 @@ 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 [] [...]"), NULL diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index fc76575430..cb6cb77e08 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "cache.h" #include "gettext.h" #include "hex.h" #include "transport.h" @@ -7,7 +8,6 @@ #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=]\n" diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 4e17f13648..077977a461 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -3,17 +3,17 @@ * * Copyright (C) Linus Torvalds, 2005 */ -#include "builtin.h" +#include "cache.h" #include "config.h" #include "gettext.h" #include "hex.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.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" diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c index 53b55dd71c..a032a1c388 100644 --- a/builtin/mailinfo.c +++ b/builtin/mailinfo.c @@ -2,8 +2,9 @@ * Another stupid program, this one parsing the headers of an * email to figure out authorship and subject */ -#include "builtin.h" +#include "cache.h" #include "abspath.h" +#include "builtin.h" #include "environment.h" #include "gettext.h" #include "utf8.h" diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c index 3af9ddb8ae..0b6193a091 100644 --- a/builtin/mailsplit.c +++ b/builtin/mailsplit.c @@ -4,6 +4,7 @@ * 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 e68b7fe45d..854019a32d 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -1,4 +1,5 @@ #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 d7eb4c6540..781818d08f 100644 --- a/builtin/merge-file.c +++ b/builtin/merge-file.c @@ -1,5 +1,6 @@ #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 270d5f644a..ab16e70f23 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -1,10 +1,8 @@ #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 932924e5d0..c2e519301e 100644 --- a/builtin/merge-ours.c +++ b/builtin/merge-ours.c @@ -10,7 +10,6 @@ #include "git-compat-util.h" #include "builtin.h" #include "diff.h" -#include "repository.h" static const char builtin_merge_ours_usage[] = "git merge-ours ... -- HEAD ..."; diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c index 3366699657..b9e980384a 100644 --- a/builtin/merge-recursive.c +++ b/builtin/merge-recursive.c @@ -1,3 +1,4 @@ +#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 6f7db436d2..4325897a80 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-ll.h" +#include "object-store.h" #include "parse-options.h" #include "repository.h" #include "blob.h" diff --git a/builtin/merge.c b/builtin/merge.c index 420e81008e..8da3e46abb 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -7,7 +7,7 @@ */ #define USE_THE_INDEX_VARIABLE -#include "builtin.h" +#include "cache.h" #include "abspath.h" #include "advice.h" #include "alloc.h" @@ -18,6 +18,7 @@ #include "hex.h" #include "object-name.h" #include "parse-options.h" +#include "builtin.h" #include "lockfile.h" #include "run-command.h" #include "hook.h" @@ -27,7 +28,6 @@ #include "refspec.h" #include "commit.h" #include "diffcore.h" -#include "path.h" #include "revision.h" #include "unpack-trees.h" #include "cache-tree.h" @@ -37,7 +37,6 @@ #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" diff --git a/builtin/mktag.c b/builtin/mktag.c index 43e2766db4..44fa56eff3 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -2,11 +2,10 @@ #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-ll.h" +#include "object-store.h" #include "fsck.h" #include "config.h" diff --git a/builtin/mktree.c b/builtin/mktree.c index 0eea810c7e..09a7bd5c5c 100644 --- a/builtin/mktree.c +++ b/builtin/mktree.c @@ -8,10 +8,9 @@ #include "gettext.h" #include "hex.h" #include "quote.h" -#include "strbuf.h" #include "tree.h" #include "parse-options.h" -#include "object-store-ll.h" +#include "object-store.h" static struct treeent { unsigned mode; diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index a31dde1db9..1b5083f8b2 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-ll.h" +#include "object-store.h" #define BUILTIN_MIDX_WRITE_USAGE \ N_("git multi-pack-index [] write [--preferred-pack=]" \ diff --git a/builtin/mv.c b/builtin/mv.c index ae462bd7d4..665bd27448 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -11,7 +11,6 @@ #include "config.h" #include "environment.h" #include "gettext.h" -#include "name-hash.h" #include "object-file.h" #include "pathspec.h" #include "lockfile.h" @@ -19,7 +18,6 @@ #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 c3b722b36f..4d15a23fc4 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -15,7 +15,6 @@ #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 0a19796f73..d5788352b6 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -7,15 +7,15 @@ * and builtin/tag.c by Kristian Høgsberg and Carlos Rica. */ -#include "builtin.h" +#include "cache.h" #include "config.h" +#include "builtin.h" #include "editor.h" #include "gettext.h" #include "hex.h" #include "notes.h" #include "object-name.h" -#include "object-store-ll.h" -#include "path.h" +#include "object-store.h" #include "repository.h" #include "blob.h" #include "pretty.h" diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 3c4db66478..3af2d84f58 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -34,7 +34,7 @@ #include "list.h" #include "packfile.h" #include "object-file.h" -#include "object-store-ll.h" +#include "object-store.h" #include "replace-object.h" #include "dir.h" #include "midx.h" diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c index 4c735ba069..43e9d12dfd 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-ll.h" +#include "object-store.h" #define BLKSIZE 512 diff --git a/builtin/patch-id.c b/builtin/patch-id.c index b7118b290b..9d5585d3a7 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" diff --git a/builtin/prune.c b/builtin/prune.c index 57fe31467f..2877201737 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -1,20 +1,19 @@ -#include "builtin.h" +#include "cache.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-ll.h" +#include "object-store.h" #include "shallow.h" static const char * const prune_usage[] = { diff --git a/builtin/pull.c b/builtin/pull.c index b9e5c64ee8..0c7bac97b7 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 "builtin.h" +#include "cache.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,8 +19,6 @@ #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" diff --git a/builtin/push.c b/builtin/push.c index 6f8a8dc711..dbdf609daf 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -1,7 +1,7 @@ /* * "git push" */ -#include "builtin.h" +#include "cache.h" #include "advice.h" #include "branch.h" #include "config.h" @@ -10,6 +10,7 @@ #include "refs.h" #include "refspec.h" #include "run-command.h" +#include "builtin.h" #include "remote.h" #include "transport.h" #include "parse-options.h" diff --git a/builtin/range-diff.c b/builtin/range-diff.c index e455a4795c..04339a92ea 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 63c92936fa..440f19b1b8 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -5,7 +5,7 @@ */ #define USE_THE_INDEX_VARIABLE -#include "builtin.h" +#include "cache.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" diff --git a/builtin/rebase.c b/builtin/rebase.c index 91849f920f..ace1d5e8d1 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -24,7 +24,6 @@ #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" diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 91caaf8706..1a31a58367 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -30,8 +30,7 @@ #include "oidset.h" #include "packfile.h" #include "object-name.h" -#include "object-store-ll.h" -#include "path.h" +#include "object-store.h" #include "protocol.h" #include "commit-reach.h" #include "server-info.h" diff --git a/builtin/reflog.c b/builtin/reflog.c index 79b4ff04aa..a1fa0c855f 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -1,10 +1,8 @@ #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" diff --git a/builtin/remote.c b/builtin/remote.c index 7d96687ec7..1e0b137d97 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -2,7 +2,6 @@ #include "config.h" #include "gettext.h" #include "parse-options.h" -#include "path.h" #include "transport.h" #include "remote.h" #include "string-list.h" @@ -11,7 +10,7 @@ #include "rebase.h" #include "refs.h" #include "refspec.h" -#include "object-store-ll.h" +#include "object-store.h" #include "strvec.h" #include "commit-reach.h" #include "progress.h" diff --git a/builtin/repack.c b/builtin/repack.c index a96e1c2638..1e21a21ea8 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -6,7 +6,6 @@ #include "gettext.h" #include "hex.h" #include "parse-options.h" -#include "path.h" #include "run-command.h" #include "server-info.h" #include "sigchain.h" @@ -16,7 +15,7 @@ #include "midx.h" #include "packfile.h" #include "prune-packed.h" -#include "object-store-ll.h" +#include "object-store.h" #include "promisor-remote.h" #include "shallow.h" #include "pack.h" diff --git a/builtin/replace.c b/builtin/replace.c index 9ceaa25233..abff800276 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -8,23 +8,22 @@ * git-tag.sh and mktag.c by Linus Torvalds. */ -#include "builtin.h" +#include "cache.h" #include "config.h" +#include "builtin.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-ll.h" +#include "object-store.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] "), diff --git a/builtin/rerere.c b/builtin/rerere.c index 0458db9cad..d4bd52797f 100644 --- a/builtin/rerere.c +++ b/builtin/rerere.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "cache.h" #include "config.h" #include "dir.h" #include "gettext.h" diff --git a/builtin/reset.c b/builtin/reset.c index dad2117c97..f99f32d580 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -13,7 +13,6 @@ #include "config.h" #include "environment.h" #include "gettext.h" -#include "hash.h" #include "hex.h" #include "lockfile.h" #include "tag.h" @@ -27,11 +26,9 @@ #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" diff --git a/builtin/rev-list.c b/builtin/rev-list.c index ff715d6918..6dc8be492a 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -1,4 +1,4 @@ -#include "builtin.h" +#include "cache.h" #include "config.h" #include "commit.h" #include "diff.h" @@ -12,9 +12,10 @@ #include "object.h" #include "object-name.h" #include "object-file.h" -#include "object-store-ll.h" +#include "object-store.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 3e2ee44177..d2eb239a08 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -4,22 +4,20 @@ * Copyright (C) Linus Torvalds, 2005 */ #define USE_THE_INDEX_VARIABLE -#include "builtin.h" +#include "cache.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" diff --git a/builtin/revert.c b/builtin/revert.c index f6f07d9b53..0240ec8593 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -5,7 +5,6 @@ #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 463eeabcea..b4589c824c 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -16,11 +16,9 @@ #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/shortlog.c b/builtin/shortlog.c index 1307ed2b88..46f4e0832a 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 a203f13cb0..7ef4a642c1 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -1,4 +1,4 @@ -#include "builtin.h" +#include "cache.h" #include "config.h" #include "environment.h" #include "gettext.h" @@ -6,6 +6,7 @@ #include "hex.h" #include "pretty.h" #include "refs.h" +#include "builtin.h" #include "color.h" #include "strvec.h" #include "object-name.h" @@ -14,7 +15,6 @@ #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" diff --git a/builtin/show-index.c b/builtin/show-index.c index 540dc3dad1..d839e55335 100644 --- a/builtin/show-index.c +++ b/builtin/show-index.c @@ -1,4 +1,5 @@ #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 5110814f79..a2243b4219 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -1,10 +1,11 @@ #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-ll.h" +#include "object-store.h" #include "object.h" #include "tag.h" #include "string-list.h" diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 5c8ffb1f75..40d420f06c 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -1,4 +1,5 @@ #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 84e83e0627..a7e17ffe38 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -4,7 +4,6 @@ #include "config.h" #include "environment.h" #include "gettext.h" -#include "hash.h" #include "hex.h" #include "object-name.h" #include "parse-options.h" @@ -18,12 +17,9 @@ #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" diff --git a/builtin/stripspace.c b/builtin/stripspace.c index 397d7fe2dc..9451eb69ff 100644 --- a/builtin/stripspace.c +++ b/builtin/stripspace.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "cache.h" #include "config.h" #include "gettext.h" #include "parse-options.h" diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 6321d7e9c9..6a16208e8a 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -6,16 +6,13 @@ #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" @@ -29,7 +26,7 @@ #include "diff.h" #include "object-file.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" #include "advice.h" #include "branch.h" #include "list-objects-filter-options.h" diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c index a61fa3c0f8..10198a74fa 100644 --- a/builtin/symbolic-ref.c +++ b/builtin/symbolic-ref.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "config.h" +#include "cache.h" #include "gettext.h" #include "refs.h" #include "parse-options.h" diff --git a/builtin/tag.c b/builtin/tag.c index e63bee8eab..49b64c7a28 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 "builtin.h" +#include "cache.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-ll.h" -#include "path.h" +#include "object-store.h" #include "tag.h" #include "run-command.h" #include "parse-options.h" diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c index 6842a6c499..b35a4b9dfe 100644 --- a/builtin/unpack-file.c +++ b/builtin/unpack-file.c @@ -2,7 +2,7 @@ #include "config.h" #include "hex.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" #include "wrapper.h" static char *create_temp_file(struct object_id *oid) diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 1979532a9d..0b4fe803cc 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -1,11 +1,12 @@ #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-ll.h" +#include "object-store.h" #include "object.h" #include "delta.h" #include "pack.h" diff --git a/builtin/update-index.c b/builtin/update-index.c index aee3cb8cbd..5fab9ad2ec 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 "builtin.h" +#include "cache.h" #include "bulk-checkin.h" #include "config.h" #include "environment.h" @@ -15,16 +15,15 @@ #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 242102273e..0c59b1c9ef 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -1,8 +1,9 @@ -#include "builtin.h" +#include "cache.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 1dc3971ede..19dce3c065 100644 --- a/builtin/update-server-info.c +++ b/builtin/update-server-info.c @@ -1,5 +1,6 @@ -#include "builtin.h" +#include "cache.h" #include "config.h" +#include "builtin.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 1b09e5e1aa..44ad400e18 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 9b021ef026..81d2008e01 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" diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c index 9680b58701..5d99b82a64 100644 --- a/builtin/verify-commit.c +++ b/builtin/verify-commit.c @@ -5,11 +5,12 @@ * * Based on git-verify-tag */ -#include "builtin.h" +#include "cache.h" #include "config.h" +#include "builtin.h" #include "gettext.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" #include "repository.h" #include "commit.h" #include "run-command.h" diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c index 011dddd2dc..190fd69540 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 d8753270eb..c6019a0ad8 100644 --- a/builtin/verify-tag.c +++ b/builtin/verify-tag.c @@ -5,8 +5,9 @@ * * Based on git-verify-tag.sh */ -#include "builtin.h" +#include "cache.h" #include "config.h" +#include "builtin.h" #include "gettext.h" #include "tag.h" #include "run-command.h" diff --git a/builtin/worktree.c b/builtin/worktree.c index 05dec7e330..5a9cf076ad 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -1,9 +1,10 @@ -#include "builtin.h" +#include "cache.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,10 +12,8 @@ #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" diff --git a/builtin/write-tree.c b/builtin/write-tree.c index 66e83d0ecb..84b83318c9 100644 --- a/builtin/write-tree.c +++ b/builtin/write-tree.c @@ -5,6 +5,7 @@ */ #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 e2f71db0f6..d843279715 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -16,7 +16,7 @@ #include "tmp-objdir.h" #include "packfile.h" #include "object-file.h" -#include "object-store-ll.h" +#include "object-store.h" #include "wrapper.h" static int odb_transaction_nesting; diff --git a/bundle-uri.c b/bundle-uri.c index a97dcbdb86..2a2db1a1d3 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-ll.h" +#include "object-store.h" #include "refs.h" #include "run-command.h" #include "hashmap.h" diff --git a/bundle.c b/bundle.c index 8d5936c421..a5505368de 100644 --- a/bundle.c +++ b/bundle.c @@ -4,7 +4,7 @@ #include "environment.h" #include "gettext.h" #include "hex.h" -#include "object-store-ll.h" +#include "object-store.h" #include "repository.h" #include "object.h" #include "commit.h" diff --git a/cache-tree.c b/cache-tree.c index 84d7491420..ebfe649b33 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -1,4 +1,4 @@ -#include "git-compat-util.h" +#include "cache.h" #include "alloc.h" #include "environment.h" #include "hex.h" @@ -8,8 +8,7 @@ #include "cache-tree.h" #include "bulk-checkin.h" #include "object-file.h" -#include "object-store-ll.h" -#include "read-cache-ll.h" +#include "object-store.h" #include "replace-object.h" #include "promisor-remote.h" #include "sparse-index.h" diff --git a/read-cache-ll.h b/cache.h similarity index 79% rename from read-cache-ll.h rename to cache.h index 9a1a7edc5a..bdedb87e83 100644 --- a/read-cache-ll.h +++ b/cache.h @@ -1,8 +1,11 @@ -#ifndef READ_CACHE_LL_H -#define READ_CACHE_LL_H +#ifndef CACHE_H +#define CACHE_H -#include "hash-ll.h" +#include "git-compat-util.h" +#include "strbuf.h" #include "hashmap.h" +#include "pathspec.h" +#include "object.h" #include "statinfo.h" /* @@ -123,6 +126,42 @@ 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 */ @@ -206,6 +245,12 @@ 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 */ /* @@ -273,14 +318,31 @@ 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) @@ -323,6 +385,9 @@ 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. @@ -431,6 +496,19 @@ 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); @@ -469,13 +547,69 @@ 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_); -int add_files_to_cache(struct repository *repo, const char *prefix, - const struct pathspec *pathspec, int include_sparse, - int flags); +/* 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); +/* 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); -#endif /* READ_CACHE_LL_H */ +/* 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 */ diff --git a/combine-diff.c b/combine-diff.c index 11e9d7494a..1e3cd7fb17 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -1,5 +1,5 @@ #include "git-compat-util.h" -#include "object-store-ll.h" +#include "object-store.h" #include "commit.h" #include "convert.h" #include "blob.h" diff --git a/commit-graph.c b/commit-graph.c index f70afccada..fd0ff8c7b8 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -12,9 +12,8 @@ #include "hash-lookup.h" #include "commit-graph.h" #include "object-file.h" -#include "object-store-ll.h" +#include "object-store.h" #include "oid-array.h" -#include "path.h" #include "alloc.h" #include "hashmap.h" #include "replace-object.h" diff --git a/commit-graph.h b/commit-graph.h index 5e534f0fcc..83aaa1dbb9 100644 --- a/commit-graph.h +++ b/commit-graph.h @@ -1,7 +1,7 @@ #ifndef COMMIT_GRAPH_H #define COMMIT_GRAPH_H -#include "object-store-ll.h" +#include "object-store.h" #include "oidset.h" #define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH" diff --git a/commit.c b/commit.c index 6507791061..0fb9316931 100644 --- a/commit.c +++ b/commit.c @@ -7,7 +7,7 @@ #include "hex.h" #include "repository.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" #include "pkt-line.h" #include "utf8.h" #include "diff.h" diff --git a/compat/fsmonitor/fsm-health-darwin.c b/compat/fsmonitor/fsm-health-darwin.c index 5b1709d63f..4c291f8a06 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-ll.h" +#include "fsmonitor.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 2d4e245beb..fe11bdd9ce 100644 --- a/compat/fsmonitor/fsm-health-win32.c +++ b/compat/fsmonitor/fsm-health-win32.c @@ -1,6 +1,6 @@ -#include "git-compat-util.h" +#include "cache.h" #include "config.h" -#include "fsmonitor-ll.h" +#include "fsmonitor.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 6f3a95410c..793073aaa7 100644 --- a/compat/fsmonitor/fsm-ipc-darwin.c +++ b/compat/fsmonitor/fsm-ipc-darwin.c @@ -2,10 +2,9 @@ #include "config.h" #include "gettext.h" #include "hex.h" -#include "path.h" #include "repository.h" #include "strbuf.h" -#include "fsmonitor-ll.h" +#include "fsmonitor.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 36c7e13281..23e24b4b37 100644 --- a/compat/fsmonitor/fsm-listen-darwin.c +++ b/compat/fsmonitor/fsm-listen-darwin.c @@ -24,13 +24,12 @@ #endif #include "git-compat-util.h" -#include "fsmonitor-ll.h" +#include "fsmonitor.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 a361a7db20..677b1bbdec 100644 --- a/compat/fsmonitor/fsm-listen-win32.c +++ b/compat/fsmonitor/fsm-listen-win32.c @@ -1,6 +1,6 @@ -#include "git-compat-util.h" +#include "cache.h" #include "config.h" -#include "fsmonitor-ll.h" +#include "fsmonitor.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 049f97eaaf..45eb4a9b9e 100644 --- a/compat/fsmonitor/fsm-path-utils-darwin.c +++ b/compat/fsmonitor/fsm-path-utils-darwin.c @@ -1,8 +1,6 @@ -#include "git-compat-util.h" -#include "fsmonitor-ll.h" +#include "fsmonitor.h" #include "fsmonitor-path-utils.h" #include "gettext.h" -#include "trace.h" #include #include #include diff --git a/compat/fsmonitor/fsm-path-utils-win32.c b/compat/fsmonitor/fsm-path-utils-win32.c index c8a3e9dcdb..4024baafb9 100644 --- a/compat/fsmonitor/fsm-path-utils-win32.c +++ b/compat/fsmonitor/fsm-path-utils-win32.c @@ -1,8 +1,7 @@ -#include "git-compat-util.h" -#include "fsmonitor-ll.h" +#include "cache.h" +#include "fsmonitor.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 a382590635..58b623fbb9 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-ll.h" +#include "fsmonitor.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 b6f6744494..a8af31b71d 100644 --- a/compat/fsmonitor/fsm-settings-win32.c +++ b/compat/fsmonitor/fsm-settings-win32.c @@ -1,7 +1,7 @@ -#include "git-compat-util.h" +#include "cache.h" #include "config.h" #include "repository.h" -#include "fsmonitor-ll.h" +#include "fsmonitor.h" #include "fsmonitor-settings.h" #include "fsmonitor-path-utils.h" diff --git a/compat/mingw.c b/compat/mingw.c index 559abb1c61..d06cdc6254 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -6,6 +6,7 @@ #include #include "../strbuf.h" #include "../run-command.h" +#include "../cache.h" #include "../abspath.h" #include "../alloc.h" #include "win32/lazyload.h" diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c index 0bd5c24250..a4d11376ba 100644 --- a/compat/precompose_utf8.c +++ b/compat/precompose_utf8.c @@ -5,12 +5,11 @@ #define PRECOMPOSE_UNICODE_C -#include "git-compat-util.h" +#include "cache.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 a4a6f930d7..6adfcfd540 100644 --- a/compat/sha1-chunked.c +++ b/compat/sha1-chunked.c @@ -1,5 +1,4 @@ -#include "git-compat-util.h" -#include "hash-ll.h" +#include "cache.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 8bfe51248e..6adce3c650 100644 --- a/compat/simple-ipc/ipc-win32.c +++ b/compat/simple-ipc/ipc-win32.c @@ -1,4 +1,4 @@ -#include "git-compat-util.h" +#include "cache.h" #include "abspath.h" #include "gettext.h" #include "simple-ipc.h" diff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c index a2b1506f9c..a4e33768f4 100644 --- a/compat/win32/trace2_win32_process_info.c +++ b/compat/win32/trace2_win32_process_info.c @@ -1,4 +1,4 @@ -#include "../../git-compat-util.h" +#include "../../cache.h" #include "../../json-writer.h" #include "../../repository.h" #include "../../trace2.h" diff --git a/config.c b/config.c index 1cdad1e160..2eeb662142 100644 --- a/config.c +++ b/config.c @@ -25,18 +25,15 @@ #include "hashmap.h" #include "string-list.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.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" diff --git a/connect.c b/connect.c index 37674f7112..3a0186280c 100644 --- a/connect.c +++ b/connect.c @@ -12,7 +12,6 @@ #include "url.h" #include "string-list.h" #include "oid-array.h" -#include "path.h" #include "transport.h" #include "trace2.h" #include "strbuf.h" diff --git a/connected.c b/connected.c index 8f89376dbc..d672521da4 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-ll.h" +#include "object-store.h" #include "run-command.h" #include "sigchain.h" #include "connected.h" diff --git a/convert.c b/convert.c index 3d8325d49e..9ee79fe469 100644 --- a/convert.c +++ b/convert.c @@ -1,21 +1,20 @@ -#include "git-compat-util.h" +#include "cache.h" #include "advice.h" #include "config.h" #include "convert.h" #include "copy.h" #include "gettext.h" #include "hex.h" -#include "object-store-ll.h" +#include "object-store.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 "merge-ll.h" +#include "ll-merge.h" #include "wrapper.h" /* diff --git a/decorate.c b/decorate.c index a5c43c0c14..71e79daa82 100644 --- a/decorate.c +++ b/decorate.c @@ -3,6 +3,7 @@ * data. */ #include "git-compat-util.h" +#include "hashmap.h" #include "object.h" #include "decorate.h" diff --git a/diagnose.c b/diagnose.c index 8430064000..c8c7ebcfa3 100644 --- a/diagnose.c +++ b/diagnose.c @@ -7,7 +7,7 @@ #include "gettext.h" #include "hex.h" #include "strvec.h" -#include "object-store-ll.h" +#include "object-store.h" #include "packfile.h" #include "parse-options.h" #include "write-or-die.h" diff --git a/diff-lib.c b/diff-lib.c index 6b0c6a7180..1918517ebd 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -1,21 +1,18 @@ /* * Copyright (C) 2005 Junio C Hamano */ -#include "git-compat-util.h" +#include "cache.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" diff --git a/diff.c b/diff.c index 6fb2946a64..c106f8a4ff 100644 --- a/diff.c +++ b/diff.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2005 Junio C Hamano */ -#include "git-compat-util.h" +#include "cache.h" #include "abspath.h" #include "alloc.h" #include "base85.h" @@ -20,13 +20,13 @@ #include "attr.h" #include "run-command.h" #include "utf8.h" -#include "object-store-ll.h" +#include "object-store.h" #include "userdiff.h" #include "submodule-config.h" #include "submodule.h" #include "hashmap.h" #include "mem-pool.h" -#include "merge-ll.h" +#include "ll-merge.h" #include "string-list.h" #include "strvec.h" #include "graph.h" @@ -39,7 +39,6 @@ #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" diff --git a/diff.h b/diff.h index 2102df329a..6c10ce289d 100644 --- a/diff.h +++ b/diff.h @@ -4,12 +4,10 @@ #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. @@ -703,6 +701,4 @@ 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 f57ece2757..5462420bbb 100644 --- a/diffcore-break.c +++ b/diffcore-break.c @@ -1,11 +1,9 @@ /* * Copyright (C) 2005 Junio C Hamano */ -#include "git-compat-util.h" +#include "cache.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 e7d20ebd2d..57ccab2846 100644 --- a/diffcore-order.c +++ b/diffcore-order.c @@ -5,7 +5,6 @@ #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 b195fa4eb3..13c98a7b5e 100644 --- a/diffcore-pickaxe.c +++ b/diffcore-pickaxe.c @@ -7,7 +7,6 @@ #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 926b554bd5..8e2e7a3ad7 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -6,7 +6,7 @@ #include "alloc.h" #include "diff.h" #include "diffcore.h" -#include "object-store-ll.h" +#include "object-store.h" #include "hashmap.h" #include "mem-pool.h" #include "oid-array.h" diff --git a/dir.c b/dir.c index 3acac7beb1..a7469df3ac 100644 --- a/dir.c +++ b/dir.c @@ -13,10 +13,8 @@ #include "dir.h" #include "environment.h" #include "gettext.h" -#include "name-hash.h" #include "object-file.h" -#include "object-store-ll.h" -#include "path.h" +#include "object-store.h" #include "attr.h" #include "refs.h" #include "wildmatch.h" @@ -24,10 +22,8 @@ #include "utf8.h" #include "varint.h" #include "ewah/ewok.h" -#include "fsmonitor-ll.h" -#include "read-cache-ll.h" +#include "fsmonitor.h" #include "setup.h" -#include "sparse-index.h" #include "submodule-config.h" #include "symlinks.h" #include "trace2.h" diff --git a/dir.h b/dir.h index 461f0971e4..d65a40126c 100644 --- a/dir.h +++ b/dir.h @@ -1,7 +1,6 @@ #ifndef DIR_H #define DIR_H -#include "hash-ll.h" #include "hashmap.h" #include "pathspec.h" #include "statinfo.h" diff --git a/entry.c b/entry.c index f9a7c726a4..91a540bd29 100644 --- a/entry.c +++ b/entry.c @@ -1,12 +1,10 @@ -#include "git-compat-util.h" +#include "cache.h" #include "blob.h" -#include "object-store-ll.h" +#include "object-store.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" diff --git a/environment.c b/environment.c index 8128104373..d449f9719b 100644 --- a/environment.c +++ b/environment.c @@ -20,8 +20,7 @@ #include "commit.h" #include "strvec.h" #include "object-file.h" -#include "object-store-ll.h" -#include "path.h" +#include "object-store.h" #include "replace-object.h" #include "tmp-objdir.h" #include "chdir-notify.h" @@ -109,7 +108,7 @@ char *git_work_tree_cfg; static char *git_namespace; /* - * Repository-local GIT_* environment variables; see environment.h for details. + * Repository-local GIT_* environment variables; see cache.h for details. */ const char * const local_repo_env[] = { ALTERNATE_DB_ENVIRONMENT, diff --git a/environment.h b/environment.h index 611aa0ffed..e666807926 100644 --- a/environment.h +++ b/environment.h @@ -1,8 +1,9 @@ #ifndef ENVIRONMENT_H #define ENVIRONMENT_H +#include "strvec.h" + struct repository; -struct strvec; /* * The character that begins a commented line in user-editable file diff --git a/exec-cmd.c b/exec-cmd.c index 1d597e84ea..1e34e48c0e 100644 --- a/exec-cmd.c +++ b/exec-cmd.c @@ -1,11 +1,10 @@ -#include "git-compat-util.h" +#include "cache.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 a432eacab9..0f71054fba 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -24,8 +24,7 @@ #include "oid-array.h" #include "oidset.h" #include "packfile.h" -#include "object-store-ll.h" -#include "path.h" +#include "object-store.h" #include "connected.h" #include "fetch-negotiator.h" #include "fsck.h" diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c index 4da6c7a8bd..5af0d4715b 100644 --- a/fmt-merge-msg.c +++ b/fmt-merge-msg.c @@ -4,7 +4,7 @@ #include "environment.h" #include "refs.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" #include "diff.h" #include "diff-merges.h" #include "hex.h" @@ -15,7 +15,6 @@ #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; diff --git a/fsck.c b/fsck.c index a219d6f2c0..3261ef9ec2 100644 --- a/fsck.c +++ b/fsck.c @@ -1,10 +1,8 @@ #include "git-compat-util.h" #include "alloc.h" #include "date.h" -#include "dir.h" #include "hex.h" -#include "object-store-ll.h" -#include "path.h" +#include "object-store.h" #include "repository.h" #include "object.h" #include "attr.h" diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c index 88575aa54c..6a6a89764a 100644 --- a/fsmonitor-ipc.c +++ b/fsmonitor-ipc.c @@ -1,5 +1,5 @@ -#include "git-compat-util.h" -#include "fsmonitor-ll.h" +#include "cache.h" +#include "fsmonitor.h" #include "gettext.h" #include "simple-ipc.h" #include "fsmonitor-ipc.h" diff --git a/fsmonitor-ll.h b/fsmonitor-ll.h deleted file mode 100644 index 0504ca07d6..0000000000 --- a/fsmonitor-ll.h +++ /dev/null @@ -1,52 +0,0 @@ -#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 f670c50937..28c083d4d8 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -1,4 +1,4 @@ -#include "git-compat-util.h" +#include "cache.h" #include "config.h" #include "dir.h" #include "environment.h" diff --git a/fsmonitor.h b/fsmonitor.h index 5195a8624d..c67e0ebc09 100644 --- a/fsmonitor.h +++ b/fsmonitor.h @@ -1,13 +1,56 @@ #ifndef FSMONITOR_H #define FSMONITOR_H -#include "fsmonitor-ll.h" +#include "cache.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 1889da7986..5b2b99c17c 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -625,6 +625,8 @@ static inline int git_has_dir_sep(const char *path) #include "compat/bswap.h" +#include "wildmatch.h" + struct strbuf; /* General helper functions */ diff --git a/git.c b/git.c index c67e44dd82..bb6ea3547e 100644 --- a/git.c +++ b/git.c @@ -5,7 +5,6 @@ #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" diff --git a/grep.c b/grep.c index ebcd647478..f00986c451 100644 --- a/grep.c +++ b/grep.c @@ -3,7 +3,7 @@ #include "gettext.h" #include "grep.h" #include "hex.h" -#include "object-store-ll.h" +#include "object-store.h" #include "pretty.h" #include "userdiff.h" #include "xdiff-interface.h" diff --git a/hash-ll.h b/hash-ll.h index 8d7973769f..8050925137 100644 --- a/hash-ll.h +++ b/hash-ll.h @@ -270,25 +270,6 @@ 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 9f0f95e2b9..bb54dfde9c 100644 --- a/hash-lookup.c +++ b/hash-lookup.c @@ -1,7 +1,6 @@ -#include "git-compat-util.h" +#include "cache.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 c8216e47bb..2695f3d3a6 100644 --- a/hashmap.h +++ b/hashmap.h @@ -1,6 +1,8 @@ #ifndef HASHMAP_H #define HASHMAP_H +#include "hash-ll.h" + /* * Generic implementation of hash-based key-value mappings. * @@ -118,6 +120,25 @@ unsigned int memhash(const void *buf, size_t len); 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. diff --git a/http-backend.c b/http-backend.c index e1969c05dc..ac146d85c5 100644 --- a/http-backend.c +++ b/http-backend.c @@ -4,7 +4,6 @@ #include "environment.h" #include "git-zlib.h" #include "hex.h" -#include "path.h" #include "repository.h" #include "refs.h" #include "pkt-line.h" @@ -16,7 +15,7 @@ #include "url.h" #include "strvec.h" #include "packfile.h" -#include "object-store-ll.h" +#include "object-store.h" #include "protocol.h" #include "date.h" #include "wrapper.h" diff --git a/http-push.c b/http-push.c index 9ab2383d2b..29cf9db34e 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-ll.h" +#include "object-store.h" #include "commit-reach.h" #ifdef EXPAT_NEEDS_XMLPARSE_H diff --git a/http-walker.c b/http-walker.c index 78d99f7c4b..bba306b2d5 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-ll.h" +#include "object-store.h" struct alt_base { char *base; diff --git a/http.c b/http.c index 5772c8ced3..b71bb1e3ad 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-ll.h" +#include "object-store.h" static struct trace_key trace_curl = TRACE_KEY_INIT(CURL); static int trace_curl_data = 1; diff --git a/khash.h b/khash.h index ff88163177..56241e6a5c 100644 --- a/khash.h +++ b/khash.h @@ -26,6 +26,7 @@ #ifndef __AC_KHASH_H #define __AC_KHASH_H +#include "hashmap.h" #include "hash.h" #define AC_VERSION_KHASH_H "0.2.8" @@ -61,7 +62,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 kh_##name { \ + typedef struct { \ khint_t n_buckets, size, n_occupied, upper_bound; \ khint32_t *flags; \ khkey_t *keys; \ diff --git a/line-log.c b/line-log.c index 2eff914bf3..6a7ac312a4 100644 --- a/line-log.c +++ b/line-log.c @@ -8,7 +8,6 @@ #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.h b/list-objects-filter-options.h index 55fab8563d..f620612586 100644 --- a/list-objects-filter-options.h +++ b/list-objects-filter-options.h @@ -3,6 +3,7 @@ #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 e075a66c99..5d270ce598 100644 --- a/list-objects-filter.c +++ b/list-objects-filter.c @@ -16,7 +16,7 @@ #include "oidmap.h" #include "oidset.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" /* Remember to update object flag allocation in object.h */ /* diff --git a/list-objects.c b/list-objects.c index 672a4cd529..eecca721ac 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-ll.h" +#include "object-store.h" #include "trace.h" struct traversal_context { diff --git a/merge-ll.c b/ll-merge.c similarity index 99% rename from merge-ll.c rename to ll-merge.c index 740b8c6bfd..07ec16e8e5 100644 --- a/merge-ll.c +++ b/ll-merge.c @@ -10,7 +10,7 @@ #include "attr.h" #include "xdiff-interface.h" #include "run-command.h" -#include "merge-ll.h" +#include "ll-merge.h" #include "quote.h" #include "strbuf.h" #include "wrapper.h" diff --git a/merge-ll.h b/ll-merge.h similarity index 100% rename from merge-ll.h rename to ll-merge.h diff --git a/log-tree.c b/log-tree.c index 208c69cbb7..48468087af 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-ll.h" +#include "object-store.h" #include "repository.h" #include "tmp-objdir.h" #include "commit.h" @@ -16,7 +16,6 @@ #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" @@ -26,7 +25,6 @@ #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" }; diff --git a/log-tree.h b/log-tree.h index bdb6432815..e7e4641cf8 100644 --- a/log-tree.h +++ b/log-tree.h @@ -1,7 +1,7 @@ #ifndef LOG_TREE_H #define LOG_TREE_H -struct rev_info; +#include "revision.h" struct log_info { struct commit *commit, *parent; diff --git a/mailmap.c b/mailmap.c index 3d6a5e9400..5dc5223c43 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-ll.h" +#include "object-store.h" #include "setup.h" const char *git_mailmap_file; diff --git a/match-trees.c b/match-trees.c index 0885ac681c..6bc8eb7647 100644 --- a/match-trees.c +++ b/match-trees.c @@ -1,10 +1,9 @@ #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-ll.h" +#include "object-store.h" static int score_missing(unsigned mode) { diff --git a/merge-blobs.c b/merge-blobs.c index 9293cbf75c..5632ff6abb 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 "merge-ll.h" +#include "ll-merge.h" #include "blob.h" #include "merge-blobs.h" -#include "object-store-ll.h" +#include "object-store.h" static int fill_mmfile_blob(mmfile_t *f, struct blob *obj) { diff --git a/merge-ort-wrappers.c b/merge-ort-wrappers.c index 4acedf3c33..a550753300 100644 --- a/merge-ort-wrappers.c +++ b/merge-ort-wrappers.c @@ -1,9 +1,8 @@ -#include "git-compat-util.h" +#include "cache.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 8631c99700..a50b095c47 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -14,7 +14,7 @@ * "cale", "peedy", or "ins" instead of "ort"?) */ -#include "git-compat-util.h" +#include "cache.h" #include "merge-ort.h" #include "alloc.h" @@ -30,17 +30,14 @@ #include "gettext.h" #include "hex.h" #include "entry.h" -#include "merge-ll.h" +#include "ll-merge.h" #include "match-trees.h" #include "mem-pool.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.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 43f6b2d036..8e87b6386d 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 "git-compat-util.h" +#include "cache.h" #include "merge-recursive.h" #include "advice.h" @@ -20,17 +20,14 @@ #include "environment.h" #include "gettext.h" #include "hex.h" -#include "merge-ll.h" +#include "ll-merge.h" #include "lockfile.h" #include "match-trees.h" -#include "name-hash.h" #include "object-file.h" #include "object-name.h" -#include "object-store-ll.h" -#include "path.h" +#include "object-store.h" #include "repository.h" #include "revision.h" -#include "sparse-index.h" #include "string-list.h" #include "submodule-config.h" #include "submodule.h" diff --git a/merge.c b/merge.c index b60925459c..10aaec3a6c 100644 --- a/merge.c +++ b/merge.c @@ -1,13 +1,10 @@ -#include "git-compat-util.h" +#include "cache.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 deleted file mode 100644 index 21ac7ef2f1..0000000000 --- a/merge.h +++ /dev/null @@ -1,17 +0,0 @@ -#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 db459e448b..b500174d1f 100644 --- a/midx.c +++ b/midx.c @@ -9,7 +9,7 @@ #include "lockfile.h" #include "packfile.h" #include "object-file.h" -#include "object-store-ll.h" +#include "object-store.h" #include "hash-lookup.h" #include "midx.h" #include "progress.h" diff --git a/name-hash.c b/name-hash.c index 251f036eef..fb13716e43 100644 --- a/name-hash.c +++ b/name-hash.c @@ -5,12 +5,9 @@ * * Copyright (C) 2008 Linus Torvalds */ -#include "git-compat-util.h" +#include "cache.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 deleted file mode 100644 index b1b4b0fb33..0000000000 --- a/name-hash.h +++ /dev/null @@ -1,16 +0,0 @@ -#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 0e1d5b1ac7..14288caf98 100644 --- a/notes-cache.c +++ b/notes-cache.c @@ -1,11 +1,10 @@ #include "git-compat-util.h" #include "notes-cache.h" -#include "object-store-ll.h" +#include "object-store.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 071947894e..233e49e319 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -5,14 +5,13 @@ #include "refs.h" #include "object-file.h" #include "object-name.h" -#include "object-store-ll.h" -#include "path.h" +#include "object-store.h" #include "repository.h" #include "diff.h" #include "diffcore.h" #include "hex.h" #include "xdiff-interface.h" -#include "merge-ll.h" +#include "ll-merge.h" #include "dir.h" #include "notes.h" #include "notes-merge.h" diff --git a/notes.c b/notes.c index 503dbc4be1..f51a2d3630 100644 --- a/notes.c +++ b/notes.c @@ -4,7 +4,7 @@ #include "hex.h" #include "notes.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" #include "blob.h" #include "tree.h" #include "utf8.h" diff --git a/object-file.c b/object-file.c index 8d87720dd5..7c1af5c8db 100644 --- a/object-file.c +++ b/object-file.c @@ -39,7 +39,6 @@ #include "object-file.h" #include "object-store.h" #include "oidtree.h" -#include "path.h" #include "promisor-remote.h" #include "setup.h" #include "submodule.h" diff --git a/object-name.c b/object-name.c index 7e96c97051..6fc3fa595b 100644 --- a/object-name.c +++ b/object-name.c @@ -1,4 +1,4 @@ -#include "git-compat-util.h" +#include "cache.h" #include "object-name.h" #include "advice.h" #include "config.h" @@ -17,8 +17,7 @@ #include "oidtree.h" #include "packfile.h" #include "pretty.h" -#include "object-store-ll.h" -#include "read-cache-ll.h" +#include "object-store.h" #include "repository.h" #include "setup.h" #include "submodule.h" diff --git a/object-store-ll.h b/object-store-ll.h deleted file mode 100644 index e8f22cdb1b..0000000000 --- a/object-store-ll.h +++ /dev/null @@ -1,533 +0,0 @@ -#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; - 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; - 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 " " 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 1b3e3d7d01..12415e5ea7 100644 --- a/object-store.h +++ b/object-store.h @@ -1,11 +1,537 @@ #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 "object-store-ll.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; +}; 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 " " 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 2c61e4c862..f1adb458b6 100644 --- a/object.c +++ b/object.c @@ -1,4 +1,4 @@ -#include "git-compat-util.h" +#include "cache.h" #include "gettext.h" #include "hex.h" #include "object.h" @@ -6,7 +6,6 @@ #include "object-file.h" #include "object-store.h" #include "blob.h" -#include "statinfo.h" #include "tree.h" #include "commit.h" #include "tag.h" diff --git a/oidmap.h b/oidmap.h index 05c673eb7c..c1642927fa 100644 --- a/oidmap.h +++ b/oidmap.h @@ -1,7 +1,6 @@ #ifndef OIDMAP_H #define OIDMAP_H -#include "hash-ll.h" #include "hashmap.h" /* diff --git a/oss-fuzz/fuzz-pack-idx.c b/oss-fuzz/fuzz-pack-idx.c index 3e190214d1..609a343ee3 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-ll.h" +#include "object-store.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 d86f4e739a..cdffe2ce47 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -3,7 +3,7 @@ #include "environment.h" #include "gettext.h" #include "hex.h" -#include "object-store-ll.h" +#include "object-store.h" #include "commit.h" #include "tag.h" #include "diff.h" @@ -15,7 +15,6 @@ #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 7367f62bb6..35669e2478 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -17,7 +17,7 @@ #include "repository.h" #include "trace2.h" #include "object-file.h" -#include "object-store-ll.h" +#include "object-store.h" #include "list-objects-filter-options.h" #include "midx.h" #include "config.h" diff --git a/pack-check.c b/pack-check.c index 977f619618..049f2f0bfc 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-ll.h" +#include "object-store.h" struct idx_entry { off_t offset; diff --git a/pack-mtimes.c b/pack-mtimes.c index cdf30b8d2b..020a37f8fe 100644 --- a/pack-mtimes.c +++ b/pack-mtimes.c @@ -2,9 +2,8 @@ #include "gettext.h" #include "pack-mtimes.h" #include "object-file.h" -#include "object-store-ll.h" +#include "object-store.h" #include "packfile.h" -#include "strbuf.h" static char *pack_mtimes_filename(struct packed_git *p) { diff --git a/pack-objects.h b/pack-objects.h index 0d78db40cb..579476687c 100644 --- a/pack-objects.h +++ b/pack-objects.h @@ -1,7 +1,7 @@ #ifndef PACK_OBJECTS_H #define PACK_OBJECTS_H -#include "object-store-ll.h" +#include "object-store.h" #include "thread-utils.h" #include "pack.h" diff --git a/pack-revindex.c b/pack-revindex.c index 7fffcad912..1f51b712e8 100644 --- a/pack-revindex.c +++ b/pack-revindex.c @@ -2,9 +2,8 @@ #include "gettext.h" #include "pack-revindex.h" #include "object-file.h" -#include "object-store-ll.h" +#include "object-store.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 af48813a9b..3b3ce89de6 100644 --- a/pack-write.c +++ b/pack-write.c @@ -10,8 +10,6 @@ #include "oidmap.h" #include "pack-objects.h" #include "pack-revindex.h" -#include "path.h" -#include "strbuf.h" #include "wrapper.h" void reset_pack_idx_option(struct pack_idx_option *opts) diff --git a/packfile.c b/packfile.c index c60aeb05ec..fd083c86e0 100644 --- a/packfile.c +++ b/packfile.c @@ -19,7 +19,7 @@ #include "tree-walk.h" #include "tree.h" #include "object-file.h" -#include "object-store-ll.h" +#include "object-store.h" #include "midx.h" #include "commit-graph.h" #include "pack-revindex.h" diff --git a/parallel-checkout.c b/parallel-checkout.c index 602fbf19d3..69d569f352 100644 --- a/parallel-checkout.c +++ b/parallel-checkout.c @@ -1,4 +1,4 @@ -#include "git-compat-util.h" +#include "cache.h" #include "alloc.h" #include "config.h" #include "entry.h" @@ -8,7 +8,6 @@ #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" diff --git a/patch-ids.c b/patch-ids.c index c3e1a0dd21..19af7bee98 100644 --- a/patch-ids.c +++ b/patch-ids.c @@ -1,7 +1,6 @@ #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 c3b6618c77..7c1cd8182a 100644 --- a/path.c +++ b/path.c @@ -15,7 +15,7 @@ #include "submodule-config.h" #include "path.h" #include "packfile.h" -#include "object-store-ll.h" +#include "object-store.h" #include "lockfile.h" #include "exec-cmd.h" #include "wrapper.h" diff --git a/pathspec.c b/pathspec.c index 3a3a5724c4..5049dbb528 100644 --- a/pathspec.c +++ b/pathspec.c @@ -1,4 +1,4 @@ -#include "git-compat-util.h" +#include "cache.h" #include "abspath.h" #include "config.h" #include "dir.h" @@ -6,13 +6,11 @@ #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. diff --git a/preload-index.c b/preload-index.c index e44530c80c..7a26b08c21 100644 --- a/preload-index.c +++ b/preload-index.c @@ -1,16 +1,14 @@ /* * Copyright (C) 2008 Linus Torvalds */ -#include "git-compat-util.h" +#include "cache.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 deleted file mode 100644 index 251b1ed88e..0000000000 --- a/preload-index.h +++ /dev/null @@ -1,15 +0,0 @@ -#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 2cf2cbbd03..0bb938021b 100644 --- a/pretty.c +++ b/pretty.c @@ -4,7 +4,6 @@ #include "commit.h" #include "environment.h" #include "gettext.h" -#include "hash.h" #include "hex.h" #include "utf8.h" #include "diff.h" diff --git a/promisor-remote.c b/promisor-remote.c index db88d2064d..1adcd6fb0a 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-ll.h" +#include "object-store.h" #include "promisor-remote.h" #include "config.h" #include "trace2.h" diff --git a/protocol-caps.c b/protocol-caps.c index 808a68c974..a90c48852e 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-ll.h" +#include "object-store.h" #include "string-list.h" #include "strbuf.h" diff --git a/prune-packed.c b/prune-packed.c index e54daf740a..58412b4fb9 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-ll.h" +#include "object-store.h" #include "packfile.h" #include "progress.h" #include "prune-packed.h" diff --git a/range-diff.c b/range-diff.c index 2e86063491..6a704e6f47 100644 --- a/range-diff.c +++ b/range-diff.c @@ -13,7 +13,6 @@ #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 0ce8f83e56..60a7336b87 100644 --- a/reachable.c +++ b/reachable.c @@ -13,7 +13,7 @@ #include "list-objects.h" #include "packfile.h" #include "worktree.h" -#include "object-store-ll.h" +#include "object-store.h" #include "pack-bitmap.h" #include "pack-mtimes.h" #include "config.h" diff --git a/read-cache.c b/read-cache.c index b9a995e5a1..f4c31a68c8 100644 --- a/read-cache.c +++ b/read-cache.c @@ -3,9 +3,8 @@ * * Copyright (C) Linus Torvalds, 2005 */ -#include "git-compat-util.h" +#include "cache.h" #include "alloc.h" -#include "bulk-checkin.h" #include "config.h" #include "date.h" #include "diff.h" @@ -17,7 +16,7 @@ #include "refs.h" #include "dir.h" #include "object-file.h" -#include "object-store-ll.h" +#include "object-store.h" #include "oid-array.h" #include "tree.h" #include "commit.h" @@ -25,13 +24,8 @@ #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" @@ -181,6 +175,61 @@ 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 @@ -3485,6 +3534,35 @@ 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; @@ -3728,240 +3806,3 @@ 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 deleted file mode 100644 index 043da1f1aa..0000000000 --- a/read-cache.h +++ /dev/null @@ -1,45 +0,0 @@ -#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/ref-filter.c b/ref-filter.c index e0d03a9f8e..4991cd4f7a 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -8,7 +8,7 @@ #include "refs.h" #include "wildmatch.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" #include "oid-array.h" #include "repository.h" #include "commit.h" diff --git a/reflog-walk.c b/reflog-walk.c index d337e64431..4ba1a10c82 100644 --- a/reflog-walk.c +++ b/reflog-walk.c @@ -3,7 +3,6 @@ #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 9ad50e7d93..ee1bf5d032 100644 --- a/reflog.c +++ b/reflog.c @@ -1,6 +1,6 @@ #include "git-compat-util.h" #include "gettext.h" -#include "object-store-ll.h" +#include "object-store.h" #include "reflog.h" #include "refs.h" #include "revision.h" diff --git a/refs.c b/refs.c index c029f64982..881a0da65c 100644 --- a/refs.c +++ b/refs.c @@ -17,9 +17,8 @@ #include "run-command.h" #include "hook.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" #include "object.h" -#include "path.h" #include "tag.h" #include "submodule.h" #include "worktree.h" @@ -29,7 +28,6 @@ #include "sigchain.h" #include "date.h" #include "commit.h" -#include "wildmatch.h" #include "wrapper.h" /* diff --git a/refs/files-backend.c b/refs/files-backend.c index 09b4954f21..9a8333c0d0 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1,4 +1,4 @@ -#include "../git-compat-util.h" +#include "../cache.h" #include "../config.h" #include "../copy.h" #include "../environment.h" @@ -15,7 +15,6 @@ #include "../lockfile.h" #include "../object.h" #include "../object-file.h" -#include "../path.h" #include "../dir.h" #include "../chdir-notify.h" #include "../setup.h" diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 27bd6339ff..291e53f5cf 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -1,4 +1,4 @@ -#include "../git-compat-util.h" +#include "../cache.h" #include "../alloc.h" #include "../config.h" #include "../gettext.h" @@ -10,7 +10,6 @@ #include "../iterator.h" #include "../lockfile.h" #include "../chdir-notify.h" -#include "../statinfo.h" #include "../wrapper.h" #include "../write-or-die.h" diff --git a/remote.c b/remote.c index a81f2e2f17..1bcd36e358 100644 --- a/remote.c +++ b/remote.c @@ -10,8 +10,7 @@ #include "refs.h" #include "refspec.h" #include "object-name.h" -#include "object-store-ll.h" -#include "path.h" +#include "object-store.h" #include "commit.h" #include "diff.h" #include "revision.h" diff --git a/remote.h b/remote.h index 929c7c676d..73638cefeb 100644 --- a/remote.h +++ b/remote.h @@ -1,7 +1,6 @@ #ifndef REMOTE_H #define REMOTE_H -#include "hash-ll.h" #include "hashmap.h" #include "refspec.h" diff --git a/replace-object.c b/replace-object.c index 523215589d..ae2d55b014 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-ll.h" +#include "object-store.h" #include "replace-object.h" #include "refs.h" #include "repository.h" diff --git a/replace-object.h b/replace-object.h index 66c41b938b..ba478eb30c 100644 --- a/replace-object.h +++ b/replace-object.h @@ -3,7 +3,7 @@ #include "oidmap.h" #include "repository.h" -#include "object-store-ll.h" +#include "object-store.h" struct replace_object { struct oidmap_entry original; diff --git a/repository.c b/repository.c index a7679ceeaa..104960f8f5 100644 --- a/repository.c +++ b/repository.c @@ -3,15 +3,13 @@ * declaration matches the definition in this file. */ #define USE_THE_INDEX_VARIABLE -#include "git-compat-util.h" +#include "cache.h" #include "abspath.h" #include "repository.h" -#include "object-store-ll.h" +#include "object-store.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" diff --git a/repository.h b/repository.h index 5f18486f64..af294deb8c 100644 --- a/repository.h +++ b/repository.h @@ -1,6 +1,8 @@ #ifndef REPOSITORY_H #define REPOSITORY_H +#include "path.h" + struct config_set; struct fsmonitor_settings; struct git_hash_algo; @@ -178,9 +180,6 @@ struct repository { }; 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 @@ -232,6 +231,9 @@ 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 e2b8597f88..e968d413d6 100644 --- a/rerere.c +++ b/rerere.c @@ -1,4 +1,4 @@ -#include "git-compat-util.h" +#include "cache.h" #include "abspath.h" #include "alloc.h" #include "config.h" @@ -7,17 +7,15 @@ #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 "merge-ll.h" +#include "ll-merge.h" #include "attr.h" -#include "path.h" #include "pathspec.h" #include "object-file.h" -#include "object-store-ll.h" +#include "object-store.h" #include "hash-lookup.h" #include "strmap.h" #include "wrapper.h" diff --git a/resolve-undo.c b/resolve-undo.c index 7817f5d6db..70a6db526d 100644 --- a/resolve-undo.c +++ b/resolve-undo.c @@ -1,9 +1,7 @@ -#include "git-compat-util.h" +#include "cache.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 84768565ce..b33cc1d106 100644 --- a/revision.c +++ b/revision.c @@ -1,4 +1,4 @@ -#include "git-compat-util.h" +#include "cache.h" #include "alloc.h" #include "config.h" #include "environment.h" @@ -6,7 +6,7 @@ #include "hex.h" #include "object-name.h" #include "object-file.h" -#include "object-store-ll.h" +#include "object-store.h" #include "tag.h" #include "blob.h" #include "tree.h" @@ -31,9 +31,7 @@ #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" @@ -46,7 +44,6 @@ #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; diff --git a/run-command.c b/run-command.c index b22ee36073..758f8534da 100644 --- a/run-command.c +++ b/run-command.c @@ -1,4 +1,4 @@ -#include "git-compat-util.h" +#include "cache.h" #include "run-command.h" #include "environment.h" #include "exec-cmd.h" diff --git a/run-command.h b/run-command.h index 1f22cc3827..072db56a4d 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 - * environment.h for more information. + * cache.h for more information. */ void prepare_other_repo_env(struct strvec *env, const char *new_git_dir); @@ -564,6 +564,4 @@ 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/send-pack.c b/send-pack.c index 9510bef856..0c7ccaef68 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-ll.h" +#include "object-store.h" #include "pkt-line.h" #include "sideband.h" #include "run-command.h" diff --git a/sequencer.c b/sequencer.c index 8dd5bdeb36..bceb6abcb6 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1,4 +1,4 @@ -#include "git-compat-util.h" +#include "cache.h" #include "abspath.h" #include "advice.h" #include "alloc.h" @@ -11,7 +11,7 @@ #include "dir.h" #include "object-file.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" #include "object.h" #include "pager.h" #include "commit.h" @@ -23,14 +23,11 @@ #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" diff --git a/serve.c b/serve.c index a1d71134d4..5329c91011 100644 --- a/serve.c +++ b/serve.c @@ -1,7 +1,6 @@ #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 382e481a2b..55aa04f00a 100644 --- a/server-info.c +++ b/server-info.c @@ -9,9 +9,8 @@ #include "commit.h" #include "tag.h" #include "packfile.h" -#include "path.h" #include "object-file.h" -#include "object-store-ll.h" +#include "object-store.h" #include "server-info.h" #include "strbuf.h" #include "wrapper.h" diff --git a/setup.c b/setup.c index 5912d961ab..6f6e92b96b 100644 --- a/setup.c +++ b/setup.c @@ -1,22 +1,17 @@ #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 "worktree.h" #include "wrapper.h" static int inside_git_dir = -1; @@ -1710,495 +1705,3 @@ int daemonize(void) return 0; #endif } - -#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 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 58fd2605dd..4c1ca9d0c9 100644 --- a/setup.h +++ b/setup.h @@ -140,15 +140,6 @@ 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/shallow.c b/shallow.c index f3ef94d4c9..128f56179e 100644 --- a/shallow.c +++ b/shallow.c @@ -1,24 +1,22 @@ -#include "git-compat-util.h" +#include "cache.h" #include "alloc.h" #include "hex.h" #include "repository.h" #include "tempfile.h" #include "lockfile.h" -#include "object-store-ll.h" +#include "object-store.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" diff --git a/sparse-index.c b/sparse-index.c index 90d0462256..886054729e 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -1,9 +1,7 @@ -#include "git-compat-util.h" +#include "cache.h" #include "alloc.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" @@ -12,7 +10,7 @@ #include "cache-tree.h" #include "config.h" #include "dir.h" -#include "fsmonitor-ll.h" +#include "fsmonitor.h" struct modify_index_context { struct index_state *write; diff --git a/sparse-index.h b/sparse-index.h index a16f3e67d7..59a92d819e 100644 --- a/sparse-index.h +++ b/sparse-index.h @@ -37,6 +37,4 @@ 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 0ee3865a55..40e54760b3 100644 --- a/split-index.c +++ b/split-index.c @@ -1,9 +1,8 @@ -#include "git-compat-util.h" +#include "cache.h" #include "alloc.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 deleted file mode 100644 index 17bb8966c3..0000000000 --- a/statinfo.c +++ /dev/null @@ -1,87 +0,0 @@ -#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 700f502ac0..fe8df633a4 100644 --- a/statinfo.h +++ b/statinfo.h @@ -1,8 +1,6 @@ #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 @@ -23,55 +21,6 @@ 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 diff --git a/strbuf.c b/strbuf.c index b7fd474a83..31dc48c0ab 100644 --- a/strbuf.c +++ b/strbuf.c @@ -6,7 +6,6 @@ #include "hex.h" #include "object-name.h" #include "refs.h" -#include "path.h" #include "repository.h" #include "string-list.h" #include "utf8.h" diff --git a/strbuf.h b/strbuf.h index 507670ce3c..0e69b656bc 100644 --- a/strbuf.h +++ b/strbuf.h @@ -72,6 +72,10 @@ 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; /** diff --git a/streaming.c b/streaming.c index 49791ab958..21e39585e8 100644 --- a/streaming.c +++ b/streaming.c @@ -7,7 +7,7 @@ #include "streaming.h" #include "repository.h" #include "object-file.h" -#include "object-store-ll.h" +#include "object-store.h" #include "replace-object.h" #include "packfile.h" #include "wrapper.h" diff --git a/submodule-config.c b/submodule-config.c index 515ff5bba4..7eb7a0d88d 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -4,14 +4,13 @@ #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-ll.h" +#include "object-store.h" #include "parse-options.h" #include "thread-utils.h" #include "tree-walk.h" diff --git a/submodule.c b/submodule.c index f0f8788d2e..2e78f51349 100644 --- a/submodule.c +++ b/submodule.c @@ -1,4 +1,4 @@ -#include "git-compat-util.h" +#include "cache.h" #include "abspath.h" #include "alloc.h" #include "repository.h" @@ -20,16 +20,14 @@ #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-ll.h" +#include "object-store.h" #include "commit-reach.h" -#include "read-cache-ll.h" #include "setup.h" #include "shallow.h" #include "trace2.h" diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c index e7236392c8..9507b356e2 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-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c index c38f546e4f..f22f7bd84a 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 4f215fea02..9a098a25cb 100644 --- a/t/helper/test-dump-fsmonitor.c +++ b/t/helper/test-dump-fsmonitor.c @@ -1,5 +1,5 @@ #include "test-tool.h" -#include "read-cache-ll.h" +#include "cache.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 5cf0b26dca..d1badd7112 100644 --- a/t/helper/test-dump-split-index.c +++ b/t/helper/test-dump-split-index.c @@ -1,8 +1,7 @@ #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" diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c index b4af9712fe..df70be549f 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 cac20a72b3..d1d63feaa9 100644 --- a/t/helper/test-fast-rebase.c +++ b/t/helper/test-fast-rebase.c @@ -12,16 +12,15 @@ #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 58d1dc5fc8..9f18c685b7 100644 --- a/t/helper/test-fsmonitor-client.c +++ b/t/helper/test-fsmonitor-client.c @@ -4,9 +4,9 @@ */ #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" diff --git a/t/helper/test-hash-speed.c b/t/helper/test-hash-speed.c index b235da594f..f40d9ad0c2 100644 --- a/t/helper/test-hash-speed.c +++ b/t/helper/test-hash-speed.c @@ -1,5 +1,5 @@ #include "test-tool.h" -#include "hash-ll.h" +#include "cache.h" #define NUM_SECONDS 3 diff --git a/t/helper/test-index-version.c b/t/helper/test-index-version.c index f3c2dbe0a2..a06c45c1f8 100644 --- a/t/helper/test-index-version.c +++ b/t/helper/test-index-version.c @@ -1,5 +1,5 @@ #include "test-tool.h" -#include "read-cache-ll.h" +#include "cache.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 187a115d57..b83a75d19f 100644 --- a/t/helper/test-lazy-init-name-hash.c +++ b/t/helper/test-lazy-init-name-hash.c @@ -1,9 +1,8 @@ #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-pack-mtimes.c b/t/helper/test-pack-mtimes.c index 67a964ef90..0f3fbeec53 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-ll.h" +#include "object-store.h" #include "packfile.h" #include "pack-mtimes.h" #include "setup.h" diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c index 910a128614..362bd64a4c 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-ll.h" +#include "object-store.h" #include "setup.h" /* diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c index 70396fa384..2ef53d5f7a 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-read-cache.c b/t/helper/test-read-cache.c index 56c2d25f35..c1ae276395 100644 --- a/t/helper/test-read-cache.c +++ b/t/helper/test-read-cache.c @@ -1,7 +1,7 @@ #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" diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c index 8c7a83f578..3ac496e27e 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-ll.h" +#include "object-store.h" #include "bloom.h" #include "setup.h" diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c index e9a444ddba..211addaa00 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-ll.h" +#include "object-store.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 fb18831ec2..a6977b5e83 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -3,10 +3,8 @@ #include "refs.h" #include "setup.h" #include "worktree.h" -#include "object-store-ll.h" -#include "path.h" +#include "object-store.h" #include "repository.h" -#include "strbuf.h" #include "revision.h" struct flag_definition { diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c index 4cd8a952e5..bafd2a5bf9 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-ll.h" +#include "object-store.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 f346951bc2..0c62b9de18 100644 --- a/t/helper/test-revision-walking.c +++ b/t/helper/test-revision-walking.c @@ -11,7 +11,6 @@ #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 0a816a96e2..6e17f50d22 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 dcb7f6c003..71fe5c6145 100644 --- a/t/helper/test-sha1.c +++ b/t/helper/test-sha1.c @@ -1,5 +1,5 @@ #include "test-tool.h" -#include "hash-ll.h" +#include "cache.h" int cmd__sha1(int ac, const char **av) { diff --git a/t/helper/test-sha256.c b/t/helper/test-sha256.c index 08cf149001..0ac6a99d5f 100644 --- a/t/helper/test-sha256.c +++ b/t/helper/test-sha256.c @@ -1,5 +1,5 @@ #include "test-tool.h" -#include "hash-ll.h" +#include "cache.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 d8473cf2fc..96b9a5b529 100644 --- a/t/helper/test-strcmp-offset.c +++ b/t/helper/test-strcmp-offset.c @@ -1,5 +1,5 @@ #include "test-tool.h" -#include "read-cache-ll.h" +#include "cache.h" int cmd__strcmp_offset(int argc UNUSED, const char **argv) { diff --git a/t/helper/test-wildmatch.c b/t/helper/test-wildmatch.c index b4ff5f986a..a95bb4da9b 100644 --- a/t/helper/test-wildmatch.c +++ b/t/helper/test-wildmatch.c @@ -1,5 +1,4 @@ #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 f084034d38..eace08072d 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/t1301-shared-repo.sh b/t/t1301-shared-repo.sh index e5a0d65caa..ae5cd3f5a0 100755 --- a/t/t1301-shared-repo.sh +++ b/t/t1301-shared-repo.sh @@ -52,28 +52,6 @@ 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/t5606-clone-options.sh b/t/t5606-clone-options.sh index 5890319b97..27f9f77638 100755 --- a/t/t5606-clone-options.sh +++ b/t/t5606-clone-options.sh @@ -120,16 +120,6 @@ 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/tag.c b/tag.c index c5426484b2..96dbd5b2d5 100644 --- a/tag.c +++ b/tag.c @@ -2,7 +2,7 @@ #include "environment.h" #include "tag.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" #include "commit.h" #include "tree.h" #include "blob.h" diff --git a/tmp-objdir.c b/tmp-objdir.c index 5f9074ad1c..c33a554f92 100644 --- a/tmp-objdir.c +++ b/tmp-objdir.c @@ -5,13 +5,12 @@ #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-ll.h" +#include "object-store.h" struct tmp_objdir { struct strbuf path; diff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c index db817a80c5..78cfc15d52 100644 --- a/trace2/tr2_cfg.c +++ b/trace2/tr2_cfg.c @@ -4,7 +4,6 @@ #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; diff --git a/transport-helper.c b/transport-helper.c index 5c0bc6a896..6b816940dc 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -8,7 +8,6 @@ #include "gettext.h" #include "hex.h" #include "object-name.h" -#include "repository.h" #include "revision.h" #include "remote.h" #include "string-list.h" diff --git a/transport.c b/transport.c index 4dc187a388..67afdae57c 100644 --- a/transport.c +++ b/transport.c @@ -27,7 +27,7 @@ #include "transport-internal.h" #include "protocol.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" #include "color.h" #include "bundle-uri.h" #include "wrapper.h" diff --git a/tree-diff.c b/tree-diff.c index 966946848a..20bb15f38d 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -4,7 +4,6 @@ #include "git-compat-util.h" #include "diff.h" #include "diffcore.h" -#include "hash.h" #include "tree.h" #include "tree-walk.h" diff --git a/tree-walk.c b/tree-walk.c index 42ed86ef58..d3c48e06df 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -5,7 +5,7 @@ #include "gettext.h" #include "hex.h" #include "object-file.h" -#include "object-store-ll.h" +#include "object-store.h" #include "trace2.h" #include "tree.h" #include "pathspec.h" diff --git a/tree.c b/tree.c index e118914a76..0dd2029a8a 100644 --- a/tree.c +++ b/tree.c @@ -3,7 +3,7 @@ #include "hex.h" #include "tree.h" #include "object-name.h" -#include "object-store-ll.h" +#include "object-store.h" #include "blob.h" #include "commit.h" #include "tag.h" diff --git a/unpack-trees.c b/unpack-trees.c index 87517364dc..e8c32a40dc 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1,4 +1,4 @@ -#include "git-compat-util.h" +#include "cache.h" #include "advice.h" #include "strvec.h" #include "repository.h" @@ -7,7 +7,6 @@ #include "environment.h" #include "gettext.h" #include "hex.h" -#include "name-hash.h" #include "tree.h" #include "tree-walk.h" #include "cache-tree.h" @@ -15,7 +14,6 @@ #include "progress.h" #include "refs.h" #include "attr.h" -#include "read-cache.h" #include "split-index.h" #include "sparse-index.h" #include "submodule.h" @@ -23,7 +21,7 @@ #include "symlinks.h" #include "trace2.h" #include "fsmonitor.h" -#include "object-store-ll.h" +#include "object-store.h" #include "promisor-remote.h" #include "entry.h" #include "parallel-checkout.h" diff --git a/unpack-trees.h b/unpack-trees.h index 9b827c307f..30622aeebf 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 318b650b1e..d3312006a3 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-ll.h" +#include "object-store.h" #include "oid-array.h" #include "tag.h" #include "object.h" diff --git a/walker.c b/walker.c index 65002a7220..24ff7dfdc2 100644 --- a/walker.c +++ b/walker.c @@ -3,9 +3,8 @@ #include "hex.h" #include "walker.h" #include "repository.h" -#include "object-store-ll.h" +#include "object-store.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 b4b01340a0..c448fecd4b 100644 --- a/worktree.c +++ b/worktree.c @@ -3,7 +3,6 @@ #include "alloc.h" #include "environment.h" #include "gettext.h" -#include "path.h" #include "repository.h" #include "refs.h" #include "setup.h" diff --git a/wt-status.c b/wt-status.c index bcd0ef8044..068b76ef6d 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1,4 +1,4 @@ -#include "git-compat-util.h" +#include "cache.h" #include "advice.h" #include "wt-status.h" #include "object.h" @@ -7,10 +7,8 @@ #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" @@ -20,7 +18,6 @@ #include "refs.h" #include "submodule.h" #include "column.h" -#include "read-cache.h" #include "setup.h" #include "strbuf.h" #include "trace.h" diff --git a/xdiff-interface.c b/xdiff-interface.c index abc7275a52..0460e03f5e 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -1,8 +1,7 @@ #include "git-compat-util.h" #include "config.h" #include "hex.h" -#include "object-store-ll.h" -#include "strbuf.h" +#include "object-store.h" #include "xdiff-interface.h" #include "xdiff/xtypes.h" #include "xdiff/xdiffi.h"