From 22e1f61a8bd30248635806ee2b12f14d126770d4 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Sun, 29 Mar 2009 02:52:40 -0400 Subject: Add tree formatting. --- read_object.pl | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/read_object.pl b/read_object.pl index 100ad57..b60f8eb 100755 --- a/read_object.pl +++ b/read_object.pl @@ -38,8 +38,7 @@ sub format_object { } elsif ($type eq 'tag') { $obj; } elsif ($type eq 'tree') { - warn 'TODO - unimplemented'; - hexdump($obj); + format_tree($obj) } elsif ($type eq 'blob') { hexdump($obj); } else { @@ -48,6 +47,23 @@ sub format_object { } } +sub format_tree { + my ($str) = @_; + + my @tree = split /\0(.{20})/, $str; + my @rc = (); + while (@tree) { + my ($info, $id) = (shift @tree, shift @tree); + $info =~ /^([^ ]*) (.*)/; + my ($mode, $name) = ($1, $2); + my @bytes = unpack('C*', $id); + my $sig = join '', map { sprintf('%02x', $_) } @bytes; + + push @rc, "$mode $name\t$sig"; + } + join "\n", @rc; +} + sub hexdump { my ($str) = @_; -- cgit v1.2.3