submodule: fix NULL correctness in renamed broken submodules
[gitweb.git] / attr.c
diff --git a/attr.c b/attr.c
index 56961f02361129b5cb49e6ffb7ab185655f09c41..067fb9e0c08cefa2ba1a9b1d3444938c9bab6e3d 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -10,7 +10,7 @@
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
-#include "exec_cmd.h"
+#include "exec-cmd.h"
 #include "attr.h"
 #include "dir.h"
 #include "utf8.h"
@@ -76,18 +76,20 @@ struct attr_hash_entry {
 };
 
 /* attr_hashmap comparison function */
-static int attr_hash_entry_cmp(void *unused_cmp_data,
-                              const struct attr_hash_entry *a,
-                              const struct attr_hash_entry *b,
-                              void *unused_keydata)
+static int attr_hash_entry_cmp(const void *unused_cmp_data,
+                              const void *entry,
+                              const void *entry_or_key,
+                              const void *unused_keydata)
 {
+       const struct attr_hash_entry *a = entry;
+       const struct attr_hash_entry *b = entry_or_key;
        return (a->keylen != b->keylen) || strncmp(a->key, b->key, a->keylen);
 }
 
 /* Initialize an 'attr_hashmap' object */
 static void attr_hashmap_init(struct attr_hashmap *map)
 {
-       hashmap_init(&map->map, (hashmap_cmp_fn) attr_hash_entry_cmp, NULL, 0);
+       hashmap_init(&map->map, attr_hash_entry_cmp, NULL, 0);
 }
 
 /*
@@ -149,11 +151,13 @@ struct all_attrs_item {
 static void all_attrs_init(struct attr_hashmap *map, struct attr_check *check)
 {
        int i;
+       unsigned int size;
 
        hashmap_lock(map);
 
-       if (map->map.size < check->all_attrs_nr)
-               die("BUG: interned attributes shouldn't be deleted");
+       size = hashmap_get_size(&map->map);
+       if (size < check->all_attrs_nr)
+               BUG("interned attributes shouldn't be deleted");
 
        /*
         * If the number of attributes in the global dictionary has increased
@@ -161,13 +165,13 @@ static void all_attrs_init(struct attr_hashmap *map, struct attr_check *check)
         * field), reallocate the provided attr_check instance's all_attrs
         * field and fill each entry with its corresponding git_attr.
         */
-       if (map->map.size != check->all_attrs_nr) {
+       if (size != check->all_attrs_nr) {
                struct attr_hash_entry *e;
                struct hashmap_iter iter;
                hashmap_iter_init(&map->map, &iter);
 
-               REALLOC_ARRAY(check->all_attrs, map->map.size);
-               check->all_attrs_nr = map->map.size;
+               REALLOC_ARRAY(check->all_attrs, size);
+               check->all_attrs_nr = size;
 
                while ((e = hashmap_iter_next(&iter))) {
                        const struct git_attr *a = e->value;
@@ -235,10 +239,11 @@ static const struct git_attr *git_attr_internal(const char *name, int namelen)
 
        if (!a) {
                FLEX_ALLOC_MEM(a, name, name, namelen);
-               a->attr_nr = g_attr_hashmap.map.size;
+               a->attr_nr = hashmap_get_size(&g_attr_hashmap.map);
 
                attr_hashmap_add(&g_attr_hashmap, a->name, namelen, a);
-               assert(a->attr_nr == (g_attr_hashmap.map.size - 1));
+               assert(a->attr_nr ==
+                      (hashmap_get_size(&g_attr_hashmap.map) - 1));
        }
 
        hashmap_unlock(&g_attr_hashmap);
@@ -536,7 +541,7 @@ static void check_vector_remove(struct attr_check *check)
                        break;
 
        if (i >= check_vector.nr)
-               die("BUG: no entry found");
+               BUG("no entry found");
 
        /* shift entries over */
        for (; i < check_vector.nr - 1; i++)
@@ -594,11 +599,11 @@ struct attr_check *attr_check_initl(const char *one, ...)
                const struct git_attr *attr;
                param = va_arg(params, const char *);
                if (!param)
-                       die("BUG: counted %d != ended at %d",
+                       BUG("counted %d != ended at %d",
                            check->nr, cnt);
                attr = git_attr(param);
                if (!attr)
-                       die("BUG: %s: not a valid attribute name", param);
+                       BUG("%s: not a valid attribute name", param);
                check->items[cnt].attr = attr;
        }
        va_end(params);
@@ -709,7 +714,7 @@ void git_attr_set_direction(enum git_attr_direction new_direction,
                            struct index_state *istate)
 {
        if (is_bare_repository() && new_direction != GIT_ATTR_INDEX)
-               die("BUG: non-INDEX attr direction in a bare repo");
+               BUG("non-INDEX attr direction in a bare repo");
 
        if (new_direction != direction)
                drop_all_attr_stacks();