* [GSoC][PATCH 0/5] Add refs optimize subcommand
@ 2025-08-26 7:36 Meet Soni
2025-08-26 7:36 ` [GSoC][PATCH 1/5] builtin/pack-refs: factor out core logic into a helper Meet Soni
` (4 more replies)
0 siblings, 5 replies; 17+ messages in thread
From: Meet Soni @ 2025-08-26 7:36 UTC (permalink / raw)
To: git; +Cc: ps, shejialuo, Meet Soni
This series introduces `git refs optimize` as a modern replacement for
`git pack-refs`, continuing the effort to consolidate commands
under the `git refs` namespace.
Meet Soni (5):
builtin/pack-refs: factor out core logic into a helper
doc: factor out common option
builtin/refs: add optimize subcommand
t0601: refactor tests to be shareable
t: add test for git refs optimize subcommand
Documentation/git-pack-refs.adoc | 54 +---
Documentation/git-refs.adoc | 10 +
Documentation/pack-refs-options.adoc | 52 ++++
builtin/pack-refs.c | 31 +-
builtin/refs.c | 16 +
pack-refs.h | 22 ++
t/meson.build | 3 +-
t/pack-refs-tests.sh | 431 +++++++++++++++++++++++++++
t/t0601-reffiles-pack-refs.sh | 430 +-------------------------
t/t1463-refs-optimize.sh | 17 ++
10 files changed, 572 insertions(+), 494 deletions(-)
create mode 100644 Documentation/pack-refs-options.adoc
create mode 100644 pack-refs.h
create mode 100644 t/pack-refs-tests.sh
create mode 100755 t/t1463-refs-optimize.sh
base-commit: 1fa68948c3d76328236cac73d2adf33c905bd8e3
--
2.34.1
^ permalink raw reply [flat|nested] 17+ messages in thread
* [GSoC][PATCH 1/5] builtin/pack-refs: factor out core logic into a helper
2025-08-26 7:36 [GSoC][PATCH 0/5] Add refs optimize subcommand Meet Soni
@ 2025-08-26 7:36 ` Meet Soni
2025-09-02 10:18 ` Patrick Steinhardt
2025-08-26 7:36 ` [GSoC][PATCH 2/5] doc: factor out common option Meet Soni
` (3 subsequent siblings)
4 siblings, 1 reply; 17+ messages in thread
From: Meet Soni @ 2025-08-26 7:36 UTC (permalink / raw)
To: git; +Cc: ps, shejialuo, Meet Soni
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.
Introduce a new `pack-refs.h` header to define the public interface
for this shared logic. It contains the declaration for a new helper
function, `pack_refs_core()`, and a macro for the common usage
options.
Move the option parsing and packing logic from `cmd_pack_refs()` into a
new helper function named `pack_refs_core()`. This helper is made
generic by accepting the command's usage string as a parameter.
The original `cmd_pack_refs()` is simplified to a thin wrapper that
is only responsible for defining its specific usage array and calling
the shared helper.
Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
---
builtin/pack-refs.c | 31 ++++++++++++++++++++-----------
pack-refs.h | 22 ++++++++++++++++++++++
2 files changed, 42 insertions(+), 11 deletions(-)
create mode 100644 pack-refs.h
diff --git a/builtin/pack-refs.c b/builtin/pack-refs.c
index 5e28d0f9e8..7c4d7854c8 100644
--- a/builtin/pack-refs.c
+++ b/builtin/pack-refs.c
@@ -2,19 +2,16 @@
#include "config.h"
#include "environment.h"
#include "gettext.h"
+#include "pack-refs.h"
#include "parse-options.h"
#include "refs.h"
#include "revision.h"
-static char const * const pack_refs_usage[] = {
- N_("git pack-refs [--all] [--no-prune] [--auto] [--include <pattern>] [--exclude <pattern>]"),
- NULL
-};
-
-int cmd_pack_refs(int argc,
- const char **argv,
- const char *prefix,
- struct repository *repo)
+int pack_refs_core(int argc,
+ const char **argv,
+ const char *prefix,
+ struct repository *repo,
+ const char * const *usage_opts)
{
struct ref_exclusions excludes = REF_EXCLUSIONS_INIT;
struct string_list included_refs = STRING_LIST_INIT_NODUP;
@@ -39,8 +36,8 @@ int cmd_pack_refs(int argc,
OPT_END(),
};
repo_config(repo, git_default_config, NULL);
- if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
- usage_with_options(pack_refs_usage, opts);
+ if (parse_options(argc, argv, prefix, opts, usage_opts, 0))
+ usage_with_options(usage_opts, opts);
for_each_string_list_item(item, &option_excluded_refs)
add_ref_exclusion(pack_refs_opts.exclusions, item->string);
@@ -58,3 +55,15 @@ int cmd_pack_refs(int argc,
string_list_clear(&option_excluded_refs, 0);
return ret;
}
+
+int cmd_pack_refs(int argc,
+ const char **argv,
+ const char *prefix,
+ struct repository *repo)
+{
+ static char const * const pack_refs_usage[] = {
+ N_("git pack-refs " PACK_REFS_OPTS),
+ NULL
+ };
+ return pack_refs_core(argc, argv, prefix, repo, pack_refs_usage);
+}
diff --git a/pack-refs.h b/pack-refs.h
new file mode 100644
index 0000000000..ba51d154e3
--- /dev/null
+++ b/pack-refs.h
@@ -0,0 +1,22 @@
+#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 \
+ "[--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 */
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [GSoC][PATCH 2/5] doc: factor out common option
2025-08-26 7:36 [GSoC][PATCH 0/5] Add refs optimize subcommand Meet Soni
2025-08-26 7:36 ` [GSoC][PATCH 1/5] builtin/pack-refs: factor out core logic into a helper Meet Soni
@ 2025-08-26 7:36 ` Meet Soni
2025-08-26 7:36 ` [GSoC][PATCH 3/5] builtin/refs: add optimize subcommand Meet Soni
` (2 subsequent siblings)
4 siblings, 0 replies; 17+ messages in thread
From: Meet Soni @ 2025-08-26 7:36 UTC (permalink / raw)
To: git; +Cc: ps, shejialuo, Meet Soni
In preparation for adding documentation for `git refs optimize`, factor
out the common options from the `git-pack-refs` man page into a
shareable file `pack-refs-options.adoc` and update `git-pack-refs.adoc`
to use an `include::` macro.
This change is a pure refactoring and results in no change to the
final rendered documentation for `pack-refs`.
Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
---
Documentation/git-pack-refs.adoc | 54 +---------------------------
Documentation/pack-refs-options.adoc | 52 +++++++++++++++++++++++++++
2 files changed, 53 insertions(+), 53 deletions(-)
create mode 100644 Documentation/pack-refs-options.adoc
diff --git a/Documentation/git-pack-refs.adoc b/Documentation/git-pack-refs.adoc
index 42b90051e6..dac63e5e12 100644
--- a/Documentation/git-pack-refs.adoc
+++ b/Documentation/git-pack-refs.adoc
@@ -45,59 +45,7 @@ unpacked.
OPTIONS
-------
---all::
-
-The command by default packs all tags and refs that are already
-packed, and leaves other refs
-alone. This is because branches are expected to be actively
-developed and packing their tips does not help performance.
-This option causes all refs to be packed as well, with the exception
-of hidden refs, broken refs, and symbolic refs. Useful for a repository
-with many branches of historical interests.
-
---no-prune::
-
-The command usually removes loose refs under `$GIT_DIR/refs`
-hierarchy after packing them. This option tells it not to.
-
---auto::
-
-Pack refs as needed depending on the current state of the ref database. The
-behavior depends on the ref format used by the repository and may change in the
-future.
-+
- - "files": Loose references are packed into the `packed-refs` file
- based on the ratio of loose references to the size of the
- `packed-refs` file. The bigger the `packed-refs` file, the more loose
- references need to exist before we repack.
-+
- - "reftable": Tables are compacted such that they form a geometric
- sequence. For two tables N and N+1, where N+1 is newer, this
- maintains the property that N is at least twice as big as N+1. Only
- tables that violate this property are compacted.
-
---include <pattern>::
-
-Pack refs based on a `glob(7)` pattern. Repetitions of this option
-accumulate inclusion patterns. If a ref is both included in `--include` and
-`--exclude`, `--exclude` takes precedence. Using `--include` will preclude all
-tags from being included by default. Symbolic refs and broken refs will never
-be packed. When used with `--all`, it will be a noop. Use `--no-include` to clear
-and reset the list of patterns.
-
---exclude <pattern>::
-
-Do not pack refs matching the given `glob(7)` pattern. Repetitions of this option
-accumulate exclusion patterns. Use `--no-exclude` to clear and reset the list of
-patterns. If a ref is already packed, including it with `--exclude` will not
-unpack it.
-+
-When used with `--all`, pack only loose refs which do not match any of
-the provided `--exclude` patterns.
-+
-When used with `--include`, refs provided to `--include`, minus refs that are
-provided to `--exclude` will be packed.
-
+include::pack-refs-options.adoc[]
BUGS
----
diff --git a/Documentation/pack-refs-options.adoc b/Documentation/pack-refs-options.adoc
new file mode 100644
index 0000000000..0b11282941
--- /dev/null
+++ b/Documentation/pack-refs-options.adoc
@@ -0,0 +1,52 @@
+--all::
+
+The command by default packs all tags and refs that are already
+packed, and leaves other refs
+alone. This is because branches are expected to be actively
+developed and packing their tips does not help performance.
+This option causes all refs to be packed as well, with the exception
+of hidden refs, broken refs, and symbolic refs. Useful for a repository
+with many branches of historical interests.
+
+--no-prune::
+
+The command usually removes loose refs under `$GIT_DIR/refs`
+hierarchy after packing them. This option tells it not to.
+
+--auto::
+
+Pack refs as needed depending on the current state of the ref database. The
+behavior depends on the ref format used by the repository and may change in the
+future.
++
+ - "files": Loose references are packed into the `packed-refs` file
+ based on the ratio of loose references to the size of the
+ `packed-refs` file. The bigger the `packed-refs` file, the more loose
+ references need to exist before we repack.
++
+ - "reftable": Tables are compacted such that they form a geometric
+ sequence. For two tables N and N+1, where N+1 is newer, this
+ maintains the property that N is at least twice as big as N+1. Only
+ tables that violate this property are compacted.
+
+--include <pattern>::
+
+Pack refs based on a `glob(7)` pattern. Repetitions of this option
+accumulate inclusion patterns. If a ref is both included in `--include` and
+`--exclude`, `--exclude` takes precedence. Using `--include` will preclude all
+tags from being included by default. Symbolic refs and broken refs will never
+be packed. When used with `--all`, it will be a noop. Use `--no-include` to clear
+and reset the list of patterns.
+
+--exclude <pattern>::
+
+Do not pack refs matching the given `glob(7)` pattern. Repetitions of this option
+accumulate exclusion patterns. Use `--no-exclude` to clear and reset the list of
+patterns. If a ref is already packed, including it with `--exclude` will not
+unpack it.
++
+When used with `--all`, pack only loose refs which do not match any of
+the provided `--exclude` patterns.
++
+When used with `--include`, refs provided to `--include`, minus refs that are
+provided to `--exclude` will be packed.
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [GSoC][PATCH 3/5] builtin/refs: add optimize subcommand
2025-08-26 7:36 [GSoC][PATCH 0/5] Add refs optimize subcommand Meet Soni
2025-08-26 7:36 ` [GSoC][PATCH 1/5] builtin/pack-refs: factor out core logic into a helper Meet Soni
2025-08-26 7:36 ` [GSoC][PATCH 2/5] doc: factor out common option Meet Soni
@ 2025-08-26 7:36 ` Meet Soni
2025-09-02 10:18 ` Patrick Steinhardt
2025-08-26 7:36 ` [GSoC][PATCH 4/5] t0601: refactor tests to be shareable Meet Soni
2025-08-26 7:36 ` [GSoC][PATCH 5/5] t: add test for git refs optimize subcommand Meet Soni
4 siblings, 1 reply; 17+ messages in thread
From: Meet Soni @ 2025-08-26 7:36 UTC (permalink / raw)
To: git; +Cc: ps, shejialuo, Meet Soni
As part of the ongoing effort to consolidate reference handling,
introduce a new `optimize` subcommand. This command provides the same
functionality and exit-code behavior as `git pack-refs`, serving
as its modern replacement.
Implement `cmd_refs_optimize` by having it call the `pack_refs_core()`
helper function. This helper was factored out of the original
`cmd_pack_refs` in a preceding commit, allowing both commands to
share the same core logic as independent peers.
Add documentation for the new command. The man page leverages the shared
options file, created in a previous commit, by using the AsciiDoc
`include::` macro to ensure consistency with git-pack-refs(1).
Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
---
Documentation/git-refs.adoc | 10 ++++++++++
builtin/refs.c | 16 ++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/Documentation/git-refs.adoc b/Documentation/git-refs.adoc
index e608980711..121a2fbeff 100644
--- a/Documentation/git-refs.adoc
+++ b/Documentation/git-refs.adoc
@@ -18,6 +18,7 @@ git refs list [--count=<count>] [--shell|--perl|--python|--tcl]
[--contains[=<object>]] [--no-contains[=<object>]]
[(--exclude=<pattern>)...] [--start-after=<marker>]
[ --stdin | <pattern>... ]
+git refs optimize [--all] [--no-prune] [--auto] [--include <pattern>] [--exclude <pattern>]
DESCRIPTION
-----------
@@ -38,6 +39,11 @@ list::
formatting, and sorting. This subcommand is an alias for
linkgit:git-for-each-ref[1] and offers identical functionality.
+optimize::
+ Pack references into a single file to improve repository performance
+ and reduce storage usage. This subcommand is an alias for
+ linkgit:git-pack-refs[1] and offers identical functionality.
+
OPTIONS
-------
@@ -73,6 +79,10 @@ The following options are specific to 'git refs list':
include::for-each-ref-options.adoc[]
+The following options are specific to 'git refs optimize':
+
+include::pack-refs-options.adoc[]
+
KNOWN LIMITATIONS
-----------------
diff --git a/builtin/refs.c b/builtin/refs.c
index 76224feba4..e05fa5b8a6 100644
--- a/builtin/refs.c
+++ b/builtin/refs.c
@@ -2,6 +2,7 @@
#include "builtin.h"
#include "config.h"
#include "fsck.h"
+#include "pack-refs.h"
#include "parse-options.h"
#include "refs.h"
#include "strbuf.h"
@@ -14,6 +15,9 @@
#define REFS_VERIFY_USAGE \
N_("git refs verify [--strict] [--verbose]")
+#define REFS_OPTIMIZE_USAGE \
+ N_("git refs optimize " PACK_REFS_OPTS)
+
static int cmd_refs_migrate(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
@@ -113,6 +117,16 @@ static int cmd_refs_list(int argc, const char **argv, const char *prefix,
return for_each_ref_core(argc, argv, prefix, repo, refs_list_usage);
}
+static int cmd_refs_optimize(int argc, const char **argv, const char *prefix,
+ struct repository *repo)
+{
+ static char const * const refs_optimize_usage[] = {
+ REFS_OPTIMIZE_USAGE,
+ NULL
+ };
+ return pack_refs_core(argc, argv, prefix, repo, refs_optimize_usage);
+}
+
int cmd_refs(int argc,
const char **argv,
const char *prefix,
@@ -122,6 +136,7 @@ int cmd_refs(int argc,
REFS_MIGRATE_USAGE,
REFS_VERIFY_USAGE,
"git refs list " COMMON_USAGE_FOR_EACH_REF,
+ REFS_OPTIMIZE_USAGE,
NULL,
};
parse_opt_subcommand_fn *fn = NULL;
@@ -129,6 +144,7 @@ int cmd_refs(int argc,
OPT_SUBCOMMAND("migrate", &fn, cmd_refs_migrate),
OPT_SUBCOMMAND("verify", &fn, cmd_refs_verify),
OPT_SUBCOMMAND("list", &fn, cmd_refs_list),
+ OPT_SUBCOMMAND("optimize", &fn, cmd_refs_optimize),
OPT_END(),
};
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [GSoC][PATCH 4/5] t0601: refactor tests to be shareable
2025-08-26 7:36 [GSoC][PATCH 0/5] Add refs optimize subcommand Meet Soni
` (2 preceding siblings ...)
2025-08-26 7:36 ` [GSoC][PATCH 3/5] builtin/refs: add optimize subcommand Meet Soni
@ 2025-08-26 7:36 ` Meet Soni
2025-08-26 7:36 ` [GSoC][PATCH 5/5] t: add test for git refs optimize subcommand Meet Soni
4 siblings, 0 replies; 17+ messages in thread
From: Meet Soni @ 2025-08-26 7:36 UTC (permalink / raw)
To: git; +Cc: ps, shejialuo, Meet Soni
In preparation for adding tests for the new `git refs optimize` command,
refactor the existing t0601 test suite to make its logic shareable.
Move the core test logic from `t0601-reffiles-pack-refs.sh` into a new
`pack-refs-tests.sh` file. Inside this new script, replace hardcoded
calls to "pack-refs" with the `$pack_refs` variable.
The original `t0601-reffiles-pack-refs.sh` script now becomes a simple
"driver". It is responsible for setting the default value of the
variable and then sourcing the test library.
This new structure follows the established pattern used for sharing
tests between `git-for-each-ref` and `git-refs list` and prepares the test suite
for the `refs optimize` tests to be added in a subsequent commit.
Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
---
t/pack-refs-tests.sh | 431 ++++++++++++++++++++++++++++++++++
t/t0601-reffiles-pack-refs.sh | 430 +--------------------------------
2 files changed, 432 insertions(+), 429 deletions(-)
create mode 100644 t/pack-refs-tests.sh
diff --git a/t/pack-refs-tests.sh b/t/pack-refs-tests.sh
new file mode 100644
index 0000000000..3dbcc01718
--- /dev/null
+++ b/t/pack-refs-tests.sh
@@ -0,0 +1,431 @@
+pack_refs=${pack_refs:-pack-refs}
+
+test_expect_success 'enable reflogs' '
+ git config core.logallrefupdates true
+'
+
+test_expect_success 'prepare a trivial repository' '
+ echo Hello > A &&
+ git update-index --add A &&
+ git commit -m "Initial commit." &&
+ HEAD=$(git rev-parse --verify HEAD)
+'
+
+test_expect_success '${pack_refs} --prune --all' '
+ test_path_is_missing .git/packed-refs &&
+ git ${pack_refs} --no-prune --all &&
+ test_path_is_file .git/packed-refs &&
+ N=$(find .git/refs -type f | wc -l) &&
+ test "$N" != 0 &&
+
+ git ${pack_refs} --prune --all &&
+ test_path_is_file .git/packed-refs &&
+ N=$(find .git/refs -type f) &&
+ test -z "$N"
+'
+
+SHA1=
+
+test_expect_success 'see if git show-ref works as expected' '
+ git branch a &&
+ SHA1=$(cat .git/refs/heads/a) &&
+ echo "$SHA1 refs/heads/a" >expect &&
+ git show-ref a >result &&
+ test_cmp expect result
+'
+
+test_expect_success 'see if a branch still exists when packed' '
+ git branch b &&
+ git ${pack_refs} --all &&
+ rm -f .git/refs/heads/b &&
+ echo "$SHA1 refs/heads/b" >expect &&
+ git show-ref b >result &&
+ test_cmp expect result
+'
+
+test_expect_success 'git branch c/d should barf if branch c exists' '
+ git branch c &&
+ git ${pack_refs} --all &&
+ rm -f .git/refs/heads/c &&
+ test_must_fail git branch c/d
+'
+
+test_expect_success 'see if a branch still exists after git ${pack_refs} --prune' '
+ git branch e &&
+ git ${pack_refs} --all --prune &&
+ echo "$SHA1 refs/heads/e" >expect &&
+ git show-ref e >result &&
+ test_cmp expect result
+'
+
+test_expect_success 'see if git ${pack_refs} --prune remove ref files' '
+ git branch f &&
+ git ${pack_refs} --all --prune &&
+ ! test -f .git/refs/heads/f
+'
+
+test_expect_success 'see if git ${pack_refs} --prune removes empty dirs' '
+ git branch r/s/t &&
+ git ${pack_refs} --all --prune &&
+ ! test -e .git/refs/heads/r
+'
+
+test_expect_success 'git branch g should work when git branch g/h has been deleted' '
+ git branch g/h &&
+ git ${pack_refs} --all --prune &&
+ git branch -d g/h &&
+ git branch g &&
+ git ${pack_refs} --all &&
+ git branch -d g
+'
+
+test_expect_success 'git branch i/j/k should barf if branch i exists' '
+ git branch i &&
+ git ${pack_refs} --all --prune &&
+ test_must_fail git branch i/j/k
+'
+
+test_expect_success 'test git branch k after branch k/l/m and k/lm have been deleted' '
+ git branch k/l &&
+ git branch k/lm &&
+ git branch -d k/l &&
+ git branch k/l/m &&
+ git branch -d k/l/m &&
+ git branch -d k/lm &&
+ git branch k
+'
+
+test_expect_success 'test git branch n after some branch deletion and pruning' '
+ git branch n/o &&
+ git branch n/op &&
+ git branch -d n/o &&
+ git branch n/o/p &&
+ git branch -d n/op &&
+ git ${pack_refs} --all --prune &&
+ git branch -d n/o/p &&
+ git branch n
+'
+
+test_expect_success 'test excluded refs are not packed' '
+ git branch dont_pack1 &&
+ git branch dont_pack2 &&
+ git branch pack_this &&
+ git ${pack_refs} --all --exclude "refs/heads/dont_pack*" &&
+ test -f .git/refs/heads/dont_pack1 &&
+ test -f .git/refs/heads/dont_pack2 &&
+ ! test -f .git/refs/heads/pack_this'
+
+test_expect_success 'test --no-exclude refs clears excluded refs' '
+ git branch dont_pack3 &&
+ git branch dont_pack4 &&
+ git ${pack_refs} --all --exclude "refs/heads/dont_pack*" --no-exclude &&
+ ! test -f .git/refs/heads/dont_pack3 &&
+ ! test -f .git/refs/heads/dont_pack4'
+
+test_expect_success 'test only included refs are packed' '
+ git branch pack_this1 &&
+ git branch pack_this2 &&
+ git tag dont_pack5 &&
+ git ${pack_refs} --include "refs/heads/pack_this*" &&
+ test -f .git/refs/tags/dont_pack5 &&
+ ! test -f .git/refs/heads/pack_this1 &&
+ ! test -f .git/refs/heads/pack_this2'
+
+test_expect_success 'test --no-include refs clears included refs' '
+ git branch pack1 &&
+ git branch pack2 &&
+ git ${pack_refs} --include "refs/heads/pack*" --no-include &&
+ test -f .git/refs/heads/pack1 &&
+ test -f .git/refs/heads/pack2'
+
+test_expect_success 'test --exclude takes precedence over --include' '
+ git branch dont_pack5 &&
+ git ${pack_refs} --include "refs/heads/pack*" --exclude "refs/heads/pack*" &&
+ test -f .git/refs/heads/dont_pack5'
+
+test_expect_success 'see if up-to-date packed refs are preserved' '
+ git branch q &&
+ git ${pack_refs} --all --prune &&
+ git update-ref refs/heads/q refs/heads/q &&
+ ! test -f .git/refs/heads/q
+'
+
+test_expect_success 'pack, prune and repack' '
+ git tag foo &&
+ git ${pack_refs} --all --prune &&
+ git show-ref >all-of-them &&
+ git ${pack_refs} &&
+ git show-ref >again &&
+ test_cmp all-of-them again
+'
+
+test_expect_success 'explicit ${pack_refs} with dangling packed reference' '
+ git commit --allow-empty -m "soon to be garbage-collected" &&
+ git ${pack_refs} --all &&
+ git reset --hard HEAD^ &&
+ git reflog expire --expire=all --all &&
+ git prune --expire=all &&
+ git ${pack_refs} --all 2>result &&
+ test_must_be_empty result
+'
+
+test_expect_success 'delete ref with dangling packed version' '
+ git checkout -b lamb &&
+ git commit --allow-empty -m "future garbage" &&
+ git ${pack_refs} --all &&
+ git reset --hard HEAD^ &&
+ git checkout main &&
+ git reflog expire --expire=all --all &&
+ git prune --expire=all &&
+ git branch -d lamb 2>result &&
+ test_must_be_empty result
+'
+
+test_expect_success 'delete ref while another dangling packed ref' '
+ git branch lamb &&
+ git commit --allow-empty -m "future garbage" &&
+ git ${pack_refs} --all &&
+ git reset --hard HEAD^ &&
+ git reflog expire --expire=all --all &&
+ git prune --expire=all &&
+ git branch -d lamb 2>result &&
+ test_must_be_empty result
+'
+
+test_expect_success 'pack ref directly below refs/' '
+ git update-ref refs/top HEAD &&
+ git ${pack_refs} --all --prune &&
+ grep refs/top .git/packed-refs &&
+ test_path_is_missing .git/refs/top
+'
+
+test_expect_success 'do not pack ref in refs/bisect' '
+ git update-ref refs/bisect/local HEAD &&
+ git ${pack_refs} --all --prune &&
+ ! grep refs/bisect/local .git/packed-refs >/dev/null &&
+ test_path_is_file .git/refs/bisect/local
+'
+
+test_expect_success 'disable reflogs' '
+ git config core.logallrefupdates false &&
+ rm -rf .git/logs
+'
+
+test_expect_success 'create packed foo/bar/baz branch' '
+ git branch foo/bar/baz &&
+ git ${pack_refs} --all --prune &&
+ test_path_is_missing .git/refs/heads/foo/bar/baz &&
+ test_must_fail git reflog exists refs/heads/foo/bar/baz
+'
+
+test_expect_success 'notice d/f conflict with existing directory' '
+ test_must_fail git branch foo &&
+ test_must_fail git branch foo/bar
+'
+
+test_expect_success 'existing directory reports concrete ref' '
+ test_must_fail git branch foo 2>stderr &&
+ test_grep refs/heads/foo/bar/baz stderr
+'
+
+test_expect_success 'notice d/f conflict with existing ref' '
+ test_must_fail git branch foo/bar/baz/extra &&
+ test_must_fail git branch foo/bar/baz/lots/of/extra/components
+'
+
+test_expect_success 'reject packed-refs with unterminated line' '
+ cp .git/packed-refs .git/packed-refs.bak &&
+ test_when_finished "mv .git/packed-refs.bak .git/packed-refs" &&
+ printf "%s" "$HEAD refs/zzzzz" >>.git/packed-refs &&
+ echo "fatal: unterminated line in .git/packed-refs: $HEAD refs/zzzzz" >expected_err &&
+ test_must_fail git for-each-ref >out 2>err &&
+ test_cmp expected_err err
+'
+
+test_expect_success 'reject packed-refs containing junk' '
+ cp .git/packed-refs .git/packed-refs.bak &&
+ test_when_finished "mv .git/packed-refs.bak .git/packed-refs" &&
+ printf "%s\n" "bogus content" >>.git/packed-refs &&
+ echo "fatal: unexpected line in .git/packed-refs: bogus content" >expected_err &&
+ test_must_fail git for-each-ref >out 2>err &&
+ test_cmp expected_err err
+'
+
+test_expect_success 'reject packed-refs with a short SHA-1' '
+ cp .git/packed-refs .git/packed-refs.bak &&
+ test_when_finished "mv .git/packed-refs.bak .git/packed-refs" &&
+ printf "%.7s %s\n" $HEAD refs/zzzzz >>.git/packed-refs &&
+ printf "fatal: unexpected line in .git/packed-refs: %.7s %s\n" $HEAD refs/zzzzz >expected_err &&
+ test_must_fail git for-each-ref >out 2>err &&
+ test_cmp expected_err err
+'
+
+test_expect_success 'timeout if packed-refs.lock exists' '
+ LOCK=.git/packed-refs.lock &&
+ >"$LOCK" &&
+ test_when_finished "rm -f $LOCK" &&
+ test_must_fail git ${pack_refs} --all --prune
+'
+
+test_expect_success 'retry acquiring packed-refs.lock' '
+ LOCK=.git/packed-refs.lock &&
+ >"$LOCK" &&
+ test_when_finished "wait && rm -f $LOCK" &&
+ {
+ ( sleep 1 && rm -f $LOCK ) &
+ } &&
+ git -c core.packedrefstimeout=3000 ${pack_refs} --all --prune
+'
+
+test_expect_success SYMLINKS 'pack symlinked packed-refs' '
+ # First make sure that symlinking works when reading:
+ git update-ref refs/heads/lossy refs/heads/main &&
+ git for-each-ref >all-refs-before &&
+ mv .git/packed-refs .git/my-deviant-packed-refs &&
+ ln -s my-deviant-packed-refs .git/packed-refs &&
+ git for-each-ref >all-refs-linked &&
+ test_cmp all-refs-before all-refs-linked &&
+ git ${pack_refs} --all --prune &&
+ git for-each-ref >all-refs-packed &&
+ test_cmp all-refs-before all-refs-packed &&
+ test -h .git/packed-refs &&
+ test "$(test_readlink .git/packed-refs)" = "my-deviant-packed-refs"
+'
+
+# The 'packed-refs' file is stored directly in .git/. This means it is global
+# to the repository, and can only contain refs that are shared across all
+# worktrees.
+test_expect_success 'refs/worktree must not be packed' '
+ test_commit initial &&
+ test_commit wt1 &&
+ test_commit wt2 &&
+ git worktree add wt1 wt1 &&
+ git worktree add wt2 wt2 &&
+ git checkout initial &&
+ git update-ref refs/worktree/foo HEAD &&
+ git -C wt1 update-ref refs/worktree/foo HEAD &&
+ git -C wt2 update-ref refs/worktree/foo HEAD &&
+ git ${pack_refs} --all &&
+ test_path_is_missing .git/refs/tags/wt1 &&
+ test_path_is_file .git/refs/worktree/foo &&
+ test_path_is_file .git/worktrees/wt1/refs/worktree/foo &&
+ test_path_is_file .git/worktrees/wt2/refs/worktree/foo
+'
+
+# we do not want to count on running ${pack_refs} to
+# actually pack it, as it is perfectly reasonable to
+# skip processing a broken ref
+test_expect_success 'create packed-refs file with broken ref' '
+ test_tick && git commit --allow-empty -m one &&
+ recoverable=$(git rev-parse HEAD) &&
+ test_tick && git commit --allow-empty -m two &&
+ missing=$(git rev-parse HEAD) &&
+ rm -f .git/refs/heads/main &&
+ cat >.git/packed-refs <<-EOF &&
+ $missing refs/heads/main
+ $recoverable refs/heads/other
+ EOF
+ echo $missing >expect &&
+ git rev-parse refs/heads/main >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '${pack_refs} does not silently delete broken packed ref' '
+ git ${pack_refs} --all --prune &&
+ git rev-parse refs/heads/main >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '${pack_refs} does not drop broken refs during deletion' '
+ git update-ref -d refs/heads/other &&
+ git rev-parse refs/heads/main >actual &&
+ test_cmp expect actual
+'
+
+for command in "git ${pack_refs} --all --auto" "git maintenance run --task=${pack_refs} --auto"
+do
+ test_expect_success "$command does not repack below 16 refs without packed-refs" '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ git config set maintenance.auto false &&
+ git commit --allow-empty --message "initial" &&
+
+ # Create 14 additional references, which brings us to
+ # 15 together with the default branch.
+ printf "create refs/heads/loose-%d HEAD\n" $(test_seq 14) >stdin &&
+ git update-ref --stdin <stdin &&
+ test_path_is_missing .git/packed-refs &&
+ git ${pack_refs} --auto --all &&
+ test_path_is_missing .git/packed-refs &&
+
+ # Create the 16th reference, which should cause us to repack.
+ git update-ref refs/heads/loose-15 HEAD &&
+ git ${pack_refs} --auto --all &&
+ test_path_is_file .git/packed-refs
+ )
+ '
+
+ test_expect_success "$command does not repack below 16 refs with small packed-refs" '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ git config set maintenance.auto false &&
+ git commit --allow-empty --message "initial" &&
+
+ git ${pack_refs} --all &&
+ test_line_count = 2 .git/packed-refs &&
+
+ # Create 15 loose references.
+ printf "create refs/heads/loose-%d HEAD\n" $(test_seq 15) >stdin &&
+ git update-ref --stdin <stdin &&
+ git ${pack_refs} --auto --all &&
+ test_line_count = 2 .git/packed-refs &&
+
+ # Create the 16th loose reference, which should cause us to repack.
+ git update-ref refs/heads/loose-17 HEAD &&
+ git ${pack_refs} --auto --all &&
+ test_line_count = 18 .git/packed-refs
+ )
+ '
+
+ test_expect_success "$command scales with size of packed-refs" '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ git config set maintenance.auto false &&
+ git commit --allow-empty --message "initial" &&
+
+ # Create 99 packed refs. This should cause the heuristic
+ # to require more than the minimum amount of loose refs.
+ test_seq 99 |
+ while read i
+ do
+ printf "create refs/heads/packed-%d HEAD\n" $i || return 1
+ done >stdin &&
+ git update-ref --stdin <stdin &&
+ git ${pack_refs} --all &&
+ test_line_count = 101 .git/packed-refs &&
+
+ # Create 24 loose refs, which should not yet cause us to repack.
+ printf "create refs/heads/loose-%d HEAD\n" $(test_seq 24) >stdin &&
+ git update-ref --stdin <stdin &&
+ git ${pack_refs} --auto --all &&
+ test_line_count = 101 .git/packed-refs &&
+
+ # Create another handful of refs to cross the border.
+ # Note that we explicitly do not check for strict
+ # boundaries here, as this also depends on the size of
+ # the object hash.
+ printf "create refs/heads/addn-%d HEAD\n" $(test_seq 10) >stdin &&
+ git update-ref --stdin <stdin &&
+ git ${pack_refs} --auto --all &&
+ test_line_count = 135 .git/packed-refs
+ )
+ '
+done
+
+test_done
diff --git a/t/t0601-reffiles-pack-refs.sh b/t/t0601-reffiles-pack-refs.sh
index aa7f6ecd81..12cf5d1dcb 100755
--- a/t/t0601-reffiles-pack-refs.sh
+++ b/t/t0601-reffiles-pack-refs.sh
@@ -17,432 +17,4 @@ export GIT_TEST_DEFAULT_REF_FORMAT
. ./test-lib.sh
-test_expect_success 'enable reflogs' '
- git config core.logallrefupdates true
-'
-
-test_expect_success 'prepare a trivial repository' '
- echo Hello > A &&
- git update-index --add A &&
- git commit -m "Initial commit." &&
- HEAD=$(git rev-parse --verify HEAD)
-'
-
-test_expect_success 'pack-refs --prune --all' '
- test_path_is_missing .git/packed-refs &&
- git pack-refs --no-prune --all &&
- test_path_is_file .git/packed-refs &&
- N=$(find .git/refs -type f | wc -l) &&
- test "$N" != 0 &&
-
- git pack-refs --prune --all &&
- test_path_is_file .git/packed-refs &&
- N=$(find .git/refs -type f) &&
- test -z "$N"
-'
-
-SHA1=
-
-test_expect_success 'see if git show-ref works as expected' '
- git branch a &&
- SHA1=$(cat .git/refs/heads/a) &&
- echo "$SHA1 refs/heads/a" >expect &&
- git show-ref a >result &&
- test_cmp expect result
-'
-
-test_expect_success 'see if a branch still exists when packed' '
- git branch b &&
- git pack-refs --all &&
- rm -f .git/refs/heads/b &&
- echo "$SHA1 refs/heads/b" >expect &&
- git show-ref b >result &&
- test_cmp expect result
-'
-
-test_expect_success 'git branch c/d should barf if branch c exists' '
- git branch c &&
- git pack-refs --all &&
- rm -f .git/refs/heads/c &&
- test_must_fail git branch c/d
-'
-
-test_expect_success 'see if a branch still exists after git pack-refs --prune' '
- git branch e &&
- git pack-refs --all --prune &&
- echo "$SHA1 refs/heads/e" >expect &&
- git show-ref e >result &&
- test_cmp expect result
-'
-
-test_expect_success 'see if git pack-refs --prune remove ref files' '
- git branch f &&
- git pack-refs --all --prune &&
- ! test -f .git/refs/heads/f
-'
-
-test_expect_success 'see if git pack-refs --prune removes empty dirs' '
- git branch r/s/t &&
- git pack-refs --all --prune &&
- ! test -e .git/refs/heads/r
-'
-
-test_expect_success 'git branch g should work when git branch g/h has been deleted' '
- git branch g/h &&
- git pack-refs --all --prune &&
- git branch -d g/h &&
- git branch g &&
- git pack-refs --all &&
- git branch -d g
-'
-
-test_expect_success 'git branch i/j/k should barf if branch i exists' '
- git branch i &&
- git pack-refs --all --prune &&
- test_must_fail git branch i/j/k
-'
-
-test_expect_success 'test git branch k after branch k/l/m and k/lm have been deleted' '
- git branch k/l &&
- git branch k/lm &&
- git branch -d k/l &&
- git branch k/l/m &&
- git branch -d k/l/m &&
- git branch -d k/lm &&
- git branch k
-'
-
-test_expect_success 'test git branch n after some branch deletion and pruning' '
- git branch n/o &&
- git branch n/op &&
- git branch -d n/o &&
- git branch n/o/p &&
- git branch -d n/op &&
- git pack-refs --all --prune &&
- git branch -d n/o/p &&
- git branch n
-'
-
-test_expect_success 'test excluded refs are not packed' '
- git branch dont_pack1 &&
- git branch dont_pack2 &&
- git branch pack_this &&
- git pack-refs --all --exclude "refs/heads/dont_pack*" &&
- test -f .git/refs/heads/dont_pack1 &&
- test -f .git/refs/heads/dont_pack2 &&
- ! test -f .git/refs/heads/pack_this'
-
-test_expect_success 'test --no-exclude refs clears excluded refs' '
- git branch dont_pack3 &&
- git branch dont_pack4 &&
- git pack-refs --all --exclude "refs/heads/dont_pack*" --no-exclude &&
- ! test -f .git/refs/heads/dont_pack3 &&
- ! test -f .git/refs/heads/dont_pack4'
-
-test_expect_success 'test only included refs are packed' '
- git branch pack_this1 &&
- git branch pack_this2 &&
- git tag dont_pack5 &&
- git pack-refs --include "refs/heads/pack_this*" &&
- test -f .git/refs/tags/dont_pack5 &&
- ! test -f .git/refs/heads/pack_this1 &&
- ! test -f .git/refs/heads/pack_this2'
-
-test_expect_success 'test --no-include refs clears included refs' '
- git branch pack1 &&
- git branch pack2 &&
- git pack-refs --include "refs/heads/pack*" --no-include &&
- test -f .git/refs/heads/pack1 &&
- test -f .git/refs/heads/pack2'
-
-test_expect_success 'test --exclude takes precedence over --include' '
- git branch dont_pack5 &&
- git pack-refs --include "refs/heads/pack*" --exclude "refs/heads/pack*" &&
- test -f .git/refs/heads/dont_pack5'
-
-test_expect_success 'see if up-to-date packed refs are preserved' '
- git branch q &&
- git pack-refs --all --prune &&
- git update-ref refs/heads/q refs/heads/q &&
- ! test -f .git/refs/heads/q
-'
-
-test_expect_success 'pack, prune and repack' '
- git tag foo &&
- git pack-refs --all --prune &&
- git show-ref >all-of-them &&
- git pack-refs &&
- git show-ref >again &&
- test_cmp all-of-them again
-'
-
-test_expect_success 'explicit pack-refs with dangling packed reference' '
- git commit --allow-empty -m "soon to be garbage-collected" &&
- git pack-refs --all &&
- git reset --hard HEAD^ &&
- git reflog expire --expire=all --all &&
- git prune --expire=all &&
- git pack-refs --all 2>result &&
- test_must_be_empty result
-'
-
-test_expect_success 'delete ref with dangling packed version' '
- git checkout -b lamb &&
- git commit --allow-empty -m "future garbage" &&
- git pack-refs --all &&
- git reset --hard HEAD^ &&
- git checkout main &&
- git reflog expire --expire=all --all &&
- git prune --expire=all &&
- git branch -d lamb 2>result &&
- test_must_be_empty result
-'
-
-test_expect_success 'delete ref while another dangling packed ref' '
- git branch lamb &&
- git commit --allow-empty -m "future garbage" &&
- git pack-refs --all &&
- git reset --hard HEAD^ &&
- git reflog expire --expire=all --all &&
- git prune --expire=all &&
- git branch -d lamb 2>result &&
- test_must_be_empty result
-'
-
-test_expect_success 'pack ref directly below refs/' '
- git update-ref refs/top HEAD &&
- git pack-refs --all --prune &&
- grep refs/top .git/packed-refs &&
- test_path_is_missing .git/refs/top
-'
-
-test_expect_success 'do not pack ref in refs/bisect' '
- git update-ref refs/bisect/local HEAD &&
- git pack-refs --all --prune &&
- ! grep refs/bisect/local .git/packed-refs >/dev/null &&
- test_path_is_file .git/refs/bisect/local
-'
-
-test_expect_success 'disable reflogs' '
- git config core.logallrefupdates false &&
- rm -rf .git/logs
-'
-
-test_expect_success 'create packed foo/bar/baz branch' '
- git branch foo/bar/baz &&
- git pack-refs --all --prune &&
- test_path_is_missing .git/refs/heads/foo/bar/baz &&
- test_must_fail git reflog exists refs/heads/foo/bar/baz
-'
-
-test_expect_success 'notice d/f conflict with existing directory' '
- test_must_fail git branch foo &&
- test_must_fail git branch foo/bar
-'
-
-test_expect_success 'existing directory reports concrete ref' '
- test_must_fail git branch foo 2>stderr &&
- test_grep refs/heads/foo/bar/baz stderr
-'
-
-test_expect_success 'notice d/f conflict with existing ref' '
- test_must_fail git branch foo/bar/baz/extra &&
- test_must_fail git branch foo/bar/baz/lots/of/extra/components
-'
-
-test_expect_success 'reject packed-refs with unterminated line' '
- cp .git/packed-refs .git/packed-refs.bak &&
- test_when_finished "mv .git/packed-refs.bak .git/packed-refs" &&
- printf "%s" "$HEAD refs/zzzzz" >>.git/packed-refs &&
- echo "fatal: unterminated line in .git/packed-refs: $HEAD refs/zzzzz" >expected_err &&
- test_must_fail git for-each-ref >out 2>err &&
- test_cmp expected_err err
-'
-
-test_expect_success 'reject packed-refs containing junk' '
- cp .git/packed-refs .git/packed-refs.bak &&
- test_when_finished "mv .git/packed-refs.bak .git/packed-refs" &&
- printf "%s\n" "bogus content" >>.git/packed-refs &&
- echo "fatal: unexpected line in .git/packed-refs: bogus content" >expected_err &&
- test_must_fail git for-each-ref >out 2>err &&
- test_cmp expected_err err
-'
-
-test_expect_success 'reject packed-refs with a short SHA-1' '
- cp .git/packed-refs .git/packed-refs.bak &&
- test_when_finished "mv .git/packed-refs.bak .git/packed-refs" &&
- printf "%.7s %s\n" $HEAD refs/zzzzz >>.git/packed-refs &&
- printf "fatal: unexpected line in .git/packed-refs: %.7s %s\n" $HEAD refs/zzzzz >expected_err &&
- test_must_fail git for-each-ref >out 2>err &&
- test_cmp expected_err err
-'
-
-test_expect_success 'timeout if packed-refs.lock exists' '
- LOCK=.git/packed-refs.lock &&
- >"$LOCK" &&
- test_when_finished "rm -f $LOCK" &&
- test_must_fail git pack-refs --all --prune
-'
-
-test_expect_success 'retry acquiring packed-refs.lock' '
- LOCK=.git/packed-refs.lock &&
- >"$LOCK" &&
- test_when_finished "wait && rm -f $LOCK" &&
- {
- ( sleep 1 && rm -f $LOCK ) &
- } &&
- git -c core.packedrefstimeout=3000 pack-refs --all --prune
-'
-
-test_expect_success SYMLINKS 'pack symlinked packed-refs' '
- # First make sure that symlinking works when reading:
- git update-ref refs/heads/lossy refs/heads/main &&
- git for-each-ref >all-refs-before &&
- mv .git/packed-refs .git/my-deviant-packed-refs &&
- ln -s my-deviant-packed-refs .git/packed-refs &&
- git for-each-ref >all-refs-linked &&
- test_cmp all-refs-before all-refs-linked &&
- git pack-refs --all --prune &&
- git for-each-ref >all-refs-packed &&
- test_cmp all-refs-before all-refs-packed &&
- test -h .git/packed-refs &&
- test "$(test_readlink .git/packed-refs)" = "my-deviant-packed-refs"
-'
-
-# The 'packed-refs' file is stored directly in .git/. This means it is global
-# to the repository, and can only contain refs that are shared across all
-# worktrees.
-test_expect_success 'refs/worktree must not be packed' '
- test_commit initial &&
- test_commit wt1 &&
- test_commit wt2 &&
- git worktree add wt1 wt1 &&
- git worktree add wt2 wt2 &&
- git checkout initial &&
- git update-ref refs/worktree/foo HEAD &&
- git -C wt1 update-ref refs/worktree/foo HEAD &&
- git -C wt2 update-ref refs/worktree/foo HEAD &&
- git pack-refs --all &&
- test_path_is_missing .git/refs/tags/wt1 &&
- test_path_is_file .git/refs/worktree/foo &&
- test_path_is_file .git/worktrees/wt1/refs/worktree/foo &&
- test_path_is_file .git/worktrees/wt2/refs/worktree/foo
-'
-
-# we do not want to count on running pack-refs to
-# actually pack it, as it is perfectly reasonable to
-# skip processing a broken ref
-test_expect_success 'create packed-refs file with broken ref' '
- test_tick && git commit --allow-empty -m one &&
- recoverable=$(git rev-parse HEAD) &&
- test_tick && git commit --allow-empty -m two &&
- missing=$(git rev-parse HEAD) &&
- rm -f .git/refs/heads/main &&
- cat >.git/packed-refs <<-EOF &&
- $missing refs/heads/main
- $recoverable refs/heads/other
- EOF
- echo $missing >expect &&
- git rev-parse refs/heads/main >actual &&
- test_cmp expect actual
-'
-
-test_expect_success 'pack-refs does not silently delete broken packed ref' '
- git pack-refs --all --prune &&
- git rev-parse refs/heads/main >actual &&
- test_cmp expect actual
-'
-
-test_expect_success 'pack-refs does not drop broken refs during deletion' '
- git update-ref -d refs/heads/other &&
- git rev-parse refs/heads/main >actual &&
- test_cmp expect actual
-'
-
-for command in "git pack-refs --all --auto" "git maintenance run --task=pack-refs --auto"
-do
- test_expect_success "$command does not repack below 16 refs without packed-refs" '
- test_when_finished "rm -rf repo" &&
- git init repo &&
- (
- cd repo &&
- git config set maintenance.auto false &&
- git commit --allow-empty --message "initial" &&
-
- # Create 14 additional references, which brings us to
- # 15 together with the default branch.
- printf "create refs/heads/loose-%d HEAD\n" $(test_seq 14) >stdin &&
- git update-ref --stdin <stdin &&
- test_path_is_missing .git/packed-refs &&
- git pack-refs --auto --all &&
- test_path_is_missing .git/packed-refs &&
-
- # Create the 16th reference, which should cause us to repack.
- git update-ref refs/heads/loose-15 HEAD &&
- git pack-refs --auto --all &&
- test_path_is_file .git/packed-refs
- )
- '
-
- test_expect_success "$command does not repack below 16 refs with small packed-refs" '
- test_when_finished "rm -rf repo" &&
- git init repo &&
- (
- cd repo &&
- git config set maintenance.auto false &&
- git commit --allow-empty --message "initial" &&
-
- git pack-refs --all &&
- test_line_count = 2 .git/packed-refs &&
-
- # Create 15 loose references.
- printf "create refs/heads/loose-%d HEAD\n" $(test_seq 15) >stdin &&
- git update-ref --stdin <stdin &&
- git pack-refs --auto --all &&
- test_line_count = 2 .git/packed-refs &&
-
- # Create the 16th loose reference, which should cause us to repack.
- git update-ref refs/heads/loose-17 HEAD &&
- git pack-refs --auto --all &&
- test_line_count = 18 .git/packed-refs
- )
- '
-
- test_expect_success "$command scales with size of packed-refs" '
- test_when_finished "rm -rf repo" &&
- git init repo &&
- (
- cd repo &&
- git config set maintenance.auto false &&
- git commit --allow-empty --message "initial" &&
-
- # Create 99 packed refs. This should cause the heuristic
- # to require more than the minimum amount of loose refs.
- test_seq 99 |
- while read i
- do
- printf "create refs/heads/packed-%d HEAD\n" $i || return 1
- done >stdin &&
- git update-ref --stdin <stdin &&
- git pack-refs --all &&
- test_line_count = 101 .git/packed-refs &&
-
- # Create 24 loose refs, which should not yet cause us to repack.
- printf "create refs/heads/loose-%d HEAD\n" $(test_seq 24) >stdin &&
- git update-ref --stdin <stdin &&
- git pack-refs --auto --all &&
- test_line_count = 101 .git/packed-refs &&
-
- # Create another handful of refs to cross the border.
- # Note that we explicitly do not check for strict
- # boundaries here, as this also depends on the size of
- # the object hash.
- printf "create refs/heads/addn-%d HEAD\n" $(test_seq 10) >stdin &&
- git update-ref --stdin <stdin &&
- git pack-refs --auto --all &&
- test_line_count = 135 .git/packed-refs
- )
- '
-done
-
-test_done
+. "$TEST_DIRECTORY"/pack-refs-tests.sh
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [GSoC][PATCH 5/5] t: add test for git refs optimize subcommand
2025-08-26 7:36 [GSoC][PATCH 0/5] Add refs optimize subcommand Meet Soni
` (3 preceding siblings ...)
2025-08-26 7:36 ` [GSoC][PATCH 4/5] t0601: refactor tests to be shareable Meet Soni
@ 2025-08-26 7:36 ` Meet Soni
2025-08-26 15:18 ` shejialuo
2025-09-02 10:18 ` Patrick Steinhardt
4 siblings, 2 replies; 17+ messages in thread
From: Meet Soni @ 2025-08-26 7:36 UTC (permalink / raw)
To: git; +Cc: ps, shejialuo, Meet Soni
Add a test script, `t/t1463-refs-optimize.sh`, for the new `git refs
optimize` command.
This script acts as a simple driver, leveraging the shared test library
created in the preceding commit. It works by overriding the
`$pack_refs` variable to "refs optimize" and then sourcing the
shared library (`t/pack-refs-tests.sh`).
This approach ensures that `git refs optimize` is tested against the
entire comprehensive test suite of `git pack-refs`, verifying
that it acts as a compatible drop-in replacement.
Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
---
t/meson.build | 3 ++-
t/t1463-refs-optimize.sh | 17 +++++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
create mode 100755 t/t1463-refs-optimize.sh
diff --git a/t/meson.build b/t/meson.build
index daf01fb5d0..48f83e12a7 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -210,6 +210,7 @@ integration_tests = [
't1451-fsck-buffer.sh',
't1460-refs-migrate.sh',
't1461-refs-list.sh',
+ 't1463-refs-optimize.sh',
't1500-rev-parse.sh',
't1501-work-tree.sh',
't1502-rev-parse-parseopt.sh',
@@ -1216,4 +1217,4 @@ if perl.found() and time.found()
timeout: 0,
)
endforeach
-endif
\ No newline at end of file
+endif
diff --git a/t/t1463-refs-optimize.sh b/t/t1463-refs-optimize.sh
new file mode 100755
index 0000000000..c11c905d79
--- /dev/null
+++ b/t/t1463-refs-optimize.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+test_description='git refs optimize should not change the branch semantic
+
+This test runs git refs optimize and git show-ref and checks that the branch
+semantic is still the same.
+'
+
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+GIT_TEST_DEFAULT_REF_FORMAT=files
+export GIT_TEST_DEFAULT_REF_FORMAT
+
+. ./test-lib.sh
+
+pack_refs='refs optimize'
+. "$TEST_DIRECTORY"/pack-refs-tests.sh
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [GSoC][PATCH 5/5] t: add test for git refs optimize subcommand
2025-08-26 7:36 ` [GSoC][PATCH 5/5] t: add test for git refs optimize subcommand Meet Soni
@ 2025-08-26 15:18 ` shejialuo
2025-08-31 6:20 ` Meet Soni
2025-09-02 10:18 ` Patrick Steinhardt
1 sibling, 1 reply; 17+ messages in thread
From: shejialuo @ 2025-08-26 15:18 UTC (permalink / raw)
To: Meet Soni; +Cc: git, ps
On Tue, Aug 26, 2025 at 01:06:45PM +0530, Meet Soni wrote:
> diff --git a/t/t1463-refs-optimize.sh b/t/t1463-refs-optimize.sh
> new file mode 100755
> index 0000000000..c11c905d79
> --- /dev/null
> +++ b/t/t1463-refs-optimize.sh
> @@ -0,0 +1,17 @@
> +#!/bin/sh
> +
> +test_description='git refs optimize should not change the branch semantic
> +
> +This test runs git refs optimize and git show-ref and checks that the branch
> +semantic is still the same.
> +'
When reading the description, I am wondering how this test runs `git
refs optimize` and `git show-ref` to achieve the goal. Should we simply
just say we use "pack-refs-tests.sh" to ensure the compatibility with
the `git pack-refs`?
> +
> +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
> +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
> +GIT_TEST_DEFAULT_REF_FORMAT=files
> +export GIT_TEST_DEFAULT_REF_FORMAT
> +
> +. ./test-lib.sh
> +
> +pack_refs='refs optimize'
> +. "$TEST_DIRECTORY"/pack-refs-tests.sh
> --
> 2.34.1
>
Thanks,
Jialuo
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [GSoC][PATCH 5/5] t: add test for git refs optimize subcommand
2025-08-26 15:18 ` shejialuo
@ 2025-08-31 6:20 ` Meet Soni
0 siblings, 0 replies; 17+ messages in thread
From: Meet Soni @ 2025-08-31 6:20 UTC (permalink / raw)
To: shejialuo; +Cc: git, ps
Thanks for the review, and apologies for missing your email earlier, I just saw
your comments today.
On Tue, 26 Aug 2025 at 20:48, shejialuo <shejialuo@gmail.com> wrote:
>
> On Tue, Aug 26, 2025 at 01:06:45PM +0530, Meet Soni wrote:
>
> > diff --git a/t/t1463-refs-optimize.sh b/t/t1463-refs-optimize.sh
> > new file mode 100755
> > index 0000000000..c11c905d79
> > --- /dev/null
> > +++ b/t/t1463-refs-optimize.sh
> > @@ -0,0 +1,17 @@
> > +#!/bin/sh
> > +
> > +test_description='git refs optimize should not change the branch semantic
> > +
> > +This test runs git refs optimize and git show-ref and checks that the branch
> > +semantic is still the same.
> > +'
>
> When reading the description, I am wondering how this test runs `git
> refs optimize` and `git show-ref` to achieve the goal. Should we simply
> just say we use "pack-refs-tests.sh" to ensure the compatibility with
> the `git pack-refs`?
>
You're right that the current description is too tied to implementation details
(git show-ref). The intent of this test is to ensure that git refs optimize
does not change branch semantics, similar to the existing pack-refs tests.
I'll update the description to focus on the behavior being verified, not the
specific commands used.
> > +
> > +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
> > +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
> > +GIT_TEST_DEFAULT_REF_FORMAT=files
> > +export GIT_TEST_DEFAULT_REF_FORMAT
> > +
> > +. ./test-lib.sh
> > +
> > +pack_refs='refs optimize'
> > +. "$TEST_DIRECTORY"/pack-refs-tests.sh
> > --
> > 2.34.1
> >
>
> Thanks,
> Jialuo
Thanks,
Meet
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [GSoC][PATCH 1/5] builtin/pack-refs: factor out core logic into a helper
2025-08-26 7:36 ` [GSoC][PATCH 1/5] builtin/pack-refs: factor out core logic into a helper Meet Soni
@ 2025-09-02 10:18 ` Patrick Steinhardt
2025-09-03 3:56 ` Meet Soni
2025-09-03 5:25 ` Junio C Hamano
0 siblings, 2 replies; 17+ messages in thread
From: Patrick Steinhardt @ 2025-09-02 10:18 UTC (permalink / raw)
To: Meet Soni; +Cc: git, shejialuo
On Tue, Aug 26, 2025 at 01:06:41PM +0530, Meet Soni wrote:
> 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.
>
> Introduce a new `pack-refs.h` header to define the public interface
> for this shared logic. It contains the declaration for a new helper
> function, `pack_refs_core()`, and a macro for the common usage
> options.
>
> Move the option parsing and packing logic from `cmd_pack_refs()` into a
> new helper function named `pack_refs_core()`. This helper is made
> generic by accepting the command's usage string as a parameter.
>
> The original `cmd_pack_refs()` is simplified to a thin wrapper that
> is only responsible for defining its specific usage array and calling
> the shared helper.
>
> Mentored-by: Patrick Steinhardt <ps@pks.im>
> Mentored-by: shejialuo <shejialuo@gmail.com>
> Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
> ---
> builtin/pack-refs.c | 31 ++++++++++++++++++++-----------
> pack-refs.h | 22 ++++++++++++++++++++++
> 2 files changed, 42 insertions(+), 11 deletions(-)
> create mode 100644 pack-refs.h
Shouldn't that header live in "builtin/pack-refs.h"? Makes it way more
obvious that it exposes functions from "builtin/pack-refs.c".
> diff --git a/pack-refs.h b/pack-refs.h
> new file mode 100644
> index 0000000000..ba51d154e3
> --- /dev/null
> +++ b/pack-refs.h
> @@ -0,0 +1,22 @@
> +#ifndef PACK_REFS_H
> +#define PACK_REFS_H
> +
> +struct repository;
Let's add a newline here.
> +/*
> + * 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 \
> + "[--all] [--no-prune] [--auto] [--include <pattern>] [--exclude <pattern>]"
> +
> +/*
> + * The core logic for pack-refs and its clones
And a dot after to terminate the sentence.
> + */
> +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
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [GSoC][PATCH 3/5] builtin/refs: add optimize subcommand
2025-08-26 7:36 ` [GSoC][PATCH 3/5] builtin/refs: add optimize subcommand Meet Soni
@ 2025-09-02 10:18 ` Patrick Steinhardt
0 siblings, 0 replies; 17+ messages in thread
From: Patrick Steinhardt @ 2025-09-02 10:18 UTC (permalink / raw)
To: Meet Soni; +Cc: git, shejialuo
On Tue, Aug 26, 2025 at 01:06:43PM +0530, Meet Soni wrote:
> diff --git a/Documentation/git-refs.adoc b/Documentation/git-refs.adoc
> index e608980711..121a2fbeff 100644
> --- a/Documentation/git-refs.adoc
> +++ b/Documentation/git-refs.adoc
> @@ -18,6 +18,7 @@ git refs list [--count=<count>] [--shell|--perl|--python|--tcl]
> [--contains[=<object>]] [--no-contains[=<object>]]
> [(--exclude=<pattern>)...] [--start-after=<marker>]
> [ --stdin | <pattern>... ]
> +git refs optimize [--all] [--no-prune] [--auto] [--include <pattern>] [--exclude <pattern>]
>
> DESCRIPTION
> -----------
> @@ -38,6 +39,11 @@ list::
> formatting, and sorting. This subcommand is an alias for
> linkgit:git-for-each-ref[1] and offers identical functionality.
>
> +optimize::
> + Pack references into a single file to improve repository performance
> + and reduce storage usage. This subcommand is an alias for
> + linkgit:git-pack-refs[1] and offers identical functionality.
This feels way too specific to the "files" backend. We do pack
references there, but with the "reftable" backend we don't. Furthermore,
there is no guarantee that we'll only have a single file after
optimizing the store with either of the backends.
So this should be rephrased to become agnostic of the actual backend
that is in use. Maybe just say something like "Optimizes references to
improve repository performance and reduce disk usage."
Patrick
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [GSoC][PATCH 5/5] t: add test for git refs optimize subcommand
2025-08-26 7:36 ` [GSoC][PATCH 5/5] t: add test for git refs optimize subcommand Meet Soni
2025-08-26 15:18 ` shejialuo
@ 2025-09-02 10:18 ` Patrick Steinhardt
2025-09-03 3:58 ` Meet Soni
1 sibling, 1 reply; 17+ messages in thread
From: Patrick Steinhardt @ 2025-09-02 10:18 UTC (permalink / raw)
To: Meet Soni; +Cc: git, shejialuo
On Tue, Aug 26, 2025 at 01:06:45PM +0530, Meet Soni wrote:
> diff --git a/t/meson.build b/t/meson.build
> index daf01fb5d0..48f83e12a7 100644
> --- a/t/meson.build
> +++ b/t/meson.build
> @@ -210,6 +210,7 @@ integration_tests = [
> 't1451-fsck-buffer.sh',
> 't1460-refs-migrate.sh',
> 't1461-refs-list.sh',
> + 't1463-refs-optimize.sh',
What happened to t1462? Is this due to the parallel patch series that
introduces `git refs exists`?
Patrick
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [GSoC][PATCH 1/5] builtin/pack-refs: factor out core logic into a helper
2025-09-02 10:18 ` Patrick Steinhardt
@ 2025-09-03 3:56 ` Meet Soni
2025-09-03 4:37 ` Patrick Steinhardt
2025-09-03 5:25 ` Junio C Hamano
1 sibling, 1 reply; 17+ messages in thread
From: Meet Soni @ 2025-09-03 3:56 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git, shejialuo
On Tue, 2 Sept 2025 at 15:48, Patrick Steinhardt <ps@pks.im> wrote:
>
> On Tue, Aug 26, 2025 at 01:06:41PM +0530, Meet Soni wrote:
> > 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.
> >
> > Introduce a new `pack-refs.h` header to define the public interface
> > for this shared logic. It contains the declaration for a new helper
> > function, `pack_refs_core()`, and a macro for the common usage
> > options.
> >
> > Move the option parsing and packing logic from `cmd_pack_refs()` into a
> > new helper function named `pack_refs_core()`. This helper is made
> > generic by accepting the command's usage string as a parameter.
> >
> > The original `cmd_pack_refs()` is simplified to a thin wrapper that
> > is only responsible for defining its specific usage array and calling
> > the shared helper.
> >
> > Mentored-by: Patrick Steinhardt <ps@pks.im>
> > Mentored-by: shejialuo <shejialuo@gmail.com>
> > Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
> > ---
> > builtin/pack-refs.c | 31 ++++++++++++++++++++-----------
> > pack-refs.h | 22 ++++++++++++++++++++++
> > 2 files changed, 42 insertions(+), 11 deletions(-)
> > create mode 100644 pack-refs.h
>
> Shouldn't that header live in "builtin/pack-refs.h"? Makes it way more
> obvious that it exposes functions from "builtin/pack-refs.c".
>
I couldn't find any header files in the builtin/ directory. Also, since we
placed the for-each-ref.h file in the root directory in our previous series, I
decided to do the same here.
> > diff --git a/pack-refs.h b/pack-refs.h
> > new file mode 100644
> > index 0000000000..ba51d154e3
> > --- /dev/null
> > +++ b/pack-refs.h
> > @@ -0,0 +1,22 @@
> > +#ifndef PACK_REFS_H
> > +#define PACK_REFS_H
> > +
> > +struct repository;
>
> Let's add a newline here.
>
> > +/*
> > + * 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 \
> > + "[--all] [--no-prune] [--auto] [--include <pattern>] [--exclude <pattern>]"
> > +
> > +/*
> > + * The core logic for pack-refs and its clones
>
> And a dot after to terminate the sentence.
>
> > + */
> > +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
Thanks
Meet
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [GSoC][PATCH 5/5] t: add test for git refs optimize subcommand
2025-09-02 10:18 ` Patrick Steinhardt
@ 2025-09-03 3:58 ` Meet Soni
0 siblings, 0 replies; 17+ messages in thread
From: Meet Soni @ 2025-09-03 3:58 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git, shejialuo
On Tue, 2 Sept 2025 at 15:48, Patrick Steinhardt <ps@pks.im> wrote:
>
> On Tue, Aug 26, 2025 at 01:06:45PM +0530, Meet Soni wrote:
> > diff --git a/t/meson.build b/t/meson.build
> > index daf01fb5d0..48f83e12a7 100644
> > --- a/t/meson.build
> > +++ b/t/meson.build
> > @@ -210,6 +210,7 @@ integration_tests = [
> > 't1451-fsck-buffer.sh',
> > 't1460-refs-migrate.sh',
> > 't1461-refs-list.sh',
> > + 't1463-refs-optimize.sh',
>
> What happened to t1462? Is this due to the parallel patch series that
> introduces `git refs exists`?
Yes, t1462-refs-exists.sh
>
> Patrick
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [GSoC][PATCH 1/5] builtin/pack-refs: factor out core logic into a helper
2025-09-03 3:56 ` Meet Soni
@ 2025-09-03 4:37 ` Patrick Steinhardt
0 siblings, 0 replies; 17+ messages in thread
From: Patrick Steinhardt @ 2025-09-03 4:37 UTC (permalink / raw)
To: Meet Soni; +Cc: git, shejialuo
On Wed, Sep 03, 2025 at 09:26:37AM +0530, Meet Soni wrote:
> On Tue, 2 Sept 2025 at 15:48, Patrick Steinhardt <ps@pks.im> wrote:
> >
> > On Tue, Aug 26, 2025 at 01:06:41PM +0530, Meet Soni wrote:
> > > 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.
> > >
> > > Introduce a new `pack-refs.h` header to define the public interface
> > > for this shared logic. It contains the declaration for a new helper
> > > function, `pack_refs_core()`, and a macro for the common usage
> > > options.
> > >
> > > Move the option parsing and packing logic from `cmd_pack_refs()` into a
> > > new helper function named `pack_refs_core()`. This helper is made
> > > generic by accepting the command's usage string as a parameter.
> > >
> > > The original `cmd_pack_refs()` is simplified to a thin wrapper that
> > > is only responsible for defining its specific usage array and calling
> > > the shared helper.
> > >
> > > Mentored-by: Patrick Steinhardt <ps@pks.im>
> > > Mentored-by: shejialuo <shejialuo@gmail.com>
> > > Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
> > > ---
> > > builtin/pack-refs.c | 31 ++++++++++++++++++++-----------
> > > pack-refs.h | 22 ++++++++++++++++++++++
> > > 2 files changed, 42 insertions(+), 11 deletions(-)
> > > create mode 100644 pack-refs.h
> >
> > Shouldn't that header live in "builtin/pack-refs.h"? Makes it way more
> > obvious that it exposes functions from "builtin/pack-refs.c".
>
> I couldn't find any header files in the builtin/ directory. Also, since we
> placed the for-each-ref.h file in the root directory in our previous series, I
> decided to do the same here.
Hm. Honestly, I'd much rather also move "for-each-ref.h" into
"builtin/", as well. The logic is not part of libgit.a and specific to
the builtins, so I think it's preferable to have it in that directory.
Patrick
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [GSoC][PATCH 1/5] builtin/pack-refs: factor out core logic into a helper
2025-09-02 10:18 ` Patrick Steinhardt
2025-09-03 3:56 ` Meet Soni
@ 2025-09-03 5:25 ` Junio C Hamano
2025-09-03 6:00 ` Patrick Steinhardt
1 sibling, 1 reply; 17+ messages in thread
From: Junio C Hamano @ 2025-09-03 5:25 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Meet Soni, git, shejialuo
Patrick Steinhardt <ps@pks.im> writes:
>> builtin/pack-refs.c | 31 ++++++++++++++++++++-----------
>> pack-refs.h | 22 ++++++++++++++++++++++
>> 2 files changed, 42 insertions(+), 11 deletions(-)
>> create mode 100644 pack-refs.h
>
> Shouldn't that header live in "builtin/pack-refs.h"? Makes it way more
> obvious that it exposes functions from "builtin/pack-refs.c".
There shouldn't be any *.h files in builtin/. since the top-level
is where the library-ish reusable things live, so that they can
eventually be used by more than one *.c files in builtin/ and also
by other *.c files outside builtin.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [GSoC][PATCH 1/5] builtin/pack-refs: factor out core logic into a helper
2025-09-03 5:25 ` Junio C Hamano
@ 2025-09-03 6:00 ` Patrick Steinhardt
2025-09-03 18:20 ` Junio C Hamano
0 siblings, 1 reply; 17+ messages in thread
From: Patrick Steinhardt @ 2025-09-03 6:00 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Meet Soni, git, shejialuo
On Tue, Sep 02, 2025 at 10:25:44PM -0700, Junio C Hamano wrote:
> Patrick Steinhardt <ps@pks.im> writes:
>
> >> builtin/pack-refs.c | 31 ++++++++++++++++++++-----------
> >> pack-refs.h | 22 ++++++++++++++++++++++
> >> 2 files changed, 42 insertions(+), 11 deletions(-)
> >> create mode 100644 pack-refs.h
> >
> > Shouldn't that header live in "builtin/pack-refs.h"? Makes it way more
> > obvious that it exposes functions from "builtin/pack-refs.c".
>
> There shouldn't be any *.h files in builtin/. since the top-level
> is where the library-ish reusable things live, so that they can
> eventually be used by more than one *.c files in builtin/ and also
> by other *.c files outside builtin.
Hm, okay. I still find it puzzling if the header file for
"builtin/pack-refs.c" sits in "pack-refs.h" as it makes it very hard to
connect these two. How would you reconcile that? By moving the shared
logic into (non-"builtin/) "pack-refs.c"?
Patrick
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [GSoC][PATCH 1/5] builtin/pack-refs: factor out core logic into a helper
2025-09-03 6:00 ` Patrick Steinhardt
@ 2025-09-03 18:20 ` Junio C Hamano
0 siblings, 0 replies; 17+ messages in thread
From: Junio C Hamano @ 2025-09-03 18:20 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Meet Soni, git, shejialuo
Patrick Steinhardt <ps@pks.im> writes:
> Hm, okay. I still find it puzzling if the header file for
> "builtin/pack-refs.c" sits in "pack-refs.h" as it makes it very hard to
> connect these two. How would you reconcile that? By moving the shared
> logic into (non-"builtin/) "pack-refs.c"?
Yeah, if that is not happening, then the change is only half done, I
would think.
Thanks.
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2025-09-03 18:20 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-26 7:36 [GSoC][PATCH 0/5] Add refs optimize subcommand Meet Soni
2025-08-26 7:36 ` [GSoC][PATCH 1/5] builtin/pack-refs: factor out core logic into a helper Meet Soni
2025-09-02 10:18 ` Patrick Steinhardt
2025-09-03 3:56 ` Meet Soni
2025-09-03 4:37 ` Patrick Steinhardt
2025-09-03 5:25 ` Junio C Hamano
2025-09-03 6:00 ` Patrick Steinhardt
2025-09-03 18:20 ` Junio C Hamano
2025-08-26 7:36 ` [GSoC][PATCH 2/5] doc: factor out common option Meet Soni
2025-08-26 7:36 ` [GSoC][PATCH 3/5] builtin/refs: add optimize subcommand Meet Soni
2025-09-02 10:18 ` Patrick Steinhardt
2025-08-26 7:36 ` [GSoC][PATCH 4/5] t0601: refactor tests to be shareable Meet Soni
2025-08-26 7:36 ` [GSoC][PATCH 5/5] t: add test for git refs optimize subcommand Meet Soni
2025-08-26 15:18 ` shejialuo
2025-08-31 6:20 ` Meet Soni
2025-09-02 10:18 ` Patrick Steinhardt
2025-09-03 3:58 ` Meet Soni
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.