Convert lookup_tree to struct object_id

Convert the lookup_tree function to take a pointer to struct object_id.

The commit was created with manual changes to tree.c, tree.h, and
object.c, plus the following semantic patch:

@@
@@
- lookup_tree(EMPTY_TREE_SHA1_BIN)
+ lookup_tree(&empty_tree_oid)

@@
expression E1;
@@
- lookup_tree(E1.hash)
+ lookup_tree(&E1)

@@
expression E1;
@@
- lookup_tree(E1->hash)
+ lookup_tree(E1)

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
2017-05-06 22:10:17 +00:00
committed by Junio C Hamano
parent 49a09e74a4
commit 740ee055c6
18 changed files with 25 additions and 25 deletions

View File

@ -1453,9 +1453,9 @@ static void write_index_patch(const struct am_state *state)
FILE *fp; FILE *fp;
if (!get_sha1_tree("HEAD", head.hash)) if (!get_sha1_tree("HEAD", head.hash))
tree = lookup_tree(head.hash); tree = lookup_tree(&head);
else else
tree = lookup_tree(EMPTY_TREE_SHA1_BIN); tree = lookup_tree(&empty_tree_oid);
fp = xfopen(am_path(state, "patch"), "w"); fp = xfopen(am_path(state, "patch"), "w");
init_revisions(&rev_info, NULL); init_revisions(&rev_info, NULL);

View File

@ -44,7 +44,7 @@ static int stdin_diff_trees(struct tree *tree1, const char *p)
struct tree *tree2; struct tree *tree2;
if (!isspace(*p++) || parse_oid_hex(p, &oid, &p) || *p) if (!isspace(*p++) || parse_oid_hex(p, &oid, &p) || *p)
return error("Need exactly two trees, separated by a space"); return error("Need exactly two trees, separated by a space");
tree2 = lookup_tree(oid.hash); tree2 = lookup_tree(&oid);
if (!tree2 || parse_tree(tree2)) if (!tree2 || parse_tree(tree2))
return -1; return -1;
printf("%s %s\n", oid_to_hex(&tree1->object.oid), printf("%s %s\n", oid_to_hex(&tree1->object.oid),

View File

@ -381,7 +381,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
add_head_to_pending(&rev); add_head_to_pending(&rev);
if (!rev.pending.nr) { if (!rev.pending.nr) {
struct tree *tree; struct tree *tree;
tree = lookup_tree(EMPTY_TREE_SHA1_BIN); tree = lookup_tree(&empty_tree_oid);
add_pending_object(&rev, &tree->object, "HEAD"); add_pending_object(&rev, &tree->object, "HEAD");
} }
break; break;

View File

@ -62,7 +62,7 @@ static int tree_is_complete(const struct object_id *oid)
int complete; int complete;
struct tree *tree; struct tree *tree;
tree = lookup_tree(oid->hash); tree = lookup_tree(oid);
if (!tree) if (!tree)
return 0; return 0;
if (tree->object.flags & SEEN) if (tree->object.flags & SEEN)

View File

@ -672,7 +672,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
cnt++; cnt++;
else { else {
struct cache_tree_sub *sub; struct cache_tree_sub *sub;
struct tree *subtree = lookup_tree(entry.oid->hash); struct tree *subtree = lookup_tree(entry.oid);
if (!subtree->object.parsed) if (!subtree->object.parsed)
parse_tree(subtree); parse_tree(subtree);
sub = cache_tree_sub(it, entry.path); sub = cache_tree_sub(it, entry.path);

View File

@ -331,7 +331,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
if (get_sha1_hex(bufptr + 5, parent.hash) < 0) if (get_sha1_hex(bufptr + 5, parent.hash) < 0)
return error("bad tree pointer in commit %s", return error("bad tree pointer in commit %s",
oid_to_hex(&item->object.oid)); oid_to_hex(&item->object.oid));
item->tree = lookup_tree(parent.hash); item->tree = lookup_tree(&parent);
bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */ bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
pptr = &item->parents; pptr = &item->parents;

2
fsck.c
View File

@ -358,7 +358,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
continue; continue;
if (S_ISDIR(entry.mode)) { if (S_ISDIR(entry.mode)) {
obj = &lookup_tree(entry.oid->hash)->object; obj = &lookup_tree(entry.oid)->object;
if (name) if (name)
put_object_name(options, obj, "%s%s/", name, put_object_name(options, obj, "%s%s/", name,
entry.path); entry.path);

View File

@ -1312,7 +1312,7 @@ static struct object_list **process_tree(struct tree *tree,
while (tree_entry(&desc, &entry)) while (tree_entry(&desc, &entry))
switch (object_type(entry.mode)) { switch (object_type(entry.mode)) {
case OBJ_TREE: case OBJ_TREE:
p = process_tree(lookup_tree(entry.oid->hash), p); p = process_tree(lookup_tree(entry.oid), p);
break; break;
case OBJ_BLOB: case OBJ_BLOB:
p = process_blob(lookup_blob(entry.oid), p); p = process_blob(lookup_blob(entry.oid), p);

View File

@ -110,7 +110,7 @@ static void process_tree(struct rev_info *revs,
if (S_ISDIR(entry.mode)) if (S_ISDIR(entry.mode))
process_tree(revs, process_tree(revs,
lookup_tree(entry.oid->hash), lookup_tree(entry.oid),
show, base, entry.path, show, base, entry.path,
cb_data); cb_data);
else if (S_ISGITLINK(entry.mode)) else if (S_ISGITLINK(entry.mode))

View File

@ -67,7 +67,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
} }
if (!oidcmp(&two->object.oid, &shifted)) if (!oidcmp(&two->object.oid, &shifted))
return two; return two;
return lookup_tree(shifted.hash); return lookup_tree(&shifted);
} }
static struct commit *make_virtual_commit(struct tree *tree, const char *comment) static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
@ -304,7 +304,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
return NULL; return NULL;
} }
result = lookup_tree(active_cache_tree->oid.hash); result = lookup_tree(&active_cache_tree->oid);
return result; return result;
} }
@ -2042,7 +2042,7 @@ int merge_recursive(struct merge_options *o,
/* if there is no common ancestor, use an empty tree */ /* if there is no common ancestor, use an empty tree */
struct tree *tree; struct tree *tree;
tree = lookup_tree(EMPTY_TREE_SHA1_BIN); tree = lookup_tree(&empty_tree_oid);
merged_common_ancestors = make_virtual_commit(tree, "ancestor"); merged_common_ancestors = make_virtual_commit(tree, "ancestor");
} }

View File

@ -197,7 +197,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
obj = &blob->object; obj = &blob->object;
} }
} else if (type == OBJ_TREE) { } else if (type == OBJ_TREE) {
struct tree *tree = lookup_tree(sha1); struct tree *tree = lookup_tree(&oid);
if (tree) { if (tree) {
obj = &tree->object; obj = &tree->object;
if (!tree->buffer) if (!tree->buffer)

View File

@ -85,7 +85,7 @@ static void add_recent_object(const struct object_id *oid,
obj = parse_object_or_die(oid->hash, NULL); obj = parse_object_or_die(oid->hash, NULL);
break; break;
case OBJ_TREE: case OBJ_TREE:
obj = (struct object *)lookup_tree(oid->hash); obj = (struct object *)lookup_tree(oid);
break; break;
case OBJ_BLOB: case OBJ_BLOB:
obj = (struct object *)lookup_blob(oid); obj = (struct object *)lookup_blob(oid);

View File

@ -59,7 +59,7 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
while (tree_entry(&desc, &entry)) { while (tree_entry(&desc, &entry)) {
switch (object_type(entry.mode)) { switch (object_type(entry.mode)) {
case OBJ_TREE: case OBJ_TREE:
mark_tree_uninteresting(lookup_tree(entry.oid->hash)); mark_tree_uninteresting(lookup_tree(entry.oid));
break; break;
case OBJ_BLOB: case OBJ_BLOB:
mark_blob_uninteresting(lookup_blob(entry.oid)); mark_blob_uninteresting(lookup_blob(entry.oid));
@ -1249,7 +1249,7 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
int i; int i;
if (it->entry_count >= 0) { if (it->entry_count >= 0) {
struct tree *tree = lookup_tree(it->oid.hash); struct tree *tree = lookup_tree(&it->oid);
add_pending_object_with_path(revs, &tree->object, "", add_pending_object_with_path(revs, &tree->object, "",
040000, path->buf); 040000, path->buf);
} }

View File

@ -344,7 +344,7 @@ static int read_oneliner(struct strbuf *buf,
static struct tree *empty_tree(void) static struct tree *empty_tree(void)
{ {
return lookup_tree(EMPTY_TREE_SHA1_BIN); return lookup_tree(&empty_tree_oid);
} }
static int error_dirty_index(struct replay_opts *opts) static int error_dirty_index(struct replay_opts *opts)

2
tag.c
View File

@ -144,7 +144,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
if (!strcmp(type, blob_type)) { if (!strcmp(type, blob_type)) {
item->tagged = &lookup_blob(&oid)->object; item->tagged = &lookup_blob(&oid)->object;
} else if (!strcmp(type, tree_type)) { } else if (!strcmp(type, tree_type)) {
item->tagged = &lookup_tree(oid.hash)->object; item->tagged = &lookup_tree(&oid)->object;
} else if (!strcmp(type, commit_type)) { } else if (!strcmp(type, commit_type)) {
item->tagged = &lookup_commit(&oid)->object; item->tagged = &lookup_commit(&oid)->object;
} else if (!strcmp(type, tag_type)) { } else if (!strcmp(type, tag_type)) {

8
tree.c
View File

@ -110,7 +110,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
len = tree_entry_len(&entry); len = tree_entry_len(&entry);
strbuf_add(base, entry.path, len); strbuf_add(base, entry.path, len);
strbuf_addch(base, '/'); strbuf_addch(base, '/');
retval = read_tree_1(lookup_tree(oid.hash), retval = read_tree_1(lookup_tree(&oid),
base, stage, pathspec, base, stage, pathspec,
fn, context); fn, context);
strbuf_setlen(base, oldlen); strbuf_setlen(base, oldlen);
@ -184,11 +184,11 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match)
return 0; return 0;
} }
struct tree *lookup_tree(const unsigned char *sha1) struct tree *lookup_tree(const struct object_id *oid)
{ {
struct object *obj = lookup_object(sha1); struct object *obj = lookup_object(oid->hash);
if (!obj) if (!obj)
return create_object(sha1, alloc_tree_node()); return create_object(oid->hash, alloc_tree_node());
return object_as_type(obj, OBJ_TREE, 0); return object_as_type(obj, OBJ_TREE, 0);
} }

2
tree.h
View File

@ -12,7 +12,7 @@ struct tree {
unsigned long size; unsigned long size;
}; };
struct tree *lookup_tree(const unsigned char *sha1); struct tree *lookup_tree(const struct object_id *oid);
int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);

View File

@ -47,7 +47,7 @@ static int process_tree(struct walker *walker, struct tree *tree)
if (S_ISGITLINK(entry.mode)) if (S_ISGITLINK(entry.mode))
continue; continue;
if (S_ISDIR(entry.mode)) { if (S_ISDIR(entry.mode)) {
struct tree *tree = lookup_tree(entry.oid->hash); struct tree *tree = lookup_tree(entry.oid);
if (tree) if (tree)
obj = &tree->object; obj = &tree->object;
} }