From patchwork Sun Jun 9 04:49:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 10983539 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 CF6521850 for ; Sun, 9 Jun 2019 04:49:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C025A28A99 for ; Sun, 9 Jun 2019 04:49:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B48E828B00; Sun, 9 Jun 2019 04:49:40 +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 2DED828AFC for ; Sun, 9 Jun 2019 04:49:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726178AbfFIEtc (ORCPT ); Sun, 9 Jun 2019 00:49:32 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:55341 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725787AbfFIEtc (ORCPT ); Sun, 9 Jun 2019 00:49:32 -0400 Received: by mail-wm1-f67.google.com with SMTP id a15so5514048wmj.5 for ; Sat, 08 Jun 2019 21:49:30 -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=oq7MYXaWMxG0fDN/89eHW6L1CBiq5MTFLH5MXXeWvM0=; b=iRilU9LuhLzJzrsOkw6T/gATaGUyZuZdZrkEi9Pfk7fWwe+jXse4SmqFwMxPhHRFMZ xoOJ4nfVqVZaue2vJcwPgWl+WHHp9muXbr+/WBaKMEV75ZgdM8iogMpxrRcVNTnxlr3A 6PsLg2TUlMM7bfe7oaTv8PoP4U9p4HbcBzUW96eG/qq2kMrxumZMx+QUX/8kFIHyPK0m acly47xtGqWIA083t7Rm41Nw4CM8EvqXsvrHbCjSKYstzmttW0wadV10XzqZHMkJEwgD PvaqMWz64fdcUjdtM84dlswkRe1ciJOyXzH+9o9BwNjTGaiVnWwrJ5Xt4AqHC8p24SWU ojLA== 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=oq7MYXaWMxG0fDN/89eHW6L1CBiq5MTFLH5MXXeWvM0=; b=bSSj/tAgjFvk41OSXB1GWkoKvYtjL/9GvtJvjfWAf0CvCqrBzcKzSIDQkaxK47rvlA fP5B+WlYelGU3oRMFGMgVpKr/oufcWo731bXc+XILo/mfquRVf+DqSpJE6ZSxiveL4nH is1oLqGPxSW+sE5ODrTWzrJaf5LeLBVjCGXqi9l2SSiH29nVpbcvBp/1935Lf+SmBTrJ Ln/aElesZsz3MHE96ZuoWtEOdMkH5YbbpvjlHgOt9W5diMPUG/zodA0LNqw3RgZzDnd4 gO1bXCFWSQSVTDxljhHo7NCooyojjBZQ9NZm16P/lIW9SenjPVKHJ5SgzuXUz37tHkoD A7xA== X-Gm-Message-State: APjAAAX6CURiET8k8BGCknC8N1GETMlftBk1njtH9dtDpulK36E2kcBd SdiwAuL9uAfOUaIin2+zsUYFhWp4WtU= X-Google-Smtp-Source: APXvYqxInkPsQhcwkx9RcG5wR+ykMs2StdEWEr1hSh8lBqEJSD8Aii0MomZHDyiYlhkZetLerViI1Q== X-Received: by 2002:a05:600c:389:: with SMTP id w9mr8454349wmd.139.1560055769454; Sat, 08 Jun 2019 21:49:29 -0700 (PDT) Received: from localhost.localdomain (160.10.112.78.rev.sfr.net. [78.112.10.160]) by smtp.gmail.com with ESMTPSA id y2sm6461116wra.58.2019.06.08.21.49.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Jun 2019 21:49:29 -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 , Brandon Williams , Christian Couder Subject: [PATCH 1/3] t/helper: add test-oidmap.c Date: Sun, 9 Jun 2019 06:49:05 +0200 Message-Id: <20190609044907.32477-2-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.22.0.14.g9023ccb50a In-Reply-To: <20190609044907.32477-1-chriscool@tuxfamily.org> References: <20190609044907.32477-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. 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..0ba122a264 --- /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("%u\n", 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 Sun Jun 9 04:49:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 10983541 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 6A9DD924 for ; Sun, 9 Jun 2019 04:49:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BC9128A99 for ; Sun, 9 Jun 2019 04:49:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5060028AFC; Sun, 9 Jun 2019 04:49:42 +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 4E9B328AFD for ; Sun, 9 Jun 2019 04:49:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726218AbfFIEtf (ORCPT ); Sun, 9 Jun 2019 00:49:35 -0400 Received: from mail-wm1-f43.google.com ([209.85.128.43]:52966 "EHLO mail-wm1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725787AbfFIEtf (ORCPT ); Sun, 9 Jun 2019 00:49:35 -0400 Received: by mail-wm1-f43.google.com with SMTP id s3so5514753wms.2 for ; Sat, 08 Jun 2019 21:49:34 -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=c6nBiDODMszO5Mzwz3NH9Uy8z6QjASLf3fPwTu1D78U=; b=uVcYaEltCSW24nuRjVu3YtukQXeuxjvx3bplKkTdVYc+gNHd/gafhkamBI6WWflGLc Kn9m5crTIEEFSb6nUvCtYMNgOlpgd9j44rfIISonDmiUNAl3j5/Joy3zatVIQKS1inTm 1G5a2OlN9+diEQJNKEFHa3FDAoBgHHzl0onJwR1NxevoCd3Ormz2eomigyo6fSHqVG2f mbqCcMEC7x4O8y+mKo+CJAa+zFnXF0Blf7DdOdOc1pL/4084iOMnGWX1atZjs1BcDC3I 70/ibHzomclQSBsGhTqtmgIGl4xF3dWDna2b1uQByisEmRjYjh/FLsMqjUq7/2eeUDbh 2FOg== 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=c6nBiDODMszO5Mzwz3NH9Uy8z6QjASLf3fPwTu1D78U=; b=OHrheE9PCX5KjuJI8Rwuf53t2bgLXXdtTGsq2/oFHoEMHEOkGgP5BaxC7ghZv7x/Qx aHQ+1iWfb6f4lsW0Y2uDz1SCp+KaxBG7CrF2QJR8avsBovib8MkKFrFdoMb43bIjE/UC 58MS86qeoJNzUhU0ZxeSuYPkrpbizEM4c2xzWaaENZmHi3bSljA/AxfhkOPym01cV2gd 0PsR1TNJjcDrFpINGNLBv+JbB67OG4f6Y0gGoFwxSm5H+pDADmnw63tiR3sNo9WD3d38 6xoTLAl6EFw9xsOdsm4T62Abm0Yrewls761htE0MzofpztN8x9xecrj+aG/t2DaMuVto wVVg== X-Gm-Message-State: APjAAAUgS1u+Va5PEoCnAiSodRRI+7RtdtWCh3QJoqRSxcylC25CrcLu H/nnYy8PfJlWA47fp9a+GT3qpwNc3lg= X-Google-Smtp-Source: APXvYqy7uMnfXd8p7lIWuy8LEq/2JHWiZ5nSR0PmsyzALEgo7y7c7BhsovEeo0pGF9RWFwhBvnnHdw== X-Received: by 2002:a1c:2004:: with SMTP id g4mr8289714wmg.173.1560055773064; Sat, 08 Jun 2019 21:49:33 -0700 (PDT) Received: from localhost.localdomain (160.10.112.78.rev.sfr.net. [78.112.10.160]) by smtp.gmail.com with ESMTPSA id y2sm6461116wra.58.2019.06.08.21.49.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Jun 2019 21:49:32 -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 , Brandon Williams , Christian Couder , Christian Couder Subject: [PATCH 2/3] t: add t0016-oidmap.sh Date: Sun, 9 Jun 2019 06:49:06 +0200 Message-Id: <20190609044907.32477-3-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.22.0.14.g9023ccb50a In-Reply-To: <20190609044907.32477-1-chriscool@tuxfamily.org> References: <20190609044907.32477-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}. 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..3a8e8bdb3d --- /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" | perl -ne 'print hex("$4$3$2$1") . "\n" if m/^(..)(..)(..)(..).*/;' +} + +test_expect_success PERL '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 Sun Jun 9 04:49:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 10983543 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 B0F281850 for ; Sun, 9 Jun 2019 04:49:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A032428A99 for ; Sun, 9 Jun 2019 04:49:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 947CD28AFC; Sun, 9 Jun 2019 04:49:42 +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 784BD28AFF for ; Sun, 9 Jun 2019 04:49:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726358AbfFIEth (ORCPT ); Sun, 9 Jun 2019 00:49:37 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43677 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725787AbfFIEth (ORCPT ); Sun, 9 Jun 2019 00:49:37 -0400 Received: by mail-wr1-f68.google.com with SMTP id r18so5853857wrm.10 for ; Sat, 08 Jun 2019 21:49:36 -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=X2WAeH9XKfpktBnDzZsrryQ7Qm3OzWGPMO2fj+263LQ=; b=cvFn4gxPobAF0irPGvXMT2w6/QCAcmgwjlOw/xd484f0C47iuDd2KdisnRxhf/oMxt hHKCC1TWiLzYqL8BiDuNmOssSxvaoDA6jEr/34HSIovGZOL/a73mB69vixLkq9RqR9rf tG5pYvt9gHceXx/17aZWhGsGQoeoc/nLg5fgOxe1SNiHdOizlFTDuiUUt+bd7zNRMLrG DMsJbwgexCtwSOFt37iV4ztLYuJXAHoVgAUG/ZY8v6AWHG30tOdZLG1nbLFD6vOpFu4N 0TiEilrtaqNjb0ly6bUVBn+wdvvL9/8r6ojcVdbtPmLkHOjhoVes3E9LjI0tgmk9nqbR aVOw== 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=X2WAeH9XKfpktBnDzZsrryQ7Qm3OzWGPMO2fj+263LQ=; b=QOWI0RZ/0pO01LHc6qzrxQ710OQbHEJ3VsE8ajZdwi0EIJMqkbpqTJ1BCk8lnXF1Ez kJ61wQbEOo/GiUQipaO15CYzzvvtUKGMZWAciALaeACQWteoeB492t6SJy/civE5/vb3 9FrpxYlH/hn46v0/wezVjiNNVLjVhS2cupoxkP8eS4PYfjbpt4xxiGEy8gnQfry2ST3M 4U9A35K8pnd05w+lAFsjhsIsPRkeILNouQwp8SH5kZtt7fe4Gy6P03ZXEPGJzoHl6Ow4 iJTz2UKM/RqkWP2YzFFoPFFg4x/WVJ72NwxynLikpvbZk4RSHjRFlanPsf0wt9uAZP7z DFoQ== X-Gm-Message-State: APjAAAVRHNKiaTDl4HIuLSdqfaycEfP2Fn5CzI0W71c/DN15pzk6rb3B ibiqLqyKTSM45Wr+EZR12ckzREywsIo= X-Google-Smtp-Source: APXvYqxIwV1clKwPIc6ureQi83lxw+u+GBn0TcER70eIDyXlLhQdSpEDDWtLKR6E7q8qvBgNN2HKlQ== X-Received: by 2002:a5d:40cd:: with SMTP id b13mr5139931wrq.290.1560055775486; Sat, 08 Jun 2019 21:49:35 -0700 (PDT) Received: from localhost.localdomain (160.10.112.78.rev.sfr.net. [78.112.10.160]) by smtp.gmail.com with ESMTPSA id y2sm6461116wra.58.2019.06.08.21.49.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Jun 2019 21:49:34 -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 , Brandon Williams , Christian Couder , Christian Couder Subject: [PATCH 3/3] oidmap: use sha1hash() instead of static hash() function Date: Sun, 9 Jun 2019 06:49:07 +0200 Message-Id: <20190609044907.32477-4-chriscool@tuxfamily.org> X-Mailer: git-send-email 2.22.0.14.g9023ccb50a In-Reply-To: <20190609044907.32477-1-chriscool@tuxfamily.org> References: <20190609044907.32477-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); }