From patchwork Wed Jun 12 23:24:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 10993151 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1FE14924 for ; Thu, 13 Jun 2019 17:01:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C3F322A68 for ; Thu, 13 Jun 2019 17:01:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0048822B1F; Thu, 13 Jun 2019 17:01:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E7D022A68 for ; Thu, 13 Jun 2019 17:01:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729622AbfFMRBy (ORCPT ); Thu, 13 Jun 2019 13:01:54 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:37112 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729550AbfFLXYw (ORCPT ); Wed, 12 Jun 2019 19:24:52 -0400 Received: by mail-wm1-f65.google.com with SMTP id 22so8168379wmg.2 for ; Wed, 12 Jun 2019 16:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lCC//pn3KNrzGN31dr8tmRVR9Rr02A8N6rblEqNJqHU=; b=hjoLykvv85U21W0k6iEA/YxZTfN9ZjU3UOr1F/eJPpTMrWanAMIHE1NJBvO0IzBlQX XVPwHRduEpJUJS9jxeKmR3b26WqQAse1CM1yscYHFP+sT5gsadGIowar1nJjbc950zFB zgG31dPkTK0/DNij09dqVOeFpdru6KL2WGqBpuzkSdkNu5SnUwbxwPMCsNvN3NtVUlpZ SpUKjnUd2SkiiYq9bjxPY6tOEXeF/LM2SDB3dr+0ulcNXNVzDMr41x/BsMP6lUpWPVnn WPQz6h9jV1CbEQspZlIV6jvMj4SRJX3E9Dt7XkWWxu6C99PCZZS4LpwMyDytX/jOT83d sLZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lCC//pn3KNrzGN31dr8tmRVR9Rr02A8N6rblEqNJqHU=; b=mWFGUcVX0ifi843Jxbsan/y4TwNQrKsoxYat6Q+MAMagsaEcSbN1Ei13IPaaCUNsbt KDYm2jxJwk16ajUvJXkQctfqTxbqVqi4UjKBSdtctZWrfxFprIijgwoOl2h+cWzxKo8J zU5H2iWmRABjANhx1XpNSwg4EVgFu610ntB0STEBm8gPB0K1x84UqQGziHBOMjMMzR3W ZYs8M/YgOo09TDpWUg9FHAzZVn6ZGPWcqIDcStEjvDAPdGjH1UcZve/wrmHkV0gntaPw 69rKm0RaPXKZCHEV9gWwHzA/4Amqyqs3NiCy2LfDdFAGn4WZIylOkAJ+J1ACF3r6apz1 sODw== X-Gm-Message-State: APjAAAV1h4cI/Eqx0I4jovZQ6Q+HRv0tp5X/Jq3sb1QGsDnQPKnR2HGQ ByI3MGToC/CC7WLwrpoxk9qATkNf X-Google-Smtp-Source: APXvYqwW6e2ds71tPSfqlePDp9YKRX4Ph2KzET4ftVMgAIDLRT06cHe+qjbeRatxeNjcXMsJbloFQA== X-Received: by 2002:a1c:99ca:: with SMTP id b193mr1013816wme.31.1560381888768; Wed, 12 Jun 2019 16:24:48 -0700 (PDT) Received: from localhost.localdomain ([2a04:cec0:1018:b2dd:2143:78cf:c452:5744]) by smtp.gmail.com with ESMTPSA id o126sm1414803wmo.31.2019.06.12.16.24.47 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 12 Jun 2019 16:24:48 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= , Jonathan Tan , =?utf-8?q?SZEDER_G=C3=A1bor?= , Christian Couder Subject: [PATCH v3 1/3] t/helper: add test-oidmap.c Date: Thu, 13 Jun 2019 01:24:23 +0200 Message-Id: <20190612232425.12149-2-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.22.0.6.gde8b105b43 In-Reply-To: <20190612232425.12149-1-chriscool@tuxfamily.org> References: <20190612232425.12149-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This new helper is very similar to "test-hashmap.c" and will help test how `struct oidmap` from oidmap.{c,h} can be used. Helped-by: SZEDER Gábor Signed-off-by: Christian Couder --- Makefile | 1 + t/helper/test-oidmap.c | 134 +++++++++++++++++++++++++++++++++++++++++ t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + 4 files changed, 137 insertions(+) create mode 100644 t/helper/test-oidmap.c diff --git a/Makefile b/Makefile index 8a7e235352..5efc7700ed 100644 --- a/Makefile +++ b/Makefile @@ -727,6 +727,7 @@ TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o TEST_BUILTINS_OBJS += test-match-trees.o TEST_BUILTINS_OBJS += test-mergesort.o TEST_BUILTINS_OBJS += test-mktemp.o +TEST_BUILTINS_OBJS += test-oidmap.o TEST_BUILTINS_OBJS += test-online-cpus.o TEST_BUILTINS_OBJS += test-parse-options.o TEST_BUILTINS_OBJS += test-path-utils.o diff --git a/t/helper/test-oidmap.c b/t/helper/test-oidmap.c new file mode 100644 index 0000000000..60e92096a1 --- /dev/null +++ b/t/helper/test-oidmap.c @@ -0,0 +1,134 @@ +#include "test-tool.h" +#include "cache.h" +#include "oidmap.h" +#include "strbuf.h" + +/* key is an oid and value is a name (could be a refname for example) */ +struct test_entry { + struct oidmap_entry entry; + char name[FLEX_ARRAY]; +}; + +#define DELIM " \t\r\n" + +/* + * Read stdin line by line and print result of commands to stdout: + * + * hash oidkey -> sha1hash(oidkey) + * put oidkey namevalue -> NULL / old namevalue + * get oidkey -> NULL / namevalue + * remove oidkey -> NULL / old namevalue + * iterate -> oidkey1 namevalue1\noidkey2 namevalue2\n... + * + */ +int cmd__oidmap(int argc, const char **argv) +{ + struct strbuf line = STRBUF_INIT; + struct oidmap map = OIDMAP_INIT; + + setup_git_directory(); + + /* init oidmap */ + oidmap_init(&map, 0); + + /* process commands from stdin */ + while (strbuf_getline(&line, stdin) != EOF) { + char *cmd, *p1 = NULL, *p2 = NULL; + struct test_entry *entry; + struct object_id oid; + + /* break line into command and up to two parameters */ + cmd = strtok(line.buf, DELIM); + /* ignore empty lines */ + if (!cmd || *cmd == '#') + continue; + + p1 = strtok(NULL, DELIM); + if (p1) + p2 = strtok(NULL, DELIM); + + if (!strcmp("hash", cmd) && p1) { + + /* print hash of oid */ + if (!get_oid(p1, &oid)) + printf("%x\n", ntohl(sha1hash(oid.hash))); + else + printf("Unknown oid: %s\n", p1); + + } else if (!strcmp("add", cmd) && p1 && p2) { + + if (get_oid(p1, &oid)) { + printf("Unknown oid: %s\n", p1); + continue; + } + + /* create entry with oidkey from p1, value = p2 */ + FLEX_ALLOC_STR(entry, name, p2); + oidcpy(&entry->entry.oid, &oid); + + /* add to oidmap */ + oidmap_put(&map, entry); + + } else if (!strcmp("put", cmd) && p1 && p2) { + + if (get_oid(p1, &oid)) { + printf("Unknown oid: %s\n", p1); + continue; + } + + /* create entry with oid_key = p1, name_value = p2 */ + FLEX_ALLOC_STR(entry, name, p2); + oidcpy(&entry->entry.oid, &oid); + + /* add / replace entry */ + entry = oidmap_put(&map, entry); + + /* print and free replaced entry, if any */ + puts(entry ? entry->name : "NULL"); + free(entry); + + } else if (!strcmp("get", cmd) && p1) { + + if (get_oid(p1, &oid)) { + printf("Unknown oid: %s\n", p1); + continue; + } + + /* lookup entry in oidmap */ + entry = oidmap_get(&map, &oid); + + /* print result */ + puts(entry ? entry->name : "NULL"); + + } else if (!strcmp("remove", cmd) && p1) { + + if (get_oid(p1, &oid)) { + printf("Unknown oid: %s\n", p1); + continue; + } + + /* remove entry from oidmap */ + entry = oidmap_remove(&map, &oid); + + /* print result and free entry*/ + puts(entry ? entry->name : "NULL"); + free(entry); + + } else if (!strcmp("iterate", cmd)) { + + struct oidmap_iter iter; + oidmap_iter_init(&map, &iter); + while ((entry = oidmap_iter_next(&iter))) + printf("%s %s\n", oid_to_hex(&entry->entry.oid), entry->name); + + } else { + + printf("Unknown command %s\n", cmd); + + } + } + + strbuf_release(&line); + oidmap_free(&map, 1); + return 0; +} diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index 087a8c0cc9..1eac25233f 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -35,6 +35,7 @@ static struct test_cmd cmds[] = { { "match-trees", cmd__match_trees }, { "mergesort", cmd__mergesort }, { "mktemp", cmd__mktemp }, + { "oidmap", cmd__oidmap }, { "online-cpus", cmd__online_cpus }, { "parse-options", cmd__parse_options }, { "path-utils", cmd__path_utils }, diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index 7e703f3038..c7a46dc320 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -25,6 +25,7 @@ int cmd__lazy_init_name_hash(int argc, const char **argv); int cmd__match_trees(int argc, const char **argv); int cmd__mergesort(int argc, const char **argv); int cmd__mktemp(int argc, const char **argv); +int cmd__oidmap(int argc, const char **argv); int cmd__online_cpus(int argc, const char **argv); int cmd__parse_options(int argc, const char **argv); int cmd__path_utils(int argc, const char **argv); From patchwork Wed Jun 12 23:24:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 10993155 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DE38214DB for ; Thu, 13 Jun 2019 17:02:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA1EB22A68 for ; Thu, 13 Jun 2019 17:02:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD1DA22BF1; Thu, 13 Jun 2019 17:02:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6321422A68 for ; Thu, 13 Jun 2019 17:02:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729585AbfFMRBx (ORCPT ); Thu, 13 Jun 2019 13:01:53 -0400 Received: from mail-wm1-f44.google.com ([209.85.128.44]:54101 "EHLO mail-wm1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729551AbfFLXYy (ORCPT ); Wed, 12 Jun 2019 19:24:54 -0400 Received: by mail-wm1-f44.google.com with SMTP id x15so8200827wmj.3 for ; Wed, 12 Jun 2019 16:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DjVPIMf+xSlw8VRxJOPb8SnirDuQ2XY9HUor0KgqFv0=; b=MowxwC7xZ86LJ4paWGVWzVTQPsVotq9j3DerxQ8q9kxF7PbANqeHFRHcXHCmEYvMBk /9sF5QbPE4GEdYuWgFJUUMSsDbQFdg0LAVmDcWetjtBaFznavk/xaLeU+sI3anM1uCBT WL3IStftovjWv4UkKA1BwcxtUSw3sNipzl+M4QY8Gb9rMWoL+iu6LLwSf/RPttoRGMzD ttkFjAmKxVQrlPdOkEGa7BUa/5ItkQHXzHOfKm1rsr6GfEDUg8REJ0+N4UNul3PY7038 RhnavVLwR6TrtUtgxVtOt+5ScaJfF87shnfUsqbvTCyD0DTqW84NdFBoeZ34XMWLle/6 bn9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DjVPIMf+xSlw8VRxJOPb8SnirDuQ2XY9HUor0KgqFv0=; b=cmLpq6OjDqvFVtMHs4ZU8dPm2SjAhtdiZgb3khwZn2c1PemaNfDnTETXgAuWQ9y6/u LNYrtCfEW2tSUJwJHWnf5Vih76uwj343h9u0iVlQht/c4GFl1/nQPCclwowzACmuXXRT QUf2oUMiJ1rranKHsbDNhAMs0GmkqqrkXhXPBoCwLQzds1Is6bVbsWMy/CllUezCuYky Uq6c/tBhqAU2ji2eeUB2w/TLKYSJzvl0ctsFSyQPon2M4ZpQFrNdscdnbEmV7Xx5aJR/ e43exQN3UzZ4GyaAGs/FN6djYhC30goMn1Ri5S42wk8499hyh+e32qV467D826fqaTxc NrFQ== X-Gm-Message-State: APjAAAUdsbAGvXw7pdUJzgic9rN9kanINsIdNXQBTEmJbcu/UECUepRf o8N50DTV+MsUG0JLZ5BpMDItu2hG X-Google-Smtp-Source: APXvYqyrn/LpbRB9najqRYS5CtsTXGtmM+DVBoDewLnJs6LKYgERlZ+Pem4o0/9t52X6P7gZBOe58w== X-Received: by 2002:a1c:6c08:: with SMTP id h8mr1138835wmc.62.1560381892104; Wed, 12 Jun 2019 16:24:52 -0700 (PDT) Received: from localhost.localdomain ([2a04:cec0:1018:b2dd:2143:78cf:c452:5744]) by smtp.gmail.com with ESMTPSA id o126sm1414803wmo.31.2019.06.12.16.24.51 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 12 Jun 2019 16:24:51 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= , Jonathan Tan , =?utf-8?q?SZEDER_G=C3=A1bor?= , Christian Couder , Christian Couder Subject: [PATCH v3 2/3] t: add t0016-oidmap.sh Date: Thu, 13 Jun 2019 01:24:24 +0200 Message-Id: <20190612232425.12149-3-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.22.0.6.gde8b105b43 In-Reply-To: <20190612232425.12149-1-chriscool@tuxfamily.org> References: <20190612232425.12149-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Christian Couder Add actual tests for operations using `struct oidmap` from oidmap.{c,h}. Helped-by: SZEDER Gábor Signed-off-by: Christian Couder --- t/t0016-oidmap.sh | 100 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100755 t/t0016-oidmap.sh diff --git a/t/t0016-oidmap.sh b/t/t0016-oidmap.sh new file mode 100755 index 0000000000..f5315f42b8 --- /dev/null +++ b/t/t0016-oidmap.sh @@ -0,0 +1,100 @@ +#!/bin/sh + +test_description='test oidmap' +. ./test-lib.sh + +# This purposefully is very similar to t0011-hashmap.sh + +test_oidmap () { + echo "$1" | test-tool oidmap $3 >actual && + echo "$2" >expect && + test_cmp expect actual +} + + +test_expect_success 'setup' ' + + test_commit one && + test_commit two && + test_commit three && + test_commit four + +' + +test_oidhash () { + git rev-parse "$1" | cut -c1-8 +} + +test_expect_success 'hash' ' + +test_oidmap "hash one +hash two +hash invalidOid +hash three" "$(test_oidhash one) +$(test_oidhash two) +Unknown oid: invalidOid +$(test_oidhash three)" + +' + +test_expect_success 'put' ' + +test_oidmap "put one 1 +put two 2 +put invalidOid 4 +put three 3" "NULL +NULL +Unknown oid: invalidOid +NULL" + +' + +test_expect_success 'replace' ' + +test_oidmap "put one 1 +put two 2 +put three 3 +put invalidOid 4 +put two deux +put one un" "NULL +NULL +NULL +Unknown oid: invalidOid +2 +1" + +' + +test_expect_success 'get' ' + +test_oidmap "put one 1 +put two 2 +put three 3 +get two +get four +get invalidOid +get one" "NULL +NULL +NULL +2 +NULL +Unknown oid: invalidOid +1" + +' + +test_expect_success 'iterate' ' + +test_oidmap "put one 1 +put two 2 +put three 3 +iterate" "NULL +NULL +NULL +$(git rev-parse two) 2 +$(git rev-parse one) 1 +$(git rev-parse three) 3" + +' + +test_done From patchwork Wed Jun 12 23:24:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 10993153 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A3E1114DB for ; Thu, 13 Jun 2019 17:02:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F9DF22A68 for ; Thu, 13 Jun 2019 17:02:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83B4B22BF1; Thu, 13 Jun 2019 17:02:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72D1B22A68 for ; Thu, 13 Jun 2019 17:02:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729640AbfFMRBx (ORCPT ); Thu, 13 Jun 2019 13:01:53 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:50638 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729552AbfFLXY4 (ORCPT ); Wed, 12 Jun 2019 19:24:56 -0400 Received: by mail-wm1-f67.google.com with SMTP id c66so8197012wmf.0 for ; Wed, 12 Jun 2019 16:24:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JQxy7QTZ3SJg459ql3zBsovlVdVKcSjTR6ROqdx/idk=; b=Idjs0MvfxlfwkFTIKyuJlwZ2sZ8CORwTJ5k8lz/DMBn0N4QWm65o7VPxh1Zq4bCiBz t66FFNG7VWmda20gOq1Hug5FRNk1iQVmsUyfxQ4ADGOXo+07UQjEjZt7dJVMC7brNT/5 uo38dsGvsHuWixJgTIYb/7/MQM10vaVo+qOMC1rOGu08IdB2cHTak/8GsGAU0BoRV6Jl 284JIbRJccJ8+5sqWB7sqmS+lwNORd0L2Uzdg0ZPJvsCqTN0eQvXYCvEkVyibQ9yNZuT 1n+u8PQQstivaiE5zZZUjzB379FKN2jnJjxsfnRaOJu+LmOu1sMSVaJpBrYXe/4yjKoP 8pdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JQxy7QTZ3SJg459ql3zBsovlVdVKcSjTR6ROqdx/idk=; b=gGAcb3pJCgsi0M7A8D4zeXD+L/P5Vp/ynm8KP1SZSpG0303Ff6vY5Im44Qjkv5blS3 /HyT/xzvDlGPJzIHym4Q+ByVTyUeDwm/scAX9172XuLPr6xQpAD1g2XTkOkYn33axi/5 cYUNFhXGXeNZ3p+ZXX9TSELJGkAIqPvIL6eiVfMSji2IvDoRYh6VYgDTJSPDchBlu/AT BFkIEuNOq1NEDNpT+OETfn6q0L1UYER9f8vabV6vavKGTSDc6VLHAZvpubmA+OfPVy1l wTNX5NgNLFf8eAjBJfqfuSAIPsGx6hV3MoqWrxnySxGLf2crbWphJwfDHEdb39e7azS9 mAjw== X-Gm-Message-State: APjAAAVYXH0YZd524iOoJwmwwdRwTiard8AfOVTqmsoUAnZaP5vvvb8Q B6zae/epB2AznoCTIg3gEVBW41Ne X-Google-Smtp-Source: APXvYqypyHEoxRJzeWGUjYTnP9yZ9NK55/nLzipkST9RE9tHZ3qQU5+UuxSA3HXrRJSsbeV6g4I35g== X-Received: by 2002:a7b:c313:: with SMTP id k19mr1055681wmj.2.1560381894359; Wed, 12 Jun 2019 16:24:54 -0700 (PDT) Received: from localhost.localdomain ([2a04:cec0:1018:b2dd:2143:78cf:c452:5744]) by smtp.gmail.com with ESMTPSA id o126sm1414803wmo.31.2019.06.12.16.24.53 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 12 Jun 2019 16:24:53 -0700 (PDT) From: Christian Couder X-Google-Original-From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= , Jonathan Tan , =?utf-8?q?SZEDER_G=C3=A1bor?= , Christian Couder , Christian Couder Subject: [PATCH v3 3/3] oidmap: use sha1hash() instead of static hash() function Date: Thu, 13 Jun 2019 01:24:25 +0200 Message-Id: <20190612232425.12149-4-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.22.0.6.gde8b105b43 In-Reply-To: <20190612232425.12149-1-chriscool@tuxfamily.org> References: <20190612232425.12149-1-chriscool@tuxfamily.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Christian Couder Get rid of the static hash() function in oidmap.c which is redundant with sha1hash(). Use sha1hash() directly instead. Let's be more consistent and not use several hash functions doing nearly exactly the same thing. Signed-off-by: Christian Couder --- oidmap.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/oidmap.c b/oidmap.c index b0841a0f58..01c206aaef 100644 --- a/oidmap.c +++ b/oidmap.c @@ -12,13 +12,6 @@ static int oidmap_neq(const void *hashmap_cmp_fn_data, &((const struct oidmap_entry *) entry_or_key)->oid); } -static int hash(const struct object_id *oid) -{ - int hash; - memcpy(&hash, oid->hash, sizeof(hash)); - return hash; -} - void oidmap_init(struct oidmap *map, size_t initial_size) { hashmap_init(&map->map, oidmap_neq, NULL, initial_size); @@ -36,7 +29,7 @@ void *oidmap_get(const struct oidmap *map, const struct object_id *key) if (!map->map.cmpfn) return NULL; - return hashmap_get_from_hash(&map->map, hash(key), key); + return hashmap_get_from_hash(&map->map, sha1hash(key->hash), key); } void *oidmap_remove(struct oidmap *map, const struct object_id *key) @@ -46,7 +39,7 @@ void *oidmap_remove(struct oidmap *map, const struct object_id *key) if (!map->map.cmpfn) oidmap_init(map, 0); - hashmap_entry_init(&entry, hash(key)); + hashmap_entry_init(&entry, sha1hash(key->hash)); return hashmap_remove(&map->map, &entry, key); } @@ -57,6 +50,6 @@ void *oidmap_put(struct oidmap *map, void *entry) if (!map->map.cmpfn) oidmap_init(map, 0); - hashmap_entry_init(&to_put->internal_entry, hash(&to_put->oid)); + hashmap_entry_init(&to_put->internal_entry, sha1hash(to_put->oid.hash)); return hashmap_put(&map->map, to_put); }