Skip to content

Instantly share code, notes, and snippets.

@esc
Created April 1, 2015 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esc/1f7097d6c33b037b6911 to your computer and use it in GitHub Desktop.
Save esc/1f7097d6c33b037b6911 to your computer and use it in GitHub Desktop.
hashing with git and python
zsh» git init example
Initialized empty Git repository in /tmp/example/.git/
zsh» cd example
zsh» cp ../objektmodell-beispiel/hello.py .
zsh» cat hello.py
#! /usr/bin/env python
""" Hello World! """
print 'Hello World!'
zsh» git hash-object -w hello.py
52ea6d6f53b2990f5d6167553f43c98dc8788e81
zsh» cat .git/objects/52/ea6d6f53b2990f5d6167553f43c98dc8788e81
xKÊÉOR03gPVTÐ/-.ÒOÊÌÓOÍ+S(¨,ÉÈÏãâRRRRðHÍÉÉÏ/ÊIQT
pqeæ(¨#K¨sHÝ% zsh» ipython
In [1]: import zlib
In [2]: data = open(".git/objects/52/ea6d6f53b2990f5d6167553f43c98dc8788e81").read()
In [3]: zlib.decompress(data)
Out[3]: 'blob 67\x00#! /usr/bin/env python\n\n""" Hello World! """\n\nprint \'Hello World!\'\n'
In [4]: dec = zlib.decompress(data)
In [5]: import hashlib
In [6]: hashlib.sha1(dec).hexdigest()
Out[6]: '52ea6d6f53b2990f5d6167553f43c98dc8788e81'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment