Skip to content

Commit b9fbc04

Browse files
committed
Merge branch 'sb/more-repo-in-api' into md/list-objects-filter-by-depth
2 parents 5d826e9 + ff509c5 commit b9fbc04

21 files changed

+454
-150
lines changed

builtin/fsck.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
381381
if (obj->type == OBJ_TREE)
382382
free_tree_buffer((struct tree *)obj);
383383
if (obj->type == OBJ_COMMIT)
384-
free_commit_buffer((struct commit *)obj);
384+
free_commit_buffer(the_repository->parsed_objects,
385+
(struct commit *)obj);
385386
return err;
386387
}
387388

builtin/log.c

Lines changed: 4 additions & 2 deletions
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
}
@@ -1939,7 +1940,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
19391940
open_next_file(rev.numbered_files ? NULL : commit, NULL, &rev, quiet))
19401941
die(_("Failed to create output files"));
19411942
shown = log_tree_commit(&rev, commit);
1942-
free_commit_buffer(commit);
1943+
free_commit_buffer(the_repository->parsed_objects,
1944+
commit);
19431945

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

builtin/rev-list.c

Lines changed: 2 additions & 1 deletion
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)

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,8 @@ static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
10341034
*
10351035
* This will need to be extended or ripped out when we learn about
10361036
* hashes of different sizes.
1037+
*
1038+
* When ripping this out, see TODO in test-repository.c.
10371039
*/
10381040
if (the_hash_algo->rawsz != 20)
10391041
BUG("hash size not yet supported by hashcmp");

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),

commit-reach.c

Lines changed: 43 additions & 30 deletions
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)