{"thread":{"id":"56183","subject":"[PATCH] use fspathhash() everywhere","startedAt":"2021-07-30T19:07:08Z","lastAt":"2021-07-30T20:27:53Z","messageCount":3,"participants":["René Scharfe","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"431599","messageId":"b85ed04f-ef9c-f460-e21b-bd1f8dfba9e2@web.de","threadId":"56183","inReplyTo":null,"subject":"[PATCH] use fspathhash() everywhere","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2021-07-30T19:06:58Z","receivedAt":"2021-07-30T19:07:08Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"cf2dc1c238 (speed up alt_odb_usable() with many alternates, 2021-07-07)\nintroduced the function fspathhash() for calculating path hashes while\nrespecting the configuration option core.ignorecase.  Call it instead of\nopen-coding it; the resulting code is shorter and less repetitive.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n builtin/sparse-checkout.c | 10 ++--------\n dir.c                     | 13 +++----------\n merge-recursive.c         | 11 +++--------\n 3 files changed, 8 insertions(+), 26 deletions(-)\n\ndiff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c\nindex a4bdd7c494..8ba9f13787 100644\n--- a/builtin/sparse-checkout.c\n+++ b/builtin/sparse-checkout.c\n@@ -380,10 +380,7 @@ static void insert_recursive_pattern(struct pattern_list *pl, struct strbuf *pat\n \tstruct pattern_entry *e = xmalloc(sizeof(*e));\n \te->patternlen = path->len;\n \te->pattern = strbuf_detach(path, NULL);\n-\thashmap_entry_init(&e->ent,\n-\t\t\t   ignore_case ?\n-\t\t\t   strihash(e->pattern) :\n-\t\t\t   strhash(e->pattern));\n+\thashmap_entry_init(&e->ent, fspathhash(e->pattern));\n\n \thashmap_add(&pl->recursive_hashmap, &e->ent);\n\n@@ -399,10 +396,7 @@ static void insert_recursive_pattern(struct pattern_list *pl, struct strbuf *pat\n \t\te = xmalloc(sizeof(struct pattern_entry));\n \t\te->patternlen = newlen;\n \t\te->pattern = xstrndup(oldpattern, newlen);\n-\t\thashmap_entry_init(&e->ent,\n-\t\t\t\t   ignore_case ?\n-\t\t\t\t   strihash(e->pattern) :\n-\t\t\t\t   strhash(e->pattern));\n+\t\thashmap_entry_init(&e->ent, fspathhash(e->pattern));\n\n \t\tif (!hashmap_get_entry(&pl->parent_hashmap, e, ent, NULL))\n \t\t\thashmap_add(&pl->parent_hashmap, &e->ent);\ndiff --git a/dir.c b/dir.c\nindex 23b4417268..03c4d21267 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -782,9 +782,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern\n \t\ttranslated->pattern = truncated;\n \t\ttranslated->patternlen = given->patternlen - 2;\n \t\thashmap_entry_init(&translated->ent,\n-\t\t\t\t   ignore_case ?\n-\t\t\t\t   strihash(translated->pattern) :\n-\t\t\t\t   strhash(translated->pattern));\n+\t\t\t\t   fspathhash(translated->pattern));\n\n \t\tif (!hashmap_get_entry(&pl->recursive_hashmap,\n \t\t\t\t       translated, ent, NULL)) {\n@@ -813,9 +811,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern\n \ttranslated->pattern = dup_and_filter_pattern(given->pattern);\n \ttranslated->patternlen = given->patternlen;\n \thashmap_entry_init(&translated->ent,\n-\t\t\t   ignore_case ?\n-\t\t\t   strihash(translated->pattern) :\n-\t\t\t   strhash(translated->pattern));\n+\t\t\t   fspathhash(translated->pattern));\n\n \thashmap_add(&pl->recursive_hashmap, &translated->ent);\n\n@@ -845,10 +841,7 @@ static int hashmap_contains_path(struct hashmap *map,\n \t/* Check straight mapping */\n \tp.pattern = pattern->buf;\n \tp.patternlen = pattern->len;\n-\thashmap_entry_init(&p.ent,\n-\t\t\t   ignore_case ?\n-\t\t\t   strihash(p.pattern) :\n-\t\t\t   strhash(p.pattern));\n+\thashmap_entry_init(&p.ent, fspathhash(p.pattern));\n \treturn !!hashmap_get_entry(map, &p, ent, NULL);\n }\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 7008a90df5..3355d50e8a 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -61,11 +61,6 @@ static int path_hashmap_cmp(const void *cmp_data,\n \t\treturn strcmp(a->path, key ? key : b->path);\n }\n\n-static unsigned int path_hash(const char *path)\n-{\n-\treturn ignore_case ? strihash(path) : strhash(path);\n-}\n-\n /*\n  * For dir_rename_entry, directory names are stored as a full path from the\n  * toplevel of the repository and do not include a trailing '/'.  Also:\n@@ -463,7 +458,7 @@ static int save_files_dirs(const struct object_id *oid,\n \tstrbuf_addstr(base, path);\n\n \tFLEX_ALLOC_MEM(entry, path, base->buf, base->len);\n-\thashmap_entry_init(&entry->e, path_hash(entry->path));\n+\thashmap_entry_init(&entry->e, fspathhash(entry->path));\n \thashmap_add(&opt->priv->current_file_dir_set, &entry->e);\n\n \tstrbuf_setlen(base, baselen);\n@@ -737,14 +732,14 @@ static char *unique_path(struct merge_options *opt,\n\n \tbase_len = newpath.len;\n \twhile (hashmap_get_from_hash(&opt->priv->current_file_dir_set,\n-\t\t\t\t     path_hash(newpath.buf), newpath.buf) ||\n+\t\t\t\t     fspathhash(newpath.buf), newpath.buf) ||\n \t       (!opt->priv->call_depth && file_exists(newpath.buf))) {\n \t\tstrbuf_setlen(&newpath, base_len);\n \t\tstrbuf_addf(&newpath, \"_%d\", suffix++);\n \t}\n\n \tFLEX_ALLOC_MEM(entry, path, newpath.buf, newpath.len);\n-\thashmap_entry_init(&entry->e, path_hash(entry->path));\n+\thashmap_entry_init(&entry->e, fspathhash(entry->path));\n \thashmap_add(&opt->priv->current_file_dir_set, &entry->e);\n \treturn strbuf_detach(&newpath, NULL);\n }\n--\n2.32.0\n\n"},{"id":"431600","messageId":"xmqq35rv1u2a.fsf@gitster.g","threadId":"56183","inReplyTo":"b85ed04f-ef9c-f460-e21b-bd1f8dfba9e2@web.de","subject":"Re: [PATCH] use fspathhash() everywhere","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-07-30T19:27:09Z","receivedAt":"2021-07-30T19:27:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"René Scharfe <l.s.r@web.de> writes:\n\n> cf2dc1c238 (speed up alt_odb_usable() with many alternates, 2021-07-07)\n> introduced the function fspathhash() for calculating path hashes while\n> respecting the configuration option core.ignorecase.  Call it instead of\n> open-coding it; the resulting code is shorter and less repetitive.\n>\n> Signed-off-by: René Scharfe <l.s.r@web.de>\n> ---\n>  builtin/sparse-checkout.c | 10 ++--------\n>  dir.c                     | 13 +++----------\n>  merge-recursive.c         | 11 +++--------\n>  3 files changed, 8 insertions(+), 26 deletions(-)\n\nI love this kind of \"now we have this thing available, let's use it\nat more places\" clean-up patch.\n\nWas coccinelle involved in finding these places?\n\nThanks.\n"},{"id":"431602","messageId":"14653a9b-8999-78bc-03f7-b9f21954b873@web.de","threadId":"56183","inReplyTo":"xmqq35rv1u2a.fsf@gitster.g","subject":"Re: [PATCH] use fspathhash() everywhere","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2021-07-30T20:22:38Z","receivedAt":"2021-07-30T20:27:53Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 30.07.21 um 21:27 schrieb Junio C Hamano:\n> René Scharfe <l.s.r@web.de> writes:\n>\n>> cf2dc1c238 (speed up alt_odb_usable() with many alternates, 2021-07-07)\n>> introduced the function fspathhash() for calculating path hashes while\n>> respecting the configuration option core.ignorecase.  Call it instead of\n>> open-coding it; the resulting code is shorter and less repetitive.\n>>\n>> Signed-off-by: René Scharfe <l.s.r@web.de>\n>> ---\n>>  builtin/sparse-checkout.c | 10 ++--------\n>>  dir.c                     | 13 +++----------\n>>  merge-recursive.c         | 11 +++--------\n>>  3 files changed, 8 insertions(+), 26 deletions(-)\n>\n> I love this kind of \"now we have this thing available, let's use it\n> at more places\" clean-up patch.\n>\n> Was coccinelle involved in finding these places?\n\nJust git grep this time; there were not enough hits for me to consider\nwriting a semantic patch.\n\nRené\n"}]}