FYI, here is how you can parse raw tree output from 'git cat-file --batch',
assuming that you have plain-ASCII filenames ('use bytes;' would probably
be needed):
-- 8< --
sub decode_tree {
my $contents = shift;
# ...
while (my @entry = decode_tree_entry($contents)) {
# ...
my $len = tree_entry_len(@entry);
contents = substr($contents, $len);
last unless $contents;
}
# ...
}
sub tree_entry_len {
my ($mode_str, $filename) = @_;
# length of mode string + separator + 20 bytes of SHA-1
# + length of filename (in bytes) + terminating NUL ('\0')
length($mode_str)+1 + length($filename)+1 + 20;
}
sub decode_tree_entry {
my $buf = shift;
$buf =~ s/^([0-7]+) //;
my ($mode_str) = $1;
my ($filename, $sha1_str) = unpack('Z*H[40]', $buf);
return ($mode_str, $filename, $sha1_str);
}
-- >8 --
--
Jakub Narebski
Poland
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html