diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-01-19 11:40:09 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-01-19 11:10:41 -0800 |
commit | fd7c6ffa9e118cdf18a3752ec456070ed0a22e3b (patch) | |
tree | 8ed2182341844aadbdcd481e396dbce854a2db02 | |
parent | bb02e95f3b25d933272bcf9d6883828d26271f69 (diff) | |
download | git-fd7c6ffa9e118cdf18a3752ec456070ed0a22e3b.tar.gz |
refs: convert AUTO_MERGE to become a normal pseudo-ref
In 70c70de616 (refs: complete list of special refs, 2023-12-14) we have
inrtoduced a new `is_special_ref()` function that classifies some refs
as being special. The rule is that special refs are exclusively read and
written via the filesystem directly, whereas normal refs exclucsively go
via the refs API.
The intent of that commit was to record the status quo so that we know
to route reads of such special refs consistently. Eventually, the list
should be reduced to its bare minimum of refs which really are special,
namely FETCH_HEAD and MERGE_HEAD.
Follow up on this promise and convert the AUTO_MERGE ref to become a
normal pseudo-ref by using the refs API to both read and write it
instead of accessing the filesystem directly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | branch.c | 3 | ||||
-rw-r--r-- | builtin/rebase.c | 2 | ||||
-rw-r--r-- | merge-ort.c | 19 | ||||
-rw-r--r-- | path.c | 1 | ||||
-rw-r--r-- | path.h | 1 | ||||
-rw-r--r-- | refs.c | 1 | ||||
-rw-r--r-- | repository.c | 1 | ||||
-rw-r--r-- | repository.h | 1 | ||||
-rw-r--r-- | sequencer.c | 12 |
9 files changed, 23 insertions, 18 deletions
@@ -817,7 +817,8 @@ void remove_merge_branch_state(struct repository *r) unlink(git_path_merge_rr(r)); unlink(git_path_merge_msg(r)); unlink(git_path_merge_mode(r)); - unlink(git_path_auto_merge(r)); + refs_delete_ref(get_main_ref_store(r), "", "AUTO_MERGE", + NULL, REF_NO_DEREF); save_autostash(git_path_merge_autostash(r)); } diff --git a/builtin/rebase.c b/builtin/rebase.c index 995818c28d..5b086f651a 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -515,7 +515,7 @@ static int finish_rebase(struct rebase_options *opts) int ret = 0; delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF); - unlink(git_path_auto_merge(the_repository)); + delete_ref(NULL, "AUTO_MERGE", NULL, REF_NO_DEREF); apply_autostash(state_dir_path("autostash", opts)); /* * We ignore errors in 'git maintenance run --auto', since the diff --git a/merge-ort.c b/merge-ort.c index 77ba7f3020..d72fd04f58 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -38,6 +38,7 @@ #include "path.h" #include "promisor-remote.h" #include "read-cache-ll.h" +#include "refs.h" #include "revision.h" #include "sparse-index.h" #include "strmap.h" @@ -4659,9 +4660,6 @@ void merge_switch_to_result(struct merge_options *opt, { assert(opt->priv == NULL); if (result->clean >= 0 && update_worktree_and_index) { - const char *filename; - FILE *fp; - trace2_region_enter("merge", "checkout", opt->repo); if (checkout(opt, head, result->tree)) { /* failure to function */ @@ -4687,10 +4685,17 @@ void merge_switch_to_result(struct merge_options *opt, trace2_region_leave("merge", "record_conflicted", opt->repo); trace2_region_enter("merge", "write_auto_merge", opt->repo); - filename = git_path_auto_merge(opt->repo); - fp = xfopen(filename, "w"); - fprintf(fp, "%s\n", oid_to_hex(&result->tree->object.oid)); - fclose(fp); + if (refs_update_ref(get_main_ref_store(opt->repo), "", "AUTO_MERGE", + &result->tree->object.oid, NULL, REF_NO_DEREF, + UPDATE_REFS_MSG_ON_ERR)) { + /* failure to function */ + opt->priv = NULL; + result->clean = -1; + merge_finalize(opt, result); + trace2_region_leave("merge", "write_auto_merge", + opt->repo); + return; + } trace2_region_leave("merge", "write_auto_merge", opt->repo); } if (display_update_msgs) @@ -1589,6 +1589,5 @@ REPO_GIT_PATH_FUNC(merge_rr, "MERGE_RR") REPO_GIT_PATH_FUNC(merge_mode, "MERGE_MODE") REPO_GIT_PATH_FUNC(merge_head, "MERGE_HEAD") REPO_GIT_PATH_FUNC(merge_autostash, "MERGE_AUTOSTASH") -REPO_GIT_PATH_FUNC(auto_merge, "AUTO_MERGE") REPO_GIT_PATH_FUNC(fetch_head, "FETCH_HEAD") REPO_GIT_PATH_FUNC(shallow, "shallow") @@ -176,7 +176,6 @@ const char *git_path_merge_rr(struct repository *r); const char *git_path_merge_mode(struct repository *r); const char *git_path_merge_head(struct repository *r); const char *git_path_merge_autostash(struct repository *r); -const char *git_path_auto_merge(struct repository *r); const char *git_path_fetch_head(struct repository *r); const char *git_path_shallow(struct repository *r); @@ -1874,7 +1874,6 @@ static int is_special_ref(const char *refname) * (normal ones). */ static const char * const special_refs[] = { - "AUTO_MERGE", "FETCH_HEAD", "MERGE_AUTOSTASH", "MERGE_HEAD", diff --git a/repository.c b/repository.c index d7d24d416a..a931e3b1b3 100644 --- a/repository.c +++ b/repository.c @@ -263,7 +263,6 @@ static void repo_clear_path_cache(struct repo_path_cache *cache) FREE_AND_NULL(cache->merge_mode); FREE_AND_NULL(cache->merge_head); FREE_AND_NULL(cache->merge_autostash); - FREE_AND_NULL(cache->auto_merge); FREE_AND_NULL(cache->fetch_head); FREE_AND_NULL(cache->shallow); } diff --git a/repository.h b/repository.h index f5269b3730..47e7d20b59 100644 --- a/repository.h +++ b/repository.h @@ -68,7 +68,6 @@ struct repo_path_cache { char *merge_mode; char *merge_head; char *merge_autostash; - char *auto_merge; char *fetch_head; char *shallow; }; diff --git a/sequencer.c b/sequencer.c index 6f620f5717..47c8d17cbb 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2408,7 +2408,8 @@ static int do_pick_commit(struct repository *r, refs_delete_ref(get_main_ref_store(r), "", "CHERRY_PICK_HEAD", NULL, REF_NO_DEREF); unlink(git_path_merge_msg(r)); - unlink(git_path_auto_merge(r)); + refs_delete_ref(get_main_ref_store(r), "", "AUTO_MERGE", + NULL, REF_NO_DEREF); fprintf(stderr, _("dropping %s %s -- patch contents already upstream\n"), oid_to_hex(&commit->object.oid), msg.subject); @@ -2818,7 +2819,8 @@ void sequencer_post_commit_cleanup(struct repository *r, int verbose) need_cleanup = 1; } - unlink(git_path_auto_merge(r)); + refs_delete_ref(get_main_ref_store(r), "", "AUTO_MERGE", + NULL, REF_NO_DEREF); if (!need_cleanup) return; @@ -4766,7 +4768,8 @@ static int pick_commits(struct repository *r, } unlink(rebase_path_author_script()); unlink(git_path_merge_head(r)); - unlink(git_path_auto_merge(r)); + refs_delete_ref(get_main_ref_store(r), "", "AUTO_MERGE", + NULL, REF_NO_DEREF); refs_delete_ref(get_main_ref_store(r), "", "REBASE_HEAD", NULL, REF_NO_DEREF); @@ -5123,7 +5126,8 @@ static int commit_staged_changes(struct repository *r, return error(_("could not commit staged changes.")); unlink(rebase_path_amend()); unlink(git_path_merge_head(r)); - unlink(git_path_auto_merge(r)); + refs_delete_ref(get_main_ref_store(r), "", "AUTO_MERGE", + NULL, REF_NO_DEREF); if (final_fixup) { unlink(rebase_path_fixup_msg()); unlink(rebase_path_squash_msg()); |