|
6 | 6 | #include "advice.h"
|
7 | 7 | #include "config.h"
|
8 | 8 | #include "environment.h"
|
9 |
| -#include "hashmap.h" |
| 9 | +#include "strmap.h" |
10 | 10 | #include "gettext.h"
|
11 | 11 | #include "hex.h"
|
12 | 12 | #include "lockfile.h"
|
@@ -1960,66 +1960,27 @@ int resolve_gitlink_ref(const char *submodule, const char *refname,
|
1960 | 1960 | return 0;
|
1961 | 1961 | }
|
1962 | 1962 |
|
1963 |
| -struct ref_store_hash_entry |
1964 |
| -{ |
1965 |
| - struct hashmap_entry ent; |
1966 |
| - |
1967 |
| - struct ref_store *refs; |
1968 |
| - |
1969 |
| - /* NUL-terminated identifier of the ref store: */ |
1970 |
| - char name[FLEX_ARRAY]; |
1971 |
| -}; |
| 1963 | +/* A strmap of ref_stores, stored by submodule name: */ |
| 1964 | +static struct strmap submodule_ref_stores; |
1972 | 1965 |
|
1973 |
| -static int ref_store_hash_cmp(const void *cmp_data UNUSED, |
1974 |
| - const struct hashmap_entry *eptr, |
1975 |
| - const struct hashmap_entry *entry_or_key, |
1976 |
| - const void *keydata) |
1977 |
| -{ |
1978 |
| - const struct ref_store_hash_entry *e1, *e2; |
1979 |
| - const char *name; |
1980 |
| - |
1981 |
| - e1 = container_of(eptr, const struct ref_store_hash_entry, ent); |
1982 |
| - e2 = container_of(entry_or_key, const struct ref_store_hash_entry, ent); |
1983 |
| - name = keydata ? keydata : e2->name; |
1984 |
| - |
1985 |
| - return strcmp(e1->name, name); |
1986 |
| -} |
1987 |
| - |
1988 |
| -static struct ref_store_hash_entry *alloc_ref_store_hash_entry( |
1989 |
| - const char *name, struct ref_store *refs) |
1990 |
| -{ |
1991 |
| - struct ref_store_hash_entry *entry; |
1992 |
| - |
1993 |
| - FLEX_ALLOC_STR(entry, name, name); |
1994 |
| - hashmap_entry_init(&entry->ent, strhash(name)); |
1995 |
| - entry->refs = refs; |
1996 |
| - return entry; |
1997 |
| -} |
1998 |
| - |
1999 |
| -/* A hashmap of ref_stores, stored by submodule name: */ |
2000 |
| -static struct hashmap submodule_ref_stores; |
2001 |
| - |
2002 |
| -/* A hashmap of ref_stores, stored by worktree id: */ |
2003 |
| -static struct hashmap worktree_ref_stores; |
| 1966 | +/* A strmap of ref_stores, stored by worktree id: */ |
| 1967 | +static struct strmap worktree_ref_stores; |
2004 | 1968 |
|
2005 | 1969 | /*
|
2006 | 1970 | * Look up a ref store by name. If that ref_store hasn't been
|
2007 | 1971 | * registered yet, return NULL.
|
2008 | 1972 | */
|
2009 |
| -static struct ref_store *lookup_ref_store_map(struct hashmap *map, |
| 1973 | +static struct ref_store *lookup_ref_store_map(struct strmap *map, |
2010 | 1974 | const char *name)
|
2011 | 1975 | {
|
2012 |
| - struct ref_store_hash_entry *entry; |
2013 |
| - unsigned int hash; |
| 1976 | + struct strmap_entry *entry; |
2014 | 1977 |
|
2015 |
| - if (!map->tablesize) |
| 1978 | + if (!map->map.tablesize) |
2016 | 1979 | /* It's initialized on demand in register_ref_store(). */
|
2017 | 1980 | return NULL;
|
2018 | 1981 |
|
2019 |
| - hash = strhash(name); |
2020 |
| - entry = hashmap_get_entry_from_hash(map, hash, name, |
2021 |
| - struct ref_store_hash_entry, ent); |
2022 |
| - return entry ? entry->refs : NULL; |
| 1982 | + entry = strmap_get_entry(map, name); |
| 1983 | + return entry ? entry->value : NULL; |
2023 | 1984 | }
|
2024 | 1985 |
|
2025 | 1986 | /*
|
@@ -2064,18 +2025,14 @@ struct ref_store *get_main_ref_store(struct repository *r)
|
2064 | 2025 | * Associate a ref store with a name. It is a fatal error to call this
|
2065 | 2026 | * function twice for the same name.
|
2066 | 2027 | */
|
2067 |
| -static void register_ref_store_map(struct hashmap *map, |
| 2028 | +static void register_ref_store_map(struct strmap *map, |
2068 | 2029 | const char *type,
|
2069 | 2030 | struct ref_store *refs,
|
2070 | 2031 | const char *name)
|
2071 | 2032 | {
|
2072 |
| - struct ref_store_hash_entry *entry; |
2073 |
| - |
2074 |
| - if (!map->tablesize) |
2075 |
| - hashmap_init(map, ref_store_hash_cmp, NULL, 0); |
2076 |
| - |
2077 |
| - entry = alloc_ref_store_hash_entry(name, refs); |
2078 |
| - if (hashmap_put(map, &entry->ent)) |
| 2033 | + if (!map->map.tablesize) |
| 2034 | + strmap_init(map); |
| 2035 | + if (strmap_put(map, name, refs)) |
2079 | 2036 | BUG("%s ref_store '%s' initialized twice", type, name);
|
2080 | 2037 | }
|
2081 | 2038 |
|
|
0 commit comments