Skip to content

Commit

Permalink
test-tool: add the path-walk subcommand
Browse files Browse the repository at this point in the history
This is currently primarily here for me to test out a couple of ideas or
to investigate how this path walk API thing works.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Sep 17, 2024
1 parent fee8f88 commit 489ce0c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ TEST_BUILTINS_OBJS += test-parse-options.o
TEST_BUILTINS_OBJS += test-parse-pathspec-file.o
TEST_BUILTINS_OBJS += test-partial-clone.o
TEST_BUILTINS_OBJS += test-path-utils.o
TEST_BUILTINS_OBJS += test-path-walk.o
TEST_BUILTINS_OBJS += test-pcre2-config.o
TEST_BUILTINS_OBJS += test-pkt-line.o
TEST_BUILTINS_OBJS += test-proc-receive.o
Expand Down
67 changes: 67 additions & 0 deletions t/helper/test-path-walk.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "test-tool.h"
#include "git-compat-util.h"
#include "parse-options.h"
#include "setup.h"
#include "revision.h"
#include "path-walk.h"
#include "oid-array.h"
#include "hex.h"

static const char * const path_walk_usage[] = {
N_("test-tool path-walk <options>"),
NULL
};

static int verbose;

static int callback_fn(const char *path,
struct oid_array *list,
enum object_type type,
void *data)
{
printf("visiting path '%s' (count: %"PRIuMAX") of type '%s'\n",

Check failure on line 24 in t/helper/test-path-walk.c

View workflow job for this annotation

GitHub Actions / linux32 (daald/ubuntu32:xenial)

t/helper/test-path-walk.c:24:9: format '%llu' expects argument of type 'long long unsigned int', but argument 3 has type 'size_t {aka unsigned int}' [-Werror=format=]
path, list->nr, type_name(type));
if (verbose)
for (size_t i = 0; i < list->nr; i++)
printf("\t%s\n", oid_to_hex(list->oid + i));

return 0;
}

int cmd__path_walk(int argc, const char **argv)
{
struct rev_info revs;
struct path_walk_info info = PATH_WALK_INFO_INIT;
struct option options[] = {
OPT_BOOL(0, "tags", &info.tags, N_("walk tags")),
OPT_BOOL(0, "commits", &info.commits, N_("walk commits")),
OPT_BOOL(0, "trees", &info.trees, N_("walk trees")),
OPT_BOOL(0, "blobs", &info.blobs, N_("walk blobs")),
OPT__VERBOSE(&verbose, N_("verbose")),
OPT_END(),
};
int ret = 0;

if (argc == 2 && !strcmp(argv[1], "-h"))
usage_with_options(path_walk_usage, options);

argc = parse_options(argc, argv, NULL, options, path_walk_usage,
PARSE_OPT_KEEP_ARGV0);

setup_git_directory();

repo_init_revisions(the_repository, &revs, "");
setup_revisions(argc, argv, &revs, NULL);

info.revs = &revs;
info.path_fn = callback_fn;

ret = walk_objects_by_path(&info);

reset_revision_walk();
release_revisions(&revs);

return ret;
}
1 change: 1 addition & 0 deletions t/helper/test-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static struct test_cmd cmds[] = {
{ "parse-subcommand", cmd__parse_subcommand },
{ "partial-clone", cmd__partial_clone },
{ "path-utils", cmd__path_utils },
{ "path-walk", cmd__path_walk },
{ "pcre2-config", cmd__pcre2_config },
{ "pkt-line", cmd__pkt_line },
{ "proc-receive", cmd__proc_receive },
Expand Down
1 change: 1 addition & 0 deletions t/helper/test-tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ int cmd__parse_pathspec_file(int argc, const char** argv);
int cmd__parse_subcommand(int argc, const char **argv);
int cmd__partial_clone(int argc, const char **argv);
int cmd__path_utils(int argc, const char **argv);
int cmd__path_walk(int argc, const char **argv);
int cmd__pcre2_config(int argc, const char **argv);
int cmd__pkt_line(int argc, const char **argv);
int cmd__proc_receive(int argc, const char **argv);
Expand Down

0 comments on commit 489ce0c

Please sign in to comment.