]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ew/hashmap'
authorJunio C Hamano <gitster@pobox.com>
Tue, 15 Oct 2019 04:48:01 +0000 (13:48 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 15 Oct 2019 04:48:02 +0000 (13:48 +0900)
Code clean-up of the hashmap API, both users and implementation.

* ew/hashmap:
  hashmap_entry: remove first member requirement from docs
  hashmap: remove type arg from hashmap_{get,put,remove}_entry
  OFFSETOF_VAR macro to simplify hashmap iterators
  hashmap: introduce hashmap_free_entries
  hashmap: hashmap_{put,remove} return hashmap_entry *
  hashmap: use *_entry APIs for iteration
  hashmap_cmp_fn takes hashmap_entry params
  hashmap_get{,_from_hash} return "struct hashmap_entry *"
  hashmap: use *_entry APIs to wrap container_of
  hashmap_get_next returns "struct hashmap_entry *"
  introduce container_of macro
  hashmap_put takes "struct hashmap_entry *"
  hashmap_remove takes "const struct hashmap_entry *"
  hashmap_get takes "const struct hashmap_entry *"
  hashmap_add takes "struct hashmap_entry *"
  hashmap_get_next takes "const struct hashmap_entry *"
  hashmap_entry_init takes "struct hashmap_entry *"
  packfile: use hashmap_entry in delta_base_cache_entry
  coccicheck: detect hashmap_entry.hash assignment
  diff: use hashmap_entry_init on moved_entry.ent

15 files changed:
1  2 
attr.c
blame.c
builtin/describe.c
builtin/fast-export.c
builtin/fetch.c
config.c
diff.c
diffcore-rename.c
git-compat-util.h
merge-recursive.c
packfile.c
range-diff.c
ref-filter.c
revision.c
sequencer.c

diff --cc attr.c
Simple merge
diff --cc blame.c
Simple merge
Simple merge
Simple merge
diff --cc builtin/fetch.c
index b0f9473489fd5e4a1485c3e8f4a65b5fda2485ac,a3154a4edb92fbd5fd2595f4d982d25d33798f3e..ef731631c2df2ae89445112f2baee851dbe6bdc2
@@@ -413,9 -401,8 +416,9 @@@ static void find_non_local_tags(const s
                **tail = rm;
                *tail = &rm->next;
        }
-       hashmap_free(&remote_refs, 1);
+       hashmap_free_entries(&remote_refs, struct refname_hash_entry, ent);
        string_list_clear(&remote_refs_list, 0);
 +      oidset_clear(&fetch_oids);
  }
  
  static struct ref *get_ref_map(struct remote *remote,
diff --cc config.c
Simple merge
diff --cc diff.c
Simple merge
Simple merge
Simple merge
index e86571c91be9e82ae9b88371db4c706103e88785,8787a40b0c2525b6b9be7bf1c42b345ed4b36d3c..42be7c9960ad5c02f3968a27977203a638d79bbd
@@@ -64,24 -56,6 +66,24 @@@ static unsigned int path_hash(const cha
        return ignore_case ? strihash(path) : strhash(path);
  }
  
-       struct hashmap_entry ent; /* must be the first member! */
 +/*
 + * For dir_rename_entry, directory names are stored as a full path from the
 + * toplevel of the repository and do not include a trailing '/'.  Also:
 + *
 + *   dir:                original name of directory being renamed
 + *   non_unique_new_dir: if true, could not determine new_dir
 + *   new_dir:            final name of directory being renamed
 + *   possible_new_dirs:  temporary used to help determine new_dir; see comments
 + *                       in get_directory_renames() for details
 + */
 +struct dir_rename_entry {
++      struct hashmap_entry ent;
 +      char *dir;
 +      unsigned non_unique_new_dir:1;
 +      struct strbuf new_dir;
 +      struct string_list possible_new_dirs;
 +};
 +
  static struct dir_rename_entry *dir_rename_find_entry(struct hashmap *hashmap,
                                                      char *dir)
  {
@@@ -120,13 -96,6 +124,13 @@@ static void dir_rename_entry_init(struc
        string_list_init(&entry->possible_new_dirs, 0);
  }
  
-       struct hashmap_entry ent; /* must be the first member! */
 +struct collision_entry {
++      struct hashmap_entry ent;
 +      char *target_file;
 +      struct string_list source_files;
 +      unsigned reported_already:1;
 +};
 +
  static struct collision_entry *collision_find_entry(struct hashmap *hashmap,
                                                    char *target_file)
  {
@@@ -464,8 -463,8 +473,8 @@@ static int save_files_dirs(const struc
        strbuf_addstr(base, path);
  
        FLEX_ALLOC_MEM(entry, path, base->buf, base->len);
-       hashmap_entry_init(entry, path_hash(entry->path));
-       hashmap_add(&opt->priv->current_file_dir_set, entry);
+       hashmap_entry_init(&entry->e, path_hash(entry->path));
 -      hashmap_add(&opt->current_file_dir_set, &entry->e);
++      hashmap_add(&opt->priv->current_file_dir_set, &entry->e);
  
        strbuf_setlen(base, baselen);
        return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
@@@ -743,8 -740,8 +752,8 @@@ static char *unique_path(struct merge_o
        }
  
        FLEX_ALLOC_MEM(entry, path, newpath.buf, newpath.len);
-       hashmap_entry_init(entry, path_hash(entry->path));
-       hashmap_add(&opt->priv->current_file_dir_set, entry);
+       hashmap_entry_init(&entry->e, path_hash(entry->path));
 -      hashmap_add(&opt->current_file_dir_set, &entry->e);
++      hashmap_add(&opt->priv->current_file_dir_set, &entry->e);
        return strbuf_detach(&newpath, NULL);
  }
  
@@@ -3475,7 -3475,8 +3485,8 @@@ static int merge_trees_internal(struct 
                string_list_clear(entries, 1);
                free(entries);
  
-               hashmap_free(&opt->priv->current_file_dir_set, 1);
 -              hashmap_free_entries(&opt->current_file_dir_set,
++              hashmap_free_entries(&opt->priv->current_file_dir_set,
+                                       struct path_hashmap_entry, e);
  
                if (clean < 0) {
                        unpack_trees_finish(opt);
diff --cc packfile.c
Simple merge
diff --cc range-diff.c
Simple merge
diff --cc ref-filter.c
Simple merge
diff --cc revision.c
Simple merge
diff --cc sequencer.c
Simple merge