Skip to content

Commit 2813c97

Browse files
pks-tgitster
authored andcommitted
treewide: enumerate promisor objects via odb_for_each_object()
We have multiple callsites where we enumerate all promisor objects in the object database via `for_each_packed_object()`. This is done by passing the `ODB_FOR_EACH_OBJECT_PROMISOR_ONLY` flag, which causes us to skip over all non-promisor objects. These callsites can be trivially converted to `odb_for_each_object()` as we know to skip enumeration of loose objects in case the `PROMISOR_ONLY` flag was passed by the caller. Refactor the sites accordingly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent cc47e3d commit 2813c97

3 files changed

Lines changed: 30 additions & 25 deletions

File tree

packfile.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,28 +2411,32 @@ int packfile_store_for_each_object(struct packfile_store *store,
24112411
return pack_errors ? -1 : 0;
24122412
}
24132413

2414+
struct add_promisor_object_data {
2415+
struct repository *repo;
2416+
struct oidset *set;
2417+
};
2418+
24142419
static int add_promisor_object(const struct object_id *oid,
2415-
struct packed_git *pack,
2416-
uint32_t pos UNUSED,
2417-
void *set_)
2420+
struct object_info *oi UNUSED,
2421+
void *cb_data)
24182422
{
2419-
struct oidset *set = set_;
2423+
struct add_promisor_object_data *data = cb_data;
24202424
struct object *obj;
24212425
int we_parsed_object;
24222426

2423-
obj = lookup_object(pack->repo, oid);
2427+
obj = lookup_object(data->repo, oid);
24242428
if (obj && obj->parsed) {
24252429
we_parsed_object = 0;
24262430
} else {
24272431
we_parsed_object = 1;
2428-
obj = parse_object_with_flags(pack->repo, oid,
2432+
obj = parse_object_with_flags(data->repo, oid,
24292433
PARSE_OBJECT_SKIP_HASH_CHECK);
24302434
}
24312435

24322436
if (!obj)
24332437
return 1;
24342438

2435-
oidset_insert(set, oid);
2439+
oidset_insert(data->set, oid);
24362440

24372441
/*
24382442
* If this is a tree, commit, or tag, the objects it refers
@@ -2450,19 +2454,19 @@ static int add_promisor_object(const struct object_id *oid,
24502454
*/
24512455
return 0;
24522456
while (tree_entry_gently(&desc, &entry))
2453-
oidset_insert(set, &entry.oid);
2457+
oidset_insert(data->set, &entry.oid);
24542458
if (we_parsed_object)
24552459
free_tree_buffer(tree);
24562460
} else if (obj->type == OBJ_COMMIT) {
24572461
struct commit *commit = (struct commit *) obj;
24582462
struct commit_list *parents = commit->parents;
24592463

2460-
oidset_insert(set, get_commit_tree_oid(commit));
2464+
oidset_insert(data->set, get_commit_tree_oid(commit));
24612465
for (; parents; parents = parents->next)
2462-
oidset_insert(set, &parents->item->object.oid);
2466+
oidset_insert(data->set, &parents->item->object.oid);
24632467
} else if (obj->type == OBJ_TAG) {
24642468
struct tag *tag = (struct tag *) obj;
2465-
oidset_insert(set, get_tagged_oid(tag));
2469+
oidset_insert(data->set, get_tagged_oid(tag));
24662470
}
24672471
return 0;
24682472
}
@@ -2474,10 +2478,13 @@ int is_promisor_object(struct repository *r, const struct object_id *oid)
24742478

24752479
if (!promisor_objects_prepared) {
24762480
if (repo_has_promisor_remote(r)) {
2477-
for_each_packed_object(r, add_promisor_object,
2478-
&promisor_objects,
2479-
ODB_FOR_EACH_OBJECT_PROMISOR_ONLY |
2480-
ODB_FOR_EACH_OBJECT_PACK_ORDER);
2481+
struct add_promisor_object_data data = {
2482+
.repo = r,
2483+
.set = &promisor_objects,
2484+
};
2485+
2486+
odb_for_each_object(r->objects, NULL, add_promisor_object, &data,
2487+
ODB_FOR_EACH_OBJECT_PROMISOR_ONLY | ODB_FOR_EACH_OBJECT_PACK_ORDER);
24812488
}
24822489
promisor_objects_prepared = 1;
24832490
}

repack-promisor.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ struct write_oid_context {
1717
* necessary.
1818
*/
1919
static int write_oid(const struct object_id *oid,
20-
struct packed_git *pack UNUSED,
21-
uint32_t pos UNUSED, void *data)
20+
struct object_info *oi UNUSED,
21+
void *data)
2222
{
2323
struct write_oid_context *ctx = data;
2424
struct child_process *cmd = ctx->cmd;
@@ -55,8 +55,8 @@ void repack_promisor_objects(struct repository *repo,
5555
*/
5656
ctx.cmd = &cmd;
5757
ctx.algop = repo->hash_algo;
58-
for_each_packed_object(repo, write_oid, &ctx,
59-
ODB_FOR_EACH_OBJECT_PROMISOR_ONLY);
58+
odb_for_each_object(repo->objects, NULL, write_oid, &ctx,
59+
ODB_FOR_EACH_OBJECT_PROMISOR_ONLY);
6060

6161
if (cmd.in == -1) {
6262
/* No packed objects; cmd was never started */

revision.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3626,8 +3626,7 @@ void reset_revision_walk(void)
36263626
}
36273627

36283628
static int mark_uninteresting(const struct object_id *oid,
3629-
struct packed_git *pack UNUSED,
3630-
uint32_t pos UNUSED,
3629+
struct object_info *oi UNUSED,
36313630
void *cb)
36323631
{
36333632
struct rev_info *revs = cb;
@@ -3936,10 +3935,9 @@ int prepare_revision_walk(struct rev_info *revs)
39363935
(revs->limited && limiting_can_increase_treesame(revs)))
39373936
revs->treesame.name = "treesame";
39383937

3939-
if (revs->exclude_promisor_objects) {
3940-
for_each_packed_object(revs->repo, mark_uninteresting, revs,
3941-
ODB_FOR_EACH_OBJECT_PROMISOR_ONLY);
3942-
}
3938+
if (revs->exclude_promisor_objects)
3939+
odb_for_each_object(revs->repo->objects, NULL, mark_uninteresting,
3940+
revs, ODB_FOR_EACH_OBJECT_PROMISOR_ONLY);
39433941

39443942
if (!revs->reflog_info)
39453943
prepare_to_use_bloom_filter(revs);

0 commit comments

Comments
 (0)