From 2c3b40799fcdb9d2dedc90134e4f3841af08bbe7 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Tue, 9 May 2017 12:17:58 -0700 Subject: [PATCH 1/6] pathspec: provide a more descriptive die message The current message displayed upon an internal error in 'init_pathspec_item()' isn't very descriptive and doesn't provide much context to where the error occurred. Update the error message to provide more context to where the error occured. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- pathspec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pathspec.c b/pathspec.c index 50f76fff45..904cfb7393 100644 --- a/pathspec.c +++ b/pathspec.c @@ -555,7 +555,7 @@ static void init_pathspec_item(struct pathspec_item *item, unsigned flags, * would trigger that. */ die_inside_submodule_path(item); - die ("BUG: item->nowildcard_len > item->len || item->prefix > item->len)"); + die ("BUG: error initializing pathspec_item"); } } From bdab972153a73815e04e9699406433e409ed28ab Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Tue, 9 May 2017 12:17:59 -0700 Subject: [PATCH 2/6] submodule: add die_in_unpopulated_submodule function Currently 'git add' is the only command which dies when launched from an unpopulated submodule (the place-holder directory for a submodule which hasn't been checked out). This is triggered implicitly by passing the PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE flag to 'parse_pathspec()'. Instead make this desire more explicit by creating a function 'die_in_unpopulated_submodule()' which dies if the provided 'prefix' has a leading path component which matches a submodule in the the index. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/add.c | 3 +++ pathspec.c | 29 ----------------------------- submodule.c | 30 ++++++++++++++++++++++++++++++ submodule.h | 2 ++ t/t6134-pathspec-in-submodule.sh | 6 +----- 5 files changed, 36 insertions(+), 34 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index 9f53f020d0..ec58e36796 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -17,6 +17,7 @@ #include "revision.h" #include "bulk-checkin.h" #include "argv-array.h" +#include "submodule.h" static const char * const builtin_add_usage[] = { N_("git add [] [--] ..."), @@ -379,6 +380,8 @@ int cmd_add(int argc, const char **argv, const char *prefix) if (read_cache() < 0) die(_("index file corrupt")); + die_in_unpopulated_submodule(&the_index, prefix); + /* * Check the "pathspec '%s' did not match any files" block * below before enabling new magic. diff --git a/pathspec.c b/pathspec.c index 904cfb7393..9b7634c5aa 100644 --- a/pathspec.c +++ b/pathspec.c @@ -424,27 +424,6 @@ static void strip_submodule_slash_expensive(struct pathspec_item *item) } } -static void die_inside_submodule_path(struct pathspec_item *item) -{ - int i; - - for (i = 0; i < active_nr; i++) { - struct cache_entry *ce = active_cache[i]; - int ce_len = ce_namelen(ce); - - if (!S_ISGITLINK(ce->ce_mode)) - continue; - - if (item->len < ce_len || - !(item->match[ce_len] == '/' || item->match[ce_len] == '\0') || - memcmp(ce->name, item->match, ce_len)) - continue; - - die(_("Pathspec '%s' is in submodule '%.*s'"), - item->original, ce_len, ce->name); - } -} - /* * Perform the initialization of a pathspec_item based on a pathspec element. */ @@ -547,14 +526,6 @@ static void init_pathspec_item(struct pathspec_item *item, unsigned flags, /* sanity checks, pathspec matchers assume these are sane */ if (item->nowildcard_len > item->len || item->prefix > item->len) { - /* - * This case can be triggered by the user pointing us to a - * pathspec inside a submodule, which is an input error. - * Detect that here and complain, but fallback in the - * non-submodule case to a BUG, as we have no idea what - * would trigger that. - */ - die_inside_submodule_path(item); die ("BUG: error initializing pathspec_item"); } } diff --git a/submodule.c b/submodule.c index d3299e29c0..885663c421 100644 --- a/submodule.c +++ b/submodule.c @@ -282,6 +282,36 @@ int is_submodule_populated_gently(const char *path, int *return_error_code) return ret; } +/* + * Dies if the provided 'prefix' corresponds to an unpopulated submodule + */ +void die_in_unpopulated_submodule(const struct index_state *istate, + const char *prefix) +{ + int i, prefixlen; + + if (!prefix) + return; + + prefixlen = strlen(prefix); + + for (i = 0; i < istate->cache_nr; i++) { + struct cache_entry *ce = istate->cache[i]; + int ce_len = ce_namelen(ce); + + if (!S_ISGITLINK(ce->ce_mode)) + continue; + if (prefixlen <= ce_len) + continue; + if (strncmp(ce->name, prefix, ce_len)) + continue; + if (prefix[ce_len] != '/') + continue; + + die(_("in unpopulated submodule '%s'"), ce->name); + } +} + int parse_submodule_update_strategy(const char *value, struct submodule_update_strategy *dst) { diff --git a/submodule.h b/submodule.h index 1277480add..d11b4da40f 100644 --- a/submodule.h +++ b/submodule.h @@ -49,6 +49,8 @@ extern int is_submodule_initialized(const char *path); * Otherwise the return error code is the same as of resolve_gitdir_gently. */ extern int is_submodule_populated_gently(const char *path, int *return_error_code); +extern void die_in_unpopulated_submodule(const struct index_state *istate, + const char *prefix); extern int parse_submodule_update_strategy(const char *value, struct submodule_update_strategy *dst); extern const char *submodule_strategy_to_string(const struct submodule_update_strategy *s); diff --git a/t/t6134-pathspec-in-submodule.sh b/t/t6134-pathspec-in-submodule.sh index fd401ca605..0f1cb49ced 100755 --- a/t/t6134-pathspec-in-submodule.sh +++ b/t/t6134-pathspec-in-submodule.sh @@ -24,13 +24,9 @@ test_expect_success 'error message for path inside submodule' ' test_cmp expect actual ' -cat <expect -fatal: Pathspec '.' is in submodule 'sub' -EOF - test_expect_success 'error message for path inside submodule from within submodule' ' test_must_fail git -C sub add . 2>actual && - test_cmp expect actual + test_i18ngrep "in unpopulated submodule" actual ' test_done From c08397e3aa46fd0f0da29dfe5b257839b9c5d1c8 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 11 May 2017 15:04:24 -0700 Subject: [PATCH 3/6] pathspec: remove PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE flag Since (ae8d08242 pathspec: pass directory indicator to match_pathspec_item()) the path matching logic has been able to cope with submodules without needing to strip off a trailing slash if a path refers to a submodule. Since the stripping the trailing slash is no longer necessary, remove the PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE flag. In addition, factor out the logic which dies if a path decends into a submodule so that it can still be used as a check after a pathspec struct has been initialized. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/add.c | 5 +++-- builtin/check-ignore.c | 4 +++- pathspec.c | 29 ----------------------------- pathspec.h | 14 +++----------- submodule.c | 33 +++++++++++++++++++++++++++++++++ submodule.h | 2 ++ 6 files changed, 44 insertions(+), 43 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index ec58e36796..86770d6af4 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -388,10 +388,11 @@ int cmd_add(int argc, const char **argv, const char *prefix) */ parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_FULL | - PATHSPEC_SYMLINK_LEADING_PATH | - PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE, + PATHSPEC_SYMLINK_LEADING_PATH, prefix, argv); + die_path_inside_submodule(&the_index, &pathspec); + if (add_new_files) { int baselen; diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c index 1d73d3ca3d..91040a4b04 100644 --- a/builtin/check-ignore.c +++ b/builtin/check-ignore.c @@ -4,6 +4,7 @@ #include "quote.h" #include "pathspec.h" #include "parse-options.h" +#include "submodule.h" static int quiet, verbose, stdin_paths, show_non_matching, no_index; static const char * const check_ignore_usage[] = { @@ -87,10 +88,11 @@ static int check_ignore(struct dir_struct *dir, parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC & ~PATHSPEC_FROMTOP, PATHSPEC_SYMLINK_LEADING_PATH | - PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE | PATHSPEC_KEEP_ORDER, prefix, argv); + die_path_inside_submodule(&the_index, &pathspec); + /* * look for pathspecs matching entries in the index, since these * should not be ignored, in order to be consistent with diff --git a/pathspec.c b/pathspec.c index 9b7634c5aa..e424312786 100644 --- a/pathspec.c +++ b/pathspec.c @@ -398,32 +398,6 @@ static void strip_submodule_slash_cheap(struct pathspec_item *item) } } -static void strip_submodule_slash_expensive(struct pathspec_item *item) -{ - int i; - - for (i = 0; i < active_nr; i++) { - struct cache_entry *ce = active_cache[i]; - int ce_len = ce_namelen(ce); - - if (!S_ISGITLINK(ce->ce_mode)) - continue; - - if (item->len <= ce_len || item->match[ce_len] != '/' || - memcmp(ce->name, item->match, ce_len)) - continue; - - if (item->len == ce_len + 1) { - /* strip trailing slash */ - item->len--; - item->match[item->len] = '\0'; - } else { - die(_("Pathspec '%s' is in submodule '%.*s'"), - item->original, ce_len, ce->name); - } - } -} - /* * Perform the initialization of a pathspec_item based on a pathspec element. */ @@ -499,9 +473,6 @@ static void init_pathspec_item(struct pathspec_item *item, unsigned flags, if (flags & PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP) strip_submodule_slash_cheap(item); - if (flags & PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE) - strip_submodule_slash_expensive(item); - if (magic & PATHSPEC_LITERAL) { item->nowildcard_len = item->len; } else { diff --git a/pathspec.h b/pathspec.h index 55e976972c..3729efa85c 100644 --- a/pathspec.h +++ b/pathspec.h @@ -62,23 +62,15 @@ struct pathspec { #define PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP (1<<3) /* die if a symlink is part of the given path's directory */ #define PATHSPEC_SYMLINK_LEADING_PATH (1<<4) -/* - * This is like a combination of ..LEADING_PATH and .._SLASH_CHEAP - * (but not the same): it strips the trailing slash if the given path - * is a gitlink but also checks and dies if gitlink is part of the - * leading path (i.e. the given path goes beyond a submodule). It's - * safer than _SLASH_CHEAP and also more expensive. - */ -#define PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE (1<<5) -#define PATHSPEC_PREFIX_ORIGIN (1<<6) -#define PATHSPEC_KEEP_ORDER (1<<7) +#define PATHSPEC_PREFIX_ORIGIN (1<<5) +#define PATHSPEC_KEEP_ORDER (1<<6) /* * For the callers that just need pure paths from somewhere else, not * from command line. Global --*-pathspecs options are ignored. No * magic is parsed in each pathspec either. If PATHSPEC_LITERAL is * allowed, then it will automatically set for every pathspec. */ -#define PATHSPEC_LITERAL_PATH (1<<8) +#define PATHSPEC_LITERAL_PATH (1<<7) extern void parse_pathspec(struct pathspec *pathspec, unsigned magic_mask, diff --git a/submodule.c b/submodule.c index 885663c421..80851d0447 100644 --- a/submodule.c +++ b/submodule.c @@ -312,6 +312,39 @@ void die_in_unpopulated_submodule(const struct index_state *istate, } } +/* + * Dies if any paths in the provided pathspec descends into a submodule + */ +void die_path_inside_submodule(const struct index_state *istate, + const struct pathspec *ps) +{ + int i, j; + + for (i = 0; i < istate->cache_nr; i++) { + struct cache_entry *ce = istate->cache[i]; + int ce_len = ce_namelen(ce); + + if (!S_ISGITLINK(ce->ce_mode)) + continue; + + for (j = 0; j < ps->nr ; j++) { + const struct pathspec_item *item = &ps->items[j]; + + if (item->len <= ce_len) + continue; + if (item->match[ce_len] != '/') + continue; + if (strncmp(ce->name, item->match, ce_len)) + continue; + if (item->len == ce_len + 1) + continue; + + die(_("Pathspec '%s' is in submodule '%.*s'"), + item->original, ce_len, ce->name); + } + } +} + int parse_submodule_update_strategy(const char *value, struct submodule_update_strategy *dst) { diff --git a/submodule.h b/submodule.h index d11b4da40f..266d81f1c4 100644 --- a/submodule.h +++ b/submodule.h @@ -51,6 +51,8 @@ extern int is_submodule_initialized(const char *path); extern int is_submodule_populated_gently(const char *path, int *return_error_code); extern void die_in_unpopulated_submodule(const struct index_state *istate, const char *prefix); +extern void die_path_inside_submodule(const struct index_state *istate, + const struct pathspec *ps); extern int parse_submodule_update_strategy(const char *value, struct submodule_update_strategy *dst); extern const char *submodule_strategy_to_string(const struct submodule_update_strategy *s); From cbca060e102aedcedbd1c4b5394aeed24885d5de Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 11 May 2017 15:04:25 -0700 Subject: [PATCH 4/6] ls-files: prevent prune_cache from overeagerly pruning submodules Since (ae8d08242 pathspec: pass directory indicator to match_pathspec_item()) the path matching logic has been able to cope with submodules without needing to strip off a trailing slash if a path refers to a submodule. ls-files is the only caller of 'parse_pathspec()' which relies on the behavior of the PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP flag because it uses the result to construct a common prefix of all provided pathspecs which is then used to prune the index of all entries which don't have that prefix. Since submodules entries in the index don't have a trailing slash 'prune_cache()' will be overeager and prune a submodule 'sub' if the common prefix is 'sub/'. To correct this behavior, only prune entries which don't match up to, but not including, a trailing slash of the common prefix. This is in preparation to remove the PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP flag in a later patch. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/ls-files.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index a6c70dbe9e..1f3d478443 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -97,7 +97,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent) { int len = max_prefix_len; - if (len >= ent->len) + if (len > ent->len) die("git ls-files: internal error - directory entry not superset of prefix"); if (!dir_path_match(ent, &pathspec, len, ps_matched)) @@ -238,7 +238,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce) strbuf_addstr(&name, super_prefix); strbuf_addstr(&name, ce->name); - if (len >= ce_namelen(ce)) + if (len > ce_namelen(ce)) die("git ls-files: internal error - cache entry not superset of prefix"); if (recurse_submodules && S_ISGITLINK(ce->ce_mode) && @@ -403,6 +403,25 @@ static void prune_cache(const char *prefix, size_t prefixlen) active_nr = last - pos; } +static int get_common_prefix_len(const char *common_prefix) +{ + int common_prefix_len; + + if (!common_prefix) + return 0; + + common_prefix_len = strlen(common_prefix); + + /* + * If the prefix has a trailing slash, strip it so that submodules wont + * be pruned from the index. + */ + if (common_prefix[common_prefix_len - 1] == '/') + common_prefix_len--; + + return common_prefix_len; +} + /* * Read the tree specified with --with-tree option * (typically, HEAD) into stage #1 and then @@ -624,8 +643,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) "--error-unmatch"); parse_pathspec(&pathspec, 0, - PATHSPEC_PREFER_CWD | - PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP, + PATHSPEC_PREFER_CWD, prefix, argv); /* @@ -637,7 +655,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) max_prefix = NULL; else max_prefix = common_prefix(&pathspec); - max_prefix_len = max_prefix ? strlen(max_prefix) : 0; + max_prefix_len = get_common_prefix_len(max_prefix); + + prune_cache(max_prefix, max_prefix_len); /* Treat unmatching pathspec elements as errors */ if (pathspec.nr && error_unmatch) @@ -651,7 +671,6 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) show_killed || show_modified || show_resolve_undo)) show_cached = 1; - prune_cache(max_prefix, max_prefix_len); if (with_tree) { /* * Basic sanity check; show-stages and show-unmerged From 2249d4dbc197d45da5407cbc80b2461e49bb8785 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 11 May 2017 15:04:26 -0700 Subject: [PATCH 5/6] pathspec: remove PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP Since (ae8d08242 pathspec: pass directory indicator to match_pathspec_item()) the path matching logic has been able to cope with submodules without needing to strip off a trailing slash if a path refers to a submodule. Since stripping the slash is no longer necessary, remove the PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP flag. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/reset.c | 1 - builtin/rm.c | 3 +-- builtin/submodule--helper.c | 3 +-- pathspec.c | 15 --------------- pathspec.h | 10 ++++------ 5 files changed, 6 insertions(+), 26 deletions(-) diff --git a/builtin/reset.c b/builtin/reset.c index fc3b906c47..5db2adc4c4 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -236,7 +236,6 @@ static void parse_args(struct pathspec *pathspec, parse_pathspec(pathspec, 0, PATHSPEC_PREFER_FULL | - PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP | (patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0), prefix, argv); } diff --git a/builtin/rm.c b/builtin/rm.c index fb79dcab18..7c323d0123 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -271,8 +271,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix) die(_("index file corrupt")); parse_pathspec(&pathspec, 0, - PATHSPEC_PREFER_CWD | - PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP, + PATHSPEC_PREFER_CWD, prefix, argv); refresh_index(&the_index, REFRESH_QUIET, &pathspec, NULL, NULL); diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 566a5b6a6f..8cc648d85b 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -233,8 +233,7 @@ static int module_list_compute(int argc, const char **argv, int i, result = 0; char *ps_matched = NULL; parse_pathspec(pathspec, 0, - PATHSPEC_PREFER_FULL | - PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP, + PATHSPEC_PREFER_FULL, prefix, argv); if (pathspec->nr) diff --git a/pathspec.c b/pathspec.c index e424312786..1e5df2316e 100644 --- a/pathspec.c +++ b/pathspec.c @@ -386,18 +386,6 @@ static const char *parse_element_magic(unsigned *magic, int *prefix_len, return parse_short_magic(magic, elem); } -static void strip_submodule_slash_cheap(struct pathspec_item *item) -{ - if (item->len >= 1 && item->match[item->len - 1] == '/') { - int i = cache_name_pos(item->match, item->len - 1); - - if (i >= 0 && S_ISGITLINK(active_cache[i]->ce_mode)) { - item->len--; - item->match[item->len] = '\0'; - } - } -} - /* * Perform the initialization of a pathspec_item based on a pathspec element. */ @@ -470,9 +458,6 @@ static void init_pathspec_item(struct pathspec_item *item, unsigned flags, item->original = xstrdup(elt); } - if (flags & PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP) - strip_submodule_slash_cheap(item); - if (magic & PATHSPEC_LITERAL) { item->nowildcard_len = item->len; } else { diff --git a/pathspec.h b/pathspec.h index 3729efa85c..6671b95770 100644 --- a/pathspec.h +++ b/pathspec.h @@ -58,19 +58,17 @@ struct pathspec { #define PATHSPEC_PREFER_CWD (1<<0) /* No args means match cwd */ #define PATHSPEC_PREFER_FULL (1<<1) /* No args means match everything */ #define PATHSPEC_MAXDEPTH_VALID (1<<2) /* max_depth field is valid */ -/* strip the trailing slash if the given path is a gitlink */ -#define PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP (1<<3) /* die if a symlink is part of the given path's directory */ -#define PATHSPEC_SYMLINK_LEADING_PATH (1<<4) -#define PATHSPEC_PREFIX_ORIGIN (1<<5) -#define PATHSPEC_KEEP_ORDER (1<<6) +#define PATHSPEC_SYMLINK_LEADING_PATH (1<<3) +#define PATHSPEC_PREFIX_ORIGIN (1<<4) +#define PATHSPEC_KEEP_ORDER (1<<5) /* * For the callers that just need pure paths from somewhere else, not * from command line. Global --*-pathspecs options are ignored. No * magic is parsed in each pathspec either. If PATHSPEC_LITERAL is * allowed, then it will automatically set for every pathspec. */ -#define PATHSPEC_LITERAL_PATH (1<<7) +#define PATHSPEC_LITERAL_PATH (1<<6) extern void parse_pathspec(struct pathspec *pathspec, unsigned magic_mask, From 08de9151a8a67f29a3a5a36931298237d78ca736 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 11 May 2017 15:04:27 -0700 Subject: [PATCH 6/6] pathspec: convert find_pathspecs_matching_against_index to take an index Convert find_pathspecs_matching_against_index to take an index parameter. In addition mark pathspec.c with NO_THE_INDEX_COMPATIBILITY_MACROS now that it doesn't use any cache macros or reference 'the_index'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/add.c | 4 ++-- builtin/check-ignore.c | 2 +- pathspec.c | 11 +++++++---- pathspec.h | 7 +++++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index 86770d6af4..0365a52098 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -136,7 +136,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec, *dst++ = entry; } dir->nr = dst - dir->entries; - add_pathspec_matches_against_index(pathspec, seen); + add_pathspec_matches_against_index(pathspec, &the_index, seen); return seen; } @@ -418,7 +418,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) int i; if (!seen) - seen = find_pathspecs_matching_against_index(&pathspec); + seen = find_pathspecs_matching_against_index(&pathspec, &the_index); /* * file_exists() assumes exact match diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c index 91040a4b04..7629018a56 100644 --- a/builtin/check-ignore.c +++ b/builtin/check-ignore.c @@ -98,7 +98,7 @@ static int check_ignore(struct dir_struct *dir, * should not be ignored, in order to be consistent with * 'git status', 'git add' etc. */ - seen = find_pathspecs_matching_against_index(&pathspec); + seen = find_pathspecs_matching_against_index(&pathspec, &the_index); for (i = 0; i < pathspec.nr; i++) { full_path = pathspec.items[i].match; exclude = NULL; diff --git a/pathspec.c b/pathspec.c index 1e5df2316e..828405021f 100644 --- a/pathspec.c +++ b/pathspec.c @@ -1,3 +1,4 @@ +#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "dir.h" #include "pathspec.h" @@ -17,6 +18,7 @@ * to use find_pathspecs_matching_against_index() instead. */ void add_pathspec_matches_against_index(const struct pathspec *pathspec, + const struct index_state *istate, char *seen) { int num_unmatched = 0, i; @@ -32,8 +34,8 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec, num_unmatched++; if (!num_unmatched) return; - 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]; ce_path_match(ce, pathspec, seen); } } @@ -46,10 +48,11 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec, * nature of the "closest" (i.e. most specific) matches which each of the * given pathspecs achieves against all items in the index. */ -char *find_pathspecs_matching_against_index(const struct pathspec *pathspec) +char *find_pathspecs_matching_against_index(const struct pathspec *pathspec, + const struct index_state *istate) { char *seen = xcalloc(pathspec->nr, 1); - add_pathspec_matches_against_index(pathspec, seen); + add_pathspec_matches_against_index(pathspec, istate, seen); return seen; } diff --git a/pathspec.h b/pathspec.h index 6671b95770..60e6500401 100644 --- a/pathspec.h +++ b/pathspec.h @@ -96,7 +96,10 @@ static inline int ps_strcmp(const struct pathspec_item *item, return strcmp(s1, s2); } -extern char *find_pathspecs_matching_against_index(const struct pathspec *pathspec); -extern void add_pathspec_matches_against_index(const struct pathspec *pathspec, char *seen); +extern void add_pathspec_matches_against_index(const struct pathspec *pathspec, + const struct index_state *istate, + char *seen); +extern char *find_pathspecs_matching_against_index(const struct pathspec *pathspec, + const struct index_state *istate); #endif /* PATHSPEC_H */