
    	^c=                     D   d dl mZ d dlmZmZm Z mZ d dlmZ d Z G d d          Z	 G d de	          Z
 G d	 d
e	          Zd Z G d de	          Z G d de	          Z G d de          Z G d de          ZddZ G d de	          Z G d de          ZdS )   )getattr)encodingerrorpycompatutil)
stringutilc                 t    t          j        t          |           j                                      d          S )N   _)r   sysbytestype__name__lstrip)os    4/usr/lib/python3/dist-packages/mercurial/smartset.py	_typenamer      s*    T!WW-..55d;;;    c                       e Zd Zd Z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d ZddZd Zd Zd ZddZd Zd ZdS )abstractsmartsetc                     t                      )z!True if the smartset is not emptyNotImplementedErrorselfs    r   __nonzero__zabstractsmartset.__nonzero__       !###r   c                     t                      )zprovide fast membership testingr   )r   revs     r   __contains__zabstractsmartset.__contains__   r   r   c                     t                      )z:iterate the set in the order it is supposed to be iteratedr   r   s    r   __iter__zabstractsmartset.__iter__"   r   r   Nc                     t                      )z/True if the set will iterate in ascending orderr   r   s    r   isascendingzabstractsmartset.isascending.   r   r   c                     t                      )z0True if the set will iterate in descending orderr   r   s    r   isdescendingzabstractsmartset.isdescending2   r   r   c                     t                      )z3True if the set will iterate in topographical orderr   r   s    r   istopozabstractsmartset.istopo6   r   r   c                     | j         t          |           n'|                                  D ] nt          d          fd| _        S )z%return the minimum element in the setN   arg is an empty sequencec                       S N vs   r   <lambda>z&abstractsmartset.min.<locals>.<lambda>C       1 r   )fastascmin
ValueErrorr   r-   s    @r   r1   zabstractsmartset.min:   sU    <D		AA\\^^ > > !<===999r   c                     | j         t          |           S |                                  D ] nt          d          fd| _        S )z%return the maximum element in the setNr(   c                       S r*   r+   r,   s   r   r.   z&abstractsmartset.max.<locals>.<lambda>O   r/   r   )fastdescmaxr2   r3   s    @r   r7   zabstractsmartset.maxF   sT    = t99]]__ > > !<===999r   c                     t                      )zireturn the first element in the set (user iteration perspective)

        Return None if the set is emptyr   r   s    r   firstzabstractsmartset.firstR        "###r   c                     t                      )zhreturn the last element in the set (user iteration perspective)

        Return None if the set is emptyr   r   s    r   lastzabstractsmartset.lastX   r:   r   c                     t                      )zkreturn the length of the smartsets

        This can be expensive on smartset that could be lazy otherwise.r   r   s    r   __len__zabstractsmartset.__len__^   r:   r   c                     t                      )z$reverse the expected iteration orderr   r   s    r   reversezabstractsmartset.reversed   r   r   Fc                     t                      )z:get the set to iterate in an ascending or descending orderr   r   r@   s     r   sortzabstractsmartset.sorth   r   r   c                 j    t          |t                    r| S |                     |j        |d          S )z{Returns a new object with the intersection of the two collections.

        This is part of the mandatory API for smartset.Fcondreprcache)
isinstancefullreposetfilterr   r   others     r   __and__zabstractsmartset.__and__l   s6     e[)) 	K{{5-U{KKKr   c                 "    t          | |          S )ztReturns a new object with the union of the two collections.

        This is part of the mandatory API for smartset.)addsetrK   s     r   __add__zabstractsmartset.__add__t   s     dE"""r   c                 L    |j         |                     fdd|fd          S )z{Returns a new object with the substraction of the two collections.

        This is part of the mandatory API for smartset.c                      |            S r*   r+   )rcs    r   r.   z*abstractsmartset.__sub__.<locals>.<lambda>   s    !!A$$h r   s   <not %r>FrE   )r   rJ   )r   rL   rT   s     @r   __sub__zabstractsmartset.__sub__z   s=     {{+u)=U  
 
 	
r   Tc                 z    |r)t          j        |d          rt          j        |          }t          | ||          S )a1  Returns this smartset filtered by condition as a new smartset.

        `condition` is a callable which takes a revision number and returns a
        boolean. Optional `condrepr` provides a printable representation of
        the given `condition`.

        This is part of the mandatory API for smartset.s   __code__)r   safehasattr	cachefuncfilteredset)r   	conditionrF   rG   s       r   rJ   zabstractsmartset.filter   sA      	2T%i== 	2y11I4H555r   c                 n    |dk     s|dk     rt          j        d          |                     ||          S )zAReturn new smartset that contains selected elements from this set    s   negative index not allowed)r   ProgrammingError_slice)r   startstops      r   slicezabstractsmartset.slice   s9    199q()FGGG{{5$'''r   c                    g }t          |           }t          |          D ]}t          |d           }| nt          ||z
            D ]+}t          |d           }| n|                    |           ,t	          |d||| f          S )Ns   slice=%d:%d %r)datarepr)iterrangenextappendbaseset)r   r_   r`   ysitxys          r   r^   zabstractsmartset._slice   s     $ZZu 	 	ARAy te|$$ 	 	ARAyIIaLLLLr%6tT$JKKKKr   FNT)r   
__module____qualname__r   __bool__r   r    r0   r6   r"   r$   r&   r1   r7   r9   r<   r>   r@   rC   rM   rP   rU   rJ   ra   r^   r+   r   r   r   r      sV       $ $ $ H$ $ $$ $ $ GH$ $ $$ $ $$ $ $
 
 

 
 
$ $ $$ $ $$ $ $$ $ $$ $ $ $L L L# # #
 
 
6 6 6 6( ( (L L L L Lr   r   c                   *    e Zd ZdZddZej        d             Zej        d             Zej        d             Z	d	 Z
d
 Zd Zej        d             Zd ZeZddZd Zd Zd Zd Zd Zd Zd Z fdZd Zd Zd Zej        d             Z xZS )rh   a  Basic data structure that represents a revset and contains the basic
    operation that it should be able to perform.

    Every method in this class should be implemented by any smartset class.

    This class could be constructed by an (unordered) set, or an (ordered)
    list-like object. If a set is provided, it'll be sorted lazily.

    >>> x = [4, 0, 7, 6]
    >>> y = [5, 6, 7, 3]

    Construct by a set:
    >>> xs = baseset(set(x))
    >>> ys = baseset(set(y))
    >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]]
    [[0, 4, 6, 7, 3, 5], [6, 7], [0, 4]]
    >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]]
    ['addset', 'baseset', 'baseset']

    Construct by a list-like:
    >>> xs = baseset(x)
    >>> ys = baseset(i for i in y)
    >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]]
    [[4, 0, 7, 6, 5, 3], [7, 6], [4, 0]]
    >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]]
    ['addset', 'filteredset', 'filteredset']

    Populate "_set" fields in the lists so set optimization may be used:
    >>> [1 in xs, 3 in ys]
    [False, True]

    Without sort(), results won't be changed:
    >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]]
    [[4, 0, 7, 6, 5, 3], [7, 6], [4, 0]]
    >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]]
    ['addset', 'filteredset', 'filteredset']

    With sort(), set optimization could be used:
    >>> xs.sort(reverse=True)
    >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]]
    [[7, 6, 4, 0, 5, 3], [7, 6], [4, 0]]
    >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]]
    ['addset', 'baseset', 'baseset']

    >>> ys.sort()
    >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]]
    [[7, 6, 4, 0, 3, 5], [7, 6], [4, 0]]
    >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]]
    ['addset', 'baseset', 'baseset']

    istopo is preserved across set operations
    >>> xs = baseset(set(x), istopo=True)
    >>> rs = xs & ys
    >>> type(rs).__name__
    'baseset'
    >>> rs._istopo
    True
    r+   NFc                     d| _         || _        t          |t                    r|| _        d| _         n+t          |t
                    st          |          }|| _        || _        dS )z
        datarepr: a tuple of (format, obj, ...), a function or an object that
                  provides a printable representation of the given data.
        NT)
_ascending_istoporH   set_setlist_list	_datarepr)r   datarc   r&   s       r   __init__zbaseset.__init__   sc    
 dC   	DI"DOOdD)) "DzzDJ!r   c                 *    t          | j                  S r*   )rv   ry   r   s    r   rw   zbaseset._set   s    4:r   c                 L    | j         d d          }|                                 |S r*   )ry   rC   )r   asclists     r   _asclistzbaseset._asclist   s#    *QQQ-r   c                 @    d| j         v sJ t          | j                  S )Nrw   )__dict__rx   rw   r   s    r   ry   zbaseset._list   s%     &&&&DIr   c                     | j         t          | j                  S | j         rt          | j                  S t	          | j                  S r*   )rt   rd   ry   r   reversedr   s    r   r    zbaseset.__iter__  sD    ?"
###_ 	+&&&DM***r   c                 *    t          | j                  S r*   )rd   r   r   s    r   r0   zbaseset.fastasc  s    DM"""r   c                 *    t          | j                  S r*   )r   r   r   s    r   r6   zbaseset.fastdesc  s    &&&r   c                     | j         j        S r*   )rw   r   r   s    r   r   zbaseset.__contains__  s    y%%r   c                 :    t          t          |                     S r*   )boollenr   s    r   r   zbaseset.__nonzero__  s    CIIr   c                 >    t          |           | _        d| _        d S NF)r   rt   ru   rB   s     r   rC   zbaseset.sort  s    "7mm+r   c                 p    | j         | j                                         n| j          | _         d| _        d S r   )rt   ry   r@   ru   r   s    r   r@   zbaseset.reverse   s8    ?"J    "&/1DOr   c                 d    d| j         v rt          | j                  S t          | j                  S )Nry   )r   r   ry   rw   r   s    r   r>   zbaseset.__len__'  s+    dm##tz??"ty>>!r   c                 L    t          |           dk    rdS | j        duo| j        S )zyReturns True if the collection is ascending order, False if not.

        This is part of the mandatory API for smartset.r   TNr   rt   r   s    r   r"   zbaseset.isascending-  s,     t99>>4d*>t>r   c                 N    t          |           dk    rdS | j        duo| j         S )zzReturns True if the collection is descending order, False if not.

        This is part of the mandatory API for smartset.r   TNr   r   s    r   r$   zbaseset.isdescending5  s/     t99>>4d*B4?/BBr   c                 :    t          |           dk    rdS | j        S )zlIs the collection is in topographical order or not.

        This is part of the mandatory API for smartset.r   T)r   ru   r   s    r   r&   zbaseset.istopo=  s      t99>>4|r   c                 t    | r5| j         | j        d         S | j         r| j        d         S | j        d         S d S )Nr\   rt   ry   r   r   s    r   r9   zbaseset.firstE  sG     	)&z!}$ )}Q''}R((tr   c                 t    | r5| j         | j        d         S | j         r| j        d         S | j        d         S d S )Nr   r\   r   r   s    r   r<   zbaseset.lastO  sG     	(&z"~% (}R((}Q''tr   c                 F   t          |          t          u r]d|j        v rTd| j        v rK| j        Dt           t	          | j        |          |j                  | j                  }| j        |_        n, t	          t          t          |           |          |          }|S )Nrw   )r{   r&   )r   rh   r   rt   r   rw   ru   super)r   rL   ops	__class__s       r   
_fastsetopzbaseset._fastsetopY  s     KK7""%.(($-''++WTY++EJ77  A  ?ALL1gt,,b11%88Ar   c                 .    |                      |d          S )Ns   __and__r   rK   s     r   rM   zbaseset.__and__i      uj111r   c                 .    |                      |d          S )Ns   __sub__r   rK   s     r   rU   zbaseset.__sub__l  r   r   c                 J   | j         #t          | j        ||         | j                  S | j        }| j         s@t          t          |          |z
  d          t          t          |          |z
  d          }}t          |||         | j                  }| j         |_         |S )N)r&   r\   )rt   rh   ry   ru   r   r7   r   )r   r_   r`   r{   r   s        r   r^   zbaseset._sliceo  s    ?"4:eDj1$,GGGG} 	Nc$ii$.22CD		E8I14M4M4EDt$T\:::r   c                     dddd| j                  }t          j        | j                  }|s)| j        }| j         | j        }t          j        |          }dt          |           ||fz  S )Nr      -   +NFTs	   <%s%s %s>)	rt   r   	buildreprrz   ry   r   r   bytereprr   )r   dr   ls       r   __repr__zbaseset.__repr__{  sr    t400A 00 	%
A *M!!$$Ay1555r   )r+   NFrm   ) r   ro   rp   __doc__r|   r   propertycacherw   r   ry   r    r0   r6   r   r   rq   rC   r@   r>   r"   r$   r&   r9   r<   r   rM   rU   r^   r   	strmethodr   __classcell__r   s   @r   rh   rh      s       9 9v" " " "$ 
   
  
 
  
+ + +# # #' ' ' 
& & &   H     " " "? ? ?C C C           2 2 22 2 2
 
 
 6 6 6 6 6 6 6r   rh   c                       e Zd ZdZd dfdZd Zd Zd Zed             Z	ed	             Z
d
 ZeZd ZddZd Zd Zd Zd Zd Zd Zej        d             ZdS )rY   zDuck type for baseset class which iterates lazily over the revisions in
    the subset and contains a function which tests for membership in the
    revset
    c                     dS rn   r+   )rk   s    r   r.   zfilteredset.<lambda>  s    4 r   Nc                 0    || _         || _        || _        dS )a!  
        condition: a function that decide whether a revision in the subset
                   belongs to the revset or not.
        condrepr: a tuple of (format, obj, ...), a function or an object that
                  provides a printable representation of the given condition.
        N)_subset
_condition	_condrepr)r   subsetrZ   rF   s       r   r|   zfilteredset.__init__  s     #!r   c                 >    || j         v o|                     |          S r*   )r   r   r   rk   s     r   r   zfilteredset.__contains__  s     DL 7T__Q%7%77r   c                 6    |                      | j                  S r*   )_iterfilterr   r   s    r   r    zfilteredset.__iter__  s    ---r   c              #   @   K   | j         }|D ]} ||          r|V  d S r*   )r   )r   rj   condrk   s       r   r   zfilteredset._iterfilter  s@       	 	AtAww 	 	r   c                 2      j         j        d S  fdS )Nc                  >                                                 S r*   r   rj   r   s   r   r.   z%filteredset.fastasc.<locals>.<lambda>      t''-- r   )r   r0   r   rj   s   `@r   r0   zfilteredset.fastasc  s*    \!:4------r   c                 2      j         j        d S  fdS )Nc                  >                                                 S r*   r   r   s   r   r.   z&filteredset.fastdesc.<locals>.<lambda>  r   r   )r   r6   r   s   `@r   r6   zfilteredset.fastdesc  s*    \":4------r   c                     d }|                                  r| j        nd |                                 r| j        nd | j        | j        g}|D ]}||} n	| |            }n| }|D ]} dS dS NTF)r"   r0   r$   r6   )r   fast
candidates	candidaterj   rS   s         r   r   zfilteredset.__nonzero__  s     ,,..8DLLD!..00:DMMdLM	

 $ 	 	I$  % BBB 	 	A44ur   c                 R    t          d | D                       }t          |          S )Nc              3      K   | ]}|V  d S r*   r+   ).0rS   s     r   	<genexpr>z&filteredset.__len__.<locals>.<genexpr>  s"      $$!A$$$$$$r   )rh   r   )r   r   s     r   r>   zfilteredset.__len__  s+    
 $$t$$$$$1vvr   Fc                 <    | j                             |           d S )Nr@   )r   rC   rB   s     r   rC   zfilteredset.sort  s!    '*****r   c                 8    | j                                          d S r*   )r   r@   r   s    r   r@   zfilteredset.reverse  s    r   c                 4    | j                                         S r*   )r   r"   r   s    r   r"   zfilteredset.isascending  s    |'')))r   c                 4    | j                                         S r*   )r   r$   r   s    r   r$   zfilteredset.isdescending  s    |((***r   c                 4    | j                                         S r*   )r   r&   r   s    r   r&   zfilteredset.istopo  s    |""$$$r   c                     | D ]}|c S d S r*   r+   r   s     r   r9   zfilteredset.first       	 	AHHHtr   c                     d }|                                  r| j        }n|                                 r| j        }| |            D ]}|c S d S d }| D ]}|S r*   )r"   r6   r$   r0   r   rj   rk   s      r   r<   zfilteredset.last  s     	BB   	B>RTT  4A  Hr   c                     t          j        | j                  g}t          j        | j                  }|r|                    |           dt          |           d                    |          fz  S )Ns   <%s %s>s   , )	r   r   r   r   r   r   rg   r   join)r   xsr   s      r   r   zfilteredset.__repr__  s`    --. 00 	IIaLLLYt__ejjnn===r   rm   )r   ro   rp   r   r|   r   r    r   propertyr0   r6   r   rq   r>   rC   r@   r"   r$   r&   r9   r<   r   r   r   r+   r   r   rY   rY     sP        
 *8$ 	" 	" 	" 	"8 8 8. . .   . . X. . . X.  , H  + + + +  * * *+ + +% % %  
    > > > > >r   rY   c              #     K   t           }| rt          }d}d}	 	 |t          |          }|t          |          } |||          }|V  ||k    rd}||k    rd}C# t          $ r |}||V  |}n||V  |D ]}|V  Y dS w xY w)zproduce an ordered iteration from two iterators with the same order

    The ascending is used to indicated the iteration direction.
    N)r7   r1   rf   StopIteration)		ascendingiter1iter2choiceval1val2nrj   vals	            r   _iterorderedr     s      
 F DD
	|E{{|E{{tT""AGGGqyyqyy
	  
 
 
JJJBBJJJ 	 	CIIII	 	 	
s   AA $BBc                       e Zd ZdZddZd Zd ZeZej	        d             Z
d Zd Zed	             Zed
             Zd ZddZd Zd Zd Zd Zd Zd Zej        d             ZdS )rO   a	  Represent the addition of two sets

    Wrapper structure for lazily adding two structures without losing much
    performance on the __contains__ method

    If the ascending attribute is set, that means the two structures are
    ordered in either an ascending or descending way. Therefore, we can add
    them maintaining the order by iterating over both at the same time

    >>> xs = baseset([0, 3, 2])
    >>> ys = baseset([5, 2, 4])

    >>> rs = addset(xs, ys)
    >>> bool(rs), 0 in rs, 1 in rs, 5 in rs, rs.first(), rs.last()
    (True, True, False, True, 0, 4)
    >>> rs = addset(xs, baseset([]))
    >>> bool(rs), 0 in rs, 1 in rs, rs.first(), rs.last()
    (True, True, False, 0, 2)
    >>> rs = addset(baseset([]), baseset([]))
    >>> bool(rs), 0 in rs, rs.first(), rs.last()
    (False, False, None, None)

    iterate unsorted:
    >>> rs = addset(xs, ys)
    >>> # (use generator because pypy could call len())
    >>> list(x for x in rs)  # without _genlist
    [0, 3, 2, 5, 4]
    >>> assert not rs._genlist
    >>> len(rs)
    5
    >>> [x for x in rs]  # with _genlist
    [0, 3, 2, 5, 4]
    >>> assert rs._genlist

    iterate ascending:
    >>> rs = addset(xs, ys, ascending=True)
    >>> # (use generator because pypy could call len())
    >>> list(x for x in rs), list(x for x in rs.fastasc())  # without _asclist
    ([0, 2, 3, 4, 5], [0, 2, 3, 4, 5])
    >>> assert not rs._asclist
    >>> len(rs)
    5
    >>> [x for x in rs], [x for x in rs.fastasc()]
    ([0, 2, 3, 4, 5], [0, 2, 3, 4, 5])
    >>> assert rs._asclist

    iterate descending:
    >>> rs = addset(xs, ys, ascending=False)
    >>> # (use generator because pypy could call len())
    >>> list(x for x in rs), list(x for x in rs.fastdesc())  # without _asclist
    ([5, 4, 3, 2, 0], [5, 4, 3, 2, 0])
    >>> assert not rs._asclist
    >>> len(rs)
    5
    >>> [x for x in rs], [x for x in rs.fastdesc()]
    ([5, 4, 3, 2, 0], [5, 4, 3, 2, 0])
    >>> assert rs._asclist

    iterate ascending without fastasc:
    >>> rs = addset(xs, generatorset(ys), ascending=True)
    >>> assert rs.fastasc is None
    >>> [x for x in rs]
    [0, 2, 3, 4, 5]

    iterate descending without fastdesc:
    >>> rs = addset(generatorset(xs), ys, ascending=False)
    >>> assert rs.fastdesc is None
    >>> [x for x in rs]
    [5, 4, 3, 2, 0]
    Nc                 Z    || _         || _        d | _        || _        d | _        d | _        d S r*   )_r1_r2_iterrt   _genlistr   )r   revs1revs2r   s       r   r|   zaddset.__init__o  s0    
#r   c                 *    t          | j                  S r*   )r   ry   r   s    r   r>   zaddset.__len__w  s    4:r   c                 R    t          | j                  pt          | j                  S r*   )r   r   r   r   s    r   r   zaddset.__nonzero__z  s    DH~~/dh/r   c                 `    | j         s!t          t          |                     | _         | j         S r*   )r   rh   rd   r   s    r   ry   zaddset._list  s)    } 	0#DJJ//DM}r   c                 6     j         * j        rt           j                  S  fd} |            S                                    j         rd}nd}t	           |          }|
 |            S t	           j        |          }|*t          t           j         j                              }n
 |            }t	           j        |          }|*t          t           j         j                              }n
 |            }t           j         ||          S )a  Iterate over both collections without repeating elements

        If the ascending attribute is not set, iterate over the first one and
        then over the second one checking for membership on the first one so we
        dont yield any duplicates.

        If the ascending attribute is set, iterate over both collections at the
        same time, yielding only one value at a time in the given order.
        Nc               3   r   K   j         D ]} | V  j         j        }j        D ]}  ||           s| V  d S r*   )r   r   r   )rS   inr1r   s     r   arbitraryordergenz*addset.__iter__.<locals>.arbitraryordergen  sb        AGGGGx,    A477     r   s   fastascs   fastdescr   )	rt   r   rd   _trysetasclistr   r   sortedr   r   )r   r   attrrj   r   r   s   `     r   r    zaddset.__iter__  s6    ?"} +DM***          %$&&&? 	DDDT4  >244K $''=do2EFFFGGEEEGGE$''=do2EFFFGGEEEGGEDOUE:::r   c                 \    | j         "| j        t          | j                   | _        dS dS dS )z9populate the _asclist attribute if possible and necessaryN)r   r   r   r   s    r   r   zaddset._trysetasclist  s4    =$)>"4=11DMMM %$)>)>r   c                     |                                   | j        | j        j        S | j        j        | j        j        d fv rd S fdS )Nc                  F    t          d                                     S rn   r   r   r   s   r   r.   z addset.fastasc.<locals>.<lambda>  s    |D%%''5577;; r   )r   r   r    r   r0   r   r   r   r   s    @@r   r0   zaddset.fastasc  sc    =$=))  E5>!!4;;;;;;r   c                     |                                   | j        | j        j        S | j        j        | j        j        d fv rd S fdS )Nc                  F    t          d                                     S r   r   r   s   r   r.   z!addset.fastdesc.<locals>.<lambda>  s    |E5577EEGG<< r   )r   r   __reversed__r   r6   r   r   s    @@r   r6   zaddset.fastdesc  sc    =$=--!!E5>!!4<<<<<<r   c                 &    || j         v p|| j        v S r*   )r   r   r   s     r   r   zaddset.__contains__  s    DH}-TX-r   Fc                     | | _         dS )zSort the added set

        For this we use the cached list with all the generated values and if we
        know they are ascending or descending we can sort them in a smart way.
        Nrt   rB   s     r   rC   zaddset.sort  s     &+r   c                 "    | j         d uo| j         S r*   r  r   s    r   r"   zaddset.isascending  s    d*>t>r   c                 $    | j         d uo| j          S r*   r  r   s    r   r$   zaddset.isdescending  s    d*B4?/BBr   c                     dS r   r+   r   s    r   r&   zaddset.istopo  	     ur   c                 d    | j         | j                                         d S | j          | _         d S r*   )rt   ry   r@   r   s    r   r@   zaddset.reverse  s4    ?"J     "&/1DOOOr   c                     | D ]}|c S d S r*   r+   r   s     r   r9   zaddset.first  r   r   c                 ~    |                                   |                                 }|                                   |S r*   )r@   r9   )r   r   s     r   r<   zaddset.last  s.    jjll
r   c                 d    dddd| j                  }dt          |           || j        | j        fz  S )Nr   r   r   r   s   <%s%s %r, %r>)rt   r   r   r   r   r   s     r   r   zaddset.__repr__  s6    t400A9T??Atx"JJJr   r*   rm   )r   ro   rp   r   r|   r>   r   rq   r   r   ry   r    r   r   r0   r6   r   rC   r"   r$   r&   r@   r9   r<   r   r   r   r+   r   r   rO   rO   '  sp       E EN     0 0 0 H	  
/; /; /;b2 2 2
 < < X< = = X=. . .& & & &? ? ?C C C  2 2 2  
   K K K K Kr   rO   c                        e Zd ZdZd fd	ZddZd ZeZd Zd Z	d Z
d	 Zd
 ZddZd Zd Zd Zd Zd Zd Zej        d             Z xZS )generatorseta  Wrap a generator for lazy iteration

    Wrapper structure for generators that provides lazy membership and can
    be iterated more than once.
    When asked for membership it generates values until either it finds the
    requested one or has gone through all the elements in the generator

    >>> xs = generatorset([0, 1, 4], iterasc=True)
    >>> assert xs.last() == xs.last()
    >>> xs.last()  # cached
    4
    Nc                     || }n|rt           }nt          }t          t          |                               |          S r*   )_generatorsetasc_generatorsetdescr   r  __new__)clsgeniterasctypr   s       r   r  zgeneratorset.__new__  sA    ?CC 	$"CC#C\3''//444r   c                 Z    || _         d| _        i | _        g | _        d| _        d| _        dS )zM
        gen: a generator producing the values for the generatorset.
        NFT)_genr   _cacher   	_finishedrt   )r   r  r  s      r   r|   zgeneratorset.__init__  s2     	r   c                 J    | j         rdS |                                 D ]} dS dS r   )r   _consumegenr   rS   s     r   r   zgeneratorset.__nonzero__"  s:     = 	4!!## 	 	A44ur   c                     || j         v r| j         |         S |                                 D ]}||k    r dS d| j         |<   dS r   r  r  r   rk   r   s      r   r   zgeneratorset.__contains__.  s_    ;q>! !!## 	 	AAvvtt  Aur   c                     | j         r| j        }n| j        }|
 |            S |                                 D ]}t	          |           S r*   )rt   r0   r6   r  rd   r   s      r   r    zgeneratorset.__iter__:  sV    ? 	BBB>244K!!## 	 	ADzzr   c                     | j         rt          | j                  S | j        |                                 t          t
          cfd} |            S )Nc               3      K   d} 	 |            k     r|          V  n 	            V  n# t           $ r Y d S w xY w| dz  } @)Nr\   Tr   )r   )i_len_nextgenlistnextgens    r   r  z#generatorset._iterator.<locals>.genU  s      AttG}}$$!!*$$$$#eGnn,,,,(   Qs   0 
>>)r  rd   r   r  r   rf   )r   r  r&  r'  r(  r)  s     @@@@r   	_iteratorzgeneratorset._iteratorG  sz    > 	'&&& -""$$4e
	 
	 
	 
	 
	 
	 
	 
	 suur   c              #     K   | j         }| j        j        }| j        D ]}d||<    ||           |V  | j        sKd| _        | j        d d          }|                                 || _        |j        | _        |j	        | _
        d S d S rn   )r  r   rg   r  r  rC   r   r    r0   r  r6   )r   rG   r(  itemascs        r   r  zgeneratorset._consumegenc  s      -&I 	 	DE$KGDMMMJJJJ~ 	-!DN-"CHHJJJDM<DL,DMMM	- 	-r   c                 X    |                                  D ]}t          | j                  S r*   )r  r   r   r   s     r   r>   zgeneratorset.__len__r  s0    !!## 	 	A4=!!!r   Fc                     | | _         d S r*   r  rB   s     r   rC   zgeneratorset.sortw      %+r   c                      | j          | _         d S r*   r  r   s    r   r@   zgeneratorset.reversez      "o-r   c                     | j         S r*   r  r   s    r   r"   zgeneratorset.isascending}  
    r   c                     | j          S r*   r  r   s    r   r$   zgeneratorset.isdescending      ?""r   c                     dS r   r+   r   s    r   r&   zgeneratorset.istopo  r  r   c                     | j         r| j        }n| j        }|+|                                 D ]}|                                 S t           |            d           S r*   )rt   r0   r6   r  r9   rf   r   s      r   r9   zgeneratorset.first  sc    ? 	BBB:%%''  ::<<BBDD$r   c                     | j         r| j        }n| j        }|+|                                 D ]}|                                 S t           |            d           S r*   )rt   r6   r0   r  r<   rf   r   s      r   r<   zgeneratorset.last  sc    ? 	BBB:%%''  99;;BBDD$r   c                 J    ddd| j                  }dt          |           |fz  S )Nr   r   FTs   <%s%s>)rt   r   r  s     r   r   zgeneratorset.__repr__  s,    %%do6IdOOQ///r   r*   rm   )r   ro   rp   r   r  r|   r   rq   r   r    r*  r  r>   rC   r@   r"   r$   r&   r9   r<   r   r   r   r   r   s   @r   r  r    sI        5 5 5 5 5 5	 	 	 	   H
 
 
    8- - -" " "
& & & &. . .  # # #  
  
  
 
  
  
  0 0 0 0 0 0 0r   r  c                   &    e Zd ZdZej        Zd ZdS )r  z@Special case of generatorset optimized for ascending generators.c                     || j         v r| j         |         S |                                 D ]}||k    r dS ||k    r nd| j         |<   dS r   r   r!  s      r   r   z_generatorsetasc.__contains__  m    ;q>! !!## 	 	AAvvtt1uu  Aur   N)r   ro   rp   r   r  r*  r0   r   r+   r   r   r  r    s1        JJ$G    r   r  c                   &    e Zd ZdZej        Zd ZdS )r  zASpecial case of generatorset optimized for descending generators.c                     || j         v r| j         |         S |                                 D ]}||k    r dS ||k     r nd| j         |<   dS r   r   r!  s      r   r   z_generatorsetdesc.__contains__  r>  r   N)r   ro   rp   r   r  r*  r6   r   r+   r   r   r  r    s1        KK%H    r   r  r\   Nc                     |t          |           }||k    }|s
|dz   |dz   }}t          |||| j        j                  S )zCreate a spanset that represents a range of repository revisions

    start: first revision included the set (default to 0)
    end:   first revision excluded (last+1) (default to len(repo))

    Spanset will be descending if `end` < `start`.
    Nr   )r   _spanset	changelogfilteredrevs)repor_   endr   s       r   spansetrG    sO     {$iiI (1WeaisE3	4>+FGGGr   c                        e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd ZeZd Zd Zd Zd Zd Z fdZej        d             Z xZS )rB  a[  Duck type for baseset class which represents a range of revisions and
    can work lazily and without having all the range in memory

    Note that spanset(x, y) behave almost like range(x, y) except for two
    notable points:
    - when x < y it will be automatically descending,
    - revision filtered with this repoview will be skipped.

    c                 >    || _         || _        || _        || _        d S r*   )_start_endrt   _hiddenrevs)r   r_   rF  r   
hiddenrevss        r   r|   z_spanset.__init__  s%    	#%r   Fc                     | | _         d S r*   r  rB   s     r   rC   z_spanset.sort  r0  r   c                      | j          | _         d S r*   r  r   s    r   r@   z_spanset.reverse  r2  r   c                     dS r   r+   r   s    r   r&   z_spanset.istopo  r  r   c              #   2   K   | j         }|D ]
}||vr|V  d S r*   )rL  )r   	iterranger   rS   s       r   r   z_spanset._iterfilter  s:       	 	Azz	 	r   c                 `    | j         r|                                 S |                                 S r*   rt   r0   r6   r   s    r   r    z_spanset.__iter__  s(    ? 	#<<>>!==??"r   c                     t          | j        | j                  }| j        r|                     |          S t          |          S r*   )re   rJ  rK  rL  r   rd   r   rR  s     r   r0   z_spanset.fastasc  s@    $+ty11	 	/##I...Ir   c                     t          | j        dz
  | j        dz
  d          }| j        r|                     |          S t          |          S )Nr   r   )re   rK  rJ  rL  r   rd   rV  s     r   r6   z_spanset.fastdesc  sJ    $)a-q"==	 	/##I...Ir   c                 R    | j         }| j        |cxk    o
| j        k     nc o|o||v  S r*   )rL  rJ  rK  )r   r   hiddens      r   r   z_spanset.__contains__  sH    !s....TY.... 
$sf}5
 	
r   c                     | D ]} dS dS r   r+   r  s     r   r   z_spanset.__nonzero__  s     	 	A44ur   c                    | j         st          | j        | j        z
            S d}| j        }| j        }| j         D ]&}||cxk     r|k    sn ||cxk    r|k     rn !|dz  }'t          | j        | j        z
            |z
  S )Nr\   r   )rL  absrK  rJ  )r   countr_   rF  r   s        r   r>   z_spanset.__len__!  s     		8ty4;.///EKE)C'  #&&&&&&&&ES,>,>,>,>3,>,>,>,>,>QJEty4;.//%77r   c                     | j         S r*   r  r   s    r   r"   z_spanset.isascending-  r4  r   c                     | j          S r*   r  r   s    r   r$   z_spanset.isdescending0  r6  r   c                 R    | j         r| j        }n| j        } |            D ]}|c S d S r*   rT  r   s      r   r9   z_spanset.first3  s?    ? 	BBB 	 	AHHHtr   c                 R    | j         r| j        }n| j        } |            D ]}|c S d S r*   )rt   r6   r0   r   s      r   r<   z_spanset.last<  s?    ? 	BBB 	 	AHHHtr   c                    | j         r)t          t          |                               ||          S | j        r;t          | j        |z   | j                  }t          | j        |z   | j                  }n:t          | j        |z
  | j                  }t          | j        |z
  | j                  }t          ||| j        | j                   S r*   )	rL  r   rB  r^   rt   r1   rJ  rK  r7   )r   r_   r`   rk   rl   r   s        r   r^   z_spanset._sliceE  s     	=4((//t<<<? 	4DK%'33ADK$&	22AADI$dk22ADI%t{33A1dot/?@@@r   c                 b    ddd| j                  }dt          |           || j        | j        fz  S )Nr   r   r;  s   <%s%s %d:%d>)rt   r   rJ  rK  r  s     r   r   z_spanset.__repr__Q  s4    %%do6)D//1dk49!MMMr   rm   )r   ro   rp   r   r|   rC   r@   r&   r   r    r0   r6   r   r   rq   r>   r"   r$   r9   r<   r^   r   r   r   r   r   s   @r   rB  rB    sZ        & & && & & &. . .    # # #    
 
 
  
 H
8 
8 
8  # # #    
A 
A 
A 
A 
A N N N N N N Nr   rB  c                   (     e Zd ZdZ fdZd Z xZS )rI   za set containing all revisions in the repo

    This class exists to host special optimization and magic to handle virtual
    revisions such as "null".
    c                     t          t          |                               dt          |          d|j        j                   d S )Nr\   T)r   rI   r|   r   rC  rD  )r   rE  r   s     r   r|   zfullreposet.__init__^  sC    k4  ))s4yy$ ;	
 	
 	
 	
 	
r   c                     t          j        |d          st          || j        z
            }|                    |                                            |S )zAs self contains the whole repo, all of the other set should also be
        in self. Therefore `self & other = other`.

        This boldly assumes the other contains valid revs only.
        s   isascendingr   )r   rW   rh   rL  rC   r$   rK   s     r   rM   zfullreposet.__and__c  sU     ~66 	6 ED$4455E

4,,..
///r   )r   ro   rp   r   r|   rM   r   r   s   @r   rI   rI   W  sQ         
 
 
 
 

      r   rI   )r\   N)r   r    r   r   r   utilsr   r   r   rh   rY   r   rO   r  r  r  rG  rB  rI   r+   r   r   <module>ri     su                         < < <ML ML ML ML ML ML ML ML``6 `6 `6 `6 `6 `6 `6 `6Fu> u> u> u> u>" u> u> u>p" " "JUK UK UK UK UK UK UK UKpe0 e0 e0 e0 e0# e0 e0 e0P    |   (       (H H H H uN uN uN uN uN uN uN uNp    (     r   