commit-graph: return 64-bit generation number
In a preparatory step for introducing corrected commit dates, let's return timestamp_t values from commit_graph_generation(), use timestamp_t for local variables and define GENERATION_NUMBER_INFINITY as (2 ^ 63 - 1) instead. We rename GENERATION_NUMBER_MAX to GENERATION_NUMBER_V1_MAX to represent the largest topological level we can store in the commit data chunk. With corrected commit dates implemented, we will have two such *_MAX variables to denote the largest offset and largest topological level that can be stored. Signed-off-by: Abhishek Kumar <abhishekkumar8222@gmail.com> Reviewed-by: Taylor Blau <me@ttaylorr.com> Reviewed-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Abhishek Kumar committed
Jan 16, 2021 at 18:11 UTC
d7f92784c65b143c5ec9f435484146b6098c2f85
8 files changed
+42
-42
commit-graph.c
+11
-11
@@ -101,7 +101,7 @@ uint32_t commit_graph_position(const struct commit *c)
101
return data ? data->graph_pos : COMMIT_NOT_FROM_GRAPH;
102
}
103
104
-uint32_t commit_graph_generation(const struct commit *c)
104
+timestamp_t commit_graph_generation(const struct commit *c)
105
{
106
struct commit_graph_data *data =
107
commit_graph_data_slab_peek(&commit_graph_data_slab, c);
@@ -150,8 +150,8 @@ static int commit_gen_cmp(const void *va, const void *vb)
150
const struct commit *a = *(const struct commit **)va;
151
const struct commit *b = *(const struct commit **)vb;
152
153
- uint32_t generation_a = commit_graph_data_at(a)->generation;
154
- uint32_t generation_b = commit_graph_data_at(b)->generation;
153
+ const timestamp_t generation_a = commit_graph_data_at(a)->generation;
154
+ const timestamp_t generation_b = commit_graph_data_at(b)->generation;
155
/* lower generation commits first */
156
if (generation_a < generation_b)
157
return -1;
@@ -1370,8 +1370,8 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
1370
if (all_parents_computed) {
1371
pop_commit(&list);
1372
1373
- if (max_level > GENERATION_NUMBER_MAX - 1)
1374
- max_level = GENERATION_NUMBER_MAX - 1;
1373
+ if (max_level > GENERATION_NUMBER_V1_MAX - 1)
1374
+ max_level = GENERATION_NUMBER_V1_MAX - 1;
1375
*topo_level_slab_at(ctx->topo_levels, current) = max_level + 1;
1376
}
1377
}
@@ -2367,8 +2367,8 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
2367
for (i = 0; i < g->num_commits; i++) {
2368
struct commit *graph_commit, *odb_commit;
2369
struct commit_list *graph_parents, *odb_parents;
2370
- uint32_t max_generation = 0;
2371
- uint32_t generation;
2370
+ timestamp_t max_generation = 0;
2371
+ timestamp_t generation;
2372
2373
display_progress(progress, i + 1);
2374
hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i);
@@ -2432,16 +2432,16 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
2432
continue;
2433
2434
/*
2435
- * If one of our parents has generation GENERATION_NUMBER_MAX, then
2436
- * our generation is also GENERATION_NUMBER_MAX. Decrement to avoid
2435
+ * If one of our parents has generation GENERATION_NUMBER_V1_MAX, then
2436
+ * our generation is also GENERATION_NUMBER_V1_MAX. Decrement to avoid
2437
* extra logic in the following condition.
2438
*/
2439
- if (max_generation == GENERATION_NUMBER_MAX)
2439
+ if (max_generation == GENERATION_NUMBER_V1_MAX)
2440
max_generation--;
2441
2442
generation = commit_graph_generation(graph_commit);
2443
if (generation != max_generation + 1)
2444
- graph_report(_("commit-graph generation for commit %s is %u != %u"),
2444
+ graph_report(_("commit-graph generation for commit %s is %"PRItime" != %"PRItime),
2445
oid_to_hex(&cur_oid),
2446
generation,
2447
max_generation + 1);
commit-graph.h
+2
-2
@@ -145,12 +145,12 @@ void disable_commit_graph(struct repository *r);
145
146
struct commit_graph_data {
147
uint32_t graph_pos;
148
- uint32_t generation;
148
+ timestamp_t generation;
149
};
150
151
/*
152
* Commits should be parsed before accessing generation, graph positions.
153
*/
154
-uint32_t commit_graph_generation(const struct commit *);
154
+timestamp_t commit_graph_generation(const struct commit *);
155
uint32_t commit_graph_position(const struct commit *);
156
#endif
commit-reach.c
+18
-18
@@ -32,12 +32,12 @@ static int queue_has_nonstale(struct prio_queue *queue)
32
static struct commit_list *paint_down_to_common(struct repository *r,
33
struct commit *one, int n,
34
struct commit **twos,
35
- int min_generation)
35
+ timestamp_t min_generation)
36
{
37
struct prio_queue queue = { compare_commits_by_gen_then_commit_date };
38
struct commit_list *result = NULL;
39
int i;
40
- uint32_t last_gen = GENERATION_NUMBER_INFINITY;
40
+ timestamp_t last_gen = GENERATION_NUMBER_INFINITY;
41
42
if (!min_generation)
43
queue.compare = compare_commits_by_commit_date;
@@ -58,10 +58,10 @@ static struct commit_list *paint_down_to_common(struct repository *r,
58
struct commit *commit = prio_queue_get(&queue);
59
struct commit_list *parents;
60
int flags;
61
- uint32_t generation = commit_graph_generation(commit);
61
+ timestamp_t generation = commit_graph_generation(commit);
62
63
if (min_generation && generation > last_gen)
64
- BUG("bad generation skip %8x > %8x at %s",
64
+ BUG("bad generation skip %"PRItime" > %"PRItime" at %s",
65
generation, last_gen,
66
oid_to_hex(&commit->object.oid));
67
last_gen = generation;
@@ -177,12 +177,12 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt
177
repo_parse_commit(r, array[i]);
178
for (i = 0; i < cnt; i++) {
179
struct commit_list *common;
180
- uint32_t min_generation = commit_graph_generation(array[i]);
180
+ timestamp_t min_generation = commit_graph_generation(array[i]);
181
182
if (redundant[i])
183
continue;
184
for (j = filled = 0; j < cnt; j++) {
185
- uint32_t curr_generation;
185
+ timestamp_t curr_generation;
186
if (i == j || redundant[j])
187
continue;
188
filled_index[filled] = j;
@@ -321,7 +321,7 @@ int repo_in_merge_bases_many(struct repository *r, struct commit *commit,
321
{
322
struct commit_list *bases;
323
int ret = 0, i;
324
- uint32_t generation, max_generation = GENERATION_NUMBER_ZERO;
324
+ timestamp_t generation, max_generation = GENERATION_NUMBER_ZERO;
325
326
if (repo_parse_commit(r, commit))
327
return ret;
@@ -470,7 +470,7 @@ static int in_commit_list(const struct commit_list *want, struct commit *c)
470
static enum contains_result contains_test(struct commit *candidate,
471
const struct commit_list *want,
472
struct contains_cache *cache,
473
- uint32_t cutoff)
473
+ timestamp_t cutoff)
474
{
475
enum contains_result *cached = contains_cache_at(cache, candidate);
476
@@ -506,11 +506,11 @@ static enum contains_result contains_tag_algo(struct commit *candidate,
506
{
507
struct contains_stack contains_stack = { 0, 0, NULL };
508
enum contains_result result;
509
- uint32_t cutoff = GENERATION_NUMBER_INFINITY;
509
+ timestamp_t cutoff = GENERATION_NUMBER_INFINITY;
510
const struct commit_list *p;
511
512
for (p = want; p; p = p->next) {
513
- uint32_t generation;
513
+ timestamp_t generation;
514
struct commit *c = p->item;
515
load_commit_graph_info(the_repository, c);
516
generation = commit_graph_generation(c);
@@ -566,8 +566,8 @@ static int compare_commits_by_gen(const void *_a, const void *_b)
566
const struct commit *a = *(const struct commit * const *)_a;
567
const struct commit *b = *(const struct commit * const *)_b;
568
569
- uint32_t generation_a = commit_graph_generation(a);
570
- uint32_t generation_b = commit_graph_generation(b);
569
+ timestamp_t generation_a = commit_graph_generation(a);
570
+ timestamp_t generation_b = commit_graph_generation(b);
571
572
if (generation_a < generation_b)
573
return -1;
@@ -580,7 +580,7 @@ int can_all_from_reach_with_flag(struct object_array *from,
580
unsigned int with_flag,
581
unsigned int assign_flag,
582
time_t min_commit_date,
583
- uint32_t min_generation)
583
+ timestamp_t min_generation)
584
{
585
struct commit **list = NULL;
586
int i;
@@ -681,13 +681,13 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to,
681
time_t min_commit_date = cutoff_by_min_date ? from->item->date : 0;
682
struct commit_list *from_iter = from, *to_iter = to;
683
int result;
684
- uint32_t min_generation = GENERATION_NUMBER_INFINITY;
684
+ timestamp_t min_generation = GENERATION_NUMBER_INFINITY;
685
686
while (from_iter) {
687
add_object_array(&from_iter->item->object, NULL, &from_objs);
688
689
if (!parse_commit(from_iter->item)) {
690
- uint32_t generation;
690
+ timestamp_t generation;
691
if (from_iter->item->date < min_commit_date)
692
min_commit_date = from_iter->item->date;
693
@@ -701,7 +701,7 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to,
701
702
while (to_iter) {
703
if (!parse_commit(to_iter->item)) {
704
- uint32_t generation;
704
+ timestamp_t generation;
705
if (to_iter->item->date < min_commit_date)
706
min_commit_date = to_iter->item->date;
707
@@ -741,13 +741,13 @@ struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
741
struct commit_list *found_commits = NULL;
742
struct commit **to_last = to + nr_to;
743
struct commit **from_last = from + nr_from;
744
- uint32_t min_generation = GENERATION_NUMBER_INFINITY;
744
+ timestamp_t min_generation = GENERATION_NUMBER_INFINITY;
745
int num_to_find = 0;
746
747
struct prio_queue queue = { compare_commits_by_gen_then_commit_date };
748
749
for (item = to; item < to_last; item++) {
750
- uint32_t generation;
750
+ timestamp_t generation;
751
struct commit *c = *item;
752
753
parse_commit(c);
commit-reach.h
+1
-1
@@ -87,7 +87,7 @@ int can_all_from_reach_with_flag(struct object_array *from,
87
unsigned int with_flag,
88
unsigned int assign_flag,
89
time_t min_commit_date,
90
- uint32_t min_generation);
90
+ timestamp_t min_generation);
91
int can_all_from_reach(struct commit_list *from, struct commit_list *to,
92
int commit_date_cutoff);
93
commit.c
+2
-2
@@ -731,8 +731,8 @@ int compare_commits_by_author_date(const void *a_, const void *b_,
731
int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void *unused)
732
{
733
const struct commit *a = a_, *b = b_;
734
- const uint32_t generation_a = commit_graph_generation(a),
735
- generation_b = commit_graph_generation(b);
734
+ const timestamp_t generation_a = commit_graph_generation(a),
735
+ generation_b = commit_graph_generation(b);
736
737
/* newer commits first */
738
if (generation_a < generation_b)
commit.h
+2
-2
@@ -11,8 +11,8 @@
11
#include "commit-slab.h"
12
13
#define COMMIT_NOT_FROM_GRAPH 0xFFFFFFFF
14
-#define GENERATION_NUMBER_INFINITY 0xFFFFFFFF
15
-#define GENERATION_NUMBER_MAX 0x3FFFFFFF
14
+#define GENERATION_NUMBER_INFINITY ((1ULL << 63) - 1)
15
+#define GENERATION_NUMBER_V1_MAX 0x3FFFFFFF
16
#define GENERATION_NUMBER_ZERO 0
17
18
struct commit_list {
revision.c
+5
-5
@@ -3300,7 +3300,7 @@ define_commit_slab(indegree_slab, int);
3300
define_commit_slab(author_date_slab, timestamp_t);
3301
3302
struct topo_walk_info {
3303
- uint32_t min_generation;
3303
+ timestamp_t min_generation;
3304
struct prio_queue explore_queue;
3305
struct prio_queue indegree_queue;
3306
struct prio_queue topo_queue;
@@ -3346,7 +3346,7 @@ static void explore_walk_step(struct rev_info *revs)
3346
}
3347
3348
static void explore_to_depth(struct rev_info *revs,
3349
- uint32_t gen_cutoff)
3349
+ timestamp_t gen_cutoff)
3350
{
3351
struct topo_walk_info *info = revs->topo_walk_info;
3352
struct commit *c;
@@ -3389,7 +3389,7 @@ static void indegree_walk_step(struct rev_info *revs)
3389
}
3390
3391
static void compute_indegrees_to_depth(struct rev_info *revs,
3392
- uint32_t gen_cutoff)
3392
+ timestamp_t gen_cutoff)
3393
{
3394
struct topo_walk_info *info = revs->topo_walk_info;
3395
struct commit *c;
@@ -3447,7 +3447,7 @@ static void init_topo_walk(struct rev_info *revs)
3447
info->min_generation = GENERATION_NUMBER_INFINITY;
3448
for (list = revs->commits; list; list = list->next) {
3449
struct commit *c = list->item;
3450
- uint32_t generation;
3450
+ timestamp_t generation;
3451
3452
if (repo_parse_commit_gently(revs->repo, c, 1))
3453
continue;
@@ -3508,7 +3508,7 @@ static void expand_topo_walk(struct rev_info *revs, struct commit *commit)
3508
for (p = commit->parents; p; p = p->next) {
3509
struct commit *parent = p->item;
3510
int *pi;
3511
- uint32_t generation;
3511
+ timestamp_t generation;
3512
3513
if (parent->object.flags & UNINTERESTING)
3514
continue;
upload-pack.c
+1
-1
@@ -500,7 +500,7 @@ static int got_oid(struct upload_pack_data *data,
500
501
static int ok_to_give_up(struct upload_pack_data *data)
502
{
503
- uint32_t min_generation = GENERATION_NUMBER_ZERO;
503
+ timestamp_t min_generation = GENERATION_NUMBER_ZERO;
504
505
if (!data->have_obj.nr)
506
return 0;