diff options
author | Junio C Hamano <gitster@pobox.com> | 2009-01-25 17:13:11 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-01-25 17:13:11 -0800 |
commit | d64d4835b83669d5c9c8ce1989859efa803874db (patch) | |
tree | 6748e48171e74bb97dc56efa9e7d133a7674e1a2 /builtin-ls-files.c | |
parent | f18e6bef23809d2823c1a687f375b22c6af0e735 (diff) | |
parent | 0b50922abffb82c473182b03eb5bb47a978cceac (diff) | |
download | git-d64d4835b83669d5c9c8ce1989859efa803874db.tar.gz |
Merge branch 'cb/add-pathspec'
* cb/add-pathspec:
remove pathspec_match, use match_pathspec instead
clean up pathspec matching
Diffstat (limited to 'builtin-ls-files.c')
-rw-r--r-- | builtin-ls-files.c | 40 |
1 files changed, 2 insertions, 38 deletions
diff --git a/builtin-ls-files.c b/builtin-ls-files.c index f72eb85475..3434031295 100644 --- a/builtin-ls-files.c +++ b/builtin-ls-files.c @@ -36,42 +36,6 @@ static const char *tag_other = ""; static const char *tag_killed = ""; static const char *tag_modified = ""; - -/* - * Match a pathspec against a filename. The first "skiplen" characters - * are the common prefix - */ -int pathspec_match(const char **spec, char *ps_matched, - const char *filename, int skiplen) -{ - const char *m; - - while ((m = *spec++) != NULL) { - int matchlen = strlen(m + skiplen); - - if (!matchlen) - goto matched; - if (!strncmp(m + skiplen, filename + skiplen, matchlen)) { - if (m[skiplen + matchlen - 1] == '/') - goto matched; - switch (filename[skiplen + matchlen]) { - case '/': case '\0': - goto matched; - } - } - if (!fnmatch(m + skiplen, filename + skiplen, 0)) - goto matched; - if (ps_matched) - ps_matched++; - continue; - matched: - if (ps_matched) - *ps_matched = 1; - return 1; - } - return 0; -} - static void show_dir_entry(const char *tag, struct dir_entry *ent) { int len = prefix_len; @@ -80,7 +44,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent) if (len >= ent->len) die("git ls-files: internal error - directory entry not superset of prefix"); - if (pathspec && !pathspec_match(pathspec, ps_matched, ent->name, len)) + if (!match_pathspec(pathspec, ent->name, ent->len, len, ps_matched)) return; fputs(tag, stdout); @@ -156,7 +120,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce) if (len >= ce_namelen(ce)) die("git ls-files: internal error - cache entry not superset of prefix"); - if (pathspec && !pathspec_match(pathspec, ps_matched, ce->name, len)) + if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), len, ps_matched)) return; if (tag && *tag && show_valid_bit && |