Re: Manually decoding a git object
- From
Philip Oakley <philipoakley@iee.org>
- Date
- Feb 20, 2012, 09:05 UTC
- Message-ID
- <5D290031F60941368FB1A36464201DCF@PhilipOakley>
- In-Reply-To
- <87mx8dj4at.fsf@thomas.inf.ethz.ch>
From: "Thomas Rast" <trast@inf.ethz.ch> Sent: Monday, February 20, 2012 8:29 AM
Show 9 quoted lines
> "Philip Oakley" <philipoakley@iee.org> writes: > >> If I have a renamed file which is a git object, such a "Git_Object", was >> 8c-something-or-other, what is the easiest way of examining / decoding / >> recreating the original file (either as its sha1, or a cat-file). >> >> I don't appear to be able to unzip the file in its raw format... I'm >> using >> Msysgit on windows XP.
Correction to reply to xu's message: and I have /NOT/ located an unzip programme that will take the plain git object and decode it.
Show 22 quoted lines
>
> The SHA1 is over the decompressed object contents. The file simply
> holds a zlib-compressed stream of those contents. (It's pretty much
> like gzip without the file header.)
>
> You can use any bindings to zlib and something that does sha1, e.g. in
> python:
>
> $ cd g/.git/objects/aa/ # my git.git
> $ ls
> 592bda986a8380b64acd8cbb3d5bdfcbc0834d
> 6322a757bee31919f54edcc127608a3d724c99
> $ python
> Python 2.7.2 (default, Aug 19 2011, 20:41:43) [GCC] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import hashlib
> >>>
> hashlib.sha1(open('592bda986a8380b64acd8cbb3d5bdfcbc0834d').read().decode('zlib')).digest().encode('hex')
> 'aa592bda986a8380b64acd8cbb3d5bdfcbc0834d'
>
> Notice that the first byte of the hash goes into the directory name.
>At the moment I'm in a Catch 22 situation where I can't make the first step of examining the deflated contents, so I can't do all those next steps to get the sha1 etc.. Have I misunderstood your suggestions?
Philip