Skip to content

Commit 891435d

Browse files
derrickstoleegitster
authored andcommitted
treewide: rename tree to maybe_tree
Using the commit-graph file to walk commit history removes the large cost of parsing commits during the walk. This exposes a performance issue: lookup_tree() takes a large portion of the computation time, even when Git never uses those trees. In anticipation of lazy-loading these trees, rename the 'tree' member of struct commit to 'maybe_tree'. This serves two purposes: it hints at the future role of possibly being NULL even if the commit has a valid tree, and it allows for unambiguous transformation from simple member access (i.e. commit->maybe_tree) to method access. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2d5792f commit 891435d

24 files changed

+65
-64
lines changed

blame.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,10 @@ static struct blame_origin *find_origin(struct commit *parent,
553553
diff_setup_done(&diff_opts);
554554

555555
if (is_null_oid(&origin->commit->object.oid))
556-
do_diff_cache(&parent->tree->object.oid, &diff_opts);
556+
do_diff_cache(&parent->maybe_tree->object.oid, &diff_opts);
557557
else
558-
diff_tree_oid(&parent->tree->object.oid,
559-
&origin->commit->tree->object.oid,
558+
diff_tree_oid(&parent->maybe_tree->object.oid,
559+
&origin->commit->maybe_tree->object.oid,
560560
"", &diff_opts);
561561
diffcore_std(&diff_opts);
562562

@@ -622,10 +622,10 @@ static struct blame_origin *find_rename(struct commit *parent,
622622
diff_setup_done(&diff_opts);
623623

624624
if (is_null_oid(&origin->commit->object.oid))
625-
do_diff_cache(&parent->tree->object.oid, &diff_opts);
625+
do_diff_cache(&parent->maybe_tree->object.oid, &diff_opts);
626626
else
627-
diff_tree_oid(&parent->tree->object.oid,
628-
&origin->commit->tree->object.oid,
627+
diff_tree_oid(&parent->maybe_tree->object.oid,
628+
&origin->commit->maybe_tree->object.oid,
629629
"", &diff_opts);
630630
diffcore_std(&diff_opts);
631631

@@ -1257,10 +1257,10 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
12571257
diff_opts.flags.find_copies_harder = 1;
12581258

12591259
if (is_null_oid(&target->commit->object.oid))
1260-
do_diff_cache(&parent->tree->object.oid, &diff_opts);
1260+
do_diff_cache(&parent->maybe_tree->object.oid, &diff_opts);
12611261
else
1262-
diff_tree_oid(&parent->tree->object.oid,
1263-
&target->commit->tree->object.oid,
1262+
diff_tree_oid(&parent->maybe_tree->object.oid,
1263+
&target->commit->maybe_tree->object.oid,
12641264
"", &diff_opts);
12651265

12661266
if (!diff_opts.flags.find_copies_harder)

builtin/checkout.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
484484

485485
resolve_undo_clear();
486486
if (opts->force) {
487-
ret = reset_tree(new_branch_info->commit->tree, opts, 1, writeout_error);
487+
ret = reset_tree(new_branch_info->commit->maybe_tree, opts, 1, writeout_error);
488488
if (ret)
489489
return ret;
490490
} else {
@@ -570,18 +570,18 @@ static int merge_working_tree(const struct checkout_opts *opts,
570570
o.verbosity = 0;
571571
work = write_tree_from_memory(&o);
572572

573-
ret = reset_tree(new_branch_info->commit->tree, opts, 1,
573+
ret = reset_tree(new_branch_info->commit->maybe_tree, opts, 1,
574574
writeout_error);
575575
if (ret)
576576
return ret;
577577
o.ancestor = old_branch_info->name;
578578
o.branch1 = new_branch_info->name;
579579
o.branch2 = "local";
580-
ret = merge_trees(&o, new_branch_info->commit->tree, work,
581-
old_branch_info->commit->tree, &result);
580+
ret = merge_trees(&o, new_branch_info->commit->maybe_tree, work,
581+
old_branch_info->commit->maybe_tree, &result);
582582
if (ret < 0)
583583
exit(128);
584-
ret = reset_tree(new_branch_info->commit->tree, opts, 0,
584+
ret = reset_tree(new_branch_info->commit->maybe_tree, opts, 0,
585585
writeout_error);
586586
strbuf_release(&o.obuf);
587587
if (ret)
@@ -1002,7 +1002,7 @@ static int parse_branchname_arg(int argc, const char **argv,
10021002
*source_tree = parse_tree_indirect(rev);
10031003
} else {
10041004
parse_commit_or_die(new_branch_info->commit);
1005-
*source_tree = new_branch_info->commit->tree;
1005+
*source_tree = new_branch_info->commit->maybe_tree;
10061006
}
10071007

10081008
if (!*source_tree) /* case (1): want a tree */

builtin/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
398398
if (!obj)
399399
die(_("invalid object '%s' given."), name);
400400
if (obj->type == OBJ_COMMIT)
401-
obj = &((struct commit *)obj)->tree->object;
401+
obj = &((struct commit *)obj)->maybe_tree->object;
402402

403403
if (obj->type == OBJ_TREE) {
404404
obj->flags |= flags;

builtin/fast-export.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,11 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
578578
get_object_mark(&commit->parents->item->object) != 0 &&
579579
!full_tree) {
580580
parse_commit_or_die(commit->parents->item);
581-
diff_tree_oid(&commit->parents->item->tree->object.oid,
582-
&commit->tree->object.oid, "", &rev->diffopt);
581+
diff_tree_oid(&commit->parents->item->maybe_tree->object.oid,
582+
&commit->maybe_tree->object.oid, "", &rev->diffopt);
583583
}
584584
else
585-
diff_root_tree_oid(&commit->tree->object.oid,
585+
diff_root_tree_oid(&commit->maybe_tree->object.oid,
586586
"", &rev->diffopt);
587587

588588
/* Export the referenced blobs, and remember the marks. */

builtin/log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,8 +1064,8 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
10641064

10651065
diff_setup_done(&opts);
10661066

1067-
diff_tree_oid(&origin->tree->object.oid,
1068-
&head->tree->object.oid,
1067+
diff_tree_oid(&origin->maybe_tree->object.oid,
1068+
&head->maybe_tree->object.oid,
10691069
"", &opts);
10701070
diffcore_std(&opts);
10711071
diff_flush(&opts);

builtin/reflog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static int commit_is_complete(struct commit *commit)
153153
for (i = 0; i < found.nr; i++) {
154154
struct commit *c =
155155
(struct commit *)found.objects[i].item;
156-
if (!tree_is_complete(&c->tree->object.oid)) {
156+
if (!tree_is_complete(&c->maybe_tree->object.oid)) {
157157
is_incomplete = 1;
158158
c->object.flags |= INCOMPLETE;
159159
}

commit-graph.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static int fill_commit_in_graph(struct commit *item, struct commit_graph *g, uin
258258
item->graph_pos = pos;
259259

260260
hashcpy(oid.hash, commit_data);
261-
item->tree = lookup_tree(&oid);
261+
item->maybe_tree = lookup_tree(&oid);
262262

263263
date_high = get_be32(commit_data + g->hash_len + 8) & 0x3;
264264
date_low = get_be32(commit_data + g->hash_len + 12);
@@ -369,7 +369,7 @@ static void write_graph_chunk_data(struct hashfile *f, int hash_len,
369369
uint32_t packedDate[2];
370370

371371
parse_commit(*list);
372-
hashwrite(f, (*list)->tree->object.oid.hash, hash_len);
372+
hashwrite(f, (*list)->maybe_tree->object.oid.hash, hash_len);
373373

374374
parent = (*list)->parents;
375375

commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
335335
if (get_sha1_hex(bufptr + 5, parent.hash) < 0)
336336
return error("bad tree pointer in commit %s",
337337
oid_to_hex(&item->object.oid));
338-
item->tree = lookup_tree(&parent);
338+
item->maybe_tree = lookup_tree(&parent);
339339
bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
340340
pptr = &item->parents;
341341

commit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct commit {
2222
unsigned int index;
2323
timestamp_t date;
2424
struct commit_list *parents;
25-
struct tree *tree;
25+
struct tree *maybe_tree;
2626
uint32_t graph_pos;
2727
};
2828

fsck.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,9 @@ static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_optio
396396

397397
name = get_object_name(options, &commit->object);
398398
if (name)
399-
put_object_name(options, &commit->tree->object, "%s:", name);
399+
put_object_name(options, &commit->maybe_tree->object, "%s:", name);
400400

401-
result = options->walk((struct object *)commit->tree, OBJ_TREE, data, options);
401+
result = options->walk((struct object *)commit->maybe_tree, OBJ_TREE, data, options);
402402
if (result < 0)
403403
return result;
404404
res = result;
@@ -772,7 +772,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
772772
err = fsck_ident(&buffer, &commit->object, options);
773773
if (err)
774774
return err;
775-
if (!commit->tree) {
775+
if (!commit->maybe_tree) {
776776
err = report(options, &commit->object, FSCK_MSG_BAD_TREE, "could not load commit's tree %s", sha1_to_hex(tree_sha1));
777777
if (err)
778778
return err;

0 commit comments

Comments
 (0)