Git fork

refs: add a generic 'optimize' API

The existing `pack-refs` API is conceptually tied to the 'files'
backend, but its behavior is generic (e.g., it triggers compaction for
reftable). This naming is confusing.

Introduce a new generic refs_optimize() API that dispatches to a
backend-specific implementation via a new 'optimize' vtable method.

This lays the architectural groundwork for different reference backends
(like 'files' and 'reftable') to provide their own storage optimization
logic, which will be called from a single, generic entry point.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Meet Soni and committed by
Junio C Hamano
8dfe077f f814da67

+14
+5
refs.c
··· 2282 2282 return refs->be->pack_refs(refs, opts); 2283 2283 } 2284 2284 2285 + int refs_optimize(struct ref_store *refs, struct pack_refs_opts *opts) 2286 + { 2287 + return refs->be->optimize(refs, opts); 2288 + } 2289 + 2285 2290 int peel_iterated_oid(struct repository *r, const struct object_id *base, struct object_id *peeled) 2286 2291 { 2287 2292 if (current_ref_iter &&
+6
refs.h
··· 481 481 int refs_pack_refs(struct ref_store *refs, struct pack_refs_opts *opts); 482 482 483 483 /* 484 + * Optimize the ref store. The exact behavior is up to the backend. 485 + * For the files backend, this is equivalent to packing refs. 486 + */ 487 + int refs_optimize(struct ref_store *refs, struct pack_refs_opts *opts); 488 + 489 + /* 484 490 * Setup reflog before using. Fill in err and return -1 on failure. 485 491 */ 486 492 int refs_create_reflog(struct ref_store *refs, const char *refname,
+3
refs/refs-internal.h
··· 447 447 448 448 typedef int pack_refs_fn(struct ref_store *ref_store, 449 449 struct pack_refs_opts *opts); 450 + typedef int optimize_fn(struct ref_store *ref_store, 451 + struct pack_refs_opts *opts); 450 452 typedef int rename_ref_fn(struct ref_store *ref_store, 451 453 const char *oldref, const char *newref, 452 454 const char *logmsg); ··· 572 574 ref_transaction_abort_fn *transaction_abort; 573 575 574 576 pack_refs_fn *pack_refs; 577 + optimize_fn *optimize; 575 578 rename_ref_fn *rename_ref; 576 579 copy_ref_fn *copy_ref; 577 580