
    	^c~                        d dl Z ddlmZmZmZ ddlmZmZmZm	Z	m
Z
mZ ddlmZmZ e	j        r3d dlmZmZmZmZmZmZmZmZmZ ddlmZ  eeeeeeeeeeef
          sJ ej        Ze j        Ze j        Ze j        Z G d d	          Z d
 Z!d Z" G d d          Z# G d de#          Z$dZ%de%z   Z&de%z   Z'dZ( ee(          Z)de)z  Z*dZ+dZ,dZ- G d d          Z.dS )    N   )binhexnullrev)encodingerrorobsoletepycompatscmutilutil)repoviewutil
stringutil)	AnyCallableDictIterableListOptionalSetTupleUnion)	localrepoc                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	BranchMapCachez8mapping of filtered views of repo with their branchcachec                     i | _         d S N)_per_filterselfs    5/usr/lib/python3/dist-packages/mercurial/branchmap.py__init__zBranchMapCache.__init__D   s        c                 P    |                      |           | j        |j                 S r   )updatecacher   
filternamer   repos     r    __getitem__zBranchMapCache.__getitem__G   s&    00r"   c                    |j         }|j        }| j                            |                              |          st
                              |          g }t                              |          }|e|                    |          }| |         	                                |j         j
        |j
        z
  }|                    fd|D                        nt          |          |                    |                    j        dz                        |r                    ||                               |          s
J |            | j        |j        <   dS )z<Update the cache for the given filtered view on a repositoryNc              3   2   K   | ]}|j         k    |V  d S r   )tiprev).0rbcaches     r    	<genexpr>z-BranchMapCache.updatecache.<locals>.<genexpr>b   s/      GG!A4F4FA4F4F4F4FGGr"   r   )start)	changelogr%   r   getvalidforbranchcachefromfilesubsettablefilteredcopyfilteredrevsextendrevsr+   update)	r   r'   clr%   r;   
subsetnamesubset	extrarevsr.   s	           @r    r$   zBranchMapCache.updatecacheK   s]    ^_
!%%j11>!6!6> ))$//F> %44J%z22f**,,",9BOK	GGGGyGGGGGGG %T**BGG&-!"3G44555 	&MM$%%%t$$00j000,2)))r"   c                 ,   |j         }|j        |j        }g }t                      }|                                D ]<}||z  }|D ]2} |          }	 ||	          \  }
}|r|                    |           3=|rt          fd|D                       }t          ||||                                         ||          }dD ]P}|	                    |          }|
                    |          r"|| j        |<   |                    |            dS OdS dS )zReplace the branchmap cache for a repo with a branch mapping.

        This is likely only called during clone with a branch map from a
        remote.

        c              3   H   K   | ]}t           |                    V  d S r   )int)r,   nodeclrevs     r    r/   z)BranchMapCache.replace.<locals>.<genexpr>   s3      @@3uuT{{++@@@@@@r"   )closednodes)s   bases	   immutables   servedN)r1   rev
branchinfosetvaluesaddmaxr4   rD   r7   r3   r   write)r   r'   remotebranchmapr=   clbranchinforbheadsclosedbheadshr-   bcrtiprevcache	candidaterviewrE   s                   @r    replacezBranchMapCache.replacen   sl    ^}%,,.. 	" 	"FvG " "E!HH#|A1 "JJqMMM	"  	@@@@@@@AAGW""$$"  E @  	i00>>%(( 27D$Y/KK&&&FF	 	 r"   c                 8    | j                                          d S r   )r   clearr   s    r    r\   zBranchMapCache.clear   s         r"   c                     |                                 }| j                                        D ]6\  }}|j        r*|                    |          }|                    |           7d S r   )
unfilteredr   items_delayedr7   rM   )r   r'   unfir%   rW   s        r    write_delayedzBranchMapCache.write_delayed   sl      !%!1!7!7!9!9 	" 	"J~ "}}Z00D!!!	" 	"r"   N)
__name__
__module____qualname____doc__r!   r(   r$   rZ   r\   rb    r"   r    r   r   A   sv        BB  1 1 1!3 !3 !3F% % %N! ! !" " " " "r"   r   c                 J    t          d|                                 z            )zEraises ValueError when branchcache found a node which does not existsznode %s does not exist)
ValueErrorr   rD   s    r    _unknownnoderk      s    
-

:
;
;;r"   c                 (    | j         
d| j         z  S dS )Ns   branch cache (%s)s   branch cacher%   )r'   s    r    _branchcachedescrn      s    "#do55r"   c                       e Zd ZdZddedddfdZd Zd Zd Zd Z	d	 Z
d
 Zd Zd ZeZd Zed             Zd Zed             Zd Zd Zd Zd ZddZd Zd Zd Zd Zd ZdS )r4   a<  A dict like object that hold branches heads cache.

    This cache is used to avoid costly computations to determine all the
    branch heads of a repo.

    The cache is serialized on disk in the following format:

    <tip hex node> <tip rev number> [optional filtered repo hex hash]
    <branch head hex node> <open/closed state> <branch name>
    <branch head hex node> <open/closed state> <branch name>
    ...

    The first line is used to check if the cache is still valid. If the
    branch cache is for a filtered repo view, an optional third hash is
    included that hashes the hashes of all filtered and obsolete revisions.

    The open/closed state is represented by a single letter 'o' or 'c'.
    This field can be used to avoid changelog reads when determining if a
    branch head closes a branch or not.
    rg   Nc                 0   || _         d| _        ||j        | _        n|| _        || _        || _        |t                      | _        n|| _        t          |          | _	        d| _
        t                      | _        || _        | j        
d | _        dS dS )zhasnode is a function which can be used to verify whether changelog
        has a given node or not. If it's not provided, we assume that every node
        we have exists in changelogFNc                     dS )NTrg   )xs    r    <lambda>z&branchcache.__init__.<locals>.<lambda>   s    d r"   )_repor`   nullidtipnoder+   filteredhashrI   _closednodesdict_entries_closedverified_verifiedbranches_hasnode)r   r'   entriesrv   r+   rw   rF   hasnodes           r    r!   zbranchcache.__init__   s     
?;DLL"DL(  #D +DW$!$= *NDMMM ! r"   c                     | j         rdS | j        D ]&}|                     |          st          |           'd| _         dS )zverify the closed nodes we haveNT)r{   rx   r}   rk   )r   rD   s     r    _verifyclosedzbranchcache._verifyclosed   sU     	F% 	# 	#D==&& #T"""#r"   c                     || j         vs	|| j        v rdS | j         |         D ]&}|                     |          st          |           '| j                            |           dS )z'verify head nodes for the given branch.N)rz   r|   r}   rk   rK   )r   branchns      r    _verifybranchzbranchcache._verifybranch   st    &&&D4J*J*JFv& 	  	 A==##  Q""6*****r"   c                     t          | j                                                  | j        z
  }|D ]}|                     |           dS )z"verifies nodes of all the branchesN)rI   rz   keysr|   r   )r   needverificationrT   s      r    
_verifyallzbranchcache._verifyall   sV    t}113344t7MM! 	" 	"Aq!!!!	" 	"r"   c                 *    t          | j                  S r   )iterrz   r   s    r    __iter__zbranchcache.__iter__  s    DM"""r"   c                     || j         |<   d S r   )rz   )r   keyvalues      r    __setitem__zbranchcache.__setitem__  s    "cr"   c                 F    |                      |           | j        |         S r   r   rz   r   r   s     r    r(   zbranchcache.__getitem__  s#    3}S!!r"   c                 >    |                      |           || j        v S r   r   r   s     r    __contains__zbranchcache.__contains__  s#    3dm##r"   c              #   ~   K   | j                                         D ] \  }}|                     |           ||fV  !d S r   )rz   r_   r   )r   kvs      r    	iteritemszbranchcache.iteritems  sT      M'')) 	 	DAqq!!!Q$JJJJ	 	r"   c                 >    |                      |           || j        v S )z2checks whether a branch of this name exists or notr   )r   labels     r    	hasbranchzbranchcache.hasbranch  s#    5!!!%%r"   c                    d }	 |                     |                     |                    }t          |          }t          |                              d                              dd          }|d d         \  }}t          |          t          |          }}d }|j        j	        }t          |          dk    rt          |d                   } | |||||          }	|	                    |          st          d          |	                    ||           n# t          t          f$ r Y |r|                                 d S d S t"          $ rX}
|j        j        r@d}|j                            |t+          |          t-          j        |
          fz             d }	Y d }
~
nd }
~
ww xY w|r|                                 n# |r|                                 w w xY w|	S )N   
       )rv   r+   rw   r   ztip differss   invalid %s: %s
)cachevfs	_filenamer   nextrstripsplitr   rC   r1   r   lenr3   ri   loadIOErrorOSErrorclose	Exceptionui	debugflagdebugrn   r   forcebytestr)clsr'   flineitercachekeylastlrevrw   r   r.   instmsgs               r    r5   zbranchcache.fromfile  s   &	cmmD1122AAwwHH~~,,U3399$BBH!"1"JD$TCII$DLn,G8}}q  "8A;//S)  F ??4(( 0 ///KKh''''! 	 	 	  					   
	 
	 
	w  )(.."/55   FFFFFF
	  			  				 s=   DD G F*.G 		F*AF% G %F**G Gc                    |D ]}|                     d          }|s|                    dd          \  }}}|dvrt          d          t          j        |                                          }t          |          }| j                            |g           	                    |           |dk    r| j
                            |           dS )z[fully loads the branchcache by reading from the file using the line
        iterator passedr   r   r   s   oczinvalid branch state   cN)r   r   ri   r   tolocalstripr   rz   
setdefaultappendrx   rK   )r   r'   r   linerD   stater   s          r    r   zbranchcache.loadI  s      	, 	,D;;u%%D !%D!!4!4D%E!! !7888$U[[]]33Et99DM$$UB//66t<<<}}!%%d+++	, 	,r"   c                 0    d}| j         rd|| j         fz  }|S )z7name of a branchcache file for a given repo or repoviews   branch2s   %s-%srm   )r'   filenames     r    r   zbranchcache._filenameY  s)     ? 	>8T_"==Hr"   c                     	 |j                             | j                  }n# t          $ r Y dS w xY w| j        |k    rdS t          j        || j        d          }| j        |k    S )zcheck that cache contents are valid for (a subset of) this repo

        - False when the order of changesets changed or if we detect a strip.
        - True when cache is up-to-date for the current repo or its subset.FTneedobsolete)r1   rD   r+   
IndexErrorrv   r   rw   )r   r'   rD   tiphashs       r    r3   zbranchcache.validfora  s    
	>&&t{33DD 	 	 	 55	 <4 5&tT[tLLL  G++s   " 
00c                 `    |d         }d}t          |          D ]}|| j        vr|}d} n||fS )zhReturn tuple with last open head in heads and false,
        otherwise return last closed head and true.TF)reversedrx   )r   headstiprQ   rS   s        r    
_branchtipzbranchcache._branchtipv  sU     Bi% 	 	A))) * F{r"   c                 D    |                      | |                   d         S )zReturn the tipmost open head on branch head, otherwise return the
        tipmost closed head on branch.
        Raise KeyError for unknown branch.r   )r   )r   r   s     r    	branchtipzbranchcache.branchtip  s     tF|,,Q//r"   c                        fd|D             S )Nc              3   .   K   | ]}|j         v|V  d S r   )rx   )r,   r   r   s     r    r/   z'branchcache.iteropen.<locals>.<genexpr>  s0      ??aAT->$>$>$>$>$>$>??r"   rg   )r   nodess   ` r    iteropenzbranchcache.iteropen  s    ????5????r"   Fc                     |                      |           | j        |         }|s"t          |                     |                    }|S r   )r   rz   listr   )r   r   rQ   r   s       r    branchheadszbranchcache.branchheads  sH    6"""f% 	/u--..Er"   c              #   v   K   |                                  D ]!\  }}||f|                     |          z   V  "d S r   )r_   r   )r   bnr   s      r    iterbrancheszbranchcache.iterbranches  sO       	7 	7IBu+ 6 666666	7 	7r"   c                 \    |                                   | j                                        S )zreturns all the heads)r   rz   rJ   r   s    r    	iterheadszbranchcache.iterheads  s&    }##%%%r"   c                 x     t          |           | j        | j        | j        | j        | j        | j                  S )z-return an deep copy of the branchcache object)typert   rz   rv   r+   rw   rx   r   s    r    r8   zbranchcache.copy  s<    tDzzJMLK
 
 	
r"   c           	         |                                 }t          |dd          s	d| _        d S 	 |                     |          }|                    |dd          5 }t          | j                  d| j        z  g}| j        '|	                    t          | j                             |
                    d                    |          dz              d}t          | j                                                  D ]Y\  }}t          j        |          }|D ]=}	|d	z  }|	| j        v rd
}
nd}
|
                    dt          |	          |
|fz             >Z	 d d d            n# 1 swxY w Y   |j                            ddt)          |          t+          | j                  |           d| _        d S # t,          t.          t0          j        f$ r:}|j                            dt7          j        |          z             Y d }~d S d }~ww xY w)N	finalizedT   w)
atomictemps   %dr   r   r   r   r      os	   %s %s %s
   branchcaches%   wrote %s with %d labels and %d nodes
Fs    couldn't write branch cache: %s
)currenttransactiongetattrr`   r   r   r   rv   r+   rw   r   rM   joinsortedrz   r_   r   	fromlocalrx   r   logrn   r   r   r   r   Abortr   r   r   )r   r'   trr   r   r   	nodecountr   r   rD   r   r   s               r    rM   zbranchcache.write  s   $$&&r;-- 	 !DMF	~~d++Hx$?? K1--ut{/BC$0OOC(9$:$:;;;		(++e3444	$*4=+>+>+@+@$A$A K KLE5$.u55E % K K!Q	4#444$(EE$(ETE50I IJJJJKKK K K K K K K K K K K K K K K GKK9 &&DM""   "DMMM%+. 	 	 	GMM4)$//0        	s=   -F5 C:E$F5 $E((F5 +E(,AF5 5H/HHc                    t          j                    }|j        i }|                                j        }|D ]h} ||          \  }}|                    |g                               |           |r-| j                            	                    |                     i| j
        }	d}
|                                j        j        }t          j        |d          }|                                D ]8\  }}| j                            |g           }fd|D             }t%                      }t'          |          D ]?}||v r|s|                    |            d  ||          D             }t%                      }t%                      }t%                      }|D ]`}||v r|                    |           ||v s ||          d         |k    r|                    |           K|                    |           at)          |          t)          |          cxk    rdk    s,n |                    |           |                    |           |                    |           |                    |           A|rr|
!t%                                                    }
||
z
  rJt1          |          }|t3          |          k    r(t%                              ||                    }||z  }|rfdt'          |          D             | |<   t3          |          }||	k    r|}	:|	| j
        k    r!|	| _
        	                    |	          | _        |                     |          sy|j        | _        t<          | _
        |                                 D ]L}|st3          fd|D                       }|| j
        k    r!	                    |          | _        || _
        MtA          j!        || j
        d	
          | _!        t          j                    |z
  }|j"        #                    ddtI          |          |           | %                    |           dS )zGiven a branchhead cache, self, that may have extra nodes or be
        missing heads, and a generator of nodes that are strictly a superset of
        heads missing, this function updates self to be correct.
        Ns   obsoletec                 :    h | ]}                     |          S rg   rG   r,   rD   r=   s     r    	<setcomp>z%branchcache.update.<locals>.<setcomp>  s#    888t888r"   c                 (    g | ]}|t           k    |S rg   )r   )r,   ps     r    
<listcomp>z&branchcache.update.<locals>.<listcomp>  s    IIIALL1LLLr"   r   r   c                 :    g | ]}                     |          S rg   rj   )r,   rG   r=   s     r    r   z&branchcache.update.<locals>.<listcomp>=  s#    IIIIIIr"   c              3   B   K   | ]}                     |          V  d S r   r   r   s     r    r/   z%branchcache.update.<locals>.<genexpr>R  s-      <<dRVVD\\<<<<<<r"   Tr   r   s   updated %s in %.4f seconds
)&r   timerr1   revbranchcacherH   r   r   rx   rK   rD   r+   r^   
parentrevsr	   getrevsr_   rz   r2   rI   r   r   r<   difference_updateheadrevsminrL   	ancestorsrv   r3   ru   r   r   r   rw   r   r   rn   rM   )r   r'   revgen	starttimenewbranchesgetbranchinfor-   r   closesbranchntiprev	topoheadsr   obsrevsnewheadrevsrR   bheadset	uncertainnewrevparents
samebranchotherbranch
obsparentsr   floorrevr   r+   r   durationr=   s                               @r    r<   zbranchcache.update  s   
 JLL	^++--8 	2 	2A#0=#3#3 FL""62..55a888 2!%%bggajj111 + 	 __&&0;
 "455#.#4#4#6#6 S	! S	!FKH ]&&vr22F8888888HI -- % %W$$  LL(((IIjj&8&8III UU
!ee UU
  + +AG|| #q))))h--*:*:1*=*G*G"q))))#****HZ====A====$$[111$$Z000**:666V$$$$ .$ #BKKMM 2 2Ii' ."8}}H3y>>11$'Y(I(I$J$J	 I- JIIIIx8H8HIIIV%%F T[  !DK777++DL}}T"" 	)  ;DL!DK)) 	) 	)  <<<<e<<<<<DK''#%776??DL"(DK#0$+D
 
 
 :<<)++T""		
 	
 	
 	

4r"   )F)rc   rd   re   rf   r   r!   r   r   r   r   r   r(   r   r   r_   r   classmethodr5   r   staticmethodr   r3   r   r   r   r   r   r   r8   rM   r<   rg   r"   r    r4   r4      s        0 $+ $+ $+ $+L$ $ $+ + +" " "# # ## # #" " "$ $ $  
 E& & &
 * * [*X, , ,    \, , ,*
 
 
0 0 0@ @ @   7 7 7& & &
	
 	
 	
& & &PT T T T Tr"   r4   c                       e Zd ZdZd ZdS )remotebranchcachez@Branchmap info for a remote connection, should not write locallyc                     d S r   rg   r&   s     r    rM   zremotebranchcache.writeh  s    r"   N)rc   rd   re   rf   rM   rg   r"   r    r  r  e  s)        JJ    r"   r  s   -v1s	   rbc-namess   rbc-revss   >4sI@      il        c                   l    e Zd ZdZddZd Zej        d             Zd Z	d Z
d Zd	 ZddZd Zd Zd
S )r   a  Persistent cache, mapping from revision number to branch name and close.
    This is a low level cache, independent of filtering.

    Branch names are stored in rbc-names in internal encoding separated by 0.
    rbc-names is append-only, and each branch name is only stored once and will
    thus have a unique index.

    The branch info for each revision is stored in rbc-revs as constant size
    records. The whole file is read into memory, but it is only 'parsed' on
    demand. The file is usually append-only but will be truncated if repo
    modification is detected.
    The record for each revision contains the first 4 bytes of the
    corresponding node hash, and the record is only used if it still matches.
    Even a completely trashed rbc-revs fill thus still give the right result
    while converging towards full recovery ... assuming no incorrectly matching
    node hashes.
    The record also contains 4 bytes where 31 bits contains the index of the
    branch and the last bit indicate that it is a branch close commit.
    The usage pattern for rbc-revs is thus somewhat similar to 00changelog.i
    and will grow with it but be 1/8th of its size.
    Tc                 B   |j         J || _        g | _        t                      | _        d| _        	 |j                            t                    }t          |          | _        |r$d |
                    d          D             | _        n%# t          t          f$ r |r| j        | _        Y nw xY w| j        rz	 |j                            t                    }|| j        d d <   nM# t          t          f$ r9}|j                            dt#          j        |          z             Y d }~nd }~ww xY wt'          t          | j                  t(          z  t          |j                            | _        | j        dk    rg | _        t          | j                  | _        d S )Nr   c                 6    g | ]}t          j        |          S rg   )r   r   )r,   r   s     r    r   z+revbranchcache.__init__.<locals>.<listcomp>  s0       -/H$R((  r"       s(   couldn't read revision branch cache: %s
)r%   rt   _names	bytearray_rbcrevs_rbcsnameslenr   read	_rbcnamesr   r   r   r   _branchinforH   r   r   r   r   r   _rbcrecsizer1   _rbcrevslen_rbcnamescount)r   r'   readonlybndatadatar   s         r    r!   zrevbranchcache.__init__  s   &&&
!
	3]''	22F!$VD  39<<3F3F   ! 	3 	3 	3 3"&"2	3
 ; 	}))(33#'aaa  W%   @ -d334        +-s4>/B/B
 
 q  DK!$+..s*   AB B/.B/:+C& &D07/D++D0c                     d| _         | j        d d = d| _        t          | j        j                  | _        t          | j        t          z            | _	        t          j        | d           d S )Nr   s   _namesreverse)r  r  r$  r   rt   r1   r#  r  r"  r  r   clearcachedpropertyr   s    r    _clearzrevbranchcache._clear  se    KNtz344!$"2["@AA '788888r"   c                 >    d t          | j                  D             S )Nc                     i | ]\  }}||	S rg   rg   )r,   r-   rT   s      r    
<dictcomp>z0revbranchcache._namesreverse.<locals>.<dictcomp>  s    888A1888r"   )	enumerater  r   s    r    _namesreversezrevbranchcache._namesreverse  s     884;!7!78888r"   c                 L   | j         j        }|t          z  }|t          k    r|                    |          S t          | j                  |t          z   k     r|                     |          S |                    |          dt                   }t          t          t          j        | j                  |          \  }}t          |t          z            }|r
|t           z  }|dk    rn||k    rS	 | j        |         |fS # t$          $ r6 | j         j                            d           |                                  Y nTw xY w| j         j                            d|z             |t          z   }| j        |d= t-          | j        |          | _        |                     |          S )zWReturn branch name and close flag for rev, using and updating
        persistent cache.Ns       sR   referenced branch names not found - rebuilding revision branch cache from scratch
sP   history modification detected - truncating revision branch cache to revision %d
)rt   r1   r"  r   rH   r   r  r!  rD   _rbcnodelenunpack_from
_rbcrecfmtr   bufferbool_rbccloseflag_rbcbranchidxmaskr  r   r   r   r*  r   r#  )	r   rG   r1   	rbcrevidxreponode	cachenode	branchidxr   truncates	            r    rH   zrevbranchcache.branchinfo  s    J(	+%	 '>>'',,, t}	K 777##C((( >>#&&||4*DM22I 
  
	9 Y.// 	+**I##(""{9-u44   
##J    JM:<?@   !;.Hhii("4#3X>>D $$$s   /C> >=D>=D>c                 `   | j         j        }|                    |          \  }}|| j        v r| j        |         }n8t	          | j                  }| j                            |           || j        |<   |                    |          }|r
|t          z  }| 	                    |||           ||fS )z7Retrieve branch info from changelog and update _rbcrevs)
rt   r1   rH   r/  r   r  r   rD   r6  _setcachedata)r   rG   r1   rT   r   r;  r9  s          r    r!  zrevbranchcache._branchinfo  s    J(	'',,5"""*1-IIDK((IKq!!!$-Dq!>>#&& 	'&I3)444%xr"   c                 b   |j         \  }}|| j        v r| j        |         }n8t          | j                  }| j                            |           || j        |<   |r
|t
          z  }|                     || j        j        	                    |          |           dt          |           v r| ` dS dS )z%add new data information to the cacherH   N)rH   r/  r   r  r   r6  r>  rt   r1   rD   vars)r   rG   changelogrevisionr   r   r;  s         r    setdatazrevbranchcache.setdata   s    )4T'''*62IIDK((IKv&&&)2Dv& 	'&I3
 4 9 9# > >	JJJ 4::%% &%r"   c                    |t           k    rdS |t          z  }|t          z   }t          | j                  }||k     r0| j                            dt          t          |          z             t          t          | j        |||           t          | j
        |          | _
        | j                                        }|r|                    d| j                   dS dS )z:Writes the node's branch data to the in-memory cache data.Nr  s   write-revbranchcache)r   r"  r   r  r:   rL   
_rbcmininc	pack_intor3  r   r#  rt   r   addfinalizerM   )r   rG   rD   r;  r8  requiredsizerbccurr   s           r    r>  zrevbranchcache._setcachedata  s    '>>F+%	 ;.T]##L   M  Z)F)F!FGGG*dmYiHHHt/55Z**,, 	@NN2DJ?????	@ 	@r"   Nc                    | j         }d}d}	 | j        t          | j                  k     r-|                    d          }d}|                     |           | j        t          z  }|t          | j                  k    r0d}||                    d          }| 	                    ||           ne# t          t          t          j        t          j        f$ r;}|j                            d|t#          j        |          fz             Y d}~nd}~ww xY w||                                 dS dS # ||                                 w w xY w)z!Save branch cache if it is dirty.Nr"   F)waits    namess+   couldn't write revision branch cache%s: %s
)rt   r$  r   r  wlock_writenamesr#  r"  r  
_writerevsr   r   r   r   	LockErrorr   r   r   r   release)r   r   r'   rK  stepr0   r   s          r    rM   zrevbranchcache.write+  sh   z	 "S%5%555


..   &&& ${2EDM****= JJEJ22Ee,,,%+u? 	 	 	GMM?06678       	   ! u  !s0   B!B/ .D. /'D1DD. DD. .Ec                    | j         dk    r|j                            t          d          }|                                | j        k    r|                    d           nD|                                 |j        	                    dt          z             d| _         d| _
        | j         dk    rA|j                            t          d           |j                            t          d          }|                    d                    d | j        | j         d	         D                                  |                                | _        |                                 t          | j                  | _         d	S )
z,write the new branch names to revbranchcacher      abr  s   %s changed - rewriting it
T)ignoremissings   wbc              3   >   K   | ]}t          j        |          V  d S r   )r   r   )r,   rT   s     r    r/   z-revbranchcache._writenames.<locals>.<genexpr>X  sA         "1%%     r"   N)r$  r   openr   tellr  rM   r   r   r   r#  
unlinkpathr  r   r  r   )r   r'   r   s      r    rL  zrevbranchcache._writenamesH  sO   !##""9e44Avvxx4---			<yHIII&'##$ !##M$$XT$BBB""9e44A	JJ  T%8%:%:;    	
 	
 	
 VVXX				!$+..r"   c                 |   t          t          |j                  t          | j                  t          z            }|j                            t          d          5 }|                                |k    r||j        	                    dt          |fz             |
                    |           |                                |k    rd}|
                    |           |                                 |t          z  }|                    | j        ||                    ddd           n# 1 swxY w Y   || _        dS )z$write the new revs to revbranchcacherR  s   truncating cache/%s to %d
r   N)r   r   r1   r  r"  r   rU  rV  r   r   seekr<  rM   r#  )r   r'   r0   r;   r   ends         r    rM  zrevbranchcache._writerevsa  sH   3t~&&DM(:(:k(IJJ]%00 	.Avvxx5  2h5FF   u6688u$$EFF5MMM

$CGGDM%),---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.  s   CD**D.1D.)Tr   )rc   rd   re   rf   r!   r*  r   propertycacher/  rH   r!  rB  r>  rM   rL  rM  rg   r"   r    r   r   z  s         ,!/ !/ !/ !/H9 9 9 
9 9 9-% -% -%^        ,@ @ @*       :/ / /2         r"   r   )/structrD   r   r   r    r   r   r	   r
   r   r   utilsr   r   TYPE_CHECKINGtypingr   r   r   r   r   r   r   r   r   r   anyr6   calcsizerE  r2  r   rk   rn   r4   r  _rbcversionr   r  r3  r"  rD  r1  r7  r6  r   rg   r"   r    <module>rd     s            
                      
  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 3	
     &?	 \" \" \" \" \" \" \" \"~< < <
  v v v v v v v vr        ;&	$
hz""+
 v  v  v  v  v  v  v  v  v  v r"   