pack-mtimes: support writing pack .mtimes files

Now that the `.mtimes` format is defined, supplement the pack-write API
to be able to conditionally write an `.mtimes` file along with a pack by
setting an additional flag and passing an oidmap that contains the
timestamps corresponding to each object in the pack.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Taylor Blau
2022-05-20 19:17:43 -04:00
committed by Junio C Hamano
parent d9fef9d90d
commit 5dfaf49a5a
4 changed files with 109 additions and 0 deletions

View File

@@ -168,6 +168,14 @@ struct packing_data {
/* delta islands */
unsigned int *tree_depth;
unsigned char *layer;
/*
* Used when writing cruft packs.
*
* Object mtimes are stored in pack order when writing, but
* written out in lexicographic (index) order.
*/
uint32_t *cruft_mtime;
};
void prepare_packing_data(struct repository *r, struct packing_data *pdata);
@@ -289,4 +297,21 @@ static inline void oe_set_layer(struct packing_data *pack,
pack->layer[e - pack->objects] = layer;
}
static inline uint32_t oe_cruft_mtime(struct packing_data *pack,
struct object_entry *e)
{
if (!pack->cruft_mtime)
return 0;
return pack->cruft_mtime[e - pack->objects];
}
static inline void oe_set_cruft_mtime(struct packing_data *pack,
struct object_entry *e,
uint32_t mtime)
{
if (!pack->cruft_mtime)
CALLOC_ARRAY(pack->cruft_mtime, pack->nr_alloc);
pack->cruft_mtime[e - pack->objects] = mtime;
}
#endif