<s> import hashlib <EOL> from . datatypes import Atom , Dictionary , List , Tuple <EOL> from . datatypes import wrap <EOL> class Commit : <EOL> def __init__ ( self , repo , obj_sha , message , parents ) : <EOL> self . repo = repo <EOL> self . obj_sha = obj_sha <EOL> self . message = message <EOL> self . parents = parents <EOL> self . content = repo . shrink ( ( obj_sha , parents , message ) ) <EOL> def __bytes__ ( self ) : <EOL> return ( "<STR_LIT>" % ( self . __class__ , self . content ) ) . encode ( "<STR_LIT:utf-8>" ) <EOL> class Repo : <EOL> def __init__ ( self ) : <EOL> self . objects = { } <EOL> self . refs = { } <EOL> self . HEAD = "<STR_LIT>" <EOL> def resolve ( self , ref ) : <EOL> """<STR_LIT>""" <EOL> if ref . startswith ( "<STR_LIT>" ) : <EOL> return self . resolve ( self . refs [ ref ] ) <EOL> else : <EOL> return ref <EOL> def store ( self , obj ) : <EOL> sha = hashlib . sha1 ( bytes ( obj ) ) . hexdigest ( ) <EOL> self . objects [ sha ] = obj <EOL> return sha <EOL> def shrink ( self , content ) : <EOL> return self . store ( wrap ( self , content ) ) <EOL> def get_object ( self , sha ) : <EOL> """<STR_LIT>""" <EOL> return self . objects [ sha ] <EOL> def expand ( self , sha ) : <EOL> """<STR_LIT>""" <EOL> return self . get_object ( sha ) . expand ( ) <EOL> def create_commit ( self , obj_sha , message , parents = None ) : <EOL> if parents is None : <EOL> parents = [ ] <EOL> return self . store ( Commit ( self , obj_sha , message , parents ) ) <EOL> def commit ( self , obj , message ) : <EOL> obj_sha = self . shrink ( obj ) <EOL> old_head = self . resolve ( self . HEAD ) <EOL> commit_sha = self . create_commit ( obj_sha , message , parents = [ old_head ] ) <EOL> self . refs [ self . HEAD ] = commit_sha <EOL> return commit_sha <EOL> def retrieve_commit ( self , commit_sha = None ) : <EOL> obj = self . get_object ( commit_sha or self . resolve ( self . HEAD ) ) <EOL> return self . expand ( obj . obj_sha ) <EOL> def create_branch ( self , branch_name , commit_sha = None ) : <EOL> self . refs [ "<STR_LIT>" + branch_name ] = commit_sha or self . resolve ( self . HEAD ) <EOL> def checkout_branch ( self , branch_name ) : <EOL> self . HEAD = "<STR_LIT>" + branch_name </s>
