diff --git a/refs.c b/refs.c index 2d5c827..2fd3db2 100644 --- a/refs.c +++ b/refs.c @@ -457,7 +457,6 @@ static int is_dup_ref(const struct ref_entry *ref1, const struct ref_entry *ref2 */ static void sort_ref_dir(struct ref_entry *direntry) { - int i, j; struct ref_entry *last = NULL; struct ref_dir *dir; assert(direntry->flag & REF_DIR); @@ -468,19 +467,24 @@ static void sort_ref_dir(struct ref_entry *direntry) qsort(dir->entries, dir->nr, sizeof(*dir->entries), ref_entry_cmp); - /* Remove any duplicates: */ - for (i = 0, j = 0; j < dir->nr; j++) { - struct ref_entry *entry = dir->entries[j]; - if (last && is_dup_ref(last, entry)) { - free_ref_entry(entry); - } else if (entry->flag & REF_DIR) { - dir->entries[i++] = entry; - last = NULL; - } else { - last = dir->entries[i++] = entry; + /* Remove any duplicates, but not for extra_refs: */ + if (dir->ref_cache != NULL) { + int i, j; + for (i = 0, j = 0; j < dir->nr; j++) { + struct ref_entry *entry = dir->entries[j]; + if (last && is_dup_ref(last, entry)) { + free_ref_entry(entry); + } else if (entry->flag & REF_DIR) { + dir->entries[i++] = entry; + last = NULL; + } else { + last = dir->entries[i++] = entry; + } } + dir->nr = i; } - dir->sorted = dir->nr = i; + + dir->sorted = dir->nr; } #define DO_FOR_EACH_INCLUDE_BROKEN 01