Message ID | 20250220095614.62042-1-karthik.188@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [v4] builtin/refs: add '--no-reflog' flag to drop reflogs | expand |
Karthik Nayak <karthik.188@gmail.com> writes: > The 'git-refs(1)' migrate subcommand, which transfers repositories > between reference backends, currently migrates reflogs by default as of > 246cebe320 (refs: add support for migrating reflogs, 2024-12-16). "transfer" is a curious verb to use here, as it almost exclusively is used in the context of fetch-and-push object transfer over the wire. The "git refs migrate" subcommand converts the backend used for ref storage. It always migrates reflog data as well as refs. Allow it to optionally discard reflog data. This is useful because ... or something? > builtin/refs.c | 3 +++ > refs.c | 8 +++++--- > refs.h | 5 ++++- > t/t1460-refs-migrate.sh | 28 ++++++++++++++++++++++++---- > 4 files changed, 36 insertions(+), 8 deletions(-) I notice there is something missing. > diff --git a/builtin/refs.c b/builtin/refs.c > index a29f195834..c459507d51 100644 > --- a/builtin/refs.c > +++ b/builtin/refs.c > ... > + OPT_BIT(0, "no-reflog", &flags, > + N_("drop reflogs entirely during the migration"), > + REPO_MIGRATE_REF_STORAGE_FORMAT_SKIP_REFLOG), This is somewhat ugly, but parseopt API is nice enough to hide the "--no-no-reflog" nonsense from the end users, so this is OK. I think we are almost there but lack documentation updates? Documentation/git-refs.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git c/Documentation/git-refs.txt w/Documentation/git-refs.txt index 9829984b0a..bb50d6f888 100644 --- c/Documentation/git-refs.txt +++ w/Documentation/git-refs.txt @@ -8,9 +8,9 @@ git-refs - Low-level access to refs SYNOPSIS -------- -[verse] -'git refs migrate' --ref-format=<format> [--dry-run] -'git refs verify' [--strict] [--verbose] +[synopsis] +git refs migrate --ref-format=<format> [--no-reflog] [--dry-run] +git refs verify [--strict] [--verbose] DESCRIPTION ----------- @@ -43,6 +43,11 @@ include::ref-storage-format.txt[] can be used to double check that the migration works as expected before performing the actual migration. +--reflog:: +--no-reflog:: + Choose between migrating the reflog data to the new backend, + and discarding them. The default is "--reflog" to migrate. + The following options are specific to 'git refs verify': --strict::
FJunio C Hamano <gitster@pobox.com> writes: > Karthik Nayak <karthik.188@gmail.com> writes: > >> The 'git-refs(1)' migrate subcommand, which transfers repositories >> between reference backends, currently migrates reflogs by default as of >> 246cebe320 (refs: add support for migrating reflogs, 2024-12-16). > > "transfer" is a curious verb to use here, as it almost exclusively > is used in the context of fetch-and-push object transfer over the > wire. > > The "git refs migrate" subcommand converts the backend used > for ref storage. It always migrates reflog data as well as > refs. Allow it to optionally discard reflog data. This is > useful because ... > > or something? > Sure, I'll modify it to something along these lines :) >> builtin/refs.c | 3 +++ >> refs.c | 8 +++++--- >> refs.h | 5 ++++- >> t/t1460-refs-migrate.sh | 28 ++++++++++++++++++++++++---- >> 4 files changed, 36 insertions(+), 8 deletions(-) > > I notice there is something missing. > For a minute I thought I broke something here, but I'm assuming you mean the lack of documentation. > >> diff --git a/builtin/refs.c b/builtin/refs.c >> index a29f195834..c459507d51 100644 >> --- a/builtin/refs.c >> +++ b/builtin/refs.c >> ... >> + OPT_BIT(0, "no-reflog", &flags, >> + N_("drop reflogs entirely during the migration"), >> + REPO_MIGRATE_REF_STORAGE_FORMAT_SKIP_REFLOG), > > This is somewhat ugly, but parseopt API is nice enough to hide the > "--no-no-reflog" nonsense from the end users, so this is OK. > > I think we are almost there but lack documentation updates? > Yeah, this was a total miss. Thanks for pointing out. Will add it in. > > Documentation/git-refs.txt | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git c/Documentation/git-refs.txt w/Documentation/git-refs.txt > index 9829984b0a..bb50d6f888 100644 > --- c/Documentation/git-refs.txt > +++ w/Documentation/git-refs.txt > @@ -8,9 +8,9 @@ git-refs - Low-level access to refs > > SYNOPSIS > -------- > -[verse] > -'git refs migrate' --ref-format=<format> [--dry-run] > -'git refs verify' [--strict] [--verbose] > +[synopsis] I see '[synopsis]' being called out in 'Documentation/CodingGuidelines', but nothing about '[verse]'. > +git refs migrate --ref-format=<format> [--no-reflog] [--dry-run] > +git refs verify [--strict] [--verbose] > > DESCRIPTION > ----------- > @@ -43,6 +43,11 @@ include::ref-storage-format.txt[] > can be used to double check that the migration works as expected before > performing the actual migration. > > +--reflog:: > +--no-reflog:: > + Choose between migrating the reflog data to the new backend, > + and discarding them. The default is "--reflog" to migrate. > + > The following options are specific to 'git refs verify': > > --strict:: Will add this in! Thanks for the review.
diff --git a/builtin/refs.c b/builtin/refs.c index a29f195834..c459507d51 100644 --- a/builtin/refs.c +++ b/builtin/refs.c @@ -30,6 +30,9 @@ static int cmd_refs_migrate(int argc, const char **argv, const char *prefix, OPT_BIT(0, "dry-run", &flags, N_("perform a non-destructive dry-run"), REPO_MIGRATE_REF_STORAGE_FORMAT_DRYRUN), + OPT_BIT(0, "no-reflog", &flags, + N_("drop reflogs entirely during the migration"), + REPO_MIGRATE_REF_STORAGE_FORMAT_SKIP_REFLOG), OPT_END(), }; struct strbuf errbuf = STRBUF_INIT; diff --git a/refs.c b/refs.c index f4094a326a..5e8f5c06fa 100644 --- a/refs.c +++ b/refs.c @@ -3035,9 +3035,11 @@ int repo_migrate_ref_storage_format(struct repository *repo, if (ret < 0) goto done; - ret = refs_for_each_reflog(old_refs, migrate_one_reflog, &data); - if (ret < 0) - goto done; + if (!(flags & REPO_MIGRATE_REF_STORAGE_FORMAT_SKIP_REFLOG)) { + ret = refs_for_each_reflog(old_refs, migrate_one_reflog, &data); + if (ret < 0) + goto done; + } ret = ref_transaction_commit(transaction, errbuf); if (ret < 0) diff --git a/refs.h b/refs.h index a0cdd99250..ccee8fc670 100644 --- a/refs.h +++ b/refs.h @@ -1157,8 +1157,11 @@ int is_pseudo_ref(const char *refname); * - REPO_MIGRATE_REF_STORAGE_FORMAT_DRYRUN: perform a dry-run migration * without touching the main repository. The result will be written into a * temporary ref storage directory. + * + * - REPO_MIGRATE_REF_STORAGE_FORMAT_SKIP_REFLOG: skip migration of reflogs. */ -#define REPO_MIGRATE_REF_STORAGE_FORMAT_DRYRUN (1 << 0) +#define REPO_MIGRATE_REF_STORAGE_FORMAT_DRYRUN (1 << 0) +#define REPO_MIGRATE_REF_STORAGE_FORMAT_SKIP_REFLOG (1 << 1) /* * Migrate the ref storage format used by the repository to the diff --git a/t/t1460-refs-migrate.sh b/t/t1460-refs-migrate.sh index a6d9b35a46..2ab97e1b7d 100755 --- a/t/t1460-refs-migrate.sh +++ b/t/t1460-refs-migrate.sh @@ -9,14 +9,21 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME # Migrate the provided repository from one format to the other and # verify that the references and logs are migrated over correctly. -# Usage: test_migration <repo> <format> <skip_reflog_verify> +# Usage: test_migration <repo> <format> [<skip_reflog_verify> [<options...>]] # <repo> is the relative path to the repo to be migrated. # <format> is the ref format to be migrated to. -# <skip_reflog_verify> (true or false) whether to skip reflog verification. +# <skip_reflog_verify> (default: false) whether to skip reflog verification. +# <options...> are other options be passed directly to 'git refs migrate'. test_migration () { repo=$1 && format=$2 && - skip_reflog_verify=${3:-false} && + shift 2 && + skip_reflog_verify=false && + if test $# -ge 1 + then + skip_reflog_verify=$1 + shift + fi && git -C "$repo" for-each-ref --include-root-refs \ --format='%(refname) %(objectname) %(symref)' >expect && if ! $skip_reflog_verify @@ -25,7 +32,7 @@ test_migration () { git -C "$repo" reflog list >expect_log_list fi && - git -C "$repo" refs migrate --ref-format="$2" && + git -C "$repo" refs migrate --ref-format="$format" "$@" && git -C "$repo" for-each-ref --include-root-refs \ --format='%(refname) %(objectname) %(symref)' >actual && @@ -241,6 +248,19 @@ do test_cmp expect.reflog actual.reflog ) ' + + test_expect_success "$from_format -> $to_format: skip reflog with --skip-reflog" ' + test_when_finished "rm -rf repo" && + git init --ref-format=$from_format repo && + test_commit -C repo initial && + # we see that the repository contains reflogs. + git -C repo reflog --all >reflogs && + test_line_count = 2 reflogs && + test_migration repo "$to_format" true --no-reflog && + # there should be no reflogs post migration. + git -C repo reflog --all >reflogs && + test_must_be_empty reflogs + ' done done