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>
This commit is contained in:
brian m. carlson 2018-03-12 02:27:51 +00:00 committed by Junio C Hamano
parent 575042a04f
commit 916bc35b29
11 changed files with 31 additions and 35 deletions

View File

@ -397,8 +397,8 @@ static void parse_treeish_arg(const char **argv,
unsigned int mode; unsigned int mode;
int err; int err;
err = get_tree_entry(tree->object.oid.hash, prefix, err = get_tree_entry(&tree->object.oid, prefix, &tree_oid,
tree_oid.hash, &mode); &mode);
if (err || !S_ISDIR(mode)) if (err || !S_ISDIR(mode))
die("current working directory is untracked"); die("current working directory is untracked");

View File

@ -80,7 +80,7 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
struct object_id blob_oid; struct object_id blob_oid;
unsigned mode; unsigned mode;
if (!get_tree_entry(commit_oid->hash, path, blob_oid.hash, &mode) && if (!get_tree_entry(commit_oid, path, &blob_oid, &mode) &&
oid_object_info(&blob_oid, NULL) == OBJ_BLOB) oid_object_info(&blob_oid, NULL) == OBJ_BLOB)
return; return;
} }
@ -502,9 +502,7 @@ static int fill_blob_sha1_and_mode(struct blame_origin *origin)
{ {
if (!is_null_oid(&origin->blob_oid)) if (!is_null_oid(&origin->blob_oid))
return 0; return 0;
if (get_tree_entry(origin->commit->object.oid.hash, if (get_tree_entry(&origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
origin->path,
origin->blob_oid.hash, &origin->mode))
goto error_out; goto error_out;
if (oid_object_info(&origin->blob_oid, NULL) != OBJ_BLOB) if (oid_object_info(&origin->blob_oid, NULL) != OBJ_BLOB)
goto error_out; goto error_out;

View File

@ -178,7 +178,7 @@ static int check_local_mod(struct object_id *head, int index_only)
* way as changed from the HEAD. * way as changed from the HEAD.
*/ */
if (no_head if (no_head
|| get_tree_entry(head->hash, name, oid.hash, &mode) || get_tree_entry(head, name, &oid, &mode)
|| ce->ce_mode != create_ce_mode(mode) || ce->ce_mode != create_ce_mode(mode)
|| oidcmp(&ce->oid, &oid)) || oidcmp(&ce->oid, &oid))
staged_changes = 1; staged_changes = 1;

View File

@ -592,7 +592,7 @@ static struct cache_entry *read_one_ent(const char *which,
int size; int size;
struct cache_entry *ce; struct cache_entry *ce;
if (get_tree_entry(ent->hash, path, oid.hash, &mode)) { if (get_tree_entry(ent, path, &oid, &mode)) {
if (which) if (which)
error("%s: not in %s branch.", path, which); error("%s: not in %s branch.", path, which);
return NULL; return NULL;

View File

@ -501,8 +501,7 @@ static void fill_blob_sha1(struct commit *commit, struct diff_filespec *spec)
unsigned mode; unsigned mode;
struct object_id oid; struct object_id oid;
if (get_tree_entry(commit->object.oid.hash, spec->path, if (get_tree_entry(&commit->object.oid, spec->path, &oid, &mode))
oid.hash, &mode))
die("There is no path %s in the commit", spec->path); die("There is no path %s in the commit", spec->path);
fill_filespec(spec, &oid, 1, mode); fill_filespec(spec, &oid, 1, mode);

View File

@ -269,7 +269,7 @@ void shift_tree(const struct object_id *hash1,
if (!*del_prefix) if (!*del_prefix)
return; return;
if (get_tree_entry(hash2->hash, del_prefix, shifted->hash, &mode)) if (get_tree_entry(hash2, del_prefix, shifted, &mode))
die("cannot find path %s in tree %s", die("cannot find path %s in tree %s",
del_prefix, oid_to_hex(hash2)); del_prefix, oid_to_hex(hash2));
return; return;
@ -296,12 +296,12 @@ void shift_tree_by(const struct object_id *hash1,
unsigned candidate = 0; unsigned candidate = 0;
/* Can hash2 be a tree at shift_prefix in tree hash1? */ /* Can hash2 be a tree at shift_prefix in tree hash1? */
if (!get_tree_entry(hash1->hash, shift_prefix, sub1.hash, &mode1) && if (!get_tree_entry(hash1, shift_prefix, &sub1, &mode1) &&
S_ISDIR(mode1)) S_ISDIR(mode1))
candidate |= 1; candidate |= 1;
/* Can hash1 be a tree at shift_prefix in tree hash2? */ /* Can hash1 be a tree at shift_prefix in tree hash2? */
if (!get_tree_entry(hash2->hash, shift_prefix, sub2.hash, &mode2) && if (!get_tree_entry(hash2, shift_prefix, &sub2, &mode2) &&
S_ISDIR(mode2)) S_ISDIR(mode2))
candidate |= 2; candidate |= 2;

View File

@ -370,12 +370,12 @@ static struct stage_data *insert_stage_data(const char *path,
{ {
struct string_list_item *item; struct string_list_item *item;
struct stage_data *e = xcalloc(1, sizeof(struct stage_data)); struct stage_data *e = xcalloc(1, sizeof(struct stage_data));
get_tree_entry(o->object.oid.hash, path, get_tree_entry(&o->object.oid, path,
e->stages[1].oid.hash, &e->stages[1].mode); &e->stages[1].oid, &e->stages[1].mode);
get_tree_entry(a->object.oid.hash, path, get_tree_entry(&a->object.oid, path,
e->stages[2].oid.hash, &e->stages[2].mode); &e->stages[2].oid, &e->stages[2].mode);
get_tree_entry(b->object.oid.hash, path, get_tree_entry(&b->object.oid, path,
e->stages[3].oid.hash, &e->stages[3].mode); &e->stages[3].oid, &e->stages[3].mode);
item = string_list_insert(entries, path); item = string_list_insert(entries, path);
item->util = e; item->util = e;
return e; return e;

View File

@ -1012,7 +1012,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
return; return;
if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid)) if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid))
die("Cannot use notes ref %s", notes_ref); die("Cannot use notes ref %s", notes_ref);
if (get_tree_entry(object_oid.hash, "", oid.hash, &mode)) if (get_tree_entry(&object_oid, "", &oid, &mode))
die("Failed to read notes tree referenced by %s (%s)", die("Failed to read notes tree referenced by %s (%s)",
notes_ref, oid_to_hex(&object_oid)); notes_ref, oid_to_hex(&object_oid));

View File

@ -1529,8 +1529,7 @@ static void diagnose_invalid_oid_path(const char *prefix,
if (is_missing_file_error(errno)) { if (is_missing_file_error(errno)) {
char *fullname = xstrfmt("%s%s", prefix, filename); char *fullname = xstrfmt("%s%s", prefix, filename);
if (!get_tree_entry(tree_oid->hash, fullname, if (!get_tree_entry(tree_oid, fullname, &oid, &mode)) {
oid.hash, &mode)) {
die("Path '%s' exists, but not '%s'.\n" die("Path '%s' exists, but not '%s'.\n"
"Did you mean '%.*s:%s' aka '%.*s:./%s'?", "Did you mean '%.*s:%s' aka '%.*s:./%s'?",
fullname, fullname,
@ -1722,8 +1721,8 @@ static int get_oid_with_context_1(const char *name,
filename, oid->hash, &oc->symlink_path, filename, oid->hash, &oc->symlink_path,
&oc->mode); &oc->mode);
} else { } else {
ret = get_tree_entry(tree_oid.hash, filename, ret = get_tree_entry(&tree_oid, filename, oid,
oid->hash, &oc->mode); &oc->mode);
if (ret && only_to_die) { if (ret && only_to_die) {
diagnose_invalid_oid_path(prefix, diagnose_invalid_oid_path(prefix,
filename, filename,

View File

@ -492,7 +492,7 @@ struct dir_state {
unsigned char sha1[20]; unsigned char sha1[20];
}; };
static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char *result, unsigned *mode) static int find_tree_entry(struct tree_desc *t, const char *name, struct object_id *result, unsigned *mode)
{ {
int namelen = strlen(name); int namelen = strlen(name);
while (t->size) { while (t->size) {
@ -511,7 +511,7 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
if (cmp < 0) if (cmp < 0)
break; break;
if (entrylen == namelen) { if (entrylen == namelen) {
hashcpy(result, oid->hash); oidcpy(result, oid);
return 0; return 0;
} }
if (name[entrylen] != '/') if (name[entrylen] != '/')
@ -519,27 +519,27 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
if (!S_ISDIR(*mode)) if (!S_ISDIR(*mode))
break; break;
if (++entrylen == namelen) { if (++entrylen == namelen) {
hashcpy(result, oid->hash); oidcpy(result, oid);
return 0; return 0;
} }
return get_tree_entry(oid->hash, name + entrylen, result, mode); return get_tree_entry(oid, name + entrylen, result, mode);
} }
return -1; return -1;
} }
int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned char *sha1, unsigned *mode) int get_tree_entry(const struct object_id *tree_oid, const char *name, struct object_id *oid, unsigned *mode)
{ {
int retval; int retval;
void *tree; void *tree;
unsigned long size; unsigned long size;
unsigned char root[20]; struct object_id root;
tree = read_object_with_reference(tree_sha1, tree_type, &size, root); tree = read_object_with_reference(tree_oid->hash, tree_type, &size, root.hash);
if (!tree) if (!tree)
return -1; return -1;
if (name[0] == '\0') { if (name[0] == '\0') {
hashcpy(sha1, root); oidcpy(oid, &root);
free(tree); free(tree);
return 0; return 0;
} }
@ -549,7 +549,7 @@ int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned ch
} else { } else {
struct tree_desc t; struct tree_desc t;
init_tree_desc(&t, tree, size); init_tree_desc(&t, tree, size);
retval = find_tree_entry(&t, name, sha1, mode); retval = find_tree_entry(&t, name, oid, mode);
} }
free(tree); free(tree);
return retval; return retval;
@ -671,7 +671,7 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
/* Look up the first (or only) path component in the tree. */ /* Look up the first (or only) path component in the tree. */
find_result = find_tree_entry(&t, namebuf.buf, find_result = find_tree_entry(&t, namebuf.buf,
current_tree_oid.hash, mode); &current_tree_oid, mode);
if (find_result) { if (find_result) {
goto done; goto done;
} }

View File

@ -79,7 +79,7 @@ struct traverse_info {
int show_all_errors; int show_all_errors;
}; };
int get_tree_entry(const unsigned char *, const char *, unsigned char *, unsigned *); int get_tree_entry(const struct object_id *, const char *, struct object_id *, unsigned *);
extern char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n); extern char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n);
extern void setup_traverse_info(struct traverse_info *info, const char *base); extern void setup_traverse_info(struct traverse_info *info, const char *base);