read-cache: fix index corruption with index v4
[gitweb.git] / submodule-config.c
index 89de1d6a53db0c2222c008f98f2bb61bb9b25df7..bede338c8539f18081168bacd0b562a927e9532c 100644 (file)
@@ -4,6 +4,7 @@
 #include "submodule-config.h"
 #include "submodule.h"
 #include "strbuf.h"
+#include "parse-options.h"
 
 /*
  * submodule cache lookup structure
@@ -33,18 +34,26 @@ enum lookup_type {
        lookup_path
 };
 
-static int config_path_cmp(const struct submodule_entry *a,
-                          const struct submodule_entry *b,
-                          const void *unused)
+static int config_path_cmp(const void *unused_cmp_data,
+                          const void *entry,
+                          const void *entry_or_key,
+                          const void *unused_keydata)
 {
+       const struct submodule_entry *a = entry;
+       const struct submodule_entry *b = entry_or_key;
+
        return strcmp(a->config->path, b->config->path) ||
               hashcmp(a->config->gitmodules_sha1, b->config->gitmodules_sha1);
 }
 
-static int config_name_cmp(const struct submodule_entry *a,
-                          const struct submodule_entry *b,
-                          const void *unused)
+static int config_name_cmp(const void *unused_cmp_data,
+                          const void *entry,
+                          const void *entry_or_key,
+                          const void *unused_keydata)
 {
+       const struct submodule_entry *a = entry;
+       const struct submodule_entry *b = entry_or_key;
+
        return strcmp(a->config->name, b->config->name) ||
               hashcmp(a->config->gitmodules_sha1, b->config->gitmodules_sha1);
 }
@@ -56,8 +65,8 @@ static struct submodule_cache *submodule_cache_alloc(void)
 
 static void submodule_cache_init(struct submodule_cache *cache)
 {
-       hashmap_init(&cache->for_path, (hashmap_cmp_fn) config_path_cmp, 0);
-       hashmap_init(&cache->for_name, (hashmap_cmp_fn) config_name_cmp, 0);
+       hashmap_init(&cache->for_path, config_path_cmp, NULL, 0);
+       hashmap_init(&cache->for_name, config_name_cmp, NULL, 0);
        cache->initialized = 1;
 }
 
@@ -250,6 +259,27 @@ int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg)
        return parse_fetch_recurse(opt, arg, 1);
 }
 
+int option_fetch_parse_recurse_submodules(const struct option *opt,
+                                         const char *arg, int unset)
+{
+       int *v;
+
+       if (!opt->value)
+               return -1;
+
+       v = opt->value;
+
+       if (unset) {
+               *v = RECURSE_SUBMODULES_OFF;
+       } else {
+               if (arg)
+                       *v = parse_fetch_recurse_submodules_arg(opt->long_name, arg);
+               else
+                       *v = RECURSE_SUBMODULES_ON;
+       }
+       return 0;
+}
+
 static int parse_update_recurse(const char *opt, const char *arg,
                                int die_on_error)
 {