Skip to content

Commit

Permalink
Merge branch 'kn/ref-migrate-skip-reflog' into seen
Browse files Browse the repository at this point in the history
"git refs migrate" can optionally be told not to migrate the reflog.

Comments?
cf. <[email protected]>

* kn/ref-migrate-skip-reflog:
  builtin/refs: add '--skip-reflog' flag to bypass reflog migration
  • Loading branch information
gitster committed Feb 18, 2025
2 parents 8f83453 + 4635371 commit 3d14c94
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
3 changes: 3 additions & 0 deletions builtin/refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, "skip-reflog", &flags,
N_("skip migrating reflogs"),
REPO_MIGRATE_REF_STORAGE_FORMAT_SKIP_REFLOG),
OPT_END(),
};
struct strbuf errbuf = STRBUF_INIT;
Expand Down
8 changes: 5 additions & 3 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3043,9 +3043,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)
Expand Down
5 changes: 4 additions & 1 deletion refs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1143,8 +1143,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
Expand Down
28 changes: 24 additions & 4 deletions t/t1460-refs-migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 &&
Expand Down Expand Up @@ -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 --skip-reflog &&
# there should be no reflogs post migration.
git -C repo reflog --all >reflogs &&
test_must_be_empty reflogs
'
done
done

Expand Down

0 comments on commit 3d14c94

Please sign in to comment.