summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xread_object.pl20
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) = @_;