Tuesday, November 15, 2011

How to see decompress git objects (in text)

Git maintains all its objects in in .git/objects directory. These files are compressed. To read the text contents of the file, create a file read_git_obj.pl and add folloing code to it

use strict ;
use warnings ;
use Compress::Zlib ;

my $x = inflateInit() or die "Cannot create a inflation stream\n" ;
my $input = '' ;
binmode STDIN;
binmode STDOUT;

my ($output, $status) ;
while (read(STDIN, $input, 4096)){
        ($output, $status) = $x->inflate(\$input) ;
        print $output
        if $status == Z_OK or $status == Z_STREAM_END ;
        last if $status != Z_OK ;
}
die "inflation failed\n" unless $status == Z_STREAM_END ;


This program reads data from STDIN. It can be used as
cat .git/objects/fd/3feaffcc13c86991c5cbe920f006b4e9b5922f | perl read_git_obj.pl

No comments:

Post a Comment