@@ -932,21 +932,15 @@ struct tree *get_commit_tree_in_graph(struct repository *r, const struct commit
932
932
933
933
struct packed_commit_list {
934
934
struct commit * * list ;
935
- int nr ;
936
- int alloc ;
937
- };
938
-
939
- struct packed_oid_list {
940
- struct object_id * list ;
941
- int nr ;
942
- int alloc ;
935
+ size_t nr ;
936
+ size_t alloc ;
943
937
};
944
938
945
939
struct write_commit_graph_context {
946
940
struct repository * r ;
947
941
struct object_directory * odb ;
948
942
char * graph_name ;
949
- struct packed_oid_list oids ;
943
+ struct oid_array oids ;
950
944
struct packed_commit_list commits ;
951
945
int num_extra_edges ;
952
946
unsigned long approx_nr_objects ;
@@ -1240,13 +1234,6 @@ static int write_graph_chunk_bloom_data(struct hashfile *f,
1240
1234
return 0 ;
1241
1235
}
1242
1236
1243
- static int oid_compare (const void * _a , const void * _b )
1244
- {
1245
- const struct object_id * a = (const struct object_id * )_a ;
1246
- const struct object_id * b = (const struct object_id * )_b ;
1247
- return oidcmp (a , b );
1248
- }
1249
-
1250
1237
static int add_packed_commits (const struct object_id * oid ,
1251
1238
struct packed_git * pack ,
1252
1239
uint32_t pos ,
@@ -1267,10 +1254,7 @@ static int add_packed_commits(const struct object_id *oid,
1267
1254
if (type != OBJ_COMMIT )
1268
1255
return 0 ;
1269
1256
1270
- ALLOC_GROW (ctx -> oids .list , ctx -> oids .nr + 1 , ctx -> oids .alloc );
1271
- oidcpy (& (ctx -> oids .list [ctx -> oids .nr ]), oid );
1272
- ctx -> oids .nr ++ ;
1273
-
1257
+ oid_array_append (& ctx -> oids , oid );
1274
1258
set_commit_pos (ctx -> r , oid );
1275
1259
1276
1260
return 0 ;
@@ -1281,9 +1265,7 @@ static void add_missing_parents(struct write_commit_graph_context *ctx, struct c
1281
1265
struct commit_list * parent ;
1282
1266
for (parent = commit -> parents ; parent ; parent = parent -> next ) {
1283
1267
if (!(parent -> item -> object .flags & REACHABLE )) {
1284
- ALLOC_GROW (ctx -> oids .list , ctx -> oids .nr + 1 , ctx -> oids .alloc );
1285
- oidcpy (& ctx -> oids .list [ctx -> oids .nr ], & (parent -> item -> object .oid ));
1286
- ctx -> oids .nr ++ ;
1268
+ oid_array_append (& ctx -> oids , & parent -> item -> object .oid );
1287
1269
parent -> item -> object .flags |= REACHABLE ;
1288
1270
}
1289
1271
}
@@ -1302,7 +1284,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
1302
1284
ctx -> oids .nr );
1303
1285
for (i = 0 ; i < ctx -> oids .nr ; i ++ ) {
1304
1286
display_progress (ctx -> progress , i + 1 );
1305
- commit = lookup_commit (ctx -> r , & ctx -> oids .list [i ]);
1287
+ commit = lookup_commit (ctx -> r , & ctx -> oids .oid [i ]);
1306
1288
if (commit )
1307
1289
commit -> object .flags |= REACHABLE ;
1308
1290
}
@@ -1319,7 +1301,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
1319
1301
0 );
1320
1302
for (i = 0 ; i < ctx -> oids .nr ; i ++ ) {
1321
1303
display_progress (ctx -> progress , i + 1 );
1322
- commit = lookup_commit (ctx -> r , & ctx -> oids .list [i ]);
1304
+ commit = lookup_commit (ctx -> r , & ctx -> oids .oid [i ]);
1323
1305
1324
1306
if (!commit )
1325
1307
continue ;
@@ -1339,7 +1321,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
1339
1321
ctx -> oids .nr );
1340
1322
for (i = 0 ; i < ctx -> oids .nr ; i ++ ) {
1341
1323
display_progress (ctx -> progress , i + 1 );
1342
- commit = lookup_commit (ctx -> r , & ctx -> oids .list [i ]);
1324
+ commit = lookup_commit (ctx -> r , & ctx -> oids .oid [i ]);
1343
1325
1344
1326
if (commit )
1345
1327
commit -> object .flags &= ~REACHABLE ;
@@ -1567,9 +1549,7 @@ static int fill_oids_from_commits(struct write_commit_graph_context *ctx,
1567
1549
1568
1550
oidset_iter_init (commits , & iter );
1569
1551
while ((oid = oidset_iter_next (& iter ))) {
1570
- ALLOC_GROW (ctx -> oids .list , ctx -> oids .nr + 1 , ctx -> oids .alloc );
1571
- oidcpy (& ctx -> oids .list [ctx -> oids .nr ], oid );
1572
- ctx -> oids .nr ++ ;
1552
+ oid_array_append (& ctx -> oids , oid );
1573
1553
}
1574
1554
1575
1555
return 0 ;
@@ -1588,35 +1568,6 @@ static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)
1588
1568
stop_progress (& ctx -> progress );
1589
1569
}
1590
1570
1591
- static uint32_t count_distinct_commits (struct write_commit_graph_context * ctx )
1592
- {
1593
- uint32_t i , count_distinct = 1 ;
1594
-
1595
- if (ctx -> report_progress )
1596
- ctx -> progress = start_delayed_progress (
1597
- _ ("Counting distinct commits in commit graph" ),
1598
- ctx -> oids .nr );
1599
- display_progress (ctx -> progress , 0 ); /* TODO: Measure QSORT() progress */
1600
- QSORT (ctx -> oids .list , ctx -> oids .nr , oid_compare );
1601
-
1602
- for (i = 1 ; i < ctx -> oids .nr ; i ++ ) {
1603
- display_progress (ctx -> progress , i + 1 );
1604
- if (!oideq (& ctx -> oids .list [i - 1 ], & ctx -> oids .list [i ])) {
1605
- if (ctx -> split ) {
1606
- struct commit * c = lookup_commit (ctx -> r , & ctx -> oids .list [i ]);
1607
-
1608
- if (!c || commit_graph_position (c ) != COMMIT_NOT_FROM_GRAPH )
1609
- continue ;
1610
- }
1611
-
1612
- count_distinct ++ ;
1613
- }
1614
- }
1615
- stop_progress (& ctx -> progress );
1616
-
1617
- return count_distinct ;
1618
- }
1619
-
1620
1571
static void copy_oids_to_commits (struct write_commit_graph_context * ctx )
1621
1572
{
1622
1573
uint32_t i ;
@@ -1628,15 +1579,14 @@ static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
1628
1579
ctx -> progress = start_delayed_progress (
1629
1580
_ ("Finding extra edges in commit graph" ),
1630
1581
ctx -> oids .nr );
1631
- for (i = 0 ; i < ctx -> oids .nr ; i ++ ) {
1582
+ oid_array_sort (& ctx -> oids );
1583
+ for (i = 0 ; i < ctx -> oids .nr ; i = oid_array_next_unique (& ctx -> oids , i )) {
1632
1584
unsigned int num_parents ;
1633
1585
1634
1586
display_progress (ctx -> progress , i + 1 );
1635
- if (i > 0 && oideq (& ctx -> oids .list [i - 1 ], & ctx -> oids .list [i ]))
1636
- continue ;
1637
1587
1638
1588
ALLOC_GROW (ctx -> commits .list , ctx -> commits .nr + 1 , ctx -> commits .alloc );
1639
- ctx -> commits .list [ctx -> commits .nr ] = lookup_commit (ctx -> r , & ctx -> oids .list [i ]);
1589
+ ctx -> commits .list [ctx -> commits .nr ] = lookup_commit (ctx -> r , & ctx -> oids .oid [i ]);
1640
1590
1641
1591
if (ctx -> split && flags != COMMIT_GRAPH_SPLIT_REPLACE &&
1642
1592
commit_graph_position (ctx -> commits .list [ctx -> commits .nr ]) != COMMIT_NOT_FROM_GRAPH )
@@ -2155,7 +2105,7 @@ int write_commit_graph(struct object_directory *odb,
2155
2105
const struct commit_graph_opts * opts )
2156
2106
{
2157
2107
struct write_commit_graph_context * ctx ;
2158
- uint32_t i , count_distinct = 0 ;
2108
+ uint32_t i ;
2159
2109
int res = 0 ;
2160
2110
int replace = 0 ;
2161
2111
struct bloom_filter_settings bloom_settings = DEFAULT_BLOOM_FILTER_SETTINGS ;
@@ -2227,26 +2177,16 @@ int write_commit_graph(struct object_directory *odb,
2227
2177
}
2228
2178
2229
2179
ctx -> approx_nr_objects = approximate_object_count ();
2230
- ctx -> oids .alloc = ctx -> approx_nr_objects / 32 ;
2231
-
2232
- if (ctx -> split && opts && ctx -> oids .alloc > opts -> max_commits )
2233
- ctx -> oids .alloc = opts -> max_commits ;
2234
2180
2235
- if (ctx -> append ) {
2181
+ if (ctx -> append )
2236
2182
prepare_commit_graph_one (ctx -> r , ctx -> odb );
2237
- if (ctx -> r -> objects -> commit_graph )
2238
- ctx -> oids .alloc += ctx -> r -> objects -> commit_graph -> num_commits ;
2239
- }
2240
-
2241
- if (ctx -> oids .alloc < 1024 )
2242
- ctx -> oids .alloc = 1024 ;
2243
- ALLOC_ARRAY (ctx -> oids .list , ctx -> oids .alloc );
2244
2183
2245
2184
if (ctx -> append && ctx -> r -> objects -> commit_graph ) {
2246
2185
struct commit_graph * g = ctx -> r -> objects -> commit_graph ;
2247
2186
for (i = 0 ; i < g -> num_commits ; i ++ ) {
2248
- const unsigned char * hash = g -> chunk_oid_lookup + g -> hash_len * i ;
2249
- hashcpy (ctx -> oids .list [ctx -> oids .nr ++ ].hash , hash );
2187
+ struct object_id oid ;
2188
+ hashcpy (oid .hash , g -> chunk_oid_lookup + g -> hash_len * i );
2189
+ oid_array_append (& ctx -> oids , & oid );
2250
2190
}
2251
2191
}
2252
2192
@@ -2268,17 +2208,6 @@ int write_commit_graph(struct object_directory *odb,
2268
2208
2269
2209
close_reachable (ctx );
2270
2210
2271
- count_distinct = count_distinct_commits (ctx );
2272
-
2273
- if (count_distinct >= GRAPH_EDGE_LAST_MASK ) {
2274
- error (_ ("the commit graph format cannot write %d commits" ), count_distinct );
2275
- res = -1 ;
2276
- goto cleanup ;
2277
- }
2278
-
2279
- ctx -> commits .alloc = count_distinct ;
2280
- ALLOC_ARRAY (ctx -> commits .list , ctx -> commits .alloc );
2281
-
2282
2211
copy_oids_to_commits (ctx );
2283
2212
2284
2213
if (ctx -> commits .nr >= GRAPH_EDGE_LAST_MASK ) {
@@ -2313,7 +2242,7 @@ int write_commit_graph(struct object_directory *odb,
2313
2242
cleanup :
2314
2243
free (ctx -> graph_name );
2315
2244
free (ctx -> commits .list );
2316
- free ( ctx -> oids . list );
2245
+ oid_array_clear ( & ctx -> oids );
2317
2246
2318
2247
if (ctx -> commit_graph_filenames_after ) {
2319
2248
for (i = 0 ; i < ctx -> num_commit_graphs_after ; i ++ ) {
0 commit comments