Skip to content

Commit c1a0911

Browse files
abhishekkumar2718gitster
authored andcommitted
commit-graph: implement corrected commit date
With most of preparations done, let's implement corrected commit date. The corrected commit date for a commit is defined as: * A commit with no parents (a root commit) has corrected commit date equal to its committer date. * A commit with at least one parent has corrected commit date equal to the maximum of its commit date and one more than the largest corrected commit date among its parents. As a special case, a root commit with timestamp of zero (01.01.1970 00:00:00Z) has corrected commit date of one, to be able to distinguish from GENERATION_NUMBER_ZERO (that is, an uncomputed corrected commit date). To minimize the space required to store corrected commit date, Git stores corrected commit date offsets into the commit-graph file. The corrected commit date offset for a commit is defined as the difference between its corrected commit date and actual commit date. Storing corrected commit date requires sizeof(timestamp_t) bytes, which in most cases is 64 bits (uintmax_t). However, corrected commit date offsets can be safely stored using only 32-bits. This halves the size of GDAT chunk, which is a reduction of around 6% in the size of commit-graph file. However, using offsets be problematic if a commit is malformed but valid and has committer date of 0 Unix time, as the offset would be the same as corrected commit date and thus require 64-bits to be stored properly. While Git does not write out offsets at this stage, Git stores the corrected commit dates in member generation of struct commit_graph_data. It will begin writing commit date offsets with the introduction of generation data chunk. 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 d7f9278 commit c1a0911

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

commit-graph.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,9 +1343,11 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
13431343
ctx->commits.nr);
13441344
for (i = 0; i < ctx->commits.nr; i++) {
13451345
uint32_t level = *topo_level_slab_at(ctx->topo_levels, ctx->commits.list[i]);
1346+
timestamp_t corrected_commit_date = commit_graph_data_at(ctx->commits.list[i])->generation;
13461347

13471348
display_progress(ctx->progress, i + 1);
1348-
if (level != GENERATION_NUMBER_ZERO)
1349+
if (level != GENERATION_NUMBER_ZERO &&
1350+
corrected_commit_date != GENERATION_NUMBER_ZERO)
13491351
continue;
13501352

13511353
commit_list_insert(ctx->commits.list[i], &list);
@@ -1354,17 +1356,24 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
13541356
struct commit_list *parent;
13551357
int all_parents_computed = 1;
13561358
uint32_t max_level = 0;
1359+
timestamp_t max_corrected_commit_date = 0;
13571360

13581361
for (parent = current->parents; parent; parent = parent->next) {
13591362
level = *topo_level_slab_at(ctx->topo_levels, parent->item);
1363+
corrected_commit_date = commit_graph_data_at(parent->item)->generation;
13601364

1361-
if (level == GENERATION_NUMBER_ZERO) {
1365+
if (level == GENERATION_NUMBER_ZERO ||
1366+
corrected_commit_date == GENERATION_NUMBER_ZERO) {
13621367
all_parents_computed = 0;
13631368
commit_list_insert(parent->item, &list);
13641369
break;
1365-
} else if (level > max_level) {
1366-
max_level = level;
13671370
}
1371+
1372+
if (level > max_level)
1373+
max_level = level;
1374+
1375+
if (corrected_commit_date > max_corrected_commit_date)
1376+
max_corrected_commit_date = corrected_commit_date;
13681377
}
13691378

13701379
if (all_parents_computed) {
@@ -1373,6 +1382,10 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
13731382
if (max_level > GENERATION_NUMBER_V1_MAX - 1)
13741383
max_level = GENERATION_NUMBER_V1_MAX - 1;
13751384
*topo_level_slab_at(ctx->topo_levels, current) = max_level + 1;
1385+
1386+
if (current->date && current->date > max_corrected_commit_date)
1387+
max_corrected_commit_date = current->date - 1;
1388+
commit_graph_data_at(current)->generation = max_corrected_commit_date + 1;
13761389
}
13771390
}
13781391
}

0 commit comments

Comments
 (0)