{"thread":{"id":"9449","subject":"[PATCH 3/3] Use the empty tree for base diff in paranoid-update on new branches","startedAt":"2007-08-09T06:38:16Z","lastAt":"2007-08-09T06:38:16Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"50285","messageId":"20070809063816.GC26843@spearce.org","threadId":"9449","inReplyTo":null,"subject":"[PATCH 3/3] Use the empty tree for base diff in paranoid-update on new branches","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-08-09T06:38:16Z","receivedAt":"2007-08-09T06:38:16Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"We have to load a tree difference for the purpose of testing\nfile patterns.  But if our branch is being created and there is no\nspecific base to difference against in the rule our base will be\n'0'x40.  This is (usually) not a valid tree-ish object in a Git\nrepository, so there's nothing to difference against.\n\nInstead of creating the empty tree and running git-diff against\nthat we just take the output of `ls-tree -r --name-only` and mark\nevery returned pathname as an add.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n contrib/hooks/update-paranoid |   31 +++++++++++++++++++++----------\n 1 files changed, 21 insertions(+), 10 deletions(-)\n\ndiff --git a/contrib/hooks/update-paranoid b/contrib/hooks/update-paranoid\nindex 84ed452..068fa37 100644\n--- a/contrib/hooks/update-paranoid\n+++ b/contrib/hooks/update-paranoid\n@@ -223,20 +223,31 @@ sub load_diff ($) {\n \tmy $d = $diff_cache{$base};\n \tunless ($d) {\n \t\tlocal $/ = \"\\0\";\n-\t\topen(T,'-|','git','diff-tree',\n-\t\t\t'-r','--name-status','-z',\n-\t\t\t$base,$new) or return undef;\n \t\tmy %this_diff;\n-\t\twhile (<T>) {\n-\t\t\tmy $op = $_;\n-\t\t\tchop $op;\n+\t\tif ($base =~ /^0{40}$/) {\n+\t\t\topen(T,'-|','git','ls-tree',\n+\t\t\t\t'-r','--name-only','-z',\n+\t\t\t\t$new) or return undef;\n+\t\t\twhile (<T>) {\n+\t\t\t\tchop;\n+\t\t\t\t$this_diff{$_} = 'A';\n+\t\t\t}\n+\t\t\tclose T or return undef;\n+\t\t} else {\n+\t\t\topen(T,'-|','git','diff-tree',\n+\t\t\t\t'-r','--name-status','-z',\n+\t\t\t\t$base,$new) or return undef;\n+\t\t\twhile (<T>) {\n+\t\t\t\tmy $op = $_;\n+\t\t\t\tchop $op;\n \n-\t\t\tmy $path = <T>;\n-\t\t\tchop $path;\n+\t\t\t\tmy $path = <T>;\n+\t\t\t\tchop $path;\n \n-\t\t\t$this_diff{$path} = $op;\n+\t\t\t\t$this_diff{$path} = $op;\n+\t\t\t}\n+\t\t\tclose T or return undef;\n \t\t}\n-\t\tclose T or return undef;\n \t\t$d = \\%this_diff;\n \t\t$diff_cache{$base} = $d;\n \t}\n-- \n1.5.3.rc4.29.g74276\n"}]}