diff options
525 files changed, 4035 insertions, 1914 deletions
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 9d5c27807a..003393ed16 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -442,8 +442,12 @@ For C programs: detail. - The first #include in C files, except in platform specific compat/ - implementations, must be either "git-compat-util.h", "cache.h" or - "builtin.h". You do not have to include more than one of these. + implementations and sha1dc/, must be either "git-compat-util.h" or + one of the approved headers that includes it first for you. (The + approved headers currently include "cache.h", "builtin.h", + "t/helper/test-tool.h", "xdiff/xinclude.h", or + "reftable/system.h"). You do not have to include more than one of + these. - A C file must directly include the header files that declare the functions and the types it uses, except for the functions and types diff --git a/Documentation/RelNotes/2.41.0.txt b/Documentation/RelNotes/2.41.0.txt new file mode 100644 index 0000000000..d6095a5df3 --- /dev/null +++ b/Documentation/RelNotes/2.41.0.txt @@ -0,0 +1,88 @@ +Git v2.41 Release Notes +======================= + +UI, Workflows & Features + + * Allow information carried on the WWW-AUthenticate header to be + passed to the credential helpers. + + * A new "fetch.hideRefs" option can be used to exclude specified refs + from "rev-list --objects --stdin --not --all" traversal for + checking object connectivity, most useful when there are many + unrelated histories in a single repository. + + * "git push" has been taught to allow deletion of refs with one-level + names to help repairing a repository who acquired such a ref by + mistake. In general, we don't encourage use of such a ref, and + creation or update to such a ref is rejected as before. + + * Allow "git bisect reset" to check out the original branch when the + branch is already checked out in a different worktree linked to the + same repository. + + * A few subcommands have been taught to stop users from working on a + branch that is being used in another worktree linked to the same + repository. + + * "git format-patch" learned to write a log-message only output file + for empty commits. + + +Performance, Internal Implementation, Development Support etc. + + * Code clean-up to clarify directory traversal API. + + * Code clean-up to clarify the rule that "git-compat-util.h" must be + the first to be included. + + * More work towards -Wunused. + + * Instead of forcing each command to choose to honor GPG related + configuration variables, make the subsystem lazily initialize + itself. + + +Fixes since v2.40 +----------------- + + * "git fsck" learned to check the index files in other worktrees, + just like "git gc" honors them as anchoring points. + (merge 8d3e7eac52 jk/fsck-indices-in-worktrees later to maint). + + * Fix a segfaulting loop. The function and its caller may need + further clean-up. + (merge c5773dc078 ew/commit-reach-clean-up-flags-fix later to maint). + + * "git restore" supports options like "--ours" that are only + meaningful during a conflicted merge, but these options are only + meaningful when updating the working tree files. These options are + marked to be incompatible when both "--staged" and "--worktree" are + in effect. + (merge ee8a88826a ak/restore-both-incompatible-with-conflicts later to maint). + + * Simplify UI to control progress meter given by "git bundle" command. + (merge 8b95521edb jk/bundle-progress later to maint). + + * "git bundle" learned that "-" is a common way to say that the input + comes from the standard input and/or the output goes to the + standard output. It used to work only for output and only from the + root level of the working tree. + (merge 0bbe10313e jk/bundle-use-dash-for-stdfiles later to maint). + + * Once we start running, we assumed that the list of alternate object + databases would never change. Hook into the machinery used to + update the list of packfiles during runtime to update this list as + well. + (merge e2d003dbed ds/reprepare-alternates-when-repreparing-packfiles later to maint). + + * The code to parse "git rebase -X<opt>" was not prepared to see an + unparsable option string, which has been corrected. + (merge 15a4cc912e ab/fix-strategy-opts-parsing later to maint). + + * "git add -p" while the index is unmerged sometimes failed to parse + the diff output it internally produces and died, which has been + corrected. + (merge 28d1122f9c jk/add-p-unmerged-fix later to maint). + + * Other code cleanup, docfix, build fix, etc. + (merge f7111175df as/doc-markup-fix later to maint). diff --git a/Documentation/config/advice.txt b/Documentation/config/advice.txt index a00d0100a8..c96b5b2e5d 100644 --- a/Documentation/config/advice.txt +++ b/Documentation/config/advice.txt @@ -136,4 +136,6 @@ advice.*:: Advice shown when either linkgit:git-add[1] or linkgit:git-rm[1] is asked to update index entries outside the current sparse checkout. + diverging:: + Advice shown when a fast-forward is not possible. -- diff --git a/Documentation/git-bundle.txt b/Documentation/git-bundle.txt index 18a022b4b4..3ab42a19ca 100644 --- a/Documentation/git-bundle.txt +++ b/Documentation/git-bundle.txt @@ -9,7 +9,7 @@ git-bundle - Move objects and refs by archive SYNOPSIS -------- [verse] -'git bundle' create [-q | --quiet | --progress | --all-progress] [--all-progress-implied] +'git bundle' create [-q | --quiet | --progress] [--version=<version>] <file> <git-rev-list-args> 'git bundle' verify [-q | --quiet] <file> 'git bundle' list-heads <file> [<refname>...] @@ -66,7 +66,7 @@ create [options] <file> <git-rev-list-args>:: Used to create a bundle named 'file'. This requires the '<git-rev-list-args>' arguments to define the bundle contents. 'options' contains the options specific to the 'git bundle create' - subcommand. + subcommand. If 'file' is `-`, the bundle is written to stdout. verify <file>:: Used to check that a bundle file is valid and will apply @@ -77,12 +77,13 @@ verify <file>:: Finally, information about additional capabilities, such as "object filter", is printed. See "Capabilities" in linkgit:gitformat-bundle[5] for more information. The exit code is zero for success, but will - be nonzero if the bundle file is invalid. + be nonzero if the bundle file is invalid. If 'file' is `-`, the + bundle is read from stdin. list-heads <file>:: Lists the references defined in the bundle. If followed by a list of references, only references matching those given are - printed out. + printed out. If 'file' is `-`, the bundle is read from stdin. unbundle <file>:: Passes the objects in the bundle to 'git index-pack' @@ -90,6 +91,7 @@ unbundle <file>:: defined references. If a list of references is given, only references matching those in the list are printed. This command is really plumbing, intended to be called only by 'git fetch'. + If 'file' is `-`, the bundle is read from stdin. <git-rev-list-args>:: A list of arguments, acceptable to 'git rev-parse' and @@ -115,22 +117,6 @@ unbundle <file>:: is specified. This flag forces progress status even if the standard error stream is not directed to a terminal. ---all-progress:: - When --stdout is specified then progress report is - displayed during the object count and compression phases - but inhibited during the write-out phase. The reason is - that in some cases the output stream is directly linked - to another command which may wish to display progress - status of its own as it processes incoming pack data. - This flag is like --progress except that it forces progress - report for the write-out phase as well even if --stdout is - used. - ---all-progress-implied:: - This is used to imply --all-progress whenever progress display - is activated. Unlike --all-progress this flag doesn't actually - force any progress display by itself. - --version=<version>:: Specify the bundle version. Version 2 is the older format and can only be used with SHA-1 repositories; the newer version 3 contains capabilities that diff --git a/Documentation/git-credential.txt b/Documentation/git-credential.txt index 29d184ab82..3394c03611 100644 --- a/Documentation/git-credential.txt +++ b/Documentation/git-credential.txt @@ -113,7 +113,13 @@ separated by an `=` (equals) sign, followed by a newline. The key may contain any bytes except `=`, newline, or NUL. The value may contain any bytes except newline or NUL. -In both cases, all bytes are treated as-is (i.e., there is no quoting, +Attributes with keys that end with C-style array brackets `[]` can have +multiple values. Each instance of a multi-valued attribute forms an +ordered list of values - the order of the repeated attributes defines +the order of the values. An empty multi-valued attribute (`key[]=\n`) +acts to clear any previous entries and reset the list. + +In all cases, all bytes are treated as-is (i.e., there is no quoting, and one cannot transmit a value with newline or NUL in it). The list of attributes is terminated by a blank line or end-of-file. @@ -166,6 +172,17 @@ empty string. Components which are missing from the URL (e.g., there is no username in the example above) will be left unset. +`wwwauth[]`:: + + When an HTTP response is received by Git that includes one or more + 'WWW-Authenticate' authentication headers, these will be passed by Git + to credential helpers. ++ +Each 'WWW-Authenticate' header value is passed as a multi-valued +attribute 'wwwauth[]', where the order of the attributes is the same as +they appear in the HTTP response. This attribute is 'one-way' from Git +to pass additional information to credential helpers. + Unrecognised attributes are silently discarded. GIT diff --git a/Documentation/git-merge-tree.txt b/Documentation/git-merge-tree.txt index 88ee942101..ffc4fbf7e8 100644 --- a/Documentation/git-merge-tree.txt +++ b/Documentation/git-merge-tree.txt @@ -108,7 +108,7 @@ This is an integer status followed by a NUL character. The integer status is: 0: merge had conflicts 1: merge was clean - <0: something prevented the merge from running (e.g. access to repository + <0: something prevented the merge from running (e.g. access to repository objects denied by filesystem) [[OIDTLT]] diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt index bcd8069287..f26a7591e3 100644 --- a/Documentation/git-rev-parse.txt +++ b/Documentation/git-rev-parse.txt @@ -197,10 +197,11 @@ respectively, and they must begin with `refs/` when applied to `--glob` or `--all`. If a trailing '/{asterisk}' is intended, it must be given explicitly. ---exclude-hidden=[receive|uploadpack]:: - Do not include refs that would be hidden by `git-receive-pack` or - `git-upload-pack` by consulting the appropriate `receive.hideRefs` or - `uploadpack.hideRefs` configuration along with `transfer.hideRefs` (see +--exclude-hidden=[fetch|receive|uploadpack]:: + Do not include refs that would be hidden by `git-fetch`, + `git-receive-pack` or `git-upload-pack` by consulting the appropriate + `fetch.hideRefs`, `receive.hideRefs` or `uploadpack.hideRefs` + configuration along with `transfer.hideRefs` (see linkgit:git-config[1]). This option affects the next pseudo-ref option `--all` or `--glob` and is cleared after processing them. diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt index 0d90d5b154..90c73d6708 100644 --- a/Documentation/rev-list-options.txt +++ b/Documentation/rev-list-options.txt @@ -195,10 +195,11 @@ respectively, and they must begin with `refs/` when applied to `--glob` or `--all`. If a trailing '/{asterisk}' is intended, it must be given explicitly. ---exclude-hidden=[receive|uploadpack]:: - Do not include refs that would be hidden by `git-receive-pack` or - `git-upload-pack` by consulting the appropriate `receive.hideRefs` or - `uploadpack.hideRefs` configuration along with `transfer.hideRefs` (see +--exclude-hidden=[fetch|receive|uploadpack]:: + Do not include refs that would be hidden by `git-fetch`, + `git-receive-pack` or `git-upload-pack` by consulting the appropriate + `fetch.hideRefs`, `receive.hideRefs` or `uploadpack.hideRefs` + configuration along with `transfer.hideRefs` (see linkgit:git-config[1]). This option affects the next pseudo-ref option `--all` or `--glob` and is cleared after processing them. diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN index a87f0adf80..9a1111af9b 100755 --- a/GIT-VERSION-GEN +++ b/GIT-VERSION-GEN @@ -1,7 +1,7 @@ #!/bin/sh GVF=GIT-VERSION-FILE -DEF_VER=v2.40.0 +DEF_VER=v2.40.GIT LF=' ' @@ -1 +1 @@ -Documentation/RelNotes/2.40.0.txt
\ No newline at end of file +Documentation/RelNotes/2.41.0.txt
\ No newline at end of file @@ -1,4 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "abspath.h" +#include "strbuf.h" /* * Do not use this for inspecting *tracked* content. When path is a @@ -280,3 +282,10 @@ char *prefix_filename(const char *pfx, const char *arg) #endif return strbuf_detach(&path, NULL); } + +char *prefix_filename_except_for_dash(const char *pfx, const char *arg) +{ + if (!strcmp(arg, "-")) + return xstrdup(arg); + return prefix_filename(pfx, arg); +} diff --git a/abspath.h b/abspath.h new file mode 100644 index 0000000000..7cd3de5e9d --- /dev/null +++ b/abspath.h @@ -0,0 +1,33 @@ +#ifndef ABSPATH_H +#define ABSPATH_H + +int is_directory(const char *); +char *strbuf_realpath(struct strbuf *resolved, const char *path, + int die_on_error); +char *strbuf_realpath_forgiving(struct strbuf *resolved, const char *path, + int die_on_error); +char *real_pathdup(const char *path, int die_on_error); +const char *absolute_path(const char *path); +char *absolute_pathdup(const char *path); + +/* + * Concatenate "prefix" (if len is non-zero) and "path", with no + * connecting characters (so "prefix" should end with a "/"). + * Unlike prefix_path, this should be used if the named file does + * not have to interact with index entry; i.e. name of a random file + * on the filesystem. + * + * The return value is always a newly allocated string (even if the + * prefix was empty). + */ +char *prefix_filename(const char *prefix, const char *path); + +/* Likewise, but path=="-" always yields "-" */ +char *prefix_filename_except_for_dash(const char *prefix, const char *path); + +static inline int is_absolute_path(const char *path) +{ + return is_dir_sep(path[0]) || has_dos_drive_prefix(path); +} + +#endif /* ABSPATH_H */ diff --git a/add-interactive.c b/add-interactive.c index 02bf6fc15c..757a9929d4 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -3,6 +3,8 @@ #include "color.h" #include "config.h" #include "diffcore.h" +#include "gettext.h" +#include "hex.h" #include "revision.h" #include "refs.h" #include "string-list.h" diff --git a/add-patch.c b/add-patch.c index 3cbb959194..1e1ee2df59 100644 --- a/add-patch.c +++ b/add-patch.c @@ -1,5 +1,8 @@ #include "cache.h" #include "add-interactive.h" +#include "alloc.h" +#include "environment.h" +#include "gettext.h" #include "strbuf.h" #include "run-command.h" #include "strvec.h" @@ -483,7 +486,8 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps) if (!eol) eol = pend; - if (starts_with(p, "diff ")) { + if (starts_with(p, "diff ") || + starts_with(p, "* Unmerged path ")) { complete_file(marker, hunk); ALLOC_GROW_BY(s->file_diff, s->file_diff_nr, 1, file_diff_alloc); @@ -1,6 +1,8 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "advice.h" #include "config.h" #include "color.h" +#include "gettext.h" #include "help.h" #include "string-list.h" @@ -44,6 +46,7 @@ static struct { [ADVICE_COMMIT_BEFORE_MERGE] = { "commitBeforeMerge", 1 }, [ADVICE_DETACHED_HEAD] = { "detachedHead", 1 }, [ADVICE_SUGGEST_DETACHING_HEAD] = { "suggestDetachingHead", 1 }, + [ADVICE_DIVERGING] = { "diverging", 1 }, [ADVICE_FETCH_SHOW_FORCED_UPDATES] = { "fetchShowForcedUpdates", 1 }, [ADVICE_GRAFT_FILE_DEPRECATED] = { "graftFileDeprecated", 1 }, [ADVICE_IGNORED_HOOK] = { "ignoredHook", 1 }, @@ -217,6 +220,14 @@ void NORETURN die_conclude_merge(void) void NORETURN die_ff_impossible(void) { + advise_if_enabled(ADVICE_DIVERGING, + _("Diverging branches can't be fast-forwarded, you need to either:\n" + "\n" + "\tgit merge --no-ff\n" + "\n" + "or:\n" + "\n" + "\tgit rebase\n")); die(_("Not possible to fast-forward, aborting.")); } @@ -1,8 +1,6 @@ #ifndef ADVICE_H #define ADVICE_H -#include "git-compat-util.h" - struct string_list; /* @@ -21,6 +19,7 @@ struct string_list; ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME, ADVICE_COMMIT_BEFORE_MERGE, ADVICE_DETACHED_HEAD, + ADVICE_DIVERGING, ADVICE_SUGGEST_DETACHING_HEAD, ADVICE_FETCH_SHOW_FORCED_UPDATES, ADVICE_GRAFT_FILE_DEPRECATED, @@ -1,6 +1,8 @@ -#include "cache.h" +#include "git-compat-util.h" #include "alias.h" +#include "alloc.h" #include "config.h" +#include "gettext.h" #include "string-list.h" struct config_alias_data { @@ -8,7 +8,7 @@ * up with maximal alignment because it doesn't know what the object alignment * for the new allocation is. */ -#include "cache.h" +#include "git-compat-util.h" #include "object.h" #include "blob.h" #include "tree.h" @@ -17,4 +17,79 @@ void *alloc_object_node(struct repository *r); struct alloc_state *allocate_alloc_state(void); void clear_alloc_state(struct alloc_state *s); +#define alloc_nr(x) (((x)+16)*3/2) + +/** + * Dynamically growing an array using realloc() is error prone and boring. + * + * Define your array with: + * + * - a pointer (`item`) that points at the array, initialized to `NULL` + * (although please name the variable based on its contents, not on its + * type); + * + * - an integer variable (`alloc`) that keeps track of how big the current + * allocation is, initialized to `0`; + * + * - another integer variable (`nr`) to keep track of how many elements the + * array currently has, initialized to `0`. + * + * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n, + * alloc)`. This ensures that the array can hold at least `n` elements by + * calling `realloc(3)` and adjusting `alloc` variable. + * + * ------------ + * sometype *item; + * size_t nr; + * size_t alloc + * + * for (i = 0; i < nr; i++) + * if (we like item[i] already) + * return; + * + * // we did not like any existing one, so add one + * ALLOC_GROW(item, nr + 1, alloc); + * item[nr++] = value you like; + * ------------ + * + * You are responsible for updating the `nr` variable. + * + * If you need to specify the number of elements to allocate explicitly + * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`. + * + * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some + * added niceties. + * + * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'. + */ +#define ALLOC_GROW(x, nr, alloc) \ + do { \ + if ((nr) > alloc) { \ + if (alloc_nr(alloc) < (nr)) \ + alloc = (nr); \ + else \ + alloc = alloc_nr(alloc); \ + REALLOC_ARRAY(x, alloc); \ + } \ + } while (0) + +/* + * Similar to ALLOC_GROW but handles updating of the nr value and + * zeroing the bytes of the newly-grown array elements. + * + * DO NOT USE any expression with side-effect for any of the + * arguments. + */ +#define ALLOC_GROW_BY(x, nr, increase, alloc) \ + do { \ + if (increase) { \ + size_t new_nr = nr + (increase); \ + if (new_nr < nr) \ + BUG("negative growth in ALLOC_GROW_BY"); \ + ALLOC_GROW(x, new_nr, alloc); \ + memset((x) + nr, 0, sizeof(*(x)) * (increase)); \ + nr = new_nr; \ + } \ + } while (0) + #endif @@ -8,12 +8,17 @@ */ #include "cache.h" +#include "abspath.h" +#include "alloc.h" #include "config.h" #include "object-store.h" #include "blob.h" #include "delta.h" #include "diff.h" #include "dir.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "xdiff-interface.h" #include "ll-merge.h" #include "lockfile.h" @@ -22,6 +27,8 @@ #include "rerere.h" #include "apply.h" #include "entry.h" +#include "setup.h" +#include "wrapper.h" struct gitdiff_data { struct strbuf *root; diff --git a/archive-tar.c b/archive-tar.c index f8fad2946e..497dad0b3a 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -1,13 +1,17 @@ /* * Copyright (c) 2005, 2006 Rene Scharfe */ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" +#include "gettext.h" +#include "hex.h" #include "tar.h" #include "archive.h" #include "object-store.h" #include "streaming.h" #include "run-command.h" +#include "write-or-die.h" #define RECORDSIZE (512) #define BLOCKSIZE (RECORDSIZE * 20) diff --git a/archive-zip.c b/archive-zip.c index 0456f1ebf1..e6f5c10a14 100644 --- a/archive-zip.c +++ b/archive-zip.c @@ -4,10 +4,13 @@ #include "cache.h" #include "config.h" #include "archive.h" +#include "gettext.h" +#include "hex.h" #include "streaming.h" #include "utf8.h" #include "object-store.h" #include "userdiff.h" +#include "write-or-die.h" #include "xdiff-interface.h" #include "date.h" @@ -1,5 +1,11 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "abspath.h" +#include "alloc.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" +#include "setup.h" #include "refs.h" #include "object-store.h" #include "commit.h" @@ -7,14 +7,18 @@ */ #include "cache.h" +#include "alloc.h" #include "config.h" +#include "environment.h" #include "exec-cmd.h" #include "attr.h" #include "dir.h" +#include "gettext.h" #include "utf8.h" #include "quote.h" #include "revision.h" #include "object-store.h" +#include "setup.h" #include "thread-utils.h" const char git_attr__true[] = "(builtin)true"; @@ -2,6 +2,9 @@ #include "config.h" #include "commit.h" #include "diff.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "revision.h" #include "refs.h" #include "list-objects.h" @@ -5,6 +5,9 @@ #include "mergesort.h" #include "diff.h" #include "diffcore.h" +#include "gettext.h" +#include "hex.h" +#include "setup.h" #include "tag.h" #include "blame.h" #include "alloc.h" @@ -1,7 +1,6 @@ #ifndef BLAME_H #define BLAME_H -#include "cache.h" #include "commit.h" #include "xdiff-interface.h" #include "revision.h" @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "blob.h" #include "repository.h" #include "alloc.h" @@ -2,6 +2,9 @@ #include "cache.h" #include "config.h" #include "branch.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "refs.h" #include "refspec.h" #include "remote.h" @@ -821,12 +824,16 @@ void remove_branch_state(struct repository *r, int verbose) void die_if_checked_out(const char *branch, int ignore_current_worktree) { struct worktree **worktrees = get_worktrees(); - const struct worktree *wt; - wt = find_shared_symref(worktrees, "HEAD", branch); - if (wt && (!ignore_current_worktree || !wt->is_current)) { - skip_prefix(branch, "refs/heads/", &branch); - die(_("'%s' is already checked out at '%s'"), branch, wt->path); + for (int i = 0; worktrees[i]; i++) { + if (worktrees[i]->is_current && ignore_current_worktree) + continue; + + if (is_shared_symref(worktrees[i], "HEAD", branch)) { + skip_prefix(branch, "refs/heads/", &branch); + die(_("'%s' is already checked out at '%s'"), + branch, worktrees[i]->path); + } } free_worktrees(worktrees); diff --git a/builtin/add.c b/builtin/add.c index 61dd386d10..f12054d9be 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -9,6 +9,7 @@ #include "builtin.h" #include "lockfile.h" #include "dir.h" +#include "gettext.h" #include "pathspec.h" #include "exec-cmd.h" #include "cache-tree.h" diff --git a/builtin/am.c b/builtin/am.c index 456884852e..cd1e20f24e 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -5,9 +5,13 @@ */ #define USE_THE_INDEX_VARIABLE #include "cache.h" +#include "abspath.h" #include "config.h" #include "builtin.h" +#include "environment.h" #include "exec-cmd.h" +#include "gettext.h" +#include "hex.h" #include "parse-options.h" #include "dir.h" #include "run-command.h" @@ -35,6 +39,7 @@ #include "packfile.h" #include "repository.h" #include "pretty.h" +#include "wrapper.h" /** * Returns the length of the first line of msg. @@ -2301,17 +2306,6 @@ static int parse_opt_show_current_patch(const struct option *opt, const char *ar return 0; } -static int git_am_config(const char *k, const char *v, void *cb UNUSED) -{ - int status; - - status = git_gpg_config(k, v, NULL); - if (status) - return status; - - return git_default_config(k, v, NULL); -} - int cmd_am(int argc, const char **argv, const char *prefix) { struct am_state state; @@ -2435,7 +2429,7 @@ int cmd_am(int argc, const char **argv, const char *prefix) if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(usage, options); - git_config(git_am_config, NULL); + git_config(git_default_config, NULL); am_state_init(&state); diff --git a/builtin/apply.c b/builtin/apply.c index 555219de40..fe72c0ec3e 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -1,5 +1,6 @@ #include "cache.h" #include "builtin.h" +#include "gettext.h" #include "parse-options.h" #include "apply.h" diff --git a/builtin/archive.c b/builtin/archive.c index f094390ee0..d13934f1a8 100644 --- a/builtin/archive.c +++ b/builtin/archive.c @@ -5,6 +5,7 @@ #include "cache.h" #include "builtin.h" #include "archive.h" +#include "gettext.h" #include "transport.h" #include "parse-options.h" #include "pkt-line.h" @@ -81,7 +82,7 @@ static int run_remote_archiver(int argc, const char **argv, int cmd_archive(int argc, const char **argv, const char *prefix) { const char *exec = "git-upload-archive"; - const char *output = NULL; + char *output = NULL; const char *remote = NULL; struct option local_opts[] = { OPT_FILENAME('o', "output", &output, @@ -106,5 +107,6 @@ int cmd_archive(int argc, const char **argv, const char *prefix) setvbuf(stderr, NULL, _IOLBF, BUFSIZ); + UNLEAK(output); return write_archive(argc, argv, prefix, the_repository, output, 0); } diff --git a/builtin/bisect.c b/builtin/bisect.c index 0f35361bd1..26f07357a0 100644 --- a/builtin/bisect.c +++ b/builtin/bisect.c @@ -1,5 +1,8 @@ #include "builtin.h" #include "cache.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "parse-options.h" #include "bisect.h" #include "refs.h" @@ -9,6 +12,7 @@ #include "prompt.h" #include "quote.h" #include "revision.h" +#include "wrapper.h" static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS") static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV") @@ -244,7 +248,8 @@ static int bisect_reset(const char *commit) struct child_process cmd = CHILD_PROCESS_INIT; cmd.git_cmd = 1; - strvec_pushl(&cmd.args, "checkout", branch.buf, "--", NULL); + strvec_pushl(&cmd.args, "checkout", "--ignore-other-worktrees", + branch.buf, "--", NULL); if (run_command(&cmd)) { error(_("could not check out original" " HEAD '%s'. Try 'git bisect" diff --git a/builtin/blame.c b/builtin/blame.c index 91e04f57cc..a8d2114adc 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -5,10 +5,14 @@ * See COPYING for licensing conditions */ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "color.h" #include "builtin.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "repository.h" #include "commit.h" #include "diff.h" @@ -27,7 +31,9 @@ #include "object-store.h" #include "blame.h" #include "refs.h" +#include "setup.h" #include "tag.h" +#include "write-or-die.h" static char blame_usage[] = N_("git blame [<options>] [<rev-opts>] [<rev>] [--] <file>"); static char annotate_usage[] = N_("git annotate [<options>] [<rev-opts>] [<rev>] [--] <file>"); diff --git a/builtin/branch.c b/builtin/branch.c index 45910039e6..5706eb0097 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -8,9 +8,11 @@ #include "cache.h" #include "config.h" #include "color.h" +#include "environment.h" #include "refs.h" #include "commit.h" #include "builtin.h" +#include "gettext.h" #include "remote.h" #include "parse-options.h" #include "branch.h" @@ -24,6 +26,7 @@ #include "worktree.h" #include "help.h" #include "commit-reach.h" +#include "wrapper.h" static const char * const builtin_branch_usage[] = { N_("git branch [<options>] [-r | -a] [--merged] [--no-merged]"), diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 5bc254be80..52955e1d38 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -1,4 +1,6 @@ #include "builtin.h" +#include "abspath.h" +#include "gettext.h" #include "parse-options.h" #include "strbuf.h" #include "help.h" @@ -6,7 +8,8 @@ #include "hook.h" #include "hook-list.h" #include "diagnose.h" - +#include "setup.h" +#include "wrapper.h" static void get_system_info(struct strbuf *sys_info) { diff --git a/builtin/bundle.c b/builtin/bundle.c index acceef6200..e68fc83d94 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -1,4 +1,7 @@ #include "builtin.h" +#include "abspath.h" +#include "gettext.h" +#include "setup.h" #include "strvec.h" #include "parse-options.h" #include "cache.h" @@ -12,7 +15,7 @@ */ #define BUILTIN_BUNDLE_CREATE_USAGE \ - N_("git bundle create [-q | --quiet | --progress | --all-progress] [--all-progress-implied]\n" \ + N_("git bundle create [-q | --quiet | --progress]\n" \ " [--version=<version>] <file> <git-rev-list-args>") #define BUILTIN_BUNDLE_VERIFY_USAGE \ N_("git bundle verify [-q | --quiet] <file>") @@ -59,12 +62,12 @@ static int parse_options_cmd_bundle(int argc, PARSE_OPT_STOP_AT_NON_OPTION); if (!argc) usage_msg_opt(_("need a <file> argument"), usagestr, options); - *bundle_file = prefix_filename(prefix, argv[0]); + *bundle_file = prefix_filename_except_for_dash(prefix, argv[0]); return argc; } static int cmd_bundle_create(int argc, const char **argv, const char *prefix) { - int all_progress_implied = 0; + int all_progress_implied = 1; int progress = isatty(STDERR_FILENO); struct strvec pack_opts; int version = -1; @@ -74,11 +77,12 @@ static int cmd_bundle_create(int argc, const char **argv, const char *prefix) { N_("do not show progress meter"), 0), OPT_SET_INT(0, "progress", &progress, N_("show progress meter"), 1), - OPT_SET_INT(0, "all-progress", &progress, - N_("show progress meter during object writing phase"), 2), - OPT_BOOL(0, "all-progress-implied", - &all_progress_implied, - N_("similar to --all-progress when progress meter is shown")), + OPT_SET_INT_F(0, "all-progress", &progress, + N_("historical; same as --progress"), 2, + PARSE_OPT_HIDDEN), + OPT_HIDDEN_BOOL(0, "all-progress-implied", + &all_progress_implied, + N_("historical; does nothing")), OPT_INTEGER(0, "version", &version, N_("specify bundle format version")), OPT_END() @@ -107,6 +111,23 @@ static int cmd_bundle_create(int argc, const char **argv, const char *prefix) { return ret; } +/* + * Similar to read_bundle_header(), but handle "-" as stdin. + */ +static int open_bundle(const char *path, struct bundle_header *header, + const char **name) +{ + if (!strcmp(path, "-")) { + if (name) + *name = "<stdin>"; + return read_bundle_header_fd(0, header, "<stdin>"); + } + + if (name) + *name = path; + return read_bundle_header(path, header); +} + static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) { struct bundle_header header = BUNDLE_HEADER_INIT; int bundle_fd = -1; @@ -118,12 +139,13 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) { OPT_END() }; char *bundle_file; + const char *name; argc = parse_options_cmd_bundle(argc, argv, prefix, builtin_bundle_verify_usage, options, &bundle_file); /* bundle internals use argv[1] as further parameters */ - if ((bundle_fd = read_bundle_header(bundle_file, &header)) < 0) { + if ((bundle_fd = open_bundle(bundle_file, &header, &name)) < 0) { ret = 1; goto cleanup; } @@ -134,7 +156,7 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) { goto cleanup; } - fprintf(stderr, _("%s is okay\n"), bundle_file); + fprintf(stderr, _("%s is okay\n"), name); ret = 0; cleanup: free(bundle_file); @@ -155,7 +177,7 @@ static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix builtin_bundle_list_heads_usage, options, &bundle_file); /* bundle internals use argv[1] as further parameters */ - if ((bundle_fd = read_bundle_header(bundle_file, &header)) < 0) { + if ((bundle_fd = open_bundle(bundle_file, &header, NULL)) < 0) { ret = 1; goto cleanup; } @@ -185,7 +207,7 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix) builtin_bundle_unbundle_usage, options, &bundle_file); /* bundle internals use argv[1] as further parameters */ - if ((bundle_fd = read_bundle_header(bundle_file, &header)) < 0) { + if ((bundle_fd = open_bundle(bundle_file, &header, NULL)) < 0) { ret = 1; goto cleanup; } diff --git a/builtin/cat-file.c b/builtin/cat-file.c index b72dd91bd1..04d4bb6c77 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -5,9 +5,14 @@ */ #define USE_THE_INDEX_VARIABLE #include "cache.h" +#include "alloc.h" #include "config.h" #include "builtin.h" #include "diff.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" +#include "ident.h" #include "parse-options.h" #include "userdiff.h" #include "streaming.h" @@ -15,8 +20,10 @@ #include "oid-array.h" #include "packfile.h" #include "object-store.h" +#include "replace-object.h" #include "promisor-remote.h" #include "mailmap.h" +#include "write-or-die.h" enum batch_mode { BATCH_MODE_CONTENTS, @@ -564,7 +571,7 @@ static int batch_object_cb(const struct object_id *oid, void *vdata) } static int collect_loose_object(const struct object_id *oid, - const char *path, + const char *path UNUSED, void *data) { oid_array_append(data, oid); @@ -572,8 +579,8 @@ static int collect_loose_object(const struct object_id *oid, } static int collect_packed_object(const struct object_id *oid, - struct packed_git *pack, - uint32_t pos, + struct packed_git *pack UNUSED, + uint32_t pos UNUSED, void *data) { oid_array_append(data, oid); @@ -596,7 +603,7 @@ static int batch_unordered_object(const struct object_id *oid, } static int batch_unordered_loose(const struct object_id *oid, - const char *path, + const char *path UNUSED, void *data) { return batch_unordered_object(oid, NULL, 0, data); diff --git a/builtin/check-attr.c b/builtin/check-attr.c index d7a40e674c..1dbe9d6ca8 100644 --- a/builtin/check-attr.c +++ b/builtin/check-attr.c @@ -3,8 +3,12 @@ #include "cache.h" #include "config.h" #include "attr.h" +#include "environment.h" +#include "gettext.h" #include "quote.h" +#include "setup.h" #include "parse-options.h" +#include "write-or-die.h" static int all_attrs; static int cached_attrs; diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c index ab776061c7..9401dad007 100644 --- a/builtin/check-ignore.c +++ b/builtin/check-ignore.c @@ -3,10 +3,12 @@ #include "cache.h" #include "config.h" #include "dir.h" +#include "gettext.h" #include "quote.h" #include "pathspec.h" #include "parse-options.h" #include "submodule.h" +#include "write-or-die.h" static int quiet, verbose, stdin_paths, show_non_matching, no_index; static const char * const check_ignore_usage[] = { diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c index 7dc47e4793..002d2941e9 100644 --- a/builtin/check-mailmap.c +++ b/builtin/check-mailmap.c @@ -1,8 +1,11 @@ #include "builtin.h" #include "config.h" +#include "gettext.h" +#include "ident.h" #include "mailmap.h" #include "parse-options.h" #include "string-list.h" +#include "write-or-die.h" static int use_stdin; static const char * const check_mailmap_usage[] = { diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c index fd0e5f8683..b026346742 100644 --- a/builtin/check-ref-format.c +++ b/builtin/check-ref-format.c @@ -5,6 +5,7 @@ #include "cache.h" #include "refs.h" #include "builtin.h" +#include "setup.h" #include "strbuf.h" static const char builtin_check_ref_format_usage[] = diff --git a/builtin/checkout--worker.c b/builtin/checkout--worker.c index ede7dc32a4..2120dd1d30 100644 --- a/builtin/checkout--worker.c +++ b/builtin/checkout--worker.c @@ -1,6 +1,8 @@ #include "builtin.h" +#include "alloc.h" #include "config.h" #include "entry.h" +#include "gettext.h" #include "parallel-checkout.h" #include "parse-options.h" #include "pkt-line.h" diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c index cf6fba97ba..7df673e3e7 100644 --- a/builtin/checkout-index.c +++ b/builtin/checkout-index.c @@ -8,12 +8,14 @@ #include "builtin.h" #include "config.h" #include "dir.h" +#include "gettext.h" #include "lockfile.h" #include "quote.h" #include "cache-tree.h" #include "parse-options.h" #include "entry.h" #include "parallel-checkout.h" +#include "setup.h" #define CHECKOUT_ALL 4 static int nul_term_line; diff --git a/builtin/checkout.c b/builtin/checkout.c index cb7cd315b3..38a8cd6a96 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -9,6 +9,9 @@ #include "config.h" #include "diff.h" #include "dir.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "hook.h" #include "ll-merge.h" #include "lockfile.h" @@ -20,6 +23,7 @@ #include "resolve-undo.h" #include "revision.h" #include "run-command.h" +#include "setup.h" #include "submodule.h" #include "submodule-config.h" #include "tree.h" @@ -75,7 +79,7 @@ struct checkout_opts { const char *ignore_unmerged_opt; int ignore_unmerged; int pathspec_file_nul; - const char *pathspec_from_file; + char *pathspec_from_file; const char *new_branch; const char *new_branch_force; @@ -489,15 +493,28 @@ static int checkout_paths(const struct checkout_opts *opts, die(_("'%s' must be used when '%s' is not specified"), "--worktree", "--source"); - if (opts->checkout_index && !opts->checkout_worktree && - opts->writeout_stage) - die(_("'%s' or '%s' cannot be used with %s"), - "--ours", "--theirs", "--staged"); - - if (opts->checkout_index && !opts->checkout_worktree && - opts->merge) - die(_("'%s' or '%s' cannot be used with %s"), - "--merge", "--conflict", "--staged"); + /* + * Reject --staged option to the restore command when combined with + * merge-related options. Use the accept_ref flag to distinguish it + * from the checkout command, which does not accept --staged anyway. + * + * `restore --ours|--theirs --worktree --staged` could mean resolving + * conflicted paths to one side in both the worktree and the index, + * but does not currently. + * + * `restore --merge|--conflict=<style>` already recreates conflicts + * in both the worktree and the index, so adding --staged would be + * meaningless. + */ + if (!opts->accept_ref && opts->checkout_index) { + if (opts->writeout_stage) + die(_("'%s' or '%s' cannot be used with %s"), + "--ours", "--theirs", "--staged"); + + if (opts->merge) + die(_("'%s' or '%s' cannot be used with %s"), + "--merge", "--conflict", "--staged"); + } if (opts->patch_mode) { enum add_p_mode patch_mode; @@ -1883,6 +1900,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) options, checkout_usage, &new_branch_info); branch_info_release(&new_branch_info); clear_pathspec(&opts.pathspec); + free(opts.pathspec_from_file); FREE_AND_NULL(options); return ret; } diff --git a/builtin/clean.c b/builtin/clean.c index 10aaa8c603..14c0d555ea 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -8,10 +8,13 @@ #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 "setup.h" #include "string-list.h" #include "quote.h" #include "column.h" diff --git a/builtin/clone.c b/builtin/clone.c index 4de4640ed4..c171def1f3 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -10,7 +10,11 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "abspath.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "lockfile.h" #include "parse-options.h" #include "fetch-pack.h" @@ -29,6 +33,7 @@ #include "branch.h" #include "remote.h" #include "run-command.h" +#include "setup.h" #include "connected.h" #include "packfile.h" #include "list-objects-filter-options.h" diff --git a/builtin/column.c b/builtin/column.c index 158fdf53d9..de623a16c2 100644 --- a/builtin/column.c +++ b/builtin/column.c @@ -1,6 +1,7 @@ #include "builtin.h" #include "cache.h" #include "config.h" +#include "gettext.h" #include "strbuf.h" #include "parse-options.h" #include "string-list.h" diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 93704f95a9..9011426976 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -1,12 +1,16 @@ #include "builtin.h" #include "config.h" #include "dir.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "lockfile.h" #include "parse-options.h" #include "repository.h" #include "commit-graph.h" #include "object-store.h" #include "progress.h" +#include "replace-object.h" #include "tag.h" #define BUILTIN_COMMIT_GRAPH_VERIFY_USAGE \ diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index 7941512c19..15be167f87 100644 --- a/builtin/commit-tree.c +++ b/builtin/commit-tree.c @@ -5,6 +5,8 @@ */ #include "cache.h" #include "config.h" +#include "gettext.h" +#include "hex.h" #include "object-store.h" #include "repository.h" #include "commit.h" @@ -37,14 +39,6 @@ static void new_parent(struct commit *parent, struct commit_list **parents_p) commit_list_insert(parent, parents_p); } -static int commit_tree_config(const char *var, const char *value, void *cb) -{ - int status = git_gpg_config(var, value, NULL); - if (status) - return status; - return git_default_config(var, value, cb); -} - static int parse_parent_arg_callback(const struct option *opt, const char *arg, int unset) { @@ -121,7 +115,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix) OPT_END() }; - git_config(commit_tree_config, NULL); + git_config(git_default_config, NULL); if (argc < 2 || !strcmp(argv[1], "-h")) usage_with_options(commit_tree_usage, options); diff --git a/builtin/commit.c b/builtin/commit.c index 92b7e8c56f..9d8e1ea91a 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -12,10 +12,12 @@ #include "cache-tree.h" #include "color.h" #include "dir.h" +#include "environment.h" #include "builtin.h" #include "diff.h" #include "diffcore.h" #include "commit.h" +#include "gettext.h" #include "revision.h" #include "wt-status.h" #include "run-command.h" @@ -1603,7 +1605,6 @@ int cmd_status(int argc, const char **argv, const char *prefix) static int git_commit_config(const char *k, const char *v, void *cb) { struct wt_status *s = cb; - int status; if (!strcmp(k, "commit.template")) return git_config_pathname(&template_file, k, v); @@ -1623,9 +1624,6 @@ static int git_commit_config(const char *k, const char *v, void *cb) return 0; } - status = git_gpg_config(k, v, NULL); - if (status) - return status; return git_status_config(k, v, s); } diff --git a/builtin/config.c b/builtin/config.c index 060cf9f3e0..fe79fb60c4 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -1,11 +1,17 @@ #include "builtin.h" -#include "cache.h" +#include "abspath.h" +#include "alloc.h" #include "config.h" #include "color.h" +#include "environment.h" +#include "gettext.h" +#include "ident.h" #include "parse-options.h" #include "urlmatch.h" #include "quote.h" +#include "setup.h" #include "worktree.h" +#include "wrapper.h" static const char *const builtin_config_usage[] = { N_("git config [<options>]"), diff --git a/builtin/count-objects.c b/builtin/count-objects.c index 07b9419596..f3d8f1bcbb 100644 --- a/builtin/count-objects.c +++ b/builtin/count-objects.c @@ -7,6 +7,8 @@ #include "cache.h" #include "config.h" #include "dir.h" +#include "environment.h" +#include "gettext.h" #include "repository.h" #include "builtin.h" #include "parse-options.h" @@ -57,7 +59,8 @@ static void loose_garbage(const char *path) report_garbage(PACKDIR_FILE_GARBAGE, path); } -static int count_loose(const struct object_id *oid, const char *path, void *data) +static int count_loose(const struct object_id *oid, const char *path, + void *data UNUSED) { struct stat st; @@ -72,7 +75,8 @@ static int count_loose(const struct object_id *oid, const char *path, void *data return 0; } -static int count_cruft(const char *basename, const char *path, void *data) +static int count_cruft(const char *basename UNUSED, const char *path, + void *data UNUSED) { loose_garbage(path); return 0; diff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c index 338058be7f..62c09a271d 100644 --- a/builtin/credential-cache--daemon.c +++ b/builtin/credential-cache--daemon.c @@ -1,4 +1,7 @@ #include "builtin.h" +#include "abspath.h" +#include "alloc.h" +#include "gettext.h" #include "parse-options.h" #ifndef NO_UNIX_SOCKETS diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c index 78c02ad531..508da4c6e4 100644 --- a/builtin/credential-cache.c +++ b/builtin/credential-cache.c @@ -1,5 +1,8 @@ #include "builtin.h" +#include "gettext.h" #include "parse-options.h" +#include "wrapper.h" +#include "write-or-die.h" #ifndef NO_UNIX_SOCKETS diff --git a/builtin/credential-store.c b/builtin/credential-store.c index 62a4f3c265..8977604eb9 100644 --- a/builtin/credential-store.c +++ b/builtin/credential-store.c @@ -1,9 +1,11 @@ #include "builtin.h" #include "config.h" +#include "gettext.h" #include "lockfile.h" #include "credential.h" #include "string-list.h" #include "parse-options.h" +#include "write-or-die.h" static struct lock_file credential_lock; diff --git a/builtin/describe.c b/builtin/describe.c index e880a86f37..0125d4ddba 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -1,6 +1,9 @@ #define USE_THE_INDEX_VARIABLE #include "cache.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "lockfile.h" #include "commit.h" #include "tag.h" @@ -12,6 +15,7 @@ #include "revision.h" #include "diff.h" #include "hashmap.h" +#include "setup.h" #include "strvec.h" #include "run-command.h" #include "object-store.h" diff --git a/builtin/diagnose.c b/builtin/diagnose.c index d52015c67a..0f8b64994c 100644 --- a/builtin/diagnose.c +++ b/builtin/diagnose.c @@ -1,4 +1,6 @@ #include "builtin.h" +#include "abspath.h" +#include "gettext.h" #include "parse-options.h" #include "diagnose.h" diff --git a/builtin/diff-index.c b/builtin/diff-index.c index 35dc9b23ee..b9a19bb7d3 100644 --- a/builtin/diff-index.c +++ b/builtin/diff-index.c @@ -5,6 +5,7 @@ #include "commit.h" #include "revision.h" #include "builtin.h" +#include "setup.h" #include "submodule.h" static const char diff_cache_usage[] = diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index 25b853b85c..385c2d0230 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -3,6 +3,8 @@ #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" diff --git a/builtin/diff.c b/builtin/diff.c index 1091c377af..8f386535d6 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -11,6 +11,7 @@ #include "color.h" #include "commit.h" #include "blob.h" +#include "gettext.h" #include "tag.h" #include "diff.h" #include "diff-merges.h" @@ -18,6 +19,7 @@ #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 30daa83bc6..e010a21bfb 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -13,10 +13,14 @@ */ #define USE_THE_INDEX_VARIABLE #include "cache.h" +#include "abspath.h" #include "config.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 "strvec.h" #include "strbuf.h" @@ -24,6 +28,8 @@ #include "object-store.h" #include "dir.h" #include "entry.h" +#include "setup.h" +#include "wrapper.h" static int trust_exit_code; diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 550f078a8e..0bb779deb6 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -6,6 +6,8 @@ #include "builtin.h" #include "cache.h" #include "config.h" +#include "gettext.h" +#include "hex.h" #include "refs.h" #include "refspec.h" #include "object-store.h" diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 2065434178..68b1a53987 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -1,5 +1,9 @@ #include "builtin.h" +#include "abspath.h" #include "cache.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "repository.h" #include "config.h" #include "lockfile.h" @@ -20,6 +24,7 @@ #include "commit-reach.h" #include "khash.h" #include "date.h" +#include "wrapper.h" #define PACK_ID_BITS 16 #define MAX_PACK_ID ((1<<PACK_ID_BITS)-1) @@ -436,7 +441,7 @@ static void set_checkpoint_signal(void) #else -static void checkpoint_signal(int signo) +static void checkpoint_signal(int signo UNUSED) { checkpoint_requested = 1; } diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index afe679368d..60e5a10ffc 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -1,4 +1,7 @@ #include "builtin.h" +#include "alloc.h" +#include "gettext.h" +#include "hex.h" #include "pkt-line.h" #include "fetch-pack.h" #include "remote.h" diff --git a/builtin/fetch.c b/builtin/fetch.c index 0020015ca4..6a6a58d49c 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -3,6 +3,9 @@ */ #include "cache.h" #include "config.h" +#include "gettext.h" +#include "environment.h" +#include "hex.h" #include "repository.h" #include "refs.h" #include "refspec.h" @@ -1133,6 +1136,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, if (!connectivity_checked) { struct check_connected_options opt = CHECK_CONNECTED_INIT; + opt.exclude_hidden_refs_section = "fetch"; rm = ref_map; if (check_connected(iterate_ref_map, &rm, &opt)) { rc = error(_("%s did not send all necessary objects\n"), url); @@ -1326,6 +1330,7 @@ static int check_exist_and_connected(struct ref *ref_map) } opt.quiet = 1; + opt.exclude_hidden_refs_section = "fetch"; return check_connected(iterate_ref_map, &rm, &opt); } @@ -1881,6 +1886,8 @@ static void add_options_to_argv(struct strvec *argv) strvec_push(argv, "--ipv4"); else if (family == TRANSPORT_FAMILY_IPV6) strvec_push(argv, "--ipv6"); + if (!write_fetch_head) + strvec_push(argv, "--no-write-fetch-head"); } /* Fetch multiple remotes in parallel */ @@ -1891,7 +1898,8 @@ struct parallel_fetch_state { int next, result; }; -static int fetch_next_remote(struct child_process *cp, struct strbuf *out, +static int fetch_next_remote(struct child_process *cp, + struct strbuf *out UNUSED, void *cb, void **task_cb) { struct parallel_fetch_state *state = cb; @@ -1913,7 +1921,8 @@ static int fetch_next_remote(struct child_process *cp, struct strbuf *out, return 1; } -static int fetch_failed_to_start(struct strbuf *out, void *cb, void *task_cb) +static int fetch_failed_to_start(struct strbuf *out UNUSED, + void *cb, void *task_cb) { struct parallel_fetch_state *state = cb; const char *remote = task_cb; diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index 8d8fd393f8..cc81241642 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -1,7 +1,9 @@ #include "builtin.h" #include "config.h" #include "fmt-merge-msg.h" +#include "gettext.h" #include "parse-options.h" +#include "wrapper.h" static const char * const fmt_merge_msg_usage[] = { N_("git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]"), diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index 6f62f40d12..7a8ff5902c 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -1,6 +1,7 @@ #include "builtin.h" #include "cache.h" #include "config.h" +#include "gettext.h" #include "refs.h" #include "object.h" #include "parse-options.h" diff --git a/builtin/for-each-repo.c b/builtin/for-each-repo.c index 6aeac37148..27425c2fc9 100644 --- a/builtin/for-each-repo.c +++ b/builtin/for-each-repo.c @@ -1,6 +1,7 @@ #include "cache.h" #include "config.h" #include "builtin.h" +#include "gettext.h" #include "parse-options.h" #include "run-command.h" #include "string-list.h" diff --git a/builtin/fsck.c b/builtin/fsck.c index 2bf183a43b..095b39d398 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -1,6 +1,7 @@ -#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "cache.h" +#include "gettext.h" +#include "hex.h" #include "repository.h" #include "config.h" #include "commit.h" @@ -19,6 +20,7 @@ #include "decorate.h" #include "packfile.h" #include "object-store.h" +#include "replace-object.h" #include "resolve-undo.h" #include "run-command.h" #include "worktree.h" @@ -233,17 +235,17 @@ static void mark_unreachable_referents(const struct object_id *oid) } static int mark_loose_unreachable_referents(const struct object_id *oid, - const char *path, - void *data) + const char *path UNUSED, + void *data UNUSED) { mark_unreachable_referents(oid); return 0; } static int mark_packed_unreachable_referents(const struct object_id *oid, - struct packed_git *pack, - uint32_t pos, - void *data) + struct packed_git *pack UNUSED, + uint32_t pos UNUSED, + void *data UNUSED) { mark_unreachable_referents(oid); return 0; @@ -661,14 +663,15 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data) return 0; /* keep checking other objects, even if we saw an error */ } -static int fsck_cruft(const char *basename, const char *path, void *data) +static int fsck_cruft(const char *basename, const char *path, + void *data UNUSED) { if (!starts_with(basename, "tmp_obj_")) fprintf_ln(stderr, _("bad sha1 file: %s"), path); return 0; } -static int fsck_subdir(unsigned int nr, const char *path, void *data) +static int fsck_subdir(unsigned int nr, const char *path UNUSED, void *data) { struct for_each_loose_cb *cb_data = data; struct progress *progress = cb_data->progress; @@ -732,19 +735,19 @@ static int fsck_head_link(const char *head_ref_name, return 0; } -static int fsck_cache_tree(struct cache_tree *it) +static int fsck_cache_tree(struct cache_tree *it, const char *index_path) { int i; int err = 0; if (verbose) - fprintf_ln(stderr, _("Checking cache tree")); + fprintf_ln(stderr, _("Checking cache tree of %s"), index_path); if (0 <= it->entry_count) { struct object *obj = parse_object(the_repository, &it->oid); if (!obj) { - error(_("%s: invalid sha1 pointer in cache-tree"), - oid_to_hex(&it->oid)); + error(_("%s: invalid sha1 pointer in cache-tree of %s"), + oid_to_hex(&it->oid), index_path); errors_found |= ERROR_REFS; return 1; } @@ -755,11 +758,12 @@ static int fsck_cache_tree(struct cache_tree *it) err |= objerror(obj, _("non-tree in cache-tree")); } for (i = 0; i < it->subtree_nr; i++) - err |= fsck_cache_tree(it->down[i]->cache_tree); + err |= fsck_cache_tree(it->down[i]->cache_tree, index_path); return err; } -static int fsck_resolve_undo(struct index_state *istate) +static int fsck_resolve_undo(struct index_state *istate, + const char *index_path) { struct string_list_item *item; struct string_list *resolve_undo = istate->resolve_undo; @@ -782,8 +786,9 @@ static int fsck_resolve_undo(struct index_state *istate) obj = parse_object(the_repository, &ru->oid[i]); if (!obj) { - error(_("%s: invalid sha1 pointer in resolve-undo"), - oid_to_hex(&ru->oid[i])); + error(_("%s: invalid sha1 pointer in resolve-undo of %s"), + oid_to_hex(&ru->oid[i]), + index_path); errors_found |= ERROR_REFS; continue; } @@ -796,6 +801,38 @@ static int fsck_resolve_undo(struct index_state *istate) return 0; } +static void fsck_index(struct index_state *istate, const char *index_path, + int is_main_index) +{ + unsigned int i; + + /* TODO: audit for interaction with sparse-index. */ + ensure_full_index(istate); + for (i = 0; i < istate->cache_nr; i++) { + unsigned int mode; + struct blob *blob; + struct object *obj; + + mode = istate->cache[i]->ce_mode; + if (S_ISGITLINK(mode)) + continue; + blob = lookup_blob(the_repository, + &istate->cache[i]->oid); + if (!blob) + continue; + obj = &blob->object; + obj->flags |= USED; + fsck_put_object_name(&fsck_walk_options, &obj->oid, + "%s:%s", + is_main_index ? "" : index_path, + istate->cache[i]->name); + mark_object_reachable(obj); + } + if (istate->cache_tree) + fsck_cache_tree(istate->cache_tree, index_path); + fsck_resolve_undo(istate, index_path); +} + static void mark_object_for_connectivity(const struct object_id *oid) { struct object *obj = lookup_unknown_object(the_repository, oid); @@ -803,17 +840,17 @@ static void mark_object_for_connectivity(const struct object_id *oid) } static int mark_loose_for_connectivity(const struct object_id *oid, - const char *path, - void *data) + const char *path UNUSED, + void *data UNUSED) { mark_object_for_connectivity(oid); return 0; } static int mark_packed_for_connectivity(const struct object_id *oid, - struct packed_git *pack, - uint32_t pos, - void *data) + struct packed_git *pack UNUSED, + uint32_t pos UNUSED, + void *data UNUSED) { mark_object_for_connectivity(oid); return 0; @@ -956,32 +993,30 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) } if (keep_cache_objects) { + struct worktree **worktrees, **p; + verify_index_checksum = 1; verify_ce_order = 1; - repo_read_index(the_repository); - /* TODO: audit for interaction with sparse-index. */ - ensure_full_index(&the_index); - for (i = 0; i < the_index.cache_nr; i++) { - unsigned int mode; - struct blob *blob; - struct object *obj; - mode = the_index.cache[i]->ce_mode; - if (S_ISGITLINK(mode)) - continue; - blob = lookup_blob(the_repository, - &the_index.cache[i]->oid); - if (!blob) - continue; - obj = &blob->object; - obj->flags |= USED; - fsck_put_object_name(&fsck_walk_options, &obj->oid, - ":%s", the_index.cache[i]->name); - mark_object_reachable(obj); + worktrees = get_worktrees(); + for (p = worktrees; *p; p++) { + struct worktree *wt = *p; + struct index_state istate = + INDEX_STATE_INIT(the_repository); + char *path; + + /* + * Make a copy since the buffer is reusable + * and may get overwritten by other calls + * while we're examining the index. + */ + path = xstrdup(worktree_git_path(wt, "index")); + read_index_from(&istate, path, get_worktree_git_dir(wt)); + fsck_index(&istate, path, wt->is_current); + discard_index(&istate); + free(path); } - if (the_index.cache_tree) - fsck_cache_tree(the_index.cache_tree); - fsck_resolve_undo(&the_index); + free_worktrees(worktrees); } check_connectivity(); diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c index 0feef8caf6..a280d8bb14 100644 --- a/builtin/fsmonitor--daemon.c +++ b/builtin/fsmonitor--daemon.c @@ -1,5 +1,9 @@ #include "builtin.h" +#include "abspath.h" +#include "alloc.h" #include "config.h" +#include "environment.h" +#include "gettext.h" #include "parse-options.h" #include "fsmonitor.h" #include "fsmonitor-ipc.h" diff --git a/builtin/gc.c b/builtin/gc.c index a1a2ae4da2..b291e23b13 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -11,6 +11,9 @@ */ #include "builtin.h" +#include "abspath.h" +#include "environment.h" +#include "hex.h" #include "repository.h" #include "config.h" #include "tempfile.h" @@ -31,7 +34,10 @@ #include "refs.h" #include "remote.h" #include "exec-cmd.h" +#include "gettext.h" #include "hook.h" +#include "setup.h" +#include "wrapper.h" #define FAILED_RUN "failed to run %s" @@ -976,9 +982,9 @@ struct write_loose_object_data { static int loose_object_auto_limit = 100; -static int loose_object_count(const struct object_id *oid, - const char *path, - void *data) +static int loose_object_count(const struct object_id *oid UNUSED, + const char *path UNUSED, + void *data) { int *count = (int*)data; if (++(*count) >= loose_object_auto_limit) @@ -1003,15 +1009,15 @@ static int loose_object_auto_condition(void) NULL, NULL, &count); } -static int bail_on_loose(const struct object_id *oid, - const char *path, - void *data) +static int bail_on_loose(const struct object_id *oid UNUSED, + const char *path UNUSED, + void *data UNUSED) { return 1; } static int write_loose_object_to_stdin(const struct object_id *oid, - const char *path, + const char *path UNUSED, void *data) { struct write_loose_object_data *d = (struct write_loose_object_data *)data; diff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c index 491af9202d..6745796998 100644 --- a/builtin/get-tar-commit-id.c +++ b/builtin/get-tar-commit-id.c @@ -6,6 +6,7 @@ #include "tar.h" #include "builtin.h" #include "quote.h" +#include "wrapper.h" static const char builtin_get_tar_commit_id_usage[] = "git get-tar-commit-id"; diff --git a/builtin/grep.c b/builtin/grep.c index 18561b1002..a1b68d90bd 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -4,6 +4,9 @@ * Copyright (c) 2006 Junio C Hamano */ #include "cache.h" +#include "alloc.h" +#include "gettext.h" +#include "hex.h" #include "repository.h" #include "config.h" #include "blob.h" @@ -20,10 +23,12 @@ #include "quote.h" #include "dir.h" #include "pathspec.h" +#include "setup.h" #include "submodule.h" #include "submodule-config.h" #include "object-store.h" #include "packfile.h" +#include "write-or-die.h" static const char *grep_prefix; diff --git a/builtin/hash-object.c b/builtin/hash-object.c index 44db83f07f..a15fe4fd3f 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -5,12 +5,17 @@ * Copyright (C) Junio C Hamano, 2005 */ #include "builtin.h" +#include "abspath.h" #include "config.h" +#include "gettext.h" +#include "hex.h" #include "object-store.h" #include "blob.h" #include "quote.h" #include "parse-options.h" #include "exec-cmd.h" +#include "setup.h" +#include "write-or-die.h" /* * This is to create corrupt objects for debugging and as such it diff --git a/builtin/help.c b/builtin/help.c index 53f2812dfb..87333a02ec 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -5,11 +5,13 @@ #include "config.h" #include "builtin.h" #include "exec-cmd.h" +#include "gettext.h" #include "parse-options.h" #include "run-command.h" #include "config-list.h" #include "help.h" #include "alias.h" +#include "setup.h" #ifndef DEFAULT_HELP_FORMAT #define DEFAULT_HELP_FORMAT "man" diff --git a/builtin/hook.c b/builtin/hook.c index f95b7965c5..88051795c7 100644 --- a/builtin/hook.c +++ b/builtin/hook.c @@ -1,6 +1,7 @@ #include "cache.h" #include "builtin.h" #include "config.h" +#include "gettext.h" #include "hook.h" #include "parse-options.h" #include "strbuf.h" diff --git a/builtin/index-pack.c b/builtin/index-pack.c index de47f3f644..b17e79cd40 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1,6 +1,10 @@ #include "builtin.h" +#include "alloc.h" #include "config.h" #include "delta.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "pack.h" #include "csum-file.h" #include "blob.h" @@ -14,7 +18,10 @@ #include "thread-utils.h" #include "packfile.h" #include "object-store.h" +#include "replace-object.h" #include "promisor-remote.h" +#include "setup.h" +#include "wrapper.h" static const char index_pack_usage[] = "git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--[no-]rev-index] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])"; diff --git a/builtin/init-db.c b/builtin/init-db.c index dcaaf102ea..ba6e0b20fa 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -4,12 +4,17 @@ * Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "abspath.h" #include "config.h" +#include "environment.h" +#include "gettext.h" #include "refs.h" #include "builtin.h" #include "exec-cmd.h" #include "parse-options.h" +#include "setup.h" #include "worktree.h" +#include "wrapper.h" #ifndef DEFAULT_GIT_TEMPLATE_DIR #define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates" diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index e58627c72a..107ac28f0e 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -7,6 +7,7 @@ #include "cache.h" #include "builtin.h" +#include "gettext.h" #include "parse-options.h" #include "string-list.h" #include "trailer.h" diff --git a/builtin/log.c b/builtin/log.c index acf3faecd8..2ce645eee9 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -4,8 +4,13 @@ * (C) Copyright 2006 Linus Torvalds * 2006 Junio Hamano */ -#include "cache.h" +#include "git-compat-util.h" +#include "abspath.h" +#include "alloc.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "refs.h" #include "object-store.h" #include "color.h" @@ -35,6 +40,7 @@ #include "commit-reach.h" #include "range-diff.h" #include "tmp-objdir.h" +#include "write-or-die.h" #define MAIL_DEFAULT_WRAP 72 #define COVER_FROM_AUTO_MAX_SUBJECT_LEN 100 @@ -436,7 +442,7 @@ static void log_show_early(struct rev_info *revs, struct commit_list *list) setitimer(ITIMER_REAL, &early_output_timer, NULL); } -static void early_output(int signal) +static void early_output(int signal UNUSED) { show_early_output = log_show_early; } @@ -601,8 +607,6 @@ static int git_log_config(const char *var, const char *value, void *cb) return 0; } - if (git_gpg_config(var, value, cb) < 0) - return -1; return git_diff_ui_config(var, value, cb); } @@ -2103,6 +2107,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) /* Always generate a patch */ rev.diffopt.output_format |= DIFF_FORMAT_PATCH; + rev.always_show_header = 1; rev.zero_commit = zero_commit; rev.patch_name_max = fmt_patch_name_max; diff --git a/builtin/ls-files.c b/builtin/ls-files.c index c10d51a969..68532f3e51 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -11,6 +11,7 @@ #include "quote.h" #include "dir.h" #include "builtin.h" +#include "gettext.h" #include "strbuf.h" #include "tree.h" #include "cache-tree.h" @@ -19,6 +20,7 @@ #include "string-list.h" #include "pathspec.h" #include "run-command.h" +#include "setup.h" #include "submodule.h" #include "submodule-config.h" diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index 6516177348..11d9424804 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -1,5 +1,7 @@ #include "builtin.h" #include "cache.h" +#include "gettext.h" +#include "hex.h" #include "transport.h" #include "ref-filter.h" #include "remote.h" diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index ebcc8fd6ff..f32e6be219 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -5,6 +5,8 @@ */ #include "cache.h" #include "config.h" +#include "gettext.h" +#include "hex.h" #include "object-store.h" #include "blob.h" #include "tree.h" diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c index 01d16ef9e5..a032a1c388 100644 --- a/builtin/mailinfo.c +++ b/builtin/mailinfo.c @@ -3,7 +3,10 @@ * email to figure out authorship and subject */ #include "cache.h" +#include "abspath.h" #include "builtin.h" +#include "environment.h" +#include "gettext.h" #include "utf8.h" #include "strbuf.h" #include "mailinfo.h" diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c index 73509f651b..b08069ce60 100644 --- a/builtin/mailsplit.c +++ b/builtin/mailsplit.c @@ -6,6 +6,7 @@ */ #include "cache.h" #include "builtin.h" +#include "gettext.h" #include "string-list.h" #include "strbuf.h" diff --git a/builtin/merge-base.c b/builtin/merge-base.c index 64d29136d1..3f22273b40 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -2,6 +2,8 @@ #include "cache.h" #include "config.h" #include "commit.h" +#include "gettext.h" +#include "hex.h" #include "refs.h" #include "diff.h" #include "revision.h" diff --git a/builtin/merge-file.c b/builtin/merge-file.c index c923bbf2ab..781818d08f 100644 --- a/builtin/merge-file.c +++ b/builtin/merge-file.c @@ -1,6 +1,9 @@ #include "builtin.h" +#include "abspath.h" #include "cache.h" #include "config.h" +#include "gettext.h" +#include "setup.h" #include "xdiff/xdiff.h" #include "xdiff-interface.h" #include "parse-options.h" diff --git a/builtin/merge-index.c b/builtin/merge-index.c index 452f833ac4..c875f5d37e 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -1,5 +1,6 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "hex.h" #include "run-command.h" static const char *pgm; diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c index a50b328d94..8ea9dc78aa 100644 --- a/builtin/merge-recursive.c +++ b/builtin/merge-recursive.c @@ -1,6 +1,7 @@ #include "cache.h" #include "builtin.h" #include "commit.h" +#include "gettext.h" #include "tag.h" #include "merge-recursive.h" #include "xdiff-interface.h" diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index d628ad1da9..803e380856 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -3,6 +3,8 @@ #include "tree-walk.h" #include "xdiff-interface.h" #include "help.h" +#include "gettext.h" +#include "hex.h" #include "commit.h" #include "commit-reach.h" #include "merge-ort.h" diff --git a/builtin/merge.c b/builtin/merge.c index 69666546ca..a99be9610e 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -8,7 +8,12 @@ #define USE_THE_INDEX_VARIABLE #include "cache.h" +#include "abspath.h" +#include "alloc.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "parse-options.h" #include "builtin.h" #include "lockfile.h" @@ -44,6 +49,7 @@ #include "commit-reach.h" #include "wt-status.h" #include "commit-graph.h" +#include "wrapper.h" #define DEFAULT_TWOHEAD (1<<0) #define DEFAULT_OCTOPUS (1<<1) @@ -662,9 +668,6 @@ static int git_merge_config(const char *k, const char *v, void *cb) status = fmt_merge_msg_config(k, v, cb); if (status) return status; - status = git_gpg_config(k, v, NULL); - if (status) - return status; return git_diff_ui_config(k, v, cb); } diff --git a/builtin/mktag.c b/builtin/mktag.c index 141a2d4569..f9d9a38452 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -1,4 +1,6 @@ #include "builtin.h" +#include "gettext.h" +#include "hex.h" #include "parse-options.h" #include "tag.h" #include "replace-object.h" diff --git a/builtin/mktree.c b/builtin/mktree.c index 06d81400f5..09a7bd5c5c 100644 --- a/builtin/mktree.c +++ b/builtin/mktree.c @@ -4,6 +4,9 @@ * Copyright (c) Junio C Hamano, 2006, 2009 */ #include "builtin.h" +#include "alloc.h" +#include "gettext.h" +#include "hex.h" #include "quote.h" #include "tree.h" #include "parse-options.h" diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index 9a18a82b05..1b5083f8b2 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -1,6 +1,9 @@ #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 "trace2.h" diff --git a/builtin/mv.c b/builtin/mv.c index edd7b931fd..b7c5ffbd8c 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -5,13 +5,18 @@ */ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "abspath.h" +#include "alloc.h" #include "config.h" +#include "environment.h" +#include "gettext.h" #include "pathspec.h" #include "lockfile.h" #include "dir.h" #include "cache-tree.h" #include "string-list.h" #include "parse-options.h" +#include "setup.h" #include "submodule.h" #include "entry.h" diff --git a/builtin/name-rev.c b/builtin/name-rev.c index ad1de02308..831d360a78 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -1,5 +1,8 @@ #include "builtin.h" -#include "cache.h" +#include "alloc.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "repository.h" #include "config.h" #include "commit.h" diff --git a/builtin/notes.c b/builtin/notes.c index f4939176da..4ff44f1e3d 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -10,6 +10,8 @@ #include "cache.h" #include "config.h" #include "builtin.h" +#include "gettext.h" +#include "hex.h" #include "notes.h" #include "object-store.h" #include "repository.h" @@ -23,6 +25,7 @@ #include "notes-merge.h" #include "notes-utils.h" #include "worktree.h" +#include "write-or-die.h" static const char * const git_notes_usage[] = { N_("git notes [--ref <notes-ref>] [list [<object>]]"), @@ -113,8 +116,9 @@ static void free_note_data(struct note_data *d) } static int list_each_note(const struct object_id *object_oid, - const struct object_id *note_oid, char *note_path, - void *cb_data) + const struct object_id *note_oid, + char *note_path UNUSED, + void *cb_data UNUSED) { printf("%s %s\n", oid_to_hex(note_oid), oid_to_hex(object_oid)); return 0; diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 2f2c02589b..69c6542861 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1,5 +1,8 @@ #include "builtin.h" -#include "cache.h" +#include "alloc.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "repository.h" #include "config.h" #include "attr.h" @@ -31,12 +34,14 @@ #include "list.h" #include "packfile.h" #include "object-store.h" +#include "replace-object.h" #include "dir.h" #include "midx.h" #include "trace2.h" #include "shallow.h" #include "promisor-remote.h" #include "pack-mtimes.h" +#include "wrapper.h" /* * Objects we are going to pack are collected in the `to_pack` structure. @@ -1594,7 +1599,7 @@ static int add_object_entry(const struct object_id *oid, enum object_type type, static int add_object_entry_from_bitmap(const struct object_id *oid, enum object_type type, - int flags, uint32_t name_hash, + int flags UNUSED, uint32_t name_hash, struct packed_git *pack, off_t offset) { display_progress(progress_state, ++nr_seen); @@ -3268,13 +3273,14 @@ static int add_object_entry_from_pack(const struct object_id *oid, return 0; } -static void show_commit_pack_hint(struct commit *commit, void *_data) +static void show_commit_pack_hint(struct commit *commit UNUSED, + void *data UNUSED) { /* nothing to do; commits don't have a namehash */ } static void show_object_pack_hint(struct object *object, const char *name, - void *_data) + void *data UNUSED) { struct object_entry *oe = packlist_find(&to_pack, &object->oid); if (!oe) @@ -3472,7 +3478,7 @@ static void add_cruft_object_entry(const struct object_id *oid, enum object_type return; } -static void show_cruft_object(struct object *obj, const char *name, void *data) +static void show_cruft_object(struct object *obj, const char *name, void *data UNUSED) { /* * if we did not record it earlier, it's at least as old as our @@ -3492,7 +3498,7 @@ static void show_cruft_commit(struct commit *commit, void *data) show_cruft_object((struct object*)commit, NULL, data); } -static int cruft_include_check_obj(struct object *obj, void *data) +static int cruft_include_check_obj(struct object *obj, void *data UNUSED) { return !has_object_kept_pack(&obj->oid, IN_CORE_KEEP_PACKS); } @@ -3671,7 +3677,7 @@ static void read_object_list_from_stdin(void) } } -static void show_commit(struct commit *commit, void *data) +static void show_commit(struct commit *commit, void *data UNUSED) { add_object_entry(&commit->object.oid, OBJ_COMMIT, NULL, 0); @@ -3682,7 +3688,8 @@ static void show_commit(struct commit *commit, void *data) propagate_island_marks(commit); } -static void show_object(struct object *obj, const char *name, void *data) +static void show_object(struct object *obj, const char *name, + void *data UNUSED) { add_preferred_base_object(name); add_object_entry(&obj->oid, obj->type, name, 0); @@ -3769,7 +3776,7 @@ static void show_edge(struct commit *commit) static int add_object_in_unpacked_pack(const struct object_id *oid, struct packed_git *pack, uint32_t pos, - void *_data) + void *data UNUSED) { if (cruft) { off_t offset; @@ -3803,7 +3810,7 @@ static void add_objects_in_unpacked_packs(void) } static int add_loose_object(const struct object_id *oid, const char *path, - void *data) + void *data UNUSED) { enum object_type type = oid_object_info(the_repository, oid, NULL); @@ -3954,13 +3961,13 @@ static int get_object_list_from_bitmap(struct rev_info *revs) } static void record_recent_object(struct object *obj, - const char *name, - void *data) + const char *name UNUSED, + void *data UNUSED) { oid_array_append(&recent_objects, &obj->oid); } -static void record_recent_commit(struct commit *commit, void *data) +static void record_recent_commit(struct commit *commit, void *data UNUSED) { oid_array_append(&recent_objects, &commit->object.oid); } diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c index ecd49ca268..3451971b56 100644 --- a/builtin/pack-redundant.c +++ b/builtin/pack-redundant.c @@ -7,6 +7,8 @@ */ #include "builtin.h" +#include "gettext.h" +#include "hex.h" #include "repository.h" #include "packfile.h" #include "object-store.h" diff --git a/builtin/pack-refs.c b/builtin/pack-refs.c index 27c2ca06ac..9833815fb3 100644 --- a/builtin/pack-refs.c +++ b/builtin/pack-refs.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "config.h" +#include "gettext.h" #include "parse-options.h" #include "refs.h" #include "repository.h" diff --git a/builtin/patch-id.c b/builtin/patch-id.c index f840fbf1c7..9d5585d3a7 100644 --- a/builtin/patch-id.c +++ b/builtin/patch-id.c @@ -2,6 +2,8 @@ #include "builtin.h" #include "config.h" #include "diff.h" +#include "gettext.h" +#include "hex.h" #include "parse-options.h" static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result) diff --git a/builtin/prune-packed.c b/builtin/prune-packed.c index da3273a268..ca3578e158 100644 --- a/builtin/prune-packed.c +++ b/builtin/prune-packed.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "gettext.h" #include "parse-options.h" #include "prune-packed.h" diff --git a/builtin/prune.c b/builtin/prune.c index 93be90825d..5c0952f5c6 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -1,12 +1,16 @@ #include "cache.h" #include "commit.h" #include "diff.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "revision.h" #include "builtin.h" #include "reachable.h" #include "parse-options.h" #include "progress.h" #include "prune-packed.h" +#include "replace-object.h" #include "object-store.h" #include "shallow.h" @@ -98,7 +102,8 @@ static int prune_object(const struct object_id *oid, const char *fullpath, return 0; } -static int prune_cruft(const char *basename, const char *path, void *data) +static int prune_cruft(const char *basename, const char *path, + void *data UNUSED) { if (starts_with(basename, "tmp_obj_")) prune_tmp_file(path); @@ -107,7 +112,8 @@ static int prune_cruft(const char *basename, const char *path, void *data) return 0; } -static int prune_subdir(unsigned int nr, const char *path, void *data) +static int prune_subdir(unsigned int nr UNUSED, const char *path, + void *data UNUSED) { if (!show_only) rmdir(path); diff --git a/builtin/pull.c b/builtin/pull.c index 880eebcdd6..5405d09f22 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -9,6 +9,8 @@ #include "cache.h" #include "config.h" #include "builtin.h" +#include "gettext.h" +#include "hex.h" #include "parse-options.h" #include "exec-cmd.h" #include "run-command.h" @@ -359,8 +361,6 @@ static enum rebase_type config_get_rebase(int *rebase_unspecified) */ static int git_pull_config(const char *var, const char *value, void *cb) { - int status; - if (!strcmp(var, "rebase.autostash")) { config_autostash = git_config_bool(var, value); return 0; @@ -372,10 +372,6 @@ static int git_pull_config(const char *var, const char *value, void *cb) check_trust_level = 0; } - status = git_gpg_config(var, value, cb); - if (status) - return status; - return git_default_config(var, value, cb); } diff --git a/builtin/push.c b/builtin/push.c index 8f7d326ab3..fa550b8f80 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -4,6 +4,8 @@ #include "cache.h" #include "branch.h" #include "config.h" +#include "environment.h" +#include "gettext.h" #include "refs.h" #include "refspec.h" #include "run-command.h" @@ -508,11 +510,6 @@ static int git_push_config(const char *k, const char *v, void *cb) { const char *slot_name; int *flags = cb; - int status; - - status = git_gpg_config(k, v, NULL); - if (status) - return status; if (!strcmp(k, "push.followtags")) { if (git_config_bool(k, v)) diff --git a/builtin/range-diff.c b/builtin/range-diff.c index 556ee84b6d..b72af527f0 100644 --- a/builtin/range-diff.c +++ b/builtin/range-diff.c @@ -1,5 +1,6 @@ #include "cache.h" #include "builtin.h" +#include "gettext.h" #include "parse-options.h" #include "range-diff.h" #include "config.h" diff --git a/builtin/read-tree.c b/builtin/read-tree.c index a1c6aa9641..600d4f748f 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -7,6 +7,8 @@ #define USE_THE_INDEX_VARIABLE #include "cache.h" #include "config.h" +#include "gettext.h" +#include "hex.h" #include "lockfile.h" #include "object.h" #include "tree.h" @@ -17,6 +19,7 @@ #include "builtin.h" #include "parse-options.h" #include "resolve-undo.h" +#include "setup.h" #include "submodule.h" #include "submodule-config.h" @@ -87,9 +90,9 @@ static int debug_merge(const struct cache_entry * const *stages, { int i; - printf("* %d-way merge\n", o->merge_size); + printf("* %d-way merge\n", o->internal.merge_size); debug_stage("index", stages[0], o); - for (i = 1; i <= o->merge_size; i++) { + for (i = 1; i <= o->internal.merge_size; i++) { char buf[24]; xsnprintf(buf, sizeof(buf), "ent#%d", i); debug_stage(buf, stages[i], o); @@ -144,7 +147,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) OPT__DRY_RUN(&opts.dry_run, N_("don't update the index or the work tree")), OPT_BOOL(0, "no-sparse-checkout", &opts.skip_sparse_checkout, N_("skip applying sparse checkout filter")), - OPT_BOOL(0, "debug-unpack", &opts.debug_unpack, + OPT_BOOL(0, "debug-unpack", &opts.internal.debug_unpack, N_("debug unpack-trees")), OPT_CALLBACK_F(0, "recurse-submodules", NULL, "checkout", "control recursive updating of submodules", @@ -247,7 +250,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) opts.head_idx = 1; } - if (opts.debug_unpack) + if (opts.internal.debug_unpack) opts.fn = debug_merge; /* If we're going to prime_cache_tree later, skip cache tree update */ @@ -263,7 +266,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) if (unpack_trees(nr_trees, t, &opts)) return 128; - if (opts.debug_unpack || opts.dry_run) + if (opts.internal.debug_unpack || opts.dry_run) return 0; /* do not write the index out */ /* diff --git a/builtin/rebase.c b/builtin/rebase.c index 76cce94373..dbc8f90ef0 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -6,6 +6,10 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "abspath.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "run-command.h" #include "exec-cmd.h" #include "strvec.h" @@ -29,6 +33,7 @@ #include "rebase-interactive.h" #include "reset.h" #include "hook.h" +#include "wrapper.h" static char const * const builtin_rebase_usage[] = { N_("git rebase [-i] [options] [--exec <cmd>] " @@ -1516,7 +1521,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) die(_("apply options and merge options " "cannot be used together")); else if (options.autosquash == -1 && options.config_autosquash == 1) - die(_("apply options are incompatible with rebase.autosquash. Consider adding --no-autosquash")); + die(_("apply options are incompatible with rebase.autoSquash. Consider adding --no-autosquash")); else if (options.update_refs == -1 && options.config_update_refs == 1) die(_("apply options are incompatible with rebase.updateRefs. Consider adding --no-update-refs")); else diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 5609206499..2ba5a74ba7 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1,6 +1,10 @@ #include "builtin.h" +#include "abspath.h" #include "repository.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "lockfile.h" #include "pack.h" #include "refs.h" @@ -30,6 +34,7 @@ #include "commit-reach.h" #include "worktree.h" #include "shallow.h" +#include "wrapper.h" static const char * const receive_pack_usage[] = { N_("git receive-pack <git-dir>"), @@ -136,10 +141,6 @@ static int receive_pack_config(const char *var, const char *value, void *cb) if (status) return status; - status = git_gpg_config(var, value, NULL); - if (status) - return status; - if (strcmp(var, "receive.denydeletes") == 0) { deny_deletes = git_config_bool(var, value); return 0; @@ -1463,8 +1464,10 @@ static const char *update(struct command *cmd, struct shallow_info *si) find_shared_symref(worktrees, "HEAD", name); /* only refs/... are allowed */ - if (!starts_with(name, "refs/") || check_refname_format(name + 5, 0)) { - rp_error("refusing to create funny ref '%s' remotely", name); + if (!starts_with(name, "refs/") || + check_refname_format(name + 5, is_null_oid(new_oid) ? + REFNAME_ALLOW_ONELEVEL : 0)) { + rp_error("refusing to update funny ref '%s' remotely", name); ret = "funny refname"; goto out; } diff --git a/builtin/reflog.c b/builtin/reflog.c index 270681dcdf..0879d4d224 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "config.h" +#include "gettext.h" #include "revision.h" #include "reachable.h" #include "worktree.h" diff --git a/builtin/remote.c b/builtin/remote.c index a6b100dce7..1e0b137d97 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "config.h" +#include "gettext.h" #include "parse-options.h" #include "transport.h" #include "remote.h" diff --git a/builtin/repack.c b/builtin/repack.c index 25658fe732..df4d8e0f0b 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -1,7 +1,10 @@ #include "builtin.h" -#include "cache.h" +#include "alloc.h" #include "config.h" #include "dir.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "parse-options.h" #include "run-command.h" #include "sigchain.h" @@ -182,8 +185,9 @@ static void prepare_pack_objects(struct child_process *cmd, * Write oid to the given struct child_process's stdin, starting it first if * necessary. */ -static int write_oid(const struct object_id *oid, struct packed_git *pack, - uint32_t pos, void *data) +static int write_oid(const struct object_id *oid, + struct packed_git *pack UNUSED, + uint32_t pos UNUSED, void *data) { struct child_process *cmd = data; diff --git a/builtin/replace.c b/builtin/replace.c index bd67107a7c..d2adc8ab61 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -11,10 +11,14 @@ #include "cache.h" #include "config.h" #include "builtin.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "refs.h" #include "parse-options.h" #include "run-command.h" #include "object-store.h" +#include "replace-object.h" #include "repository.h" #include "tag.h" diff --git a/builtin/rerere.c b/builtin/rerere.c index 94ffb8c21a..d4a03707b1 100644 --- a/builtin/rerere.c +++ b/builtin/rerere.c @@ -2,9 +2,11 @@ #include "cache.h" #include "config.h" #include "dir.h" +#include "gettext.h" #include "parse-options.h" #include "string-list.h" #include "rerere.h" +#include "wrapper.h" #include "xdiff/xdiff.h" #include "xdiff-interface.h" #include "pathspec.h" diff --git a/builtin/reset.c b/builtin/reset.c index b65f379440..0ed329236c 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -10,6 +10,9 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "lockfile.h" #include "tag.h" #include "object.h" @@ -23,6 +26,7 @@ #include "parse-options.h" #include "unpack-trees.h" #include "cache-tree.h" +#include "setup.h" #include "submodule.h" #include "submodule-config.h" #include "dir.h" @@ -317,7 +321,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix) int reset_type = NONE, update_ref_status = 0, quiet = 0; int no_refresh = 0; int patch_mode = 0, pathspec_file_nul = 0, unborn; - const char *rev, *pathspec_from_file = NULL; + const char *rev; + char *pathspec_from_file = NULL; struct object_id oid; struct pathspec pathspec; int intent_to_add = 0; @@ -497,5 +502,6 @@ int cmd_reset(int argc, const char **argv, const char *prefix) cleanup: clear_pathspec(&pathspec); + free(pathspec_from_file); return update_ref_status; } diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 0f55eae22e..a3dbbb6338 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -2,6 +2,9 @@ #include "config.h" #include "commit.h" #include "diff.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "revision.h" #include "list-objects.h" #include "list-objects-filter.h" @@ -38,7 +41,7 @@ static const char rev_list_usage[] = " --tags\n" " --remotes\n" " --stdin\n" -" --exclude-hidden=[receive|uploadpack]\n" +" --exclude-hidden=[fetch|receive|uploadpack]\n" " --quiet\n" " ordering output:\n" " --topo-order\n" @@ -257,7 +260,8 @@ static inline void finish_object__ma(struct object *obj) } } -static int finish_object(struct object *obj, const char *name, void *cb_data) +static int finish_object(struct object *obj, const char *name UNUSED, + void *cb_data) { struct rev_list_info *info = cb_data; if (oid_object_info_extended(the_repository, &obj->oid, NULL, 0) < 0) { @@ -362,11 +366,11 @@ static int show_bisect_vars(struct rev_list_info *info, int reaches, int all) static int show_object_fast( const struct object_id *oid, - enum object_type type, - int exclude, - uint32_t name_hash, - struct packed_git *found_pack, - off_t found_offset) + enum object_type type UNUSED, + int exclude UNUSED, + uint32_t name_hash UNUSED, + struct packed_git *found_pack UNUSED, + off_t found_offset UNUSED) { fprintf(stdout, "%s\n", oid_to_hex(oid)); return 1; diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 663f282c5f..1af2089f9b 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -5,14 +5,20 @@ */ #define USE_THE_INDEX_VARIABLE #include "cache.h" +#include "abspath.h" +#include "alloc.h" #include "config.h" #include "commit.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "refs.h" #include "quote.h" #include "builtin.h" #include "parse-options.h" #include "diff.h" #include "revision.h" +#include "setup.h" #include "split-index.h" #include "submodule.h" #include "commit-reach.h" diff --git a/builtin/revert.c b/builtin/revert.c index 77d2035616..dd6587a99d 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -1,8 +1,10 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "builtin.h" #include "parse-options.h" #include "diff.h" +#include "gettext.h" #include "revision.h" #include "rerere.h" #include "dir.h" diff --git a/builtin/rm.c b/builtin/rm.c index 25130f1b19..6be9281742 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -5,14 +5,17 @@ */ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "alloc.h" #include "advice.h" #include "config.h" #include "lockfile.h" #include "dir.h" #include "cache-tree.h" +#include "gettext.h" #include "tree-walk.h" #include "parse-options.h" #include "string-list.h" +#include "setup.h" #include "submodule.h" #include "pathspec.h" diff --git a/builtin/send-pack.c b/builtin/send-pack.c index 4c5d125fa0..2b360fee42 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -1,6 +1,7 @@ #include "builtin.h" #include "config.h" #include "commit.h" +#include "hex.h" #include "refs.h" #include "pkt-line.h" #include "sideband.h" @@ -15,6 +16,7 @@ #include "gpg-interface.h" #include "gettext.h" #include "protocol.h" +#include "write-or-die.h" static const char * const send_pack_usage[] = { N_("git send-pack [--mirror] [--dry-run] [--force]\n" @@ -130,8 +132,6 @@ static void print_helper_status(struct ref *ref) static int send_pack_config(const char *k, const char *v, void *cb) { - git_gpg_config(k, v, NULL); - if (!strcmp(k, "push.gpgsign")) { const char *value; if (!git_config_get_value("push.gpgsign", &value)) { diff --git a/builtin/shortlog.c b/builtin/shortlog.c index f287a6acd0..46f4e0832a 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -3,10 +3,13 @@ #include "config.h" #include "commit.h" #include "diff.h" +#include "environment.h" +#include "gettext.h" #include "string-list.h" #include "revision.h" #include "utf8.h" #include "mailmap.h" +#include "setup.h" #include "shortlog.h" #include "parse-options.h" #include "trailer.h" diff --git a/builtin/show-branch.c b/builtin/show-branch.c index af680485d5..463a8d11c3 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -1,5 +1,8 @@ #include "cache.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "pretty.h" #include "refs.h" #include "builtin.h" diff --git a/builtin/show-index.c b/builtin/show-index.c index 0e0b9fb95b..d4bbbbcd6c 100644 --- a/builtin/show-index.c +++ b/builtin/show-index.c @@ -1,5 +1,7 @@ #include "builtin.h" #include "cache.h" +#include "gettext.h" +#include "hex.h" #include "pack.h" #include "parse-options.h" diff --git a/builtin/show-ref.c b/builtin/show-ref.c index b294ae4164..138d30a005 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -1,6 +1,8 @@ #include "builtin.h" #include "cache.h" #include "config.h" +#include "gettext.h" +#include "hex.h" #include "refs.h" #include "object-store.h" #include "object.h" diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index c5c8b7b89c..090bf33510 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -2,6 +2,8 @@ #include "cache.h" #include "config.h" #include "dir.h" +#include "environment.h" +#include "gettext.h" #include "parse-options.h" #include "pathspec.h" #include "repository.h" @@ -14,6 +16,7 @@ #include "unpack-trees.h" #include "wt-status.h" #include "quote.h" +#include "setup.h" #include "sparse-index.h" #include "worktree.h" @@ -217,16 +220,14 @@ static int update_working_directory(struct pattern_list *pl) o.head_idx = -1; o.src_index = r->index; o.dst_index = r->index; - index_state_init(&o.result, r); o.skip_sparse_checkout = 0; - o.pl = pl; setup_work_tree(); repo_hold_locked_index(r, &lock_file, LOCK_DIE_ON_ERROR); setup_unpack_trees_porcelain(&o, "sparse-checkout"); - result = update_sparsity(&o); + result = update_sparsity(&o, pl); clear_unpack_trees_porcelain(&o); if (result == UPDATE_SPARSITY_WARNINGS) diff --git a/builtin/stash.c b/builtin/stash.c index 888ffa0728..14194b13bd 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1,6 +1,10 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "abspath.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "parse-options.h" #include "refs.h" #include "lockfile.h" @@ -14,6 +18,7 @@ #include "entry.h" #include "rerere.h" #include "revision.h" +#include "setup.h" #include "log-tree.h" #include "diffcore.h" #include "exec-cmd.h" diff --git a/builtin/stripspace.c b/builtin/stripspace.c index 1e34cf2beb..9451eb69ff 100644 --- a/builtin/stripspace.c +++ b/builtin/stripspace.c @@ -1,8 +1,11 @@ #include "builtin.h" #include "cache.h" #include "config.h" +#include "gettext.h" #include "parse-options.h" +#include "setup.h" #include "strbuf.h" +#include "write-or-die.h" static void comment_lines(struct strbuf *buf) { diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 32b8e49817..8337703715 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1,5 +1,10 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "abspath.h" +#include "alloc.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "repository.h" #include "cache.h" #include "config.h" @@ -7,6 +12,7 @@ #include "quote.h" #include "pathspec.h" #include "dir.h" +#include "setup.h" #include "submodule.h" #include "submodule-config.h" #include "string-list.h" @@ -2132,9 +2138,9 @@ static int update_clone_get_next_task(struct child_process *child, return 0; } -static int update_clone_start_failure(struct strbuf *err, +static int update_clone_start_failure(struct strbuf *err UNUSED, void *suc_cb, - void *idx_task_cb) + void *idx_task_cb UNUSED) { struct submodule_update_clone *suc = suc_cb; diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c index e00768a8b7..10198a74fa 100644 --- a/builtin/symbolic-ref.c +++ b/builtin/symbolic-ref.c @@ -1,6 +1,7 @@ #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 cd97a141fa..bfd5138957 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -9,6 +9,9 @@ #include "cache.h" #include "config.h" #include "builtin.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "refs.h" #include "object-store.h" #include "tag.h" @@ -21,6 +24,7 @@ #include "column.h" #include "ref-filter.h" #include "date.h" +#include "write-or-die.h" static const char * const git_tag_usage[] = { N_("git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>] [-e]\n" @@ -180,8 +184,6 @@ static const char tag_template_nocleanup[] = static int git_tag_config(const char *var, const char *value, void *cb) { - int status; - if (!strcmp(var, "tag.gpgsign")) { config_sign_tag = git_config_bool(var, value); return 0; @@ -194,9 +196,6 @@ static int git_tag_config(const char *var, const char *value, void *cb) return 0; } - status = git_gpg_config(var, value, cb); - if (status) - return status; if (!strcmp(var, "tag.forcesignannotated")) { force_sign_annotate = git_config_bool(var, value); return 0; @@ -433,7 +432,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix) int create_reflog = 0; int annotate = 0, force = 0; int cmdmode = 0, create_tag_object = 0; - const char *msgfile = NULL, *keyid = NULL; + char *msgfile = NULL; + const char *keyid = NULL; struct msg_arg msg = { .buf = STRBUF_INIT }; struct ref_transaction *transaction; struct strbuf err = STRBUF_INIT; @@ -643,5 +643,6 @@ cleanup: strbuf_release(&reflog_msg); strbuf_release(&msg.buf); strbuf_release(&err); + free(msgfile); return ret; } diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c index 9d5c152419..314761b0b4 100644 --- a/builtin/unpack-file.c +++ b/builtin/unpack-file.c @@ -1,6 +1,8 @@ #include "builtin.h" #include "config.h" +#include "hex.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 c072096174..f2c1323e66 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -2,12 +2,16 @@ #include "cache.h" #include "bulk-checkin.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "object-store.h" #include "object.h" #include "delta.h" #include "pack.h" #include "blob.h" #include "commit.h" +#include "replace-object.h" #include "tag.h" #include "tree.h" #include "tree-walk.h" diff --git a/builtin/update-index.c b/builtin/update-index.c index bf38885d54..03cda5e60d 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -7,6 +7,9 @@ #include "cache.h" #include "bulk-checkin.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "lockfile.h" #include "quote.h" #include "cache-tree.h" @@ -17,8 +20,10 @@ #include "parse-options.h" #include "pathspec.h" #include "dir.h" +#include "setup.h" #include "split-index.h" #include "fsmonitor.h" +#include "write-or-die.h" /* * Default to not allowing changes to the list of files. The diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 1ba0727ba7..3ffd75b3e7 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -1,5 +1,6 @@ #include "cache.h" #include "config.h" +#include "gettext.h" #include "refs.h" #include "builtin.h" #include "parse-options.h" diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c index d2239c9ef4..e7bff27ae4 100644 --- a/builtin/update-server-info.c +++ b/builtin/update-server-info.c @@ -1,6 +1,7 @@ #include "cache.h" #include "config.h" #include "builtin.h" +#include "gettext.h" #include "parse-options.h" static const char * const update_server_info_usage[] = { diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c index 25b69da2bf..beb9dd0861 100644 --- a/builtin/upload-pack.c +++ b/builtin/upload-pack.c @@ -1,9 +1,11 @@ #include "cache.h" #include "builtin.h" #include "exec-cmd.h" +#include "gettext.h" #include "pkt-line.h" #include "parse-options.h" #include "protocol.h" +#include "replace-object.h" #include "upload-pack.h" #include "serve.h" diff --git a/builtin/var.c b/builtin/var.c index a80c1df86f..d9943be9af 100644 --- a/builtin/var.c +++ b/builtin/var.c @@ -5,6 +5,7 @@ */ #include "builtin.h" #include "config.h" +#include "ident.h" #include "refs.h" static const char var_usage[] = "git var (-l | <variable>)"; diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c index 424b43083c..4d10aa98b1 100644 --- a/builtin/verify-commit.c +++ b/builtin/verify-commit.c @@ -8,6 +8,7 @@ #include "cache.h" #include "config.h" #include "builtin.h" +#include "gettext.h" #include "object-store.h" #include "repository.h" #include "commit.h" @@ -52,14 +53,6 @@ static int verify_commit(const char *name, unsigned flags) return run_gpg_verify((struct commit *)obj, flags); } -static int git_verify_commit_config(const char *var, const char *value, void *cb) -{ - int status = git_gpg_config(var, value, cb); - if (status) - return status; - return git_default_config(var, value, cb); -} - int cmd_verify_commit(int argc, const char **argv, const char *prefix) { int i = 1, verbose = 0, had_error = 0; @@ -70,7 +63,7 @@ int cmd_verify_commit(int argc, const char **argv, const char *prefix) OPT_END() }; - git_config(git_verify_commit_config, NULL); + git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, verify_commit_options, verify_commit_usage, PARSE_OPT_KEEP_ARGV0); diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c index 27d6f75fd8..190fd69540 100644 --- a/builtin/verify-pack.c +++ b/builtin/verify-pack.c @@ -1,6 +1,7 @@ #include "builtin.h" #include "cache.h" #include "config.h" +#include "gettext.h" #include "run-command.h" #include "parse-options.h" diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c index 050fd29251..28d0da6845 100644 --- a/builtin/verify-tag.c +++ b/builtin/verify-tag.c @@ -8,6 +8,7 @@ #include "cache.h" #include "config.h" #include "builtin.h" +#include "gettext.h" #include "tag.h" #include "run-command.h" #include "parse-options.h" @@ -19,14 +20,6 @@ static const char * const verify_tag_usage[] = { NULL }; -static int git_verify_tag_config(const char *var, const char *value, void *cb) -{ - int status = git_gpg_config(var, value, cb); - if (status) - return status; - return git_default_config(var, value, cb); -} - int cmd_verify_tag(int argc, const char **argv, const char *prefix) { int i = 1, verbose = 0, had_error = 0; @@ -39,7 +32,7 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix) OPT_END() }; - git_config(git_verify_tag_config, NULL); + git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, verify_tag_options, verify_tag_usage, PARSE_OPT_KEEP_ARGV0); diff --git a/builtin/worktree.c b/builtin/worktree.c index 16fa30f01c..944dd40f94 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -1,8 +1,12 @@ #include "cache.h" +#include "abspath.h" #include "checkout.h" #include "config.h" #include "builtin.h" #include "dir.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "parse-options.h" #include "strvec.h" #include "branch.h" @@ -13,6 +17,7 @@ #include "submodule.h" #include "utf8.h" #include "worktree.h" +#include "wrapper.h" #include "quote.h" #define BUILTIN_WORKTREE_ADD_USAGE \ diff --git a/builtin/write-tree.c b/builtin/write-tree.c index 078010315f..6085f64d10 100644 --- a/builtin/write-tree.c +++ b/builtin/write-tree.c @@ -7,6 +7,9 @@ #include "builtin.h" #include "cache.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "tree.h" #include "cache-tree.h" #include "parse-options.h" diff --git a/bulk-checkin.c b/bulk-checkin.c index b44b94e866..6362b6aabc 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -2,7 +2,11 @@ * Copyright (c) 2011, Google Inc. */ #include "cache.h" +#include "alloc.h" #include "bulk-checkin.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "lockfile.h" #include "repository.h" #include "csum-file.h" diff --git a/bulk-checkin.h b/bulk-checkin.h index 8281b9cb15..48fe9a6e91 100644 --- a/bulk-checkin.h +++ b/bulk-checkin.h @@ -4,7 +4,7 @@ #ifndef BULK_CHECKIN_H #define BULK_CHECKIN_H -#include "cache.h" +#include "object.h" void prepare_loose_object_bulk_checkin(void); void fsync_loose_object_bulk_checkin(int fd, const char *filename); diff --git a/bundle-uri.c b/bundle-uri.c index 8a3c39ce57..1ff1cf51da 100644 --- a/bundle-uri.c +++ b/bundle-uri.c @@ -1,6 +1,8 @@ #include "cache.h" #include "bundle-uri.h" #include "bundle.h" +#include "environment.h" +#include "gettext.h" #include "object-store.h" #include "refs.h" #include "run-command.h" @@ -884,7 +886,7 @@ int bundle_uri_command(struct repository *r, * Read all "bundle.*" config lines to the client as key=value * packet lines. */ - git_config(config_to_packet_line, &writer); + repo_config(r, config_to_packet_line, &writer); packet_writer_flush(&writer); @@ -1,6 +1,9 @@ #include "cache.h" #include "lockfile.h" #include "bundle.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "object-store.h" #include "repository.h" #include "object.h" @@ -13,6 +16,7 @@ #include "strvec.h" #include "list-objects-filter-options.h" #include "connected.h" +#include "write-or-die.h" static const char v2_bundle_signature[] = "# v2 git bundle\n"; static const char v3_bundle_signature[] = "# v3 git bundle\n"; @@ -2,7 +2,6 @@ #define BUNDLE_H #include "strvec.h" -#include "cache.h" #include "string-list.h" #include "list-objects-filter-options.h" diff --git a/cache-tree.c b/cache-tree.c index b0e490b5aa..ff14b527da 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -1,4 +1,7 @@ #include "cache.h" +#include "alloc.h" +#include "environment.h" +#include "hex.h" #include "lockfile.h" #include "tree.h" #include "tree-walk.h" diff --git a/cache-tree.h b/cache-tree.h index bd97caa07b..faae88be63 100644 --- a/cache-tree.h +++ b/cache-tree.h @@ -1,7 +1,6 @@ #ifndef CACHE_TREE_H #define CACHE_TREE_H -#include "cache.h" #include "tree.h" #include "tree-walk.h" @@ -14,8 +14,11 @@ #include "pack-revindex.h" #include "hash.h" #include "path.h" +#include "pathspec.h" +#include "object.h" #include "oid-array.h" #include "repository.h" +#include "statinfo.h" #include "mem-pool.h" typedef struct git_zstream { @@ -118,26 +121,6 @@ struct cache_header { #define INDEX_FORMAT_LB 2 #define INDEX_FORMAT_UB 4 -/* - * The "cache_time" is just the low 32 bits of the - * time. It doesn't matter if it overflows - we only - * check it for equality in the 32 bits we save. - */ -struct cache_time { - uint32_t sec; - uint32_t nsec; -}; - -struct stat_data { - struct cache_time sd_ctime; - struct cache_time sd_mtime; - unsigned int sd_dev; - unsigned int sd_ino; - unsigned int sd_uid; - unsigned int sd_gid; - unsigned int sd_size; -}; - struct cache_entry { struct hashmap_entry ent; struct stat_data ce_stat_data; @@ -293,6 +276,15 @@ static inline unsigned int canon_mode(unsigned int mode) return S_IFGITLINK; } +static inline int ce_path_match(struct index_state *istate, + const struct cache_entry *ce, + const struct pathspec *pathspec, + char *seen) +{ + return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen, + S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode)); +} + #define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1) #define SOMETHING_CHANGED (1 << 0) /* unclassified changes go here */ @@ -453,26 +445,6 @@ void prefetch_cache_entries(const struct index_state *istate, extern struct index_state the_index; #endif -#define TYPE_BITS 3 - -/* - * Values in this enum (except those outside the 3 bit range) are part - * of pack file format. See gitformat-pack(5) for more information. - */ -enum object_type { - OBJ_BAD = -1, - OBJ_NONE = 0, - OBJ_COMMIT = 1, - OBJ_TREE = 2, - OBJ_BLOB = 3, - OBJ_TAG = 4, - /* 5 for future expansion */ - OBJ_OFS_DELTA = 6, - OBJ_REF_DELTA = 7, - OBJ_ANY, - OBJ_MAX -}; - static inline enum object_type object_type(unsigned int mode) { return S_ISDIR(mode) ? OBJ_TREE : @@ -480,171 +452,6 @@ static inline enum object_type object_type(unsigned int mode) OBJ_BLOB; } -/* Double-check local_repo_env below if you add to this list. */ -#define GIT_DIR_ENVIRONMENT "GIT_DIR" -#define GIT_COMMON_DIR_ENVIRONMENT "GIT_COMMON_DIR" -#define GIT_NAMESPACE_ENVIRONMENT "GIT_NAMESPACE" -#define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE" -#define GIT_PREFIX_ENVIRONMENT "GIT_PREFIX" -#define DEFAULT_GIT_DIR_ENVIRONMENT ".git" -#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY" -#define INDEX_ENVIRONMENT "GIT_INDEX_FILE" -#define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE" -#define GIT_SHALLOW_FILE_ENVIRONMENT "GIT_SHALLOW_FILE" -#define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR" -#define CONFIG_ENVIRONMENT "GIT_CONFIG" -#define CONFIG_DATA_ENVIRONMENT "GIT_CONFIG_PARAMETERS" -#define CONFIG_COUNT_ENVIRONMENT "GIT_CONFIG_COUNT" -#define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH" -#define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES" -#define NO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS" -#define GIT_REPLACE_REF_BASE_ENVIRONMENT "GIT_REPLACE_REF_BASE" -#define GITATTRIBUTES_FILE ".gitattributes" -#define INFOATTRIBUTES_FILE "info/attributes" -#define ATTRIBUTE_MACRO_PREFIX "[attr]" -#define GITMODULES_FILE ".gitmodules" -#define GITMODULES_INDEX ":.gitmodules" -#define GITMODULES_HEAD "HEAD:.gitmodules" -#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF" -#define GIT_NOTES_DEFAULT_REF "refs/notes/commits" -#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF" -#define GIT_NOTES_REWRITE_REF_ENVIRONMENT "GIT_NOTES_REWRITE_REF" -#define GIT_NOTES_REWRITE_MODE_ENVIRONMENT "GIT_NOTES_REWRITE_MODE" -#define GIT_LITERAL_PATHSPECS_ENVIRONMENT "GIT_LITERAL_PATHSPECS" -#define GIT_GLOB_PATHSPECS_ENVIRONMENT "GIT_GLOB_PATHSPECS" -#define GIT_NOGLOB_PATHSPECS_ENVIRONMENT "GIT_NOGLOB_PATHSPECS" -#define GIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS" -#define GIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH" -#define GIT_OPTIONAL_LOCKS_ENVIRONMENT "GIT_OPTIONAL_LOCKS" -#define GIT_TEXT_DOMAIN_DIR_ENVIRONMENT "GIT_TEXTDOMAINDIR" - -/* - * Environment variable used in handshaking the wire protocol. - * Contains a colon ':' separated list of keys with optional values - * 'key[=value]'. Presence of unknown keys and values must be - * ignored. - */ -#define GIT_PROTOCOL_ENVIRONMENT "GIT_PROTOCOL" -/* HTTP header used to handshake the wire protocol */ -#define GIT_PROTOCOL_HEADER "Git-Protocol" - -/* - * This environment variable is expected to contain a boolean indicating - * whether we should or should not treat: - * - * GIT_DIR=foo.git git ... - * - * as if GIT_WORK_TREE=. was given. It's not expected that users will make use - * of this, but we use it internally to communicate to sub-processes that we - * are in a bare repo. If not set, defaults to true. - */ -#define GIT_IMPLICIT_WORK_TREE_ENVIRONMENT "GIT_IMPLICIT_WORK_TREE" - -/* - * Repository-local GIT_* environment variables; these will be cleared - * when git spawns a sub-process that runs inside another repository. - * The array is NULL-terminated, which makes it easy to pass in the "env" - * parameter of a run-command invocation, or to do a simple walk. - */ -extern const char * const local_repo_env[]; - -void setup_git_env(const char *git_dir); - -/* - * Returns true iff we have a configured git repository (either via - * setup_git_directory, or in the environment via $GIT_DIR). - */ -int have_git_dir(void); - -extern int is_bare_repository_cfg; -int is_bare_repository(void); -int is_inside_git_dir(void); -extern char *git_work_tree_cfg; -int is_inside_work_tree(void); -const char *get_git_dir(void); -const char *get_git_common_dir(void); -const char *get_object_directory(void); -char *get_index_file(void); -char *get_graft_file(struct repository *r); -void set_git_dir(const char *path, int make_realpath); -int get_common_dir_noenv(struct strbuf *sb, const char *gitdir); -int get_common_dir(struct strbuf *sb, const char *gitdir); -const char *get_git_namespace(void); -const char *strip_namespace(const char *namespaced_ref); -const char *get_git_work_tree(void); - -/* - * Return true if the given path is a git directory; note that this _just_ - * looks at the directory itself. If you want to know whether "foo/.git" - * is a repository, you must feed that path, not just "foo". - */ -int is_git_directory(const char *path); - -/* - * Return 1 if the given path is the root of a git repository or - * submodule, else 0. Will not return 1 for bare repositories with the - * exception of creating a bare repository in "foo/.git" and calling - * is_git_repository("foo"). - * - * If we run into read errors, we err on the side of saying "yes, it is", - * as we usually consider sub-repos precious, and would prefer to err on the - * side of not disrupting or deleting them. - */ -int is_nonbare_repository_dir(struct strbuf *path); - -#define READ_GITFILE_ERR_STAT_FAILED 1 -#define READ_GITFILE_ERR_NOT_A_FILE 2 -#define READ_GITFILE_ERR_OPEN_FAILED 3 -#define READ_GITFILE_ERR_READ_FAILED 4 -#define READ_GITFILE_ERR_INVALID_FORMAT 5 -#define READ_GITFILE_ERR_NO_PATH 6 -#define READ_GITFILE_ERR_NOT_A_REPO 7 -#define READ_GITFILE_ERR_TOO_LARGE 8 -void read_gitfile_error_die(int error_code, const char *path, const char *dir); -const char *read_gitfile_gently(const char *path, int *return_error_code); -#define read_gitfile(path) read_gitfile_gently((path), NULL) -const char *resolve_gitdir_gently(const char *suspect, int *return_error_code); -#define resolve_gitdir(path) resolve_gitdir_gently((path), NULL) - -void set_git_work_tree(const char *tree); - -#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" - -void setup_work_tree(void); -/* - * Find the commondir and gitdir of the repository that contains the current - * working directory, without changing the working directory or other global - * state. The result is appended to commondir and gitdir. If the discovered - * gitdir does not correspond to a worktree, then 'commondir' and 'gitdir' will - * both have the same result appended to the buffer. The return value is - * either 0 upon success and non-zero if no repository was found. - */ -int discover_git_directory(struct strbuf *commondir, - struct strbuf *gitdir); -const char *setup_git_directory_gently(int *); -const char *setup_git_directory(void); -char *prefix_path(const char *prefix, int len, const char *path); -char *prefix_path_gently(const char *prefix, int len, int *remaining, const char *path); - -/* - * Concatenate "prefix" (if len is non-zero) and "path", with no - * connecting characters (so "prefix" should end with a "/"). - * Unlike prefix_path, this should be used if the named file does - * not have to interact with index entry; i.e. name of a random file - * on the filesystem. - * - * The return value is always a newly allocated string (even if the - * prefix was empty). - */ -char *prefix_filename(const char *prefix, const char *path); - -int check_filename(const char *prefix, const char *name); -void verify_filename(const char *prefix, - const char *name, - int diagnose_misspelt_rev); -void verify_non_filename(const char *prefix, const char *name); -int path_inside_repo(const char *prefix, const char *path); - #define INIT_DB_QUIET 0x0001 #define INIT_DB_EXIST_OK 0x0002 @@ -653,84 +460,6 @@ int init_db(const char *git_dir, const char *real_git_dir, const char *initial_branch, unsigned int flags); void initialize_repository_version(int hash_algo, int reinit); -void sanitize_stdfds(void); -int daemonize(void); - -#define alloc_nr(x) (((x)+16)*3/2) - -/** - * Dynamically growing an array using realloc() is error prone and boring. - * - * Define your array with: - * - * - a pointer (`item`) that points at the array, initialized to `NULL` - * (although please name the variable based on its contents, not on its - * type); - * - * - an integer variable (`alloc`) that keeps track of how big the current - * allocation is, initialized to `0`; - * - * - another integer variable (`nr`) to keep track of how many elements the - * array currently has, initialized to `0`. - * - * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n, - * alloc)`. This ensures that the array can hold at least `n` elements by - * calling `realloc(3)` and adjusting `alloc` variable. - * - * ------------ - * sometype *item; - * size_t nr; - * size_t alloc - * - * for (i = 0; i < nr; i++) - * if (we like item[i] already) - * return; - * - * // we did not like any existing one, so add one - * ALLOC_GROW(item, nr + 1, alloc); - * item[nr++] = value you like; - * ------------ - * - * You are responsible for updating the `nr` variable. - * - * If you need to specify the number of elements to allocate explicitly - * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`. - * - * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some - * added niceties. - * - * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'. - */ -#define ALLOC_GROW(x, nr, alloc) \ - do { \ - if ((nr) > alloc) { \ - if (alloc_nr(alloc) < (nr)) \ - alloc = (nr); \ - else \ - alloc = alloc_nr(alloc); \ - REALLOC_ARRAY(x, alloc); \ - } \ - } while (0) - -/* - * Similar to ALLOC_GROW but handles updating of the nr value and - * zeroing the bytes of the newly-grown array elements. - * - * DO NOT USE any expression with side-effect for any of the - * arguments. - */ -#define ALLOC_GROW_BY(x, nr, increase, alloc) \ - do { \ - if (increase) { \ - size_t new_nr = nr + (increase); \ - if (new_nr < nr) \ - BUG("negative growth in ALLOC_GROW_BY"); \ - ALLOC_GROW(x, new_nr, alloc); \ - memset((x) + nr, 0, sizeof(*(x)) * (increase)); \ - nr = new_nr; \ - } \ - } while (0) - /* Initialize and use the cache information */ struct lock_file; void preload_index(struct index_state *index, @@ -955,237 +684,7 @@ void set_alternate_index_output(const char *); extern int verify_index_checksum; extern int verify_ce_order; -/* Environment bits from configuration mechanism */ -extern int trust_executable_bit; -extern int trust_ctime; -extern int check_stat; extern int quote_path_fully; -extern int has_symlinks; -extern int minimum_abbrev, default_abbrev; -extern int ignore_case; -extern int assume_unchanged; -extern int prefer_symlink_refs; -extern int warn_ambiguous_refs; -extern int warn_on_object_refname_ambiguity; -extern char *apply_default_whitespace; -extern char *apply_default_ignorewhitespace; -extern const char *git_attributes_file; -extern const char *git_hooks_path; -extern int zlib_compression_level; -extern int pack_compression_level; -extern size_t packed_git_window_size; -extern size_t packed_git_limit; -extern size_t delta_base_cache_limit; -extern unsigned long big_file_threshold; -extern unsigned long pack_size_limit_cfg; - -/* - * Accessors for the core.sharedrepository config which lazy-load the value - * from the config (if not already set). The "reset" function can be - * used to unset "set" or cached value, meaning that the value will be loaded - * fresh from the config file on the next call to get_shared_repository(). - */ -void set_shared_repository(int value); -int get_shared_repository(void); -void reset_shared_repository(void); - -/* - * Do replace refs need to be checked this run? This variable is - * initialized to true unless --no-replace-object is used or - * $GIT_NO_REPLACE_OBJECTS is set, but is set to false by some - * commands that do not want replace references to be active. - */ -extern int read_replace_refs; - -/* - * These values are used to help identify parts of a repository to fsync. - * FSYNC_COMPONENT_NONE identifies data that will not be a persistent part of the - * repository and so shouldn't be fsynced. - */ -enum fsync_component { - FSYNC_COMPONENT_NONE, - FSYNC_COMPONENT_LOOSE_OBJECT = 1 << 0, - FSYNC_COMPONENT_PACK = 1 << 1, - FSYNC_COMPONENT_PACK_METADATA = 1 << 2, - FSYNC_COMPONENT_COMMIT_GRAPH = 1 << 3, - FSYNC_COMPONENT_INDEX = 1 << 4, - FSYNC_COMPONENT_REFERENCE = 1 << 5, -}; - -#define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \ - FSYNC_COMPONENT_PACK) - -#define FSYNC_COMPONENTS_DERIVED_METADATA (FSYNC_COMPONENT_PACK_METADATA | \ - FSYNC_COMPONENT_COMMIT_GRAPH) - -#define FSYNC_COMPONENTS_DEFAULT ((FSYNC_COMPONENTS_OBJECTS | \ - FSYNC_COMPONENTS_DERIVED_METADATA) & \ - ~FSYNC_COMPONENT_LOOSE_OBJECT) - -#define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \ - FSYNC_COMPONENT_REFERENCE) - -#define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \ - FSYNC_COMPONENT_INDEX) - -#define FSYNC_COMPONENTS_ALL (FSYNC_COMPONENT_LOOSE_OBJECT | \ - FSYNC_COMPONENT_PACK | \ - FSYNC_COMPONENT_PACK_METADATA | \ - FSYNC_COMPONENT_COMMIT_GRAPH | \ - FSYNC_COMPONENT_INDEX | \ - FSYNC_COMPONENT_REFERENCE) - -#ifndef FSYNC_COMPONENTS_PLATFORM_DEFAULT -#define FSYNC_COMPONENTS_PLATFORM_DEFAULT FSYNC_COMPONENTS_DEFAULT -#endif - -/* - * A bitmask indicating which components of the repo should be fsynced. - */ -extern enum fsync_component fsync_components; -extern int fsync_object_files; -extern int use_fsync; - -enum fsync_method { - FSYNC_METHOD_FSYNC, - FSYNC_METHOD_WRITEOUT_ONLY, - FSYNC_METHOD_BATCH, -}; - -extern enum fsync_method fsync_method; -extern int core_preload_index; -extern int precomposed_unicode; -extern int protect_hfs; -extern int protect_ntfs; - -extern int core_apply_sparse_checkout; -extern int core_sparse_checkout_cone; -extern int sparse_expect_files_outside_of_patterns; - -/* - * Returns the boolean value of $GIT_OPTIONAL_LOCKS (or the default value). - */ -int use_optional_locks(void); - -/* - * The character that begins a commented line in user-editable file - * that is subject to stripspace. - */ -extern char comment_line_char; -extern int auto_comment_line_char; - -enum log_refs_config { - LOG_REFS_UNSET = -1, - LOG_REFS_NONE = 0, - LOG_REFS_NORMAL, - LOG_REFS_ALWAYS -}; -extern enum log_refs_config log_all_ref_updates; - -enum rebase_setup_type { - AUTOREBASE_NEVER = 0, - AUTOREBASE_LOCAL, - AUTOREBASE_REMOTE, - AUTOREBASE_ALWAYS -}; - -enum push_default_type { - PUSH_DEFAULT_NOTHING = 0, - PUSH_DEFAULT_MATCHING, - PUSH_DEFAULT_SIMPLE, - PUSH_DEFAULT_UPSTREAM, - PUSH_DEFAULT_CURRENT, - PUSH_DEFAULT_UNSPECIFIED -}; - -extern enum rebase_setup_type autorebase; -extern enum push_default_type push_default; - -enum object_creation_mode { - OBJECT_CREATION_USES_HARDLINKS = 0, - OBJECT_CREATION_USES_RENAMES = 1 -}; - -extern enum object_creation_mode object_creation_mode; - -extern char *notes_ref_name; - -extern int grafts_replace_parents; - -/* - * GIT_REPO_VERSION is the version we write by default. The - * _READ variant is the highest number we know how to - * handle. - */ -#define GIT_REPO_VERSION 0 -#define GIT_REPO_VERSION_READ 1 -extern int repository_format_precious_objects; -extern int repository_format_worktree_config; - -/* - * You _have_ to initialize a `struct repository_format` using - * `= REPOSITORY_FORMAT_INIT` before calling `read_repository_format()`. - */ -struct repository_format { - int version; - int precious_objects; - char *partial_clone; /* value of extensions.partialclone */ - int worktree_config; - int is_bare; - int hash_algo; - int sparse_index; - char *work_tree; - struct string_list unknown_extensions; - struct string_list v1_only_extensions; -}; - -/* - * Always use this to initialize a `struct repository_format` - * to a well-defined, default state before calling - * `read_repository()`. - */ -#define REPOSITORY_FORMAT_INIT \ -{ \ - .version = -1, \ - .is_bare = -1, \ - .hash_algo = GIT_HASH_SHA1, \ - .unknown_extensions = STRING_LIST_INIT_DUP, \ - .v1_only_extensions = STRING_LIST_INIT_DUP, \ -} - -/* - * Read the repository format characteristics from the config file "path" into - * "format" struct. Returns the numeric version. On error, or if no version is - * found in the configuration, -1 is returned, format->version is set to -1, - * and all other fields in the struct are set to the default configuration - * (REPOSITORY_FORMAT_INIT). Always initialize the struct using - * REPOSITORY_FORMAT_INIT before calling this function. - */ -int read_repository_format(struct repository_format *format, const char *path); - -/* - * Free the memory held onto by `format`, but not the struct itself. - * (No need to use this after `read_repository_format()` fails.) - */ -void clear_repository_format(struct repository_format *format); - -/* - * Verify that the repository described by repository_format is something we - * can read. If it is, return 0. Otherwise, return -1, and "err" will describe - * any errors encountered. - */ -int verify_repository_format(const struct repository_format *format, - struct strbuf *err); - -/* - * Check the repository format version in the path found in get_git_dir(), - * and die if it is a version we don't understand. Generally one would - * set_git_dir() before calling this, and use it only for "are we in a valid - * repo?". - * - * If successful and fmt is not NULL, fill fmt with data. - */ -void check_repository_format(struct repository_format *fmt); #define MTIME_CHANGED 0x0001 #define CTIME_CHANGED 0x0002 @@ -1213,28 +712,6 @@ void check_repository_format(struct repository_format *fmt); const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len); int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len); -/* set default permissions by passing mode arguments to open(2) */ -int git_mkstemps_mode(char *pattern, int suffix_len, int mode); -int git_mkstemp_mode(char *pattern, int mode); - -/* - * NOTE NOTE NOTE!! - * - * PERM_UMASK, OLD_PERM_GROUP and OLD_PERM_EVERYBODY enumerations must - * not be changed. Old repositories have core.sharedrepository written in - * numeric format, and therefore these values are preserved for compatibility - * reasons. - */ -enum sharedrepo { - PERM_UMASK = 0, - OLD_PERM_GROUP = 1, - OLD_PERM_EVERYBODY = 2, - PERM_GROUP = 0660, - PERM_EVERYBODY = 0664 -}; -int git_config_perm(const char *var, const char *value); -int adjust_shared_perm(const char *path); - /* * Create the directory containing the named path, using care to be * somewhat safe against races. Return one of the scld_error values to @@ -1269,68 +746,6 @@ enum scld_error safe_create_leading_directories_const(const char *path); enum scld_error safe_create_leading_directories_no_share(char *path); int mkdir_in_gitdir(const char *path); -char *interpolate_path(const char *path, int real_home); -/* NEEDSWORK: remove this synonym once in-flight topics have migrated */ -#define expand_user_path interpolate_path -const char *enter_repo(const char *path, int strict); -static inline int is_absolute_path(const char *path) -{ - return is_dir_sep(path[0]) || has_dos_drive_prefix(path); -} -int is_directory(const char *); -char *strbuf_realpath(struct strbuf *resolved, const char *path, - int die_on_error); -char *strbuf_realpath_forgiving(struct strbuf *resolved, const char *path, - int die_on_error); -char *real_pathdup(const char *path, int die_on_error); -const char *absolute_path(const char *path); -char *absolute_pathdup(const char *path); -const char *remove_leading_path(const char *in, const char *prefix); -const char *relative_path(const char *in, const char *prefix, struct strbuf *sb); -int normalize_path_copy_len(char *dst, const char *src, int *prefix_len); -int normalize_path_copy(char *dst, const char *src); -int longest_ancestor_length(const char *path, struct string_list *prefixes); -char *strip_path_suffix(const char *path, const char *suffix); -int daemon_avoid_alias(const char *path); - -/* - * These functions match their is_hfs_dotgit() counterparts; see utf8.h for - * details. - */ -int is_ntfs_dotgit(const char *name); -int is_ntfs_dotgitmodules(const char *name); -int is_ntfs_dotgitignore(const char *name); -int is_ntfs_dotgitattributes(const char *name); -int is_ntfs_dotmailmap(const char *name); - -/* - * Returns true iff "str" could be confused as a command-line option when - * passed to a sub-program like "ssh". Note that this has nothing to do with - * shell-quoting, which should be handled separately; we're assuming here that - * the string makes it verbatim to the sub-program. - */ -int looks_like_command_line_option(const char *str); - -/** - * Return a newly allocated string with the evaluation of - * "$XDG_CONFIG_HOME/$subdir/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise - * "$HOME/.config/$subdir/$filename". Return NULL upon error. - */ -char *xdg_config_home_for(const char *subdir, const char *filename); - -/** - * Return a newly allocated string with the evaluation of - * "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise - * "$HOME/.config/git/$filename". Return NULL upon error. - */ -char *xdg_config_home(const char *filename); - -/** - * Return a newly allocated string with the evaluation of - * "$XDG_CACHE_HOME/git/$filename" if $XDG_CACHE_HOME is non-empty, otherwise - * "$HOME/.cache/git/$filename". Return NULL upon error. - */ -char *xdg_cache_home(const char *filename); int git_open_cloexec(const char *name, int flags); #define git_open(name) git_open_cloexec(name, O_RDONLY) @@ -1398,22 +813,6 @@ int finalize_object_file(const char *tmpfile, const char *filename); /* Helper to check and "touch" a file */ int check_and_freshen_file(const char *fn, int freshen); -extern const signed char hexval_table[256]; -static inline unsigned int hexval(unsigned char c) -{ - return hexval_table[c]; -} - -/* - * Convert two consecutive hexadecimal digits into a char. Return a - * negative value on error. Don't run over the end of short strings. - */ -static inline int hex2chr(const char *s) -{ - unsigned int val = hexval(s[0]); - return (val & ~0xf) ? val : (val << 4) | hexval(s[1]); -} - /* Convert to/from hex/sha1 representation */ #define MINIMUM_ABBREV minimum_abbrev #define DEFAULT_ABBREV default_abbrev @@ -1436,40 +835,6 @@ struct object_context { char *path; }; -#define GET_OID_QUIETLY 01 -#define GET_OID_COMMIT 02 -#define GET_OID_COMMITTISH 04 -#define GET_OID_TREE 010 -#define GET_OID_TREEISH 020 -#define GET_OID_BLOB 040 -#define GET_OID_FOLLOW_SYMLINKS 0100 -#define GET_OID_RECORD_PATH 0200 -#define GET_OID_ONLY_TO_DIE 04000 -#define GET_OID_REQUIRE_PATH 010000 - -#define GET_OID_DISAMBIGUATORS \ - (GET_OID_COMMIT | GET_OID_COMMITTISH | \ - GET_OID_TREE | GET_OID_TREEISH | \ - GET_OID_BLOB) - -enum get_oid_result { - FOUND = 0, - MISSING_OBJECT = -1, /* The requested object is missing */ - SHORT_NAME_AMBIGUOUS = -2, - /* The following only apply when symlinks are followed */ - DANGLING_SYMLINK = -4, /* - * The initial symlink is there, but - * (transitively) points to a missing - * in-tree file - */ - SYMLINK_LOOP = -5, - NOT_DIR = -6, /* - * Somewhere along the symlink chain, a path is - * requested which contains a file as a - * non-final element. - */ -}; - int repo_get_oid(struct repository *r, const char *str, struct object_id *oid); __attribute__((format (printf, 2, 3))) int get_oidf(struct object_id *oid, const char *fmt, ...); @@ -1492,68 +857,6 @@ int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_f int set_disambiguate_hint_config(const char *var, const char *value); /* - * Try to read a SHA1 in hexadecimal format from the 40 characters - * starting at hex. Write the 20-byte result to sha1 in binary form. - * Return 0 on success. Reading stops if a NUL is encountered in the - * input, so it is safe to pass this function an arbitrary - * null-terminated string. - */ -int get_sha1_hex(const char *hex, unsigned char *sha1); -int get_oid_hex(const char *hex, struct object_id *sha1); - -/* Like get_oid_hex, but for an arbitrary hash algorithm. */ -int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_hash_algo *algop); - -/* - * Read `len` pairs of hexadecimal digits from `hex` and write the - * values to `binary` as `len` bytes. Return 0 on success, or -1 if - * the input does not consist of hex digits). - */ -int hex_to_bytes(unsigned char *binary, const char *hex, size_t len); - -/* - * Convert a binary hash in "unsigned char []" or an object name in - * "struct object_id *" to its hex equivalent. The `_r` variant is reentrant, - * and writes the NUL-terminated output to the buffer `out`, which must be at - * least `GIT_MAX_HEXSZ + 1` bytes, and returns a pointer to out for - * convenience. - * - * The non-`_r` variant returns a static buffer, but uses a ring of 4 - * buffers, making it safe to make multiple calls for a single statement, like: - * - * printf("%s -> %s", hash_to_hex(one), hash_to_hex(two)); - * printf("%s -> %s", oid_to_hex(one), oid_to_hex(two)); - */ -char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash, const struct git_hash_algo *); -char *oid_to_hex_r(char *out, const struct object_id *oid); -char *hash_to_hex_algop(const unsigned char *hash, const struct git_hash_algo *); /* static buffer result! */ -char *hash_to_hex(const unsigned char *hash); /* same static buffer */ -char *oid_to_hex(const struct object_id *oid); /* same static buffer */ - -/* - * Parse a 40-character hexadecimal object ID starting from hex, updating the - * pointer specified by end when parsing stops. The resulting object ID is - * stored in oid. Returns 0 on success. Parsing will stop on the first NUL or - * other invalid character. end is only updated on success; otherwise, it is - * unmodified. - */ -int parse_oid_hex(const char *hex, struct object_id *oid, const char **end); - -/* Like parse_oid_hex, but for an arbitrary hash algorithm. */ -int parse_oid_hex_algop(const char *hex, struct object_id *oid, const char **end, - const struct git_hash_algo *algo); - - -/* - * These functions work like get_oid_hex and parse_oid_hex, but they will parse - * a hex value for any algorithm. The algorithm is detected based on the length - * and the algorithm in use is returned. If this is not a hex object ID in any - * algorithm, returns GIT_HASH_UNKNOWN. - */ -int get_oid_hex_any(const char *hex, struct object_id *oid); -int parse_oid_hex_any(const char *hex, struct object_id *oid, const char **end); - -/* * This reads short-hand syntax that not only evaluates to a commit * object name, but also can act as if the end user spelled the name * of the branch from the command line. @@ -1598,8 +901,6 @@ int repo_interpret_branch_name(struct repository *r, struct strbuf *buf, const struct interpret_branch_name_options *options); -int validate_headref(const char *ref); - int base_name_compare(const char *name1, size_t len1, int mode1, const char *name2, size_t len2, int mode2); int df_name_compare(const char *name1, size_t len1, int mode1, @@ -1617,65 +918,10 @@ struct object *repo_peel_to_type(struct repository *r, const char *name, int namelen, struct object *o, enum object_type); -#define IDENT_STRICT 1 -#define IDENT_NO_DATE 2 -#define IDENT_NO_NAME 4 - -enum want_ident { - WANT_BLANK_IDENT, - WANT_AUTHOR_IDENT, - WANT_COMMITTER_IDENT -}; - -const char *git_author_info(int); -const char *git_committer_info(int); -const char *fmt_ident(const char *name, const char *email, - enum want_ident whose_ident, - const char *date_str, int); -const char *fmt_name(enum want_ident); -const char *ident_default_name(void); -const char *ident_default_email(void); const char *git_editor(void); const char *git_sequence_editor(void); const char *git_pager(int stdout_is_tty); int is_terminal_dumb(void); -int git_ident_config(const char *, const char *, void *); -/* - * Prepare an ident to fall back on if the user didn't configure it. - */ -void prepare_fallback_ident(const char *name, const char *email); -void reset_ident_date(void); - -struct ident_split { - const char *name_begin; - const char *name_end; - const char *mail_begin; - const char *mail_end; - const char *date_begin; - const char *date_end; - const char *tz_begin; - const char *tz_end; -}; -/* - * Signals an success with 0, but time part of the result may be NULL - * if the input lacks timestamp and zone - */ -int split_ident_line(struct ident_split *, const char *, int); - -/* - * Given a commit or tag object buffer and the commit or tag headers, replaces - * the idents in the headers with their canonical versions using the mailmap mechanism. - */ -void apply_mailmap_to_header(struct strbuf *, const char **, struct string_list *); - -/* - * Compare split idents for equality or strict ordering. Note that we - * compare only the ident part of the line, ignoring any timestamp. - * - * Because there are two fields, we must choose one as the primary key; we - * currently arbitrarily pick the email. - */ -int ident_cmp(const struct ident_split *, const struct ident_split *); struct cache_def { struct strbuf path; @@ -1714,21 +960,6 @@ struct pack_entry { }; /* - * Create a temporary file rooted in the object database directory, or - * die on failure. The filename is taken from "pattern", which should have the - * usual "XXXXXX" trailer, and the resulting filename is written into the - * "template" buffer. Returns the open descriptor. - */ -int odb_mkstemp(struct strbuf *temp_filename, const char *pattern); - -/* - * Create a pack .keep file named "name" (which should generally be the output - * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on - * error. - */ -int odb_pack_keep(const char *name); - -/* * Set this to 0 to prevent oid_object_info_extended() from fetching missing * blobs. This has a difference only if extensions.partialClone is set. * @@ -1739,65 +970,15 @@ extern int fetch_if_missing; /* Dumb servers support */ int update_server_info(int); -const char *get_log_output_encoding(void); -const char *get_commit_output_encoding(void); - -int committer_ident_sufficiently_given(void); -int author_ident_sufficiently_given(void); - -extern const char *git_commit_encoding; -extern const char *git_log_output_encoding; extern const char *git_mailmap_file; extern const char *git_mailmap_blob; -/* IO helper functions */ -void maybe_flush_or_die(FILE *, const char *); -__attribute__((format (printf, 2, 3))) -void fprintf_or_die(FILE *, const char *fmt, ...); -void fwrite_or_die(FILE *f, const void *buf, size_t count); -void fflush_or_die(FILE *f); - #define COPY_READ_ERROR (-2) #define COPY_WRITE_ERROR (-3) int copy_fd(int ifd, int ofd); int copy_file(const char *dst, const char *src, int mode); int copy_file_with_time(const char *dst, const char *src, int mode); -void write_or_die(int fd, const void *buf, size_t count); -void fsync_or_die(int fd, const char *); -int fsync_component(enum fsync_component component, int fd); -void fsync_component_or_die(enum fsync_component component, int fd, const char *msg); - -static inline int batch_fsync_enabled(enum fsync_component component) -{ - return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH); -} - -ssize_t read_in_full(int fd, void *buf, size_t count); -ssize_t write_in_full(int fd, const void *buf, size_t count); -ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset); - -static inline ssize_t write_str_in_full(int fd, const char *str) -{ - return write_in_full(fd, str, strlen(str)); -} - -/** - * Open (and truncate) the file at path, write the contents of buf to it, - * and close it. Dies if any errors are encountered. - */ -void write_file_buf(const char *path, const char *buf, size_t len); - -/** - * Like write_file_buf(), but format the contents into a buffer first. - * Additionally, write_file() will append a newline if one is not already - * present, making it convenient to write text files: - * - * write_file(path, "counter: %d", ctr); - */ -__attribute__((format (printf, 2, 3))) -void write_file(const char *path, const char *fmt, ...); - /* pager.c */ void setup_pager(void); int pager_in_use(void); @@ -1808,10 +989,6 @@ int decimal_width(uintmax_t); int check_pager_config(const char *cmd); void prepare_pager_args(struct child_process *, const char *pager); -extern const char *editor_program; -extern const char *askpass_program; -extern const char *excludes_file; - /* base85 */ int decode_85(char *dst, const char *line, int linelen); void encode_85(char *buf, const unsigned char *data, int bytes); @@ -1863,15 +1040,6 @@ int ws_blank_line(const char *line, int len); void overlay_tree_on_index(struct index_state *istate, const char *tree_name, const char *prefix); -/* setup.c */ -struct startup_info { - int have_repository; - const char *prefix; - const char *original_cwd; -}; -extern struct startup_info *startup_info; -extern const char *tmp_original_cwd; - /* merge.c */ struct commit_list; int try_merge_command(struct repository *r, @@ -1915,21 +1083,4 @@ void stat_validity_update(struct stat_validity *sv, int fd); int versioncmp(const char *s1, const char *s2); -/* - * Create a directory and (if share is nonzero) adjust its permissions - * according to the shared_repository setting. Only use this for - * directories under $GIT_DIR. Don't use it for working tree - * directories. - */ -void safe_create_dir(const char *dir, int share); - -/* - * Should we print an ellipsis after an abbreviated SHA-1 value - * when doing diff-raw output or indicating a detached HEAD? - */ -int print_sha1_ellipsis(void); - -/* Return 1 if the file is empty or does not exists, 0 otherwise. */ -int is_empty_or_missing_file(const char *filename); - #endif /* CACHE_H */ @@ -4,6 +4,7 @@ * Based on Adam Langley's adaptation of Dan Bernstein's public domain code * git clone https://github.com/agl/critbit.git */ +#include "git-compat-util.h" #include "cbtree.h" static struct cb_node *cb_node_of(const void *p) @@ -14,8 +14,6 @@ #ifndef CBTREE_H #define CBTREE_H -#include "git-compat-util.h" - struct cb_node; struct cb_node { struct cb_node *child[2]; diff --git a/chdir-notify.c b/chdir-notify.c index 5f7f2c2ac2..929ec01b3a 100644 --- a/chdir-notify.c +++ b/chdir-notify.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "abspath.h" #include "chdir-notify.h" #include "list.h" #include "strbuf.h" diff --git a/checkout.h b/checkout.h index 1152133bd7..1917f3b323 100644 --- a/checkout.h +++ b/checkout.h @@ -1,7 +1,7 @@ #ifndef CHECKOUT_H #define CHECKOUT_H -#include "cache.h" +#include "hash.h" /* * Check if the branch name uniquely matches a branch name on a remote diff --git a/chunk-format.c b/chunk-format.c index 0275b74a89..60a73c1b14 100644 --- a/chunk-format.c +++ b/chunk-format.c @@ -1,6 +1,9 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "chunk-format.h" #include "csum-file.h" +#include "gettext.h" +#include "trace2.h" /* * When writing a chunk-based file format, collect the chunks in diff --git a/chunk-format.h b/chunk-format.h index 7885aa0848..025c38f938 100644 --- a/chunk-format.h +++ b/chunk-format.h @@ -1,7 +1,6 @@ #ifndef CHUNK_FORMAT_H #define CHUNK_FORMAT_H -#include "git-compat-util.h" #include "hash.h" struct hashfile; @@ -1,6 +1,8 @@ #include "cache.h" #include "config.h" #include "color.h" +#include "gettext.h" +#include "hex.h" static int git_use_color_default = GIT_COLOR_AUTO; int color_stdout_is_tty = -1; diff --git a/combine-diff.c b/combine-diff.c index fa5967a5be..44ef6a1a81 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -4,6 +4,8 @@ #include "blob.h" #include "diff.h" #include "diffcore.h" +#include "environment.h" +#include "hex.h" #include "quote.h" #include "xdiff-interface.h" #include "xdiff/xmacros.h" diff --git a/commit-graph.c b/commit-graph.c index 035816f4d8..1bf673b134 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1,5 +1,7 @@ -#include "git-compat-util.h" +#include "cache.h" #include "config.h" +#include "gettext.h" +#include "hex.h" #include "lockfile.h" #include "pack.h" #include "packfile.h" @@ -20,6 +22,7 @@ #include "json-writer.h" #include "trace2.h" #include "chunk-format.h" +#include "wrapper.h" void git_test_write_commit_graph_or_die(void) { diff --git a/commit-graph.h b/commit-graph.h index 37faee6b66..bb88bec7aa 100644 --- a/commit-graph.h +++ b/commit-graph.h @@ -1,7 +1,6 @@ #ifndef COMMIT_GRAPH_H #define COMMIT_GRAPH_H -#include "git-compat-util.h" #include "object-store.h" #include "oidset.h" diff --git a/commit-reach.c b/commit-reach.c index 01eb11b595..5957a8e950 100644 --- a/commit-reach.c +++ b/commit-reach.c @@ -1,7 +1,9 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "commit.h" #include "commit-graph.h" #include "decorate.h" +#include "hex.h" #include "prio-queue.h" #include "tree.h" #include "ref-filter.h" @@ -808,8 +810,12 @@ cleanup: clear_commit_marks_many(nr_commits, list, RESULT | assign_flag); free(list); - for (i = 0; i < from->nr; i++) - from->objects[i].item->flags &= ~assign_flag; + for (i = 0; i < from->nr; i++) { + struct object *from_one = from->objects[i].item; + + if (from_one) + from_one->flags &= ~assign_flag; + } return result; } diff --git a/commit-slab-impl.h b/commit-slab-impl.h index 557738df27..4a414ee905 100644 --- a/commit-slab-impl.h +++ b/commit-slab-impl.h @@ -1,8 +1,6 @@ #ifndef COMMIT_SLAB_IMPL_H #define COMMIT_SLAB_IMPL_H -#include "git-compat-util.h" - #define implement_static_commit_slab(slabname, elemtype) \ implement_commit_slab(slabname, elemtype, MAYBE_UNUSED static) @@ -2,6 +2,9 @@ #include "tag.h" #include "commit.h" #include "commit-graph.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "repository.h" #include "object-store.h" #include "pkt-line.h" @@ -20,6 +23,7 @@ #include "refs.h" #include "commit-reach.h" #include "run-command.h" +#include "setup.h" #include "shallow.h" #include "hook.h" @@ -802,7 +806,8 @@ int compare_commits_by_author_date(const void *a_, const void *b_, return 0; } -int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void *unused) +int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, + void *unused UNUSED) { const struct commit *a = a_, *b = b_; const timestamp_t generation_a = commit_graph_generation(a), @@ -822,7 +827,8 @@ int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void return 0; } -int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused) +int compare_commits_by_commit_date(const void *a_, const void *b_, + void *unused UNUSED) { const struct commit *a = a_, *b = b_; /* newer commits with larger date first */ @@ -193,7 +193,6 @@ void free_commit_list(struct commit_list *list); struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */ -int has_non_ascii(const char *text); const char *repo_logmsg_reencode(struct repository *r, const struct commit *commit, char **commit_encoding, diff --git a/common-main.c b/common-main.c index 0a22861f1c..b83cb5cf06 100644 --- a/common-main.c +++ b/common-main.c @@ -1,6 +1,8 @@ #include "cache.h" #include "exec-cmd.h" +#include "gettext.h" #include "attr.h" +#include "setup.h" /* * Many parts of Git have subprograms communicate via pipe, expect the diff --git a/compat/disk.h b/compat/disk.h index 50a32e3d8a..6c979c27d8 100644 --- a/compat/disk.h +++ b/compat/disk.h @@ -2,6 +2,8 @@ #define COMPAT_DISK_H #include "git-compat-util.h" +#include "abspath.h" +#include "gettext.h" static int get_disk_info(struct strbuf *out) { diff --git a/compat/fsmonitor/fsm-health-win32.c b/compat/fsmonitor/fsm-health-win32.c index 2ea08c1d4e..fe11bdd9ce 100644 --- a/compat/fsmonitor/fsm-health-win32.c +++ b/compat/fsmonitor/fsm-health-win32.c @@ -3,6 +3,7 @@ #include "fsmonitor.h" #include "fsm-health.h" #include "fsmonitor--daemon.h" +#include "gettext.h" /* * Every minute wake up and test our health. diff --git a/compat/fsmonitor/fsm-ipc-darwin.c b/compat/fsmonitor/fsm-ipc-darwin.c index d67b0ee50d..eb25123fa1 100644 --- a/compat/fsmonitor/fsm-ipc-darwin.c +++ b/compat/fsmonitor/fsm-ipc-darwin.c @@ -1,5 +1,6 @@ #include "cache.h" #include "config.h" +#include "hex.h" #include "strbuf.h" #include "fsmonitor.h" #include "fsmonitor-ipc.h" diff --git a/compat/fsmonitor/fsm-ipc-win32.c b/compat/fsmonitor/fsm-ipc-win32.c index e08c505c14..c9536dfb66 100644 --- a/compat/fsmonitor/fsm-ipc-win32.c +++ b/compat/fsmonitor/fsm-ipc-win32.c @@ -1,3 +1,4 @@ +#include "git-compat-util.h" #include "config.h" #include "fsmonitor-ipc.h" diff --git a/compat/fsmonitor/fsm-listen-darwin.c b/compat/fsmonitor/fsm-listen-darwin.c index 97a55a6f0a..5eb6402ab8 100644 --- a/compat/fsmonitor/fsm-listen-darwin.c +++ b/compat/fsmonitor/fsm-listen-darwin.c @@ -28,6 +28,7 @@ #include "fsm-listen.h" #include "fsmonitor--daemon.h" #include "fsmonitor-path-utils.h" +#include "gettext.h" struct fsm_listen_data { diff --git a/compat/fsmonitor/fsm-listen-win32.c b/compat/fsmonitor/fsm-listen-win32.c index 03df8d951b..7b07b74ba5 100644 --- a/compat/fsmonitor/fsm-listen-win32.c +++ b/compat/fsmonitor/fsm-listen-win32.c @@ -3,6 +3,7 @@ #include "fsmonitor.h" #include "fsm-listen.h" #include "fsmonitor--daemon.h" +#include "gettext.h" /* * The documentation of ReadDirectoryChangesW() states that the maximum diff --git a/compat/fsmonitor/fsm-path-utils-darwin.c b/compat/fsmonitor/fsm-path-utils-darwin.c index ce5a8febe0..45eb4a9b9e 100644 --- a/compat/fsmonitor/fsm-path-utils-darwin.c +++ b/compat/fsmonitor/fsm-path-utils-darwin.c @@ -1,5 +1,6 @@ #include "fsmonitor.h" #include "fsmonitor-path-utils.h" +#include "gettext.h" #include <dirent.h> #include <errno.h> #include <fcntl.h> diff --git a/compat/fsmonitor/fsm-path-utils-win32.c b/compat/fsmonitor/fsm-path-utils-win32.c index 0d95bbb416..4024baafb9 100644 --- a/compat/fsmonitor/fsm-path-utils-win32.c +++ b/compat/fsmonitor/fsm-path-utils-win32.c @@ -1,6 +1,7 @@ #include "cache.h" #include "fsmonitor.h" #include "fsmonitor-path-utils.h" +#include "gettext.h" /* * Check remote working directory protocol. diff --git a/compat/fsmonitor/fsm-settings-darwin.c b/compat/fsmonitor/fsm-settings-darwin.c index 6abbc7af3a..58b623fbb9 100644 --- a/compat/fsmonitor/fsm-settings-darwin.c +++ b/compat/fsmonitor/fsm-settings-darwin.c @@ -1,3 +1,4 @@ +#include "git-compat-util.h" #include "config.h" #include "fsmonitor.h" #include "fsmonitor-ipc.h" diff --git a/compat/linux/procinfo.c b/compat/linux/procinfo.c index bc2f9382a1..4bb2d66227 100644 --- a/compat/linux/procinfo.c +++ b/compat/linux/procinfo.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "strbuf.h" #include "strvec.h" diff --git a/compat/mingw.c b/compat/mingw.c index e433740381..94c5a1daa4 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -7,9 +7,14 @@ #include "../strbuf.h" #include "../run-command.h" #include "../cache.h" +#include "../abspath.h" +#include "../alloc.h" #include "win32/lazyload.h" #include "../config.h" +#include "../environment.h" +#include "../wrapper.h" #include "dir.h" +#include "gettext.h" #define SECURITY_WIN32 #include <sspi.h> diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c index cce1d57a46..8a9881db07 100644 --- a/compat/precompose_utf8.c +++ b/compat/precompose_utf8.c @@ -7,6 +7,8 @@ #include "cache.h" #include "config.h" +#include "environment.h" +#include "gettext.h" #include "utf8.h" #include "precompose_utf8.h" diff --git a/compat/simple-ipc/ipc-shared.c b/compat/simple-ipc/ipc-shared.c index 1b9d359ab6..e5e1dda8cc 100644 --- a/compat/simple-ipc/ipc-shared.c +++ b/compat/simple-ipc/ipc-shared.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "simple-ipc.h" #include "strbuf.h" #include "pkt-line.h" diff --git a/compat/simple-ipc/ipc-unix-socket.c b/compat/simple-ipc/ipc-unix-socket.c index 28a79289d4..152db60a31 100644 --- a/compat/simple-ipc/ipc-unix-socket.c +++ b/compat/simple-ipc/ipc-unix-socket.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "gettext.h" #include "simple-ipc.h" #include "strbuf.h" #include "pkt-line.h" diff --git a/compat/simple-ipc/ipc-win32.c b/compat/simple-ipc/ipc-win32.c index 20ea7b65e0..997f614434 100644 --- a/compat/simple-ipc/ipc-win32.c +++ b/compat/simple-ipc/ipc-win32.c @@ -1,4 +1,6 @@ #include "cache.h" +#include "abspath.h" +#include "gettext.h" #include "simple-ipc.h" #include "strbuf.h" #include "pkt-line.h" diff --git a/compat/terminal.c b/compat/terminal.c index ea490a7ced..d87e321189 100644 --- a/compat/terminal.c +++ b/compat/terminal.c @@ -1,10 +1,12 @@ -#include "cache.h" +#include "git-compat-util.h" #include "compat/terminal.h" +#include "gettext.h" #include "sigchain.h" #include "strbuf.h" #include "run-command.h" #include "string-list.h" #include "hashmap.h" +#include "wrapper.h" #if defined(HAVE_DEV_TTY) || defined(GIT_WINDOWS_NATIVE) @@ -6,10 +6,14 @@ * */ #include "cache.h" +#include "abspath.h" +#include "alloc.h" #include "date.h" #include "branch.h" #include "config.h" #include "environment.h" +#include "gettext.h" +#include "ident.h" #include "repository.h" #include "lockfile.h" #include "exec-cmd.h" @@ -21,8 +25,12 @@ #include "utf8.h" #include "dir.h" #include "color.h" +#include "replace-object.h" #include "refs.h" +#include "setup.h" #include "worktree.h" +#include "wrapper.h" +#include "write-or-die.h" struct config_source { struct config_source *prev; @@ -1,6 +1,9 @@ #include "git-compat-util.h" #include "cache.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "pkt-line.h" #include "quote.h" #include "refs.h" @@ -30,7 +33,8 @@ static int check_ref(const char *name, unsigned int flags) return 0; /* REF_NORMAL means that we don't want the magic fake tag refs */ - if ((flags & REF_NORMAL) && check_refname_format(name, 0)) + if ((flags & REF_NORMAL) && check_refname_format(name, + REFNAME_ALLOW_ONELEVEL)) return 0; /* REF_HEADS means that we want regular branch heads */ diff --git a/connected.c b/connected.c index 5853fd7cbf..d672521da4 100644 --- a/connected.c +++ b/connected.c @@ -1,4 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "gettext.h" +#include "hex.h" #include "object-store.h" #include "run-command.h" #include "sigchain.h" @@ -1,5 +1,7 @@ #include "cache.h" #include "config.h" +#include "gettext.h" +#include "hex.h" #include "object-store.h" #include "attr.h" #include "run-command.h" @@ -9,6 +11,7 @@ #include "sub-process.h" #include "utf8.h" #include "ll-merge.h" +#include "wrapper.h" /* * convert.c - convert a file when checking it out and checking it in. @@ -1,4 +1,5 @@ #include "cache.h" +#include "wrapper.h" int copy_fd(int ifd, int ofd) { diff --git a/credential.c b/credential.c index f32011343f..e6417bf880 100644 --- a/credential.c +++ b/credential.c @@ -1,6 +1,8 @@ #include "cache.h" +#include "abspath.h" #include "config.h" #include "credential.h" +#include "gettext.h" #include "string-list.h" #include "run-command.h" #include "url.h" @@ -23,6 +25,7 @@ void credential_clear(struct credential *c) free(c->username); free(c->password); string_list_clear(&c->helpers, 0); + strvec_clear(&c->wwwauth_headers); credential_init(c); } @@ -280,6 +283,8 @@ void credential_write(const struct credential *c, FILE *fp) credential_write_item(fp, "password_expiry_utc", s, 0); free(s); } + for (size_t i = 0; i < c->wwwauth_headers.nr; i++) + credential_write_item(fp, "wwwauth[]", c->wwwauth_headers.v[i], 0); } static int run_credential_helper(struct credential *c, diff --git a/credential.h b/credential.h index 935b28a70f..2b5958cd43 100644 --- a/credential.h +++ b/credential.h @@ -2,6 +2,7 @@ #define CREDENTIAL_H #include "string-list.h" +#include "strvec.h" /** * The credentials API provides an abstracted way of gathering username and @@ -115,6 +116,20 @@ struct credential { */ struct string_list helpers; + /** + * A `strvec` of WWW-Authenticate header values. Each string + * is the value of a WWW-Authenticate header in an HTTP response, + * in the order they were received in the response. + */ + struct strvec wwwauth_headers; + + /** + * Internal use only. Keeps track of if we previously matched against a + * WWW-Authenticate header line in order to re-fold future continuation + * lines into one value. + */ + unsigned header_is_last_match:1; + unsigned approved:1, configured:1, quit:1, @@ -132,6 +147,7 @@ struct credential { #define CREDENTIAL_INIT { \ .helpers = STRING_LIST_INIT_DUP, \ .password_expiry_utc = TIME_MAX, \ + .wwwauth_headers = STRVEC_INIT, \ } /* Initialize a credential structure, setting all fields to empty. */ diff --git a/csum-file.c b/csum-file.c index cce13c0f04..82ae2973d3 100644 --- a/csum-file.c +++ b/csum-file.c @@ -7,9 +7,10 @@ * files. Useful when you write a file that you want to be * able to verify hasn't been messed with afterwards. */ -#include "cache.h" +#include "git-compat-util.h" #include "progress.h" #include "csum-file.h" +#include "wrapper.h" static void verify_buffer_or_die(struct hashfile *f, const void *buf, diff --git a/csum-file.h b/csum-file.h index 793a59da12..566e05cbd2 100644 --- a/csum-file.h +++ b/csum-file.h @@ -1,8 +1,8 @@ #ifndef CSUM_FILE_H #define CSUM_FILE_H -#include "cache.h" #include "hash.h" +#include "write-or-die.h" struct progress; @@ -1,9 +1,14 @@ #include "cache.h" +#include "abspath.h" +#include "alloc.h" #include "config.h" +#include "environment.h" #include "pkt-line.h" #include "run-command.h" +#include "setup.h" #include "strbuf.h" #include "string-list.h" +#include "wrapper.h" #ifdef NO_INITGROUPS #define initgroups(x, y) (0) /* nothing */ @@ -928,7 +933,7 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen) add_child(&cld, addr, addrlen); } -static void child_handler(int signo) +static void child_handler(int signo UNUSED) { /* * Otherwise empty handler because systemcalls will get interrupted @@ -6,6 +6,7 @@ #include "cache.h" #include "date.h" +#include "gettext.h" /* * This is like mktime, but without normalization of tm_wday and tm_yday. diff --git a/decorate.c b/decorate.c index 2036d15967..71e79daa82 100644 --- a/decorate.c +++ b/decorate.c @@ -2,7 +2,8 @@ * decorate.c - decorate a git object with some arbitrary * data. */ -#include "cache.h" +#include "git-compat-util.h" +#include "hashmap.h" #include "object.h" #include "decorate.h" diff --git a/delta-islands.c b/delta-islands.c index 05448851ad..40f2ccfb55 100644 --- a/delta-islands.c +++ b/delta-islands.c @@ -1,8 +1,11 @@ #include "cache.h" +#include "alloc.h" #include "attr.h" #include "object.h" #include "blob.h" #include "commit.h" +#include "gettext.h" +#include "hex.h" #include "tag.h" #include "tree.h" #include "delta.h" diff --git a/diagnose.c b/diagnose.c index 8f26569896..f9a2496c7f 100644 --- a/diagnose.c +++ b/diagnose.c @@ -4,9 +4,12 @@ #include "archive.h" #include "dir.h" #include "help.h" +#include "gettext.h" +#include "hex.h" #include "strvec.h" #include "object-store.h" #include "packfile.h" +#include "write-or-die.h" struct archive_dir { const char *path; @@ -43,7 +46,8 @@ int option_parse_diagnose(const struct option *opt, const char *arg, int unset) return error(_("invalid --%s value '%s'"), opt->long_name, arg); } -static void dir_file_stats_objects(const char *full_path, size_t full_path_len, +static void dir_file_stats_objects(const char *full_path, + size_t full_path_len UNUSED, const char *file_name, void *data) { struct strbuf *buf = data; diff --git a/diff-lib.c b/diff-lib.c index 24470b2161..4169dd8cb1 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -6,6 +6,8 @@ #include "commit.h" #include "diff.h" #include "diffcore.h" +#include "gettext.h" +#include "hex.h" #include "revision.h" #include "cache-tree.h" #include "unpack-trees.h" diff --git a/diff-merges.c b/diff-merges.c index 85cbefa5af..ec97616db1 100644 --- a/diff-merges.c +++ b/diff-merges.c @@ -1,5 +1,7 @@ +#include "git-compat-util.h" #include "diff-merges.h" +#include "gettext.h" #include "revision.h" typedef void (*diff_merges_setup_func_t)(struct rev_info *); diff --git a/diff-no-index.c b/diff-no-index.c index 05fafd0019..934a24bee5 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -5,15 +5,16 @@ */ #include "cache.h" +#include "abspath.h" #include "color.h" #include "commit.h" #include "blob.h" #include "tag.h" #include "diff.h" #include "diffcore.h" +#include "gettext.h" #include "revision.h" #include "log-tree.h" -#include "builtin.h" #include "parse-options.h" #include "string-list.h" #include "dir.h" @@ -2,12 +2,17 @@ * Copyright (C) 2005 Junio C Hamano */ #include "cache.h" +#include "abspath.h" +#include "alloc.h" #include "config.h" +#include "environment.h" +#include "gettext.h" #include "tempfile.h" #include "quote.h" #include "diff.h" #include "diffcore.h" #include "delta.h" +#include "hex.h" #include "xdiff-interface.h" #include "color.h" #include "attr.h" @@ -28,7 +33,9 @@ #include "help.h" #include "promisor-remote.h" #include "dir.h" +#include "setup.h" #include "strmap.h" +#include "wrapper.h" #ifdef NO_FAST_WORKING_DIRECTORY #define FAST_WORKING_DIRECTORY 0 @@ -6,8 +6,8 @@ #include "tree-walk.h" #include "pathspec.h" -#include "object.h" #include "oidset.h" +#include "strbuf.h" /** * The diff API is for programs that compare two sets of files (e.g. two trees, @@ -71,7 +71,6 @@ struct oid_array; struct option; struct repository; struct rev_info; -struct strbuf; struct userdiff_driver; typedef int (*pathchange_fn_t)(struct diff_options *options, diff --git a/diffcore-delta.c b/diffcore-delta.c index 18d8f766d7..c30b56e983 100644 --- a/diffcore-delta.c +++ b/diffcore-delta.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "diff.h" #include "diffcore.h" diff --git a/diffcore-order.c b/diffcore-order.c index 19e73311f9..57ccab2846 100644 --- a/diffcore-order.c +++ b/diffcore-order.c @@ -1,7 +1,8 @@ /* * Copyright (C) 2005 Junio C Hamano */ -#include "cache.h" +#include "git-compat-util.h" +#include "gettext.h" #include "diff.h" #include "diffcore.h" diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c index 03fcbcb40b..13c98a7b5e 100644 --- a/diffcore-pickaxe.c +++ b/diffcore-pickaxe.c @@ -2,12 +2,12 @@ * Copyright (C) 2005 Junio C Hamano * Copyright (C) 2010 Google Inc. */ -#include "cache.h" +#include "git-compat-util.h" #include "diff.h" #include "diffcore.h" #include "xdiff-interface.h" #include "kwset.h" -#include "commit.h" +#include "pretty.h" #include "quote.h" typedef int (*pickaxe_fn)(mmfile_t *one, mmfile_t *two, diff --git a/diffcore-rename.c b/diffcore-rename.c index a97b1322b5..8e2e7a3ad7 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -2,14 +2,19 @@ * * Copyright (C) 2005 Junio C Hamano */ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "diff.h" #include "diffcore.h" #include "object-store.h" #include "hashmap.h" +#include "mem-pool.h" +#include "oid-array.h" #include "progress.h" #include "promisor-remote.h" +#include "string-list.h" #include "strmap.h" +#include "trace2.h" /* Table of rename/copy destinations */ diff --git a/diffcore-rotate.c b/diffcore-rotate.c index 445f060ab0..533986cf63 100644 --- a/diffcore-rotate.c +++ b/diffcore-rotate.c @@ -2,7 +2,8 @@ * Copyright (C) 2021, Google LLC. * Based on diffcore-order.c, which is Copyright (C) 2005, Junio C Hamano */ -#include "cache.h" +#include "git-compat-util.h" +#include "gettext.h" #include "diff.h" #include "diffcore.h" diff --git a/diffcore.h b/diffcore.h index 9b588a1ee1..1701ed50b9 100644 --- a/diffcore.h +++ b/diffcore.h @@ -4,9 +4,11 @@ #ifndef DIFFCORE_H #define DIFFCORE_H -#include "cache.h" +#include "hash.h" struct diff_options; +struct mem_pool; +struct oid_array; struct repository; struct strintmap; struct strmap; diff --git a/dir-iterator.c b/dir-iterator.c index cedd304759..fb7c47f0e8 100644 --- a/dir-iterator.c +++ b/dir-iterator.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "dir.h" #include "iterator.h" #include "dir-iterator.h" @@ -5,9 +5,13 @@ * Copyright (C) Linus Torvalds, 2005-2006 * Junio Hamano, 2005-2006 */ -#include "cache.h" +#include "git-compat-util.h" +#include "abspath.h" +#include "alloc.h" #include "config.h" #include "dir.h" +#include "environment.h" +#include "gettext.h" #include "object-store.h" #include "attr.h" #include "refs.h" @@ -17,7 +21,9 @@ #include "varint.h" #include "ewah/ewok.h" #include "fsmonitor.h" +#include "setup.h" #include "submodule-config.h" +#include "wrapper.h" /* * Tells read_directory_recursive how a file or directory should be treated. @@ -1190,7 +1196,7 @@ struct pattern_list *add_pattern_list(struct dir_struct *dir, struct pattern_list *pl; struct exclude_list_group *group; - group = &dir->exclude_list_group[group_type]; + group = &dir->internal.exclude_list_group[group_type]; ALLOC_GROW(group->pl, group->nr + 1, group->alloc); pl = &group->pl[group->nr++]; memset(pl, 0, sizeof(*pl)); @@ -1211,7 +1217,7 @@ static void add_patterns_from_file_1(struct dir_struct *dir, const char *fname, * differently when dir->untracked is non-NULL. */ if (!dir->untracked) - dir->unmanaged_exclude_files++; + dir->internal.unmanaged_exclude_files++; pl = add_pattern_list(dir, EXC_FILE, fname); if (add_patterns(fname, "", 0, pl, NULL, 0, oid_stat) < 0) die(_("cannot use %s as an exclude file"), fname); @@ -1219,7 +1225,7 @@ static void add_patterns_from_file_1(struct dir_struct *dir, const char *fname, void add_patterns_from_file(struct dir_struct *dir, const char *fname) { - dir->unmanaged_exclude_files++; /* see validate_untracked_cache() */ + dir->internal.unmanaged_exclude_files++; /* see validate_untracked_cache() */ add_patterns_from_file_1(dir, fname, NULL); } @@ -1519,7 +1525,7 @@ static struct path_pattern *last_matching_pattern_from_lists( struct exclude_list_group *group; struct path_pattern *pattern; for (i = EXC_CMDL; i <= EXC_FILE; i++) { - group = &dir->exclude_list_group[i]; + group = &dir->internal.exclude_list_group[i]; for (j = group->nr - 1; j >= 0; j--) { pattern = last_matching_pattern_from_list( pathname, pathlen, basename, dtype_p, @@ -1545,20 +1551,20 @@ static void prep_exclude(struct dir_struct *dir, struct untracked_cache_dir *untracked; int current; - group = &dir->exclude_list_group[EXC_DIRS]; + group = &dir->internal.exclude_list_group[EXC_DIRS]; /* * Pop the exclude lists from the EXCL_DIRS exclude_list_group * which originate from directories not in the prefix of the * path being checked. */ - while ((stk = dir->exclude_stack) != NULL) { + while ((stk = dir->internal.exclude_stack) != NULL) { if (stk->baselen <= baselen && - !strncmp(dir->basebuf.buf, base, stk->baselen)) + !strncmp(dir->internal.basebuf.buf, base, stk->baselen)) break; - pl = &group->pl[dir->exclude_stack->exclude_ix]; - dir->exclude_stack = stk->prev; - dir->pattern = NULL; + pl = &group->pl[dir->internal.exclude_stack->exclude_ix]; + dir->internal.exclude_stack = stk->prev; + dir->internal.pattern = NULL; free((char *)pl->src); /* see strbuf_detach() below */ clear_pattern_list(pl); free(stk); @@ -1566,7 +1572,7 @@ static void prep_exclude(struct dir_struct *dir, } /* Skip traversing into sub directories if the parent is excluded */ - if (dir->pattern) + if (dir->internal.pattern) return; /* @@ -1574,12 +1580,12 @@ static void prep_exclude(struct dir_struct *dir, * memset(dir, 0, sizeof(*dir)) before use. Changing all of * them seems lots of work for little benefit. */ - if (!dir->basebuf.buf) - strbuf_init(&dir->basebuf, PATH_MAX); + if (!dir->internal.basebuf.buf) + strbuf_init(&dir->internal.basebuf, PATH_MAX); /* Read from the parent directories and push them down. */ current = stk ? stk->baselen : -1; - strbuf_setlen(&dir->basebuf, current < 0 ? 0 : current); + strbuf_setlen(&dir->internal.basebuf, current < 0 ? 0 : current); if (dir->untracked) untracked = stk ? stk->ucd : dir->untracked->root; else @@ -1599,32 +1605,33 @@ static void prep_exclude(struct dir_struct *dir, die("oops in prep_exclude"); cp++; untracked = - lookup_untracked(dir->untracked, untracked, + lookup_untracked(dir->untracked, + untracked, base + current, cp - base - current); } - stk->prev = dir->exclude_stack; + stk->prev = dir->internal.exclude_stack; stk->baselen = cp - base; stk->exclude_ix = group->nr; stk->ucd = untracked; pl = add_pattern_list(dir, EXC_DIRS, NULL); - strbuf_add(&dir->basebuf, base + current, stk->baselen - current); - assert(stk->baselen == dir->basebuf.len); + strbuf_add(&dir->internal.basebuf, base + current, stk->baselen - current); + assert(stk->baselen == dir->internal.basebuf.len); /* Abort if the directory is excluded */ if (stk->baselen) { int dt = DT_DIR; - dir->basebuf.buf[stk->baselen - 1] = 0; - dir->pattern = last_matching_pattern_from_lists(dir, + dir->internal.basebuf.buf[stk->baselen - 1] = 0; + dir->internal.pattern = last_matching_pattern_from_lists(dir, istate, - dir->basebuf.buf, stk->baselen - 1, - dir->basebuf.buf + current, &dt); - dir->basebuf.buf[stk->baselen - 1] = '/'; - if (dir->pattern && - dir->pattern->flags & PATTERN_FLAG_NEGATIVE) - dir->pattern = NULL; - if (dir->pattern) { - dir->exclude_stack = stk; + dir->internal.basebuf.buf, stk->baselen - 1, + dir->internal.basebuf.buf + current, &dt); + dir->internal.basebuf.buf[stk->baselen - 1] = '/'; + if (dir->internal.pattern && + dir->internal.pattern->flags & PATTERN_FLAG_NEGATIVE) + dir->internal.pattern = NULL; + if (dir->internal.pattern) { + dir->internal.exclude_stack = stk; return; } } @@ -1647,15 +1654,15 @@ static void prep_exclude(struct dir_struct *dir, */ !is_null_oid(&untracked->exclude_oid))) { /* - * dir->basebuf gets reused by the traversal, but we - * need fname to remain unchanged to ensure the src - * member of each struct path_pattern correctly + * dir->internal.basebuf gets reused by the traversal, + * but we need fname to remain unchanged to ensure the + * src member of each struct path_pattern correctly * back-references its source file. Other invocations * of add_pattern_list provide stable strings, so we * strbuf_detach() and free() here in the caller. */ struct strbuf sb = STRBUF_INIT; - strbuf_addbuf(&sb, &dir->basebuf); + strbuf_addbuf(&sb, &dir->internal.basebuf); strbuf_addstr(&sb, dir->exclude_per_dir); pl->src = strbuf_detach(&sb, NULL); add_patterns(pl->src, pl->src, stk->baselen, pl, istate, @@ -1681,10 +1688,10 @@ static void prep_exclude(struct dir_struct *dir, invalidate_gitignore(dir->untracked, untracked); oidcpy(&untracked->exclude_oid, &oid_stat.oid); } - dir->exclude_stack = stk; + dir->internal.exclude_stack = stk; current = stk->baselen; } - strbuf_setlen(&dir->basebuf, baselen); + strbuf_setlen(&dir->internal.basebuf, baselen); } /* @@ -1704,8 +1711,8 @@ struct path_pattern *last_matching_pattern(struct dir_struct *dir, prep_exclude(dir, istate, pathname, basename-pathname); - if (dir->pattern) - return dir->pattern; + if (dir->internal.pattern) + return dir->internal.pattern; return last_matching_pattern_from_lists(dir, istate, pathname, pathlen, basename, dtype_p); @@ -1742,7 +1749,7 @@ static struct dir_entry *dir_add_name(struct dir_struct *dir, if (index_file_exists(istate, pathname, len, ignore_case)) return NULL; - ALLOC_GROW(dir->entries, dir->nr+1, dir->alloc); + ALLOC_GROW(dir->entries, dir->nr+1, dir->internal.alloc); return dir->entries[dir->nr++] = dir_entry_new(pathname, len); } @@ -1753,7 +1760,7 @@ struct dir_entry *dir_add_ignored(struct dir_struct *dir, if (!index_name_is_other(istate, pathname, len)) return NULL; - ALLOC_GROW(dir->ignored, dir->ignored_nr+1, dir->ignored_alloc); + ALLOC_GROW(dir->ignored, dir->ignored_nr+1, dir->internal.ignored_alloc); return dir->ignored[dir->ignored_nr++] = dir_entry_new(pathname, len); } @@ -2569,7 +2576,7 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir, if (open_cached_dir(&cdir, dir, untracked, istate, &path, check_only)) goto out; - dir->visited_directories++; + dir->internal.visited_directories++; if (untracked) untracked->check_only = !!check_only; @@ -2578,7 +2585,7 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir, /* check how the file or directory should be treated */ state = treat_path(dir, untracked, &cdir, istate, &path, baselen, pathspec); - dir->visited_paths++; + dir->internal.visited_paths++; if (state > dir_state) dir_state = state; @@ -2586,7 +2593,8 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir, /* recurse into subdir if instructed by treat_path */ if (state == path_recurse) { struct untracked_cache_dir *ud; - ud = lookup_untracked(dir->untracked, untracked, + ud = lookup_untracked(dir->untracked, + untracked, path.buf + baselen, path.len - baselen); subdir_state = @@ -2846,7 +2854,7 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d * condition also catches running setup_standard_excludes() * before setting dir->untracked! */ - if (dir->unmanaged_exclude_files) + if (dir->internal.unmanaged_exclude_files) return NULL; /* @@ -2875,7 +2883,7 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d * EXC_CMDL is not considered in the cache. If people set it, * skip the cache. */ - if (dir->exclude_list_group[EXC_CMDL].nr) + if (dir->internal.exclude_list_group[EXC_CMDL].nr) return NULL; if (!ident_in_untracked(dir->untracked)) { @@ -2935,15 +2943,15 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d /* Validate $GIT_DIR/info/exclude and core.excludesfile */ root = dir->untracked->root; - if (!oideq(&dir->ss_info_exclude.oid, + if (!oideq(&dir->internal.ss_info_exclude.oid, &dir->untracked->ss_info_exclude.oid)) { invalidate_gitignore(dir->untracked, root); - dir->untracked->ss_info_exclude = dir->ss_info_exclude; + dir->untracked->ss_info_exclude = dir->internal.ss_info_exclude; } - if (!oideq(&dir->ss_excludes_file.oid, + if (!oideq(&dir->internal.ss_excludes_file.oid, &dir->untracked->ss_excludes_file.oid)) { invalidate_gitignore(dir->untracked, root); - dir->untracked->ss_excludes_file = dir->ss_excludes_file; + dir->untracked->ss_excludes_file = dir->internal.ss_excludes_file; } /* Make sure this directory is not dropped out at saving phase */ @@ -2969,9 +2977,9 @@ static void emit_traversal_statistics(struct dir_struct *dir, } trace2_data_intmax("read_directory", repo, - "directories-visited", dir->visited_directories); + "directories-visited", dir->internal.visited_directories); trace2_data_intmax("read_directory", repo, - "paths-visited", dir->visited_paths); + "paths-visited", dir->internal.visited_paths); if (!dir->untracked) return; @@ -2993,8 +3001,8 @@ int read_directory(struct dir_struct *dir, struct index_state *istate, struct untracked_cache_dir *untracked; trace2_region_enter("dir", "read_directory", istate->repo); - dir->visited_paths = 0; - dir->visited_directories = 0; + dir->internal.visited_paths = 0; + dir->internal.visited_directories = 0; if (has_symlink_leading_path(path, len)) { trace2_region_leave("dir", "read_directory", istate->repo); @@ -3342,14 +3350,14 @@ void setup_standard_excludes(struct dir_struct *dir) excludes_file = xdg_config_home("ignore"); if (excludes_file && !access_or_warn(excludes_file, R_OK, 0)) add_patterns_from_file_1(dir, excludes_file, - dir->untracked ? &dir->ss_excludes_file : NULL); + dir->untracked ? &dir->internal.ss_excludes_file : NULL); /* per repository user preference */ if (startup_info->have_repository) { const char *path = git_path_info_exclude(); if (!access_or_warn(path, R_OK, 0)) add_patterns_from_file_1(dir, path, - dir->untracked ? &dir->ss_info_exclude : NULL); + dir->untracked ? &dir->internal.ss_info_exclude : NULL); } } @@ -3405,7 +3413,7 @@ void dir_clear(struct dir_struct *dir) struct dir_struct new = DIR_INIT; for (i = EXC_CMDL; i <= EXC_FILE; i++) { - group = &dir->exclude_list_group[i]; + group = &dir->internal.exclude_list_group[i]; for (j = 0; j < group->nr; j++) { pl = &group->pl[j]; if (i == EXC_DIRS) @@ -3422,13 +3430,13 @@ void dir_clear(struct dir_struct *dir) free(dir->ignored); free(dir->entries); - stk = dir->exclude_stack; + stk = dir->internal.exclude_stack; while (stk) { struct exclude_stack *prev = stk->prev; free(stk); stk = prev; } - strbuf_release(&dir->basebuf); + strbuf_release(&dir->internal.basebuf); memcpy(dir, &new, sizeof(*dir)); } @@ -1,8 +1,9 @@ #ifndef DIR_H #define DIR_H -#include "cache.h" #include "hashmap.h" +#include "pathspec.h" +#include "statinfo.h" #include "strbuf.h" /** @@ -212,17 +213,6 @@ struct untracked_cache { */ struct dir_struct { - /* The number of members in `entries[]` array. */ - int nr; - - /* Internal use; keeps track of allocation of `entries[]` array.*/ - int alloc; - - /* The number of members in `ignored[]` array. */ - int ignored_nr; - - int ignored_alloc; - /* bit-field of options */ enum { @@ -287,60 +277,81 @@ struct dir_struct { DIR_SKIP_NESTED_GIT = 1<<9 } flags; + /* The number of members in `entries[]` array. */ + int nr; /* output only */ + + /* The number of members in `ignored[]` array. */ + int ignored_nr; /* output only */ + /* An array of `struct dir_entry`, each element of which describes a path. */ - struct dir_entry **entries; + struct dir_entry **entries; /* output only */ /** * used for ignored paths with the `DIR_SHOW_IGNORED_TOO` and * `DIR_COLLECT_IGNORED` flags. */ - struct dir_entry **ignored; + struct dir_entry **ignored; /* output only */ + + /* Enable/update untracked file cache if set */ + struct untracked_cache *untracked; /** - * The name of the file to be read in each directory for excluded files - * (typically `.gitignore`). + * Deprecated: ls-files is the only allowed caller; all other callers + * should leave this as NULL; it pre-dated the + * setup_standard_excludes() mechanism that replaces this. + * + * This field tracks the name of the file to be read in each directory + * for excluded files (typically `.gitignore`). */ const char *exclude_per_dir; - /* - * We maintain three groups of exclude pattern lists: - * - * EXC_CMDL lists patterns explicitly given on the command line. - * EXC_DIRS lists patterns obtained from per-directory ignore files. - * EXC_FILE lists patterns from fallback ignore files, e.g. - * - .git/info/exclude - * - core.excludesfile - * - * Each group contains multiple exclude lists, a single list - * per source. - */ + struct dir_struct_internal { + /* Keeps track of allocation of `entries[]` array.*/ + int alloc; + + /* Keeps track of allocation of `ignored[]` array. */ + int ignored_alloc; + + /* + * We maintain three groups of exclude pattern lists: + * + * EXC_CMDL lists patterns explicitly given on the command line. + * EXC_DIRS lists patterns obtained from per-directory ignore + * files. + * EXC_FILE lists patterns from fallback ignore files, e.g. + * - .git/info/exclude + * - core.excludesfile + * + * Each group contains multiple exclude lists, a single list + * per source. + */ #define EXC_CMDL 0 #define EXC_DIRS 1 #define EXC_FILE 2 - struct exclude_list_group exclude_list_group[3]; - - /* - * Temporary variables which are used during loading of the - * per-directory exclude lists. - * - * exclude_stack points to the top of the exclude_stack, and - * basebuf contains the full path to the current - * (sub)directory in the traversal. Exclude points to the - * matching exclude struct if the directory is excluded. - */ - struct exclude_stack *exclude_stack; - struct path_pattern *pattern; - struct strbuf basebuf; + struct exclude_list_group exclude_list_group[3]; - /* Enable untracked file cache if set */ - struct untracked_cache *untracked; - struct oid_stat ss_info_exclude; - struct oid_stat ss_excludes_file; - unsigned unmanaged_exclude_files; - - /* Stats about the traversal */ - unsigned visited_paths; - unsigned visited_directories; + /* + * Temporary variables which are used during loading of the + * per-directory exclude lists. + * + * exclude_stack points to the top of the exclude_stack, and + * basebuf contains the full path to the current + * (sub)directory in the traversal. Exclude points to the + * matching exclude struct if the directory is excluded. + */ + struct exclude_stack *exclude_stack; + struct path_pattern *pattern; + struct strbuf basebuf; + + /* Additional metadata related to 'untracked' */ + struct oid_stat ss_info_exclude; + struct oid_stat ss_excludes_file; + unsigned unmanaged_exclude_files; + + /* Stats about the traversal */ + unsigned visited_paths; + unsigned visited_directories; + } internal; }; #define DIR_INIT { 0 } @@ -363,10 +374,6 @@ int count_slashes(const char *s); int simple_length(const char *match); int no_wildcard(const char *string); char *common_prefix(const struct pathspec *pathspec); -int match_pathspec(struct index_state *istate, - const struct pathspec *pathspec, - const char *name, int namelen, - int prefix, char *seen, int is_dir); int report_path_error(const char *ps_matched, const struct pathspec *pathspec); int within_depth(const char *name, int namelen, int depth, int max_depth); @@ -533,15 +540,6 @@ int submodule_path_match(struct index_state *istate, const char *submodule_name, char *seen); -static inline int ce_path_match(struct index_state *istate, - const struct cache_entry *ce, - const struct pathspec *pathspec, - char *seen) -{ - return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen, - S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode)); -} - static inline int dir_path_match(struct index_state *istate, const struct dir_entry *ent, const struct pathspec *pathspec, @@ -1,5 +1,8 @@ #include "cache.h" +#include "abspath.h" #include "config.h" +#include "environment.h" +#include "gettext.h" #include "strbuf.h" #include "strvec.h" #include "run-command.h" @@ -2,12 +2,16 @@ #include "blob.h" #include "object-store.h" #include "dir.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "streaming.h" #include "submodule.h" #include "progress.h" #include "fsmonitor.h" #include "entry.h" #include "parallel-checkout.h" +#include "wrapper.h" static void create_directories(const char *path, int path_len, const struct checkout *state) @@ -1,9 +1,11 @@ #ifndef ENTRY_H #define ENTRY_H -#include "cache.h" #include "convert.h" +struct cache_entry; +struct index_state; + struct checkout { struct index_state *istate; const char *base_dir; diff --git a/environment.c b/environment.c index 1ee3686fd8..63c697e7e9 100644 --- a/environment.c +++ b/environment.c @@ -8,8 +8,10 @@ * are. */ #include "cache.h" +#include "abspath.h" #include "branch.h" #include "environment.h" +#include "gettext.h" #include "repository.h" #include "config.h" #include "refs.h" @@ -17,9 +19,13 @@ #include "commit.h" #include "strvec.h" #include "object-store.h" +#include "replace-object.h" #include "tmp-objdir.h" #include "chdir-notify.h" +#include "setup.h" #include "shallow.h" +#include "wrapper.h" +#include "write-or-die.h" int trust_executable_bit = 1; int trust_ctime = 1; diff --git a/environment.h b/environment.h index d438b5c8f3..a63f0c6a24 100644 --- a/environment.h +++ b/environment.h @@ -3,10 +3,230 @@ #include "strvec.h" +struct repository; + +/* + * The character that begins a commented line in user-editable file + * that is subject to stripspace. + */ +extern char comment_line_char; +extern int auto_comment_line_char; + /* * Wrapper of getenv() that returns a strdup value. This value is kept * in argv to be freed later. */ const char *getenv_safe(struct strvec *argv, const char *name); +/* Double-check local_repo_env below if you add to this list. */ +#define GIT_DIR_ENVIRONMENT "GIT_DIR" +#define GIT_COMMON_DIR_ENVIRONMENT "GIT_COMMON_DIR" +#define GIT_NAMESPACE_ENVIRONMENT "GIT_NAMESPACE" +#define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE" +#define GIT_PREFIX_ENVIRONMENT "GIT_PREFIX" +#define DEFAULT_GIT_DIR_ENVIRONMENT ".git" +#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY" +#define INDEX_ENVIRONMENT "GIT_INDEX_FILE" +#define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE" +#define GIT_SHALLOW_FILE_ENVIRONMENT "GIT_SHALLOW_FILE" +#define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR" +#define CONFIG_ENVIRONMENT "GIT_CONFIG" +#define CONFIG_DATA_ENVIRONMENT "GIT_CONFIG_PARAMETERS" +#define CONFIG_COUNT_ENVIRONMENT "GIT_CONFIG_COUNT" +#define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH" +#define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES" +#define NO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS" +#define GIT_REPLACE_REF_BASE_ENVIRONMENT "GIT_REPLACE_REF_BASE" +#define GITATTRIBUTES_FILE ".gitattributes" +#define INFOATTRIBUTES_FILE "info/attributes" +#define ATTRIBUTE_MACRO_PREFIX "[attr]" +#define GITMODULES_FILE ".gitmodules" +#define GITMODULES_INDEX ":.gitmodules" +#define GITMODULES_HEAD "HEAD:.gitmodules" +#define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF" +#define GIT_NOTES_DEFAULT_REF "refs/notes/commits" +#define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF" +#define GIT_NOTES_REWRITE_REF_ENVIRONMENT "GIT_NOTES_REWRITE_REF" +#define GIT_NOTES_REWRITE_MODE_ENVIRONMENT "GIT_NOTES_REWRITE_MODE" +#define GIT_LITERAL_PATHSPECS_ENVIRONMENT "GIT_LITERAL_PATHSPECS" +#define GIT_GLOB_PATHSPECS_ENVIRONMENT "GIT_GLOB_PATHSPECS" +#define GIT_NOGLOB_PATHSPECS_ENVIRONMENT "GIT_NOGLOB_PATHSPECS" +#define GIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS" +#define GIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH" +#define GIT_OPTIONAL_LOCKS_ENVIRONMENT "GIT_OPTIONAL_LOCKS" +#define GIT_TEXT_DOMAIN_DIR_ENVIRONMENT "GIT_TEXTDOMAINDIR" + +/* + * Environment variable used in handshaking the wire protocol. + * Contains a colon ':' separated list of keys with optional values + * 'key[=value]'. Presence of unknown keys and values must be + * ignored. + */ +#define GIT_PROTOCOL_ENVIRONMENT "GIT_PROTOCOL" +/* HTTP header used to handshake the wire protocol */ +#define GIT_PROTOCOL_HEADER "Git-Protocol" + +/* + * This environment variable is expected to contain a boolean indicating + * whether we should or should not treat: + * + * GIT_DIR=foo.git git ... + * + * as if GIT_WORK_TREE=. was given. It's not expected that users will make use + * of this, but we use it internally to communicate to sub-processes that we + * are in a bare repo. If not set, defaults to true. + */ +#define GIT_IMPLICIT_WORK_TREE_ENVIRONMENT "GIT_IMPLICIT_WORK_TREE" + +/* + * Repository-local GIT_* environment variables; these will be cleared + * when git spawns a sub-process that runs inside another repository. + * The array is NULL-terminated, which makes it easy to pass in the "env" + * parameter of a run-command invocation, or to do a simple walk. + */ +extern const char * const local_repo_env[]; + +void setup_git_env(const char *git_dir); + +/* + * Returns true iff we have a configured git repository (either via + * setup_git_directory, or in the environment via $GIT_DIR). + */ +int have_git_dir(void); + +extern int is_bare_repository_cfg; +int is_bare_repository(void); +extern char *git_work_tree_cfg; +const char *get_git_dir(void); +const char *get_git_common_dir(void); +const char *get_object_directory(void); +char *get_index_file(void); +char *get_graft_file(struct repository *r); +void set_git_dir(const char *path, int make_realpath); +const char *get_git_namespace(void); +const char *strip_namespace(const char *namespaced_ref); +const char *get_git_work_tree(void); +void set_git_work_tree(const char *tree); + +#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" + +/* Environment bits from configuration mechanism */ +extern int trust_executable_bit; +extern int trust_ctime; +extern int check_stat; +extern int has_symlinks; +extern int minimum_abbrev, default_abbrev; +extern int ignore_case; +extern int assume_unchanged; +extern int prefer_symlink_refs; +extern int warn_ambiguous_refs; +extern int warn_on_object_refname_ambiguity; +extern char *apply_default_whitespace; +extern char *apply_default_ignorewhitespace; +extern const char *git_attributes_file; +extern const char *git_hooks_path; +extern int zlib_compression_level; +extern int pack_compression_level; +extern size_t packed_git_window_size; +extern size_t packed_git_limit; +extern size_t delta_base_cache_limit; +extern unsigned long big_file_threshold; +extern unsigned long pack_size_limit_cfg; + +/* + * Accessors for the core.sharedrepository config which lazy-load the value + * from the config (if not already set). The "reset" function can be + * used to unset "set" or cached value, meaning that the value will be loaded + * fresh from the config file on the next call to get_shared_repository(). + */ +void set_shared_repository(int value); +int get_shared_repository(void); +void reset_shared_repository(void); + +extern int core_preload_index; +extern int precomposed_unicode; +extern int protect_hfs; +extern int protect_ntfs; + +extern int core_apply_sparse_checkout; +extern int core_sparse_checkout_cone; +extern int sparse_expect_files_outside_of_patterns; + +/* + * Returns the boolean value of $GIT_OPTIONAL_LOCKS (or the default value). + */ +int use_optional_locks(void); + +enum log_refs_config { + LOG_REFS_UNSET = -1, + LOG_REFS_NONE = 0, + LOG_REFS_NORMAL, + LOG_REFS_ALWAYS +}; +extern enum log_refs_config log_all_ref_updates; + +enum rebase_setup_type { + AUTOREBASE_NEVER = 0, + AUTOREBASE_LOCAL, + AUTOREBASE_REMOTE, + AUTOREBASE_ALWAYS +}; + +enum push_default_type { + PUSH_DEFAULT_NOTHING = 0, + PUSH_DEFAULT_MATCHING, + PUSH_DEFAULT_SIMPLE, + PUSH_DEFAULT_UPSTREAM, + PUSH_DEFAULT_CURRENT, + PUSH_DEFAULT_UNSPECIFIED +}; + +extern enum rebase_setup_type autorebase; +extern enum push_default_type push_default; + +enum object_creation_mode { + OBJECT_CREATION_USES_HARDLINKS = 0, + OBJECT_CREATION_USES_RENAMES = 1 +}; + +extern enum object_creation_mode object_creation_mode; + +extern char *notes_ref_name; + +extern int grafts_replace_parents; + +extern int repository_format_precious_objects; +extern int repository_format_worktree_config; + +/* + * Create a temporary file rooted in the object database directory, or + * die on failure. The filename is taken from "pattern", which should have the + * usual "XXXXXX" trailer, and the resulting filename is written into the + * "template" buffer. Returns the open descriptor. + */ +int odb_mkstemp(struct strbuf *temp_filename, const char *pattern); + +/* + * Create a pack .keep file named "name" (which should generally be the output + * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on + * error. + */ +int odb_pack_keep(const char *name); + +const char *get_log_output_encoding(void); +const char *get_commit_output_encoding(void); + +extern const char *git_commit_encoding; +extern const char *git_log_output_encoding; + +extern const char *editor_program; +extern const char *askpass_program; +extern const char *excludes_file; + +/* + * Should we print an ellipsis after an abbreviated SHA-1 value + * when doing diff-raw output or indicating a detached HEAD? + */ +int print_sha1_ellipsis(void); + #endif diff --git a/ewah/bitmap.c b/ewah/bitmap.c index ac61864163..12d6aa398e 100644 --- a/ewah/bitmap.c +++ b/ewah/bitmap.c @@ -16,7 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, see <http://www.gnu.org/licenses/>. */ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "ewok.h" #define EWAH_MASK(x) ((eword_t)1 << (x % BITS_IN_EWORD)) diff --git a/ewah/ewah_bitmap.c b/ewah/ewah_bitmap.c index 6fe48d3ae0..c6d4ffc87c 100644 --- a/ewah/ewah_bitmap.c +++ b/ewah/ewah_bitmap.c @@ -17,9 +17,9 @@ * along with this program; if not, see <http://www.gnu.org/licenses/>. */ #include "git-compat-util.h" +#include "alloc.h" #include "ewok.h" #include "ewok_rlw.h" -#include "cache.h" static inline size_t min_size(size_t a, size_t b) { diff --git a/exec-cmd.c b/exec-cmd.c index 0232bbc990..fae0d4b244 100644 --- a/exec-cmd.c +++ b/exec-cmd.c @@ -1,5 +1,8 @@ #include "cache.h" +#include "abspath.h" +#include "environment.h" #include "exec-cmd.h" +#include "gettext.h" #include "quote.h" #include "strvec.h" diff --git a/fetch-pack.c b/fetch-pack.c index 8c497b4821..368f2ed25a 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -1,6 +1,10 @@ #include "cache.h" +#include "alloc.h" #include "repository.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "lockfile.h" #include "refs.h" #include "pkt-line.h" @@ -27,6 +31,7 @@ #include "commit-graph.h" #include "sigchain.h" #include "mergesort.h" +#include "wrapper.h" static int transfer_unpack_limit = -1; static int fetch_unpack_limit = -1; @@ -722,7 +727,7 @@ static void filter_refs(struct fetch_pack_args *args, *refs = newlist; } -static void mark_alternate_complete(struct fetch_negotiator *unused, +static void mark_alternate_complete(struct fetch_negotiator *negotiator UNUSED, struct object *obj) { mark_complete(&obj->oid); diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c index 6252934440..1886c92ddb 100644 --- a/fmt-merge-msg.c +++ b/fmt-merge-msg.c @@ -1,8 +1,12 @@ +#include "cache.h" +#include "alloc.h" #include "config.h" +#include "environment.h" #include "refs.h" #include "object-store.h" #include "diff.h" #include "diff-merges.h" +#include "hex.h" #include "revision.h" #include "tag.h" #include "string-list.h" @@ -17,8 +21,6 @@ static struct string_list suppress_dest_patterns = STRING_LIST_INIT_DUP; int fmt_merge_msg_config(const char *key, const char *value, void *cb) { - int status = 0; - if (!strcmp(key, "merge.log") || !strcmp(key, "merge.summary")) { int is_bool; merge_log_config = git_config_bool_or_int(key, value, &is_bool); @@ -37,9 +39,6 @@ int fmt_merge_msg_config(const char *key, const char *value, void *cb) string_list_append(&suppress_dest_patterns, value); suppress_dest_pattern_seen = 1; } else { - status = git_gpg_config(key, value, NULL); - if (status) - return status; return git_default_config(key, value, cb); } return 0; @@ -1,4 +1,6 @@ #include "cache.h" +#include "alloc.h" +#include "hex.h" #include "object-store.h" #include "repository.h" #include "object.h" @@ -1,6 +1,7 @@ #ifndef GIT_FSCK_H #define GIT_FSCK_H +#include "object.h" #include "oidset.h" enum fsck_msg_type { diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c index 19d772f0f3..866828e299 100644 --- a/fsmonitor-ipc.c +++ b/fsmonitor-ipc.c @@ -1,5 +1,6 @@ #include "cache.h" #include "fsmonitor.h" +#include "gettext.h" #include "simple-ipc.h" #include "fsmonitor-ipc.h" #include "run-command.h" diff --git a/fsmonitor-settings.c b/fsmonitor-settings.c index 899bfe9c81..b62acf44ae 100644 --- a/fsmonitor-settings.c +++ b/fsmonitor-settings.c @@ -1,5 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" +#include "gettext.h" #include "repository.h" #include "fsmonitor-ipc.h" #include "fsmonitor-settings.h" diff --git a/fsmonitor.c b/fsmonitor.c index a5b9e75437..c956a347a2 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -1,6 +1,7 @@ #include "cache.h" #include "config.h" #include "dir.h" +#include "environment.h" #include "ewah/ewok.h" #include "fsmonitor.h" #include "fsmonitor-ipc.h" @@ -2,7 +2,9 @@ * Copyright (c) 2010 Ævar Arnfjörð Bjarmason */ -#include "cache.h" +#include "git-compat-util.h" +#include "abspath.h" +#include "environment.h" #include "exec-cmd.h" #include "gettext.h" #include "strbuf.h" diff --git a/git-compat-util.h b/git-compat-util.h index 4f0028ce60..1e6592624d 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -1225,6 +1225,7 @@ extern const unsigned char tolower_trans_tbl[256]; #undef isxdigit extern const unsigned char sane_ctype[256]; +extern const signed char hexval_table[256]; #define GIT_SPACE 0x01 #define GIT_DIGIT 0x02 #define GIT_ALPHA 0x04 @@ -1287,6 +1288,25 @@ static inline int skip_iprefix(const char *str, const char *prefix, return 0; } +/* + * Like skip_prefix_mem, but compare case-insensitively. Note that the + * comparison is done via tolower(), so it is strictly ASCII (no multi-byte + * characters or locale-specific conversions). + */ +static inline int skip_iprefix_mem(const char *buf, size_t len, + const char *prefix, + const char **out, size_t *outlen) +{ + do { + if (!*prefix) { + *out = buf; + *outlen = len; + return 1; + } + } while (len-- > 0 && tolower(*buf++) == tolower(*prefix++)); + return 0; +} + static inline int strtoul_ui(char const *s, int base, unsigned int *result) { unsigned long ul; @@ -1,9 +1,13 @@ #include "builtin.h" #include "config.h" +#include "environment.h" #include "exec-cmd.h" +#include "gettext.h" #include "help.h" #include "run-command.h" #include "alias.h" +#include "replace-object.h" +#include "setup.h" #include "shallow.h" #define RUN_SETUP (1<<0) diff --git a/gpg-interface.c b/gpg-interface.c index 5cd66d3a78..aceeb08336 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -1,13 +1,28 @@ -#include "cache.h" +#include "git-compat-util.h" #include "commit.h" #include "config.h" +#include "gettext.h" #include "run-command.h" #include "strbuf.h" #include "dir.h" +#include "ident.h" #include "gpg-interface.h" #include "sigchain.h" #include "tempfile.h" #include "alias.h" +#include "wrapper.h" + +static int git_gpg_config(const char *, const char *, void *); + +static void gpg_interface_lazy_init(void) +{ + static int done; + + if (done) + return; + done = 1; + git_config(git_gpg_config, NULL); +} static char *configured_signing_key; static const char *ssh_default_key_command, *ssh_allowed_signers, *ssh_revocation_file; @@ -632,6 +647,8 @@ int check_signature(struct signature_check *sigc, struct gpg_format *fmt; int status; + gpg_interface_lazy_init(); + sigc->result = 'N'; sigc->trust_level = -1; @@ -695,11 +712,13 @@ int parse_signature(const char *buf, size_t size, struct strbuf *payload, struct void set_signing_key(const char *key) { + gpg_interface_lazy_init(); + free(configured_signing_key); configured_signing_key = xstrdup(key); } -int git_gpg_config(const char *var, const char *value, void *cb UNUSED) +static int git_gpg_config(const char *var, const char *value, void *cb UNUSED) { struct gpg_format *fmt = NULL; char *fmtname = NULL; @@ -888,6 +907,8 @@ static const char *get_ssh_key_id(void) { /* Returns a textual but unique representation of the signing key */ const char *get_signing_key_id(void) { + gpg_interface_lazy_init(); + if (use_format->get_key_id) { return use_format->get_key_id(); } @@ -898,6 +919,8 @@ const char *get_signing_key_id(void) const char *get_signing_key(void) { + gpg_interface_lazy_init(); + if (configured_signing_key) return configured_signing_key; if (use_format->get_default_key) { @@ -923,6 +946,8 @@ const char *gpg_trust_level_to_str(enum signature_trust_level level) int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key) { + gpg_interface_lazy_init(); + return use_format->sign_buffer(buffer, signature, signing_key); } @@ -1025,7 +1050,7 @@ static int sign_buffer_ssh(struct strbuf *buffer, struct strbuf *signature, ssh_signing_key_file = strbuf_detach(&key_file->filename, NULL); } else { /* We assume a file */ - ssh_signing_key_file = expand_user_path(signing_key, 1); + ssh_signing_key_file = interpolate_path(signing_key, 1); } buffer_file = mks_tempfile_t(".git_signing_buffer_tmpXXXXXX"); diff --git a/gpg-interface.h b/gpg-interface.h index 8a9ef41779..143cdc1c02 100644 --- a/gpg-interface.h +++ b/gpg-interface.h @@ -79,7 +79,6 @@ int sign_buffer(struct strbuf *buffer, struct strbuf *signature, */ const char *gpg_trust_level_to_str(enum signature_trust_level level); -int git_gpg_config(const char *, const char *, void *); void set_signing_key(const char *); const char *get_signing_key(void); @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "gettext.h" #include "config.h" #include "commit.h" #include "color.h" @@ -1,6 +1,8 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" +#include "gettext.h" #include "grep.h" +#include "hex.h" #include "object-store.h" #include "userdiff.h" #include "xdiff-interface.h" @@ -1,7 +1,6 @@ #ifndef HASH_H #define HASH_H -#include "git-compat-util.h" #include "repository.h" #if defined(SHA1_APPLE) @@ -124,6 +123,40 @@ struct object_id { int algo; /* XXX requires 4-byte alignment */ }; +#define GET_OID_QUIETLY 01 +#define GET_OID_COMMIT 02 +#define GET_OID_COMMITTISH 04 +#define GET_OID_TREE 010 +#define GET_OID_TREEISH 020 +#define GET_OID_BLOB 040 +#define GET_OID_FOLLOW_SYMLINKS 0100 +#define GET_OID_RECORD_PATH 0200 +#define GET_OID_ONLY_TO_DIE 04000 +#define GET_OID_REQUIRE_PATH 010000 + +#define GET_OID_DISAMBIGUATORS \ + (GET_OID_COMMIT | GET_OID_COMMITTISH | \ + GET_OID_TREE | GET_OID_TREEISH | \ + GET_OID_BLOB) + +enum get_oid_result { + FOUND = 0, + MISSING_OBJECT = -1, /* The requested object is missing */ + SHORT_NAME_AMBIGUOUS = -2, + /* The following only apply when symlinks are followed */ + DANGLING_SYMLINK = -4, /* + * The initial symlink is there, but + * (transitively) points to a missing + * in-tree file + */ + SYMLINK_LOOP = -5, + NOT_DIR = -6, /* + * Somewhere along the symlink chain, a path is + * requested which contains a file as a + * non-final element. + */ +}; + /* A suitably aligned type for stack allocations of hash contexts. */ union git_hash_ctx { git_SHA_CTX sha1; @@ -1,7 +1,7 @@ /* * Generic implementation of hash-based key value mappings. */ -#include "cache.h" +#include "git-compat-util.h" #include "hashmap.h" #define FNV32_BASE ((unsigned int) 0x811c9dc5) @@ -1,9 +1,11 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "builtin.h" #include "exec-cmd.h" #include "run-command.h" #include "levenshtein.h" +#include "gettext.h" #include "help.h" #include "command-list.h" #include "string-list.h" @@ -540,7 +542,8 @@ static struct cmdnames aliases; #define AUTOCORRECT_NEVER (-2) #define AUTOCORRECT_IMMEDIATELY (-1) -static int git_unknown_cmd_config(const char *var, const char *value, void *cb) +static int git_unknown_cmd_config(const char *var, const char *value, + void *cb UNUSED) { const char *p; @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "hex.h" const signed char hexval_table[256] = { -1, -1, -1, -1, -1, -1, -1, -1, /* 00-07 */ @@ -0,0 +1,84 @@ +#ifndef HEX_H +#define HEX_H + +#include "hash.h" + +extern const signed char hexval_table[256]; +static inline unsigned int hexval(unsigned char c) +{ + return hexval_table[c]; +} + +/* + * Convert two consecutive hexadecimal digits into a char. Return a + * negative value on error. Don't run over the end of short strings. + */ +static inline int hex2chr(const char *s) +{ + unsigned int val = hexval(s[0]); + return (val & ~0xf) ? val : (val << 4) | hexval(s[1]); +} + +/* + * Try to read a SHA1 in hexadecimal format from the 40 characters + * starting at hex. Write the 20-byte result to sha1 in binary form. + * Return 0 on success. Reading stops if a NUL is encountered in the + * input, so it is safe to pass this function an arbitrary + * null-terminated string. + */ +int get_sha1_hex(const char *hex, unsigned char *sha1); +int get_oid_hex(const char *hex, struct object_id *sha1); + +/* Like get_oid_hex, but for an arbitrary hash algorithm. */ +int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_hash_algo *algop); + +/* + * Read `len` pairs of hexadecimal digits from `hex` and write the + * values to `binary` as `len` bytes. Return 0 on success, or -1 if + * the input does not consist of hex digits). + */ +int hex_to_bytes(unsigned char *binary, const char *hex, size_t len); + +/* + * Convert a binary hash in "unsigned char []" or an object name in + * "struct object_id *" to its hex equivalent. The `_r` variant is reentrant, + * and writes the NUL-terminated output to the buffer `out`, which must be at + * least `GIT_MAX_HEXSZ + 1` bytes, and returns a pointer to out for + * convenience. + * + * The non-`_r` variant returns a static buffer, but uses a ring of 4 + * buffers, making it safe to make multiple calls for a single statement, like: + * + * printf("%s -> %s", hash_to_hex(one), hash_to_hex(two)); + * printf("%s -> %s", oid_to_hex(one), oid_to_hex(two)); + */ +char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash, const struct git_hash_algo *); +char *oid_to_hex_r(char *out, const struct object_id *oid); +char *hash_to_hex_algop(const unsigned char *hash, const struct git_hash_algo *); /* static buffer result! */ +char *hash_to_hex(const unsigned char *hash); /* same static buffer */ +char *oid_to_hex(const struct object_id *oid); /* same static buffer */ + +/* + * Parse a 40-character hexadecimal object ID starting from hex, updating the + * pointer specified by end when parsing stops. The resulting object ID is + * stored in oid. Returns 0 on success. Parsing will stop on the first NUL or + * other invalid character. end is only updated on success; otherwise, it is + * unmodified. + */ +int parse_oid_hex(const char *hex, struct object_id *oid, const char **end); + +/* Like parse_oid_hex, but for an arbitrary hash algorithm. */ +int parse_oid_hex_algop(const char *hex, struct object_id *oid, const char **end, + const struct git_hash_algo *algo); + + +/* + * These functions work like get_oid_hex and parse_oid_hex, but they will parse + * a hex value for any algorithm. The algorithm is detected based on the length + * and the algorithm in use is returned. If this is not a hex object ID in any + * algorithm, returns GIT_HASH_UNKNOWN. + */ +int get_oid_hex_any(const char *hex, struct object_id *oid); +int parse_oid_hex_any(const char *hex, struct object_id *oid, const char **end); + +#endif @@ -1,7 +1,10 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "advice.h" +#include "gettext.h" #include "hook.h" #include "run-command.h" #include "config.h" +#include "strbuf.h" const char *find_hook(const char *name) { @@ -43,9 +46,9 @@ int hook_exists(const char *name) } static int pick_next_hook(struct child_process *cp, - struct strbuf *out, + struct strbuf *out UNUSED, void *pp_cb, - void **pp_task_cb) + void **pp_task_cb UNUSED) { struct hook_cb_data *hook_cb = pp_cb; const char *hook_path = hook_cb->hook_path; @@ -77,9 +80,9 @@ static int pick_next_hook(struct child_process *cp, return 1; } -static int notify_start_failure(struct strbuf *out, +static int notify_start_failure(struct strbuf *out UNUSED, void *pp_cb, - void *pp_task_cp) + void *pp_task_cp UNUSED) { struct hook_cb_data *hook_cb = pp_cb; @@ -89,9 +92,9 @@ static int notify_start_failure(struct strbuf *out, } static int notify_hook_finished(int result, - struct strbuf *out, + struct strbuf *out UNUSED, void *pp_cb, - void *pp_task_cb) + void *pp_task_cb UNUSED) { struct hook_cb_data *hook_cb = pp_cb; struct run_hooks_opt *opt = hook_cb->options; diff --git a/http-backend.c b/http-backend.c index 8ab58e55f8..89aad1b42c 100644 --- a/http-backend.c +++ b/http-backend.c @@ -1,5 +1,8 @@ #include "cache.h" +#include "alloc.h" #include "config.h" +#include "environment.h" +#include "hex.h" #include "repository.h" #include "refs.h" #include "pkt-line.h" @@ -14,6 +17,8 @@ #include "object-store.h" #include "protocol.h" #include "date.h" +#include "wrapper.h" +#include "write-or-die.h" static const char content_type[] = "Content-Type"; static const char content_length[] = "Content-Length"; @@ -524,7 +529,7 @@ static int show_text_ref(const char *name, const struct object_id *oid, return 0; } -static void get_info_refs(struct strbuf *hdr, char *arg) +static void get_info_refs(struct strbuf *hdr, char *arg UNUSED) { const char *service_name = get_parameter("service"); struct strbuf buf = STRBUF_INIT; @@ -578,7 +583,7 @@ static int show_head_ref(const char *refname, const struct object_id *oid, return 0; } -static void get_head(struct strbuf *hdr, char *arg) +static void get_head(struct strbuf *hdr, char *arg UNUSED) { struct strbuf buf = STRBUF_INIT; @@ -588,7 +593,7 @@ static void get_head(struct strbuf *hdr, char *arg) strbuf_release(&buf); } -static void get_info_packs(struct strbuf *hdr, char *arg) +static void get_info_packs(struct strbuf *hdr, char *arg UNUSED) { size_t objdirlen = strlen(get_object_directory()); struct strbuf buf = STRBUF_INIT; @@ -736,7 +741,7 @@ static int bad_request(struct strbuf *hdr, const struct service_cmd *c) return 0; } -int cmd_main(int argc, const char **argv) +int cmd_main(int argc UNUSED, const char **argv UNUSED) { char *method = getenv("REQUEST_METHOD"); const char *proto_header; diff --git a/http-fetch.c b/http-fetch.c index 258fec2068..c874d3402d 100644 --- a/http-fetch.c +++ b/http-fetch.c @@ -1,8 +1,11 @@ #include "cache.h" #include "config.h" #include "exec-cmd.h" +#include "gettext.h" +#include "hex.h" #include "http.h" #include "walker.h" +#include "setup.h" #include "strvec.h" #include "urlmatch.h" #include "trace2.h" diff --git a/http-push.c b/http-push.c index 6776f3f275..a8af6c0f69 100644 --- a/http-push.c +++ b/http-push.c @@ -1,4 +1,6 @@ #include "cache.h" +#include "environment.h" +#include "hex.h" #include "repository.h" #include "commit.h" #include "tag.h" @@ -10,6 +12,7 @@ #include "exec-cmd.h" #include "remote.h" #include "list-objects.h" +#include "setup.h" #include "sigchain.h" #include "strvec.h" #include "packfile.h" diff --git a/http-walker.c b/http-walker.c index da1b6b6421..4588e6a340 100644 --- a/http-walker.c +++ b/http-walker.c @@ -1,6 +1,7 @@ #include "cache.h" #include "repository.h" #include "commit.h" +#include "hex.h" #include "walker.h" #include "http.h" #include "list.h" @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "git-curl-compat.h" +#include "hex.h" #include "http.h" #include "config.h" #include "pack.h" @@ -181,6 +182,115 @@ size_t fwrite_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_) return nmemb; } +/* + * A folded header continuation line starts with any number of spaces or + * horizontal tab characters (SP or HTAB) as per RFC 7230 section 3.2. + * It is not a continuation line if the line starts with any other character. + */ +static inline int is_hdr_continuation(const char *ptr, const size_t size) +{ + return size && (*ptr == ' ' || *ptr == '\t'); +} + +static size_t fwrite_wwwauth(char *ptr, size_t eltsize, size_t nmemb, void *p) +{ + size_t size = eltsize * nmemb; + struct strvec *values = &http_auth.wwwauth_headers; + struct strbuf buf = STRBUF_INIT; + const char *val; + size_t val_len; + + /* + * Header lines may not come NULL-terminated from libcurl so we must + * limit all scans to the maximum length of the header line, or leverage + * strbufs for all operations. + * + * In addition, it is possible that header values can be split over + * multiple lines as per RFC 7230. 'Line folding' has been deprecated + * but older servers may still emit them. A continuation header field + * value is identified as starting with a space or horizontal tab. + * + * The formal definition of a header field as given in RFC 7230 is: + * + * header-field = field-name ":" OWS field-value OWS + * + * field-name = token + * field-value = *( field-content / obs-fold ) + * field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ] + * field-vchar = VCHAR / obs-text + * + * obs-fold = CRLF 1*( SP / HTAB ) + * ; obsolete line folding + * ; see Section 3.2.4 + */ + + /* Start of a new WWW-Authenticate header */ + if (skip_iprefix_mem(ptr, size, "www-authenticate:", &val, &val_len)) { + strbuf_add(&buf, val, val_len); + + /* + * Strip the CRLF that should be present at the end of each + * field as well as any trailing or leading whitespace from the + * value. + */ + strbuf_trim(&buf); + + strvec_push(values, buf.buf); + http_auth.header_is_last_match = 1; + goto exit; + } + + /* + * This line could be a continuation of the previously matched header + * field. If this is the case then we should append this value to the + * end of the previously consumed value. + */ + if (http_auth.header_is_last_match && is_hdr_continuation(ptr, size)) { + /* + * Trim the CRLF and any leading or trailing from this line. + */ + strbuf_add(&buf, ptr, size); + strbuf_trim(&buf); + + /* + * At this point we should always have at least one existing + * value, even if it is empty. Do not bother appending the new + * value if this continuation header is itself empty. + */ + if (!values->nr) { + BUG("should have at least one existing header value"); + } else if (buf.len) { + char *prev = xstrdup(values->v[values->nr - 1]); + + /* Join two non-empty values with a single space. */ + const char *const sp = *prev ? " " : ""; + + strvec_pop(values); + strvec_pushf(values, "%s%s%s", prev, sp, buf.buf); + free(prev); + } + + goto exit; + } + + /* Not a continuation of a previously matched auth header line. */ + http_auth.header_is_last_match = 0; + + /* + * If this is a HTTP status line and not a header field, this signals + * a different HTTP response. libcurl writes all the output of all + * response headers of all responses, including redirects. + * We only care about the last HTTP request response's headers so clear + * the existing array. + */ + if (skip_iprefix_mem(ptr, size, "http/", &val, &val_len)) + strvec_clear(values); + +exit: + strbuf_release(&buf); + return size; +} + size_t fwrite_null(char *ptr, size_t eltsize, size_t nmemb, void *strbuf) { return nmemb; @@ -1895,6 +2005,8 @@ static int http_request(const char *url, fwrite_buffer); } + curl_easy_setopt(slot->curl, CURLOPT_HEADERFUNCTION, fwrite_wwwauth); + accept_language = http_get_accept_language_header(); if (accept_language) @@ -5,10 +5,13 @@ * * Copyright (C) 2005 Linus Torvalds */ -#include "cache.h" +#include "git-compat-util.h" +#include "ident.h" #include "config.h" #include "date.h" +#include "gettext.h" #include "mailmap.h" +#include "strbuf.h" static struct strbuf git_default_name = STRBUF_INIT; static struct strbuf git_default_email = STRBUF_INIT; diff --git a/ident.h b/ident.h new file mode 100644 index 0000000000..96a64896a0 --- /dev/null +++ b/ident.h @@ -0,0 +1,67 @@ +#ifndef IDENT_H +#define IDENT_H + +#include "string-list.h" + +struct ident_split { + const char *name_begin; + const char *name_end; + const char *mail_begin; + const char *mail_end; + const char *date_begin; + const char *date_end; + const char *tz_begin; + const char *tz_end; +}; + +#define IDENT_STRICT 1 +#define IDENT_NO_DATE 2 +#define IDENT_NO_NAME 4 + +enum want_ident { + WANT_BLANK_IDENT, + WANT_AUTHOR_IDENT, + WANT_COMMITTER_IDENT +}; + +const char *ident_default_name(void); +const char *ident_default_email(void); +/* + * Prepare an ident to fall back on if the user didn't configure it. + */ +void prepare_fallback_ident(const char *name, const char *email); +void reset_ident_date(void); +/* + * Signals an success with 0, but time part of the result may be NULL + * if the input lacks timestamp and zone + */ +int split_ident_line(struct ident_split *, const char *, int); + +/* + * Given a commit or tag object buffer and the commit or tag headers, replaces + * the idents in the headers with their canonical versions using the mailmap mechanism. + */ +void apply_mailmap_to_header(struct strbuf *, const char **, struct string_list *); + +/* + * Compare split idents for equality or strict ordering. Note that we + * compare only the ident part of the line, ignoring any timestamp. + * + * Because there are two fields, we must choose one as the primary key; we + * currently arbitrarily pick the email. + */ +int ident_cmp(const struct ident_split *, const struct ident_split *); + +const char *git_author_info(int); +const char *git_committer_info(int); +const char *fmt_ident(const char *name, const char *email, + enum want_ident whose_ident, + const char *date_str, int); +const char *fmt_name(enum want_ident); + +int committer_ident_sufficiently_given(void); +int author_ident_sufficiently_given(void); + +int git_ident_config(const char *, const char *, void *); + +#endif diff --git a/imap-send.c b/imap-send.c index a50af56b82..a62424e90a 100644 --- a/imap-send.c +++ b/imap-send.c @@ -21,12 +21,15 @@ * along with this program; if not, see <http://www.gnu.org/licenses/>. */ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "credential.h" #include "exec-cmd.h" +#include "gettext.h" #include "run-command.h" #include "parse-options.h" +#include "setup.h" +#include "wrapper.h" #if defined(NO_OPENSSL) && !defined(HAVE_OPENSSL_CSPRNG) typedef void *SSL; #endif diff --git a/json-writer.c b/json-writer.c index f1cfd8fa8c..005c820aa4 100644 --- a/json-writer.c +++ b/json-writer.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "json-writer.h" void jw_init(struct json_writer *jw) @@ -26,7 +26,6 @@ #ifndef __AC_KHASH_H #define __AC_KHASH_H -#include "cache.h" #include "hashmap.h" #define AC_VERSION_KHASH_H "0.2.8" @@ -32,7 +32,7 @@ String Matching: An Aid to Bibliographic Search," CACM June 1975, Vol. 18, No. 6, which describes the failure function used below. */ -#include "cache.h" +#include "git-compat-util.h" #include "kwset.h" #include "compat/obstack.h" diff --git a/levenshtein.c b/levenshtein.c index d2632690d5..fd8026fe20 100644 --- a/levenshtein.c +++ b/levenshtein.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "levenshtein.h" /* diff --git a/line-log.c b/line-log.c index a7f3e7f6ce..10c19daec4 100644 --- a/line-log.c +++ b/line-log.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" +#include "alloc.h" #include "line-range.h" -#include "cache.h" +#include "hex.h" #include "tag.h" #include "blob.h" #include "tree.h" @@ -14,6 +15,7 @@ #include "graph.h" #include "userdiff.h" #include "line-log.h" +#include "setup.h" #include "strvec.h" #include "bloom.h" @@ -1281,7 +1283,8 @@ int line_log_process_ranges_arbitrary_commit(struct rev_info *rev, struct commit return changed; } -static enum rewrite_result line_log_rewrite_one(struct rev_info *rev, struct commit **pp) +static enum rewrite_result line_log_rewrite_one(struct rev_info *rev UNUSED, + struct commit **pp) { for (;;) { struct commit *p = *pp; diff --git a/line-log.h b/line-log.h index 82ae8d98a4..adff361b1b 100644 --- a/line-log.h +++ b/line-log.h @@ -5,6 +5,7 @@ struct rev_info; struct commit; +struct string_list; /* A range [start,end]. Lines are numbered starting at 0, and the * ranges include start but exclude end. */ diff --git a/linear-assignment.c b/linear-assignment.c index ecffc09be6..5416cbcf40 100644 --- a/linear-assignment.c +++ b/linear-assignment.c @@ -3,7 +3,7 @@ * algorithm for dense and sparse linear assignment problems</i>. Computing, * 38(4), 325-340. */ -#include "cache.h" +#include "git-compat-util.h" #include "linear-assignment.h" #define COST(column, row) cost[(column) + column_count * (row)] diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c index ccfeabc477..b82ba0a2e5 100644 --- a/list-objects-filter-options.c +++ b/list-objects-filter-options.c @@ -1,6 +1,8 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "commit.h" #include "config.h" +#include "gettext.h" #include "revision.h" #include "strvec.h" #include "list-objects.h" diff --git a/list-objects-filter-options.h b/list-objects-filter-options.h index 1fe393f447..65c6119e9d 100644 --- a/list-objects-filter-options.h +++ b/list-objects-filter-options.h @@ -1,9 +1,11 @@ #ifndef LIST_OBJECTS_FILTER_OPTIONS_H #define LIST_OBJECTS_FILTER_OPTIONS_H -#include "cache.h" +#include "gettext.h" +#include "object.h" #include "parse-options.h" #include "string-list.h" +#include "strbuf.h" /* * The list of defined filters for list-objects. diff --git a/list-objects-filter.c b/list-objects-filter.c index 7ed21cb299..298ca08711 100644 --- a/list-objects-filter.c +++ b/list-objects-filter.c @@ -1,5 +1,8 @@ #include "cache.h" +#include "alloc.h" #include "dir.h" +#include "gettext.h" +#include "hex.h" #include "tag.h" #include "commit.h" #include "tree.h" diff --git a/list-objects.c b/list-objects.c index ccad7304df..df18d10306 100644 --- a/list-objects.c +++ b/list-objects.c @@ -1,6 +1,8 @@ #include "cache.h" #include "tag.h" #include "commit.h" +#include "gettext.h" +#include "hex.h" #include "tree.h" #include "blob.h" #include "diff.h" diff --git a/ll-merge.c b/ll-merge.c index 130d26501c..8be38d3bd4 100644 --- a/ll-merge.c +++ b/ll-merge.c @@ -11,6 +11,7 @@ #include "run-command.h" #include "ll-merge.h" #include "quote.h" +#include "wrapper.h" struct ll_merge_driver; diff --git a/lockfile.c b/lockfile.c index cc9a4b8428..1d5ed01682 100644 --- a/lockfile.c +++ b/lockfile.c @@ -2,7 +2,9 @@ * Copyright (c) 2005, Junio C Hamano */ -#include "cache.h" +#include "git-compat-util.h" +#include "abspath.h" +#include "gettext.h" #include "lockfile.h" /* diff --git a/log-tree.c b/log-tree.c index 7eee664cd2..627c711f70 100644 --- a/log-tree.c +++ b/log-tree.c @@ -2,6 +2,8 @@ #include "commit-reach.h" #include "config.h" #include "diff.h" +#include "environment.h" +#include "hex.h" #include "object-store.h" #include "repository.h" #include "tmp-objdir.h" @@ -12,6 +14,7 @@ #include "merge-ort.h" #include "reflog-walk.h" #include "refs.h" +#include "replace-object.h" #include "string-list.h" #include "color.h" #include "gpg-interface.h" @@ -20,6 +23,7 @@ #include "help.h" #include "range-diff.h" #include "strmap.h" +#include "write-or-die.h" static struct decoration name_decoration = { "object names" }; static int decoration_loaded; @@ -196,7 +200,8 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid, return 0; } -static int add_graft_decoration(const struct commit_graft *graft, void *cb_data) +static int add_graft_decoration(const struct commit_graft *graft, + void *cb_data UNUSED) { struct commit *commit = lookup_commit(the_repository, &graft->oid); if (!commit) @@ -1,4 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "repository.h" #include "refs.h" #include "remote.h" @@ -8,38 +11,32 @@ #include "config.h" #include "string-list.h" -static int config_read; -static int advertise_unborn; -static int allow_unborn; - -static void ensure_config_read(void) +static enum { + UNBORN_IGNORE = 0, + UNBORN_ALLOW, + UNBORN_ADVERTISE /* implies ALLOW */ +} unborn_config(struct repository *r) { const char *str = NULL; - if (config_read) - return; - - if (repo_config_get_string_tmp(the_repository, "lsrefs.unborn", &str)) { + if (repo_config_get_string_tmp(r, "lsrefs.unborn", &str)) { /* * If there is no such config, advertise and allow it by * default. */ - advertise_unborn = 1; - allow_unborn = 1; + return UNBORN_ADVERTISE; } else { if (!strcmp(str, "advertise")) { - advertise_unborn = 1; - allow_unborn = 1; + return UNBORN_ADVERTISE; } else if (!strcmp(str, "allow")) { - allow_unborn = 1; + return UNBORN_ALLOW; } else if (!strcmp(str, "ignore")) { - /* do nothing */ + return UNBORN_IGNORE; } else { die(_("invalid value for '%s': '%s'"), "lsrefs.unborn", str); } } - config_read = 1; } /* @@ -159,7 +156,6 @@ int ls_refs(struct repository *r, struct packet_reader *request) strbuf_init(&data.buf, 0); string_list_init_dup(&data.hidden_refs); - ensure_config_read(); git_config(ls_refs_config, &data); while (packet_reader_read(request) == PACKET_READ_NORMAL) { @@ -175,7 +171,7 @@ int ls_refs(struct repository *r, struct packet_reader *request) strvec_push(&data.prefixes, out); } else if (!strcmp("unborn", arg)) - data.unborn = allow_unborn; + data.unborn = !!unborn_config(r); else die(_("unexpected line: '%s'"), arg); } @@ -206,11 +202,8 @@ int ls_refs(struct repository *r, struct packet_reader *request) int ls_refs_advertise(struct repository *r, struct strbuf *value) { - if (value) { - ensure_config_read(); - if (advertise_unborn) - strbuf_addstr(value, "unborn"); - } + if (value && unborn_config(r) == UNBORN_ADVERTISE) + strbuf_addstr(value, "unborn"); return 1; } diff --git a/mailinfo.c b/mailinfo.c index 833d28612f..9f1495ddcf 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -1,5 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" +#include "gettext.h" +#include "hex.h" #include "utf8.h" #include "strbuf.h" #include "mailinfo.h" @@ -1,7 +1,9 @@ #include "cache.h" +#include "environment.h" #include "string-list.h" #include "mailmap.h" #include "object-store.h" +#include "setup.h" #define DEBUG_MAILMAP 0 #if DEBUG_MAILMAP diff --git a/match-trees.c b/match-trees.c index dfc4093425..5877fc64a8 100644 --- a/match-trees.c +++ b/match-trees.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hex.h" #include "tree.h" #include "tree-walk.h" #include "object-store.h" diff --git a/mem-pool.c b/mem-pool.c index 599d8e895f..c34846d176 100644 --- a/mem-pool.c +++ b/mem-pool.c @@ -2,7 +2,7 @@ * Memory Pool implementation logic. */ -#include "cache.h" +#include "git-compat-util.h" #include "mem-pool.h" #define BLOCK_GROWTH_SIZE (1024 * 1024 - sizeof(struct mp_block)) diff --git a/merge-blobs.c b/merge-blobs.c index f13246406c..5632ff6abb 100644 --- a/merge-blobs.c +++ b/merge-blobs.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "run-command.h" #include "xdiff-interface.h" #include "ll-merge.h" diff --git a/merge-ort-wrappers.c b/merge-ort-wrappers.c index 748924a69b..c00dfbab1c 100644 --- a/merge-ort-wrappers.c +++ b/merge-ort-wrappers.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "gettext.h" #include "merge-ort.h" #include "merge-ort-wrappers.h" diff --git a/merge-ort.c b/merge-ort.c index ba3f5607bb..5bf64354d1 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -26,6 +26,9 @@ #include "diff.h" #include "diffcore.h" #include "dir.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "entry.h" #include "ll-merge.h" #include "object-store.h" diff --git a/merge-recursive.c b/merge-recursive.c index 20aa18e220..ed5534eb57 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -10,7 +10,6 @@ #include "alloc.h" #include "attr.h" #include "blob.h" -#include "builtin.h" #include "cache-tree.h" #include "commit.h" #include "commit-reach.h" @@ -18,6 +17,9 @@ #include "diff.h" #include "diffcore.h" #include "dir.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "ll-merge.h" #include "lockfile.h" #include "object-store.h" @@ -29,6 +31,7 @@ #include "tag.h" #include "tree-walk.h" #include "unpack-trees.h" +#include "wrapper.h" #include "xdiff-interface.h" struct merge_options_internal { @@ -1,6 +1,8 @@ #include "cache.h" #include "diff.h" #include "diffcore.h" +#include "gettext.h" +#include "hex.h" #include "lockfile.h" #include "commit.h" #include "run-command.h" @@ -1,7 +1,11 @@ #include "cache.h" +#include "abspath.h" +#include "alloc.h" #include "config.h" #include "csum-file.h" #include "dir.h" +#include "gettext.h" +#include "hex.h" #include "lockfile.h" #include "packfile.h" #include "object-store.h" @@ -1607,7 +1611,7 @@ struct clear_midx_data { const char *ext; }; -static void clear_midx_file_ext(const char *full_path, size_t full_path_len, +static void clear_midx_file_ext(const char *full_path, size_t full_path_len UNUSED, const char *file_name, void *_data) { struct clear_midx_data *data = _data; diff --git a/name-hash.c b/name-hash.c index cd009c7c8a..2c2861efd1 100644 --- a/name-hash.c +++ b/name-hash.c @@ -6,6 +6,8 @@ * Copyright (C) 2008 Linus Torvalds */ #include "cache.h" +#include "environment.h" +#include "gettext.h" #include "thread-utils.h" #include "trace2.h" #include "sparse-index.h" diff --git a/negotiator/default.c b/negotiator/default.c index 658d9dd6b9..f4b78eb47d 100644 --- a/negotiator/default.c +++ b/negotiator/default.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "default.h" #include "../commit.h" #include "../fetch-negotiator.h" diff --git a/negotiator/noop.c b/negotiator/noop.c index 60569b8350..7b72937686 100644 --- a/negotiator/noop.c +++ b/negotiator/noop.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "noop.h" #include "../commit.h" #include "../fetch-negotiator.h" diff --git a/negotiator/skipping.c b/negotiator/skipping.c index 594639b25a..c7d6ab39bc 100644 --- a/negotiator/skipping.c +++ b/negotiator/skipping.c @@ -1,7 +1,8 @@ -#include "cache.h" +#include "git-compat-util.h" #include "skipping.h" #include "../commit.h" #include "../fetch-negotiator.h" +#include "../hex.h" #include "../prio-queue.h" #include "../refs.h" #include "../tag.h" @@ -50,7 +51,7 @@ struct data { int non_common_revs; }; -static int compare(const void *a_, const void *b_, void *unused) +static int compare(const void *a_, const void *b_, void *data UNUSED) { const struct entry *a = a_; const struct entry *b = b_; diff --git a/notes-cache.c b/notes-cache.c index 1a6e214ea7..fbcdfd0dfe 100644 --- a/notes-cache.c +++ b/notes-cache.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "notes-cache.h" #include "object-store.h" #include "repository.h" diff --git a/notes-merge.c b/notes-merge.c index 8a09cd9f77..c40107c3aa 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -1,10 +1,12 @@ #include "cache.h" #include "commit.h" +#include "gettext.h" #include "refs.h" #include "object-store.h" #include "repository.h" #include "diff.h" #include "diffcore.h" +#include "hex.h" #include "xdiff-interface.h" #include "ll-merge.h" #include "dir.h" @@ -13,6 +15,7 @@ #include "strbuf.h" #include "notes-utils.h" #include "commit-reach.h" +#include "wrapper.h" struct notes_merge_pair { struct object_id obj, base, local, remote; diff --git a/notes-utils.c b/notes-utils.c index 4be0aaa6de..cb88171b7b 100644 --- a/notes-utils.c +++ b/notes-utils.c @@ -1,6 +1,8 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "commit.h" +#include "environment.h" +#include "gettext.h" #include "refs.h" #include "notes-utils.h" #include "repository.h" @@ -1,5 +1,7 @@ #include "cache.h" #include "config.h" +#include "environment.h" +#include "hex.h" #include "notes.h" #include "object-store.h" #include "blob.h" @@ -752,7 +754,7 @@ static int write_each_non_note_until(const char *note_path, return 0; } -static int write_each_note(const struct object_id *object_oid, +static int write_each_note(const struct object_id *object_oid UNUSED, const struct object_id *note_oid, char *note_path, void *cb_data) { @@ -780,8 +782,9 @@ struct note_delete_list { }; static int prune_notes_helper(const struct object_id *object_oid, - const struct object_id *note_oid, char *note_path, - void *cb_data) + const struct object_id *note_oid UNUSED, + char *note_path UNUSED, + void *cb_data) { struct note_delete_list **l = (struct note_delete_list **) cb_data; struct note_delete_list *n; @@ -850,8 +853,8 @@ int combine_notes_overwrite(struct object_id *cur_oid, return 0; } -int combine_notes_ignore(struct object_id *cur_oid, - const struct object_id *new_oid) +int combine_notes_ignore(struct object_id *cur_oid UNUSED, + const struct object_id *new_oid UNUSED) { return 0; } diff --git a/object-file.c b/object-file.c index 47c5268164..76b22ca75c 100644 --- a/object-file.c +++ b/object-file.c @@ -7,7 +7,12 @@ * creation etc. */ #include "cache.h" +#include "abspath.h" +#include "alloc.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "string-list.h" #include "lockfile.h" #include "delta.h" @@ -32,8 +37,10 @@ #include "packfile.h" #include "object-store.h" #include "promisor-remote.h" +#include "setup.h" #include "submodule.h" #include "fsck.h" +#include "wrapper.h" /* The maximum size for an object header. */ #define MAX_HEADER_LEN 32 @@ -2644,7 +2651,8 @@ int for_each_loose_object(each_loose_object_fn cb, void *data, return 0; } -static int append_loose_object(const struct object_id *oid, const char *path, +static int append_loose_object(const struct object_id *oid, + const char *path UNUSED, void *data) { oidtree_insert(data, oid); diff --git a/object-name.c b/object-name.c index c7bc311dce..53f9d359ee 100644 --- a/object-name.c +++ b/object-name.c @@ -1,5 +1,8 @@ #include "cache.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "tag.h" #include "commit.h" #include "tree.h" @@ -12,6 +15,7 @@ #include "packfile.h" #include "object-store.h" #include "repository.h" +#include "setup.h" #include "submodule.h" #include "midx.h" #include "commit-reach.h" @@ -223,7 +227,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds, static int disambiguate_commit_only(struct repository *r, const struct object_id *oid, - void *cb_data_unused) + void *cb_data UNUSED) { int kind = oid_object_info(r, oid, NULL); return kind == OBJ_COMMIT; @@ -231,7 +235,7 @@ static int disambiguate_commit_only(struct repository *r, static int disambiguate_committish_only(struct repository *r, const struct object_id *oid, - void *cb_data_unused) + void *cb_data UNUSED) { struct object *obj; int kind; @@ -251,7 +255,7 @@ static int disambiguate_committish_only(struct repository *r, static int disambiguate_tree_only(struct repository *r, const struct object_id *oid, - void *cb_data_unused) + void *cb_data UNUSED) { int kind = oid_object_info(r, oid, NULL); return kind == OBJ_TREE; @@ -259,7 +263,7 @@ static int disambiguate_tree_only(struct repository *r, static int disambiguate_treeish_only(struct repository *r, const struct object_id *oid, - void *cb_data_unused) + void *cb_data UNUSED) { struct object *obj; int kind; @@ -279,7 +283,7 @@ static int disambiguate_treeish_only(struct repository *r, static int disambiguate_blob_only(struct repository *r, const struct object_id *oid, - void *cb_data_unused) + void *cb_data UNUSED) { int kind = oid_object_info(r, oid, NULL); return kind == OBJ_BLOB; @@ -475,7 +479,7 @@ static int collect_ambiguous(const struct object_id *oid, void *data) return 0; } -static int repo_collect_ambiguous(struct repository *r, +static int repo_collect_ambiguous(struct repository *r UNUSED, const struct object_id *oid, void *data) { @@ -667,7 +671,7 @@ static int extend_abbrev_len(const struct object_id *oid, void *cb_data) return 0; } -static int repo_extend_abbrev_len(struct repository *r, +static int repo_extend_abbrev_len(struct repository *r UNUSED, const struct object_id *oid, void *cb_data) { diff --git a/object-store.h b/object-store.h index 9217ae8306..f9d225783a 100644 --- a/object-store.h +++ b/object-store.h @@ -1,7 +1,7 @@ #ifndef OBJECT_STORE_H #define OBJECT_STORE_H -#include "cache.h" +#include "object.h" #include "oidmap.h" #include "list.h" #include "oid-array.h" @@ -281,6 +281,69 @@ int pretend_object_file(void *, unsigned long, enum object_type, int force_object_loose(const struct object_id *oid, time_t mtime); +struct object_info { + /* Request */ + enum object_type *typep; + unsigned long *sizep; + off_t *disk_sizep; + struct object_id *delta_base_oid; + struct strbuf *type_name; + void **contentp; + + /* Response */ + enum { + OI_CACHED, + OI_LOOSE, + OI_PACKED, + OI_DBCACHED + } whence; + union { + /* + * struct { + * ... Nothing to expose in this case + * } cached; + * struct { + * ... Nothing to expose in this case + * } loose; + */ + struct { + struct packed_git *pack; + off_t offset; + unsigned int is_delta; + } packed; + } u; +}; + +/* + * Initializer for a "struct object_info" that wants no items. You may + * also memset() the memory to all-zeroes. + */ +#define OBJECT_INFO_INIT { 0 } + +/* Invoke lookup_replace_object() on the given hash */ +#define OBJECT_INFO_LOOKUP_REPLACE 1 +/* Allow reading from a loose object file of unknown/bogus type */ +#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2 +/* Do not retry packed storage after checking packed and loose storage */ +#define OBJECT_INFO_QUICK 8 +/* + * Do not attempt to fetch the object if missing (even if fetch_is_missing is + * nonzero). + */ +#define OBJECT_INFO_SKIP_FETCH_OBJECT 16 +/* + * This is meant for bulk prefetching of missing blobs in a partial + * clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK + */ +#define OBJECT_INFO_FOR_PREFETCH (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK) + +/* Die if object corruption (not just an object being missing) was detected. */ +#define OBJECT_INFO_DIE_IF_CORRUPT 32 + +int oid_object_info_extended(struct repository *r, + const struct object_id *, + struct object_info *, unsigned flags); + /* * Open the loose object at path, check its hash, and return the contents, * use the "oi" argument to assert things about the object, or e.g. populate its @@ -374,69 +437,6 @@ static inline void obj_read_unlock(void) pthread_mutex_unlock(&obj_read_mutex); } -struct object_info { - /* Request */ - enum object_type *typep; - unsigned long *sizep; - off_t *disk_sizep; - struct object_id *delta_base_oid; - struct strbuf *type_name; - void **contentp; - - /* Response */ - enum { - OI_CACHED, - OI_LOOSE, - OI_PACKED, - OI_DBCACHED - } whence; - union { - /* - * struct { - * ... Nothing to expose in this case - * } cached; - * struct { - * ... Nothing to expose in this case - * } loose; - */ - struct { - struct packed_git *pack; - off_t offset; - unsigned int is_delta; - } packed; - } u; -}; - -/* - * Initializer for a "struct object_info" that wants no items. You may - * also memset() the memory to all-zeroes. - */ -#define OBJECT_INFO_INIT { 0 } - -/* Invoke lookup_replace_object() on the given hash */ -#define OBJECT_INFO_LOOKUP_REPLACE 1 -/* Allow reading from a loose object file of unknown/bogus type */ -#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2 -/* Do not retry packed storage after checking packed and loose storage */ -#define OBJECT_INFO_QUICK 8 -/* - * Do not attempt to fetch the object if missing (even if fetch_is_missing is - * nonzero). - */ -#define OBJECT_INFO_SKIP_FETCH_OBJECT 16 -/* - * This is meant for bulk prefetching of missing blobs in a partial - * clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK - */ -#define OBJECT_INFO_FOR_PREFETCH (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK) - -/* Die if object corruption (not just an object being missing) was detected. */ -#define OBJECT_INFO_DIE_IF_CORRUPT 32 - -int oid_object_info_extended(struct repository *r, - const struct object_id *, - struct object_info *, unsigned flags); - /* * Iterate over the files in the loose-object parts of the object * directory "path", triggering the following callbacks: @@ -1,4 +1,6 @@ #include "cache.h" +#include "gettext.h" +#include "hex.h" #include "object.h" #include "replace-object.h" #include "object-store.h" @@ -1,7 +1,7 @@ #ifndef OBJECT_H #define OBJECT_H -#include "cache.h" +#include "hash.h" struct buffer_slab; @@ -81,6 +81,26 @@ struct object_array { */ #define FLAG_BITS 28 +#define TYPE_BITS 3 + +/* + * Values in this enum (except those outside the 3 bit range) are part + * of pack file format. See gitformat-pack(5) for more information. + */ +enum object_type { + OBJ_BAD = -1, + OBJ_NONE = 0, + OBJ_COMMIT = 1, + OBJ_TREE = 2, + OBJ_BLOB = 3, + OBJ_TAG = 4, + /* 5 for future expansion */ + OBJ_OFS_DELTA = 6, + OBJ_REF_DELTA = 7, + OBJ_ANY, + OBJ_MAX +}; + /* * The object type is stored in 3 bits. */ diff --git a/oid-array.c b/oid-array.c index 73ba76e9e9..e8228c777b 100644 --- a/oid-array.c +++ b/oid-array.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "oid-array.h" #include "hash-lookup.h" @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "oidmap.h" static int oidmap_neq(const void *hashmap_cmp_fn_data UNUSED, @@ -1,7 +1,6 @@ #ifndef OIDMAP_H #define OIDMAP_H -#include "cache.h" #include "hashmap.h" /* @@ -1,5 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" #include "oidset.h" +#include "hex.h" +#include "strbuf.h" void oidset_init(struct oidset *set, size_t initial_size) { @@ -2,6 +2,7 @@ * A wrapper around cbtree which stores oids * May be used to replace oid-array for prefix (abbreviation) matches */ +#include "git-compat-util.h" #include "oidtree.h" #include "alloc.h" #include "hash.h" diff --git a/oss-fuzz/fuzz-commit-graph.c b/oss-fuzz/fuzz-commit-graph.c index 914026f5d8..2992079dd9 100644 --- a/oss-fuzz/fuzz-commit-graph.c +++ b/oss-fuzz/fuzz-commit-graph.c @@ -1,3 +1,4 @@ +#include "git-compat-util.h" #include "commit-graph.h" #include "repository.h" diff --git a/oss-fuzz/fuzz-pack-headers.c b/oss-fuzz/fuzz-pack-headers.c index 99da1d0fd3..150c0f5fa2 100644 --- a/oss-fuzz/fuzz-pack-headers.c +++ b/oss-fuzz/fuzz-pack-headers.c @@ -1,3 +1,4 @@ +#include "git-compat-util.h" #include "packfile.h" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); diff --git a/oss-fuzz/fuzz-pack-idx.c b/oss-fuzz/fuzz-pack-idx.c index 0c3d777aac..609a343ee3 100644 --- a/oss-fuzz/fuzz-pack-idx.c +++ b/oss-fuzz/fuzz-pack-idx.c @@ -1,3 +1,4 @@ +#include "git-compat-util.h" #include "object-store.h" #include "packfile.h" diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index 84b6132893..7f5f489beb 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -1,4 +1,8 @@ #include "cache.h" +#include "alloc.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "object-store.h" #include "commit.h" #include "tag.h" @@ -13,6 +17,7 @@ #include "pack-objects.h" #include "commit-reach.h" #include "prio-queue.h" +#include "trace2.h" struct bitmapped_commit { struct commit *commit; diff --git a/pack-bitmap.c b/pack-bitmap.c index d2a42abf28..23d87e71bd 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -1,5 +1,8 @@ #include "cache.h" +#include "alloc.h" #include "commit.h" +#include "gettext.h" +#include "hex.h" #include "strbuf.h" #include "tag.h" #include "diff.h" @@ -951,7 +954,8 @@ static void show_object(struct object *object, const char *name, void *data_) bitmap_set(data->base, bitmap_pos); } -static void show_commit(struct commit *commit, void *data) +static void show_commit(struct commit *commit UNUSED, + void *data UNUSED) { } @@ -1940,7 +1944,8 @@ static void test_bitmap_type(struct bitmap_test_data *tdata, type_name(bitmap_type)); } -static void test_show_object(struct object *object, const char *name, +static void test_show_object(struct object *object, + const char *name UNUSED, void *data) { struct bitmap_test_data *tdata = data; diff --git a/pack-check.c b/pack-check.c index bfb593ba72..6974e40a95 100644 --- a/pack-check.c +++ b/pack-check.c @@ -1,4 +1,6 @@ #include "cache.h" +#include "environment.h" +#include "hex.h" #include "repository.h" #include "pack.h" #include "pack-revindex.h" diff --git a/pack-mtimes.c b/pack-mtimes.c index 0f9785fc5e..afed632190 100644 --- a/pack-mtimes.c +++ b/pack-mtimes.c @@ -1,4 +1,5 @@ -#include "git-compat-util.h" +#include "cache.h" +#include "gettext.h" #include "pack-mtimes.h" #include "object-store.h" #include "packfile.h" diff --git a/pack-mtimes.h b/pack-mtimes.h index cc957b3e85..107327cec0 100644 --- a/pack-mtimes.h +++ b/pack-mtimes.h @@ -1,8 +1,6 @@ #ifndef PACK_MTIMES_H #define PACK_MTIMES_H -#include "git-compat-util.h" - #define MTIMES_SIGNATURE 0x4d544d45 /* "MTME" */ #define MTIMES_VERSION 1 diff --git a/pack-objects.c b/pack-objects.c index 272e8d4517..ccab09fe65 100644 --- a/pack-objects.c +++ b/pack-objects.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "object.h" #include "pack.h" #include "pack-objects.h" diff --git a/pack-revindex.c b/pack-revindex.c index 08dc160167..03c7e81f9d 100644 --- a/pack-revindex.c +++ b/pack-revindex.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "gettext.h" #include "pack-revindex.h" #include "object-store.h" #include "packfile.h" diff --git a/pack-write.c b/pack-write.c index 3363729748..f171405495 100644 --- a/pack-write.c +++ b/pack-write.c @@ -1,4 +1,7 @@ #include "cache.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "pack.h" #include "csum-file.h" #include "remote.h" @@ -4,6 +4,8 @@ #include "object.h" #include "csum-file.h" +struct packed_git; +struct pack_window; struct repository; /* diff --git a/packfile.c b/packfile.c index 4aee73d545..b120405ccc 100644 --- a/packfile.c +++ b/packfile.c @@ -1,4 +1,8 @@ #include "cache.h" +#include "alloc.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "list.h" #include "pack.h" #include "repository.h" @@ -17,6 +21,7 @@ #include "midx.h" #include "commit-graph.h" #include "promisor-remote.h" +#include "wrapper.h" char *odb_pack_name(struct strbuf *buf, const unsigned char *hash, @@ -1008,6 +1013,16 @@ void reprepare_packed_git(struct repository *r) struct object_directory *odb; obj_read_lock(); + + /* + * Reprepare alt odbs, in case the alternates file was modified + * during the course of this process. This only _adds_ odbs to + * the linked list, so existing odbs will continue to exist for + * the lifetime of the process. + */ + r->objects->loaded_alternates = 0; + prepare_alt_odb(r); + for (odb = r->objects->odb; odb; odb = odb->next) odb_clear_loose_cache(odb); @@ -2204,8 +2219,8 @@ int for_each_packed_object(each_packed_object_fn cb, void *data, } static int add_promisor_object(const struct object_id *oid, - struct packed_git *pack, - uint32_t pos, + struct packed_git *pack UNUSED, + uint32_t pos UNUSED, void *set_) { struct oidset *set = set_; diff --git a/packfile.h b/packfile.h index 6ec1656797..665603b696 100644 --- a/packfile.h +++ b/packfile.h @@ -1,11 +1,13 @@ #ifndef PACKFILE_H #define PACKFILE_H -#include "cache.h" +#include "object.h" #include "oidset.h" /* in object-store.h */ struct packed_git; +struct pack_entry; +struct pack_window; struct object_info; /* diff --git a/parallel-checkout.c b/parallel-checkout.c index 4f6819f240..50fd7fe31e 100644 --- a/parallel-checkout.c +++ b/parallel-checkout.c @@ -1,6 +1,9 @@ #include "cache.h" +#include "alloc.h" #include "config.h" #include "entry.h" +#include "gettext.h" +#include "hex.h" #include "parallel-checkout.h" #include "pkt-line.h" #include "progress.h" @@ -9,6 +12,7 @@ #include "streaming.h" #include "thread-utils.h" #include "trace2.h" +#include "wrapper.h" struct pc_worker { struct child_process cp; diff --git a/parse-options-cb.c b/parse-options-cb.c index 0f7b40d0c0..666c212979 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -4,6 +4,8 @@ #include "cache.h" #include "commit.h" #include "color.h" +#include "environment.h" +#include "gettext.h" #include "string-list.h" #include "strvec.h" #include "oid-array.h" diff --git a/parse-options.c b/parse-options.c index fd4743293f..b6803647d0 100644 --- a/parse-options.c +++ b/parse-options.c @@ -1,9 +1,10 @@ #include "git-compat-util.h" #include "parse-options.h" -#include "cache.h" +#include "abspath.h" #include "config.h" #include "commit.h" #include "color.h" +#include "gettext.h" #include "utf8.h" static int disallow_abbreviated_options; @@ -59,12 +60,12 @@ static enum parse_opt_result get_arg(struct parse_opt_ctx_t *p, return 0; } -static void fix_filename(const char *prefix, const char **file) +static void fix_filename(const char *prefix, char **file) { - if (!file || !*file || !prefix || is_absolute_path(*file) - || !strcmp("-", *file)) - return; - *file = prefix_filename(prefix, *file); + if (!file || !*file) + ; /* leave as NULL */ + else + *file = prefix_filename_except_for_dash(prefix, *file); } static enum parse_opt_result opt_command_mode_error( @@ -177,7 +178,7 @@ static enum parse_opt_result get_value(struct parse_opt_ctx_t *p, err = get_arg(p, opt, flags, (const char **)opt->value); if (!err) - fix_filename(p->prefix, (const char **)opt->value); + fix_filename(p->prefix, (char **)opt->value); return err; case OPTION_CALLBACK: diff --git a/parse-options.h b/parse-options.h index 50d852f299..d57868eff9 100644 --- a/parse-options.h +++ b/parse-options.h @@ -1,6 +1,8 @@ #ifndef PARSE_OPTIONS_H #define PARSE_OPTIONS_H +#include "gettext.h" + /** * Refer to Documentation/technical/api-parse-options.txt for the API doc. */ diff --git a/patch-ids.c b/patch-ids.c index 3153446626..19af7bee98 100644 --- a/patch-ids.c +++ b/patch-ids.c @@ -1,7 +1,8 @@ -#include "cache.h" +#include "git-compat-util.h" #include "diff.h" #include "commit.h" #include "hash-lookup.h" +#include "hex.h" #include "patch-ids.h" static int patch_id_defined(struct commit *commit) @@ -1,12 +1,17 @@ /* * Utilities for paths and pathnames */ -#include "cache.h" +#include "git-compat-util.h" +#include "abspath.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "repository.h" #include "strbuf.h" #include "string-list.h" #include "dir.h" #include "worktree.h" +#include "setup.h" #include "submodule-config.h" #include "path.h" #include "packfile.h" @@ -347,7 +352,8 @@ static void init_common_trie(void) * Helper function for update_common_dir: returns 1 if the dir * prefix is common. */ -static int check_common(const char *unmatched, void *value, void *baton) +static int check_common(const char *unmatched, void *value, + void *baton UNUSED) { struct common_dir *dir = value; @@ -3,6 +3,7 @@ struct repository; struct strbuf; +struct string_list; /* * The result to all functions which return statically allocated memory may be @@ -179,7 +180,66 @@ const char *git_path_auto_merge(struct repository *r); const char *git_path_fetch_head(struct repository *r); const char *git_path_shallow(struct repository *r); - int ends_with_path_components(const char *path, const char *components); +int validate_headref(const char *ref); + +int adjust_shared_perm(const char *path); + +char *interpolate_path(const char *path, int real_home); +const char *enter_repo(const char *path, int strict); +const char *remove_leading_path(const char *in, const char *prefix); +const char *relative_path(const char *in, const char *prefix, struct strbuf *sb); +int normalize_path_copy_len(char *dst, const char *src, int *prefix_len); +int normalize_path_copy(char *dst, const char *src); +int longest_ancestor_length(const char *path, struct string_list *prefixes); +char *strip_path_suffix(const char *path, const char *suffix); +int daemon_avoid_alias(const char *path); + +/* + * These functions match their is_hfs_dotgit() counterparts; see utf8.h for + * details. + */ +int is_ntfs_dotgit(const char *name); +int is_ntfs_dotgitmodules(const char *name); +int is_ntfs_dotgitignore(const char *name); +int is_ntfs_dotgitattributes(const char *name); +int is_ntfs_dotmailmap(const char *name); + +/* + * Returns true iff "str" could be confused as a command-line option when + * passed to a sub-program like "ssh". Note that this has nothing to do with + * shell-quoting, which should be handled separately; we're assuming here that + * the string makes it verbatim to the sub-program. + */ +int looks_like_command_line_option(const char *str); + +/** + * Return a newly allocated string with the evaluation of + * "$XDG_CONFIG_HOME/$subdir/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise + * "$HOME/.config/$subdir/$filename". Return NULL upon error. + */ +char *xdg_config_home_for(const char *subdir, const char *filename); + +/** + * Return a newly allocated string with the evaluation of + * "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise + * "$HOME/.config/git/$filename". Return NULL upon error. + */ +char *xdg_config_home(const char *filename); + +/** + * Return a newly allocated string with the evaluation of + * "$XDG_CACHE_HOME/git/$filename" if $XDG_CACHE_HOME is non-empty, otherwise + * "$HOME/.cache/git/$filename". Return NULL upon error. + */ +char *xdg_cache_home(const char *filename); + +/* + * Create a directory and (if share is nonzero) adjust its permissions + * according to the shared_repository setting. Only use this for + * directories under $GIT_DIR. Don't use it for working tree + * directories. + */ +void safe_create_dir(const char *dir, int share); #endif /* PATH_H */ diff --git a/pathspec.c b/pathspec.c index ab70fcbe61..6972d515f0 100644 --- a/pathspec.c +++ b/pathspec.c @@ -1,8 +1,12 @@ #include "cache.h" +#include "abspath.h" #include "config.h" #include "dir.h" +#include "environment.h" +#include "gettext.h" #include "pathspec.h" #include "attr.h" +#include "setup.h" #include "strvec.h" #include "quote.h" diff --git a/pathspec.h b/pathspec.h index 41f6adfbb4..a5b38e0907 100644 --- a/pathspec.h +++ b/pathspec.h @@ -171,6 +171,11 @@ int match_pathspec_attrs(struct index_state *istate, const char *name, int namelen, const struct pathspec_item *item); +int match_pathspec(struct index_state *istate, + const struct pathspec *pathspec, + const char *name, int namelen, + int prefix, char *seen, int is_dir); + /* * Determine whether a pathspec will match only entire index entries (non-sparse * files and/or entire sparse directories). If the pathspec has the potential to diff --git a/pkt-line.c b/pkt-line.c index ce4e73b683..36ae0fea4a 100644 --- a/pkt-line.c +++ b/pkt-line.c @@ -1,6 +1,10 @@ #include "cache.h" #include "pkt-line.h" +#include "gettext.h" +#include "hex.h" #include "run-command.h" +#include "wrapper.h" +#include "write-or-die.h" char packet_buffer[LARGE_PACKET_MAX]; static const char *packet_trace_prefix = "git"; diff --git a/pkt-line.h b/pkt-line.h index 79c538b99e..8e9846f315 100644 --- a/pkt-line.h +++ b/pkt-line.h @@ -1,7 +1,6 @@ #ifndef PKTLINE_H #define PKTLINE_H -#include "git-compat-util.h" #include "strbuf.h" #include "sideband.h" diff --git a/preload-index.c b/preload-index.c index 100f7a374d..52544d004e 100644 --- a/preload-index.c +++ b/preload-index.c @@ -4,7 +4,9 @@ #include "cache.h" #include "pathspec.h" #include "dir.h" +#include "environment.h" #include "fsmonitor.h" +#include "gettext.h" #include "config.h" #include "progress.h" #include "thread-utils.h" @@ -1,6 +1,10 @@ #include "cache.h" +#include "alloc.h" #include "config.h" #include "commit.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "utf8.h" #include "diff.h" #include "revision.h" @@ -1857,7 +1861,8 @@ static size_t format_commit_item(struct strbuf *sb, /* in UTF-8 */ return consumed + 1; } -static size_t userformat_want_item(struct strbuf *sb, const char *placeholder, +static size_t userformat_want_item(struct strbuf *sb UNUSED, + const char *placeholder, void *context) { struct userformat_want *w = context; @@ -1,11 +1,11 @@ #ifndef PRETTY_H #define PRETTY_H -#include "cache.h" #include "date.h" #include "string-list.h" struct commit; +struct repository; struct strbuf; struct process_trailer_options; @@ -149,6 +149,8 @@ int commit_format_is_empty(enum cmit_fmt); /* Make subject of commit message suitable for filename */ void format_sanitized_subject(struct strbuf *sb, const char *msg, size_t len); +int has_non_ascii(const char *text); + /* * Set values of fields in "struct process_trailer_options" * according to trailers arguments. diff --git a/prio-queue.c b/prio-queue.c index d31b48e725..dc2476be53 100644 --- a/prio-queue.c +++ b/prio-queue.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "prio-queue.h" static inline int compare(struct prio_queue *queue, int i, int j) diff --git a/progress.c b/progress.c index 0cdd875d37..44c784d75f 100644 --- a/progress.c +++ b/progress.c @@ -10,7 +10,6 @@ #define GIT_TEST_PROGRESS_ONLY #include "cache.h" -#include "gettext.h" #include "progress.h" #include "strbuf.h" #include "trace.h" @@ -59,7 +58,7 @@ void progress_test_force_update(void) } -static void progress_interval(int signum) +static void progress_interval(int signum UNUSED) { progress_update = 1; } diff --git a/promisor-remote.c b/promisor-remote.c index faa7612941..a8dbb788e8 100644 --- a/promisor-remote.c +++ b/promisor-remote.c @@ -1,4 +1,6 @@ #include "cache.h" +#include "gettext.h" +#include "hex.h" #include "object-store.h" #include "promisor-remote.h" #include "config.h" @@ -1,5 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" +#include "environment.h" #include "run-command.h" #include "strbuf.h" #include "prompt.h" diff --git a/protocol-caps.c b/protocol-caps.c index bbde91810a..874bc815b4 100644 --- a/protocol-caps.c +++ b/protocol-caps.c @@ -1,9 +1,11 @@ #include "git-compat-util.h" #include "protocol-caps.h" #include "gettext.h" +#include "hex.h" #include "pkt-line.h" #include "strvec.h" #include "hash.h" +#include "hex.h" #include "object.h" #include "object-store.h" #include "string-list.h" diff --git a/protocol.c b/protocol.c index c53f7df5be..bdb32e1eeb 100644 --- a/protocol.c +++ b/protocol.c @@ -1,5 +1,6 @@ #include "cache.h" #include "config.h" +#include "environment.h" #include "protocol.h" static enum protocol_version parse_protocol_version(const char *value) diff --git a/prune-packed.c b/prune-packed.c index 261520b472..58412b4fb9 100644 --- a/prune-packed.c +++ b/prune-packed.c @@ -1,3 +1,6 @@ +#include "git-compat-util.h" +#include "environment.h" +#include "gettext.h" #include "object-store.h" #include "packfile.h" #include "progress.h" @@ -1,5 +1,7 @@ #include "cache.h" +#include "alloc.h" #include "quote.h" +#include "strbuf.h" #include "strvec.h" int quote_path_fully = 1; diff --git a/range-diff.c b/range-diff.c index ff5d19f8ad..d1ed3b8ee5 100644 --- a/range-diff.c +++ b/range-diff.c @@ -1,4 +1,6 @@ #include "cache.h" +#include "environment.h" +#include "gettext.h" #include "range-diff.h" #include "string-list.h" #include "run-command.h" diff --git a/reachable.c b/reachable.c index aba63ebeb3..55bb114353 100644 --- a/reachable.c +++ b/reachable.c @@ -1,4 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "gettext.h" +#include "hex.h" #include "refs.h" #include "tag.h" #include "commit.h" @@ -48,7 +50,9 @@ static int add_one_ref(const char *path, const struct object_id *oid, * The traversal will have already marked us as SEEN, so we * only need to handle any progress reporting here. */ -static void mark_object(struct object *obj, const char *name, void *data) +static void mark_object(struct object *obj UNUSED, + const char *name UNUSED, + void *data) { update_progress(data); } @@ -152,7 +156,8 @@ static int add_recent_loose(const struct object_id *oid, } static int add_recent_packed(const struct object_id *oid, - struct packed_git *p, uint32_t pos, + struct packed_git *p, + uint32_t pos, void *data) { struct object *obj; @@ -202,10 +207,10 @@ int add_unseen_recent_objects_to_traversal(struct rev_info *revs, static int mark_object_seen(const struct object_id *oid, enum object_type type, - int exclude, - uint32_t name_hash, - struct packed_git *found_pack, - off_t found_offset) + int exclude UNUSED, + uint32_t name_hash UNUSED, + struct packed_git *found_pack UNUSED, + off_t found_offset UNUSED) { struct object *obj = lookup_object_by_type(the_repository, oid, type); if (!obj) diff --git a/read-cache.c b/read-cache.c index 892fede6b4..e5e7216904 100644 --- a/read-cache.c +++ b/read-cache.c @@ -4,9 +4,11 @@ * Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "alloc.h" #include "config.h" #include "diff.h" #include "diffcore.h" +#include "hex.h" #include "tempfile.h" #include "lockfile.h" #include "cache-tree.h" @@ -16,6 +18,8 @@ #include "tree.h" #include "commit.h" #include "blob.h" +#include "environment.h" +#include "gettext.h" #include "resolve-undo.h" #include "run-command.h" #include "strbuf.h" @@ -29,6 +33,7 @@ #include "csum-file.h" #include "promisor-remote.h" #include "hook.h" +#include "wrapper.h" /* Mask for the name length in ce_flags in the on-disk index */ diff --git a/rebase-interactive.c b/rebase-interactive.c index c151db0ad2..79ed61b9fa 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -1,11 +1,14 @@ #include "cache.h" #include "commit.h" +#include "environment.h" +#include "gettext.h" #include "sequencer.h" #include "rebase-interactive.h" #include "strbuf.h" #include "commit-slab.h" #include "config.h" #include "dir.h" +#include "wrapper.h" static const char edit_todo_list_advice[] = N_("You can fix this with 'git rebase --edit-todo' " @@ -1,3 +1,4 @@ +#include "git-compat-util.h" #include "rebase.h" #include "config.h" #include "gettext.h" diff --git a/ref-filter.c b/ref-filter.c index c6cd131e70..df84bb7164 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1,5 +1,8 @@ -#include "builtin.h" #include "cache.h" +#include "alloc.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "parse-options.h" #include "refs.h" #include "wildmatch.h" @@ -13,7 +16,6 @@ #include "ref-filter.h" #include "revision.h" #include "utf8.h" -#include "git-compat-util.h" #include "version.h" #include "trailer.h" #include "wt-status.h" @@ -282,7 +284,8 @@ static int refname_atom_parser_internal(struct refname_atom *atom, const char *a return 0; } -static int remote_ref_atom_parser(struct ref_format *format, struct used_atom *atom, +static int remote_ref_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { struct string_list params = STRING_LIST_INIT_DUP; @@ -329,7 +332,8 @@ static int remote_ref_atom_parser(struct ref_format *format, struct used_atom *a return 0; } -static int objecttype_atom_parser(struct ref_format *format, struct used_atom *atom, +static int objecttype_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (arg) @@ -341,7 +345,8 @@ static int objecttype_atom_parser(struct ref_format *format, struct used_atom *a return 0; } -static int objectsize_atom_parser(struct ref_format *format, struct used_atom *atom, +static int objectsize_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (!arg) { @@ -361,7 +366,8 @@ static int objectsize_atom_parser(struct ref_format *format, struct used_atom *a return 0; } -static int deltabase_atom_parser(struct ref_format *format, struct used_atom *atom, +static int deltabase_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (arg) @@ -373,7 +379,8 @@ static int deltabase_atom_parser(struct ref_format *format, struct used_atom *at return 0; } -static int body_atom_parser(struct ref_format *format, struct used_atom *atom, +static int body_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (arg) @@ -382,7 +389,8 @@ static int body_atom_parser(struct ref_format *format, struct used_atom *atom, return 0; } -static int subject_atom_parser(struct ref_format *format, struct used_atom *atom, +static int subject_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (!arg) @@ -394,7 +402,8 @@ static int subject_atom_parser(struct ref_format *format, struct used_atom *atom return 0; } -static int trailers_atom_parser(struct ref_format *format, struct used_atom *atom, +static int trailers_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { atom->u.contents.trailer_opts.no_divider = 1; @@ -448,8 +457,9 @@ static int contents_atom_parser(struct ref_format *format, struct used_atom *ato return 0; } -static int raw_atom_parser(struct ref_format *format, struct used_atom *atom, - const char *arg, struct strbuf *err) +static int raw_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, + const char *arg, struct strbuf *err) { if (!arg) atom->u.raw_data.option = RAW_BARE; @@ -460,7 +470,8 @@ static int raw_atom_parser(struct ref_format *format, struct used_atom *atom, return 0; } -static int oid_atom_parser(struct ref_format *format, struct used_atom *atom, +static int oid_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (!arg) @@ -479,7 +490,8 @@ static int oid_atom_parser(struct ref_format *format, struct used_atom *atom, return 0; } -static int person_email_atom_parser(struct ref_format *format, struct used_atom *atom, +static int person_email_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (!arg) @@ -493,7 +505,8 @@ static int person_email_atom_parser(struct ref_format *format, struct used_atom return 0; } -static int refname_atom_parser(struct ref_format *format, struct used_atom *atom, +static int refname_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { return refname_atom_parser_internal(&atom->u.refname, arg, atom->name, err); @@ -510,7 +523,8 @@ static align_type parse_align_position(const char *s) return -1; } -static int align_atom_parser(struct ref_format *format, struct used_atom *atom, +static int align_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { struct align *align = &atom->u.align; @@ -562,7 +576,8 @@ static int align_atom_parser(struct ref_format *format, struct used_atom *atom, return 0; } -static int if_atom_parser(struct ref_format *format, struct used_atom *atom, +static int if_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (!arg) { @@ -577,7 +592,8 @@ static int if_atom_parser(struct ref_format *format, struct used_atom *atom, return 0; } -static int rest_atom_parser(struct ref_format *format, struct used_atom *atom, +static int rest_atom_parser(struct ref_format *format, + struct used_atom *atom UNUSED, const char *arg, struct strbuf *err) { if (arg) @@ -586,7 +602,8 @@ static int rest_atom_parser(struct ref_format *format, struct used_atom *atom, return 0; } -static int head_atom_parser(struct ref_format *format, struct used_atom *atom, +static int head_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, const char *arg, struct strbuf *err) { if (arg) @@ -791,7 +808,7 @@ static void quote_formatting(struct strbuf *s, const char *str, ssize_t len, int } static int append_atom(struct atom_value *v, struct ref_formatting_state *state, - struct strbuf *unused_err) + struct strbuf *err UNUSED) { /* * Quote formatting is only done when the stack has a single @@ -841,7 +858,7 @@ static void end_align_handler(struct ref_formatting_stack **stack) } static int align_atom_handler(struct atom_value *atomv, struct ref_formatting_state *state, - struct strbuf *unused_err) + struct strbuf *err UNUSED) { struct ref_formatting_stack *new_stack; @@ -888,7 +905,7 @@ static void if_then_else_handler(struct ref_formatting_stack **stack) } static int if_atom_handler(struct atom_value *atomv, struct ref_formatting_state *state, - struct strbuf *unused_err) + struct strbuf *err UNUSED) { struct ref_formatting_stack *new_stack; struct if_then_else *if_then_else = xcalloc(1, @@ -915,7 +932,8 @@ static int is_empty(struct strbuf *buf) return cur == end; } -static int then_atom_handler(struct atom_value *atomv, struct ref_formatting_state *state, +static int then_atom_handler(struct atom_value *atomv UNUSED, + struct ref_formatting_state *state, struct strbuf *err) { struct ref_formatting_stack *cur = state->stack; @@ -952,7 +970,8 @@ static int then_atom_handler(struct atom_value *atomv, struct ref_formatting_sta return 0; } -static int else_atom_handler(struct atom_value *atomv, struct ref_formatting_state *state, +static int else_atom_handler(struct atom_value *atomv UNUSED, + struct ref_formatting_state *state, struct strbuf *err) { struct ref_formatting_stack *prev = state->stack; @@ -973,7 +992,8 @@ static int else_atom_handler(struct atom_value *atomv, struct ref_formatting_sta return 0; } -static int end_atom_handler(struct atom_value *atomv, struct ref_formatting_state *state, +static int end_atom_handler(struct atom_value *atomv UNUSED, + struct ref_formatting_state *state, struct strbuf *err) { struct ref_formatting_stack *current = state->stack; @@ -1824,7 +1844,7 @@ static void lazy_init_worktree_map(void) populate_worktree_map(&(ref_to_worktree_map.map), ref_to_worktree_map.worktrees); } -static char *get_worktree_path(const struct used_atom *atom, const struct ref_array_item *ref) +static char *get_worktree_path(const struct ref_array_item *ref) { struct hashmap_entry entry, *e; struct ref_to_worktree_entry *lookup_result; @@ -1883,7 +1903,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) refname = get_refname(atom, ref); else if (atom_type == ATOM_WORKTREEPATH) { if (ref->kind == FILTER_REFS_BRANCHES) - v->s = get_worktree_path(atom, ref); + v->s = get_worktree_path(ref); else v->s = xstrdup(""); continue; diff --git a/ref-filter.h b/ref-filter.h index aa0eea4ecf..cc811c2cad 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -1,6 +1,7 @@ #ifndef REF_FILTER_H #define REF_FILTER_H +#include "gettext.h" #include "oid-array.h" #include "refs.h" #include "commit.h" diff --git a/reflog-walk.c b/reflog-walk.c index 8a4d8fa3bd..4ba1a10c82 100644 --- a/reflog-walk.c +++ b/reflog-walk.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "commit.h" #include "refs.h" #include "diff.h" diff --git a/reflog-walk.h b/reflog-walk.h index 8076f10d9f..4d93a26957 100644 --- a/reflog-walk.h +++ b/reflog-walk.h @@ -1,8 +1,6 @@ #ifndef REFLOG_WALK_H #define REFLOG_WALK_H -#include "cache.h" - struct commit; struct reflog_walk_info; struct date_mode; @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "gettext.h" #include "object-store.h" #include "reflog.h" #include "refs.h" @@ -3,8 +3,12 @@ */ #include "cache.h" +#include "alloc.h" #include "config.h" +#include "environment.h" #include "hashmap.h" +#include "gettext.h" +#include "hex.h" #include "lockfile.h" #include "iterator.h" #include "refs.h" @@ -18,9 +22,11 @@ #include "worktree.h" #include "strvec.h" #include "repository.h" +#include "setup.h" #include "sigchain.h" #include "date.h" #include "commit.h" +#include "wrapper.h" /* * List of all available backends @@ -1,7 +1,6 @@ #ifndef REFS_H #define REFS_H -#include "cache.h" #include "commit.h" struct object_id; diff --git a/refs/debug.c b/refs/debug.c index eed8bc94b0..adc34c836f 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -1,4 +1,5 @@ - +#include "git-compat-util.h" +#include "hex.h" #include "refs-internal.h" #include "trace.h" diff --git a/refs/files-backend.c b/refs/files-backend.c index b89954355d..e6a6971381 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1,16 +1,23 @@ #include "../cache.h" #include "../config.h" +#include "../environment.h" +#include "../gettext.h" +#include "../hex.h" #include "../refs.h" #include "refs-internal.h" #include "ref-cache.h" #include "packed-backend.h" +#include "../ident.h" #include "../iterator.h" #include "../dir-iterator.h" #include "../lockfile.h" #include "../object.h" #include "../dir.h" #include "../chdir-notify.h" -#include "worktree.h" +#include "../setup.h" +#include "../worktree.h" +#include "../wrapper.h" +#include "../write-or-die.h" /* * This backend uses the following flags in `ref_update::flags` for diff --git a/refs/iterator.c b/refs/iterator.c index c9fd0bcaf9..6b680f610e 100644 --- a/refs/iterator.c +++ b/refs/iterator.c @@ -3,7 +3,7 @@ * documentation about the design and use of reference iterators. */ -#include "cache.h" +#include "git-compat-util.h" #include "refs.h" #include "refs/refs-internal.h" #include "iterator.h" diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 6f5a0709fb..1eba1015dd 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -1,11 +1,15 @@ #include "../cache.h" +#include "../alloc.h" #include "../config.h" +#include "../gettext.h" +#include "../hex.h" #include "../refs.h" #include "refs-internal.h" #include "packed-backend.h" #include "../iterator.h" #include "../lockfile.h" #include "../chdir-notify.h" +#include "../write-or-die.h" enum mmap_strategy { /* diff --git a/refs/ref-cache.c b/refs/ref-cache.c index 32afd8a40b..dc1ca49c85 100644 --- a/refs/ref-cache.c +++ b/refs/ref-cache.c @@ -1,4 +1,5 @@ -#include "../cache.h" +#include "../git-compat-util.h" +#include "../alloc.h" #include "../refs.h" #include "refs-internal.h" #include "ref-cache.h" diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 69f93b0e2a..a85d113123 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -1,7 +1,6 @@ #ifndef REFS_REFS_INTERNAL_H #define REFS_REFS_INTERNAL_H -#include "cache.h" #include "refs.h" #include "iterator.h" @@ -1,4 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" +#include "gettext.h" +#include "hex.h" #include "strvec.h" #include "refs.h" #include "refspec.h" diff --git a/remote-curl.c b/remote-curl.c index a76b6405eb..0f2410da8e 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -1,5 +1,9 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "remote.h" #include "connect.h" #include "strbuf.h" @@ -14,9 +18,11 @@ #include "credential.h" #include "oid-array.h" #include "send-pack.h" +#include "setup.h" #include "protocol.h" #include "quote.h" #include "transport.h" +#include "write-or-die.h" static struct remote *remote; /* always ends with a trailing slash */ @@ -1,5 +1,10 @@ #include "cache.h" +#include "abspath.h" +#include "alloc.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "remote.h" #include "urlmatch.h" #include "refs.h" @@ -10,6 +15,7 @@ #include "revision.h" #include "dir.h" #include "tag.h" +#include "setup.h" #include "string-list.h" #include "strvec.h" #include "commit-reach.h" @@ -1,7 +1,6 @@ #ifndef REMOTE_H #define REMOTE_H -#include "cache.h" #include "parse-options.h" #include "hashmap.h" #include "refspec.h" diff --git a/replace-object.c b/replace-object.c index 320be2522d..e98825d585 100644 --- a/replace-object.c +++ b/replace-object.c @@ -1,4 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "gettext.h" +#include "hex.h" #include "oidmap.h" #include "object-store.h" #include "replace-object.h" diff --git a/replace-object.h b/replace-object.h index 3fbc32eb7b..500482b02b 100644 --- a/replace-object.h +++ b/replace-object.h @@ -5,6 +5,14 @@ #include "repository.h" #include "object-store.h" +/* + * Do replace refs need to be checked this run? This variable is + * initialized to true unless --no-replace-object is used or + * $GIT_NO_REPLACE_OBJECTS is set, but is set to false by some + * commands that do not want replace references to be active. + */ +extern int read_replace_refs; + struct replace_object { struct oidmap_entry original; struct object_id replacement; diff --git a/repo-settings.c b/repo-settings.c index 3dbd3f0e2e..0a6c0b381f 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "repository.h" #include "midx.h" diff --git a/repository.c b/repository.c index 937fa974b3..f6d9f5db08 100644 --- a/repository.c +++ b/repository.c @@ -4,12 +4,14 @@ */ #define USE_THE_INDEX_VARIABLE #include "cache.h" +#include "abspath.h" #include "repository.h" #include "object-store.h" #include "config.h" #include "object.h" #include "lockfile.h" #include "remote.h" +#include "setup.h" #include "submodule-config.h" #include "sparse-index.h" #include "promisor-remote.h" diff --git a/repository.h b/repository.h index e8c67ffe16..15a8afc5fb 100644 --- a/repository.h +++ b/repository.h @@ -1,7 +1,6 @@ #ifndef REPOSITORY_H #define REPOSITORY_H -#include "git-compat-util.h" #include "path.h" struct config_set; @@ -1,5 +1,9 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "abspath.h" +#include "alloc.h" #include "config.h" +#include "gettext.h" +#include "hex.h" #include "lockfile.h" #include "string-list.h" #include "rerere.h" @@ -12,6 +16,7 @@ #include "object-store.h" #include "hash-lookup.h" #include "strmap.h" +#include "wrapper.h" #define RESOLVED 0 #define PUNTED 1 @@ -1,6 +1,7 @@ #ifndef RERERE_H #define RERERE_H +#include "gettext.h" #include "string-list.h" struct pathspec; @@ -1,5 +1,7 @@ #include "git-compat-util.h" #include "cache-tree.h" +#include "gettext.h" +#include "hex.h" #include "lockfile.h" #include "refs.h" #include "reset.h" diff --git a/revision.c b/revision.c index 79e78b6f7e..cd3e841433 100644 --- a/revision.c +++ b/revision.c @@ -1,5 +1,9 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "object-store.h" #include "tag.h" #include "blob.h" @@ -25,6 +29,7 @@ #include "bisect.h" #include "packfile.h" #include "worktree.h" +#include "setup.h" #include "strvec.h" #include "commit-reach.h" #include "commit-graph.h" @@ -1575,7 +1580,8 @@ void exclude_hidden_refs(struct ref_exclusions *exclusions, const char *section) { struct exclude_hidden_refs_cb cb; - if (strcmp(section, "receive") && strcmp(section, "uploadpack")) + if (strcmp(section, "fetch") && strcmp(section, "receive") && + strcmp(section, "uploadpack")) die(_("unsupported section for hidden refs: %s"), section); if (exclusions->hidden_refs_configured) @@ -3441,8 +3447,8 @@ void reset_revision_walk(void) } static int mark_uninteresting(const struct object_id *oid, - struct packed_git *pack, - uint32_t pos, + struct packed_git *pack UNUSED, + uint32_t pos UNUSED, void *cb) { struct rev_info *revs = cb; @@ -4160,7 +4166,7 @@ static struct commit *get_revision_1(struct rev_info *revs) * Return true for entries that have not yet been shown. (This is an * object_array_each_func_t.) */ -static int entry_unshown(struct object_array_entry *entry, void *cb_data_unused) +static int entry_unshown(struct object_array_entry *entry, void *cb_data UNUSED) { return !(entry->item->flags & SHOWN); } diff --git a/revision.h b/revision.h index eeb91677d0..742700504a 100644 --- a/revision.h +++ b/revision.h @@ -8,6 +8,7 @@ #include "pretty.h" #include "diff.h" #include "commit-slab-decl.h" +#include "ident.h" #include "list-objects-filter-options.h" /** diff --git a/run-command.c b/run-command.c index 6bd16acb06..614d48fa9a 100644 --- a/run-command.c +++ b/run-command.c @@ -1,6 +1,8 @@ #include "cache.h" #include "run-command.h" +#include "environment.h" #include "exec-cmd.h" +#include "gettext.h" #include "sigchain.h" #include "strvec.h" #include "thread-utils.h" @@ -341,19 +343,19 @@ static void child_close_pair(int fd[2]) child_close(fd[1]); } -static void child_error_fn(const char *err, va_list params) +static void child_error_fn(const char *err UNUSED, va_list params UNUSED) { const char msg[] = "error() should not be called in child\n"; xwrite(2, msg, sizeof(msg) - 1); } -static void child_warn_fn(const char *err, va_list params) +static void child_warn_fn(const char *err UNUSED, va_list params UNUSED) { const char msg[] = "warn() should not be called in child\n"; xwrite(2, msg, sizeof(msg) - 1); } -static void NORETURN child_die_fn(const char *err, va_list params) +static void NORETURN child_die_fn(const char *err UNUSED, va_list params UNUSED) { const char msg[] = "die() should not be called in child\n"; xwrite(2, msg, sizeof(msg) - 1); @@ -3,6 +3,7 @@ */ #include "cache.h" +#include "abspath.h" #include "gettext.h" #include "parse-options.h" #include "config.h" @@ -14,6 +15,7 @@ #include "dir.h" #include "packfile.h" #include "help.h" +#include "setup.h" static void setup_enlistment_directory(int argc, const char **argv, const char * const *usagestr, diff --git a/send-pack.c b/send-pack.c index 8f8b3d986c..72ebb7b61a 100644 --- a/send-pack.c +++ b/send-pack.c @@ -1,6 +1,8 @@ -#include "builtin.h" +#include "git-compat-util.h" #include "config.h" #include "commit.h" +#include "gettext.h" +#include "hex.h" #include "refs.h" #include "object-store.h" #include "pkt-line.h" @@ -14,8 +16,9 @@ #include "version.h" #include "oid-array.h" #include "gpg-interface.h" -#include "cache.h" #include "shallow.h" +#include "trace2.h" +#include "write-or-die.h" int option_parse_push_signed(const struct option *opt, const char *arg, int unset) diff --git a/sequencer.c b/sequencer.c index f8f4e72112..1a315ac13c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1,5 +1,10 @@ #include "cache.h" +#include "abspath.h" +#include "alloc.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "lockfile.h" #include "dir.h" #include "object-store.h" @@ -36,6 +41,7 @@ #include "rebase-interactive.h" #include "reset.h" #include "branch.h" +#include "wrapper.h" #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION" @@ -263,10 +269,6 @@ static int git_sequencer_config(const char *k, const char *v, void *cb) if (opts->action == REPLAY_REVERT && !strcmp(k, "revert.reference")) opts->commit_use_reference = git_config_bool(k, v); - status = git_gpg_config(k, v, NULL); - if (status) - return status; - return git_diff_basic_config(k, v, NULL); } @@ -2928,13 +2930,18 @@ static int populate_opts_cb(const char *key, const char *value, void *data) void parse_strategy_opts(struct replay_opts *opts, char *raw_opts) { int i; + int count; char *strategy_opts_string = raw_opts; if (*strategy_opts_string == ' ') strategy_opts_string++; - opts->xopts_nr = split_cmdline(strategy_opts_string, - (const char ***)&opts->xopts); + count = split_cmdline(strategy_opts_string, + (const char ***)&opts->xopts); + if (count < 0) + die(_("could not split '%s': %s"), strategy_opts_string, + split_cmdline_strerror(count)); + opts->xopts_nr = count; for (i = 0; i < opts->xopts_nr; i++) { const char *arg = opts->xopts[i]; diff --git a/sequencer.h b/sequencer.h index 3bcdfa1b58..33dbaf5b66 100644 --- a/sequencer.h +++ b/sequencer.h @@ -1,11 +1,11 @@ #ifndef SEQUENCER_H #define SEQUENCER_H -#include "cache.h" #include "strbuf.h" #include "wt-status.h" struct commit; +struct index_state; struct repository; const char *git_path_commit_editmsg(void); @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "repository.h" #include "config.h" #include "pkt-line.h" @@ -8,17 +8,18 @@ #include "serve.h" #include "upload-pack.h" #include "bundle-uri.h" +#include "trace2.h" static int advertise_sid = -1; static int client_hash_algo = GIT_HASH_SHA1; -static int always_advertise(struct repository *r, - struct strbuf *value) +static int always_advertise(struct repository *r UNUSED, + struct strbuf *value UNUSED) { return 1; } -static int agent_advertise(struct repository *r, +static int agent_advertise(struct repository *r UNUSED, struct strbuf *value) { if (value) @@ -34,7 +35,7 @@ static int object_format_advertise(struct repository *r, return 1; } -static void object_format_receive(struct repository *r, +static void object_format_receive(struct repository *r UNUSED, const char *algo_name) { if (!algo_name) @@ -48,7 +49,7 @@ static void object_format_receive(struct repository *r, static int session_id_advertise(struct repository *r, struct strbuf *value) { if (advertise_sid == -1 && - git_config_get_bool("transfer.advertisesid", &advertise_sid)) + repo_config_get_bool(r, "transfer.advertisesid", &advertise_sid)) advertise_sid = 0; if (!advertise_sid) return 0; @@ -57,7 +58,7 @@ static int session_id_advertise(struct repository *r, struct strbuf *value) return 1; } -static void session_id_receive(struct repository *r, +static void session_id_receive(struct repository *r UNUSED, const char *client_sid) { if (!client_sid) diff --git a/server-info.c b/server-info.c index 0ec6c0c165..355b6e01a5 100644 --- a/server-info.c +++ b/server-info.c @@ -1,5 +1,8 @@ #include "cache.h" +#include "alloc.h" #include "dir.h" +#include "environment.h" +#include "hex.h" #include "repository.h" #include "refs.h" #include "object.h" @@ -8,6 +11,7 @@ #include "packfile.h" #include "object-store.h" #include "strbuf.h" +#include "wrapper.h" struct update_info_ctx { FILE *cur_fp; @@ -1,7 +1,11 @@ #include "cache.h" +#include "abspath.h" +#include "environment.h" +#include "gettext.h" #include "repository.h" #include "config.h" #include "dir.h" +#include "setup.h" #include "string-list.h" #include "chdir-notify.h" #include "promisor-remote.h" diff --git a/setup.h b/setup.h new file mode 100644 index 0000000000..4c1ca9d0c9 --- /dev/null +++ b/setup.h @@ -0,0 +1,168 @@ +#ifndef SETUP_H +#define SETUP_H + +#include "string-list.h" + +int is_inside_git_dir(void); +int is_inside_work_tree(void); +int get_common_dir_noenv(struct strbuf *sb, const char *gitdir); +int get_common_dir(struct strbuf *sb, const char *gitdir); + +/* + * Return true if the given path is a git directory; note that this _just_ + * looks at the directory itself. If you want to know whether "foo/.git" + * is a repository, you must feed that path, not just "foo". + */ +int is_git_directory(const char *path); + +/* + * Return 1 if the given path is the root of a git repository or + * submodule, else 0. Will not return 1 for bare repositories with the + * exception of creating a bare repository in "foo/.git" and calling + * is_git_repository("foo"). + * + * If we run into read errors, we err on the side of saying "yes, it is", + * as we usually consider sub-repos precious, and would prefer to err on the + * side of not disrupting or deleting them. + */ +int is_nonbare_repository_dir(struct strbuf *path); + +#define READ_GITFILE_ERR_STAT_FAILED 1 +#define READ_GITFILE_ERR_NOT_A_FILE 2 +#define READ_GITFILE_ERR_OPEN_FAILED 3 +#define READ_GITFILE_ERR_READ_FAILED 4 +#define READ_GITFILE_ERR_INVALID_FORMAT 5 +#define READ_GITFILE_ERR_NO_PATH 6 +#define READ_GITFILE_ERR_NOT_A_REPO 7 +#define READ_GITFILE_ERR_TOO_LARGE 8 +void read_gitfile_error_die(int error_code, const char *path, const char *dir); +const char *read_gitfile_gently(const char *path, int *return_error_code); +#define read_gitfile(path) read_gitfile_gently((path), NULL) +const char *resolve_gitdir_gently(const char *suspect, int *return_error_code); +#define resolve_gitdir(path) resolve_gitdir_gently((path), NULL) + +void setup_work_tree(void); +/* + * Find the commondir and gitdir of the repository that contains the current + * working directory, without changing the working directory or other global + * state. The result is appended to commondir and gitdir. If the discovered + * gitdir does not correspond to a worktree, then 'commondir' and 'gitdir' will + * both have the same result appended to the buffer. The return value is + * either 0 upon success and non-zero if no repository was found. + */ +int discover_git_directory(struct strbuf *commondir, + struct strbuf *gitdir); +const char *setup_git_directory_gently(int *); +const char *setup_git_directory(void); +char *prefix_path(const char *prefix, int len, const char *path); +char *prefix_path_gently(const char *prefix, int len, int *remaining, const char *path); + +int check_filename(const char *prefix, const char *name); +void verify_filename(const char *prefix, + const char *name, + int diagnose_misspelt_rev); +void verify_non_filename(const char *prefix, const char *name); +int path_inside_repo(const char *prefix, const char *path); + +void sanitize_stdfds(void); +int daemonize(void); + +/* + * GIT_REPO_VERSION is the version we write by default. The + * _READ variant is the highest number we know how to + * handle. + */ +#define GIT_REPO_VERSION 0 +#define GIT_REPO_VERSION_READ 1 + +/* + * You _have_ to initialize a `struct repository_format` using + * `= REPOSITORY_FORMAT_INIT` before calling `read_repository_format()`. + */ +struct repository_format { + int version; + int precious_objects; + char *partial_clone; /* value of extensions.partialclone */ + int worktree_config; + int is_bare; + int hash_algo; + int sparse_index; + char *work_tree; + struct string_list unknown_extensions; + struct string_list v1_only_extensions; +}; + +/* + * Always use this to initialize a `struct repository_format` + * to a well-defined, default state before calling + * `read_repository()`. + */ +#define REPOSITORY_FORMAT_INIT \ +{ \ + .version = -1, \ + .is_bare = -1, \ + .hash_algo = GIT_HASH_SHA1, \ + .unknown_extensions = STRING_LIST_INIT_DUP, \ + .v1_only_extensions = STRING_LIST_INIT_DUP, \ +} + +/* + * Read the repository format characteristics from the config file "path" into + * "format" struct. Returns the numeric version. On error, or if no version is + * found in the configuration, -1 is returned, format->version is set to -1, + * and all other fields in the struct are set to the default configuration + * (REPOSITORY_FORMAT_INIT). Always initialize the struct using + * REPOSITORY_FORMAT_INIT before calling this function. + */ +int read_repository_format(struct repository_format *format, const char *path); + +/* + * Free the memory held onto by `format`, but not the struct itself. + * (No need to use this after `read_repository_format()` fails.) + */ +void clear_repository_format(struct repository_format *format); + +/* + * Verify that the repository described by repository_format is something we + * can read. If it is, return 0. Otherwise, return -1, and "err" will describe + * any errors encountered. + */ +int verify_repository_format(const struct repository_format *format, + struct strbuf *err); + +/* + * Check the repository format version in the path found in get_git_dir(), + * and die if it is a version we don't understand. Generally one would + * set_git_dir() before calling this, and use it only for "are we in a valid + * repo?". + * + * If successful and fmt is not NULL, fill fmt with data. + */ +void check_repository_format(struct repository_format *fmt); + +/* + * NOTE NOTE NOTE!! + * + * PERM_UMASK, OLD_PERM_GROUP and OLD_PERM_EVERYBODY enumerations must + * not be changed. Old repositories have core.sharedrepository written in + * numeric format, and therefore these values are preserved for compatibility + * reasons. + */ +enum sharedrepo { + PERM_UMASK = 0, + OLD_PERM_GROUP = 1, + OLD_PERM_EVERYBODY = 2, + PERM_GROUP = 0660, + PERM_EVERYBODY = 0664 +}; +int git_config_perm(const char *var, const char *value); + +struct startup_info { + int have_repository; + const char *prefix; + const char *original_cwd; +}; +extern struct startup_info *startup_info; +extern const char *tmp_original_cwd; + +#endif /* SETUP_H */ diff --git a/sha1dc_git.c b/sha1dc_git.c index 5c300e812e..9b675a046e 100644 --- a/sha1dc_git.c +++ b/sha1dc_git.c @@ -1,4 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "sha1dc_git.h" +#include "hex.h" #ifdef DC_SHA1_EXTERNAL /* @@ -1,4 +1,6 @@ #include "cache.h" +#include "alloc.h" +#include "hex.h" #include "repository.h" #include "tempfile.h" #include "lockfile.h" @@ -15,6 +17,7 @@ #include "list-objects.h" #include "commit-reach.h" #include "shallow.h" +#include "wrapper.h" void set_alternate_shallow_file(struct repository *r, const char *path, int override) { @@ -6,6 +6,8 @@ #include "repository.h" #include "strbuf.h" +struct oid_array; + void set_alternate_shallow_file(struct repository *r, const char *path, int override); int register_shallow(struct repository *r, const struct object_id *oid); int unregister_shallow(const struct object_id *oid); @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "quote.h" #include "exec-cmd.h" #include "strbuf.h" diff --git a/sideband.c b/sideband.c index 85bddfdcd4..0af582858b 100644 --- a/sideband.c +++ b/sideband.c @@ -1,9 +1,11 @@ #include "cache.h" #include "color.h" #include "config.h" +#include "gettext.h" #include "sideband.h" #include "help.h" #include "pkt-line.h" +#include "write-or-die.h" struct keyword_entry { /* diff --git a/sigchain.c b/sigchain.c index 022677b6ab..ee778c0580 100644 --- a/sigchain.c +++ b/sigchain.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "sigchain.h" #define SIGCHAIN_MAX_SIGNALS 32 diff --git a/sparse-index.c b/sparse-index.c index 147a13386a..886054729e 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -1,4 +1,7 @@ #include "cache.h" +#include "alloc.h" +#include "environment.h" +#include "gettext.h" #include "repository.h" #include "sparse-index.h" #include "tree.h" diff --git a/split-index.c b/split-index.c index 5d0f04763e..c98807c655 100644 --- a/split-index.c +++ b/split-index.c @@ -1,4 +1,6 @@ #include "cache.h" +#include "alloc.h" +#include "gettext.h" #include "split-index.h" #include "ewah/ewok.h" diff --git a/statinfo.h b/statinfo.h new file mode 100644 index 0000000000..e49e3054ea --- /dev/null +++ b/statinfo.h @@ -0,0 +1,24 @@ +#ifndef STATINFO_H +#define STATINFO_H + +/* + * The "cache_time" is just the low 32 bits of the + * time. It doesn't matter if it overflows - we only + * check it for equality in the 32 bits we save. + */ +struct cache_time { + uint32_t sec; + uint32_t nsec; +}; + +struct stat_data { + struct cache_time sd_ctime; + struct cache_time sd_mtime; + unsigned int sd_dev; + unsigned int sd_ino; + unsigned int sd_uid; + unsigned int sd_gid; + unsigned int sd_size; +}; + +#endif @@ -1,8 +1,14 @@ #include "cache.h" +#include "abspath.h" +#include "alloc.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "refs.h" #include "string-list.h" #include "utf8.h" #include "date.h" +#include "wrapper.h" int starts_with(const char *str, const char *prefix) { diff --git a/streaming.c b/streaming.c index 27841dc1d9..024fd796b7 100644 --- a/streaming.c +++ b/streaming.c @@ -2,11 +2,13 @@ * Copyright (c) 2011, Google Inc. */ #include "cache.h" +#include "environment.h" #include "streaming.h" #include "repository.h" #include "object-store.h" #include "replace-object.h" #include "packfile.h" +#include "wrapper.h" typedef int (*open_istream_fn)(struct git_istream *, struct repository *, diff --git a/streaming.h b/streaming.h index 5e4e6acfd0..bd27f59e57 100644 --- a/streaming.h +++ b/streaming.h @@ -3,10 +3,12 @@ */ #ifndef STREAMING_H #define STREAMING_H 1 -#include "cache.h" + +#include "object.h" /* opaque */ struct git_istream; +struct stream_filter; struct git_istream *open_istream(struct repository *, const struct object_id *, enum object_type *, unsigned long *, diff --git a/string-list.c b/string-list.c index 42bacaec55..db473f273e 100644 --- a/string-list.c +++ b/string-list.c @@ -1,5 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" #include "string-list.h" +#include "alloc.h" void string_list_init_nodup(struct string_list *list) { @@ -1,5 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" #include "strvec.h" +#include "alloc.h" +#include "hex.h" #include "strbuf.h" const char *empty_strvec[] = { NULL }; diff --git a/sub-process.c b/sub-process.c index 6d4232294d..1daf5a9752 100644 --- a/sub-process.c +++ b/sub-process.c @@ -1,6 +1,7 @@ /* * Generic implementation of background process infrastructure. */ +#include "git-compat-util.h" #include "sub-process.h" #include "sigchain.h" #include "pkt-line.h" diff --git a/sub-process.h b/sub-process.h index e85f21fa1a..6a61638a8a 100644 --- a/sub-process.h +++ b/sub-process.h @@ -1,7 +1,6 @@ #ifndef SUBPROCESS_H #define SUBPROCESS_H -#include "git-compat-util.h" #include "hashmap.h" #include "run-command.h" diff --git a/submodule-config.c b/submodule-config.c index 4245bc5975..ecf0fcf007 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -1,5 +1,9 @@ #include "cache.h" +#include "alloc.h" #include "dir.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "repository.h" #include "config.h" #include "submodule-config.h" diff --git a/submodule-config.h b/submodule-config.h index 28a8ca6bf4..c2045875bb 100644 --- a/submodule-config.h +++ b/submodule-config.h @@ -1,7 +1,6 @@ #ifndef SUBMODULE_CONFIG_CACHE_H #define SUBMODULE_CONFIG_CACHE_H -#include "cache.h" #include "config.h" #include "hashmap.h" #include "submodule.h" diff --git a/submodule.c b/submodule.c index 5936553464..d7d0a8a083 100644 --- a/submodule.c +++ b/submodule.c @@ -1,5 +1,6 @@ - #include "cache.h" +#include "abspath.h" +#include "alloc.h" #include "repository.h" #include "config.h" #include "submodule-config.h" @@ -7,6 +8,9 @@ #include "dir.h" #include "diff.h" #include "commit.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "revision.h" #include "run-command.h" #include "diffcore.h" @@ -22,6 +26,7 @@ #include "parse-options.h" #include "object-store.h" #include "commit-reach.h" +#include "setup.h" #include "shallow.h" static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF; @@ -1739,7 +1744,7 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err, return 0; } -static int fetch_start_failure(struct strbuf *err, +static int fetch_start_failure(struct strbuf *err UNUSED, void *cb, void *task_cb) { struct submodule_parallel_fetch *spf = cb; @@ -1760,7 +1765,7 @@ static int commit_missing_in_sub(const struct object_id *oid, void *data) return type != OBJ_COMMIT; } -static int fetch_finish(int retvalue, struct strbuf *err, +static int fetch_finish(int retvalue, struct strbuf *err UNUSED, void *cb, void *task_cb) { struct submodule_parallel_fetch *spf = cb; diff --git a/symlinks.c b/symlinks.c index c667baa949..27ecc93693 100644 --- a/symlinks.c +++ b/symlinks.c @@ -1,4 +1,6 @@ #include "cache.h" +#include "gettext.h" +#include "setup.h" static int threaded_check_leading_path(struct cache_def *cache, const char *name, int len, int warn_on_lstat_err); diff --git a/t/helper/test-advise.c b/t/helper/test-advise.c index cb881139f7..8a3fd0009a 100644 --- a/t/helper/test-advise.c +++ b/t/helper/test-advise.c @@ -1,7 +1,7 @@ #include "test-tool.h" -#include "cache.h" #include "advice.h" #include "config.h" +#include "setup.h" int cmd__advise_if_enabled(int argc, const char **argv) { diff --git a/t/helper/test-bitmap.c b/t/helper/test-bitmap.c index ff35f5999b..af43ee1cb5 100644 --- a/t/helper/test-bitmap.c +++ b/t/helper/test-bitmap.c @@ -1,6 +1,7 @@ #include "test-tool.h" -#include "cache.h" +#include "git-compat-util.h" #include "pack-bitmap.h" +#include "setup.h" static int bitmap_list_commits(void) { diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c index 6c900ca668..d2b30d644d 100644 --- a/t/helper/test-bloom.c +++ b/t/helper/test-bloom.c @@ -1,7 +1,8 @@ -#include "git-compat-util.h" -#include "bloom.h" #include "test-tool.h" +#include "bloom.h" +#include "hex.h" #include "commit.h" +#include "setup.h" static struct bloom_filter_settings settings = DEFAULT_BLOOM_FILTER_SETTINGS; diff --git a/t/helper/test-bundle-uri.c b/t/helper/test-bundle-uri.c index b18e760310..475058592d 100644 --- a/t/helper/test-bundle-uri.c +++ b/t/helper/test-bundle-uri.c @@ -1,6 +1,7 @@ #include "test-tool.h" #include "parse-options.h" #include "bundle-uri.h" +#include "gettext.h" #include "strbuf.h" #include "string-list.h" #include "transport.h" diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c index 9159a17301..cdaf5046f5 100644 --- a/t/helper/test-cache-tree.c +++ b/t/helper/test-cache-tree.c @@ -1,9 +1,12 @@ #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 "setup.h" static char const * const test_cache_tree_usage[] = { N_("test-tool cache-tree <options> (control|prime|update)"), diff --git a/t/helper/test-config.c b/t/helper/test-config.c index 4ba9eb6560..32d170ec30 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -1,6 +1,6 @@ #include "test-tool.h" -#include "cache.h" #include "config.h" +#include "setup.h" #include "string-list.h" /* diff --git a/t/helper/test-crontab.c b/t/helper/test-crontab.c index e6c1b1e22b..597027a96e 100644 --- a/t/helper/test-crontab.c +++ b/t/helper/test-crontab.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" /* * Usage: test-tool crontab <file> -l|<input> diff --git a/t/helper/test-ctype.c b/t/helper/test-ctype.c index b21bd672d9..534ca66441 100644 --- a/t/helper/test-ctype.c +++ b/t/helper/test-ctype.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" static int rc; diff --git a/t/helper/test-delta.c b/t/helper/test-delta.c index b15481ea59..e7d134ec25 100644 --- a/t/helper/test-delta.c +++ b/t/helper/test-delta.c @@ -11,7 +11,7 @@ #include "test-tool.h" #include "git-compat-util.h" #include "delta.h" -#include "cache.h" +#include "wrapper.h" static const char usage_str[] = "test-tool delta (-d|-p) <from_file> <data_file> <out_file>"; diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c index 454f17b1a0..715aabfbae 100644 --- a/t/helper/test-dump-cache-tree.c +++ b/t/helper/test-dump-cache-tree.c @@ -1,9 +1,10 @@ #define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" +#include "hex.h" #include "tree.h" #include "cache-tree.h" - +#include "setup.h" static void dump_one(struct cache_tree *it, const char *pfx, const char *x) { diff --git a/t/helper/test-dump-fsmonitor.c b/t/helper/test-dump-fsmonitor.c index 975f0ac890..7e9de296db 100644 --- a/t/helper/test-dump-fsmonitor.c +++ b/t/helper/test-dump-fsmonitor.c @@ -1,5 +1,6 @@ #include "test-tool.h" #include "cache.h" +#include "setup.h" int cmd__dump_fsmonitor(int ac, const char **av) { diff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c index 0ea97b8407..289a01c10a 100644 --- a/t/helper/test-dump-split-index.c +++ b/t/helper/test-dump-split-index.c @@ -1,6 +1,8 @@ #define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" +#include "hex.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 6d53683f13..415f55f31d 100644 --- a/t/helper/test-dump-untracked-cache.c +++ b/t/helper/test-dump-untracked-cache.c @@ -2,6 +2,8 @@ #include "test-tool.h" #include "cache.h" #include "dir.h" +#include "hex.h" +#include "setup.h" static int compare_untracked(const void *a_, const void *b_) { diff --git a/t/helper/test-example-decorate.c b/t/helper/test-example-decorate.c index b9d1200eb9..7c7fc8efc1 100644 --- a/t/helper/test-example-decorate.c +++ b/t/helper/test-example-decorate.c @@ -1,5 +1,5 @@ #include "test-tool.h" -#include "cache.h" +#include "git-compat-util.h" #include "object.h" #include "decorate.h" diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c index 214612846a..fd48e0ee2c 100644 --- a/t/helper/test-fast-rebase.c +++ b/t/helper/test-fast-rebase.c @@ -12,14 +12,18 @@ #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 "hex.h" #include "lockfile.h" #include "merge-ort.h" #include "refs.h" #include "revision.h" #include "sequencer.h" +#include "setup.h" #include "strvec.h" #include "tree.h" diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c index 54a4856c48..a37236cd0a 100644 --- a/t/helper/test-fsmonitor-client.c +++ b/t/helper/test-fsmonitor-client.c @@ -7,8 +7,10 @@ #include "cache.h" #include "parse-options.h" #include "fsmonitor-ipc.h" +#include "setup.h" #include "thread-utils.h" #include "trace2.h" +#include "wrapper.h" #ifndef HAVE_FSMONITOR_DAEMON_BACKEND int cmd__fsmonitor_client(int argc, const char **argv) diff --git a/t/helper/test-hash.c b/t/helper/test-hash.c index 5860dab0ff..45d829c908 100644 --- a/t/helper/test-hash.c +++ b/t/helper/test-hash.c @@ -1,5 +1,5 @@ #include "test-tool.h" -#include "cache.h" +#include "hex.h" int cmd_hash_impl(int ac, const char **av, int algo) { diff --git a/t/helper/test-json-writer.c b/t/helper/test-json-writer.c index 8c3edacc00..86887f5320 100644 --- a/t/helper/test-json-writer.c +++ b/t/helper/test-json-writer.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" #include "json-writer.h" static const char *expect_obj1 = "{\"a\":\"abc\",\"b\":42,\"c\":true}"; diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c index ab86c14c8b..06ce3a47cc 100644 --- a/t/helper/test-lazy-init-name-hash.c +++ b/t/helper/test-lazy-init-name-hash.c @@ -1,7 +1,9 @@ #define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" +#include "environment.h" #include "parse-options.h" +#include "setup.h" static int single; static int multi; diff --git a/t/helper/test-match-trees.c b/t/helper/test-match-trees.c index daadf3827a..7066f3c71d 100644 --- a/t/helper/test-match-trees.c +++ b/t/helper/test-match-trees.c @@ -1,5 +1,7 @@ #include "test-tool.h" #include "cache.h" +#include "hex.h" +#include "setup.h" #include "tree.h" int cmd__match_trees(int ac, const char **av) diff --git a/t/helper/test-oid-array.c b/t/helper/test-oid-array.c index d1324d086a..fd6f73ea03 100644 --- a/t/helper/test-oid-array.c +++ b/t/helper/test-oid-array.c @@ -1,6 +1,8 @@ #include "test-tool.h" #include "cache.h" +#include "hex.h" #include "oid-array.h" +#include "setup.h" static int print_oid(const struct object_id *oid, void *data) { diff --git a/t/helper/test-oidmap.c b/t/helper/test-oidmap.c index 7b194edde2..e2eb25ecde 100644 --- a/t/helper/test-oidmap.c +++ b/t/helper/test-oidmap.c @@ -1,6 +1,8 @@ #include "test-tool.h" #include "cache.h" +#include "hex.h" #include "oidmap.h" +#include "setup.h" #include "strbuf.h" /* key is an oid and value is a name (could be a refname for example) */ diff --git a/t/helper/test-oidtree.c b/t/helper/test-oidtree.c index d48a409f4e..edcb7e9f44 100644 --- a/t/helper/test-oidtree.c +++ b/t/helper/test-oidtree.c @@ -1,6 +1,8 @@ #include "test-tool.h" #include "cache.h" +#include "hex.h" #include "oidtree.h" +#include "setup.h" static enum cb_next print_oid(const struct object_id *oid, void *data) { diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c index f7b79daf4c..0f3fbeec53 100644 --- a/t/helper/test-pack-mtimes.c +++ b/t/helper/test-pack-mtimes.c @@ -1,9 +1,10 @@ -#include "git-compat-util.h" #include "test-tool.h" +#include "hex.h" #include "strbuf.h" #include "object-store.h" #include "packfile.h" #include "pack-mtimes.h" +#include "setup.h" static void dump_mtimes(struct packed_git *p) { diff --git a/t/helper/test-parse-pathspec-file.c b/t/helper/test-parse-pathspec-file.c index b3e08cef4b..89ecefd1cd 100644 --- a/t/helper/test-parse-pathspec-file.c +++ b/t/helper/test-parse-pathspec-file.c @@ -1,12 +1,11 @@ #include "test-tool.h" #include "parse-options.h" #include "pathspec.h" -#include "gettext.h" int cmd__parse_pathspec_file(int argc, const char **argv) { struct pathspec pathspec; - const char *pathspec_from_file = NULL; + char *pathspec_from_file = NULL; int pathspec_file_nul = 0, i; static const char *const usage[] = { @@ -29,5 +28,6 @@ int cmd__parse_pathspec_file(int argc, const char **argv) printf("%s\n", pathspec.items[i].original); clear_pathspec(&pathspec); + free(pathspec_from_file); return 0; } diff --git a/t/helper/test-partial-clone.c b/t/helper/test-partial-clone.c index 3f102cfddd..362bd64a4c 100644 --- a/t/helper/test-partial-clone.c +++ b/t/helper/test-partial-clone.c @@ -1,7 +1,8 @@ -#include "cache.h" #include "test-tool.h" +#include "hex.h" #include "repository.h" #include "object-store.h" +#include "setup.h" /* * Prints the size of the object corresponding to the given hash in a specific diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c index f69709d674..4f5ac2fadc 100644 --- a/t/helper/test-path-utils.c +++ b/t/helper/test-path-utils.c @@ -1,5 +1,8 @@ #include "test-tool.h" #include "cache.h" +#include "abspath.h" +#include "environment.h" +#include "setup.h" #include "string-list.h" #include "utf8.h" diff --git a/t/helper/test-pcre2-config.c b/t/helper/test-pcre2-config.c index 5258fdddba..5d0b2a2e10 100644 --- a/t/helper/test-pcre2-config.c +++ b/t/helper/test-pcre2-config.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" #include "grep.h" int cmd__pcre2_config(int argc, const char **argv) diff --git a/t/helper/test-pkt-line.c b/t/helper/test-pkt-line.c index c5e052e537..f4d134a145 100644 --- a/t/helper/test-pkt-line.c +++ b/t/helper/test-pkt-line.c @@ -1,6 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" #include "test-tool.h" #include "pkt-line.h" +#include "write-or-die.h" static void pack_line(const char *line) { diff --git a/t/helper/test-prio-queue.c b/t/helper/test-prio-queue.c index 133b5e6f4a..4915412e07 100644 --- a/t/helper/test-prio-queue.c +++ b/t/helper/test-prio-queue.c @@ -1,8 +1,7 @@ #include "test-tool.h" -#include "cache.h" #include "prio-queue.h" -static int intcmp(const void *va, const void *vb, void *data) +static int intcmp(const void *va, const void *vb, void *data UNUSED) { const int *a = va, *b = vb; return *a - *b; diff --git a/t/helper/test-proc-receive.c b/t/helper/test-proc-receive.c index a4b305f494..f30022d222 100644 --- a/t/helper/test-proc-receive.c +++ b/t/helper/test-proc-receive.c @@ -1,9 +1,10 @@ -#include "cache.h" +#include "test-tool.h" #include "connect.h" +#include "hex.h" #include "parse-options.h" #include "pkt-line.h" +#include "setup.h" #include "sigchain.h" -#include "test-tool.h" static const char *proc_receive_usage[] = { "test-tool proc-receive [<options>]", diff --git a/t/helper/test-progress.c b/t/helper/test-progress.c index 6cc9735b60..66acb6a06c 100644 --- a/t/helper/test-progress.c +++ b/t/helper/test-progress.c @@ -19,7 +19,6 @@ */ #define GIT_TEST_PROGRESS_ONLY #include "test-tool.h" -#include "gettext.h" #include "parse-options.h" #include "progress.h" #include "strbuf.h" diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c index b6d197722f..b0deaa106a 100644 --- a/t/helper/test-reach.c +++ b/t/helper/test-reach.c @@ -1,10 +1,14 @@ #include "test-tool.h" #include "cache.h" +#include "alloc.h" #include "commit.h" #include "commit-reach.h" #include "config.h" +#include "gettext.h" +#include "hex.h" #include "parse-options.h" #include "ref-filter.h" +#include "setup.h" #include "string-list.h" #include "tag.h" diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c index 23e9e27109..a4c24d0e42 100644 --- a/t/helper/test-read-cache.c +++ b/t/helper/test-read-cache.c @@ -2,6 +2,8 @@ #include "test-tool.h" #include "cache.h" #include "config.h" +#include "setup.h" +#include "wrapper.h" int cmd__read_cache(int argc, const char **argv) { diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c index 98b73bb8f2..78965a6ebd 100644 --- a/t/helper/test-read-graph.c +++ b/t/helper/test-read-graph.c @@ -1,9 +1,9 @@ #include "test-tool.h" -#include "cache.h" #include "commit-graph.h" #include "repository.h" #include "object-store.h" #include "bloom.h" +#include "setup.h" int cmd__read_graph(int argc, const char **argv) { diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c index 27072ba94d..05c4f2b262 100644 --- a/t/helper/test-read-midx.c +++ b/t/helper/test-read-midx.c @@ -1,9 +1,11 @@ #include "test-tool.h" #include "cache.h" +#include "hex.h" #include "midx.h" #include "repository.h" #include "object-store.h" #include "pack-bitmap.h" +#include "setup.h" static int read_midx_file(const char *object_dir, int show_objects) { diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index ae8a5648da..d1192c8c03 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -1,6 +1,7 @@ #include "test-tool.h" -#include "cache.h" +#include "hex.h" #include "refs.h" +#include "setup.h" #include "worktree.h" #include "object-store.h" #include "repository.h" diff --git a/t/helper/test-repository.c b/t/helper/test-repository.c index 56f0e3c1be..bafd2a5bf9 100644 --- a/t/helper/test-repository.c +++ b/t/helper/test-repository.c @@ -1,11 +1,13 @@ #include "test-tool.h" -#include "cache.h" #include "commit-graph.h" #include "commit.h" #include "config.h" +#include "environment.h" +#include "hex.h" #include "object-store.h" #include "object.h" #include "repository.h" +#include "setup.h" #include "tree.h" static void test_parse_commit_in_graph(const char *gitdir, const char *worktree, diff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c index c7b22cb33d..0c62b9de18 100644 --- a/t/helper/test-revision-walking.c +++ b/t/helper/test-revision-walking.c @@ -9,10 +9,10 @@ */ #include "test-tool.h" -#include "cache.h" #include "commit.h" #include "diff.h" #include "revision.h" +#include "setup.h" static void print_commit(struct commit *commit) { diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c index 3ecb830f4a..c0ed8722c8 100644 --- a/t/helper/test-run-command.c +++ b/t/helper/test-run-command.c @@ -9,8 +9,6 @@ */ #include "test-tool.h" -#include "git-compat-util.h" -#include "cache.h" #include "run-command.h" #include "strvec.h" #include "strbuf.h" @@ -18,13 +16,12 @@ #include "string-list.h" #include "thread-utils.h" #include "wildmatch.h" -#include "gettext.h" static int number_callbacks; static int parallel_next(struct child_process *cp, struct strbuf *err, void *cb, - void **task_cb) + void **task_cb UNUSED) { struct child_process *d = cb; if (number_callbacks >= 4) @@ -40,10 +37,10 @@ static int parallel_next(struct child_process *cp, return 1; } -static int no_job(struct child_process *cp, +static int no_job(struct child_process *cp UNUSED, struct strbuf *err, - void *cb, - void **task_cb) + void *cb UNUSED, + void **task_cb UNUSED) { if (err) strbuf_addstr(err, "no further jobs available\n"); @@ -52,10 +49,10 @@ static int no_job(struct child_process *cp, return 0; } -static int task_finished(int result, +static int task_finished(int result UNUSED, struct strbuf *err, - void *pp_cb, - void *pp_task_cb) + void *pp_cb UNUSED, + void *pp_task_cb UNUSED) { if (err) strbuf_addstr(err, "asking for a quick stop\n"); diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c index a26107ed70..15b7688774 100644 --- a/t/helper/test-scrap-cache-tree.c +++ b/t/helper/test-scrap-cache-tree.c @@ -2,6 +2,7 @@ #include "test-tool.h" #include "cache.h" #include "lockfile.h" +#include "setup.h" #include "tree.h" #include "cache-tree.h" diff --git a/t/helper/test-serve-v2.c b/t/helper/test-serve-v2.c index 824e5c0a95..054cbcf5d8 100644 --- a/t/helper/test-serve-v2.c +++ b/t/helper/test-serve-v2.c @@ -1,7 +1,8 @@ #include "test-tool.h" -#include "cache.h" +#include "gettext.h" #include "parse-options.h" #include "serve.h" +#include "setup.h" static char const * const serve_usage[] = { N_("test-tool serve-v2 [<options>]"), diff --git a/t/helper/test-sigchain.c b/t/helper/test-sigchain.c index d013bccdda..d1cf7377b7 100644 --- a/t/helper/test-sigchain.c +++ b/t/helper/test-sigchain.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" #include "sigchain.h" #define X(f) \ diff --git a/t/helper/test-simple-ipc.c b/t/helper/test-simple-ipc.c index 28365ff85b..3d1436da59 100644 --- a/t/helper/test-simple-ipc.c +++ b/t/helper/test-simple-ipc.c @@ -3,13 +3,14 @@ */ #include "test-tool.h" -#include "cache.h" +#include "gettext.h" #include "strbuf.h" #include "simple-ipc.h" #include "parse-options.h" #include "thread-utils.h" #include "strvec.h" #include "run-command.h" +#include "trace2.h" #ifndef SUPPORTS_SIMPLE_IPC int cmd__simple_ipc(int argc, const char **argv) diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c index 91c82d4159..66063b58de 100644 --- a/t/helper/test-submodule-config.c +++ b/t/helper/test-submodule-config.c @@ -1,6 +1,7 @@ #include "test-tool.h" #include "cache.h" #include "config.h" +#include "setup.h" #include "submodule-config.h" #include "submodule.h" diff --git a/t/helper/test-submodule-nested-repo-config.c b/t/helper/test-submodule-nested-repo-config.c index dc1c14bde3..d31f5e48ab 100644 --- a/t/helper/test-submodule-nested-repo-config.c +++ b/t/helper/test-submodule-nested-repo-config.c @@ -1,4 +1,5 @@ #include "test-tool.h" +#include "setup.h" #include "submodule-config.h" static void die_usage(const char **argv, const char *msg) diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c index e060cc6226..0e34581b20 100644 --- a/t/helper/test-submodule.c +++ b/t/helper/test-submodule.c @@ -1,8 +1,8 @@ #include "test-tool.h" #include "test-tool-utils.h" -#include "cache.h" #include "parse-options.h" #include "remote.h" +#include "setup.h" #include "submodule-config.h" #include "submodule.h" diff --git a/t/helper/test-subprocess.c b/t/helper/test-subprocess.c index ff22f2fa2c..c344f1694d 100644 --- a/t/helper/test-subprocess.c +++ b/t/helper/test-subprocess.c @@ -1,6 +1,6 @@ #include "test-tool.h" -#include "cache.h" #include "run-command.h" +#include "setup.h" int cmd__subprocess(int argc, const char **argv) { diff --git a/t/helper/test-trace2.c b/t/helper/test-trace2.c index f374c21ec3..a476df6c6c 100644 --- a/t/helper/test-trace2.c +++ b/t/helper/test-trace2.c @@ -1,9 +1,9 @@ #include "test-tool.h" -#include "cache.h" #include "strvec.h" #include "run-command.h" #include "exec-cmd.h" #include "config.h" +#include "trace2.h" typedef int(fn_unit_test)(int argc, const char **argv); diff --git a/t/helper/test-userdiff.c b/t/helper/test-userdiff.c index a2b56b9cae..680124a676 100644 --- a/t/helper/test-userdiff.c +++ b/t/helper/test-userdiff.c @@ -1,5 +1,5 @@ #include "test-tool.h" -#include "cache.h" +#include "setup.h" #include "userdiff.h" #include "config.h" diff --git a/t/helper/test-wildmatch.c b/t/helper/test-wildmatch.c index 2c103d1824..a95bb4da9b 100644 --- a/t/helper/test-wildmatch.c +++ b/t/helper/test-wildmatch.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "cache.h" int cmd__wildmatch(int argc, const char **argv) { diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c index 7d45cd61e8..a93417ed3a 100644 --- a/t/helper/test-write-cache.c +++ b/t/helper/test-write-cache.c @@ -2,6 +2,7 @@ #include "test-tool.h" #include "cache.h" #include "lockfile.h" +#include "setup.h" int cmd__write_cache(int argc, const char **argv) { diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh index 09cf5ed012..6805229dcb 100644 --- a/t/lib-httpd.sh +++ b/t/lib-httpd.sh @@ -142,6 +142,7 @@ prepare_httpd() { install_script error-smart-http.sh install_script error.sh install_script apply-one-time-perl.sh + install_script nph-custom-auth.sh ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules" @@ -227,8 +228,12 @@ test_http_push_nonff () { git commit -a -m path2 --amend && test_must_fail git push -v origin >output 2>&1 && - (cd "$REMOTE_REPO" && - test $HEAD = $(git rev-parse --verify HEAD)) + ( + cd "$REMOTE_REPO" && + echo "$HEAD" >expect && + git rev-parse --verify HEAD >actual && + test_cmp expect actual + ) ' test_expect_success 'non-fast-forward push show ref status' ' diff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf index 31f82fa093..f43a25c1f1 100644 --- a/t/lib-httpd/apache.conf +++ b/t/lib-httpd/apache.conf @@ -141,6 +141,11 @@ Alias /auth/dumb/ www/auth/dumb/ SetEnv GIT_HTTP_EXPORT_ALL SetEnv GIT_PROTOCOL </LocationMatch> +<LocationMatch /custom_auth/> + SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH} + SetEnv GIT_HTTP_EXPORT_ALL + CGIPassAuth on +</LocationMatch> ScriptAlias /smart/incomplete_length/git-upload-pack incomplete-length-upload-pack-v2-http.sh/ ScriptAlias /smart/incomplete_body/git-upload-pack incomplete-body-upload-pack-v2-http.sh/ ScriptAlias /smart/no_report/git-receive-pack error-no-report.sh/ @@ -150,6 +155,7 @@ ScriptAlias /broken_smart/ broken-smart-http.sh/ ScriptAlias /error_smart/ error-smart-http.sh/ ScriptAlias /error/ error.sh/ ScriptAliasMatch /one_time_perl/(.*) apply-one-time-perl.sh/$1 +ScriptAliasMatch /custom_auth/(.*) nph-custom-auth.sh/$1 <Directory ${GIT_EXEC_PATH}> Options FollowSymlinks </Directory> diff --git a/t/lib-httpd/nph-custom-auth.sh b/t/lib-httpd/nph-custom-auth.sh new file mode 100644 index 0000000000..f5345e775e --- /dev/null +++ b/t/lib-httpd/nph-custom-auth.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +VALID_CREDS_FILE=custom-auth.valid +CHALLENGE_FILE=custom-auth.challenge + +# +# If $VALID_CREDS_FILE exists in $HTTPD_ROOT_PATH, consider each line as a valid +# credential for the current request. Each line in the file is considered a +# valid HTTP Authorization header value. For example: +# +# Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA== +# +# If $CHALLENGE_FILE exists in $HTTPD_ROOT_PATH, output the contents as headers +# in a 401 response if no valid authentication credentials were included in the +# request. For example: +# +# WWW-Authenticate: Bearer authorize_uri="id.example.com" p=1 q=0 +# WWW-Authenticate: Basic realm="example.com" +# + +if test -n "$HTTP_AUTHORIZATION" && \ + grep -Fqsx "${HTTP_AUTHORIZATION}" "$VALID_CREDS_FILE" +then + # Note that although git-http-backend returns a status line, it + # does so using a CGI 'Status' header. Because this script is an + # No Parsed Headers (NPH) script, we must return a real HTTP + # status line. + # This is only a test script, so we don't bother to check for + # the actual status from git-http-backend and always return 200. + echo 'HTTP/1.1 200 OK' + exec "$GIT_EXEC_PATH"/git-http-backend +fi + +echo 'HTTP/1.1 401 Authorization Required' +if test -f "$CHALLENGE_FILE" +then + cat "$CHALLENGE_FILE" +fi +echo diff --git a/t/lib-patch-mode.sh b/t/lib-patch-mode.sh index cfd76bf987..89ca1f7805 100644 --- a/t/lib-patch-mode.sh +++ b/t/lib-patch-mode.sh @@ -29,8 +29,12 @@ set_and_save_state () { # verify_state <path> <expected-worktree-content> <expected-index-content> verify_state () { - test "$(cat "$1")" = "$2" && - test "$(git show :"$1")" = "$3" + echo "$2" >expect && + test_cmp expect "$1" && + + echo "$3" >expect && + git show :"$1" >actual && + test_cmp expect actual } # verify_saved_state <path> @@ -46,5 +50,6 @@ save_head () { } verify_saved_head () { - test "$(cat _head)" = "$(git rev-parse HEAD)" + git rev-parse HEAD >actual && + test_cmp _head actual } diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh index 2d31fcfda1..dee14992c5 100644 --- a/t/lib-submodule-update.sh +++ b/t/lib-submodule-update.sh @@ -168,20 +168,16 @@ replace_gitfile_with_git_dir () { # Note that this only supports submodules at the root level of the # superproject, with the default name, i.e. same as its path. test_git_directory_is_unchanged () { - ( - cd ".git/modules/$1" && - # does core.worktree point at the right place? - test "$(git config core.worktree)" = "../../../$1" && - # remove it temporarily before comparing, as - # "$1/.git/config" lacks it... - git config --unset core.worktree - ) && + # does core.worktree point at the right place? + echo "../../../$1" >expect && + git -C ".git/modules/$1" config core.worktree >actual && + test_cmp expect actual && + # remove it temporarily before comparing, as + # "$1/.git/config" lacks it... + git -C ".git/modules/$1" config --unset core.worktree && diff -r ".git/modules/$1" "$1/.git" && - ( - # ... and then restore. - cd ".git/modules/$1" && - git config core.worktree "../../../$1" - ) + # ... and then restore. + git -C ".git/modules/$1" config core.worktree "../../../$1" } test_git_directory_exists () { @@ -189,7 +185,9 @@ test_git_directory_exists () { if test -f sub1/.git then # does core.worktree point at the right place? - test "$(git -C .git/modules/$1 config core.worktree)" = "../../../$1" + echo "../../../$1" >expect && + git -C ".git/modules/$1" config core.worktree >actual && + test_cmp expect actual fi } diff --git a/t/t0001-init.sh b/t/t0001-init.sh index d479303efa..30a6edca1d 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -598,9 +598,14 @@ test_expect_success 'invalid default branch name' ' test_expect_success 'branch -m with the initial branch' ' git init rename-initial && git -C rename-initial branch -m renamed && - test renamed = $(git -C rename-initial symbolic-ref --short HEAD) && + echo renamed >expect && + git -C rename-initial symbolic-ref --short HEAD >actual && + test_cmp expect actual && + git -C rename-initial branch -m renamed again && - test again = $(git -C rename-initial symbolic-ref --short HEAD) + echo again >expect && + git -C rename-initial symbolic-ref --short HEAD >actual && + test_cmp expect actual ' test_done diff --git a/t/t0002-gitfile.sh b/t/t0002-gitfile.sh index 26eaca095a..e013d38f48 100755 --- a/t/t0002-gitfile.sh +++ b/t/t0002-gitfile.sh @@ -33,7 +33,9 @@ test_expect_success 'bad setup: invalid .git file path' ' test_expect_success 'final setup + check rev-parse --git-dir' ' echo "gitdir: $REAL" >.git && - test "$REAL" = "$(git rev-parse --git-dir)" + echo "$REAL" >expect && + git rev-parse --git-dir >actual && + test_cmp expect actual ' test_expect_success 'check hash-object' ' diff --git a/t/t0027-auto-crlf.sh b/t/t0027-auto-crlf.sh index a94ac1eae3..2f57c8669c 100755 --- a/t/t0027-auto-crlf.sh +++ b/t/t0027-auto-crlf.sh @@ -70,7 +70,8 @@ create_NNO_MIX_files () { cp CRLF ${pfx}_CRLF.txt && cp CRLF_mix_LF ${pfx}_CRLF_mix_LF.txt && cp LF_mix_CR ${pfx}_LF_mix_CR.txt && - cp CRLF_nul ${pfx}_CRLF_nul.txt + cp CRLF_nul ${pfx}_CRLF_nul.txt || + return 1 done done done @@ -101,7 +102,8 @@ commit_check_warn () { do fname=${pfx}_$f.txt && cp $f $fname && - git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" + git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" || + return 1 done && git commit -m "core.autocrlf $crlf" && check_warning "$lfname" ${pfx}_LF.err && @@ -121,15 +123,19 @@ commit_chk_wrnNNO () { lfmixcr=$1 ; shift crlfnul=$1 ; shift pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf} - #Commit files on top of existing file - create_gitattributes "$attr" $aeol && - for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul - do - fname=${pfx}_$f.txt && - cp $f $fname && - printf Z >>"$fname" && - git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" - done + + test_expect_success 'setup commit NNO files' ' + #Commit files on top of existing file + create_gitattributes "$attr" $aeol && + for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul + do + fname=${pfx}_$f.txt && + cp $f $fname && + printf Z >>"$fname" && + git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" || + return 1 + done + ' test_expect_success "commit NNO files crlf=$crlf attr=$attr LF" ' check_warning "$lfwarn" ${pfx}_LF.err @@ -163,15 +169,19 @@ commit_MIX_chkwrn () { lfmixcr=$1 ; shift crlfnul=$1 ; shift pfx=MIX_attr_${attr}_aeol_${aeol}_${crlf} - #Commit file with CLRF_mix_LF on top of existing file - create_gitattributes "$attr" $aeol && - for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul - do - fname=${pfx}_$f.txt && - cp CRLF_mix_LF $fname && - printf Z >>"$fname" && - git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" - done + + test_expect_success 'setup commit file with mixed EOL' ' + #Commit file with CLRF_mix_LF on top of existing file + create_gitattributes "$attr" $aeol && + for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul + do + fname=${pfx}_$f.txt && + cp CRLF_mix_LF $fname && + printf Z >>"$fname" && + git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" || + return 1 + done + ' test_expect_success "commit file with mixed EOL onto LF crlf=$crlf attr=$attr" ' check_warning "$lfwarn" ${pfx}_LF.err @@ -289,17 +299,17 @@ checkout_files () { lfmixcrlf=$1 ; shift lfmixcr=$1 ; shift crlfnul=$1 ; shift - create_gitattributes "$attr" $ident $aeol && - git config core.autocrlf $crlf && + test_expect_success "setup config for checkout attr=$attr ident=$ident aeol=$aeol core.autocrlf=$crlf" ' + create_gitattributes "$attr" $ident $aeol && + git config core.autocrlf $crlf + ' pfx=eol_${ceol}_crlf_${crlf}_attr_${attr}_ && for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul do - rm crlf_false_attr__$f.txt && - if test -z "$ceol"; then - git checkout -- crlf_false_attr__$f.txt - else - git -c core.eol=$ceol checkout -- crlf_false_attr__$f.txt - fi + test_expect_success "setup $f checkout ${ceol:+ with -c core.eol=$ceol}" ' + rm -f crlf_false_attr__$f.txt && + git ${ceol:+-c core.eol=$ceol} checkout -- crlf_false_attr__$f.txt + ' done test_expect_success "ls-files --eol attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol" ' diff --git a/t/t0055-beyond-symlinks.sh b/t/t0055-beyond-symlinks.sh index 6bada37022..c3eb1158ef 100755 --- a/t/t0055-beyond-symlinks.sh +++ b/t/t0055-beyond-symlinks.sh @@ -15,12 +15,22 @@ test_expect_success SYMLINKS setup ' test_expect_success SYMLINKS 'update-index --add beyond symlinks' ' test_must_fail git update-index --add c/d && - ! ( git ls-files | grep c/d ) + cat >expect <<-\EOF && + a + b/d + EOF + git ls-files >actual && + test_cmp expect actual ' test_expect_success SYMLINKS 'add beyond symlinks' ' test_must_fail git add c/d && - ! ( git ls-files | grep c/d ) + cat >expect <<-\EOF && + a + b/d + EOF + git ls-files >actual && + test_cmp expect actual ' test_done diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 68e29c904a..0afa3d0d31 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -10,20 +10,27 @@ TEST_PASSES_SANITIZE_LEAK=true norm_path() { expected=$(test-tool path-utils print_path "$2") - test_expect_success $3 "normalize path: $1 => $2" \ - "test \"\$(test-tool path-utils normalize_path_copy '$1')\" = '$expected'" + test_expect_success $3 "normalize path: $1 => $2" " + echo '$expected' >expect && + test-tool path-utils normalize_path_copy '$1' >actual && + test_cmp expect actual + " } relative_path() { expected=$(test-tool path-utils print_path "$3") - test_expect_success $4 "relative path: $1 $2 => $3" \ - "test \"\$(test-tool path-utils relative_path '$1' '$2')\" = '$expected'" + test_expect_success $4 "relative path: $1 $2 => $3" " + echo '$expected' >expect && + test-tool path-utils relative_path '$1' '$2' >actual && + test_cmp expect actual + " } test_submodule_relative_url() { test_expect_success "test_submodule_relative_url: $1 $2 $3 => $4" " - actual=\$(test-tool submodule resolve-relative-url '$1' '$2' '$3') && - test \"\$actual\" = '$4' + echo '$4' >expect && + test-tool submodule resolve-relative-url '$1' '$2' '$3' >actual && + test_cmp expect actual " } @@ -64,9 +71,11 @@ ancestor() { expected=$(($expected-$rootslash+$rootoff)) ;; esac - test_expect_success $4 "longest ancestor: $1 $2 => $expected" \ - "actual=\$(test-tool path-utils longest_ancestor_length '$1' '$2') && - test \"\$actual\" = '$expected'" + test_expect_success $4 "longest ancestor: $1 $2 => $expected" " + echo '$expected' >expect && + test-tool path-utils longest_ancestor_length '$1' '$2' >actual && + test_cmp expect actual + " } # Some absolute path tests should be skipped on Windows due to path mangling @@ -166,8 +175,10 @@ ancestor D:/Users/me C:/ -1 MINGW ancestor //server/share/my-directory //server/share/ 14 MINGW test_expect_success 'strip_path_suffix' ' - test c:/msysgit = $(test-tool path-utils strip_path_suffix \ - c:/msysgit/libexec//git-core libexec/git-core) + echo c:/msysgit >expect && + test-tool path-utils strip_path_suffix \ + c:/msysgit/libexec//git-core libexec/git-core >actual && + test_cmp expect actual ' test_expect_success 'absolute path rejects the empty string' ' @@ -188,35 +199,61 @@ test_expect_success 'real path rejects the empty string' ' ' test_expect_success POSIX 'real path works on absolute paths 1' ' + echo / >expect && + test-tool path-utils real_path "/" >actual && + test_cmp expect actual && + nopath="hopefully-absent-path" && - test "/" = "$(test-tool path-utils real_path "/")" && - test "/$nopath" = "$(test-tool path-utils real_path "/$nopath")" + echo "/$nopath" >expect && + test-tool path-utils real_path "/$nopath" >actual && + test_cmp expect actual ' test_expect_success 'real path works on absolute paths 2' ' - nopath="hopefully-absent-path" && # Find an existing top-level directory for the remaining tests: d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") && - test "$d" = "$(test-tool path-utils real_path "$d")" && - test "$d/$nopath" = "$(test-tool path-utils real_path "$d/$nopath")" + echo "$d" >expect && + test-tool path-utils real_path "$d" >actual && + test_cmp expect actual && + + nopath="hopefully-absent-path" && + echo "$d/$nopath" >expect && + test-tool path-utils real_path "$d/$nopath" >actual && + test_cmp expect actual ' test_expect_success POSIX 'real path removes extra leading slashes' ' + echo "/" >expect && + test-tool path-utils real_path "///" >actual && + test_cmp expect actual && + nopath="hopefully-absent-path" && - test "/" = "$(test-tool path-utils real_path "///")" && - test "/$nopath" = "$(test-tool path-utils real_path "///$nopath")" && + echo "/$nopath" >expect && + test-tool path-utils real_path "///$nopath" >actual && + test_cmp expect actual && + # Find an existing top-level directory for the remaining tests: d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") && - test "$d" = "$(test-tool path-utils real_path "//$d")" && - test "$d/$nopath" = "$(test-tool path-utils real_path "//$d/$nopath")" + echo "$d" >expect && + test-tool path-utils real_path "//$d" >actual && + test_cmp expect actual && + + echo "$d/$nopath" >expect && + test-tool path-utils real_path "//$d/$nopath" >actual && + test_cmp expect actual ' test_expect_success 'real path removes other extra slashes' ' - nopath="hopefully-absent-path" && # Find an existing top-level directory for the remaining tests: d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") && - test "$d" = "$(test-tool path-utils real_path "$d///")" && - test "$d/$nopath" = "$(test-tool path-utils real_path "$d///$nopath")" + echo "$d" >expect && + test-tool path-utils real_path "$d///" >actual && + test_cmp expect actual && + + nopath="hopefully-absent-path" && + echo "$d/$nopath" >expect && + test-tool path-utils real_path "$d///$nopath" >actual && + test_cmp expect actual ' test_expect_success SYMLINKS 'real path works on symlinks' ' @@ -227,19 +264,29 @@ test_expect_success SYMLINKS 'real path works on symlinks' ' mkdir third && dir="$(cd .git && pwd -P)" && dir2=third/../second/other/.git && - test "$dir" = "$(test-tool path-utils real_path $dir2)" && + echo "$dir" >expect && + test-tool path-utils real_path $dir2 >actual && + test_cmp expect actual && file="$dir"/index && - test "$file" = "$(test-tool path-utils real_path $dir2/index)" && + echo "$file" >expect && + test-tool path-utils real_path $dir2/index >actual && + test_cmp expect actual && basename=blub && - test "$dir/$basename" = "$(cd .git && test-tool path-utils real_path "$basename")" && + echo "$dir/$basename" >expect && + test-tool -C .git path-utils real_path "$basename" >actual && + test_cmp expect actual && ln -s ../first/file .git/syml && sym="$(cd first && pwd -P)"/file && - test "$sym" = "$(test-tool path-utils real_path "$dir2/syml")" + echo "$sym" >expect && + test-tool path-utils real_path "$dir2/syml" >actual && + test_cmp expect actual ' test_expect_success SYMLINKS 'prefix_path works with absolute paths to work tree symlinks' ' ln -s target symlink && - test "$(test-tool path-utils prefix_path prefix "$(pwd)/symlink")" = "symlink" + echo "symlink" >expect && + test-tool path-utils prefix_path prefix "$(pwd)/symlink" >actual && + test_cmp expect actual ' test_expect_success 'prefix_path works with only absolute path to work tree' ' @@ -255,7 +302,10 @@ test_expect_success 'prefix_path rejects absolute path to dir with same beginnin test_expect_success SYMLINKS 'prefix_path works with absolute path to a symlink to work tree having same beginning as work tree' ' git init repo && ln -s repo repolink && - test "a" = "$(cd repo && test-tool path-utils prefix_path prefix "$(pwd)/../repolink/a")" + echo "a" >expect && + repo_path="$(cd repo && pwd)" && + test-tool -C repo path-utils prefix_path prefix "$repo_path/../repolink/a" >actual && + test_cmp expect actual ' relative_path /foo/a/b/c/ /foo/a/b/ c/ diff --git a/t/t0100-previous.sh b/t/t0100-previous.sh index a16cc3d298..70a3223f21 100755 --- a/t/t0100-previous.sh +++ b/t/t0100-previous.sh @@ -12,7 +12,9 @@ test_expect_success 'branch -d @{-1}' ' test_commit A && git checkout -b junk && git checkout - && - test "$(git symbolic-ref HEAD)" = refs/heads/main && + echo refs/heads/main >expect && + git symbolic-ref HEAD >actual && + test_cmp expect actual && git branch -d @{-1} && test_must_fail git rev-parse --verify refs/heads/junk ' @@ -21,7 +23,9 @@ test_expect_success 'branch -d @{-12} when there is not enough switches yet' ' git reflog expire --expire=now && git checkout -b junk2 && git checkout - && - test "$(git symbolic-ref HEAD)" = refs/heads/main && + echo refs/heads/main >expect && + git symbolic-ref HEAD >actual && + test_cmp expect actual && test_must_fail git branch -d @{-12} && git rev-parse --verify refs/heads/main ' diff --git a/t/t1401-symbolic-ref.sh b/t/t1401-symbolic-ref.sh index be23be30c7..c7745e1bf6 100755 --- a/t/t1401-symbolic-ref.sh +++ b/t/t1401-symbolic-ref.sh @@ -33,7 +33,8 @@ test_expect_success 'symbolic-ref refuses non-ref for HEAD' ' reset_to_sane test_expect_success 'symbolic-ref refuses bare sha1' ' - test_must_fail git symbolic-ref HEAD $(git rev-parse HEAD) + rev=$(git rev-parse HEAD) && + test_must_fail git symbolic-ref HEAD "$rev" ' reset_to_sane diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index fdb886dfe4..bca46378b2 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -1023,4 +1023,34 @@ test_expect_success 'fsck error on gitattributes with excessive size' ' test_cmp expected actual ' +test_expect_success 'fsck detects problems in worktree index' ' + test_when_finished "git worktree remove -f wt" && + git worktree add wt && + + echo "this will be removed to break the worktree index" >wt/file && + git -C wt add file && + blob=$(git -C wt rev-parse :file) && + remove_object $blob && + + test_must_fail git fsck --name-objects >actual 2>&1 && + cat >expect <<-EOF && + missing blob $blob (.git/worktrees/wt/index:file) + EOF + test_cmp expect actual +' + +test_expect_success 'fsck reports problems in main index without filename' ' + test_when_finished "rm -f .git/index && git read-tree HEAD" && + echo "this object will be removed to break the main index" >file && + git add file && + blob=$(git rev-parse :file) && + remove_object $blob && + + test_must_fail git fsck --name-objects >actual 2>&1 && + cat >expect <<-EOF && + missing blob $blob (:file) + EOF + test_cmp expect actual +' + test_done diff --git a/t/t1504-ceiling-dirs.sh b/t/t1504-ceiling-dirs.sh index 0fafcf9dde..c1679e31d8 100755 --- a/t/t1504-ceiling-dirs.sh +++ b/t/t1504-ceiling-dirs.sh @@ -6,8 +6,12 @@ TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_prefix() { - test_expect_success "$1" \ - "test '$2' = \"\$(git rev-parse --show-prefix)\"" + local expect="$2" && + test_expect_success "$1: git rev-parse --show-prefix is '$2'" ' + echo "$expect" >expect && + git rev-parse --show-prefix >actual && + test_cmp expect actual + ' } test_fail() { diff --git a/t/t2005-checkout-index-symlinks.sh b/t/t2005-checkout-index-symlinks.sh index 112682a45a..67d18cfa10 100755 --- a/t/t2005-checkout-index-symlinks.sh +++ b/t/t2005-checkout-index-symlinks.sh @@ -22,8 +22,10 @@ test_expect_success \ git checkout-index symlink && test -f symlink' -test_expect_success \ -'the file must be the blob we added during the setup' ' -test "$(git hash-object -t blob symlink)" = $l' +test_expect_success 'the file must be the blob we added during the setup' ' + echo "$l" >expect && + git hash-object -t blob symlink >actual && + test_cmp expect actual +' test_done diff --git a/t/t2021-checkout-overwrite.sh b/t/t2021-checkout-overwrite.sh index 713c3fa603..034f62c13c 100755 --- a/t/t2021-checkout-overwrite.sh +++ b/t/t2021-checkout-overwrite.sh @@ -50,10 +50,13 @@ test_expect_success 'checkout commit with dir must not remove untracked a/b' ' test_expect_success SYMLINKS 'the symlink remained' ' - test_when_finished "rm a/b" && test -h a/b ' +test_expect_success 'cleanup after previous symlink tests' ' + rm a/b +' + test_expect_success SYMLINKS 'checkout -f must not follow symlinks when removing entries' ' git checkout -f start && mkdir dir && @@ -66,4 +69,15 @@ test_expect_success SYMLINKS 'checkout -f must not follow symlinks when removing test_path_is_file untracked/f ' +test_expect_success 'checkout --overwrite-ignore should succeed if only ignored files in the way' ' + git checkout -b df_conflict && + test_commit contents some_dir && + git checkout start && + mkdir some_dir && + echo autogenerated information >some_dir/ignore && + echo ignore >.git/info/exclude && + git checkout --overwrite-ignore df_conflict && + ! test_path_is_dir some_dir +' + test_done diff --git a/t/t2060-switch.sh b/t/t2060-switch.sh index 5a7caf958c..e247a4735b 100755 --- a/t/t2060-switch.sh +++ b/t/t2060-switch.sh @@ -146,4 +146,33 @@ test_expect_success 'tracking info copied with autoSetupMerge=inherit' ' test_cmp_config "" --default "" branch.main2.merge ' +test_expect_success 'switch back when temporarily detached and checked out elsewhere ' ' + test_when_finished " + git worktree remove wt1 ||: + git worktree remove wt2 ||: + git checkout - ||: + git branch -D shared ||: + " && + git checkout -b shared && + test_commit shared-first && + HASH1=$(git rev-parse --verify HEAD) && + test_commit shared-second && + test_commit shared-third && + HASH2=$(git rev-parse --verify HEAD) && + git worktree add wt1 -f shared && + git -C wt1 bisect start && + git -C wt1 bisect good $HASH1 && + git -C wt1 bisect bad $HASH2 && + git worktree add wt2 -f shared && + git -C wt2 bisect start && + git -C wt2 bisect good $HASH1 && + git -C wt2 bisect bad $HASH2 && + # we test in both worktrees to ensure that works + # as expected with "first" and "next" worktrees + test_must_fail git -C wt1 switch shared && + git -C wt1 switch --ignore-other-worktrees shared && + test_must_fail git -C wt2 switch shared && + git -C wt2 switch --ignore-other-worktrees shared +' + test_done diff --git a/t/t2070-restore.sh b/t/t2070-restore.sh index 7c43ddf1d9..c5d19dd973 100755 --- a/t/t2070-restore.sh +++ b/t/t2070-restore.sh @@ -137,4 +137,20 @@ test_expect_success 'restore --staged invalidates cache tree for deletions' ' test_must_fail git rev-parse HEAD:new1 ' +test_expect_success 'restore with merge options rejects --staged' ' + for opts in \ + "--staged --ours" \ + "--staged --theirs" \ + "--staged --merge" \ + "--staged --conflict=diff3" \ + "--staged --worktree --ours" \ + "--staged --worktree --theirs" \ + "--staged --worktree --merge" \ + "--staged --worktree --conflict=zdiff3" + do + test_must_fail git restore $opts . 2>err && + grep "cannot be used with --staged" err || return + done +' + test_done diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 5a169b68d6..5a8a48287c 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -245,9 +245,13 @@ test_expect_success 'git branch -M baz bam should succeed within a worktree in w ( cd bazdir && git branch -M baz bam && - test $(git rev-parse --abbrev-ref HEAD) = bam + echo bam >expect && + git rev-parse --abbrev-ref HEAD >actual && + test_cmp expect actual ) && - test $(git rev-parse --abbrev-ref HEAD) = bam && + echo bam >expect && + git rev-parse --abbrev-ref HEAD >actual && + test_cmp expect actual && rm -r bazdir && git worktree prune ' diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index d5a8ee39fc..3ce918fdb8 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -388,6 +388,20 @@ test_expect_success 'switch to branch checked out here' ' git rebase main main ' +test_expect_success 'switch to branch checked out elsewhere fails' ' + test_when_finished " + git worktree remove wt1 && + git worktree remove wt2 && + git branch -d shared + " && + git worktree add wt1 -b shared && + git worktree add wt2 -f shared && + # we test in both worktrees to ensure that works + # as expected with "first" and "next" worktrees + test_must_fail git -C wt1 rebase shared shared && + test_must_fail git -C wt2 rebase shared shared +' + test_expect_success 'switch to branch not checked out' ' git checkout main && git branch other && diff --git a/t/t3436-rebase-more-options.sh b/t/t3436-rebase-more-options.sh index 94671d3c46..c3184c9ade 100755 --- a/t/t3436-rebase-more-options.sh +++ b/t/t3436-rebase-more-options.sh @@ -40,6 +40,24 @@ test_expect_success 'setup' ' EOF ' +test_expect_success 'bad -X <strategy-option> arguments: unclosed quote' ' + cat >expect <<-\EOF && + fatal: could not split '\''--bad'\'': unclosed quote + EOF + test_expect_code 128 git rebase -X"bad argument\"" side main >out 2>actual && + test_must_be_empty out && + test_cmp expect actual +' + +test_expect_success 'bad -X <strategy-option> arguments: bad escape' ' + cat >expect <<-\EOF && + fatal: could not split '\''--bad'\'': cmdline ends with \ + EOF + test_expect_code 128 git rebase -X"bad escape \\" side main >out 2>actual && + test_must_be_empty out && + test_cmp expect actual +' + test_expect_success '--ignore-whitespace works with apply backend' ' test_must_fail git rebase --apply main side && git rebase --abort && diff --git a/t/t3700-add.sh b/t/t3700-add.sh index 51afbd7b24..82dd768944 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -106,24 +106,32 @@ test_expect_success '.gitignore test setup' ' test_expect_success '.gitignore is honored' ' git add . && - ! (git ls-files | grep "\\.ig") + git ls-files >files && + sed -n "/\\.ig/p" <files >actual && + test_must_be_empty actual ' test_expect_success 'error out when attempting to add ignored ones without -f' ' test_must_fail git add a.?? && - ! (git ls-files | grep "\\.ig") + git ls-files >files && + sed -n "/\\.ig/p" <files >actual && + test_must_be_empty actual ' test_expect_success 'error out when attempting to add ignored ones without -f' ' test_must_fail git add d.?? && - ! (git ls-files | grep "\\.ig") + git ls-files >files && + sed -n "/\\.ig/p" <files >actual && + test_must_be_empty actual ' test_expect_success 'error out when attempting to add ignored ones but add others' ' touch a.if && test_must_fail git add a.?? && - ! (git ls-files | grep "\\.ig") && - (git ls-files | grep a.if) + git ls-files >files && + sed -n "/\\.ig/p" <files >actual && + test_must_be_empty actual && + grep a.if files ' test_expect_success 'add ignored ones with -f' ' diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 3a99837d9b..b8aaece860 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -311,9 +311,11 @@ test_expect_success FILEMODE 'stage mode and hunk' ' echo content >>file && chmod +x file && printf "y\\ny\\n" | git add -p && - git diff --cached file | grep "new mode" && - git diff --cached file | grep "+content" && - test -z "$(git diff file)" + git diff --cached file >out && + grep "new mode" out && + grep "+content" out && + git diff file >out && + test_must_be_empty out ' # end of tests disabled when filemode is not usable @@ -1075,4 +1077,25 @@ test_expect_success 'show help from add--helper' ' test_cmp expect actual ' +test_expect_success 'reset -p with unmerged files' ' + test_when_finished "git checkout --force main" && + test_commit one conflict && + git checkout -B side HEAD^ && + test_commit two conflict && + test_must_fail git merge one && + + # this is a noop with only an unmerged entry + git reset -p && + + # add files that sort before and after unmerged entry + echo a >a && + echo z >z && + git add a z && + + # confirm that we can reset those files + printf "%s\n" y y | git reset -p && + git diff-index --cached --diff-filter=u HEAD >staged && + test_must_be_empty staged +' + test_done diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index f3313b8c58..ffc7c60680 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -59,6 +59,10 @@ test_expect_success setup ' test_tick && git commit -m "patchid 3" && + git checkout -b empty main && + test_tick && + git commit --allow-empty -m "empty commit" && + git checkout main ' @@ -128,6 +132,12 @@ test_expect_success 'replay did not screw up the log message' ' grep "^Side .* with .* backslash-n" actual ' +test_expect_success 'format-patch empty commit' ' + git format-patch --stdout main..empty >empty && + grep "^From " empty >from && + test_line_count = 1 from +' + test_expect_success 'extra headers' ' git config format.headers "To: R E Cipient <rcipient@example.com> " && diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 34a1261520..dc44da9c79 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -1171,6 +1171,15 @@ test_expect_success '--no-show-forced-updates' ' ) ' +for section in fetch transfer +do + test_expect_success "$section.hideRefs affects connectivity check" ' + GIT_TRACE="$PWD"/trace git -c $section.hideRefs=refs -c \ + $section.hideRefs="!refs/tags/" fetch && + grep "git rev-list .*--exclude-hidden=fetch" trace + ' +done + setup_negotiation_tip () { SERVER="$1" URL="$2" diff --git a/t/t5514-fetch-multiple.sh b/t/t5514-fetch-multiple.sh index 54f422ced3..98f034aa77 100755 --- a/t/t5514-fetch-multiple.sh +++ b/t/t5514-fetch-multiple.sh @@ -58,6 +58,13 @@ test_expect_success 'git fetch --all' ' test_cmp expect output) ' +test_expect_success 'git fetch --all --no-write-fetch-head' ' + (cd test && + rm -f .git/FETCH_HEAD && + git fetch --all --no-write-fetch-head && + test_path_is_missing .git/FETCH_HEAD) +' + test_expect_success 'git fetch --all should continue if a remote has errors' ' (git clone one test2 && cd test2 && diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 98a27a2948..19ebefa5ac 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -401,6 +401,11 @@ test_expect_success 'push with ambiguity' ' ' +test_expect_success 'push with onelevel ref' ' + mk_test testrepo heads/main && + test_must_fail git push testrepo HEAD:refs/onelevel +' + test_expect_success 'push with colon-less refspec (1)' ' mk_test testrepo heads/frotz tags/frotz && @@ -898,6 +903,13 @@ test_expect_success 'push --delete refuses empty string' ' test_must_fail git push testrepo --delete "" ' +test_expect_success 'push --delete onelevel refspecs' ' + mk_test testrepo heads/main && + git -C testrepo update-ref refs/onelevel refs/heads/main && + git push testrepo --delete refs/onelevel && + test_must_fail git -C testrepo rev-parse --verify refs/onelevel +' + test_expect_success 'warn on push to HEAD of non-bare repository' ' mk_test testrepo heads/main && ( diff --git a/t/t5522-pull-symlink.sh b/t/t5522-pull-symlink.sh index 394bc60cb8..cc5496e28f 100755 --- a/t/t5522-pull-symlink.sh +++ b/t/t5522-pull-symlink.sh @@ -79,7 +79,9 @@ test_expect_success SYMLINKS 'pushing from symlinked subdir' ' git commit -m push ./file && git push ) && - test push = $(git show HEAD:subdir/file) + echo push >expect && + git show HEAD:subdir/file >actual && + test_cmp expect actual ' test_done diff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh index b9546ef8e5..dcdbe26a08 100755 --- a/t/t5526-fetch-submodules.sh +++ b/t/t5526-fetch-submodules.sh @@ -167,6 +167,19 @@ test_expect_success "fetch --recurse-submodules recurses into submodules" ' verify_fetch_result actual.err ' +test_expect_success "fetch --recurse-submodules honors --no-write-fetch-head" ' + ( + cd downstream && + git submodule foreach --recursive \ + sh -c "cd \"\$(git rev-parse --git-dir)\" && rm -f FETCH_HEAD" && + + git fetch --recurse-submodules --no-write-fetch-head && + + git submodule foreach --recursive \ + sh -c "cd \"\$(git rev-parse --git-dir)\" && ! test -f FETCH_HEAD" + ) +' + test_expect_success "submodule.recurse option triggers recursive fetch" ' add_submodule_commits && ( diff --git a/t/t5563-simple-http-auth.sh b/t/t5563-simple-http-auth.sh new file mode 100755 index 0000000000..ccf7e54b07 --- /dev/null +++ b/t/t5563-simple-http-auth.sh @@ -0,0 +1,325 @@ +#!/bin/sh + +test_description='test http auth header and credential helper interop' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-httpd.sh + +start_httpd + +test_expect_success 'setup_credential_helper' ' + mkdir "$TRASH_DIRECTORY/bin" && + PATH=$PATH:"$TRASH_DIRECTORY/bin" && + export PATH && + + CREDENTIAL_HELPER="$TRASH_DIRECTORY/bin/git-credential-test-helper" && + write_script "$CREDENTIAL_HELPER" <<-\EOF + cmd=$1 + teefile=$cmd-query.cred + catfile=$cmd-reply.cred + sed -n -e "/^$/q" -e "p" >>$teefile + if test "$cmd" = "get" + then + cat $catfile + fi + EOF +' + +set_credential_reply () { + cat >"$TRASH_DIRECTORY/$1-reply.cred" +} + +expect_credential_query () { + cat >"$TRASH_DIRECTORY/$1-expect.cred" && + test_cmp "$TRASH_DIRECTORY/$1-expect.cred" \ + "$TRASH_DIRECTORY/$1-query.cred" +} + +per_test_cleanup () { + rm -f *.cred && + rm -f "$HTTPD_ROOT_PATH"/custom-auth.valid \ + "$HTTPD_ROOT_PATH"/custom-auth.challenge +} + +test_expect_success 'setup repository' ' + test_commit foo && + git init --bare "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + git push --mirror "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" +' + +test_expect_success 'access using basic auth' ' + test_when_finished "per_test_cleanup" && + + set_credential_reply get <<-EOF && + username=alice + password=secret-passwd + EOF + + # Basic base64(alice:secret-passwd) + cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF && + Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA== + EOF + + cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF && + WWW-Authenticate: Basic realm="example.com" + EOF + + test_config_global credential.helper test-helper && + git ls-remote "$HTTPD_URL/custom_auth/repo.git" && + + expect_credential_query get <<-EOF && + protocol=http + host=$HTTPD_DEST + wwwauth[]=Basic realm="example.com" + EOF + + expect_credential_query store <<-EOF + protocol=http + host=$HTTPD_DEST + username=alice + password=secret-passwd + EOF +' + +test_expect_success 'access using basic auth invalid credentials' ' + test_when_finished "per_test_cleanup" && + + set_credential_reply get <<-EOF && + username=baduser + password=wrong-passwd + EOF + + # Basic base64(alice:secret-passwd) + cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF && + Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA== + EOF + + cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF && + WWW-Authenticate: Basic realm="example.com" + EOF + + test_config_global credential.helper test-helper && + test_must_fail git ls-remote "$HTTPD_URL/custom_auth/repo.git" && + + expect_credential_query get <<-EOF && + protocol=http + host=$HTTPD_DEST + wwwauth[]=Basic realm="example.com" + EOF + + expect_credential_query erase <<-EOF + protocol=http + host=$HTTPD_DEST + username=baduser + password=wrong-passwd + wwwauth[]=Basic realm="example.com" + EOF +' + +test_expect_success 'access using basic auth with extra challenges' ' + test_when_finished "per_test_cleanup" && + + set_credential_reply get <<-EOF && + username=alice + password=secret-passwd + EOF + + # Basic base64(alice:secret-passwd) + cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF && + Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA== + EOF + + cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF && + WWW-Authenticate: FooBar param1="value1" param2="value2" + WWW-Authenticate: Bearer authorize_uri="id.example.com" p=1 q=0 + WWW-Authenticate: Basic realm="example.com" + EOF + + test_config_global credential.helper test-helper && + git ls-remote "$HTTPD_URL/custom_auth/repo.git" && + + expect_credential_query get <<-EOF && + protocol=http + host=$HTTPD_DEST + wwwauth[]=FooBar param1="value1" param2="value2" + wwwauth[]=Bearer authorize_uri="id.example.com" p=1 q=0 + wwwauth[]=Basic realm="example.com" + EOF + + expect_credential_query store <<-EOF + protocol=http + host=$HTTPD_DEST + username=alice + password=secret-passwd + EOF +' + +test_expect_success 'access using basic auth mixed-case wwwauth header name' ' + test_when_finished "per_test_cleanup" && + + set_credential_reply get <<-EOF && + username=alice + password=secret-passwd + EOF + + # Basic base64(alice:secret-passwd) + cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF && + Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA== + EOF + + cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF && + www-authenticate: foobar param1="value1" param2="value2" + WWW-AUTHENTICATE: BEARER authorize_uri="id.example.com" p=1 q=0 + WwW-aUtHeNtIcAtE: baSiC realm="example.com" + EOF + + test_config_global credential.helper test-helper && + git ls-remote "$HTTPD_URL/custom_auth/repo.git" && + + expect_credential_query get <<-EOF && + protocol=http + host=$HTTPD_DEST + wwwauth[]=foobar param1="value1" param2="value2" + wwwauth[]=BEARER authorize_uri="id.example.com" p=1 q=0 + wwwauth[]=baSiC realm="example.com" + EOF + + expect_credential_query store <<-EOF + protocol=http + host=$HTTPD_DEST + username=alice + password=secret-passwd + EOF +' + +test_expect_success 'access using basic auth with wwwauth header continuations' ' + test_when_finished "per_test_cleanup" && + + set_credential_reply get <<-EOF && + username=alice + password=secret-passwd + EOF + + # Basic base64(alice:secret-passwd) + cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF && + Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA== + EOF + + # Note that leading and trailing whitespace is important to correctly + # simulate a continuation/folded header. + cat >"$HTTPD_ROOT_PATH/custom-auth.challenge" <<-EOF && + WWW-Authenticate: FooBar param1="value1" + param2="value2" + WWW-Authenticate: Bearer authorize_uri="id.example.com" + p=1 + q=0 + WWW-Authenticate: Basic realm="example.com" + EOF + + test_config_global credential.helper test-helper && + git ls-remote "$HTTPD_URL/custom_auth/repo.git" && + + expect_credential_query get <<-EOF && + protocol=http + host=$HTTPD_DEST + wwwauth[]=FooBar param1="value1" param2="value2" + wwwauth[]=Bearer authorize_uri="id.example.com" p=1 q=0 + wwwauth[]=Basic realm="example.com" + EOF + + expect_credential_query store <<-EOF + protocol=http + host=$HTTPD_DEST + username=alice + password=secret-passwd + EOF +' + +test_expect_success 'access using basic auth with wwwauth header empty continuations' ' + test_when_finished "per_test_cleanup" && + + set_credential_reply get <<-EOF && + username=alice + password=secret-passwd + EOF + + # Basic base64(alice:secret-passwd) + cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF && + Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA== + EOF + + CHALLENGE="$HTTPD_ROOT_PATH/custom-auth.challenge" && + + # Note that leading and trailing whitespace is important to correctly + # simulate a continuation/folded header. + printf "">$CHALLENGE && + printf "WWW-Authenticate: FooBar param1=\"value1\"\r\n" >$CHALLENGE && + printf " \r\n" >>$CHALLENGE && + printf " param2=\"value2\"\r\n" >>$CHALLENGE && + printf "WWW-Authenticate: Bearer authorize_uri=\"id.example.com\"\r\n" >>$CHALLENGE && + printf " p=1\r\n" >>$CHALLENGE && + printf " \r\n" >>$CHALLENGE && + printf " q=0\r\n" >>$CHALLENGE && + printf "WWW-Authenticate: Basic realm=\"example.com\"\r\n" >>$CHALLENGE && + + test_config_global credential.helper test-helper && + git ls-remote "$HTTPD_URL/custom_auth/repo.git" && + + expect_credential_query get <<-EOF && + protocol=http + host=$HTTPD_DEST + wwwauth[]=FooBar param1="value1" param2="value2" + wwwauth[]=Bearer authorize_uri="id.example.com" p=1 q=0 + wwwauth[]=Basic realm="example.com" + EOF + + expect_credential_query store <<-EOF + protocol=http + host=$HTTPD_DEST + username=alice + password=secret-passwd + EOF +' + +test_expect_success 'access using basic auth with wwwauth header mixed line-endings' ' + test_when_finished "per_test_cleanup" && + + set_credential_reply get <<-EOF && + username=alice + password=secret-passwd + EOF + + # Basic base64(alice:secret-passwd) + cat >"$HTTPD_ROOT_PATH/custom-auth.valid" <<-EOF && + Basic YWxpY2U6c2VjcmV0LXBhc3N3ZA== + EOF + + CHALLENGE="$HTTPD_ROOT_PATH/custom-auth.challenge" && + + # Note that leading and trailing whitespace is important to correctly + # simulate a continuation/folded header. + printf "">$CHALLENGE && + printf "WWW-Authenticate: FooBar param1=\"value1\"\r\n" >$CHALLENGE && + printf " \r\n" >>$CHALLENGE && + printf "\tparam2=\"value2\"\r\n" >>$CHALLENGE && + printf "WWW-Authenticate: Basic realm=\"example.com\"" >>$CHALLENGE && + + test_config_global credential.helper test-helper && + git ls-remote "$HTTPD_URL/custom_auth/repo.git" && + + expect_credential_query get <<-EOF && + protocol=http + host=$HTTPD_DEST + wwwauth[]=FooBar param1="value1" param2="value2" + wwwauth[]=Basic realm="example.com" + EOF + + expect_credential_query store <<-EOF + protocol=http + host=$HTTPD_DEST + username=alice + password=secret-passwd + EOF +' + +test_done diff --git a/t/t5605-clone-local.sh b/t/t5605-clone-local.sh index 38b850c10e..1d7b1abda1 100755 --- a/t/t5605-clone-local.sh +++ b/t/t5605-clone-local.sh @@ -15,8 +15,12 @@ test_expect_success 'preparing origin repository' ' : >file && git add . && git commit -m1 && git clone --bare . a.git && git clone --bare . x && - test "$(cd a.git && git config --bool core.bare)" = true && - test "$(cd x && git config --bool core.bare)" = true && + echo true >expect && + git -C a.git config --bool core.bare >actual && + test_cmp expect actual && + echo true >expect && + git -C x config --bool core.bare >actual && + test_cmp expect actual && git bundle create b1.bundle --all && git bundle create b2.bundle main && mkdir dir && @@ -29,7 +33,9 @@ test_expect_success 'preparing origin repository' ' test_expect_success 'local clone without .git suffix' ' git clone -l -s a b && (cd b && - test "$(git config --bool core.bare)" = false && + echo false >expect && + git config --bool core.bare >actual && + test_cmp expect actual && git fetch) ' diff --git a/t/t6018-rev-list-glob.sh b/t/t6018-rev-list-glob.sh index aabf590dda..67d523d405 100755 --- a/t/t6018-rev-list-glob.sh +++ b/t/t6018-rev-list-glob.sh @@ -187,7 +187,7 @@ test_expect_success 'rev-parse --exclude=ref with --remotes=glob' ' compare rev-parse "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two" ' -for section in receive uploadpack +for section in fetch receive uploadpack do test_expect_success "rev-parse --exclude-hidden=$section with --all" ' compare "-c transfer.hideRefs=refs/remotes/ rev-parse" "--branches --tags" "--exclude-hidden=$section --all" diff --git a/t/t6020-bundle-misc.sh b/t/t6020-bundle-misc.sh index 7d40994991..dface8bcfe 100755 --- a/t/t6020-bundle-misc.sh +++ b/t/t6020-bundle-misc.sh @@ -10,6 +10,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh . "$TEST_DIRECTORY"/lib-bundle.sh +. "$TEST_DIRECTORY"/lib-terminal.sh for cmd in create verify list-heads unbundle do @@ -606,4 +607,42 @@ test_expect_success 'verify catches unreachable, broken prerequisites' ' ) ' +test_expect_success 'bundle progress includes write phase' ' + GIT_PROGRESS_DELAY=0 \ + git bundle create --progress out.bundle --all 2>err && + grep 'Writing' err +' + +test_expect_success TTY 'create --quiet disables all bundle progress' ' + test_terminal env GIT_PROGRESS_DELAY=0 \ + git bundle create --quiet out.bundle --all 2>err && + test_must_be_empty err +' + +test_expect_success 'read bundle over stdin' ' + git bundle create some.bundle HEAD && + + git bundle verify - <some.bundle 2>err && + grep "<stdin> is okay" err && + + git bundle list-heads some.bundle >expect && + git bundle list-heads - <some.bundle >actual && + test_cmp expect actual && + + git bundle unbundle some.bundle >expect && + git bundle unbundle - <some.bundle >actual && + test_cmp expect actual +' + +test_expect_success 'send a bundle to standard output' ' + git bundle create - --all HEAD >bundle-one && + mkdir -p down && + git -C down bundle create - --all HEAD >bundle-two && + git bundle verify bundle-one && + git bundle verify bundle-two && + git ls-remote bundle-one >expect && + git ls-remote bundle-two >actual && + test_cmp expect actual +' + test_done diff --git a/t/t6021-rev-list-exclude-hidden.sh b/t/t6021-rev-list-exclude-hidden.sh index 11c50b7c0d..1a9d37e638 100755 --- a/t/t6021-rev-list-exclude-hidden.sh +++ b/t/t6021-rev-list-exclude-hidden.sh @@ -22,7 +22,7 @@ test_expect_success 'invalid section' ' test_cmp expected err ' -for section in receive uploadpack +for section in fetch receive uploadpack do test_expect_success "$section: passed multiple times" ' echo "fatal: --exclude-hidden= passed more than once" >expected && diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index 3ba4fdf615..fb01bd6abc 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -122,6 +122,29 @@ test_expect_success 'bisect start without -- takes unknown arg as pathspec' ' grep bar ".git/BISECT_NAMES" ' +test_expect_success 'bisect reset: back in a branch checked out also elsewhere' ' + echo "shared" > branch.expect && + test_bisect_reset() { + git -C $1 bisect start && + git -C $1 bisect good $HASH1 && + git -C $1 bisect bad $HASH3 && + git -C $1 bisect reset && + git -C $1 branch --show-current > branch.output && + cmp branch.expect branch.output + } && + test_when_finished " + git worktree remove wt1 && + git worktree remove wt2 && + git branch -d shared + " && + git worktree add wt1 -b shared && + git worktree add wt2 -f shared && + # we test in both worktrees to ensure that works + # as expected with "first" and "next" worktrees + test_bisect_reset wt1 && + test_bisect_reset wt2 +' + test_expect_success 'bisect reset: back in the main branch' ' git bisect reset && echo "* main" > branch.expect && diff --git a/t/t7031-verify-tag-signed-ssh.sh b/t/t7031-verify-tag-signed-ssh.sh index 36eb86a4b1..20913b3713 100755 --- a/t/t7031-verify-tag-signed-ssh.sh +++ b/t/t7031-verify-tag-signed-ssh.sh @@ -200,4 +200,14 @@ test_expect_success GPGSSH 'verifying a forged tag with --format should fail sil test_must_be_empty actual-forged ' +test_expect_success GPGSSH 'rev-list --format=%G' ' + test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && + git rev-list -1 --format="%G? %H" sixth-signed >actual && + cat >expect <<-EOF && + commit $(git rev-parse sixth-signed^0) + G $(git rev-parse sixth-signed^0) + EOF + test_cmp expect actual +' + test_done diff --git a/t/t7402-submodule-rebase.sh b/t/t7402-submodule-rebase.sh index b19792b326..2b3c363078 100755 --- a/t/t7402-submodule-rebase.sh +++ b/t/t7402-submodule-rebase.sh @@ -56,12 +56,15 @@ chmod a+x fake-editor.sh test_expect_success 'interactive rebase with a dirty submodule' ' - test submodule = $(git diff --name-only) && + echo submodule >expect && + git diff --name-only >actual && + test_cmp expect actual && HEAD=$(git rev-parse HEAD) && GIT_EDITOR="\"$(pwd)/fake-editor.sh\"" EDITOR_TEXT="pick $HEAD" \ git rebase -i HEAD^ && - test submodule = $(git diff --name-only) - + echo submodule >expect && + git diff --name-only >actual && + test_cmp expect actual ' test_expect_success 'rebase with dirty file and submodule fails' ' @@ -83,11 +86,19 @@ test_expect_success 'stash with a dirty submodule' ' CURRENT=$(cd submodule && git rev-parse HEAD) && git stash && test new != $(cat file) && - test submodule = $(git diff --name-only) && - test $CURRENT = $(cd submodule && git rev-parse HEAD) && + echo submodule >expect && + git diff --name-only >actual && + test_cmp expect actual && + + echo "$CURRENT" >expect && + git -C submodule rev-parse HEAD >actual && + test_cmp expect actual && + git stash apply && test new = $(cat file) && - test $CURRENT = $(cd submodule && git rev-parse HEAD) + echo "$CURRENT" >expect && + git -C submodule rev-parse HEAD >actual && + test_cmp expect actual ' diff --git a/t/t7504-commit-msg-hook.sh b/t/t7504-commit-msg-hook.sh index 07ca46fb0d..d1255228d5 100755 --- a/t/t7504-commit-msg-hook.sh +++ b/t/t7504-commit-msg-hook.sh @@ -102,7 +102,9 @@ test_expect_success 'setup: commit-msg hook that always fails' ' ' commit_msg_is () { - test "$(git log --pretty=format:%s%b -1)" = "$1" + printf "%s" "$1" >expect && + git log --pretty=format:%s%b -1 >actual && + test_cmp expect actual } test_expect_success 'with failing hook' ' diff --git a/t/t7516-commit-races.sh b/t/t7516-commit-races.sh index f2ce14e907..2d38a16480 100755 --- a/t/t7516-commit-races.sh +++ b/t/t7516-commit-races.sh @@ -10,7 +10,8 @@ test_expect_success 'race to create orphan commit' ' test_must_fail env EDITOR=./hare-editor git commit --allow-empty -m tortoise -e && git show -s --pretty=format:%s >subject && grep hare subject && - test -z "$(git show -s --pretty=format:%P)" + git show -s --pretty=format:%P >out && + test_must_be_empty out ' test_expect_success 'race to create non-orphan commit' ' diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 8eded6ab27..39d6d713ec 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -1001,7 +1001,9 @@ test_expect_success 'log --committer does not search in timestamp' ' test_expect_success 'grep with CE_VALID file' ' git update-index --assume-unchanged t/t && rm t/t && - test "$(git grep test)" = "t/t:test" && + echo "t/t:test" >expect && + git grep test >actual && + test_cmp expect actual && git update-index --no-assume-unchanged t/t && git checkout t/t ' @@ -1,4 +1,5 @@ #include "cache.h" +#include "environment.h" #include "tag.h" #include "object-store.h" #include "commit.h" @@ -6,7 +7,9 @@ #include "blob.h" #include "alloc.h" #include "gpg-interface.h" +#include "hex.h" #include "packfile.h" +#include "wrapper.h" const char *tag_type = "tag"; diff --git a/tempfile.c b/tempfile.c index e27048f970..50c377134c 100644 --- a/tempfile.c +++ b/tempfile.c @@ -42,9 +42,11 @@ * file created by its parent. */ -#include "cache.h" +#include "git-compat-util.h" +#include "path.h" #include "tempfile.h" #include "sigchain.h" +#include "wrapper.h" static VOLATILE_LIST_HEAD(tempfile_list); diff --git a/thread-utils.c b/thread-utils.c index 5329845691..1f89ffab4c 100644 --- a/thread-utils.c +++ b/thread-utils.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "thread-utils.h" #if defined(hpux) || defined(__hpux) || defined(_hpux) diff --git a/tmp-objdir.c b/tmp-objdir.c index 2a2012eb6d..5adad1925d 100644 --- a/tmp-objdir.c +++ b/tmp-objdir.c @@ -1,7 +1,9 @@ #include "cache.h" #include "tmp-objdir.h" +#include "abspath.h" #include "chdir-notify.h" #include "dir.h" +#include "environment.h" #include "sigchain.h" #include "string-list.h" #include "strbuf.h" @@ -22,7 +22,11 @@ */ #include "cache.h" +#include "abspath.h" +#include "environment.h" #include "quote.h" +#include "setup.h" +#include "wrapper.h" struct trace_key trace_default_key = { "GIT_TRACE", 0, 0, 0 }; struct trace_key trace_perf_key = TRACE_KEY_INIT(PERFORMANCE); @@ -1,7 +1,6 @@ #ifndef TRACE_H #define TRACE_H -#include "git-compat-util.h" #include "strbuf.h" /** @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "json-writer.h" #include "quote.h" @@ -6,6 +6,7 @@ #include "sigchain.h" #include "thread-utils.h" #include "version.h" +#include "trace.h" #include "trace2/tr2_cfg.h" #include "trace2/tr2_cmd_name.h" #include "trace2/tr2_ctr.h" diff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c index ec9ac1a6ef..78cfc15d52 100644 --- a/trace2/tr2_cfg.c +++ b/trace2/tr2_cfg.c @@ -1,5 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" +#include "strbuf.h" +#include "trace2.h" #include "trace2/tr2_cfg.h" #include "trace2/tr2_sysenv.h" diff --git a/trace2/tr2_cmd_name.c b/trace2/tr2_cmd_name.c index dd313204f5..b7b5a869b7 100644 --- a/trace2/tr2_cmd_name.c +++ b/trace2/tr2_cmd_name.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "strbuf.h" #include "trace2/tr2_cmd_name.h" #define TR2_ENVVAR_PARENT_NAME "GIT_TRACE2_PARENT_NAME" diff --git a/trace2/tr2_ctr.c b/trace2/tr2_ctr.c index 483ca7c308..b342d3b1a3 100644 --- a/trace2/tr2_ctr.c +++ b/trace2/tr2_ctr.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "thread-utils.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" diff --git a/trace2/tr2_dst.c b/trace2/tr2_dst.c index 8a21dd2972..5be892cd5c 100644 --- a/trace2/tr2_dst.c +++ b/trace2/tr2_dst.c @@ -1,5 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "abspath.h" #include "sigchain.h" +#include "strbuf.h" #include "trace2/tr2_dst.h" #include "trace2/tr2_sid.h" #include "trace2/tr2_sysenv.h" diff --git a/trace2/tr2_sid.c b/trace2/tr2_sid.c index dc6e75ef13..09c4ef0d17 100644 --- a/trace2/tr2_sid.c +++ b/trace2/tr2_sid.c @@ -1,4 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "hex.h" +#include "strbuf.h" #include "trace2/tr2_tbuf.h" #include "trace2/tr2_sid.h" diff --git a/trace2/tr2_sysenv.c b/trace2/tr2_sysenv.c index a380dcf910..069786cb92 100644 --- a/trace2/tr2_sysenv.c +++ b/trace2/tr2_sysenv.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "dir.h" #include "tr2_sysenv.h" diff --git a/trace2/tr2_tbuf.c b/trace2/tr2_tbuf.c index 2498482d9a..c3b3822ed7 100644 --- a/trace2/tr2_tbuf.c +++ b/trace2/tr2_tbuf.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "tr2_tbuf.h" void tr2_tbuf_local_time(struct tr2_tbuf *tb) diff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c index 16f6332755..9e7aab6d51 100644 --- a/trace2/tr2_tgt_event.c +++ b/trace2/tr2_tgt_event.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "json-writer.h" #include "run-command.h" diff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c index fbbef68dfc..8672c2c2d0 100644 --- a/trace2/tr2_tgt_normal.c +++ b/trace2/tr2_tgt_normal.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "run-command.h" #include "quote.h" diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c index adae803263..3f2b2d5311 100644 --- a/trace2/tr2_tgt_perf.c +++ b/trace2/tr2_tgt_perf.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "run-command.h" #include "quote.h" diff --git a/trace2/tr2_tls.c b/trace2/tr2_tls.c index 04900bb4c3..9f46ae12f5 100644 --- a/trace2/tr2_tls.c +++ b/trace2/tr2_tls.c @@ -1,5 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "thread-utils.h" +#include "trace.h" #include "trace2/tr2_tls.h" /* diff --git a/trace2/tr2_tmr.c b/trace2/tr2_tmr.c index 786762dfd2..31d0e4d1bd 100644 --- a/trace2/tr2_tmr.c +++ b/trace2/tr2_tmr.c @@ -1,8 +1,9 @@ -#include "cache.h" +#include "git-compat-util.h" #include "thread-utils.h" #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" #include "trace2/tr2_tmr.h" +#include "trace.h" #define MY_MAX(a, b) ((a) > (b) ? (a) : (b)) #define MY_MIN(a, b) ((a) < (b) ? (a) : (b)) @@ -1,5 +1,8 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" +#include "environment.h" +#include "gettext.h" #include "string-list.h" #include "run-command.h" #include "commit.h" diff --git a/transport-helper.c b/transport-helper.c index 2a1b4497ca..76d146ee88 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -4,6 +4,9 @@ #include "run-command.h" #include "commit.h" #include "diff.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "revision.h" #include "remote.h" #include "string-list.h" @@ -14,6 +17,7 @@ #include "refspec.h" #include "transport-internal.h" #include "protocol.h" +#include "wrapper.h" static int debug; diff --git a/transport.c b/transport.c index 7488622e77..d2a1af43b5 100644 --- a/transport.c +++ b/transport.c @@ -1,5 +1,8 @@ #include "cache.h" +#include "alloc.h" #include "config.h" +#include "environment.h" +#include "hex.h" #include "transport.h" #include "hook.h" #include "pkt-line.h" @@ -10,6 +13,7 @@ #include "walker.h" #include "bundle.h" #include "dir.h" +#include "gettext.h" #include "refs.h" #include "refspec.h" #include "branch.h" @@ -23,6 +27,7 @@ #include "object-store.h" #include "color.h" #include "bundle-uri.h" +#include "wrapper.h" static int transport_use_color = -1; static char transport_colors[][COLOR_MAXLEN] = { diff --git a/transport.h b/transport.h index 85150f504f..6393cd9823 100644 --- a/transport.h +++ b/transport.h @@ -1,7 +1,6 @@ #ifndef TRANSPORT_H #define TRANSPORT_H -#include "cache.h" #include "run-command.h" #include "remote.h" #include "list-objects-filter-options.h" diff --git a/tree-walk.c b/tree-walk.c index 74f4d710e8..38b6556478 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -1,6 +1,9 @@ #include "cache.h" #include "tree-walk.h" +#include "alloc.h" #include "dir.h" +#include "gettext.h" +#include "hex.h" #include "object-store.h" #include "tree.h" #include "pathspec.h" diff --git a/tree-walk.h b/tree-walk.h index 6305d53150..25fe27e352 100644 --- a/tree-walk.h +++ b/tree-walk.h @@ -1,7 +1,9 @@ #ifndef TREE_WALK_H #define TREE_WALK_H -#include "cache.h" +#include "hash.h" + +struct index_state; #define MAX_TRAVERSE_TREES 8 @@ -1,5 +1,6 @@ #include "cache.h" #include "cache-tree.h" +#include "hex.h" #include "tree.h" #include "object-store.h" #include "blob.h" diff --git a/unix-socket.c b/unix-socket.c index e0be1badb5..79800d8063 100644 --- a/unix-socket.c +++ b/unix-socket.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "strbuf.h" #include "unix-socket.h" #define DEFAULT_UNIX_STREAM_LISTEN_BACKLOG (5) diff --git a/unix-stream-server.c b/unix-stream-server.c index efa2a207ab..22ac2373e0 100644 --- a/unix-stream-server.c +++ b/unix-stream-server.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "lockfile.h" #include "unix-socket.h" #include "unix-stream-server.h" diff --git a/unpack-trees.c b/unpack-trees.c index b82ad7e45d..4a5522bdb2 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -3,6 +3,9 @@ #include "repository.h" #include "config.h" #include "dir.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "tree.h" #include "tree-walk.h" #include "cache-tree.h" @@ -19,6 +22,7 @@ #include "promisor-remote.h" #include "entry.h" #include "parallel-checkout.h" +#include "setup.h" /* * Error messages expected by scripts out of plumbing commands such as @@ -66,8 +70,8 @@ static const char *unpack_plumbing_errors[NB_UNPACK_TREES_WARNING_TYPES] = { }; #define ERRORMSG(o,type) \ - ( ((o) && (o)->msgs[(type)]) \ - ? ((o)->msgs[(type)]) \ + ( ((o) && (o)->internal.msgs[(type)]) \ + ? ((o)->internal.msgs[(type)]) \ : (unpack_plumbing_errors[(type)]) ) static const char *super_prefixed(const char *path, const char *super_prefix) @@ -108,10 +112,10 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, const char *cmd) { int i; - const char **msgs = opts->msgs; + const char **msgs = opts->internal.msgs; const char *msg; - strvec_init(&opts->msgs_to_free); + strvec_init(&opts->internal.msgs_to_free); if (!strcmp(cmd, "checkout")) msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE) @@ -129,7 +133,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, "Please commit your changes or stash them before you %s.") : _("Your local changes to the following files would be overwritten by %s:\n%%s"); msgs[ERROR_WOULD_OVERWRITE] = msgs[ERROR_NOT_UPTODATE_FILE] = - strvec_pushf(&opts->msgs_to_free, msg, cmd, cmd); + strvec_pushf(&opts->internal.msgs_to_free, msg, cmd, cmd); msgs[ERROR_NOT_UPTODATE_DIR] = _("Updating the following directories would lose untracked files in them:\n%s"); @@ -153,7 +157,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, "Please move or remove them before you %s.") : _("The following untracked working tree files would be removed by %s:\n%%s"); msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = - strvec_pushf(&opts->msgs_to_free, msg, cmd, cmd); + strvec_pushf(&opts->internal.msgs_to_free, msg, cmd, cmd); if (!strcmp(cmd, "checkout")) msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE) @@ -171,7 +175,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, "Please move or remove them before you %s.") : _("The following untracked working tree files would be overwritten by %s:\n%%s"); msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = - strvec_pushf(&opts->msgs_to_free, msg, cmd, cmd); + strvec_pushf(&opts->internal.msgs_to_free, msg, cmd, cmd); /* * Special case: ERROR_BIND_OVERLAP refers to a pair of paths, we @@ -189,16 +193,16 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, msgs[WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN] = _("The following paths were already present and thus not updated despite sparse patterns:\n%s"); - opts->show_all_errors = 1; + opts->internal.show_all_errors = 1; /* rejected paths may not have a static buffer */ - for (i = 0; i < ARRAY_SIZE(opts->unpack_rejects); i++) - opts->unpack_rejects[i].strdup_strings = 1; + for (i = 0; i < ARRAY_SIZE(opts->internal.unpack_rejects); i++) + opts->internal.unpack_rejects[i].strdup_strings = 1; } void clear_unpack_trees_porcelain(struct unpack_trees_options *opts) { - strvec_clear(&opts->msgs_to_free); - memset(opts->msgs, 0, sizeof(opts->msgs)); + strvec_clear(&opts->internal.msgs_to_free); + memset(opts->internal.msgs, 0, sizeof(opts->internal.msgs)); } static int do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce, @@ -210,7 +214,7 @@ static int do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce, set |= CE_WT_REMOVE; ce->ce_flags = (ce->ce_flags & ~clear) | set; - return add_index_entry(&o->result, ce, + return add_index_entry(&o->internal.result, ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE); } @@ -218,7 +222,7 @@ static void add_entry(struct unpack_trees_options *o, const struct cache_entry *ce, unsigned int set, unsigned int clear) { - do_add_entry(o, dup_cache_entry(ce, &o->result), set, clear); + do_add_entry(o, dup_cache_entry(ce, &o->internal.result), set, clear); } /* @@ -233,7 +237,7 @@ static int add_rejected_path(struct unpack_trees_options *o, if (o->quiet) return -1; - if (!o->show_all_errors) + if (!o->internal.show_all_errors) return error(ERRORMSG(o, e), super_prefixed(path, o->super_prefix)); @@ -241,7 +245,7 @@ static int add_rejected_path(struct unpack_trees_options *o, * Otherwise, insert in a list for future display by * display_(error|warning)_msgs() */ - string_list_append(&o->unpack_rejects[e], path); + string_list_append(&o->internal.unpack_rejects[e], path); return -1; } @@ -253,7 +257,7 @@ static void display_error_msgs(struct unpack_trees_options *o) int e; unsigned error_displayed = 0; for (e = 0; e < NB_UNPACK_TREES_ERROR_TYPES; e++) { - struct string_list *rejects = &o->unpack_rejects[e]; + struct string_list *rejects = &o->internal.unpack_rejects[e]; if (rejects->nr > 0) { int i; @@ -281,7 +285,7 @@ static void display_warning_msgs(struct unpack_trees_options *o) unsigned warning_displayed = 0; for (e = NB_UNPACK_TREES_ERROR_TYPES + 1; e < NB_UNPACK_TREES_WARNING_TYPES; e++) { - struct string_list *rejects = &o->unpack_rejects[e]; + struct string_list *rejects = &o->internal.unpack_rejects[e]; if (rejects->nr > 0) { int i; @@ -600,13 +604,14 @@ static void mark_ce_used(struct cache_entry *ce, struct unpack_trees_options *o) { ce->ce_flags |= CE_UNPACKED; - if (o->cache_bottom < o->src_index->cache_nr && - o->src_index->cache[o->cache_bottom] == ce) { - int bottom = o->cache_bottom; + if (o->internal.cache_bottom < o->src_index->cache_nr && + o->src_index->cache[o->internal.cache_bottom] == ce) { + int bottom = o->internal.cache_bottom; + while (bottom < o->src_index->cache_nr && o->src_index->cache[bottom]->ce_flags & CE_UNPACKED) bottom++; - o->cache_bottom = bottom; + o->internal.cache_bottom = bottom; } } @@ -652,7 +657,7 @@ static void mark_ce_used_same_name(struct cache_entry *ce, static struct cache_entry *next_cache_entry(struct unpack_trees_options *o) { const struct index_state *index = o->src_index; - int pos = o->cache_bottom; + int pos = o->internal.cache_bottom; while (pos < index->cache_nr) { struct cache_entry *ce = index->cache[pos]; @@ -711,7 +716,7 @@ static void restore_cache_bottom(struct traverse_info *info, int bottom) if (o->diff_index_cached) return; - o->cache_bottom = bottom; + o->internal.cache_bottom = bottom; } static int switch_cache_bottom(struct traverse_info *info) @@ -721,13 +726,13 @@ static int switch_cache_bottom(struct traverse_info *info) if (o->diff_index_cached) return 0; - ret = o->cache_bottom; + ret = o->internal.cache_bottom; pos = find_cache_pos(info->prev, info->name, info->namelen); if (pos < -1) - o->cache_bottom = -2 - pos; + o->internal.cache_bottom = -2 - pos; else if (pos < 0) - o->cache_bottom = o->src_index->cache_nr; + o->internal.cache_bottom = o->src_index->cache_nr; return ret; } @@ -838,7 +843,7 @@ static int traverse_by_cache_tree(int pos, int nr_entries, int nr_names, mark_ce_used(src[0], o); } free(tree_ce); - if (o->debug_unpack) + if (o->internal.debug_unpack) printf("Unpacked %d entries from %s to %s using cache-tree\n", nr_entries, o->src_index->cache[pos]->name, @@ -873,9 +878,9 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, * save and restore cache_bottom anyway to not miss * unprocessed entries before 'pos'. */ - bottom = o->cache_bottom; + bottom = o->internal.cache_bottom; ret = traverse_by_cache_tree(pos, nr_entries, n, info); - o->cache_bottom = bottom; + o->internal.cache_bottom = bottom; return ret; } @@ -1212,8 +1217,8 @@ static int unpack_single_entry(int n, unsigned long mask, * cache entry from the index aware logic. */ src[i + o->merge] = create_ce_entry(info, names + i, stage, - &o->result, o->merge, - bit & dirmask); + &o->internal.result, + o->merge, bit & dirmask); } if (o->merge) { @@ -1237,7 +1242,7 @@ static int unpack_single_entry(int n, unsigned long mask, static int unpack_failed(struct unpack_trees_options *o, const char *message) { - discard_index(&o->result); + discard_index(&o->internal.result); if (!o->quiet && !o->exiting_early) { if (message) return error("%s", message); @@ -1260,7 +1265,7 @@ static int find_cache_pos(struct traverse_info *info, struct index_state *index = o->src_index; int pfxlen = info->pathlen; - for (pos = o->cache_bottom; pos < index->cache_nr; pos++) { + for (pos = o->internal.cache_bottom; pos < index->cache_nr; pos++) { const struct cache_entry *ce = index->cache[pos]; const char *ce_name, *ce_slash; int cmp, ce_len; @@ -1271,8 +1276,8 @@ static int find_cache_pos(struct traverse_info *info, * we can never match it; don't check it * again. */ - if (pos == o->cache_bottom) - ++o->cache_bottom; + if (pos == o->internal.cache_bottom) + ++o->internal.cache_bottom; continue; } if (!ce_in_traverse_path(ce, info)) { @@ -1450,7 +1455,7 @@ static int unpack_sparse_callback(int n, unsigned long mask, unsigned long dirma */ if (!is_null_oid(&names[0].oid)) { src[0] = create_ce_entry(info, &names[0], 0, - &o->result, 1, + &o->internal.result, 1, dirmask & (1ul << 0)); src[0]->ce_flags |= (CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE); } @@ -1487,7 +1492,7 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str while (!p->mode) p++; - if (o->debug_unpack) + if (o->internal.debug_unpack) debug_unpack_callback(n, mask, dirmask, names, info); /* Are we supposed to look at the index too? */ @@ -1560,7 +1565,7 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str * in 'mark_ce_used()' */ if (!src[0] || !S_ISSPARSEDIR(src[0]->ce_mode)) - o->cache_bottom += matches; + o->internal.cache_bottom += matches; return mask; } } @@ -1809,7 +1814,7 @@ static void populate_from_existing_patterns(struct unpack_trees_options *o, if (get_sparse_checkout_patterns(pl) < 0) o->skip_sparse_checkout = 1; else - o->pl = pl; + o->internal.pl = pl; } static void update_sparsity_for_prefix(const char *prefix, @@ -1871,8 +1876,12 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options if (len > MAX_UNPACK_TREES) die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES); - if (o->dir) - BUG("o->dir is for internal use only"); + if (o->internal.dir) + BUG("o->internal.dir is for internal use only"); + if (o->internal.pl) + BUG("o->internal.pl is for internal use only"); + if (o->df_conflict_entry) + BUG("o->df_conflict_entry is an output only field"); trace_performance_enter(); trace2_region_enter("unpack_trees", "unpack_trees", the_repository); @@ -1889,9 +1898,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options BUG("UNPACK_RESET_OVERWRITE_UNTRACKED incompatible with preserved ignored files"); if (!o->preserve_ignored) { - o->dir = &dir; - o->dir->flags |= DIR_SHOW_IGNORED; - setup_standard_excludes(o->dir); + o->internal.dir = &dir; + o->internal.dir->flags |= DIR_SHOW_IGNORED; + setup_standard_excludes(o->internal.dir); } if (o->prefix) @@ -1899,49 +1908,50 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options if (!core_apply_sparse_checkout || !o->update) o->skip_sparse_checkout = 1; - if (!o->skip_sparse_checkout && !o->pl) { + if (!o->skip_sparse_checkout) { memset(&pl, 0, sizeof(pl)); free_pattern_list = 1; populate_from_existing_patterns(o, &pl); } - index_state_init(&o->result, o->src_index->repo); - o->result.initialized = 1; - o->result.timestamp.sec = o->src_index->timestamp.sec; - o->result.timestamp.nsec = o->src_index->timestamp.nsec; - o->result.version = o->src_index->version; + index_state_init(&o->internal.result, o->src_index->repo); + o->internal.result.initialized = 1; + o->internal.result.timestamp.sec = o->src_index->timestamp.sec; + o->internal.result.timestamp.nsec = o->src_index->timestamp.nsec; + o->internal.result.version = o->src_index->version; if (!o->src_index->split_index) { - o->result.split_index = NULL; + o->internal.result.split_index = NULL; } else if (o->src_index == o->dst_index) { /* * o->dst_index (and thus o->src_index) will be discarded - * and overwritten with o->result at the end of this function, - * so just use src_index's split_index to avoid having to - * create a new one. + * and overwritten with o->internal.result at the end of + * this function, so just use src_index's split_index to + * avoid having to create a new one. */ - o->result.split_index = o->src_index->split_index; - o->result.split_index->refcount++; + o->internal.result.split_index = o->src_index->split_index; + o->internal.result.split_index->refcount++; } else { - o->result.split_index = init_split_index(&o->result); + o->internal.result.split_index = + init_split_index(&o->internal.result); } - oidcpy(&o->result.oid, &o->src_index->oid); - o->merge_size = len; + oidcpy(&o->internal.result.oid, &o->src_index->oid); + o->internal.merge_size = len; mark_all_ce_unused(o->src_index); - o->result.fsmonitor_last_update = + o->internal.result.fsmonitor_last_update = xstrdup_or_null(o->src_index->fsmonitor_last_update); - o->result.fsmonitor_has_run_once = o->src_index->fsmonitor_has_run_once; + o->internal.result.fsmonitor_has_run_once = o->src_index->fsmonitor_has_run_once; if (!o->src_index->initialized && !repo->settings.command_requires_full_index && - is_sparse_index_allowed(&o->result, 0)) - o->result.sparse_index = 1; + is_sparse_index_allowed(&o->internal.result, 0)) + o->internal.result.sparse_index = 1; /* * Sparse checkout loop #1: set NEW_SKIP_WORKTREE on existing entries */ if (!o->skip_sparse_checkout) - mark_new_skip_worktree(o->pl, o->src_index, 0, + mark_new_skip_worktree(o->internal.pl, o->src_index, 0, CE_NEW_SKIP_WORKTREE, o->verbose_update); if (!dfc) @@ -1955,7 +1965,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options setup_traverse_info(&info, prefix); info.fn = unpack_callback; info.data = o; - info.show_all_errors = o->show_all_errors; + info.show_all_errors = o->internal.show_all_errors; info.pathspec = o->pathspec; if (o->prefix) { @@ -1996,7 +2006,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options } mark_all_ce_unused(o->src_index); - if (o->trivial_merges_only && o->nontrivial_merge) { + if (o->trivial_merges_only && o->internal.nontrivial_merge) { ret = unpack_failed(o, "Merge requires file-level merging"); goto done; } @@ -2007,13 +2017,13 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options * If they will have NEW_SKIP_WORKTREE, also set CE_SKIP_WORKTREE * so apply_sparse_checkout() won't attempt to remove it from worktree */ - mark_new_skip_worktree(o->pl, &o->result, + mark_new_skip_worktree(o->internal.pl, &o->internal.result, CE_ADDED, CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE, o->verbose_update); ret = 0; - for (i = 0; i < o->result.cache_nr; i++) { - struct cache_entry *ce = o->result.cache[i]; + for (i = 0; i < o->internal.result.cache_nr; i++) { + struct cache_entry *ce = o->internal.result.cache[i]; /* * Entries marked with CE_ADDED in merged_entry() do not have @@ -2027,7 +2037,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options verify_absent(ce, WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN, o)) ret = 1; - if (apply_sparse_checkout(&o->result, ce, o)) + if (apply_sparse_checkout(&o->internal.result, ce, o)) ret = 1; } if (ret == 1) { @@ -2035,46 +2045,47 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options * Inability to sparsify or de-sparsify individual * paths is not an error, but just a warning. */ - if (o->show_all_errors) + if (o->internal.show_all_errors) display_warning_msgs(o); ret = 0; } } - ret = check_updates(o, &o->result) ? (-2) : 0; + ret = check_updates(o, &o->internal.result) ? (-2) : 0; if (o->dst_index) { - move_index_extensions(&o->result, o->src_index); + move_index_extensions(&o->internal.result, o->src_index); if (!ret) { if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0)) - cache_tree_verify(the_repository, &o->result); + cache_tree_verify(the_repository, + &o->internal.result); if (!o->skip_cache_tree_update && - !cache_tree_fully_valid(o->result.cache_tree)) - cache_tree_update(&o->result, + !cache_tree_fully_valid(o->internal.result.cache_tree)) + cache_tree_update(&o->internal.result, WRITE_TREE_SILENT | WRITE_TREE_REPAIR); } - o->result.updated_workdir = 1; + o->internal.result.updated_workdir = 1; discard_index(o->dst_index); - *o->dst_index = o->result; + *o->dst_index = o->internal.result; } else { - discard_index(&o->result); + discard_index(&o->internal.result); } o->src_index = NULL; done: if (free_pattern_list) clear_pattern_list(&pl); - if (o->dir) { - dir_clear(o->dir); - o->dir = NULL; + if (o->internal.dir) { + dir_clear(o->internal.dir); + o->internal.dir = NULL; } trace2_region_leave("unpack_trees", "unpack_trees", the_repository); trace_performance_leave("unpack_trees"); return ret; return_failed: - if (o->show_all_errors) + if (o->internal.show_all_errors) display_error_msgs(o); mark_all_ce_unused(o->src_index); ret = unpack_failed(o, NULL); @@ -2089,16 +2100,17 @@ return_failed: * * CE_NEW_SKIP_WORKTREE is used internally. */ -enum update_sparsity_result update_sparsity(struct unpack_trees_options *o) +enum update_sparsity_result update_sparsity(struct unpack_trees_options *o, + struct pattern_list *pl) { enum update_sparsity_result ret = UPDATE_SPARSITY_SUCCESS; - struct pattern_list pl; int i; unsigned old_show_all_errors; int free_pattern_list = 0; - old_show_all_errors = o->show_all_errors; - o->show_all_errors = 1; + old_show_all_errors = o->internal.show_all_errors; + o->internal.show_all_errors = 1; + index_state_init(&o->internal.result, o->src_index->repo); /* Sanity checks */ if (!o->update || o->index_only || o->skip_sparse_checkout) @@ -2109,20 +2121,19 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o) trace_performance_enter(); /* If we weren't given patterns, use the recorded ones */ - if (!o->pl) { - memset(&pl, 0, sizeof(pl)); + if (!pl) { free_pattern_list = 1; - populate_from_existing_patterns(o, &pl); - if (o->skip_sparse_checkout) - goto skip_sparse_checkout; + pl = xcalloc(1, sizeof(*pl)); + populate_from_existing_patterns(o, pl); } + o->internal.pl = pl; /* Expand sparse directories as needed */ - expand_index(o->src_index, o->pl); + expand_index(o->src_index, o->internal.pl); /* Set NEW_SKIP_WORKTREE on existing entries. */ mark_all_ce_unused(o->src_index); - mark_new_skip_worktree(o->pl, o->src_index, 0, + mark_new_skip_worktree(o->internal.pl, o->src_index, 0, CE_NEW_SKIP_WORKTREE, o->verbose_update); /* Then loop over entries and update/remove as needed */ @@ -2142,14 +2153,16 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o) ret = UPDATE_SPARSITY_WARNINGS; } -skip_sparse_checkout: if (check_updates(o, o->src_index)) ret = UPDATE_SPARSITY_WORKTREE_UPDATE_FAILURES; display_warning_msgs(o); - o->show_all_errors = old_show_all_errors; - if (free_pattern_list) - clear_pattern_list(&pl); + o->internal.show_all_errors = old_show_all_errors; + if (free_pattern_list) { + clear_pattern_list(pl); + free(pl); + o->internal.pl = NULL; + } trace_performance_leave("update_sparsity"); return ret; } @@ -2244,15 +2257,15 @@ static int verify_uptodate_sparse(const struct cache_entry *ce, } /* - * TODO: We should actually invalidate o->result, not src_index [1]. + * TODO: We should actually invalidate o->internal.result, not src_index [1]. * But since cache tree and untracked cache both are not copied to - * o->result until unpacking is complete, we invalidate them on + * o->internal.result until unpacking is complete, we invalidate them on * src_index instead with the assumption that they will be copied to * dst_index at the end. * * [1] src_index->cache_tree is also used in unpack_callback() so if - * we invalidate o->result, we need to update it to use - * o->result.cache_tree as well. + * we invalidate o->internal.result, we need to update it to use + * o->internal.result.cache_tree as well. */ static void invalidate_ce_path(const struct cache_entry *ce, struct unpack_trees_options *o) @@ -2336,8 +2349,8 @@ static int verify_clean_subdirectory(const struct cache_entry *ce, pathbuf = xstrfmt("%.*s/", namelen, ce->name); memset(&d, 0, sizeof(d)); - if (o->dir) - d.exclude_per_dir = o->dir->exclude_per_dir; + if (o->internal.dir) + setup_standard_excludes(&d); i = read_directory(&d, o->src_index, pathbuf, namelen+1, NULL); dir_clear(&d); free(pathbuf); @@ -2391,8 +2404,8 @@ static int check_ok_to_remove(const char *name, int len, int dtype, if (ignore_case && icase_exists(o, name, len, st)) return 0; - if (o->dir && - is_excluded(o->dir, o->src_index, name, &dtype)) + if (o->internal.dir && + is_excluded(o->internal.dir, o->src_index, name, &dtype)) /* * ce->name is explicitly excluded, so it is Ok to * overwrite it. @@ -2420,7 +2433,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype, * delete this path, which is in a subdirectory that * is being replaced with a blob. */ - result = index_file_exists(&o->result, name, len, 0); + result = index_file_exists(&o->internal.result, name, len, 0); if (result) { if (result->ce_flags & CE_REMOVE) return 0; @@ -2521,7 +2534,7 @@ static int merged_entry(const struct cache_entry *ce, struct unpack_trees_options *o) { int update = CE_UPDATE; - struct cache_entry *merge = dup_cache_entry(ce, &o->result); + struct cache_entry *merge = dup_cache_entry(ce, &o->internal.result); if (!old) { /* @@ -2616,7 +2629,7 @@ static int merged_sparse_dir(const struct cache_entry * const *src, int n, setup_traverse_info(&info, src[0]->name); info.fn = unpack_sparse_callback; info.data = o; - info.show_all_errors = o->show_all_errors; + info.show_all_errors = o->internal.show_all_errors; info.pathspec = o->pathspec; /* Get the tree descriptors of the sparse directory in each of the merging trees */ @@ -2834,7 +2847,7 @@ int threeway_merge(const struct cache_entry * const *stages, return -1; } - o->nontrivial_merge = 1; + o->internal.nontrivial_merge = 1; /* #2, #3, #4, #6, #7, #9, #10, #11. */ count = 0; @@ -2875,9 +2888,9 @@ int twoway_merge(const struct cache_entry * const *src, const struct cache_entry *oldtree = src[1]; const struct cache_entry *newtree = src[2]; - if (o->merge_size != 2) + if (o->internal.merge_size != 2) return error("Cannot do a twoway merge of %d trees", - o->merge_size); + o->internal.merge_size); if (oldtree == o->df_conflict_entry) oldtree = NULL; @@ -2957,9 +2970,9 @@ int bind_merge(const struct cache_entry * const *src, const struct cache_entry *old = src[0]; const struct cache_entry *a = src[1]; - if (o->merge_size != 1) + if (o->internal.merge_size != 1) return error("Cannot do a bind merge of %d trees", - o->merge_size); + o->internal.merge_size); if (a && old) return o->quiet ? -1 : error(ERRORMSG(o, ERROR_BIND_OVERLAP), @@ -2983,9 +2996,9 @@ int oneway_merge(const struct cache_entry * const *src, const struct cache_entry *old = src[0]; const struct cache_entry *a = src[1]; - if (o->merge_size != 1) + if (o->internal.merge_size != 1) return error("Cannot do a oneway merge of %d trees", - o->merge_size); + o->internal.merge_size); if (!a || a == o->df_conflict_entry) return deleted_entry(old, old, o); @@ -3020,8 +3033,8 @@ int stash_worktree_untracked_merge(const struct cache_entry * const *src, const struct cache_entry *worktree = src[1]; const struct cache_entry *untracked = src[2]; - if (o->merge_size != 2) - BUG("invalid merge_size: %d", o->merge_size); + if (o->internal.merge_size != 2) + BUG("invalid merge_size: %d", o->internal.merge_size); if (worktree && untracked) return error(_("worktree and untracked commit have duplicate entries: %s"), diff --git a/unpack-trees.h b/unpack-trees.h index 3a7b3e5f00..61c06eb7c5 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -59,47 +59,54 @@ struct unpack_trees_options { preserve_ignored, clone, index_only, - nontrivial_merge, trivial_merges_only, verbose_update, aggressive, skip_unmerged, initial_checkout, diff_index_cached, - debug_unpack, skip_sparse_checkout, quiet, exiting_early, - show_all_errors, dry_run, skip_cache_tree_update; enum unpack_trees_reset_type reset; const char *prefix; const char *super_prefix; - int cache_bottom; struct pathspec *pathspec; merge_fn_t fn; - const char *msgs[NB_UNPACK_TREES_WARNING_TYPES]; - struct strvec msgs_to_free; - /* - * Store error messages in an array, each case - * corresponding to a error message type - */ - struct string_list unpack_rejects[NB_UNPACK_TREES_WARNING_TYPES]; int head_idx; - int merge_size; - struct cache_entry *df_conflict_entry; + struct cache_entry *df_conflict_entry; /* output only */ void *unpack_data; struct index_state *dst_index; struct index_state *src_index; - struct index_state result; - struct pattern_list *pl; /* for internal use */ - struct dir_struct *dir; /* for internal use only */ struct checkout_metadata meta; + + struct unpack_trees_options_internal { + unsigned int nontrivial_merge, + show_all_errors, + debug_unpack; /* used by read-tree debugging */ + + int merge_size; /* used by read-tree debugging */ + int cache_bottom; + const char *msgs[NB_UNPACK_TREES_WARNING_TYPES]; + struct strvec msgs_to_free; + + /* + * Store error messages in an array, each case + * corresponding to a error message type + */ + struct string_list unpack_rejects[NB_UNPACK_TREES_WARNING_TYPES]; + + struct index_state result; + + struct pattern_list *pl; + struct dir_struct *dir; + } internal; }; int unpack_trees(unsigned n, struct tree_desc *t, @@ -112,7 +119,8 @@ enum update_sparsity_result { UPDATE_SPARSITY_WORKTREE_UPDATE_FAILURES = -2 }; -enum update_sparsity_result update_sparsity(struct unpack_trees_options *options); +enum update_sparsity_result update_sparsity(struct unpack_trees_options *options, + struct pattern_list *pl); int verify_uptodate(const struct cache_entry *ce, struct unpack_trees_options *o); diff --git a/upload-pack.c b/upload-pack.c index 4ef27ed47f..e23f16dfdd 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -1,5 +1,8 @@ #include "cache.h" #include "config.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "refs.h" #include "pkt-line.h" #include "sideband.h" @@ -27,6 +30,7 @@ #include "commit-graph.h" #include "commit-reach.h" #include "shallow.h" +#include "write-or-die.h" /* Remember to update object flag allocation in object.h */ #define THEY_HAVE (1u << 11) @@ -1699,7 +1703,7 @@ enum fetch_state { FETCH_DONE, }; -int upload_pack_v2(struct repository *r, struct packet_reader *request) +int upload_pack_v2(struct repository *r UNUSED, struct packet_reader *request) { enum fetch_state state = FETCH_PROCESS_ARGS; struct upload_pack_data data; @@ -1775,26 +1779,26 @@ int upload_pack_advertise(struct repository *r, strbuf_addstr(value, "shallow wait-for-done"); - if (!repo_config_get_bool(the_repository, + if (!repo_config_get_bool(r, "uploadpack.allowfilter", &allow_filter_value) && allow_filter_value) strbuf_addstr(value, " filter"); - if (!repo_config_get_bool(the_repository, + if (!repo_config_get_bool(r, "uploadpack.allowrefinwant", &allow_ref_in_want) && allow_ref_in_want) strbuf_addstr(value, " ref-in-want"); if (git_env_bool("GIT_TEST_SIDEBAND_ALL", 0) || - (!repo_config_get_bool(the_repository, + (!repo_config_get_bool(r, "uploadpack.allowsidebandall", &allow_sideband_all_value) && allow_sideband_all_value)) strbuf_addstr(value, " sideband-all"); - if (!repo_config_get_string(the_repository, + if (!repo_config_get_string(r, "uploadpack.blobpackfileuri", &str) && str) { @@ -1,4 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "hex.h" +#include "strbuf.h" #include "url.h" int is_urlschemechar(int first_flag, int ch) diff --git a/urlmatch.c b/urlmatch.c index 620a648efc..eba0bdd77f 100644 --- a/urlmatch.c +++ b/urlmatch.c @@ -1,4 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "gettext.h" +#include "hex.h" +#include "strbuf.h" #include "urlmatch.h" #define URL_ALPHA "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" @@ -4,7 +4,9 @@ * Copyright (C) Linus Torvalds, 2005 */ #include "git-compat-util.h" -#include "cache.h" +#include "gettext.h" +#include "trace2.h" +#include "wrapper.h" static void vreportf(const char *prefix, const char *err, va_list params) { diff --git a/userdiff.c b/userdiff.c index 58a3d59ef8..09203fbc35 100644 --- a/userdiff.c +++ b/userdiff.c @@ -1,7 +1,9 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "alloc.h" #include "config.h" #include "userdiff.h" #include "attr.h" +#include "strbuf.h" static struct userdiff_driver *drivers; static int ndrivers; @@ -1,4 +1,6 @@ #include "cache.h" +#include "gettext.h" +#include "hex.h" #include "walker.h" #include "repository.h" #include "object-store.h" diff --git a/wildmatch.c b/wildmatch.c index 7e5a7ea1ea..42e38e3459 100644 --- a/wildmatch.c +++ b/wildmatch.c @@ -9,7 +9,7 @@ ** work differently than '*', and to fix the character-class code. */ -#include "cache.h" +#include "git-compat-util.h" #include "wildmatch.h" typedef unsigned char uchar; diff --git a/worktree.c b/worktree.c index aa43c64119..b5ee71c5eb 100644 --- a/worktree.c +++ b/worktree.c @@ -1,11 +1,17 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "abspath.h" +#include "alloc.h" +#include "environment.h" +#include "gettext.h" #include "repository.h" #include "refs.h" +#include "setup.h" #include "strbuf.h" #include "worktree.h" #include "dir.h" #include "wt-status.h" #include "config.h" +#include "wrapper.h" void free_worktrees(struct worktree **worktrees) { @@ -403,44 +409,43 @@ int is_worktree_being_bisected(const struct worktree *wt, * bisect). New commands that do similar things should update this * function as well. */ -const struct worktree *find_shared_symref(struct worktree **worktrees, - const char *symref, - const char *target) +int is_shared_symref(const struct worktree *wt, const char *symref, + const char *target) { - const struct worktree *existing = NULL; - int i = 0; + const char *symref_target; + struct ref_store *refs; + int flags; - for (i = 0; worktrees[i]; i++) { - struct worktree *wt = worktrees[i]; - const char *symref_target; - struct ref_store *refs; - int flags; + if (wt->is_bare) + return 0; - if (wt->is_bare) - continue; + if (wt->is_detached && !strcmp(symref, "HEAD")) { + if (is_worktree_being_rebased(wt, target)) + return 1; + if (is_worktree_being_bisected(wt, target)) + return 1; + } - if (wt->is_detached && !strcmp(symref, "HEAD")) { - if (is_worktree_being_rebased(wt, target)) { - existing = wt; - break; - } - if (is_worktree_being_bisected(wt, target)) { - existing = wt; - break; - } - } + refs = get_worktree_ref_store(wt); + symref_target = refs_resolve_ref_unsafe(refs, symref, 0, + NULL, &flags); + if ((flags & REF_ISSYMREF) && + symref_target && !strcmp(symref_target, target)) + return 1; - refs = get_worktree_ref_store(wt); - symref_target = refs_resolve_ref_unsafe(refs, symref, 0, - NULL, &flags); - if ((flags & REF_ISSYMREF) && - symref_target && !strcmp(symref_target, target)) { - existing = wt; - break; - } - } + return 0; +} - return existing; +const struct worktree *find_shared_symref(struct worktree **worktrees, + const char *symref, + const char *target) +{ + + for (int i = 0; worktrees[i]; i++) + if (is_shared_symref(worktrees[i], symref, target)) + return worktrees[i]; + + return NULL; } int submodule_uses_worktrees(const char *path) diff --git a/worktree.h b/worktree.h index 9dcea6fc8c..ce45b66de9 100644 --- a/worktree.h +++ b/worktree.h @@ -1,7 +1,6 @@ #ifndef WORKTREE_H #define WORKTREE_H -#include "cache.h" #include "refs.h" struct strbuf; @@ -150,6 +149,12 @@ const struct worktree *find_shared_symref(struct worktree **worktrees, const char *target); /* + * Returns true if a symref points to a ref in a worktree. + */ +int is_shared_symref(const struct worktree *wt, + const char *symref, const char *target); + +/* * Similar to head_ref() for all HEADs _except_ one from the current * worktree, which is covered by head_ref(). */ @@ -2,7 +2,10 @@ * Various trivial helper wrappers around standard functions */ #include "cache.h" +#include "abspath.h" #include "config.h" +#include "gettext.h" +#include "wrapper.h" static intmax_t count_fsync_writeout_only; static intmax_t count_fsync_hardware_flush; diff --git a/wrapper.h b/wrapper.h new file mode 100644 index 0000000000..f0c7d0616d --- /dev/null +++ b/wrapper.h @@ -0,0 +1,36 @@ +#ifndef WRAPPER_H +#define WRAPPER_H + +/* set default permissions by passing mode arguments to open(2) */ +int git_mkstemps_mode(char *pattern, int suffix_len, int mode); +int git_mkstemp_mode(char *pattern, int mode); + +ssize_t read_in_full(int fd, void *buf, size_t count); +ssize_t write_in_full(int fd, const void *buf, size_t count); +ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset); + +static inline ssize_t write_str_in_full(int fd, const char *str) +{ + return write_in_full(fd, str, strlen(str)); +} + +/** + * Open (and truncate) the file at path, write the contents of buf to it, + * and close it. Dies if any errors are encountered. + */ +void write_file_buf(const char *path, const char *buf, size_t len); + +/** + * Like write_file_buf(), but format the contents into a buffer first. + * Additionally, write_file() will append a newline if one is not already + * present, making it convenient to write text files: + * + * write_file(path, "counter: %d", ctr); + */ +__attribute__((format (printf, 2, 3))) +void write_file(const char *path, const char *fmt, ...); + +/* Return 1 if the file is empty or does not exists, 0 otherwise. */ +int is_empty_or_missing_file(const char *filename); + +#endif /* WRAPPER_H */ diff --git a/write-or-die.c b/write-or-die.c index aaa0318e82..cc9e0787a1 100644 --- a/write-or-die.c +++ b/write-or-die.c @@ -1,6 +1,8 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "run-command.h" +#include "wrapper.h" +#include "write-or-die.h" /* * Some cases use stdio, but want to flush after the write diff --git a/write-or-die.h b/write-or-die.h new file mode 100644 index 0000000000..65a5c42a47 --- /dev/null +++ b/write-or-die.h @@ -0,0 +1,78 @@ +#ifndef WRITE_OR_DIE_H +#define WRITE_OR_DIE_H + +void maybe_flush_or_die(FILE *, const char *); +__attribute__((format (printf, 2, 3))) +void fprintf_or_die(FILE *, const char *fmt, ...); +void fwrite_or_die(FILE *f, const void *buf, size_t count); +void fflush_or_die(FILE *f); +void write_or_die(int fd, const void *buf, size_t count); + +/* + * These values are used to help identify parts of a repository to fsync. + * FSYNC_COMPONENT_NONE identifies data that will not be a persistent part of the + * repository and so shouldn't be fsynced. + */ +enum fsync_component { + FSYNC_COMPONENT_NONE, + FSYNC_COMPONENT_LOOSE_OBJECT = 1 << 0, + FSYNC_COMPONENT_PACK = 1 << 1, + FSYNC_COMPONENT_PACK_METADATA = 1 << 2, + FSYNC_COMPONENT_COMMIT_GRAPH = 1 << 3, + FSYNC_COMPONENT_INDEX = 1 << 4, + FSYNC_COMPONENT_REFERENCE = 1 << 5, +}; + +#define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \ + FSYNC_COMPONENT_PACK) + +#define FSYNC_COMPONENTS_DERIVED_METADATA (FSYNC_COMPONENT_PACK_METADATA | \ + FSYNC_COMPONENT_COMMIT_GRAPH) + +#define FSYNC_COMPONENTS_DEFAULT ((FSYNC_COMPONENTS_OBJECTS | \ + FSYNC_COMPONENTS_DERIVED_METADATA) & \ + ~FSYNC_COMPONENT_LOOSE_OBJECT) + +#define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \ + FSYNC_COMPONENT_REFERENCE) + +#define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \ + FSYNC_COMPONENT_INDEX) + +#define FSYNC_COMPONENTS_ALL (FSYNC_COMPONENT_LOOSE_OBJECT | \ + FSYNC_COMPONENT_PACK | \ + FSYNC_COMPONENT_PACK_METADATA | \ + FSYNC_COMPONENT_COMMIT_GRAPH | \ + FSYNC_COMPONENT_INDEX | \ + FSYNC_COMPONENT_REFERENCE) + +#ifndef FSYNC_COMPONENTS_PLATFORM_DEFAULT +#define FSYNC_COMPONENTS_PLATFORM_DEFAULT FSYNC_COMPONENTS_DEFAULT +#endif + +/* IO helper functions */ +void fsync_or_die(int fd, const char *); +int fsync_component(enum fsync_component component, int fd); +void fsync_component_or_die(enum fsync_component component, int fd, const char *msg); + +/* + * A bitmask indicating which components of the repo should be fsynced. + */ +extern enum fsync_component fsync_components; +extern int fsync_object_files; +extern int use_fsync; + +enum fsync_method { + FSYNC_METHOD_FSYNC, + FSYNC_METHOD_WRITEOUT_ONLY, + FSYNC_METHOD_BATCH, +}; + +extern enum fsync_method fsync_method; + +static inline int batch_fsync_enabled(enum fsync_component component) +{ + return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH); +} + +#endif /* WRITE_OR_DIE_H */ diff --git a/wt-status.c b/wt-status.c index 28e35a2165..4bef09de1c 100644 --- a/wt-status.c +++ b/wt-status.c @@ -4,6 +4,9 @@ #include "dir.h" #include "commit.h" #include "diff.h" +#include "environment.h" +#include "gettext.h" +#include "hex.h" #include "revision.h" #include "diffcore.h" #include "quote.h" @@ -13,6 +16,7 @@ #include "refs.h" #include "submodule.h" #include "column.h" +#include "setup.h" #include "strbuf.h" #include "utf8.h" #include "worktree.h" diff --git a/xdiff-interface.c b/xdiff-interface.c index c6f244116c..0460e03f5e 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -1,5 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" +#include "hex.h" #include "object-store.h" #include "xdiff-interface.h" #include "xdiff/xtypes.h" diff --git a/xdiff-interface.h b/xdiff-interface.h index 4301a7eef2..3750794afe 100644 --- a/xdiff-interface.h +++ b/xdiff-interface.h @@ -1,7 +1,7 @@ #ifndef XDIFF_INTERFACE_H #define XDIFF_INTERFACE_H -#include "cache.h" +#include "hash.h" #include "xdiff/xdiff.h" /* |