tree-walk: convert tree entry functions to object_id

Convert get_tree_entry and find_tree_entry to take pointers to struct object_id. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Mar 12, 2018 at 02:27 UTC 916bc35b29af6e0f4f215dea9c84e4185de0fec4
11 files changed +31 -35
archive.c
+2 -2
@@ -397,8 +397,8 @@ static void parse_treeish_arg(const char **argv,
397 unsigned int mode;
398 int err;
399
400 - err = get_tree_entry(tree->object.oid.hash, prefix,
401 - tree_oid.hash, &mode);
400 + err = get_tree_entry(&tree->object.oid, prefix, &tree_oid,
401 + &mode);
402 if (err || !S_ISDIR(mode))
403 die("current working directory is untracked");
404
blame.c
+2 -4
@@ -80,7 +80,7 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
80 struct object_id blob_oid;
81 unsigned mode;
82
83 - if (!get_tree_entry(commit_oid->hash, path, blob_oid.hash, &mode) &&
83 + if (!get_tree_entry(commit_oid, path, &blob_oid, &mode) &&
84 oid_object_info(&blob_oid, NULL) == OBJ_BLOB)
85 return;
86 }
@@ -502,9 +502,7 @@ static int fill_blob_sha1_and_mode(struct blame_origin *origin)
502 {
503 if (!is_null_oid(&origin->blob_oid))
504 return 0;
505 - if (get_tree_entry(origin->commit->object.oid.hash,
506 - origin->path,
507 - origin->blob_oid.hash, &origin->mode))
505 + if (get_tree_entry(&origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
506 goto error_out;
507 if (oid_object_info(&origin->blob_oid, NULL) != OBJ_BLOB)
508 goto error_out;
builtin/rm.c
+1 -1
@@ -178,7 +178,7 @@ static int check_local_mod(struct object_id *head, int index_only)
178 * way as changed from the HEAD.
179 */
180 if (no_head
181 - || get_tree_entry(head->hash, name, oid.hash, &mode)
181 + || get_tree_entry(head, name, &oid, &mode)
182 || ce->ce_mode != create_ce_mode(mode)
183 || oidcmp(&ce->oid, &oid))
184 staged_changes = 1;
builtin/update-index.c
+1 -1
@@ -592,7 +592,7 @@ static struct cache_entry *read_one_ent(const char *which,
592 int size;
593 struct cache_entry *ce;
594
595 - if (get_tree_entry(ent->hash, path, oid.hash, &mode)) {
595 + if (get_tree_entry(ent, path, &oid, &mode)) {
596 if (which)
597 error("%s: not in %s branch.", path, which);
598 return NULL;
line-log.c
+1 -2
@@ -501,8 +501,7 @@ static void fill_blob_sha1(struct commit *commit, struct diff_filespec *spec)
501 unsigned mode;
502 struct object_id oid;
503
504 - if (get_tree_entry(commit->object.oid.hash, spec->path,
505 - oid.hash, &mode))
504 + if (get_tree_entry(&commit->object.oid, spec->path, &oid, &mode))
505 die("There is no path %s in the commit", spec->path);
506 fill_filespec(spec, &oid, 1, mode);
507
match-trees.c
+3 -3
@@ -269,7 +269,7 @@ void shift_tree(const struct object_id *hash1,
269 if (!*del_prefix)
270 return;
271
272 - if (get_tree_entry(hash2->hash, del_prefix, shifted->hash, &mode))
272 + if (get_tree_entry(hash2, del_prefix, shifted, &mode))
273 die("cannot find path %s in tree %s",
274 del_prefix, oid_to_hex(hash2));
275 return;
@@ -296,12 +296,12 @@ void shift_tree_by(const struct object_id *hash1,
296 unsigned candidate = 0;
297
298 /* Can hash2 be a tree at shift_prefix in tree hash1? */
299 - if (!get_tree_entry(hash1->hash, shift_prefix, sub1.hash, &mode1) &&
299 + if (!get_tree_entry(hash1, shift_prefix, &sub1, &mode1) &&
300 S_ISDIR(mode1))
301 candidate |= 1;
302
303 /* Can hash1 be a tree at shift_prefix in tree hash2? */
304 - if (!get_tree_entry(hash2->hash, shift_prefix, sub2.hash, &mode2) &&
304 + if (!get_tree_entry(hash2, shift_prefix, &sub2, &mode2) &&
305 S_ISDIR(mode2))
306 candidate |= 2;
307
merge-recursive.c
+6 -6
@@ -370,12 +370,12 @@ static struct stage_data *insert_stage_data(const char *path,
370 {
371 struct string_list_item *item;
372 struct stage_data *e = xcalloc(1, sizeof(struct stage_data));
373 - get_tree_entry(o->object.oid.hash, path,
374 - e->stages[1].oid.hash, &e->stages[1].mode);
375 - get_tree_entry(a->object.oid.hash, path,
376 - e->stages[2].oid.hash, &e->stages[2].mode);
377 - get_tree_entry(b->object.oid.hash, path,
378 - e->stages[3].oid.hash, &e->stages[3].mode);
373 + get_tree_entry(&o->object.oid, path,
374 + &e->stages[1].oid, &e->stages[1].mode);
375 + get_tree_entry(&a->object.oid, path,
376 + &e->stages[2].oid, &e->stages[2].mode);
377 + get_tree_entry(&b->object.oid, path,
378 + &e->stages[3].oid, &e->stages[3].mode);
379 item = string_list_insert(entries, path);
380 item->util = e;
381 return e;
notes.c
+1 -1
@@ -1012,7 +1012,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
1012 return;
1013 if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid))
1014 die("Cannot use notes ref %s", notes_ref);
1015 - if (get_tree_entry(object_oid.hash, "", oid.hash, &mode))
1015 + if (get_tree_entry(&object_oid, "", &oid, &mode))
1016 die("Failed to read notes tree referenced by %s (%s)",
1017 notes_ref, oid_to_hex(&object_oid));
1018
sha1_name.c
+3 -4
@@ -1529,8 +1529,7 @@ static void diagnose_invalid_oid_path(const char *prefix,
1529 if (is_missing_file_error(errno)) {
1530 char *fullname = xstrfmt("%s%s", prefix, filename);
1531
1532 - if (!get_tree_entry(tree_oid->hash, fullname,
1533 - oid.hash, &mode)) {
1532 + if (!get_tree_entry(tree_oid, fullname, &oid, &mode)) {
1533 die("Path '%s' exists, but not '%s'.\n"
1534 "Did you mean '%.*s:%s' aka '%.*s:./%s'?",
1535 fullname,
@@ -1722,8 +1721,8 @@ static int get_oid_with_context_1(const char *name,
1721 filename, oid->hash, &oc->symlink_path,
1722 &oc->mode);
1723 } else {
1725 - ret = get_tree_entry(tree_oid.hash, filename,
1726 - oid->hash, &oc->mode);
1724 + ret = get_tree_entry(&tree_oid, filename, oid,
1725 + &oc->mode);
1726 if (ret && only_to_die) {
1727 diagnose_invalid_oid_path(prefix,
1728 filename,
tree-walk.c
+10 -10
@@ -492,7 +492,7 @@ struct dir_state {
492 unsigned char sha1[20];
493 };
494
495 -static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char *result, unsigned *mode)
495 +static int find_tree_entry(struct tree_desc *t, const char *name, struct object_id *result, unsigned *mode)
496 {
497 int namelen = strlen(name);
498 while (t->size) {
@@ -511,7 +511,7 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
511 if (cmp < 0)
512 break;
513 if (entrylen == namelen) {
514 - hashcpy(result, oid->hash);
514 + oidcpy(result, oid);
515 return 0;
516 }
517 if (name[entrylen] != '/')
@@ -519,27 +519,27 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
519 if (!S_ISDIR(*mode))
520 break;
521 if (++entrylen == namelen) {
522 - hashcpy(result, oid->hash);
522 + oidcpy(result, oid);
523 return 0;
524 }
525 - return get_tree_entry(oid->hash, name + entrylen, result, mode);
525 + return get_tree_entry(oid, name + entrylen, result, mode);
526 }
527 return -1;
528 }
529
530 -int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned char *sha1, unsigned *mode)
530 +int get_tree_entry(const struct object_id *tree_oid, const char *name, struct object_id *oid, unsigned *mode)
531 {
532 int retval;
533 void *tree;
534 unsigned long size;
535 - unsigned char root[20];
535 + struct object_id root;
536
537 - tree = read_object_with_reference(tree_sha1, tree_type, &size, root);
537 + tree = read_object_with_reference(tree_oid->hash, tree_type, &size, root.hash);
538 if (!tree)
539 return -1;
540
541 if (name[0] == '\0') {
542 - hashcpy(sha1, root);
542 + oidcpy(oid, &root);
543 free(tree);
544 return 0;
545 }
@@ -549,7 +549,7 @@ int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned ch
549 } else {
550 struct tree_desc t;
551 init_tree_desc(&t, tree, size);
552 - retval = find_tree_entry(&t, name, sha1, mode);
552 + retval = find_tree_entry(&t, name, oid, mode);
553 }
554 free(tree);
555 return retval;
@@ -671,7 +671,7 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
671
672 /* Look up the first (or only) path component in the tree. */
673 find_result = find_tree_entry(&t, namebuf.buf,
674 - current_tree_oid.hash, mode);
674 + &current_tree_oid, mode);
675 if (find_result) {
676 goto done;
677 }
tree-walk.h
+1 -1
@@ -79,7 +79,7 @@ struct traverse_info {
79 int show_all_errors;
80 };
81
82 -int get_tree_entry(const unsigned char *, const char *, unsigned char *, unsigned *);
82 +int get_tree_entry(const struct object_id *, const char *, struct object_id *, unsigned *);
83 extern char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n);
84 extern void setup_traverse_info(struct traverse_info *info, const char *base);
85