diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-05-30 11:16:40 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-05-30 11:16:40 +0900 |
commit | 3c5a78280fa5535050fe83b51cafb9ca51e8d9e8 (patch) | |
tree | c4872e1654f52d2e5e9c5160479b26c778697074 /submodule.c | |
parent | 78089b71da60fcf846b2e7029a90db492f1d3a9d (diff) | |
parent | 08de9151a8a67f29a3a5a36931298237d78ca736 (diff) | |
download | git-3c5a78280fa5535050fe83b51cafb9ca51e8d9e8.tar.gz |
Merge branch 'bw/pathspec-sans-the-index'
Simplify parse_pathspec() codepath and stop it from looking at the
default in-core index.
* bw/pathspec-sans-the-index:
pathspec: convert find_pathspecs_matching_against_index to take an index
pathspec: remove PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP
ls-files: prevent prune_cache from overeagerly pruning submodules
pathspec: remove PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE flag
submodule: add die_in_unpopulated_submodule function
pathspec: provide a more descriptive die message
Diffstat (limited to 'submodule.c')
-rw-r--r-- | submodule.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/submodule.c b/submodule.c index 9d5ec5f084..bf5a93d16f 100644 --- a/submodule.c +++ b/submodule.c @@ -282,6 +282,69 @@ 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); + } +} + +/* + * 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) { |