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 <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Dec 14, 2018 at 16:09 UTC 4f542b7a7f944986e3f7567f7e94b256b1929f6c
1 file changed +24 -16
commit-graph.c
+24 -16
@@ -292,7 +292,8 @@ static int bsearch_graph(struct commit_graph *g, struct object_id *oid, uint32_t
292 g->chunk_oid_lookup, g->hash_len, pos);
293 }
294
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,
297 uint64_t pos,
298 struct commit_list **pptr)
299 {
@@ -303,7 +304,7 @@ static struct commit_list **insert_parent_or_die(struct commit_graph *g,
304 die("invalid parent position %"PRIu64, pos);
305
306 hashcpy(oid.hash, g->chunk_oid_lookup + g->hash_len * pos);
306 - c = lookup_commit(the_repository, &oid);
307 + c = lookup_commit(r, &oid);
308 if (!c)
309 die(_("could not find commit %s"), oid_to_hex(&oid));
310 c->graph_pos = pos;
@@ -317,7 +318,9 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
318 item->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
319 }
320
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)
324 {
325 uint32_t edge_value;
326 uint32_t *parent_data_ptr;
@@ -341,13 +344,13 @@ static int fill_commit_in_graph(struct commit *item, struct commit_graph *g, uin
344 edge_value = get_be32(commit_data + g->hash_len);
345 if (edge_value == GRAPH_PARENT_NONE)
346 return 1;
344 - pptr = insert_parent_or_die(g, edge_value, pptr);
347 + pptr = insert_parent_or_die(r, g, edge_value, pptr);
348
349 edge_value = get_be32(commit_data + g->hash_len + 4);
350 if (edge_value == GRAPH_PARENT_NONE)
351 return 1;
352 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);
354 return 1;
355 }
356
@@ -355,7 +358,7 @@ static int fill_commit_in_graph(struct commit *item, struct commit_graph *g, uin
358 4 * (uint64_t)(edge_value & GRAPH_EDGE_LAST_MASK));
359 do {
360 edge_value = get_be32(parent_data_ptr);
358 - pptr = insert_parent_or_die(g,
361 + pptr = insert_parent_or_die(r, g,
362 edge_value & GRAPH_EDGE_LAST_MASK,
363 pptr);
364 parent_data_ptr++;
@@ -374,7 +377,9 @@ static int find_commit_in_graph(struct commit *item, struct commit_graph *g, uin
377 }
378 }
379
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)
383 {
384 uint32_t pos;
385
@@ -382,7 +387,7 @@ static int parse_commit_in_graph_one(struct commit_graph *g, struct commit *item
387 return 1;
388
389 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);
391
392 return 0;
393 }
@@ -391,7 +396,7 @@ int parse_commit_in_graph(struct repository *r, struct commit *item)
396 {
397 if (!prepare_commit_graph(r))
398 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);
400 }
401
402 void load_commit_graph_info(struct repository *r, struct commit *item)
@@ -403,19 +408,22 @@ void load_commit_graph_info(struct repository *r, struct commit *item)
408 fill_commit_graph_info(item, r->objects->commit_graph, pos);
409 }
410
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)
414 {
415 struct object_id oid;
416 const unsigned char *commit_data = g->chunk_commit_data +
417 GRAPH_DATA_WIDTH * (c->graph_pos);
418
419 hashcpy(oid.hash, commit_data);
413 - c->maybe_tree = lookup_tree(the_repository, &oid);
420 + c->maybe_tree = lookup_tree(r, &oid);
421
422 return c->maybe_tree;
423 }
424
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,
427 const struct commit *c)
428 {
429 if (c->maybe_tree)
@@ -423,12 +431,12 @@ static struct tree *get_commit_tree_in_graph_one(struct commit_graph *g,
431 if (c->graph_pos == COMMIT_NOT_FROM_GRAPH)
432 BUG("get_commit_tree_in_graph_one called from non-commit-graph commit");
433
426 - return load_tree_for_commit(g, (struct commit *)c);
434 + return load_tree_for_commit(r, g, (struct commit *)c);
435 }
436
437 struct tree *get_commit_tree_in_graph(struct repository *r, const struct commit *c)
438 {
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);
440 }
441
442 static void write_graph_chunk_fanout(struct hashfile *f,
@@ -1025,7 +1033,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
1033 }
1034
1035 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))
1037 graph_report("failed to parse %s from commit-graph",
1038 oid_to_hex(&cur_oid));
1039 }
@@ -1061,7 +1069,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
1069 continue;
1070 }
1071
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,
1073 get_commit_tree_oid(odb_commit)))
1074 graph_report("root tree OID for commit %s in commit-graph is %s != %s",
1075 oid_to_hex(&cur_oid),