Skip to content

Commit 1553f5e

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cd475b3 commit 1553f5e

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

builtin/remote.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,13 +766,15 @@ static int mv(int argc, const char **argv)
766766
for_each_ref(read_remote_branches, &rename);
767767
for (i = 0; i < remote_branches.nr; i++) {
768768
struct string_list_item *item = remote_branches.items + i;
769-
int flag = 0;
769+
struct strbuf referent = STRBUF_INIT;
770770

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))
773773
continue;
774774
if (delete_ref(NULL, item->string, NULL, REF_NO_DEREF))
775775
die(_("deleting '%s' failed"), item->string);
776+
777+
strbuf_release(&referent);
776778
}
777779
for (i = 0; i < remote_branches.nr; i++) {
778780
struct string_list_item *item = remote_branches.items + i;

remote.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,13 +1945,9 @@ const char *branch_get_push(struct branch *branch, struct strbuf *err)
19451945
return branch->push_tracking_ref;
19461946
}
19471947

1948-
static int ignore_symref_update(const char *refname)
1948+
static int ignore_symref_update(const char *refname, struct strbuf *scratch)
19491949
{
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);
19551951
}
19561952

19571953
/*
@@ -1964,18 +1960,21 @@ static int ignore_symref_update(const char *refname)
19641960
static struct ref *get_expanded_map(const struct ref *remote_refs,
19651961
const struct refspec_item *refspec)
19661962
{
1963+
struct strbuf scratch = STRBUF_INIT;
19671964
const struct ref *ref;
19681965
struct ref *ret = NULL;
19691966
struct ref **tail = &ret;
19701967

19711968
for (ref = remote_refs; ref; ref = ref->next) {
19721969
char *expn_name = NULL;
19731970

1971+
strbuf_reset(&scratch);
1972+
19741973
if (strchr(ref->name, '^'))
19751974
continue; /* a dereference item */
19761975
if (match_name_with_pattern(refspec->src, ref->name,
19771976
refspec->dst, &expn_name) &&
1978-
!ignore_symref_update(expn_name)) {
1977+
!ignore_symref_update(expn_name, &scratch)) {
19791978
struct ref *cpy = copy_ref(ref);
19801979

19811980
cpy->peer_ref = alloc_ref(expn_name);
@@ -1987,6 +1986,7 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,
19871986
free(expn_name);
19881987
}
19891988

1989+
strbuf_release(&scratch);
19901990
return ret;
19911991
}
19921992

0 commit comments

Comments
 (0)