X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=dir.c;h=d1e5e5e5bfaea81cb46fc3e3f57df31c6ef1eb2a;hb=2844923d62a4c408bd59ddb2caacca4aa7eb86bc;hp=cb83332a261f97026f9c6273afb162245944dec7;hpb=28bf4ba014c9b41679f41580fa9e1cc294b240d9;p=git.git diff --git a/dir.c b/dir.c index cb83332a2..d1e5e5e5b 100644 --- a/dir.c +++ b/dir.c @@ -31,22 +31,22 @@ static int common_prefix(const char **pathspec) if (!slash) return 0; + /* + * The first 'prefix' characters of 'path' are common leading + * path components among the pathspecs we have seen so far, + * including the trailing slash. + */ prefix = slash - path + 1; while ((next = *++pathspec) != NULL) { - int len = strlen(next); - if (len >= prefix && !memcmp(path, next, prefix)) + int len, last_matching_slash = -1; + for (len = 0; len < prefix && next[len] == path[len]; len++) + if (next[len] == '/') + last_matching_slash = len; + if (len == prefix) continue; - len = prefix - 1; - for (;;) { - if (!len) - return 0; - if (next[--len] != '/') - continue; - if (memcmp(path, next, len+1)) - continue; - prefix = len + 1; - break; - } + if (last_matching_slash < 0) + return 0; + prefix = last_matching_slash + 1; } return prefix; } @@ -232,7 +232,7 @@ int add_excludes_from_file_to_list(const char *fname, { struct stat st; int fd, i; - size_t size; + size_t size = 0; char *buf, *entry; fd = open(fname, O_RDONLY); @@ -453,7 +453,7 @@ static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathna return dir->entries[dir->nr++] = dir_entry_new(pathname, len); } -static struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len) +struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len) { if (!cache_name_is_other(pathname, len)) return NULL; @@ -465,7 +465,7 @@ static struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pat enum exist_status { index_nonexistent = 0, index_directory, - index_gitdir, + index_gitdir }; /* @@ -533,7 +533,7 @@ static enum exist_status directory_exists_in_index(const char *dirname, int len) enum directory_treatment { show_directory, ignore_directory, - recurse_into_directory, + recurse_into_directory }; static enum directory_treatment treat_directory(struct dir_struct *dir, @@ -684,7 +684,7 @@ static int get_dtype(struct dirent *de, const char *path, int len) enum path_treatment { path_ignored, path_handled, - path_recurse, + path_recurse }; static enum path_treatment treat_one_path(struct dir_struct *dir, @@ -958,9 +958,14 @@ char *get_relative_cwd(char *buffer, int size, const char *dir) } if (*dir) return NULL; - if (*cwd == '/') + switch (*cwd) { + case '\0': + return cwd; + case '/': return cwd + 1; - return cwd; + default: + return NULL; + } } int is_inside_dir(const char *dir)