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

Re: [GSoC][PATCH v4 5/9] builtin/pack-refs: factor out core logic into a shared library

From
Patrick Steinhardt <ps@pks.im>
Date
Sep 24, 2025, 06:18 UTC
Message-ID
<aNONRY10f6R-3Il0@pks.im>
In-Reply-To
<20250919082647.535213-6-meetsoni3017@gmail.com>
On Fri, Sep 19, 2025 at 01:56:43PM +0530, Meet Soni wrote:
Show 10 quoted lines
> The implementation of `git pack-refs` is monolithic within
> `cmd_pack_refs()`, making it impossible to share its logic with other
> commands. To enable code reuse for the upcoming `git refs optimize`
> subcommand, refactor the core logic into a shared helper function.
> 
> Split the original `builtin/pack-refs.c` file into two parts:
> 
> - A new shared library file, `pack-refs.c`, which contains the
>   core option parsing and packing logic in a new `pack_refs_core()`
>   helper function.

Should we maybe host that file in "refs/pack.c"? This ensures that all ref-related infra continues to sit in one place. We could also build on your previous steps and call it "refs/optimize.c" right away.

Show 15 quoted lines
> diff --git a/pack-refs.c b/pack-refs.c
> new file mode 100644
> index 0000000000..1a5e07d8b8
> --- /dev/null
> +++ b/pack-refs.c
> @@ -0,0 +1,56 @@
> +#include "builtin.h"
> +#include "config.h"
> +#include "environment.h"
> +#include "pack-refs.h"
> +#include "parse-options.h"
> +#include "refs.h"
> +#include "revision.h"
> +
> +int pack_refs_core(int argc,

If we want to go with "refs/optimize.c" I'd call this `refs_optimize_core()`.

Show 17 quoted lines
> diff --git a/pack-refs.h b/pack-refs.h
> new file mode 100644
> index 0000000000..5de27e7da8
> --- /dev/null
> +++ b/pack-refs.h
> @@ -0,0 +1,23 @@
> +#ifndef PACK_REFS_H
> +#define PACK_REFS_H
> +
> +struct repository;
> +
> +/*
> + * Shared usage string for options common to git-pack-refs(1)
> + * and git-refs-optimize(1). The command-specific part (e.g., "git refs optimize ")
> + * must be prepended by the caller.
> + */
> +#define PACK_REFS_OPTS \
This would become `REFS_OPTIMIZE_OPTS`.
Show 12 quoted lines
> +	"[--all] [--no-prune] [--auto] [--include <pattern>] [--exclude <pattern>]"
> +
> +/*
> + * The core logic for pack-refs and its clones.
> + */
> +int pack_refs_core(int argc,
> +		   const char **argv,
> +		   const char *prefix,
> +		   struct repository *repo,
> +		   const char * const *usage_opts);
> +
> +#endif /* PACK_REFS_H */
Patrick
Previous: Meet SoniNext: Meet Soni
Message 31 of 36 in “Add refs optimize subcommand”
  1. Meet SoniSep 6, 2025
  2. [GSoC][PATCH v2 1/5] builtin/pack-refs: factor out core logic into a shared libraryMeet Soni, Sep 6, 2025
  3. [GSoC][PATCH v2 2/5] doc: factor out common optionMeet Soni, Sep 6, 2025
  4. Junio C HamanoSep 8, 2025
  5. [GSoC][PATCH v2 3/5] builtin/refs: add optimize subcommandMeet Soni, Sep 6, 2025
  6. [GSoC][PATCH v2 4/5] t0601: refactor tests to be shareableMeet Soni, Sep 6, 2025
  7. [GSoC][PATCH v2 5/5] t: add test for git refs optimize subcommandMeet Soni, Sep 6, 2025
  8. Junio C HamanoSep 8, 2025
  9. Junio C HamanoSep 8, 2025
  10. [GSoC][PATCH v3 0/9] Add refs optimize subcommandMeet Soni, Sep 18, 2025
  11. [GSoC][PATCH v3 1/9] refs: add a generic 'optimize' APIMeet Soni, Sep 18, 2025
  12. shejialuoSep 18, 2025
  13. Junio C HamanoSep 18, 2025
  14. [GSoC][PATCH v3 2/9] files-backend: implement 'optimize' actionMeet Soni, Sep 18, 2025
  15. [GSoC][PATCH v3 3/9] reftable-backend: implement 'optimize' actionMeet Soni, Sep 18, 2025
  16. [GSoC][PATCH v3 4/9] builtin/pack-refs: convert to use the generic refs_optimize() APIMeet Soni, Sep 18, 2025
  17. shejialuoSep 18, 2025
  18. [GSoC][PATCH v3 5/9] builtin/pack-refs: factor out core logic into a shared libraryMeet Soni, Sep 18, 2025
  19. [GSoC][GSoC][PATCH v3 6/9] doc: pack-refs: factor out common optionsMeet Soni, Sep 18, 2025
  20. [GSoC][PATCH v3 7/9] builtin/refs: add optimize subcommandMeet Soni, Sep 18, 2025
  21. Junio C HamanoSep 18, 2025
  22. [GSoC][PATCH v3 8/9] t0601: refactor tests to be shareableMeet Soni, Sep 18, 2025
  23. [GSoC][PATCH v3 9/9] t: add test for git refs optimize subcommandMeet Soni, Sep 18, 2025
  24. [GSoC][PATCH v4 0/9] Add refs optimize subcommandMeet Soni, Sep 19, 2025
  25. [GSoC][PATCH v4 1/9] refs: add a generic 'optimize' APIMeet Soni, Sep 19, 2025
  26. Patrick SteinhardtSep 24, 2025
  27. [GSoC][PATCH v4 2/9] files-backend: implement 'optimize' actionMeet Soni, Sep 19, 2025
  28. [GSoC][PATCH v4 3/9] reftable-backend: implement 'optimize' actionMeet Soni, Sep 19, 2025
  29. [GSoC][PATCH v4 4/9] builtin/pack-refs: convert to use the generic refs_optimize() APIMeet Soni, Sep 19, 2025
  30. [GSoC][PATCH v4 5/9] builtin/pack-refs: factor out core logic into a shared libraryMeet Soni, Sep 19, 2025
  31. Patrick SteinhardtSep 24, 2025
  32. [GSoC][PATCH v4 6/9] doc: pack-refs: factor out common optionsMeet Soni, Sep 19, 2025
  33. [GSoC][PATCH v4 7/9] builtin/refs: add optimize subcommandMeet Soni, Sep 19, 2025
  34. [GSoC][PATCH v4 8/9] t0601: refactor tests to be shareableMeet Soni, Sep 19, 2025
  35. [GSoC][PATCH v4 9/9] t: add test for git refs optimize subcommandMeet Soni, Sep 19, 2025
  36. Junio C HamanoSep 19, 2025

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.