From a7609c54b399219bae5b8b94b305cf8e18bf20f8 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:13:52 -0700 Subject: convert: convert get_cached_convert_stats_ascii to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/ls-files.c | 3 ++- convert.c | 5 +++-- convert.h | 5 ++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index b376afc312..0044abf669 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -63,7 +63,8 @@ static void write_eolinfo(const struct cache_entry *ce, const char *path) 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(&the_index, + 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); diff --git a/convert.c b/convert.c index f1e168bc30..03160b376a 100644 --- a/convert.c +++ b/convert.c @@ -134,11 +134,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; diff --git a/convert.h b/convert.h index 82871a11d5..667b7dfe07 100644 --- 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,7 +35,8 @@ 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); -- cgit v1.2.3 From 49a6d31fc8c4277b1c5f5b82331e7190afa1d4ce Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:13:53 -0700 Subject: convert: convert crlf_to_git to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- convert.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/convert.c b/convert.c index 03160b376a..0cafb06f56 100644 --- a/convert.c +++ b/convert.c @@ -218,13 +218,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; @@ -254,7 +254,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) { @@ -286,7 +287,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 || @@ -1098,7 +1100,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(&the_index, path, src, len, dst, ca.crlf_action, checksafe); if (ret && dst) { src = dst->buf; len = dst->len; @@ -1118,7 +1120,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(&the_index, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe); ident_to_git(path, dst->buf, dst->len, dst, ca.ident); } -- cgit v1.2.3 From d6c41c20e688a1b284b92d92320ba56f639688de Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:13:54 -0700 Subject: convert: convert convert_to_git_filter_fd to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- convert.c | 5 +++-- convert.h | 3 ++- sha1_file.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/convert.c b/convert.c index 0cafb06f56..c09242cec0 100644 --- a/convert.c +++ b/convert.c @@ -1108,7 +1108,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; @@ -1120,7 +1121,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(&the_index, 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); } diff --git a/convert.h b/convert.h index 667b7dfe07..3a813a7976 100644 --- a/convert.h +++ b/convert.h @@ -52,7 +52,8 @@ static inline int would_convert_to_git(const char *path) return convert_to_git(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); diff --git a/sha1_file.c b/sha1_file.c index 59a4ed2ed3..ab09241d20 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -3580,7 +3580,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) -- cgit v1.2.3 From 82b474e025e89cfa294e81611c81355a73dc23a2 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:13:55 -0700 Subject: convert: convert convert_to_git to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- apply.c | 2 +- blame.c | 2 +- combine-diff.c | 2 +- convert.c | 7 ++++--- convert.h | 8 +++++--- diff.c | 6 +++--- dir.c | 2 +- sha1_file.c | 4 ++-- 8 files changed, 18 insertions(+), 15 deletions(-) diff --git a/apply.c b/apply.c index c49cef0637..97afb6f60a 100644 --- a/apply.c +++ b/apply.c @@ -2267,7 +2267,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; diff --git a/blame.c b/blame.c index 843c845cba..a6f3d72df8 100644 --- 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); diff --git a/combine-diff.c b/combine-diff.c index 2848034fe9..74f723af3d 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -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; diff --git a/convert.c b/convert.c index c09242cec0..600d11e73f 100644 --- a/convert.c +++ b/convert.c @@ -1084,7 +1084,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; @@ -1100,7 +1101,7 @@ int convert_to_git(const char *path, const char *src, size_t len, src = dst->buf; len = dst->len; } - ret |= crlf_to_git(&the_index, 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; @@ -1171,7 +1172,7 @@ int renormalize_buffer(const char *path, const char *src, size_t len, struct str src = dst->buf; len = dst->len; } - return ret | convert_to_git(path, src, len, dst, SAFE_CRLF_RENORMALIZE); + return ret | convert_to_git(&the_index, path, src, len, dst, SAFE_CRLF_RENORMALIZE); } /***************************************************************** diff --git a/convert.h b/convert.h index 3a813a7976..60cb41d6a4 100644 --- a/convert.h +++ b/convert.h @@ -41,15 +41,17 @@ 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, 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 struct index_state *istate, diff --git a/diff.c b/diff.c index 5275c4b780..976a6f91b1 100644 --- a/diff.c +++ b/diff.c @@ -2755,7 +2755,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int * 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 +2877,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 +2904,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 9efcf1eab6..f673b86f31 100644 --- a/dir.c +++ b/dir.c @@ -795,7 +795,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 diff --git a/sha1_file.c b/sha1_file.c index ab09241d20..feb227a837 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -3546,7 +3546,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; @@ -3668,7 +3668,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 -- cgit v1.2.3 From a33e0b2a77d7010ba8bf0e025fffaf98f464a938 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:13:56 -0700 Subject: convert: convert renormalize_buffer to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- convert.c | 6 ++++-- convert.h | 3 ++- ll-merge.c | 2 +- merge-recursive.c | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/convert.c b/convert.c index 600d11e73f..4097f521f2 100644 --- a/convert.c +++ b/convert.c @@ -1,3 +1,4 @@ +#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "attr.h" #include "run-command.h" @@ -1165,14 +1166,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(&the_index, path, src, len, dst, SAFE_CRLF_RENORMALIZE); + return ret | convert_to_git(istate, path, src, len, dst, SAFE_CRLF_RENORMALIZE); } /***************************************************************** diff --git a/convert.h b/convert.h index 60cb41d6a4..cecf59d1aa 100644 --- a/convert.h +++ b/convert.h @@ -46,7 +46,8 @@ extern int convert_to_git(const struct index_state *istate, 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 struct index_state *istate, const char *path) diff --git a/ll-merge.c b/ll-merge.c index ac0d4a5d78..d7eafb61a6 100644 --- a/ll-merge.c +++ b/ll-merge.c @@ -339,7 +339,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); diff --git a/merge-recursive.c b/merge-recursive.c index ae5238d82c..eac12d4888 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1639,8 +1639,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: -- cgit v1.2.3 From 85ab50f938601cf874c841cee4c56f1d1dc8199e Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:13:57 -0700 Subject: tree: convert read_tree to take an index parameter Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/ls-files.c | 2 +- tree.c | 28 ++++++++++++++++++---------- tree.h | 3 ++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 0044abf669..93e46ab5fb 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -460,7 +460,7 @@ 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, &the_index)) die("unable to read tree entries %s", tree_name); for (i = 0; i < active_nr; i++) { diff --git a/tree.c b/tree.c index 603b29ee80..dd69423d9a 100644 --- 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 0d4734b94b..744e6dc2ac 100644 --- 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 */ -- cgit v1.2.3 From 312c984a027f50247501d002fbd228a982f4f096 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:13:58 -0700 Subject: ls-files: convert overlay_tree_on_cache to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/commit.c | 3 ++- builtin/ls-files.c | 15 ++++++++------- cache.h | 3 ++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index da1ba4c862..78ef319a24 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -253,7 +253,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); } diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 93e46ab5fb..a78b291abd 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -431,7 +431,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; @@ -446,8 +447,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; @@ -460,11 +461,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, &the_index)) + 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; @@ -679,7 +680,7 @@ 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); if (show_resolve_undo) diff --git a/cache.h b/cache.h index 4d92aae0e8..5a0e0a9e5d 100644 --- a/cache.h +++ b/cache.h @@ -2186,7 +2186,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); -- cgit v1.2.3 From 1985fd68c65f2989033924416367a683b1d8ca67 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:13:59 -0700 Subject: ls-files: convert write_eolinfo to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/ls-files.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index a78b291abd..8c3f3d8cac 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -53,17 +53,16 @@ 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(&the_index, + 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); @@ -105,7 +104,7 @@ 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); } @@ -275,7 +274,7 @@ 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(&the_index, ce, ce->name); write_name(ce->name); if (debug_mode) { const struct stat_data *sd = &ce->ce_stat_data; -- cgit v1.2.3 From 23d6236a07be1434479a5d2f1f82cd8dda4818f9 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:00 -0700 Subject: ls-files: convert show_killed_files to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/ls-files.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 8c3f3d8cac..b82b78036d 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -120,7 +120,8 @@ static void show_other_files(struct dir_struct *dir) } } -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 +135,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. @@ -337,7 +338,7 @@ static void show_files(struct dir_struct *dir) if (show_others) show_other_files(dir); if (show_killed) - show_killed_files(dir); + show_killed_files(&the_index, dir); } if (show_cached || show_stage) { for (i = 0; i < active_nr; i++) { -- cgit v1.2.3 From 23d6846b2324ef647a339b84ba3abc52e0a4dc94 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:01 -0700 Subject: ls-files: convert show_other_files to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/ls-files.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index b82b78036d..5dbff94961 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -108,13 +108,14 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent) 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); } @@ -336,7 +337,7 @@ static void show_files(struct dir_struct *dir) dir->flags |= DIR_COLLECT_KILLED_ONLY; fill_directory(dir, &the_index, &pathspec); if (show_others) - show_other_files(dir); + show_other_files(&the_index, dir); if (show_killed) show_killed_files(&the_index, dir); } -- cgit v1.2.3 From 2d407e2da1b12fd1f3cb5fc0b072732ab2ac1c6a Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:02 -0700 Subject: ls-files: convert show_ru_info to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/ls-files.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 5dbff94961..375fe09d1e 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -292,14 +292,14 @@ static void show_ce_entry(const char *tag, const struct cache_entry *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; @@ -685,7 +685,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) } show_files(&dir); if (show_resolve_undo) - show_ru_info(); + show_ru_info(&the_index); if (ps_matched) { int bad; -- cgit v1.2.3 From 1d35e3bf056b508f4ece3875f9d2851be5fcd3d4 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:03 -0700 Subject: ls-files: convert ce_excluded to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/ls-files.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 375fe09d1e..762257f399 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -321,10 +321,11 @@ static void show_ru_info(const struct index_state *istate) } } -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) @@ -345,7 +346,7 @@ static void show_files(struct dir_struct *dir) for (i = 0; i < active_nr; i++) { const struct cache_entry *ce = active_cache[i]; if ((dir->flags & DIR_SHOW_IGNORED) && - !ce_excluded(dir, ce)) + !ce_excluded(dir, &the_index, ce)) continue; if (show_unmerged && !ce_stage(ce)) continue; @@ -361,7 +362,7 @@ static void show_files(struct dir_struct *dir) struct stat st; int err; if ((dir->flags & DIR_SHOW_IGNORED) && - !ce_excluded(dir, ce)) + !ce_excluded(dir, &the_index, ce)) continue; if (ce->ce_flags & CE_UPDATE) continue; -- cgit v1.2.3 From 6510ae173a8630e39a225f15031a7975547979ec Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:04 -0700 Subject: ls-files: convert prune_cache to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/ls-files.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 762257f399..b1626b13b4 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -380,30 +380,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) @@ -661,7 +662,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) -- cgit v1.2.3 From ff020a8ab0a40a3f938a30be6d73607c2041cc34 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:05 -0700 Subject: ls-files: convert show_ce_entry to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/ls-files.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index b1626b13b4..927aa67469 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -232,7 +232,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; @@ -276,7 +277,7 @@ 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(&the_index, 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; @@ -352,7 +353,7 @@ static void show_files(struct dir_struct *dir) continue; if (ce->ce_flags & CE_UPDATE) continue; - show_ce_entry(ce_stage(ce) ? tag_unmerged : + show_ce_entry(&the_index, ce_stage(ce) ? tag_unmerged : (ce_skip_worktree(ce) ? tag_skip_worktree : tag_cached), ce); } } @@ -370,9 +371,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); + show_ce_entry(&the_index, tag_removed, ce); if (show_modified && ce_modified(ce, &st, 0)) - show_ce_entry(tag_modified, ce); + show_ce_entry(&the_index, tag_modified, ce); } } } -- cgit v1.2.3 From f587c8dcdef17aea15aee45689e181b58b011706 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:06 -0700 Subject: ls-files: convert show_files to take an index Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/ls-files.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 927aa67469..55d6f54fd8 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -329,7 +329,7 @@ static int ce_excluded(struct dir_struct *dir, struct index_state *istate, 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; @@ -337,33 +337,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(&the_index, dir); + show_other_files(istate, dir); if (show_killed) - show_killed_files(&the_index, 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, &the_index, ce)) + !ce_excluded(dir, istate, ce)) continue; if (show_unmerged && !ce_stage(ce)) continue; if (ce->ce_flags & CE_UPDATE) continue; - show_ce_entry(&the_index, 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, &the_index, ce)) + !ce_excluded(dir, istate, ce)) continue; if (ce->ce_flags & CE_UPDATE) continue; @@ -371,9 +371,9 @@ static void show_files(struct dir_struct *dir) continue; err = lstat(ce->name, &st); if (show_deleted && err) - show_ce_entry(&the_index, tag_removed, ce); - if (show_modified && ce_modified(ce, &st, 0)) - show_ce_entry(&the_index, 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); } } } @@ -686,7 +686,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) die("ls-files --with-tree is incompatible with -s or -u"); 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(&the_index); -- cgit v1.2.3 From 5306ccf9e9ec7204eef409e90b57ddf23b8f5ca6 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:07 -0700 Subject: ls-files: factor out debug info into a function Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/ls-files.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 55d6f54fd8..c9307f9ef4 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -93,6 +93,19 @@ static void write_name(const char *name) strbuf_release(&full_name); } +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; @@ -279,15 +292,7 @@ static void show_ce_entry(const struct index_state *istate, } 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); -- cgit v1.2.3 From a84f3e59ebde9e891275ef8325c432db6bdf950c Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 12 Jun 2017 15:14:08 -0700 Subject: ls-files: factor out tag calculation Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/ls-files.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index c9307f9ef4..cdc1cfdd26 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -93,6 +93,30 @@ 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) { @@ -264,22 +288,7 @@ static void show_ce_entry(const struct index_state *istate, 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); -- cgit v1.2.3 From 69743f9b4f8411853e347fbd392221552b43fd12 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 14 Jun 2017 13:35:26 +0200 Subject: discover_git_directory(): avoid setting invalid git_dir When discovering a .git/ directory, we take pains to ensure that its repository format version matches Git's expectations, and we return NULL otherwise. However, we still appended the invalid path to the strbuf passed as argument. Let's just reset the strbuf to the state before we appended the .git/ directory that was eventually rejected. There is another early return path in that function, when setup_git_directory_gently_1() returns GIT_DIR_NONE or an error. In that case, the gitdir parameter has not been touched, therefore there is no need for an equivalent change in that code path. Signed-off-by: Johannes Schindelin Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- setup.c | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.c b/setup.c index 0309c27821..ba3241bf02 100644 --- a/setup.c +++ b/setup.c @@ -977,6 +977,7 @@ const char *discover_git_directory(struct strbuf *gitdir) warning("ignoring git dir '%s': %s", gitdir->buf + gitdir_offset, err.buf); strbuf_release(&err); + strbuf_setlen(gitdir, gitdir_offset); return NULL; } -- cgit v1.2.3 From e2e142510762712b4b005dca6c7a9676f93a3278 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 14 Jun 2017 13:35:46 +0200 Subject: config: report correct line number upon error When get_value() parses a key/value pair, it is possible that the line number is decreased (because the \n has been consumed already) before the key/value pair is passed to the callback function, to allow for the correct line to be attributed in case of an error. However, when git_parse_source() asks get_value() to parse the key/value pair, the error reporting is performed *after* get_value() returns. Which means that we have to be careful not to increase the line number in get_value() after the callback function returned an error. Signed-off-by: Johannes Schindelin Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- config.c | 3 ++- t/t1300-repo-config.sh | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index b4a3205da3..3df7515db2 100644 --- a/config.c +++ b/config.c @@ -588,7 +588,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; } diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index afcca0d52c..f664bfc671 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -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 -- cgit v1.2.3 From 659fef199fb52d4a5cb24f1dfd2b272980fc5038 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 14 Jun 2017 13:35:50 +0200 Subject: help: use early config when autocorrecting aliases Git has this feature which suggests similar commands (including aliases) in case the user specified an unknown command. This feature currently relies on a side effect of the way we expand aliases right now: when a command is not a builtin, we use the regular config machinery (meaning: discovering the .git/ directory and initializing global state such as the config cache) to see whether the command refers to an alias. However, we will change the way aliases are expanded in the next commits, to use the early config instead. That means that the autocorrect feature can no longer discover the available aliases by looking at the config cache (because it has not yet been initialized). So let's just use the early config machinery instead. This is slightly less performant than the previous way, as the early config is used *twice*: once to see whether the command refers to an alias, and then to see what aliases are most similar. However, this is hardly a performance-critical code path, so performance is less important here. Signed-off-by: Johannes Schindelin Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- help.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/help.c b/help.c index bc6cd19cf3..91ec8ab36f 100644 --- a/help.c +++ b/help.c @@ -330,7 +330,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); -- cgit v1.2.3 From e4feff4898f4705cc8df50e3dc152ed45ef06db6 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 14 Jun 2017 13:35:53 +0200 Subject: t1308: relax the test verifying that empty alias values are disallowed We are about to change the way aliases are expanded, to use the early config machinery. This machinery reports errors in a slightly different manner than the cached config machinery. Let's not get hung up by the precise wording of the message mentioning the line number. It is really sufficient to verify that all the relevant information is given to the user. Signed-off-by: Johannes Schindelin Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- t/t1308-config-set.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh index ff50960cca..69a0aa56d6 100755 --- a/t/t1308-config-set.sh +++ b/t/t1308-config-set.sh @@ -215,7 +215,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' ' -- cgit v1.2.3 From 3f9c5dfb7118256747de5efbaa4b5cd3f0e02331 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 14 Jun 2017 13:35:56 +0200 Subject: t7006: demonstrate a problem with aliases in subdirectories When expanding aliases, the git_dir is set during the alias expansion (by virtue of running setup_git_directory_gently()). This git_dir may be relative to the current working directory, and indeed often is simply ".git/". When the alias expands to a shell command, we restore the original working directory, though, yet we do not reset git_dir. As a consequence, subsequent read_early_config() runs will mistake the git_dir to be populated properly and not find the correct config. Demonstrate this problem by adding a test case. Signed-off-by: Johannes Schindelin Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- t/t7006-pager.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index 4f3794d415..83881ec3a0 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -391,6 +391,17 @@ test_expect_success TTY 'core.pager in repo config works and retains cwd' ' ) ' +test_expect_failure 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' -- cgit v1.2.3 From a9bcf6586d1a4888aea91553d73cda20494b8335 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 14 Jun 2017 13:36:00 +0200 Subject: alias: use the early config machinery to expand aliases Instead of discovering the .git/ directory, reading the config and then trying to painstakingly reset all the global state if we did not find a matching alias, let's use the early config machinery instead. It may look like unnecessary work to discover the .git/ directory in the early config machinery and then call setup_git_directory_gently() in the case of a shell alias, repeating the very same discovery *again*. However, we have to do this as the early config machinery takes pains *not* to touch any global state, while shell aliases expect a possibly changed working directory and at least the GIT_PREFIX and GIT_DIR variables to be set. This change also fixes a known issue where Git tried to read the pager config from an incorrect path in a subdirectory of a Git worktree if an alias expanded to a shell command. Signed-off-by: Johannes Schindelin Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- alias.c | 28 +++++++++++++++++++++------- git.c | 55 ++++--------------------------------------------------- t/t7006-pager.sh | 2 +- 3 files changed, 26 insertions(+), 59 deletions(-) diff --git a/alias.c b/alias.c index 3b90397a99..0526304661 100644 --- a/alias.c +++ b/alias.c @@ -1,14 +1,28 @@ #include "cache.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/git.c b/git.c index 8ff44f081d..58ef570294 100644 --- a/git.c +++ b/git.c @@ -16,50 +16,6 @@ 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 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) { @@ -250,19 +206,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); @@ -308,8 +263,6 @@ static int handle_alias(int *argcp, const char ***argv) ret = 1; } - restore_env(0); - errno = saved_errno; return ret; diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index 83881ec3a0..20b4d83c28 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -391,7 +391,7 @@ test_expect_success TTY 'core.pager in repo config works and retains cwd' ' ) ' -test_expect_failure TTY 'core.pager is found via alias in subdirectory' ' +test_expect_success TTY 'core.pager is found via alias in subdirectory' ' sane_unset GIT_PAGER && test_config core.pager "cat >via-alias" && ( -- cgit v1.2.3 From e67a57fc5187f93ced9631edf80fc09eefb3fed9 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 14 Jun 2017 11:07:34 -0700 Subject: config: create config.h Move all config related declarations from cache.h to a new config.h header file. This makes cache.h smaller and allows for the opportunity in a following patch to only include config.h when needed. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- cache.h | 190 +------------------------------------------------------------ config.h | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 195 insertions(+), 189 deletions(-) create mode 100644 config.h diff --git a/cache.h b/cache.h index e1f0e182ad..67efb47a14 100644 --- a/cache.h +++ b/cache.h @@ -11,6 +11,7 @@ #include "string-list.h" #include "pack-revindex.h" #include "hash.h" +#include "config.h" #ifndef platform_SHA_CTX /* @@ -1865,188 +1866,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. @@ -2054,16 +1876,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); diff --git a/config.h b/config.h new file mode 100644 index 0000000000..f7f8b66c59 --- /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 *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 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); + +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 */ -- cgit v1.2.3 From f1c985da05c136414c10f034cdc09bdb6939cb8f Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 14 Jun 2017 11:07:35 -0700 Subject: config: remove git_config_iter Since there is no implementation of the function 'git_config_iter', let's stop exporting it and remove the prototype from config.h. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- config.h | 1 - 1 file changed, 1 deletion(-) diff --git a/config.h b/config.h index f7f8b66c59..c70599bd5f 100644 --- a/config.h +++ b/config.h @@ -165,7 +165,6 @@ extern int git_configset_get_pathname(struct config_set *cs, const char *key, co 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); -- cgit v1.2.3 From b2141fc1d20e659810245ec6ca1c143c60e033ec Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 14 Jun 2017 11:07:36 -0700 Subject: config: don't include config.h by default Stop including config.h by default in cache.h. Instead only include config.h in those files which require use of the config system. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- advice.c | 1 + alias.c | 1 + apply.c | 1 + archive-tar.c | 1 + archive-zip.c | 1 + archive.c | 1 + attr.c | 1 + bisect.c | 1 + branch.c | 1 + builtin/add.c | 1 + builtin/am.c | 1 + builtin/blame.c | 1 + builtin/branch.c | 1 + builtin/cat-file.c | 1 + builtin/check-attr.c | 1 + builtin/check-ignore.c | 1 + builtin/check-mailmap.c | 1 + builtin/checkout-index.c | 1 + builtin/checkout.c | 1 + builtin/clean.c | 1 + builtin/clone.c | 1 + builtin/column.c | 1 + builtin/commit-tree.c | 1 + builtin/commit.c | 1 + builtin/config.c | 1 + builtin/count-objects.c | 1 + builtin/describe.c | 1 + builtin/diff-files.c | 1 + builtin/diff-index.c | 1 + builtin/diff-tree.c | 1 + builtin/diff.c | 1 + builtin/difftool.c | 1 + builtin/fast-export.c | 1 + builtin/fetch.c | 1 + builtin/fmt-merge-msg.c | 1 + builtin/for-each-ref.c | 1 + builtin/fsck.c | 1 + builtin/gc.c | 1 + builtin/grep.c | 1 + builtin/hash-object.c | 1 + builtin/help.c | 1 + builtin/index-pack.c | 1 + builtin/init-db.c | 1 + builtin/log.c | 1 + builtin/ls-files.c | 1 + builtin/ls-tree.c | 1 + builtin/merge-base.c | 1 + builtin/merge-file.c | 1 + builtin/merge.c | 1 + builtin/mv.c | 1 + builtin/name-rev.c | 1 + builtin/notes.c | 1 + builtin/pack-objects.c | 1 + builtin/patch-id.c | 1 + builtin/pull.c | 1 + builtin/push.c | 1 + builtin/read-tree.c | 1 + builtin/rebase--helper.c | 1 + builtin/receive-pack.c | 1 + builtin/reflog.c | 1 + builtin/remote.c | 1 + builtin/repack.c | 1 + builtin/replace.c | 1 + builtin/rerere.c | 1 + builtin/reset.c | 1 + builtin/rev-list.c | 1 + builtin/rev-parse.c | 1 + builtin/revert.c | 1 + builtin/rm.c | 1 + builtin/send-pack.c | 1 + builtin/shortlog.c | 1 + builtin/show-branch.c | 1 + builtin/stripspace.c | 1 + builtin/submodule--helper.c | 1 + builtin/symbolic-ref.c | 1 + builtin/tag.c | 1 + builtin/unpack-file.c | 1 + builtin/unpack-objects.c | 1 + builtin/update-index.c | 1 + builtin/update-ref.c | 1 + builtin/update-server-info.c | 1 + builtin/var.c | 1 + builtin/verify-commit.c | 1 + builtin/verify-pack.c | 1 + builtin/verify-tag.c | 1 + builtin/worktree.c | 1 + builtin/write-tree.c | 1 + cache.h | 1 - color.c | 1 + column.c | 1 + compat/precompose_utf8.c | 1 + config.c | 1 + connect.c | 1 + convert.c | 1 + credential-cache--daemon.c | 1 + credential.c | 1 + daemon.c | 1 + diff.c | 1 + dir.c | 1 + environment.c | 1 + fast-import.c | 1 + fetch-pack.c | 1 + git.c | 1 + gpg-interface.c | 1 + graph.c | 1 + grep.c | 1 + help.c | 1 + http-backend.c | 1 + http-fetch.c | 1 + http.c | 1 + ident.c | 1 + imap-send.c | 1 + ll-merge.c | 1 + log-tree.c | 1 + mailinfo.c | 1 + merge-recursive.c | 1 + notes-utils.c | 1 + notes.c | 1 + pager.c | 1 + parse-options.c | 1 + pathspec.c | 1 + pretty.c | 1 + prompt.c | 1 + read-cache.c | 1 + refs.c | 1 + refs/files-backend.c | 1 + remote-curl.c | 1 + remote.c | 1 + rerere.c | 1 + send-pack.c | 1 + sequencer.c | 1 + setup.c | 1 + sha1_file.c | 1 + sha1_name.c | 1 + submodule-config.c | 1 + submodule.c | 1 + t/helper/test-config.c | 1 + t/helper/test-submodule-config.c | 1 + trailer.c | 1 + transport.c | 1 + unpack-trees.c | 1 + upload-pack.c | 1 + userdiff.c | 1 + versioncmp.c | 1 + wrapper.c | 1 + xdiff-interface.c | 1 + 146 files changed, 145 insertions(+), 1 deletion(-) diff --git a/advice.c b/advice.c index b84ae4960f..3fa04fca0b 100644 --- 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 0526304661..de8e6a3f49 100644 --- a/alias.c +++ b/alias.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" struct config_alias_data { const char *alias; diff --git a/apply.c b/apply.c index e6dbab26ad..5b442860df 100644 --- 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" diff --git a/archive-tar.c b/archive-tar.c index 380e3aedd2..d65ac016df 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -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" diff --git a/archive-zip.c b/archive-zip.c index b429a8d974..04fcd86872 100644 --- a/archive-zip.c +++ b/archive-zip.c @@ -2,6 +2,7 @@ * Copyright (c) 2006 Rene Scharfe */ #include "cache.h" +#include "config.h" #include "archive.h" #include "streaming.h" #include "utf8.h" diff --git a/archive.c b/archive.c index 60b8891986..0cba5b4096 100644 --- 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 7e2134471c..9f8b029363 100644 --- 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" diff --git a/bisect.c b/bisect.c index 08c9fb7266..e8f03a08c4 100644 --- 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/branch.c b/branch.c index ad5a2299ba..5532b4218f 100644 --- 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" diff --git a/builtin/add.c b/builtin/add.c index 9f53f020d0..55759a6a78 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -4,6 +4,7 @@ * Copyright (C) 2006 Linus Torvalds */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "lockfile.h" #include "dir.h" diff --git a/builtin/am.c b/builtin/am.c index a95dd8b4e6..59f46a29ee 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -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" diff --git a/builtin/blame.c b/builtin/blame.c index 07506a3e45..1a7371808a 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -6,6 +6,7 @@ */ #include "cache.h" +#include "config.h" #include "refs.h" #include "builtin.h" #include "blob.h" diff --git a/builtin/branch.c b/builtin/branch.c index 48a513a84d..50b59238d4 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -6,6 +6,7 @@ */ #include "cache.h" +#include "config.h" #include "color.h" #include "refs.h" #include "commit.h" diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 1890d7a639..12451205cf 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -4,6 +4,7 @@ * Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "parse-options.h" #include "userdiff.h" diff --git a/builtin/check-attr.c b/builtin/check-attr.c index 4d01ca0c8b..91444dc044 100644 --- a/builtin/check-attr.c +++ b/builtin/check-attr.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "attr.h" #include "quote.h" #include "parse-options.h" diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c index 1d73d3ca3d..a2da09f4ae 100644 --- a/builtin/check-ignore.c +++ b/builtin/check-ignore.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "dir.h" #include "quote.h" #include "pathspec.h" diff --git a/builtin/check-mailmap.c b/builtin/check-mailmap.c index cf0f54f6b9..cdce144f3b 100644 --- a/builtin/check-mailmap.c +++ b/builtin/check-mailmap.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "config.h" #include "mailmap.h" #include "parse-options.h" #include "string-list.h" diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c index 07631d0c9c..39c8be05dc 100644 --- a/builtin/checkout-index.c +++ b/builtin/checkout-index.c @@ -5,6 +5,7 @@ * */ #include "builtin.h" +#include "config.h" #include "lockfile.h" #include "quote.h" #include "cache-tree.h" diff --git a/builtin/checkout.c b/builtin/checkout.c index bfa5419f33..e0b58ddc0b 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "config.h" #include "lockfile.h" #include "parse-options.h" #include "refs.h" diff --git a/builtin/clean.c b/builtin/clean.c index d861f836a2..57093db8be 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -8,6 +8,7 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "dir.h" #include "parse-options.h" #include "string-list.h" diff --git a/builtin/clone.c b/builtin/clone.c index de85b85254..eaacac221b 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -9,6 +9,7 @@ */ #include "builtin.h" +#include "config.h" #include "lockfile.h" #include "parse-options.h" #include "fetch-pack.h" diff --git a/builtin/column.c b/builtin/column.c index 33314b4d71..0c3223d64b 100644 --- a/builtin/column.c +++ b/builtin/column.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "strbuf.h" #include "parse-options.h" #include "string-list.h" diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index 605017261c..e1c17ba64b 100644 --- a/builtin/commit-tree.c +++ b/builtin/commit-tree.c @@ -4,6 +4,7 @@ * Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "commit.h" #include "tree.h" #include "builtin.h" diff --git a/builtin/commit.c b/builtin/commit.c index 1d805f5da8..929a45abed 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -6,6 +6,7 @@ */ #include "cache.h" +#include "config.h" #include "lockfile.h" #include "cache-tree.h" #include "color.h" diff --git a/builtin/config.c b/builtin/config.c index 3a554ad50c..b2045cd6c3 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "color.h" #include "parse-options.h" #include "urlmatch.h" diff --git a/builtin/count-objects.c b/builtin/count-objects.c index acb05940fc..1d82e61f2a 100644 --- a/builtin/count-objects.c +++ b/builtin/count-objects.c @@ -5,6 +5,7 @@ */ #include "cache.h" +#include "config.h" #include "dir.h" #include "builtin.h" #include "parse-options.h" diff --git a/builtin/describe.c b/builtin/describe.c index a5cd8c513f..3eddfd3706 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "lockfile.h" #include "commit.h" #include "tag.h" diff --git a/builtin/diff-files.c b/builtin/diff-files.c index 15c61fd8d1..29d3e4f416 100644 --- a/builtin/diff-files.c +++ b/builtin/diff-files.c @@ -4,6 +4,7 @@ * Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "diff.h" #include "commit.h" #include "revision.h" diff --git a/builtin/diff-index.c b/builtin/diff-index.c index 1af373d002..e3d418361c 100644 --- a/builtin/diff-index.c +++ b/builtin/diff-index.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "diff.h" #include "commit.h" #include "revision.h" diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index 326f88b657..c81063d534 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "diff.h" #include "commit.h" #include "log-tree.h" diff --git a/builtin/diff.c b/builtin/diff.c index d184aafab9..1ce40c63b2 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -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" diff --git a/builtin/difftool.c b/builtin/difftool.c index 1354d0e462..538b0187fa 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -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" diff --git a/builtin/fast-export.c b/builtin/fast-export.c index e0220630d0..e4304e2dd6 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -5,6 +5,7 @@ */ #include "builtin.h" #include "cache.h" +#include "config.h" #include "refs.h" #include "commit.h" #include "object.h" diff --git a/builtin/fetch.c b/builtin/fetch.c index 5f2c2ab23e..1fe8f62385 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -2,6 +2,7 @@ * "git fetch" */ #include "cache.h" +#include "config.h" #include "refs.h" #include "commit.h" #include "builtin.h" diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index 6faa3c0d24..2e30b514f2 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "refs.h" #include "commit.h" #include "diff.h" diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index eca365bf89..52be99cbac 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "refs.h" #include "object.h" #include "parse-options.h" diff --git a/builtin/fsck.c b/builtin/fsck.c index b5e13a4556..0c63f6259f 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "commit.h" #include "tree.h" #include "blob.h" diff --git a/builtin/gc.c b/builtin/gc.c index 91f7696a85..0a6790d714 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -11,6 +11,7 @@ */ #include "builtin.h" +#include "config.h" #include "tempfile.h" #include "lockfile.h" #include "parse-options.h" diff --git a/builtin/grep.c b/builtin/grep.c index 3ffb5b4e81..3df9e08f03 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -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" diff --git a/builtin/hash-object.c b/builtin/hash-object.c index bbeaf20bcc..d04baf999a 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -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" diff --git a/builtin/help.c b/builtin/help.c index 49f7a07f85..334a8494ab 100644 --- a/builtin/help.c +++ b/builtin/help.c @@ -2,6 +2,7 @@ * Builtin help command */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "exec_cmd.h" #include "parse-options.h" diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 4ff567db47..dfb3d1296a 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "config.h" #include "delta.h" #include "pack.h" #include "csum-file.h" diff --git a/builtin/init-db.c b/builtin/init-db.c index 8a6acb0ec6..47823f9aa4 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -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" diff --git a/builtin/log.c b/builtin/log.c index b3b10cc1ed..b333d4fea2 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -5,6 +5,7 @@ * 2006 Junio Hamano */ #include "cache.h" +#include "config.h" #include "refs.h" #include "color.h" #include "commit.h" diff --git a/builtin/ls-files.c b/builtin/ls-files.c index a6c70dbe9e..9751010780 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -6,6 +6,7 @@ * Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "quote.h" #include "dir.h" #include "builtin.h" diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index d7ebeb4ce6..4b53a8282b 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -4,6 +4,7 @@ * Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "blob.h" #include "tree.h" #include "commit.h" diff --git a/builtin/merge-base.c b/builtin/merge-base.c index cfe2a796f8..9c201cbfc0 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "commit.h" #include "refs.h" #include "diff.h" diff --git a/builtin/merge-file.c b/builtin/merge-file.c index 47dde7c39c..b08803e611 100644 --- a/builtin/merge-file.c +++ b/builtin/merge-file.c @@ -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" diff --git a/builtin/merge.c b/builtin/merge.c index 703827f006..9bdd577e09 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -7,6 +7,7 @@ */ #include "cache.h" +#include "config.h" #include "parse-options.h" #include "builtin.h" #include "lockfile.h" diff --git a/builtin/mv.c b/builtin/mv.c index 61d20037ad..dcf6736b5b 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -4,6 +4,7 @@ * Copyright (C) 2006 Johannes Schindelin */ #include "builtin.h" +#include "config.h" #include "pathspec.h" #include "lockfile.h" #include "dir.h" diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 92a5d8a5d2..c222daaa14 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "commit.h" #include "tag.h" #include "refs.h" diff --git a/builtin/notes.c b/builtin/notes.c index 7b891471c4..dceb681bad 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -8,6 +8,7 @@ */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "notes.h" #include "blob.h" diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 0fe35d1b5a..0e17184354 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "attr.h" #include "object.h" #include "blob.h" diff --git a/builtin/patch-id.c b/builtin/patch-id.c index 81552e02e4..970d0d30b4 100644 --- a/builtin/patch-id.c +++ b/builtin/patch-id.c @@ -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) { diff --git a/builtin/pull.c b/builtin/pull.c index dd1a4a94e4..3632921f03 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -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" diff --git a/builtin/push.c b/builtin/push.c index a597759d8f..76aa713d22 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -2,6 +2,7 @@ * "git push" */ #include "cache.h" +#include "config.h" #include "refs.h" #include "run-command.h" #include "builtin.h" diff --git a/builtin/read-tree.c b/builtin/read-tree.c index 23e212ee8c..0a85b6d938 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -5,6 +5,7 @@ */ #include "cache.h" +#include "config.h" #include "lockfile.h" #include "object.h" #include "tree.h" diff --git a/builtin/rebase--helper.c b/builtin/rebase--helper.c index ca1ebb2fa1..c82b4dce68 100644 --- a/builtin/rebase--helper.c +++ b/builtin/rebase--helper.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "parse-options.h" #include "sequencer.h" diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index f96834f42c..01ae7154e6 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "config.h" #include "lockfile.h" #include "pack.h" #include "refs.h" diff --git a/builtin/reflog.c b/builtin/reflog.c index 7472775778..6e9a8213ea 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "config.h" #include "lockfile.h" #include "commit.h" #include "refs.h" diff --git a/builtin/remote.c b/builtin/remote.c index addf97ad29..a470ed7c62 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "config.h" #include "parse-options.h" #include "transport.h" #include "remote.h" diff --git a/builtin/repack.c b/builtin/repack.c index 677bc7c81a..c01ff7c30b 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "dir.h" #include "parse-options.h" #include "run-command.h" diff --git a/builtin/replace.c b/builtin/replace.c index ab17668f43..905b1759a4 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -9,6 +9,7 @@ */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "refs.h" #include "parse-options.h" diff --git a/builtin/rerere.c b/builtin/rerere.c index 1bf72423bf..ffb66e2907 100644 --- a/builtin/rerere.c +++ b/builtin/rerere.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "dir.h" #include "parse-options.h" #include "string-list.h" diff --git a/builtin/reset.c b/builtin/reset.c index fc3b906c47..fdd5e5e003 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -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" diff --git a/builtin/rev-list.c b/builtin/rev-list.c index bcf77f0b8a..f9e2caee16 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "commit.h" #include "diff.h" #include "revision.h" diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 0513330910..9d18bbd648 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -4,6 +4,7 @@ * Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "config.h" #include "commit.h" #include "refs.h" #include "quote.h" diff --git a/builtin/revert.c b/builtin/revert.c index 345d9586a7..16028b9ea8 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "builtin.h" #include "parse-options.h" #include "diff.h" diff --git a/builtin/rm.c b/builtin/rm.c index fb79dcab18..b1adf1c961 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -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" diff --git a/builtin/send-pack.c b/builtin/send-pack.c index b8e2e74fe0..633e0c3cdd 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "config.h" #include "commit.h" #include "refs.h" #include "pkt-line.h" diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 7cff1839fc..43c4799ea9 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "commit.h" #include "diff.h" #include "string-list.h" diff --git a/builtin/show-branch.c b/builtin/show-branch.c index 19756595d5..6825439970 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "commit.h" #include "refs.h" #include "builtin.h" diff --git a/builtin/stripspace.c b/builtin/stripspace.c index 1e62a008cb..bdf0328869 100644 --- a/builtin/stripspace.c +++ b/builtin/stripspace.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "parse-options.h" #include "strbuf.h" diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 566a5b6a6f..700460c349 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "parse-options.h" #include "quote.h" #include "pathspec.h" diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c index 70addef158..df75cb9d4a 100644 --- a/builtin/symbolic-ref.c +++ b/builtin/symbolic-ref.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "config.h" #include "cache.h" #include "refs.h" #include "parse-options.h" diff --git a/builtin/tag.c b/builtin/tag.c index bdf1e88e93..b85bcf6809 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -7,6 +7,7 @@ */ #include "cache.h" +#include "config.h" #include "builtin.h" #include "refs.h" #include "tag.h" diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c index 6fc6bcdf7f..73f1334191 100644 --- a/builtin/unpack-file.c +++ b/builtin/unpack-file.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "config.h" static char *create_temp_file(unsigned char *sha1) { diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 4532aa0831..9da06548f0 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "object.h" #include "delta.h" #include "pack.h" diff --git a/builtin/update-index.c b/builtin/update-index.c index ebfc09faa0..0a4c236487 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -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" diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 0b2ecf41ae..40ccfc193b 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "refs.h" #include "builtin.h" #include "parse-options.h" diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c index 6c8cc3edc1..873070e517 100644 --- a/builtin/update-server-info.c +++ b/builtin/update-server-info.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "builtin.h" #include "parse-options.h" diff --git a/builtin/var.c b/builtin/var.c index aedbb53a2d..6c6f46b4ae 100644 --- a/builtin/var.c +++ b/builtin/var.c @@ -4,6 +4,7 @@ * Copyright (C) Eric Biederman, 2005 */ #include "builtin.h" +#include "config.h" static const char var_usage[] = "git var (-l | )"; diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c index 38bedf8f9f..d5e9a17a77 100644 --- a/builtin/verify-commit.c +++ b/builtin/verify-commit.c @@ -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" diff --git a/builtin/verify-pack.c b/builtin/verify-pack.c index c94e156932..c2a1a5c504 100644 --- a/builtin/verify-pack.c +++ b/builtin/verify-pack.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "config.h" #include "run-command.h" #include "parse-options.h" diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c index 5199553d91..f9a5f7535a 100644 --- a/builtin/verify-tag.c +++ b/builtin/verify-tag.c @@ -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" diff --git a/builtin/worktree.c b/builtin/worktree.c index 1722a9bdc2..d414b6870b 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "builtin.h" #include "dir.h" #include "parse-options.h" diff --git a/builtin/write-tree.c b/builtin/write-tree.c index 084c0df783..bd0a78aa3c 100644 --- a/builtin/write-tree.c +++ b/builtin/write-tree.c @@ -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 67efb47a14..160ff81aa7 100644 --- a/cache.h +++ b/cache.h @@ -11,7 +11,6 @@ #include "string-list.h" #include "pack-revindex.h" #include "hash.h" -#include "config.h" #ifndef platform_SHA_CTX /* diff --git a/color.c b/color.c index dee61557e0..31b6207a00 100644 --- 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; diff --git a/column.c b/column.c index d55ead18ef..ff7bdab1a3 100644 --- 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" diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c index 4293b53b17..de61c15d34 100644 --- a/compat/precompose_utf8.c +++ b/compat/precompose_utf8.c @@ -6,6 +6,7 @@ #define PRECOMPOSE_UNICODE_C #include "cache.h" +#include "config.h" #include "utf8.h" #include "precompose_utf8.h" diff --git a/config.c b/config.c index 3df7515db2..eec7613e04 100644 --- 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" diff --git a/connect.c b/connect.c index cd21a1b6f7..efddb30ea8 100644 --- 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" diff --git a/convert.c b/convert.c index 8d652bf27c..69f23cfcaa 100644 --- a/convert.c +++ b/convert.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "attr.h" #include "run-command.h" #include "quote.h" diff --git a/credential-cache--daemon.c b/credential-cache--daemon.c index 46c5937526..2787b29c05 100644 --- a/credential-cache--daemon.c +++ b/credential-cache--daemon.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "tempfile.h" #include "credential.h" #include "unix-socket.h" diff --git a/credential.c b/credential.c index aa996669fc..67a523353b 100644 --- a/credential.c +++ b/credential.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "credential.h" #include "string-list.h" #include "run-command.h" diff --git a/daemon.c b/daemon.c index ac7181a483..30747075f0 100644 --- 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 74283d9001..4f9b9f8382 100644 --- 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" diff --git a/dir.c b/dir.c index f451bfa48c..42beb65bea 100644 --- a/dir.c +++ b/dir.c @@ -8,6 +8,7 @@ * Junio Hamano, 2005-2006 */ #include "cache.h" +#include "config.h" #include "dir.h" #include "attr.h" #include "refs.h" diff --git a/environment.c b/environment.c index ff6e4f06e9..9d9b367925 100644 --- a/environment.c +++ b/environment.c @@ -8,6 +8,7 @@ * are. */ #include "cache.h" +#include "config.h" #include "refs.h" #include "fmt-merge-msg.h" #include "commit.h" diff --git a/fast-import.c b/fast-import.c index cf58f875b8..bbc3e79eaf 100644 --- a/fast-import.c +++ b/fast-import.c @@ -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" diff --git a/fetch-pack.c b/fetch-pack.c index afb8b05024..963d45db91 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -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 58ef570294..c03de2c090 100644 --- 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" diff --git a/gpg-interface.c b/gpg-interface.c index e44cc27da1..8ab32df457 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -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 8b9049dd2c..e7e20650da 100644 --- 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 47cee45067..d5211fc5a6 100644 --- 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 91ec8ab36f..b8f3a98e4c 100644 --- a/help.c +++ b/help.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "builtin.h" #include "exec_cmd.h" #include "levenshtein.h" diff --git a/http-backend.c b/http-backend.c index eef0a361f4..109df44e31 100644 --- a/http-backend.c +++ b/http-backend.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "refs.h" #include "pkt-line.h" #include "object.h" diff --git a/http-fetch.c b/http-fetch.c index 3b556d6619..8af380050c 100644 --- a/http-fetch.c +++ b/http-fetch.c @@ -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 d2e11ec6f0..013bb0cc65 100644 --- 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 bea871c8e0..d41fc91192 100644 --- 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; diff --git a/imap-send.c b/imap-send.c index 857591660f..59e9b12d29 100644 --- a/imap-send.c +++ b/imap-send.c @@ -23,6 +23,7 @@ */ #include "cache.h" +#include "config.h" #include "credential.h" #include "exec_cmd.h" #include "run-command.h" diff --git a/ll-merge.c b/ll-merge.c index ac0d4a5d78..24ff94e1dd 100644 --- a/ll-merge.c +++ b/ll-merge.c @@ -5,6 +5,7 @@ */ #include "cache.h" +#include "config.h" #include "attr.h" #include "xdiff-interface.h" #include "run-command.h" diff --git a/log-tree.c b/log-tree.c index 4618dd04ca..282510b105 100644 --- a/log-tree.c +++ b/log-tree.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "diff.h" #include "commit.h" #include "tag.h" diff --git a/mailinfo.c b/mailinfo.c index 68037758f2..aaed3870a4 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "utf8.h" #include "strbuf.h" #include "mailinfo.h" diff --git a/merge-recursive.c b/merge-recursive.c index 62decd51cc..a85144c23a 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -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" diff --git a/notes-utils.c b/notes-utils.c index 24a33616a4..9d7fdd6354 100644 --- a/notes-utils.c +++ b/notes-utils.c @@ -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 542563b280..dbcfef4d7a 100644 --- 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 c113d898a4..4dd9e1b265 100644 --- a/pager.c +++ b/pager.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "run-command.h" #include "sigchain.h" diff --git a/parse-options.c b/parse-options.c index a23a1e67f0..cbf84a6048 100644 --- a/parse-options.c +++ b/parse-options.c @@ -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" diff --git a/pathspec.c b/pathspec.c index 50f76fff45..e4659b1440 100644 --- a/pathspec.c +++ b/pathspec.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "dir.h" #include "pathspec.h" #include "attr.h" diff --git a/pretty.c b/pretty.c index d0f86f5d85..06a1f13c60 100644 --- 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" diff --git a/prompt.c b/prompt.c index 75406390c6..6d5885d009 100644 --- 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" diff --git a/read-cache.c b/read-cache.c index 0d0081a11b..e623e075de 100644 --- a/read-cache.c +++ b/read-cache.c @@ -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 df75f8e0d6..c0cd259141 100644 --- 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" diff --git a/refs/files-backend.c b/refs/files-backend.c index 83ea080e01..1d530f6020 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1,4 +1,5 @@ #include "../cache.h" +#include "../config.h" #include "../refs.h" #include "refs-internal.h" #include "ref-cache.h" diff --git a/remote-curl.c b/remote-curl.c index ece45993da..0053b09549 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "remote.h" #include "strbuf.h" #include "walker.h" diff --git a/remote.c b/remote.c index 801137c72e..6ef03bb730 100644 --- 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" diff --git a/rerere.c b/rerere.c index 3bd55caf3b..344d6aa818 100644 --- 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" diff --git a/send-pack.c b/send-pack.c index 78bb34ebec..ed3cee3211 100644 --- a/send-pack.c +++ b/send-pack.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "config.h" #include "commit.h" #include "refs.h" #include "pkt-line.h" diff --git a/sequencer.c b/sequencer.c index 10c3b4ff81..7356a93562 100644 --- a/sequencer.c +++ b/sequencer.c @@ -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 ba3241bf02..c45443f696 100644 --- a/setup.c +++ b/setup.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "dir.h" #include "string-list.h" diff --git a/sha1_file.c b/sha1_file.c index 59a4ed2ed3..44561e0b92 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -7,6 +7,7 @@ * creation etc. */ #include "cache.h" +#include "config.h" #include "string-list.h" #include "lockfile.h" #include "delta.h" diff --git a/sha1_name.c b/sha1_name.c index 8eec9f7c1b..7e1e86c97a 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "tag.h" #include "commit.h" #include "tree.h" diff --git a/submodule-config.c b/submodule-config.c index 4f58491ddb..d8f8d5ea32 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "submodule-config.h" #include "submodule.h" #include "strbuf.h" diff --git a/submodule.c b/submodule.c index d3299e29c0..8cfcb3bedd 100644 --- a/submodule.c +++ b/submodule.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "submodule-config.h" #include "submodule.h" #include "dir.h" diff --git a/t/helper/test-config.c b/t/helper/test-config.c index 8e3ed6a76c..1a7b8bd3d6 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "string-list.h" /* diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c index 2f144d539a..c6c57bba0d 100644 --- a/t/helper/test-submodule-config.c +++ b/t/helper/test-submodule-config.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "submodule-config.h" #include "submodule.h" diff --git a/trailer.c b/trailer.c index 11f0b9fb40..751b56c009 100644 --- 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" diff --git a/transport.c b/transport.c index 4d33138a75..6096f82586 100644 --- a/transport.c +++ b/transport.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "transport.h" #include "run-command.h" #include "pkt-line.h" diff --git a/unpack-trees.c b/unpack-trees.c index aa15111fef..e7b5a21ef7 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -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" diff --git a/upload-pack.c b/upload-pack.c index ffb028d623..7581a51960 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "refs.h" #include "pkt-line.h" #include "sideband.h" diff --git a/userdiff.c b/userdiff.c index 8b732e40bc..2c1502f719 100644 --- a/userdiff.c +++ b/userdiff.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "userdiff.h" #include "attr.h" diff --git a/versioncmp.c b/versioncmp.c index 9f81dc1062..069ee94a4d 100644 --- a/versioncmp.c +++ b/versioncmp.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "string-list.h" /* diff --git a/wrapper.c b/wrapper.c index d837417709..487a9f7532 100644 --- 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) { diff --git a/xdiff-interface.c b/xdiff-interface.c index 060038c2d6..5ac07d7348 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "config.h" #include "xdiff-interface.h" #include "xdiff/xtypes.h" #include "xdiff/xdiffi.h" -- cgit v1.2.3 From d3fb71b3cb36971608a46744261e6b5f8802e784 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 14 Jun 2017 11:07:37 -0700 Subject: setup: teach discover_git_directory to respect the commondir Currently 'discover_git_directory' only looks at the gitdir to determine if a git directory was discovered. This causes a problem in the event that the gitdir which was discovered was in fact a per-worktree git directory and not the common git directory. This is because the repository config, which is checked to verify the repository's format, is stored in the commondir and not in the per-worktree gitdir. Correct this behavior by checking the config stored in the commondir. It will also be of use for callers to have access to the commondir, so lets also return that upon successfully discovering a git directory. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- cache.h | 15 +++++++++------ config.c | 10 ++++++---- setup.c | 17 +++++++++++------ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/cache.h b/cache.h index 160ff81aa7..82f39f7a9e 100644 --- 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); diff --git a/config.c b/config.c index eec7613e04..e8dbf9e64a 100644 --- a/config.c +++ b/config.c @@ -1639,7 +1639,8 @@ 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; @@ -1653,12 +1654,13 @@ 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.git_dir = gitdir.buf; git_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/setup.c b/setup.c index c45443f696..4e38cf2a4f 100644 --- a/setup.c +++ b/setup.c @@ -941,19 +941,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; } /* @@ -969,8 +971,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); @@ -978,11 +982,12 @@ const char *discover_git_directory(struct strbuf *gitdir) warning("ignoring git dir '%s': %s", gitdir->buf + gitdir_offset, err.buf); strbuf_release(&err); + strbuf_setlen(commondir, commondir_offset); strbuf_setlen(gitdir, gitdir_offset); - return NULL; + return -1; } - return gitdir->buf + gitdir_offset; + return 0; } const char *setup_git_directory_gently(int *nongit_ok) -- cgit v1.2.3 From a577fb5fdc53a4729eeedc2922d1461350b92f73 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 14 Jun 2017 11:07:38 -0700 Subject: config: respect commondir Worktrees present an interesting problem when it comes to the config. Historically we could assume that the per-repository config lives at 'gitdir/config', but since worktrees were introduced this isn't the case anymore. There is currently no way to specify per-worktree configuration, and as such the repository config is shared with all worktrees and is located at 'commondir/config'. Many users of the config machinery correctly set 'config_options.git_dir' with the repository's commondir, allowing the config to be properly loaded when operating in a worktree. But other's, like 'read_early_config()', set 'config_options.git_dir' with the repository's gitdir which can be incorrect when using worktrees. To fix this issue, and to make things less ambiguous, lets add a 'commondir' field to the 'config_options' struct and have all callers properly set both the 'git_dir' and 'commondir' fields so that the config machinery is able to properly find the repository's config. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- config.c | 11 +++++++---- config.h | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/config.c b/config.c index e8dbf9e64a..edc0d17708 100644 --- a/config.c +++ b/config.c @@ -1531,8 +1531,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); + if (opts->commondir) + repo_config = mkpathdup("%s/config", opts->commondir); else if (have_git_dir()) repo_config = git_pathdup("config"); else @@ -1644,7 +1644,8 @@ void read_early_config(config_fn_t cb, void *data) 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 @@ -1654,8 +1655,10 @@ 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(&commondir, &gitdir)) + } else if (!discover_git_directory(&commondir, &gitdir)) { + opts.commondir = commondir.buf; opts.git_dir = gitdir.buf; + } git_config_with_options(cb, data, NULL, &opts); diff --git a/config.h b/config.h index c70599bd5f..63b92784cd 100644 --- a/config.h +++ b/config.h @@ -30,6 +30,7 @@ enum config_origin_type { struct config_options { unsigned int respect_includes : 1; + const char *commondir; const char *git_dir; }; -- cgit v1.2.3 From dc8441fdb4598f54865a5c783d1f86c1e0bcb6dc Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 14 Jun 2017 11:07:39 -0700 Subject: config: don't implicitly use gitdir or commondir 'git_config_with_options()' takes a 'config_options' struct which contains feilds for 'git_dir' and 'commondir'. If those feilds happen to be NULL the config machinery falls back to querying global repository state. Let's change this and instead use these fields in the 'config_options' struct explicilty all the time. Since the API is slightly changing to require these two fields to be set if callers want the config machinery to load the repository's config, let's change the name to 'config_with_optison()'. This allows the config machinery to not implicitly rely on any global repository state. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/config.c | 26 +++++++++++++++----------- config.c | 21 +++++++++++---------- config.h | 6 +++--- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index b2045cd6c3..1fc6471f37 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -243,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; @@ -321,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) @@ -353,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")) @@ -442,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; @@ -536,6 +536,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'; @@ -580,9 +584,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); diff --git a/config.c b/config.c index edc0d17708..ca9e9efec1 100644 --- a/config.c +++ b/config.c @@ -218,8 +218,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; @@ -1533,8 +1531,6 @@ static int do_git_config_sequence(const struct config_options *opts, if (opts->commondir) repo_config = mkpathdup("%s/config", opts->commondir); - else if (have_git_dir()) - repo_config = git_pathdup("config"); else repo_config = NULL; @@ -1565,9 +1561,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; @@ -1598,9 +1594,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 @@ -1660,7 +1661,7 @@ void read_early_config(config_fn_t cb, void *data) opts.git_dir = gitdir.buf; } - git_config_with_options(cb, data, NULL, &opts); + config_with_options(cb, data, NULL, &opts); strbuf_release(&commondir); strbuf_release(&gitdir); diff --git a/config.h b/config.h index 63b92784cd..9e038cce25 100644 --- a/config.h +++ b/config.h @@ -45,9 +45,9 @@ 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 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 *); -- cgit v1.2.3