99import subprocess
1010import zlib
1111
12+ repo_dir = 'repo.tmp'
1213git_dir = b'.git'
1314objects_dir = os .path .join (git_dir , b'objects' )
1415
2223default_email = b'a@a.com'
2324# 2000-01-01T00:00:00+0000
2425default_date_s = 946684800
25- default_date_format = b'%s +0000'
26- default_date = b'%s +0000' % str ( default_date_s ). encode ( 'ascii' )
27- default_author_date = default_date
26+ default_tz = b'+0000'
27+ default_author_date_s = default_date_s
28+ default_author_date_tz = default_tz
2829default_author_email = default_email
2930default_author_name = default_name
30- default_committer_date = default_date
31+ default_committer_date_s = default_date_s
32+ default_committer_date_tz = default_tz
3133default_committer_email = default_email
3234default_committer_name = default_name
3335default_message = b'a'
3436# ASCII hex of parents.
3537default_parents = ()
3638
3739def init ():
38- repo = 'tmp/repo.tmp'
39- for d in (repo , 'clone.tmp' ):
40+ for d in (repo_dir , 'clone.tmp' ):
4041 shutil .rmtree (d , ignore_errors = True )
41- os .mkdir (repo )
42- os .chdir (repo )
42+ os .mkdir (repo_dir )
43+ os .chdir (repo_dir )
4344 subprocess .check_output (['git' , 'init' , '-q' ])
4445
4546def get_object_and_sha (obj_type , content ):
@@ -66,21 +67,23 @@ def save_commit_object(
6667 parents = default_parents ,
6768 author_name = default_author_name ,
6869 author_email = default_author_email ,
69- author_date = default_author_date ,
70+ author_date_s = default_author_date_s ,
71+ author_date_tz = default_author_date_tz ,
7072 committer_name = default_committer_name ,
7173 committer_email = default_committer_email ,
72- committer_date = default_committer_date ,
74+ committer_date_s = default_committer_date_s ,
75+ committer_date_tz = default_committer_date_tz ,
7376 message = default_message ):
7477 if parents and parents [0 ]:
7578 parents_bytes = b''
7679 sep = b'\n parent '
7780 parents_bytes = sep + sep .join (parents ) + b'\n '
7881 else :
7982 parents_bytes = b'\n '
80- commit_content = b'tree %s%sauthor %s <%s> %s\n committer %s <%s> %s\n \n %s\n ' % (
83+ commit_content = b'tree %s%sauthor %s <%s> %s %s \n committer %s <%s> %s %s\n \n %s\n ' % (
8184 tree_sha_ascii , parents_bytes ,
82- author_name , author_email , author_date ,
83- committer_name , committer_email , committer_date ,
85+ author_name , author_email , str ( author_date_s ). encode ( 'ascii' ), author_date_tz ,
86+ committer_name , committer_email , str ( committer_date_s ). encode ( 'ascii' ), committer_date_tz ,
8487 message )
8588 return save_object (b'commit' , commit_content ) + (commit_content ,)
8689
0 commit comments