Skip to content

Commit

Permalink
parse_pathspec: support stripping submodule trailing slashes
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Jul 15, 2013
1 parent 6330a17 commit b69bb3f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pathspec.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
*raw = item->match = match;
item->original = elt;
item->len = strlen(item->match);

if ((flags & PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP) &&
(item->len >= 1 && item->match[item->len - 1] == '/') &&
(i = cache_name_pos(item->match, item->len - 1)) >= 0 &&
S_ISGITLINK(active_cache[i]->ce_mode)) {
item->len--;
match[item->len] = '\0';
}

if (limit_pathspec_to_literal())
item->nowildcard_len = item->len;
else
Expand Down
2 changes: 2 additions & 0 deletions pathspec.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ struct pathspec {
#define PATHSPEC_PREFER_CWD (1<<0) /* No args means match cwd */
#define PATHSPEC_PREFER_FULL (1<<1) /* No args means match everything */
#define PATHSPEC_MAXDEPTH_VALID (1<<2) /* max_depth field is valid */
/* strip the trailing slash if the given path is a gitlink */
#define PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP (1<<3)

extern int init_pathspec(struct pathspec *, const char **);
extern void parse_pathspec(struct pathspec *pathspec,
Expand Down

0 comments on commit b69bb3f

Please sign in to comment.