From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Pitre Subject: [PATCH 32/38] pack v4: parse delta base reference Date: Thu, 05 Sep 2013 02:19:55 -0400 Message-ID: <1378362001-1738-33-git-send-email-nico@fluxnic.net> References: <1378362001-1738-1-git-send-email-nico@fluxnic.net> Content-Transfer-Encoding: 7BIT To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Thu Sep 05 08:20:53 2013 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VHSvy-0007xc-Pj for gcvg-git-2@plane.gmane.org; Thu, 05 Sep 2013 08:20:51 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757517Ab3IEGUn (ORCPT ); Thu, 5 Sep 2013 02:20:43 -0400 Received: from relais.videotron.ca ([24.201.245.36]:22894 "EHLO relais.videotron.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757393Ab3IEGUW (ORCPT ); Thu, 5 Sep 2013 02:20:22 -0400 Received: from yoda.home ([70.83.209.44]) by VL-VM-MR006.ip.videotron.ca (Oracle Communications Messaging Exchange Server 7u4-22.01 64bit (built Apr 21 2011)) with ESMTP id <0MSN00ANX2XQCY00@VL-VM-MR006.ip.videotron.ca> for git@vger.kernel.org; Thu, 05 Sep 2013 02:20:16 -0400 (EDT) Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTP id 2E7DA2DA05D6 for ; Thu, 05 Sep 2013 02:20:16 -0400 (EDT) X-Mailer: git-send-email 1.8.4.38.g317e65b In-reply-to: <1378362001-1738-1-git-send-email-nico@fluxnic.net> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: There is only one type of delta with pack v4. The base reference encoding already handles either an offset (via the pack index) or a literal SHA1. We assume in the literal SHA1 case that the object lives in the same pack, just like with previous pack versions. Signed-off-by: Nicolas Pitre --- sha1_file.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sha1_file.c b/sha1_file.c index 67eb903..f3bfa28 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1686,7 +1686,19 @@ static off_t get_delta_base(struct packed_git *p, * that is assured. An OFS_DELTA longer than the hash size * is stupid, as then a REF_DELTA would be smaller to store. */ - if (type == OBJ_OFS_DELTA) { + if (p->version >= 4) { + if (base_info[0] != 0) { + const unsigned char *cp = base_info; + unsigned int base_index = decode_varint(&cp); + if (!base_index || base_index - 1 >= p->num_objects) + return 0; /* out of bounds */ + *curpos += cp - base_info; + base_offset = nth_packed_object_offset(p, base_index - 1); + } else { + base_offset = find_pack_entry_one(base_info+1, p); + *curpos += 21; + } + } else if (type == OBJ_OFS_DELTA) { const unsigned char *cp = base_info; base_offset = decode_varint(&cp); base_offset = delta_obj_offset - base_offset; -- 1.8.4.38.g317e65b