git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH 3/3] Use the empty tree for base diff in paranoid-update on new branches
Date: Thu, 9 Aug 2007 02:38:16 -0400	[thread overview]
Message-ID: <20070809063816.GC26843@spearce.org> (raw)

We have to load a tree difference for the purpose of testing
file patterns.  But if our branch is being created and there is no
specific base to difference against in the rule our base will be
'0'x40.  This is (usually) not a valid tree-ish object in a Git
repository, so there's nothing to difference against.

Instead of creating the empty tree and running git-diff against
that we just take the output of `ls-tree -r --name-only` and mark
every returned pathname as an add.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/hooks/update-paranoid |   31 +++++++++++++++++++++----------
 1 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/contrib/hooks/update-paranoid b/contrib/hooks/update-paranoid
index 84ed452..068fa37 100644
--- a/contrib/hooks/update-paranoid
+++ b/contrib/hooks/update-paranoid
@@ -223,20 +223,31 @@ sub load_diff ($) {
 	my $d = $diff_cache{$base};
 	unless ($d) {
 		local $/ = "\0";
-		open(T,'-|','git','diff-tree',
-			'-r','--name-status','-z',
-			$base,$new) or return undef;
 		my %this_diff;
-		while (<T>) {
-			my $op = $_;
-			chop $op;
+		if ($base =~ /^0{40}$/) {
+			open(T,'-|','git','ls-tree',
+				'-r','--name-only','-z',
+				$new) or return undef;
+			while (<T>) {
+				chop;
+				$this_diff{$_} = 'A';
+			}
+			close T or return undef;
+		} else {
+			open(T,'-|','git','diff-tree',
+				'-r','--name-status','-z',
+				$base,$new) or return undef;
+			while (<T>) {
+				my $op = $_;
+				chop $op;
 
-			my $path = <T>;
-			chop $path;
+				my $path = <T>;
+				chop $path;
 
-			$this_diff{$path} = $op;
+				$this_diff{$path} = $op;
+			}
+			close T or return undef;
 		}
-		close T or return undef;
 		$d = \%this_diff;
 		$diff_cache{$base} = $d;
 	}
-- 
1.5.3.rc4.29.g74276

                 reply	other threads:[~2007-08-09  6:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070809063816.GC26843@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).