Skip to content

Commit 83073cc

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8fb572a commit 83073cc

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

alloc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ void *alloc_commit_node(void)
9494
c->object.type = OBJ_COMMIT;
9595
c->index = alloc_commit_index();
9696
c->graph_pos = COMMIT_NOT_FROM_GRAPH;
97+
c->generation = GENERATION_NUMBER_INFINITY;
9798
return c;
9899
}
99100

commit-graph.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ static int fill_commit_in_graph(struct commit *item, struct commit_graph *g, uin
262262
date_low = get_be32(commit_data + g->hash_len + 12);
263263
item->date = (timestamp_t)((date_high << 32) | date_low);
264264

265+
item->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
266+
265267
pptr = &item->parents;
266268

267269
edge_value = get_be32(commit_data + g->hash_len);

commit.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include "pretty.h"
1111

1212
#define COMMIT_NOT_FROM_GRAPH 0xFFFFFFFF
13+
#define GENERATION_NUMBER_INFINITY 0xFFFFFFFF
14+
#define GENERATION_NUMBER_MAX 0x3FFFFFFF
15+
#define GENERATION_NUMBER_ZERO 0
1316

1417
struct commit_list {
1518
struct commit *item;
@@ -30,6 +33,7 @@ struct commit {
3033
*/
3134
struct tree *maybe_tree;
3235
uint32_t graph_pos;
36+
uint32_t generation;
3337
};
3438

3539
extern int save_commit_buffer;

0 commit comments

Comments
 (0)