@@ -1127,18 +1127,12 @@ struct tree *get_commit_tree_in_graph(struct repository *r, const struct commit
11271127 return get_commit_tree_in_graph_one (r -> objects -> commit_graph , c );
11281128}
11291129
1130- struct packed_commit_list {
1131- struct commit * * list ;
1132- size_t nr ;
1133- size_t alloc ;
1134- };
1135-
11361130struct write_commit_graph_context {
11371131 struct repository * r ;
11381132 struct odb_source * odb_source ;
11391133 char * graph_name ;
11401134 struct oid_array oids ;
1141- struct packed_commit_list commits ;
1135+ struct commit_stack commits ;
11421136 int num_extra_edges ;
11431137 int num_generation_data_overflows ;
11441138 unsigned long approx_nr_objects ;
@@ -1180,7 +1174,7 @@ static int write_graph_chunk_fanout(struct hashfile *f,
11801174{
11811175 struct write_commit_graph_context * ctx = data ;
11821176 int i , count = 0 ;
1183- struct commit * * list = ctx -> commits .list ;
1177+ struct commit * * list = ctx -> commits .items ;
11841178
11851179 /*
11861180 * Write the first-level table (the list is sorted,
@@ -1206,7 +1200,7 @@ static int write_graph_chunk_oids(struct hashfile *f,
12061200 void * data )
12071201{
12081202 struct write_commit_graph_context * ctx = data ;
1209- struct commit * * list = ctx -> commits .list ;
1203+ struct commit * * list = ctx -> commits .items ;
12101204 int count ;
12111205 for (count = 0 ; count < ctx -> commits .nr ; count ++ , list ++ ) {
12121206 display_progress (ctx -> progress , ++ ctx -> progress_cnt );
@@ -1226,8 +1220,8 @@ static int write_graph_chunk_data(struct hashfile *f,
12261220 void * data )
12271221{
12281222 struct write_commit_graph_context * ctx = data ;
1229- struct commit * * list = ctx -> commits .list ;
1230- struct commit * * last = ctx -> commits .list + ctx -> commits .nr ;
1223+ struct commit * * list = ctx -> commits .items ;
1224+ struct commit * * last = ctx -> commits .items + ctx -> commits .nr ;
12311225 uint32_t num_extra_edges = 0 ;
12321226
12331227 while (list < last ) {
@@ -1249,7 +1243,7 @@ static int write_graph_chunk_data(struct hashfile *f,
12491243 edge_value = GRAPH_PARENT_NONE ;
12501244 else {
12511245 edge_value = oid_pos (& parent -> item -> object .oid ,
1252- ctx -> commits .list ,
1246+ ctx -> commits .items ,
12531247 ctx -> commits .nr ,
12541248 commit_to_oid );
12551249
@@ -1280,7 +1274,7 @@ static int write_graph_chunk_data(struct hashfile *f,
12801274 edge_value = GRAPH_EXTRA_EDGES_NEEDED | num_extra_edges ;
12811275 else {
12821276 edge_value = oid_pos (& parent -> item -> object .oid ,
1283- ctx -> commits .list ,
1277+ ctx -> commits .items ,
12841278 ctx -> commits .nr ,
12851279 commit_to_oid );
12861280
@@ -1332,7 +1326,7 @@ static int write_graph_chunk_generation_data(struct hashfile *f,
13321326 int i , num_generation_data_overflows = 0 ;
13331327
13341328 for (i = 0 ; i < ctx -> commits .nr ; i ++ ) {
1335- struct commit * c = ctx -> commits .list [i ];
1329+ struct commit * c = ctx -> commits .items [i ];
13361330 timestamp_t offset ;
13371331 repo_parse_commit (ctx -> r , c );
13381332 offset = commit_graph_data_at (c )-> generation - c -> date ;
@@ -1355,7 +1349,7 @@ static int write_graph_chunk_generation_data_overflow(struct hashfile *f,
13551349 struct write_commit_graph_context * ctx = data ;
13561350 int i ;
13571351 for (i = 0 ; i < ctx -> commits .nr ; i ++ ) {
1358- struct commit * c = ctx -> commits .list [i ];
1352+ struct commit * c = ctx -> commits .items [i ];
13591353 timestamp_t offset = commit_graph_data_at (c )-> generation - c -> date ;
13601354 display_progress (ctx -> progress , ++ ctx -> progress_cnt );
13611355
@@ -1372,8 +1366,8 @@ static int write_graph_chunk_extra_edges(struct hashfile *f,
13721366 void * data )
13731367{
13741368 struct write_commit_graph_context * ctx = data ;
1375- struct commit * * list = ctx -> commits .list ;
1376- struct commit * * last = ctx -> commits .list + ctx -> commits .nr ;
1369+ struct commit * * list = ctx -> commits .items ;
1370+ struct commit * * last = ctx -> commits .items + ctx -> commits .nr ;
13771371 struct commit_list * parent ;
13781372
13791373 while (list < last ) {
@@ -1393,7 +1387,7 @@ static int write_graph_chunk_extra_edges(struct hashfile *f,
13931387 /* Since num_parents > 2, this initializer is safe. */
13941388 for (parent = (* list )-> parents -> next ; parent ; parent = parent -> next ) {
13951389 int edge_value = oid_pos (& parent -> item -> object .oid ,
1396- ctx -> commits .list ,
1390+ ctx -> commits .items ,
13971391 ctx -> commits .nr ,
13981392 commit_to_oid );
13991393
@@ -1427,8 +1421,8 @@ static int write_graph_chunk_bloom_indexes(struct hashfile *f,
14271421 void * data )
14281422{
14291423 struct write_commit_graph_context * ctx = data ;
1430- struct commit * * list = ctx -> commits .list ;
1431- struct commit * * last = ctx -> commits .list + ctx -> commits .nr ;
1424+ struct commit * * list = ctx -> commits .items ;
1425+ struct commit * * last = ctx -> commits .items + ctx -> commits .nr ;
14321426 uint32_t cur_pos = 0 ;
14331427
14341428 while (list < last ) {
@@ -1463,8 +1457,8 @@ static int write_graph_chunk_bloom_data(struct hashfile *f,
14631457 void * data )
14641458{
14651459 struct write_commit_graph_context * ctx = data ;
1466- struct commit * * list = ctx -> commits .list ;
1467- struct commit * * last = ctx -> commits .list + ctx -> commits .nr ;
1460+ struct commit * * list = ctx -> commits .items ;
1461+ struct commit * * last = ctx -> commits .items + ctx -> commits .nr ;
14681462
14691463 trace2_bloom_filter_settings (ctx );
14701464
@@ -1585,7 +1579,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
15851579
15861580struct compute_generation_info {
15871581 struct repository * r ;
1588- struct packed_commit_list * commits ;
1582+ struct commit_stack * commits ;
15891583 struct progress * progress ;
15901584 int progress_cnt ;
15911585
@@ -1622,7 +1616,7 @@ static void compute_reachable_generation_numbers(
16221616 struct commit_list * list = NULL ;
16231617
16241618 for (i = 0 ; i < info -> commits -> nr ; i ++ ) {
1625- struct commit * c = info -> commits -> list [i ];
1619+ struct commit * c = info -> commits -> items [i ];
16261620 timestamp_t gen ;
16271621 repo_parse_commit (info -> r , c );
16281622 gen = info -> get_generation (c , info -> data );
@@ -1729,7 +1723,7 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
17291723
17301724 if (!ctx -> trust_generation_numbers ) {
17311725 for (i = 0 ; i < ctx -> commits .nr ; i ++ ) {
1732- struct commit * c = ctx -> commits .list [i ];
1726+ struct commit * c = ctx -> commits .items [i ];
17331727 repo_parse_commit (ctx -> r , c );
17341728 commit_graph_data_at (c )-> generation = GENERATION_NUMBER_ZERO ;
17351729 }
@@ -1738,7 +1732,7 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
17381732 compute_reachable_generation_numbers (& info , 2 );
17391733
17401734 for (i = 0 ; i < ctx -> commits .nr ; i ++ ) {
1741- struct commit * c = ctx -> commits .list [i ];
1735+ struct commit * c = ctx -> commits .items [i ];
17421736 timestamp_t offset = commit_graph_data_at (c )-> generation - c -> date ;
17431737 if (offset > GENERATION_NUMBER_V2_OFFSET_MAX )
17441738 ctx -> num_generation_data_overflows ++ ;
@@ -1760,8 +1754,8 @@ void ensure_generations_valid(struct repository *r,
17601754 struct commit * * commits , size_t nr )
17611755{
17621756 int generation_version = get_configured_generation_version (r );
1763- struct packed_commit_list list = {
1764- .list = commits ,
1757+ struct commit_stack list = {
1758+ .items = commits ,
17651759 .alloc = nr ,
17661760 .nr = nr ,
17671761 };
@@ -1804,7 +1798,7 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
18041798 _ ("Computing commit changed paths Bloom filters" ),
18051799 ctx -> commits .nr );
18061800
1807- DUP_ARRAY (sorted_commits , ctx -> commits .list , ctx -> commits .nr );
1801+ DUP_ARRAY (sorted_commits , ctx -> commits .items , ctx -> commits .nr );
18081802
18091803 if (ctx -> order_by_pack )
18101804 QSORT (sorted_commits , ctx -> commits .nr , commit_pos_cmp );
@@ -1992,26 +1986,26 @@ static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
19921986 oid_array_sort (& ctx -> oids );
19931987 for (i = 0 ; i < ctx -> oids .nr ; i = oid_array_next_unique (& ctx -> oids , i )) {
19941988 unsigned int num_parents ;
1989+ struct commit * commit ;
19951990
19961991 display_progress (ctx -> progress , i + 1 );
19971992
1998- ALLOC_GROW (ctx -> commits .list , ctx -> commits .nr + 1 , ctx -> commits .alloc );
1999- ctx -> commits .list [ctx -> commits .nr ] = lookup_commit (ctx -> r , & ctx -> oids .oid [i ]);
1993+ commit = lookup_commit (ctx -> r , & ctx -> oids .oid [i ]);
20001994
20011995 if (ctx -> split && flags != COMMIT_GRAPH_SPLIT_REPLACE &&
2002- commit_graph_position (ctx -> commits . list [ ctx -> commits . nr ] ) != COMMIT_NOT_FROM_GRAPH )
1996+ commit_graph_position (commit ) != COMMIT_NOT_FROM_GRAPH )
20031997 continue ;
20041998
20051999 if (ctx -> split && flags == COMMIT_GRAPH_SPLIT_REPLACE )
2006- repo_parse_commit (ctx -> r , ctx -> commits . list [ ctx -> commits . nr ] );
2000+ repo_parse_commit (ctx -> r , commit );
20072001 else
2008- repo_parse_commit_no_graph (ctx -> r , ctx -> commits . list [ ctx -> commits . nr ] );
2002+ repo_parse_commit_no_graph (ctx -> r , commit );
20092003
2010- num_parents = commit_list_count (ctx -> commits . list [ ctx -> commits . nr ] -> parents );
2004+ num_parents = commit_list_count (commit -> parents );
20112005 if (num_parents > 2 )
20122006 ctx -> num_extra_edges += num_parents - 1 ;
20132007
2014- ctx -> commits . nr ++ ;
2008+ commit_stack_push ( & ctx -> commits , commit ) ;
20152009 }
20162010 stop_progress (& ctx -> progress );
20172011}
@@ -2330,7 +2324,7 @@ static void merge_commit_graph(struct write_commit_graph_context *ctx,
23302324 oid_to_hex (& g -> oid ),
23312325 (uintmax_t )st_add (ctx -> commits .nr , g -> num_commits ));
23322326
2333- ALLOC_GROW ( ctx -> commits . list , ctx -> commits . nr + g -> num_commits , ctx -> commits . alloc );
2327+ commit_stack_grow ( & ctx -> commits , g -> num_commits );
23342328
23352329 for (i = 0 ; i < g -> num_commits ; i ++ ) {
23362330 struct object_id oid ;
@@ -2343,10 +2337,8 @@ static void merge_commit_graph(struct write_commit_graph_context *ctx,
23432337 /* only add commits if they still exist in the repo */
23442338 result = lookup_commit_reference_gently (ctx -> r , & oid , 1 );
23452339
2346- if (result ) {
2347- ctx -> commits .list [ctx -> commits .nr ] = result ;
2348- ctx -> commits .nr ++ ;
2349- }
2340+ if (result )
2341+ commit_stack_push (& ctx -> commits , result );
23502342 }
23512343}
23522344
@@ -2367,14 +2359,14 @@ static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
23672359 _ ("Scanning merged commits" ),
23682360 ctx -> commits .nr );
23692361
2370- QSORT (ctx -> commits .list , ctx -> commits .nr , commit_compare );
2362+ QSORT (ctx -> commits .items , ctx -> commits .nr , commit_compare );
23712363
23722364 ctx -> num_extra_edges = 0 ;
23732365 for (i = 0 ; i < ctx -> commits .nr ; i ++ ) {
23742366 display_progress (ctx -> progress , i + 1 );
23752367
2376- if (i && oideq (& ctx -> commits .list [i - 1 ]-> object .oid ,
2377- & ctx -> commits .list [i ]-> object .oid )) {
2368+ if (i && oideq (& ctx -> commits .items [i - 1 ]-> object .oid ,
2369+ & ctx -> commits .items [i ]-> object .oid )) {
23782370 /*
23792371 * Silently ignore duplicates. These were likely
23802372 * created due to a commit appearing in multiple
@@ -2385,10 +2377,10 @@ static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
23852377 } else {
23862378 unsigned int num_parents ;
23872379
2388- ctx -> commits .list [dedup_i ] = ctx -> commits .list [i ];
2380+ ctx -> commits .items [dedup_i ] = ctx -> commits .items [i ];
23892381 dedup_i ++ ;
23902382
2391- num_parents = commit_list_count (ctx -> commits .list [i ]-> parents );
2383+ num_parents = commit_list_count (ctx -> commits .items [i ]-> parents );
23922384 if (num_parents > 2 )
23932385 ctx -> num_extra_edges += num_parents - 1 ;
23942386 }
@@ -2666,7 +2658,7 @@ int write_commit_graph(struct odb_source *source,
26662658cleanup :
26672659 free (ctx .graph_name );
26682660 free (ctx .base_graph_name );
2669- free ( ctx .commits . list );
2661+ commit_stack_clear ( & ctx .commits );
26702662 oid_array_clear (& ctx .oids );
26712663 clear_topo_level_slab (& topo_levels );
26722664
0 commit comments