@matheusbsbs / matheus-bagliano / commits / 0b50922abf
Fork 0

remove pathspec_match, use match_pathspec instead

Both versions have the same functionality. This removes any redundancy. This also adds makes two extensions to match_pathspec: - If pathspec is NULL, return 1. This reflects the behavior of git commands, for which no paths usually means "match all paths". - If seen is NULL, do not use it. Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Clemens Buchacher committed Jan 14, 2009 at 15:54 UTC 0b50922abffb82c473182b03eb5bb47a978cceac
5 files changed +17 -51
builtin-checkout.c
+3 -3
@@ -240,7 +240,7 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec,
240
241 for (pos = 0; pos < active_nr; pos++) {
242 struct cache_entry *ce = active_cache[pos];
243 - pathspec_match(pathspec, ps_matched, ce->name, 0);
243 + match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, ps_matched);
244 }
245
246 if (report_path_error(ps_matched, pathspec, 0))
@@ -249,7 +249,7 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec,
249 /* Any unmerged paths? */
250 for (pos = 0; pos < active_nr; pos++) {
251 struct cache_entry *ce = active_cache[pos];
252 - if (pathspec_match(pathspec, NULL, ce->name, 0)) {
252 + if (match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL)) {
253 if (!ce_stage(ce))
254 continue;
255 if (opts->force) {
@@ -274,7 +274,7 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec,
274 state.refresh_cache = 1;
275 for (pos = 0; pos < active_nr; pos++) {
276 struct cache_entry *ce = active_cache[pos];
277 - if (pathspec_match(pathspec, NULL, ce->name, 0)) {
277 + if (match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL)) {
278 if (!ce_stage(ce)) {
279 errs |= checkout_entry(ce, &state, NULL);
280 continue;
builtin-commit.c
+1 -1
@@ -166,7 +166,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
166 struct cache_entry *ce = active_cache[i];
167 if (ce->ce_flags & CE_UPDATE)
168 continue;
169 - if (!pathspec_match(pattern, m, ce->name, 0))
169 + if (!match_pathspec(pattern, ce->name, ce_namelen(ce), 0, m))
170 continue;
171 string_list_insert(ce->name, list);
172 }
builtin-ls-files.c
+2 -38
@@ -36,42 +36,6 @@ static const char *tag_other = "";
36 static const char *tag_killed = "";
37 static const char *tag_modified = "";
38
39 -
40 -/*
41 - * Match a pathspec against a filename. The first "skiplen" characters
42 - * are the common prefix
43 - */
44 -int pathspec_match(const char **spec, char *ps_matched,
45 - const char *filename, int skiplen)
46 -{
47 - const char *m;
48 -
49 - while ((m = *spec++) != NULL) {
50 - int matchlen = strlen(m + skiplen);
51 -
52 - if (!matchlen)
53 - goto matched;
54 - if (!strncmp(m + skiplen, filename + skiplen, matchlen)) {
55 - if (m[skiplen + matchlen - 1] == '/')
56 - goto matched;
57 - switch (filename[skiplen + matchlen]) {
58 - case '/': case '\0':
59 - goto matched;
60 - }
61 - }
62 - if (!fnmatch(m + skiplen, filename + skiplen, 0))
63 - goto matched;
64 - if (ps_matched)
65 - ps_matched++;
66 - continue;
67 - matched:
68 - if (ps_matched)
69 - *ps_matched = 1;
70 - return 1;
71 - }
72 - return 0;
73 -}
74 -
39 static void show_dir_entry(const char *tag, struct dir_entry *ent)
40 {
41 int len = prefix_len;
@@ -80,7 +44,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
44 if (len >= ent->len)
45 die("git ls-files: internal error - directory entry not superset of prefix");
46
83 - if (pathspec && !pathspec_match(pathspec, ps_matched, ent->name, len))
47 + if (!match_pathspec(pathspec, ent->name, ent->len, len, ps_matched))
48 return;
49
50 fputs(tag, stdout);
@@ -156,7 +120,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
120 if (len >= ce_namelen(ce))
121 die("git ls-files: internal error - cache entry not superset of prefix");
122
159 - if (pathspec && !pathspec_match(pathspec, ps_matched, ce->name, len))
123 + if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), len, ps_matched))
124 return;
125
126 if (tag && *tag && show_valid_bit &&
cache.h
-1
@@ -936,7 +936,6 @@ extern int ws_fix_copy(char *, const char *, int, unsigned, int *);
936 extern int ws_blank_line(const char *line, int len, unsigned ws_rule);
937
938 /* ls-files */
939 -int pathspec_match(const char **spec, char *matched, const char *filename, int skiplen);
939 int report_path_error(const char *ps_matched, const char **pathspec, int prefix_offset);
940 void overlay_tree_on_cache(const char *tree_name, const char *prefix);
941
dir.c
+11 -8
@@ -108,25 +108,28 @@ static int match_one(const char *match, const char *name, int namelen)
108 * and a mark is left in seen[] array for pathspec element that
109 * actually matched anything.
110 */
111 -int match_pathspec(const char **pathspec, const char *name, int namelen, int prefix, char *seen)
111 +int match_pathspec(const char **pathspec, const char *name, int namelen,
112 + int prefix, char *seen)
113 {
113 - int retval;
114 - const char *match;
114 + int i, retval = 0;
115 +
116 + if (!pathspec)
117 + return 1;
118
119 name += prefix;
120 namelen -= prefix;
121
119 - for (retval = 0; (match = *pathspec++) != NULL; seen++) {
122 + for (i = 0; pathspec[i] != NULL; i++) {
123 int how;
121 - if (*seen == MATCHED_EXACTLY)
124 + const char *match = pathspec[i] + prefix;
125 + if (seen && seen[i] == MATCHED_EXACTLY)
126 continue;
123 - match += prefix;
127 how = match_one(match, name, namelen);
128 if (how) {
129 if (retval < how)
130 retval = how;
128 - if (*seen < how)
129 - *seen = how;
131 + if (seen && seen[i] < how)
132 + seen[i] = how;
133 }
134 }
135 return retval;