Skip to content

Commit fd7c6ff

Browse files
pks-tgitster
authored andcommitted
refs: convert AUTO_MERGE to become a normal pseudo-ref
In 70c70de (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bb02e95 commit fd7c6ff

File tree

9 files changed

+23
-18
lines changed

9 files changed

+23
-18
lines changed

branch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,8 @@ void remove_merge_branch_state(struct repository *r)
817817
unlink(git_path_merge_rr(r));
818818
unlink(git_path_merge_msg(r));
819819
unlink(git_path_merge_mode(r));
820-
unlink(git_path_auto_merge(r));
820+
refs_delete_ref(get_main_ref_store(r), "", "AUTO_MERGE",
821+
NULL, REF_NO_DEREF);
821822
save_autostash(git_path_merge_autostash(r));
822823
}
823824

builtin/rebase.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ static int finish_rebase(struct rebase_options *opts)
515515
int ret = 0;
516516

517517
delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
518-
unlink(git_path_auto_merge(the_repository));
518+
delete_ref(NULL, "AUTO_MERGE", NULL, REF_NO_DEREF);
519519
apply_autostash(state_dir_path("autostash", opts));
520520
/*
521521
* We ignore errors in 'git maintenance run --auto', since the

merge-ort.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "path.h"
3939
#include "promisor-remote.h"
4040
#include "read-cache-ll.h"
41+
#include "refs.h"
4142
#include "revision.h"
4243
#include "sparse-index.h"
4344
#include "strmap.h"
@@ -4659,9 +4660,6 @@ void merge_switch_to_result(struct merge_options *opt,
46594660
{
46604661
assert(opt->priv == NULL);
46614662
if (result->clean >= 0 && update_worktree_and_index) {
4662-
const char *filename;
4663-
FILE *fp;
4664-
46654663
trace2_region_enter("merge", "checkout", opt->repo);
46664664
if (checkout(opt, head, result->tree)) {
46674665
/* failure to function */
@@ -4687,10 +4685,17 @@ void merge_switch_to_result(struct merge_options *opt,
46874685
trace2_region_leave("merge", "record_conflicted", opt->repo);
46884686

46894687
trace2_region_enter("merge", "write_auto_merge", opt->repo);
4690-
filename = git_path_auto_merge(opt->repo);
4691-
fp = xfopen(filename, "w");
4692-
fprintf(fp, "%s\n", oid_to_hex(&result->tree->object.oid));
4693-
fclose(fp);
4688+
if (refs_update_ref(get_main_ref_store(opt->repo), "", "AUTO_MERGE",
4689+
&result->tree->object.oid, NULL, REF_NO_DEREF,
4690+
UPDATE_REFS_MSG_ON_ERR)) {
4691+
/* failure to function */
4692+
opt->priv = NULL;
4693+
result->clean = -1;
4694+
merge_finalize(opt, result);
4695+
trace2_region_leave("merge", "write_auto_merge",
4696+
opt->repo);
4697+
return;
4698+
}
46944699
trace2_region_leave("merge", "write_auto_merge", opt->repo);
46954700
}
46964701
if (display_update_msgs)

path.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,5 @@ REPO_GIT_PATH_FUNC(merge_rr, "MERGE_RR")
15891589
REPO_GIT_PATH_FUNC(merge_mode, "MERGE_MODE")
15901590
REPO_GIT_PATH_FUNC(merge_head, "MERGE_HEAD")
15911591
REPO_GIT_PATH_FUNC(merge_autostash, "MERGE_AUTOSTASH")
1592-
REPO_GIT_PATH_FUNC(auto_merge, "AUTO_MERGE")
15931592
REPO_GIT_PATH_FUNC(fetch_head, "FETCH_HEAD")
15941593
REPO_GIT_PATH_FUNC(shallow, "shallow")

path.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ const char *git_path_merge_rr(struct repository *r);
176176
const char *git_path_merge_mode(struct repository *r);
177177
const char *git_path_merge_head(struct repository *r);
178178
const char *git_path_merge_autostash(struct repository *r);
179-
const char *git_path_auto_merge(struct repository *r);
180179
const char *git_path_fetch_head(struct repository *r);
181180
const char *git_path_shallow(struct repository *r);
182181

refs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1874,7 +1874,6 @@ static int is_special_ref(const char *refname)
18741874
* (normal ones).
18751875
*/
18761876
static const char * const special_refs[] = {
1877-
"AUTO_MERGE",
18781877
"FETCH_HEAD",
18791878
"MERGE_AUTOSTASH",
18801879
"MERGE_HEAD",

repository.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ static void repo_clear_path_cache(struct repo_path_cache *cache)
263263
FREE_AND_NULL(cache->merge_mode);
264264
FREE_AND_NULL(cache->merge_head);
265265
FREE_AND_NULL(cache->merge_autostash);
266-
FREE_AND_NULL(cache->auto_merge);
267266
FREE_AND_NULL(cache->fetch_head);
268267
FREE_AND_NULL(cache->shallow);
269268
}

repository.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ struct repo_path_cache {
6868
char *merge_mode;
6969
char *merge_head;
7070
char *merge_autostash;
71-
char *auto_merge;
7271
char *fetch_head;
7372
char *shallow;
7473
};

sequencer.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,7 +2408,8 @@ static int do_pick_commit(struct repository *r,
24082408
refs_delete_ref(get_main_ref_store(r), "", "CHERRY_PICK_HEAD",
24092409
NULL, REF_NO_DEREF);
24102410
unlink(git_path_merge_msg(r));
2411-
unlink(git_path_auto_merge(r));
2411+
refs_delete_ref(get_main_ref_store(r), "", "AUTO_MERGE",
2412+
NULL, REF_NO_DEREF);
24122413
fprintf(stderr,
24132414
_("dropping %s %s -- patch contents already upstream\n"),
24142415
oid_to_hex(&commit->object.oid), msg.subject);
@@ -2818,7 +2819,8 @@ void sequencer_post_commit_cleanup(struct repository *r, int verbose)
28182819
need_cleanup = 1;
28192820
}
28202821

2821-
unlink(git_path_auto_merge(r));
2822+
refs_delete_ref(get_main_ref_store(r), "", "AUTO_MERGE",
2823+
NULL, REF_NO_DEREF);
28222824

28232825
if (!need_cleanup)
28242826
return;
@@ -4766,7 +4768,8 @@ static int pick_commits(struct repository *r,
47664768
}
47674769
unlink(rebase_path_author_script());
47684770
unlink(git_path_merge_head(r));
4769-
unlink(git_path_auto_merge(r));
4771+
refs_delete_ref(get_main_ref_store(r), "", "AUTO_MERGE",
4772+
NULL, REF_NO_DEREF);
47704773
refs_delete_ref(get_main_ref_store(r), "", "REBASE_HEAD",
47714774
NULL, REF_NO_DEREF);
47724775

@@ -5123,7 +5126,8 @@ static int commit_staged_changes(struct repository *r,
51235126
return error(_("could not commit staged changes."));
51245127
unlink(rebase_path_amend());
51255128
unlink(git_path_merge_head(r));
5126-
unlink(git_path_auto_merge(r));
5129+
refs_delete_ref(get_main_ref_store(r), "", "AUTO_MERGE",
5130+
NULL, REF_NO_DEREF);
51275131
if (final_fixup) {
51285132
unlink(rebase_path_fixup_msg());
51295133
unlink(rebase_path_squash_msg());

0 commit comments

Comments
 (0)