@matheusbsbs / matheus-bagliano / commits / c49c82aa4c
Fork 0

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 <abhishekkumar8222@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Abhishek Kumar committed Jun 17, 2020 at 14:44 UTC c49c82aa4c1036ba1629f73223cff53230e695f3
9 files changed +78 -64
alloc.c
-2
@@ -114,8 +114,6 @@ void init_commit_node(struct commit *c)
114 {
115 c->object.type = OBJ_COMMIT;
116 c->index = alloc_commit_index();
117 - c->graph_pos = COMMIT_NOT_FROM_GRAPH;
118 - c->generation = GENERATION_NUMBER_INFINITY;
117 }
118
119 void *alloc_commit_node(struct repository *r)
blame.c
+1 -1
@@ -1272,7 +1272,7 @@ static int maybe_changed_path(struct repository *r,
1272 if (!bd)
1273 return 1;
1274
1275 - if (origin->commit->generation == GENERATION_NUMBER_INFINITY)
1275 + if (commit_graph_generation(origin->commit) == GENERATION_NUMBER_INFINITY)
1276 return 1;
1277
1278 filter = get_bloom_filter(r, origin->commit, 0);
bloom.c
+3 -3
@@ -34,14 +34,14 @@ static int load_bloom_filter_from_graph(struct commit_graph *g,
34 {
35 uint32_t lex_pos, start_index, end_index;
36
37 - while (c->graph_pos < g->num_commits_in_base)
37 + while (commit_graph_position(c) < g->num_commits_in_base)
38 g = g->base_graph;
39
40 /* The commit graph commit 'c' lives in doesn't carry bloom filters. */
41 if (!g->chunk_bloom_indexes)
42 return 0;
43
44 - lex_pos = c->graph_pos - g->num_commits_in_base;
44 + lex_pos = commit_graph_position(c) - g->num_commits_in_base;
45
46 end_index = get_be32(g->chunk_bloom_indexes + 4 * lex_pos);
47
@@ -193,7 +193,7 @@ struct bloom_filter *get_bloom_filter(struct repository *r,
193
194 if (!filter->data) {
195 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 &&
197 r->objects->commit_graph->chunk_bloom_indexes) {
198 if (load_bloom_filter_from_graph(r->objects->commit_graph, filter, c))
199 return filter;
commit-graph.c
+20 -20
@@ -145,9 +145,9 @@ static int commit_gen_cmp(const void *va, const void *vb)
145 const struct commit *b = *(const struct commit **)vb;
146
147 /* lower generation commits first */
148 - if (a->generation < b->generation)
148 + if (commit_graph_generation(a) < commit_graph_generation(b))
149 return -1;
150 - else if (a->generation > b->generation)
150 + else if (commit_graph_generation(a) > commit_graph_generation(b))
151 return 1;
152
153 /* use date as a heuristic when generations are equal */
@@ -722,7 +722,7 @@ static struct commit_list **insert_parent_or_die(struct repository *r,
722 c = lookup_commit(r, &oid);
723 if (!c)
724 die(_("could not find commit %s"), oid_to_hex(&oid));
725 - c->graph_pos = pos;
725 + commit_graph_data_at(c)->graph_pos = pos;
726 return &commit_list_insert(c, pptr)->next;
727 }
728
@@ -736,8 +736,8 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
736
737 lex_index = pos - g->num_commits_in_base;
738 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;
741 }
742
743 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,
766 * Store the "full" position, but then use the
767 * "local" position for the rest of the calculation.
768 */
769 - item->graph_pos = pos;
769 + commit_graph_data_at(item)->graph_pos = pos;
770 lex_index = pos - g->num_commits_in_base;
771
772 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,
779 date_low = get_be32(commit_data + g->hash_len + 12);
780 item->date = (timestamp_t)((date_high << 32) | date_low);
781
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;
783
784 pptr = &item->parents;
785
@@ -811,8 +811,8 @@ static int fill_commit_in_graph(struct repository *r,
811
812 static int find_commit_in_graph(struct commit *item, struct commit_graph *g, uint32_t *pos)
813 {
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);
816 return 1;
817 } else {
818 struct commit_graph *cur_g = g;
@@ -868,11 +868,11 @@ static struct tree *load_tree_for_commit(struct repository *r,
868 struct object_id oid;
869 const unsigned char *commit_data;
870
871 - while (c->graph_pos < g->num_commits_in_base)
871 + while (commit_graph_position(c) < g->num_commits_in_base)
872 g = g->base_graph;
873
874 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);
876
877 hashcpy(oid.hash, commit_data);
878 set_commit_tree(c, lookup_tree(r, &oid));
@@ -886,7 +886,7 @@ static struct tree *get_commit_tree_in_graph_one(struct repository *r,
886 {
887 if (c->maybe_tree)
888 return c->maybe_tree;
889 - if (c->graph_pos == COMMIT_NOT_FROM_GRAPH)
889 + if (commit_graph_position(c) == COMMIT_NOT_FROM_GRAPH)
890 BUG("get_commit_tree_in_graph_one called from non-commit-graph commit");
891
892 return load_tree_for_commit(r, g, (struct commit *)c);
@@ -1271,7 +1271,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
1271 continue;
1272 if (ctx->split) {
1273 if ((!parse_commit(commit) &&
1274 - commit->graph_pos == COMMIT_NOT_FROM_GRAPH) ||
1274 + commit_graph_position(commit) == COMMIT_NOT_FROM_GRAPH) ||
1275 flags == COMMIT_GRAPH_SPLIT_REPLACE)
1276 add_missing_parents(ctx, commit);
1277 } else if (!parse_commit_no_graph(commit))
@@ -1516,7 +1516,7 @@ static uint32_t count_distinct_commits(struct write_commit_graph_context *ctx)
1516 if (ctx->split) {
1517 struct commit *c = lookup_commit(ctx->r, &ctx->oids.list[i]);
1518
1519 - if (!c || c->graph_pos != COMMIT_NOT_FROM_GRAPH)
1519 + if (!c || commit_graph_position(c) != COMMIT_NOT_FROM_GRAPH)
1520 continue;
1521 }
1522
@@ -1550,7 +1550,7 @@ static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
1550 ctx->commits.list[ctx->commits.nr] = lookup_commit(ctx->r, &ctx->oids.list[i]);
1551
1552 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)
1554 continue;
1555
1556 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)
2337 oid_to_hex(&graph_parents->item->object.oid),
2338 oid_to_hex(&odb_parents->item->object.oid));
2339
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);
2342
2343 graph_parents = graph_parents->next;
2344 odb_parents = odb_parents->next;
@@ -2348,7 +2348,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
2348 graph_report(_("commit-graph parent list for commit %s terminates early"),
2349 oid_to_hex(&cur_oid));
2350
2351 - if (!graph_commit->generation) {
2351 + if (!commit_graph_generation(graph_commit)) {
2352 if (generation_zero == GENERATION_NUMBER_EXISTS)
2353 graph_report(_("commit-graph has generation number zero for commit %s, but non-zero elsewhere"),
2354 oid_to_hex(&cur_oid));
@@ -2368,10 +2368,10 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
2368 if (max_generation == GENERATION_NUMBER_MAX)
2369 max_generation--;
2370
2371 - if (graph_commit->generation != max_generation + 1)
2371 + if (commit_graph_generation(graph_commit) != max_generation + 1)
2372 graph_report(_("commit-graph generation for commit %s is %u != %u"),
2373 oid_to_hex(&cur_oid),
2374 - graph_commit->generation,
2374 + commit_graph_generation(graph_commit),
2375 max_generation + 1);
2376
2377 if (graph_commit->date != odb_commit->date)
commit-reach.c
+25 -25
@@ -59,13 +59,13 @@ static struct commit_list *paint_down_to_common(struct repository *r,
59 struct commit_list *parents;
60 int flags;
61
62 - if (min_generation && commit->generation > last_gen)
62 + if (min_generation && commit_graph_generation(commit) > last_gen)
63 BUG("bad generation skip %8x > %8x at %s",
64 - commit->generation, last_gen,
64 + commit_graph_generation(commit), last_gen,
65 oid_to_hex(&commit->object.oid));
66 - last_gen = commit->generation;
66 + last_gen = commit_graph_generation(commit);
67
68 - if (commit->generation < min_generation)
68 + if (commit_graph_generation(commit) < min_generation)
69 break;
70
71 flags = commit->object.flags & (PARENT1 | PARENT2 | STALE);
@@ -176,7 +176,7 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt
176 repo_parse_commit(r, array[i]);
177 for (i = 0; i < cnt; i++) {
178 struct commit_list *common;
179 - uint32_t min_generation = array[i]->generation;
179 + uint32_t min_generation = commit_graph_generation(array[i]);
180
181 if (redundant[i])
182 continue;
@@ -186,8 +186,8 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt
186 filled_index[filled] = j;
187 work[filled++] = array[j];
188
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]);
191 }
192 common = paint_down_to_common(r, array[i], filled,
193 work, min_generation);
@@ -323,16 +323,16 @@ int repo_in_merge_bases_many(struct repository *r, struct commit *commit,
323 for (i = 0; i < nr_reference; i++) {
324 if (repo_parse_commit(r, reference[i]))
325 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]);
328 }
329
330 - if (commit->generation > min_generation)
330 + if (commit_graph_generation(commit) > min_generation)
331 return ret;
332
333 bases = paint_down_to_common(r, commit,
334 nr_reference, reference,
335 - commit->generation);
335 + commit_graph_generation(commit));
336 if (commit->object.flags & PARENT2)
337 ret = 1;
338 clear_commit_marks(commit, all_flags);
@@ -467,7 +467,7 @@ static enum contains_result contains_test(struct commit *candidate,
467 /* Otherwise, we don't know; prepare to recurse */
468 parse_commit_or_die(candidate);
469
470 - if (candidate->generation < cutoff)
470 + if (commit_graph_generation(candidate) < cutoff)
471 return CONTAINS_NO;
472
473 return CONTAINS_UNKNOWN;
@@ -492,8 +492,8 @@ static enum contains_result contains_tag_algo(struct commit *candidate,
492 for (p = want; p; p = p->next) {
493 struct commit *c = p->item;
494 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);
497 }
498
499 result = contains_test(candidate, want, cache, cutoff);
@@ -544,9 +544,9 @@ static int compare_commits_by_gen(const void *_a, const void *_b)
544 const struct commit *a = *(const struct commit * const *)_a;
545 const struct commit *b = *(const struct commit * const *)_b;
546
547 - if (a->generation < b->generation)
547 + if (commit_graph_generation(a) < commit_graph_generation(b))
548 return -1;
549 - if (a->generation > b->generation)
549 + if (commit_graph_generation(a) > commit_graph_generation(b))
550 return 1;
551 return 0;
552 }
@@ -585,7 +585,7 @@ int can_all_from_reach_with_flag(struct object_array *from,
585
586 list[nr_commits] = (struct commit *)from_one;
587 if (parse_commit(list[nr_commits]) ||
588 - list[nr_commits]->generation < min_generation) {
588 + commit_graph_generation(list[nr_commits]) < min_generation) {
589 result = 0;
590 goto cleanup;
591 }
@@ -621,7 +621,7 @@ int can_all_from_reach_with_flag(struct object_array *from,
621
622 if (parse_commit(parent->item) ||
623 parent->item->date < min_commit_date ||
624 - parent->item->generation < min_generation)
624 + commit_graph_generation(parent->item) < min_generation)
625 continue;
626
627 commit_list_insert(parent->item, &stack);
@@ -665,8 +665,8 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to,
665 if (from_iter->item->date < min_commit_date)
666 min_commit_date = from_iter->item->date;
667
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);
670 }
671
672 from_iter = from_iter->next;
@@ -677,8 +677,8 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to,
677 if (to_iter->item->date < min_commit_date)
678 min_commit_date = to_iter->item->date;
679
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);
682 }
683
684 to_iter->item->object.flags |= PARENT2;
@@ -721,8 +721,8 @@ struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
721 struct commit *c = *item;
722
723 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);
726
727 if (!(c->object.flags & PARENT1)) {
728 c->object.flags |= PARENT1;
@@ -755,7 +755,7 @@ struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
755
756 parse_commit(p);
757
758 - if (p->generation < min_generation)
758 + if (commit_graph_generation(p) < min_generation)
759 continue;
760
761 if (p->object.flags & PARENT2)
commit.c
+3 -3
@@ -339,7 +339,7 @@ struct tree *repo_get_commit_tree(struct repository *r,
339 if (commit->maybe_tree || !commit->object.parsed)
340 return commit->maybe_tree;
341
342 - if (commit->graph_pos != COMMIT_NOT_FROM_GRAPH)
342 + if (commit_graph_position(commit) != COMMIT_NOT_FROM_GRAPH)
343 return get_commit_tree_in_graph(r, commit);
344
345 return NULL;
@@ -731,9 +731,9 @@ int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void
731 const struct commit *a = a_, *b = b_;
732
733 /* newer commits first */
734 - if (a->generation < b->generation)
734 + if (commit_graph_generation(a) < commit_graph_generation(b))
735 return 1;
736 - else if (a->generation > b->generation)
736 + else if (commit_graph_generation(a) > commit_graph_generation(b))
737 return -1;
738
739 /* use date as a heuristic when generations are equal */
commit.h
-2
@@ -36,8 +36,6 @@ struct commit {
36 * or get_commit_tree_oid().
37 */
38 struct tree *maybe_tree;
39 - uint32_t graph_pos;
40 - uint32_t generation;
39 unsigned int index;
40 };
41
contrib/coccinelle/commit.cocci
+18
@@ -32,3 +32,21 @@ expression c;
32 - c->maybe_tree
33 + repo_get_commit_tree(specify_the_right_repo_here, c)
34 ...>}
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 +)
revision.c
+8 -8
@@ -725,7 +725,7 @@ static int check_maybe_different_in_bloom_filter(struct rev_info *revs,
725 if (!revs->repo->objects->commit_graph)
726 return -1;
727
728 - if (commit->generation == GENERATION_NUMBER_INFINITY)
728 + if (commit_graph_generation(commit) == GENERATION_NUMBER_INFINITY)
729 return -1;
730
731 filter = get_bloom_filter(revs->repo, commit, 0);
@@ -3320,7 +3320,7 @@ static void explore_to_depth(struct rev_info *revs,
3320 struct topo_walk_info *info = revs->topo_walk_info;
3321 struct commit *c;
3322 while ((c = prio_queue_peek(&info->explore_queue)) &&
3323 - c->generation >= gen_cutoff)
3323 + commit_graph_generation(c) >= gen_cutoff)
3324 explore_walk_step(revs);
3325 }
3326
@@ -3336,7 +3336,7 @@ static void indegree_walk_step(struct rev_info *revs)
3336 if (parse_commit_gently(c, 1) < 0)
3337 return;
3338
3339 - explore_to_depth(revs, c->generation);
3339 + explore_to_depth(revs, commit_graph_generation(c));
3340
3341 for (p = c->parents; p; p = p->next) {
3342 struct commit *parent = p->item;
@@ -3360,7 +3360,7 @@ static void compute_indegrees_to_depth(struct rev_info *revs,
3360 struct topo_walk_info *info = revs->topo_walk_info;
3361 struct commit *c;
3362 while ((c = prio_queue_peek(&info->indegree_queue)) &&
3363 - c->generation >= gen_cutoff)
3363 + commit_graph_generation(c) >= gen_cutoff)
3364 indegree_walk_step(revs);
3365 }
3366
@@ -3420,8 +3420,8 @@ static void init_topo_walk(struct rev_info *revs)
3420 test_flag_and_insert(&info->explore_queue, c, TOPO_WALK_EXPLORED);
3421 test_flag_and_insert(&info->indegree_queue, c, TOPO_WALK_INDEGREE);
3422
3423 - if (c->generation < info->min_generation)
3424 - info->min_generation = c->generation;
3423 + if (commit_graph_generation(c) < info->min_generation)
3424 + info->min_generation = commit_graph_generation(c);
3425
3426 *(indegree_slab_at(&info->indegree, c)) = 1;
3427
@@ -3479,8 +3479,8 @@ static void expand_topo_walk(struct rev_info *revs, struct commit *commit)
3479 if (parse_commit_gently(parent, 1) < 0)
3480 continue;
3481
3482 - if (parent->generation < info->min_generation) {
3483 - info->min_generation = parent->generation;
3482 + if (commit_graph_generation(parent) < info->min_generation) {
3483 + info->min_generation = commit_graph_generation(parent);
3484 compute_indegrees_to_depth(revs, info->min_generation);
3485 }
3486