Skip to content

Commit 4f542b7

Browse files
stefanbellergitster
authored andcommitted
commit-graph: convert remaining functions to handle any repo
Convert all functions to handle arbitrary repositories in commit-graph.c that are used by functions taking a repository argument already. Notable exclusion is write_commit_graph and its local functions as that only works on the_repository. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 142e9f4 commit 4f542b7

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

commit-graph.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ static int bsearch_graph(struct commit_graph *g, struct object_id *oid, uint32_t
292292
g->chunk_oid_lookup, g->hash_len, pos);
293293
}
294294

295-
static struct commit_list **insert_parent_or_die(struct commit_graph *g,
295+
static struct commit_list **insert_parent_or_die(struct repository *r,
296+
struct commit_graph *g,
296297
uint64_t pos,
297298
struct commit_list **pptr)
298299
{
@@ -303,7 +304,7 @@ static struct commit_list **insert_parent_or_die(struct commit_graph *g,
303304
die("invalid parent position %"PRIu64, pos);
304305

305306
hashcpy(oid.hash, g->chunk_oid_lookup + g->hash_len * pos);
306-
c = lookup_commit(the_repository, &oid);
307+
c = lookup_commit(r, &oid);
307308
if (!c)
308309
die(_("could not find commit %s"), oid_to_hex(&oid));
309310
c->graph_pos = pos;
@@ -317,7 +318,9 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
317318
item->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
318319
}
319320

320-
static int fill_commit_in_graph(struct commit *item, struct commit_graph *g, uint32_t pos)
321+
static int fill_commit_in_graph(struct repository *r,
322+
struct commit *item,
323+
struct commit_graph *g, uint32_t pos)
321324
{
322325
uint32_t edge_value;
323326
uint32_t *parent_data_ptr;
@@ -341,21 +344,21 @@ static int fill_commit_in_graph(struct commit *item, struct commit_graph *g, uin
341344
edge_value = get_be32(commit_data + g->hash_len);
342345
if (edge_value == GRAPH_PARENT_NONE)
343346
return 1;
344-
pptr = insert_parent_or_die(g, edge_value, pptr);
347+
pptr = insert_parent_or_die(r, g, edge_value, pptr);
345348

346349
edge_value = get_be32(commit_data + g->hash_len + 4);
347350
if (edge_value == GRAPH_PARENT_NONE)
348351
return 1;
349352
if (!(edge_value & GRAPH_OCTOPUS_EDGES_NEEDED)) {
350-
pptr = insert_parent_or_die(g, edge_value, pptr);
353+
pptr = insert_parent_or_die(r, g, edge_value, pptr);
351354
return 1;
352355
}
353356

354357
parent_data_ptr = (uint32_t*)(g->chunk_large_edges +
355358
4 * (uint64_t)(edge_value & GRAPH_EDGE_LAST_MASK));
356359
do {
357360
edge_value = get_be32(parent_data_ptr);
358-
pptr = insert_parent_or_die(g,
361+
pptr = insert_parent_or_die(r, g,
359362
edge_value & GRAPH_EDGE_LAST_MASK,
360363
pptr);
361364
parent_data_ptr++;
@@ -374,15 +377,17 @@ static int find_commit_in_graph(struct commit *item, struct commit_graph *g, uin
374377
}
375378
}
376379

377-
static int parse_commit_in_graph_one(struct commit_graph *g, struct commit *item)
380+
static int parse_commit_in_graph_one(struct repository *r,
381+
struct commit_graph *g,
382+
struct commit *item)
378383
{
379384
uint32_t pos;
380385

381386
if (item->object.parsed)
382387
return 1;
383388

384389
if (find_commit_in_graph(item, g, &pos))
385-
return fill_commit_in_graph(item, g, pos);
390+
return fill_commit_in_graph(r, item, g, pos);
386391

387392
return 0;
388393
}
@@ -391,7 +396,7 @@ int parse_commit_in_graph(struct repository *r, struct commit *item)
391396
{
392397
if (!prepare_commit_graph(r))
393398
return 0;
394-
return parse_commit_in_graph_one(r->objects->commit_graph, item);
399+
return parse_commit_in_graph_one(r, r->objects->commit_graph, item);
395400
}
396401

397402
void load_commit_graph_info(struct repository *r, struct commit *item)
@@ -403,32 +408,35 @@ void load_commit_graph_info(struct repository *r, struct commit *item)
403408
fill_commit_graph_info(item, r->objects->commit_graph, pos);
404409
}
405410

406-
static struct tree *load_tree_for_commit(struct commit_graph *g, struct commit *c)
411+
static struct tree *load_tree_for_commit(struct repository *r,
412+
struct commit_graph *g,
413+
struct commit *c)
407414
{
408415
struct object_id oid;
409416
const unsigned char *commit_data = g->chunk_commit_data +
410417
GRAPH_DATA_WIDTH * (c->graph_pos);
411418

412419
hashcpy(oid.hash, commit_data);
413-
c->maybe_tree = lookup_tree(the_repository, &oid);
420+
c->maybe_tree = lookup_tree(r, &oid);
414421

415422
return c->maybe_tree;
416423
}
417424

418-
static struct tree *get_commit_tree_in_graph_one(struct commit_graph *g,
425+
static struct tree *get_commit_tree_in_graph_one(struct repository *r,
426+
struct commit_graph *g,
419427
const struct commit *c)
420428
{
421429
if (c->maybe_tree)
422430
return c->maybe_tree;
423431
if (c->graph_pos == COMMIT_NOT_FROM_GRAPH)
424432
BUG("get_commit_tree_in_graph_one called from non-commit-graph commit");
425433

426-
return load_tree_for_commit(g, (struct commit *)c);
434+
return load_tree_for_commit(r, g, (struct commit *)c);
427435
}
428436

429437
struct tree *get_commit_tree_in_graph(struct repository *r, const struct commit *c)
430438
{
431-
return get_commit_tree_in_graph_one(r->objects->commit_graph, c);
439+
return get_commit_tree_in_graph_one(r, r->objects->commit_graph, c);
432440
}
433441

434442
static void write_graph_chunk_fanout(struct hashfile *f,
@@ -1025,7 +1033,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
10251033
}
10261034

10271035
graph_commit = lookup_commit(r, &cur_oid);
1028-
if (!parse_commit_in_graph_one(g, graph_commit))
1036+
if (!parse_commit_in_graph_one(r, g, graph_commit))
10291037
graph_report("failed to parse %s from commit-graph",
10301038
oid_to_hex(&cur_oid));
10311039
}
@@ -1061,7 +1069,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
10611069
continue;
10621070
}
10631071

1064-
if (!oideq(&get_commit_tree_in_graph_one(g, graph_commit)->object.oid,
1072+
if (!oideq(&get_commit_tree_in_graph_one(r, g, graph_commit)->object.oid,
10651073
get_commit_tree_oid(odb_commit)))
10661074
graph_report("root tree OID for commit %s in commit-graph is %s != %s",
10671075
oid_to_hex(&cur_oid),

0 commit comments

Comments
 (0)