commit: add generation number to struct commit

The generation number of a commit is defined recursively as follows: * If a commit A has no parents, then the generation number of A is one. * If a commit A has parents, then the generation number of A is one more than the maximum generation number among the parents of A. Add a uint32_t generation field to struct commit so we can pass this information to revision walks. We use three special values to signal the generation number is invalid: GENERATION_NUMBER_INFINITY 0xFFFFFFFF GENERATION_NUMBER_MAX 0x3FFFFFFF GENERATION_NUMBER_ZERO 0 The first (_INFINITY) means the generation number has not been loaded or computed. The second (_MAX) means the generation number is too large to store in the commit-graph file. The third (_ZERO) means the generation number was loaded from a commit graph file that was written by a version of git that did not support generation numbers. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Apr 25, 2018 at 14:37 UTC 83073cc994cc3cd364f3f213478b9162476e8e44
3 files changed +7
alloc.c
+1
@@ -94,6 +94,7 @@ void *alloc_commit_node(void)
94 c->object.type = OBJ_COMMIT;
95 c->index = alloc_commit_index();
96 c->graph_pos = COMMIT_NOT_FROM_GRAPH;
97 + c->generation = GENERATION_NUMBER_INFINITY;
98 return c;
99 }
100
commit-graph.c
+2
@@ -262,6 +262,8 @@ static int fill_commit_in_graph(struct commit *item, struct commit_graph *g, uin
262 date_low = get_be32(commit_data + g->hash_len + 12);
263 item->date = (timestamp_t)((date_high << 32) | date_low);
264
265 + item->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
266 +
267 pptr = &item->parents;
268
269 edge_value = get_be32(commit_data + g->hash_len);
commit.h
+4
@@ -10,6 +10,9 @@
10 #include "pretty.h"
11
12 #define COMMIT_NOT_FROM_GRAPH 0xFFFFFFFF
13 +#define GENERATION_NUMBER_INFINITY 0xFFFFFFFF
14 +#define GENERATION_NUMBER_MAX 0x3FFFFFFF
15 +#define GENERATION_NUMBER_ZERO 0
16
17 struct commit_list {
18 struct commit *item;
@@ -30,6 +33,7 @@ struct commit {
33 */
34 struct tree *maybe_tree;
35 uint32_t graph_pos;
36 + uint32_t generation;
37 };
38
39 extern int save_commit_buffer;