diff options
author | Junio C Hamano <junkio@cox.net> | 2006-05-19 17:30:34 -0700 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-05-19 17:30:34 -0700 |
commit | bf78d1a6cb65fe877a8d90b9d4ec95678621ff17 (patch) | |
tree | 29371f4937eab3daecf9ba01147a1c12b1e21016 /builtin-add.c | |
parent | Merge branch 'eb/quilt' into next (diff) | |
parent | Add builtin "git rm" command (diff) | |
download | tgif-bf78d1a6cb65fe877a8d90b9d4ec95678621ff17.tar.xz |
Merge branch 'lt/dirwalk' into next
* lt/dirwalk:
Add builtin "git rm" command
Move pathspec matching from builtin-add.c into dir.c
Diffstat (limited to 'builtin-add.c')
-rw-r--r-- | builtin-add.c | 82 |
1 files changed, 1 insertions, 81 deletions
diff --git a/builtin-add.c b/builtin-add.c index 2afb82d6c1..02fe38b0c4 100644 --- a/builtin-add.c +++ b/builtin-add.c @@ -13,86 +13,6 @@ static const char builtin_add_usage[] = "git-add [-n] [-v] <filepattern>..."; -static int common_prefix(const char **pathspec) -{ - const char *path, *slash, *next; - int prefix; - - if (!pathspec) - return 0; - - path = *pathspec; - slash = strrchr(path, '/'); - if (!slash) - return 0; - - prefix = slash - path + 1; - while ((next = *++pathspec) != NULL) { - int len = strlen(next); - if (len >= prefix && !memcmp(path, next, len)) - continue; - for (;;) { - if (!len) - return 0; - if (next[--len] != '/') - continue; - if (memcmp(path, next, len+1)) - continue; - prefix = len + 1; - break; - } - } - return prefix; -} - -static int match_one(const char *match, const char *name, int namelen) -{ - int matchlen; - - /* If the match was just the prefix, we matched */ - matchlen = strlen(match); - if (!matchlen) - return 1; - - /* - * If we don't match the matchstring exactly, - * we need to match by fnmatch - */ - if (strncmp(match, name, matchlen)) - return !fnmatch(match, name, 0); - - /* - * If we did match the string exactly, we still - * need to make sure that it happened on a path - * component boundary (ie either the last character - * of the match was '/', or the next character of - * the name was '/' or the terminating NUL. - */ - return match[matchlen-1] == '/' || - name[matchlen] == '/' || - !name[matchlen]; -} - -static int match(const char **pathspec, const char *name, int namelen, int prefix, char *seen) -{ - int retval; - const char *match; - - name += prefix; - namelen -= prefix; - - for (retval = 0; (match = *pathspec++) != NULL; seen++) { - if (retval & *seen) - continue; - match += prefix; - if (match_one(match, name, namelen)) { - retval = 1; - *seen = 1; - } - } - return retval; -} - static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix) { char *seen; @@ -108,7 +28,7 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p i = dir->nr; while (--i >= 0) { struct dir_entry *entry = *src++; - if (!match(pathspec, entry->name, entry->len, prefix, seen)) { + if (!match_pathspec(pathspec, entry->name, entry->len, prefix, seen)) { free(entry); continue; } |