Skip to content

Commit f151dfe

Browse files
KarthikNayakgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 300b38e commit f151dfe

File tree

5 files changed

+9
-11
lines changed

5 files changed

+9
-11
lines changed

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ static int replace_each_worktree_head_symref(struct worktree **worktrees,
555555
continue;
556556

557557
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))
559559
ret = error(_("HEAD of working tree %s is not updated"),
560560
worktrees[i]->path);
561561
}

builtin/worktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ static int add_worktree(const char *path, const char *refname,
517517
ret = refs_update_ref(wt_refs, NULL, "HEAD", &commit->object.oid,
518518
NULL, 0, UPDATE_REFS_MSG_ON_ERR);
519519
else
520-
ret = refs_create_symref(wt_refs, "HEAD", symref.buf, NULL);
520+
ret = refs_update_symref(wt_refs, "HEAD", symref.buf, NULL);
521521
if (ret)
522522
goto done;
523523

refs.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,19 +2284,17 @@ int peel_iterated_oid(const struct object_id *base, struct object_id *peeled)
22842284
return peel_object(base, peeled) ? -1 : 0;
22852285
}
22862286

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)
22912289
{
22922290
struct ref_transaction *transaction;
22932291
struct strbuf err = STRBUF_INIT;
22942292
int ret = 0;
22952293

22962294
transaction = ref_store_transaction_begin(refs, &err);
22972295
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,
23002298
logmsg, &err) ||
23012299
ref_transaction_commit(transaction, &err)) {
23022300
ret = error("%s", err.buf);
@@ -2312,7 +2310,7 @@ int refs_create_symref(struct ref_store *refs,
23122310
int create_symref(const char *ref_target, const char *refs_heads_master,
23132311
const char *logmsg)
23142312
{
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,
23162314
refs_heads_master, logmsg);
23172315
}
23182316

refs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ int refs_copy_existing_ref(struct ref_store *refs, const char *oldref,
606606
int copy_existing_ref(const char *oldref, const char *newref,
607607
const char *logmsg);
608608

609-
int refs_create_symref(struct ref_store *refs, const char *refname,
609+
int refs_update_symref(struct ref_store *refs, const char *refname,
610610
const char *target, const char *logmsg);
611611
int create_symref(const char *refname, const char *target, const char *logmsg);
612612

t/helper/test-ref-store.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static int cmd_create_symref(struct ref_store *refs, const char **argv)
118118
const char *target = notnull(*argv++, "target");
119119
const char *logmsg = *argv++;
120120

121-
return refs_create_symref(refs, refname, target, logmsg);
121+
return refs_update_symref(refs, refname, target, logmsg);
122122
}
123123

124124
static struct flag_definition transaction_flags[] = {

0 commit comments

Comments
 (0)