From patchwork Fri Jul 30 19:06:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 12411759 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E6BEC4338F for ; Fri, 30 Jul 2021 19:07:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FAB560F00 for ; Fri, 30 Jul 2021 19:07:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230467AbhG3THM (ORCPT ); Fri, 30 Jul 2021 15:07:12 -0400 Received: from mout.web.de ([212.227.15.4]:41275 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229773AbhG3THL (ORCPT ); Fri, 30 Jul 2021 15:07:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1627672018; bh=cW2NUh9eJGPgyUnoQULQf4B1h37F1PXTscJKOOmywz4=; h=X-UI-Sender-Class:To:Cc:From:Subject:Date; b=IkuaXENnvYL4tnyVlitT/qFkFpS0FNw6StV0wq3N8m68ojR5uDS+MBj0lctqrhWQW 4a7n4qSzpvw+IRM7SMhBLW80VdRBlQOOQl6HNCNB4lS59oOTiMI50wSUQQzIH6oLJC zVQuX8V3r02zb5K4S5mgWYtPJgypbsQFUDUkWS3U= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from Mini-von-Rene.fritz.box ([91.47.159.106]) by smtp.web.de (mrweb002 [213.165.67.108]) with ESMTPSA (Nemesis) id 0LeLin-1mxUWl3O1t-00q9I1; Fri, 30 Jul 2021 21:06:58 +0200 X-Mozilla-News-Host: news://public-inbox.org:119 To: Git List Cc: Junio C Hamano , Eric Wong From: =?utf-8?q?Ren=C3=A9_Scharfe?= Subject: [PATCH] use fspathhash() everywhere Message-ID: Date: Fri, 30 Jul 2021 21:06:58 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 Content-Language: en-US X-Provags-ID: V03:K1:ddUycUVC4VrtUayOCd+mLA5eJixkMoK/aITjbdZRVhj17x48qHv 9sjZDZsizVmaogapucG3Fi6JrZN4vMTXSaJNnqubgxO7ufcRiSh4Y+ZE1pBg1Em2Qy1RPuP YKwSHN+20ZXV1IhIvgmShhC1QdeMNBgbhSkpuDa8Lx+lPPteRmKR6BnT+LGSd5D9/vu+Ax4 oMTbxRd1FDQp5iDGSJcxg== X-UI-Out-Filterresults: notjunk:1;V03:K0:gf1WQxt102E=:V6hvQ7SYb7ywksDdESKYOM ZdrS6yvGuQq0V5eVbtfA9W2xOyJn6H2d4KqWSTktRkyZhOBnLF8WcCW7YT9YDGkAB3eTcpb8f RlOzIBpN4Pbno44zOCHfvD4CU0yIKA3H18OEloXR0JmAZTCeYlmFB3vNb4JTCxMXKFVmCBFfJ nUeEL/LQ35EbE3dyf2iv8iRMFHUIyUU3ajUUMy9gvE2uQvkPssz5c3fYQHb29Wu2HZ8KNqsmi NsKpCBJqYMEzjO3qdv9YMp6a0BSM5UoHmG2Fx2Uvh1wyoIeVpLCGOkgOdenuBIzGe6OZym/9n nPPTgNXsyLtfac6pPXY0YO9CMCF4dfzGukU3H0OZ7IKK62nUey2AIZ+f3Wc6AYbQeVoiQbe08 FKjVd/Z+mn9weVDZ6nBuxs+HKV5zMG416Y827h8/nJ9PnrG03nGvN0BnelOEuyVpc2rA8YWzg vOozCQoucrfL/XEGEvzu89EDZFFIcXgCC1M5Q43n574qJiOG6Nctl+kcUkkcktwEV7TUggrTP dR1Aef7hJCpx8zy9hfBzuPyvoLf5wpZ/ayo2A/bbl6htfy0C3ewX0KDZfqqILFFohFH95ohvJ xOyNqY39GYmedAyMPJx+XDf8E7CQ+laKtGBV4sXyAty63WO2I/tt8QUWeIgc5vHKkGUd49txI OWhurxOqjK8ieMNp+iQ8QqyRxAwpeQ5SzY9hREYEwa6hEGXGTb45lHaJC7g7drFomZJGQw6H0 Zh0J2zxyLOKJrvKOIGBb+VqIXYuTuxX8wPP4VKdpuN/xNuHlYpNvRgicY58E4vlqXZ8/00Cru fj4trpzLzAbHslkyj/9rmPN4jUDv1EsTn9j6H9fkavsdrjxjN0I793ZATmuQ8Q4OjEAE48oh/ xUU/thcSDPREfL7d9pu8dflYmXpOQqqAgwWLalasKXyHkELaBRRYThBnNpekHP0C8q2QOiTOv P4mRG0C4DOH8LpV0sxifOz24j7+Ieya4Rli54NPclh8p4lrUSVUhDfB/bcj9SFRrEXvnntLD5 7t7cIKx5Y7HWCNag/iWrUPkKe+wdLyXKdBHIe9tfyPT5JUPxczn8pdIusNakQoQzxDSUekfF4 UqLQs+x5/7W76PzM0x2AoJS1bEGPc8zVBCE Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org cf2dc1c238 (speed up alt_odb_usable() with many alternates, 2021-07-07) introduced the function fspathhash() for calculating path hashes while respecting the configuration option core.ignorecase. Call it instead of open-coding it; the resulting code is shorter and less repetitive. Signed-off-by: René Scharfe --- builtin/sparse-checkout.c | 10 ++-------- dir.c | 13 +++---------- merge-recursive.c | 11 +++-------- 3 files changed, 8 insertions(+), 26 deletions(-) -- 2.32.0 diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index a4bdd7c494..8ba9f13787 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -380,10 +380,7 @@ static void insert_recursive_pattern(struct pattern_list *pl, struct strbuf *pat struct pattern_entry *e = xmalloc(sizeof(*e)); e->patternlen = path->len; e->pattern = strbuf_detach(path, NULL); - hashmap_entry_init(&e->ent, - ignore_case ? - strihash(e->pattern) : - strhash(e->pattern)); + hashmap_entry_init(&e->ent, fspathhash(e->pattern)); hashmap_add(&pl->recursive_hashmap, &e->ent); @@ -399,10 +396,7 @@ static void insert_recursive_pattern(struct pattern_list *pl, struct strbuf *pat e = xmalloc(sizeof(struct pattern_entry)); e->patternlen = newlen; e->pattern = xstrndup(oldpattern, newlen); - hashmap_entry_init(&e->ent, - ignore_case ? - strihash(e->pattern) : - strhash(e->pattern)); + hashmap_entry_init(&e->ent, fspathhash(e->pattern)); if (!hashmap_get_entry(&pl->parent_hashmap, e, ent, NULL)) hashmap_add(&pl->parent_hashmap, &e->ent); diff --git a/dir.c b/dir.c index 23b4417268..03c4d21267 100644 --- a/dir.c +++ b/dir.c @@ -782,9 +782,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern translated->pattern = truncated; translated->patternlen = given->patternlen - 2; hashmap_entry_init(&translated->ent, - ignore_case ? - strihash(translated->pattern) : - strhash(translated->pattern)); + fspathhash(translated->pattern)); if (!hashmap_get_entry(&pl->recursive_hashmap, translated, ent, NULL)) { @@ -813,9 +811,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern translated->pattern = dup_and_filter_pattern(given->pattern); translated->patternlen = given->patternlen; hashmap_entry_init(&translated->ent, - ignore_case ? - strihash(translated->pattern) : - strhash(translated->pattern)); + fspathhash(translated->pattern)); hashmap_add(&pl->recursive_hashmap, &translated->ent); @@ -845,10 +841,7 @@ static int hashmap_contains_path(struct hashmap *map, /* Check straight mapping */ p.pattern = pattern->buf; p.patternlen = pattern->len; - hashmap_entry_init(&p.ent, - ignore_case ? - strihash(p.pattern) : - strhash(p.pattern)); + hashmap_entry_init(&p.ent, fspathhash(p.pattern)); return !!hashmap_get_entry(map, &p, ent, NULL); } diff --git a/merge-recursive.c b/merge-recursive.c index 7008a90df5..3355d50e8a 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -61,11 +61,6 @@ static int path_hashmap_cmp(const void *cmp_data, return strcmp(a->path, key ? key : b->path); } -static unsigned int path_hash(const char *path) -{ - 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: @@ -463,7 +458,7 @@ static int save_files_dirs(const struct object_id *oid, strbuf_addstr(base, path); FLEX_ALLOC_MEM(entry, path, base->buf, base->len); - hashmap_entry_init(&entry->e, path_hash(entry->path)); + hashmap_entry_init(&entry->e, fspathhash(entry->path)); hashmap_add(&opt->priv->current_file_dir_set, &entry->e); strbuf_setlen(base, baselen); @@ -737,14 +732,14 @@ static char *unique_path(struct merge_options *opt, base_len = newpath.len; while (hashmap_get_from_hash(&opt->priv->current_file_dir_set, - path_hash(newpath.buf), newpath.buf) || + fspathhash(newpath.buf), newpath.buf) || (!opt->priv->call_depth && file_exists(newpath.buf))) { strbuf_setlen(&newpath, base_len); strbuf_addf(&newpath, "_%d", suffix++); } FLEX_ALLOC_MEM(entry, path, newpath.buf, newpath.len); - hashmap_entry_init(&entry->e, path_hash(entry->path)); + hashmap_entry_init(&entry->e, fspathhash(entry->path)); hashmap_add(&opt->priv->current_file_dir_set, &entry->e); return strbuf_detach(&newpath, NULL); }