diff options
author | Brian Cully <bjc@kublai.com> | 2009-03-29 02:52:40 -0400 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2009-03-29 02:52:40 -0400 |
commit | 22e1f61a8bd30248635806ee2b12f14d126770d4 (patch) | |
tree | d75c1aba1a4024d6208f96f344126476fc0a4382 | |
parent | 8cad075d401507e2901647a3af2f6ccb160a926f (diff) | |
download | dvcs-git-slides-22e1f61a8bd30248635806ee2b12f14d126770d4.tar.gz dvcs-git-slides-22e1f61a8bd30248635806ee2b12f14d126770d4.zip |
Add tree formatting.
-rwxr-xr-x | read_object.pl | 20 |
1 files 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) = @_; |