New field plain_len is used to mark the first part of 'match' where no magic can be applied. It's not used though. tree_entry_interesting() should learn to utilize it. Now we can show get_pathspec() what magic a pathspec has. Make sure only certain magic is accepted because more will come in future and not all of them can be converted to plain string like PATHSPEC_FROMTOP. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- match_pathspec_depth() should also check for unsupported magic.. cache.h | 1 + setup.c | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/cache.h b/cache.h index fe46f1e..17df06f 100644 --- a/cache.h +++ b/cache.h @@ -548,6 +548,7 @@ struct pathspec { struct pathspec_item { const char *match; int len; + int plain_len; /* match[0..plain_len-1] does not have any kind of magic*/ unsigned magic; } *items; }; diff --git a/setup.c b/setup.c index 35db910..8f1c2c0 100644 --- a/setup.c +++ b/setup.c @@ -126,7 +126,8 @@ static struct pathspec_magic { * the prefix part must always match literally, and a single stupid * string cannot express such a case. */ -static const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt) +static const char *prefix_pathspec(struct pathspec_item *item, const char *prefix, + int prefixlen, const char *elt) { unsigned magic = 0; const char *copyfrom = elt; @@ -181,10 +182,17 @@ static const char *prefix_pathspec(const char *prefix, int prefixlen, const char copyfrom++; } + memset(item, 0, sizeof(*item)); + item->magic = magic; + if (magic & PATHSPEC_FROMTOP) - return xstrdup(copyfrom); - else - return prefix_path(prefix, prefixlen, copyfrom); + item->match = xstrdup(copyfrom); + else { + item->match = prefix_path(prefix, prefixlen, copyfrom); + item->plain_len = prefixlen; + } + item->len = strlen(item->match); + return 0; } const char **get_pathspec(const char *prefix, const char **pathspec) @@ -208,7 +216,11 @@ const char **get_pathspec(const char *prefix, const char **pathspec) dst = pathspec; prefixlen = prefix ? strlen(prefix) : 0; while (*src) { - *(dst++) = prefix_pathspec(prefix, prefixlen, *src); + struct pathspec_item item; + prefix_pathspec(&item, prefix, prefixlen, *src); + if (item.magic & ~PATHSPEC_FROMTOP) + die("Unsupported magic pathspec %s", *src); + *(dst++) = item.match; src++; } *dst = NULL; -- 1.7.3.1.256.g2539c.dirty -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html