summaryrefslogtreecommitdiff
path: root/pathspec.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-05-30 02:16:40 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-05-30 02:16:40 (GMT)
commit3c5a78280fa5535050fe83b51cafb9ca51e8d9e8 (patch)
treec4872e1654f52d2e5e9c5160479b26c778697074 /pathspec.c
parent78089b71da60fcf846b2e7029a90db492f1d3a9d (diff)
parent08de9151a8a67f29a3a5a36931298237d78ca736 (diff)
downloadgit-3c5a78280fa5535050fe83b51cafb9ca51e8d9e8.zip
git-3c5a78280fa5535050fe83b51cafb9ca51e8d9e8.tar.gz
git-3c5a78280fa5535050fe83b51cafb9ca51e8d9e8.tar.bz2
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 'pathspec.c')
-rw-r--r--pathspec.c86
1 files changed, 8 insertions, 78 deletions
diff --git a/pathspec.c b/pathspec.c
index 50f76ff..8284050 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;
}
@@ -386,65 +389,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';
- }
- }
-}
-
-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);
- }
- }
-}
-
-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.
*/
@@ -517,12 +461,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 (flags & PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE)
- strip_submodule_slash_expensive(item);
-
if (magic & PATHSPEC_LITERAL) {
item->nowildcard_len = item->len;
} else {
@@ -547,15 +485,7 @@ 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: item->nowildcard_len > item->len || item->prefix > item->len)");
+ die ("BUG: error initializing pathspec_item");
}
}