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 <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Shawn O. Pearce committed
Aug 9, 2007 at 02:38 UTC
cabead982b7cf40f8930e6e38327fc396b7fef81
1 file changed
+21
-10
contrib/hooks/update-paranoid
+21
-10
@@ -223,20 +223,31 @@ sub load_diff ($) {
223
my $d = $diff_cache{$base};
224
unless ($d) {
225
local $/ = "\0";
226
- open(T,'-|','git','diff-tree',
227
- '-r','--name-status','-z',
228
- $base,$new) or return undef;
226
my %this_diff;
230
- while (<T>) {
231
- my $op = $_;
232
- chop $op;
227
+ if ($base =~ /^0{40}$/) {
228
+ open(T,'-|','git','ls-tree',
229
+ '-r','--name-only','-z',
230
+ $new) or return undef;
231
+ while (<T>) {
232
+ chop;
233
+ $this_diff{$_} = 'A';
234
+ }
235
+ close T or return undef;
236
+ } else {
237
+ open(T,'-|','git','diff-tree',
238
+ '-r','--name-status','-z',
239
+ $base,$new) or return undef;
240
+ while (<T>) {
241
+ my $op = $_;
242
+ chop $op;
243
234
- my $path = <T>;
235
- chop $path;
244
+ my $path = <T>;
245
+ chop $path;
246
237
- $this_diff{$path} = $op;
247
+ $this_diff{$path} = $op;
248
+ }
249
+ close T or return undef;
250
}
239
- close T or return undef;
251
$d = \%this_diff;
252
$diff_cache{$base} = $d;
253
}