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>
This commit is contained in:

committed by
Junio C Hamano

parent
d190124f27
commit
c8dba310d7
@ -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;
|
||||
|
Reference in New Issue
Block a user