#include "list-objects.h"
#include "object.h"
#include "oid-array.h"
+#include "path.h"
#include "prio-queue.h"
#include "repository.h"
#include "revision.h"
match != MATCHED)
continue;
}
+ if (ctx->revs->prune_data.nr) {
+ struct pathspec *pd = &ctx->revs->prune_data;
+ bool found = false;
+ int did_strip_suffix = strbuf_strip_suffix(&path, "/");
+
+
+ for (int i = 0; i < pd->nr; i++) {
+ struct pathspec_item *item = &pd->items[i];
+
+ /*
+ * Continue if either is a directory prefix
+ * of the other.
+ */
+ if (dir_prefix(path.buf, item->match) ||
+ dir_prefix(item->match, path.buf)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (did_strip_suffix)
+ strbuf_addch(&path, '/');
+
+ /* Skip paths that do not match the prefix. */
+ if (!found)
+ continue;
+ }
add_path_to_list(ctx, path.buf, type, &entry.oid,
!(o->flags & UNINTERESTING));
if (info->tags)
info->revs->tag_objects = 1;
+ if (ctx.revs->prune_data.nr) {
+ /*
+ * Only exact prefix pathspecs are currently supported.
+ * Clear any wildcard or magic pathspecs to avoid
+ * incorrect prefix matching.
+ */
+ if (ctx.revs->prune_data.has_wildcard ||
+ ctx.revs->prune_data.magic)
+ clear_pathspec(&ctx.revs->prune_data);
+ }
+
/* Insert a single list for the root tree into the paths. */
CALLOC_ARRAY(root_tree_list, 1);
root_tree_list->type = OBJ_TREE;
strbuf_remove(sb, 0, path - sb->buf);
}
-static int dir_prefix(const char *buf, const char *dir)
+int dir_prefix(const char *buf, const char *dir)
{
size_t len = strlen(dir);
return !strncmp(buf, dir, len) &&
const char *fmt, ...)
__attribute__((format (printf, 4, 5)));
+/*
+ * Given a directory name 'dir' (not ending with a trailing '/'),
+ * determine if 'buf' is equal to 'dir' or has prefix 'dir'+'/'.
+ */
+int dir_prefix(const char *buf, const char *dir);
+
void report_linked_checkout_garbage(struct repository *r);
/*
git -C backfill-path rev-list --quiet --objects --missing=print HEAD >missing &&
test_line_count = 48 missing &&
- # TODO: The pathspec should limit the downloaded blobs to
- # only those matching the prefix "d/f", but currently all
- # blobs are downloaded.
- git -C backfill-path backfill HEAD -- d/f &&
+ git -C backfill-path backfill HEAD -- d/f 2>err &&
+ test_must_be_empty err &&
git -C backfill-path rev-list --quiet --objects --missing=print HEAD >missing &&
- test_line_count = 0 missing
+ test_line_count = 40 missing
'
test_expect_success 'backfill with multiple pathspecs' '
git -C backfill-path rev-list --quiet --objects --missing=print HEAD >missing &&
test_line_count = 48 missing &&
- # TODO: The pathspecs should limit the downloaded blobs to
- # only those matching "d/f" or "a", but currently all blobs
- # are downloaded.
- git -C backfill-path backfill HEAD -- d/f a &&
+ git -C backfill-path backfill HEAD -- d/f a 2>err &&
+ test_must_be_empty err &&
git -C backfill-path rev-list --quiet --objects --missing=print HEAD >missing &&
- test_line_count = 0 missing
+ test_line_count = 16 missing
'
test_expect_success 'backfill with wildcard pathspec' '