From cabead982b7cf40f8930e6e38327fc396b7fef81 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 9 Aug 2007 02:38:16 -0400 Subject: [PATCH] Use the empty tree for base diff in paranoid-update on new branches 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 Signed-off-by: Junio C Hamano --- contrib/hooks/update-paranoid | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/contrib/hooks/update-paranoid b/contrib/hooks/update-paranoid index 84ed45248..068fa3708 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 () { - my $op = $_; - chop $op; + if ($base =~ /^0{40}$/) { + open(T,'-|','git','ls-tree', + '-r','--name-only','-z', + $new) or return undef; + while () { + 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 () { + my $op = $_; + chop $op; - my $path = ; - chop $path; + my $path = ; + 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; } -- 2.30.2