| 1556 | } |
| 1557 | |
| 1558 | static int want_cruft_object_mtime(struct repository *r, |
| 1559 | const struct object_id *oid, |
| 1560 | unsigned flags, uint32_t mtime) |
| 1561 | { |
| 1562 | struct odb_source *source; |
| 1563 | |
| 1564 | for (source = r->objects->sources; source; source = source->next) { |
| 1565 | struct odb_source_files *files = odb_source_files_downcast(source); |
| 1566 | struct packed_git **cache = packfile_store_get_kept_pack_cache(files->packed, flags); |
| 1567 | |
| 1568 | for (; *cache; cache++) { |
| 1569 | struct packed_git *p = *cache; |
| 1570 | off_t ofs; |
| 1571 | uint32_t candidate_mtime; |
| 1572 | |
| 1573 | ofs = find_pack_entry_one(oid, p); |
| 1574 | if (!ofs) |
| 1575 | continue; |
| 1576 | |
| 1577 | /* |
| 1578 | * We have a copy of the object 'oid' in a non-cruft |
| 1579 | * pack. We can avoid packing an additional copy |
| 1580 | * regardless of what the existing copy's mtime is since |
| 1581 | * it is outside of a cruft pack. |
| 1582 | */ |
| 1583 | if (!p->is_cruft) |
| 1584 | return 0; |
| 1585 | |
| 1586 | /* |
| 1587 | * If we have a copy of the object 'oid' in a cruft |
| 1588 | * pack, then either read the cruft pack's mtime for |
| 1589 | * that object, or, if that can't be loaded, assume the |
| 1590 | * pack's mtime itself. |
| 1591 | */ |
| 1592 | if (!load_pack_mtimes(p)) { |
| 1593 | uint32_t pos; |
| 1594 | if (offset_to_pack_pos(p, ofs, &pos) < 0) |
| 1595 | continue; |
| 1596 | candidate_mtime = nth_packed_mtime(p, pos); |
| 1597 | } else { |
| 1598 | candidate_mtime = p->mtime; |
| 1599 | } |
| 1600 | |
| 1601 | /* |
| 1602 | * We have a surviving copy of the object in a cruft |
| 1603 | * pack whose mtime is greater than or equal to the one |
| 1604 | * we are considering. We can thus avoid packing an |
| 1605 | * additional copy of that object. |
| 1606 | */ |
| 1607 | if (mtime <= candidate_mtime) |
| 1608 | return 0; |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | return -1; |
| 1613 | } |
| 1614 | |
| 1615 | static int want_found_object(const struct object_id *oid, int exclude, |
no test coverage detected