tree-walk: convert fill_tree_descriptor() to object_id

All callers of fill_tree_descriptor() have been converted to object_id already, so convert that function as well. As a nice side-effect we get rid of NULL checks in tree-diff.c, as fill_tree_descriptor() already does them for us. Helped-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Rene Scharfe <l.s.r@web.de> Reviewed-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Aug 12, 2017 at 10:32 UTC 5c377d3d593d324346bbaa965cbff8870795b420
8 files changed +23 -23
Documentation/technical/api-tree-walking.txt
+3 -3
@@ -55,9 +55,9 @@ Initializing
55
56 `fill_tree_descriptor`::
57
58 - Initialize a `tree_desc` and decode its first entry given the sha1 of
59 - a tree. Returns the `buffer` member if the sha1 is a valid tree
60 - identifier and NULL otherwise.
58 + Initialize a `tree_desc` and decode its first entry given the
59 + object ID of a tree. Returns the `buffer` member if the latter
60 + is a valid tree identifier and NULL otherwise.
61
62 `setup_traverse_info`::
63
builtin/merge-tree.c
+6 -6
@@ -213,11 +213,11 @@ static void unresolved_directory(const struct traverse_info *info,
213
214 newbase = traverse_path(info, p);
215
216 -#define ENTRY_SHA1(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->oid->hash : NULL)
217 - buf0 = fill_tree_descriptor(t+0, ENTRY_SHA1(n + 0));
218 - buf1 = fill_tree_descriptor(t+1, ENTRY_SHA1(n + 1));
219 - buf2 = fill_tree_descriptor(t+2, ENTRY_SHA1(n + 2));
220 -#undef ENTRY_SHA1
216 +#define ENTRY_OID(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->oid : NULL)
217 + buf0 = fill_tree_descriptor(t + 0, ENTRY_OID(n + 0));
218 + buf1 = fill_tree_descriptor(t + 1, ENTRY_OID(n + 1));
219 + buf2 = fill_tree_descriptor(t + 2, ENTRY_OID(n + 2));
220 +#undef ENTRY_OID
221
222 merge_trees(t, newbase);
223
@@ -352,7 +352,7 @@ static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)
352
353 if (get_oid(rev, &oid))
354 die("unknown rev %s", rev);
355 - buf = fill_tree_descriptor(desc, oid.hash);
355 + buf = fill_tree_descriptor(desc, &oid);
356 if (!buf)
357 die("%s is not a tree", rev);
358 return buf;
builtin/reset.c
+2 -2
@@ -75,13 +75,13 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)
75 struct object_id head_oid;
76 if (get_oid("HEAD", &head_oid))
77 return error(_("You do not have a valid HEAD."));
78 - if (!fill_tree_descriptor(desc, head_oid.hash))
78 + if (!fill_tree_descriptor(desc, &head_oid))
79 return error(_("Failed to find tree of HEAD."));
80 nr++;
81 opts.fn = twoway_merge;
82 }
83
84 - if (!fill_tree_descriptor(desc + nr - 1, oid->hash))
84 + if (!fill_tree_descriptor(desc + nr - 1, oid))
85 return error(_("Failed to find tree of %s."), oid_to_hex(oid));
86 if (unpack_trees(nr, desc, &opts))
87 return -1;
notes.c
+1 -1
@@ -425,7 +425,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
425 unsigned char type;
426 struct leaf_node *l;
427
428 - buf = fill_tree_descriptor(&desc, subtree->val_oid.hash);
428 + buf = fill_tree_descriptor(&desc, &subtree->val_oid);
429 if (!buf)
430 die("Could not read %s for notes-index",
431 oid_to_hex(&subtree->val_oid));
tree-diff.c
+2 -3
@@ -421,9 +421,8 @@ static struct combine_diff_path *ll_diff_tree_paths(
421 * diff_tree_oid(parent, commit) )
422 */
423 for (i = 0; i < nparent; ++i)
424 - tptree[i] = fill_tree_descriptor(&tp[i],
425 - parents_oid[i] ? parents_oid[i]->hash : NULL);
426 - ttree = fill_tree_descriptor(&t, oid ? oid->hash : NULL);
424 + tptree[i] = fill_tree_descriptor(&tp[i], parents_oid[i]);
425 + ttree = fill_tree_descriptor(&t, oid);
426
427 /* Enable recursion indefinitely */
428 opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE);
tree-walk.c
+5 -4
@@ -78,15 +78,16 @@ int init_tree_desc_gently(struct tree_desc *desc, const void *buffer, unsigned l
78 return result;
79 }
80
81 -void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1)
81 +void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid)
82 {
83 unsigned long size = 0;
84 void *buf = NULL;
85
86 - if (sha1) {
87 - buf = read_object_with_reference(sha1, tree_type, &size, NULL);
86 + if (oid) {
87 + buf = read_object_with_reference(oid->hash, tree_type, &size,
88 + NULL);
89 if (!buf)
89 - die("unable to read tree %s", sha1_to_hex(sha1));
90 + die("unable to read tree %s", oid_to_hex(oid));
91 }
92 init_tree_desc(desc, buf, size);
93 return buf;
tree-walk.h
+1 -1
@@ -42,7 +42,7 @@ int init_tree_desc_gently(struct tree_desc *desc, const void *buf, unsigned long
42 int tree_entry(struct tree_desc *, struct name_entry *);
43 int tree_entry_gently(struct tree_desc *, struct name_entry *);
44
45 -void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1);
45 +void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid);
46
47 struct traverse_info;
48 typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *);
unpack-trees.c
+3 -3
@@ -662,10 +662,10 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
662 else if (i > 1 && are_same_oid(&names[i], &names[i - 2]))
663 t[i] = t[i - 2];
664 else {
665 - const unsigned char *sha1 = NULL;
665 + const struct object_id *oid = NULL;
666 if (dirmask & 1)
667 - sha1 = names[i].oid->hash;
668 - buf[nr_buf++] = fill_tree_descriptor(t+i, sha1);
667 + oid = names[i].oid;
668 + buf[nr_buf++] = fill_tree_descriptor(t + i, oid);
669 }
670 }
671