Skip to content

Commit fb546d6

Browse files
ttaylorrgitster
authored andcommitted
reachable: report precise timestamps from objects in cruft packs
When generating a cruft pack, the caller within pack-objects will want to know the precise timestamps of cruft objects (i.e., their corresponding values in the .mtimes table) rather than the mtime of the cruft pack itself. Teach add_recent_packed() to lookup each object's precise mtime from the .mtimes file if one exists (indicated by the is_cruft bit on the packed_git structure). A couple of small things worth noting here: - load_pack_mtimes() needs to be called before asking for nth_packed_mtime(), and that call is done lazily here. That function exits early if the .mtimes file has already been opened and parsed, so only the first call is slow. - Checking the is_cruft bit can be done without any extra work on the caller's behalf, since it is set up for us automatically as a side-effect of calling add_packed_git() (just like the 'pack_keep' and 'pack_promisor' bits). Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2fb9040 commit fb546d6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

reachable.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "worktree.h"
1414
#include "object-store.h"
1515
#include "pack-bitmap.h"
16+
#include "pack-mtimes.h"
1617

1718
struct connectivity_progress {
1819
struct progress *progress;
@@ -155,6 +156,7 @@ static int add_recent_packed(const struct object_id *oid,
155156
void *data)
156157
{
157158
struct object *obj;
159+
timestamp_t mtime = p->mtime;
158160

159161
if (!want_recent_object(data, oid))
160162
return 0;
@@ -163,7 +165,12 @@ static int add_recent_packed(const struct object_id *oid,
163165

164166
if (obj && obj->flags & SEEN)
165167
return 0;
166-
add_recent_object(oid, p, nth_packed_object_offset(p, pos), p->mtime, data);
168+
if (p->is_cruft) {
169+
if (load_pack_mtimes(p) < 0)
170+
die(_("could not load cruft pack .mtimes"));
171+
mtime = nth_packed_mtime(p, pos);
172+
}
173+
add_recent_object(oid, p, nth_packed_object_offset(p, pos), mtime, data);
167174
return 0;
168175
}
169176

0 commit comments

Comments
 (0)