From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Subject: [PATCH] cache-tree: do not cache empty trees Date: Sat, 5 Feb 2011 16:50:27 +0700 Message-ID: <1296899427-1394-1-git-send-email-pclouds@gmail.com> References: <1296894611-29398-1-git-send-email-pclouds@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Jakub Narebski , Jonathan Nieder , "Dmitry S. Kravtsov" , Shawn Pearce , =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= To: git@vger.kernel.org, Ilari Liusvaara X-From: git-owner@vger.kernel.org Sat Feb 05 10:52:07 2011 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PleoH-0007oN-Io for gcvg-git-2@lo.gmane.org; Sat, 05 Feb 2011 10:52:05 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751279Ab1BEJv7 convert rfc822-to-quoted-printable (ORCPT ); Sat, 5 Feb 2011 04:51:59 -0500 Received: from mail-pw0-f46.google.com ([209.85.160.46]:55126 "EHLO mail-pw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750970Ab1BEJv5 (ORCPT ); Sat, 5 Feb 2011 04:51:57 -0500 Received: by pwj3 with SMTP id 3so590439pwj.19 for ; Sat, 05 Feb 2011 01:51:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:mime-version:content-type :content-transfer-encoding; bh=dDw6mpm9UDQjbuzrNTxPBytA04fqO3BEICmUdD7zOVE=; b=wbW9JWL0EsYsHlEqlGGQY5Zh4zH316UdnG2oOAVfcE3qxPQ5X9Jew5lvwpsK4sZxw0 mFdukuPXg5SDXXozbJVLT7/m7UaIarChiV/vonJkItruC7cFRYh2JEXuOkHG2clpDma8 iOMRXONP+G7QWbHWNIzuQhjM4d7Oy9aHyoXlA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding; b=rQfffAfVkz0cLqgusQPuaDT7UpKKwHaZ7PUg+/JiIdFJZkzQQhBUJXyfjiFwD394Lq mUn1L53tazxNogOEpESaj+w5yW/L0GsrP4WXwq6nDuXHyKbN1zDfziM3S2ytejWBDkqP GTJX9bSRDFA37hy0q+l6jFjrTJWfvLDQp0bho= Received: by 10.142.133.11 with SMTP id g11mr12977066wfd.103.1296899517360; Sat, 05 Feb 2011 01:51:57 -0800 (PST) Received: from pclouds@gmail.com ([115.73.232.10]) by mx.google.com with ESMTPS id w14sm2311325wfd.6.2011.02.05.01.51.52 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 05 Feb 2011 01:51:56 -0800 (PST) Received: by pclouds@gmail.com (sSMTP sendmail emulation); Sat, 05 Feb 2011 16:50:28 +0700 X-Mailer: git-send-email 1.7.3.4.878.g439c7 In-Reply-To: <1296894611-29398-1-git-send-email-pclouds@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Current index does not support empty trees. But users can construct empty trees directly using plumbing. When empty trees are checked out, things become inconsistent: - If cache-tree somehow is invalidated, when a tree is read to index, empty trees disappear. When we write trees back, empty trees will be gone. - If cache-tree is generated by read-tree and remains valid by the time trees are written back, empty trees remain. Let's do it in a consistent way, always disregard empty trees in index. If users choose to create empty trees their own way, they should not use index at all. Signed-off-by: Nguy=E1=BB=85n Th=C3=A1i Ng=E1=BB=8Dc Duy --- Scratch the first version. This one actually works. cache-tree.c | 9 +++++++++ t/t1013-read-tree-empty.sh | 38 ++++++++++++++++++++++++++++++++++++= ++ 2 files changed, 47 insertions(+), 0 deletions(-) create mode 100755 t/t1013-read-tree-empty.sh diff --git a/cache-tree.c b/cache-tree.c index f755590..03732ad 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -621,9 +621,18 @@ static void prime_cache_tree_rec(struct cache_tree= *it, struct tree *tree) struct tree *subtree =3D lookup_tree(entry.sha1); if (!subtree->object.parsed) parse_tree(subtree); + if (!hashcmp(entry.sha1, (unsigned char *)EMPTY_TREE_SHA1_BIN)) { + warning("empty tree detected! Will be removed from new commits"); + cnt =3D -1; + break; + } sub =3D cache_tree_sub(it, entry.path); sub->cache_tree =3D cache_tree(); prime_cache_tree_rec(sub->cache_tree, subtree); + if (sub->cache_tree->entry_count =3D=3D -1) { + cnt =3D -1; + break; + } cnt +=3D sub->cache_tree->entry_count; } } diff --git a/t/t1013-read-tree-empty.sh b/t/t1013-read-tree-empty.sh new file mode 100755 index 0000000..a9279f0 --- /dev/null +++ b/t/t1013-read-tree-empty.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +test_description=3D'read-tree with empty trees' + +. ./test-lib.sh + +T1=3Df4ec99e8174c01eab488469b4c2680500bbb18da +T2=3D4b825dc642cb6eb9a060e54bf8d69288fbee4904 + +test_expect_success 'setup' ' + printf "40000 empty\0\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60\xe5\x4b= \xf8\xd6\x92\x88\xfb\xee\x49\x04" >newtree && + git hash-object -w -t tree newtree >actual && + echo $T1 >expected + test_cmp expected actual +' + +test_expect_success 'ls-tree T1 (with empty tree)' ' + git ls-tree $T1 >actual && + cat <expected && +040000 tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 empty +EOF + test_cmp expected actual +' + +test_expect_success 'write-tree removes empty tree' ' + git read-tree "$T1" && + git write-tree >actual + echo $T2 >expected + test_cmp expected actual +' + +test_expect_success 'ls-tree T2 (without empty tree)' ' + git ls-tree $T2 >actual && + : >expected && + test_cmp expected actual +' + +test_done --=20 1.7.3.4.878.g439c7