]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hashmap_get_next takes "const struct hashmap_entry *"
authorEric Wong <e@80x24.org>
Sun, 6 Oct 2019 23:30:28 +0000 (23:30 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Oct 2019 01:20:10 +0000 (10:20 +0900)
This is less error-prone than "const void *" as the compiler
now detects invalid types being passed.

Signed-off-by: Eric Wong <e@80x24.org>
Reviewed-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff.c
diffcore-rename.c
hashmap.c
hashmap.h
name-hash.c
t/helper/test-hashmap.c

diff --git a/diff.c b/diff.c
index 02491ee68481e99fb178cac93ab0631b12dbca8e..1168f0cbb94c00ce78ad5c2721a3c6a6151d3946 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1036,7 +1036,7 @@ static void pmb_advance_or_null_multi_match(struct diff_options *o,
        int i;
        char *got_match = xcalloc(1, pmb_nr);
 
-       for (; match; match = hashmap_get_next(hm, match)) {
+       for (; match; match = hashmap_get_next(hm, &match->ent)) {
                for (i = 0; i < pmb_nr; i++) {
                        struct moved_entry *prev = pmb[i].match;
                        struct moved_entry *cur = (prev && prev->next_line) ?
@@ -1189,7 +1189,8 @@ static void mark_color_as_moved(struct diff_options *o,
                         * The current line is the start of a new block.
                         * Setup the set of potential blocks.
                         */
-                       for (; match; match = hashmap_get_next(hm, match)) {
+                       for (; match; match = hashmap_get_next(hm,
+                                                               &match->ent)) {
                                ALLOC_GROW(pmb, pmb_nr + 1, pmb_alloc);
                                if (o->color_moved_ws_handling &
                                    COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) {
index 44a3ab1e3165c5f2ec5debf8fc78f9b1db7f0060..2a1449013bf58a2e64ef4abc261baf39220f4c07 100644 (file)
@@ -285,7 +285,7 @@ static int find_identical_files(struct hashmap *srcs,
        p = hashmap_get_from_hash(srcs,
                                  hash_filespec(options->repo, target),
                                  NULL);
-       for (; p; p = hashmap_get_next(srcs, p)) {
+       for (; p; p = hashmap_get_next(srcs, &p->entry)) {
                int score;
                struct diff_filespec *source = p->filespec;
 
index 6818c65174869406f57fc0cea79fda4af8c63938..c1de40eea0aa1e1f5b99d7626c0f6988b6ba2ffc 100644 (file)
--- a/hashmap.c
+++ b/hashmap.c
@@ -191,9 +191,10 @@ void *hashmap_get(const struct hashmap *map, const void *key, const void *keydat
        return *find_entry_ptr(map, key, keydata);
 }
 
-void *hashmap_get_next(const struct hashmap *map, const void *entry)
+void *hashmap_get_next(const struct hashmap *map,
+                       const struct hashmap_entry *entry)
 {
-       struct hashmap_entry *e = ((struct hashmap_entry *) entry)->next;
+       struct hashmap_entry *e = entry->next;
        for (; e; e = e->next)
                if (entry_equals(map, entry, e, NULL))
                        return e;
index 54b0b8c698013ff56372c51af4cad3ee28b97cd9..93fb9599ca9ad3f7aa77dd308086386cccccf49d 100644 (file)
--- a/hashmap.h
+++ b/hashmap.h
@@ -318,7 +318,8 @@ static inline void *hashmap_get_from_hash(const struct hashmap *map,
  * `entry` is the hashmap_entry to start the search from, obtained via a previous
  * call to `hashmap_get` or `hashmap_get_next`.
  */
-void *hashmap_get_next(const struct hashmap *map, const void *entry);
+void *hashmap_get_next(const struct hashmap *map,
+                       const struct hashmap_entry *entry);
 
 /*
  * Adds a hashmap entry. This allows to add duplicate entries (i.e.
index 1ce1417f7edc5a3be97fb63fbe704705f46ca2ee..4d84326c5809de3531c4d33ad9633ac2c0507e8e 100644 (file)
@@ -710,7 +710,7 @@ struct cache_entry *index_file_exists(struct index_state *istate, const char *na
        while (ce) {
                if (same_name(ce, name, namelen, icase))
                        return ce;
-               ce = hashmap_get_next(&istate->name_hash, ce);
+               ce = hashmap_get_next(&istate->name_hash, &ce->ent);
        }
        return NULL;
 }
index 0c9fd7c9962c0b3d103e85f4cdf02387fc8f3cbc..bf063a2521c166ce3c691cf73b39852309465bfa 100644 (file)
@@ -203,7 +203,7 @@ int cmd__hashmap(int argc, const char **argv)
                                puts("NULL");
                        while (entry) {
                                puts(get_value(entry));
-                               entry = hashmap_get_next(&map, entry);
+                               entry = hashmap_get_next(&map, &entry->ent);
                        }
 
                } else if (!strcmp("remove", cmd) && p1) {