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>
brian m. carlson committed
May 6, 2017 at 22:10 UTC
740ee055c6178fc2dd43c5ccfbd367c4c64d6e0d
18 files changed
+25
-25
builtin/am.c
+2
-2
@@ -1453,9 +1453,9 @@ static void write_index_patch(const struct am_state *state)
1453
FILE *fp;
1454
1455
if (!get_sha1_tree("HEAD", head.hash))
1456
- tree = lookup_tree(head.hash);
1456
+ tree = lookup_tree(&head);
1457
else
1458
- tree = lookup_tree(EMPTY_TREE_SHA1_BIN);
1458
+ tree = lookup_tree(&empty_tree_oid);
1459
1460
fp = xfopen(am_path(state, "patch"), "w");
1461
init_revisions(&rev_info, NULL);
builtin/diff-tree.c
+1
-1
@@ -44,7 +44,7 @@ static int stdin_diff_trees(struct tree *tree1, const char *p)
44
struct tree *tree2;
45
if (!isspace(*p++) || parse_oid_hex(p, &oid, &p) || *p)
46
return error("Need exactly two trees, separated by a space");
47
- tree2 = lookup_tree(oid.hash);
47
+ tree2 = lookup_tree(&oid);
48
if (!tree2 || parse_tree(tree2))
49
return -1;
50
printf("%s %s\n", oid_to_hex(&tree1->object.oid),
builtin/diff.c
+1
-1
@@ -381,7 +381,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
381
add_head_to_pending(&rev);
382
if (!rev.pending.nr) {
383
struct tree *tree;
384
- tree = lookup_tree(EMPTY_TREE_SHA1_BIN);
384
+ tree = lookup_tree(&empty_tree_oid);
385
add_pending_object(&rev, &tree->object, "HEAD");
386
}
387
break;
builtin/reflog.c
+1
-1
@@ -62,7 +62,7 @@ static int tree_is_complete(const struct object_id *oid)
62
int complete;
63
struct tree *tree;
64
65
- tree = lookup_tree(oid->hash);
65
+ tree = lookup_tree(oid);
66
if (!tree)
67
return 0;
68
if (tree->object.flags & SEEN)
cache-tree.c
+1
-1
@@ -672,7 +672,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
672
cnt++;
673
else {
674
struct cache_tree_sub *sub;
675
- struct tree *subtree = lookup_tree(entry.oid->hash);
675
+ struct tree *subtree = lookup_tree(entry.oid);
676
if (!subtree->object.parsed)
677
parse_tree(subtree);
678
sub = cache_tree_sub(it, entry.path);
commit.c
+1
-1
@@ -331,7 +331,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
331
if (get_sha1_hex(bufptr + 5, parent.hash) < 0)
332
return error("bad tree pointer in commit %s",
333
oid_to_hex(&item->object.oid));
334
- item->tree = lookup_tree(parent.hash);
334
+ item->tree = lookup_tree(&parent);
335
bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
336
pptr = &item->parents;
337
fsck.c
+1
-1
@@ -358,7 +358,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
358
continue;
359
360
if (S_ISDIR(entry.mode)) {
361
- obj = &lookup_tree(entry.oid->hash)->object;
361
+ obj = &lookup_tree(entry.oid)->object;
362
if (name)
363
put_object_name(options, obj, "%s%s/", name,
364
entry.path);
http-push.c
+1
-1
@@ -1312,7 +1312,7 @@ static struct object_list **process_tree(struct tree *tree,
1312
while (tree_entry(&desc, &entry))
1313
switch (object_type(entry.mode)) {
1314
case OBJ_TREE:
1315
- p = process_tree(lookup_tree(entry.oid->hash), p);
1315
+ p = process_tree(lookup_tree(entry.oid), p);
1316
break;
1317
case OBJ_BLOB:
1318
p = process_blob(lookup_blob(entry.oid), p);
list-objects.c
+1
-1
@@ -110,7 +110,7 @@ static void process_tree(struct rev_info *revs,
110
111
if (S_ISDIR(entry.mode))
112
process_tree(revs,
113
- lookup_tree(entry.oid->hash),
113
+ lookup_tree(entry.oid),
114
show, base, entry.path,
115
cb_data);
116
else if (S_ISGITLINK(entry.mode))
merge-recursive.c
+3
-3
@@ -67,7 +67,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
67
}
68
if (!oidcmp(&two->object.oid, &shifted))
69
return two;
70
- return lookup_tree(shifted.hash);
70
+ return lookup_tree(&shifted);
71
}
72
73
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)
304
return NULL;
305
}
306
307
- result = lookup_tree(active_cache_tree->oid.hash);
307
+ result = lookup_tree(&active_cache_tree->oid);
308
309
return result;
310
}
@@ -2042,7 +2042,7 @@ int merge_recursive(struct merge_options *o,
2042
/* if there is no common ancestor, use an empty tree */
2043
struct tree *tree;
2044
2045
- tree = lookup_tree(EMPTY_TREE_SHA1_BIN);
2045
+ tree = lookup_tree(&empty_tree_oid);
2046
merged_common_ancestors = make_virtual_commit(tree, "ancestor");
2047
}
2048
object.c
+1
-1
@@ -197,7 +197,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
197
obj = &blob->object;
198
}
199
} else if (type == OBJ_TREE) {
200
- struct tree *tree = lookup_tree(sha1);
200
+ struct tree *tree = lookup_tree(&oid);
201
if (tree) {
202
obj = &tree->object;
203
if (!tree->buffer)
reachable.c
+1
-1
@@ -85,7 +85,7 @@ static void add_recent_object(const struct object_id *oid,
85
obj = parse_object_or_die(oid->hash, NULL);
86
break;
87
case OBJ_TREE:
88
- obj = (struct object *)lookup_tree(oid->hash);
88
+ obj = (struct object *)lookup_tree(oid);
89
break;
90
case OBJ_BLOB:
91
obj = (struct object *)lookup_blob(oid);
revision.c
+2
-2
@@ -59,7 +59,7 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
59
while (tree_entry(&desc, &entry)) {
60
switch (object_type(entry.mode)) {
61
case OBJ_TREE:
62
- mark_tree_uninteresting(lookup_tree(entry.oid->hash));
62
+ mark_tree_uninteresting(lookup_tree(entry.oid));
63
break;
64
case OBJ_BLOB:
65
mark_blob_uninteresting(lookup_blob(entry.oid));
@@ -1249,7 +1249,7 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
1249
int i;
1250
1251
if (it->entry_count >= 0) {
1252
- struct tree *tree = lookup_tree(it->oid.hash);
1252
+ struct tree *tree = lookup_tree(&it->oid);
1253
add_pending_object_with_path(revs, &tree->object, "",
1254
040000, path->buf);
1255
}
sequencer.c
+1
-1
@@ -344,7 +344,7 @@ static int read_oneliner(struct strbuf *buf,
344
345
static struct tree *empty_tree(void)
346
{
347
- return lookup_tree(EMPTY_TREE_SHA1_BIN);
347
+ return lookup_tree(&empty_tree_oid);
348
}
349
350
static int error_dirty_index(struct replay_opts *opts)
tag.c
+1
-1
@@ -144,7 +144,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
144
if (!strcmp(type, blob_type)) {
145
item->tagged = &lookup_blob(&oid)->object;
146
} else if (!strcmp(type, tree_type)) {
147
- item->tagged = &lookup_tree(oid.hash)->object;
147
+ item->tagged = &lookup_tree(&oid)->object;
148
} else if (!strcmp(type, commit_type)) {
149
item->tagged = &lookup_commit(&oid)->object;
150
} else if (!strcmp(type, tag_type)) {
tree.c
+4
-4
@@ -110,7 +110,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
110
len = tree_entry_len(&entry);
111
strbuf_add(base, entry.path, len);
112
strbuf_addch(base, '/');
113
- retval = read_tree_1(lookup_tree(oid.hash),
113
+ retval = read_tree_1(lookup_tree(&oid),
114
base, stage, pathspec,
115
fn, context);
116
strbuf_setlen(base, oldlen);
@@ -184,11 +184,11 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match)
184
return 0;
185
}
186
187
-struct tree *lookup_tree(const unsigned char *sha1)
187
+struct tree *lookup_tree(const struct object_id *oid)
188
{
189
- struct object *obj = lookup_object(sha1);
189
+ struct object *obj = lookup_object(oid->hash);
190
if (!obj)
191
- return create_object(sha1, alloc_tree_node());
191
+ return create_object(oid->hash, alloc_tree_node());
192
return object_as_type(obj, OBJ_TREE, 0);
193
}
194
tree.h
+1
-1
@@ -12,7 +12,7 @@ struct tree {
12
unsigned long size;
13
};
14
15
-struct tree *lookup_tree(const unsigned char *sha1);
15
+struct tree *lookup_tree(const struct object_id *oid);
16
17
int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
18
walker.c
+1
-1
@@ -47,7 +47,7 @@ static int process_tree(struct walker *walker, struct tree *tree)
47
if (S_ISGITLINK(entry.mode))
48
continue;
49
if (S_ISDIR(entry.mode)) {
50
- struct tree *tree = lookup_tree(entry.oid->hash);
50
+ struct tree *tree = lookup_tree(entry.oid);
51
if (tree)
52
obj = &tree->object;
53
}