#NEWLINE# def write_cache( entries , stream , extension_data = None , ShaStreamCls = IndexFileSHA1Writer ) : #NEWLINE# #INDENT# 'Write the cache represented by entries to a stream\n\n    :param entries: **sorted** list of entries\n    :param stream: stream to wrap into the AdapterStreamCls - it is used for\n        final output.\n\n    :param ShaStreamCls: Type to use when writing to the stream. It produces a sha\n        while writing to it, before the data is passed on to the wrapped stream\n\n    :param extension_data: any kind of data to write as a trailer, it must begin\n        a 4 byte identifier, followed by its size ( 4 bytes )' #NEWLINE# stream = ShaStreamCls ( stream ) #NEWLINE# tell = stream . tell #NEWLINE# write = stream . write #NEWLINE# version = 2 #NEWLINE# write ( b'DIRC' ) #NEWLINE# write ( pack ( '>LL' , version , len ( entries ) ) ) #NEWLINE# for entry in entries : #NEWLINE# #INDENT# beginoffset = tell ( ) #NEWLINE# write ( entry [ 4 ] ) #NEWLINE# write ( entry [ 5 ] ) #NEWLINE# path = entry [ 3 ] #NEWLINE# path = force_bytes ( path , encoding = defenc ) #NEWLINE# plen = ( len ( path ) & CE_NAMEMASK ) #NEWLINE# assert ( plen == len ( path ) ) , ( 'Path %s too long to fit into index' % entry [ 3 ] ) #NEWLINE# flags = ( plen | ( entry [ 2 ] & CE_NAMEMASK_INV ) ) #NEWLINE# write ( pack ( '>LLLLLL20sH' , entry [ 6 ] , entry [ 7 ] , entry [ 0 ] , entry [ 8 ] , entry [ 9 ] , entry [ 10 ] , entry [ 1 ] , flags ) ) #NEWLINE# write ( path ) #NEWLINE# real_size = ( ( ( tell ( ) - beginoffset ) + 8 ) & ( ~ 7 ) ) #NEWLINE# write ( ( b'\x00' * ( ( beginoffset + real_size ) - tell ( ) ) ) ) #NEWLINE# #UNINDENT# if ( extension_data is not None ) : #NEWLINE# #INDENT# stream . write ( extension_data ) #NEWLINE# #UNINDENT# stream . write_sha ( )