Skip to content

Commit c49c82a

Browse files
abhishekkumar2718gitster
authored andcommitted
commit: move members graph_pos, generation to a slab
We remove members `graph_pos` and `generation` from the struct commit. The default assignments in init_commit_node() are no longer valid, which is fine as the slab helpers return appropriate default values and the assignments are removed. We will replace existing use of commit->generation and commit->graph_pos by commit_graph_data_slab helpers using `contrib/coccinelle/commit.cocci'. Signed-off-by: Abhishek Kumar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4844812 commit c49c82a

File tree

9 files changed

+78
-64
lines changed

9 files changed

+78
-64
lines changed

alloc.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ void init_commit_node(struct commit *c)
114114
{
115115
c->object.type = OBJ_COMMIT;
116116
c->index = alloc_commit_index();
117-
c->graph_pos = COMMIT_NOT_FROM_GRAPH;
118-
c->generation = GENERATION_NUMBER_INFINITY;
119117
}
120118

121119
void *alloc_commit_node(struct repository *r)

blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ static int maybe_changed_path(struct repository *r,
12721272
if (!bd)
12731273
return 1;
12741274

1275-
if (origin->commit->generation == GENERATION_NUMBER_INFINITY)
1275+
if (commit_graph_generation(origin->commit) == GENERATION_NUMBER_INFINITY)
12761276
return 1;
12771277

12781278
filter = get_bloom_filter(r, origin->commit, 0);

bloom.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ static int load_bloom_filter_from_graph(struct commit_graph *g,
3434
{
3535
uint32_t lex_pos, start_index, end_index;
3636

37-
while (c->graph_pos < g->num_commits_in_base)
37+
while (commit_graph_position(c) < g->num_commits_in_base)
3838
g = g->base_graph;
3939

4040
/* The commit graph commit 'c' lives in doesn't carry bloom filters. */
4141
if (!g->chunk_bloom_indexes)
4242
return 0;
4343

44-
lex_pos = c->graph_pos - g->num_commits_in_base;
44+
lex_pos = commit_graph_position(c) - g->num_commits_in_base;
4545

4646
end_index = get_be32(g->chunk_bloom_indexes + 4 * lex_pos);
4747

@@ -193,7 +193,7 @@ struct bloom_filter *get_bloom_filter(struct repository *r,
193193

194194
if (!filter->data) {
195195
load_commit_graph_info(r, c);
196-
if (c->graph_pos != COMMIT_NOT_FROM_GRAPH &&
196+
if (commit_graph_position(c) != COMMIT_NOT_FROM_GRAPH &&
197197
r->objects->commit_graph->chunk_bloom_indexes) {
198198
if (load_bloom_filter_from_graph(r->objects->commit_graph, filter, c))
199199
return filter;

commit-graph.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ static int commit_gen_cmp(const void *va, const void *vb)
145145
const struct commit *b = *(const struct commit **)vb;
146146

147147
/* lower generation commits first */
148-
if (a->generation < b->generation)
148+
if (commit_graph_generation(a) < commit_graph_generation(b))
149149
return -1;
150-
else if (a->generation > b->generation)
150+
else if (commit_graph_generation(a) > commit_graph_generation(b))
151151
return 1;
152152

153153
/* use date as a heuristic when generations are equal */
@@ -722,7 +722,7 @@ static struct commit_list **insert_parent_or_die(struct repository *r,
722722
c = lookup_commit(r, &oid);
723723
if (!c)
724724
die(_("could not find commit %s"), oid_to_hex(&oid));
725-
c->graph_pos = pos;
725+
commit_graph_data_at(c)->graph_pos = pos;
726726
return &commit_list_insert(c, pptr)->next;
727727
}
728728

@@ -736,8 +736,8 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
736736

737737
lex_index = pos - g->num_commits_in_base;
738738
commit_data = g->chunk_commit_data + GRAPH_DATA_WIDTH * lex_index;
739-
item->graph_pos = pos;
740-
item->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
739+
commit_graph_data_at(item)->graph_pos = pos;
740+
commit_graph_data_at(item)->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
741741
}
742742

743743
static inline void set_commit_tree(struct commit *c, struct tree *t)
@@ -766,7 +766,7 @@ static int fill_commit_in_graph(struct repository *r,
766766
* Store the "full" position, but then use the
767767
* "local" position for the rest of the calculation.
768768
*/
769-
item->graph_pos = pos;
769+
commit_graph_data_at(item)->graph_pos = pos;
770770
lex_index = pos - g->num_commits_in_base;
771771

772772
commit_data = g->chunk_commit_data + (g->hash_len + 16) * lex_index;
@@ -779,7 +779,7 @@ static int fill_commit_in_graph(struct repository *r,
779779
date_low = get_be32(commit_data + g->hash_len + 12);
780780
item->date = (timestamp_t)((date_high << 32) | date_low);
781781

782-
item->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
782+
commit_graph_data_at(item)->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
783783

784784
pptr = &item->parents;
785785

@@ -811,8 +811,8 @@ static int fill_commit_in_graph(struct repository *r,
811811

812812
static int find_commit_in_graph(struct commit *item, struct commit_graph *g, uint32_t *pos)
813813
{
814-
if (item->graph_pos != COMMIT_NOT_FROM_GRAPH) {
815-
*pos = item->graph_pos;
814+
if (commit_graph_position(item) != COMMIT_NOT_FROM_GRAPH) {
815+
*pos = commit_graph_position(item);
816816
return 1;
817817
} else {
818818
struct commit_graph *cur_g = g;
@@ -868,11 +868,11 @@ static struct tree *load_tree_for_commit(struct repository *r,
868868
struct object_id oid;
869869
const unsigned char *commit_data;
870870

871-
while (c->graph_pos < g->num_commits_in_base)
871+
while (commit_graph_position(c) < g->num_commits_in_base)
872872
g = g->base_graph;
873873

874874
commit_data = g->chunk_commit_data +
875-
GRAPH_DATA_WIDTH * (c->graph_pos - g->num_commits_in_base);
875+
GRAPH_DATA_WIDTH * (commit_graph_position(c) - g->num_commits_in_base);
876876

877877
hashcpy(oid.hash, commit_data);
878878
set_commit_tree(c, lookup_tree(r, &oid));
@@ -886,7 +886,7 @@ static struct tree *get_commit_tree_in_graph_one(struct repository *r,
886886
{
887887
if (c->maybe_tree)
888888
return c->maybe_tree;
889-
if (c->graph_pos == COMMIT_NOT_FROM_GRAPH)
889+
if (commit_graph_position(c) == COMMIT_NOT_FROM_GRAPH)
890890
BUG("get_commit_tree_in_graph_one called from non-commit-graph commit");
891891

892892
return load_tree_for_commit(r, g, (struct commit *)c);
@@ -1271,7 +1271,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
12711271
continue;
12721272
if (ctx->split) {
12731273
if ((!parse_commit(commit) &&
1274-
commit->graph_pos == COMMIT_NOT_FROM_GRAPH) ||
1274+
commit_graph_position(commit) == COMMIT_NOT_FROM_GRAPH) ||
12751275
flags == COMMIT_GRAPH_SPLIT_REPLACE)
12761276
add_missing_parents(ctx, commit);
12771277
} else if (!parse_commit_no_graph(commit))
@@ -1516,7 +1516,7 @@ static uint32_t count_distinct_commits(struct write_commit_graph_context *ctx)
15161516
if (ctx->split) {
15171517
struct commit *c = lookup_commit(ctx->r, &ctx->oids.list[i]);
15181518

1519-
if (!c || c->graph_pos != COMMIT_NOT_FROM_GRAPH)
1519+
if (!c || commit_graph_position(c) != COMMIT_NOT_FROM_GRAPH)
15201520
continue;
15211521
}
15221522

@@ -1550,7 +1550,7 @@ static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
15501550
ctx->commits.list[ctx->commits.nr] = lookup_commit(ctx->r, &ctx->oids.list[i]);
15511551

15521552
if (ctx->split && flags != COMMIT_GRAPH_SPLIT_REPLACE &&
1553-
ctx->commits.list[ctx->commits.nr]->graph_pos != COMMIT_NOT_FROM_GRAPH)
1553+
commit_graph_position(ctx->commits.list[ctx->commits.nr]) != COMMIT_NOT_FROM_GRAPH)
15541554
continue;
15551555

15561556
if (ctx->split && flags == COMMIT_GRAPH_SPLIT_REPLACE)
@@ -2337,8 +2337,8 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
23372337
oid_to_hex(&graph_parents->item->object.oid),
23382338
oid_to_hex(&odb_parents->item->object.oid));
23392339

2340-
if (graph_parents->item->generation > max_generation)
2341-
max_generation = graph_parents->item->generation;
2340+
if (commit_graph_generation(graph_parents->item) > max_generation)
2341+
max_generation = commit_graph_generation(graph_parents->item);
23422342

23432343
graph_parents = graph_parents->next;
23442344
odb_parents = odb_parents->next;
@@ -2348,7 +2348,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
23482348
graph_report(_("commit-graph parent list for commit %s terminates early"),
23492349
oid_to_hex(&cur_oid));
23502350

2351-
if (!graph_commit->generation) {
2351+
if (!commit_graph_generation(graph_commit)) {
23522352
if (generation_zero == GENERATION_NUMBER_EXISTS)
23532353
graph_report(_("commit-graph has generation number zero for commit %s, but non-zero elsewhere"),
23542354
oid_to_hex(&cur_oid));
@@ -2368,10 +2368,10 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
23682368
if (max_generation == GENERATION_NUMBER_MAX)
23692369
max_generation--;
23702370

2371-
if (graph_commit->generation != max_generation + 1)
2371+
if (commit_graph_generation(graph_commit) != max_generation + 1)
23722372
graph_report(_("commit-graph generation for commit %s is %u != %u"),
23732373
oid_to_hex(&cur_oid),
2374-
graph_commit->generation,
2374+
commit_graph_generation(graph_commit),
23752375
max_generation + 1);
23762376

23772377
if (graph_commit->date != odb_commit->date)

commit-reach.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ static struct commit_list *paint_down_to_common(struct repository *r,
5959
struct commit_list *parents;
6060
int flags;
6161

62-
if (min_generation && commit->generation > last_gen)
62+
if (min_generation && commit_graph_generation(commit) > last_gen)
6363
BUG("bad generation skip %8x > %8x at %s",
64-
commit->generation, last_gen,
64+
commit_graph_generation(commit), last_gen,
6565
oid_to_hex(&commit->object.oid));
66-
last_gen = commit->generation;
66+
last_gen = commit_graph_generation(commit);
6767

68-
if (commit->generation < min_generation)
68+
if (commit_graph_generation(commit) < min_generation)
6969
break;
7070

7171
flags = commit->object.flags & (PARENT1 | PARENT2 | STALE);
@@ -176,7 +176,7 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt
176176
repo_parse_commit(r, array[i]);
177177
for (i = 0; i < cnt; i++) {
178178
struct commit_list *common;
179-
uint32_t min_generation = array[i]->generation;
179+
uint32_t min_generation = commit_graph_generation(array[i]);
180180

181181
if (redundant[i])
182182
continue;
@@ -186,8 +186,8 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt
186186
filled_index[filled] = j;
187187
work[filled++] = array[j];
188188

189-
if (array[j]->generation < min_generation)
190-
min_generation = array[j]->generation;
189+
if (commit_graph_generation(array[j]) < min_generation)
190+
min_generation = commit_graph_generation(array[j]);
191191
}
192192
common = paint_down_to_common(r, array[i], filled,
193193
work, min_generation);
@@ -323,16 +323,16 @@ int repo_in_merge_bases_many(struct repository *r, struct commit *commit,
323323
for (i = 0; i < nr_reference; i++) {
324324
if (repo_parse_commit(r, reference[i]))
325325
return ret;
326-
if (reference[i]->generation < min_generation)
327-
min_generation = reference[i]->generation;
326+
if (commit_graph_generation(reference[i]) < min_generation)
327+
min_generation = commit_graph_generation(reference[i]);
328328
}
329329

330-
if (commit->generation > min_generation)
330+
if (commit_graph_generation(commit) > min_generation)
331331
return ret;
332332

333333
bases = paint_down_to_common(r, commit,
334334
nr_reference, reference,
335-
commit->generation);
335+
commit_graph_generation(commit));
336336
if (commit->object.flags & PARENT2)
337337
ret = 1;
338338
clear_commit_marks(commit, all_flags);
@@ -467,7 +467,7 @@ static enum contains_result contains_test(struct commit *candidate,
467467
/* Otherwise, we don't know; prepare to recurse */
468468
parse_commit_or_die(candidate);
469469

470-
if (candidate->generation < cutoff)
470+
if (commit_graph_generation(candidate) < cutoff)
471471
return CONTAINS_NO;
472472

473473
return CONTAINS_UNKNOWN;
@@ -492,8 +492,8 @@ static enum contains_result contains_tag_algo(struct commit *candidate,
492492
for (p = want; p; p = p->next) {
493493
struct commit *c = p->item;
494494
load_commit_graph_info(the_repository, c);
495-
if (c->generation < cutoff)
496-
cutoff = c->generation;
495+
if (commit_graph_generation(c) < cutoff)
496+
cutoff = commit_graph_generation(c);
497497
}
498498

499499
result = contains_test(candidate, want, cache, cutoff);
@@ -544,9 +544,9 @@ static int compare_commits_by_gen(const void *_a, const void *_b)
544544
const struct commit *a = *(const struct commit * const *)_a;
545545
const struct commit *b = *(const struct commit * const *)_b;
546546

547-
if (a->generation < b->generation)
547+
if (commit_graph_generation(a) < commit_graph_generation(b))
548548
return -1;
549-
if (a->generation > b->generation)
549+
if (commit_graph_generation(a) > commit_graph_generation(b))
550550
return 1;
551551
return 0;
552552
}
@@ -585,7 +585,7 @@ int can_all_from_reach_with_flag(struct object_array *from,
585585

586586
list[nr_commits] = (struct commit *)from_one;
587587
if (parse_commit(list[nr_commits]) ||
588-
list[nr_commits]->generation < min_generation) {
588+
commit_graph_generation(list[nr_commits]) < min_generation) {
589589
result = 0;
590590
goto cleanup;
591591
}
@@ -621,7 +621,7 @@ int can_all_from_reach_with_flag(struct object_array *from,
621621

622622
if (parse_commit(parent->item) ||
623623
parent->item->date < min_commit_date ||
624-
parent->item->generation < min_generation)
624+
commit_graph_generation(parent->item) < min_generation)
625625
continue;
626626

627627
commit_list_insert(parent->item, &stack);
@@ -665,8 +665,8 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to,
665665
if (from_iter->item->date < min_commit_date)
666666
min_commit_date = from_iter->item->date;
667667

668-
if (from_iter->item->generation < min_generation)
669-
min_generation = from_iter->item->generation;
668+
if (commit_graph_generation(from_iter->item) < min_generation)
669+
min_generation = commit_graph_generation(from_iter->item);
670670
}
671671

672672
from_iter = from_iter->next;
@@ -677,8 +677,8 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to,
677677
if (to_iter->item->date < min_commit_date)
678678
min_commit_date = to_iter->item->date;
679679

680-
if (to_iter->item->generation < min_generation)
681-
min_generation = to_iter->item->generation;
680+
if (commit_graph_generation(to_iter->item) < min_generation)
681+
min_generation = commit_graph_generation(to_iter->item);
682682
}
683683

684684
to_iter->item->object.flags |= PARENT2;
@@ -721,8 +721,8 @@ struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
721721
struct commit *c = *item;
722722

723723
parse_commit(c);
724-
if (c->generation < min_generation)
725-
min_generation = c->generation;
724+
if (commit_graph_generation(c) < min_generation)
725+
min_generation = commit_graph_generation(c);
726726

727727
if (!(c->object.flags & PARENT1)) {
728728
c->object.flags |= PARENT1;
@@ -755,7 +755,7 @@ struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
755755

756756
parse_commit(p);
757757

758-
if (p->generation < min_generation)
758+
if (commit_graph_generation(p) < min_generation)
759759
continue;
760760

761761
if (p->object.flags & PARENT2)

commit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ struct tree *repo_get_commit_tree(struct repository *r,
339339
if (commit->maybe_tree || !commit->object.parsed)
340340
return commit->maybe_tree;
341341

342-
if (commit->graph_pos != COMMIT_NOT_FROM_GRAPH)
342+
if (commit_graph_position(commit) != COMMIT_NOT_FROM_GRAPH)
343343
return get_commit_tree_in_graph(r, commit);
344344

345345
return NULL;
@@ -731,9 +731,9 @@ int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void
731731
const struct commit *a = a_, *b = b_;
732732

733733
/* newer commits first */
734-
if (a->generation < b->generation)
734+
if (commit_graph_generation(a) < commit_graph_generation(b))
735735
return 1;
736-
else if (a->generation > b->generation)
736+
else if (commit_graph_generation(a) > commit_graph_generation(b))
737737
return -1;
738738

739739
/* use date as a heuristic when generations are equal */

commit.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ struct commit {
3636
* or get_commit_tree_oid().
3737
*/
3838
struct tree *maybe_tree;
39-
uint32_t graph_pos;
40-
uint32_t generation;
4139
unsigned int index;
4240
};
4341

contrib/coccinelle/commit.cocci

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,21 @@ expression c;
3232
- c->maybe_tree
3333
+ repo_get_commit_tree(specify_the_right_repo_here, c)
3434
...>}
35+
36+
@@
37+
struct commit *c;
38+
expression E;
39+
@@
40+
(
41+
- c->generation = E;
42+
+ commit_graph_data_at(c)->generation = E;
43+
|
44+
- c->graph_pos = E;
45+
+ commit_graph_data_at(c)->graph_pos = E;
46+
|
47+
- c->generation
48+
+ commit_graph_generation(c)
49+
|
50+
- c->graph_pos
51+
+ commit_graph_position(c)
52+
)

0 commit comments

Comments
 (0)