From: Junio C Hamano Date: Tue, 15 Oct 2019 04:48:01 +0000 (+0900) Subject: Merge branch 'ew/hashmap' X-Git-Tag: v2.24.0-rc0~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5efabc7ed9e57bb73159d1ad7739c508167ef24a;p=thirdparty%2Fgit.git Merge branch 'ew/hashmap' 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 --- 5efabc7ed9e57bb73159d1ad7739c508167ef24a diff --cc builtin/fetch.c index b0f9473489,a3154a4edb..ef731631c2 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@@ -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 merge-recursive.c index e86571c91b,8787a40b0c..42be7c9960 --- a/merge-recursive.c +++ b/merge-recursive.c @@@ -64,24 -56,6 +66,24 @@@ static unsigned int path_hash(const cha return ignore_case ? strihash(path) : strhash(path); } +/* + * 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; /* must be the first member! */ ++ 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 collision_entry { - struct hashmap_entry ent; /* must be the first member! */ ++ 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);