
    6h                       S SK Jr  SSKJrJrJrJr  SSKJr  S r	 " S S5      r
 " S S	\
5      r " S
 S\
5      rS r " S S\
5      r " S S\
5      r " S S\5      r " S S\5      rSS jr " S S\
5      r " S S\5      rg)    )annotations   )encodingerrorpycompatutil)
stringutilc                r    [         R                  " [        U 5      R                  5      R	                  S5      $ )N   _)r   sysbytestype__name__lstrip)os    4/usr/lib/python3/dist-packages/mercurial/smartset.py	_typenamer      s(    T!W--.55d;;    c                      \ rS rSrS r\rS rS rSrSr	S r
S rS rS	 rS
 rS rS rS rS rSS jrS rS rS rSS jrS rS rSrg)abstractsmartset   c                    [        5       e)z!True if the smartset is not emptyNotImplementedErrorselfs    r   __nonzero__abstractsmartset.__nonzero__       !##r   c                    [        5       e)zprovide fast membership testingr   )r   revs     r   __contains__abstractsmartset.__contains__   r   r   c                    [        5       e)z:iterate the set in the order it is supposed to be iteratedr   r   s    r   __iter__abstractsmartset.__iter__"   r   r   Nc                    [        5       e)z/True if the set will iterate in ascending orderr   r   s    r   isascendingabstractsmartset.isascending.   r   r   c                    [        5       e)z0True if the set will iterate in descending orderr   r   s    r   isdescendingabstractsmartset.isdescending2   r   r   c                    [        5       e)z3True if the set will iterate in topographical orderr   r   s    r   istopoabstractsmartset.istopo6   r   r   c                   ^ U R                   c  [        U 5      mO"U R                  5        H  m  O   [        S5      eU4S jU l        T$ )z%return the minimum element in the set   arg is an empty sequencec                    > T $ N vs   r   <lambda>&abstractsmartset.min.<locals>.<lambda>C       1r   )fastascmin
ValueErrorr   r5   s    @r   r:   abstractsmartset.min:   sC    <<D	A\\^ $ !!<==r   c                   ^ U R                   c  [        U 5      $ U R                  5        H  m  O   [        S5      eU4S jU l        T$ )z%return the maximum element in the setr0   c                    > T $ r2   r3   r4   s   r   r6   &abstractsmartset.max.<locals>.<lambda>O   r8   r   )fastdescmaxr;   r<   s    @r   rB   abstractsmartset.maxF   sD    == t9]]_ % !!<==r   c                    [        5       e)zareturn the first element in the set (user iteration perspective)

Return None if the set is emptyr   r   s    r   firstabstractsmartset.firstR        "##r   c                    [        5       e)z`return the last element in the set (user iteration perspective)

Return None if the set is emptyr   r   s    r   lastabstractsmartset.lastX   rG   r   c                    [        5       e)zcreturn the length of the smartsets

This can be expensive on smartset that could be lazy otherwise.r   r   s    r   __len__abstractsmartset.__len__^   rG   r   c                    [        5       e)z$reverse the expected iteration orderr   r   s    r   reverseabstractsmartset.reversed   r   r   c                    [        5       e)z:get the set to iterate in an ascending or descending orderr   r   rO   s     r   sortabstractsmartset.sorth   r   r   c                f    [        U[        5      (       a  U $ U R                  UR                  USS9$ )zsReturns 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__abstractsmartset.__and__l   s1     e[))K{{5--U{KKr   c                    [        X5      $ )zlReturns a new object with the union of the two collections.

This is part of the mandatory API for smartset.)addsetr\   s     r   __add__abstractsmartset.__add__t   s     d""r   c                J   ^ UR                   mU R                  U4S jSU4SS9$ )zsReturns a new object with the substraction of the two collections.

This is part of the mandatory API for smartset.c                   > T" U 5      (       + $ r2   r3   )rcs    r   r6   *abstractsmartset.__sub__.<locals>.<lambda>   s    !A$hr   s   <not %r>FrV   )r!   r[   )r   r]   rg   s     @r   __sub__abstractsmartset.__sub__z   s2     {{+u)=U  
 	
r   c                v    U(       a'  [        US5      (       a  [        R                  " U5      n[        XU5      $ )a  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.__code__)hasattrr   	cachefuncfilteredset)r   	conditionrW   rX   s       r   r[   abstractsmartset.filter   s.     WY
33y1I4H55r   c                h    US:  d  US:  a  [         R                  " S5      eU R                  X5      $ )zAReturn new smartset that contains selected elements from this setr   s   negative index not allowed)r   ProgrammingError_slice)r   startstops      r   sliceabstractsmartset.slice   s0    19q(()FGG{{5''r   c                    / n[        U 5      n[        U5       H  n[        US 5      nUb  M    O   [        X!-
  5       H%  n[        US 5      nUc    OUR                  U5        M'     [	        USXU 4S9$ )Ns   slice=%d:%d %r)datarepr)iterrangenextappendbaseset)r   ru   rv   ysitxys          r   rt   abstractsmartset._slice   s{     $ZuARAy  t|$ARAyIIaL	 %
 r%6T$JKKr   )rB   r:   FNT)r   
__module____qualname____firstlineno__r   __bool__r!   r$   r9   rA   r'   r*   r-   r:   rB   rE   rI   rL   rO   rS   r^   rb   ri   r[   rw   rt   __static_attributes__r3   r   r   r   r      sv    $ H$$ GH$$$

$$$$$L#
6(Lr   r   c                  L  ^  \ rS rSrSrSS jr\R                  S 5       r\R                  S 5       r	\R                  S 5       r
S rS rS	 r\R                  S
 5       rS r\rSS jrS rS rS rS rS rS rS rU 4S jrS rS rS r\R<                  S 5       rSr U =r!$ )r      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
c                    SU l         X0l        [        U[        5      (       a  Xl        SU l         O&[        U[
        5      (       d  [        U5      nXl        X l        g)z
datarepr: a tuple of (format, obj, ...), a function or an object that
          provides a printable representation of the given data.
NT)
_ascending_istoporY   set_setlist_list	_datarepr)r   datarz   r-   s       r   __init__baseset.__init__   sI    
 dC  I"DOdD))DzJ!r   c                ,    [        U R                  5      $ r2   )r   r   r   s    r   r   baseset._set   s    4::r   c                D    U R                   S S  nUR                  5         U$ r2   )r   rS   )r   asclists     r   _asclistbaseset._asclist   s    **Q-r   c                P    SU R                   ;   d   e[        U R                  5      $ )Nr   )__dict__r   r   r   s    r   r   baseset._list   s$     &&&DIIr   c                    U R                   c  [        U R                  5      $ U R                   (       a  [        U R                  5      $ [	        U R                  5      $ r2   )r   r{   r   r   reversedr   s    r   r$   baseset.__iter__  s@    ??"

##__&&DMM**r   c                ,    [        U R                  5      $ r2   )r{   r   r   s    r   r9   baseset.fastasc  s    DMM""r   c                ,    [        U R                  5      $ r2   )r   r   r   s    r   rA   baseset.fastdesc  s    &&r   c                .    U R                   R                  $ r2   )r   r!   r   s    r   r!   baseset.__contains__  s    yy%%%r   c                *    [        [        U 5      5      $ r2   )boollenr   s    r   r   baseset.__nonzero__  s    CIr   c                <    [        U5      (       + U l        SU l        g NF)r   r   r   rR   s     r   rS   baseset.sort  s    "7m+r   c                    U R                   c  U R                  R                  5         OU R                   (       + U l         SU l        g r   )r   r   rO   r   r   s    r   rO   baseset.reverse   s1    ??"JJ "&//1DOr   c                v    SU R                   ;   a  [        U R                  5      $ [        U R                  5      $ )Nr   )r   r   r   r   r   s    r   rL   baseset.__len__'  s*    dmm#tzz?"tyy>!r   c                d    [        U 5      S::  a  gU R                  SL=(       a    U R                  $ )zqReturns True if the collection is ascending order, False if not.

This is part of the mandatory API for smartset.r   TNr   r   r   s    r   r'   baseset.isascending-  s*     t9>d*>t>r   c                n    [        U 5      S::  a  gU R                  SL=(       a    U R                  (       + $ )zrReturns 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*   baseset.isdescending5  s-     t9>d*B4??/BBr   c                :    [        U 5      S::  a  gU R                  $ )zdIs the collection is in topographical order or not.

This is part of the mandatory API for smartset.r   T)r   r   r   s    r   r-   baseset.istopo=  s     t9>||r   c                    U (       aK  U R                   c  U R                  S   $ U R                   (       a  U R                  S   $ U R                  S   $ g )Nr   r   r   r   r   s    r   rE   baseset.firstE  sE    &zz!}$}}Q''}}R((r   c                    U (       aK  U R                   c  U R                  S   $ U R                   (       a  U R                  S   $ U R                  S   $ g )Nr   r   r   r   s    r   rI   baseset.lastO  sE    &zz"~%}}R((}}Q''r   c                P  > [        U5      [        L ax  SUR                  ;   ah  SU R                  ;   aX  U R                  bK  [        [	        U R
                  U5      " UR
                  5      U R                  S9nU R                  Ul        U$ [	        [        5       U5      " U5      nU$ )Nr   )r   r-   )r   r   r   r   getattrr   r   super)r   r]   ops	__class__s       r   
_fastsetopbaseset._fastsetopY  s     K7"%..($--'+TYY+EJJ7A  ??AL  $U+Ar   c                &    U R                  US5      $ )Nr^   r   r\   s     r   r^   baseset.__and__i      ui00r   c                &    U R                  US5      $ )Nri   r   r\   s     r   ri   baseset.__sub__l  r   r   c                F   U R                   c   [        U R                  X U R                  S9$ U R                  nU R                   (       d/  [        [        U5      U-
  S5      [        [        U5      U-
  S5      p![        X1U U R                  S9nU R                   Ul         U$ )N)r-   r   )r   r   r   r   r   rB   r   )r   ru   rv   r   r   s        r   rt   baseset._sliceo  s    ??"4::e1$,,GG}}c$i$.2CD	E8I14M4Dt$T\\:r   c                   SSSS.U R                      n[        R                  " U R                  5      nU(       d;  U R                  nU R                   b  U R
                  n[        R                  " U5      nS[        U 5      X4-  $ )Nr      -   +NFTs	   <%s%s %s>)	r   r	   	buildreprr   r   r   r   bytereprr   )r   dr   ls       r   __repr__baseset.__repr__{  sp    t40A  0

A *MM!!!$Ay555r   )r   r   r   r   r   )r3   NFr   )"r   r   r   r   __doc__r   r   propertycacher   r   r   r$   r9   rA   r!   r   r   rS   rO   rL   r'   r*   r-   rE   rI   r   r^   ri   rt   r   	strmethodr   r   __classcell__r   s   @r   r   r      s    9v"$ 
  
 
 
 
+#' 
& & H"?C 11
 6 6r   r   c                      \ rS rSrSrS S4S jrS rS rS r\	S	 5       r
\	S
 5       rS r\rS rSS jrS rS rS rS rS rS r\R.                  S 5       rSrg)ro   i  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                    gr   r3   )r   s    r   r6   filteredset.<lambda>  s    4r   Nc                (    Xl         X l        X0l        g)z
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   subsetrp   rW   s       r   r   filteredset.__init__  s     #!r   c                N    XR                   ;   =(       a    U R                  U5      $ r2   )r   r   r   r   s     r   r!   filteredset.__contains__  s    LL 7T__Q%77r   c                8    U R                  U R                  5      $ r2   )_iterfilterr   r   s    r   r$   filteredset.__iter__  s    --r   c              #  \   #    U R                   nU H  nU" U5      (       d  M  Uv   M     g 7fr2   )r   )r   r   condr   s       r   r   filteredset._iterfilter  s&     AAww s   ,	,c                H   ^ ^ T R                   R                  mTc  g UU 4S j$ )Nc                 0   > TR                  T " 5       5      $ r2   r   r   r   s   r   r6   %filteredset.fastasc.<locals>.<lambda>      t''-r   )r   r9   r   r   s   `@r   r9   filteredset.fastasc  s     \\!!:--r   c                H   ^ ^ T R                   R                  mTc  g UU 4S j$ )Nc                 0   > TR                  T " 5       5      $ r2   r   r   s   r   r6   &filteredset.fastdesc.<locals>.<lambda>  r   r   )r   rA   r   s   `@r   rA   filteredset.fastdesc  s     \\"":--r   c                   S nU R                  5       (       a  U R                  OS U R                  5       (       a  U R                  OS U R                  U R                  /nU H
  nUc  M  Un  O   Ub  U" 5       nOU nU H  n  g   gNTF)r'   r9   r*   rA   )r   fast
candidates	candidater   rf   s         r   r   filteredset.__nonzero__  s     ,,..DLLD!..00DMMdLLMM	

 $I$  $
 BBA r   c                <    [        S U  5       5      n[        U5      $ )Nc              3  $   #    U  H  ov   M     g 7fr2   r3   ).0rf   s     r   	<genexpr>&filteredset.__len__.<locals>.<genexpr>  s     $t!Ats   )r   r   )r   r   s     r   rL   filteredset.__len__  s    
 $t$$1vr   c                6    U R                   R                  US9  g )NrO   )r   rS   rR   s     r   rS   filteredset.sort  s    '*r   c                8    U R                   R                  5         g r2   )r   rO   r   s    r   rO   filteredset.reverse  s    r   c                6    U R                   R                  5       $ r2   )r   r'   r   s    r   r'   filteredset.isascending  s    ||''))r   c                6    U R                   R                  5       $ r2   )r   r*   r   s    r   r*   filteredset.isdescending  s    ||((**r   c                6    U R                   R                  5       $ r2   )r   r-   r   s    r   r-   filteredset.istopo  s    ||""$$r   c                    U  H  nUs  $    g r2   r3   r   s     r   rE   filteredset.first      AH r   c                    S nU R                  5       (       a  U R                  nO!U R                  5       (       a  U R                  nUb  U" 5        H  nUs  $    g S nU  H  nM     U$ r2   )r'   rA   r*   r9   r   r   r   s      r   rI   filteredset.last  sg    B  B>T A Hr   c                    [         R                  " U R                  5      /n[        R                  " U R
                  5      nU(       a  UR                  U5        S[        U 5      SR                  U5      4-  $ )Ns   <%s %s>s   , )	r   r   r   r	   r   r   r~   r   join)r   xsr   s      r   r   filteredset.__repr__  sW    -.  0IIaLYt_ejjn===r   )r   r   r   r   )r   r   r   r   r   r   r!   r$   r   propertyr9   rA   r   r   rL   rS   rO   r'   r*   r-   rE   rI   r   r   r   r   r3   r   r   ro   ro     s    
 *8$ 	"8. . . . ., H+*+%
  > >r   ro   c              #    #    [         nU (       a  [        nSnSn  Uc  [        U5      nUc  [        U5      nU" XE5      nUv   XF:X  a  SnXV:X  a  SnM8  ! [         a!    UnUb  Uv   UnOUb  Uv   U Sh  vN     gf = f7f)zproduce an ordered iteration from two iterators with the same order

The ascending is used to indicated the iteration direction.
N)rB   r:   r}   StopIteration)	ascendingiter1iter2choiceval1val2nr   s           r   _iterorderedr+    s     
 FDD|E{|E{t"AGyy   	JBJ	s.   B9A "A?6A97A?<B>A??Bc                      \ rS rSrSrSS jrS rS r\r\	R                  S 5       rS rS	 r\S
 5       r\S 5       rS rSS jrS rS rS rS rS rS r\R4                  S 5       rSrg)ra   i&  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                R    Xl         X l        S U l        X0l        S U l        S U l        g r2   )_r1_r2_iterr   _genlistr   )r   revs1revs2r$  s       r   r   addset.__init__n  s&    
#r   c                ,    [        U R                  5      $ r2   )r   r   r   s    r   rL   addset.__len__v  s    4::r   c                d    [        U R                  5      =(       d    [        U R                  5      $ r2   )r   r.  r/  r   s    r   r   addset.__nonzero__y  s    DHH~/dhh/r   c                n    U R                   (       d  [        [        U 5      5      U l         U R                   $ r2   )r1  r   r{   r   s    r   r   addset._list~  s#    }}#DJ/DM}}r   c                \  ^  T R                   c3  T R                  (       a  [        T R                  5      $ U 4S jnU" 5       $ T R                  5         T R                   (       a  SnOSn[	        T U5      nUb  U" 5       $ [	        T R
                  U5      nUc-  [        [        T R
                  T R                   (       + S95      nOU" 5       n[	        T R                  U5      nUc-  [        [        T R                  T R                   (       + S95      nOU" 5       n[        T R                   XE5      $ )am  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.
c               3     >#    TR                    H  n U v   M	     TR                   R                  nTR                   H  n U" U 5      (       a  M  U v   M     g 7fr2   )r.  r!   r/  )rf   inr1r   s     r   arbitraryordergen*addset.__iter__.<locals>.arbitraryordergen  sD     AG "xx,,A77 "s   AA	Ar9   rA   r  )	r   r1  r{   _trysetasclistr   r.  sortedr/  r+  )r   r>  attrr   r%  r&  s   `     r   r$   addset.__iter__  s     ??"}}DMM**  %&&??DDT4 >4K $'=doo2EFGEGE$'=doo2EFGEGEDOOU::r   c                p    U R                   b)  U R                  c  [        U R                   5      U l        ggg)z9populate the _asclist attribute if possible and necessaryN)r1  r   rA  r   s    r   r@  addset._trysetasclist  s-    ==$)>"4==1DM *?$r   c                   ^^ U R                  5         U R                  b  U R                  R                  $ U R                  R                  mU R
                  R                  mS TT4;   a  g UU4S j$ )Nc                 2   > [        ST " 5       T" 5       5      $ r   r+  r%  r&  s   r   r6    addset.fastasc.<locals>.<lambda>  s    |D%'57;r   )r@  r   r$   r.  r9   r/  r   r%  r&  s    @@r   r9   addset.fastasc  s\    ==$==)))    E5>!;;r   c                   ^^ U R                  5         U R                  b  U R                  R                  $ U R                  R                  mU R
                  R                  mS TT4;   a  g UU4S j$ )Nc                 2   > [        ST " 5       T" 5       5      $ r   rH  rI  s   r   r6   !addset.fastdesc.<locals>.<lambda>  s    |E57EG<r   )r@  r   __reversed__r.  rA   r/  rK  s    @@r   rA   addset.fastdesc  s\    ==$==---!!!!E5>!<<r   c                H    XR                   ;   =(       d    XR                  ;   $ r2   )r.  r/  r   s     r   r!   addset.__contains__  s    HH}-XX-r   c                    U(       + U l         g)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r   rR   s     r   rS   addset.sort  s     &+r   c                D    U R                   S L=(       a    U R                   $ r2   rU  r   s    r   r'   addset.isascending  s    d*>t>r   c                N    U R                   S L=(       a    U R                   (       + $ r2   rU  r   s    r   r*   addset.isdescending  s    d*B4??/BBr   c                    gr   r3   r   s    r   r-   addset.istopo       r   c                    U R                   c  U R                  R                  5         g U R                   (       + U l         g r2   )r   r   rO   r   s    r   rO   addset.reverse  s*    ??"JJ "&//1DOr   c                    U  H  nUs  $    g r2   r3   r   s     r   rE   addset.first  r  r   c                f    U R                  5         U R                  5       nU R                  5         U$ r2   )rO   rE   )r   vals     r   rI   addset.last  s$    jjl
r   c                r    SSSS.U R                      nS[        U 5      XR                  U R                  4-  $ )Nr   r   r   r   s   <%s%s %r, %r>)r   r   r.  r/  r   r   s     r   r   addset.__repr__  s5    t40A9T?Axx"JJJr   )r   r   r1  r0  r.  r/  r2   r   )r   r   r   r   r   r   rL   r   r   r   r   r   r$   r@  r!  r9   rA   r!   rS   r'   r*   r-   rO   rE   rI   r   r   r   r   r3   r   r   ra   ra   &  s    EN0 H	 
/;b2
 < < = =.&?C2
 K Kr   ra   c                     ^  \ rS rSrSrSU 4S jjrSS jrS r\rS r	S r
S rS	 rS
 rSS jrS rS rS rS rS rS r\R,                  S 5       rSrU =r$ )generatorseti  a  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
c                V   > Uc  U nOU(       a  [         nO[        n[        TU ]  U5      $ r2   )_generatorsetasc_generatorsetdescr   __new__)clsgeniterasctypr   s       r   rm  generatorset.__new__  s)    ?C"C#Cws##r   c                V    Xl         SU l        0 U l        / U l        SU l        SU l        g)z=
gen: a generator producing the values for the generatorset.
NFT)_genr   _cacher1  	_finishedr   )r   ro  rp  s      r   r   generatorset.__init__  s,     	r   c                V    U R                   (       a  gU R                  5        H  n  g   gr  )r1  _consumegenr   rf   s     r   r   generatorset.__nonzero__!  s'     ==!!#A $r   c                    XR                   ;   a  U R                   U   $ U R                  5        H
  nX!:X  d  M
    g   SU R                   U'   gr  ru  ry  r   r   r   s      r   r!   generatorset.__contains__-  sI    ;;q>! !!#Av $ Ar   c                    U R                   (       a  U R                  nOU R                  nUb  U" 5       $ U R                  5        H  nM     [	        U 5      $ r2   )r   r9   rA   ry  r{   r  s      r   r$   generatorset.__iter__9  sI    ??BB>4K!!#A $ Dzr   c                   ^^^^ U R                   (       a  [        U R                  5      $ U R                  mU R                  5       m[        [
        smmUUUU4S jnU" 5       $ )Nc               3  ~   >#    Sn  U T" T5      :  a  TU    v   O T" T5      v   U S-  n M&  ! [          a     g f = f7fNr   r   )r#  )i_len_nextgenlistnextgens    r   ro  #generatorset._iterator.<locals>.genT  sV     AtG}$!!*$#Gn, Q  ) s   =
- =
:=:=)rv  r{   r1  ry  r   r}   )r   ro  r  r  r  r  s     @@@@r   	_iteratorgeneratorset._iteratorF  sP    >>&& --""$4e
	 
	 ur   c              #  V  #    U R                   nU R                  R                  nU R                   H  nSX'   U" U5        Uv   M     U R                  (       dO  SU l        U R                  S S  nUR                  5         X@l        UR                  U l        UR                  U l
        g g 7fr   )ru  r1  r~   rt  rv  rS   r   r$   r9   rP  rA   )r   rX   r  itemascs        r   ry  generatorset._consumegenb  s     --&&IIDEKDMJ  ~~!DN--"CHHJM<<DL,,DM s   B'B)c                Z    U R                  5        H  nM     [        U R                  5      $ r2   )ry  r   r1  r   s     r   rL   generatorset.__len__q  s'    !!#A $4==!!r   c                    U(       + U l         g r2   rU  rR   s     r   rS   generatorset.sortv      %+r   c                0    U R                   (       + U l         g r2   rU  r   s    r   rO   generatorset.reversey      "oo-r   c                    U R                   $ r2   rU  r   s    r   r'   generatorset.isascending|      r   c                $    U R                   (       + $ r2   rU  r   s    r   r*   generatorset.isdescending      ??""r   c                    gr   r3   r   s    r   r-   generatorset.istopo  r]  r   c                    U R                   (       a  U R                  nOU R                  nUc'  U R                  5        H  nM     U R	                  5       $ [        U" 5       S 5      $ r2   )r   r9   rA   ry  rE   r}   r  s      r   rE   generatorset.first  sQ    ??BB:%%' (::<BD$r   c                    U R                   (       a  U R                  nOU R                  nUc'  U R                  5        H  nM     U R	                  5       $ [        U" 5       S 5      $ r2   )r   rA   r9   ry  rI   r}   r  s      r   rI   generatorset.last  sQ    ??BB:%%' (99;BD$r   c                F    SSS.U R                      nS[        U 5      U4-  $ )Nr   r   FTs   <%s%s>)r   r   rf  s     r   r   generatorset.__repr__  s)    %doo6IdOQ///r   )r   r   ru  rv  rt  r1  r9   rA   r2   r   )r   r   r   r   r   rm  r   r   r   r!   r$   r  ry  rL   rS   rO   r'   r*   r-   rE   rI   r   r   r   r   r   r   s   @r   ri  ri    st    $	 H
8-"
&.#
 
  0 0r   ri  c                  6    \ rS rSrSr\R                  rS rSr	g)rk  i  z@Special case of generatorset optimized for ascending generators.c                    XR                   ;   a  U R                   U   $ U R                  5        H  nX!:X  a    gX!:  d  M    O   SU R                   U'   gr  r}  r~  s      r   r!   _generatorsetasc.__contains__  Q    ;;q>! !!#Avu	 $ Ar   r3   N)
r   r   r   r   r   ri  r  r9   r!   r   r3   r   r   rk  rk    s    J$$Gr   rk  c                  6    \ rS rSrSr\R                  rS rSr	g)rl  i  zASpecial case of generatorset optimized for descending generators.c                    XR                   ;   a  U R                   U   $ U R                  5        H  nX!:X  a    gX!:  d  M    O   SU R                   U'   gr  r}  r~  s      r   r!   _generatorsetdesc.__contains__  r  r   r3   N)
r   r   r   r   r   ri  r  rA   r!   r   r3   r   r   rl  rl    s    K%%Hr   rl  Nc                    Uc  [        U 5      nX:*  nU(       d	  US-   US-   p![        XX0R                  R                  5      $ )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`.
r   )r   _spanset	changelogfilteredrevs)reporu   endr$  s       r   spansetr    sB     {$iI1WeaisE	>>+F+FGGr   c                     ^  \ rS rSrSrS rSS jrS rS rS r	S r
S	 rS
 rS rS r\rS rS rS rS rS rU 4S jr\R.                  S 5       rSrU =r$ )r  i  aC  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                4    Xl         X l        X0l        X@l        g r2   )_start_endr   _hiddenrevs)r   ru   r  r$  
hiddenrevss        r   r   _spanset.__init__  s    	#%r   c                    U(       + U l         g r2   rU  rR   s     r   rS   _spanset.sort  r  r   c                0    U R                   (       + U l         g r2   rU  r   s    r   rO   _spanset.reverse  r  r   c                    gr   r3   r   s    r   r-   _spanset.istopo  r]  r   c              #  L   #    U R                   nU H  nX2;  d  M
  Uv   M     g 7fr2   )r  )r   	iterranger   rf   s       r   r   _spanset._iterfilter  s$     Az s   $	$c                d    U R                   (       a  U R                  5       $ U R                  5       $ r2   r   r9   rA   r   s    r   r$   _spanset.__iter__  s!    ??<<>!==?"r   c                    [        U R                  U R                  5      nU R                  (       a  U R	                  U5      $ [        U5      $ r2   )r|   r  r  r  r   r{   r   r  s     r   r9   _spanset.fastasc  s:    $++tyy1	##I..Ir   c                    [        U R                  S-
  U R                  S-
  S5      nU R                  (       a  U R	                  U5      $ [        U5      $ )Nr   r   )r|   r  r  r  r   r{   r  s     r   rA   _spanset.fastdesc  sD    $))a-q"=	##I..Ir   c                    U R                   nU R                  Us=:*  =(       a    U R                  :  Os  =(       a    U=(       a    X;   (       + $ r2   )r  r  r  )r   r    hiddens      r   r!   _spanset.__contains__  s>    !!s..TYY. 
$s}5
 	
r   c                    U  H  n  g   gr  r3   rz  s     r   r   _spanset.__nonzero__  s    A r   c                V   U R                   (       d"  [        U R                  U R                  -
  5      $ SnU R                  nU R                  nU R                    H(  nX4s=:  a  U::  d  O  X$s=::  a  U:  d  M  O  M#  US-  nM*     [        U R                  U R                  -
  5      U-
  $ r  )r  absr  r  )r   countru   r  r    s        r   rL   _spanset.__len__   s    tyy4;;.//EKKE))C''&&E,>3,>,>QJE ( tyy4;;./%77r   c                    U R                   $ r2   rU  r   s    r   r'   _spanset.isascending,  r  r   c                $    U R                   (       + $ r2   rU  r   s    r   r*   _spanset.isdescending/  r  r   c                x    U R                   (       a  U R                  nOU R                  nU" 5        H  nUs  $    g r2   r  r  s      r   rE   _spanset.first2  s/    ??BBAH r   c                x    U R                   (       a  U R                  nOU R                  nU" 5        H  nUs  $    g r2   )r   rA   r9   r  s      r   rI   _spanset.last;  s/    ??BBAH r   c                  > U R                   (       a  [        TU ]	  X5      $ U R                  (       aG  [	        U R
                  U-   U R                  5      n[	        U R
                  U-   U R                  5      nOF[        U R                  U-
  U R
                  5      n[        U R                  U-
  U R
                  5      n[        X4U R                  U R                   5      $ r2   )	r  r   rt   r   r:   r  r  rB   r  )r   ru   rv   r   r   r   s        r   rt   _spanset._sliceD  s    7>%..??DKK%'3ADKK$&		2ADII$dkk2ADII%t{{3Adoot/?/?@@r   c                p    SSS.U R                      nS[        U 5      XR                  U R                  4-  $ )Nr   r   r  s   <%s%s %d:%d>)r   r   r  r  rf  s     r   r   _spanset.__repr__P  s3    %doo6)D/1kk499!MMMr   )r   r  r  r  r   )r   r   r   r   r   r   rS   rO   r-   r   r$   r9   rA   r!   r   r   rL   r'   r*   rE   rI   rt   r   r   r   r   r   r   s   @r   r  r    s|    &&.#

 H
8#
A N Nr   r  c                  2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )rZ   iV  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                d   > [         TU ]  S[        U5      SUR                  R                  5        g )Nr   T)r   r   r   r  r  )r   r  r   s     r   r   fullreposet.__init__]  s$    CItT^^-H-HIr   c                    [        US5      (       d  [        U5      nU R                  (       a  XR                  -
  nUR                  U R	                  5       S9  U$ )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.
r'   r  )rm   r   r  rS   r*   r\   s     r   r^   fullreposet.__and__`  sO     um,, ENE,,,E

4,,.
/r   r3   )	r   r   r   r   r   r   r^   r   r   r   s   @r   rZ   rZ   V  s    J r   rZ   )r   N)
__future__r    r   r   r   r   utilsr	   r   r   r   ro   r+  ra   ri  rk  rl  r  r  rZ   r3   r   r   <module>r     s    #  <ML ML``6 `6Fu>" u>p!HUK UKpe0# e0P| ( (H uN uNp( r   