]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branches 'bw/ls-files-sans-the-index' and 'bw/config-h' into bw/repo-object
authorJunio C Hamano <gitster@pobox.com>
Wed, 21 Jun 2017 22:20:44 +0000 (15:20 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 24 Jun 2017 01:24:00 +0000 (18:24 -0700)
* bw/ls-files-sans-the-index:
  ls-files: factor out tag calculation
  ls-files: factor out debug info into a function
  ls-files: convert show_files to take an index
  ls-files: convert show_ce_entry to take an index
  ls-files: convert prune_cache to take an index
  ls-files: convert ce_excluded to take an index
  ls-files: convert show_ru_info to take an index
  ls-files: convert show_other_files to take an index
  ls-files: convert show_killed_files to take an index
  ls-files: convert write_eolinfo to take an index
  ls-files: convert overlay_tree_on_cache to take an index
  tree: convert read_tree to take an index parameter
  convert: convert renormalize_buffer to take an index
  convert: convert convert_to_git to take an index
  convert: convert convert_to_git_filter_fd to take an index
  convert: convert crlf_to_git to take an index
  convert: convert get_cached_convert_stats_ascii to take an index

* bw/config-h:
  config: don't implicitly use gitdir or commondir
  config: respect commondir
  setup: teach discover_git_directory to respect the commondir
  config: don't include config.h by default
  config: remove git_config_iter
  config: create config.h
  alias: use the early config machinery to expand aliases
  t7006: demonstrate a problem with aliases in subdirectories
  t1308: relax the test verifying that empty alias values are disallowed
  help: use early config when autocorrecting aliases
  config: report correct line number upon error
  discover_git_directory(): avoid setting invalid git_dir

155 files changed:
advice.c
alias.c
apply.c
archive-tar.c
archive-zip.c
archive.c
attr.c
bisect.c
blame.c
branch.c
builtin/add.c
builtin/am.c
builtin/blame.c
builtin/branch.c
builtin/cat-file.c
builtin/check-attr.c
builtin/check-ignore.c
builtin/check-mailmap.c
builtin/checkout-index.c
builtin/checkout.c
builtin/clean.c
builtin/clone.c
builtin/column.c
builtin/commit-tree.c
builtin/commit.c
builtin/config.c
builtin/count-objects.c
builtin/describe.c
builtin/diff-files.c
builtin/diff-index.c
builtin/diff-tree.c
builtin/diff.c
builtin/difftool.c
builtin/fast-export.c
builtin/fetch.c
builtin/fmt-merge-msg.c
builtin/for-each-ref.c
builtin/fsck.c
builtin/gc.c
builtin/grep.c
builtin/hash-object.c
builtin/help.c
builtin/index-pack.c
builtin/init-db.c
builtin/log.c
builtin/ls-files.c
builtin/ls-tree.c
builtin/merge-base.c
builtin/merge-file.c
builtin/merge.c
builtin/mv.c
builtin/name-rev.c
builtin/notes.c
builtin/pack-objects.c
builtin/patch-id.c
builtin/pull.c
builtin/push.c
builtin/read-tree.c
builtin/rebase--helper.c
builtin/receive-pack.c
builtin/reflog.c
builtin/remote.c
builtin/repack.c
builtin/replace.c
builtin/rerere.c
builtin/reset.c
builtin/rev-list.c
builtin/rev-parse.c
builtin/revert.c
builtin/rm.c
builtin/send-pack.c
builtin/shortlog.c
builtin/show-branch.c
builtin/stripspace.c
builtin/submodule--helper.c
builtin/symbolic-ref.c
builtin/tag.c
builtin/unpack-file.c
builtin/unpack-objects.c
builtin/update-index.c
builtin/update-ref.c
builtin/update-server-info.c
builtin/var.c
builtin/verify-commit.c
builtin/verify-pack.c
builtin/verify-tag.c
builtin/worktree.c
builtin/write-tree.c
cache.h
color.c
column.c
combine-diff.c
compat/precompose_utf8.c
config.c
config.h [new file with mode: 0644]
connect.c
convert.c
convert.h
credential-cache--daemon.c
credential.c
daemon.c
diff.c
dir.c
environment.c
fast-import.c
fetch-pack.c
git.c
gpg-interface.c
graph.c
grep.c
help.c
http-backend.c
http-fetch.c
http.c
ident.c
imap-send.c
ll-merge.c
log-tree.c
mailinfo.c
merge-recursive.c
notes-utils.c
notes.c
pager.c
parse-options.c
pathspec.c
pretty.c
prompt.c
read-cache.c
refs.c
refs/files-backend.c
remote-curl.c
remote.c
rerere.c
send-pack.c
sequencer.c
setup.c
sha1_file.c
sha1_name.c
submodule-config.c
submodule.c
t/helper/test-config.c
t/helper/test-submodule-config.c
t/t1300-repo-config.sh
t/t1308-config-set.sh
t/t7006-pager.sh
trailer.c
transport.c
tree.c
tree.h
unpack-trees.c
upload-pack.c
userdiff.c
versioncmp.c
wrapper.c
xdiff-interface.c

index b84ae4960f11af10d01667d01eb0bb27f52ecb14..3fa04fca0b81ce0b4788ad3331ae759de805e0ff 100644 (file)
--- a/advice.c
+++ b/advice.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 
 int advice_push_update_rejected = 1;
 int advice_push_non_ff_current = 1;
diff --git a/alias.c b/alias.c
index 3b90397a99d9f7ed4a0c1c5a83f5e69c879e752f..de8e6a3f496accd9bd06916411ebb7e10b27d4cb 100644 (file)
--- a/alias.c
+++ b/alias.c
@@ -1,14 +1,29 @@
 #include "cache.h"
+#include "config.h"
+
+struct config_alias_data {
+       const char *alias;
+       char *v;
+};
+
+static int config_alias_cb(const char *key, const char *value, void *d)
+{
+       struct config_alias_data *data = d;
+       const char *p;
+
+       if (skip_prefix(key, "alias.", &p) && !strcmp(p, data->alias))
+               return git_config_string((const char **)&data->v, key, value);
+
+       return 0;
+}
 
 char *alias_lookup(const char *alias)
 {
-       char *v = NULL;
-       struct strbuf key = STRBUF_INIT;
-       strbuf_addf(&key, "alias.%s", alias);
-       if (git_config_key_is_valid(key.buf))
-               git_config_get_string(key.buf, &v);
-       strbuf_release(&key);
-       return v;
+       struct config_alias_data data = { alias, NULL };
+
+       read_early_config(config_alias_cb, &data);
+
+       return data.v;
 }
 
 #define SPLIT_CMDLINE_BAD_ENDING 1
diff --git a/apply.c b/apply.c
index 854faa67795bcd356b33420f46260f208c2ec047..65063785c1651ed288133788980a1a8d0a410cbd 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -8,6 +8,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "blob.h"
 #include "delta.h"
 #include "diff.h"
@@ -2267,7 +2268,7 @@ static int read_old_data(struct stat *st, const char *path, struct strbuf *buf)
        case S_IFREG:
                if (strbuf_read_file(buf, path, st->st_size) != st->st_size)
                        return error(_("unable to open or read %s"), path);
-               convert_to_git(path, buf->buf, buf->len, buf, 0);
+               convert_to_git(&the_index, path, buf->buf, buf->len, buf, 0);
                return 0;
        default:
                return -1;
index 073e60ebd3c366b42298ae443eee230407d4e3a7..c6ed96ee74ec10f5c9ffb6f520193326d4704b6b 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright (c) 2005, 2006 Rene Scharfe
  */
 #include "cache.h"
+#include "config.h"
 #include "tar.h"
 #include "archive.h"
 #include "streaming.h"
index 27563e9e2602108997033e6fa79c660bc08aa863..e8913e5a26c6e97216c4b79ad96b5e3ddf906c45 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright (c) 2006 Rene Scharfe
  */
 #include "cache.h"
+#include "config.h"
 #include "archive.h"
 #include "streaming.h"
 #include "utf8.h"
index b15a922dab56a525ca3ce7f1143d215fe39f3132..60b3035a7a6a9e7c2e69b4ba7de00ebdf8bfdbb8 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "commit.h"
 #include "tree-walk.h"
diff --git a/attr.c b/attr.c
index 821203e2a980c329fc065a0dfabe37ef67a4bbbe..6e4b247acd91d30ac5a879183332725d54e756a0 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -9,6 +9,7 @@
 
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "config.h"
 #include "exec_cmd.h"
 #include "attr.h"
 #include "dir.h"
index 2a2b9b7267acbb8752015d64ec477f64c6047875..a9fd9fbc61a661ab19e18713b115f868daab2f98 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
diff --git a/blame.c b/blame.c
index 194b58e96066f9620005f64a57ca9ecc618c86f4..6d57ab9715665a8bc6a2ba02015342ad851b6d2f 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -229,7 +229,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
                if (strbuf_read(&buf, 0, 0) < 0)
                        die_errno("failed to read from stdin");
        }
-       convert_to_git(path, buf.buf, buf.len, &buf, 0);
+       convert_to_git(&the_index, path, buf.buf, buf.len, &buf, 0);
        origin->file.ptr = buf.buf;
        origin->file.size = buf.len;
        pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_oid.hash);
index 985316eb76505a60bca0aa303322bef35e7defaa..a8a548ccf2870c99bbdbcdc7036003aa648faa0c 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "cache.h"
+#include "config.h"
 #include "branch.h"
 #include "refs.h"
 #include "remote.h"
index d9a2491e48f16d9ef7de5c05008f8c7e6a5e64b2..f2415e99f37d48e562913c17d8917bda4f892c09 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) 2006 Linus Torvalds
  */
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "lockfile.h"
 #include "dir.h"
index 3985f9a89f985baa139ea69f5fde8ce1384871f6..7c7b916d2328be8e6dc7abb7e08bb9416b21d2e6 100644 (file)
@@ -4,6 +4,7 @@
  * Based on git-am.sh by Junio C Hamano.
  */
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "exec_cmd.h"
 #include "parse-options.h"
index 749ad7f05b657ba34534a4ae6601dd5d85649b36..bda1a787265e6d44d2ec0bec1e4dee5bf8de9c3b 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "commit.h"
 #include "diff.h"
index 83fcda43dceec0255c6164eb42a35d3d89011efb..c958e93257910816bd8d40673805e8553f921f3f 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "color.h"
 #include "refs.h"
 #include "commit.h"
index 4bffd7a2d8eee2ea251afef70f63f646f184a339..7efbc4019ac59a16ae4f147889e6f489dac1e661 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "diff.h"
 #include "parse-options.h"
index 4d01ca0c8ba0ba2a1d2c209b766e19d9ca9c8ac0..91444dc0448b32e854f1923fe1e57e28c87f5b35 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "attr.h"
 #include "quote.h"
 #include "parse-options.h"
index c7b8c08897193e225d8da32f4d402def3f16fe50..3e280b9c7aa9c93c8e7572a4fe3f7ef3ac92b3af 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "quote.h"
 #include "pathspec.h"
index cf0f54f6b92ec8db45158c43ad164413ec4a1333..cdce144f3b7f160f508721ed4f4afc69d683262a 100644 (file)
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "mailmap.h"
 #include "parse-options.h"
 #include "string-list.h"
index 07631d0c9c59f6ba03f288294797e08cdfe22b7c..39c8be05dc4beda2f0cd179e5c5f495ce079f8d9 100644 (file)
@@ -5,6 +5,7 @@
  *
  */
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "quote.h"
 #include "cache-tree.h"
index 1624eed7e7625c18da7ffb58f1b9ae456c3dbd77..9661e1bcba31ffa4f7b8a2fb1a9d2060cb8efda7 100644 (file)
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "parse-options.h"
 #include "refs.h"
index 142bf668cffe814006fae791f1bdc6b20fe6f366..ed954134d2dd03242a06eef88bcaec71cc41ffe9 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "parse-options.h"
 #include "string-list.h"
index a2ea019c590190a00d1a7cf51a917c7ebdc7886c..08b5cc433c6fcad5eea2dfc3321aea28a599d51f 100644 (file)
@@ -9,6 +9,7 @@
  */
 
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "parse-options.h"
 #include "fetch-pack.h"
index 33314b4d7127cb6e4116c350e113058e07f58474..0c3223d64b159580935bf24f8583a35a1ae903ff 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "strbuf.h"
 #include "parse-options.h"
 #include "string-list.h"
index f39c2b27375fcd70f050e56174b0966053652eef..a4a923d7c0b688e162c8e4d0411ff9b72748fb5c 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "tree.h"
 #include "builtin.h"
index e3c9e190b06a63250a9c7eff3e256efcb10660f7..021070e693e78fe49a168f842f64aeea73de4a8b 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "cache-tree.h"
 #include "color.h"
@@ -253,7 +254,8 @@ static int list_paths(struct string_list *list, const char *with_tree,
 
        if (with_tree) {
                char *max_prefix = common_prefix(pattern);
-               overlay_tree_on_cache(with_tree, max_prefix ? max_prefix : prefix);
+               overlay_tree_on_index(&the_index, with_tree,
+                                     max_prefix ? max_prefix : prefix);
                free(max_prefix);
        }
 
index 7f6c25d4d95b37f7785e0b6872d059095548c87f..82db29fae71551a44150c64a4c1187ef4ebd572a 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "color.h"
 #include "parse-options.h"
 #include "urlmatch.h"
@@ -242,8 +243,8 @@ static int get_value(const char *key_, const char *regex_)
                }
        }
 
-       git_config_with_options(collect_config, &values,
-                               &given_config_source, &config_options);
+       config_with_options(collect_config, &values,
+                           &given_config_source, &config_options);
 
        ret = !values.nr;
 
@@ -320,8 +321,8 @@ static void get_color(const char *var, const char *def_color)
        get_color_slot = var;
        get_color_found = 0;
        parsed_color[0] = '\0';
-       git_config_with_options(git_get_color_config, NULL,
-                               &given_config_source, &config_options);
+       config_with_options(git_get_color_config, NULL,
+                           &given_config_source, &config_options);
 
        if (!get_color_found && def_color) {
                if (color_parse(def_color, parsed_color) < 0)
@@ -352,8 +353,8 @@ static int get_colorbool(const char *var, int print)
        get_colorbool_found = -1;
        get_diff_color_found = -1;
        get_color_ui_found = -1;
-       git_config_with_options(git_get_colorbool_config, NULL,
-                               &given_config_source, &config_options);
+       config_with_options(git_get_colorbool_config, NULL,
+                           &given_config_source, &config_options);
 
        if (get_colorbool_found < 0) {
                if (!strcmp(get_colorbool_slot, "color.diff"))
@@ -441,8 +442,8 @@ static int get_urlmatch(const char *var, const char *url)
                show_keys = 1;
        }
 
-       git_config_with_options(urlmatch_config_entry, &config,
-                               &given_config_source, &config_options);
+       config_with_options(urlmatch_config_entry, &config,
+                           &given_config_source, &config_options);
 
        ret = !values.nr;
 
@@ -538,6 +539,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                config_options.respect_includes = !given_config_source.file;
        else
                config_options.respect_includes = respect_includes_opt;
+       if (!nongit) {
+               config_options.commondir = get_git_common_dir();
+               config_options.git_dir = get_git_dir();
+       }
 
        if (end_null) {
                term = '\0';
@@ -582,9 +587,9 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 
        if (actions == ACTION_LIST) {
                check_argc(argc, 0, 0);
-               if (git_config_with_options(show_all_config, NULL,
-                                           &given_config_source,
-                                           &config_options) < 0) {
+               if (config_with_options(show_all_config, NULL,
+                                       &given_config_source,
+                                       &config_options) < 0) {
                        if (given_config_source.file)
                                die_errno("unable to read config file '%s'",
                                          given_config_source.file);
index acb05940fc3cd902d4c9bfa480f2c473dcc4d9d5..1d82e61f2a6391bd93a6c3dd91a2515189ff79cc 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "builtin.h"
 #include "parse-options.h"
index 893c8789f4f563c58041040740384322e6ea205b..70eb1446089583cd859ea1f05b260283cd78067f 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "commit.h"
 #include "tag.h"
index c97069a714e42a1737b5dfa223fe39c26ad9aa67..17bf84d18f802d3f223e7408fee644b94878b35f 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "revision.h"
index d59bf6cf5f8da394251532765f27a044c14a572d..185e6f9b582fdcf15072038b570463a0cfb1bbf2 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "revision.h"
index 7e15d01f36396fdc6b630eb43a5f36d462fb78e6..31d2cb410738d335d9f6431d6901ea1c0f8b67ff 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "log-tree.h"
index d9152c21bf5a8aa41778f838b4d804ac698bdc2b..7cde6abbcf7651af8313bd3d70eb1944e72c9cb3 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (c) 2006 Junio C Hamano
  */
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "color.h"
 #include "commit.h"
index b9a892f2693efe01a08c958f7064f13ba6ec43aa..9199227f6e9dc0b6d0c3e350f701aeaf9caaddd3 100644 (file)
@@ -12,6 +12,7 @@
  * Copyright (C) 2016 Johannes Schindelin
  */
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "run-command.h"
 #include "exec_cmd.h"
index a932be04f4d5f733eebe1ebeba82c1bc64de3088..12d501bfde3aac09c411169f99ff28ad35593a3b 100644 (file)
@@ -5,6 +5,7 @@
  */
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "commit.h"
 #include "object.h"
index 100248c5afe3e1c16fa7fe79696200aeb5d1bde2..16cf8421ce4cc2221e6ed59110928328693481fb 100644 (file)
@@ -2,6 +2,7 @@
  * "git fetch"
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "commit.h"
 #include "builtin.h"
index 70137b0b7e56e6319872fddc3527fe1094009dee..10cbb434163f2f6e60e0cc9cb55bab220004a549 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "commit.h"
 #include "diff.h"
index eca365bf89bb64a71d02d21da29fc1e84204c1a1..52be99cbacdd84f60e5b9f2efd1f1d50f602cdb8 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "object.h"
 #include "parse-options.h"
index 3a2c27f2413e5e377926e0e7df339549c37a76b3..87c675689986413f4c2ace09701adccf6e836942 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "tree.h"
 #include "blob.h"
index f484eda43ca06046924931d2055b50c2f89ea8d7..bd91f136fed125ab06502c22b74b4f193f60773a 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include "builtin.h"
+#include "config.h"
 #include "tempfile.h"
 #include "lockfile.h"
 #include "parse-options.h"
index 3e4b9600e86b661c99f4b936dfa574029ac4fbba..f61a9d938b44424414812c57eecc309bd563f4b3 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (c) 2006 Junio C Hamano
  */
 #include "cache.h"
+#include "config.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
index bbeaf20bcca1ae1e9bfa55b5a8e4adbed83c00e8..d04baf999a94cfa6a07e74861876d6a9f1c88a6d 100644 (file)
@@ -5,6 +5,7 @@
  * Copyright (C) Junio C Hamano, 2005
  */
 #include "builtin.h"
+#include "config.h"
 #include "blob.h"
 #include "quote.h"
 #include "parse-options.h"
index 49f7a07f85db1e36d959749adf2eb1962940fb19..334a8494abcc4ac52babf468d8a1ef415aa7f297 100644 (file)
@@ -2,6 +2,7 @@
  * Builtin help command
  */
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "exec_cmd.h"
 #include "parse-options.h"
index 04b9dcaf0f4ca90712cbb85cace521e226194f3b..edc1a91d89b308b1e164c48c1dfb06c8f6ebf0d1 100644 (file)
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "delta.h"
 #include "pack.h"
 #include "csum-file.h"
index 8a6acb0ec69330f7aae20d34fb5c5733f0058c67..47823f9aa4452edfa684b042dd5fbaa935df1d39 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "builtin.h"
 #include "exec_cmd.h"
index 998437b23dcb32a45e4d722d695c86d3cc82b4bc..8ca1de98943bdc62248ddd31708a6632557c61de 100644 (file)
@@ -5,6 +5,7 @@
  *              2006 Junio Hamano
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "color.h"
 #include "commit.h"
index b376afc3124c3240f4f249ccc206efa0b064675e..b12d0bb61240890b3145baa8f051c83005b97dbe 100644 (file)
@@ -6,6 +6,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "quote.h"
 #include "dir.h"
 #include "builtin.h"
@@ -53,17 +54,17 @@ static const char *tag_modified = "";
 static const char *tag_skip_worktree = "";
 static const char *tag_resolve_undo = "";
 
-static void write_eolinfo(const struct cache_entry *ce, const char *path)
+static void write_eolinfo(const struct index_state *istate,
+                         const struct cache_entry *ce, const char *path)
 {
-       if (!show_eol)
-               return;
-       else {
+       if (show_eol) {
                struct stat st;
                const char *i_txt = "";
                const char *w_txt = "";
                const char *a_txt = get_convert_attr_ascii(path);
                if (ce && S_ISREG(ce->ce_mode))
-                       i_txt = get_cached_convert_stats_ascii(ce->name);
+                       i_txt = get_cached_convert_stats_ascii(istate,
+                                                              ce->name);
                if (!lstat(path, &st) && S_ISREG(st.st_mode))
                        w_txt = get_wt_convert_stats_ascii(path);
                printf("i/%-5s w/%-5s attr/%-17s\t", i_txt, w_txt, a_txt);
@@ -93,6 +94,43 @@ static void write_name(const char *name)
        strbuf_release(&full_name);
 }
 
+static const char *get_tag(const struct cache_entry *ce, const char *tag)
+{
+       static char alttag[4];
+
+       if (tag && *tag && show_valid_bit && (ce->ce_flags & CE_VALID)) {
+               memcpy(alttag, tag, 3);
+
+               if (isalpha(tag[0])) {
+                       alttag[0] = tolower(tag[0]);
+               } else if (tag[0] == '?') {
+                       alttag[0] = '!';
+               } else {
+                       alttag[0] = 'v';
+                       alttag[1] = tag[0];
+                       alttag[2] = ' ';
+                       alttag[3] = 0;
+               }
+
+               tag = alttag;
+       }
+
+       return tag;
+}
+
+static void print_debug(const struct cache_entry *ce)
+{
+       if (debug_mode) {
+               const struct stat_data *sd = &ce->ce_stat_data;
+
+               printf("  ctime: %d:%d\n", sd->sd_ctime.sec, sd->sd_ctime.nsec);
+               printf("  mtime: %d:%d\n", sd->sd_mtime.sec, sd->sd_mtime.nsec);
+               printf("  dev: %d\tino: %d\n", sd->sd_dev, sd->sd_ino);
+               printf("  uid: %d\tgid: %d\n", sd->sd_uid, sd->sd_gid);
+               printf("  size: %d\tflags: %x\n", sd->sd_size, ce->ce_flags);
+       }
+}
+
 static void show_dir_entry(const char *tag, struct dir_entry *ent)
 {
        int len = max_prefix_len;
@@ -104,23 +142,25 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
                return;
 
        fputs(tag, stdout);
-       write_eolinfo(NULL, ent->name);
+       write_eolinfo(NULL, NULL, ent->name);
        write_name(ent->name);
 }
 
-static void show_other_files(struct dir_struct *dir)
+static void show_other_files(const struct index_state *istate,
+                            const struct dir_struct *dir)
 {
        int i;
 
        for (i = 0; i < dir->nr; i++) {
                struct dir_entry *ent = dir->entries[i];
-               if (!cache_name_is_other(ent->name, ent->len))
+               if (!index_name_is_other(istate, ent->name, ent->len))
                        continue;
                show_dir_entry(tag_other, ent);
        }
 }
 
-static void show_killed_files(struct dir_struct *dir)
+static void show_killed_files(const struct index_state *istate,
+                             const struct dir_struct *dir)
 {
        int i;
        for (i = 0; i < dir->nr; i++) {
@@ -134,29 +174,29 @@ static void show_killed_files(struct dir_struct *dir)
                                /* If ent->name is prefix of an entry in the
                                 * cache, it will be killed.
                                 */
-                               pos = cache_name_pos(ent->name, ent->len);
+                               pos = index_name_pos(istate, ent->name, ent->len);
                                if (0 <= pos)
                                        die("BUG: killed-file %.*s not found",
                                                ent->len, ent->name);
                                pos = -pos - 1;
-                               while (pos < active_nr &&
-                                      ce_stage(active_cache[pos]))
+                               while (pos < istate->cache_nr &&
+                                      ce_stage(istate->cache[pos]))
                                        pos++; /* skip unmerged */
-                               if (active_nr <= pos)
+                               if (istate->cache_nr <= pos)
                                        break;
                                /* pos points at a name immediately after
                                 * ent->name in the cache.  Does it expect
                                 * ent->name to be a directory?
                                 */
-                               len = ce_namelen(active_cache[pos]);
+                               len = ce_namelen(istate->cache[pos]);
                                if ((ent->len < len) &&
-                                   !strncmp(active_cache[pos]->name,
+                                   !strncmp(istate->cache[pos]->name,
                                             ent->name, ent->len) &&
-                                   active_cache[pos]->name[ent->len] == '/')
+                                   istate->cache[pos]->name[ent->len] == '/')
                                        killed = 1;
                                break;
                        }
-                       if (0 <= cache_name_pos(ent->name, sp - ent->name)) {
+                       if (0 <= index_name_pos(istate, ent->name, sp - ent->name)) {
                                /* If any of the leading directories in
                                 * ent->name is registered in the cache,
                                 * ent->name will be killed.
@@ -230,7 +270,8 @@ static void show_gitlink(const struct cache_entry *ce)
                exit(status);
 }
 
-static void show_ce_entry(const char *tag, const struct cache_entry *ce)
+static void show_ce_entry(const struct index_state *istate,
+                         const char *tag, const struct cache_entry *ce)
 {
        struct strbuf name = STRBUF_INIT;
        int len = max_prefix_len;
@@ -248,22 +289,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)
                                  len, ps_matched,
                                  S_ISDIR(ce->ce_mode) ||
                                  S_ISGITLINK(ce->ce_mode))) {
-               if (tag && *tag && show_valid_bit &&
-                   (ce->ce_flags & CE_VALID)) {
-                       static char alttag[4];
-                       memcpy(alttag, tag, 3);
-                       if (isalpha(tag[0]))
-                               alttag[0] = tolower(tag[0]);
-                       else if (tag[0] == '?')
-                               alttag[0] = '!';
-                       else {
-                               alttag[0] = 'v';
-                               alttag[1] = tag[0];
-                               alttag[2] = ' ';
-                               alttag[3] = 0;
-                       }
-                       tag = alttag;
-               }
+               tag = get_tag(ce, tag);
 
                if (!show_stage) {
                        fputs(tag, stdout);
@@ -274,30 +300,22 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)
                               find_unique_abbrev(ce->oid.hash, abbrev),
                               ce_stage(ce));
                }
-               write_eolinfo(ce, ce->name);
+               write_eolinfo(istate, ce, ce->name);
                write_name(ce->name);
-               if (debug_mode) {
-                       const struct stat_data *sd = &ce->ce_stat_data;
-
-                       printf("  ctime: %d:%d\n", sd->sd_ctime.sec, sd->sd_ctime.nsec);
-                       printf("  mtime: %d:%d\n", sd->sd_mtime.sec, sd->sd_mtime.nsec);
-                       printf("  dev: %d\tino: %d\n", sd->sd_dev, sd->sd_ino);
-                       printf("  uid: %d\tgid: %d\n", sd->sd_uid, sd->sd_gid);
-                       printf("  size: %d\tflags: %x\n", sd->sd_size, ce->ce_flags);
-               }
+               print_debug(ce);
        }
 
        strbuf_release(&name);
 }
 
-static void show_ru_info(void)
+static void show_ru_info(const struct index_state *istate)
 {
        struct string_list_item *item;
 
-       if (!the_index.resolve_undo)
+       if (!istate->resolve_undo)
                return;
 
-       for_each_string_list_item(item, the_index.resolve_undo) {
+       for_each_string_list_item(item, istate->resolve_undo) {
                const char *path = item->string;
                struct resolve_undo_info *ui = item->util;
                int i, len;
@@ -319,13 +337,14 @@ static void show_ru_info(void)
        }
 }
 
-static int ce_excluded(struct dir_struct *dir, const struct cache_entry *ce)
+static int ce_excluded(struct dir_struct *dir, struct index_state *istate,
+                      const struct cache_entry *ce)
 {
        int dtype = ce_to_dtype(ce);
-       return is_excluded(dir, &the_index, ce->name, &dtype);
+       return is_excluded(dir, istate, ce->name, &dtype);
 }
 
-static void show_files(struct dir_struct *dir)
+static void show_files(struct index_state *istate, struct dir_struct *dir)
 {
        int i;
 
@@ -333,33 +352,33 @@ static void show_files(struct dir_struct *dir)
        if (show_others || show_killed) {
                if (!show_others)
                        dir->flags |= DIR_COLLECT_KILLED_ONLY;
-               fill_directory(dir, &the_index, &pathspec);
+               fill_directory(dir, istate, &pathspec);
                if (show_others)
-                       show_other_files(dir);
+                       show_other_files(istate, dir);
                if (show_killed)
-                       show_killed_files(dir);
+                       show_killed_files(istate, dir);
        }
        if (show_cached || show_stage) {
-               for (i = 0; i < active_nr; i++) {
-                       const struct cache_entry *ce = active_cache[i];
+               for (i = 0; i < istate->cache_nr; i++) {
+                       const struct cache_entry *ce = istate->cache[i];
                        if ((dir->flags & DIR_SHOW_IGNORED) &&
-                           !ce_excluded(dir, ce))
+                           !ce_excluded(dir, istate, ce))
                                continue;
                        if (show_unmerged && !ce_stage(ce))
                                continue;
                        if (ce->ce_flags & CE_UPDATE)
                                continue;
-                       show_ce_entry(ce_stage(ce) ? tag_unmerged :
+                       show_ce_entry(istate, ce_stage(ce) ? tag_unmerged :
                                (ce_skip_worktree(ce) ? tag_skip_worktree : tag_cached), ce);
                }
        }
        if (show_deleted || show_modified) {
-               for (i = 0; i < active_nr; i++) {
-                       const struct cache_entry *ce = active_cache[i];
+               for (i = 0; i < istate->cache_nr; i++) {
+                       const struct cache_entry *ce = istate->cache[i];
                        struct stat st;
                        int err;
                        if ((dir->flags & DIR_SHOW_IGNORED) &&
-                           !ce_excluded(dir, ce))
+                           !ce_excluded(dir, istate, ce))
                                continue;
                        if (ce->ce_flags & CE_UPDATE)
                                continue;
@@ -367,9 +386,9 @@ static void show_files(struct dir_struct *dir)
                                continue;
                        err = lstat(ce->name, &st);
                        if (show_deleted && err)
-                               show_ce_entry(tag_removed, ce);
-                       if (show_modified && ce_modified(ce, &st, 0))
-                               show_ce_entry(tag_modified, ce);
+                               show_ce_entry(istate, tag_removed, ce);
+                       if (show_modified && ie_modified(istate, ce, &st, 0))
+                               show_ce_entry(istate, tag_modified, ce);
                }
        }
 }
@@ -377,30 +396,31 @@ static void show_files(struct dir_struct *dir)
 /*
  * Prune the index to only contain stuff starting with "prefix"
  */
-static void prune_cache(const char *prefix, size_t prefixlen)
+static void prune_index(struct index_state *istate,
+                       const char *prefix, size_t prefixlen)
 {
        int pos;
        unsigned int first, last;
 
        if (!prefix)
                return;
-       pos = cache_name_pos(prefix, prefixlen);
+       pos = index_name_pos(istate, prefix, prefixlen);
        if (pos < 0)
                pos = -pos-1;
        first = pos;
-       last = active_nr;
+       last = istate->cache_nr;
        while (last > first) {
                int next = (last + first) >> 1;
-               const struct cache_entry *ce = active_cache[next];
+               const struct cache_entry *ce = istate->cache[next];
                if (!strncmp(ce->name, prefix, prefixlen)) {
                        first = next+1;
                        continue;
                }
                last = next;
        }
-       memmove(active_cache, active_cache + pos,
+       memmove(istate->cache, istate->cache + pos,
                (last - pos) * sizeof(struct cache_entry *));
-       active_nr = last - pos;
+       istate->cache_nr = last - pos;
 }
 
 static int get_common_prefix_len(const char *common_prefix)
@@ -430,7 +450,8 @@ static int get_common_prefix_len(const char *common_prefix)
  * that were given from the command line.  We are not
  * going to write this index out.
  */
-void overlay_tree_on_cache(const char *tree_name, const char *prefix)
+void overlay_tree_on_index(struct index_state *istate,
+                          const char *tree_name, const char *prefix)
 {
        struct tree *tree;
        struct object_id oid;
@@ -445,8 +466,8 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
                die("bad tree-ish %s", tree_name);
 
        /* Hoist the unmerged entries up to stage #3 to make room */
-       for (i = 0; i < active_nr; i++) {
-               struct cache_entry *ce = active_cache[i];
+       for (i = 0; i < istate->cache_nr; i++) {
+               struct cache_entry *ce = istate->cache[i];
                if (!ce_stage(ce))
                        continue;
                ce->ce_flags |= CE_STAGEMASK;
@@ -459,11 +480,11 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
                               PATHSPEC_PREFER_CWD, prefix, matchbuf);
        } else
                memset(&pathspec, 0, sizeof(pathspec));
-       if (read_tree(tree, 1, &pathspec))
+       if (read_tree(tree, 1, &pathspec, istate))
                die("unable to read tree entries %s", tree_name);
 
-       for (i = 0; i < active_nr; i++) {
-               struct cache_entry *ce = active_cache[i];
+       for (i = 0; i < istate->cache_nr; i++) {
+               struct cache_entry *ce = istate->cache[i];
                switch (ce_stage(ce)) {
                case 0:
                        last_stage0 = ce;
@@ -657,7 +678,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
                max_prefix = common_prefix(&pathspec);
        max_prefix_len = get_common_prefix_len(max_prefix);
 
-       prune_cache(max_prefix, max_prefix_len);
+       prune_index(&the_index, max_prefix, max_prefix_len);
 
        /* Treat unmatching pathspec elements as errors */
        if (pathspec.nr && error_unmatch)
@@ -678,11 +699,11 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
                 */
                if (show_stage || show_unmerged)
                        die("ls-files --with-tree is incompatible with -s or -u");
-               overlay_tree_on_cache(with_tree, max_prefix);
+               overlay_tree_on_index(&the_index, with_tree, max_prefix);
        }
-       show_files(&dir);
+       show_files(&the_index, &dir);
        if (show_resolve_undo)
-               show_ru_info();
+               show_ru_info(&the_index);
 
        if (ps_matched) {
                int bad;
index ee7b293b11eb5c73dd6fe1ea31c5d3bf52c79656..ef965408e8fc5d80fa9e9daf0264a91abccd978c 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "blob.h"
 #include "tree.h"
 #include "commit.h"
index 0c36a70ad8f4dba1744ba6c4fa93389e2b796925..6dbd167d3b0874cd966b4590951a12d01f8f6aeb 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "diff.h"
index 47dde7c39c922c77bf388e87db27618d09f5bb74..b08803e61119a569e2ca5a33402666d8978d9ff0 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "xdiff/xdiff.h"
 #include "xdiff-interface.h"
 #include "parse-options.h"
index 84970cd85e8b0788928ff24b47c8c1b3dc3409e2..900bafdb45d0b28ab5497cfd251535266fc92be5 100644 (file)
@@ -7,6 +7,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "parse-options.h"
 #include "builtin.h"
 #include "lockfile.h"
index 61d20037add7cf56df721f8d69612b50412f94e9..dcf6736b5b4c53989ee1fb3c5240e04f5dbb337d 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) 2006 Johannes Schindelin
  */
 #include "builtin.h"
+#include "config.h"
 #include "pathspec.h"
 #include "lockfile.h"
 #include "dir.h"
index 7fc7e66e8500b82cbfecc21a1dce77e09de28ab0..e21715f1d0874171bcda2486adb4d27ea5cbbc99 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "tag.h"
 #include "refs.h"
index c939a84b7629cd5d4dda09d427255410d723d95b..77573cf1ea8cb4d998597e265263487e22fde592 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "notes.h"
 #include "blob.h"
index f672225def033595602bc4ff91ee26edd9804944..d5e96ed2d0ce0d74a40961f6729896722dacf9a2 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "attr.h"
 #include "object.h"
 #include "blob.h"
index 81552e02e412b53fcb50ffa6a4d5949acdaac79c..970d0d30b4f4107e667f3a75d172cc2d25b04b8f 100644 (file)
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 
 static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result)
 {
index 69417e4f362f6d7baa11885bd1cb8c5cbb676b14..2ce311a52eb6111fd16951c860d194dc35300438 100644 (file)
@@ -6,6 +6,7 @@
  * Fetch one or more remote refs and merge it/them into the current HEAD.
  */
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "parse-options.h"
 #include "exec_cmd.h"
index 258648d5fd685f4284b3a2bbc0def0076a670b28..03846e83795c477c8e802d078c5a5ed77140d550 100644 (file)
@@ -2,6 +2,7 @@
  * "git push"
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "run-command.h"
 #include "builtin.h"
index 5bfd4c9f76d84c177b72a8ed97d3418d111583e9..d5f618d086365520fcf36ed8db110ba701ba37d3 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "object.h"
 #include "tree.h"
index ca1ebb2fa18a221446e5f8458e1f30528c31ed98..c82b4dce6838fa039e9c2cfc769c7cd17a8ef562 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "parse-options.h"
 #include "sequencer.h"
 
index b1706a5731c0e527a8abc1d42ac4f0e6d346c47c..71c0c768db92378b824951acd6efb7179438017b 100644 (file)
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "pack.h"
 #include "refs.h"
index 920c16dac025b0f5650b0f91511c22359d5bda2d..44cdc2dbd0cbf64be1672428e930223425ed7b04 100644 (file)
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "commit.h"
 #include "refs.h"
index f1a88fe2658986af2e33d3979af1764f6decc43b..6273c0c23c904d5f789ff794458cf0c3f2661d94 100644 (file)
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "parse-options.h"
 #include "transport.h"
 #include "remote.h"
index 38ba4ef825ebf4791afb50e72e69bdb61db2aa14..f17a68a17da960813e6e925837638a5d9a26d5ee 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "parse-options.h"
 #include "run-command.h"
index c921bc976f2299adc39277a21a74abbcc0c100f7..80a15cf35f3fa5a1a7c038924a84e34fdc15aa0b 100644 (file)
@@ -9,6 +9,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "refs.h"
 #include "parse-options.h"
index 1bf72423bf72d7b7d224c14808b0652d78305d63..ffb66e29073c07c43197ae34f2c31d3b9b610903 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "parse-options.h"
 #include "string-list.h"
index 45001e5200cb4c5aaf0ad316cf1622f9495d851d..7aeaea2737991f021eb788708c1710305abb4b08 100644 (file)
@@ -8,6 +8,7 @@
  * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
  */
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "tag.h"
 #include "object.h"
index b250c515b1aecab2b43aebe591ad7a22d5829271..95d84d5cda1bdb6a699bc74ad57f7f1910946440 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
index efdc14473be53ff79b13012d650ec5fded052fd9..c78b7b33d6604bb38a16e30d64cfabee0fd67f40 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "quote.h"
index 345d9586a709c08a1095f2635833d075c45fe7be..16028b9ea82edee9cf41044c69a47e8994d78fc6 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "parse-options.h"
 #include "diff.h"
index b39f10fcb64f047090967dbf8b31120d2beb1b67..52826d137935ca6698006258ebdb8b207f7161df 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds 2006
  */
 #include "builtin.h"
+#include "config.h"
 #include "lockfile.h"
 #include "dir.h"
 #include "cache-tree.h"
index b8e2e74fe0c5cdefa6ed4d6c309a8bba203cc6e8..633e0c3cdd3171e6e51944c5b68e4a4afa48862e 100644 (file)
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "pkt-line.h"
index 7cff1839fc15f46d58c9f78361f362d1d790cbd9..43c4799ea9a9d963f9a44be5cd0ee5bc511e73df 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "diff.h"
 #include "string-list.h"
index 4a6cc6f490f4e7b8a98adb362213535b6a9ae97d..e4cf1b5bb25e14b54e29d0b467e94a374ec9c9d5 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "builtin.h"
index 1e62a008cbc57691c6a0055f0286a2c11d1e3122..bdf032886912bb768cf3528efbffab4fe3029a58 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "parse-options.h"
 #include "strbuf.h"
 
index 1b4d2b346762af8e6150d88fed87409e877ca676..8517032b3e08ded36075ded55dac8ae219cfbc59 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "parse-options.h"
 #include "quote.h"
 #include "pathspec.h"
index 70addef158b347488366f6c5787d326c3657adcd..df75cb9d4a21a76df3451f925d674b475dc26753 100644 (file)
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "cache.h"
 #include "refs.h"
 #include "parse-options.h"
index 1f74a56db749a5e1ffa06715e347cdc1b041033b..01154ea8dcca869ed635eb433d5afe879b8e883c 100644 (file)
@@ -7,6 +7,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "refs.h"
 #include "tag.h"
index 6fc6bcdf7f014a52703fcd44677a705c824bc0b0..73f133419167840d150300faa696bc32027cd02f 100644 (file)
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 
 static char *create_temp_file(unsigned char *sha1)
 {
index 8bc9997767adbb77cc8af81b2b289e22f2b61c5a..193f8b9d57f0759c38004fd1d99f660919ac30e3 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "object.h"
 #include "delta.h"
 #include "pack.h"
index f99b1e5790b9b6aeafaa88f438a8a50f1538c2fe..56721cf03db23a2f5a1b8e9419422df916d7b00f 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "quote.h"
 #include "cache-tree.h"
index 0b2ecf41aeda427e75eb7fe36388e7d0d91d5413..40ccfc193bf785cfae0f83526c561eedf0d310bc 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "builtin.h"
 #include "parse-options.h"
index 6c8cc3edc1f5fec4e2aa173f2650a69db5e065f0..873070e517090cbb21bf53cbc03088da6f85ec1f 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "parse-options.h"
 
index aedbb53a2da5e02b2c8fc29a1a4dc22dc76fbefb..6c6f46b4aeaf658f4de9dc02895a2b19a5c7c5a8 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) Eric Biederman, 2005
  */
 #include "builtin.h"
+#include "config.h"
 
 static const char var_usage[] = "git var (-l | <variable>)";
 
index 05b734e6d1bd469b63aa7b51921622a590730b6d..ba38ac9b1518884693e2c89ec19cc9e00fce9fa3 100644 (file)
@@ -6,6 +6,7 @@
  * Based on git-verify-tag
  */
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "commit.h"
 #include "run-command.h"
index c94e156932c0c8e0ba0c2dc302043c0f3ec0336d..c2a1a5c5048412abaa545862dbd0f3dd93338dc5 100644 (file)
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "parse-options.h"
 
index 5199553d914f266315ffc3f170ef95a2a7f621ff..f9a5f7535aad9c24041e0677dfa4ed4af87cabf0 100644 (file)
@@ -6,6 +6,7 @@
  * Based on git-verify-tag.sh
  */
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "tag.h"
 #include "run-command.h"
index 793306ea5162f1c3e9663c0c99d693b88baaea3d..0c5476ee9de464cb0fae22c49775bc10efb0731b 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "dir.h"
 #include "parse-options.h"
index 084c0df7833f29c7554a4ffe95dac4bda1c6ce66..bd0a78aa3c56b7e817c7ddf6fcaba703d6d5fecc 100644 (file)
@@ -5,6 +5,7 @@
  */
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "tree.h"
 #include "cache-tree.h"
 #include "parse-options.h"
diff --git a/cache.h b/cache.h
index d6ba8a2f11a63d4d9ec5257a75532414d22526c0..96055c222929e4ba307f3162b58740eccf165f2c 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -525,12 +525,15 @@ extern void set_git_work_tree(const char *tree);
 
 extern void setup_work_tree(void);
 /*
- * Find GIT_DIR of the repository that contains the current working directory,
- * without changing the working directory or other global state. The result is
- * appended to gitdir. The return value is either NULL if no repository was
- * found, or pointing to the path inside gitdir's buffer.
- */
-extern const char *discover_git_directory(struct strbuf *gitdir);
+ * Find the commondir and gitdir of the repository that contains the current
+ * working directory, without changing the working directory or other global
+ * state. The result is appended to commondir and gitdir.  If the discovered
+ * gitdir does not correspond to a worktree, then 'commondir' and 'gitdir' will
+ * both have the same result appended to the buffer.  The return value is
+ * either 0 upon success and non-zero if no repository was found.
+ */
+extern int discover_git_directory(struct strbuf *commondir,
+                                 struct strbuf *gitdir);
 extern const char *setup_git_directory_gently(int *);
 extern const char *setup_git_directory(void);
 extern char *prefix_path(const char *prefix, int len, const char *path);
@@ -1879,188 +1882,9 @@ extern int packed_object_info(struct packed_git *pack, off_t offset, struct obje
 /* Dumb servers support */
 extern int update_server_info(int);
 
-/* git_config_parse_key() returns these negated: */
-#define CONFIG_INVALID_KEY 1
-#define CONFIG_NO_SECTION_OR_NAME 2
-/* git_config_set_gently(), git_config_set_multivar_gently() return the above or these: */
-#define CONFIG_NO_LOCK -1
-#define CONFIG_INVALID_FILE 3
-#define CONFIG_NO_WRITE 4
-#define CONFIG_NOTHING_SET 5
-#define CONFIG_INVALID_PATTERN 6
-#define CONFIG_GENERIC_ERROR 7
-
-#define CONFIG_REGEX_NONE ((void *)1)
-
-struct git_config_source {
-       unsigned int use_stdin:1;
-       const char *file;
-       const char *blob;
-};
-
-enum config_origin_type {
-       CONFIG_ORIGIN_BLOB,
-       CONFIG_ORIGIN_FILE,
-       CONFIG_ORIGIN_STDIN,
-       CONFIG_ORIGIN_SUBMODULE_BLOB,
-       CONFIG_ORIGIN_CMDLINE
-};
-
-struct config_options {
-       unsigned int respect_includes : 1;
-       const char *git_dir;
-};
-
-typedef int (*config_fn_t)(const char *, const char *, void *);
-extern int git_default_config(const char *, const char *, void *);
-extern int git_config_from_file(config_fn_t fn, const char *, void *);
-extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
-                                       const char *name, const char *buf, size_t len, void *data);
-extern int git_config_from_blob_sha1(config_fn_t fn, const char *name,
-                                    const unsigned char *sha1, void *data);
-extern void git_config_push_parameter(const char *text);
-extern int git_config_from_parameters(config_fn_t fn, void *data);
-extern void read_early_config(config_fn_t cb, void *data);
-extern void git_config(config_fn_t fn, void *);
-extern int git_config_with_options(config_fn_t fn, void *,
-                                  struct git_config_source *config_source,
-                                  const struct config_options *opts);
-extern int git_parse_ulong(const char *, unsigned long *);
-extern int git_parse_maybe_bool(const char *);
-extern int git_config_int(const char *, const char *);
-extern int64_t git_config_int64(const char *, const char *);
-extern unsigned long git_config_ulong(const char *, const char *);
-extern ssize_t git_config_ssize_t(const char *, const char *);
-extern int git_config_bool_or_int(const char *, const char *, int *);
-extern int git_config_bool(const char *, const char *);
-extern int git_config_maybe_bool(const char *, const char *);
-extern int git_config_string(const char **, const char *, const char *);
-extern int git_config_pathname(const char **, const char *, const char *);
-extern int git_config_set_in_file_gently(const char *, const char *, const char *);
-extern void git_config_set_in_file(const char *, const char *, const char *);
-extern int git_config_set_gently(const char *, const char *);
-extern void git_config_set(const char *, const char *);
-extern int git_config_parse_key(const char *, char **, int *);
-extern int git_config_key_is_valid(const char *key);
-extern int git_config_set_multivar_gently(const char *, const char *, const char *, int);
-extern void git_config_set_multivar(const char *, const char *, const char *, int);
-extern int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int);
-extern void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int);
-extern int git_config_rename_section(const char *, const char *);
-extern int git_config_rename_section_in_file(const char *, const char *, const char *);
-extern const char *git_etc_gitconfig(void);
-extern int git_env_bool(const char *, int);
-extern unsigned long git_env_ulong(const char *, unsigned long);
-extern int git_config_system(void);
-extern int config_error_nonbool(const char *);
-#if defined(__GNUC__)
-#define config_error_nonbool(s) (config_error_nonbool(s), const_error())
-#endif
 extern const char *get_log_output_encoding(void);
 extern const char *get_commit_output_encoding(void);
 
-extern int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
-
-enum config_scope {
-       CONFIG_SCOPE_UNKNOWN = 0,
-       CONFIG_SCOPE_SYSTEM,
-       CONFIG_SCOPE_GLOBAL,
-       CONFIG_SCOPE_REPO,
-       CONFIG_SCOPE_CMDLINE,
-};
-
-extern enum config_scope current_config_scope(void);
-extern const char *current_config_origin_type(void);
-extern const char *current_config_name(void);
-
-struct config_include_data {
-       int depth;
-       config_fn_t fn;
-       void *data;
-       const struct config_options *opts;
-};
-#define CONFIG_INCLUDE_INIT { 0 }
-extern int git_config_include(const char *name, const char *value, void *data);
-
-/*
- * Match and parse a config key of the form:
- *
- *   section.(subsection.)?key
- *
- * (i.e., what gets handed to a config_fn_t). The caller provides the section;
- * we return -1 if it does not match, 0 otherwise. The subsection and key
- * out-parameters are filled by the function (and *subsection is NULL if it is
- * missing).
- *
- * If the subsection pointer-to-pointer passed in is NULL, returns 0 only if
- * there is no subsection at all.
- */
-extern int parse_config_key(const char *var,
-                           const char *section,
-                           const char **subsection, int *subsection_len,
-                           const char **key);
-
-struct config_set_element {
-       struct hashmap_entry ent;
-       char *key;
-       struct string_list value_list;
-};
-
-struct configset_list_item {
-       struct config_set_element *e;
-       int value_index;
-};
-
-/*
- * the contents of the list are ordered according to their
- * position in the config files and order of parsing the files.
- * (i.e. key-value pair at the last position of .git/config will
- * be at the last item of the list)
- */
-struct configset_list {
-       struct configset_list_item *items;
-       unsigned int nr, alloc;
-};
-
-struct config_set {
-       struct hashmap config_hash;
-       int hash_initialized;
-       struct configset_list list;
-};
-
-extern void git_configset_init(struct config_set *cs);
-extern int git_configset_add_file(struct config_set *cs, const char *filename);
-extern int git_configset_get_value(struct config_set *cs, const char *key, const char **value);
-extern const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key);
-extern void git_configset_clear(struct config_set *cs);
-extern int git_configset_get_string_const(struct config_set *cs, const char *key, const char **dest);
-extern int git_configset_get_string(struct config_set *cs, const char *key, char **dest);
-extern int git_configset_get_int(struct config_set *cs, const char *key, int *dest);
-extern int git_configset_get_ulong(struct config_set *cs, const char *key, unsigned long *dest);
-extern int git_configset_get_bool(struct config_set *cs, const char *key, int *dest);
-extern int git_configset_get_bool_or_int(struct config_set *cs, const char *key, int *is_bool, int *dest);
-extern int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *dest);
-extern int git_configset_get_pathname(struct config_set *cs, const char *key, const char **dest);
-
-extern int git_config_get_value(const char *key, const char **value);
-extern const struct string_list *git_config_get_value_multi(const char *key);
-extern void git_config_clear(void);
-extern void git_config_iter(config_fn_t fn, void *data);
-extern int git_config_get_string_const(const char *key, const char **dest);
-extern int git_config_get_string(const char *key, char **dest);
-extern int git_config_get_int(const char *key, int *dest);
-extern int git_config_get_ulong(const char *key, unsigned long *dest);
-extern int git_config_get_bool(const char *key, int *dest);
-extern int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest);
-extern int git_config_get_maybe_bool(const char *key, int *dest);
-extern int git_config_get_pathname(const char *key, const char **dest);
-extern int git_config_get_untracked_cache(void);
-extern int git_config_get_split_index(void);
-extern int git_config_get_max_percent_split_change(void);
-
-/* This dies if the configured or default date is in the future */
-extern int git_config_get_expiry(const char *key, const char **output);
-
 /*
  * This is a hack for test programs like test-dump-untracked-cache to
  * ensure that they do not modify the untracked cache when reading it.
@@ -2068,16 +1892,6 @@ extern int git_config_get_expiry(const char *key, const char **output);
  */
 extern int ignore_untracked_cache_config;
 
-struct key_value_info {
-       const char *filename;
-       int linenr;
-       enum config_origin_type origin_type;
-       enum config_scope scope;
-};
-
-extern NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3)));
-extern NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr);
-
 extern int committer_ident_sufficiently_given(void);
 extern int author_ident_sufficiently_given(void);
 
@@ -2193,7 +2007,8 @@ extern int ws_blank_line(const char *line, int len, unsigned ws_rule);
 #define ws_tab_width(rule)     ((rule) & WS_TAB_WIDTH_MASK)
 
 /* ls-files */
-void overlay_tree_on_cache(const char *tree_name, const char *prefix);
+void overlay_tree_on_index(struct index_state *istate,
+                          const char *tree_name, const char *prefix);
 
 char *alias_lookup(const char *alias);
 int split_cmdline(char *cmdline, const char ***argv);
diff --git a/color.c b/color.c
index dee61557e03f452f1e20ce6c8c467203aa8aed60..31b6207a00de42a386e98c5656209ea7a010abe4 100644 (file)
--- a/color.c
+++ b/color.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "color.h"
 
 static int git_use_color_default = GIT_COLOR_AUTO;
index d55ead18efeba9435bd2f2e76e2d7ac9ddc064c1..ff7bdab1a32478c8719ee3b973742456df7dc629 100644 (file)
--- a/column.c
+++ b/column.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "column.h"
 #include "string-list.h"
 #include "parse-options.h"
index ec9d930440993b265fe74aacd2a3fdb768dccf64..9e163d5adabd93fd48a6b563c5f31c32740e01c7 100644 (file)
@@ -1053,7 +1053,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
                        if (is_file) {
                                struct strbuf buf = STRBUF_INIT;
 
-                               if (convert_to_git(elem->path, result, len, &buf, safe_crlf)) {
+                               if (convert_to_git(&the_index, elem->path, result, len, &buf, safe_crlf)) {
                                        free(result);
                                        result = strbuf_detach(&buf, &len);
                                        result_size = len;
index 4293b53b171f5002127d7a354309d343706c0272..de61c15d3483fc4a9e8e163bd7cfa5280996c61a 100644 (file)
@@ -6,6 +6,7 @@
 #define PRECOMPOSE_UNICODE_C
 
 #include "cache.h"
+#include "config.h"
 #include "utf8.h"
 #include "precompose_utf8.h"
 
index 34a139c40bd57ff2dd23318beca53fd2e2948000..6f0f8b30f39ba3a32d1a1795bdf12d78c5ea97f9 100644 (file)
--- a/config.c
+++ b/config.c
@@ -6,6 +6,7 @@
  *
  */
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "exec_cmd.h"
 #include "strbuf.h"
@@ -218,8 +219,6 @@ static int include_by_gitdir(const struct config_options *opts,
 
        if (opts->git_dir)
                git_dir = opts->git_dir;
-       else if (have_git_dir())
-               git_dir = get_git_dir();
        else
                goto done;
 
@@ -604,7 +603,8 @@ static int get_value(config_fn_t fn, void *data, struct strbuf *name)
         */
        cf->linenr--;
        ret = fn(name->buf, value, data);
-       cf->linenr++;
+       if (ret >= 0)
+               cf->linenr++;
        return ret;
 }
 
@@ -1545,10 +1545,8 @@ static int do_git_config_sequence(const struct config_options *opts,
        char *user_config = expand_user_path("~/.gitconfig", 0);
        char *repo_config;
 
-       if (opts->git_dir)
-               repo_config = mkpathdup("%s/config", opts->git_dir);
-       else if (have_git_dir())
-               repo_config = git_pathdup("config");
+       if (opts->commondir)
+               repo_config = mkpathdup("%s/config", opts->commondir);
        else
                repo_config = NULL;
 
@@ -1579,9 +1577,9 @@ static int do_git_config_sequence(const struct config_options *opts,
        return ret;
 }
 
-int git_config_with_options(config_fn_t fn, void *data,
-                           struct git_config_source *config_source,
-                           const struct config_options *opts)
+int config_with_options(config_fn_t fn, void *data,
+                       struct git_config_source *config_source,
+                       const struct config_options *opts)
 {
        struct config_include_data inc = CONFIG_INCLUDE_INIT;
 
@@ -1612,9 +1610,14 @@ static void git_config_raw(config_fn_t fn, void *data)
        struct config_options opts = {0};
 
        opts.respect_includes = 1;
-       if (git_config_with_options(fn, data, NULL, &opts) < 0)
+       if (have_git_dir()) {
+               opts.commondir = get_git_common_dir();
+               opts.git_dir = get_git_dir();
+       }
+
+       if (config_with_options(fn, data, NULL, &opts) < 0)
                /*
-                * git_config_with_options() normally returns only
+                * config_with_options() normally returns only
                 * zero, as most errors are fatal, and
                 * non-fatal potential errors are guarded by "if"
                 * statements that are entered only when no error is
@@ -1653,11 +1656,13 @@ static void configset_iter(struct config_set *cs, config_fn_t fn, void *data)
 void read_early_config(config_fn_t cb, void *data)
 {
        struct config_options opts = {0};
-       struct strbuf buf = STRBUF_INIT;
+       struct strbuf commondir = STRBUF_INIT;
+       struct strbuf gitdir = STRBUF_INIT;
 
        opts.respect_includes = 1;
 
-       if (have_git_dir())
+       if (have_git_dir()) {
+               opts.commondir = get_git_common_dir();
                opts.git_dir = get_git_dir();
        /*
         * When setup_git_directory() was not yet asked to discover the
@@ -1667,12 +1672,15 @@ void read_early_config(config_fn_t cb, void *data)
         * notably, the current working directory is still the same after the
         * call).
         */
-       else if (discover_git_directory(&buf))
-               opts.git_dir = buf.buf;
+       } else if (!discover_git_directory(&commondir, &gitdir)) {
+               opts.commondir = commondir.buf;
+               opts.git_dir = gitdir.buf;
+       }
 
-       git_config_with_options(cb, data, NULL, &opts);
+       config_with_options(cb, data, NULL, &opts);
 
-       strbuf_release(&buf);
+       strbuf_release(&commondir);
+       strbuf_release(&gitdir);
 }
 
 static void git_config_check_init(void);
diff --git a/config.h b/config.h
new file mode 100644 (file)
index 0000000..9e038cc
--- /dev/null
+++ b/config.h
@@ -0,0 +1,194 @@
+#ifndef CONFIG_H
+#define CONFIG_H
+
+/* git_config_parse_key() returns these negated: */
+#define CONFIG_INVALID_KEY 1
+#define CONFIG_NO_SECTION_OR_NAME 2
+/* git_config_set_gently(), git_config_set_multivar_gently() return the above or these: */
+#define CONFIG_NO_LOCK -1
+#define CONFIG_INVALID_FILE 3
+#define CONFIG_NO_WRITE 4
+#define CONFIG_NOTHING_SET 5
+#define CONFIG_INVALID_PATTERN 6
+#define CONFIG_GENERIC_ERROR 7
+
+#define CONFIG_REGEX_NONE ((void *)1)
+
+struct git_config_source {
+       unsigned int use_stdin:1;
+       const char *file;
+       const char *blob;
+};
+
+enum config_origin_type {
+       CONFIG_ORIGIN_BLOB,
+       CONFIG_ORIGIN_FILE,
+       CONFIG_ORIGIN_STDIN,
+       CONFIG_ORIGIN_SUBMODULE_BLOB,
+       CONFIG_ORIGIN_CMDLINE
+};
+
+struct config_options {
+       unsigned int respect_includes : 1;
+       const char *commondir;
+       const char *git_dir;
+};
+
+typedef int (*config_fn_t)(const char *, const char *, void *);
+extern int git_default_config(const char *, const char *, void *);
+extern int git_config_from_file(config_fn_t fn, const char *, void *);
+extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
+                                       const char *name, const char *buf, size_t len, void *data);
+extern int git_config_from_blob_sha1(config_fn_t fn, const char *name,
+                                    const unsigned char *sha1, void *data);
+extern void git_config_push_parameter(const char *text);
+extern int git_config_from_parameters(config_fn_t fn, void *data);
+extern void read_early_config(config_fn_t cb, void *data);
+extern void git_config(config_fn_t fn, void *);
+extern int config_with_options(config_fn_t fn, void *,
+                              struct git_config_source *config_source,
+                              const struct config_options *opts);
+extern int git_parse_ulong(const char *, unsigned long *);
+extern int git_parse_maybe_bool(const char *);
+extern int git_config_int(const char *, const char *);
+extern int64_t git_config_int64(const char *, const char *);
+extern unsigned long git_config_ulong(const char *, const char *);
+extern ssize_t git_config_ssize_t(const char *, const char *);
+extern int git_config_bool_or_int(const char *, const char *, int *);
+extern int git_config_bool(const char *, const char *);
+extern int git_config_maybe_bool(const char *, const char *);
+extern int git_config_string(const char **, const char *, const char *);
+extern int git_config_pathname(const char **, const char *, const char *);
+extern int git_config_set_in_file_gently(const char *, const char *, const char *);
+extern void git_config_set_in_file(const char *, const char *, const char *);
+extern int git_config_set_gently(const char *, const char *);
+extern void git_config_set(const char *, const char *);
+extern int git_config_parse_key(const char *, char **, int *);
+extern int git_config_key_is_valid(const char *key);
+extern int git_config_set_multivar_gently(const char *, const char *, const char *, int);
+extern void git_config_set_multivar(const char *, const char *, const char *, int);
+extern int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int);
+extern void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int);
+extern int git_config_rename_section(const char *, const char *);
+extern int git_config_rename_section_in_file(const char *, const char *, const char *);
+extern const char *git_etc_gitconfig(void);
+extern int git_env_bool(const char *, int);
+extern unsigned long git_env_ulong(const char *, unsigned long);
+extern int git_config_system(void);
+extern int config_error_nonbool(const char *);
+#if defined(__GNUC__)
+#define config_error_nonbool(s) (config_error_nonbool(s), const_error())
+#endif
+
+extern int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
+
+enum config_scope {
+       CONFIG_SCOPE_UNKNOWN = 0,
+       CONFIG_SCOPE_SYSTEM,
+       CONFIG_SCOPE_GLOBAL,
+       CONFIG_SCOPE_REPO,
+       CONFIG_SCOPE_CMDLINE,
+};
+
+extern enum config_scope current_config_scope(void);
+extern const char *current_config_origin_type(void);
+extern const char *current_config_name(void);
+
+struct config_include_data {
+       int depth;
+       config_fn_t fn;
+       void *data;
+       const struct config_options *opts;
+};
+#define CONFIG_INCLUDE_INIT { 0 }
+extern int git_config_include(const char *name, const char *value, void *data);
+
+/*
+ * Match and parse a config key of the form:
+ *
+ *   section.(subsection.)?key
+ *
+ * (i.e., what gets handed to a config_fn_t). The caller provides the section;
+ * we return -1 if it does not match, 0 otherwise. The subsection and key
+ * out-parameters are filled by the function (and *subsection is NULL if it is
+ * missing).
+ *
+ * If the subsection pointer-to-pointer passed in is NULL, returns 0 only if
+ * there is no subsection at all.
+ */
+extern int parse_config_key(const char *var,
+                           const char *section,
+                           const char **subsection, int *subsection_len,
+                           const char **key);
+
+struct config_set_element {
+       struct hashmap_entry ent;
+       char *key;
+       struct string_list value_list;
+};
+
+struct configset_list_item {
+       struct config_set_element *e;
+       int value_index;
+};
+
+/*
+ * the contents of the list are ordered according to their
+ * position in the config files and order of parsing the files.
+ * (i.e. key-value pair at the last position of .git/config will
+ * be at the last item of the list)
+ */
+struct configset_list {
+       struct configset_list_item *items;
+       unsigned int nr, alloc;
+};
+
+struct config_set {
+       struct hashmap config_hash;
+       int hash_initialized;
+       struct configset_list list;
+};
+
+extern void git_configset_init(struct config_set *cs);
+extern int git_configset_add_file(struct config_set *cs, const char *filename);
+extern int git_configset_get_value(struct config_set *cs, const char *key, const char **value);
+extern const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key);
+extern void git_configset_clear(struct config_set *cs);
+extern int git_configset_get_string_const(struct config_set *cs, const char *key, const char **dest);
+extern int git_configset_get_string(struct config_set *cs, const char *key, char **dest);
+extern int git_configset_get_int(struct config_set *cs, const char *key, int *dest);
+extern int git_configset_get_ulong(struct config_set *cs, const char *key, unsigned long *dest);
+extern int git_configset_get_bool(struct config_set *cs, const char *key, int *dest);
+extern int git_configset_get_bool_or_int(struct config_set *cs, const char *key, int *is_bool, int *dest);
+extern int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *dest);
+extern int git_configset_get_pathname(struct config_set *cs, const char *key, const char **dest);
+
+extern int git_config_get_value(const char *key, const char **value);
+extern const struct string_list *git_config_get_value_multi(const char *key);
+extern void git_config_clear(void);
+extern int git_config_get_string_const(const char *key, const char **dest);
+extern int git_config_get_string(const char *key, char **dest);
+extern int git_config_get_int(const char *key, int *dest);
+extern int git_config_get_ulong(const char *key, unsigned long *dest);
+extern int git_config_get_bool(const char *key, int *dest);
+extern int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest);
+extern int git_config_get_maybe_bool(const char *key, int *dest);
+extern int git_config_get_pathname(const char *key, const char **dest);
+extern int git_config_get_untracked_cache(void);
+extern int git_config_get_split_index(void);
+extern int git_config_get_max_percent_split_change(void);
+
+/* This dies if the configured or default date is in the future */
+extern int git_config_get_expiry(const char *key, const char **output);
+
+struct key_value_info {
+       const char *filename;
+       int linenr;
+       enum config_origin_type origin_type;
+       enum config_scope scope;
+};
+
+extern NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3)));
+extern NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr);
+
+#endif /* CONFIG_H */
index c72b1d1151744c5e7c7b82f453892a1bc9b26021..e78d3f43d84b7f90f4395cb289c9cf0cb34e8297 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "cache.h"
+#include "config.h"
 #include "pkt-line.h"
 #include "quote.h"
 #include "refs.h"
index f1e168bc303c71542b692b2b9d08cdb2e2c98669..7d2a519dafe5dcf892df10c51e1bfb83bc8a2091 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -1,4 +1,6 @@
+#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "config.h"
 #include "attr.h"
 #include "run-command.h"
 #include "quote.h"
@@ -134,11 +136,12 @@ static const char *gather_convert_stats_ascii(const char *data, unsigned long si
        }
 }
 
-const char *get_cached_convert_stats_ascii(const char *path)
+const char *get_cached_convert_stats_ascii(const struct index_state *istate,
+                                          const char *path)
 {
        const char *ret;
        unsigned long sz;
-       void *data = read_blob_data_from_cache(path, &sz);
+       void *data = read_blob_data_from_index(istate, path, &sz);
        ret = gather_convert_stats_ascii(data, sz);
        free(data);
        return ret;
@@ -217,13 +220,13 @@ static void check_safe_crlf(const char *path, enum crlf_action crlf_action,
        }
 }
 
-static int has_cr_in_index(const char *path)
+static int has_cr_in_index(const struct index_state *istate, const char *path)
 {
        unsigned long sz;
        void *data;
        int has_cr;
 
-       data = read_blob_data_from_cache(path, &sz);
+       data = read_blob_data_from_index(istate, path, &sz);
        if (!data)
                return 0;
        has_cr = memchr(data, '\r', sz) != NULL;
@@ -253,7 +256,8 @@ static int will_convert_lf_to_crlf(size_t len, struct text_stat *stats,
 
 }
 
-static int crlf_to_git(const char *path, const char *src, size_t len,
+static int crlf_to_git(const struct index_state *istate,
+                      const char *path, const char *src, size_t len,
                       struct strbuf *buf,
                       enum crlf_action crlf_action, enum safe_crlf checksafe)
 {
@@ -285,7 +289,8 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
                 * unless we want to renormalize in a merge or
                 * cherry-pick.
                 */
-               if ((checksafe != SAFE_CRLF_RENORMALIZE) && has_cr_in_index(path))
+               if ((checksafe != SAFE_CRLF_RENORMALIZE) &&
+                   has_cr_in_index(istate, path))
                        convert_crlf_into_lf = 0;
        }
        if ((checksafe == SAFE_CRLF_WARN ||
@@ -1081,7 +1086,8 @@ const char *get_convert_attr_ascii(const char *path)
        return "";
 }
 
-int convert_to_git(const char *path, const char *src, size_t len,
+int convert_to_git(const struct index_state *istate,
+                  const char *path, const char *src, size_t len,
                    struct strbuf *dst, enum safe_crlf checksafe)
 {
        int ret = 0;
@@ -1097,7 +1103,7 @@ int convert_to_git(const char *path, const char *src, size_t len,
                src = dst->buf;
                len = dst->len;
        }
-       ret |= crlf_to_git(path, src, len, dst, ca.crlf_action, checksafe);
+       ret |= crlf_to_git(istate, path, src, len, dst, ca.crlf_action, checksafe);
        if (ret && dst) {
                src = dst->buf;
                len = dst->len;
@@ -1105,7 +1111,8 @@ int convert_to_git(const char *path, const char *src, size_t len,
        return ret | ident_to_git(path, src, len, dst, ca.ident);
 }
 
-void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst,
+void convert_to_git_filter_fd(const struct index_state *istate,
+                             const char *path, int fd, struct strbuf *dst,
                              enum safe_crlf checksafe)
 {
        struct conv_attrs ca;
@@ -1117,7 +1124,7 @@ void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst,
        if (!apply_filter(path, NULL, 0, fd, dst, ca.drv, CAP_CLEAN))
                die("%s: clean filter '%s' failed", path, ca.drv->name);
 
-       crlf_to_git(path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);
+       crlf_to_git(istate, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);
        ident_to_git(path, dst->buf, dst->len, dst, ca.ident);
 }
 
@@ -1160,14 +1167,15 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, struc
        return convert_to_working_tree_internal(path, src, len, dst, 0);
 }
 
-int renormalize_buffer(const char *path, const char *src, size_t len, struct strbuf *dst)
+int renormalize_buffer(const struct index_state *istate, const char *path,
+                      const char *src, size_t len, struct strbuf *dst)
 {
        int ret = convert_to_working_tree_internal(path, src, len, dst, 1);
        if (ret) {
                src = dst->buf;
                len = dst->len;
        }
-       return ret | convert_to_git(path, src, len, dst, SAFE_CRLF_RENORMALIZE);
+       return ret | convert_to_git(istate, path, src, len, dst, SAFE_CRLF_RENORMALIZE);
 }
 
 /*****************************************************************
index 82871a11d5fb45133096b26ad46c6c0f65797926..cecf59d1aa15f234473dc16520c0a6647e255280 100644 (file)
--- a/convert.h
+++ b/convert.h
@@ -4,6 +4,8 @@
 #ifndef CONVERT_H
 #define CONVERT_H
 
+struct index_state;
+
 enum safe_crlf {
        SAFE_CRLF_FALSE = 0,
        SAFE_CRLF_FAIL = 1,
@@ -33,23 +35,28 @@ enum eol {
 };
 
 extern enum eol core_eol;
-extern const char *get_cached_convert_stats_ascii(const char *path);
+extern const char *get_cached_convert_stats_ascii(const struct index_state *istate,
+                                                 const char *path);
 extern const char *get_wt_convert_stats_ascii(const char *path);
 extern const char *get_convert_attr_ascii(const char *path);
 
 /* returns 1 if *dst was used */
-extern int convert_to_git(const char *path, const char *src, size_t len,
+extern int convert_to_git(const struct index_state *istate,
+                         const char *path, const char *src, size_t len,
                          struct strbuf *dst, enum safe_crlf checksafe);
 extern int convert_to_working_tree(const char *path, const char *src,
                                   size_t len, struct strbuf *dst);
-extern int renormalize_buffer(const char *path, const char *src, size_t len,
+extern int renormalize_buffer(const struct index_state *istate,
+                             const char *path, const char *src, size_t len,
                              struct strbuf *dst);
-static inline int would_convert_to_git(const char *path)
+static inline int would_convert_to_git(const struct index_state *istate,
+                                      const char *path)
 {
-       return convert_to_git(path, NULL, 0, NULL, 0);
+       return convert_to_git(istate, path, NULL, 0, NULL, 0);
 }
 /* Precondition: would_convert_to_git_filter_fd(path) == true */
-extern void convert_to_git_filter_fd(const char *path, int fd,
+extern void convert_to_git_filter_fd(const struct index_state *istate,
+                                    const char *path, int fd,
                                     struct strbuf *dst,
                                     enum safe_crlf checksafe);
 extern int would_convert_to_git_filter_fd(const char *path);
index f3814cc47a059227e24ca52007c7e19fdf2db480..0d5c6250940633e75e2c9fb4b59b242a52188411 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "tempfile.h"
 #include "credential.h"
 #include "unix-socket.h"
index aa996669fc40021e0c8cb01fa8021da7064e2781..67a523353b105764783b683a23b51d7d6a3bfda3 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "credential.h"
 #include "string-list.h"
 #include "run-command.h"
index ac7181a4832672ef1e599324a15868d1b06f8fc0..30747075f0c45942220f63202f8c984e3e0956a7 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "pkt-line.h"
 #include "run-command.h"
 #include "strbuf.h"
diff --git a/diff.c b/diff.c
index acedf86aecc151112898ff54575151f157776281..41295d4ea9ff5564fa73d45aaa3afaab20103d87 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -2,6 +2,7 @@
  * Copyright (C) 2005 Junio C Hamano
  */
 #include "cache.h"
+#include "config.h"
 #include "tempfile.h"
 #include "quote.h"
 #include "diff.h"
@@ -2755,7 +2756,7 @@ static int reuse_worktree_file(const char *name, const struct object_id *oid, in
         * Similarly, if we'd have to convert the file contents anyway, that
         * makes the optimization not worthwhile.
         */
-       if (!want_file && would_convert_to_git(name))
+       if (!want_file && would_convert_to_git(&the_index, name))
                return 0;
 
        len = strlen(name);
@@ -2877,7 +2878,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
                 * point if the path requires us to run the content
                 * conversion.
                 */
-               if (size_only && !would_convert_to_git(s->path))
+               if (size_only && !would_convert_to_git(&the_index, s->path))
                        return 0;
 
                /*
@@ -2904,7 +2905,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
                /*
                 * Convert from working tree format to canonical git format
                 */
-               if (convert_to_git(s->path, s->data, s->size, &buf, crlf_warn)) {
+               if (convert_to_git(&the_index, s->path, s->data, s->size, &buf, crlf_warn)) {
                        size_t size = 0;
                        munmap(s->data, s->size);
                        s->should_munmap = 0;
diff --git a/dir.c b/dir.c
index 17590638176f26e35f3a728e5cd56917e0568541..34445374ba60b5a2e8d1c2b6e96ba7dbdb18eb4c 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -9,6 +9,7 @@
  */
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "attr.h"
 #include "refs.h"
@@ -795,7 +796,7 @@ static int add_excludes(const char *fname, const char *base, int baselen,
                                 (pos = index_name_pos(istate, fname, strlen(fname))) >= 0 &&
                                 !ce_stage(istate->cache[pos]) &&
                                 ce_uptodate(istate->cache[pos]) &&
-                                !would_convert_to_git(fname))
+                                !would_convert_to_git(istate, fname))
                                hashcpy(sha1_stat->sha1,
                                        istate->cache[pos]->oid.hash);
                        else
index aa478e71de9d9c233593de050d6823e96be77b88..d40b21fb72168f32f1aaeac553347859e32f90c0 100644 (file)
@@ -8,6 +8,7 @@
  * are.
  */
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "fmt-merge-msg.h"
 #include "commit.h"
index 9a22fc92c0d029cf2a1362ea846f75f59978e870..94a1b06149479a11f3aa222cc7b0dba4cb94b1f0 100644 (file)
@@ -154,6 +154,7 @@ Format of STDIN stream:
 
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "object.h"
 #include "blob.h"
index cd86865beba62ffade9f8aa63427781f301e79e7..fbbc99c88856a773326e4bb310d30fe3021e2333 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "refs.h"
 #include "pkt-line.h"
diff --git a/git.c b/git.c
index 1b8b7f51a65fa2a8e62d11d7ad99f19e2926977f..5be27b07e5146e89ce6497566ec602a3f58bc313 100644 (file)
--- a/git.c
+++ b/git.c
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "exec_cmd.h"
 #include "help.h"
 #include "run-command.h"
@@ -16,53 +17,9 @@ const char git_more_info_string[] =
           "to read about a specific subcommand or concept.");
 
 static int use_pager = -1;
-static char *orig_cwd;
-static const char *env_names[] = {
-       GIT_DIR_ENVIRONMENT,
-       GIT_WORK_TREE_ENVIRONMENT,
-       GIT_IMPLICIT_WORK_TREE_ENVIRONMENT,
-       GIT_PREFIX_ENVIRONMENT
-};
-static char *orig_env[4];
-static int save_restore_env_balance;
 
 static void list_builtins(void);
 
-static void save_env_before_alias(void)
-{
-       int i;
-
-       assert(save_restore_env_balance == 0);
-       save_restore_env_balance = 1;
-       orig_cwd = xgetcwd();
-       for (i = 0; i < ARRAY_SIZE(env_names); i++) {
-               orig_env[i] = getenv(env_names[i]);
-               orig_env[i] = xstrdup_or_null(orig_env[i]);
-       }
-}
-
-static void restore_env(int external_alias)
-{
-       int i;
-
-       assert(save_restore_env_balance == 1);
-       save_restore_env_balance = 0;
-       if (!external_alias && orig_cwd && chdir(orig_cwd))
-               die_errno("could not move to %s", orig_cwd);
-       free(orig_cwd);
-       for (i = 0; i < ARRAY_SIZE(env_names); i++) {
-               if (external_alias &&
-                   !strcmp(env_names[i], GIT_PREFIX_ENVIRONMENT))
-                       continue;
-               if (orig_env[i]) {
-                       setenv(env_names[i], orig_env[i], 1);
-                       free(orig_env[i]);
-               } else {
-                       unsetenv(env_names[i]);
-               }
-       }
-}
-
 static void commit_pager_choice(void) {
        switch (use_pager) {
        case 0:
@@ -255,19 +212,18 @@ static int handle_alias(int *argcp, const char ***argv)
        const char **new_argv;
        const char *alias_command;
        char *alias_string;
-       int unused_nongit;
-
-       save_env_before_alias();
-       setup_git_directory_gently(&unused_nongit);
 
        alias_command = (*argv)[0];
        alias_string = alias_lookup(alias_command);
        if (alias_string) {
                if (alias_string[0] == '!') {
                        struct child_process child = CHILD_PROCESS_INIT;
+                       int nongit_ok;
+
+                       /* Aliases expect GIT_PREFIX, GIT_DIR etc to be set */
+                       setup_git_directory_gently(&nongit_ok);
 
                        commit_pager_choice();
-                       restore_env(1);
 
                        child.use_shell = 1;
                        argv_array_push(&child.args, alias_string + 1);
@@ -313,8 +269,6 @@ static int handle_alias(int *argcp, const char ***argv)
                ret = 1;
        }
 
-       restore_env(0);
-
        errno = saved_errno;
 
        return ret;
index e44cc27da15f03629989ee0083664d0af09c55b3..8ab32df457d8947156bec1a838de39b60d9d545a 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "strbuf.h"
 #include "gpg-interface.h"
diff --git a/graph.c b/graph.c
index 8b9049dd2c725f58314042deebfb69030e4321d3..e7e20650da6983ada7c94c22aea7ecaec41c5c17 100644 (file)
--- a/graph.c
+++ b/graph.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "color.h"
 #include "graph.h"
diff --git a/grep.c b/grep.c
index d7ef21358ea7f592dffff98884eb34169e097880..30d317a122eb5adc2c6d63eddaa12ca14cafba78 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "grep.h"
 #include "userdiff.h"
 #include "xdiff-interface.h"
diff --git a/help.c b/help.c
index f637fc80062094784d5734df91523642933ddcfc..8ba0777410bd6377a1325622f7d73a53a0aa5a60 100644 (file)
--- a/help.c
+++ b/help.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "exec_cmd.h"
 #include "run-command.h"
@@ -290,7 +291,7 @@ const char *help_unknown_cmd(const char *cmd)
        memset(&other_cmds, 0, sizeof(other_cmds));
        memset(&aliases, 0, sizeof(aliases));
 
-       git_config(git_unknown_cmd_config, NULL);
+       read_early_config(git_unknown_cmd_config, NULL);
 
        load_command_list("git-", &main_cmds, &other_cmds);
 
index ba5ff1aa2994633c055611ce566ea8cf3c09e8cc..519025d2c3d944afb6fdd6ca1f3b091827a67272 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "pkt-line.h"
 #include "object.h"
index 3b556d66196277b2730f7e3d366a28a9d5ad1c56..8af380050ce6a43a6764ad871f0de141c316421a 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "exec_cmd.h"
 #include "http.h"
 #include "walker.h"
diff --git a/http.c b/http.c
index d2e11ec6f012d3b2a9570f0c322aebf53a13cc0a..013bb0cc650888426156fd1c8d173544c1ec90e1 100644 (file)
--- a/http.c
+++ b/http.c
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "http.h"
+#include "config.h"
 #include "pack.h"
 #include "sideband.h"
 #include "run-command.h"
diff --git a/ident.c b/ident.c
index 91c7609055bf3e0a4c0b7ae3cb46219ccaad53ef..327abe557f5a66546665664511d3e71b7f0929e7 100644 (file)
--- a/ident.c
+++ b/ident.c
@@ -6,6 +6,7 @@
  * Copyright (C) 2005 Linus Torvalds
  */
 #include "cache.h"
+#include "config.h"
 
 static struct strbuf git_default_name = STRBUF_INIT;
 static struct strbuf git_default_email = STRBUF_INIT;
index 857591660f485d65dec3390b22dd2083c94d7a44..59e9b12d294da13fcfc2955c61f50709de1ae84f 100644 (file)
@@ -23,6 +23,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "credential.h"
 #include "exec_cmd.h"
 #include "run-command.h"
index ac0d4a5d78d956f09aa0082b286babc36f04b593..b9576efe97b98d8b7971045b7be3698b9592c5e6 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "attr.h"
 #include "xdiff-interface.h"
 #include "run-command.h"
@@ -339,7 +340,7 @@ static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attr
 static void normalize_file(mmfile_t *mm, const char *path)
 {
        struct strbuf strbuf = STRBUF_INIT;
-       if (renormalize_buffer(path, mm->ptr, mm->size, &strbuf)) {
+       if (renormalize_buffer(&the_index, path, mm->ptr, mm->size, &strbuf)) {
                free(mm->ptr);
                mm->size = strbuf.len;
                mm->ptr = strbuf_detach(&strbuf, NULL);
index 2903874ecf156c374ae0a120cdc20a5f5e41df53..410ab4f02de5b532485c46b5cceffc3c677df214 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "diff.h"
 #include "commit.h"
 #include "tag.h"
index f92cb9f729ca05ae1e80c9c27bc102dbb64a8dc0..f59162453eecdfb841383f71911303b594aa81e4 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "utf8.h"
 #include "strbuf.h"
 #include "mailinfo.h"
index 5cc86df2d15729e9b0e8b36fdb151d5986f42a10..59e5ee41a8cdde0613e5dfa890cb52b21666868f 100644 (file)
@@ -4,6 +4,7 @@
  * The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
  */
 #include "cache.h"
+#include "config.h"
 #include "advice.h"
 #include "lockfile.h"
 #include "cache-tree.h"
@@ -1639,8 +1640,8 @@ static int blob_unchanged(struct merge_options *opt,
         * performed.  Comparison can be skipped if both files are
         * unchanged since their sha1s have already been compared.
         */
-       if (renormalize_buffer(path, o.buf, o.len, &o) |
-           renormalize_buffer(path, a.buf, a.len, &a))
+       if (renormalize_buffer(&the_index, path, o.buf, o.len, &o) |
+           renormalize_buffer(&the_index, path, a.buf, a.len, &a))
                ret = (o.len == a.len && !memcmp(o.buf, a.buf, o.len));
 
 error_return:
index 9ebf8419565019cca42d778be96e2f3b7d6f29df..9765deb41ab02dba909ec9027701bf2fdc53f310 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "notes-utils.h"
diff --git a/notes.c b/notes.c
index 4b3a1adda566bdc82ba7005083f37dff5bd62ed4..8f47c202c58752b6d9d56852ae9c315e2f144769 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "notes.h"
 #include "blob.h"
 #include "tree.h"
diff --git a/pager.c b/pager.c
index c113d898a4ab184cf5ad5ea04dc66365fdf8a8f8..4dd9e1b26592bd3e7a7ddb52182ea79971557db0 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "sigchain.h"
 
index e5ad34a2c3f7c7d7fdb65171f8a142a2becc64bb..0dd9fc6a0dd0a518200d9bbd834decb3c3ee22c6 100644 (file)
@@ -1,6 +1,7 @@
 #include "git-compat-util.h"
 #include "parse-options.h"
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "color.h"
 #include "utf8.h"
index 828405021fca4214585e1d46b65f604d14e61143..ecc5331c232ef81f26343fd958a9b66e92a3fa5e 100644 (file)
@@ -1,5 +1,6 @@
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "pathspec.h"
 #include "attr.h"
index 09701bd2ffef3eb6d9104916e4119f757c06c244..9c9f81b5b0e0560e05da3ec3fa62c05eae92d1e3 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "commit.h"
 #include "utf8.h"
 #include "diff.h"
index 75406390c6fdabf74e74d4c2a90e6ac92afc4ccc..6d5885d0096407d7d12f4511100ebee5cb5f752d 100644 (file)
--- a/prompt.c
+++ b/prompt.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "run-command.h"
 #include "strbuf.h"
 #include "prompt.h"
index bc156a133e9ff197e3d98c63d66f2d958f47f564..c8c766dab020472d5f318c247e376f27373a5261 100644 (file)
@@ -5,6 +5,7 @@
  */
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "config.h"
 #include "tempfile.h"
 #include "lockfile.h"
 #include "cache-tree.h"
diff --git a/refs.c b/refs.c
index f0685c92513e306188d89380a1c3020024a4edb4..84112c88ee4349ef8c7411f6e046d0f2d289ea04 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -3,6 +3,7 @@
  */
 
 #include "cache.h"
+#include "config.h"
 #include "hashmap.h"
 #include "lockfile.h"
 #include "iterator.h"
index d8b3f73147c8af88597ad71259aef0a9f53dd104..621a4086c37362180f151cc1648444d4cfd69d13 100644 (file)
@@ -1,4 +1,5 @@
 #include "../cache.h"
+#include "../config.h"
 #include "../refs.h"
 #include "refs-internal.h"
 #include "ref-cache.h"
index ece45993dac582ddc6ba19b2362ba1716e075eae..0053b09549ab419ab8f2da2c519d689f5e0d83b3 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "remote.h"
 #include "strbuf.h"
 #include "walker.h"
index f998f989e92a6eb919828c72d444f091d5fdfa6a..d87482573d38b057257c08024fbe6b4339661481 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "remote.h"
 #include "refs.h"
 #include "commit.h"
index c26c29f87a6f35d2efffd226fa8922f36cd0bb37..829b3b0f08f7546c168e2728687d5729c4607cfa 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "string-list.h"
 #include "rerere.h"
index 78bb34ebec297102c852a5b88ec7b4f10ffbc1d8..ed3cee3211bb80fac5c52bfe542a2b06fb308584 100644 (file)
@@ -1,4 +1,5 @@
 #include "builtin.h"
+#include "config.h"
 #include "commit.h"
 #include "refs.h"
 #include "pkt-line.h"
index d63099d50fc4e23cb3585b12c61ba8863d2688f6..224afe79b96c89a70a36db85aa6c61826b2ebec1 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "sequencer.h"
 #include "dir.h"
diff --git a/setup.c b/setup.c
index 751d02b9be627176009cdda4f1b20a3674b0dc95..358fbc2e5301d9412b55463065b912b5708c3ceb 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "string-list.h"
 
@@ -967,19 +968,21 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
        }
 }
 
-const char *discover_git_directory(struct strbuf *gitdir)
+int discover_git_directory(struct strbuf *commondir,
+                          struct strbuf *gitdir)
 {
        struct strbuf dir = STRBUF_INIT, err = STRBUF_INIT;
        size_t gitdir_offset = gitdir->len, cwd_len;
+       size_t commondir_offset = commondir->len;
        struct repository_format candidate;
 
        if (strbuf_getcwd(&dir))
-               return NULL;
+               return -1;
 
        cwd_len = dir.len;
        if (setup_git_directory_gently_1(&dir, gitdir, 0) <= 0) {
                strbuf_release(&dir);
-               return NULL;
+               return -1;
        }
 
        /*
@@ -995,8 +998,10 @@ const char *discover_git_directory(struct strbuf *gitdir)
                strbuf_insert(gitdir, gitdir_offset, dir.buf, dir.len);
        }
 
+       get_common_dir(commondir, gitdir->buf + gitdir_offset);
+
        strbuf_reset(&dir);
-       strbuf_addf(&dir, "%s/config", gitdir->buf + gitdir_offset);
+       strbuf_addf(&dir, "%s/config", commondir->buf + commondir_offset);
        read_repository_format(&candidate, dir.buf);
        strbuf_release(&dir);
 
@@ -1004,10 +1009,12 @@ const char *discover_git_directory(struct strbuf *gitdir)
                warning("ignoring git dir '%s': %s",
                        gitdir->buf + gitdir_offset, err.buf);
                strbuf_release(&err);
-               return NULL;
+               strbuf_setlen(commondir, commondir_offset);
+               strbuf_setlen(gitdir, gitdir_offset);
+               return -1;
        }
 
-       return gitdir->buf + gitdir_offset;
+       return 0;
 }
 
 const char *setup_git_directory_gently(int *nongit_ok)
index 59a4ed2ed32336b41ab8f3b1d4aca30f045aa084..a900b280428fa4931b1a60a9ac788edaff89634e 100644 (file)
@@ -7,6 +7,7 @@
  * creation etc.
  */
 #include "cache.h"
+#include "config.h"
 #include "string-list.h"
 #include "lockfile.h"
 #include "delta.h"
@@ -3546,7 +3547,7 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size,
         */
        if ((type == OBJ_BLOB) && path) {
                struct strbuf nbuf = STRBUF_INIT;
-               if (convert_to_git(path, buf, size, &nbuf,
+               if (convert_to_git(&the_index, path, buf, size, &nbuf,
                                   write_object ? safe_crlf : SAFE_CRLF_FALSE)) {
                        buf = strbuf_detach(&nbuf, &size);
                        re_allocated = 1;
@@ -3580,7 +3581,7 @@ static int index_stream_convert_blob(unsigned char *sha1, int fd,
        assert(path);
        assert(would_convert_to_git_filter_fd(path));
 
-       convert_to_git_filter_fd(path, fd, &sbuf,
+       convert_to_git_filter_fd(&the_index, path, fd, &sbuf,
                                 write_object ? safe_crlf : SAFE_CRLF_FALSE);
 
        if (write_object)
@@ -3668,7 +3669,7 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st,
        else if (!S_ISREG(st->st_mode))
                ret = index_pipe(sha1, fd, type, path, flags);
        else if (st->st_size <= big_file_threshold || type != OBJ_BLOB ||
-                (path && would_convert_to_git(path)))
+                (path && would_convert_to_git(&the_index, path)))
                ret = index_core(sha1, fd, xsize_t(st->st_size), type, path,
                                 flags);
        else
index 5126853bb5bda5f291039588db96064ffbd1ee5c..d2d732c19b62dd13c27852fcbf2385b29dd58b1d 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "tag.h"
 #include "commit.h"
 #include "tree.h"
index 4f58491ddb0705ab56e238006199d35db19dfb5a..d8f8d5ea3277d4dcfc8119e726e2f78c9aa881c9 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "submodule-config.h"
 #include "submodule.h"
 #include "strbuf.h"
index 1b8a3b575db6c85a42e9c9e285617113ecac4a84..da0b805493b9e7cd4c26f027a9f24c823109850a 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "submodule-config.h"
 #include "submodule.h"
 #include "dir.h"
index 8e3ed6a76cb97831e85152af8e9da21d18ed2fc1..1a7b8bd3d650fe1111c77115d2c68644b6ac9edb 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "string-list.h"
 
 /*
index 2f144d539a4822619a9383ded2d3adb270484624..c6c57bba0d397e44e8897b05d479a30b53311517 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "submodule-config.h"
 #include "submodule.h"
 
index 13b7851f7c2feb87f63449d917380452e85c1f84..a37ef0422212eafdae4b4c0fae9e28d4a183117f 100755 (executable)
@@ -703,6 +703,12 @@ test_expect_success 'invalid unit' '
        test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
 '
 
+test_expect_success 'line number is reported correctly' '
+       printf "[bool]\n\tvar\n" >invalid &&
+       test_must_fail git config -f invalid --path bool.var 2>actual &&
+       test_i18ngrep "line 2" actual
+'
+
 test_expect_success 'invalid stdin config' '
        echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
        test_i18ngrep "bad config line 1 in standard input" output
index e495a616161660bcade644dea42b5c8e53cc64b3..bafed5c9b88481992ca6cf4cd6c13596c7baf16b 100755 (executable)
@@ -226,7 +226,9 @@ test_expect_success 'check line errors for malformed values' '
                br
        EOF
        test_expect_code 128 git br 2>result &&
-       test_i18ngrep "fatal: .*alias\.br.*\.git/config.*line 2" result
+       test_i18ngrep "missing value for .alias\.br" result &&
+       test_i18ngrep "fatal: .*\.git/config" result &&
+       test_i18ngrep "fatal: .*line 2" result
 '
 
 test_expect_success 'error on modifying repo config without repo' '
index 4f3794d415e95b0b65ca29b829ce278b45ea5dbd..20b4d83c281e2fde8812f309bdebef012c6ecb74 100755 (executable)
@@ -391,6 +391,17 @@ test_expect_success TTY 'core.pager in repo config works and retains cwd' '
        )
 '
 
+test_expect_success TTY 'core.pager is found via alias in subdirectory' '
+       sane_unset GIT_PAGER &&
+       test_config core.pager "cat >via-alias" &&
+       (
+               cd sub &&
+               rm -f via-alias &&
+               test_terminal git -c alias.r="-p rev-parse" r HEAD &&
+               test_path_is_file via-alias
+       )
+'
+
 test_doesnt_paginate      expect_failure test_must_fail 'git -p nonsense'
 
 test_pager_choices                       'git shortlog'
index 11f0b9fb40bcedbfcd3111fa8076ce0d9e1eb20f..751b56c009a8c2f6c3531dab65565f9e06029778 100644 (file)
--- a/trailer.c
+++ b/trailer.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "string-list.h"
 #include "run-command.h"
 #include "commit.h"
index 9bfcf870f9078f75349bd3b4976c71bbf5c49ebf..b9995306f259da0a929babdfe1fb5b99eaacead8 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "transport.h"
 #include "run-command.h"
 #include "pkt-line.h"
diff --git a/tree.c b/tree.c
index 603b29ee805b00c4b1eeeebed51c917bfef7c009..dd69423d9a3c1e1b9dd83df729ede543bfedc90a 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -1,3 +1,4 @@
+#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "cache-tree.h"
 #include "tree.h"
@@ -8,7 +9,11 @@
 
 const char *tree_type = "tree";
 
-static int read_one_entry_opt(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage, int opt)
+static int read_one_entry_opt(struct index_state *istate,
+                             const unsigned char *sha1,
+                             const char *base, int baselen,
+                             const char *pathname,
+                             unsigned mode, int stage, int opt)
 {
        int len;
        unsigned int size;
@@ -27,14 +32,15 @@ static int read_one_entry_opt(const unsigned char *sha1, const char *base, int b
        memcpy(ce->name, base, baselen);
        memcpy(ce->name + baselen, pathname, len+1);
        hashcpy(ce->oid.hash, sha1);
-       return add_cache_entry(ce, opt);
+       return add_index_entry(istate, ce, opt);
 }
 
 static int read_one_entry(const unsigned char *sha1, struct strbuf *base,
                          const char *pathname, unsigned mode, int stage,
                          void *context)
 {
-       return read_one_entry_opt(sha1, base->buf, base->len, pathname,
+       struct index_state *istate = context;
+       return read_one_entry_opt(istate, sha1, base->buf, base->len, pathname,
                                  mode, stage,
                                  ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
 }
@@ -47,7 +53,8 @@ static int read_one_entry_quick(const unsigned char *sha1, struct strbuf *base,
                                const char *pathname, unsigned mode, int stage,
                                void *context)
 {
-       return read_one_entry_opt(sha1, base->buf, base->len, pathname,
+       struct index_state *istate = context;
+       return read_one_entry_opt(istate, sha1, base->buf, base->len, pathname,
                                  mode, stage,
                                  ADD_CACHE_JUST_APPEND);
 }
@@ -144,7 +151,8 @@ static int cmp_cache_name_compare(const void *a_, const void *b_)
                                  ce2->name, ce2->ce_namelen, ce_stage(ce2));
 }
 
-int read_tree(struct tree *tree, int stage, struct pathspec *match)
+int read_tree(struct tree *tree, int stage, struct pathspec *match,
+             struct index_state *istate)
 {
        read_tree_fn_t fn = NULL;
        int i, err;
@@ -164,23 +172,23 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match)
         * do it the original slow way, otherwise, append and then
         * sort at the end.
         */
-       for (i = 0; !fn && i < active_nr; i++) {
-               const struct cache_entry *ce = active_cache[i];
+       for (i = 0; !fn && i < istate->cache_nr; i++) {
+               const struct cache_entry *ce = istate->cache[i];
                if (ce_stage(ce) == stage)
                        fn = read_one_entry;
        }
 
        if (!fn)
                fn = read_one_entry_quick;
-       err = read_tree_recursive(tree, "", 0, stage, match, fn, NULL);
+       err = read_tree_recursive(tree, "", 0, stage, match, fn, istate);
        if (fn == read_one_entry || err)
                return err;
 
        /*
         * Sort the cache entry -- we need to nuke the cache tree, though.
         */
-       cache_tree_free(&active_cache_tree);
-       QSORT(active_cache, active_nr, cmp_cache_name_compare);
+       cache_tree_free(&istate->cache_tree);
+       QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare);
        return 0;
 }
 
diff --git a/tree.h b/tree.h
index 0d4734b94b67603bc8f71a5273c3414f8785e066..744e6dc2ac883adfa0e079f5f84f45a45e22b59d 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -34,6 +34,7 @@ extern int read_tree_recursive(struct tree *tree,
                               int stage, const struct pathspec *pathspec,
                               read_tree_fn_t fn, void *context);
 
-extern int read_tree(struct tree *tree, int stage, struct pathspec *pathspec);
+extern int read_tree(struct tree *tree, int stage, struct pathspec *pathspec,
+                    struct index_state *istate);
 
 #endif /* TREE_H */
index d38c37e38cf183cf878a9f35b19544d1da0bc438..dd535bc8497e5d8202a94923fd0a68c3f46907fd 100644 (file)
@@ -1,5 +1,6 @@
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "tree.h"
 #include "tree-walk.h"
index 5330c02c1427862be1eea61c8d8e4127909d13fe..7efff2fbfd76380fd448d53173f8295d7c9c9d87 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
 #include "pkt-line.h"
 #include "sideband.h"
index 8b732e40bce4968257c2918219f7dfdb0b9ed3a0..2c1502f719a17abaef6c5c56439c560994b45d37 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "userdiff.h"
 #include "attr.h"
 
index 9f81dc1062bc1f7f243afa8c0404ff5100fc0ef8..069ee94a4d79422ea659a7ebe3923662f0626afa 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "string-list.h"
 
 /*
index 4632c7d4c08c3127c4017c98c0983871f0236d93..36630e5d1855a41407e217e610aa1f293288abe1 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
@@ -2,6 +2,7 @@
  * Various trivial helper wrappers around standard functions
  */
 #include "cache.h"
+#include "config.h"
 
 static void do_nothing(size_t size)
 {
index d3f78ca2a718d3e4928aa90067e24d19988514c1..018e03308921e3b44bb75b8bc1e005424ca4fc1b 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "xdiff-interface.h"
 #include "xdiff/xtypes.h"
 #include "xdiff/xdiffi.h"