<s> from . util import get_object_type_by_name <EOL> from git . util import LazyMixin , join_path_native , stream_copy <EOL> from gitdb . util import ( <EOL> bin_to_hex , <EOL> basename <EOL> ) <EOL> import gitdb . typ as dbtyp <EOL> _assertion_msg_format = "<STR_LIT>" <EOL> __all__ = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> class Object ( LazyMixin ) : <EOL> """<STR_LIT>""" <EOL> NULL_HEX_SHA = '<STR_LIT:0>' * <NUM_LIT> <EOL> NULL_BIN_SHA = b'<STR_LIT>' * <NUM_LIT:20> <EOL> TYPES = ( dbtyp . str_blob_type , dbtyp . str_tree_type , dbtyp . str_commit_type , dbtyp . str_tag_type ) <EOL> __slots__ = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:size>" ) <EOL> type = None <EOL> def __init__ ( self , repo , binsha ) : <EOL> """<STR_LIT>""" <EOL> super ( Object , self ) . __init__ ( ) <EOL> self . repo = repo <EOL> self . binsha = binsha <EOL> assert len ( binsha ) == <NUM_LIT:20> , "<STR_LIT>" % ( binsha , len ( binsha ) ) <EOL> @ classmethod <EOL> def new ( cls , repo , id ) : <EOL> """<STR_LIT>""" <EOL> return repo . rev_parse ( str ( id ) ) <EOL> @ classmethod <EOL> def new_from_sha ( cls , repo , sha1 ) : <EOL> """<STR_LIT>""" <EOL> if sha1 == cls . NULL_BIN_SHA : <EOL> return get_object_type_by_name ( b'<STR_LIT>' ) ( repo , sha1 ) <EOL> oinfo = repo . odb . info ( sha1 ) <EOL> inst = get_object_type_by_name ( oinfo . type ) ( repo , oinfo . binsha ) <EOL> inst . size = oinfo . size <EOL> return inst <EOL> def _set_cache_ ( self , attr ) : <EOL> """<STR_LIT>""" <EOL> if attr == "<STR_LIT:size>" : <EOL> oinfo = self . repo . odb . info ( self . binsha ) <EOL> self . size = oinfo . size <EOL> else : <EOL> super ( Object , self ) . _set_cache_ ( attr ) <EOL> def __eq__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( other , '<STR_LIT>' ) : <EOL> return False <EOL> return self . binsha == other . binsha <EOL> def __ne__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( other , '<STR_LIT>' ) : <EOL> return True <EOL> return self . binsha != other . binsha <EOL> def __hash__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return hash ( self . binsha ) <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . hexsha <EOL> def __repr__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . hexsha ) <EOL> @ property <EOL> def hexsha ( self ) : <EOL> """<STR_LIT>""" <EOL> return bin_to_hex ( self . binsha ) . decode ( '<STR_LIT:ascii>' ) <EOL> @ property <EOL> def data_stream ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . repo . odb . stream ( self . binsha ) <EOL> def stream_data ( self , ostream ) : <EOL> """<STR_LIT>""" <EOL> istream = self . repo . odb . stream ( self . binsha ) <EOL> stream_copy ( istream , ostream ) <EOL> return self <EOL> class IndexObject ( Object ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = ( "<STR_LIT:path>" , "<STR_LIT>" ) <EOL> _id_attribute_ = '<STR_LIT:path>' <EOL> def __init__ ( self , repo , binsha , mode = None , path = None ) : <EOL> """<STR_LIT>""" <EOL> super ( IndexObject , self ) . __init__ ( repo , binsha ) <EOL> if mode is not None : <EOL> self . mode = mode <EOL> if path is not None : <EOL> self . path = path <EOL> def __hash__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return hash ( self . path ) <EOL> def _set_cache_ ( self , attr ) : <EOL> if attr in IndexObject . __slots__ : <EOL> raise AttributeError ( <EOL> "<STR_LIT>" <EOL> % ( attr , type ( self ) . __name__ ) ) <EOL> else : <EOL> super ( IndexObject , self ) . _set_cache_ ( attr ) <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return basename ( self . path ) <EOL> @ property <EOL> def abspath ( self ) : <EOL> """<STR_LIT>""" <EOL> return join_path_native ( self . repo . working_tree_dir , self . path ) </s>
