@@ -227,11 +227,13 @@ static int is_dup_ref(const struct ref_entry *ref1, const struct ref_entry *ref2
227
227
}
228
228
229
229
/*
230
- * Sort the entries in dir (if they are not already sorted).
230
+ * Sort the entries in dir (if they are not already sorted)
231
+ * and remove any duplicate entries.
231
232
*/
232
233
static void sort_ref_dir (struct ref_dir * dir )
233
234
{
234
235
int i , j ;
236
+ struct ref_entry * last = NULL ;
235
237
236
238
/*
237
239
* This check also prevents passing a zero-length array to qsort(),
@@ -242,16 +244,15 @@ static void sort_ref_dir(struct ref_dir *dir)
242
244
243
245
qsort (dir -> entries , dir -> nr , sizeof (* dir -> entries ), ref_entry_cmp );
244
246
245
- /* Remove any duplicates from the ref_dir */
246
- i = 0 ;
247
- for (j = 1 ; j < dir -> nr ; j ++ ) {
248
- if (is_dup_ref (dir -> entries [i ], dir -> entries [j ])) {
249
- free_ref_entry (dir -> entries [j ]);
250
- continue ;
251
- }
252
- dir -> entries [++ i ] = dir -> entries [j ];
247
+ /* Remove any duplicates: */
248
+ for (i = 0 , j = 0 ; j < dir -> nr ; j ++ ) {
249
+ struct ref_entry * entry = dir -> entries [j ];
250
+ if (last && is_dup_ref (last , entry ))
251
+ free_ref_entry (entry );
252
+ else
253
+ last = dir -> entries [i ++ ] = entry ;
253
254
}
254
- dir -> sorted = dir -> nr = i + 1 ;
255
+ dir -> sorted = dir -> nr = i ;
255
256
}
256
257
257
258
#define DO_FOR_EACH_INCLUDE_BROKEN 01
0 commit comments