From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tay Ray Chuan Subject: [PATCH 11/23] Don't expect verify_pack() callers to set pack_size Date: Sat, 6 Jun 2009 16:43:38 +0800 Message-ID: <20090606164338.44e20f8c.rctay89@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: Junio C Hamano , Johannes Schindelin , Mike Hommey To: Git Mailing List X-From: git-owner@vger.kernel.org Sat Jun 06 10:49:50 2009 Return-path: Envelope-to: gcvg-git-2@gmane.org Received: from vger.kernel.org ([209.132.176.167]) by lo.gmane.org with esmtp (Exim 4.50) id 1MCrb1-0003yU-Vx for gcvg-git-2@gmane.org; Sat, 06 Jun 2009 10:49:48 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754404AbZFFItd (ORCPT ); Sat, 6 Jun 2009 04:49:33 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754398AbZFFItd (ORCPT ); Sat, 6 Jun 2009 04:49:33 -0400 Received: from rv-out-0506.google.com ([209.85.198.226]:51633 "EHLO rv-out-0506.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754379AbZFFItc (ORCPT ); Sat, 6 Jun 2009 04:49:32 -0400 Received: by rv-out-0506.google.com with SMTP id f9so823103rvb.1 for ; Sat, 06 Jun 2009 01:49:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:in-reply-to:references:x-mailer:mime-version :content-type:content-transfer-encoding; bh=CZh4SGuWw4uQ+UJwTwmD+BGt4uHC4HwYlxQLEKhQriY=; b=m4tLueDn0YDSRE7nTRpCsGdG4Vb11bcQxoMnyRdXbLCNSjP7JhDnrKDtDOKqYOiArg jsKw28ukg/csGvimGDfKsvLKdZmrJInV/BUM0kYOmsXZUalpV/fCliEvPD5iMYqcJLzM zxadDIoE1aWiSj0CRQUZ4JYdZdFeXJZvKIJKI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:in-reply-to:references:x-mailer :mime-version:content-type:content-transfer-encoding; b=M2KzewN+wDnD5nOvgVex+iHeVlGqHhxCRgkMybKtWZC/fbmmSn8fCBeMNNYcLCgdoq +6tfqMfaLaV90LNFR0r3zZFwuWIDyHFlPnn7G01ZdoQL5EjSxuDvt/2nO3ddqxcQRNll AnGFbGlWlnLaAWxmekKvhhxnR3ZszSQu8W5OA= Received: by 10.142.221.11 with SMTP id t11mr291270wfg.244.1244278174989; Sat, 06 Jun 2009 01:49:34 -0700 (PDT) Received: from your-cukc5e3z5n (cm97.zeta149.maxonline.com.sg [116.87.149.97]) by mx.google.com with ESMTPS id 22sm2777843wfd.39.2009.06.06.01.49.32 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 06 Jun 2009 01:49:34 -0700 (PDT) In-Reply-To: X-Mailer: Sylpheed 2.6.0 (GTK+ 2.10.14; i686-pc-mingw32) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: From: Mike Hommey Date: Sun, 18 Jan 2009 09:04:26 +0100 Since use_pack() will end up populating pack_size if it is not already set, we can just adapt the code in verify_packfile() such that it doesn't require pack_size to be set beforehand. This allows callers not to have to set pack_size themselves, and we can thus revert changes from 1c23d794 (Don't die in git-http-fetch when fetching packs). Signed-off-by: Mike Hommey Signed-off-by: Tay Ray Chuan --- pack-check.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pack-check.c b/pack-check.c index 90c33b1..166ca70 100644 --- a/pack-check.c +++ b/pack-check.c @@ -49,7 +49,7 @@ static int verify_packfile(struct packed_git *p, const unsigned char *index_base = p->index_data; git_SHA_CTX ctx; unsigned char sha1[20], *pack_sig; - off_t offset = 0, pack_sig_ofs = p->pack_size - 20; + off_t offset = 0, pack_sig_ofs = 0; uint32_t nr_objects, i; int err = 0; struct idx_entry *entries; @@ -61,14 +61,16 @@ static int verify_packfile(struct packed_git *p, */ git_SHA1_Init(&ctx); - while (offset < pack_sig_ofs) { + do { unsigned int remaining; unsigned char *in = use_pack(p, w_curs, offset, &remaining); offset += remaining; + if (!pack_sig_ofs) + pack_sig_ofs = p->pack_size - 20; if (offset > pack_sig_ofs) remaining -= (unsigned int)(offset - pack_sig_ofs); git_SHA1_Update(&ctx, in, remaining); - } + } while (offset < pack_sig_ofs); git_SHA1_Final(sha1, &ctx); pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL); if (hashcmp(sha1, pack_sig)) -- 1.6.3.1