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);

line-log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,8 @@ static void queue_diffs(struct line_log_data *range,
817817
assert(commit);
818818

819819
DIFF_QUEUE_CLEAR(&diff_queued_diff);
820-
diff_tree_oid(parent ? &parent->maybe_tree->object.oid : NULL,
821-
&commit->maybe_tree->object.oid, "", opt);
820+
diff_tree_oid(parent ? get_commit_tree_oid(parent) : NULL,
821+
get_commit_tree_oid(commit), "", opt);
822822
if (opt->detect_rename) {
823823
filter_diffs_for_paths(range, 1);
824824
if (diff_might_be_rename())

list-objects.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static void mark_edge_parents_uninteresting(struct commit *commit,
195195
struct commit *parent = parents->item;
196196
if (!(parent->object.flags & UNINTERESTING))
197197
continue;
198-
mark_tree_uninteresting(parent->maybe_tree);
198+
mark_tree_uninteresting(get_commit_tree(parent));
199199
if (revs->edge_hint && !(parent->object.flags & SHOWN)) {
200200
parent->object.flags |= SHOWN;
201201
show_edge(parent);
@@ -212,7 +212,7 @@ void mark_edges_uninteresting(struct rev_info *revs, show_edge_fn show_edge)
212212
struct commit *commit = list->item;
213213

214214
if (commit->object.flags & UNINTERESTING) {
215-
mark_tree_uninteresting(commit->maybe_tree);
215+
mark_tree_uninteresting(get_commit_tree(commit));
216216
if (revs->edge_hint_aggressive && !(commit->object.flags & SHOWN)) {
217217
commit->object.flags |= SHOWN;
218218
show_edge(commit);
@@ -227,7 +227,7 @@ void mark_edges_uninteresting(struct rev_info *revs, show_edge_fn show_edge)
227227
struct commit *commit = (struct commit *)obj;
228228
if (obj->type != OBJ_COMMIT || !(obj->flags & UNINTERESTING))
229229
continue;
230-
mark_tree_uninteresting(commit->maybe_tree);
230+
mark_tree_uninteresting(get_commit_tree(commit));
231231
if (!(obj->flags & SHOWN)) {
232232
obj->flags |= SHOWN;
233233
show_edge(commit);
@@ -300,8 +300,8 @@ static void do_traverse(struct rev_info *revs,
300300
* an uninteresting boundary commit may not have its tree
301301
* parsed yet, but we are not going to show them anyway
302302
*/
303-
if (commit->maybe_tree)
304-
add_pending_tree(revs, commit->maybe_tree);
303+
if (get_commit_tree(commit))
304+
add_pending_tree(revs, get_commit_tree(commit));
305305
show_commit(commit, show_data);
306306

307307
if (revs->tree_blobs_in_commit_order)

log-tree.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
806806
return 0;
807807

808808
parse_commit_or_die(commit);
809-
oid = &commit->maybe_tree->object.oid;
809+
oid = get_commit_tree_oid(commit);
810810

811811
/* Root commit? */
812812
parents = get_saved_parents(opt, commit);
@@ -831,7 +831,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
831831
* we merged _in_.
832832
*/
833833
parse_commit_or_die(parents->item);
834-
diff_tree_oid(&parents->item->maybe_tree->object.oid,
834+
diff_tree_oid(get_commit_tree_oid(parents->item),
835835
oid, "", &opt->diffopt);
836836
log_tree_diff_flush(opt);
837837
return !opt->loginfo;
@@ -846,7 +846,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
846846
struct commit *parent = parents->item;
847847

848848
parse_commit_or_die(parent);
849-
diff_tree_oid(&parent->maybe_tree->object.oid,
849+
diff_tree_oid(get_commit_tree_oid(parent),
850850
oid, "", &opt->diffopt);
851851
log_tree_diff_flush(opt);
852852

merge-recursive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,8 +2154,8 @@ int merge_recursive(struct merge_options *o,
21542154
read_cache();
21552155

21562156
o->ancestor = "merged common ancestors";
2157-
clean = merge_trees(o, h1->maybe_tree, h2->maybe_tree,
2158-
merged_common_ancestors->maybe_tree,
2157+
clean = merge_trees(o, get_commit_tree(h1), get_commit_tree(h2),
2158+
get_commit_tree(merged_common_ancestors),
21592159
&mrtree);
21602160
if (clean < 0) {
21612161
flush_output(o);

notes-merge.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,14 +600,14 @@ int notes_merge(struct notes_merge_options *o,
600600
printf("No merge base found; doing history-less merge\n");
601601
} else if (!bases->next) {
602602
base_oid = &bases->item->object.oid;
603-
base_tree_oid = &bases->item->maybe_tree->object.oid;
603+
base_tree_oid = get_commit_tree_oid(bases->item);
604604
if (o->verbosity >= 4)
605605
printf("One merge base found (%.7s)\n",
606606
oid_to_hex(base_oid));
607607
} else {
608608
/* TODO: How to handle multiple merge-bases? */
609609
base_oid = &bases->item->object.oid;
610-
base_tree_oid = &bases->item->maybe_tree->object.oid;
610+
base_tree_oid = get_commit_tree_oid(bases->item);
611611
if (o->verbosity >= 3)
612612
printf("Multiple merge bases found. Using the first "
613613
"(%.7s)\n", oid_to_hex(base_oid));
@@ -634,8 +634,9 @@ int notes_merge(struct notes_merge_options *o,
634634
goto found_result;
635635
}
636636

637-
result = merge_from_diffs(o, base_tree_oid, &local->maybe_tree->object.oid,
638-
&remote->maybe_tree->object.oid, local_tree);
637+
result = merge_from_diffs(o, base_tree_oid,
638+
get_commit_tree_oid(local),
639+
get_commit_tree_oid(remote), local_tree);
639640

640641
if (result != 0) { /* non-trivial merge (with or without conflicts) */
641642
/* Commit (partial) result */

packfile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,7 @@ static int add_promisor_object(const struct object_id *oid,
19251925
struct commit *commit = (struct commit *) obj;
19261926
struct commit_list *parents = commit->parents;
19271927

1928-
oidset_insert(set, &commit->maybe_tree->object.oid);
1928+
oidset_insert(set, get_commit_tree_oid(commit));
19291929
for (; parents; parents = parents->next)
19301930
oidset_insert(set, &parents->item->object.oid);
19311931
} else if (obj->type == OBJ_TAG) {

pretty.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,10 +1161,11 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
11611161
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
11621162
return 1;
11631163
case 'T': /* tree hash */
1164-
strbuf_addstr(sb, oid_to_hex(&commit->maybe_tree->object.oid));
1164+
strbuf_addstr(sb, oid_to_hex(get_commit_tree_oid(commit)));
11651165
return 1;
11661166
case 't': /* abbreviated tree hash */
1167-
strbuf_add_unique_abbrev(sb, commit->maybe_tree->object.oid.hash,
1167+
strbuf_add_unique_abbrev(sb,
1168+
get_commit_tree_oid(commit)->hash,
11681169
c->pretty_ctx->abbrev);
11691170
return 1;
11701171
case 'P': /* parent hashes */

ref-filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object
815815
if (deref)
816816
name++;
817817
if (!strcmp(name, "tree")) {
818-
v->s = xstrdup(oid_to_hex(&commit->maybe_tree->object.oid));
818+
v->s = xstrdup(oid_to_hex(get_commit_tree_oid(commit)));
819819
}
820820
else if (!strcmp(name, "numparent")) {
821821
v->value = commit_list_count(commit->parents);

revision.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ static void file_change(struct diff_options *options,
439439
static int rev_compare_tree(struct rev_info *revs,
440440
struct commit *parent, struct commit *commit)
441441
{
442-
struct tree *t1 = parent->maybe_tree;
443-
struct tree *t2 = commit->maybe_tree;
442+
struct tree *t1 = get_commit_tree(parent);
443+
struct tree *t2 = get_commit_tree(commit);
444444

445445
if (!t1)
446446
return REV_TREE_NEW;
@@ -476,7 +476,7 @@ static int rev_compare_tree(struct rev_info *revs,
476476
static int rev_same_tree_as_empty(struct rev_info *revs, struct commit *commit)
477477
{
478478
int retval;
479-
struct tree *t1 = commit->maybe_tree;
479+
struct tree *t1 = get_commit_tree(commit);
480480

481481
if (!t1)
482482
return 0;
@@ -614,7 +614,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
614614
if (!revs->prune)
615615
return;
616616

617-
if (!commit->maybe_tree)
617+
if (!get_commit_tree(commit))
618618
return;
619619

620620
if (!commit->parents) {

0 commit comments

Comments
 (0)