From patchwork Thu Jan 30 20:32:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 11358637 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B161D924 for ; Thu, 30 Jan 2020 20:33:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8EEE52083E for ; Thu, 30 Jan 2020 20:33:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=usp-br.20150623.gappssmtp.com header.i=@usp-br.20150623.gappssmtp.com header.b="gMcw6zdo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727775AbgA3Udd (ORCPT ); Thu, 30 Jan 2020 15:33:33 -0500 Received: from mail-qk1-f195.google.com ([209.85.222.195]:46471 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726514AbgA3Udd (ORCPT ); Thu, 30 Jan 2020 15:33:33 -0500 Received: by mail-qk1-f195.google.com with SMTP id g195so4267118qke.13 for ; Thu, 30 Jan 2020 12:33:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bCiHX3i0ze8uxpSTqlorZAcd0L4sog7vYgQY125mN2E=; b=gMcw6zdoRM9REVQm+g97TKH+6qKXP82ec1axuvctO7xJcugko6Jlgqgo5cWwizjf1E 32smiUM4o2gStUqqNBG7iqzwjFiJpTWZm/B32tp0wTRuFkpXDgS1ZAf+buq8Z+5XR6Rj ktR3Lq/kQF7qOe5xNF9Jye1Ac+K/jgDtP6uBJdOWr0zh4pZ/4HHz5IWUG86yX3oGBvga mjqkn6d00vMM5WmqaBP32idUqHhgDxDAuYFbWs8mpIoVI9LOe2eJfYIozjVQHmNAUi3K B1rtaXgzYviY3Q4X56/Of2x99nIM3LugSC3lWusf6sS2W4hxXdKWfdXXuD5sr4zxR14F jYuA== 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=bCiHX3i0ze8uxpSTqlorZAcd0L4sog7vYgQY125mN2E=; b=lJVGx1EAywsDLK5aGy0wMfuOoE/2GAezMePb5pWrZRx4lNXoZue7FzuNUgj9qULYFN Nafk6nkCVzuUc0ITI+1s+Pr2zvX+HKLlRv3dRXl6ViNJEXXfjXX3ztaMacHcVcZ9vmnb PpzTcBp3msfm0x4ksUkorUMsYEnYmO4QfChvjlJvIYTFC9ofEZwQ2KPCRoh8brp1XETv i/PhswB09dqrcxKk9LFwqliZ+lV+k6u7BT+DsDydZZ8s0M5PpFQaf2iVFb6EwuHSCTVG kFNcr4/SKh+QOGoEyTSIZwWF6P/RbSpTdtwmS56w7VMlDSICSQULW3bM+1EAiKyv68Q1 xBoA== X-Gm-Message-State: APjAAAUinbSnxbDxpj+fTHx8tKx7T05gVWo7tZsV/w71wmathRe5aSSg W+mxF4NpJGdb/T7pIaRcyRVvQbcAdCw= X-Google-Smtp-Source: APXvYqzpLx7iOef7cgd0uOUhcXojDDWIDat/YlvUxQKvoWGUo77FoI4aumWzpXGfEUiQk7kU4utiHQ== X-Received: by 2002:a05:620a:1108:: with SMTP id o8mr6884459qkk.118.1580416410278; Thu, 30 Jan 2020 12:33:30 -0800 (PST) Received: from mango.semfio.usp.br ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id o12sm3436514qke.79.2020.01.30.12.33.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 12:33:29 -0800 (PST) From: Matheus Tavares To: git@vger.kernel.org Cc: "brian m. carlson" , Junio C Hamano Subject: [PATCH 1/7] diff: make diff_populate_filespec() honor its repo argument Date: Thu, 30 Jan 2020 17:32:17 -0300 Message-Id: <5a31c7b9e3239f2b7e4841dcc85cbf9cddf545ed.1580413221.git.matheus.bernardino@usp.br> X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org diff_populate_filespec() takes a struct repository argument but it doesn't get passed down to read_object_file(). Signed-off-by: Matheus Tavares --- diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff.c b/diff.c index 8e2914c031..0f333c27d6 100644 --- a/diff.c +++ b/diff.c @@ -4024,7 +4024,7 @@ int diff_populate_filespec(struct repository *r, return 0; } } - s->data = read_object_file(&s->oid, &type, &s->size); + s->data = repo_read_object_file(r, &s->oid, &type, &s->size); if (!s->data) die("unable to read %s", oid_to_hex(&s->oid)); s->should_free = 1; From patchwork Thu Jan 30 20:32:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 11358639 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 07E36139A for ; Thu, 30 Jan 2020 20:33:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D9DA72083E for ; Thu, 30 Jan 2020 20:33:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=usp-br.20150623.gappssmtp.com header.i=@usp-br.20150623.gappssmtp.com header.b="t+ZggL5B" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727779AbgA3Udj (ORCPT ); Thu, 30 Jan 2020 15:33:39 -0500 Received: from mail-qv1-f66.google.com ([209.85.219.66]:38627 "EHLO mail-qv1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726514AbgA3Udi (ORCPT ); Thu, 30 Jan 2020 15:33:38 -0500 Received: by mail-qv1-f66.google.com with SMTP id g6so2175806qvy.5 for ; Thu, 30 Jan 2020 12:33:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7mXc0JGAnpaTT7WkDztXaipWGC+d+Uw0pUQB9NwsZaM=; b=t+ZggL5BiqEJROnMzl7XGA12J0JHzibLA7+G2hPhD5jBWOnYIdr7WOTTGxVxa3glQj 9pWjEtXI8W87scp6cGnAmPBv9OCt3O/hBHv6VlzCkZkU/FQSqKYZED1NmOXgg2+T0X2h Hcf0xfxu643v5uHqwk/vE0sZZV4SxLfCVV1kowMFEDNLQdtmJ2rPC2oSLcj22AI/CNQs a4g8oVkczMatGXv01Py9Pc5buduRRYlIheIu2qfzERHCnyiWNt9NpiODiwM6UokVXzrN S/zf4AaC1uireQwM8jSiFB3Bl7e+Wq/pMzc57VX0M62QsItEq0u+t8bolltkuouwrlZj G+9g== 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=7mXc0JGAnpaTT7WkDztXaipWGC+d+Uw0pUQB9NwsZaM=; b=f0XhBgh1f+gzHPA6Ouo9xYOg3WTaZZzIue0AYfENgyZYhvJbbLHXLHklr7FAuiH3K2 ATD0H33K+rTx0omjOZ2VjNCw0REuzsOuIyKb/contDHDVb0jFnHY9CU9jsPfLprH6CnT upkbIBc01nNlKNZHZ49zdXb77moYjOKZDVzLUOdpPnSiMDGzmF6DaxWPatTrAME7Z+FA RryUlQfcR/F+PM9BssUig3TWbCd6nVIEFglpBnYC9CUrnQuGNFf6NwhiO/4XyMWF5rov /JYtS/wjMp92w7nV845PQxnILBKQBf1eCW+VrmCs7sarBisUhPSn/R6HS1UAHml1SNzL 6Ymg== X-Gm-Message-State: APjAAAUpBuwBcOGZWsMqPwH9NTeMUnFf2SqfrBluyDVLcepwxbxJkOKD N2YXCfx1VGB+LvXuAdL+9LlZk+ms+HQ= X-Google-Smtp-Source: APXvYqzLM/3g2qJO2RTuSHhwMonhUQKnaW3ozT8Nlq7EVXf9yV1tjKnm8LBpHXqxNE82Jr6egvkQ4Q== X-Received: by 2002:ad4:46af:: with SMTP id br15mr6714995qvb.216.1580416417366; Thu, 30 Jan 2020 12:33:37 -0800 (PST) Received: from mango.semfio.usp.br ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id o12sm3436514qke.79.2020.01.30.12.33.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 12:33:36 -0800 (PST) From: Matheus Tavares To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , Jeff King , Junio C Hamano Subject: [PATCH 2/7] cache-tree: use given repo's hash_algo at verify_one() Date: Thu, 30 Jan 2020 17:32:18 -0300 Message-Id: <8bab40cb3357d64b8d365b8848ded99122056689.1580413221.git.matheus.bernardino@usp.br> X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org verify_one() takes a struct repository argument but uses the_hash_algo internally. Replace it with the provided repo's git_hash_algo, for consistency. For now, this is mainly a cosmetic change, as all callers of this function currently only pass the_repository to it. Signed-off-by: Matheus Tavares --- cache-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache-tree.c b/cache-tree.c index 1bd1b23d38..8c51a15751 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -826,7 +826,7 @@ static void verify_one(struct repository *r, i++; } strbuf_addf(&tree_buf, "%o %.*s%c", mode, entlen, name, '\0'); - strbuf_add(&tree_buf, oid->hash, the_hash_algo->rawsz); + strbuf_add(&tree_buf, oid->hash, r->hash_algo->rawsz); } hash_object_file(tree_buf.buf, tree_buf.len, tree_type, &new_oid); if (!oideq(&new_oid, &it->oid)) From patchwork Thu Jan 30 20:32:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 11358641 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0FBF3139A for ; Thu, 30 Jan 2020 20:33:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E132C2083E for ; Thu, 30 Jan 2020 20:33:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=usp-br.20150623.gappssmtp.com header.i=@usp-br.20150623.gappssmtp.com header.b="Kd+ad25t" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727787AbgA3Udn (ORCPT ); Thu, 30 Jan 2020 15:33:43 -0500 Received: from mail-qk1-f196.google.com ([209.85.222.196]:45430 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726514AbgA3Udm (ORCPT ); Thu, 30 Jan 2020 15:33:42 -0500 Received: by mail-qk1-f196.google.com with SMTP id x1so4283001qkl.12 for ; Thu, 30 Jan 2020 12:33:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PFlu6Kd5xZf8c1KxpG0FtgGfpr0yJL7fsgah1JBxGpM=; b=Kd+ad25tbZwmSx0IEYKssfra6/JYdmrsZxDqis1eYmURkjsmxd2w3S/nH+cVsKMTFn NlFssENrFDBuUl0py3BkHX4K0TnYEj06bZLLutvutO324A6IN6h2W4fGdfe9tDRlf8Gu 3PK5ATYMCzy//7ehN97kOHuJkfZUyynX9rjzUAMSvzlL29ux0gOtfM/PIx2C0bITxrJN po8DkeC/vLKB9bTSjr7WvAE6QERF/cBSIu4IBbSQksZS90aeOYMghbFnf4bvMgZ4AOab 3+BYhMQmrDrt4AUC4tOq7RM8djbAfGex89Yahjzx0DNfSK5Wfbkr8wR3XTbLLWvLHwvP mXgQ== 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=PFlu6Kd5xZf8c1KxpG0FtgGfpr0yJL7fsgah1JBxGpM=; b=C6Q79x16MwdhTIskhRTcxCzP6TBN1Y7KpQd1Jae73gwJqDuocnFWUyqL3WxfQlvPDq x9yM8pCL4m/1UwHH3AbV1dxyB+3TelyX5etgdaNzA5N1hV8hnwpEgH266wA/x5fkYFiR gpT/hkUKdN86nE76JAhOZbAMhCDKCs95tTrcmX7dlBnYwBD7ssZzFRJSZX0YUqLCYK9j LhCduJ8BNbk7EjuxksRvr/j5LHYHn5PPSA0hb+NlxsOk5UlgIL0wNDTFedYk44mNNAUy C30O5jxPTLWVxK06yC0p1fYRA7Qnecifhmx9k5oMXLmlTDFLs8JpYlMdKCBJHNaxJFL/ Yvlw== X-Gm-Message-State: APjAAAWS1V3CumLHeCvEO9NzLW18yxfPNnItESbGUT7H+71TSpHeQ1wk /z7CDWFuIlH7K0ja5uho+Qk9RTcEiGo= X-Google-Smtp-Source: APXvYqzhfXCezRCYw+vKRuFvWCPBXOJ303+r+++Z8oukvpoY3ltfaRfZq9aDNtqHPFoEv5oE6g6ZkQ== X-Received: by 2002:ae9:f714:: with SMTP id s20mr7186379qkg.236.1580416421540; Thu, 30 Jan 2020 12:33:41 -0800 (PST) Received: from mango.semfio.usp.br ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id o12sm3436514qke.79.2020.01.30.12.33.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 12:33:40 -0800 (PST) From: Matheus Tavares To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Jeff King Subject: [PATCH 3/7] pack-check: use given repo's hash_algo at verify_packfile() Date: Thu, 30 Jan 2020 17:32:19 -0300 Message-Id: X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org At verify_packfile(), use the git_hash_algo from the provided repository instead of the_hash_algo, for consistency. Like the previous patch, this shouldn't bring any behavior changes, since this function is currently only receiving the_repository. Signed-off-by: Matheus Tavares --- pack-check.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pack-check.c b/pack-check.c index 2cc3603189..0fb3b365c7 100644 --- a/pack-check.c +++ b/pack-check.c @@ -67,23 +67,23 @@ static int verify_packfile(struct repository *r, if (!is_pack_valid(p)) return error("packfile %s cannot be accessed", p->pack_name); - the_hash_algo->init_fn(&ctx); + r->hash_algo->init_fn(&ctx); do { unsigned long remaining; unsigned char *in = use_pack(p, w_curs, offset, &remaining); offset += remaining; if (!pack_sig_ofs) - pack_sig_ofs = p->pack_size - the_hash_algo->rawsz; + pack_sig_ofs = p->pack_size - r->hash_algo->rawsz; if (offset > pack_sig_ofs) remaining -= (unsigned int)(offset - pack_sig_ofs); - the_hash_algo->update_fn(&ctx, in, remaining); + r->hash_algo->update_fn(&ctx, in, remaining); } while (offset < pack_sig_ofs); - the_hash_algo->final_fn(hash, &ctx); + r->hash_algo->final_fn(hash, &ctx); pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL); if (!hasheq(hash, pack_sig)) err = error("%s pack checksum mismatch", p->pack_name); - if (!hasheq(index_base + index_size - the_hash_algo->hexsz, pack_sig)) + if (!hasheq(index_base + index_size - r->hash_algo->hexsz, pack_sig)) err = error("%s pack checksum does not match its index", p->pack_name); unuse_pack(w_curs); From patchwork Thu Jan 30 20:32:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 11358643 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C3479924 for ; Thu, 30 Jan 2020 20:33:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 97C2E214AF for ; Thu, 30 Jan 2020 20:33:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=usp-br.20150623.gappssmtp.com header.i=@usp-br.20150623.gappssmtp.com header.b="LFU75hdn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727641AbgA3Udv (ORCPT ); Thu, 30 Jan 2020 15:33:51 -0500 Received: from mail-qk1-f195.google.com ([209.85.222.195]:35666 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727319AbgA3Udv (ORCPT ); Thu, 30 Jan 2020 15:33:51 -0500 Received: by mail-qk1-f195.google.com with SMTP id q15so4353466qki.2 for ; Thu, 30 Jan 2020 12:33:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xVwAtYWKTNwBR38RUA1pX5i62XBJJ8+8wAULJdqv8Js=; b=LFU75hdn0hrtzAuK5qavw9B7ouTQWJ6EqN0GrUe9B2QDasaGlA88r/nPUZiC3Gpomc VPKWM8JDs+gj3g54rLCTx7cX9E7a1AFSrmZpE0xD8/J2Jr+PpCAyieQjkp0fgjp1fW1y ZuX5Jk0Or8w/ynqTCrB7PFW+l4xK+O/tpRvSFXkdW2b1es1Ot9ZzaMhgNtHtPT74h3Ts EqjHvucfCDGQC04z0Hc6lECfrXZHxe586qpfjoN+a1gSDbVR9xUALhWHcFMR+ECX7xnB I7oQ61tAsVI58BkF2laoVsAC46rcpcYk8hL9GYg4He3KL4MiA92/av82YniQ5x7t1UZy Tz7A== 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=xVwAtYWKTNwBR38RUA1pX5i62XBJJ8+8wAULJdqv8Js=; b=gWAJlecf7gOlWW8hSrN0x4cXSRT75ezY8dA3NxexTfJUQMDGv1P2VzQMGPcasTTAcU diwMG90Jy6jifygIU1e0YFx/tpj2KVSXjSkM32kGLxlqTTGZbDJ6vn85+SO4IKDv/zhM rhkLqGJSk8ixmj47r3nrut7rVVkROfDExepJlKrFwaInFCGer8282fXO27VYWiFgwABg qPaNlI7ugmI5rKApvcSOCQA8VTjBqbZg3O1wvSSr5Wo8ZSUogpq0HHkdahSEUAVx7xVK EkvpK8x02t0x+dlQswOLuY5GJ3TIMCEWkwNktXk2UPU5Bo0iYcMlH60FGn8W46kGIdQL QT7g== X-Gm-Message-State: APjAAAUE7UiPpqsPZl8llgD0Y3dPX8Io4H1kC0LipaS7cAdj8dyWC8Gm 1jJ4AvHaTs9nhvKkyUUMsXw6e4JBT2E= X-Google-Smtp-Source: APXvYqzjOqX+Eok2IMK5VLlVTGaNie+BSna5Adt/Wd85DAPdENHL5ld+CVoGrwXM9m+OA2/VMbHSfQ== X-Received: by 2002:a05:620a:1108:: with SMTP id o8mr6885743qkk.118.1580416429075; Thu, 30 Jan 2020 12:33:49 -0800 (PST) Received: from mango.semfio.usp.br ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id o12sm3436514qke.79.2020.01.30.12.33.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 12:33:48 -0800 (PST) From: Matheus Tavares To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkg?= =?utf-8?b?Tmfhu41jIER1eQ==?= , "brian m. carlson" , Jeff King , Junio C Hamano Subject: [PATCH 4/7] streaming: allow open_istream() to handle any repo Date: Thu, 30 Jan 2020 17:32:20 -0300 Message-Id: X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Some callers of open_istream() at archive-tar.c and archive-zip.c are capable of working on arbitrary repositories but the repo struct is not passed down to open_istream(), which uses the_repository internally. For now, that's not a problem since the said callers are only being called with the_repository. But to be consistent and avoid future problems, let's allow open_istream() to receive a struct repository and use that instead of the_repository. This parameter addition will also be used in a future patch to make sha1-file.c:check_object_signature() be able to work on arbitrary repos. Signed-off-by: Matheus Tavares --- archive-tar.c | 6 +++--- archive-zip.c | 3 ++- builtin/index-pack.c | 3 ++- builtin/pack-objects.c | 3 ++- sha1-file.c | 2 +- streaming.c | 28 +++++++++++++++------------- streaming.h | 4 +++- 7 files changed, 28 insertions(+), 21 deletions(-) diff --git a/archive-tar.c b/archive-tar.c index e16d3f756d..5a77701a15 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -112,7 +112,7 @@ static void write_trailer(void) * queues up writes, so that all our write(2) calls write exactly one * full block; pads writes to RECORDSIZE */ -static int stream_blocked(const struct object_id *oid) +static int stream_blocked(struct repository *r, const struct object_id *oid) { struct git_istream *st; enum object_type type; @@ -120,7 +120,7 @@ static int stream_blocked(const struct object_id *oid) char buf[BLOCKSIZE]; ssize_t readlen; - st = open_istream(oid, &type, &sz, NULL); + st = open_istream(r, oid, &type, &sz, NULL); if (!st) return error(_("cannot stream blob %s"), oid_to_hex(oid)); for (;;) { @@ -324,7 +324,7 @@ static int write_tar_entry(struct archiver_args *args, if (buffer) write_blocked(buffer, size); else - err = stream_blocked(oid); + err = stream_blocked(args->repo, oid); } free(buffer); return err; diff --git a/archive-zip.c b/archive-zip.c index 11f5b1974b..e9f426298b 100644 --- a/archive-zip.c +++ b/archive-zip.c @@ -345,7 +345,8 @@ static int write_zip_entry(struct archiver_args *args, if (S_ISREG(mode) && type == OBJ_BLOB && !args->convert && size > big_file_threshold) { - stream = open_istream(oid, &type, &size, NULL); + stream = open_istream(args->repo, oid, &type, &size, + NULL); if (!stream) return error(_("cannot stream blob %s"), oid_to_hex(oid)); diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 60a5591039..7a08da8401 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -757,7 +757,8 @@ static int check_collison(struct object_entry *entry) memset(&data, 0, sizeof(data)); data.entry = entry; - data.st = open_istream(&entry->idx.oid, &type, &size, NULL); + data.st = open_istream(the_repository, &entry->idx.oid, &type, &size, + NULL); if (!data.st) return -1; if (size != entry->size || type != entry->type) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 393c20a2d7..ef17efd94e 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -303,7 +303,8 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent if (!usable_delta) { if (oe_type(entry) == OBJ_BLOB && oe_size_greater_than(&to_pack, entry, big_file_threshold) && - (st = open_istream(&entry->idx.oid, &type, &size, NULL)) != NULL) + (st = open_istream(the_repository, &entry->idx.oid, &type, + &size, NULL)) != NULL) buf = NULL; else { buf = read_object_file(&entry->idx.oid, &type, &size); diff --git a/sha1-file.c b/sha1-file.c index 03ae9ae93a..13b90b1cb1 100644 --- a/sha1-file.c +++ b/sha1-file.c @@ -986,7 +986,7 @@ int check_object_signature(const struct object_id *oid, void *map, return !oideq(oid, &real_oid) ? -1 : 0; } - st = open_istream(oid, &obj_type, &size, NULL); + st = open_istream(the_repository, oid, &obj_type, &size, NULL); if (!st) return -1; diff --git a/streaming.c b/streaming.c index fcd6303219..800f07a52c 100644 --- a/streaming.c +++ b/streaming.c @@ -16,6 +16,7 @@ enum input_source { }; typedef int (*open_istream_fn)(struct git_istream *, + struct repository *, struct object_info *, const struct object_id *, enum object_type *); @@ -29,8 +30,8 @@ struct stream_vtbl { #define open_method_decl(name) \ int open_istream_ ##name \ - (struct git_istream *st, struct object_info *oi, \ - const struct object_id *oid, \ + (struct git_istream *st, struct repository *r, \ + struct object_info *oi, const struct object_id *oid, \ enum object_type *type) #define close_method_decl(name) \ @@ -108,7 +109,8 @@ ssize_t read_istream(struct git_istream *st, void *buf, size_t sz) return st->vtbl->read(st, buf, sz); } -static enum input_source istream_source(const struct object_id *oid, +static enum input_source istream_source(struct repository *r, + const struct object_id *oid, enum object_type *type, struct object_info *oi) { @@ -117,7 +119,7 @@ static enum input_source istream_source(const struct object_id *oid, oi->typep = type; oi->sizep = &size; - status = oid_object_info_extended(the_repository, oid, oi, 0); + status = oid_object_info_extended(r, oid, oi, 0); if (status < 0) return stream_error; @@ -133,22 +135,23 @@ static enum input_source istream_source(const struct object_id *oid, } } -struct git_istream *open_istream(const struct object_id *oid, +struct git_istream *open_istream(struct repository *r, + const struct object_id *oid, enum object_type *type, unsigned long *size, struct stream_filter *filter) { struct git_istream *st; struct object_info oi = OBJECT_INFO_INIT; - const struct object_id *real = lookup_replace_object(the_repository, oid); - enum input_source src = istream_source(real, type, &oi); + const struct object_id *real = lookup_replace_object(r, oid); + enum input_source src = istream_source(r, real, type, &oi); if (src < 0) return NULL; st = xmalloc(sizeof(*st)); - if (open_istream_tbl[src](st, &oi, real, type)) { - if (open_istream_incore(st, &oi, real, type)) { + if (open_istream_tbl[src](st, r, &oi, real, type)) { + if (open_istream_incore(st, r, &oi, real, type)) { free(st); return NULL; } @@ -338,8 +341,7 @@ static struct stream_vtbl loose_vtbl = { static open_method_decl(loose) { - st->u.loose.mapped = map_loose_object(the_repository, - oid, &st->u.loose.mapsize); + st->u.loose.mapped = map_loose_object(r, oid, &st->u.loose.mapsize); if (!st->u.loose.mapped) return -1; if ((unpack_loose_header(&st->z, @@ -499,7 +501,7 @@ static struct stream_vtbl incore_vtbl = { static open_method_decl(incore) { - st->u.incore.buf = read_object_file_extended(the_repository, oid, type, &st->size, 0); + st->u.incore.buf = read_object_file_extended(r, oid, type, &st->size, 0); st->u.incore.read_ptr = 0; st->vtbl = &incore_vtbl; @@ -520,7 +522,7 @@ int stream_blob_to_fd(int fd, const struct object_id *oid, struct stream_filter ssize_t kept = 0; int result = -1; - st = open_istream(oid, &type, &sz, filter); + st = open_istream(the_repository, oid, &type, &sz, filter); if (!st) { if (filter) free_stream_filter(filter); diff --git a/streaming.h b/streaming.h index f465a3cd31..5e4e6acfd0 100644 --- a/streaming.h +++ b/streaming.h @@ -8,7 +8,9 @@ /* opaque */ struct git_istream; -struct git_istream *open_istream(const struct object_id *, enum object_type *, unsigned long *, struct stream_filter *); +struct git_istream *open_istream(struct repository *, const struct object_id *, + enum object_type *, unsigned long *, + struct stream_filter *); int close_istream(struct git_istream *); ssize_t read_istream(struct git_istream *, void *, size_t); From patchwork Thu Jan 30 20:32:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 11358645 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B7989924 for ; Thu, 30 Jan 2020 20:33:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 958D72083E for ; Thu, 30 Jan 2020 20:33:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=usp-br.20150623.gappssmtp.com header.i=@usp-br.20150623.gappssmtp.com header.b="Jw0KWK4T" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727799AbgA3Ud6 (ORCPT ); Thu, 30 Jan 2020 15:33:58 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:46523 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727319AbgA3Ud6 (ORCPT ); Thu, 30 Jan 2020 15:33:58 -0500 Received: by mail-qk1-f193.google.com with SMTP id g195so4268500qke.13 for ; Thu, 30 Jan 2020 12:33:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5Edn93+Vhzlnnwnhkrb+f/jdc3rLUGFDFoiKL0V14Fw=; b=Jw0KWK4TF6O3oPsWKLfGbXUKBpJIy3dWu+w8dgJaqFynA9PZJ0ir4SQs+KhS85L7rj jtQrTk3NaaInmvt5gZlwI9R9ND2VGMiFjVd8nHeNHkEiktBVEBiOFL9Jbkk6u/m76bEF ItB04U2R+vRZAtqVIwFEV71ZpHWB+WuRHhsCYd0cTs5QP9gj1lqmNlUkmMrANeTtxoCl fqZFbCoAxdD5eEF3tV3RJUuzYK6RbCO/F3dO63itUeEB0KLBUMKXK7HyslOfH7VfjHiG rEHVRrF02Rs7vGM2QI/quSgd1aGtSwGk0H7Y5VUwnd464iWcMWIBfxGSJ12esA4F+9dx ZdgA== 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=5Edn93+Vhzlnnwnhkrb+f/jdc3rLUGFDFoiKL0V14Fw=; b=PYEckPFYbCWq68R0oR6nUO+mqQPc84rX64+BOoXb+mhyAZGBEsYi8ksZ8ccJcZzCeB ZN/O82rn0ygsOe4yzqANpIbC1H5zJmN8rDhMr0Q1MyR04LVGHTE9qzEJ2fqsMqu5vIke 5Y+xhLXdUusWuv3JaJJjABojBcP3PD4Hwh/d/qsUOOU/sGuvhkFZIDOitS4p5wUoMQIl 2NksEmTdV3XAIVlZiPwso+C1vyadYiMR5T/zehlXO+SJMPIW7XXb317oi6aH08dwhMhc 9kIC7bX7tB3ZnWX0yoovCSWiJo1w4YlxDBIEJy09ZXM0531OiDepkcyuPv9XeyoRNUfF 7Sjg== X-Gm-Message-State: APjAAAVpAQurUObUNUI9/LJ+eleUMpi9vJOJAm3a/JYQnZq2HEwaJSMo m6cccY5IPs1fqZcy3/kdJDozZCfkSR4= X-Google-Smtp-Source: APXvYqzJPOJk75y0pbamS2pOvNVhLY0Yes+w6j7XoYuUDX673KxWqEW6RKBrzRFZ0HgjnpkWQEFZcQ== X-Received: by 2002:a37:9f57:: with SMTP id i84mr7220296qke.29.1580416437341; Thu, 30 Jan 2020 12:33:57 -0800 (PST) Received: from mango.semfio.usp.br ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id o12sm3436514qke.79.2020.01.30.12.33.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 12:33:56 -0800 (PST) From: Matheus Tavares To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano , Patryk Obara , "brian m. carlson" , Eric Sunshine , =?utf-8?q?Torsten_B=C3=B6gershause?= =?utf-8?q?n?= Subject: [PATCH 5/7] sha1-file: pass git_hash_algo to write_object_file_prepare() Date: Thu, 30 Jan 2020 17:32:21 -0300 Message-Id: X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Allow write_object_file_prepare() to receive arbitrary 'struct git_hash_algo's instead of always using the_hash_algo. The added parameter will be used in the next commit to make hash_object_file() be able to work with arbitrary git_hash_algo's, as well. Signed-off-by: Matheus Tavares --- sha1-file.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/sha1-file.c b/sha1-file.c index 13b90b1cb1..e789bfd153 100644 --- a/sha1-file.c +++ b/sha1-file.c @@ -1647,7 +1647,8 @@ void *read_object_with_reference(struct repository *r, } } -static void write_object_file_prepare(const void *buf, unsigned long len, +static void write_object_file_prepare(const struct git_hash_algo *algo, + const void *buf, unsigned long len, const char *type, struct object_id *oid, char *hdr, int *hdrlen) { @@ -1657,10 +1658,10 @@ static void write_object_file_prepare(const void *buf, unsigned long len, *hdrlen = xsnprintf(hdr, *hdrlen, "%s %"PRIuMAX , type, (uintmax_t)len)+1; /* Sha1.. */ - the_hash_algo->init_fn(&c); - the_hash_algo->update_fn(&c, hdr, *hdrlen); - the_hash_algo->update_fn(&c, buf, len); - the_hash_algo->final_fn(oid->hash, &c); + algo->init_fn(&c); + algo->update_fn(&c, hdr, *hdrlen); + algo->update_fn(&c, buf, len); + algo->final_fn(oid->hash, &c); } /* @@ -1718,7 +1719,8 @@ int hash_object_file(const void *buf, unsigned long len, const char *type, { char hdr[MAX_HEADER_LEN]; int hdrlen = sizeof(hdr); - write_object_file_prepare(buf, len, type, oid, hdr, &hdrlen); + write_object_file_prepare(the_hash_algo, buf, len, type, oid, hdr, + &hdrlen); return 0; } @@ -1876,7 +1878,8 @@ int write_object_file(const void *buf, unsigned long len, const char *type, /* Normally if we have it in the pack then we do not bother writing * it out into .git/objects/??/?{38} file. */ - write_object_file_prepare(buf, len, type, oid, hdr, &hdrlen); + write_object_file_prepare(the_hash_algo, buf, len, type, oid, hdr, + &hdrlen); if (freshen_packed_object(oid) || freshen_loose_object(oid)) return 0; return write_loose_object(oid, hdr, hdrlen, buf, len, 0); @@ -1892,7 +1895,8 @@ int hash_object_file_literally(const void *buf, unsigned long len, /* type string, SP, %lu of the length plus NUL must fit this */ hdrlen = strlen(type) + MAX_HEADER_LEN; header = xmalloc(hdrlen); - write_object_file_prepare(buf, len, type, oid, header, &hdrlen); + write_object_file_prepare(the_hash_algo, buf, len, type, oid, header, + &hdrlen); if (!(flags & HASH_WRITE_OBJECT)) goto cleanup; From patchwork Thu Jan 30 20:32:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 11358647 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 092A1139A for ; Thu, 30 Jan 2020 20:34:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C73BD20CC7 for ; Thu, 30 Jan 2020 20:34:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=usp-br.20150623.gappssmtp.com header.i=@usp-br.20150623.gappssmtp.com header.b="sCf3UZpW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727818AbgA3UeF (ORCPT ); Thu, 30 Jan 2020 15:34:05 -0500 Received: from mail-qk1-f181.google.com ([209.85.222.181]:37560 "EHLO mail-qk1-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727706AbgA3UeF (ORCPT ); Thu, 30 Jan 2020 15:34:05 -0500 Received: by mail-qk1-f181.google.com with SMTP id 21so4341867qky.4 for ; Thu, 30 Jan 2020 12:34:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9ZzSQrYsrzbc1Ozbtg+HY0OurFxYZmDjegKiwbKYKBE=; b=sCf3UZpWDLguji2/FchJuGFuoqjcKgDZaGjwWzew6z6vgmuyVs5GQV2dSkwY0/TrIf r5ejOahSobIdFNcljK3ByAefatWfigyZJOJX0j9h0LPxdjQ0a6zI3Rc4ZgQMrFltG/Ny du1JaSSbz+Pi31K+2lob9m+2eGAE9x0Lr57zl3JbZgbEDD7VTQiPEuWov4Xsne8+ZmIx DaiB22EPTxpoTWlKU5To1gFuyXO0+84Us/L0sx+oV6ncxlcPz46kHHLAl3J6GXZRR4sf 04Se0IKiKgXstoxsVBPIMwrZsmbhPsYGPJn3ZPIikFiBDdfaKLmOJ643lHJS65J5oGvb qOOQ== 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=9ZzSQrYsrzbc1Ozbtg+HY0OurFxYZmDjegKiwbKYKBE=; b=RcP13pq7EtZfUqmpnZd2UP5y0e1/Pj8uQWXGljQv9JrawEYX5COKE9D9VAo8wKALE5 r6qWkBbZ0xhDuHwWLR2IEtMxdMT8dEyd7WplA9uuji9x92WQn14MD0zWwUvBcWLo9HzY IJhs3kKcZxYxoJ4LZne4CpRcjPxJ4703WibWl4kOY1k6fbq4m8PZ4zHx+OUTZ7WNqFG/ 3g1PuC50KTBzlo8UeqA2eKVWhIsno7ZwZTdGBjrEG3idyxF3or3mxWQbp+apN+Zt8fMW T4bpwM4aP/2iJqnHf7tra6fzebaaBt9we1IUjF5jNVtUgJH6UatBTTARs9ixLYHegm/w ik/w== X-Gm-Message-State: APjAAAXqZo3wTpoxOobntsSXu5M5cKFHRTms0blkxFk4gd0llzC37ang w2mfSUIrqjkIYOhKQ1dSxluKZ2cuMD0= X-Google-Smtp-Source: APXvYqyR2x/JH+V7fC65p4v0oRRK3dixaN3tzVXPHLw+ILmCejVOJamVNM5qxzY5Fpwqrv5AdTfI1Q== X-Received: by 2002:a37:9e96:: with SMTP id h144mr7290696qke.327.1580416443985; Thu, 30 Jan 2020 12:34:03 -0800 (PST) Received: from mango.semfio.usp.br ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id o12sm3436514qke.79.2020.01.30.12.34.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 12:34:03 -0800 (PST) From: Matheus Tavares To: git@vger.kernel.org Cc: Stefan Beller , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkg?= =?utf-8?b?Tmfhu41jIER1eQ==?= , Junio C Hamano , "brian m. carlson" , Jeff King Subject: [PATCH 6/7] sha1-file: pass git_hash_algo to hash_object_file() Date: Thu, 30 Jan 2020 17:32:22 -0300 Message-Id: <40b95d0a979eb4865572611bfb6d1bfe2be1de57.1580413221.git.matheus.bernardino@usp.br> X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Allow hash_object_file() to work on arbitrary repos by introducing a git_hash_algo parameter. Change callers which have a struct repository pointer in their scope to pass on the git_hash_algo from the said repo. For all other callers, pass on the_hash_algo, which was already being used internally at hash_object_file(). This functionality will be used in the following patch to make check_object_signature() be able to work on arbitrary repos (which, in turn, will be used to fix an inconsistency at object.c:parse_object()). Signed-off-by: Matheus Tavares --- apply.c | 6 ++++-- builtin/index-pack.c | 2 +- builtin/replace.c | 3 ++- builtin/unpack-objects.c | 3 ++- cache-tree.c | 9 ++++++--- convert.c | 2 +- diffcore-rename.c | 4 ++-- dir.c | 4 ++-- log-tree.c | 3 ++- object-store.h | 5 +++-- sha1-file.c | 20 +++++++++++--------- 11 files changed, 36 insertions(+), 25 deletions(-) diff --git a/apply.c b/apply.c index fab44322c5..bdc008fae2 100644 --- a/apply.c +++ b/apply.c @@ -3157,7 +3157,8 @@ static int apply_binary(struct apply_state *state, * See if the old one matches what the patch * applies to. */ - hash_object_file(img->buf, img->len, blob_type, &oid); + hash_object_file(the_hash_algo, img->buf, img->len, blob_type, + &oid); if (strcmp(oid_to_hex(&oid), patch->old_oid_prefix)) return error(_("the patch applies to '%s' (%s), " "which does not match the " @@ -3202,7 +3203,8 @@ static int apply_binary(struct apply_state *state, name); /* verify that the result matches */ - hash_object_file(img->buf, img->len, blob_type, &oid); + hash_object_file(the_hash_algo, img->buf, img->len, blob_type, + &oid); if (strcmp(oid_to_hex(&oid), patch->new_oid_prefix)) return error(_("binary patch to '%s' creates incorrect result (expecting %s, got %s)"), name, patch->new_oid_prefix, oid_to_hex(&oid)); diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 7a08da8401..0183610a76 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -949,7 +949,7 @@ static void resolve_delta(struct object_entry *delta_obj, free(delta_data); if (!result->data) bad_object(delta_obj->idx.offset, _("failed to apply delta")); - hash_object_file(result->data, result->size, + hash_object_file(the_hash_algo, result->data, result->size, type_name(delta_obj->real_type), &delta_obj->idx.oid); sha1_object(result->data, NULL, result->size, delta_obj->real_type, &delta_obj->idx.oid); diff --git a/builtin/replace.c b/builtin/replace.c index bd92dc63b9..b36d17a657 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -409,7 +409,8 @@ static int check_one_mergetag(struct commit *commit, struct tag *tag; int i; - hash_object_file(extra->value, extra->len, type_name(OBJ_TAG), &tag_oid); + hash_object_file(the_hash_algo, extra->value, extra->len, + type_name(OBJ_TAG), &tag_oid); tag = lookup_tag(the_repository, &tag_oid); if (!tag) return error(_("bad mergetag in commit '%s'"), ref); diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 9100964667..dd4a75e030 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -265,7 +265,8 @@ static void write_object(unsigned nr, enum object_type type, } else { struct object *obj; int eaten; - hash_object_file(buf, size, type_name(type), &obj_list[nr].oid); + hash_object_file(the_hash_algo, buf, size, type_name(type), + &obj_list[nr].oid); added_object(nr, type, buf, size); obj = parse_object_buffer(the_repository, &obj_list[nr].oid, type, size, buf, diff --git a/cache-tree.c b/cache-tree.c index 8c51a15751..a537a806c1 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -407,13 +407,15 @@ static int update_one(struct cache_tree *it, if (repair) { struct object_id oid; - hash_object_file(buffer.buf, buffer.len, tree_type, &oid); + hash_object_file(the_hash_algo, buffer.buf, buffer.len, + tree_type, &oid); if (has_object_file_with_flags(&oid, OBJECT_INFO_SKIP_FETCH_OBJECT)) oidcpy(&it->oid, &oid); else to_invalidate = 1; } else if (dryrun) { - hash_object_file(buffer.buf, buffer.len, tree_type, &it->oid); + hash_object_file(the_hash_algo, buffer.buf, buffer.len, + tree_type, &it->oid); } else if (write_object_file(buffer.buf, buffer.len, tree_type, &it->oid)) { strbuf_release(&buffer); @@ -828,7 +830,8 @@ static void verify_one(struct repository *r, strbuf_addf(&tree_buf, "%o %.*s%c", mode, entlen, name, '\0'); strbuf_add(&tree_buf, oid->hash, r->hash_algo->rawsz); } - hash_object_file(tree_buf.buf, tree_buf.len, tree_type, &new_oid); + hash_object_file(r->hash_algo, tree_buf.buf, tree_buf.len, tree_type, + &new_oid); if (!oideq(&new_oid, &it->oid)) BUG("cache-tree for path %.*s does not match. " "Expected %s got %s", len, path->buf, diff --git a/convert.c b/convert.c index 797e0bd0b1..33507ee0a9 100644 --- a/convert.c +++ b/convert.c @@ -1146,7 +1146,7 @@ static int ident_to_worktree(const char *src, size_t len, /* are we "faking" in place editing ? */ if (src == buf->buf) to_free = strbuf_detach(buf, NULL); - hash_object_file(src, len, "blob", &oid); + hash_object_file(the_hash_algo, src, len, "blob", &oid); strbuf_grow(buf, len + cnt * (the_hash_algo->hexsz + 3)); for (;;) { diff --git a/diffcore-rename.c b/diffcore-rename.c index 531d7adeaf..e189f407af 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -263,8 +263,8 @@ static unsigned int hash_filespec(struct repository *r, if (!filespec->oid_valid) { if (diff_populate_filespec(r, filespec, 0)) return 0; - hash_object_file(filespec->data, filespec->size, "blob", - &filespec->oid); + hash_object_file(r->hash_algo, filespec->data, filespec->size, + "blob", &filespec->oid); } return oidhash(&filespec->oid); } diff --git a/dir.c b/dir.c index 7d255227b1..512c5d7ea6 100644 --- a/dir.c +++ b/dir.c @@ -1002,8 +1002,8 @@ static int add_patterns(const char *fname, const char *base, int baselen, oidcpy(&oid_stat->oid, &istate->cache[pos]->oid); else - hash_object_file(buf, size, "blob", - &oid_stat->oid); + hash_object_file(the_hash_algo, buf, size, + "blob", &oid_stat->oid); fill_stat_data(&oid_stat->stat, &st); oid_stat->valid = 1; } diff --git a/log-tree.c b/log-tree.c index 4e32638de8..cae38dcc66 100644 --- a/log-tree.c +++ b/log-tree.c @@ -501,7 +501,8 @@ static int show_one_mergetag(struct commit *commit, int status, nth; size_t payload_size, gpg_message_offset; - hash_object_file(extra->value, extra->len, type_name(OBJ_TAG), &oid); + hash_object_file(the_hash_algo, extra->value, extra->len, + type_name(OBJ_TAG), &oid); tag = lookup_tag(the_repository, &oid); if (!tag) return -1; /* error message already given */ diff --git a/object-store.h b/object-store.h index 61b8b13e3b..cf97cbc292 100644 --- a/object-store.h +++ b/object-store.h @@ -198,8 +198,9 @@ static inline void *repo_read_object_file(struct repository *r, /* Read and unpack an object file into memory, write memory to an object file */ int oid_object_info(struct repository *r, const struct object_id *, unsigned long *); -int hash_object_file(const void *buf, unsigned long len, - const char *type, struct object_id *oid); +int hash_object_file(const struct git_hash_algo *algo, const void *buf, + unsigned long len, const char *type, + struct object_id *oid); int write_object_file(const void *buf, unsigned long len, const char *type, struct object_id *oid); diff --git a/sha1-file.c b/sha1-file.c index e789bfd153..d545e8b882 100644 --- a/sha1-file.c +++ b/sha1-file.c @@ -982,7 +982,7 @@ int check_object_signature(const struct object_id *oid, void *map, int hdrlen; if (map) { - hash_object_file(map, size, type, &real_oid); + hash_object_file(the_hash_algo, map, size, type, &real_oid); return !oideq(oid, &real_oid) ? -1 : 0; } @@ -1543,7 +1543,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type, { struct cached_object *co; - hash_object_file(buf, len, type_name(type), oid); + hash_object_file(the_hash_algo, buf, len, type_name(type), oid); if (has_object_file(oid) || find_cached_object(oid)) return 0; ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc); @@ -1714,13 +1714,13 @@ static int write_buffer(int fd, const void *buf, size_t len) return 0; } -int hash_object_file(const void *buf, unsigned long len, const char *type, +int hash_object_file(const struct git_hash_algo *algo, const void *buf, + unsigned long len, const char *type, struct object_id *oid) { char hdr[MAX_HEADER_LEN]; int hdrlen = sizeof(hdr); - write_object_file_prepare(the_hash_algo, buf, len, type, oid, hdr, - &hdrlen); + write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen); return 0; } @@ -2006,7 +2006,8 @@ static int index_mem(struct index_state *istate, if (write_object) ret = write_object_file(buf, size, type_name(type), oid); else - ret = hash_object_file(buf, size, type_name(type), oid); + ret = hash_object_file(the_hash_algo, buf, size, + type_name(type), oid); if (re_allocated) free(buf); return ret; @@ -2032,8 +2033,8 @@ static int index_stream_convert_blob(struct index_state *istate, ret = write_object_file(sbuf.buf, sbuf.len, type_name(OBJ_BLOB), oid); else - ret = hash_object_file(sbuf.buf, sbuf.len, type_name(OBJ_BLOB), - oid); + ret = hash_object_file(the_hash_algo, sbuf.buf, sbuf.len, + type_name(OBJ_BLOB), oid); strbuf_release(&sbuf); return ret; } @@ -2151,7 +2152,8 @@ int index_path(struct index_state *istate, struct object_id *oid, if (strbuf_readlink(&sb, path, st->st_size)) return error_errno("readlink(\"%s\")", path); if (!(flags & HASH_WRITE_OBJECT)) - hash_object_file(sb.buf, sb.len, blob_type, oid); + hash_object_file(the_hash_algo, sb.buf, sb.len, + blob_type, oid); else if (write_object_file(sb.buf, sb.len, blob_type, oid)) rc = error(_("%s: failed to insert into database"), path); strbuf_release(&sb); From patchwork Thu Jan 30 20:32:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 11358649 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9CF6D139A for ; Thu, 30 Jan 2020 20:34:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 68572214DB for ; Thu, 30 Jan 2020 20:34:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=usp-br.20150623.gappssmtp.com header.i=@usp-br.20150623.gappssmtp.com header.b="KFwdDWe7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727820AbgA3UeM (ORCPT ); Thu, 30 Jan 2020 15:34:12 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:37272 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727687AbgA3UeM (ORCPT ); Thu, 30 Jan 2020 15:34:12 -0500 Received: by mail-qk1-f193.google.com with SMTP id 21so4342178qky.4 for ; Thu, 30 Jan 2020 12:34:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nlIfW7HKBKxoTynCquzM4VgMJyBVJaX2dTNAXLz+jFg=; b=KFwdDWe7xWHw+v8Vmva5Kt0b3oDON07XGyviBJHvp/8C03xWw2fhoVnXfm3zW4MyeY iItdyVXZZxbKQ2EE9VSKDOeqQKaD8979sUyx7x61rBBipDlnU38EGkE2/pMaSRfJVpkf TzeXL8UKl3uEyk+/gQ+Y4IbM1cNQBjUCEO7UwUZ7jbzW2XEdMqnsDuvQs/ToCsDPB9UE peB6c4kZoj9j/p9ijMEURcvkk+JFF73kUwHISOeHU6YrqBQooUB0S4kZack446A4Pxa3 2LScKnM1rL5vTwxggY4fBiT1eBrzIE2Ds0BIYZwyHyafjXAH3UXy9I1vqUo7ivwcrEN7 dCwg== 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=nlIfW7HKBKxoTynCquzM4VgMJyBVJaX2dTNAXLz+jFg=; b=S/dv1hWckCzYE4k37rv2aov7AV6P6DwCPRsaDAuMEl8+XUiDfeFv74xzLWLwVDA4GG +WJek7A/Djxn5ZFpyxHuXLmJ1kew/ZHcimXWxYVc2fCXAWzLcZ3wzeuCtjAFEah1SZPt 9LiG/6wLfVd0suxU9Qz237HOBmSiLMyOFpKmcAi+Lmr6kdWBuekuCP8Ywrbz0wvLkR6Q K5aeBEinmyLES9sOUyel5Uw/oqK5HyXkXSz2UshJQS1ri/z4hXNfdFog9LrzT1lz+z4i G+etbubUXWutGL8WpDQ9tNkFXMcH8jpb9LWmTqCAMWEE8eNJlv3kmzWhPcuRHZha3j4W Kd8A== X-Gm-Message-State: APjAAAVnqZ9I6uvZuvS9Wi+I/TbVT3z10vRfQxWMWN+SgPF1kr2w6RVw 4m6w77OeNaRQZ2VVCk/MjuDJZyC78Ds= X-Google-Smtp-Source: APXvYqzfx8O6pv0NFkJOrBLa5wKkDLGtbjwjhcHLsK0nzAQ8XZZCOd+18vdCNhxPHHehgFLcy9i8wg== X-Received: by 2002:ae9:f714:: with SMTP id s20mr7188359qkg.236.1580416449508; Thu, 30 Jan 2020 12:34:09 -0800 (PST) Received: from mango.semfio.usp.br ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id o12sm3436514qke.79.2020.01.30.12.34.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 12:34:08 -0800 (PST) From: Matheus Tavares To: git@vger.kernel.org Cc: Junio C Hamano , "brian m. carlson" , Jeff King , Stefan Beller Subject: [PATCH 7/7] sha1-file: allow check_object_signature() to handle any repo Date: Thu, 30 Jan 2020 17:32:23 -0300 Message-Id: X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Some callers of check_object_signature() can work on arbitrary repositories, but the repo does not get passed to this function. Instead, the_repository is always used internally. To fix possible inconsistencies, allow the function to receive a struct repository and make those callers pass on the repo being handled. Signed-off-by: Matheus Tavares --- builtin/fast-export.c | 3 ++- builtin/index-pack.c | 5 +++-- builtin/mktag.c | 7 +++++-- cache.h | 3 ++- object.c | 5 +++-- pack-check.c | 2 +- sha1-file.c | 21 +++++++++++---------- 7 files changed, 27 insertions(+), 19 deletions(-) diff --git a/builtin/fast-export.c b/builtin/fast-export.c index dbec4df92b..25386b34d3 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -293,7 +293,8 @@ static void export_blob(const struct object_id *oid) buf = read_object_file(oid, &type, &size); if (!buf) die("could not read blob %s", oid_to_hex(oid)); - if (check_object_signature(oid, buf, size, type_name(type)) < 0) + if (check_object_signature(the_repository, oid, buf, size, + type_name(type)) < 0) die("oid mismatch in blob %s", oid_to_hex(oid)); object = parse_object_buffer(the_repository, oid, type, size, buf, &eaten); diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 0183610a76..acdda17d84 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1384,8 +1384,9 @@ static void fix_unresolved_deltas(struct hashfile *f) if (!base_obj->data) continue; - if (check_object_signature(&d->oid, base_obj->data, - base_obj->size, type_name(type))) + if (check_object_signature(the_repository, &d->oid, + base_obj->data, base_obj->size, + type_name(type))) die(_("local object %s is corrupt"), oid_to_hex(&d->oid)); base_obj->obj = append_obj_to_pack(f, d->oid.hash, base_obj->data, base_obj->size, type); diff --git a/builtin/mktag.c b/builtin/mktag.c index 6fb7dc8578..4982d3a93e 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -29,8 +29,11 @@ static int verify_object(const struct object_id *oid, const char *expected_type) const struct object_id *repl = lookup_replace_object(the_repository, oid); if (buffer) { - if (type == type_from_string(expected_type)) - ret = check_object_signature(repl, buffer, size, expected_type); + if (type == type_from_string(expected_type)) { + ret = check_object_signature(the_repository, repl, + buffer, size, + expected_type); + } free(buffer); } return ret; diff --git a/cache.h b/cache.h index cbfaead23a..40ae160991 100644 --- a/cache.h +++ b/cache.h @@ -1363,7 +1363,8 @@ int git_open_cloexec(const char *name, int flags); int unpack_loose_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz); int parse_loose_header(const char *hdr, unsigned long *sizep); -int check_object_signature(const struct object_id *oid, void *buf, unsigned long size, const char *type); +int check_object_signature(struct repository *r, const struct object_id *oid, + void *buf, unsigned long size, const char *type); int finalize_object_file(const char *tmpfile, const char *filename); diff --git a/object.c b/object.c index 142ef69399..81f5820fc3 100644 --- a/object.c +++ b/object.c @@ -262,7 +262,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid) if ((obj && obj->type == OBJ_BLOB && repo_has_object_file(r, oid)) || (!obj && repo_has_object_file(r, oid) && oid_object_info(r, oid, NULL) == OBJ_BLOB)) { - if (check_object_signature(repl, NULL, 0, NULL) < 0) { + if (check_object_signature(r, repl, NULL, 0, NULL) < 0) { error(_("hash mismatch %s"), oid_to_hex(oid)); return NULL; } @@ -272,7 +272,8 @@ struct object *parse_object(struct repository *r, const struct object_id *oid) buffer = repo_read_object_file(r, oid, &type, &size); if (buffer) { - if (check_object_signature(repl, buffer, size, type_name(type)) < 0) { + if (check_object_signature(r, repl, buffer, size, + type_name(type)) < 0) { free(buffer); error(_("hash mismatch %s"), oid_to_hex(repl)); return NULL; diff --git a/pack-check.c b/pack-check.c index 0fb3b365c7..e4ef71c673 100644 --- a/pack-check.c +++ b/pack-check.c @@ -144,7 +144,7 @@ static int verify_packfile(struct repository *r, err = error("cannot unpack %s from %s at offset %"PRIuMAX"", oid_to_hex(entries[i].oid.oid), p->pack_name, (uintmax_t)entries[i].offset); - else if (check_object_signature(entries[i].oid.oid, data, size, type_name(type))) + else if (check_object_signature(r, entries[i].oid.oid, data, size, type_name(type))) err = error("packed %s from %s is corrupt", oid_to_hex(entries[i].oid.oid), p->pack_name); else if (fn) { diff --git a/sha1-file.c b/sha1-file.c index d545e8b882..e2f608ac08 100644 --- a/sha1-file.c +++ b/sha1-file.c @@ -971,8 +971,8 @@ void *xmmap(void *start, size_t length, * With "map" == NULL, try reading the object named with "oid" using * the streaming interface and rehash it to do the same. */ -int check_object_signature(const struct object_id *oid, void *map, - unsigned long size, const char *type) +int check_object_signature(struct repository *r, const struct object_id *oid, + void *map, unsigned long size, const char *type) { struct object_id real_oid; enum object_type obj_type; @@ -982,11 +982,11 @@ int check_object_signature(const struct object_id *oid, void *map, int hdrlen; if (map) { - hash_object_file(the_hash_algo, map, size, type, &real_oid); + hash_object_file(r->hash_algo, map, size, type, &real_oid); return !oideq(oid, &real_oid) ? -1 : 0; } - st = open_istream(the_repository, oid, &obj_type, &size, NULL); + st = open_istream(r, oid, &obj_type, &size, NULL); if (!st) return -1; @@ -994,8 +994,8 @@ int check_object_signature(const struct object_id *oid, void *map, hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX , type_name(obj_type), (uintmax_t)size) + 1; /* Sha1.. */ - the_hash_algo->init_fn(&c); - the_hash_algo->update_fn(&c, hdr, hdrlen); + r->hash_algo->init_fn(&c); + r->hash_algo->update_fn(&c, hdr, hdrlen); for (;;) { char buf[1024 * 16]; ssize_t readlen = read_istream(st, buf, sizeof(buf)); @@ -1006,9 +1006,9 @@ int check_object_signature(const struct object_id *oid, void *map, } if (!readlen) break; - the_hash_algo->update_fn(&c, buf, readlen); + r->hash_algo->update_fn(&c, buf, readlen); } - the_hash_algo->final_fn(real_oid.hash, &c); + r->hash_algo->final_fn(real_oid.hash, &c); close_istream(st); return !oideq(oid, &real_oid) ? -1 : 0; } @@ -2454,8 +2454,9 @@ int read_loose_object(const char *path, git_inflate_end(&stream); goto out; } - if (check_object_signature(expected_oid, *contents, - *size, type_name(*type))) { + if (check_object_signature(the_repository, expected_oid, + *contents, *size, + type_name(*type))) { error(_("hash mismatch for %s (expected %s)"), path, oid_to_hex(expected_oid)); free(*contents);