From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carl Worth Subject: [PATCH] Add test case for ls-files --with-head Date: Wed, 03 Oct 2007 00:03:53 -0700 Message-ID: <87y7ekr86e.wl%cworth@cworth.org> References: <1191390255.16292.2.camel@koto.keithp.com> <7vtzp8g2s2.fsf@gitster.siamese.dyndns.org> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/signed; boundary="pgp-sign-Multipart_Wed_Oct__3_00:03:44_2007-1"; micalg=pgp-sha1; protocol="application/pgp-signature" Content-Transfer-Encoding: 7bit Cc: Keith Packard , Git Mailing List To: Junio C Hamano X-From: git-owner@vger.kernel.org Wed Oct 03 09:06:45 2007 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 1IcyJg-0001vZ-DR for gcvg-git-2@gmane.org; Wed, 03 Oct 2007 09:06:44 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752065AbXJCHGg (ORCPT ); Wed, 3 Oct 2007 03:06:36 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752028AbXJCHGg (ORCPT ); Wed, 3 Oct 2007 03:06:36 -0400 Received: from olra.theworths.org ([82.165.184.25]:55334 "EHLO olra.theworths.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752023AbXJCHGf (ORCPT ); Wed, 3 Oct 2007 03:06:35 -0400 Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 7DE63431FB1; Wed, 3 Oct 2007 00:06:34 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id I5Vu2b6MjaNN; Wed, 3 Oct 2007 00:03:54 -0700 (PDT) Received: from raht.cworth.org (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 9B280431FB0; Wed, 3 Oct 2007 00:03:53 -0700 (PDT) In-Reply-To: <7vtzp8g2s2.fsf@gitster.siamese.dyndns.org> User-Agent: Wanderlust/2.14.0 (Africa) Emacs/21.4 Mule/5.0 (SAKAKI) Sender: git-owner@vger.kernel.org Precedence: bulk X-Mailing-List: git@vger.kernel.org Archived-At: --pgp-sign-Multipart_Wed_Oct__3_00:03:44_2007-1 Content-Type: text/plain; charset=US-ASCII This tests basic functionality and also exercises a bug noticed by Keith Packard, (prune_cache followed by add_index_entry can trigger an attempt to realloc a pointer into the middle of an allocated buffer). --- t/t3060-ls-files-with-head.sh | 53 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 53 insertions(+), 0 deletions(-) create mode 100755 t/t3060-ls-files-with-head.sh On Tue, 02 Oct 2007 22:55:57 -0700, Junio C Hamano wrote: > > Thanks for catching this. This code originally was perfectly > Ok, but I broke it with the overlay_tree() change. Yeah, Keith and I were really scratching our heads as to how this hadn't caused more problems earlier. I wrote the test case below to explore the issue and found the recent overlay_tree change as you mention, and that made more sense. I didn't notice any existing --with-tree test case, so perhaps the patch below is useful. -Carl diff --git a/t/t3060-ls-files-with-head.sh b/t/t3060-ls-files-with-head.sh new file mode 100755 index 0000000..4ead08b --- /dev/null +++ b/t/t3060-ls-files-with-head.sh @@ -0,0 +1,53 @@ +#!/bin/sh +# +# Copyright (c) 2007 Carl D. Worth +# + +test_description='git ls-files test (--with-head). + +This test runs git ls-files --with-head and in particular in +a scenario known to trigger a crash with some versions of git. +' +. ./test-lib.sh + +# The bug we're exercising requires a fair number of entries in a +# sub-directory so that add_index_entry will trigger a realloc +echo file > expected +mkdir sub +for num in $(seq -f%04g 1 50); do + touch sub/file-$num + echo file-$num >> expected +done +git add . +git commit -m "add a bunch of files" + +# We remove them all so that we'll have something to add back with +# --with-head and so that we'll definitely be under the realloc size +# to trigger the bug. +rm -r sub +git commit -a -m "remove them all" + +# The bug also requires some entry before our directory so that +# prune_path will modify the_index.cache +mkdir a_directory_that_sorts_before_sub +touch a_directory_that_sorts_before_sub/file +mkdir sub +touch sub/file +git add . + +# We have to run from a sub-directory to trigger prune_path +cd sub + +# Then we finally get to run our --with-tree test +test_expect_success \ + 'git -ls-files --with-tree should succeed.' \ + 'git ls-files --with-tree=HEAD~1 >../output' + +cd .. +test_expect_success \ + 'git -ls-files --with-tree should add entries from named tree.' \ + 'diff output expected' + +test_done + + -- 1.5.3.3.131.g34c6d --pgp-sign-Multipart_Wed_Oct__3_00:03:44_2007-1 Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD4DBQBHAz7Z6JDdNq8qSWgRAvrxAJdrDKaEzjmoKCKikDukLohQIof5AKCH6Jww 1oNUp5J1R4+fsfsGXOIudQ== =BKqP -----END PGP SIGNATURE----- --pgp-sign-Multipart_Wed_Oct__3_00:03:44_2007-1--