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()
This commit is contained in:
Junio C Hamano 2025-05-19 16:02:47 -07:00
commit a9dcacbf2a
11 changed files with 21 additions and 18 deletions

View File

@ -924,7 +924,7 @@ int cmd_rev_list(int argc,
free((void *)entry->path);
}
oidmap_free(&missing_objects, true);
oidmap_clear(&missing_objects, true);
}
stop_progress(&progress);

View File

@ -222,7 +222,7 @@ static int commit_graph_compatible(struct repository *r)
if (replace_refs_enabled(r)) {
prepare_replace_object(r);
if (hashmap_get_size(&r->objects->replace_map->map))
if (oidmap_get_size(&r->objects->replace_map))
return 0;
}

View File

@ -244,7 +244,7 @@ static void filter_trees_free(void *filter_data) {
struct filter_trees_depth_data *d = filter_data;
if (!d)
return;
oidmap_free(&d->seen_at_depth, 1);
oidmap_clear(&d->seen_at_depth, 1);
free(d);
}

View File

@ -987,8 +987,7 @@ void raw_object_store_clear(struct raw_object_store *o)
{
FREE_AND_NULL(o->alternate_db);
oidmap_free(o->replace_map, 1);
FREE_AND_NULL(o->replace_map);
oidmap_clear(&o->replace_map, 1);
pthread_mutex_destroy(&o->replace_mutex);
free_commit_graph(o->commit_graph);

View File

@ -5,6 +5,7 @@
#include "object.h"
#include "list.h"
#include "oidset.h"
#include "oidmap.h"
#include "thread-utils.h"
struct oidmap;
@ -109,7 +110,7 @@ struct raw_object_store {
* Objects that should be substituted by other objects
* (see git-replace(1)).
*/
struct oidmap *replace_map;
struct oidmap replace_map;
unsigned replace_map_initialized : 1;
pthread_mutex_t replace_mutex; /* protect object replace functions */

View File

@ -22,7 +22,7 @@ void oidmap_init(struct oidmap *map, size_t initial_size)
hashmap_init(&map->map, oidmap_neq, NULL, initial_size);
}
void oidmap_free(struct oidmap *map, int free_entries)
void oidmap_clear(struct oidmap *map, int free_entries)
{
if (!map)
return;

View File

@ -36,12 +36,13 @@ struct oidmap {
void oidmap_init(struct oidmap *map, size_t initial_size);
/*
* Frees an oidmap structure and allocated memory.
* Clear an oidmap, freeing any allocated memory. The map is empty and
* can be reused without another explicit init.
*
* If `free_entries` is true, each oidmap_entry in the map is freed as well
* using stdlibs free().
*/
void oidmap_free(struct oidmap *map, int free_entries);
void oidmap_clear(struct oidmap *map, int free_entries);
/*
* Returns the oidmap entry for the specified oid, or NULL if not found.
@ -66,6 +67,10 @@ void *oidmap_put(struct oidmap *map, void *entry);
*/
void *oidmap_remove(struct oidmap *map, const struct object_id *key);
static inline unsigned int oidmap_get_size(struct oidmap *map)
{
return hashmap_get_size(&map->map);
}
struct oidmap_iter {
struct hashmap_iter h_iter;

View File

@ -31,7 +31,7 @@ static int register_replace_ref(const char *refname,
oidcpy(&repl_obj->replacement, oid);
/* Register new object */
if (oidmap_put(r->objects->replace_map, repl_obj))
if (oidmap_put(&r->objects->replace_map, repl_obj))
die(_("duplicate replace ref: %s"), refname);
return 0;
@ -48,9 +48,7 @@ void prepare_replace_object(struct repository *r)
return;
}
r->objects->replace_map =
xmalloc(sizeof(*r->objects->replace_map));
oidmap_init(r->objects->replace_map, 0);
oidmap_init(&r->objects->replace_map, 0);
refs_for_each_replace_ref(get_main_ref_store(r),
register_replace_ref, r);
@ -80,7 +78,7 @@ const struct object_id *do_lookup_replace_object(struct repository *r,
/* Try to recursively replace the object */
while (depth-- > 0) {
struct replace_object *repl_obj =
oidmap_get(r->objects->replace_map, cur);
oidmap_get(&r->objects->replace_map, cur);
if (!repl_obj)
return cur;
cur = &repl_obj->replacement;

View File

@ -47,7 +47,7 @@ static inline const struct object_id *lookup_replace_object(struct repository *r
{
if (!replace_refs_enabled(r) ||
(r->objects->replace_map_initialized &&
r->objects->replace_map->map.tablesize == 0))
oidmap_get_size(&r->objects->replace_map) == 0))
return oid;
return do_lookup_replace_object(r, oid);
}

View File

@ -6051,8 +6051,8 @@ static int make_script_with_merges(struct pretty_print_context *pp,
oidset_clear(&interesting);
oidset_clear(&child_seen);
oidset_clear(&shown);
oidmap_free(&commit2todo, 1);
oidmap_free(&state.commit2label, 1);
oidmap_clear(&commit2todo, 1);
oidmap_clear(&state.commit2label, 1);
hashmap_clear_and_free(&state.labels, struct labels_entry, entry);
strbuf_release(&state.buf);

View File

@ -35,7 +35,7 @@ void test_oidmap__initialize(void)
void test_oidmap__cleanup(void)
{
oidmap_free(&map, 1);
oidmap_clear(&map, 1);
}
void test_oidmap__replace(void)