* Sort the entries in dir non-recursively (if they are not already * sorted) and remove any duplicate entries. */
| 222 | * sorted) and remove any duplicate entries. |
| 223 | */ |
| 224 | static void sort_ref_dir(struct ref_dir *dir) |
| 225 | { |
| 226 | int i, j; |
| 227 | struct ref_entry *last = NULL; |
| 228 | |
| 229 | /* |
| 230 | * This check also prevents passing a zero-length array to qsort(), |
| 231 | * which is a problem on some platforms. |
| 232 | */ |
| 233 | if (dir->sorted == dir->nr) |
| 234 | return; |
| 235 | |
| 236 | QSORT(dir->entries, dir->nr, ref_entry_cmp); |
| 237 | |
| 238 | /* Remove any duplicates: */ |
| 239 | for (i = 0, j = 0; j < dir->nr; j++) { |
| 240 | struct ref_entry *entry = dir->entries[j]; |
| 241 | if (last && is_dup_ref(last, entry)) |
| 242 | free_ref_entry(entry); |
| 243 | else |
| 244 | last = dir->entries[i++] = entry; |
| 245 | } |
| 246 | dir->sorted = dir->nr = i; |
| 247 | } |
| 248 | |
| 249 | enum prefix_state { |
| 250 | /* All refs within the directory would match prefix: */ |
no test coverage detected