Skip to content

Commit b99a579

Browse files
committed
Merge branch 'sb/more-repo-in-api'
The in-core repository instances are passed through more codepaths. * sb/more-repo-in-api: (23 commits) t/helper/test-repository: celebrate independence from the_repository path.h: make REPO_GIT_PATH_FUNC repository agnostic commit: prepare free_commit_buffer and release_commit_memory for any repo commit-graph: convert remaining functions to handle any repo submodule: don't add submodule as odb for push submodule: use submodule repos for object lookup pretty: prepare format_commit_message to handle arbitrary repositories commit: prepare logmsg_reencode to handle arbitrary repositories commit: prepare repo_unuse_commit_buffer to handle any repo commit: prepare get_commit_buffer to handle any repo commit-reach: prepare in_merge_bases[_many] to handle any repo commit-reach: prepare get_merge_bases to handle any repo commit-reach.c: allow get_merge_bases_many_0 to handle any repo commit-reach.c: allow remove_redundant to handle any repo commit-reach.c: allow merge_bases_many to handle any repo commit-reach.c: allow paint_down_to_common to handle any repo commit: allow parse_commit* to handle any repo object: parse_object to honor its repository argument object-store: prepare has_{sha1, object}_file to handle any repo object-store: prepare read_object_file to deal with any repo ...
2 parents b5101f9 + ff509c5 commit b99a579

20 files changed

+452
-150
lines changed

builtin/fsck.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,8 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
401401
if (obj->type == OBJ_TREE)
402402
free_tree_buffer((struct tree *)obj);
403403
if (obj->type == OBJ_COMMIT)
404-
free_commit_buffer((struct commit *)obj);
404+
free_commit_buffer(the_repository->parsed_objects,
405+
(struct commit *)obj);
405406
return err;
406407
}
407408

builtin/log.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ static int cmd_log_walk(struct rev_info *rev)
397397
* We may show a given commit multiple times when
398398
* walking the reflogs.
399399
*/
400-
free_commit_buffer(commit);
400+
free_commit_buffer(the_repository->parsed_objects,
401+
commit);
401402
free_commit_list(commit->parents);
402403
commit->parents = NULL;
403404
}
@@ -1940,7 +1941,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
19401941
open_next_file(rev.numbered_files ? NULL : commit, NULL, &rev, quiet))
19411942
die(_("Failed to create output files"));
19421943
shown = log_tree_commit(&rev, commit);
1943-
free_commit_buffer(commit);
1944+
free_commit_buffer(the_repository->parsed_objects,
1945+
commit);
19441946

19451947
/* We put one extra blank line between formatted
19461948
* patches and this flag is used by log-tree code

builtin/rev-list.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ static void finish_commit(struct commit *commit, void *data)
197197
free_commit_list(commit->parents);
198198
commit->parents = NULL;
199199
}
200-
free_commit_buffer(commit);
200+
free_commit_buffer(the_repository->parsed_objects,
201+
commit);
201202
}
202203

203204
static inline void finish_object__ma(struct object *obj)

commit-graph.c

+24-16
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ static int bsearch_graph(struct commit_graph *g, struct object_id *oid, uint32_t
288288
g->chunk_oid_lookup, g->hash_len, pos);
289289
}
290290

291-
static struct commit_list **insert_parent_or_die(struct commit_graph *g,
291+
static struct commit_list **insert_parent_or_die(struct repository *r,
292+
struct commit_graph *g,
292293
uint64_t pos,
293294
struct commit_list **pptr)
294295
{
@@ -299,7 +300,7 @@ static struct commit_list **insert_parent_or_die(struct commit_graph *g,
299300
die("invalid parent position %"PRIu64, pos);
300301

301302
hashcpy(oid.hash, g->chunk_oid_lookup + g->hash_len * pos);
302-
c = lookup_commit(the_repository, &oid);
303+
c = lookup_commit(r, &oid);
303304
if (!c)
304305
die(_("could not find commit %s"), oid_to_hex(&oid));
305306
c->graph_pos = pos;
@@ -313,7 +314,9 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
313314
item->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
314315
}
315316

316-
static int fill_commit_in_graph(struct commit *item, struct commit_graph *g, uint32_t pos)
317+
static int fill_commit_in_graph(struct repository *r,
318+
struct commit *item,
319+
struct commit_graph *g, uint32_t pos)
317320
{
318321
uint32_t edge_value;
319322
uint32_t *parent_data_ptr;
@@ -337,21 +340,21 @@ static int fill_commit_in_graph(struct commit *item, struct commit_graph *g, uin
337340
edge_value = get_be32(commit_data + g->hash_len);
338341
if (edge_value == GRAPH_PARENT_NONE)
339342
return 1;
340-
pptr = insert_parent_or_die(g, edge_value, pptr);
343+
pptr = insert_parent_or_die(r, g, edge_value, pptr);
341344

342345
edge_value = get_be32(commit_data + g->hash_len + 4);
343346
if (edge_value == GRAPH_PARENT_NONE)
344347
return 1;
345348
if (!(edge_value & GRAPH_OCTOPUS_EDGES_NEEDED)) {
346-
pptr = insert_parent_or_die(g, edge_value, pptr);
349+
pptr = insert_parent_or_die(r, g, edge_value, pptr);
347350
return 1;
348351
}
349352

350353
parent_data_ptr = (uint32_t*)(g->chunk_large_edges +
351354
4 * (uint64_t)(edge_value & GRAPH_EDGE_LAST_MASK));
352355
do {
353356
edge_value = get_be32(parent_data_ptr);
354-
pptr = insert_parent_or_die(g,
357+
pptr = insert_parent_or_die(r, g,
355358
edge_value & GRAPH_EDGE_LAST_MASK,
356359
pptr);
357360
parent_data_ptr++;
@@ -370,15 +373,17 @@ static int find_commit_in_graph(struct commit *item, struct commit_graph *g, uin
370373
}
371374
}
372375

373-
static int parse_commit_in_graph_one(struct commit_graph *g, struct commit *item)
376+
static int parse_commit_in_graph_one(struct repository *r,
377+
struct commit_graph *g,
378+
struct commit *item)
374379
{
375380
uint32_t pos;
376381

377382
if (item->object.parsed)
378383
return 1;
379384

380385
if (find_commit_in_graph(item, g, &pos))
381-
return fill_commit_in_graph(item, g, pos);
386+
return fill_commit_in_graph(r, item, g, pos);
382387

383388
return 0;
384389
}
@@ -387,7 +392,7 @@ int parse_commit_in_graph(struct repository *r, struct commit *item)
387392
{
388393
if (!prepare_commit_graph(r))
389394
return 0;
390-
return parse_commit_in_graph_one(r->objects->commit_graph, item);
395+
return parse_commit_in_graph_one(r, r->objects->commit_graph, item);
391396
}
392397

393398
void load_commit_graph_info(struct repository *r, struct commit *item)
@@ -399,32 +404,35 @@ void load_commit_graph_info(struct repository *r, struct commit *item)
399404
fill_commit_graph_info(item, r->objects->commit_graph, pos);
400405
}
401406

402-
static struct tree *load_tree_for_commit(struct commit_graph *g, struct commit *c)
407+
static struct tree *load_tree_for_commit(struct repository *r,
408+
struct commit_graph *g,
409+
struct commit *c)
403410
{
404411
struct object_id oid;
405412
const unsigned char *commit_data = g->chunk_commit_data +
406413
GRAPH_DATA_WIDTH * (c->graph_pos);
407414

408415
hashcpy(oid.hash, commit_data);
409-
c->maybe_tree = lookup_tree(the_repository, &oid);
416+
c->maybe_tree = lookup_tree(r, &oid);
410417

411418
return c->maybe_tree;
412419
}
413420

414-
static struct tree *get_commit_tree_in_graph_one(struct commit_graph *g,
421+
static struct tree *get_commit_tree_in_graph_one(struct repository *r,
422+
struct commit_graph *g,
415423
const struct commit *c)
416424
{
417425
if (c->maybe_tree)
418426
return c->maybe_tree;
419427
if (c->graph_pos == COMMIT_NOT_FROM_GRAPH)
420428
BUG("get_commit_tree_in_graph_one called from non-commit-graph commit");
421429

422-
return load_tree_for_commit(g, (struct commit *)c);
430+
return load_tree_for_commit(r, g, (struct commit *)c);
423431
}
424432

425433
struct tree *get_commit_tree_in_graph(struct repository *r, const struct commit *c)
426434
{
427-
return get_commit_tree_in_graph_one(r->objects->commit_graph, c);
435+
return get_commit_tree_in_graph_one(r, r->objects->commit_graph, c);
428436
}
429437

430438
static void write_graph_chunk_fanout(struct hashfile *f,
@@ -1035,7 +1043,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
10351043
}
10361044

10371045
graph_commit = lookup_commit(r, &cur_oid);
1038-
if (!parse_commit_in_graph_one(g, graph_commit))
1046+
if (!parse_commit_in_graph_one(r, g, graph_commit))
10391047
graph_report("failed to parse %s from commit-graph",
10401048
oid_to_hex(&cur_oid));
10411049
}
@@ -1071,7 +1079,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
10711079
continue;
10721080
}
10731081

1074-
if (!oideq(&get_commit_tree_in_graph_one(g, graph_commit)->object.oid,
1082+
if (!oideq(&get_commit_tree_in_graph_one(r, g, graph_commit)->object.oid,
10751083
get_commit_tree_oid(odb_commit)))
10761084
graph_report("root tree OID for commit %s in commit-graph is %s != %s",
10771085
oid_to_hex(&cur_oid),

commit-reach.c

+43-30
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ static int queue_has_nonstale(struct prio_queue *queue)
3030
}
3131

3232
/* all input commits in one and twos[] must have been parsed! */
33-
static struct commit_list *paint_down_to_common(struct commit *one, int n,
33+
static struct commit_list *paint_down_to_common(struct repository *r,
34+
struct commit *one, int n,
3435
struct commit **twos,
3536
int min_generation)
3637
{
@@ -83,7 +84,7 @@ static struct commit_list *paint_down_to_common(struct commit *one, int n,
8384
parents = parents->next;
8485
if ((p->object.flags & flags) == flags)
8586
continue;
86-
if (parse_commit(p))
87+
if (repo_parse_commit(r, p))
8788
return NULL;
8889
p->object.flags |= flags;
8990
prio_queue_put(&queue, p);
@@ -94,7 +95,9 @@ static struct commit_list *paint_down_to_common(struct commit *one, int n,
9495
return result;
9596
}
9697

97-
static struct commit_list *merge_bases_many(struct commit *one, int n, struct commit **twos)
98+
static struct commit_list *merge_bases_many(struct repository *r,
99+
struct commit *one, int n,
100+
struct commit **twos)
98101
{
99102
struct commit_list *list = NULL;
100103
struct commit_list *result = NULL;
@@ -109,14 +112,14 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct co
109112
return commit_list_insert(one, &result);
110113
}
111114

112-
if (parse_commit(one))
115+
if (repo_parse_commit(r, one))
113116
return NULL;
114117
for (i = 0; i < n; i++) {
115-
if (parse_commit(twos[i]))
118+
if (repo_parse_commit(r, twos[i]))
116119
return NULL;
117120
}
118121

119-
list = paint_down_to_common(one, n, twos, 0);
122+
list = paint_down_to_common(r, one, n, twos, 0);
120123

121124
while (list) {
122125
struct commit *commit = pop_commit(&list);
@@ -153,7 +156,7 @@ struct commit_list *get_octopus_merge_bases(struct commit_list *in)
153156
return ret;
154157
}
155158

156-
static int remove_redundant(struct commit **array, int cnt)
159+
static int remove_redundant(struct repository *r, struct commit **array, int cnt)
157160
{
158161
/*
159162
* Some commit in the array may be an ancestor of
@@ -171,7 +174,7 @@ static int remove_redundant(struct commit **array, int cnt)
171174
ALLOC_ARRAY(filled_index, cnt - 1);
172175

173176
for (i = 0; i < cnt; i++)
174-
parse_commit(array[i]);
177+
repo_parse_commit(r, array[i]);
175178
for (i = 0; i < cnt; i++) {
176179
struct commit_list *common;
177180
uint32_t min_generation = array[i]->generation;
@@ -187,8 +190,8 @@ static int remove_redundant(struct commit **array, int cnt)
187190
if (array[j]->generation < min_generation)
188191
min_generation = array[j]->generation;
189192
}
190-
common = paint_down_to_common(array[i], filled, work,
191-
min_generation);
193+
common = paint_down_to_common(r, array[i], filled,
194+
work, min_generation);
192195
if (array[i]->object.flags & PARENT2)
193196
redundant[i] = 1;
194197
for (j = 0; j < filled; j++)
@@ -213,7 +216,8 @@ static int remove_redundant(struct commit **array, int cnt)
213216
return filled;
214217
}
215218

216-
static struct commit_list *get_merge_bases_many_0(struct commit *one,
219+
static struct commit_list *get_merge_bases_many_0(struct repository *r,
220+
struct commit *one,
217221
int n,
218222
struct commit **twos,
219223
int cleanup)
@@ -223,7 +227,7 @@ static struct commit_list *get_merge_bases_many_0(struct commit *one,
223227
struct commit_list *result;
224228
int cnt, i;
225229

226-
result = merge_bases_many(one, n, twos);
230+
result = merge_bases_many(r, one, n, twos);
227231
for (i = 0; i < n; i++) {
228232
if (one == twos[i])
229233
return result;
@@ -246,31 +250,35 @@ static struct commit_list *get_merge_bases_many_0(struct commit *one,
246250
clear_commit_marks(one, all_flags);
247251
clear_commit_marks_many(n, twos, all_flags);
248252

249-
cnt = remove_redundant(rslt, cnt);
253+
cnt = remove_redundant(r, rslt, cnt);
250254
result = NULL;
251255
for (i = 0; i < cnt; i++)
252256
commit_list_insert_by_date(rslt[i], &result);
253257
free(rslt);
254258
return result;
255259
}
256260

257-
struct commit_list *get_merge_bases_many(struct commit *one,
258-
int n,
259-
struct commit **twos)
261+
struct commit_list *repo_get_merge_bases_many(struct repository *r,
262+
struct commit *one,
263+
int n,
264+
struct commit **twos)
260265
{
261-
return get_merge_bases_many_0(one, n, twos, 1);
266+
return get_merge_bases_many_0(r, one, n, twos, 1);
262267
}
263268

264-
struct commit_list *get_merge_bases_many_dirty(struct commit *one,
265-
int n,
266-
struct commit **twos)
269+
struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
270+
struct commit *one,
271+
int n,
272+
struct commit **twos)
267273
{
268-
return get_merge_bases_many_0(one, n, twos, 0);
274+
return get_merge_bases_many_0(r, one, n, twos, 0);
269275
}
270276

271-
struct commit_list *get_merge_bases(struct commit *one, struct commit *two)
277+
struct commit_list *repo_get_merge_bases(struct repository *r,
278+
struct commit *one,
279+
struct commit *two)
272280
{
273-
return get_merge_bases_many_0(one, 1, &two, 1);
281+
return get_merge_bases_many_0(r, one, 1, &two, 1);
274282
}
275283

276284
/*
@@ -304,16 +312,17 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
304312
/*
305313
* Is "commit" an ancestor of one of the "references"?
306314
*/
307-
int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit **reference)
315+
int repo_in_merge_bases_many(struct repository *r, struct commit *commit,
316+
int nr_reference, struct commit **reference)
308317
{
309318
struct commit_list *bases;
310319
int ret = 0, i;
311320
uint32_t min_generation = GENERATION_NUMBER_INFINITY;
312321

313-
if (parse_commit(commit))
322+
if (repo_parse_commit(r, commit))
314323
return ret;
315324
for (i = 0; i < nr_reference; i++) {
316-
if (parse_commit(reference[i]))
325+
if (repo_parse_commit(r, reference[i]))
317326
return ret;
318327
if (reference[i]->generation < min_generation)
319328
min_generation = reference[i]->generation;
@@ -322,7 +331,9 @@ int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit *
322331
if (commit->generation > min_generation)
323332
return ret;
324333

325-
bases = paint_down_to_common(commit, nr_reference, reference, commit->generation);
334+
bases = paint_down_to_common(r, commit,
335+
nr_reference, reference,
336+
commit->generation);
326337
if (commit->object.flags & PARENT2)
327338
ret = 1;
328339
clear_commit_marks(commit, all_flags);
@@ -334,9 +345,11 @@ int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit *
334345
/*
335346
* Is "commit" an ancestor of (i.e. reachable from) the "reference"?
336347
*/
337-
int in_merge_bases(struct commit *commit, struct commit *reference)
348+
int repo_in_merge_bases(struct repository *r,
349+
struct commit *commit,
350+
struct commit *reference)
338351
{
339-
return in_merge_bases_many(commit, 1, &reference);
352+
return repo_in_merge_bases_many(r, commit, 1, &reference);
340353
}
341354

342355
struct commit_list *reduce_heads(struct commit_list *heads)
@@ -365,7 +378,7 @@ struct commit_list *reduce_heads(struct commit_list *heads)
365378
p->item->object.flags &= ~STALE;
366379
}
367380
}
368-
num_head = remove_redundant(array, num_head);
381+
num_head = remove_redundant(the_repository, array, num_head);
369382
for (i = 0; i < num_head; i++)
370383
tail = &commit_list_insert(array[i], tail)->next;
371384
free(array);

0 commit comments

Comments
 (0)