Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2020-01-31 23:16:09 +0300
committerJunio C Hamano <gitster@pobox.com>2020-02-01 00:05:29 +0300
commit4f52c2ce6c578896964e960f6017510f0efd3f46 (patch)
tree6e35b5a1de6c7d5a73319f2fe96cb0f422155027 /dir.c
parent9abc60f8015d060d3f3433b105648a4725c97bd1 (diff)
sparse-checkout: properly match escaped characters
In cone mode, the sparse-checkout feature uses hashset containment queries to match paths. Make this algorithm respect escaped asterisk (*) and backslash (\) characters. Create dup_and_filter_pattern() method to convert a pattern by removing escape characters and dropping an optional "/*" at the end. This method is available in dir.h as we will use it in builtin/sparse-checkout.c in a later change. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/dir.c b/dir.c
index 71d28331f3..7ac0920b71 100644
--- a/dir.c
+++ b/dir.c
@@ -630,6 +630,36 @@ int pl_hashmap_cmp(const void *unused_cmp_data,
return strncmp(ee1->pattern, ee2->pattern, min_len);
}
+static char *dup_and_filter_pattern(const char *pattern)
+{
+ char *set, *read;
+ size_t count = 0;
+ char *result = xstrdup(pattern);
+
+ set = result;
+ read = result;
+
+ while (*read) {
+ /* skip escape characters (once) */
+ if (*read == '\\')
+ read++;
+
+ *set = *read;
+
+ set++;
+ read++;
+ count++;
+ }
+ *set = 0;
+
+ if (count > 2 &&
+ *(set - 1) == '*' &&
+ *(set - 2) == '/')
+ *(set - 2) = 0;
+
+ return result;
+}
+
static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern *given)
{
struct pattern_entry *translated;
@@ -702,8 +732,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
goto clear_hashmaps;
}
- truncated = xstrdup(given->pattern);
- truncated[given->patternlen - 2] = 0;
+ truncated = dup_and_filter_pattern(given->pattern);
translated = xmalloc(sizeof(struct pattern_entry));
translated->pattern = truncated;
@@ -737,7 +766,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
translated = xmalloc(sizeof(struct pattern_entry));
- translated->pattern = xstrdup(given->pattern);
+ translated->pattern = dup_and_filter_pattern(given->pattern);
translated->patternlen = given->patternlen;
hashmap_entry_init(&translated->ent,
ignore_case ?