@@ -141,6 +141,18 @@ static void show_one_commit(struct commit *commit, char **head_name)
141141static char * ref_name [MAX_REVS + 1 ];
142142static int ref_name_cnt ;
143143
144+ static int compare_ref_name (const void * a_ , const void * b_ )
145+ {
146+ const char * const * a = a_ , * const * b = b_ ;
147+ return strcmp (* a , * b );
148+ }
149+
150+ static void sort_ref_range (int bottom , int top )
151+ {
152+ qsort (ref_name + bottom , top - bottom , sizeof (ref_name [0 ]),
153+ compare_ref_name );
154+ }
155+
144156static int append_ref (const char * refname , const unsigned char * sha1 )
145157{
146158 struct commit * commit = lookup_commit_reference_gently (sha1 , 1 );
@@ -161,7 +173,7 @@ static int append_head_ref(const char *refname, const unsigned char *sha1)
161173{
162174 if (strncmp (refname , "refs/heads/" , 11 ))
163175 return 0 ;
164- return append_ref (refname + 5 , sha1 );
176+ return append_ref (refname + 11 , sha1 );
165177}
166178
167179static int append_tag_ref (const char * refname , const unsigned char * sha1 )
@@ -173,10 +185,16 @@ static int append_tag_ref(const char *refname, const unsigned char *sha1)
173185
174186static void snarf_refs (int head , int tag )
175187{
176- if (head )
188+ if (head ) {
189+ int orig_cnt = ref_name_cnt ;
177190 for_each_ref (append_head_ref );
178- if (tag )
191+ sort_ref_range (orig_cnt , ref_name_cnt );
192+ }
193+ if (tag ) {
194+ int orig_cnt = ref_name_cnt ;
179195 for_each_ref (append_tag_ref );
196+ sort_ref_range (orig_cnt , ref_name_cnt );
197+ }
180198}
181199
182200static int rev_is_head (char * head_path , int headlen ,
0 commit comments