Philip Oakley [off-list ref] writes:
From: "Thomas Rast" <redacted> Sent: Monday, February 20,
2012 8:29 AM
quoted
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?
Huh? The method I showed does not rely on knowing the SHA1. The fact
that I used it on a properly filed away (by its SHA1) object file is
immaterial, if perhaps confusing.
I can untangle that python expression for you:
hashlib.sha1(foo).digest() gives the SHA1 digest of the string foo, as a (binary) string
foo.encode('hex') turns foo from (binary) string into its hex representation
open('filename').read() opens the file called filename, and returns its whole contents
foo.decode('zlib') applies the zlib decompressor to foo, and returns the resulting data
So that trick works for any file[*], and you can then use its results to
file it back where it needs to go.
[*] that is sufficiently small for Python to hold it in memory, but git
shares the same problems in that department.
--
Thomas Rast
trast@{inf,student}.ethz.ch
2012/2/20 Thomas Rast [off-list ref]:
Philip Oakley [off-list ref] writes:
quoted
From: "Thomas Rast" <redacted> Sent: Monday, February 20,
2012 8:29 AM
quoted
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.
I think Thomas got the point.
When I tried it from my home directory (not in a git directory):
$ git cat-file -p Git-Object
fatal: Not a git repository (or any of the parent directories): .git
this is because git will first do a git-dir-search, if you're current
work dir is not within git repo, it will die.
I really do not know how you get thing that mess. From the link[1] you
give, i think you just want to clone a repo across computer not by
network, if so this[2] will be helpful.
[1]:http://stackoverflow.com/questions/9343260/what-after-git-unpack-objects-to-get-the-actual-file
[2]:http://progit.org/2010/03/10/bundles.html
From: "Thomas Rast" <redacted> Sent: Monday, February 20, 2012
10:56 AM
Philip Oakley [off-list ref] writes:
quoted
From: "Thomas Rast" <redacted> Sent: Monday, February 20,
2012 8:29 AM
quoted
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?
Huh? The method I showed does not rely on knowing the SHA1. The fact
that I used it on a properly filed away (by its SHA1) object file is
immaterial, if perhaps confusing.
I can untangle that python expression for you:
hashlib.sha1(foo).digest() gives the SHA1 digest of the string foo,
as a (binary) string
foo.encode('hex') turns foo from (binary) string into its
hex representation
open('filename').read() opens the file called filename, and
returns its whole contents
foo.decode('zlib') applies the zlib decompressor to foo, and
returns the resulting data
So that trick works for any file[*], and you can then use its results to
file it back where it needs to go.
[*] that is sufficiently small for Python to hold it in memory, but git
shares the same problems in that department.
I see what you mean now. I'll need to work out how to get Python in
msysgit - the 'minimal' part of msys keeps on biting... That is, I didn't
see it (Python) in the 1.7.8 full install bash - I didn't see it anyway.
I was hopeful that unzip/gunzip would have an option to simply deflate a
(file)stream, rather than it expecting the normal file archive.