| 235 | } |
| 236 | |
| 237 | static struct worktree *find_worktree_by_suffix(struct worktree **list, |
| 238 | const char *suffix) |
| 239 | { |
| 240 | struct worktree *found = NULL; |
| 241 | int nr_found = 0, suffixlen; |
| 242 | |
| 243 | suffixlen = strlen(suffix); |
| 244 | if (!suffixlen) |
| 245 | return NULL; |
| 246 | |
| 247 | for (; *list && nr_found < 2; list++) { |
| 248 | const char *path = (*list)->path; |
| 249 | int pathlen = strlen(path); |
| 250 | int start = pathlen - suffixlen; |
| 251 | |
| 252 | /* suffix must start at directory boundary */ |
| 253 | if ((!start || (start > 0 && is_dir_sep(path[start - 1]))) && |
| 254 | !fspathcmp(suffix, path + start)) { |
| 255 | found = *list; |
| 256 | nr_found++; |
| 257 | } |
| 258 | } |
| 259 | return nr_found == 1 ? found : NULL; |
| 260 | } |
| 261 | |
| 262 | struct worktree *find_worktree(struct worktree **list, |
| 263 | const char *prefix, |