aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorDerrick Stolee <derrickstolee@github.com>2024-12-20 16:21:12 +0000
committerJunio C Hamano <gitster@pobox.com>2024-12-20 08:37:05 -0800
commitc8dba310d734962c0bcadd8cad1ebf7cfe734c8c (patch)
treeb594be4998d97ee2ff153c5c19f522a2f8410170 /t
parentd190124f277952bd828f932d87e76deabedf0c83 (diff)
downloadgit-c8dba310d734962c0bcadd8cad1ebf7cfe734c8c.tar.gz
path-walk: allow consumer to specify object types
We add the ability to filter the object types in the path-walk API so the callback function is called fewer times. This adds the ability to ask for the commits in a list, as well. We re-use the empty string for this set of objects because these are passed directly to the callback function instead of being part of the 'path_stack'. Future changes will add the ability to visit annotated tags. Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rw-r--r--t/helper/test-path-walk.c15
-rwxr-xr-xt/t6601-path-walk.sh149
2 files changed, 119 insertions, 45 deletions
diff --git a/t/helper/test-path-walk.c b/t/helper/test-path-walk.c
index def7c81ac4..a57a05a639 100644
--- a/t/helper/test-path-walk.c
+++ b/t/helper/test-path-walk.c
@@ -19,6 +19,8 @@ static const char * const path_walk_usage[] = {
struct path_walk_test_data {
uintmax_t batch_nr;
+
+ uintmax_t commit_nr;
uintmax_t tree_nr;
uintmax_t blob_nr;
};
@@ -33,6 +35,8 @@ static int emit_block(const char *path, struct oid_array *oids,
tdata->tree_nr += oids->nr;
else if (type == OBJ_BLOB)
tdata->blob_nr += oids->nr;
+ else if (type == OBJ_COMMIT)
+ tdata->commit_nr += oids->nr;
else
BUG("we do not understand this type");
@@ -54,6 +58,12 @@ int cmd__path_walk(int argc, const char **argv)
struct path_walk_info info = PATH_WALK_INFO_INIT;
struct path_walk_test_data data = { 0 };
struct option options[] = {
+ OPT_BOOL(0, "blobs", &info.blobs,
+ N_("toggle inclusion of blob objects")),
+ OPT_BOOL(0, "commits", &info.commits,
+ N_("toggle inclusion of commit objects")),
+ OPT_BOOL(0, "trees", &info.trees,
+ N_("toggle inclusion of tree objects")),
OPT_END(),
};
@@ -75,9 +85,10 @@ int cmd__path_walk(int argc, const char **argv)
res = walk_objects_by_path(&info);
- printf("trees:%" PRIuMAX "\n"
+ printf("commits:%" PRIuMAX "\n"
+ "trees:%" PRIuMAX "\n"
"blobs:%" PRIuMAX "\n",
- data.tree_nr, data.blob_nr);
+ data.commit_nr, data.tree_nr, data.blob_nr);
release_revisions(&revs);
return res;
diff --git a/t/t6601-path-walk.sh b/t/t6601-path-walk.sh
index 4e052c0930..4a4939a1b0 100755
--- a/t/t6601-path-walk.sh
+++ b/t/t6601-path-walk.sh
@@ -33,22 +33,27 @@ test_expect_success 'all' '
test-tool path-walk -- --all >out &&
cat >expect <<-EOF &&
- 0:tree::$(git rev-parse topic^{tree})
- 0:tree::$(git rev-parse base^{tree})
- 0:tree::$(git rev-parse base~1^{tree})
- 0:tree::$(git rev-parse base~2^{tree})
- 1:tree:right/:$(git rev-parse topic:right)
- 1:tree:right/:$(git rev-parse base~1:right)
- 1:tree:right/:$(git rev-parse base~2:right)
- 2:blob:right/d:$(git rev-parse base~1:right/d)
- 3:blob:right/c:$(git rev-parse base~2:right/c)
- 3:blob:right/c:$(git rev-parse topic:right/c)
- 4:tree:left/:$(git rev-parse base:left)
- 4:tree:left/:$(git rev-parse base~2:left)
- 5:blob:left/b:$(git rev-parse base~2:left/b)
- 5:blob:left/b:$(git rev-parse base:left/b)
- 6:blob:a:$(git rev-parse base~2:a)
+ 0:commit::$(git rev-parse topic)
+ 0:commit::$(git rev-parse base)
+ 0:commit::$(git rev-parse base~1)
+ 0:commit::$(git rev-parse base~2)
+ 1:tree::$(git rev-parse topic^{tree})
+ 1:tree::$(git rev-parse base^{tree})
+ 1:tree::$(git rev-parse base~1^{tree})
+ 1:tree::$(git rev-parse base~2^{tree})
+ 2:tree:right/:$(git rev-parse topic:right)
+ 2:tree:right/:$(git rev-parse base~1:right)
+ 2:tree:right/:$(git rev-parse base~2:right)
+ 3:blob:right/d:$(git rev-parse base~1:right/d)
+ 4:blob:right/c:$(git rev-parse base~2:right/c)
+ 4:blob:right/c:$(git rev-parse topic:right/c)
+ 5:tree:left/:$(git rev-parse base:left)
+ 5:tree:left/:$(git rev-parse base~2:left)
+ 6:blob:left/b:$(git rev-parse base~2:left/b)
+ 6:blob:left/b:$(git rev-parse base:left/b)
+ 7:blob:a:$(git rev-parse base~2:a)
blobs:6
+ commits:4
trees:9
EOF
@@ -59,19 +64,23 @@ test_expect_success 'topic only' '
test-tool path-walk -- topic >out &&
cat >expect <<-EOF &&
- 0:tree::$(git rev-parse topic^{tree})
- 0:tree::$(git rev-parse base~1^{tree})
- 0:tree::$(git rev-parse base~2^{tree})
- 1:tree:right/:$(git rev-parse topic:right)
- 1:tree:right/:$(git rev-parse base~1:right)
- 1:tree:right/:$(git rev-parse base~2:right)
- 2:blob:right/d:$(git rev-parse base~1:right/d)
- 3:blob:right/c:$(git rev-parse base~2:right/c)
- 3:blob:right/c:$(git rev-parse topic:right/c)
- 4:tree:left/:$(git rev-parse base~2:left)
- 5:blob:left/b:$(git rev-parse base~2:left/b)
- 6:blob:a:$(git rev-parse base~2:a)
+ 0:commit::$(git rev-parse topic)
+ 0:commit::$(git rev-parse base~1)
+ 0:commit::$(git rev-parse base~2)
+ 1:tree::$(git rev-parse topic^{tree})
+ 1:tree::$(git rev-parse base~1^{tree})
+ 1:tree::$(git rev-parse base~2^{tree})
+ 2:tree:right/:$(git rev-parse topic:right)
+ 2:tree:right/:$(git rev-parse base~1:right)
+ 2:tree:right/:$(git rev-parse base~2:right)
+ 3:blob:right/d:$(git rev-parse base~1:right/d)
+ 4:blob:right/c:$(git rev-parse base~2:right/c)
+ 4:blob:right/c:$(git rev-parse topic:right/c)
+ 5:tree:left/:$(git rev-parse base~2:left)
+ 6:blob:left/b:$(git rev-parse base~2:left/b)
+ 7:blob:a:$(git rev-parse base~2:a)
blobs:5
+ commits:3
trees:7
EOF
@@ -82,15 +91,66 @@ test_expect_success 'topic, not base' '
test-tool path-walk -- topic --not base >out &&
cat >expect <<-EOF &&
+ 0:commit::$(git rev-parse topic)
+ 1:tree::$(git rev-parse topic^{tree})
+ 2:tree:right/:$(git rev-parse topic:right)
+ 3:blob:right/d:$(git rev-parse topic:right/d)
+ 4:blob:right/c:$(git rev-parse topic:right/c)
+ 5:tree:left/:$(git rev-parse topic:left)
+ 6:blob:left/b:$(git rev-parse topic:left/b)
+ 7:blob:a:$(git rev-parse topic:a)
+ blobs:4
+ commits:1
+ trees:3
+ EOF
+
+ test_cmp_sorted expect out
+'
+
+test_expect_success 'topic, not base, only blobs' '
+ test-tool path-walk --no-trees --no-commits \
+ -- topic --not base >out &&
+
+ cat >expect <<-EOF &&
+ commits:0
+ trees:0
+ 0:blob:right/d:$(git rev-parse topic:right/d)
+ 1:blob:right/c:$(git rev-parse topic:right/c)
+ 2:blob:left/b:$(git rev-parse topic:left/b)
+ 3:blob:a:$(git rev-parse topic:a)
+ blobs:4
+ EOF
+
+ test_cmp_sorted expect out
+'
+
+# No, this doesn't make a lot of sense for the path-walk API,
+# but it is possible to do.
+test_expect_success 'topic, not base, only commits' '
+ test-tool path-walk --no-blobs --no-trees \
+ -- topic --not base >out &&
+
+ cat >expect <<-EOF &&
+ 0:commit::$(git rev-parse topic)
+ commits:1
+ trees:0
+ blobs:0
+ EOF
+
+ test_cmp_sorted expect out
+'
+
+test_expect_success 'topic, not base, only trees' '
+ test-tool path-walk --no-blobs --no-commits \
+ -- topic --not base >out &&
+
+ cat >expect <<-EOF &&
+ commits:0
0:tree::$(git rev-parse topic^{tree})
1:tree:right/:$(git rev-parse topic:right)
- 2:blob:right/d:$(git rev-parse topic:right/d)
- 3:blob:right/c:$(git rev-parse topic:right/c)
- 4:tree:left/:$(git rev-parse topic:left)
- 5:blob:left/b:$(git rev-parse topic:left/b)
- 6:blob:a:$(git rev-parse topic:a)
- blobs:4
+ 2:tree:left/:$(git rev-parse topic:left)
trees:3
+ blobs:0
EOF
test_cmp_sorted expect out
@@ -100,17 +160,20 @@ test_expect_success 'topic, not base, boundary' '
test-tool path-walk -- --boundary topic --not base >out &&
cat >expect <<-EOF &&
- 0:tree::$(git rev-parse topic^{tree})
- 0:tree::$(git rev-parse base~1^{tree})
- 1:tree:right/:$(git rev-parse topic:right)
- 1:tree:right/:$(git rev-parse base~1:right)
- 2:blob:right/d:$(git rev-parse base~1:right/d)
- 3:blob:right/c:$(git rev-parse base~1:right/c)
- 3:blob:right/c:$(git rev-parse topic:right/c)
- 4:tree:left/:$(git rev-parse base~1:left)
- 5:blob:left/b:$(git rev-parse base~1:left/b)
- 6:blob:a:$(git rev-parse base~1:a)
+ 0:commit::$(git rev-parse topic)
+ 0:commit::$(git rev-parse base~1)
+ 1:tree::$(git rev-parse topic^{tree})
+ 1:tree::$(git rev-parse base~1^{tree})
+ 2:tree:right/:$(git rev-parse topic:right)
+ 2:tree:right/:$(git rev-parse base~1:right)
+ 3:blob:right/d:$(git rev-parse base~1:right/d)
+ 4:blob:right/c:$(git rev-parse base~1:right/c)
+ 4:blob:right/c:$(git rev-parse topic:right/c)
+ 5:tree:left/:$(git rev-parse base~1:left)
+ 6:blob:left/b:$(git rev-parse base~1:left/b)
+ 7:blob:a:$(git rev-parse base~1:a)
blobs:5
+ commits:2
trees:5
EOF