refs: convert MERGE_AUTOSTASH to become a normal pseudo-ref
Similar to the preceding conversion of the AUTO_MERGE pseudo-ref, let's convert the MERGE_AUTOSTASH ref to become a normal pseudo-ref as well. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Jan 19, 2024 at 11:40 UTC
3f921c75913a4ba7b73cb0d8ec05a2cf24d1f4d4
8 files changed
+15
-21
branch.c
+1
-1
@@ -819,7 +819,7 @@ void remove_merge_branch_state(struct repository *r)
819
unlink(git_path_merge_mode(r));
820
refs_delete_ref(get_main_ref_store(r), "", "AUTO_MERGE",
821
NULL, REF_NO_DEREF);
822
- save_autostash(git_path_merge_autostash(r));
822
+ save_autostash_ref(r, "MERGE_AUTOSTASH");
823
}
824
825
void remove_branch_state(struct repository *r, int verbose)
builtin/commit.c
+1
-1
@@ -1877,7 +1877,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1877
&oid, flags);
1878
}
1879
1880
- apply_autostash(git_path_merge_autostash(the_repository));
1880
+ apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
1881
1882
cleanup:
1883
strbuf_release(&author_ident);
builtin/merge.c
+13
-14
@@ -476,7 +476,7 @@ static void finish(struct commit *head_commit,
476
run_hooks_l("post-merge", squash ? "1" : "0", NULL);
477
478
if (new_head)
479
- apply_autostash(git_path_merge_autostash(the_repository));
479
+ apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
480
strbuf_release(&reflog_message);
481
}
482
@@ -1315,7 +1315,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1315
if (abort_current_merge) {
1316
int nargc = 2;
1317
const char *nargv[] = {"reset", "--merge", NULL};
1318
- struct strbuf stash_oid = STRBUF_INIT;
1318
+ char stash_oid_hex[GIT_MAX_HEXSZ + 1];
1319
+ struct object_id stash_oid = {0};
1320
1321
if (orig_argc != 2)
1322
usage_msg_opt(_("--abort expects no arguments"),
@@ -1324,17 +1325,17 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1325
if (!file_exists(git_path_merge_head(the_repository)))
1326
die(_("There is no merge to abort (MERGE_HEAD missing)."));
1327
1327
- if (read_oneliner(&stash_oid, git_path_merge_autostash(the_repository),
1328
- READ_ONELINER_SKIP_IF_EMPTY))
1329
- unlink(git_path_merge_autostash(the_repository));
1328
+ if (!read_ref("MERGE_AUTOSTASH", &stash_oid))
1329
+ delete_ref("", "MERGE_AUTOSTASH", &stash_oid, REF_NO_DEREF);
1330
1331
/* Invoke 'git reset --merge' */
1332
ret = cmd_reset(nargc, nargv, prefix);
1333
1334
- if (stash_oid.len)
1335
- apply_autostash_oid(stash_oid.buf);
1334
+ if (!is_null_oid(&stash_oid)) {
1335
+ oid_to_hex_r(stash_oid_hex, &stash_oid);
1336
+ apply_autostash_oid(stash_oid_hex);
1337
+ }
1338
1337
- strbuf_release(&stash_oid);
1339
goto done;
1340
}
1341
@@ -1563,13 +1564,12 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1564
}
1565
1566
if (autostash)
1566
- create_autostash(the_repository,
1567
- git_path_merge_autostash(the_repository));
1567
+ create_autostash_ref(the_repository, "MERGE_AUTOSTASH");
1568
if (checkout_fast_forward(the_repository,
1569
&head_commit->object.oid,
1570
&commit->object.oid,
1571
overwrite_ignore)) {
1572
- apply_autostash(git_path_merge_autostash(the_repository));
1572
+ apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
1573
ret = 1;
1574
goto done;
1575
}
@@ -1655,8 +1655,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1655
die_ff_impossible();
1656
1657
if (autostash)
1658
- create_autostash(the_repository,
1659
- git_path_merge_autostash(the_repository));
1658
+ create_autostash_ref(the_repository, "MERGE_AUTOSTASH");
1659
1660
/* We are going to make a new commit. */
1661
git_committer_info(IDENT_STRICT);
@@ -1741,7 +1740,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1740
else
1741
fprintf(stderr, _("Merge with strategy %s failed.\n"),
1742
use_strategies[0]->name);
1744
- apply_autostash(git_path_merge_autostash(the_repository));
1743
+ apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
1744
ret = 2;
1745
goto done;
1746
} else if (best_strategy == wt_strategy)
path.c
-1
@@ -1588,6 +1588,5 @@ REPO_GIT_PATH_FUNC(merge_msg, "MERGE_MSG")
1588
REPO_GIT_PATH_FUNC(merge_rr, "MERGE_RR")
1589
REPO_GIT_PATH_FUNC(merge_mode, "MERGE_MODE")
1590
REPO_GIT_PATH_FUNC(merge_head, "MERGE_HEAD")
1591
-REPO_GIT_PATH_FUNC(merge_autostash, "MERGE_AUTOSTASH")
1591
REPO_GIT_PATH_FUNC(fetch_head, "FETCH_HEAD")
1592
REPO_GIT_PATH_FUNC(shallow, "shallow")
path.h
-1
@@ -175,7 +175,6 @@ const char *git_path_merge_msg(struct repository *r);
175
const char *git_path_merge_rr(struct repository *r);
176
const char *git_path_merge_mode(struct repository *r);
177
const char *git_path_merge_head(struct repository *r);
178
-const char *git_path_merge_autostash(struct repository *r);
178
const char *git_path_fetch_head(struct repository *r);
179
const char *git_path_shallow(struct repository *r);
180
refs.c
-1
@@ -1875,7 +1875,6 @@ static int is_special_ref(const char *refname)
1875
*/
1876
static const char * const special_refs[] = {
1877
"FETCH_HEAD",
1878
- "MERGE_AUTOSTASH",
1878
"MERGE_HEAD",
1879
};
1880
size_t i;
repository.c
-1
@@ -262,7 +262,6 @@ static void repo_clear_path_cache(struct repo_path_cache *cache)
262
FREE_AND_NULL(cache->merge_rr);
263
FREE_AND_NULL(cache->merge_mode);
264
FREE_AND_NULL(cache->merge_head);
265
- FREE_AND_NULL(cache->merge_autostash);
265
FREE_AND_NULL(cache->fetch_head);
266
FREE_AND_NULL(cache->shallow);
267
}
repository.h
-1
@@ -67,7 +67,6 @@ struct repo_path_cache {
67
char *merge_rr;
68
char *merge_mode;
69
char *merge_head;
70
- char *merge_autostash;
70
char *fetch_head;
71
char *shallow;
72
};