It may be illuminating to see which objects were not included within a
given filter. This also demonstrates, since filter-spec "tree:1" is
used, that the 'omitted' list contains all objects which are omitted,
not just the first objects which were omitted - that is, it continues to
dereference omitted trees and commits.

This is part of a tutorial on performing revision walks.

Signed-off-by: Emily Shaffer <emilyshaf...@google.com>
---
 builtin/walken.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/builtin/walken.c b/builtin/walken.c
index a744d042d8..dc59ff5009 100644
--- a/builtin/walken.c
+++ b/builtin/walken.c
@@ -45,7 +45,7 @@ static void init_walken_defaults(void)
  * mirror those settings in post_repo_init_init.
  */
 static void final_rev_info_setup(int argc, const char **argv, const char 
*prefix,
-               struct rev_info *rev)
+                                struct rev_info *rev)
 {
        /*
         * Optional:
@@ -145,6 +145,11 @@ static void walken_show_object(struct object *obj, const 
char *str, void *buf)
 static void walken_object_walk(struct rev_info *rev)
 {
        struct list_objects_filter_options filter_options = {};
+       struct oidset omitted;
+       struct oidset_iter oit;
+       struct object_id *oid = NULL;
+       int omitted_count = 0;
+       oidset_init(&omitted, 0);
 
        printf("walken_object_walk beginning...\n");
 
@@ -181,13 +186,19 @@ static void walken_object_walk(struct rev_info *rev)
                        walken_show_commit, walken_show_object, NULL, NULL);
        }
 
+       /* Count the omitted objects. */
+       oidset_iter_init(&omitted, &oit);
+
+       while ((oid = oidset_iter_next(&oit)))
+               omitted_count++;
+
        /*
         * This print statement is designed to be script-parseable. Script
         * authors will rely on the output not to change, so we will not
         * localize this string. It will go to stdout directly.
         */
-       printf("commits %d\n blobs %d\n tags %d\n trees %d\n", commit_count,
-              blob_count, tag_count, tree_count);
+       printf("commits %d\n blobs %d\n tags %d\n trees %d omitted %d\n",
+              commit_count, blob_count, tag_count, tree_count, omitted_count);
 }
 
 /*
-- 
2.22.0.410.gd8fdbe21b5-goog

Reply via email to