parse_pathspec: support stripping submodule trailing slashes

This flag is equivalent to builtin/ls-files.c:strip_trailing_slashes() and is intended to replace that function when ls-files is converted to use parse_pathspec. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jul 14, 2013 at 15:35 UTC b69bb3fc271911317c12fd6ecce6fe1e0301a2b3
2 files changed +11
pathspec.c
+9
@@ -205,6 +205,15 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
205 *raw = item->match = match;
206 item->original = elt;
207 item->len = strlen(item->match);
208 +
209 + if ((flags & PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP) &&
210 + (item->len >= 1 && item->match[item->len - 1] == '/') &&
211 + (i = cache_name_pos(item->match, item->len - 1)) >= 0 &&
212 + S_ISGITLINK(active_cache[i]->ce_mode)) {
213 + item->len--;
214 + match[item->len] = '\0';
215 + }
216 +
217 if (limit_pathspec_to_literal())
218 item->nowildcard_len = item->len;
219 else
pathspec.h
+2
@@ -31,6 +31,8 @@ struct pathspec {
31 #define PATHSPEC_PREFER_CWD (1<<0) /* No args means match cwd */
32 #define PATHSPEC_PREFER_FULL (1<<1) /* No args means match everything */
33 #define PATHSPEC_MAXDEPTH_VALID (1<<2) /* max_depth field is valid */
34 +/* strip the trailing slash if the given path is a gitlink */
35 +#define PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP (1<<3)
36
37 extern int init_pathspec(struct pathspec *, const char **);
38 extern void parse_pathspec(struct pathspec *pathspec,