MCPcopy Create free account
hub / github.com/git/git / sort_ref_dir

Function sort_ref_dir

refs/ref-cache.c:224–247  ·  view source on GitHub ↗

* Sort the entries in dir non-recursively (if they are not already * sorted) and remove any duplicate entries. */

Source from the content-addressed store, hash-verified

222 * sorted) and remove any duplicate entries.
223 */
224static 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
249enum prefix_state {
250 /* All refs within the directory would match prefix: */

Callers 3

search_ref_dirFunction · 0.85
cache_ref_iterator_seekFunction · 0.85

Calls 2

is_dup_refFunction · 0.85
free_ref_entryFunction · 0.85

Tested by

no test coverage detected