3505
add_preferred_base(&commit->object.oid);
3506
}
3507
3508
-struct in_pack_object {
3509
- off_t offset;
3510
- struct object *object;
3511
-};
3512
-
3513
-struct in_pack {
3514
- unsigned int alloc;
3515
- unsigned int nr;
3516
- struct in_pack_object *array;
3517
-};
3518
-
3519
-static void mark_in_pack_object(struct object *object, struct packed_git *p, struct in_pack *in_pack)
3508
+static int add_object_in_unpacked_pack(const struct object_id *oid,
3509
+ struct packed_git *pack,
3510
+ uint32_t pos,
3511
+ void *_data)
3512
{
3521
- in_pack->array[in_pack->nr].offset = find_pack_entry_one(object->oid.hash, p);
3522
- in_pack->array[in_pack->nr].object = object;
3523
- in_pack->nr++;
3524
-}
3525
-
3526
-/*
3527
- * Compare the objects in the offset order, in order to emulate the
3528
- * "git rev-list --objects" output that produced the pack originally.
3529
- */
3530
-static int ofscmp(const void *a_, const void *b_)
3531
-{
3532
- struct in_pack_object *a = (struct in_pack_object *)a_;
3533
- struct in_pack_object *b = (struct in_pack_object *)b_;
3534
-
3535
- if (a->offset < b->offset)
3536
- return -1;
3537
- else if (a->offset > b->offset)
3538
- return 1;
3539
- else
3540
- return oidcmp(&a->object->oid, &b->object->oid);
3513
+ struct object *obj = lookup_unknown_object(the_repository, oid);
3514
+ if (obj->flags & OBJECT_ADDED)
3515
+ return 0;
3516
+ add_object_entry(oid, obj->type, "", 0);
3517
+ obj->flags |= OBJECT_ADDED;
3518
+ return 0;
3519
}
3520
3521
static void add_objects_in_unpacked_packs(void)
3522
{
3545
- struct packed_git *p;
3546
- struct in_pack in_pack;
3547
- uint32_t i;
3548
-
3549
- memset(&in_pack, 0, sizeof(in_pack));
3550
-
3551
- for (p = get_all_packs(the_repository); p; p = p->next) {
3552
- struct object_id oid;
3553
- struct object *o;
3554
-
3555
- if (!p->pack_local || p->pack_keep || p->pack_keep_in_core)
3556
- continue;
3557
- if (open_pack_index(p))
3558
- die(_("cannot open pack index"));
3559
-
3560
- ALLOC_GROW(in_pack.array,
3561
- in_pack.nr + p->num_objects,
3562
- in_pack.alloc);
3563
-
3564
- for (i = 0; i < p->num_objects; i++) {
3565
- nth_packed_object_id(&oid, p, i);
3566
- o = lookup_unknown_object(the_repository, &oid);
3567
- if (!(o->flags & OBJECT_ADDED))
3568
- mark_in_pack_object(o, p, &in_pack);
3569
- o->flags |= OBJECT_ADDED;
3570
- }
3571
- }
3572
-
3573
- if (in_pack.nr) {
3574
- QSORT(in_pack.array, in_pack.nr, ofscmp);
3575
- for (i = 0; i < in_pack.nr; i++) {
3576
- struct object *o = in_pack.array[i].object;
3577
- add_object_entry(&o->oid, o->type, "", 0);
3578
- }
3579
- }
3580
- free(in_pack.array);
3523
+ if (for_each_packed_object(add_object_in_unpacked_pack, NULL,
3524
+ FOR_EACH_OBJECT_PACK_ORDER |
3525
+ FOR_EACH_OBJECT_LOCAL_ONLY |
3526
+ FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS |
3527
+ FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS))
3528
+ die(_("cannot open pack index"));
3529
}
3530
3531
static int add_loose_object(const struct object_id *oid, const char *path,