refs: rename `refs_create_symref()` to `refs_update_symref()`
The `refs_create_symref()` function is used to update/create a symref. But it doesn't check the old target of the symref, if existing. It force updates the symref. In this regard, the name `refs_create_symref()` is a bit misleading. So let's rename it to `refs_update_symref()`. This is akin to how 'git-update-ref(1)' also allows us to create apart from update. While we're here, rename the arguments in the function to clarify what they actually signify and reduce confusion. Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Karthik Nayak committed
May 7, 2024 at 14:58 UTC
f151dfe3c91de744a2ced6ae701d1d8c2215bfd6
5 files changed
+9
-11
builtin/branch.c
+1
-1
@@ -555,7 +555,7 @@ static int replace_each_worktree_head_symref(struct worktree **worktrees,
555
continue;
556
557
refs = get_worktree_ref_store(worktrees[i]);
558
- if (refs_create_symref(refs, "HEAD", newref, logmsg))
558
+ if (refs_update_symref(refs, "HEAD", newref, logmsg))
559
ret = error(_("HEAD of working tree %s is not updated"),
560
worktrees[i]->path);
561
}
builtin/worktree.c
+1
-1
@@ -517,7 +517,7 @@ static int add_worktree(const char *path, const char *refname,
517
ret = refs_update_ref(wt_refs, NULL, "HEAD", &commit->object.oid,
518
NULL, 0, UPDATE_REFS_MSG_ON_ERR);
519
else
520
- ret = refs_create_symref(wt_refs, "HEAD", symref.buf, NULL);
520
+ ret = refs_update_symref(wt_refs, "HEAD", symref.buf, NULL);
521
if (ret)
522
goto done;
523
refs.c
+5
-7
@@ -2284,10 +2284,8 @@ int peel_iterated_oid(const struct object_id *base, struct object_id *peeled)
2284
return peel_object(base, peeled) ? -1 : 0;
2285
}
2286
2287
-int refs_create_symref(struct ref_store *refs,
2288
- const char *ref_target,
2289
- const char *refs_heads_master,
2290
- const char *logmsg)
2287
+int refs_update_symref(struct ref_store *refs, const char *ref,
2288
+ const char *target, const char *logmsg)
2289
{
2290
struct ref_transaction *transaction;
2291
struct strbuf err = STRBUF_INIT;
@@ -2295,8 +2293,8 @@ int refs_create_symref(struct ref_store *refs,
2293
2294
transaction = ref_store_transaction_begin(refs, &err);
2295
if (!transaction ||
2298
- ref_transaction_update(transaction, ref_target, NULL, NULL,
2299
- refs_heads_master, NULL, REF_NO_DEREF,
2296
+ ref_transaction_update(transaction, ref, NULL, NULL,
2297
+ target, NULL, REF_NO_DEREF,
2298
logmsg, &err) ||
2299
ref_transaction_commit(transaction, &err)) {
2300
ret = error("%s", err.buf);
@@ -2312,7 +2310,7 @@ int refs_create_symref(struct ref_store *refs,
2310
int create_symref(const char *ref_target, const char *refs_heads_master,
2311
const char *logmsg)
2312
{
2315
- return refs_create_symref(get_main_ref_store(the_repository), ref_target,
2313
+ return refs_update_symref(get_main_ref_store(the_repository), ref_target,
2314
refs_heads_master, logmsg);
2315
}
2316
refs.h
+1
-1
@@ -606,7 +606,7 @@ int refs_copy_existing_ref(struct ref_store *refs, const char *oldref,
606
int copy_existing_ref(const char *oldref, const char *newref,
607
const char *logmsg);
608
609
-int refs_create_symref(struct ref_store *refs, const char *refname,
609
+int refs_update_symref(struct ref_store *refs, const char *refname,
610
const char *target, const char *logmsg);
611
int create_symref(const char *refname, const char *target, const char *logmsg);
612
t/helper/test-ref-store.c
+1
-1
@@ -118,7 +118,7 @@ static int cmd_create_symref(struct ref_store *refs, const char **argv)
118
const char *target = notnull(*argv++, "target");
119
const char *logmsg = *argv++;
120
121
- return refs_create_symref(refs, refname, target, logmsg);
121
+ return refs_update_symref(refs, refname, target, logmsg);
122
}
123
124
static struct flag_definition transaction_flags[] = {