git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 12/14] builtin/pack-objects: use `packfile_store_for_each_object()`

From
Taylor Blau <me@ttaylorr.com>
Date
Jan 23, 2026, 01:21 UTC
Message-ID
<aXLNM+AOpdQtmisC@nand.local>
In-Reply-To
<20260121-pks-odb-for-each-object-v3-12-12c4dfd24227@pks.im>
On Wed, Jan 21, 2026 at 01:50:28PM +0100, Patrick Steinhardt wrote:
Show 21 quoted lines
>  static int add_object_in_unpacked_pack(const struct object_id *oid,
> -				       struct packed_git *pack,
> -				       uint32_t pos,
> +				       struct object_info *oi,
>  				       void *data UNUSED)
>  {
>  	if (cruft) {
> -		off_t offset;
> -		time_t mtime;
> -
> -		if (pack->is_cruft) {
> -			if (load_pack_mtimes(pack) < 0)
> -				die(_("could not load cruft pack .mtimes"));
> -			mtime = nth_packed_mtime(pack, pos);
> -		} else {
> -			mtime = pack->mtime;
> -		}
> -		offset = nth_packed_object_offset(pack, pos);
> -
> -		add_cruft_object_entry(oid, OBJ_NONE, pack, offset,
> -				       NULL, mtime);

OK, here's where we see the existing logic for determining the mtime of an object in the GC sense. I see there's a subsequent patch that also makes use of the object_info->mtimep field, and my guess is (not having completely read that patch yet) that having the same notion of mtime between the two callsites is desirable.

I still wonder whether imposing that notion of mtime at the object_info layer is the right choice. I wonder if it would make more sense to allow the caller to have a "statp" pointer filled out (or alternatively stick a "struct stat" in both the packed union type as well as the loose one, though the latter doesn't yet exist).

Then the caller could do something like:
static time_t object_info_gc_mtime(const struct object_info *oi)
{
    if (!oi->statp)
        BUG("oops!");
    switch (oi->whence) {
    case OI_CACHED:
        return 0;
    case OI_LOOSE:
        return oi->statp->st_mtime;
    case OI_PACKED:
        struct packed_git *p = oi->u.packed.pack;
        if (p->is_cruft) {
            uint32_t pack_pos;
            if (load_pack_mtimes(p) < 0)
                die(_("could not load cruft pack .mtimes for '%s'"),
                    pack_basename(p));
            if (offset_to_pack_pos(p, oi->u.packed.offset, &pack_pos) < 0)
                die(_("could not find offset for object '%s' in cruft pack '%s'"),
                    oid_to_hex(&oi->oid),
                    pack_basename(p));
            return nth_packed_mtime(p, pack_pos_to_index(p, pack_pos));
        } else {
            return p->mtime; /* or oi->statp->st_mtime */
        }
    default:
        BUG("unknown oi->whence: %d", oi->whence);
    }
}

I like the above because it encapsulates the GC-specific interpretation of an object's mtime outside of the object_info layer, while adding information (namely statp) that is generic enough to be potentially useful to other callers who may not be interested in the GC-specific interpretation.

Show 27 quoted lines
> +		add_cruft_object_entry(oid, OBJ_NONE, oi->u.packed.pack,
> +				       oi->u.packed.offset, NULL, *oi->mtimep);
>  	} else {
>  		add_object_entry(oid, OBJ_NONE, "", 0);
>  	}
> @@ -4341,14 +4328,24 @@ static int add_object_in_unpacked_pack(const struct object_id *oid,
>
>  static void add_objects_in_unpacked_packs(void)
>  {
> -	if (for_each_packed_object(to_pack.repo,
> -				   add_object_in_unpacked_pack,
> -				   NULL,
> -				   ODB_FOR_EACH_OBJECT_PACK_ORDER |
> -				   ODB_FOR_EACH_OBJECT_LOCAL_ONLY |
> -				   ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS |
> -				   ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS))
> -		die(_("cannot open pack index"));
> +	struct odb_source *source;
> +	time_t mtime;
> +	struct object_info oi = {
> +		.mtimep = &mtime,
> +	};
> +
> +	odb_prepare_alternates(to_pack.repo->objects);
> +	for (source = to_pack.repo->objects->sources; source; source = source->next) {
> +		if (!source->local)
> +			continue;

OK, we dropped the ODB_FOR_EACH_OBJECT_LOCAL_ONLY flag when dispatching to the packfile_store iterator, but that's OK, since it's handled above here.

Interestingly, packfile_store_for_each_object_internal() has a similar check:

    if ((flags & ODB_FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
        continue;

, but I'm wondering whether these are subtly different. Would a non-local source ever have packs for which the p->pack_local bit is set? Or is the locality of a pack determined relative to the source containing it, in which case we'd need to make the check here?

Show 14 quoted lines
> +		if (packfile_store_for_each_object(source->packfiles, &oi,
> +						   add_object_in_unpacked_pack, NULL,
> +						   ODB_FOR_EACH_OBJECT_PACK_ORDER |
> +						   ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS |
> +						   ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS))
> +			die(_("cannot open pack index"));
> +	}
>  }
>
>  static int add_loose_object(const struct object_id *oid, const char *path,
>
> --
> 2.53.0.rc0.250.g0ac79233d6.dirty
>

Thanks, Taylor

Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 95 of 120 in “odb: introduce `odb_for_each_object()`”
  1. 00/14 odb: introduce `odb_for_each_object()`Patrick Steinhardt, Jan 15, 2026
  2. 01/14 odb: rename `FOR_EACH_OBJECT_*` flagsPatrick Steinhardt, Jan 15, 2026
  3. Justin ToblerJan 15, 2026
  4. 02/14 odb: fix flags parameter to be unsignedPatrick Steinhardt, Jan 15, 2026
  5. 03/14 object-file: extract function to read object info from pathPatrick Steinhardt, Jan 15, 2026
  6. Justin ToblerJan 15, 2026
  7. Patrick SteinhardtJan 16, 2026
  8. Karthik NayakJan 20, 2026
  9. 04/14 object-file: introduce function to iterate through objectsPatrick Steinhardt, Jan 15, 2026
  10. Justin ToblerJan 15, 2026
  11. Patrick SteinhardtJan 16, 2026
  12. Karthik NayakJan 20, 2026
  13. 05/14 packfile: extract function to iterate through objects of a storePatrick Steinhardt, Jan 15, 2026
  14. 06/14 packfile: introduce function to iterate through objectsPatrick Steinhardt, Jan 15, 2026
  15. 07/14 odb: introduce `odb_for_each_object()`Patrick Steinhardt, Jan 15, 2026
  16. Justin ToblerJan 15, 2026
  17. Patrick SteinhardtJan 16, 2026
  18. Justin ToblerJan 16, 2026
  19. Patrick SteinhardtJan 19, 2026
  20. Karthik NayakJan 20, 2026
  21. Patrick SteinhardtJan 21, 2026
  22. 08/14 builtin/fsck: refactor to use `odb_for_each_object()`Patrick Steinhardt, Jan 15, 2026
  23. Justin ToblerJan 15, 2026
  24. 09/14 treewide: enumerate promisor objects via `odb_for_each_object()`Patrick Steinhardt, Jan 15, 2026
  25. 10/14 treewide: drop uses of `for_each_{loose,packed}_object()`Patrick Steinhardt, Jan 15, 2026
  26. Justin ToblerJan 15, 2026
  27. Patrick SteinhardtJan 16, 2026
  28. Justin ToblerJan 16, 2026
  29. Patrick SteinhardtJan 19, 2026
  30. 11/14 odb: introduce mtime fields for object info requestsPatrick Steinhardt, Jan 15, 2026
  31. 12/14 builtin/pack-objects: use `packfile_store_for_each_object()`Patrick Steinhardt, Jan 15, 2026
  32. 13/14 reachable: convert to use `odb_for_each_object()`Patrick Steinhardt, Jan 15, 2026
  33. 14/14 odb: drop unused `for_each_{loose,packed}_object()` functionsPatrick Steinhardt, Jan 15, 2026
  34. Junio C HamanoJan 15, 2026
  35. Patrick SteinhardtJan 16, 2026
  36. Junio C HamanoJan 16, 2026
  37. 00/14 odb: introduce `odb_for_each_object()`Patrick Steinhardt, Jan 20, 2026
  38. 01/14 odb: rename `FOR_EACH_OBJECT_*` flagsPatrick Steinhardt, Jan 20, 2026
  39. 02/14 odb: fix flags parameter to be unsignedPatrick Steinhardt, Jan 20, 2026
  40. 03/14 object-file: extract function to read object info from pathPatrick Steinhardt, Jan 20, 2026
  41. 04/14 object-file: introduce function to iterate through objectsPatrick Steinhardt, Jan 20, 2026
  42. 05/14 packfile: extract function to iterate through objects of a storePatrick Steinhardt, Jan 20, 2026
  43. 06/14 packfile: introduce function to iterate through objectsPatrick Steinhardt, Jan 20, 2026
  44. 07/14 odb: introduce `odb_for_each_object()`Patrick Steinhardt, Jan 20, 2026
  45. 08/14 builtin/fsck: refactor to use `odb_for_each_object()`Patrick Steinhardt, Jan 20, 2026
  46. 09/14 treewide: enumerate promisor objects via `odb_for_each_object()`Patrick Steinhardt, Jan 20, 2026
  47. 10/14 treewide: drop uses of `for_each_{loose,packed}_object()`Patrick Steinhardt, Jan 20, 2026
  48. 11/14 odb: introduce mtime fields for object info requestsPatrick Steinhardt, Jan 20, 2026
  49. 12/14 builtin/pack-objects: use `packfile_store_for_each_object()`Patrick Steinhardt, Jan 20, 2026
  50. 13/14 reachable: convert to use `odb_for_each_object()`Patrick Steinhardt, Jan 20, 2026
  51. 14/14 odb: drop unused `for_each_{loose,packed}_object()` functionsPatrick Steinhardt, Jan 20, 2026
  52. 00/14 odb: introduce `odb_for_each_object()`Patrick Steinhardt, Jan 21, 2026
  53. 01/14 odb: rename `FOR_EACH_OBJECT_*` flagsPatrick Steinhardt, Jan 21, 2026
  54. 02/14 odb: fix flags parameter to be unsignedPatrick Steinhardt, Jan 21, 2026
  55. Jeff KingJan 21, 2026
  56. Taylor BlauJan 22, 2026
  57. Junio C HamanoJan 22, 2026
  58. Jeff KingJan 22, 2026
  59. Patrick SteinhardtJan 23, 2026
  60. Junio C HamanoJan 26, 2026
  61. Patrick SteinhardtJan 22, 2026
  62. Taylor BlauJan 22, 2026
  63. 03/14 object-file: extract function to read object info from pathPatrick Steinhardt, Jan 21, 2026
  64. Taylor BlauJan 22, 2026
  65. Patrick SteinhardtJan 22, 2026
  66. Taylor BlauJan 22, 2026
  67. 04/14 object-file: introduce function to iterate through objectsPatrick Steinhardt, Jan 21, 2026
  68. Taylor BlauJan 22, 2026
  69. Patrick SteinhardtJan 22, 2026
  70. Taylor BlauJan 23, 2026
  71. 05/14 packfile: extract function to iterate through objects of a storePatrick Steinhardt, Jan 21, 2026
  72. Taylor BlauJan 22, 2026
  73. 06/14 packfile: introduce function to iterate through objectsPatrick Steinhardt, Jan 21, 2026
  74. Taylor BlauJan 23, 2026
  75. Patrick SteinhardtJan 23, 2026
  76. Chris TorekJan 23, 2026
  77. Junio C HamanoJan 23, 2026
  78. Taylor BlauJan 23, 2026
  79. 07/14 odb: introduce `odb_for_each_object()`Patrick Steinhardt, Jan 21, 2026
  80. Taylor BlauJan 23, 2026
  81. 08/14 builtin/fsck: refactor to use `odb_for_each_object()`Patrick Steinhardt, Jan 21, 2026
  82. Taylor BlauJan 23, 2026
  83. Patrick SteinhardtJan 23, 2026
  84. 09/14 treewide: enumerate promisor objects via `odb_for_each_object()`Patrick Steinhardt, Jan 21, 2026
  85. Taylor BlauJan 23, 2026
  86. 10/14 treewide: drop uses of `for_each_{loose,packed}_object()`Patrick Steinhardt, Jan 21, 2026
  87. Taylor BlauJan 23, 2026
  88. Patrick SteinhardtJan 23, 2026
  89. 11/14 odb: introduce mtime fields for object info requestsPatrick Steinhardt, Jan 21, 2026
  90. Taylor BlauJan 23, 2026
  91. Patrick SteinhardtJan 23, 2026
  92. Taylor BlauJan 23, 2026
  93. Patrick SteinhardtJan 26, 2026
  94. 12/14 builtin/pack-objects: use `packfile_store_for_each_object()`Patrick Steinhardt, Jan 21, 2026
  95. Taylor BlauJan 23, 2026
  96. Patrick SteinhardtJan 23, 2026
  97. Taylor BlauJan 23, 2026
  98. Patrick SteinhardtJan 26, 2026
  99. Jeff KingJan 29, 2026
  100. Patrick SteinhardtJan 30, 2026
  101. 13/14 reachable: convert to use `odb_for_each_object()`Patrick Steinhardt, Jan 21, 2026
  102. 14/14 odb: drop unused `for_each_{loose,packed}_object()` functionsPatrick Steinhardt, Jan 21, 2026
  103. Taylor BlauJan 22, 2026
  104. Junio C HamanoJan 22, 2026
  105. 00/14 odb: introduce `odb_for_each_object()`Patrick Steinhardt, Jan 26, 2026
  106. 01/14 odb: rename `FOR_EACH_OBJECT_*` flagsPatrick Steinhardt, Jan 26, 2026
  107. 02/14 odb: fix flags parameter to be unsignedPatrick Steinhardt, Jan 26, 2026
  108. 03/14 object-file: extract function to read object info from pathPatrick Steinhardt, Jan 26, 2026
  109. 04/14 object-file: introduce function to iterate through objectsPatrick Steinhardt, Jan 26, 2026
  110. 05/14 packfile: extract function to iterate through objects of a storePatrick Steinhardt, Jan 26, 2026
  111. 06/14 packfile: introduce function to iterate through objectsPatrick Steinhardt, Jan 26, 2026
  112. 07/14 odb: introduce `odb_for_each_object()`Patrick Steinhardt, Jan 26, 2026
  113. 08/14 builtin/fsck: refactor to use `odb_for_each_object()`Patrick Steinhardt, Jan 26, 2026
  114. 09/14 treewide: enumerate promisor objects via `odb_for_each_object()`Patrick Steinhardt, Jan 26, 2026
  115. 10/14 treewide: drop uses of `for_each_{loose,packed}_object()`Patrick Steinhardt, Jan 26, 2026
  116. 11/14 odb: introduce mtime fields for object info requestsPatrick Steinhardt, Jan 26, 2026
  117. 12/14 builtin/pack-objects: use `packfile_store_for_each_object()`Patrick Steinhardt, Jan 26, 2026
  118. 13/14 reachable: convert to use `odb_for_each_object()`Patrick Steinhardt, Jan 26, 2026
  119. 14/14 odb: drop unused `for_each_{loose,packed}_object()` functionsPatrick Steinhardt, Jan 26, 2026
  120. Junio C HamanoFeb 20, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.