@matheusbsbs / matheus-bagliano / commits / 5290d45134
Fork 0

tree-walk.c: break circular dependency with unpack-trees

The unpack-trees API depends on the tree-walk API. But we've recently introduced a dependency in tree-walk.c on MAX_UNPACK_TREES, which doesn't otherwise care about unpack-trees at all. Let's break that dependency by reversing the constants: we'll introduce a new MAX_TRAVERSE_TREES which belongs to the tree-walk API. And then we can define MAX_UNPACK_TREES in terms of that (since unpack-trees cannot possibly work with more trees than it can traverse at once via tree-walk). The value for both will remain at 8. This is somewhat arbitrary and probably more than is necessary, per ca885a4fe6 (read-tree() and unpack_trees(): use consistent limit, 2008-03-13), but there's not really any pressing need to reduce it. Suggested-by: Elijah Newren <newren@gmail.com> Signed-off-by: Jeff King <peff@peff.net> Acked-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 1, 2020 at 06:39 UTC 5290d4513496d89f84570985a0e02e97dff477ff
3 files changed +4 -3
tree-walk.c
+1 -2
@@ -1,6 +1,5 @@
1 #include "cache.h"
2 #include "tree-walk.h"
3 -#include "unpack-trees.h"
3 #include "dir.h"
4 #include "object-store.h"
5 #include "tree.h"
@@ -410,7 +409,7 @@ int traverse_trees(struct index_state *istate,
409 struct traverse_info *info)
410 {
411 int error = 0;
413 - struct name_entry entry[MAX_UNPACK_TREES];
412 + struct name_entry entry[MAX_TRAVERSE_TREES];
413 int i;
414 struct tree_desc_x tx[ARRAY_SIZE(entry)];
415 struct strbuf base = STRBUF_INIT;
tree-walk.h
+2
@@ -3,6 +3,8 @@
3
4 #include "cache.h"
5
6 +#define MAX_TRAVERSE_TREES 8
7 +
8 /**
9 * The tree walking API is used to traverse and inspect trees.
10 */
unpack-trees.h
+1 -1
@@ -6,7 +6,7 @@
6 #include "string-list.h"
7 #include "tree-walk.h"
8
9 -#define MAX_UNPACK_TREES 8
9 +#define MAX_UNPACK_TREES MAX_TRAVERSE_TREES
10
11 struct cache_entry;
12 struct unpack_trees_options;