From: Karthik Nayak <karthik.188@gmail.com>
To: karthik.188@gmail.com, gitster@pobox.com
Cc: git@vger.kernel.org, ps@pks.im, toon@iotcl.com
Subject: [PATCH v4] builtin/refs: add '--no-reflog' flag to drop reflogs
Date: Thu, 20 Feb 2025 10:56:14 +0100 [thread overview]
Message-ID: <20250220095614.62042-1-karthik.188@gmail.com> (raw)
In-Reply-To: <20250207-477-refs-migrate-add-a-flag-to-ignore-reflogs-during-migration-v1-1-7d40f3b4e30b@gmail.com>
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).
While this behavior is desirable for most client-side repositories,
server-side repositories are not expected to contain reflogs. However,
due to historical reasons, some may still have them. This could be
caused, for example, by bugs, misconfiguration, or an administrator
enabling reflogs on the server for debugging purposes.
To handle this, introduce the '--no-reflog' flag, which skips reflog
migration. When this flag is used, reflogs from the original reference
backend are not transferred, and since only the new reference backend
remains in the repository, all previous reflogs are permanently removed.
Helped-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
builtin/refs.c | 3 +++
refs.c | 8 +++++---
refs.h | 5 ++++-
t/t1460-refs-migrate.sh | 28 ++++++++++++++++++++++++----
4 files changed, 36 insertions(+), 8 deletions(-)
Changes in v4:
- Modify the flag to `--no-reflog` to better indicate that reflogs will
be dropped during the migration. This is also reflected in the help text
and the commit message.
Changes in v3:
- Make changes to the test:
- Use "$@" instead of $@
- Mark optional arguments correctly
- Use <options...> instead of <...options> as the former is more widely
used.
- Link to v2: https://lore.kernel.org/r/20250211-477-refs-migrate-add-a-flag-to-ignore-reflogs-during-migration-v2-1-991a2ec9a796@gmail.com
Changes in v2:
- Fix typo in commit mesasge and clarify the intent.
- Modify the test to use `test_line_count` and `test_must_be_empty`.
- Link to v1: https://lore.kernel.org/r/20250207-477-refs-migrate-add-a-flag-to-ignore-reflogs-during-migration-v1-1-7d40f3b4e30b@gmail.com
Range-diff:
1: 42c40d9617 ! 1: 3a02e8e526 builtin/refs: add '--skip-reflog' flag to bypass reflog migration
@@ Metadata
Author: Karthik Nayak <karthik.188@gmail.com>
## Commit message ##
- builtin/refs: add '--skip-reflog' flag to bypass reflog migration
+ builtin/refs: add '--no-reflog' flag to drop reflogs
The 'git-refs(1)' migrate subcommand, which transfers repositories
between reference backends, currently migrates reflogs by default as of
@@ Commit message
caused, for example, by bugs, misconfiguration, or an administrator
enabling reflogs on the server for debugging purposes.
- To address this, introduce the --skip-reflog flag, allowing users to
- bypass reflog migration. This ensures that the repository ends up in the
- expected state after migration.
+ To handle this, introduce the '--no-reflog' flag, which skips reflog
+ migration. When this flag is used, reflogs from the original reference
+ backend are not transferred, and since only the new reference backend
+ remains in the repository, all previous reflogs are permanently removed.
Helped-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
@@ builtin/refs.c: static int cmd_refs_migrate(int argc, const char **argv, const c
OPT_BIT(0, "dry-run", &flags,
N_("perform a non-destructive dry-run"),
REPO_MIGRATE_REF_STORAGE_FORMAT_DRYRUN),
-+ OPT_BIT(0, "skip-reflog", &flags,
-+ N_("skip migrating reflogs"),
++ OPT_BIT(0, "no-reflog", &flags,
++ N_("drop reflogs entirely during the migration"),
+ REPO_MIGRATE_REF_STORAGE_FORMAT_SKIP_REFLOG),
OPT_END(),
};
@@ t/t1460-refs-migrate.sh: do
+ # we see that the repository contains reflogs.
+ git -C repo reflog --all >reflogs &&
+ test_line_count = 2 reflogs &&
-+ test_migration repo "$to_format" true --skip-reflog &&
++ 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
---
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
--
2.47.2
next prev parent reply other threads:[~2025-02-20 9:56 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-07 11:57 [PATCH] builtin/refs: add '--skip-reflog' flag to bypass reflog migration Karthik Nayak
2025-02-07 15:23 ` Patrick Steinhardt
2025-02-11 6:18 ` Karthik Nayak
2025-02-07 17:45 ` Justin Tobler
2025-02-11 6:09 ` Karthik Nayak
2025-02-11 11:42 ` [PATCH v2] " Karthik Nayak
2025-02-11 12:21 ` Patrick Steinhardt
2025-02-11 17:48 ` Junio C Hamano
2025-02-12 17:43 ` Karthik Nayak
2025-02-13 9:25 ` Karthik Nayak
2025-02-12 18:38 ` [PATCH v3] " Karthik Nayak
2025-02-12 22:25 ` Junio C Hamano
2025-02-13 9:22 ` Karthik Nayak
2025-02-13 18:06 ` Junio C Hamano
2025-02-14 8:50 ` Karthik Nayak
2025-02-19 10:06 ` Toon Claes
2025-02-19 17:04 ` Junio C Hamano
2025-02-19 20:28 ` Karthik Nayak
2025-02-19 21:37 ` Junio C Hamano
2025-02-20 10:00 ` Karthik Nayak
2025-02-20 9:56 ` Karthik Nayak [this message]
2025-02-20 15:14 ` [PATCH v4] builtin/refs: add '--no-reflog' flag to drop reflogs Junio C Hamano
2025-02-21 8:44 ` Karthik Nayak
2025-02-21 10:04 ` [PATCH v5] " Karthik Nayak
2025-02-21 17:54 ` Junio C Hamano
2025-02-23 20:30 ` Karthik Nayak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250220095614.62042-1-karthik.188@gmail.com \
--to=karthik.188@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ps@pks.im \
--cc=toon@iotcl.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).