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>maint
parent
300b38e46f
commit
f151dfe3c9
|
@ -555,7 +555,7 @@ static int replace_each_worktree_head_symref(struct worktree **worktrees,
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
refs = get_worktree_ref_store(worktrees[i]);
|
refs = get_worktree_ref_store(worktrees[i]);
|
||||||
if (refs_create_symref(refs, "HEAD", newref, logmsg))
|
if (refs_update_symref(refs, "HEAD", newref, logmsg))
|
||||||
ret = error(_("HEAD of working tree %s is not updated"),
|
ret = error(_("HEAD of working tree %s is not updated"),
|
||||||
worktrees[i]->path);
|
worktrees[i]->path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -517,7 +517,7 @@ static int add_worktree(const char *path, const char *refname,
|
||||||
ret = refs_update_ref(wt_refs, NULL, "HEAD", &commit->object.oid,
|
ret = refs_update_ref(wt_refs, NULL, "HEAD", &commit->object.oid,
|
||||||
NULL, 0, UPDATE_REFS_MSG_ON_ERR);
|
NULL, 0, UPDATE_REFS_MSG_ON_ERR);
|
||||||
else
|
else
|
||||||
ret = refs_create_symref(wt_refs, "HEAD", symref.buf, NULL);
|
ret = refs_update_symref(wt_refs, "HEAD", symref.buf, NULL);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
|
12
refs.c
12
refs.c
|
@ -2284,10 +2284,8 @@ int peel_iterated_oid(const struct object_id *base, struct object_id *peeled)
|
||||||
return peel_object(base, peeled) ? -1 : 0;
|
return peel_object(base, peeled) ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int refs_create_symref(struct ref_store *refs,
|
int refs_update_symref(struct ref_store *refs, const char *ref,
|
||||||
const char *ref_target,
|
const char *target, const char *logmsg)
|
||||||
const char *refs_heads_master,
|
|
||||||
const char *logmsg)
|
|
||||||
{
|
{
|
||||||
struct ref_transaction *transaction;
|
struct ref_transaction *transaction;
|
||||||
struct strbuf err = STRBUF_INIT;
|
struct strbuf err = STRBUF_INIT;
|
||||||
|
@ -2295,8 +2293,8 @@ int refs_create_symref(struct ref_store *refs,
|
||||||
|
|
||||||
transaction = ref_store_transaction_begin(refs, &err);
|
transaction = ref_store_transaction_begin(refs, &err);
|
||||||
if (!transaction ||
|
if (!transaction ||
|
||||||
ref_transaction_update(transaction, ref_target, NULL, NULL,
|
ref_transaction_update(transaction, ref, NULL, NULL,
|
||||||
refs_heads_master, NULL, REF_NO_DEREF,
|
target, NULL, REF_NO_DEREF,
|
||||||
logmsg, &err) ||
|
logmsg, &err) ||
|
||||||
ref_transaction_commit(transaction, &err)) {
|
ref_transaction_commit(transaction, &err)) {
|
||||||
ret = error("%s", err.buf);
|
ret = error("%s", err.buf);
|
||||||
|
@ -2312,7 +2310,7 @@ int refs_create_symref(struct ref_store *refs,
|
||||||
int create_symref(const char *ref_target, const char *refs_heads_master,
|
int create_symref(const char *ref_target, const char *refs_heads_master,
|
||||||
const char *logmsg)
|
const char *logmsg)
|
||||||
{
|
{
|
||||||
return refs_create_symref(get_main_ref_store(the_repository), ref_target,
|
return refs_update_symref(get_main_ref_store(the_repository), ref_target,
|
||||||
refs_heads_master, logmsg);
|
refs_heads_master, logmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
refs.h
2
refs.h
|
@ -606,7 +606,7 @@ int refs_copy_existing_ref(struct ref_store *refs, const char *oldref,
|
||||||
int copy_existing_ref(const char *oldref, const char *newref,
|
int copy_existing_ref(const char *oldref, const char *newref,
|
||||||
const char *logmsg);
|
const char *logmsg);
|
||||||
|
|
||||||
int refs_create_symref(struct ref_store *refs, const char *refname,
|
int refs_update_symref(struct ref_store *refs, const char *refname,
|
||||||
const char *target, const char *logmsg);
|
const char *target, const char *logmsg);
|
||||||
int create_symref(const char *refname, const char *target, const char *logmsg);
|
int create_symref(const char *refname, const char *target, const char *logmsg);
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ static int cmd_create_symref(struct ref_store *refs, const char **argv)
|
||||||
const char *target = notnull(*argv++, "target");
|
const char *target = notnull(*argv++, "target");
|
||||||
const char *logmsg = *argv++;
|
const char *logmsg = *argv++;
|
||||||
|
|
||||||
return refs_create_symref(refs, refname, target, logmsg);
|
return refs_update_symref(refs, refname, target, logmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct flag_definition transaction_flags[] = {
|
static struct flag_definition transaction_flags[] = {
|
||||||
|
|
Loading…
Reference in New Issue