ó
žçƒQc           @   s{   d  d l  m Z m Z m Z m Z d  d l Z d  d l Z d  d l Z d „  Z d „  Z	 d „  Z
 d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   bint   hext   nullidt   nullrevNc         C   s)   d } |  j  r% d | |  j  f } n  | S(   s7   name of a branchcache file for a given repo or repoviews   cache/branchheadss   %s-%s(   t
   filtername(   t   repot   filename(    (    s7   /sys/lib/python2.7/site-packages/mercurial/branchmap.pyt	   _filename   s    	c         C   s  y8 |  j  t |  ƒ ƒ } | j ƒ  j d ƒ } | j ƒ  Wn t t f k
 rR d  SXy4| j d ƒ j d d ƒ } | d  \ } } t	 | ƒ t
 | ƒ } } d  } t | ƒ d k rÅ t	 | d ƒ } n  t d | d | d | ƒ } | j |  ƒ sþ t d ƒ ‚ n  x… | D]} } | sqn  | j d d	 ƒ \ }	 }
 t j |
 j ƒ  ƒ }
 |	 |  k rct d
 |	 ƒ ‚ n  | j |
 g  ƒ j t	 |	 ƒ ƒ qWWn‚ t k
 r‚  no t k
 r} |  j j rd } |  j d  k	 rá| d |  j 7} n  | d 7} |  j j | | ƒ n  d  } n X| S(   Ns   
i    t    i   t   tipnodet   tiprevt   filteredhashs   tip differsi   s   node %s does not exists   invalid branchheads caches    (%s)s   : %s
(   t   openerR   t   readt   splitt   closet   IOErrort   OSErrort   Nonet   popR    t   intt   lent   branchcachet   validfort
   ValueErrort   encodingt   tolocalt   stript
   setdefaultt   appendt   KeyboardInterruptt	   Exceptiont   uit	   debugflagR   t   warn(   R   t   ft   linest   cachekeyt   lastt   lrevR   t   partialt   lt   nodet   labelt   instt   msg(    (    s7   /sys/lib/python2.7/site-packages/mercurial/branchmap.pyR      sH    	'

c            sT  |  j  } |  j } |  j j | ƒ ‰  g  } ˆ  d  k sF ˆ  j |  ƒ rß t |  ƒ ‰  ˆ  d  k rß t j j | ƒ } | d  k rˆ t	 ƒ  ‰  qÜ |  j
 | ƒ } | j ƒ  j ƒ  ‰  | j  j | j } | j ‡  f d †  | Dƒ ƒ qß n  | j | j d ˆ  j d ƒ ƒ | r%ˆ  j |  | ƒ ˆ  j |  ƒ n  ˆ  j |  ƒ s@t | ƒ ‚ ˆ  |  j |  j <d  S(   Nc         3   s$   |  ] } | ˆ  j  k r | Vq d  S(   N(   R
   (   t   .0t   r(   R(   (    s7   /sys/lib/python2.7/site-packages/mercurial/branchmap.pys	   <genexpr>M   s    t   starti   (   t	   changelogR   t   _branchcachest   getR   R   R   t   repoviewt   subsettableR   t   filteredt	   branchmapt   copyt   filteredrevst   extendt   revsR
   t   updatet   writet   AssertionError(   R   t   clR   R;   t
   subsetnamet   subsett	   extrarevs(    (   R(   s7   /sys/lib/python2.7/site-packages/mercurial/branchmap.pyt   updatecache=   s(    		# R   c           B   sP   e  Z d  Z d e e d d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(	   s1   A dict like object that hold branches heads cachec         C   s5   t  t |  ƒ j | ƒ | |  _ | |  _ | |  _ d  S(   N(   t   superR   t   __init__R	   R
   R   (   t   selft   entriesR	   R
   R   (    (    s7   /sys/lib/python2.7/site-packages/mercurial/branchmap.pyRE   X   s    		c            s‚   | j  } | j s d Sd } t ‡  f d †  | j Dƒ ƒ } | r~ t j ƒ  } x | D] } | j d | ƒ qT W| j ƒ  } n  | S(   sB  build hash of revision filtered in the current cache

        Tracking tipnode and tiprev is not enough to ensure validity of the
        cache as they do not help to distinct cache that ignored various
        revision bellow tiprev.

        To detect such difference, we build a cache of all ignored revisions.
        c         3   s$   |  ] } | ˆ  j  k r | Vq d  S(   N(   R
   (   R.   R/   (   RF   (    s7   /sys/lib/python2.7/site-packages/mercurial/branchmap.pys	   <genexpr>l   s    s   %s;N(   R1   R9   R   t   sortedt   utilt   sha1R<   t   digest(   RF   R   R?   t   keyR;   t   st   rev(    (   RF   s7   /sys/lib/python2.7/site-packages/mercurial/branchmap.pyt   _hashfiltered_   s    			c         C   sQ   y8 |  j  | j j |  j ƒ k o6 |  j |  j | ƒ k SWn t k
 rL t SXd S(   s¹   Is the cache content valid regarding a repo

        - False when cached tipnode is unknown or if we detect a strip.
        - True when cache is up to date or a subset of current repo.N(   R	   R1   R*   R
   R   RO   t
   IndexErrort   False(   RF   R   (    (    s7   /sys/lib/python2.7/site-packages/mercurial/branchmap.pyR   t   s
    c         C   s   t  |  |  j |  j |  j ƒ S(   s-   return an deep copy of the branchcache object(   R   R	   R
   R   (   RF   (    (    s7   /sys/lib/python2.7/site-packages/mercurial/branchmap.pyR8      s    c         C   s
  yæ | j  t | ƒ d d t ƒ} t |  j ƒ t |  j ƒ g } |  j d  k	 rg | j	 t |  j ƒ ƒ n  | j
 d j | ƒ d ƒ xW t |  j ƒ  ƒ D]C \ } } x4 | D], } | j
 d t | ƒ t j | ƒ f ƒ q§ Wq” W| j ƒ  Wn t t t j f k
 rn Xd  S(   Nt   wt
   atomictempR   s   
s   %s %s
(   R   R   t   TrueR   R	   t   strR
   R   R   R   R=   t   joinRH   t	   iteritemsR   t	   fromlocalR   R   R   RI   t   Abort(   RF   R   R#   R%   R+   t   nodesR*   (    (    s7   /sys/lib/python2.7/site-packages/mercurial/branchmap.pyR=   ƒ   s    .c            s#  | j  ‰  i  } ˆ  j } x6 | D]. } | j | | ƒ g  ƒ j ˆ  j | ƒ ƒ q Wx¿| j ƒ  D]±\ } } |  j | g  ƒ } g  | D]$ }	 ˆ  j |	 ƒ rƒ ˆ  j |	 ƒ ^ qƒ }
 g  | D]$ }	 ˆ  j |	 ƒ r´ ˆ  j |	 ƒ ^ q´ } |
 où t | ƒ t	 |
 ƒ k } t
 t |
 ƒ j | ƒ ƒ }
 | r,t
 | ƒ } n t |
 ƒ } xu | r¯| j ƒ  } | |
 k r_q;n  t ˆ  j | g |
 d ƒ ƒ } | r;g  |
 D] } | | k r‹| ^ q‹}
 q;q;Wg  |
 D] } ˆ  j | ƒ ^ q·|  | <t	 |
 ƒ } | |  j k r^ ˆ  j | ƒ |  _ | |  _ q^ q^ Wg  } x] |  j ƒ  D]O } g  |  | D] } ˆ  j | ƒ r7| ^ q7} | s&| j | ƒ |  | =q&q&W|  j | ƒ s˜|  j | k rt |  _ t |  _ x` |  j ƒ  D]O } t	 ‡  f d †  | Dƒ ƒ } | |  j k r·ˆ  j | ƒ |  _ | |  _ q·q·Wn  |  j | ƒ |  _ d S(   sÙ   Given a branchhead cache, self, that may have extra nodes or be
        missing heads, and a generator of nodes that are at least a superset of
        heads missing, this function updates self to be correct.
        i    c         3   s   |  ] } ˆ  j  | ƒ Vq d  S(   N(   RN   (   R.   R*   (   R?   (    s7   /sys/lib/python2.7/site-packages/mercurial/branchmap.pys	   <genexpr>Û   s    N(   R1   t   branchR   R   R*   RW   t   hasnodeRN   t   mint   maxRH   t   sett   uniont   listR   t	   ancestorsR
   R	   t   keysR:   R   R   R   t   valuesRO   R   (   RF   R   t   revgent   newbranchest	   getbranchR/   R[   t   newnodest   bheadsR*   t	   bheadrevst   newheadrevst   ctxisnewt   iterrevst   latestRb   t   bRN   R
   t   droppednodest   headRZ   t   heads(    (   R?   s7   /sys/lib/python2.7/site-packages/mercurial/branchmap.pyR<   ’   sZ    		,$$	,&		(    N(   t   __name__t
   __module__t   __doc__R   R   R   RE   RO   R   R8   R=   R<   (    (    (    s7   /sys/lib/python2.7/site-packages/mercurial/branchmap.pyR   U   s   					(   R*   R    R   R   R   R   RI   R4   R   R   RC   t   dictR   (    (    (    s7   /sys/lib/python2.7/site-packages/mercurial/branchmap.pyt   <module>   s   "		*	