|
11 | 11 | #include "list-objects.h" |
12 | 12 | #include "object.h" |
13 | 13 | #include "oid-array.h" |
| 14 | +#include "path.h" |
14 | 15 | #include "prio-queue.h" |
15 | 16 | #include "repository.h" |
16 | 17 | #include "revision.h" |
@@ -206,6 +207,33 @@ static int add_tree_entries(struct path_walk_context *ctx, |
206 | 207 | match != MATCHED) |
207 | 208 | continue; |
208 | 209 | } |
| 210 | + if (ctx->revs->prune_data.nr) { |
| 211 | + struct pathspec *pd = &ctx->revs->prune_data; |
| 212 | + bool found = false; |
| 213 | + int did_strip_suffix = strbuf_strip_suffix(&path, "/"); |
| 214 | + |
| 215 | + |
| 216 | + for (int i = 0; i < pd->nr; i++) { |
| 217 | + struct pathspec_item *item = &pd->items[i]; |
| 218 | + |
| 219 | + /* |
| 220 | + * Continue if either is a directory prefix |
| 221 | + * of the other. |
| 222 | + */ |
| 223 | + if (dir_prefix(path.buf, item->match) || |
| 224 | + dir_prefix(item->match, path.buf)) { |
| 225 | + found = true; |
| 226 | + break; |
| 227 | + } |
| 228 | + } |
| 229 | + |
| 230 | + if (did_strip_suffix) |
| 231 | + strbuf_addch(&path, '/'); |
| 232 | + |
| 233 | + /* Skip paths that do not match the prefix. */ |
| 234 | + if (!found) |
| 235 | + continue; |
| 236 | + } |
209 | 237 |
|
210 | 238 | add_path_to_list(ctx, path.buf, type, &entry.oid, |
211 | 239 | !(o->flags & UNINTERESTING)); |
@@ -481,6 +509,17 @@ int walk_objects_by_path(struct path_walk_info *info) |
481 | 509 | if (info->tags) |
482 | 510 | info->revs->tag_objects = 1; |
483 | 511 |
|
| 512 | + if (ctx.revs->prune_data.nr) { |
| 513 | + /* |
| 514 | + * Only exact prefix pathspecs are currently supported. |
| 515 | + * Clear any wildcard or magic pathspecs to avoid |
| 516 | + * incorrect prefix matching. |
| 517 | + */ |
| 518 | + if (ctx.revs->prune_data.has_wildcard || |
| 519 | + ctx.revs->prune_data.magic) |
| 520 | + clear_pathspec(&ctx.revs->prune_data); |
| 521 | + } |
| 522 | + |
484 | 523 | /* Insert a single list for the root tree into the paths. */ |
485 | 524 | CALLOC_ARRAY(root_tree_list, 1); |
486 | 525 | root_tree_list->type = OBJ_TREE; |
|
0 commit comments