[RFC,v3,12/13] walken: count omitted objects
diff mbox series

Message ID 20190701202014.34480-13-emilyshaffer@google.com
State New
Headers show
Series
  • example implementation of revwalk tutorial
Related show

Commit Message

Emily Shaffer July 1, 2019, 8:20 p.m. UTC
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 <emilyshaffer@google.com>
---
 builtin/walken.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/builtin/walken.c b/builtin/walken.c
index 7b46377a2e..1638f679f2 100644
--- a/builtin/walken.c
+++ b/builtin/walken.c
@@ -146,6 +146,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);
 
 	rev->tree_objects = 1;
 	rev->blob_objects = 1;
@@ -180,13 +185,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);
 }
 
 /*