
    	^c6                        d Z ddlZddlmZ ddlmZ ddlmZm	Z	m
Z
mZmZmZmZmZmZmZ ddlmZ dZi Z ej        e          Z ej                    Z ej                    Z edd	d
            eddd
            eddd            G d dej        j                  Z G d d          Zd Zd Zd Z edddh          d             Z  edddh          d             Z! edddh          d             Z"d Z# ed          d              Z$ ed!          d"             Z% ed#          d$             Z&dS )%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')
    N)_)bin)
	bookmarkserror
extensionslogexchange
namespaces	registrar
revsetlangsmartsettemplateutilutil)
stringutils   ships-with-hg-core   remotenames	   bookmarksT)default   branches   hoistedpeers   defaultc                   X    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eZdS )lazyremotenamedicta  
    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                 L    i | _         i | _        || _        || _        d| _        d S )NF)cachepotentialentries_kind_repoloaded)selfkindrepos      3/usr/lib/python3/dist-packages/hgext/remotenames.py__init__zlazyremotenamedict.__init__X   s*    
 "

    c                     d| _         | j        }t          j        || j                  D ]\  }}}|dz   |z   }|||f| j        |<   dS )z?Read the remotenames file, store entries matching selected kindT   /N)r   r   r   readremotenamefiler   r   )r   r   noderpathrnamenames         r    _loadzlazyremotenamedict._load_   sk    z"-"@$*#
 #
 	> 	>D% 4<%'D+/*=D!$''		> 	>r"   c                    || j         vrdS | j         |         \  }}}| j        }t          |          }	 |j                            |           n# t
          $ r Y dS w xY w| j        dk    r||                                         rdS |gS )z;Check that the node for potentialentry exists and return itNr   )r   r   r   	changelogrevLookupErrorr   closesbranch)r   potentialentryr&   remoter)   r   binnodes          r    _resolvedatazlazyremotenamedict._resolvedatai   s    !6664!2>Bfdzd))	Nw'''' 	 	 	44	 :$$g)C)C)E)E$4ys   A 
AAc                     | j         s|                                  |                     |          }||S t                      N)r   r*   _fetchandcacheKeyErrorr   keyvals      r    __getitem__zlazyremotenamedict.__getitem__z   s@    { 	JJLLL!!#&&?J**r"   c                 *    t          | j                  S r5   )iterr   r   s    r    __iter__zlazyremotenamedict.__iter__   s    D)***r"   c                 *    t          | j                  S r5   )lenr   r>   s    r    __len__zlazyremotenamedict.__len__   s    4()))r"   c                     t           r5   NotImplementedErrorr>   s    r    __setitem__zlazyremotenamedict.__setitem__       !!r"   c                     t           r5   rD   r>   s    r    __delitem__zlazyremotenamedict.__delitem__   rG   r"   c                 x    || j         v r| j         |         S |                     |          }||| j         |<   |S d S r5   )r   r3   r8   s      r    r6   z!lazyremotenamedict._fetchandcache   sH    $*:c?"$$?!DJsOJ4r"   c                 j    | j         s|                                  | j                                        S )z&Get a list of bookmark or branch names)r   r*   r   keysr>   s    r    rL   zlazyremotenamedict.keys   s.    { 	JJLLL$))+++r"   c              #      K   | j         s|                                  | j                                        D ]\  }}|t	          |d                   gfV   dS )z Iterate over (name, node) tuplesr   N)r   r*   r   itemsr   )r   kvtups      r    	iteritemszlazyremotenamedict.iteritems   sk       { 	JJLLL,2244 	& 	&GAts47||n%%%%%	& 	&r"   N)__name__
__module____qualname____doc__r!   r*   r3   r;   r?   rB   rF   rI   r6   rL   rQ   rN    r"   r    r   r   L   s        	 	  > > >  "  + + +* * *" " "" " "  , , ,& & & EEEr"   r   c                   H    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S )remotenamesa%  
    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                 <    || _         |                                  d S r5   )r   
clearnames)r   r   argss      r    r!   zremotenames.__init__   s    
r"   c                     t          d| j                  | _        t          d| j                  | _        |                                  dS )zClear all remote names stater   r   N)r   r   r   branches_invalidatecacher>   s    r    rZ   zremotenames.clearnames   s@    +L$*EE*;
CCr"   c                 >    d | _         d | _        d | _        d | _        d S r5   )_nodetobmarks_nodetobranch_hoisttonodes_nodetohoistsr>   s    r    r^   zremotenames._invalidatecache   s(    !!!!r"   c                     | j         S r5   )r   r>   s    r    bmarktonodeszremotenames.bmarktonodes   s
    ~r"   c                     | j         si|                                 }i | _         |                                D ]9\  }}| j                             |d         g                               |           :| j         S )Nr   )r`   re   rN   
setdefaultappend)r   re   r)   r&   s       r    nodetobmarkszremotenames.nodetobmarks   s    ! 	H,,..L!#D*0022 H H
d"--d1gr::AA$GGGG!!r"   c                     | j         S r5   )r]   r>   s    r    branchtonodeszremotenames.branchtonodes   s
    }r"   c                     | j         sh|                                 }i | _         |                                D ]8\  }}|D ]0}| j                             |g                               |           19| j         S r5   )ra   rk   rN   rg   rh   )r   rk   r)   nodesr&   s        r    nodetobranchzremotenames.nodetobranch   s    ! 	I ..00M!#D,2244 I Ie! I ID&11$;;BB4HHHHI!!r"   c                     | j         sp|                                 }i | _         |dz  }|                                D ];\  }}|                    |          r!|t	          |          d          }|| j         |<   <| j         S )Nr$   )rb   re   rN   
startswithrA   r   hoistmarktonodesr)   r&   s        r    hoisttonodeszremotenames.hoisttonodes   s    ! 	4++--K!#DTME)//11 4 4
d??5)) 4E

-D/3D&t,!!r"   c                 R   | j         s|                                 }i | _         |dz  }|                                D ]e\  }}|                    |          rK|t	          |          d          }| j                             |d         g                               |           f| j         S )Nr$   r   )rc   re   rN   rp   rA   rg   rh   rq   s        r    nodetohoistszremotenames.nodetohoists   s    ! 	L++--K!#DTME)//11 L L
d??5)) LE

-D&11$q'2>>EEdKKK!!r"   N)rR   rS   rT   rU   r!   rZ   r^   re   ri   rk   rn   rt   rv   rV   r"   r    rX   rX      s                " " "  " " "  " " "	" 	" 	"	" 	" 	" 	" 	"r"   rX   c                     d|j         vrd S |j         d         }|                    |          D ]+}|                    ||          }|s|d         }|ddf||<   , | ||||          S )N   remotebookmarksr       r"   )names	listnamesrm   )	origuir   fmbmarksnsr)   rm   r&   s	            r    wrapprintbookmarksr      s    ++	&	'BT"" ) )t$$ 	QxdC(t4D"f%%%r"   c                 F    t          j        t          dt                     d S )Ns   _printbookmarks)r   wrapfunctionr   r   )r}   s    r    extsetupr     s    I'9;MNNNNNr"   c           
      `   |j                             dddd           |                                sd S t          |          |_        t
          j        }|                     dd          r| |ddddd	 d
 d           }|j        	                    |           | 
                    dd          r5 |ddddfdfdfd          }|j        	                    |           |                     dd          r1 |ddddd d d           }|j        	                    |           d S d S )Ns   experimentalr   Ts   remotenames-extr   rx      remotebookmarks   remote bookmark:  %s
c                 X    | j                                                                         S r5   )_remotenamesre   rL   r   s    r    <lambda>zreposetup.<locals>.<lambda>  s!    4#4#A#A#C#C#H#H#J#J r"   c                 \    | j                                                             |g           S r5   )r   re   getr   r)   s     r    r   zreposetup.<locals>.<lambda>  *    t'8'E'E'G'G'K'Kb( ( r"   c                 \    | j                                                             |g           S r5   )r   ri   r   r   r&   s     r    r   zreposetup.<locals>.<lambda>  r   r"   )templatename	colornamelogfmtr{   namemapnodemapr   s   hoistednamess   hoistednames   hoisted name:  %s
c                 \    | j                                                                       S r5   )r   rt   rL   )r   rr   s    r    r   zreposetup.<locals>.<lambda>(  s)    t'8'E'E( ($&& r"   c                 `    | j                                                           |g           S r5   )r   rt   r   )r   r)   rr   s     r    r   zreposetup.<locals>.<lambda>+  -    4+<+I+I, ,#dB-- r"   c                 `    | j                                                           |g           S r5   )r   rv   r   )r   r&   rr   s     r    r   zreposetup.<locals>.<lambda>.  r   r"   r      remotebranches   remotebranchs   remote branch:  %s
c                 X    | j                                                                         S r5   )r   rk   rL   r   s    r    r   zreposetup.<locals>.<lambda>:  s!    4#4#B#B#D#D#I#I#K#K r"   c                 \    | j                                                             |g           S r5   )r   rk   r   r   s     r    r   zreposetup.<locals>.<lambda>;  s*    t'8'F'F'H'H'L'Lb( ( r"   c                 \    | j                                                             |g           S r5   )r   rn   r   r   s     r    r   zreposetup.<locals>.<lambda>>  r   r"   )r}   	setconfiglocalrX   r   r	   	namespace
configboolrz   addnamespaceconfig)r}   r   r   remotebookmarknshoistednamensremotebranchnsrr   s         @r    	reposetupr     s    	Go~t=OPPP::<< #D))D		B	}}^\22 "32+',JJ  
 
 
 	
 0111 		..99 	3B,(-                   M J##M222	}}^[11 0*%*KK  
 
 
 	
/////0 0r"      repo   ctx)requiresc                    |                      |d          }|                      |d          }g }d|j        v r3|j        d                             ||                                          }d|j        v r6||j        d                             ||                                          z  }t          j        | |d|d          S )z<List of strings. Remote names associated with the changeset.r   r   rx   r   s
   remotenamer   pluralresourcerz   r&   r   
compatlist)contextmappingr   ctxrX   s        r    remotenameskwr   E  s     GW--D


7F
+
+CKTZ''j!34::4LLDJ&&tz"34::4LLL"-^   r"   rx   c                    |                      |d          }|                      |d          }g }d|j        v r3|j        d                             ||                                          }t          j        | |d|d          S )z@List of strings. Remote bookmarks associated with the changeset.r   r   rx   r   r   r   )r   r   r   r   remotebmarkss        r    remotebookmarkskwr   W  s     GW--D


7F
+
+CLTZ''z"45;;D#((**MM"!   r"   r   c                    |                      |d          }|                      |d          }g }d|j        v r3|j        d                             ||                                          }t          j        | |d|d          S )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DJ&&$56<<T388::NN"    r"   c                    t          j        |ddt          d                    }|r?t          j        t          j        |d         t          d                              \  }}}ndx}}t          j        }t                      }| j	        |D ]e}	|	| j
        v rZ| j
        |	         }
|
                    |           D ]7} ||          s|                    |
                    | |                     8f|dk    r&|s$t          j        t          d          |z            fd|D             }|t!          j        |          z  S )	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   l   K   | ].}                     |                              |          V  /d S r5   )hasnoder-   ).0ncls     r    	<genexpr>z_revsetutil.<locals>.<genexpr>  s<      66!

16BFF1II666666r"   )r   getargsr   r   stringmatcher	getstringr   alwayssetr,   rz   r{   updaterm   r   RepoLookupErrorr   baseset)r   subsetxrtypesr[   r   patternmatcherrm   rtyper   r)   revsr   s                @r    _revsetutilr   }  sf   aAq)F'G'GHHD !+!9 a!,H*I*IJJ"
 "
gww w+EEE	B 3 3DJE"BT** 3 3wt}} RXXdD112222z%#011G;
 
 	
 7666u666DH$T****r"   s   remotenames([name])c                 &    t          | ||d          S )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`.
    )rx   r   r   r   r   r   s      r    remotenamesrevsetr     s     tVQ(OPPPr"   s   remotebranches([name])c                 &    t          | ||d          S )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     tVQ(<===r"   s   remotebookmarks([name])c                 &    t          | ||d          S )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`.
    )rx   r   r   s      r    remotebmarksrevsetr     s     tVQ(=>>>r"   )'rU   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   rX   r   r   r   r   r   r   r   r   r   r   rV   r"   r    <module>r      s4   &                                        ' & & & & & #
!Y!+..
+)+--+)+-- 

   
 
   
 
   \ \ \ \ \7 \ \ \~C" C" C" C" C" C" C" C"L& & & O O O=0 =0 =0@ 7F*;<<<  =<" #w.?@@@  A@$ "gv->???  @?$+ + +: '((Q Q )(Q *++> > ,+> +,,? ? -,? ? ?r"   