
    {                        d Z ddlmZ ddlZddlZddlZddlmZmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' dd	l(m)Z) d
Z*dZ+ G d de,      Z- G d de-      Z. G d de.      Z/ G d de-      Z0 G d de,      Z1 G d de1      Z2d Z3d Z4d%dZ5 G d de,      Z6 G d de,      Z7d Z8 G d  d!e-      Z9d" Z: G d# d$e.      Z;y)&z/Git object store interfaces and implementation.    BytesION)tree_changes
walk_trees)NotTreeError)GitFile)CommitShaFileTagTreeZERO_SHA
hex_to_sha
sha_to_hexhex_to_filenameS_ISGITLINKobject_classvalid_hexsha)PackPackDataPackInflaterPackFileDisappearedload_pack_index_file	iter_sha1pack_objects_to_datawrite_pack_headerwrite_pack_index_v2write_pack_datawrite_pack_objectcompute_file_shaPackIndexerPackStreamCopier)ANNOTATED_TAG_SUFFIXinfopackc                       e Zd ZdZd Zd Zd Zd Zd Ze	d        Z
d Zd	 Zd
 Zd ZddZddZ	 	 	 	 ddZddZdddd dfdZd ZddZ	 ddZd Z e        e       d fdZd Zy)BaseObjectStorezObject store interface.c                     |j                         D cg c])  \  }}|| vr |j                  t              s|t        k(  s|+ c}}S c c}}w N)itemsendswithr"   r   )selfrefsrefshas       'lib/third_party/dulwich/object_store.pydetermine_wants_allz#BaseObjectStore.determine_wants_allL   sN     #jjl
*
c$LL!568O	 *
 	
 
s   .Ac                     t        | |      S )zIterate over the objects for the specified shas.

        Args:
          shas: Iterable object with SHAs
        Returns: Object iterator
        )ObjectStoreIterator)r+   shass     r/   	iter_shaszBaseObjectStore.iter_shasU   s     #4..    c                 ,    t        | j                        z=Check if a particular object is present by SHA1 and is loose.)NotImplementedErrorcontains_looser+   r.   s     r/   r9   zBaseObjectStore.contains_loose^   s    !$"5"566r5   c                 ,    t        | j                        )>Check if a particular object is present by SHA1 and is packed.)r8   contains_packedr:   s     r/   r=   zBaseObjectStore.contains_packedb   s    !$"6"677r5   c                 J    | j                  |      xs | j                  |      S )Check if a particular object is present by SHA1.

        This method makes no distinction between loose and packed objects.
        )r=   r9   r:   s     r/   __contains__zBaseObjectStore.__contains__f   s%    
 ##C(DD,?,?,DDr5   c                     t         )zIterable of pack objects.r8   r+   s    r/   packszBaseObjectStore.packsm   s
     "!r5   c                 ,    t        | j                        zObtain the raw text for an object.

        Args:
          name: sha for the object.
        Returns: tuple with numeric type and object contents.
        )r8   get_rawr+   names     r/   rG   zBaseObjectStore.get_rawr   s     "$,,//r5   c                 Z    | j                  |      \  }}t        j                  |||      S )zObtain an object by SHA1.r.   )rG   r
   from_raw_string)r+   r.   type_numuncomps       r/   __getitem__zBaseObjectStore.__getitem__{   s*    <<,&&&xSAAr5   c                 ,    t        | j                        5Iterate over the SHAs that are present in this store.)r8   __iter__rC   s    r/   rS   zBaseObjectStore.__iter__   s    !$--00r5   c                 ,    t        | j                        ))Add a single object to this object store.)r8   
add_objectr+   objs     r/   rV   zBaseObjectStore.add_object   s    !$//22r5   Nc                 ,    t        | j                        )Add a set of objects to this object store.

        Args:
          objects: Iterable over a list of (object, path) tuples
        )r8   add_objectsr+   objectsprogresss      r/   r[   zBaseObjectStore.add_objects   s     "$"2"233r5   c                     |dk(  ry| j                         \  }}}	 t        ||||| j                          |       S # t        $ r	  |         w xY w)zAdd pack data to this object store.

        Args:
          num_items: Number of items to add
          pack_data: Iterator over pack data tuples
        r   Ncompression_level)add_packr   pack_compression_levelBaseException)r+   count	pack_datar^   fcommitaborts          r/   add_pack_datazBaseObjectStore.add_pack_data   sd     A:==?65	"&"="= 8O	  	G	s	   = Ac           	   #   D  K   t        | ||||||      D ]  }|j                  j                  |j                  j                  f|j                  j                  |j                  j                  f|j                  j
                  |j                  j
                  ff  yw)a  Find the differences between the contents of two trees

        Args:
          source: SHA1 of the source tree
          target: SHA1 of the target tree
          want_unchanged: Whether unchanged files should be reported
          include_trees: Whether to include trees
          change_type_same: Whether to report files changing
            type in the same entry.
        Returns: Iterator over tuples with
            (oldpath, newpath), (oldmode, newmode), (oldsha, newsha)
        )want_unchangedinclude_treeschange_type_samerename_detectorN)r   oldpathnewmoder.   )r+   sourcetargetrl   rm   rn   ro   changes           r/   r   zBaseObjectStore.tree_changes   s     * #)'-+
F &**//2&**//20 
s   BB c              #      K   t        | |d      D ]7  \  }}|j                  t        j                  |j                        r|s4| 9 yw)aW  Iterate the contents of a tree and all subtrees.

        Iteration is depth-first pre-order, as in e.g. os.walk.

        Args:
          tree_id: SHA1 of the tree.
          include_trees: If True, include tree objects in the iteration.
        Returns: Iterator over TreeEntry namedtuples for all the objects in a
            tree.
        N)r   rs   statS_ISDIR)r+   tree_idrm   entry_s        r/   iter_tree_contentsz"BaseObjectStore.iter_tree_contents   s@      #4$7HE1

&t||EJJ/G	 8s   AAAc                     | j                   S r(   parentsrh   s    r/   <lambda>zBaseObjectStore.<lambda>       6>>r5   c           	      R    t        | ||||||      }t        |j                  d      S )a`  Find the missing objects required for a set of revisions.

        Args:
          haves: Iterable over SHAs already in common.
          wants: Iterable over SHAs of objects to fetch.
          shallow: Set of shallow commit SHA1s to skip
          progress: Simple progress function that will be called with
            updated progress strings.
          get_tagged: Function that returns a dict of pointed-to sha ->
            tag sha for including tags.
          get_parents: Optional function for getting the parents of a
            commit.
        Returns: Iterator over (sha, path) pairs.
        )get_parentsN)MissingObjectFinderiternext)	r+   haveswantsshallowr^   
get_taggedr   depthfinders	            r/   find_missing_objectsz$BaseObjectStore.find_missing_objects   s6    0 %#
 FKK&&r5   c                     g }t        |      }|r4|| v r"|j                  |       |j                  |       t        |      }|r4|S )zFind which revisions this store has in common using graphwalker.

        Args:
          graphwalker: A graphwalker object.
        Returns: List of SHAs that are in common
        )r   appendack)r+   graphwalkerr   r.   s       r/   find_common_revisionsz%BaseObjectStore.find_common_revisions  sK     ;d{S!${#C	 
 r5   c                 L    | j                  ||||      }| j                  |      S )a-  Iterate over the contents of a pack file.

        Args:
          have: List of SHA1s of objects that should not be sent
          want: List of SHA1s of objects that should be sent
          shallow: Set of shallow commit SHA1s to skip
          progress: Optional progress reporting method
        )r   r4   )r+   havewantr   r^   missings         r/   generate_pack_contentsz&BaseObjectStore.generate_pack_contents  s)     ++D$J~~g&&r5   c                 <    t        | j                  ||||            S )ap  Generate pack data objects for a set of wants/haves.

        Args:
          have: List of SHA1s of objects that should not be sent
          want: List of SHA1s of objects that should be sent
          shallow: Set of shallow commit SHA1s to skip
          ofs_delta: Whether OFS deltas can be included
          progress: Optional progress reporting method
        )r   r   )r+   r   r   r   r^   	ofs_deltas         r/   generate_pack_dataz"BaseObjectStore.generate_pack_data  s%     $''dGXF
 	
r5   c                     | |   }t        |j                        }|t        u r|j                  \  }}| |   }|t        u r|S )a  Peel all tags from a SHA.

        Args:
          sha: The object SHA to peel.
        Returns: The fully-peeled SHA1 of a tag object, after peeling all
            intermediate tags; if the original ref does not point to a tag,
            this will equal the original SHA1.
        )r   	type_namer   object)r+   r.   rX   	obj_classs       r/   peel_shazBaseObjectStore.peel_sha.  sJ     3i /	3 ZZNIss)C 3 
r5   c                     | j                   S r(   r   r   s    r/   r   zBaseObjectStore.<lambda>C  r   r5   c                    t               }t               }g }|j                  |       |r`|j                  d      }||v r|j                  |       n6||vr2|j                  |       ||v rC| |   }	|j                   ||	             |r`||fS )a  Collect all ancestors of heads up to (excluding) those in common.

        Args:
          heads: commits to start from
          common: commits to end at, or empty set to walk repository
            completely
          get_parents: Optional function for getting the parents of a
            commit.
        Returns: a tuple (A, B) where A - all commits reachable
            from heads but not present in common, B - common (shared) elements
            that are directly reachable from heads
        r   )setextendpopadd)
r+   headscommonr   r   basescommitsqueueecmts
             r/   _collect_ancestorsz"BaseObjectStore._collect_ancestors>  s    & %U		!AF{		!'!A<1g[-.  r5   c                      y)z,Close any files opened by this object store.N rC   s    r/   closezBaseObjectStore.closea  s    r5   r(   )FFFNF)NN)NNT)__name__
__module____qualname____doc__r0   r4   r9   r=   r@   propertyrD   rG   rO   rS   rV   r[   rj   r   r}   r   r   r   r   r   r   r   r   r   r5   r/   r&   r&   I   s    !
/78E " "0B
134: "H* 1!'F 
' BF
"& u1! F;r5   r&   c                       e Zd ZddZed        Zd Zd Zd Zd Z	d Z
d Zd	 Zed
        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZddZy)PackBasedObjectStorec                      i | _         || _        y r(   )_pack_cacherc   )r+   rc   s     r/   __init__zPackBasedObjectStore.__init__g  s    &<#r5   c                     g S r(   r   rC   s    r/   
alternateszPackBasedObjectStore.alternatesk  s    	r5   c                 R    | j                   D ]	  }	 ||v r y y# t        $ r Y w xY w)zpCheck if a particular object is present by SHA1 and is packed.

        This does not check alternates.
        TF)rD   r   )r+   r.   r$   s      r/   r=   z$PackBasedObjectStore.contains_packedo  s?    
 JJD$;    ' s   	&&c                 x    | j                  |      s| j                  |      ry| j                  D ]  }||v s y y)r?   TF)r=   r9   r   )r+   r.   	alternates      r/   r@   z!PackBasedObjectStore.__contains__|  s@    
 $(;(;C(@Ii ) r5   c                     | j                   j                  |      }||ur#|| j                   |<   |r|j                          yyy)z/Add a newly appeared pack to the cache by path.N)r   getr   )r+   	base_namer$   	prev_packs       r/   _add_cached_packz%PackBasedObjectStore._add_cached_pack  sG    $$((3	D *.DY'!  !r5   c                 |    | j                   }i | _         |r'|j                         \  }}|j                          |r&y y r(   )r   popitemr   )r+   
pack_cacherI   r$   s       r/   _clear_cached_packsz(PackBasedObjectStore._clear_cached_packs  s8    %%
%--/LT4JJL r5   c                 6    | j                   j                         S r(   )r   valuesrC   s    r/   _iter_cached_packsz'PackBasedObjectStore._iter_cached_packs  s    &&((r5   c                 ,    t        | j                        r(   )r8   _update_pack_cacherC   s    r/   r   z'PackBasedObjectStore._update_pack_cache  s    !$"9"9::r5   c                 $    | j                          y r(   )r   rC   s    r/   r   zPackBasedObjectStore.close  s      "r5   c                 h    t        | j                               t        | j                               z   S zList with pack objects.)listr   r   rC   s    r/   rD   zPackBasedObjectStore.packs  s+     D++-.d6M6M6O1PPPr5   c              #   D   K   | j                   D ]  }|D ]  }|   yw)z=Iterate over the SHAs of all the objects in alternate stores.N)r   )r+   r   alternate_objects      r/   _iter_alternate_objectsz,PackBasedObjectStore._iter_alternate_objects  s%     I$- && %. )s    c                 ,    t        | j                        z+Iterate over the SHAs of all loose objects.)r8   _iter_loose_objectsrC   s    r/   r   z(PackBasedObjectStore._iter_loose_objects  s    !$":":;;r5   c                 ,    t        | j                        r(   )r8   _get_loose_objectr:   s     r/   r   z&PackBasedObjectStore._get_loose_object  s    !$"8"899r5   c                 ,    t        | j                        r(   )r8   _remove_loose_objectr:   s     r/   r   z)PackBasedObjectStore._remove_loose_object  s    !$";";<<r5   c                 ,    t        | j                        r(   r8   _remove_packrH   s     r/   r   z!PackBasedObjectStore._remove_pack      !$"3"344r5   c                    t               }| j                         D ]$  }|j                  | j                  |      df       & | j	                  t        |             |D ]   \  }}| j                  |j                         " t        |      S )zGPack loose objects.

        Returns: Number of objects packed
        N)	r   r   r   r   r[   r   r   idlen)r+   r]   r.   rX   rq   s        r/   pack_loose_objectsz'PackBasedObjectStore.pack_loose_objects  sv    
 %++-CKK//4d;< .g' IC%%cff- !7|r5   c                    t               }| j                         D ]"  }|j                  | j                  |             $ |D ch c]  }|df }}| j                  D ci c]  }|j                         | }}|j                         D ]+  \  }}|j                  d |j                         D               - | j                  |      }	|j                  |	j                         d       |D ]  }| j                  |j                          |j                         D ]  \  }}| j                  |        | j                          t        |      S c c}w c c}w )zRepack the packs in this repository.

        Note that this implementation is fairly naive and currently keeps all
        objects in memory while it repacks.
        Nc              3   $   K   | ]  }|d f 
 y wr(   r   ).0rX   s     r/   	<genexpr>z.PackBasedObjectStore.repack.<locals>.<genexpr>  s     E2D3C;2Ds   )r   r   r   r   rD   rI   r)   updateiterobjectsr[   r   r   r   r   r   r   )
r+   loose_objectsr.   rX   r]   p	old_packsrI   r$   consolidateds
             r/   repackzPackBasedObjectStore.repack  s'    ++-Cd44S9: .*78-3C;-8*.**5*QQVVXq[*	5#//+JD$NNE$2B2B2DEE , ''0l'')40 C%%cff- !#//+JD$d# ,!7|# 95s   EEc              #      K   | j                          | j                         D ]  }	 |D ]  }|   | j                         D ]  }|  | j	                         D ]  }|  y# t        $ r Y Ow xY ww)rR   N)r   r   r   r   r   )r+   r$   r.   s      r/   rS   zPackBasedObjectStore.__iter__  s~     !++-DCI   . ++-CI .//1CI 2	 ' s'   $A6A'5A6'	A30A62A33A6c                 (    | j                  |      duS )zoCheck if a particular object is present by SHA1 and is loose.

        This does not check alternates.
        N)r   r:   s     r/   r9   z#PackBasedObjectStore.contains_loose  s    
 %%c*$66r5   c                    |t         k(  rt        |      t        |      dk(  rt        |      }|}n!t        |      dk(  r|}d}nt	        d|      | j                         D ]  }	 |j                  |      c S  |t        |      }| j                  |      }||j                  |j                         fS | j                         D ]  }	 |j                  |      c S  | j                  D ]  }	 |j                  |      c S  t        |      # t        t        f$ r Y w xY w# t        $ r Y gw xY w# t        $ r Y Rw xY w)zObtain the raw fulltext for an object.

        Args:
          name: sha for the object.
        Returns: tuple with numeric type and object contents.
        (      NzInvalid object name )r   KeyErrorr   r   AssertionErrorr   rG   r   r   r   rM   as_raw_stringr   r   )r+   rI   r.   hexshar$   retr   s          r/   rG   zPackBasedObjectStore.get_raw  sT    84. t9?T"CFY"_CF T!CDD++-D||C(( .
 >%F$$V,?<<!2!2!444 ++-D||C(( .
 I ((00 )
 v' 12   
  s6   &D
D".D1DD"	D.-D.1	D=<D=Nc                 8     | j                   t        |      d|iS )zAdd a set of objects to this object store.

        Args:
          objects: Iterable over (object, path) tuples, should support
            __len__.
        Returns: Pack object of the objects written.
        r^   )rj   r   r\   s      r/   r[   z PackBasedObjectStore.add_objects  s"     "t!!#7#@T8TTr5   )r(   )r   r   r   r   r   r   r=   r@   r   r   r   r   r   rD   r   r   r   r   r   r   r   rS   r9   rG   r[   r   r5   r/   r   r   f  s    =  
");# Q Q'<:=587'RUr5   r   c                        e Zd ZdZd fd	Zd Zed        Zed        Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zed        Z xZS )DiskObjectStorez+Git-style object store that exists on disk.c                     t         t        |   |       || _        t        j                  j                  | j                  t              | _        d| _        || _	        || _
        y)zOpen an object store.

        Args:
          path: Path of the object store.
          loose_compression_level: zlib compression level for loose objects
          pack_compression_level: zlib compression level for pack objects
        )rc   N)superr   r   rq   osjoinPACKDIRpack_dir_alternatesloose_compression_levelrc   )r+   rq   r  rc   	__class__s       r/   r   zDiskObjectStore.__init__-  sW     	ot-#9 	. 	
 	TYY8'>$&<#r5   c                 P    d| j                   j                  d| j                  dS )N<(z)>)r  r   rq   rC   s    r/   __repr__zDiskObjectStore.__repr__>  s    !^^44dii@@r5   c                 x   	 t        |j                  dd      j                               }	 t        |j                  dd      j                               }	 t        |j                  dd      j                               } | |||      S # t        $ r d}Y kw xY w# t        $ r |}Y Rw xY w# t        $ r |}Y 9w xY w)N)s   cores   compressionr   s   looseCompressionpackCompression)intr   decoder   )clsrq   configdefault_compression_levelr  rc   s         r/   from_configzDiskObjectStore.from_configA  s    	+(+

:~6==?)%
	@&)

:':;BBD'#
	?%(

:'89@@B&"
 402HII  	+(*%	+  	@&?#	@  	?%>"	?s4   )B	 )B )B+ 	BBB('B(+B98B9c                     | j                   | j                   S g | _         | j                         D ]&  }| j                   j                  t        |             ( | j                   S r(   )r  _read_alternate_pathsr   r   )r+   rq   s     r/   r   zDiskObjectStore.alternatesW  sZ    '###..0D##OD$9: 1r5   c           	   #   P  K   	 t        t        j                  j                  | j                  t        d      d      }|5  |j                         D ]  }|j                  d      }|j                  d      r&t        j                  j                  |      rt        j                  |       ]t        j                  t        j                  j                  t        j                  | j                        |              	 d d d        y # t
        $ r Y y w xY w# 1 sw Y   y xY ww)Nr   rb   
   #)r   r  rq   r  INFODIRFileNotFoundError	readlinesrstrip
startswithisabsfsdecodefsencode)r+   rg   lines      r/   r  z%DiskObjectStore._read_alternate_paths`  s     	TYYFMA {{5)??4(77==&++d++++bggll2;;tyy3I4&PQQ & Q ! 		Qs?   D&9D D&CD	D&	DD&DD&D#D&c                    	 t        j                  t         j                  j                  | j                  t                     t         j                  j                  | j                  t        d      }t        |d      5 }	 t        |d      }|5  |j                  |j                                ddd       |j                  t        j                  |      dz          ddd       t         j                  j                  |      s*t         j                  j                  | j                  |      }| j                  j                  t        |             y# t
        $ r Y w xY w# 1 sw Y   xY w# t        $ r Y w xY w# 1 sw Y   xY w)z+Add an alternate path to this object store.r   wbr  Nr  )r  mkdirrq   r  r  FileExistsErrorr   openwritereadr  r"  r   r   r   r   )r+   rq   alternates_pathrg   orig_fs        r/   add_alternate_pathz"DiskObjectStore.add_alternate_patho  s   	HHRWW\\$))W56 '',,tyy'<H_d+q+ot4 GGFKKM* GGBKK%-. , ww}}T"77<<		40Dt45  		 V %  ,+sZ   AE >E> E/E> E#./E>	E E #E,	(E>/	E;8E>:E;;E>>Fc                    	 t        j                  | j                        }t               }|D ]p  }|j                  d      s|j                  d      s't         j                  j                  |      d   dz   }||v sQ|dt        d        }|j                  |       r g }|D ]d  }|| j                  vst        t         j                  j                  | j                  |            }|j                  |       || j                  |<   f t        | j                        |z
  D ]+  }| j                  j!                  |      j	                          - |S # t        $ r | j	                          g cY S w xY w)z4Read and iterate over new pack files and cache them.pack-.packr   .idxN)r  listdirr  r  r   r   r  r*   rq   splitextr   r   r   r   r  r   r   )	r+   pack_dir_contents
pack_filesrI   idx_name	pack_name	new_packsrg   r$   s	            r/   r   z"DiskObjectStore._update_pack_cache  sC   	 "

4== 9 U
%Dw'DMM',B 77++D1!4v=00 $_G} 5INN9- & 	A(((BGGLL:;  &&*  #	  T%%&3A  #))+ 4/ ! 	JJLI	s   E E10E1c                 .    t        | j                  |      S r(   )r   rq   r:   s     r/   _get_shafile_pathz!DiskObjectStore._get_shafile_path  s    tyy#..r5   c              #   F  K   t        j                  | j                        D ]{  }t        |      dk7  rt        j                  t         j                  j	                  | j                  |            D ]*  }t        j
                  ||z         }t        |      s'| , } y w)N   )r  r2  rq   r   r  r"  r   )r+   baserestr.   s       r/   r   z#DiskObjectStore._iter_loose_objects  st     JJtyy)D4yA~

277<<		4#@Akk$+.#C(		 B *s   BB!c                 n    | j                  |      }	 t        j                  |      S # t        $ r Y y w xY wr(   )r:  r
   	from_pathr  r+   r.   rq   s      r/   r   z!DiskObjectStore._get_loose_object  s:    %%c*	$$T**  		s   ( 	44c                 L    t        j                  | j                  |             y r(   )r  remover:  r:   s     r/   r   z$DiskObjectStore._remove_loose_object  s    
		$((-.r5   c                 P   	 | j                   t        j                  j                  |j                        = |j                          t        j                  |j                  j                         t        j                  |j                  j                         y # t
        $ r Y nw xY wr(   )
r   r  rq   basename	_basenamer   r   rC  dataindex)r+   r$   s     r/   r   zDiskObjectStore._remove_pack  so    	  !1!1$..!AB 	


		$))..!
		$**//"	  		s   4B 	B%$B%c                     t        d |D              }|j                  d      }t        j                  j	                  | j
                  d|z         S )Nc              3   &   K   | ]	  }|d      ywr   Nr   r   r{   s     r/   r   z5DiskObjectStore._get_pack_basepath.<locals>.<genexpr>  s     958   asciir/  )r   r  r  rq   r  r  )r+   entriessuffixs      r/   _get_pack_basepathz"DiskObjectStore._get_pack_basepath  s>    999w'ww||DMM7V+;<<r5   c                 L   t        |      }|j                  d       t        |t        |      t        |j	                               z          |j                          t        |d      }|j                  dt        j                         |j	                         D ]d  }t        |      dk(  sJ | j                  |      \  }}	|j                         }
t        |||	|| j                        }|j                  ||
|f       f |j                         }|j                  |       |j!                          |j#                          | j%                  |      }|dz   }t&        j(                  dk(  r	 t        j*                  |       t        j.                  ||       t1        |dz   d	      }	 t3        |||       |j!                          |j5                          t7        |      }|j9                          | j;                  ||       |S # t,        $ r Y w xY w# |j5                          w xY w)
a  Move a specific file containing a pack into the pack directory.

        Note: The file should be on the same file system as the
            packs directory.

        Args:
          f: Open file object for the pack.
          path: Path to the pack file.
          copier: A PackStreamCopier to use for writing pack data.
          indexer: A PackIndexer for indexing the pack.
        r   end_ofsr   )r.   ra   r0  win32r1  r%  )r   seekr   r   ext_refsflushr   r  SEEK_CURrG   tellr   rc   r   digestr)  r   sortrQ  sysplatformrC  r  renamer   r   ri   r   check_length_and_checksumr   )r+   rg   rq   copierindexerrO  new_shaext_sharM   rG  offsetcrc32pack_shapack_base_nametarget_pack
index_file
final_packs                    r/   _complete_thin_packz#DiskObjectStore._complete_thin_pack  s    w- 	
q	!S\C0@0@0B,CCD 	
	 #1c2 	
q"++ '')Gw<2%%%!\\'2NHdVVXF%"&"="=E NNGVU34 * >>#			 	009$w.<<7"		+& 			$$ ^f4d;
	
GX> .)
,,.nj9! %  s   +H &H 	HHH#c                 6   ddl }|j                  | j                  d      \  }}t        j                  |d      5 }t        || j                        }t        ||||      }|j                          | j                  ||||      cddd       S # 1 sw Y   yxY w)aw  Add a new thin pack to this object store.

        Thin packs are packs that contain deltas with parents that exist
        outside the pack. They should never be placed in the object store
        directly, and always indexed and completed as they are copied.

        Args:
          read_all: Read function that blocks until the number of
            requested bytes are read.
          read_some: Read function that returns at least one byte, but may
            not return the number of bytes requested.
        Returns: A Pack object pointing at the now-completed thin pack in the
            objects/pack directory.
        r   N	tmp_pack_)dirprefixzw+bresolve_ext_ref
delta_iter)
tempfilemkstemprq   r  fdopenr    rG   r!   verifyrm  )	r+   read_all	read_somerv  fdrq   rg   rc  rb  s	            r/   add_thin_packzDiskObjectStore.add_thin_pack  s}     	##		+#FDYYr5!Q!!T\\BG%h	1QFMMO++AtVWE	 "!!s   A
BBc                 p   t        |      5 }|j                         }| j                  |      }|dz   }t        j                  j                  |      s0t        |d      5 }t        |||j                                ddd       ddd       | j                  D ]  }|j                  k(  s|c S  dz   }t        j                  dk(  r	 t        j                  |       t        j                  ||       t!        |      }	| j#                  ||	       |	S # 1 sw Y   xY w# 1 sw Y   xY w# t        $ r Y Xw xY w)zMove a specific file containing a pack into the pack directory.

        Note: The file should be on the same file system as the
            packs directory.

        Args:
          path: Path to the pack file.
        r1  r%  Nr0  rV  )r   sorted_entriesrQ  r  rq   existsr   r   get_stored_checksumrD   rF  r^  r_  rC  r  r`  r   r   )
r+   rq   r   rO  rE  
index_namerg   r$   rj  rl  s
             r/   move_in_packzDiskObjectStore.move_in_pack'  s    d^q&&(G..w7H!F*J77>>*-Z.!'7A4I4I4KL /  JJD~~)  (<<7"		+& 			$$(^
h
3! /. ^  % s6   ADD:DD) D	DD&)	D54D5c                      ddl }|j                   j                  d      \  t        j                  d       fd}fd}||fS )Add a new pack to this object store.

        Returns: Fileobject to write to, a commit function to
            call when the pack is finished and an abort
            function.
        r   Nr0  )rp  rP  r%  c                       j                          t        j                          j                          t        j                  j                        dkD  rj                        S t        j                         y Nr   )rY  r  fsyncr   rq   getsizer  rC  )rg   r|  rq   r+   s   r/   rh   z(DiskObjectStore.add_pack.<locals>.commitS  sT    GGIHHRLGGIwwt$q(((..		$r5   c                  P     j                          t        j                         y r(   )r   r  rC  )rg   rq   s   r/   ri   z'DiskObjectStore.add_pack.<locals>.abort]  s    GGIIIdOr5   )rv  rw  r  r  rx  )r+   rv  rh   ri   rg   r|  rq   s   `   @@@r/   rb   zDiskObjectStore.add_packG  sN     	##g#FDIIb$		 &%r5   c                    | j                  |j                        }t        j                  j	                  |      }	 t        j
                  |       t        j                  j                  |      ryt        |d      5 }|j                  |j                  | j                               ddd       y# t        $ r Y lw xY w# 1 sw Y   yxY w)z^Add a single object to this object store.

        Args:
          obj: Object to add
        Nr%  r`   )r:  r   r  rq   dirnamer&  r'  r  r   r)  as_legacy_objectr  )r+   rX   rq   rp  rg   s        r/   rV   zDiskObjectStore.add_objectc  s     %%cff-ggood#	HHSM 77>>$T4 AGG$$t7S7S$T ! 	  		 ! s   B2 =,C2	B>=B>C
c                 0   	 t        j                  |       t        j                  t         j                  j	                  |d             t        j                  t         j                  j	                  |t
                      | |      S # t        $ r Y }w xY w)Nr#   )r  r&  r'  rq   r  r  )r  rq   s     r/   initzDiskObjectStore.initv  sh    	HHTN 	dF+,
dG,-4y	  		s   B	 		BB)r   r   )r   r   r   r   r   r  classmethodr  r   r   r  r-  r   r:  r   r   r   r   rQ  rm  r}  r  rb   rV   r  __classcell__r  s   @r/   r   r   *  s    5="A J J*    R6*://#=ENF0@ 8&  r5   r   c                   |     e Zd ZdZ fdZd Zd Zd Zd Ze	d        Z
d Zd	 Zd
 Zd ZddZd Zd Zd Z xZS )MemoryObjectStorez.Object store that keeps all objects in memory.c                 F    t         t        |           i | _        d| _        y )Nr   )r  r  r   _datarc   )r+   r  s    r/   r   zMemoryObjectStore.__init__  s     /1
&(#r5   c                 p    t        |      dk(  r|S t        |      dk(  rt        |      S t        d|      )Nr   r   zInvalid sha )r   r   
ValueErrorr:   s     r/   
_to_hexshazMemoryObjectStore._to_hexsha  s5    s8r>JX^c?"677r5   c                 <    | j                  |      | j                  v S r7   )r  r  r:   s     r/   r9   z MemoryObjectStore.contains_loose  s    s#tzz11r5   c                      y)r<   Fr   r:   s     r/   r=   z!MemoryObjectStore.contains_packed  s    r5   c                 H    t        | j                  j                               S rQ   )r   r  keysrC   s    r/   rS   zMemoryObjectStore.__iter__  s    DJJOO%&&r5   c                     g S r   r   rC   s    r/   rD   zMemoryObjectStore.packs  s	     	r5   c                 b    | | j                  |         }|j                  |j                         fS rF   )r  rM   r   )r+   rI   rX   s      r/   rG   zMemoryObjectStore.get_raw  s/     4??4()||S..000r5   c                 Z    | j                   | j                  |         j                         S r(   )r  r  copyrH   s     r/   rO   zMemoryObjectStore.__getitem__  s#    zz$//$/05577r5   c                 <    | j                   | j                  |      = y)z3Delete an object from this store, for testing only.N)r  r  rH   s     r/   __delitem__zMemoryObjectStore.__delitem__  s    JJtt,-r5   c                 R    |j                         | j                  |j                  <   y)rU   N)r  r  r   rW   s     r/   rV   zMemoryObjectStore.add_object  s     XXZ

366r5   c                 :    |D ]  \  }}| j                  |        y)rZ   N)rV   )r+   r]   r^   rX   rq   s        r/   r[   zMemoryObjectStore.add_objects  s     !ICOOC  !r5   c                 6     t                fd}d }||fS )a  Add a new pack to this object store.

        Because this object store doesn't support packs, we extract and add the
        individual objects.

        Returns: Fileobject to write to and a commit function to
            call when the pack is finished.
        c                     t        j                  t        j                               j	                               } j                          t        j                  | j                        D ]  }j                  |        y r(   )
r   	from_filer   getvaluer[  r   r   for_pack_datarG   rV   )r   rX   rg   r+   s     r/   rh   z*MemoryObjectStore.add_pack.<locals>.commit  sW    ""71::<#8!&&(CAGGI#11!T\\B$ Cr5   c                       y r(   r   r   r5   r/   ri   z)MemoryObjectStore.add_pack.<locals>.abort  s    r5   r   )r+   rh   ri   rg   s   `  @r/   rb   zMemoryObjectStore.add_pack  s%     I	%	 &%r5   c                    t        |      }|j                  d       t        |t        |      t        |j	                               z          t        |d      }|j	                         D ]5  }t        |      dk(  sJ | j                  |      \  }}t        ||||       7 |j                         }|j                  |       y)zComplete a thin pack by adding external references.

        Args:
          f: Open file object for the pack.
          indexer: A PackIndexer for indexing the pack.
        r   rS  rT  r   rK   N)
r   rW  r   r   rX  r   rG   r   r\  r)  )	r+   rg   rc  rO  rd  re  rM   rG  rh  s	            r/   rm  z%MemoryObjectStore._complete_thin_pack  s     w- 	
q	!S\C0@0@0B,CCD #1c2 '')Gw<2%%%!\\'2NHda4W= * >>#	r5   c                     | j                         \  }}}	 t        || j                        }t        ||||      }|j	                          | j                  ||        |        y# t        $ r	  |         w xY w)a  Add a new thin pack to this object store.

        Thin packs are packs that contain deltas with parents that exist
        outside the pack. Because this object store doesn't support packs, we
        extract and add the individual objects.

        Args:
          read_all: Read function that blocks until the number of
            requested bytes are read.
          read_some: Read function that returns at least one byte, but may
            not return the number of bytes requested.
        rr  rt  N)rb   r    rG   r!   ry  rm  rd   )r+   rz  r{  rg   rh   ri   rc  rb  s           r/   r}  zMemoryObjectStore.add_thin_pack  st      ==?65		!!T\\BG%h	1QFMMO$$Q0
 H	  	G	s   AA& &A8r(   )r   r   r   r   r   r  r9   r=   rS   r   rD   rG   rO   r  rV   r[   rb   rm  r}  r  r  s   @r/   r  r    s[    8)
82'  18.(! ,0r5   r  c                       e Zd ZdZd Zy)ObjectIteratorz%Interface for iterating over objects.c                 ,    t        | j                        r(   )r8   r   rC   s    r/   r   zObjectIterator.iterobjects  s    !$"2"233r5   N)r   r   r   r   r   r   r5   r/   r  r    s
    /4r5   r  c                   L    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)r2   z3ObjectIterator that works on top of an ObjectStore.c                 .    || _         || _        g | _        y)zCreate a new ObjectIterator.

        Args:
          store: Object store to retrieve from
          sha_iter: Iterator over (sha, path) tuples
        N)storesha_iter_shas)r+   r  r  s      r/   r   zObjectStoreIterator.__init__  s     
 
r5   c              #   b   K   | j                         D ]  \  }}| j                  |   |f  yw)z&Yield tuple with next object and path.N)itershasr  rA  s      r/   rS   zObjectStoreIterator.__iter__  s-     IC**S/4'' )s   -/c              #   (   K   | D ]	  \  }}|  yw)zIterate over just the objects.Nr   )r+   orq   s      r/   r   zObjectStoreIterator.iterobjects"  s     GAtG s   c              #      K   | j                   D ]  }|  | j                  D ]!  }| j                   j                  |       | # yw)zIterate over the SHAs.N)r  r  r   r:   s     r/   r  zObjectStoreIterator.itershas'  s>     ::CI ==CJJc"I !s   AA	c                 2    |t         k(  ry|| j                  v S )a   Check if an object is present.

        Note: This checks if the object is present in
            the underlying object store, not if it would
            be yielded by the iterator.

        Args:
          needle: SHA1 of the object to check for
        F)r   r  )r+   needles     r/   r@   z ObjectStoreIterator.__contains__/  s     X##r5   c                      | j                   |   S )zFind an object by SHA1.

        Note: This retrieves the object from the underlying
            object store. It will also succeed if the object would
            not be returned by the iterator.
        )r  )r+   keys     r/   rO   zObjectStoreIterator.__getitem__=  s     zz#r5   c                 F    t        t        | j                                     S )zReturn the number of objects.)r   r   r  rC   s    r/   __len__zObjectStoreIterator.__len__F  s    4())r5   c                 V    dd l }|j                  dt               | j                         S )Nr   zUse bool() instead.)warningswarnDeprecationWarning_empty)r+   r  s     r/   emptyzObjectStoreIterator.emptyJ  s!    +-?@{{}r5   c                 Z    | j                         }	 t        |       y# t        $ r Y yw xY w)NFT)r  r   StopIteration)r+   its     r/   r  zObjectStoreIterator._emptyP  s2    ]]_	H   		s    	**c                 $    | j                          S )z*Indicate whether this object has contents.)r  rC   s    r/   __bool__zObjectStoreIterator.__bool__Y  s    ;;=  r5   N)r   r   r   r   r   rS   r   r  r@   rO   r  r  r  r  r   r5   r/   r2   r2     s7    =	(

$*!r5   r2   c                 l     | |      }t        |t              st        |      |j                  | |      S )zLook up an object in a Git tree.

    Args:
      lookup_obj: Callback for retrieving object by SHA1
      root_sha: SHA1 of the root tree
      path: Path to lookup
    Returns: A tuple of (mode, SHA) of the resulting path.
    )
isinstancer   r   lookup_path)
lookup_objroot_sharq   trees       r/   tree_lookup_pathr  ^  s6     hDdD!8$$J--r5   c                     | |   }|j                         D ]K  \  }}}t        |      r||vs|j                  |       t        j                  |      s?t        | ||       M y)zCollect SHA1s of files and directories for specified tree.

    Args:
      obj_store: Object store to get objects by SHA from
      tree_sha: tree reference to walk
      kset: set to fill with references to files and directories
    N)	iteritemsr   r   rx   ry   _collect_filetree_revs)	obj_storetree_shaksetfiletreerI   rs   r.   s          r/   r  r  m  sX     "H#--/dC4 S_HHSM||D!&y#t<	 0r5   c                    t               }t               }t               }|D ]  }	 | |   }t        |t              r|j                  |       +t        |t              rC|j                  |       |j
                  d   }t        | |g|      \  }	}
}||	z  }||
z  }||z  }~|j                  |        |||fS # t        $ r |s Y w xY w)a4  Split object id list into three lists with commit, tag, and other SHAs.

    Commits referenced by tags are included into commits
    list as well. Only SHA1s known in this repository will get
    through, and unless ignore_unknown argument is True, KeyError
    is thrown for SHA1 missing in the repository

    Args:
      obj_store: Object store to get objects by SHA1 from
      lst: Collection of commit and tag SHAs
      ignore_unknown: True to skip SHA1 missing in the repository
        silently.
    Returns: A tuple of (commits, tags, others) SHA1s
       )ignore_unknown)r   r  r	   r   r   r   _split_commits_and_tagsr   )r  lstr  r   tagsothersr   r  taggedcts              r/   r  r  }  s     eG5DUF	!A
 !V$AAs#!1x1a 1	!

1' ( T6""#  	! "	s   B77CCc                   2    e Zd ZdZdddd fdZd Zd ZeZy)r   a1  Find the objects missing from another object store.

    Args:
      object_store: Object store containing at least all objects to be
        sent
      haves: SHA1s of commits not to send (already present in target)
      wants: SHA1s of commits to send
      progress: Optional function to report progress to.
      get_tagged: Function that returns a dict of pointed-to sha -> tag
        sha for including tags.
      get_parents: Optional function for getting the parents of a commit.
      tagged: dict of pointed-to sha -> tag sha for including tags
    Nc                     | j                   S r(   r   r   s    r/   r   zMissingObjectFinder.<lambda>  r   r5   c                    || _         |
t               }|| _        t        ||d      \  }}	}
t        ||d      \  }}}|j	                  ||| j                        d   }|j	                  |||| j                        \  }}t               | _        |D ]C  }| j
                  j                  |       ||   }t        ||j                  | j
                         E |	D ]  }| j
                  j                  |        |j                  |	      }|j                  |
      }|j                  |      }|j                  |      }t        |D cg c]  }|d df	 c}      | _        |	d | _        n|| _        |xr  |       xs i | _        y c c}w )NTF)r   r   r   c                      y r(   r   )xs    r/   r   z.MissingObjectFinder.__init__.<locals>.<lambda>  s    dr5   )object_storer   _get_parentsr  r   sha_doner   r  r  
differenceunionobjects_to_sendr^   _tagged)r+   r  r   r   r   r^   r   r   have_commits	have_tagshave_otherswant_commits	want_tagswant_othersall_ancestorsmissing_commitscommon_commitshr   r  missing_tagsmissing_othersws                          r/   r   zMissingObjectFinder.__init__  s    )?eG' 0G%0
,i 0G%0
,i
 %77't7H7H 8 

 +7*I*I))	 +J +
' 
  AMMa q/C"<4==I  
 AMMa   !++I6$//<  %%l3N+"e#DeQe$4e#DE*DM$DM!2jl8b $Es   Fc                     | j                   j                  |D cg c]  }|d   | j                  vs| c}       y c c}w r  )r  r   r  )r+   rO  r   s      r/   add_todozMissingObjectFinder.add_todo  s7    ##$U1qtt}}?TQ$UV$Us   ==c                 H   	 | j                   sy | j                   j                         \  }}}|| j                  vrn;|s| j                  |   }t	        |t
              r | j                  |j                  ddfg       nt	        |t              rX| j                  |j                         D cg c]*  \  }}}t        |      s||t        j                  |       f, c}}}       n2t	        |t              r"| j                  |j                  d   d dfg       || j                  v r"| j                  | j                  |   d dfg       | j                  j!                  |       | j#                  dt%        | j                        z  j'                  d             ||fS c c}}}w )NT Fr  zcounting objects: %drN  )r  r   r  r  r  r	   r  r  r   r  r   rx   ry   r   r   r  r   r^   r   encode)r+   r.   rI   leafr  nmss           r/   r   zMissingObjectFinder.next  sm   '' $ 4 4 8 8 :S$$--'  !!#&A!V$E234At$ (){{}'4GAq!*1~ A4<<?23'4 As#T59:;$,,MMDLL-tT:;<#/#dmm2DDLLWUVT{s   -/F)r   r   r   r   r   r  r   __next__r   r5   r/   r   r     s.    & 1A9FW6 Hr5   r   c                   (    e Zd ZdZddZd Zd ZeZy)ObjectStoreGraphWalkerzGraph walker that finds what commits are missing from an object store.

    :ivar heads: Revisions without descendants in the local repo
    :ivar get_parents: Function to retrieve parents in the local repo
    Nc                 f    t        |      | _        || _        i | _        |
t               }|| _        y)zCreate a new instance.

        Args:
          local_heads: Heads to start search with
          get_parents: Function for finding the parents of a SHA1.
        N)r   r   r   r   r   )r+   local_headsr   r   s       r/   r   zObjectStoreGraphWalker.__init__   s2     %
&?eGr5   c                    t        |      dk7  rt        d|z        t        |g      }| j                  r|D ],  }|| j                  v s| j                  j	                  |       . t               }|D ]?  }| j
                  j                  |      }||j                  |       d| j
                  |<   A |sy|}| j                  ryy)z@Ack that a revision and its ancestors are present in the source.r   zunexpected sha %r receivedN)r   r  r   r   rC  r   r   r   )r+   r.   	ancestorsanew_ancestorspss         r/   r   zObjectStoreGraphWalker.ack.  s    s8r>9C?@@J	 jj

?JJ%%a( 
  EM\\%%a(>!((,"&Q	  !%I# jjr5   c                    | j                   rt| j                   j                         }| j                  |      }|| j                  |<   | j                   j	                  |D cg c]  }|| j                  vs| c}       |S yc c}w )z.Iterate over ancestors of heads in the target.N)r   r   r   r   r   )r+   r   r  r   s       r/   r   zObjectStoreGraphWalker.nextH  sq    ::**.."C!!#&B "DLLJJ"F"Q0Eq"FGJ Gs    B4Br(   )r   r   r   r   r   r   r   r  r   r5   r/   r  r    s    &4 Hr5   r  c                    i }|D ]@  \  }}}	 |j                  dd      \  }}|j                  |g       j                  |||f       B |j	                         D ]O  \  }	}
	 | ||	   d      }t        | ||
      }t        |      dk(  r||	= 1t        j                  |j                  f||	<   Q | j                  |       |S # t        $ r |||= n||f||<   Y w xY w# t
        $ r t               }Y w xY w)a  Commit a specified set of changes to a tree structure.

    This will apply a set of changes on top of an existing tree, storing new
    objects in object_store.

    changes are a list of tuples with (path, mode, object_sha).
    Paths can be both blobs and trees. See the mode and
    object sha to None deletes the path.

    This method works especially well if there are only a small
    number of changes to a big tree. For a large number of changes
    to a large tree, use e.g. commit_tree.

    Args:
      object_store: Object store to store new objects in
        and retrieve old ones from.
      tree: Original tree root
      changes: changes to apply
    Returns: New tree root object
       /r  r   )split
setdefaultr   r  r)   r   r   commit_tree_changesr   rx   S_IFDIRr   rV   )r  r  changesnested_changesrq   new_moderd  r  subpathrI   
subchangesorig_subtreesubtrees                r/   r  r  U  s   . N%,!x	X!%D!!4Wg %%gr2997Hg:VW &- +002j	"'T
16L &lL*Mw<1T
,,

3DJ 3 D!K%  	1J&0T
		1  	"6L	"s#   B=C=CCC/.C/c                   N    e Zd ZdZddZd ZddZed        Zd Z	d Z
d	 Zd
 Zy)OverlayObjectStorez5Object store that can overlay multiple object stores.Nc                      || _         || _        y r(   )r   	add_store)r+   r   r!  s      r/   r   zOverlayObjectStore.__init__  s    
"r5   c                 z    | j                   t        | j                        | j                   j                  |      S r(   )r!  r8   rV   )r+   r   s     r/   rV   zOverlayObjectStore.add_object  s0    >>!%doo66~~((00r5   c                 |    | j                   t        | j                        | j                   j                  ||      S r(   )r!  r8   rV   r[   r\   s      r/   r[   zOverlayObjectStore.add_objects  s2    >>!%doo66~~))'8<<r5   c                 b    g }| j                   D ]  }|j                  |j                          |S r(   )r   r   rD   )r+   r   bs      r/   rD   zOverlayObjectStore.packs  s*    AJJqww 
r5   c              #      K   t               }| j                  D ]#  }|D ]  }||vs| |j                  |        % y wr(   )r   r   r   )r+   doner%  o_ids       r/   rS   zOverlayObjectStore.__iter__  s=     uAt#JHHTN  s
   #A A c                 ~    | j                   D ]  }	 |j                  |      c S  t        |      # t        $ r Y .w xY wr(   )r   rG   r   )r+   sha_idr%  s      r/   rG   zOverlayObjectStore.get_raw  sE    Ayy(( 
 v  s   0	<<c                 L    | j                   D ]  }|j                  |      s y yNTF)r   r=   r+   r.   r%  s      r/   r=   z"OverlayObjectStore.contains_packed  s&    A  %  r5   c                 L    | j                   D ]  }|j                  |      s y yr,  )r   r9   r-  s      r/   r9   z!OverlayObjectStore.contains_loose  s&    A$  r5   r(   )r   r   r   r   r   rV   r[   r   rD   rS   rG   r=   r9   r   r5   r/   r  r    s<    ?#1
=
  #r5   r  c              #      K   | j                         j                         D ]7  }|s|j                  dd      \  }}|dk7  r!t        j                  |       9 yw)z'Yield the packs listed in a packs file.    r     PN)r*  
splitlinesr  r  r!  )rg   r#  kindrI   s       r/   read_packs_filer4    sR     ##%zz$*t4<kk$ &s   AAc                   F    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)BucketBasedObjectStorezMObject store implementation that uses a bucket store like S3 as backend.
    c                     t        g       S r   )r   rC   s    r/   r   z*BucketBasedObjectStore._iter_loose_objects  s    Bxr5   c                      y r(   r   r:   s     r/   r   z(BucketBasedObjectStore._get_loose_object  s    r5   c                      y r(   r   r:   s     r/   r   z+BucketBasedObjectStore._remove_loose_object  s    r5   c                 ,    t        | j                        r(   r   rH   s     r/   r   z#BucketBasedObjectStore._remove_pack  r   r5   c                 ,    t        | j                        r(   )r8   _iter_pack_namesrC   s    r/   r<  z'BucketBasedObjectStore._iter_pack_names  s    !$"7"788r5   c                 ,    t        | j                        r(   )r8   	_get_packrH   s     r/   r>  z BucketBasedObjectStore._get_pack  s    !$..11r5   c                 V   t        | j                               }g }|D ]B  }|| j                  vs| j                  |      }|j	                  |       || j                  |<   D t        | j                        |z
  D ]+  }| j                  j                  |      j                          - |S r(   )r   r<  r   r>  r   r   r   )r+   r5  r8  rg   r$   s        r/   r   z)BucketBasedObjectStore._update_pack_cache  s    ..01
 	A(((~~a(  &&*  #	  T%%&3A  #))+ 4r5   c                     t         r(   rB   )r+   rE  	pack_filerk  s       r/   _upload_packz#BucketBasedObjectStore._upload_pack  s    !!r5   c                 \     ddl j                          fd}|j                  fS )r  r   Nc                      j                         dk(  rj                          y j                  d       t        j                        } | j                         }t        d |D              j                  d      }
j                         }| j                         }t        |||       |j                  d       t        |dz   |      }	j                  D ]G  }|j                         | j                         k(  s%| j                          |j                          |c S  j                  d       |j                  d       	j                  ||       t        j                  | |      }	j!                  ||       |S )Nr   c              3   &   K   | ]	  }|d      ywrK  r   rL  s     r/   r   zBBucketBasedObjectStore.add_pack.<locals>.commit.<locals>.<genexpr>  s      ?weqwrM  rN  r1  )r[  r   rW  r   rI   r  r   r  SpooledTemporaryFiler  r   r   rD   rB  r   from_objectsr   )r   rO  rE  idxfchecksumidxr$   rl  pfr+   rv  s           r/   rh   z/BucketBasedObjectStore.add_pack.<locals>.commit  s5   wwyA~
GGAJ"%A&&(G  ?w ??FFwOH002D,,.Hgx8IIaL&x&'8$?C

++-1F1F1HHGGIIIKK	 #
 GGAJIIaLhD1**1c2J!!(J7r5   )rv  rF  r   )r+   rh   rK  rv  s   ` @@r/   rb   zBucketBasedObjectStore.add_pack  s.     	**,	4 6288##r5   N)r   r   r   r   r   r   r   r   r<  r>  r   rB  rb   r   r5   r/   r6  r6    s4    592"%$r5   r6  r   )<r   ior   r  rx   r^  dulwich.diff_treer   r   dulwich.errorsr   dulwich.filer   dulwich.objectsr	   r
   r   r   r   r   r   r   r   r   r   dulwich.packr   r   r   r   r   r   r   r   r   r   r   r   r    r!   dulwich.refsr"   r  r  r   r&   r   r   r  r  r2   r  r  r  r   r  r  r  r4  r6  r   r5   r/   <module>rS     s	  . 6  	  
 !        .

Y;f Y;zAU? AUHT* Tn
D DN4V 4L!. L!^.= &#Rp& pf9V 9x-`2 2j O$1 O$r5   