diff options
235 files changed, 1129 insertions, 644 deletions
diff --git a/Documentation/RelNotes/2.41.0.txt b/Documentation/RelNotes/2.41.0.txt index b737371148..e2aa9720f3 100644 --- a/Documentation/RelNotes/2.41.0.txt +++ b/Documentation/RelNotes/2.41.0.txt @@ -79,6 +79,10 @@ UI, Workflows & Features of cruft packs has been made the default and no longer considered an experimental feature. + * The output given by "git blame" that attributes a line to contents + taken from the file specified by the "--contents" option shows it + differently from a line attributed to the working tree file. + Performance, Internal Implementation, Development Support etc. @@ -125,6 +129,14 @@ Performance, Internal Implementation, Development Support etc. * "git fsck" learned to validate the on-disk pack reverse index files. + * strtok() and strtok_r() are banned in this codebase. + + * The detect-compilers script to help auto-tweaking the build system + had trouble working with compilers whose version number has extra + suffixes. The script has been taught that certain suffixes (like + "-win32" in "gcc 10-win32") can be safely stripped as they share + the same features and bugs with the version without the suffix. + Fixes since v2.40 ----------------- @@ -269,6 +281,23 @@ Fixes since v2.40 key, which has been corrected. (merge 7891e46585 jk/gpg-trust-level-fix later to maint). + * The completion script used to use bare "read" without the "-r" + option to read the contents of various state files, which risked + getting confused with backslashes in them. This has been + corrected. + (merge 197152098a ek/completion-use-read-r-to-read-literally later to maint). + + * A small API fix to the ort merge strategy backend. + (merge 000c4ceca7 en/ort-finalize-after-0-merges-fix later to maint). + + * The commit object parser has been taught to be a bit more lenient + to parse timestamps on the author/committer line with a malformed + author/committer ident. + (merge 90ef0f14eb jk/parse-commit-with-malformed-ident later to maint). + + * Retitle a test script with an overly narrow name. + (merge 8bb19c14fb ob/t3501-retitle later to maint). + * Other code cleanup, docfix, build fix, etc. (merge f7111175df as/doc-markup-fix later to maint). (merge 90ff7c9898 fc/test-aggregation-clean-up later to maint). @@ -285,3 +314,5 @@ Fixes since v2.40 (merge 4833b08426 ow/ref-format-remove-unused-member later to maint). (merge d0ea2ca1cf dw/doc-submittingpatches-grammofix later to maint). (merge fd72637423 ar/t2024-checkout-output-fix later to maint). + (merge d45cbe3fe0 ob/sequencer-i18n-fix later to maint). + (merge b734fe49fd ob/messages-capitalize-exception later to maint). diff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt index 95599bd6e5..552dcc60f2 100644 --- a/Documentation/blame-options.txt +++ b/Documentation/blame-options.txt @@ -64,11 +64,9 @@ include::line-range-format.txt[] manual page. --contents <file>:: - Pretend the file being annotated has a commit with the - contents from the named file and a parent of <rev>, - defaulting to HEAD when no <rev> is specified. You may - specify '-' to make the command read from the standard - input for the file contents. + Annotate using the contents from the named file, starting from <rev> + if it is specified, and HEAD otherwise. You may specify '-' to make + the command read from the standard input for the file contents. --date <format>:: Specifies the format used to output dates. If --date is not diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt index b0f438ec99..6e988a83c5 100644 --- a/Documentation/git-send-email.txt +++ b/Documentation/git-send-email.txt @@ -484,14 +484,10 @@ edit ~/.gitconfig to specify your account settings: smtpServerPort = 587 ---- -If you have multi-factor authentication set up on your Gmail account, you will -need to generate an app-specific password for use with 'git send-email'. Visit +If you have multi-factor authentication set up on your Gmail account, you can +generate an app-specific password for use with 'git send-email'. Visit https://security.google.com/settings/security/apppasswords to create it. -If you do not have multi-factor authentication set up on your Gmail account, -you will need to allow less secure app access. Visit -https://myaccount.google.com/lesssecureapps to enable it. - Once your commits are ready to be sent to the mailing list, run the following commands: diff --git a/add-interactive.c b/add-interactive.c index 757a9929d4..de877ca052 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -12,6 +12,7 @@ #include "dir.h" #include "run-command.h" #include "prompt.h" +#include "tree.h" static void init_color(struct repository *r, struct add_i_state *s, const char *section_and_slot, char *dst, @@ -13,6 +13,7 @@ #include "blob.h" #include "tree.h" #include "commit.h" +#include "repository.h" #include "tag.h" #include "alloc.h" @@ -10,6 +10,7 @@ #include "cache.h" #include "abspath.h" #include "alloc.h" +#include "base85.h" #include "config.h" #include "object-store.h" #include "blob.h" @@ -30,6 +31,8 @@ #include "apply.h" #include "entry.h" #include "setup.h" +#include "symlinks.h" +#include "ws.h" #include "wrapper.h" struct gitdiff_data { @@ -1,7 +1,7 @@ #ifndef APPLY_H #define APPLY_H -#include "hash.h" +#include "hash-ll.h" #include "lockfile.h" #include "string-list.h" #include "strmap.h" diff --git a/archive-zip.c b/archive-zip.c index ef538a90df..d0d065a312 100644 --- a/archive-zip.c +++ b/archive-zip.c @@ -1,7 +1,7 @@ /* * Copyright (c) 2006 Rene Scharfe */ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "archive.h" #include "gettext.h" @@ -6,10 +6,12 @@ #include "environment.h" #include "gettext.h" #include "hex.h" +#include "pretty.h" #include "setup.h" #include "refs.h" #include "object-store.h" #include "commit.h" +#include "tree.h" #include "tree-walk.h" #include "attr.h" #include "archive.h" @@ -20,6 +20,7 @@ #include "object-store.h" #include "setup.h" #include "thread-utils.h" +#include "tree-walk.h" const char git_attr__true[] = "(builtin)true"; const char git_attr__false[] = "\0(builtin)false"; @@ -18,6 +18,10 @@ #define strncpy(x,y,n) BANNED(strncpy) #undef strncat #define strncat(x,y,n) BANNED(strncat) +#undef strtok +#define strtok(x,y) BANNED(strtok) +#undef strtok_r +#define strtok_r(x,y,z) BANNED(strtok_r) #undef sprintf #undef vsprintf @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "base85.h" #undef DEBUG_85 diff --git a/base85.h b/base85.h new file mode 100644 index 0000000000..c835086e09 --- /dev/null +++ b/base85.h @@ -0,0 +1,7 @@ +#ifndef BASE85_H +#define BASE85_H + +int decode_85(char *dst, const char *line, int linelen); +void encode_85(char *buf, const unsigned char *data, int bytes); + +#endif /* BASE85_H */ @@ -208,8 +208,12 @@ static struct commit *fake_working_tree_commit(struct repository *r, origin = make_origin(commit, path); - ident = fmt_ident("Not Committed Yet", "not.committed.yet", - WANT_BLANK_IDENT, NULL, 0); + if (contents_from) + ident = fmt_ident("External file (--contents)", "external.file", + WANT_BLANK_IDENT, NULL, 0); + else + ident = fmt_ident("Not Committed Yet", "not.committed.yet", + WANT_BLANK_IDENT, NULL, 0); strbuf_addstr(&msg, "tree 0000000000000000000000000000000000000000\n"); for (parent = commit->parents; parent; parent = parent->next) strbuf_addf(&msg, "parent %s\n", @@ -6,6 +6,7 @@ #include "hashmap.h" #include "commit-graph.h" #include "commit.h" +#include "commit-slab.h" define_commit_slab(bloom_filter_slab, struct bloom_filter); @@ -9,6 +9,7 @@ #include "refs.h" #include "refspec.h" #include "remote.h" +#include "repository.h" #include "sequencer.h" #include "commit.h" #include "worktree.h" diff --git a/builtin/apply.c b/builtin/apply.c index fe72c0ec3e..e3ff02a09e 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -2,6 +2,7 @@ #include "builtin.h" #include "gettext.h" #include "parse-options.h" +#include "repository.h" #include "apply.h" static const char * const apply_usage[] = { diff --git a/builtin/archive.c b/builtin/archive.c index d13934f1a8..b0eaa3c14a 100644 --- a/builtin/archive.c +++ b/builtin/archive.c @@ -9,6 +9,7 @@ #include "transport.h" #include "parse-options.h" #include "pkt-line.h" +#include "repository.h" #include "sideband.h" static void create_output_file(const char *output_file) diff --git a/builtin/bisect.c b/builtin/bisect.c index 4b2143d455..4812450c39 100644 --- a/builtin/bisect.c +++ b/builtin/bisect.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "copy.h" #include "environment.h" #include "gettext.h" #include "hex.h" diff --git a/builtin/bundle.c b/builtin/bundle.c index e68fc83d94..44113389d7 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -4,6 +4,8 @@ #include "setup.h" #include "strvec.h" #include "parse-options.h" +#include "pkt-line.h" +#include "repository.h" #include "cache.h" #include "bundle.h" diff --git a/builtin/check-attr.c b/builtin/check-attr.c index 037bf1aaa2..b2b678847f 100644 --- a/builtin/check-attr.c +++ b/builtin/check-attr.c @@ -7,6 +7,7 @@ #include "gettext.h" #include "object-name.h" #include "quote.h" +#include "repository.h" #include "setup.h" #include "parse-options.h" #include "write-or-die.h" diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c index 9401dad007..e4b78782a3 100644 --- a/builtin/check-ignore.c +++ b/builtin/check-ignore.c @@ -7,6 +7,7 @@ #include "quote.h" #include "pathspec.h" #include "parse-options.h" +#include "repository.h" #include "submodule.h" #include "write-or-die.h" diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c index 7df673e3e7..9375a05539 100644 --- a/builtin/checkout-index.c +++ b/builtin/checkout-index.c @@ -11,6 +11,7 @@ #include "gettext.h" #include "lockfile.h" #include "quote.h" +#include "repository.h" #include "cache-tree.h" #include "parse-options.h" #include "entry.h" diff --git a/builtin/checkout.c b/builtin/checkout.c index 6f5d82ed3d..715eeb5048 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -28,6 +28,7 @@ #include "setup.h" #include "submodule.h" #include "submodule-config.h" +#include "symlinks.h" #include "trace2.h" #include "tree.h" #include "tree-walk.h" diff --git a/builtin/clean.c b/builtin/clean.c index 14c0d555ea..78852d28ce 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -14,6 +14,7 @@ #include "dir.h" #include "gettext.h" #include "parse-options.h" +#include "repository.h" #include "setup.h" #include "string-list.h" #include "quote.h" diff --git a/builtin/clone.c b/builtin/clone.c index 186845ef0b..15f9912b4c 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -13,6 +13,7 @@ #include "abspath.h" #include "advice.h" #include "config.h" +#include "copy.h" #include "environment.h" #include "gettext.h" #include "hex.h" @@ -38,6 +39,7 @@ #include "setup.h" #include "connected.h" #include "packfile.h" +#include "pkt-line.h" #include "list-objects-filter-options.h" #include "hook.h" #include "bundle.h" diff --git a/builtin/config.c b/builtin/config.c index 9401f1e5e3..ff2fe8ef12 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -9,6 +9,7 @@ #include "ident.h" #include "parse-options.h" #include "urlmatch.h" +#include "path.h" #include "quote.h" #include "setup.h" #include "worktree.h" diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c index 508da4c6e4..0ffacfdd83 100644 --- a/builtin/credential-cache.c +++ b/builtin/credential-cache.c @@ -1,6 +1,7 @@ #include "builtin.h" #include "gettext.h" #include "parse-options.h" +#include "path.h" #include "wrapper.h" #include "write-or-die.h" diff --git a/builtin/credential-store.c b/builtin/credential-store.c index 8977604eb9..30c6ccf56c 100644 --- a/builtin/credential-store.c +++ b/builtin/credential-store.c @@ -3,6 +3,7 @@ #include "gettext.h" #include "lockfile.h" #include "credential.h" +#include "path.h" #include "string-list.h" #include "parse-options.h" #include "write-or-die.h" diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index 385c2d0230..0b02c62b85 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -9,6 +9,7 @@ #include "builtin.h" #include "submodule.h" #include "repository.h" +#include "tree.h" static struct rev_info log_tree_opt; diff --git a/builtin/diff.c b/builtin/diff.c index 5a6a5d7f4b..7b64659fe7 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -22,6 +22,7 @@ #include "setup.h" #include "submodule.h" #include "oid-array.h" +#include "tree.h" #define DIFF_NO_INDEX_EXPLICIT 1 #define DIFF_NO_INDEX_IMPLICIT 2 diff --git a/builtin/difftool.c b/builtin/difftool.c index f09d24d37f..0049342f5c 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -15,6 +15,7 @@ #include "cache.h" #include "abspath.h" #include "config.h" +#include "copy.h" #include "builtin.h" #include "run-command.h" #include "environment.h" diff --git a/builtin/fetch.c b/builtin/fetch.c index ab623f41b4..4d7c289752 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -29,6 +29,7 @@ #include "utf8.h" #include "packfile.h" #include "pager.h" +#include "pkt-line.h" #include "list-objects-filter-options.h" #include "commit-reach.h" #include "branch.h" diff --git a/builtin/for-each-repo.c b/builtin/for-each-repo.c index 598ca16c46..37daf7bec1 100644 --- a/builtin/for-each-repo.c +++ b/builtin/for-each-repo.c @@ -3,6 +3,8 @@ #include "builtin.h" #include "gettext.h" #include "parse-options.h" +#include "path.h" +#include "repository.h" #include "run-command.h" #include "string-list.h" diff --git a/builtin/gc.c b/builtin/gc.c index c9f8557335..f3942188a6 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -12,6 +12,7 @@ #include "builtin.h" #include "abspath.h" +#include "date.h" #include "environment.h" #include "hex.h" #include "repository.h" @@ -1685,11 +1686,11 @@ static int get_schedule_cmd(const char **cmd, int *is_available) if (is_available) *is_available = 0; - string_list_split_in_place(&list, testing, ',', -1); + string_list_split_in_place(&list, testing, ",", -1); for_each_string_list_item(item, &list) { struct string_list pair = STRING_LIST_INIT_NODUP; - if (string_list_split_in_place(&pair, item->string, ':', 2) != 2) + if (string_list_split_in_place(&pair, item->string, ":", 2) != 2) continue; if (!strcmp(*cmd, pair.items[0].string)) { diff --git a/builtin/help.c b/builtin/help.c index 128aa83099..d3cf4af3f6 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -8,6 +8,7 @@ #include "gettext.h" #include "pager.h" #include "parse-options.h" +#include "path.h" #include "run-command.h" #include "config-list.h" #include "help.h" diff --git a/builtin/init-db.c b/builtin/init-db.c index 6183f3fb3f..aef4036105 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -6,6 +6,7 @@ #include "cache.h" #include "abspath.h" #include "config.h" +#include "copy.h" #include "environment.h" #include "gettext.h" #include "refs.h" @@ -13,6 +14,7 @@ #include "exec-cmd.h" #include "object-file.h" #include "parse-options.h" +#include "path.h" #include "setup.h" #include "worktree.h" #include "wrapper.h" diff --git a/builtin/log.c b/builtin/log.c index 4f162ff4d0..676de107d6 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -44,6 +44,7 @@ #include "commit-reach.h" #include "range-diff.h" #include "tmp-objdir.h" +#include "tree.h" #include "write-or-die.h" #define MAIL_DEFAULT_WRAP 72 diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index 3c74c4a104..cb6cb77e08 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -3,6 +3,7 @@ #include "gettext.h" #include "hex.h" #include "transport.h" +#include "pkt-line.h" #include "ref-filter.h" #include "remote.h" #include "refs.h" diff --git a/builtin/merge-index.c b/builtin/merge-index.c index b747b4ed98..ab16e70f23 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -1,6 +1,7 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "hex.h" +#include "repository.h" #include "run-command.h" static const char *pgm; diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c index 708a8ffabe..b9e980384a 100644 --- a/builtin/merge-recursive.c +++ b/builtin/merge-recursive.c @@ -3,9 +3,11 @@ #include "advice.h" #include "commit.h" #include "gettext.h" +#include "hash.h" #include "tag.h" #include "merge-recursive.h" #include "object-name.h" +#include "repository.h" #include "xdiff-interface.h" static const char builtin_merge_recursive_usage[] = diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 6b9f006ec1..aa8040c2a6 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -16,6 +16,7 @@ #include "exec-cmd.h" #include "merge-blobs.h" #include "quote.h" +#include "tree.h" static int line_termination = '\n'; diff --git a/builtin/mv.c b/builtin/mv.c index 32935af48e..665bd27448 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -18,6 +18,7 @@ #include "cache-tree.h" #include "string-list.h" #include "parse-options.h" +#include "repository.h" #include "setup.h" #include "submodule.h" #include "entry.h" diff --git a/builtin/pull.c b/builtin/pull.c index 967368ebc6..0c7bac97b7 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -1047,7 +1047,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (!opt_autostash) require_clean_work_tree(the_repository, N_("pull with rebase"), - _("please commit or stash them."), 1, 0); + _("Please commit or stash them."), 1, 0); if (get_rebase_fork_point(&rebase_fork_point, repo, *refspecs)) oidclr(&rebase_fork_point); diff --git a/builtin/push.c b/builtin/push.c index 6001e4ae0a..4e5780dd50 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -14,6 +14,8 @@ #include "remote.h" #include "transport.h" #include "parse-options.h" +#include "pkt-line.h" +#include "repository.h" #include "submodule.h" #include "submodule-config.h" #include "send-pack.h" diff --git a/builtin/read-tree.c b/builtin/read-tree.c index d61cbad96d..440f19b1b8 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -19,6 +19,7 @@ #include "dir.h" #include "builtin.h" #include "parse-options.h" +#include "repository.h" #include "resolve-undo.h" #include "setup.h" #include "submodule.h" diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index d22180435c..1a31a58367 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -33,6 +33,7 @@ #include "object-store.h" #include "protocol.h" #include "commit-reach.h" +#include "server-info.h" #include "trace.h" #include "trace2.h" #include "worktree.h" diff --git a/builtin/repack.c b/builtin/repack.c index bb7bf60e7c..0541c3ce15 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -7,6 +7,7 @@ #include "hex.h" #include "parse-options.h" #include "run-command.h" +#include "server-info.h" #include "sigchain.h" #include "strbuf.h" #include "string-list.h" diff --git a/builtin/rerere.c b/builtin/rerere.c index d4a03707b1..d4bd52797f 100644 --- a/builtin/rerere.c +++ b/builtin/rerere.c @@ -4,6 +4,7 @@ #include "dir.h" #include "gettext.h" #include "parse-options.h" +#include "repository.h" #include "string-list.h" #include "rerere.h" #include "wrapper.h" diff --git a/builtin/rm.c b/builtin/rm.c index d36072252e..b4589c824c 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -12,9 +12,11 @@ #include "dir.h" #include "cache-tree.h" #include "gettext.h" +#include "hash.h" #include "tree-walk.h" #include "object-name.h" #include "parse-options.h" +#include "repository.h" #include "string-list.h" #include "setup.h" #include "submodule.h" diff --git a/builtin/show-branch.c b/builtin/show-branch.c index 20030b75e3..7ef4a642c1 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -2,6 +2,7 @@ #include "config.h" #include "environment.h" #include "gettext.h" +#include "hash.h" #include "hex.h" #include "pretty.h" #include "refs.h" @@ -10,6 +11,7 @@ #include "strvec.h" #include "object-name.h" #include "parse-options.h" +#include "repository.h" #include "dir.h" #include "commit-slab.h" #include "date.h" diff --git a/builtin/show-index.c b/builtin/show-index.c index d4bbbbcd6c..d839e55335 100644 --- a/builtin/show-index.c +++ b/builtin/show-index.c @@ -1,9 +1,11 @@ #include "builtin.h" #include "cache.h" #include "gettext.h" +#include "hash.h" #include "hex.h" #include "pack.h" #include "parse-options.h" +#include "repository.h" static const char *const show_index_usage[] = { "git show-index [--object-format=<hash-algorithm>]", diff --git a/builtin/update-index.c b/builtin/update-index.c index 33b00cef15..5fab9ad2ec 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -9,6 +9,7 @@ #include "config.h" #include "environment.h" #include "gettext.h" +#include "hash.h" #include "hex.h" #include "lockfile.h" #include "quote.h" @@ -21,8 +22,10 @@ #include "parse-options.h" #include "pathspec.h" #include "dir.h" +#include "repository.h" #include "setup.h" #include "split-index.h" +#include "symlinks.h" #include "fsmonitor.h" #include "write-or-die.h" diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 6ca85420c3..0c59b1c9ef 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -1,11 +1,13 @@ #include "cache.h" #include "config.h" #include "gettext.h" +#include "hash.h" #include "refs.h" #include "builtin.h" #include "object-name.h" #include "parse-options.h" #include "quote.h" +#include "repository.h" #include "strvec.h" static const char * const git_update_ref_usage[] = { diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c index e7bff27ae4..19dce3c065 100644 --- a/builtin/update-server-info.c +++ b/builtin/update-server-info.c @@ -3,6 +3,7 @@ #include "builtin.h" #include "gettext.h" #include "parse-options.h" +#include "server-info.h" static const char * const update_server_info_usage[] = { "git update-server-info [-f | --force]", diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c index 7f9320ac6d..44ad400e18 100644 --- a/builtin/upload-archive.c +++ b/builtin/upload-archive.c @@ -6,6 +6,7 @@ #include "archive.h" #include "pkt-line.h" #include "sideband.h" +#include "repository.h" #include "run-command.h" #include "strvec.h" diff --git a/builtin/worktree.c b/builtin/worktree.c index a61bc32189..f3180463be 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -2,6 +2,7 @@ #include "abspath.h" #include "checkout.h" #include "config.h" +#include "copy.h" #include "builtin.h" #include "dir.h" #include "environment.h" @@ -13,6 +14,7 @@ #include "strvec.h" #include "branch.h" #include "refs.h" +#include "repository.h" #include "run-command.h" #include "hook.h" #include "sigchain.h" diff --git a/builtin/write-tree.c b/builtin/write-tree.c index 32e302a813..84b83318c9 100644 --- a/builtin/write-tree.c +++ b/builtin/write-tree.c @@ -13,6 +13,7 @@ #include "tree.h" #include "cache-tree.h" #include "parse-options.h" +#include "repository.h" static const char * const write_tree_usage[] = { N_("git write-tree [--missing-ok] [--prefix=<prefix>/]"), diff --git a/bundle-uri.c b/bundle-uri.c index e2b267cc02..2a2db1a1d3 100644 --- a/bundle-uri.c +++ b/bundle-uri.c @@ -1,6 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" #include "bundle-uri.h" #include "bundle.h" +#include "copy.h" #include "environment.h" #include "gettext.h" #include "object-store.h" @@ -795,10 +796,10 @@ int fetch_bundle_uri(struct repository *r, const char *uri, init_bundle_list(&list); /* - * Do not fetch a NULL or empty bundle URI. An empty bundle URI + * Do not fetch an empty bundle URI. An empty bundle URI * could signal that a configured bundle URI has been disabled. */ - if (!uri || !*uri) { + if (!*uri) { result = 0; goto cleanup; } @@ -4,41 +4,10 @@ #include "git-compat-util.h" #include "strbuf.h" #include "hashmap.h" -#include "gettext.h" -#include "string-list.h" #include "pathspec.h" #include "object.h" #include "statinfo.h" -#if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT) -#define DTYPE(de) ((de)->d_type) -#else -#undef DT_UNKNOWN -#undef DT_DIR -#undef DT_REG -#undef DT_LNK -#define DT_UNKNOWN 0 -#define DT_DIR 1 -#define DT_REG 2 -#define DT_LNK 3 -#define DTYPE(de) DT_UNKNOWN -#endif - -/* - * Some mode bits are also used internally for computations. - * - * They *must* not overlap with any valid modes, and they *must* not be emitted - * to outside world - i.e. appear on disk or network. In other words, it's just - * temporary fields, which we internally use, but they have to stay in-house. - * - * ( such approach is valid, as standard S_IF* fits into 16 bits, and in Git - * codebase mode is `unsigned int` which is assumed to be at least 32 bits ) - */ - -/* used internally in tree-diff */ -#define S_DIFFTREE_IFXMIN_NEQ 0x80000000 - - /* * Basic data structures for the directory cache */ @@ -586,64 +555,7 @@ extern int verify_ce_order; #define DATA_CHANGED 0x0020 #define TYPE_CHANGED 0x0040 -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, - const char *name2, size_t len2, int mode2); -int name_compare(const char *name1, size_t len1, const char *name2, size_t len2); -int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2); - -struct cache_def { - struct strbuf path; - int flags; - int track_flags; - int prefix_len_stat_func; -}; -#define CACHE_DEF_INIT { \ - .path = STRBUF_INIT, \ -} -static inline void cache_def_clear(struct cache_def *cache) -{ - strbuf_release(&cache->path); -} - -int has_symlink_leading_path(const char *name, int len); -int threaded_has_symlink_leading_path(struct cache_def *, const char *, int); -int check_leading_path(const char *name, int len, int warn_on_lstat_err); -int has_dirs_only_path(const char *name, int len, int prefix_len); -void invalidate_lstat_cache(void); -void schedule_dir_for_removal(const char *name, int len); -void remove_scheduled_dirs(void); - -struct pack_window { - struct pack_window *next; - unsigned char *base; - off_t offset; - size_t len; - unsigned int last_used; - unsigned int inuse_cnt; -}; - -struct pack_entry { - off_t offset; - struct packed_git *p; -}; - -/* Dumb servers support */ -int update_server_info(int); - -#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); - -/* base85 */ -int decode_85(char *dst, const char *line, int linelen); -void encode_85(char *buf, const unsigned char *data, int bytes); - -/* pkt-line.c */ -void packet_trace_identity(const char *prog); +int cmp_cache_name_compare(const void *a_, const void *b_); /* add */ /* @@ -655,36 +567,6 @@ int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int /* diff.c */ extern int diff_auto_refresh_index; -/* match-trees.c */ -void shift_tree(struct repository *, const struct object_id *, const struct object_id *, struct object_id *, int); -void shift_tree_by(struct repository *, const struct object_id *, const struct object_id *, struct object_id *, const char *); - -/* - * whitespace rules. - * used by both diff and apply - * last two digits are tab width - */ -#define WS_BLANK_AT_EOL 0100 -#define WS_SPACE_BEFORE_TAB 0200 -#define WS_INDENT_WITH_NON_TAB 0400 -#define WS_CR_AT_EOL 01000 -#define WS_BLANK_AT_EOF 02000 -#define WS_TAB_IN_INDENT 04000 -#define WS_TRAILING_SPACE (WS_BLANK_AT_EOL|WS_BLANK_AT_EOF) -#define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB|8) -#define WS_TAB_WIDTH_MASK 077 -/* All WS_* -- when extended, adapt diff.c emit_symbol */ -#define WS_RULE_MASK 07777 -extern unsigned whitespace_rule_cfg; -unsigned whitespace_rule(struct index_state *, const char *); -unsigned parse_whitespace_rule(const char *); -unsigned ws_check(const char *line, int len, unsigned ws_rule); -void ws_check_emit(const char *line, int len, unsigned ws_rule, FILE *stream, const char *set, const char *reset, const char *ws); -char *whitespace_error_string(unsigned ws); -void ws_fix_copy(struct strbuf *, const char *, int, unsigned, int *); -int ws_blank_line(const char *line, int len); -#define ws_tab_width(rule) ((rule) & WS_TAB_WIDTH_MASK) - /* ls-files */ void overlay_tree_on_index(struct index_state *istate, const char *tree_name, const char *prefix); @@ -730,6 +612,4 @@ int stat_validity_check(struct stat_validity *sv, const char *path); */ void stat_validity_update(struct stat_validity *sv, int fd); -int versioncmp(const char *s1, const char *s2); - #endif /* CACHE_H */ diff --git a/checkout.c b/checkout.c index 04238b2713..4256e71a7c 100644 --- a/checkout.c +++ b/checkout.c @@ -2,6 +2,7 @@ #include "object-name.h" #include "remote.h" #include "refspec.h" +#include "repository.h" #include "checkout.h" #include "config.h" #include "strbuf.h" diff --git a/checkout.h b/checkout.h index 1917f3b323..3c514a5ab4 100644 --- a/checkout.h +++ b/checkout.h @@ -1,7 +1,7 @@ #ifndef CHECKOUT_H #define CHECKOUT_H -#include "hash.h" +#include "hash-ll.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 60a73c1b14..e7d613c907 100644 --- a/chunk-format.c +++ b/chunk-format.c @@ -3,6 +3,7 @@ #include "chunk-format.h" #include "csum-file.h" #include "gettext.h" +#include "hash.h" #include "trace2.h" /* diff --git a/chunk-format.h b/chunk-format.h index 025c38f938..c7794e84ad 100644 --- a/chunk-format.h +++ b/chunk-format.h @@ -1,7 +1,7 @@ #ifndef CHUNK_FORMAT_H #define CHUNK_FORMAT_H -#include "hash.h" +#include "hash-ll.h" struct hashfile; struct chunkfile; @@ -1,10 +1,11 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "color.h" #include "editor.h" #include "gettext.h" #include "hex.h" #include "pager.h" +#include "strbuf.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 f7e9fb5747..1e3cd7fb17 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "object-store.h" #include "commit.h" #include "convert.h" @@ -13,6 +13,7 @@ #include "xdiff/xmacros.h" #include "log-tree.h" #include "refs.h" +#include "tree.h" #include "userdiff.h" #include "oid-array.h" #include "revision.h" diff --git a/commit-graph.c b/commit-graph.c index 43558b4d9b..843bdb458d 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -23,6 +23,7 @@ #include "shallow.h" #include "json-writer.h" #include "trace2.h" +#include "tree.h" #include "chunk-format.h" #include "wrapper.h" @@ -26,6 +26,7 @@ #include "run-command.h" #include "setup.h" #include "shallow.h" +#include "tree.h" #include "hook.h" static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **); @@ -96,6 +97,7 @@ struct commit *lookup_commit_reference_by_name(const char *name) static timestamp_t parse_commit_date(const char *buf, const char *tail) { const char *dateptr; + const char *eol; if (buf + 6 >= tail) return 0; @@ -107,16 +109,56 @@ static timestamp_t parse_commit_date(const char *buf, const char *tail) return 0; if (memcmp(buf, "committer", 9)) return 0; - while (buf < tail && *buf++ != '>') - /* nada */; - if (buf >= tail) + + /* + * Jump to end-of-line so that we can walk backwards to find the + * end-of-email ">". This is more forgiving of malformed cases + * because unexpected characters tend to be in the name and email + * fields. + */ + eol = memchr(buf, '\n', tail - buf); + if (!eol) return 0; - dateptr = buf; - while (buf < tail && *buf++ != '\n') - /* nada */; - if (buf >= tail) + dateptr = eol; + while (dateptr > buf && dateptr[-1] != '>') + dateptr--; + if (dateptr == buf) return 0; - /* dateptr < buf && buf[-1] == '\n', so parsing will stop at buf-1 */ + + /* + * Trim leading whitespace, but make sure we have at least one + * non-whitespace character, as parse_timestamp() will otherwise walk + * right past the newline we found in "eol" when skipping whitespace + * itself. + * + * In theory it would be sufficient to allow any character not matched + * by isspace(), but there's a catch: our isspace() does not + * necessarily match the behavior of parse_timestamp(), as the latter + * is implemented by system routines which match more exotic control + * codes, or even locale-dependent sequences. + * + * Since we expect the timestamp to be a number, we can check for that. + * Anything else (e.g., a non-numeric token like "foo") would just + * cause parse_timestamp() to return 0 anyway. + */ + while (dateptr < eol && isspace(*dateptr)) + dateptr++; + if (!isdigit(*dateptr) && *dateptr != '-') + return 0; + + /* + * We know there is at least one digit (or dash), so we'll begin + * parsing there and stop at worst case at eol. + * + * Note that we may feed parse_timestamp() extra characters here if the + * commit is malformed, and it will parse as far as it can. For + * example, "123foo456" would return "123". That might be questionable + * (versus returning "0"), but it would help in a hypothetical case + * like "123456+0100", where the whitespace from the timezone is + * missing. Since such syntactic errors may be baked into history and + * hard to correct now, let's err on trying to make our best guess + * here, rather than insist on perfect syntax. + */ return parse_timestamp(dateptr, NULL, 10); } @@ -2,13 +2,10 @@ #define COMMIT_H #include "object.h" -#include "tree.h" -#include "strbuf.h" -#include "decorate.h" -#include "gpg-interface.h" -#include "string-list.h" -#include "pretty.h" -#include "commit-slab.h" + +struct signature_check; +struct strbuf; +struct tree; #define COMMIT_NOT_FROM_GRAPH 0xFFFFFFFF #define GENERATION_NUMBER_INFINITY ((1ULL << 63) - 1) diff --git a/common-main.c b/common-main.c index f319317353..033778b3c5 100644 --- a/common-main.c +++ b/common-main.c @@ -1,8 +1,10 @@ -#include "cache.h" +#include "git-compat-util.h" #include "exec-cmd.h" #include "gettext.h" #include "attr.h" +#include "repository.h" #include "setup.h" +#include "strbuf.h" #include "trace2.h" /* diff --git a/compat/fsmonitor/fsm-health-darwin.c b/compat/fsmonitor/fsm-health-darwin.c index b9f709e854..4c291f8a06 100644 --- a/compat/fsmonitor/fsm-health-darwin.c +++ b/compat/fsmonitor/fsm-health-darwin.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "fsmonitor.h" #include "fsm-health.h" diff --git a/compat/fsmonitor/fsm-ipc-darwin.c b/compat/fsmonitor/fsm-ipc-darwin.c index eb25123fa1..793073aaa7 100644 --- a/compat/fsmonitor/fsm-ipc-darwin.c +++ b/compat/fsmonitor/fsm-ipc-darwin.c @@ -1,6 +1,8 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" +#include "gettext.h" #include "hex.h" +#include "repository.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 c9536dfb66..8928fa93ce 100644 --- a/compat/fsmonitor/fsm-ipc-win32.c +++ b/compat/fsmonitor/fsm-ipc-win32.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "config.h" #include "fsmonitor-ipc.h" +#include "path.h" const char *fsmonitor_ipc__get_path(struct repository *r) { static char *ret; diff --git a/compat/fsmonitor/fsm-listen-darwin.c b/compat/fsmonitor/fsm-listen-darwin.c index 5eb6402ab8..23e24b4b37 100644 --- a/compat/fsmonitor/fsm-listen-darwin.c +++ b/compat/fsmonitor/fsm-listen-darwin.c @@ -23,12 +23,13 @@ #endif #endif -#include "cache.h" +#include "git-compat-util.h" #include "fsmonitor.h" #include "fsm-listen.h" #include "fsmonitor--daemon.h" #include "fsmonitor-path-utils.h" #include "gettext.h" +#include "string-list.h" struct fsm_listen_data { diff --git a/compat/mingw.c b/compat/mingw.c index abbc3faf32..d06cdc6254 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -13,6 +13,7 @@ #include "../config.h" #include "../environment.h" #include "../trace2.h" +#include "../symlinks.h" #include "../wrapper.h" #include "dir.h" #include "gettext.h" diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c index 8a9881db07..a4d11376ba 100644 --- a/compat/precompose_utf8.c +++ b/compat/precompose_utf8.c @@ -9,6 +9,7 @@ #include "config.h" #include "environment.h" #include "gettext.h" +#include "path.h" #include "utf8.h" #include "precompose_utf8.h" diff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c index e3e895c78a..a4e33768f4 100644 --- a/compat/win32/trace2_win32_process_info.c +++ b/compat/win32/trace2_win32_process_info.c @@ -1,5 +1,6 @@ #include "../../cache.h" #include "../../json-writer.h" +#include "../../repository.h" #include "../../trace2.h" #include "lazyload.h" #include <Psapi.h> @@ -5,7 +5,7 @@ * Copyright (C) Johannes Schindelin, 2005 * */ -#include "cache.h" +#include "git-compat-util.h" #include "abspath.h" #include "advice.h" #include "alloc.h" @@ -35,6 +35,7 @@ #include "setup.h" #include "trace2.h" #include "worktree.h" +#include "ws.h" #include "wrapper.h" #include "write-or-die.h" diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index 76ee4ab1e5..2c030050ae 100644 --- a/contrib/completion/git-prompt.sh +++ b/contrib/completion/git-prompt.sh @@ -298,7 +298,7 @@ __git_ps1_colorize_gitstring () # variable, in that order. __git_eread () { - test -r "$1" && IFS=$'\r\n' read "$2" <"$1" + test -r "$1" && IFS=$'\r\n' read -r "$2" <"$1" } # see if a cherry-pick or revert is in progress, if the user has committed a @@ -2,6 +2,7 @@ #include "advice.h" #include "config.h" #include "convert.h" +#include "copy.h" #include "gettext.h" #include "hex.h" #include "object-store.h" @@ -4,7 +4,7 @@ #ifndef CONVERT_H #define CONVERT_H -#include "hash.h" +#include "hash-ll.h" #include "string-list.h" struct index_state; @@ -1,4 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "copy.h" +#include "path.h" #include "wrapper.h" int copy_fd(int ifd, int ofd) diff --git a/copy.h b/copy.h new file mode 100644 index 0000000000..2af77cba86 --- /dev/null +++ b/copy.h @@ -0,0 +1,10 @@ +#ifndef COPY_H +#define COPY_H + +#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); + +#endif /* COPY_H */ diff --git a/credential.c b/credential.c index 96fc0daa35..7da326aa85 100644 --- a/credential.c +++ b/credential.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "abspath.h" #include "config.h" #include "credential.h" @@ -8,6 +8,7 @@ #include "url.h" #include "prompt.h" #include "sigchain.h" +#include "strbuf.h" #include "urlmatch.h" #include "git-compat-util.h" diff --git a/csum-file.c b/csum-file.c index 82ae2973d3..daf9b06dff 100644 --- a/csum-file.c +++ b/csum-file.c @@ -10,6 +10,7 @@ #include "git-compat-util.h" #include "progress.h" #include "csum-file.h" +#include "hash.h" #include "wrapper.h" static void verify_buffer_or_die(struct hashfile *f, diff --git a/csum-file.h b/csum-file.h index 566e05cbd2..bc5bec27ac 100644 --- a/csum-file.h +++ b/csum-file.h @@ -1,7 +1,7 @@ #ifndef CSUM_FILE_H #define CSUM_FILE_H -#include "hash.h" +#include "hash-ll.h" #include "write-or-die.h" struct progress; @@ -1,8 +1,9 @@ -#include "cache.h" +#include "git-compat-util.h" #include "abspath.h" #include "alloc.h" #include "config.h" #include "environment.h" +#include "path.h" #include "pkt-line.h" #include "protocol.h" #include "run-command.h" @@ -4,10 +4,11 @@ * Copyright (C) Linus Torvalds, 2005 */ -#include "cache.h" +#include "git-compat-util.h" #include "date.h" #include "gettext.h" #include "pager.h" +#include "strbuf.h" /* * This is like mktime, but without normalization of tm_wday and tm_yday. diff --git a/detect-compiler b/detect-compiler index 50087f5670..a87650b71b 100755 --- a/detect-compiler +++ b/detect-compiler @@ -17,7 +17,15 @@ get_family() { } get_version() { - get_version_line | sed 's/^.* version \([0-9][^ ]*\).*/\1/' + # A string that begins with a digit up to the next SP + ver=$(get_version_line | sed 's/^.* version \([0-9][^ ]*\).*/\1/') + + # There are known -variant suffixes that do not affect the + # meaning of the main version number. Strip them. + ver=${ver%-win32} + ver=${ver%-posix} + + echo "$ver" } print_flags() { diff --git a/diagnose.c b/diagnose.c index f1aebf0b50..c8c7ebcfa3 100644 --- a/diagnose.c +++ b/diagnose.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "diagnose.h" #include "compat/disk.h" #include "archive.h" diff --git a/diff-lib.c b/diff-lib.c index d292405a26..60e979dc1b 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -14,6 +14,7 @@ #include "unpack-trees.h" #include "refs.h" #include "submodule.h" +#include "symlinks.h" #include "trace.h" #include "dir.h" #include "fsmonitor.h" @@ -4,6 +4,7 @@ #include "cache.h" #include "abspath.h" #include "alloc.h" +#include "base85.h" #include "config.h" #include "convert.h" #include "environment.h" @@ -40,6 +41,7 @@ #include "object-name.h" #include "setup.h" #include "strmap.h" +#include "ws.h" #include "wrapper.h" #ifdef NO_FAST_WORKING_DIRECTORY @@ -139,7 +141,7 @@ static int parse_dirstat_params(struct diff_options *options, const char *params int i; if (*params_copy) - string_list_split_in_place(¶ms, params_copy, ',', -1); + string_list_split_in_place(¶ms, params_copy, ",", -1); for (i = 0; i < params.nr; i++) { const char *p = params.items[i].string; if (!strcmp(p, "changes")) { @@ -4,7 +4,6 @@ #ifndef DIFF_H #define DIFF_H -#include "tree-walk.h" #include "pathspec.h" #include "oidset.h" #include "strbuf.h" diff --git a/diffcore.h b/diffcore.h index 1701ed50b9..5ffe4ec788 100644 --- a/diffcore.h +++ b/diffcore.h @@ -4,7 +4,7 @@ #ifndef DIFFCORE_H #define DIFFCORE_H -#include "hash.h" +#include "hash-ll.h" struct diff_options; struct mem_pool; @@ -25,7 +25,9 @@ #include "fsmonitor.h" #include "setup.h" #include "submodule-config.h" +#include "symlinks.h" #include "trace2.h" +#include "tree.h" #include "wrapper.h" /* @@ -640,4 +640,19 @@ static inline int starts_with_dot_dot_slash_native(const char *const path) return path_match_flags(path, what | PATH_MATCH_NATIVE); } + +#if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT) +#define DTYPE(de) ((de)->d_type) +#else +#undef DT_UNKNOWN +#undef DT_DIR +#undef DT_REG +#undef DT_LNK +#define DT_UNKNOWN 0 +#define DT_DIR 1 +#define DT_REG 2 +#define DT_LNK 3 +#define DTYPE(de) DT_UNKNOWN +#endif + #endif @@ -6,6 +6,7 @@ #include "environment.h" #include "gettext.h" #include "pager.h" +#include "path.h" #include "strbuf.h" #include "strvec.h" #include "run-command.h" @@ -7,6 +7,7 @@ #include "hex.h" #include "streaming.h" #include "submodule.h" +#include "symlinks.h" #include "progress.h" #include "fsmonitor.h" #include "entry.h" diff --git a/environment.c b/environment.c index 8a96997539..28d18eaca8 100644 --- a/environment.c +++ b/environment.c @@ -7,7 +7,7 @@ * even if you might want to know where the git directory etc * are. */ -#include "cache.h" +#include "git-compat-util.h" #include "abspath.h" #include "branch.h" #include "convert.h" @@ -67,7 +67,6 @@ int read_replace_refs = 1; enum eol core_eol = EOL_UNSET; int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN; char *check_roundtrip_encoding = "SHIFT-JIS"; -unsigned whitespace_rule_cfg = WS_DEFAULT_RULE; enum branch_track git_branch_track = BRANCH_TRACK_REMOTE; enum rebase_setup_type autorebase = AUTOREBASE_NEVER; enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED; diff --git a/exec-cmd.c b/exec-cmd.c index 6f61846389..1e34e48c0e 100644 --- a/exec-cmd.c +++ b/exec-cmd.c @@ -3,6 +3,7 @@ #include "environment.h" #include "exec-cmd.h" #include "gettext.h" +#include "path.h" #include "quote.h" #include "strvec.h" #include "trace.h" diff --git a/fetch-pack.c b/fetch-pack.c index 6fa6e8af9a..0f71054fba 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -2,6 +2,7 @@ #include "alloc.h" #include "repository.h" #include "config.h" +#include "date.h" #include "environment.h" #include "gettext.h" #include "hex.h" @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "alloc.h" +#include "date.h" #include "hex.h" #include "object-store.h" #include "repository.h" diff --git a/fsmonitor--daemon.h b/fsmonitor--daemon.h index e24838f9a8..70d776c54f 100644 --- a/fsmonitor--daemon.h +++ b/fsmonitor--daemon.h @@ -3,7 +3,6 @@ #ifdef HAVE_FSMONITOR_DAEMON_BACKEND -#include "cache.h" #include "dir.h" #include "run-command.h" #include "simple-ipc.h" diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c index 866828e299..6a6a89764a 100644 --- a/fsmonitor-ipc.c +++ b/fsmonitor-ipc.c @@ -3,6 +3,7 @@ #include "gettext.h" #include "simple-ipc.h" #include "fsmonitor-ipc.h" +#include "repository.h" #include "run-command.h" #include "strbuf.h" #include "trace2.h" diff --git a/gpg-interface.c b/gpg-interface.c index f3ac5acdd9..19a3471a0b 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -1,12 +1,14 @@ #include "git-compat-util.h" #include "commit.h" #include "config.h" +#include "date.h" #include "gettext.h" #include "run-command.h" #include "strbuf.h" #include "dir.h" #include "ident.h" #include "gpg-interface.h" +#include "path.h" #include "sigchain.h" #include "tempfile.h" #include "alias.h" @@ -4,6 +4,7 @@ #include "grep.h" #include "hex.h" #include "object-store.h" +#include "pretty.h" #include "userdiff.h" #include "xdiff-interface.h" #include "diff.h" diff --git a/hash-ll.h b/hash-ll.h new file mode 100644 index 0000000000..8050925137 --- /dev/null +++ b/hash-ll.h @@ -0,0 +1,276 @@ +#ifndef HASH_LL_H +#define HASH_LL_H + +#if defined(SHA1_APPLE) +#include <CommonCrypto/CommonDigest.h> +#elif defined(SHA1_OPENSSL) +#include <openssl/sha.h> +#elif defined(SHA1_DC) +#include "sha1dc_git.h" +#else /* SHA1_BLK */ +#include "block-sha1/sha1.h" +#endif + +#if defined(SHA256_NETTLE) +#include "sha256/nettle.h" +#elif defined(SHA256_GCRYPT) +#define SHA256_NEEDS_CLONE_HELPER +#include "sha256/gcrypt.h" +#elif defined(SHA256_OPENSSL) +#include <openssl/sha.h> +#else +#include "sha256/block/sha256.h" +#endif + +#ifndef platform_SHA_CTX +/* + * platform's underlying implementation of SHA-1; could be OpenSSL, + * blk_SHA, Apple CommonCrypto, etc... Note that the relevant + * SHA-1 header may have already defined platform_SHA_CTX for our + * own implementations like block-sha1, so we list + * the default for OpenSSL compatible SHA-1 implementations here. + */ +#define platform_SHA_CTX SHA_CTX +#define platform_SHA1_Init SHA1_Init +#define platform_SHA1_Update SHA1_Update +#define platform_SHA1_Final SHA1_Final +#endif + +#define git_SHA_CTX platform_SHA_CTX +#define git_SHA1_Init platform_SHA1_Init +#define git_SHA1_Update platform_SHA1_Update +#define git_SHA1_Final platform_SHA1_Final + +#ifndef platform_SHA256_CTX +#define platform_SHA256_CTX SHA256_CTX +#define platform_SHA256_Init SHA256_Init +#define platform_SHA256_Update SHA256_Update +#define platform_SHA256_Final SHA256_Final +#endif + +#define git_SHA256_CTX platform_SHA256_CTX +#define git_SHA256_Init platform_SHA256_Init +#define git_SHA256_Update platform_SHA256_Update +#define git_SHA256_Final platform_SHA256_Final + +#ifdef platform_SHA256_Clone +#define git_SHA256_Clone platform_SHA256_Clone +#endif + +#ifdef SHA1_MAX_BLOCK_SIZE +#include "compat/sha1-chunked.h" +#undef git_SHA1_Update +#define git_SHA1_Update git_SHA1_Update_Chunked +#endif + +static inline void git_SHA1_Clone(git_SHA_CTX *dst, const git_SHA_CTX *src) +{ + memcpy(dst, src, sizeof(*dst)); +} + +#ifndef SHA256_NEEDS_CLONE_HELPER +static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *src) +{ + memcpy(dst, src, sizeof(*dst)); +} +#endif + +/* + * Note that these constants are suitable for indexing the hash_algos array and + * comparing against each other, but are otherwise arbitrary, so they should not + * be exposed to the user or serialized to disk. To know whether a + * git_hash_algo struct points to some usable hash function, test the format_id + * field for being non-zero. Use the name field for user-visible situations and + * the format_id field for fixed-length fields on disk. + */ +/* An unknown hash function. */ +#define GIT_HASH_UNKNOWN 0 +/* SHA-1 */ +#define GIT_HASH_SHA1 1 +/* SHA-256 */ +#define GIT_HASH_SHA256 2 +/* Number of algorithms supported (including unknown). */ +#define GIT_HASH_NALGOS (GIT_HASH_SHA256 + 1) + +/* "sha1", big-endian */ +#define GIT_SHA1_FORMAT_ID 0x73686131 + +/* The length in bytes and in hex digits of an object name (SHA-1 value). */ +#define GIT_SHA1_RAWSZ 20 +#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ) +/* The block size of SHA-1. */ +#define GIT_SHA1_BLKSZ 64 + +/* "s256", big-endian */ +#define GIT_SHA256_FORMAT_ID 0x73323536 + +/* The length in bytes and in hex digits of an object name (SHA-256 value). */ +#define GIT_SHA256_RAWSZ 32 +#define GIT_SHA256_HEXSZ (2 * GIT_SHA256_RAWSZ) +/* The block size of SHA-256. */ +#define GIT_SHA256_BLKSZ 64 + +/* The length in byte and in hex digits of the largest possible hash value. */ +#define GIT_MAX_RAWSZ GIT_SHA256_RAWSZ +#define GIT_MAX_HEXSZ GIT_SHA256_HEXSZ +/* The largest possible block size for any supported hash. */ +#define GIT_MAX_BLKSZ GIT_SHA256_BLKSZ + +struct object_id { + unsigned char hash[GIT_MAX_RAWSZ]; + 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; + git_SHA256_CTX sha256; +}; +typedef union git_hash_ctx git_hash_ctx; + +typedef void (*git_hash_init_fn)(git_hash_ctx *ctx); +typedef void (*git_hash_clone_fn)(git_hash_ctx *dst, const git_hash_ctx *src); +typedef void (*git_hash_update_fn)(git_hash_ctx *ctx, const void *in, size_t len); +typedef void (*git_hash_final_fn)(unsigned char *hash, git_hash_ctx *ctx); +typedef void (*git_hash_final_oid_fn)(struct object_id *oid, git_hash_ctx *ctx); + +struct git_hash_algo { + /* + * The name of the algorithm, as appears in the config file and in + * messages. + */ + const char *name; + + /* A four-byte version identifier, used in pack indices. */ + uint32_t format_id; + + /* The length of the hash in binary. */ + size_t rawsz; + + /* The length of the hash in hex characters. */ + size_t hexsz; + + /* The block size of the hash. */ + size_t blksz; + + /* The hash initialization function. */ + git_hash_init_fn init_fn; + + /* The hash context cloning function. */ + git_hash_clone_fn clone_fn; + + /* The hash update function. */ + git_hash_update_fn update_fn; + + /* The hash finalization function. */ + git_hash_final_fn final_fn; + + /* The hash finalization function for object IDs. */ + git_hash_final_oid_fn final_oid_fn; + + /* The OID of the empty tree. */ + const struct object_id *empty_tree; + + /* The OID of the empty blob. */ + const struct object_id *empty_blob; + + /* The all-zeros OID. */ + const struct object_id *null_oid; +}; +extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS]; + +/* + * Return a GIT_HASH_* constant based on the name. Returns GIT_HASH_UNKNOWN if + * the name doesn't match a known algorithm. + */ +int hash_algo_by_name(const char *name); +/* Identical, except based on the format ID. */ +int hash_algo_by_id(uint32_t format_id); +/* Identical, except based on the length. */ +int hash_algo_by_length(int len); +/* Identical, except for a pointer to struct git_hash_algo. */ +static inline int hash_algo_by_ptr(const struct git_hash_algo *p) +{ + return p - hash_algos; +} + +const struct object_id *null_oid(void); + +static inline int hashcmp_algop(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop) +{ + /* + * Teach the compiler that there are only two possibilities of hash size + * here, so that it can optimize for this case as much as possible. + */ + if (algop->rawsz == GIT_MAX_RAWSZ) + return memcmp(sha1, sha2, GIT_MAX_RAWSZ); + return memcmp(sha1, sha2, GIT_SHA1_RAWSZ); +} + +static inline int hasheq_algop(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop) +{ + /* + * We write this here instead of deferring to hashcmp so that the + * compiler can properly inline it and avoid calling memcmp. + */ + if (algop->rawsz == GIT_MAX_RAWSZ) + return !memcmp(sha1, sha2, GIT_MAX_RAWSZ); + return !memcmp(sha1, sha2, GIT_SHA1_RAWSZ); +} + +static inline void oidcpy(struct object_id *dst, const struct object_id *src) +{ + memcpy(dst->hash, src->hash, GIT_MAX_RAWSZ); + dst->algo = src->algo; +} + +static inline struct object_id *oiddup(const struct object_id *src) +{ + struct object_id *dst = xmalloc(sizeof(struct object_id)); + oidcpy(dst, src); + return dst; +} + +static inline void oid_set_algo(struct object_id *oid, const struct git_hash_algo *algop) +{ + oid->algo = hash_algo_by_ptr(algop); +} + +const char *empty_tree_oid_hex(void); +const char *empty_blob_oid_hex(void); + +#endif diff --git a/hash-lookup.c b/hash-lookup.c index b98ed5e11e..bb54dfde9c 100644 --- a/hash-lookup.c +++ b/hash-lookup.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "hash.h" #include "hash-lookup.h" static uint32_t take2(const struct object_id *oid, size_t ofs) @@ -1,250 +1,11 @@ #ifndef HASH_H #define HASH_H +#include "hash-ll.h" #include "repository.h" -#if defined(SHA1_APPLE) -#include <CommonCrypto/CommonDigest.h> -#elif defined(SHA1_OPENSSL) -#include <openssl/sha.h> -#elif defined(SHA1_DC) -#include "sha1dc_git.h" -#else /* SHA1_BLK */ -#include "block-sha1/sha1.h" -#endif - -#if defined(SHA256_NETTLE) -#include "sha256/nettle.h" -#elif defined(SHA256_GCRYPT) -#define SHA256_NEEDS_CLONE_HELPER -#include "sha256/gcrypt.h" -#elif defined(SHA256_OPENSSL) -#include <openssl/sha.h> -#else -#include "sha256/block/sha256.h" -#endif - -#ifndef platform_SHA_CTX -/* - * platform's underlying implementation of SHA-1; could be OpenSSL, - * blk_SHA, Apple CommonCrypto, etc... Note that the relevant - * SHA-1 header may have already defined platform_SHA_CTX for our - * own implementations like block-sha1, so we list - * the default for OpenSSL compatible SHA-1 implementations here. - */ -#define platform_SHA_CTX SHA_CTX -#define platform_SHA1_Init SHA1_Init -#define platform_SHA1_Update SHA1_Update -#define platform_SHA1_Final SHA1_Final -#endif - -#define git_SHA_CTX platform_SHA_CTX -#define git_SHA1_Init platform_SHA1_Init -#define git_SHA1_Update platform_SHA1_Update -#define git_SHA1_Final platform_SHA1_Final - -#ifndef platform_SHA256_CTX -#define platform_SHA256_CTX SHA256_CTX -#define platform_SHA256_Init SHA256_Init -#define platform_SHA256_Update SHA256_Update -#define platform_SHA256_Final SHA256_Final -#endif - -#define git_SHA256_CTX platform_SHA256_CTX -#define git_SHA256_Init platform_SHA256_Init -#define git_SHA256_Update platform_SHA256_Update -#define git_SHA256_Final platform_SHA256_Final - -#ifdef platform_SHA256_Clone -#define git_SHA256_Clone platform_SHA256_Clone -#endif - -#ifdef SHA1_MAX_BLOCK_SIZE -#include "compat/sha1-chunked.h" -#undef git_SHA1_Update -#define git_SHA1_Update git_SHA1_Update_Chunked -#endif - -static inline void git_SHA1_Clone(git_SHA_CTX *dst, const git_SHA_CTX *src) -{ - memcpy(dst, src, sizeof(*dst)); -} - -#ifndef SHA256_NEEDS_CLONE_HELPER -static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *src) -{ - memcpy(dst, src, sizeof(*dst)); -} -#endif - -/* - * Note that these constants are suitable for indexing the hash_algos array and - * comparing against each other, but are otherwise arbitrary, so they should not - * be exposed to the user or serialized to disk. To know whether a - * git_hash_algo struct points to some usable hash function, test the format_id - * field for being non-zero. Use the name field for user-visible situations and - * the format_id field for fixed-length fields on disk. - */ -/* An unknown hash function. */ -#define GIT_HASH_UNKNOWN 0 -/* SHA-1 */ -#define GIT_HASH_SHA1 1 -/* SHA-256 */ -#define GIT_HASH_SHA256 2 -/* Number of algorithms supported (including unknown). */ -#define GIT_HASH_NALGOS (GIT_HASH_SHA256 + 1) - -/* "sha1", big-endian */ -#define GIT_SHA1_FORMAT_ID 0x73686131 - -/* The length in bytes and in hex digits of an object name (SHA-1 value). */ -#define GIT_SHA1_RAWSZ 20 -#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ) -/* The block size of SHA-1. */ -#define GIT_SHA1_BLKSZ 64 - -/* "s256", big-endian */ -#define GIT_SHA256_FORMAT_ID 0x73323536 - -/* The length in bytes and in hex digits of an object name (SHA-256 value). */ -#define GIT_SHA256_RAWSZ 32 -#define GIT_SHA256_HEXSZ (2 * GIT_SHA256_RAWSZ) -/* The block size of SHA-256. */ -#define GIT_SHA256_BLKSZ 64 - -/* The length in byte and in hex digits of the largest possible hash value. */ -#define GIT_MAX_RAWSZ GIT_SHA256_RAWSZ -#define GIT_MAX_HEXSZ GIT_SHA256_HEXSZ -/* The largest possible block size for any supported hash. */ -#define GIT_MAX_BLKSZ GIT_SHA256_BLKSZ - -struct object_id { - unsigned char hash[GIT_MAX_RAWSZ]; - 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; - git_SHA256_CTX sha256; -}; -typedef union git_hash_ctx git_hash_ctx; - -typedef void (*git_hash_init_fn)(git_hash_ctx *ctx); -typedef void (*git_hash_clone_fn)(git_hash_ctx *dst, const git_hash_ctx *src); -typedef void (*git_hash_update_fn)(git_hash_ctx *ctx, const void *in, size_t len); -typedef void (*git_hash_final_fn)(unsigned char *hash, git_hash_ctx *ctx); -typedef void (*git_hash_final_oid_fn)(struct object_id *oid, git_hash_ctx *ctx); - -struct git_hash_algo { - /* - * The name of the algorithm, as appears in the config file and in - * messages. - */ - const char *name; - - /* A four-byte version identifier, used in pack indices. */ - uint32_t format_id; - - /* The length of the hash in binary. */ - size_t rawsz; - - /* The length of the hash in hex characters. */ - size_t hexsz; - - /* The block size of the hash. */ - size_t blksz; - - /* The hash initialization function. */ - git_hash_init_fn init_fn; - - /* The hash context cloning function. */ - git_hash_clone_fn clone_fn; - - /* The hash update function. */ - git_hash_update_fn update_fn; - - /* The hash finalization function. */ - git_hash_final_fn final_fn; - - /* The hash finalization function for object IDs. */ - git_hash_final_oid_fn final_oid_fn; - - /* The OID of the empty tree. */ - const struct object_id *empty_tree; - - /* The OID of the empty blob. */ - const struct object_id *empty_blob; - - /* The all-zeros OID. */ - const struct object_id *null_oid; -}; -extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS]; - -/* - * Return a GIT_HASH_* constant based on the name. Returns GIT_HASH_UNKNOWN if - * the name doesn't match a known algorithm. - */ -int hash_algo_by_name(const char *name); -/* Identical, except based on the format ID. */ -int hash_algo_by_id(uint32_t format_id); -/* Identical, except based on the length. */ -int hash_algo_by_length(int len); -/* Identical, except for a pointer to struct git_hash_algo. */ -static inline int hash_algo_by_ptr(const struct git_hash_algo *p) -{ - return p - hash_algos; -} - #define the_hash_algo the_repository->hash_algo -const struct object_id *null_oid(void); - -static inline int hashcmp_algop(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop) -{ - /* - * Teach the compiler that there are only two possibilities of hash size - * here, so that it can optimize for this case as much as possible. - */ - if (algop->rawsz == GIT_MAX_RAWSZ) - return memcmp(sha1, sha2, GIT_MAX_RAWSZ); - return memcmp(sha1, sha2, GIT_SHA1_RAWSZ); -} - static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2) { return hashcmp_algop(sha1, sha2, the_hash_algo); @@ -260,17 +21,6 @@ static inline int oidcmp(const struct object_id *oid1, const struct object_id *o return hashcmp_algop(oid1->hash, oid2->hash, algop); } -static inline int hasheq_algop(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop) -{ - /* - * We write this here instead of deferring to hashcmp so that the - * compiler can properly inline it and avoid calling memcmp. - */ - if (algop->rawsz == GIT_MAX_RAWSZ) - return !memcmp(sha1, sha2, GIT_MAX_RAWSZ); - return !memcmp(sha1, sha2, GIT_SHA1_RAWSZ); -} - static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2) { return hasheq_algop(sha1, sha2, the_hash_algo); @@ -296,12 +46,6 @@ static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src) memcpy(sha_dst, sha_src, the_hash_algo->rawsz); } -static inline void oidcpy(struct object_id *dst, const struct object_id *src) -{ - memcpy(dst->hash, src->hash, GIT_MAX_RAWSZ); - dst->algo = src->algo; -} - /* Like oidcpy() but zero-pads the unused bytes in dst's hash array. */ static inline void oidcpy_with_padding(struct object_id *dst, const struct object_id *src) @@ -318,13 +62,6 @@ static inline void oidcpy_with_padding(struct object_id *dst, dst->algo = src->algo; } -static inline struct object_id *oiddup(const struct object_id *src) -{ - struct object_id *dst = xmalloc(sizeof(struct object_id)); - oidcpy(dst, src); - return dst; -} - static inline void hashclr(unsigned char *hash) { memset(hash, 0, the_hash_algo->rawsz); @@ -362,12 +99,4 @@ static inline int is_empty_tree_oid(const struct object_id *oid) return oideq(oid, the_hash_algo->empty_tree); } -static inline void oid_set_algo(struct object_id *oid, const struct git_hash_algo *algop) -{ - oid->algo = hash_algo_by_ptr(algop); -} - -const char *empty_tree_oid_hex(void); -const char *empty_blob_oid_hex(void); - #endif @@ -1,7 +1,7 @@ #ifndef HASHMAP_H #define HASHMAP_H -#include "hash.h" +#include "hash-ll.h" /* * Generic implementation of hash-based key-value mappings. @@ -1,4 +1,5 @@ #include "git-compat-util.h" +#include "hash.h" #include "hex.h" const signed char hexval_table[256] = { @@ -1,7 +1,7 @@ #ifndef HEX_H #define HEX_H -#include "hash.h" +#include "hash-ll.h" extern const signed char hexval_table[256]; static inline unsigned int hexval(unsigned char c) @@ -2,6 +2,7 @@ #include "advice.h" #include "gettext.h" #include "hook.h" +#include "path.h" #include "run-command.h" #include "config.h" #include "strbuf.h" diff --git a/http-push.c b/http-push.c index 76ab5dbb09..29cf9db34e 100644 --- a/http-push.c +++ b/http-push.c @@ -15,6 +15,8 @@ #include "setup.h" #include "sigchain.h" #include "strvec.h" +#include "tree.h" +#include "tree-walk.h" #include "packfile.h" #include "object-store.h" #include "commit-reach.h" @@ -27,6 +27,7 @@ #define __AC_KHASH_H #include "hashmap.h" +#include "hash.h" #define AC_VERSION_KHASH_H "0.2.8" diff --git a/line-log.c b/line-log.c index 10c19daec4..6a7ac312a4 100644 --- a/line-log.c +++ b/line-log.c @@ -18,6 +18,7 @@ #include "setup.h" #include "strvec.h" #include "bloom.h" +#include "tree-walk.h" static void range_set_grow(struct range_set *rs, size_t extra) { diff --git a/ll-merge.c b/ll-merge.c index 28bc94c45d..1993530688 100644 --- a/ll-merge.c +++ b/ll-merge.c @@ -4,7 +4,7 @@ * Copyright (c) 2007 Junio C Hamano */ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "convert.h" #include "attr.h" @@ -12,6 +12,7 @@ #include "run-command.h" #include "ll-merge.h" #include "quote.h" +#include "strbuf.h" #include "wrapper.h" struct ll_merge_driver; diff --git a/log-tree.c b/log-tree.c index 143b86fecf..f4b22a60cc 100644 --- a/log-tree.c +++ b/log-tree.c @@ -24,6 +24,7 @@ #include "help.h" #include "range-diff.h" #include "strmap.h" +#include "tree.h" #include "write-or-die.h" static struct decoration name_decoration = { "object names" }; @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "environment.h" #include "gettext.h" +#include "hash.h" #include "hex.h" #include "repository.h" #include "refs.h" diff --git a/match-trees.c b/match-trees.c index 5877fc64a8..6bc8eb7647 100644 --- a/match-trees.c +++ b/match-trees.c @@ -1,5 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" #include "hex.h" +#include "match-trees.h" #include "tree.h" #include "tree-walk.h" #include "object-store.h" diff --git a/match-trees.h b/match-trees.h new file mode 100644 index 0000000000..e3877acd58 --- /dev/null +++ b/match-trees.h @@ -0,0 +1,10 @@ +#ifndef MATCH_TREES_H +#define MATCH_TREES_H + +struct object_id; +struct repository; + +void shift_tree(struct repository *, const struct object_id *, const struct object_id *, struct object_id *, int); +void shift_tree_by(struct repository *, const struct object_id *, const struct object_id *, struct object_id *, const char *); + +#endif /* MATCH_TREES_H */ diff --git a/merge-ort-wrappers.c b/merge-ort-wrappers.c index c00dfbab1c..a550753300 100644 --- a/merge-ort-wrappers.c +++ b/merge-ort-wrappers.c @@ -1,7 +1,9 @@ #include "cache.h" #include "gettext.h" +#include "hash.h" #include "merge-ort.h" #include "merge-ort-wrappers.h" +#include "tree.h" #include "commit.h" diff --git a/merge-ort.c b/merge-ort.c index 2c6a9ed9a4..a50b095c47 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -31,6 +31,7 @@ #include "hex.h" #include "entry.h" #include "ll-merge.h" +#include "match-trees.h" #include "mem-pool.h" #include "object-name.h" #include "object-store.h" @@ -4722,14 +4723,14 @@ void merge_switch_to_result(struct merge_options *opt, void merge_finalize(struct merge_options *opt, struct merge_result *result) { - struct merge_options_internal *opti = result->priv; - if (opt->renormalize) git_attr_set_direction(GIT_ATTR_CHECKIN); assert(opt->priv == NULL); - clear_or_reinit_internal_opts(opti, 0); - FREE_AND_NULL(opti); + if (result->priv) { + clear_or_reinit_internal_opts(result->priv, 0); + FREE_AND_NULL(result->priv); + } } /*** Function Grouping: helper functions for merge_incore_*() ***/ diff --git a/merge-ort.h b/merge-ort.h index a994c9a5fc..ce56ec1a78 100644 --- a/merge-ort.h +++ b/merge-ort.h @@ -2,7 +2,7 @@ #define MERGE_ORT_H #include "merge-recursive.h" -#include "hash.h" +#include "hash-ll.h" struct commit; struct tree; diff --git a/merge-recursive.c b/merge-recursive.c index 9875bdb11c..8e87b6386d 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -22,6 +22,7 @@ #include "hex.h" #include "ll-merge.h" #include "lockfile.h" +#include "match-trees.h" #include "object-file.h" #include "object-name.h" #include "object-store.h" @@ -30,6 +31,7 @@ #include "string-list.h" #include "submodule-config.h" #include "submodule.h" +#include "symlinks.h" #include "tag.h" #include "tree-walk.h" #include "unpack-trees.h" @@ -7,6 +7,7 @@ #include "commit.h" #include "run-command.h" #include "resolve-undo.h" +#include "tree.h" #include "tree-walk.h" #include "unpack-trees.h" #include "dir.h" @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "abspath.h" #include "alloc.h" #include "config.h" diff --git a/negotiator/default.c b/negotiator/default.c index f4b78eb47d..5cb2b1d204 100644 --- a/negotiator/default.c +++ b/negotiator/default.c @@ -4,6 +4,7 @@ #include "../fetch-negotiator.h" #include "../prio-queue.h" #include "../refs.h" +#include "../repository.h" #include "../tag.h" /* Remember to update object flag allocation in object.h */ diff --git a/negotiator/skipping.c b/negotiator/skipping.c index c7d6ab39bc..97e7e1ae72 100644 --- a/negotiator/skipping.c +++ b/negotiator/skipping.c @@ -5,6 +5,7 @@ #include "../hex.h" #include "../prio-queue.h" #include "../refs.h" +#include "../repository.h" #include "../tag.h" /* Remember to update object flag allocation in object.h */ diff --git a/notes-cache.c b/notes-cache.c index fbcdfd0dfe..14288caf98 100644 --- a/notes-cache.c +++ b/notes-cache.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "notes-cache.h" #include "object-store.h" +#include "pretty.h" #include "repository.h" #include "commit.h" #include "refs.h" diff --git a/notes-utils.c b/notes-utils.c index cb88171b7b..4a793eb347 100644 --- a/notes-utils.c +++ b/notes-utils.c @@ -6,6 +6,7 @@ #include "refs.h" #include "notes-utils.h" #include "repository.h" +#include "strbuf.h" void create_notes_commit(struct repository *r, struct notes_tree *t, @@ -964,7 +964,7 @@ void string_list_add_refs_from_colon_sep(struct string_list *list, char *globs_copy = xstrdup(globs); int i; - string_list_split_in_place(&split, globs_copy, ':', -1); + string_list_split_in_place(&split, globs_copy, ":", -1); string_list_remove_empty_items(&split, 0); for (i = 0; i < split.nr; i++) @@ -1020,13 +1020,13 @@ void init_notes(struct notes_tree *t, const char *notes_ref, t->root = (struct int_node *) xcalloc(1, sizeof(struct int_node)); t->first_non_note = NULL; t->prev_non_note = NULL; - t->ref = xstrdup_or_null(notes_ref); + t->ref = xstrdup(notes_ref); t->update_ref = (flags & NOTES_INIT_WRITABLE) ? t->ref : NULL; t->combine_notes = combine_notes; t->initialized = 1; t->dirty = 0; - if (flags & NOTES_INIT_EMPTY || !notes_ref || + if (flags & NOTES_INIT_EMPTY || repo_get_oid_treeish(the_repository, notes_ref, &object_oid)) return; if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid)) diff --git a/object-file.c b/object-file.c index af18e38527..7c1af5c8db 100644 --- a/object-file.c +++ b/object-file.c @@ -6,7 +6,7 @@ * This handles basic git object files - packing, unpacking, * creation etc. */ -#include "cache.h" +#include "git-compat-util.h" #include "abspath.h" #include "alloc.h" #include "config.h" @@ -38,6 +38,7 @@ #include "packfile.h" #include "object-file.h" #include "object-store.h" +#include "oidtree.h" #include "promisor-remote.h" #include "setup.h" #include "submodule.h" diff --git a/object-file.h b/object-file.h index e0cfc3a5db..d6414610f8 100644 --- a/object-file.h +++ b/object-file.h @@ -4,6 +4,8 @@ #include "git-zlib.h" #include "object.h" +struct index_state; + /* * Set this to 0 to prevent oid_object_info_extended() from fetching missing * blobs. This has a difference only if extensions.partialClone is set. diff --git a/object-name.c b/object-name.c index 538e8a8f62..6fc3fa595b 100644 --- a/object-name.c +++ b/object-name.c @@ -14,7 +14,9 @@ #include "remote.h" #include "dir.h" #include "oid-array.h" +#include "oidtree.h" #include "packfile.h" +#include "pretty.h" #include "object-store.h" #include "repository.h" #include "setup.h" diff --git a/object-store.h b/object-store.h index 4ac91e375d..12415e5ea7 100644 --- a/object-store.h +++ b/object-store.h @@ -2,16 +2,16 @@ #define OBJECT_STORE_H #include "object.h" -#include "oidmap.h" #include "list.h" -#include "oid-array.h" -#include "strbuf.h" #include "thread-utils.h" #include "khash.h" #include "dir.h" -#include "oidtree.h" #include "oidset.h" +struct oidmap; +struct oidtree; +struct strbuf; + struct object_directory { struct object_directory *next; @@ -1,9 +1,10 @@ #ifndef OBJECT_H #define OBJECT_H -#include "hash.h" +#include "hash-ll.h" struct buffer_slab; +struct repository; struct parsed_object_pool { struct object **obj_hash; @@ -1,4 +1,5 @@ #include "git-compat-util.h" +#include "hash.h" #include "oidmap.h" static int oidmap_neq(const void *hashmap_cmp_fn_data UNUSED, @@ -2,7 +2,7 @@ #define OIDTREE_H #include "cbtree.h" -#include "hash.h" +#include "hash-ll.h" #include "mem-pool.h" struct oidtree { diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index faf67c94d3..cdffe2ce47 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -18,6 +18,8 @@ #include "commit-reach.h" #include "prio-queue.h" #include "trace2.h" +#include "tree.h" +#include "tree-walk.h" struct bitmapped_commit { struct commit *commit; diff --git a/packfile.c b/packfile.c index 57df0c1956..fd083c86e0 100644 --- a/packfile.c +++ b/packfile.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "alloc.h" #include "environment.h" #include "gettext.h" diff --git a/packfile.h b/packfile.h index 665603b696..c3692308b8 100644 --- a/packfile.h +++ b/packfile.h @@ -6,10 +6,22 @@ /* in object-store.h */ struct packed_git; -struct pack_entry; -struct pack_window; struct object_info; +struct pack_window { + struct pack_window *next; + unsigned char *base; + off_t offset; + size_t len; + unsigned int last_used; + unsigned int inuse_cnt; +}; + +struct pack_entry { + off_t offset; + struct packed_git *p; +}; + /* * Generate the filename to be used for a pack file with checksum "sha1" and * extension "ext". The result is written into the strbuf "buf", overwriting diff --git a/parallel-checkout.c b/parallel-checkout.c index 50fd7fe31e..69d569f352 100644 --- a/parallel-checkout.c +++ b/parallel-checkout.c @@ -3,6 +3,7 @@ #include "config.h" #include "entry.h" #include "gettext.h" +#include "hash.h" #include "hex.h" #include "parallel-checkout.h" #include "pkt-line.h" @@ -10,6 +11,7 @@ #include "run-command.h" #include "sigchain.h" #include "streaming.h" +#include "symlinks.h" #include "thread-utils.h" #include "trace2.h" #include "wrapper.h" diff --git a/parse-options-cb.c b/parse-options-cb.c index 298decf48f..a24521dee0 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -3,6 +3,7 @@ #include "branch.h" #include "commit.h" #include "color.h" +#include "date.h" #include "environment.h" #include "gettext.h" #include "object-name.h" diff --git a/parse-options.c b/parse-options.c index b6803647d0..f8a155ee13 100644 --- a/parse-options.c +++ b/parse-options.c @@ -5,6 +5,7 @@ #include "commit.h" #include "color.h" #include "gettext.h" +#include "strbuf.h" #include "utf8.h" static int disallow_abbreviated_options; diff --git a/pathspec.c b/pathspec.c index 6972d515f0..1e57b6c667 100644 --- a/pathspec.c +++ b/pathspec.c @@ -6,8 +6,10 @@ #include "gettext.h" #include "pathspec.h" #include "attr.h" +#include "repository.h" #include "setup.h" #include "strvec.h" +#include "symlinks.h" #include "quote.h" /* diff --git a/pkt-line.c b/pkt-line.c index 3561d85358..62b4208b66 100644 --- a/pkt-line.c +++ b/pkt-line.c @@ -1,4 +1,5 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "copy.h" #include "pkt-line.h" #include "gettext.h" #include "hex.h" diff --git a/pkt-line.h b/pkt-line.h index 8e9846f315..7c23a4bfaf 100644 --- a/pkt-line.h +++ b/pkt-line.h @@ -246,4 +246,6 @@ void packet_writer_error(struct packet_writer *writer, const char *fmt, ...); void packet_writer_delim(struct packet_writer *writer); void packet_writer_flush(struct packet_writer *writer); +void packet_trace_identity(const char *prog); + #endif diff --git a/preload-index.c b/preload-index.c index 4abf9c983b..7a26b08c21 100644 --- a/preload-index.c +++ b/preload-index.c @@ -11,6 +11,7 @@ #include "progress.h" #include "thread-utils.h" #include "repository.h" +#include "symlinks.h" #include "trace2.h" /* diff --git a/progress.c b/progress.c index 72d5e0c73c..f695798aca 100644 --- a/progress.c +++ b/progress.c @@ -12,6 +12,7 @@ #include "git-compat-util.h" #include "pager.h" #include "progress.h" +#include "repository.h" #include "strbuf.h" #include "trace.h" #include "trace2.h" diff --git a/protocol-caps.c b/protocol-caps.c index 94c51862c5..a90c48852e 100644 --- a/protocol-caps.c +++ b/protocol-caps.c @@ -4,7 +4,7 @@ #include "hex.h" #include "pkt-line.h" #include "strvec.h" -#include "hash.h" +#include "hash-ll.h" #include "hex.h" #include "object.h" #include "object-store.h" diff --git a/range-diff.c b/range-diff.c index a1e0cffb9f..6a704e6f47 100644 --- a/range-diff.c +++ b/range-diff.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "environment.h" #include "gettext.h" #include "range-diff.h" diff --git a/read-cache.c b/read-cache.c index e919af3c77..f4c31a68c8 100644 --- a/read-cache.c +++ b/read-cache.c @@ -6,6 +6,7 @@ #include "cache.h" #include "alloc.h" #include "config.h" +#include "date.h" #include "diff.h" #include "diffcore.h" #include "hex.h" @@ -30,6 +31,7 @@ #include "trace2.h" #include "varint.h" #include "split-index.h" +#include "symlinks.h" #include "utf8.h" #include "fsmonitor.h" #include "thread-utils.h" @@ -498,87 +500,30 @@ int ie_modified(struct index_state *istate, return 0; } -int base_name_compare(const char *name1, size_t len1, int mode1, - const char *name2, size_t len2, int mode2) +static int cache_name_stage_compare(const char *name1, int len1, int stage1, + const char *name2, int len2, int stage2) { - unsigned char c1, c2; - size_t len = len1 < len2 ? len1 : len2; int cmp; - cmp = memcmp(name1, name2, len); - if (cmp) - return cmp; - c1 = name1[len]; - c2 = name2[len]; - if (!c1 && S_ISDIR(mode1)) - c1 = '/'; - if (!c2 && S_ISDIR(mode2)) - c2 = '/'; - return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0; -} - -/* - * df_name_compare() is identical to base_name_compare(), except it - * compares conflicting directory/file entries as equal. Note that - * while a directory name compares as equal to a regular file, they - * then individually compare _differently_ to a filename that has - * a dot after the basename (because '\0' < '.' < '/'). - * - * This is used by routines that want to traverse the git namespace - * but then handle conflicting entries together when possible. - */ -int df_name_compare(const char *name1, size_t len1, int mode1, - const char *name2, size_t len2, int mode2) -{ - unsigned char c1, c2; - size_t len = len1 < len2 ? len1 : len2; - int cmp; - - cmp = memcmp(name1, name2, len); + cmp = name_compare(name1, len1, name2, len2); if (cmp) return cmp; - /* Directories and files compare equal (same length, same name) */ - if (len1 == len2) - return 0; - c1 = name1[len]; - if (!c1 && S_ISDIR(mode1)) - c1 = '/'; - c2 = name2[len]; - if (!c2 && S_ISDIR(mode2)) - c2 = '/'; - if (c1 == '/' && !c2) - return 0; - if (c2 == '/' && !c1) - return 0; - return c1 - c2; -} -int name_compare(const char *name1, size_t len1, const char *name2, size_t len2) -{ - size_t min_len = (len1 < len2) ? len1 : len2; - int cmp = memcmp(name1, name2, min_len); - if (cmp) - return cmp; - if (len1 < len2) + if (stage1 < stage2) return -1; - if (len1 > len2) + if (stage1 > stage2) return 1; return 0; } -int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2) +int cmp_cache_name_compare(const void *a_, const void *b_) { - int cmp; + const struct cache_entry *ce1, *ce2; - cmp = name_compare(name1, len1, name2, len2); - if (cmp) - return cmp; - - if (stage1 < stage2) - return -1; - if (stage1 > stage2) - return 1; - return 0; + ce1 = *((const struct cache_entry **)a_); + ce2 = *((const struct cache_entry **)b_); + return cache_name_stage_compare(ce1->name, ce1->ce_namelen, ce_stage(ce1), + ce2->name, ce2->ce_namelen, ce_stage(ce2)); } static int index_name_stage_pos(struct index_state *istate, diff --git a/rebase-interactive.c b/rebase-interactive.c index 789f407361..852a331318 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -5,6 +5,7 @@ #include "gettext.h" #include "sequencer.h" #include "rebase-interactive.h" +#include "repository.h" #include "strbuf.h" #include "commit-slab.h" #include "config.h" diff --git a/ref-filter.c b/ref-filter.c index 10aab14f03..4991cd4f7a 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1,7 +1,8 @@ -#include "cache.h" +#include "git-compat-util.h" #include "alloc.h" #include "environment.h" #include "gettext.h" +#include "gpg-interface.h" #include "hex.h" #include "parse-options.h" #include "refs.h" @@ -19,6 +20,7 @@ #include "revision.h" #include "utf8.h" #include "version.h" +#include "versioncmp.h" #include "trailer.h" #include "wt-status.h" #include "commit-slab.h" @@ -4,6 +4,8 @@ #include "reflog.h" #include "refs.h" #include "revision.h" +#include "tree.h" +#include "tree-walk.h" #include "worktree.h" /* Remember to update object flag allocation in object.h */ diff --git a/refs/debug.c b/refs/debug.c index adc34c836f..6f11e6de46 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "hex.h" #include "refs-internal.h" +#include "string-list.h" #include "trace.h" static struct trace_key trace_refs = TRACE_KEY_INIT(REFS); diff --git a/refs/files-backend.c b/refs/files-backend.c index d0581ee41a..bca7b851c5 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1,7 +1,9 @@ #include "../cache.h" #include "../config.h" +#include "../copy.h" #include "../environment.h" #include "../gettext.h" +#include "../hash.h" #include "../hex.h" #include "../refs.h" #include "refs-internal.h" diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 2333ed5a1f..5b412a133b 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -2,6 +2,7 @@ #include "../alloc.h" #include "../config.h" #include "../gettext.h" +#include "../hash.h" #include "../hex.h" #include "../refs.h" #include "refs-internal.h" @@ -651,7 +652,7 @@ static struct snapshot *create_snapshot(struct packed_ref_store *refs) snapshot->buf, snapshot->eof - snapshot->buf); - string_list_split_in_place(&traits, p, ' ', -1); + string_list_split_in_place(&traits, p, " ", -1); if (unsorted_string_list_has_string(&traits, "fully-peeled")) snapshot->peeled = PEELED_FULLY; diff --git a/refs/ref-cache.c b/refs/ref-cache.c index dc1ca49c85..2294c4564f 100644 --- a/refs/ref-cache.c +++ b/refs/ref-cache.c @@ -1,6 +1,8 @@ #include "../git-compat-util.h" #include "../alloc.h" +#include "../hash.h" #include "../refs.h" +#include "../repository.h" #include "refs-internal.h" #include "ref-cache.h" #include "../iterator.h" diff --git a/refs/ref-cache.h b/refs/ref-cache.h index cf4ad9070b..95c76e27c8 100644 --- a/refs/ref-cache.h +++ b/refs/ref-cache.h @@ -1,10 +1,11 @@ #ifndef REFS_REF_CACHE_H #define REFS_REF_CACHE_H -#include "hash.h" +#include "hash-ll.h" struct ref_dir; struct ref_store; +struct repository; /* * If this ref_cache is filled lazily, this function is used to load @@ -1,10 +1,12 @@ #include "git-compat-util.h" #include "alloc.h" #include "gettext.h" +#include "hash.h" #include "hex.h" #include "strvec.h" #include "refs.h" #include "refspec.h" +#include "strbuf.h" static struct refspec_item s_tag_refspec = { .force = 0, diff --git a/reftable/dump.c b/reftable/dump.c index 155953d1b8..ce936b4e18 100644 --- a/reftable/dump.c +++ b/reftable/dump.c @@ -7,7 +7,7 @@ https://developers.google.com/open-source/licenses/bsd */ #include "git-compat-util.h" -#include "hash.h" +#include "hash-ll.h" #include "reftable-blocksource.h" #include "reftable-error.h" diff --git a/reftable/error.c b/reftable/error.c index 93941f2145..0d1766735e 100644 --- a/reftable/error.c +++ b/reftable/error.c @@ -6,6 +6,7 @@ license that can be found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd */ +#include "system.h" #include "reftable-error.h" #include <stdio.h> diff --git a/reftable/publicbasics.c b/reftable/publicbasics.c index 0ad7d5c0ff..bcb82530d6 100644 --- a/reftable/publicbasics.c +++ b/reftable/publicbasics.c @@ -6,10 +6,10 @@ license that can be found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd */ +#include "system.h" #include "reftable-malloc.h" #include "basics.h" -#include "system.h" static void *(*reftable_malloc_ptr)(size_t sz); static void *(*reftable_realloc_ptr)(void *, size_t); diff --git a/reftable/system.h b/reftable/system.h index 18f9207dfe..6b74a81514 100644 --- a/reftable/system.h +++ b/reftable/system.h @@ -13,7 +13,7 @@ https://developers.google.com/open-source/licenses/bsd #include "git-compat-util.h" #include "strbuf.h" -#include "hash.h" /* hash ID, sizes.*/ +#include "hash-ll.h" /* hash ID, sizes.*/ #include "dir.h" /* remove_dir_recursively, for tests.*/ int hash_size(uint32_t id); diff --git a/reftable/tree.c b/reftable/tree.c index b8899e060a..a5bf880985 100644 --- a/reftable/tree.c +++ b/reftable/tree.c @@ -6,10 +6,10 @@ license that can be found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd */ +#include "system.h" #include "tree.h" #include "basics.h" -#include "system.h" struct tree_node *tree_search(void *key, struct tree_node **rootp, int (*compare)(const void *, const void *), diff --git a/reftable/tree_test.c b/reftable/tree_test.c index cbff125588..ac3a045ad4 100644 --- a/reftable/tree_test.c +++ b/reftable/tree_test.c @@ -6,6 +6,7 @@ license that can be found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd */ +#include "system.h" #include "tree.h" #include "basics.h" @@ -2,6 +2,7 @@ #include "abspath.h" #include "alloc.h" #include "config.h" +#include "copy.h" #include "gettext.h" #include "hex.h" #include "lockfile.h" @@ -1,7 +1,7 @@ #ifndef RESET_H #define RESET_H -#include "hash.h" +#include "hash-ll.h" #include "repository.h" #define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION" diff --git a/resolve-undo.c b/resolve-undo.c index e81096e2d4..70a6db526d 100644 --- a/resolve-undo.c +++ b/resolve-undo.c @@ -1,5 +1,6 @@ #include "cache.h" #include "dir.h" +#include "hash.h" #include "resolve-undo.h" #include "string-list.h" diff --git a/resolve-undo.h b/resolve-undo.h index d1ea972771..c5deafc92f 100644 --- a/resolve-undo.h +++ b/resolve-undo.h @@ -6,7 +6,7 @@ struct index_state; struct pathspec; struct string_list; -#include "hash.h" +#include "hash-ll.h" struct resolve_undo_info { unsigned int mode[3]; diff --git a/revision.h b/revision.h index e8f6de9684..31828748dc 100644 --- a/revision.h +++ b/revision.h @@ -7,6 +7,7 @@ #include "pretty.h" #include "diff.h" #include "commit-slab-decl.h" +#include "decorate.h" #include "ident.h" #include "list-objects-filter-options.h" diff --git a/run-command.c b/run-command.c index e64bb08a5b..d4247d5fcc 100644 --- a/run-command.c +++ b/run-command.c @@ -5,6 +5,7 @@ #include "gettext.h" #include "sigchain.h" #include "strvec.h" +#include "symlinks.h" #include "thread-utils.h" #include "strbuf.h" #include "string-list.h" diff --git a/send-pack.c b/send-pack.c index 2089143555..0c7ccaef68 100644 --- a/send-pack.c +++ b/send-pack.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "config.h" #include "commit.h" +#include "date.h" #include "gettext.h" #include "hex.h" #include "refs.h" diff --git a/sequencer.c b/sequencer.c index c88d1d9553..b553b49fbb 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3,6 +3,7 @@ #include "advice.h" #include "alloc.h" #include "config.h" +#include "copy.h" #include "environment.h" #include "gettext.h" #include "hex.h" @@ -3625,14 +3626,14 @@ static int do_exec(struct repository *r, const char *command_line) " git rebase --continue\n" "\n"), command_line, - dirty ? N_("and made changes to the index and/or the " - "working tree\n") : ""); + dirty ? _("and made changes to the index and/or the " + "working tree.\n") : ""); if (status == 127) /* command not found */ status = 1; } else if (dirty) { warning(_("execution succeeded: %s\nbut " - "left changes to the index and/or the working tree\n" + "left changes to the index and/or the working tree.\n" "Commit or stash your changes, and then run\n" "\n" " git rebase --continue\n" diff --git a/server-info.c b/server-info.c index 68098ddd1a..55aa04f00a 100644 --- a/server-info.c +++ b/server-info.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "alloc.h" #include "dir.h" #include "environment.h" @@ -11,6 +11,7 @@ #include "packfile.h" #include "object-file.h" #include "object-store.h" +#include "server-info.h" #include "strbuf.h" #include "wrapper.h" diff --git a/server-info.h b/server-info.h new file mode 100644 index 0000000000..13bbde2c55 --- /dev/null +++ b/server-info.h @@ -0,0 +1,7 @@ +#ifndef SERVER_INFO_H +#define SERVER_INFO_H + +/* Dumb servers support */ +int update_server_info(int); + +#endif /* SERVER_INFO_H */ diff --git a/split-index.c b/split-index.c index 5602b74994..40e54760b3 100644 --- a/split-index.c +++ b/split-index.c @@ -1,8 +1,10 @@ #include "cache.h" #include "alloc.h" #include "gettext.h" +#include "hash.h" #include "mem-pool.h" #include "split-index.h" +#include "strbuf.h" #include "ewah/ewok.h" struct split_index *init_split_index(struct index_state *istate) diff --git a/split-index.h b/split-index.h index 1a153f47ba..15a29cd08c 100644 --- a/split-index.h +++ b/split-index.h @@ -1,7 +1,7 @@ #ifndef SPLIT_INDEX_H #define SPLIT_INDEX_H -#include "hash.h" +#include "hash-ll.h" struct index_state; struct strbuf; @@ -6,6 +6,7 @@ #include "hex.h" #include "object-name.h" #include "refs.h" +#include "repository.h" #include "string-list.h" #include "utf8.h" #include "date.h" diff --git a/string-list.c b/string-list.c index db473f273e..0f8ac117fd 100644 --- a/string-list.c +++ b/string-list.c @@ -203,6 +203,15 @@ void string_list_clear_func(struct string_list *list, string_list_clear_func_t c list->nr = list->alloc = 0; } +void string_list_setlen(struct string_list *list, size_t nr) +{ + if (list->strdup_strings) + BUG("cannot setlen a string_list which owns its entries"); + if (nr > list->nr) + BUG("cannot grow a string_list with setlen"); + list->nr = nr; +} + struct string_list_item *string_list_append_nodup(struct string_list *list, char *string) { @@ -301,7 +310,7 @@ int string_list_split(struct string_list *list, const char *string, } int string_list_split_in_place(struct string_list *list, char *string, - int delim, int maxsplit) + const char *delim, int maxsplit) { int count = 0; char *p = string, *end; @@ -315,7 +324,7 @@ int string_list_split_in_place(struct string_list *list, char *string, string_list_append(list, p); return count; } - end = strchr(p, delim); + end = strpbrk(p, delim); if (end) { *end = '\0'; string_list_append(list, p); diff --git a/string-list.h b/string-list.h index c7b0d5d000..122b318641 100644 --- a/string-list.h +++ b/string-list.h @@ -134,6 +134,16 @@ typedef void (*string_list_clear_func_t)(void *p, const char *str); /** Call a custom clear function on each util pointer */ void string_list_clear_func(struct string_list *list, string_list_clear_func_t clearfunc); +/* + * Set the length of a string_list to `nr`, provided that (a) `list` + * does not own its own storage, and (b) that `nr` is no larger than + * `list->nr`. + * + * Useful when "shrinking" `list` to write over existing entries that + * are no longer used without reallocating. + */ +void string_list_setlen(struct string_list *list, size_t nr); + /** * Apply `func` to each item. If `func` returns nonzero, the * iteration aborts and the return value is propagated. @@ -270,5 +280,5 @@ int string_list_split(struct string_list *list, const char *string, * list->strdup_strings must *not* be set. */ int string_list_split_in_place(struct string_list *list, char *string, - int delim, int maxsplit); + const char *delim, int maxsplit); #endif /* STRING_LIST_H */ diff --git a/submodule-config.c b/submodule-config.c index 7fc0812b64..58dfbde9ae 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -12,6 +12,7 @@ #include "object-name.h" #include "object-store.h" #include "parse-options.h" +#include "thread-utils.h" #include "tree-walk.h" /* diff --git a/symlinks.c b/symlinks.c index 27ecc93693..b29e340c2d 100644 --- a/symlinks.c +++ b/symlinks.c @@ -1,6 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" #include "gettext.h" #include "setup.h" +#include "symlinks.h" static int threaded_check_leading_path(struct cache_def *cache, const char *name, int len, int warn_on_lstat_err); diff --git a/symlinks.h b/symlinks.h new file mode 100644 index 0000000000..7ae3d5b856 --- /dev/null +++ b/symlinks.h @@ -0,0 +1,28 @@ +#ifndef SYMLINKS_H +#define SYMLINKS_H + +#include "strbuf.h" + +struct cache_def { + struct strbuf path; + int flags; + int track_flags; + int prefix_len_stat_func; +}; +#define CACHE_DEF_INIT { \ + .path = STRBUF_INIT, \ +} +static inline void cache_def_clear(struct cache_def *cache) +{ + strbuf_release(&cache->path); +} + +int has_symlink_leading_path(const char *name, int len); +int threaded_has_symlink_leading_path(struct cache_def *, const char *, int); +int check_leading_path(const char *name, int len, int warn_on_lstat_err); +int has_dirs_only_path(const char *name, int len, int prefix_len); +void invalidate_lstat_cache(void); +void schedule_dir_for_removal(const char *name, int len); +void remove_scheduled_dirs(void); + +#endif /* SYMLINKS_H */ diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh index b35be20cf3..2ef70235b1 100644 --- a/t/annotate-tests.sh +++ b/t/annotate-tests.sh @@ -72,6 +72,13 @@ test_expect_success 'blame 1 author' ' check_count A 2 ' +test_expect_success 'blame working copy' ' + test_when_finished "git restore file" && + echo "1A quick brown fox jumps over the" >file && + echo "another lazy dog" >>file && + check_count A 1 "Not Committed Yet" 1 +' + test_expect_success 'blame with --contents' ' check_count --contents=file A 2 ' @@ -79,7 +86,7 @@ test_expect_success 'blame with --contents' ' test_expect_success 'blame with --contents changed' ' echo "1A quick brown fox jumps over the" >contents && echo "another lazy dog" >>contents && - check_count --contents=contents A 1 "Not Committed Yet" 1 + check_count --contents=contents A 1 "External file (--contents)" 1 ' test_expect_success 'blame in a bare repo without starting commit' ' @@ -109,7 +116,7 @@ test_expect_success 'blame 2 authors' ' ' test_expect_success 'blame with --contents and revision' ' - check_count -h testTag --contents=file A 2 "Not Committed Yet" 2 + check_count -h testTag --contents=file A 2 "External file (--contents)" 2 ' test_expect_success 'setup B1 lines (branch1)' ' diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c index d2b30d644d..aabe31d724 100644 --- a/t/helper/test-bloom.c +++ b/t/helper/test-bloom.c @@ -2,6 +2,7 @@ #include "bloom.h" #include "hex.h" #include "commit.h" +#include "repository.h" #include "setup.h" static struct bloom_filter_settings settings = DEFAULT_BLOOM_FILTER_SETTINGS; diff --git a/t/helper/test-cache-tree.c b/t/helper/test-cache-tree.c index cdaf5046f5..9507b356e2 100644 --- a/t/helper/test-cache-tree.c +++ b/t/helper/test-cache-tree.c @@ -6,6 +6,7 @@ #include "tree.h" #include "cache-tree.h" #include "parse-options.h" +#include "repository.h" #include "setup.h" static char const * const test_cache_tree_usage[] = { diff --git a/t/helper/test-ctype.c b/t/helper/test-ctype.c index 71a1a5c9b0..e5659df40b 100644 --- a/t/helper/test-ctype.c +++ b/t/helper/test-ctype.c @@ -27,6 +27,8 @@ static int is_in(const char *s, int ch) if (is_in(s, i) != t(i)) \ report_error(#t, i); \ } \ + if (t(EOF)) \ + report_error(#t, EOF); \ } #define DIGIT "0123456789" diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c index 2041ca1857..f22f7bd84a 100644 --- a/t/helper/test-dump-cache-tree.c +++ b/t/helper/test-dump-cache-tree.c @@ -1,9 +1,11 @@ #define USE_THE_INDEX_VARIABLE #include "test-tool.h" #include "cache.h" +#include "hash.h" #include "hex.h" #include "tree.h" #include "cache-tree.h" +#include "repository.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 7c6f50158b..9a098a25cb 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 "repository.h" #include "setup.h" int cmd__dump_fsmonitor(int ac UNUSED, const char **av UNUSED) diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c index 9225ced534..df70be549f 100644 --- a/t/helper/test-dump-untracked-cache.c +++ b/t/helper/test-dump-untracked-cache.c @@ -3,6 +3,7 @@ #include "cache.h" #include "dir.h" #include "hex.h" +#include "repository.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 2cf302ffcb..2ed910adaa 100644 --- a/t/helper/test-example-decorate.c +++ b/t/helper/test-example-decorate.c @@ -2,6 +2,7 @@ #include "git-compat-util.h" #include "object.h" #include "decorate.h" +#include "repository.h" int cmd__example_decorate(int argc UNUSED, const char **argv UNUSED) { diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c index 14522b4c47..9f18c685b7 100644 --- a/t/helper/test-fsmonitor-client.c +++ b/t/helper/test-fsmonitor-client.c @@ -7,6 +7,7 @@ #include "cache.h" #include "parse-options.h" #include "fsmonitor-ipc.h" +#include "repository.h" #include "setup.h" #include "thread-utils.h" #include "trace2.h" diff --git a/t/helper/test-hashmap.c b/t/helper/test-hashmap.c index 36ff07bd4b..0eb0b3d49c 100644 --- a/t/helper/test-hashmap.c +++ b/t/helper/test-hashmap.c @@ -2,6 +2,7 @@ #include "git-compat-util.h" #include "hashmap.h" #include "strbuf.h" +#include "string-list.h" struct test_entry { @@ -150,6 +151,7 @@ static void perf_hashmap(unsigned int method, unsigned int rounds) */ int cmd__hashmap(int argc, const char **argv) { + struct string_list parts = STRING_LIST_INIT_NODUP; struct strbuf line = STRBUF_INIT; int icase; struct hashmap map = HASHMAP_INIT(test_entry_cmp, &icase); @@ -159,21 +161,26 @@ int cmd__hashmap(int argc, const char **argv) /* process commands from stdin */ while (strbuf_getline(&line, stdin) != EOF) { - char *cmd, *p1 = NULL, *p2 = NULL; + char *cmd, *p1, *p2; unsigned int hash = 0; struct test_entry *entry; /* break line into command and up to two parameters */ - cmd = strtok(line.buf, DELIM); + string_list_setlen(&parts, 0); + string_list_split_in_place(&parts, line.buf, DELIM, 2); + string_list_remove_empty_items(&parts, 0); + /* ignore empty lines */ - if (!cmd || *cmd == '#') + if (!parts.nr) + continue; + if (!*parts.items[0].string || *parts.items[0].string == '#') continue; - p1 = strtok(NULL, DELIM); - if (p1) { + cmd = parts.items[0].string; + p1 = parts.nr >= 1 ? parts.items[1].string : NULL; + p2 = parts.nr >= 2 ? parts.items[2].string : NULL; + if (p1) hash = icase ? strihash(p1) : strhash(p1); - p2 = strtok(NULL, DELIM); - } if (!strcmp("add", cmd) && p1 && p2) { @@ -260,6 +267,7 @@ int cmd__hashmap(int argc, const char **argv) } } + string_list_clear(&parts, 0); strbuf_release(&line); hashmap_clear_and_free(&map, struct test_entry, ent); return 0; diff --git a/t/helper/test-json-writer.c b/t/helper/test-json-writer.c index 86887f5320..afe393f597 100644 --- a/t/helper/test-json-writer.c +++ b/t/helper/test-json-writer.c @@ -1,5 +1,6 @@ #include "test-tool.h" #include "json-writer.h" +#include "string-list.h" static const char *expect_obj1 = "{\"a\":\"abc\",\"b\":42,\"c\":true}"; static const char *expect_obj2 = "{\"a\":-1,\"b\":2147483647,\"c\":0}"; @@ -394,35 +395,41 @@ static int unit_tests(void) return 0; } -static void get_s(int line_nr, char **s_in) +struct line { + struct string_list *parts; + size_t consumed_nr; + int nr; +}; + +static void get_s(struct line *line, char **s_in) { - *s_in = strtok(NULL, " "); - if (!*s_in) - die("line[%d]: expected: <s>", line_nr); + if (line->consumed_nr > line->parts->nr) + die("line[%d]: expected: <s>", line->nr); + *s_in = line->parts->items[line->consumed_nr++].string; } -static void get_i(int line_nr, intmax_t *s_in) +static void get_i(struct line *line, intmax_t *s_in) { char *s; char *endptr; - get_s(line_nr, &s); + get_s(line, &s); *s_in = strtol(s, &endptr, 10); if (*endptr || errno == ERANGE) - die("line[%d]: invalid integer value", line_nr); + die("line[%d]: invalid integer value", line->nr); } -static void get_d(int line_nr, double *s_in) +static void get_d(struct line *line, double *s_in) { char *s; char *endptr; - get_s(line_nr, &s); + get_s(line, &s); *s_in = strtod(s, &endptr); if (*endptr || errno == ERANGE) - die("line[%d]: invalid float value", line_nr); + die("line[%d]: invalid float value", line->nr); } static int pretty; @@ -453,6 +460,7 @@ static char *get_trimmed_line(char *buf, int buf_size) static int scripted(void) { + struct string_list parts = STRING_LIST_INIT_NODUP; struct json_writer jw = JSON_WRITER_INIT; char buf[MAX_LINE_LENGTH]; char *line; @@ -470,66 +478,77 @@ static int scripted(void) die("expected first line to be 'object' or 'array'"); while ((line = get_trimmed_line(buf, MAX_LINE_LENGTH)) != NULL) { + struct line state = { 0 }; char *verb; char *key; char *s_value; intmax_t i_value; double d_value; - line_nr++; + state.parts = &parts; + state.nr = ++line_nr; + + /* break line into command and zero or more tokens */ + string_list_setlen(&parts, 0); + string_list_split_in_place(&parts, line, " ", -1); + string_list_remove_empty_items(&parts, 0); + + /* ignore empty lines */ + if (!parts.nr || !*parts.items[0].string) + continue; - verb = strtok(line, " "); + verb = parts.items[state.consumed_nr++].string; if (!strcmp(verb, "end")) { jw_end(&jw); } else if (!strcmp(verb, "object-string")) { - get_s(line_nr, &key); - get_s(line_nr, &s_value); + get_s(&state, &key); + get_s(&state, &s_value); jw_object_string(&jw, key, s_value); } else if (!strcmp(verb, "object-int")) { - get_s(line_nr, &key); - get_i(line_nr, &i_value); + get_s(&state, &key); + get_i(&state, &i_value); jw_object_intmax(&jw, key, i_value); } else if (!strcmp(verb, "object-double")) { - get_s(line_nr, &key); - get_i(line_nr, &i_value); - get_d(line_nr, &d_value); + get_s(&state, &key); + get_i(&state, &i_value); + get_d(&state, &d_value); jw_object_double(&jw, key, i_value, d_value); } else if (!strcmp(verb, "object-true")) { - get_s(line_nr, &key); + get_s(&state, &key); jw_object_true(&jw, key); } else if (!strcmp(verb, "object-false")) { - get_s(line_nr, &key); + get_s(&state, &key); jw_object_false(&jw, key); } else if (!strcmp(verb, "object-null")) { - get_s(line_nr, &key); + get_s(&state, &key); jw_object_null(&jw, key); } else if (!strcmp(verb, "object-object")) { - get_s(line_nr, &key); + get_s(&state, &key); jw_object_inline_begin_object(&jw, key); } else if (!strcmp(verb, "object-array")) { - get_s(line_nr, &key); + get_s(&state, &key); jw_object_inline_begin_array(&jw, key); } else if (!strcmp(verb, "array-string")) { - get_s(line_nr, &s_value); + get_s(&state, &s_value); jw_array_string(&jw, s_value); } else if (!strcmp(verb, "array-int")) { - get_i(line_nr, &i_value); + get_i(&state, &i_value); jw_array_intmax(&jw, i_value); } else if (!strcmp(verb, "array-double")) { - get_i(line_nr, &i_value); - get_d(line_nr, &d_value); + get_i(&state, &i_value); + get_d(&state, &d_value); jw_array_double(&jw, i_value, d_value); } else if (!strcmp(verb, "array-true")) @@ -552,6 +571,7 @@ static int scripted(void) printf("%s\n", jw.json.buf); jw_release(&jw); + string_list_clear(&parts, 0); return 0; } diff --git a/t/helper/test-lazy-init-name-hash.c b/t/helper/test-lazy-init-name-hash.c index f23d983c11..b83a75d19f 100644 --- a/t/helper/test-lazy-init-name-hash.c +++ b/t/helper/test-lazy-init-name-hash.c @@ -3,6 +3,7 @@ #include "cache.h" #include "environment.h" #include "parse-options.h" +#include "repository.h" #include "setup.h" #include "trace.h" diff --git a/t/helper/test-match-trees.c b/t/helper/test-match-trees.c index 35a2b8005c..d0db5ff26f 100644 --- a/t/helper/test-match-trees.c +++ b/t/helper/test-match-trees.c @@ -1,7 +1,8 @@ #include "test-tool.h" -#include "cache.h" #include "hex.h" +#include "match-trees.h" #include "object-name.h" +#include "repository.h" #include "setup.h" #include "tree.h" diff --git a/t/helper/test-mergesort.c b/t/helper/test-mergesort.c index 737e0c5235..42ccc87051 100644 --- a/t/helper/test-mergesort.c +++ b/t/helper/test-mergesort.c @@ -1,7 +1,7 @@ #include "test-tool.h" -#include "cache.h" #include "mem-pool.h" #include "mergesort.h" +#include "strbuf.h" static uint32_t minstd_rand(uint32_t *state) { diff --git a/t/helper/test-oid-array.c b/t/helper/test-oid-array.c index 30e1947b90..eef68833b7 100644 --- a/t/helper/test-oid-array.c +++ b/t/helper/test-oid-array.c @@ -1,8 +1,8 @@ #include "test-tool.h" -#include "cache.h" #include "hex.h" #include "oid-array.h" #include "setup.h" +#include "strbuf.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 1b0e7eecb4..bd30244a54 100644 --- a/t/helper/test-oidmap.c +++ b/t/helper/test-oidmap.c @@ -2,8 +2,10 @@ #include "hex.h" #include "object-name.h" #include "oidmap.h" +#include "repository.h" #include "setup.h" #include "strbuf.h" +#include "string-list.h" /* key is an oid and value is a name (could be a refname for example) */ struct test_entry { @@ -25,6 +27,7 @@ struct test_entry { */ int cmd__oidmap(int argc UNUSED, const char **argv UNUSED) { + struct string_list parts = STRING_LIST_INIT_NODUP; struct strbuf line = STRBUF_INIT; struct oidmap map = OIDMAP_INIT; @@ -35,19 +38,24 @@ int cmd__oidmap(int argc UNUSED, const char **argv UNUSED) /* process commands from stdin */ while (strbuf_getline(&line, stdin) != EOF) { - char *cmd, *p1 = NULL, *p2 = NULL; + char *cmd, *p1, *p2; struct test_entry *entry; struct object_id oid; /* break line into command and up to two parameters */ - cmd = strtok(line.buf, DELIM); + string_list_setlen(&parts, 0); + string_list_split_in_place(&parts, line.buf, DELIM, 2); + string_list_remove_empty_items(&parts, 0); + /* ignore empty lines */ - if (!cmd || *cmd == '#') + if (!parts.nr) + continue; + if (!*parts.items[0].string || *parts.items[0].string == '#') continue; - p1 = strtok(NULL, DELIM); - if (p1) - p2 = strtok(NULL, DELIM); + cmd = parts.items[0].string; + p1 = parts.nr >= 1 ? parts.items[1].string : NULL; + p2 = parts.nr >= 2 ? parts.items[2].string : NULL; if (!strcmp("put", cmd) && p1 && p2) { @@ -108,6 +116,7 @@ int cmd__oidmap(int argc UNUSED, const char **argv UNUSED) } } + string_list_clear(&parts, 0); strbuf_release(&line); oidmap_free(&map, 1); return 0; diff --git a/t/helper/test-oidtree.c b/t/helper/test-oidtree.c index 5b98f2f70a..c7a1d4c642 100644 --- a/t/helper/test-oidtree.c +++ b/t/helper/test-oidtree.c @@ -1,8 +1,8 @@ #include "test-tool.h" -#include "cache.h" #include "hex.h" #include "oidtree.h" #include "setup.h" +#include "strbuf.h" static enum cb_next print_oid(const struct object_id *oid, void *data UNUSED) { diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c index b66039e575..00fa281a9c 100644 --- a/t/helper/test-parse-options.c +++ b/t/helper/test-parse-options.c @@ -1,6 +1,6 @@ #include "test-tool.h" -#include "cache.h" #include "parse-options.h" +#include "strbuf.h" #include "string-list.h" #include "trace2.h" diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c index 6355c9e4b6..2ef53d5f7a 100644 --- a/t/helper/test-path-utils.c +++ b/t/helper/test-path-utils.c @@ -2,6 +2,7 @@ #include "cache.h" #include "abspath.h" #include "environment.h" +#include "path.h" #include "setup.h" #include "string-list.h" #include "trace.h" diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c index a4c24d0e42..c1ae276395 100644 --- a/t/helper/test-read-cache.c +++ b/t/helper/test-read-cache.c @@ -2,6 +2,7 @@ #include "test-tool.h" #include "cache.h" #include "config.h" +#include "repository.h" #include "setup.h" #include "wrapper.h" diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c index 05c4f2b262..211addaa00 100644 --- a/t/helper/test-read-midx.c +++ b/t/helper/test-read-midx.c @@ -1,10 +1,10 @@ #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 "packfile.h" #include "setup.h" static int read_midx_file(const char *object_dir, int show_objects) diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index 1f0a28cbb6..00237ef0d9 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -1,3 +1,4 @@ +#include "reftable/system.h" #include "reftable/reftable-tests.h" #include "test-tool.h" diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c index 3fecd06d17..6e17f50d22 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 "repository.h" #include "setup.h" #include "tree.h" #include "cache-tree.h" diff --git a/t/helper/test-string-list.c b/t/helper/test-string-list.c index 2123dda85b..e2aad611d1 100644 --- a/t/helper/test-string-list.c +++ b/t/helper/test-string-list.c @@ -1,5 +1,5 @@ #include "test-tool.h" -#include "cache.h" +#include "strbuf.h" #include "string-list.h" /* @@ -62,7 +62,7 @@ int cmd__string_list(int argc, const char **argv) struct string_list list = STRING_LIST_INIT_NODUP; int i; char *s = xstrdup(argv[2]); - int delim = *argv[3]; + const char *delim = argv[3]; int maxsplit = atoi(argv[4]); i = string_list_split_in_place(&list, s, delim, maxsplit); @@ -111,7 +111,7 @@ int cmd__string_list(int argc, const char **argv) */ if (sb.len && sb.buf[sb.len - 1] == '\n') strbuf_setlen(&sb, sb.len - 1); - string_list_split_in_place(&list, sb.buf, '\n', -1); + string_list_split_in_place(&list, sb.buf, "\n", -1); string_list_sort(&list); diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c index 5e462faa9d..9df2f03ac8 100644 --- a/t/helper/test-submodule-config.c +++ b/t/helper/test-submodule-config.c @@ -1,6 +1,8 @@ #include "test-tool.h" #include "config.h" +#include "hash.h" #include "object-name.h" +#include "repository.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 d31f5e48ab..ecd40ded99 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 "repository.h" #include "setup.h" #include "submodule-config.h" diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c index 7cbd59922a..356e0a26c5 100644 --- a/t/helper/test-submodule.c +++ b/t/helper/test-submodule.c @@ -2,6 +2,7 @@ #include "test-tool-utils.h" #include "parse-options.h" #include "remote.h" +#include "repository.h" #include "setup.h" #include "submodule-config.h" #include "submodule.h" diff --git a/t/helper/test-trace2.c b/t/helper/test-trace2.c index 98f071452a..20c7495f38 100644 --- a/t/helper/test-trace2.c +++ b/t/helper/test-trace2.c @@ -3,6 +3,7 @@ #include "run-command.h" #include "exec-cmd.h" #include "config.h" +#include "repository.h" #include "trace2.h" typedef int(fn_unit_test)(int argc, const char **argv); diff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c index a93417ed3a..eace08072d 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 "repository.h" #include "setup.h" int cmd__write_cache(int argc, const char **argv) diff --git a/t/t0063-string-list.sh b/t/t0063-string-list.sh index 46d4839194..1fee6d9010 100755 --- a/t/t0063-string-list.sh +++ b/t/t0063-string-list.sh @@ -18,6 +18,14 @@ test_split () { " } +test_split_in_place() { + cat >expected && + test_expect_success "split (in place) $1 at $2, max $3" " + test-tool string-list split_in_place '$1' '$2' '$3' >actual && + test_cmp expected actual + " +} + test_split "foo:bar:baz" ":" "-1" <<EOF 3 [0]: "foo" @@ -61,6 +69,49 @@ test_split ":" ":" "-1" <<EOF [1]: "" EOF +test_split_in_place "foo:;:bar:;:baz:;:" ":;" "-1" <<EOF +10 +[0]: "foo" +[1]: "" +[2]: "" +[3]: "bar" +[4]: "" +[5]: "" +[6]: "baz" +[7]: "" +[8]: "" +[9]: "" +EOF + +test_split_in_place "foo:;:bar:;:baz" ":;" "0" <<EOF +1 +[0]: "foo:;:bar:;:baz" +EOF + +test_split_in_place "foo:;:bar:;:baz" ":;" "1" <<EOF +2 +[0]: "foo" +[1]: ";:bar:;:baz" +EOF + +test_split_in_place "foo:;:bar:;:baz" ":;" "2" <<EOF +3 +[0]: "foo" +[1]: "" +[2]: ":bar:;:baz" +EOF + +test_split_in_place "foo:;:bar:;:" ":;" "-1" <<EOF +7 +[0]: "foo" +[1]: "" +[2]: "" +[3]: "bar" +[4]: "" +[5]: "" +[6]: "" +EOF + test_expect_success "test filter_string_list" ' test "x-" = "x$(test-tool string-list filter - y)" && test "x-" = "x$(test-tool string-list filter no y)" && diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh index 2f3e3e2416..e2ef619323 100755 --- a/t/t3501-revert-cherry-pick.sh +++ b/t/t3501-revert-cherry-pick.sh @@ -1,14 +1,6 @@ #!/bin/sh -test_description='test cherry-pick and revert with renames - - -- - + rename2: renames oops to opos - + rename1: renames oops to spoo - + added: adds extra line to oops - ++ initial: has lines in oops - -' +test_description='miscellaneous basic tests for cherry-pick and revert' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME @@ -63,6 +55,14 @@ test_expect_success 'revert --nonsense' ' test_i18ngrep "[Uu]sage:" msg ' +# the following two test cherry-pick and revert with renames +# +# -- +# + rename2: renames oops to opos +# + rename1: renames oops to spoo +# + added: adds extra line to oops +# ++ initial: has lines in oops + test_expect_success 'cherry-pick after renaming branch' ' git checkout rename2 && diff --git a/t/t4212-log-corrupt.sh b/t/t4212-log-corrupt.sh index e89e1f54b6..85e90acb09 100755 --- a/t/t4212-log-corrupt.sh +++ b/t/t4212-log-corrupt.sh @@ -8,8 +8,9 @@ TEST_PASSES_SANITIZE_LEAK=true test_expect_success 'setup' ' test_commit foo && - git cat-file commit HEAD | - sed "/^author /s/>/>-<>/" >broken_email.commit && + git cat-file commit HEAD >ok.commit && + sed "s/>/>-<>/" <ok.commit >broken_email.commit && + git hash-object --literally -w -t commit broken_email.commit >broken_email.hash && git update-ref refs/heads/broken_email $(cat broken_email.hash) ' @@ -43,6 +44,11 @@ test_expect_success 'git log --format with broken author email' ' test_must_be_empty actual.err ' +test_expect_success '--until handles broken email' ' + git rev-list --until=1980-01-01 broken_email >actual && + test_must_be_empty actual +' + munge_author_date () { git cat-file commit "$1" >commit.orig && sed "s/^\(author .*>\) [0-9]*/\1 $2/" <commit.orig >commit.munge && @@ -86,4 +92,45 @@ test_expect_success 'absurdly far-in-future date' ' git log -1 --format=%ad $commit ' +test_expect_success 'create commits with whitespace committer dates' ' + # It is important that this subject line is numeric, since we want to + # be sure we are not confused by skipping whitespace and accidentally + # parsing the subject as a timestamp. + # + # Do not use munge_author_date here. Besides not hitting the committer + # line, it leaves the timezone intact, and we want nothing but + # whitespace. + # + # We will make two munged commits here. The first, ws_commit, will + # be purely spaces. The second contains a vertical tab, which is + # considered a space by strtoumax(), but not by our isspace(). + test_commit 1234567890 && + git cat-file commit HEAD >commit.orig && + sed "s/>.*/> /" <commit.orig >commit.munge && + ws_commit=$(git hash-object --literally -w -t commit commit.munge) && + sed "s/>.*/> $(printf "\013")/" <commit.orig >commit.munge && + vt_commit=$(git hash-object --literally -w -t commit commit.munge) +' + +test_expect_success '--until treats whitespace date as sentinel' ' + echo $ws_commit >expect && + git rev-list --until=1980-01-01 $ws_commit >actual && + test_cmp expect actual && + + echo $vt_commit >expect && + git rev-list --until=1980-01-01 $vt_commit >actual && + test_cmp expect actual +' + +test_expect_success 'pretty-printer handles whitespace date' ' + # as with the %ad test above, we will show these as the empty string, + # not the 1970 epoch date. This is intentional; see 7d9a281941 (t4212: + # test bogus timestamps with git-log, 2014-02-24) for more discussion. + echo : >expect && + git log -1 --format="%at:%ct" $ws_commit >actual && + test_cmp expect actual && + git log -1 --format="%at:%ct" $vt_commit >actual && + test_cmp expect actual +' + test_done @@ -2,6 +2,7 @@ #include "config.h" #include "json-writer.h" #include "quote.h" +#include "repository.h" #include "run-command.h" #include "sigchain.h" #include "thread-utils.h" diff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c index 9e7aab6d51..2af53e5d4d 100644 --- a/trace2/tr2_tgt_event.c +++ b/trace2/tr2_tgt_event.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "config.h" #include "json-writer.h" +#include "repository.h" #include "run-command.h" #include "version.h" #include "trace2/tr2_dst.h" diff --git a/trace2/tr2_tgt_normal.c b/trace2/tr2_tgt_normal.c index 8672c2c2d0..1ebfb464d5 100644 --- a/trace2/tr2_tgt_normal.c +++ b/trace2/tr2_tgt_normal.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "config.h" +#include "repository.h" #include "run-command.h" #include "quote.h" #include "version.h" diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c index 3f2b2d5311..328e483a05 100644 --- a/trace2/tr2_tgt_perf.c +++ b/trace2/tr2_tgt_perf.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "config.h" +#include "repository.h" #include "run-command.h" #include "quote.h" #include "version.h" diff --git a/tree-diff.c b/tree-diff.c index 69031d7cba..20bb15f38d 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -1,10 +1,24 @@ /* * Helper functions for tree diff generation */ -#include "cache.h" +#include "git-compat-util.h" #include "diff.h" #include "diffcore.h" #include "tree.h" +#include "tree-walk.h" + +/* + * Some mode bits are also used internally for computations. + * + * They *must* not overlap with any valid modes, and they *must* not be emitted + * to outside world - i.e. appear on disk or network. In other words, it's just + * temporary fields, which we internally use, but they have to stay in-house. + * + * ( such approach is valid, as standard S_IF* fits into 16 bits, and in Git + * codebase mode is `unsigned int` which is assumed to be at least 32 bits ) + */ + +#define S_DIFFTREE_IFXMIN_NEQ 0x80000000 /* * internal mode marker, saying a tree entry != entry of tp[imin] diff --git a/tree-walk.c b/tree-walk.c index 2993c48c2f..d3c48e06df 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "tree-walk.h" #include "alloc.h" #include "dir.h" diff --git a/tree-walk.h b/tree-walk.h index 25fe27e352..01a9d8eb44 100644 --- a/tree-walk.h +++ b/tree-walk.h @@ -1,9 +1,10 @@ #ifndef TREE_WALK_H #define TREE_WALK_H -#include "hash.h" +#include "hash-ll.h" struct index_state; +struct repository; #define MAX_TRAVERSE_TREES 8 @@ -1,4 +1,4 @@ -#include "cache.h" +#include "git-compat-util.h" #include "cache-tree.h" #include "hex.h" #include "tree.h" @@ -94,14 +94,72 @@ int read_tree(struct repository *r, return ret; } -int cmp_cache_name_compare(const void *a_, const void *b_) +int base_name_compare(const char *name1, size_t len1, int mode1, + const char *name2, size_t len2, int mode2) { - const struct cache_entry *ce1, *ce2; + unsigned char c1, c2; + size_t len = len1 < len2 ? len1 : len2; + int cmp; + + cmp = memcmp(name1, name2, len); + if (cmp) + return cmp; + c1 = name1[len]; + c2 = name2[len]; + if (!c1 && S_ISDIR(mode1)) + c1 = '/'; + if (!c2 && S_ISDIR(mode2)) + c2 = '/'; + return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0; +} + +/* + * df_name_compare() is identical to base_name_compare(), except it + * compares conflicting directory/file entries as equal. Note that + * while a directory name compares as equal to a regular file, they + * then individually compare _differently_ to a filename that has + * a dot after the basename (because '\0' < '.' < '/'). + * + * This is used by routines that want to traverse the git namespace + * but then handle conflicting entries together when possible. + */ +int df_name_compare(const char *name1, size_t len1, int mode1, + const char *name2, size_t len2, int mode2) +{ + unsigned char c1, c2; + size_t len = len1 < len2 ? len1 : len2; + int cmp; + + cmp = memcmp(name1, name2, len); + if (cmp) + return cmp; + /* Directories and files compare equal (same length, same name) */ + if (len1 == len2) + return 0; + c1 = name1[len]; + if (!c1 && S_ISDIR(mode1)) + c1 = '/'; + c2 = name2[len]; + if (!c2 && S_ISDIR(mode2)) + c2 = '/'; + if (c1 == '/' && !c2) + return 0; + if (c2 == '/' && !c1) + return 0; + return c1 - c2; +} - ce1 = *((const struct cache_entry **)a_); - ce2 = *((const struct cache_entry **)b_); - return cache_name_stage_compare(ce1->name, ce1->ce_namelen, ce_stage(ce1), - ce2->name, ce2->ce_namelen, ce_stage(ce2)); +int name_compare(const char *name1, size_t len1, const char *name2, size_t len2) +{ + size_t min_len = (len1 < len2) ? len1 : len2; + int cmp = memcmp(name1, name2, min_len); + if (cmp) + return cmp; + if (len1 < len2) + return -1; + if (len1 > len2) + return 1; + return 0; } struct tree *lookup_tree(struct repository *r, const struct object_id *oid) @@ -3,6 +3,7 @@ #include "object.h" +struct pathspec; struct repository; struct strbuf; @@ -28,7 +29,15 @@ void free_tree_buffer(struct tree *tree); /* Parses and returns the tree in the given ent, chasing tags and commits. */ struct tree *parse_tree_indirect(const struct object_id *oid); -int cmp_cache_name_compare(const void *a_, const void *b_); +/* + * Functions for comparing pathnames + */ +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, + const char *name2, size_t len2, int mode2); +int name_compare(const char *name1, size_t len1, + const char *name2, size_t len2); #define READ_TREE_RECURSIVE 1 typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, const char *, unsigned int, void *); diff --git a/unpack-trees.c b/unpack-trees.c index c0732aa0c2..e8c32a40dc 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -18,6 +18,7 @@ #include "sparse-index.h" #include "submodule.h" #include "submodule-config.h" +#include "symlinks.h" #include "trace2.h" #include "fsmonitor.h" #include "object-store.h" diff --git a/versioncmp.c b/versioncmp.c index 7498da96e0..74cc7c43f0 100644 --- a/versioncmp.c +++ b/versioncmp.c @@ -1,6 +1,7 @@ -#include "cache.h" +#include "git-compat-util.h" #include "config.h" #include "string-list.h" +#include "versioncmp.h" /* * versioncmp(): copied from string/strverscmp.c in glibc commit diff --git a/versioncmp.h b/versioncmp.h new file mode 100644 index 0000000000..879b510e82 --- /dev/null +++ b/versioncmp.h @@ -0,0 +1,6 @@ +#ifndef VERSIONCMP_H +#define VERSIONCMP_H + +int versioncmp(const char *s1, const char *s2); + +#endif /* VERSIONCMP_H */ @@ -1,10 +1,13 @@ /* * Various trivial helper wrappers around standard functions */ -#include "cache.h" +#include "git-compat-util.h" #include "abspath.h" #include "config.h" #include "gettext.h" +#include "object.h" +#include "repository.h" +#include "strbuf.h" #include "trace2.h" #include "wrapper.h" @@ -3,8 +3,12 @@ * * Copyright (c) 2007 Junio C Hamano */ -#include "cache.h" +#include "git-compat-util.h" #include "attr.h" +#include "strbuf.h" +#include "ws.h" + +unsigned whitespace_rule_cfg = WS_DEFAULT_RULE; static struct whitespace_rule { const char *rule_name; @@ -0,0 +1,33 @@ +#ifndef WS_H +#define WS_H + +struct index_state; +struct strbuf; + +/* + * whitespace rules. + * used by both diff and apply + * last two digits are tab width + */ +#define WS_BLANK_AT_EOL 0100 +#define WS_SPACE_BEFORE_TAB 0200 +#define WS_INDENT_WITH_NON_TAB 0400 +#define WS_CR_AT_EOL 01000 +#define WS_BLANK_AT_EOF 02000 +#define WS_TAB_IN_INDENT 04000 +#define WS_TRAILING_SPACE (WS_BLANK_AT_EOL|WS_BLANK_AT_EOF) +#define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB|8) +#define WS_TAB_WIDTH_MASK 077 +/* All WS_* -- when extended, adapt diff.c emit_symbol */ +#define WS_RULE_MASK 07777 +extern unsigned whitespace_rule_cfg; +unsigned whitespace_rule(struct index_state *, const char *); +unsigned parse_whitespace_rule(const char *); +unsigned ws_check(const char *line, int len, unsigned ws_rule); +void ws_check_emit(const char *line, int len, unsigned ws_rule, FILE *stream, const char *set, const char *reset, const char *ws); +char *whitespace_error_string(unsigned ws); +void ws_fix_copy(struct strbuf *, const char *, int, unsigned, int *); +int ws_blank_line(const char *line, int len); +#define ws_tab_width(rule) ((rule) & WS_TAB_WIDTH_MASK) + +#endif /* WS_H */ diff --git a/wt-status.c b/wt-status.c index 97b9c1c035..068b76ef6d 100644 --- a/wt-status.c +++ b/wt-status.c @@ -22,6 +22,7 @@ #include "strbuf.h" #include "trace.h" #include "trace2.h" +#include "tree.h" #include "utf8.h" #include "worktree.h" #include "lockfile.h" diff --git a/xdiff-interface.h b/xdiff-interface.h index 3750794afe..733c364d26 100644 --- a/xdiff-interface.h +++ b/xdiff-interface.h @@ -1,7 +1,7 @@ #ifndef XDIFF_INTERFACE_H #define XDIFF_INTERFACE_H -#include "hash.h" +#include "hash-ll.h" #include "xdiff/xdiff.h" /* |