|
32 | 32 | #include "packfile.h" |
33 | 33 | #include "object-file.h" |
34 | 34 | #include "odb.h" |
| 35 | +#include "odb/source.h" |
35 | 36 | #include "odb/streaming.h" |
36 | 37 | #include "replace-object.h" |
37 | 38 | #include "dir.h" |
@@ -1541,57 +1542,15 @@ static int have_duplicate_entry(const struct object_id *oid, |
1541 | 1542 |
|
1542 | 1543 | static int want_cruft_object_mtime(struct repository *r, |
1543 | 1544 | const struct object_id *oid, |
1544 | | - unsigned flags, uint32_t mtime) |
| 1545 | + unsigned flags UNUSED, uint32_t mtime UNUSED) |
1545 | 1546 | { |
1546 | | - struct odb_source *source; |
1547 | | - |
1548 | | - for (source = r->objects->sources; source; source = source->next) { |
1549 | | - struct odb_source_files *files = odb_source_files_downcast(source); |
1550 | | - struct packed_git **cache = packfile_store_get_kept_pack_cache(files->packed, flags); |
1551 | | - |
1552 | | - for (; *cache; cache++) { |
1553 | | - struct packed_git *p = *cache; |
1554 | | - off_t ofs; |
1555 | | - uint32_t candidate_mtime; |
1556 | | - |
1557 | | - ofs = find_pack_entry_one(oid, p); |
1558 | | - if (!ofs) |
1559 | | - continue; |
1560 | | - |
1561 | | - /* |
1562 | | - * We have a copy of the object 'oid' in a non-cruft |
1563 | | - * pack. We can avoid packing an additional copy |
1564 | | - * regardless of what the existing copy's mtime is since |
1565 | | - * it is outside of a cruft pack. |
1566 | | - */ |
1567 | | - if (!p->is_cruft) |
1568 | | - return 0; |
1569 | | - |
1570 | | - /* |
1571 | | - * If we have a copy of the object 'oid' in a cruft |
1572 | | - * pack, then either read the cruft pack's mtime for |
1573 | | - * that object, or, if that can't be loaded, assume the |
1574 | | - * pack's mtime itself. |
1575 | | - */ |
1576 | | - if (!load_pack_mtimes(p)) { |
1577 | | - uint32_t pos; |
1578 | | - if (offset_to_pack_pos(p, ofs, &pos) < 0) |
1579 | | - continue; |
1580 | | - candidate_mtime = nth_packed_mtime(p, pos); |
1581 | | - } else { |
1582 | | - candidate_mtime = p->mtime; |
1583 | | - } |
1584 | | - |
1585 | | - /* |
1586 | | - * We have a surviving copy of the object in a cruft |
1587 | | - * pack whose mtime is greater than or equal to the one |
1588 | | - * we are considering. We can thus avoid packing an |
1589 | | - * additional copy of that object. |
1590 | | - */ |
1591 | | - if (mtime <= candidate_mtime) |
1592 | | - return 0; |
1593 | | - } |
1594 | | - } |
| 1547 | + /* |
| 1548 | + * Check if the object exists in a kept source. Dispatches through |
| 1549 | + * the vtable: files backends check kept packs, non-files backends |
| 1550 | + * check their own kept tracking via OBJECT_INFO_KEPT_ONLY. |
| 1551 | + */ |
| 1552 | + if (odb_has_object_kept(r->objects, oid)) |
| 1553 | + return 0; |
1595 | 1554 |
|
1596 | 1555 | return -1; |
1597 | 1556 | } |
@@ -1657,7 +1616,7 @@ static int want_found_object(const struct object_id *oid, int exclude, |
1657 | 1616 | return 0; |
1658 | 1617 | if (ignore_packed_keep_in_core && p->pack_keep_in_core) |
1659 | 1618 | return 0; |
1660 | | - if (has_object_kept_pack(p->repo, oid, flags)) |
| 1619 | + if (odb_has_object_kept(p->repo->objects, oid)) |
1661 | 1620 | return 0; |
1662 | 1621 | } else { |
1663 | 1622 | /* |
@@ -1726,8 +1685,6 @@ static int want_object_in_pack_mtime(const struct object_id *oid, |
1726 | 1685 | uint32_t found_mtime) |
1727 | 1686 | { |
1728 | 1687 | int want; |
1729 | | - struct packfile_list_entry *e; |
1730 | | - struct odb_source *source; |
1731 | 1688 |
|
1732 | 1689 | if (!exclude && local) { |
1733 | 1690 | /* |
@@ -1757,25 +1714,18 @@ static int want_object_in_pack_mtime(const struct object_id *oid, |
1757 | 1714 |
|
1758 | 1715 | odb_prepare_alternates(the_repository->objects); |
1759 | 1716 |
|
1760 | | - for (source = the_repository->objects->sources; source; source = source->next) { |
1761 | | - struct multi_pack_index *m = get_multi_pack_index(source); |
1762 | | - struct pack_entry e; |
1763 | | - |
1764 | | - if (m && fill_midx_entry(m, oid, &e)) { |
1765 | | - want = want_object_in_pack_one(e.p, oid, exclude, found_pack, found_offset, found_mtime); |
1766 | | - if (want != -1) |
1767 | | - return want; |
1768 | | - } |
1769 | | - } |
1770 | | - |
1771 | | - for (source = the_repository->objects->sources; source; source = source->next) { |
1772 | | - struct odb_source_files *files = odb_source_files_downcast(source); |
| 1717 | + { |
| 1718 | + struct object_info oi = OBJECT_INFO_INIT; |
1773 | 1719 |
|
1774 | | - for (e = files->packed->packs.head; e; e = e->next) { |
1775 | | - struct packed_git *p = e->pack; |
1776 | | - want = want_object_in_pack_one(p, oid, exclude, found_pack, found_offset, found_mtime); |
1777 | | - if (!exclude && want > 0) |
1778 | | - packfile_list_prepend(&files->packed->packs, p); |
| 1720 | + if (!odb_read_object_info_extended(the_repository->objects, |
| 1721 | + oid, &oi, |
| 1722 | + OBJECT_INFO_QUICK) && |
| 1723 | + oi.whence == OI_PACKED) { |
| 1724 | + struct packed_git *p = oi.u.packed.pack; |
| 1725 | + want = want_object_in_pack_one(p, oid, exclude, |
| 1726 | + found_pack, |
| 1727 | + found_offset, |
| 1728 | + found_mtime); |
1779 | 1729 | if (want != -1) |
1780 | 1730 | return want; |
1781 | 1731 | } |
@@ -4065,7 +4015,7 @@ static void show_cruft_commit(struct commit *commit, void *data) |
4065 | 4015 |
|
4066 | 4016 | static int cruft_include_check_obj(struct object *obj, void *data UNUSED) |
4067 | 4017 | { |
4068 | | - return !has_object_kept_pack(to_pack.repo, &obj->oid, KEPT_PACK_IN_CORE); |
| 4018 | + return !odb_has_object_kept(to_pack.repo->objects, &obj->oid); |
4069 | 4019 | } |
4070 | 4020 |
|
4071 | 4021 | static int cruft_include_check(struct commit *commit, void *data) |
@@ -4365,17 +4315,15 @@ static void add_objects_in_unpacked_packs(void) |
4365 | 4315 |
|
4366 | 4316 | odb_prepare_alternates(to_pack.repo->objects); |
4367 | 4317 | for (source = to_pack.repo->objects->sources; source; source = source->next) { |
4368 | | - struct odb_source_files *files = odb_source_files_downcast(source); |
4369 | | - |
4370 | 4318 | if (!source->local) |
4371 | 4319 | continue; |
4372 | 4320 |
|
4373 | | - if (packfile_store_for_each_object(files->packed, &oi, |
4374 | | - add_object_in_unpacked_pack, NULL, |
4375 | | - ODB_FOR_EACH_OBJECT_PACK_ORDER | |
4376 | | - ODB_FOR_EACH_OBJECT_LOCAL_ONLY | |
4377 | | - ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS | |
4378 | | - ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS)) |
| 4321 | + if (odb_source_for_each_object(source, &oi, |
| 4322 | + add_object_in_unpacked_pack, NULL, |
| 4323 | + ODB_FOR_EACH_OBJECT_PACK_ORDER | |
| 4324 | + ODB_FOR_EACH_OBJECT_LOCAL_ONLY | |
| 4325 | + ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS | |
| 4326 | + ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS)) |
4379 | 4327 | die(_("cannot open pack index")); |
4380 | 4328 | } |
4381 | 4329 | } |
|
0 commit comments