grep: recurse in-process using 'struct repository'
[gitweb.git] / name-hash.c
index cac313c78d3fa7aba7a7ad6ea6cf5f6fd10a6445..0e10f3eab804cdc08d3a2f97021e8b18edcb552a 100644 (file)
@@ -16,8 +16,10 @@ struct dir_entry {
        char name[FLEX_ARRAY];
 };
 
-static int dir_entry_cmp(const struct dir_entry *e1,
-               const struct dir_entry *e2, const char *name)
+static int dir_entry_cmp(const void *unused_cmp_data,
+                        const struct dir_entry *e1,
+                        const struct dir_entry *e2,
+                        const char *name)
 {
        return e1->namelen != e2->namelen || strncasecmp(e1->name,
                        name ? name : e2->name, e1->namelen);
@@ -107,8 +109,10 @@ static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
                add_dir_entry(istate, ce);
 }
 
-static int cache_entry_cmp(const struct cache_entry *ce1,
-               const struct cache_entry *ce2, const void *remove)
+static int cache_entry_cmp(const void *unused_cmp_data,
+                          const struct cache_entry *ce1,
+                          const struct cache_entry *ce2,
+                          const void *remove)
 {
        /*
         * For remove_name_hash, find the exact entry (pointer equality); for
@@ -342,7 +346,9 @@ static int handle_range_dir(
         * Scan forward in the index array for index entries having the same
         * path prefix (that are also in this directory).
         */
-       if (strncmp(istate->cache[k_start + 1]->name, prefix->buf, prefix->len) > 0)
+       if (k_start + 1 >= k_end)
+               k = k_end;
+       else if (strncmp(istate->cache[k_start + 1]->name, prefix->buf, prefix->len) > 0)
                k = k_start + 1;
        else if (strncmp(istate->cache[k_end - 1]->name, prefix->buf, prefix->len) == 0)
                k = k_end;
@@ -569,9 +575,9 @@ static void lazy_init_name_hash(struct index_state *istate)
        if (istate->name_hash_initialized)
                return;
        hashmap_init(&istate->name_hash, (hashmap_cmp_fn) cache_entry_cmp,
-                       istate->cache_nr);
+                       NULL, istate->cache_nr);
        hashmap_init(&istate->dir_hash, (hashmap_cmp_fn) dir_entry_cmp,
-                       istate->cache_nr);
+                       NULL, istate->cache_nr);
 
        if (lookup_lazy_params(istate)) {
                hashmap_disallow_rehash(&istate->dir_hash, 1);