Git fork

Merge branch 'jk/oidmap-cleanup'

Code cleanup.

* jk/oidmap-cleanup:
raw_object_store: drop extra pointer to replace_map
oidmap: add size function
oidmap: rename oidmap_free() to oidmap_clear()

+21 -18
+1 -1
builtin/rev-list.c
··· 924 free((void *)entry->path); 925 } 926 927 - oidmap_free(&missing_objects, true); 928 } 929 930 stop_progress(&progress);
··· 924 free((void *)entry->path); 925 } 926 927 + oidmap_clear(&missing_objects, true); 928 } 929 930 stop_progress(&progress);
+1 -1
commit-graph.c
··· 222 223 if (replace_refs_enabled(r)) { 224 prepare_replace_object(r); 225 - if (hashmap_get_size(&r->objects->replace_map->map)) 226 return 0; 227 } 228
··· 222 223 if (replace_refs_enabled(r)) { 224 prepare_replace_object(r); 225 + if (oidmap_get_size(&r->objects->replace_map)) 226 return 0; 227 } 228
+1 -1
list-objects-filter.c
··· 244 struct filter_trees_depth_data *d = filter_data; 245 if (!d) 246 return; 247 - oidmap_free(&d->seen_at_depth, 1); 248 free(d); 249 } 250
··· 244 struct filter_trees_depth_data *d = filter_data; 245 if (!d) 246 return; 247 + oidmap_clear(&d->seen_at_depth, 1); 248 free(d); 249 } 250
+1 -2
object-store.c
··· 987 { 988 FREE_AND_NULL(o->alternate_db); 989 990 - oidmap_free(o->replace_map, 1); 991 - FREE_AND_NULL(o->replace_map); 992 pthread_mutex_destroy(&o->replace_mutex); 993 994 free_commit_graph(o->commit_graph);
··· 987 { 988 FREE_AND_NULL(o->alternate_db); 989 990 + oidmap_clear(&o->replace_map, 1); 991 pthread_mutex_destroy(&o->replace_mutex); 992 993 free_commit_graph(o->commit_graph);
+2 -1
object-store.h
··· 5 #include "object.h" 6 #include "list.h" 7 #include "oidset.h" 8 #include "thread-utils.h" 9 10 struct oidmap; ··· 109 * Objects that should be substituted by other objects 110 * (see git-replace(1)). 111 */ 112 - struct oidmap *replace_map; 113 unsigned replace_map_initialized : 1; 114 pthread_mutex_t replace_mutex; /* protect object replace functions */ 115
··· 5 #include "object.h" 6 #include "list.h" 7 #include "oidset.h" 8 + #include "oidmap.h" 9 #include "thread-utils.h" 10 11 struct oidmap; ··· 110 * Objects that should be substituted by other objects 111 * (see git-replace(1)). 112 */ 113 + struct oidmap replace_map; 114 unsigned replace_map_initialized : 1; 115 pthread_mutex_t replace_mutex; /* protect object replace functions */ 116
+1 -1
oidmap.c
··· 22 hashmap_init(&map->map, oidmap_neq, NULL, initial_size); 23 } 24 25 - void oidmap_free(struct oidmap *map, int free_entries) 26 { 27 if (!map) 28 return;
··· 22 hashmap_init(&map->map, oidmap_neq, NULL, initial_size); 23 } 24 25 + void oidmap_clear(struct oidmap *map, int free_entries) 26 { 27 if (!map) 28 return;
+7 -2
oidmap.h
··· 36 void oidmap_init(struct oidmap *map, size_t initial_size); 37 38 /* 39 - * Frees an oidmap structure and allocated memory. 40 * 41 * If `free_entries` is true, each oidmap_entry in the map is freed as well 42 * using stdlibs free(). 43 */ 44 - void oidmap_free(struct oidmap *map, int free_entries); 45 46 /* 47 * Returns the oidmap entry for the specified oid, or NULL if not found. ··· 66 */ 67 void *oidmap_remove(struct oidmap *map, const struct object_id *key); 68 69 70 struct oidmap_iter { 71 struct hashmap_iter h_iter;
··· 36 void oidmap_init(struct oidmap *map, size_t initial_size); 37 38 /* 39 + * Clear an oidmap, freeing any allocated memory. The map is empty and 40 + * can be reused without another explicit init. 41 * 42 * If `free_entries` is true, each oidmap_entry in the map is freed as well 43 * using stdlibs free(). 44 */ 45 + void oidmap_clear(struct oidmap *map, int free_entries); 46 47 /* 48 * Returns the oidmap entry for the specified oid, or NULL if not found. ··· 67 */ 68 void *oidmap_remove(struct oidmap *map, const struct object_id *key); 69 70 + static inline unsigned int oidmap_get_size(struct oidmap *map) 71 + { 72 + return hashmap_get_size(&map->map); 73 + } 74 75 struct oidmap_iter { 76 struct hashmap_iter h_iter;
+3 -5
replace-object.c
··· 31 oidcpy(&repl_obj->replacement, oid); 32 33 /* Register new object */ 34 - if (oidmap_put(r->objects->replace_map, repl_obj)) 35 die(_("duplicate replace ref: %s"), refname); 36 37 return 0; ··· 48 return; 49 } 50 51 - r->objects->replace_map = 52 - xmalloc(sizeof(*r->objects->replace_map)); 53 - oidmap_init(r->objects->replace_map, 0); 54 55 refs_for_each_replace_ref(get_main_ref_store(r), 56 register_replace_ref, r); ··· 80 /* Try to recursively replace the object */ 81 while (depth-- > 0) { 82 struct replace_object *repl_obj = 83 - oidmap_get(r->objects->replace_map, cur); 84 if (!repl_obj) 85 return cur; 86 cur = &repl_obj->replacement;
··· 31 oidcpy(&repl_obj->replacement, oid); 32 33 /* Register new object */ 34 + if (oidmap_put(&r->objects->replace_map, repl_obj)) 35 die(_("duplicate replace ref: %s"), refname); 36 37 return 0; ··· 48 return; 49 } 50 51 + oidmap_init(&r->objects->replace_map, 0); 52 53 refs_for_each_replace_ref(get_main_ref_store(r), 54 register_replace_ref, r); ··· 78 /* Try to recursively replace the object */ 79 while (depth-- > 0) { 80 struct replace_object *repl_obj = 81 + oidmap_get(&r->objects->replace_map, cur); 82 if (!repl_obj) 83 return cur; 84 cur = &repl_obj->replacement;
+1 -1
replace-object.h
··· 47 { 48 if (!replace_refs_enabled(r) || 49 (r->objects->replace_map_initialized && 50 - r->objects->replace_map->map.tablesize == 0)) 51 return oid; 52 return do_lookup_replace_object(r, oid); 53 }
··· 47 { 48 if (!replace_refs_enabled(r) || 49 (r->objects->replace_map_initialized && 50 + oidmap_get_size(&r->objects->replace_map) == 0)) 51 return oid; 52 return do_lookup_replace_object(r, oid); 53 }
+2 -2
sequencer.c
··· 6051 oidset_clear(&interesting); 6052 oidset_clear(&child_seen); 6053 oidset_clear(&shown); 6054 - oidmap_free(&commit2todo, 1); 6055 - oidmap_free(&state.commit2label, 1); 6056 hashmap_clear_and_free(&state.labels, struct labels_entry, entry); 6057 strbuf_release(&state.buf); 6058
··· 6051 oidset_clear(&interesting); 6052 oidset_clear(&child_seen); 6053 oidset_clear(&shown); 6054 + oidmap_clear(&commit2todo, 1); 6055 + oidmap_clear(&state.commit2label, 1); 6056 hashmap_clear_and_free(&state.labels, struct labels_entry, entry); 6057 strbuf_release(&state.buf); 6058
+1 -1
t/unit-tests/u-oidmap.c
··· 35 36 void test_oidmap__cleanup(void) 37 { 38 - oidmap_free(&map, 1); 39 } 40 41 void test_oidmap__replace(void)
··· 35 36 void test_oidmap__cleanup(void) 37 { 38 + oidmap_clear(&map, 1); 39 } 40 41 void test_oidmap__replace(void)