repack-promisor: allow excluding objects from the rebuilt promisor pack

Add a to_drop oidset parameter to repack_promisor_objects(). When it is
non-NULL, write_oid() omits those objects from the rebuilt promisor
pack. This is the mechanism --drop-filtered will use to remove promisor
blobs, i.e. rebuild the promisor pack without them.

All existing callers pass NULL, so behavior is unchanged.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Siddharth Asthana <siddharthasthana31@gmail.com>
Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
main
Siddharth Shrimali 2026-08-14 01:38:27 +05:30 committed by Junio C Hamano
parent 401c308671
commit 85531bbf29
3 changed files with 18 additions and 3 deletions

View File

@ -430,7 +430,7 @@ int cmd_repack(int argc,
strvec_push(&cmd.args, "--delta-islands");

if (pack_everything & ALL_INTO_ONE) {
repack_promisor_objects(repo, &po_args, &names, packtmp);
repack_promisor_objects(repo, &po_args, &names, packtmp, NULL);

if (existing_packs_has_non_kept(&existing) &&
delete_redundant &&

View File

@ -6,10 +6,12 @@
#include "path.h"
#include "repository.h"
#include "run-command.h"
#include "oidset.h"

struct write_oid_context {
struct child_process *cmd;
const struct git_hash_algo *algop;
const struct oidset *to_drop;
};

/*
@ -23,6 +25,15 @@ static int write_oid(const struct object_id *oid,
struct write_oid_context *ctx = data;
struct child_process *cmd = ctx->cmd;

/*
* Objects in to_drop are being removed from the repository, so
* omit them from the rebuilt promisor pack. Each such object is a
* promisor object and therefore remains recoverable from the
* promisor remote.
*/
if (ctx->to_drop && oidset_contains(ctx->to_drop, oid))
return 0;

if (cmd->in == -1) {
if (start_command(cmd))
die(_("could not start pack-objects to repack promisor objects"));
@ -81,7 +92,8 @@ static void finish_repacking_promisor_objects(struct repository *repo,

void repack_promisor_objects(struct repository *repo,
const struct pack_objects_args *args,
struct string_list *names, const char *packtmp)
struct string_list *names, const char *packtmp,
const struct oidset *to_drop)
{
struct write_oid_context ctx;
struct child_process cmd = CHILD_PROCESS_INIT;
@ -98,6 +110,7 @@ void repack_promisor_objects(struct repository *repo,
*/
ctx.cmd = &cmd;
ctx.algop = repo->hash_algo;
ctx.to_drop = to_drop;
odb_for_each_object(repo->objects, NULL, write_oid, &ctx,
ODB_FOR_EACH_OBJECT_PROMISOR_ONLY);


View File

@ -3,6 +3,7 @@

#include "list-objects-filter-options.h"
#include "string-list.h"
#include "oidset.h"

struct pack_objects_args {
char *window;
@ -100,7 +101,8 @@ void generated_pack_install(struct generated_pack *pack, const char *name,

void repack_promisor_objects(struct repository *repo,
const struct pack_objects_args *args,
struct string_list *names, const char *packtmp);
struct string_list *names, const char *packtmp,
const struct oidset *to_drop);

struct pack_geometry {
struct packed_git **pack;