Skip to content

Commit 3bd9256

Browse files
jaysoffiangitster
authored andcommitted
builtin-remote: fix two inconsistencies in the output of "show <remote>"
Remote and stale branches are emitted in alphabetical order, but new and tracked branches are not. So sort the latter to be consistent with the former. This also lets us use more efficient string_list_has_string() instead of unsorted_string_list_has_string(). "show <remote>" prunes symrefs, but "show <remote> -n" does not. Fix the latter to match the former. Signed-off-by: Jay Soffian <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cca7c97 commit 3bd9256

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

builtin-remote.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,8 @@ static int handle_one_branch(const char *refname,
226226
const char *name = abbrev_branch(refspec.src);
227227
/* symbolic refs pointing nowhere were handled already */
228228
if ((flags & REF_ISSYMREF) ||
229-
unsorted_string_list_has_string(&states->tracked,
230-
name) ||
231-
unsorted_string_list_has_string(&states->new,
232-
name))
229+
string_list_has_string(&states->tracked, name) ||
230+
string_list_has_string(&states->new, name))
233231
return 0;
234232
item = string_list_append(name, &states->stale);
235233
item->util = xstrdup(refname);
@@ -258,6 +256,8 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
258256
}
259257
free_refs(fetch_map);
260258

259+
sort_string_list(&states->new);
260+
sort_string_list(&states->tracked);
261261
for_each_ref(handle_one_branch, states);
262262
sort_string_list(&states->stale);
263263

@@ -638,6 +638,9 @@ static int append_ref_to_tracked_list(const char *refname,
638638
struct ref_states *states = cb_data;
639639
struct refspec refspec;
640640

641+
if (flags & REF_ISSYMREF)
642+
return 0;
643+
641644
memset(&refspec, 0, sizeof(refspec));
642645
refspec.dst = (char *)refname;
643646
if (!remote_find_tracking(states->remote, &refspec))
@@ -666,8 +669,10 @@ static int get_remote_ref_states(const char *name,
666669
transport_disconnect(transport);
667670

668671
get_ref_states(remote_refs, states);
669-
} else
672+
} else {
670673
for_each_ref(append_ref_to_tracked_list, states);
674+
sort_string_list(&states->tracked);
675+
}
671676

672677
return 0;
673678
}

t/t5505-remote.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ cat > test/expect << EOF
141141
New remote branch (next fetch will store in remotes/origin)
142142
master
143143
Tracked remote branches
144-
side
145144
master
145+
side
146146
Local branches pushed with 'git push'
147147
master:upstream
148148
+refs/tags/lastbackup

0 commit comments

Comments
 (0)