Skip to content

Commit 2e27bd7

Browse files
derrickstoleegitster
authored andcommitted
treewide: replace maybe_tree with accessor methods
In anticipation of making trees load lazily, create a Coccinelle script (contrib/coccinelle/commit.cocci) to ensure that all references to the 'maybe_tree' member of struct commit are either mutations or accesses through get_commit_tree() or get_commit_tree_oid(). Apply the Coccinelle script to create the rest of the patch. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5bb03de commit 2e27bd7

23 files changed

+101
-61
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->maybe_tree->object.oid, &diff_opts);
556+
do_diff_cache(get_commit_tree_oid(parent), &diff_opts);
557557
else
558-
diff_tree_oid(&parent->maybe_tree->object.oid,
559-
&origin->commit->maybe_tree->object.oid,
558+
diff_tree_oid(get_commit_tree_oid(parent),
559+
get_commit_tree_oid(origin->commit),
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->maybe_tree->object.oid, &diff_opts);
625+
do_diff_cache(get_commit_tree_oid(parent), &diff_opts);
626626
else
627-
diff_tree_oid(&parent->maybe_tree->object.oid,
628-
&origin->commit->maybe_tree->object.oid,
627+
diff_tree_oid(get_commit_tree_oid(parent),
628+
get_commit_tree_oid(origin->commit),
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->maybe_tree->object.oid, &diff_opts);
1260+
do_diff_cache(get_commit_tree_oid(parent), &diff_opts);
12611261
else
1262-
diff_tree_oid(&parent->maybe_tree->object.oid,
1263-
&target->commit->maybe_tree->object.oid,
1262+
diff_tree_oid(get_commit_tree_oid(parent),
1263+
get_commit_tree_oid(target->commit),
12641264
"", &diff_opts);
12651265

12661266
if (!diff_opts.flags.find_copies_harder)

builtin/checkout.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ 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->maybe_tree, opts, 1, writeout_error);
487+
ret = reset_tree(get_commit_tree(new_branch_info->commit),
488+
opts, 1, writeout_error);
488489
if (ret)
489490
return ret;
490491
} else {
@@ -570,18 +571,23 @@ static int merge_working_tree(const struct checkout_opts *opts,
570571
o.verbosity = 0;
571572
work = write_tree_from_memory(&o);
572573

573-
ret = reset_tree(new_branch_info->commit->maybe_tree, opts, 1,
574+
ret = reset_tree(get_commit_tree(new_branch_info->commit),
575+
opts, 1,
574576
writeout_error);
575577
if (ret)
576578
return ret;
577579
o.ancestor = old_branch_info->name;
578580
o.branch1 = new_branch_info->name;
579581
o.branch2 = "local";
580-
ret = merge_trees(&o, new_branch_info->commit->maybe_tree, work,
581-
old_branch_info->commit->maybe_tree, &result);
582+
ret = merge_trees(&o,
583+
get_commit_tree(new_branch_info->commit),
584+
work,
585+
get_commit_tree(old_branch_info->commit),
586+
&result);
582587
if (ret < 0)
583588
exit(128);
584-
ret = reset_tree(new_branch_info->commit->maybe_tree, opts, 0,
589+
ret = reset_tree(get_commit_tree(new_branch_info->commit),
590+
opts, 0,
585591
writeout_error);
586592
strbuf_release(&o.obuf);
587593
if (ret)
@@ -1002,7 +1008,7 @@ static int parse_branchname_arg(int argc, const char **argv,
10021008
*source_tree = parse_tree_indirect(rev);
10031009
} else {
10041010
parse_commit_or_die(new_branch_info->commit);
1005-
*source_tree = new_branch_info->commit->maybe_tree;
1011+
*source_tree = get_commit_tree(new_branch_info->commit);
10061012
}
10071013

10081014
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)->maybe_tree->object;
401+
obj = &get_commit_tree(((struct commit *)obj))->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->maybe_tree->object.oid,
582-
&commit->maybe_tree->object.oid, "", &rev->diffopt);
581+
diff_tree_oid(get_commit_tree_oid(commit->parents->item),
582+
get_commit_tree_oid(commit), "", &rev->diffopt);
583583
}
584584
else
585-
diff_root_tree_oid(&commit->maybe_tree->object.oid,
585+
diff_root_tree_oid(get_commit_tree_oid(commit),
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->maybe_tree->object.oid,
1068-
&head->maybe_tree->object.oid,
1067+
diff_tree_oid(get_commit_tree_oid(origin),
1068+
get_commit_tree_oid(head),
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->maybe_tree->object.oid)) {
156+
if (!tree_is_complete(get_commit_tree_oid(c))) {
157157
is_incomplete = 1;
158158
c->object.flags |= INCOMPLETE;
159159
}

commit-graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)->maybe_tree->object.oid.hash, hash_len);
372+
hashwrite(f, get_commit_tree_oid(*list)->hash, hash_len);
373373

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

contrib/coccinelle/commit.cocci

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@@
2+
expression c;
3+
@@
4+
- &c->maybe_tree->object.oid
5+
+ get_commit_tree_oid(c)
6+
7+
@@
8+
expression c;
9+
@@
10+
- c->maybe_tree->object.oid.hash
11+
+ get_commit_tree_oid(c)->hash
12+
13+
@@
14+
expression c;
15+
@@
16+
- c->maybe_tree
17+
+ get_commit_tree(c)
18+
19+
@@
20+
expression c;
21+
expression s;
22+
@@
23+
- get_commit_tree(c) = s
24+
+ c->maybe_tree = s
25+
26+
@@
27+
expression c;
28+
@@
29+
- return get_commit_tree(c);
30+
+ return c->maybe_tree;

fsck.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,11 @@ 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->maybe_tree->object, "%s:", name);
399+
put_object_name(options, &get_commit_tree(commit)->object,
400+
"%s:", name);
400401

401-
result = options->walk((struct object *)commit->maybe_tree, OBJ_TREE, data, options);
402+
result = options->walk((struct object *)get_commit_tree(commit),
403+
OBJ_TREE, data, options);
402404
if (result < 0)
403405
return result;
404406
res = result;
@@ -772,7 +774,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
772774
err = fsck_ident(&buffer, &commit->object, options);
773775
if (err)
774776
return err;
775-
if (!commit->maybe_tree) {
777+
if (!get_commit_tree(commit)) {
776778
err = report(options, &commit->object, FSCK_MSG_BAD_TREE, "could not load commit's tree %s", sha1_to_hex(tree_sha1));
777779
if (err)
778780
return err;

http-push.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ static int get_delta(struct rev_info *revs, struct remote_lock *lock)
13301330
int count = 0;
13311331

13321332
while ((commit = get_revision(revs)) != NULL) {
1333-
p = process_tree(commit->maybe_tree, p);
1333+
p = process_tree(get_commit_tree(commit), p);
13341334
commit->object.flags |= LOCAL;
13351335
if (!(commit->object.flags & UNINTERESTING))
13361336
count += add_send_request(&commit->object, lock);

0 commit comments

Comments
 (0)