1 import os, errno, zlib, time, sha
5 header = '%s %d\0' % (type, len(s))
9 dir = '.git/objects/%s' % hex[0:2]
10 fn = '%s/%s' % (dir, hex[2:])
11 if not os.path.exists(fn):
12 #log('creating %s' % fn)
16 if e.errno != errno.EEXIST:
18 tfn = '%s.%d' % (fn, os.getpid())
20 z = zlib.compressobj(1)
21 f.write(z.compress(header))
22 f.write(z.compress(s))
27 #log('exists %s' % fn)
33 return hash_raw('blob', blob)
36 def gen_tree(shalist):
37 l = ['%s %s\0%s' % (mode,name,hex.decode('hex'))
38 for (mode,name,hex) in shalist]
39 return hash_raw('tree', ''.join(l))
43 return time.strftime('%s %z', time.localtime(date))
46 def gen_commit(tree, parent, author, adate, committer, cdate, msg):
48 if tree: l.append('tree %s' % tree)
49 if parent: l.append('parent %s' % parent)
50 if author: l.append('author %s %s' % (author, _git_date(adate)))
51 if committer: l.append('committer %s %s' % (committer, _git_date(cdate)))
54 return hash_raw('commit', '\n'.join(l))