Skip to content

Commit d7f9278

Browse files
abhishekkumar2718gitster
authored andcommitted
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 <[email protected]> Reviewed-by: Taylor Blau <[email protected]> Reviewed-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 72a2bfc commit d7f9278

File tree

8 files changed

+42
-42
lines changed

8 files changed

+42
-42
lines changed

commit-graph.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ uint32_t commit_graph_position(const struct commit *c)
101101
return data ? data->graph_pos : COMMIT_NOT_FROM_GRAPH;
102102
}
103103

104-
uint32_t commit_graph_generation(const struct commit *c)
104+
timestamp_t commit_graph_generation(const struct commit *c)
105105
{
106106
struct commit_graph_data *data =
107107
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)
150150
const struct commit *a = *(const struct commit **)va;
151151
const struct commit *b = *(const struct commit **)vb;
152152

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;
155155
/* lower generation commits first */
156156
if (generation_a < generation_b)
157157
return -1;
@@ -1370,8 +1370,8 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
13701370
if (all_parents_computed) {
13711371
pop_commit(&list);
13721372

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;
13751375
*topo_level_slab_at(ctx->topo_levels, current) = max_level + 1;
13761376
}
13771377
}
@@ -2367,8 +2367,8 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
23672367
for (i = 0; i < g->num_commits; i++) {
23682368
struct commit *graph_commit, *odb_commit;
23692369
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;
23722372

23732373
display_progress(progress, i + 1);
23742374
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)
24322432
continue;
24332433

24342434
/*
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
24372437
* extra logic in the following condition.
24382438
*/
2439-
if (max_generation == GENERATION_NUMBER_MAX)
2439+
if (max_generation == GENERATION_NUMBER_V1_MAX)
24402440
max_generation--;
24412441

24422442
generation = commit_graph_generation(graph_commit);
24432443
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),
24452445
oid_to_hex(&cur_oid),
24462446
generation,
24472447
max_generation + 1);

commit-graph.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ void disable_commit_graph(struct repository *r);
145145

146146
struct commit_graph_data {
147147
uint32_t graph_pos;
148-
uint32_t generation;
148+
timestamp_t generation;
149149
};
150150

151151
/*
152152
* Commits should be parsed before accessing generation, graph positions.
153153
*/
154-
uint32_t commit_graph_generation(const struct commit *);
154+
timestamp_t commit_graph_generation(const struct commit *);
155155
uint32_t commit_graph_position(const struct commit *);
156156
#endif

commit-reach.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ static int queue_has_nonstale(struct prio_queue *queue)
3232
static struct commit_list *paint_down_to_common(struct repository *r,
3333
struct commit *one, int n,
3434
struct commit **twos,
35-
int min_generation)
35+
timestamp_t min_generation)
3636
{
3737
struct prio_queue queue = { compare_commits_by_gen_then_commit_date };
3838
struct commit_list *result = NULL;
3939
int i;
40-
uint32_t last_gen = GENERATION_NUMBER_INFINITY;
40+
timestamp_t last_gen = GENERATION_NUMBER_INFINITY;
4141

4242
if (!min_generation)
4343
queue.compare = compare_commits_by_commit_date;
@@ -58,10 +58,10 @@ static struct commit_list *paint_down_to_common(struct repository *r,
5858
struct commit *commit = prio_queue_get(&queue);
5959
struct commit_list *parents;
6060
int flags;
61-
uint32_t generation = commit_graph_generation(commit);
61+
timestamp_t generation = commit_graph_generation(commit);
6262

6363
if (min_generation && generation > last_gen)
64-
BUG("bad generation skip %8x > %8x at %s",
64+
BUG("bad generation skip %"PRItime" > %"PRItime" at %s",
6565
generation, last_gen,
6666
oid_to_hex(&commit->object.oid));
6767
last_gen = generation;
@@ -177,12 +177,12 @@ static int remove_redundant(struct repository *r, struct commit **array, int cnt
177177
repo_parse_commit(r, array[i]);
178178
for (i = 0; i < cnt; i++) {
179179
struct commit_list *common;
180-
uint32_t min_generation = commit_graph_generation(array[i]);
180+
timestamp_t min_generation = commit_graph_generation(array[i]);
181181

182182
if (redundant[i])
183183
continue;
184184
for (j = filled = 0; j < cnt; j++) {
185-
uint32_t curr_generation;
185+
timestamp_t curr_generation;
186186
if (i == j || redundant[j])
187187
continue;
188188
filled_index[filled] = j;
@@ -321,7 +321,7 @@ int repo_in_merge_bases_many(struct repository *r, struct commit *commit,
321321
{
322322
struct commit_list *bases;
323323
int ret = 0, i;
324-
uint32_t generation, max_generation = GENERATION_NUMBER_ZERO;
324+
timestamp_t generation, max_generation = GENERATION_NUMBER_ZERO;
325325

326326
if (repo_parse_commit(r, commit))
327327
return ret;
@@ -470,7 +470,7 @@ static int in_commit_list(const struct commit_list *want, struct commit *c)
470470
static enum contains_result contains_test(struct commit *candidate,
471471
const struct commit_list *want,
472472
struct contains_cache *cache,
473-
uint32_t cutoff)
473+
timestamp_t cutoff)
474474
{
475475
enum contains_result *cached = contains_cache_at(cache, candidate);
476476

@@ -506,11 +506,11 @@ static enum contains_result contains_tag_algo(struct commit *candidate,
506506
{
507507
struct contains_stack contains_stack = { 0, 0, NULL };
508508
enum contains_result result;
509-
uint32_t cutoff = GENERATION_NUMBER_INFINITY;
509+
timestamp_t cutoff = GENERATION_NUMBER_INFINITY;
510510
const struct commit_list *p;
511511

512512
for (p = want; p; p = p->next) {
513-
uint32_t generation;
513+
timestamp_t generation;
514514
struct commit *c = p->item;
515515
load_commit_graph_info(the_repository, c);
516516
generation = commit_graph_generation(c);
@@ -566,8 +566,8 @@ static int compare_commits_by_gen(const void *_a, const void *_b)
566566
const struct commit *a = *(const struct commit * const *)_a;
567567
const struct commit *b = *(const struct commit * const *)_b;
568568

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

572572
if (generation_a < generation_b)
573573
return -1;
@@ -580,7 +580,7 @@ int can_all_from_reach_with_flag(struct object_array *from,
580580
unsigned int with_flag,
581581
unsigned int assign_flag,
582582
time_t min_commit_date,
583-
uint32_t min_generation)
583+
timestamp_t min_generation)
584584
{
585585
struct commit **list = NULL;
586586
int i;
@@ -681,13 +681,13 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to,
681681
time_t min_commit_date = cutoff_by_min_date ? from->item->date : 0;
682682
struct commit_list *from_iter = from, *to_iter = to;
683683
int result;
684-
uint32_t min_generation = GENERATION_NUMBER_INFINITY;
684+
timestamp_t min_generation = GENERATION_NUMBER_INFINITY;
685685

686686
while (from_iter) {
687687
add_object_array(&from_iter->item->object, NULL, &from_objs);
688688

689689
if (!parse_commit(from_iter->item)) {
690-
uint32_t generation;
690+
timestamp_t generation;
691691
if (from_iter->item->date < min_commit_date)
692692
min_commit_date = from_iter->item->date;
693693

@@ -701,7 +701,7 @@ int can_all_from_reach(struct commit_list *from, struct commit_list *to,
701701

702702
while (to_iter) {
703703
if (!parse_commit(to_iter->item)) {
704-
uint32_t generation;
704+
timestamp_t generation;
705705
if (to_iter->item->date < min_commit_date)
706706
min_commit_date = to_iter->item->date;
707707

@@ -741,13 +741,13 @@ struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
741741
struct commit_list *found_commits = NULL;
742742
struct commit **to_last = to + nr_to;
743743
struct commit **from_last = from + nr_from;
744-
uint32_t min_generation = GENERATION_NUMBER_INFINITY;
744+
timestamp_t min_generation = GENERATION_NUMBER_INFINITY;
745745
int num_to_find = 0;
746746

747747
struct prio_queue queue = { compare_commits_by_gen_then_commit_date };
748748

749749
for (item = to; item < to_last; item++) {
750-
uint32_t generation;
750+
timestamp_t generation;
751751
struct commit *c = *item;
752752

753753
parse_commit(c);

commit-reach.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ int can_all_from_reach_with_flag(struct object_array *from,
8787
unsigned int with_flag,
8888
unsigned int assign_flag,
8989
time_t min_commit_date,
90-
uint32_t min_generation);
90+
timestamp_t min_generation);
9191
int can_all_from_reach(struct commit_list *from, struct commit_list *to,
9292
int commit_date_cutoff);
9393

commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,8 @@ int compare_commits_by_author_date(const void *a_, const void *b_,
731731
int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void *unused)
732732
{
733733
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);
736736

737737
/* newer commits first */
738738
if (generation_a < generation_b)

commit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include "commit-slab.h"
1212

1313
#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
1616
#define GENERATION_NUMBER_ZERO 0
1717

1818
struct commit_list {

revision.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3300,7 +3300,7 @@ define_commit_slab(indegree_slab, int);
33003300
define_commit_slab(author_date_slab, timestamp_t);
33013301

33023302
struct topo_walk_info {
3303-
uint32_t min_generation;
3303+
timestamp_t min_generation;
33043304
struct prio_queue explore_queue;
33053305
struct prio_queue indegree_queue;
33063306
struct prio_queue topo_queue;
@@ -3346,7 +3346,7 @@ static void explore_walk_step(struct rev_info *revs)
33463346
}
33473347

33483348
static void explore_to_depth(struct rev_info *revs,
3349-
uint32_t gen_cutoff)
3349+
timestamp_t gen_cutoff)
33503350
{
33513351
struct topo_walk_info *info = revs->topo_walk_info;
33523352
struct commit *c;
@@ -3389,7 +3389,7 @@ static void indegree_walk_step(struct rev_info *revs)
33893389
}
33903390

33913391
static void compute_indegrees_to_depth(struct rev_info *revs,
3392-
uint32_t gen_cutoff)
3392+
timestamp_t gen_cutoff)
33933393
{
33943394
struct topo_walk_info *info = revs->topo_walk_info;
33953395
struct commit *c;
@@ -3447,7 +3447,7 @@ static void init_topo_walk(struct rev_info *revs)
34473447
info->min_generation = GENERATION_NUMBER_INFINITY;
34483448
for (list = revs->commits; list; list = list->next) {
34493449
struct commit *c = list->item;
3450-
uint32_t generation;
3450+
timestamp_t generation;
34513451

34523452
if (repo_parse_commit_gently(revs->repo, c, 1))
34533453
continue;
@@ -3508,7 +3508,7 @@ static void expand_topo_walk(struct rev_info *revs, struct commit *commit)
35083508
for (p = commit->parents; p; p = p->next) {
35093509
struct commit *parent = p->item;
35103510
int *pi;
3511-
uint32_t generation;
3511+
timestamp_t generation;
35123512

35133513
if (parent->object.flags & UNINTERESTING)
35143514
continue;

upload-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ static int got_oid(struct upload_pack_data *data,
500500

501501
static int ok_to_give_up(struct upload_pack_data *data)
502502
{
503-
uint32_t min_generation = GENERATION_NUMBER_ZERO;
503+
timestamp_t min_generation = GENERATION_NUMBER_ZERO;
504504

505505
if (!data->have_obj.nr)
506506
return 0;

0 commit comments

Comments
 (0)