
    6hG6                    (   S r SSKJr  SSKrSSKJr  SSKJr  SSK	J
r
JrJrJrJrJrJrJrJrJr  SSKJr  Sr0 r\R0                  " \5      r\R2                  " 5       r\R4                  " 5       r\" S	S
SS9  \" S	SSS9  \" S	SSS9   " S S\R6                  R8                  5      r " S S5      rS rS r S r!\" S	SS1S9S 5       r"\" SSS1S9S 5       r#\" SSS1S9S 5       r$S r%\" S 5      S! 5       r&\" S"5      S# 5       r'\" S$5      S% 5       r(g)&a?  showing remotebookmarks and remotebranches in UI (EXPERIMENTAL)

By default both remotebookmarks and remotebranches are turned on. Config knob to
control the individually are as follows.

Config options to tweak the default behaviour:

remotenames.bookmarks
  Boolean value to enable or disable showing of remotebookmarks (default: True)

remotenames.branches
  Boolean value to enable or disable showing of remotebranches (default: True)

remotenames.hoistedpeer
  Name of the peer whose remotebookmarks should be hoisted into the top-level
  namespace (default: 'default')
    )annotationsN)_)bin)
	bookmarkserror
extensionslogexchange
namespaces	registrar
revsetlangsmartsettemplateutilutil)
stringutils   ships-with-hg-core   remotenames	   bookmarksT)default   branches   hoistedpeers   defaultc                  ^    \ 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 r\rSrg)lazyremotenamedictM   a  
Read-only dict-like Class to lazily resolve remotename entries

We are doing that because remotenames startup was slow.
We lazily read the remotenames file once to figure out the potential entries
and store them in self.potentialentries. Then when asked to resolve an
entry, if it is not in self.potentialentries, then it isn't there, if it
is in self.potentialentries we resolve it and store the result in
self.cache. We cannot be lazy is when asked all the entries (keys).
c                F    0 U l         0 U l        Xl        X l        SU l        g )NF)cachepotentialentries_kind_repoloaded)selfkindrepos      3/usr/lib/python3/dist-packages/hgext/remotenames.py__init__lazyremotenamedict.__init__Y   s"    
 "

    c                    SU l         U R                  n[        R                  " XR                  5       H  u  p#nUS-   U-   nX#U4U R
                  U'   M!     g)z?Read the remotenames file, store entries matching selected kindT   /N)r   r   r	   readremotenamefiler   r   )r   r!   noderpathrnamenames         r"   _loadlazyremotenamedict._load`   sX    zz"-"@"@**#
D 4<%'D+/*=D!!$'	#
r%   c                "   XR                   ;  a  gU R                   U   u  p#nU R                  n[        U5      n UR                  R	                  U5        U R                  S:X  a  XV   R                  5       (       a  gU/$ ! [
         a     gf = f)z;Check that the node for potentialentry exists and return itNr   )r   r   r   	changelogrevLookupErrorr   closesbranch)r   potentialentryr)   remoter,   r!   binnodes          r"   _resolvedatalazyremotenamedict._resolvedataj   s    !6!66!22>Bdzzd)	NNw' ::$)C)C)E)Ey  		s   B 
BBc                    U R                   (       d  U R                  5         U R                  U5      nUb  U$ [        5       eN)r   r-   _fetchandcacheKeyErrorr   keyvals      r"   __getitem__lazyremotenamedict.__getitem__{   s4    {{JJL!!#&?J*r%   c                ,    [        U R                  5      $ r:   )iterr   r   s    r"   __iter__lazyremotenamedict.__iter__   s    D))**r%   c                ,    [        U R                  5      $ r:   )lenr   rD   s    r"   __len__lazyremotenamedict.__len__   s    4(())r%   c                    [         er:   NotImplementedError)r   kvs      r"   __setitem__lazyremotenamedict.__setitem__       !!r%   c                    [         er:   rL   )r   rN   s     r"   __delitem__lazyremotenamedict.__delitem__   rR   r%   c                    XR                   ;   a  U R                   U   $ U R                  U5      nUb  X R                   U'   U$ g r:   )r   r7   r=   s      r"   r;   !lazyremotenamedict._fetchandcache   sB    **::c?"$?!JJsOJr%   c                x    U R                   (       d  U R                  5         U R                  R                  5       $ )z&Get a list of bookmark or branch names)r   r-   r   keysrD   s    r"   rY   lazyremotenamedict.keys   s'    {{JJL$$))++r%   c              #     #    U R                   (       d  U R                  5         U R                  R                  5        H  u  pU[	        US   5      /4v   M     g7f)z Iterate over (name, node) tuplesr   N)r   r-   r   itemsr   )r   rN   vtups      r"   	iteritemslazyremotenamedict.iteritems   sG      {{JJL,,224GAs47|n%% 5s   AA)r   r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r#   r-   r7   r@   rE   rI   rP   rT   r;   rY   r^   r\   __static_attributes__ r%   r"   r   r   M   sE    	>"+*"",& Er%   r   c                  N    \ 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g)remotenames   a  
This class encapsulates all the remotenames state. It also contains
methods to access that state in convenient ways. Remotenames are lazy
loaded. Whenever client code needs to ensure the freshest copy of
remotenames, use the `clearnames` method to force an eventual load.
c                0    Xl         U R                  5         g r:   )r   
clearnames)r   r!   argss      r"   r#   remotenames.__init__   s    
r%   c                    [        SU R                  5      U l        [        SU R                  5      U l        U R	                  5         g)zClear all remote names stater   r   N)r   r   r   branches_invalidatecacherD   s    r"   rk   remotenames.clearnames   s2    +L$**E*;

Cr%   c                <    S U l         S U l        S U l        S U l        g r:   )_nodetobmarks_nodetobranch_hoisttonodes_nodetohoistsrD   s    r"   rp   remotenames._invalidatecache   s"    !!!!r%   c                    U R                   $ r:   )r   rD   s    r"   bmarktonodesremotenames.bmarktonodes   s    ~~r%   c                    U R                   (       d^  U R                  5       n0 U l         UR                  5        H3  u  p#U R                   R                  US   / 5      R	                  U5        M5     U R                   $ )Nr   )rs   ry   r\   
setdefaultappend)r   ry   r,   r)   s       r"   nodetobmarksremotenames.nodetobmarks   sg    !!,,.L!#D*002
""--d1gr:AA$G 3!!!r%   c                    U R                   $ r:   )ro   rD   s    r"   branchtonodesremotenames.branchtonodes   s    }}r%   c                   U R                   (       dd  U R                  5       n0 U l         UR                  5        H9  u  p#U H.  nU R                   R                  U/ 5      R	                  U5        M0     M;     U R                   $ r:   )rt   r   r\   r|   r}   )r   r   r,   nodesr)   s        r"   nodetobranchremotenames.nodetobranch   so    !! ..0M!#D,224!D&&11$;BB4H "  5 !!!r%   c                   U R                   (       di  U R                  5       n0 U l         US-  nUR                  5        H9  u  p4UR                  U5      (       d  M  U[	        U5      S  nX@R                   U'   M;     U R                   $ )Nr'   )ru   ry   r\   
startswithrH   r   hoistmarktonodesr,   r)   s        r"   hoisttonodesremotenames.hoisttonodes   sz    !!++-K!#DTME)//1
??5))E
-D/3&&t, 2 !!!r%   c                N   U R                   (       d  U R                  5       n0 U l         US-  nUR                  5        HY  u  p4UR                  U5      (       d  M  U[	        U5      S  nU R                   R                  US   / 5      R                  U5        M[     U R                   $ )Nr'   r   )rv   ry   r\   r   rH   r|   r}   r   s        r"   nodetohoistsremotenames.nodetohoists   s    !!++-K!#DTME)//1
??5))E
-D&&11$q'2>EEdK 2 !!!r%   )ru   rs   rt   rv   r   r   ro   N)r`   ra   rb   rc   rd   r#   rk   rp   ry   r~   r   r   r   r   re   rf   r%   r"   rh   rh      s4     """	"	"r%   rh   c                    SUR                   ;  a  g UR                   S   nUR                  U5       H)  nUR                  X&5      nU(       d  M  US   nUSS4XF'   M+     U " XX45      $ )N   remotebookmarksr       r%   )names	listnamesr   )	origuir!   fmbmarksnsr,   r   r)   s	            r"   wrapprintbookmarksr      sm    +	&	'BT"$QxdC( # "%%r%   c                D    [         R                  " [        S[        5        g )N_printbookmarks)r   wrapfunctionr   r   )r   s    r"   extsetupr     s    I'8:LMr%   c           
     L  ^ UR                   R                  SSSS5        UR                  5       (       d  g [        U5      Ul        [
        R                  nU R                  SS5      (       av  U" SSSSS	 S
 S S9nUR                  R                  U5        U R                  SS5      mT(       a3  U" SSSSU4S jU4S jU4S jS9nUR                  R                  U5        U R                  SS5      (       a+  U" SSSSS S S S9nUR                  R                  U5        g g )Ns   experimentalr   Ts   remotenames-extr   r      remotebookmarks   remote bookmark:  %s
c                R    U R                   R                  5       R                  5       $ r:   )_remotenamesry   rY   r!   s    r"   <lambda>reposetup.<locals>.<lambda>  s    4#4#4#A#A#C#H#H#Jr%   c                V    U R                   R                  5       R                  U/ 5      $ r:   )r   ry   getr!   r,   s     r"   r   r     #    t'8'8'E'E'G'K'Kb(r%   c                V    U R                   R                  5       R                  U/ 5      $ r:   )r   r~   r   r!   r)   s     r"   r   r     r   r%   )templatename	colornamelogfmtr   namemapnodemapr   s   hoistednamess   hoistednames   hoisted name:  %s
c                V   > U R                   R                  T5      R                  5       $ r:   )r   r   rY   )r!   r   s    r"   r   r   (  s%    t'8'8'E'E($&(r%   c                Z   > U R                   R                  T5      R                  U/ 5      $ r:   )r   r   r   )r!   r,   r   s     r"   r   r   +  )    4+<+<+I+I,#dB-, r%   c                Z   > U R                   R                  T5      R                  U/ 5      $ r:   )r   r   r   )r!   r)   r   s     r"   r   r   .  r   r%   r      remotebranches   remotebranchs   remote branch:  %s
c                R    U R                   R                  5       R                  5       $ r:   )r   r   rY   r   s    r"   r   r   :  s    4#4#4#B#B#D#I#I#Kr%   c                V    U R                   R                  5       R                  U/ 5      $ r:   )r   r   r   r   s     r"   r   r   ;  s#    t'8'8'F'F'H'L'Lb(r%   c                V    U R                   R                  5       R                  U/ 5      $ r:   )r   r   r   r   s     r"   r   r   >  r   r%   )r   	setconfiglocalrh   r   r
   	namespace
configboolr   addnamespaceconfig)r   r!   r   remotebookmarknshoistednamensremotebranchnsr   s         @r"   	reposetupr     s'   GGo~t=OP::<<#D)D			B	}}^\22+',J
 	

 01 		..9,(-  M JJ##M2	}}^[11*%*K
 	

/ 2r%      repo   ctx)requiresc                p   U R                  US5      nU R                  US5      n/ nSUR                  ;   a,  UR                  S   R                  X#R                  5       5      nSUR                  ;   a.  XBR                  S   R                  X#R                  5       5      -  n[        R                  " XSUSS9$ )z<List of strings. Remote names associated with the changeset.r   r   r   r   s
   remotenamer   pluralresourcer   r)   r   
compatlist)contextmappingr!   ctxrh   s        r"   remotenameskwr   E  s     GW-D


7F
+CKTZZ'jj!34::4LDJJ&zz"34::4LL""-^ r%   r   c                    U R                  US5      nU R                  US5      n/ nSUR                  ;   a,  UR                  S   R                  X#R                  5       5      n[        R                  " U USUSS9$ )z@List of strings. Remote bookmarks associated with the changeset.r   r   r   r   r   r   )r   r   r!   r   remotebmarkss        r"   remotebookmarkskwr   W  s{     GW-D


7F
+CLTZZ'zz"45;;D((*M""! r%   r   c                    U R                  US5      nU R                  US5      n/ nSUR                  ;   a,  UR                  S   R                  X#R                  5       5      n[        R                  " U USUSS9$ )z?List of strings. Remote branches associated with the changeset.r   r   r   r   r   r   )r   r   r!   r   remotebranchess        r"   remotebrancheskwr   j  s{     GW-D


7F
+CNDJJ&$56<<T88:N""  r%   c                  ^ [         R                  " USS[        S5      5      nU(       a;  [        R                  " [         R
                  " US   [        S5      5      5      u  pVnOS=pV[        R                  n[        5       nU R                  mU Hj  n	XR                  ;   d  M  U R                  U	   n
U
R                  U 5       H2  nU" U5      (       d  M  UR                  U
R                  X5      5        M4     Ml     US:X  a)  U(       d"  [        R                  " [        S5      U-  5      eU4S jU 5       nU[         R"                  " U5      -  $ )	z<utility function to return a set of revs based on the rtypesr      s   only one argument accepteds   argument must be a stringNs   literals   remote name '%s' does not existc              3  v   >#    U  H.  nTR                  U5      (       d  M  TR                  U5      v   M0     g 7fr:   )hasnoder1   ).0ncls     r"   	<genexpr>_revsetutil.<locals>.<genexpr>  s'     6u!

1IBFF1IIus   99)r   getargsr   r   stringmatcher	getstringr   alwayssetr0   r   r   updater   r   RepoLookupErrorr   baseset)r!   subsetxrtypesrl   r    patternmatcherr   rtyper   r,   revsr   s                @r"   _revsetutilr   }  s   aAq)F'GHD!+!9!9  a!,H*IJ"
w ++EE	BJJE"BT*t}}RXXd12 +  z%##01G;
 	
 7u6DH$$T***r%   s   remotenames([name])c                    [        XUS5      $ )zAll changesets which have a remotename on them. If `name` is
specified, only remotenames of matching remote paths are considered.

Pattern matching is supported for `name`. See :hg:`help revisions.patterns`.
)r   r   r   r!   r   r   s      r"   remotenamesrevsetr     s     tQ(OPPr%   s   remotebranches([name])c                    [        XUS5      $ )zAll changesets which are branch heads on remotes. If `name` is
specified, only remotenames of matching remote paths are considered.

Pattern matching is supported for `name`. See :hg:`help revisions.patterns`.
)r   r   r   s      r"   remotebranchesrevsetr     s     tQ(<==r%   s   remotebookmarks([name])c                    [        XUS5      $ )zAll changesets which have bookmarks on remotes. If `name` is
specified, only remotenames of matching remote paths are considered.

Pattern matching is supported for `name`. See :hg:`help revisions.patterns`.
)r   r   r   s      r"   remotebmarksrevsetr     s     tQ(=>>r%   ))rd   
__future__r   collections.abccollectionsmercurial.i18nr   mercurial.noder   	mercurialr   r   r   r	   r
   r   r   r   r   r   mercurial.utilsr   
testedwithconfigtable
configitemtemplatekeywordrevsetpredicateabcMutableMappingr   rh   r   r   r   r   r   r   r   r   r   r   rf   r%   r"   <module>r     s  $ #      ' #
!!+.
++-++- 

 
 \77 \~C" C"L& N<0~ 7F*;< =" #w.?@ A$ "gv->? @$+: '(Q )Q *+> ,> +,? -?r%   