remote: read symbolic refs via `refs_read_symbolic_ref()`
We have two cases in the remote code where we check whether a reference is symbolic or not, but don't mind in case it doesn't exist or in case it exists but is a non-symbolic reference. Convert these two callsites to use the new `refs_read_symbolic_ref()` function, whose intent is to implement exactly that usecase. No change in behaviour is expected from this change. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Mar 1, 2022 at 10:33 UTC
1553f5e76c72243f61b454412b651706a869388f
2 files changed
+12
-10
builtin/remote.c
+5
-3
@@ -766,13 +766,15 @@ static int mv(int argc, const char **argv)
766
for_each_ref(read_remote_branches, &rename);
767
for (i = 0; i < remote_branches.nr; i++) {
768
struct string_list_item *item = remote_branches.items + i;
769
- int flag = 0;
769
+ struct strbuf referent = STRBUF_INIT;
770
771
- read_ref_full(item->string, RESOLVE_REF_READING, NULL, &flag);
772
- if (!(flag & REF_ISSYMREF))
771
+ if (refs_read_symbolic_ref(get_main_ref_store(the_repository), item->string,
772
+ &referent))
773
continue;
774
if (delete_ref(NULL, item->string, NULL, REF_NO_DEREF))
775
die(_("deleting '%s' failed"), item->string);
776
+
777
+ strbuf_release(&referent);
778
}
779
for (i = 0; i < remote_branches.nr; i++) {
780
struct string_list_item *item = remote_branches.items + i;
remote.c
+7
-7
@@ -1945,13 +1945,9 @@ const char *branch_get_push(struct branch *branch, struct strbuf *err)
1945
return branch->push_tracking_ref;
1946
}
1947
1948
-static int ignore_symref_update(const char *refname)
1948
+static int ignore_symref_update(const char *refname, struct strbuf *scratch)
1949
{
1950
- int flag;
1951
-
1952
- if (!resolve_ref_unsafe(refname, 0, NULL, &flag))
1953
- return 0; /* non-existing refs are OK */
1954
- return (flag & REF_ISSYMREF);
1950
+ return !refs_read_symbolic_ref(get_main_ref_store(the_repository), refname, scratch);
1951
}
1952
1953
/*
@@ -1964,6 +1960,7 @@ static int ignore_symref_update(const char *refname)
1960
static struct ref *get_expanded_map(const struct ref *remote_refs,
1961
const struct refspec_item *refspec)
1962
{
1963
+ struct strbuf scratch = STRBUF_INIT;
1964
const struct ref *ref;
1965
struct ref *ret = NULL;
1966
struct ref **tail = &ret;
@@ -1971,11 +1968,13 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,
1968
for (ref = remote_refs; ref; ref = ref->next) {
1969
char *expn_name = NULL;
1970
1971
+ strbuf_reset(&scratch);
1972
+
1973
if (strchr(ref->name, '^'))
1974
continue; /* a dereference item */
1975
if (match_name_with_pattern(refspec->src, ref->name,
1976
refspec->dst, &expn_name) &&
1978
- !ignore_symref_update(expn_name)) {
1977
+ !ignore_symref_update(expn_name, &scratch)) {
1978
struct ref *cpy = copy_ref(ref);
1979
1980
cpy->peer_ref = alloc_ref(expn_name);
@@ -1987,6 +1986,7 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,
1986
free(expn_name);
1987
}
1988
1989
+ strbuf_release(&scratch);
1990
return ret;
1991
}
1992