* Given a subdirectory name and "dir" of the current directory, * search the subdir in "dir" and return it, or create a new one if it * does not exist in "dir". * * If "name" has the trailing slash, it'll be excluded in the search. */
| 1057 | * If "name" has the trailing slash, it'll be excluded in the search. |
| 1058 | */ |
| 1059 | static struct untracked_cache_dir *lookup_untracked(struct untracked_cache *uc, |
| 1060 | struct untracked_cache_dir *dir, |
| 1061 | const char *name, int len) |
| 1062 | { |
| 1063 | int first, last; |
| 1064 | struct untracked_cache_dir *d; |
| 1065 | if (!dir) |
| 1066 | return NULL; |
| 1067 | if (len && name[len - 1] == '/') |
| 1068 | len--; |
| 1069 | first = 0; |
| 1070 | last = dir->dirs_nr; |
| 1071 | while (last > first) { |
| 1072 | int cmp, next = first + ((last - first) >> 1); |
| 1073 | d = dir->dirs[next]; |
| 1074 | cmp = strncmp(name, d->name, len); |
| 1075 | if (!cmp && strlen(d->name) > len) |
| 1076 | cmp = -1; |
| 1077 | if (!cmp) |
| 1078 | return d; |
| 1079 | if (cmp < 0) { |
| 1080 | last = next; |
| 1081 | continue; |
| 1082 | } |
| 1083 | first = next+1; |
| 1084 | } |
| 1085 | |
| 1086 | uc->dir_created++; |
| 1087 | FLEX_ALLOC_MEM(d, name, name, len); |
| 1088 | |
| 1089 | ALLOC_GROW(dir->dirs, dir->dirs_nr + 1, dir->dirs_alloc); |
| 1090 | MOVE_ARRAY(dir->dirs + first + 1, dir->dirs + first, |
| 1091 | dir->dirs_nr - first); |
| 1092 | dir->dirs_nr++; |
| 1093 | dir->dirs[first] = d; |
| 1094 | return d; |
| 1095 | } |
| 1096 | |
| 1097 | static void do_invalidate_gitignore(struct untracked_cache_dir *dir) |
| 1098 | { |
no outgoing calls
no test coverage detected