Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
pks-t committed May 27, 2024
1 parent 57c3c80 commit c41aeeb
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
15 changes: 15 additions & 0 deletions builtin/refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,44 @@ static int cmd_refs_migrate(int argc, const char **argv, const char *prefix)
struct strbuf errbuf = STRBUF_INIT;
int err;

fputs("parse options\n", stderr);
fflush(stderr);

argc = parse_options(argc, argv, prefix, options, migrate_usage, 0);
if (argc)
usage(_("too many arguments"));
if (!format_str)
usage(_("missing --ref-format=<format>"));

fputs("ref storage format\n", stderr);
fflush(stderr);

format = ref_storage_format_by_name(format_str);
if (format == REF_STORAGE_FORMAT_UNKNOWN) {
err = error(_("unknown ref storage format '%s'"), format_str);
goto out;
}

fputs("double check\n", stderr);
fflush(stderr);

if (the_repository->ref_storage_format == format) {
err = error(_("repository already uses '%s' format"),
ref_storage_format_to_name(format));
goto out;
}

fputs("repo migrate\n", stderr);
fflush(stderr);

if (repo_migrate_ref_storage_format(the_repository, format, flags, &errbuf) < 0) {
err = error("%s", errbuf.buf);
goto out;
}

fputs("repo migrate done\n", stderr);
fflush(stderr);

err = 0;

out:
Expand Down
30 changes: 30 additions & 0 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2712,6 +2712,9 @@ int repo_migrate_ref_storage_format(struct repository *repo,

old_refs = get_main_ref_store(repo);

fputs("reflog checks\n", stderr);
fflush(stderr);

/*
* We do not have any interfaces that would allow us to write many
* reflog entries. Once we have them we can remove this restriction.
Expand All @@ -2727,6 +2730,9 @@ int repo_migrate_ref_storage_format(struct repository *repo,
goto done;
}

fputs("worktree checks\n", stderr);
fflush(stderr);

/*
* Worktrees complicate the migration because every worktree has a
* separate ref storage. While it should be feasible to implement, this
Expand All @@ -2742,6 +2748,9 @@ int repo_migrate_ref_storage_format(struct repository *repo,
goto done;
}

fputs("mkdtemp\n", stderr);
fflush(stderr);

/*
* The overall logic looks like this:
*
Expand Down Expand Up @@ -2773,12 +2782,18 @@ int repo_migrate_ref_storage_format(struct repository *repo,
goto done;
}

fputs("ref store init\n", stderr);
fflush(stderr);

new_refs = ref_store_init(repo, format, new_gitdir,
REF_STORE_ALL_CAPS);
ret = ref_store_create_on_disk(new_refs, 0, errbuf);
if (ret < 0)
goto done;

fputs("ref store transaction\n", stderr);
fflush(stderr);

transaction = ref_store_transaction_begin(new_refs, errbuf);
if (!transaction)
goto done;
Expand All @@ -2787,6 +2802,9 @@ int repo_migrate_ref_storage_format(struct repository *repo,
data.transaction = transaction;
data.errbuf = errbuf;

fputs("ref enumeration\n", stderr);
fflush(stderr);

/*
* We need to use the internal `do_for_each_ref()` here so that we can
* also include broken refs and symrefs. These would otherwise be
Expand All @@ -2804,6 +2822,9 @@ int repo_migrate_ref_storage_format(struct repository *repo,
if (ret < 0)
goto done;

fputs("ref transaction commit\n", stderr);
fflush(stderr);

/*
* TODO: we might want to migrate to `initial_ref_transaction_commit()`
* here, which is more efficient for the files backend because it would
Expand All @@ -2823,6 +2844,9 @@ int repo_migrate_ref_storage_format(struct repository *repo,
goto done;
}

fputs("ref db removal\n", stderr);
fflush(stderr);

/*
* Until now we were in the non-destructive phase, where we only
* populated the new ref store. From hereon though we are about
Expand All @@ -2839,6 +2863,9 @@ int repo_migrate_ref_storage_format(struct repository *repo,
if (ret < 0)
goto done;

fputs("move files\n", stderr);
fflush(stderr);

ret = move_files(new_gitdir, old_refs->gitdir, errbuf);
if (ret < 0)
goto done;
Expand All @@ -2847,6 +2874,9 @@ int repo_migrate_ref_storage_format(struct repository *repo,
warning_errno(_("could not remove temporary migration directory '%s'"),
new_gitdir);

fputs("move over\n", stderr);
fflush(stderr);

/*
* We have migrated the repository, so we now need to adjust the
* repository format so that clients will use the new ref store.
Expand Down
29 changes: 28 additions & 1 deletion refs/reftable-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,26 +352,53 @@ static int reftable_be_remove_on_disk(struct ref_store *ref_store,
struct strbuf sb = STRBUF_INIT;
int ret = 0;

fputs("removal: remove old store\n", stderr);
fflush(stderr);

reftable_be_release(ref_store);

fputs("removal: remove reftable directory\n", stderr);
fflush(stderr);

strbuf_addf(&sb, "%s/reftable", refs->base.gitdir);
if (remove_dir_recursively(&sb, 0) < 0) {
strbuf_addstr(err, "could not delete reftables");
strbuf_addf(err, "could not delete reftables: %s",
strerror(errno));
ret = -1;

fputs(sb.buf, stderr);
fflush(stderr);
}
strbuf_reset(&sb);

fputs("removal: remove HEAD\n", stderr);
fflush(stderr);

strbuf_addf(&sb, "%s/HEAD", refs->base.gitdir);
if (remove_path(sb.buf) < 0) {
strbuf_addstr(err, "could not delete stub HEAD");
ret = -1;

fputs(sb.buf, stderr);
fflush(stderr);
}
strbuf_reset(&sb);

fputs("removal: remove refs/heads\n", stderr);
fflush(stderr);

strbuf_addf(&sb, "%s/refs/heads", refs->base.gitdir);
if (remove_path(sb.buf) < 0) {
strbuf_addstr(err, "could not delete stub heads");
ret = -1;

fputs(sb.buf, stderr);
fflush(stderr);
}

fputs("removal: done\n", stderr);
fflush(stderr);

strbuf_release(&sb);
return ret;
}
Expand Down

0 comments on commit c41aeeb

Please sign in to comment.