int remove_entry_from_dir(struct ref_dir *dir, const char *refname) { int refname_len = strlen(refname); int entry_index; struct ref_entry *entry; int is_dir = refname[refname_len - 1] == '/'; if (is_dir) { /* * refname represents a reference directory. Remove * the trailing slash; otherwise we will get the * directory *representing* refname rather than the * one *containing* it. */ char *dirname = xmemdupz(refname, refname_len - 1); dir = find_containing_dir(dir, dirname, 0); free(dirname); } else { dir = find_containing_dir(dir, refname, 0); } if (!dir) return -1; entry_index = search_ref_dir(dir, refname, refname_len); if (entry_index == -1) return -1; entry = dir->entries[entry_index]; MOVE_ARRAY(&dir->entries[entry_index], &dir->entries[entry_index + 1], dir->nr - entry_index - 1); dir->nr--; if (dir->sorted > entry_index) dir->sorted--; free_ref_entry(entry); return dir->nr; }
/* * Clear and free all entries in dir, recursively. */ static void clear_ref_dir(struct ref_dir *dir) { int i; for (i = 0; i < dir->nr; i++) free_ref_entry(dir->entries[i]); FREE_AND_NULL(dir->entries); dir->sorted = dir->nr = dir->alloc = 0; }
void free_ref_dict( ref_entry * * dict ) { ref_entry * wk; ref_entry * wkn; wk = *dict; while( wk != NULL ) { wkn = wk->next; free_ref_entry( dict, wk ); wk = wkn; } *dict = NULL; // dictionary is empty return; }
/* * Sort the entries in dir non-recursively (if they are not already * sorted) and remove any duplicate entries. */ static void sort_ref_dir(struct ref_dir *dir) { int i, j; struct ref_entry *last = NULL; /* * This check also prevents passing a zero-length array to qsort(), * which is a problem on some platforms. */ if (dir->sorted == dir->nr) return; QSORT(dir->entries, dir->nr, 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 last = dir->entries[i++] = entry; } dir->sorted = dir->nr = i; }
void free_ref_cache(struct ref_cache *cache) { free_ref_entry(cache->root); free(cache); }