
    	^c                     \    d Z ddlZddlmZ ddlmZ ddlmZ  G d dej                  ZdS )	z
    [infinitepush]
    # Server-side option. Used only if indextype=disk.
    # Filesystem path to the index store
    indexpath = PATH
    N)util)
stringutil   )indexapic                   r     e Zd Z f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 Zd Z xZS )fileindexapic                    t          t          |                                            || _        |j                            dd          }|s t          j                            dd          }t          j                            |d          | _	        t          j                            |d          | _
        t          j                            |d          | _        d | _        d S )Ns   infinitepushs	   indexpaths   scratchbranchess   indexs   nodemaps   bookmarkmaps   nodemetadatamap)superr   __init___repouiconfigospathjoin_nodemap_bookmarkmap_metadatamap_lock)selfreporoot	__class__s      A/usr/lib/python3/dist-packages/hgext/infinitepush/fileindexapi.pyr   zfileindexapi.__init__   s    lD!!**,,,
w~~o|<< 	>7<< 2H==DT:66GLL~>>GLL/ABB


    c                 B    | j                                         | _        | S N)r   wlockr   )r   s    r   	__enter__zfileindexapi.__enter__%   s    Z%%''
r   c                 P    | j         r| j                             |||           d S d S r   )r   __exit__)r   exc_typeexc_valexc_tbs       r   r!   zfileindexapi.__exit__)   s6    : 	;J'6:::::	; 	;r   c                     |D ]O}t           j                            | j        |                                          }|                     ||           Pd S r   )r   r   r   r   hex_write)r   bundleidnodesctxnodenodepaths        r   	addbundlezfileindexapi.addbundle-   sQ     	, 	,Dw||DM488::>>HKK(++++	, 	,r   c                 |    t           j                            | j        |          }|                     ||           d S r   )r   r   r   r   r'   )r   bookmarkr*   bookmarkpaths       r   addbookmarkzfileindexapi.addbookmark2   s4    w||D$5x@@L$'''''r   c                 f    |                                 D ]\  }}|                     ||           d S r   )itemsr0   )r   	bookmarksr.   r*   s       r   addmanybookmarkszfileindexapi.addmanybookmarks6   sB    'oo// 	- 	-NHdXt,,,,	- 	-r   c                     |D ]W}|                      |          D ]?\  }}t          j                            | j        |          }|                     |           @Xd S r   )_listbookmarksr   r   r   r   _delete)r   patternspatternr.   _r/   s         r   deletebookmarkszfileindexapi.deletebookmarks:   sn     	+ 	+G#227;; + +!!w||D,=xHH\****+	+ 	+r   c                 v    t           j                            | j        |          }|                     |          S r   )r   r   r   r   _read)r   r*   r+   s      r   	getbundlezfileindexapi.getbundle@   s+    7<<t44zz(###r   c                 v    t           j                            | j        |          }|                     |          S r   )r   r   r   r   r=   )r   r.   r/   s      r   getnodezfileindexapi.getnodeD   s,    w||D$5x@@zz,'''r   c                 F    t          |                     |                    S r   )dictr6   )r   querys     r   getbookmarkszfileindexapi.getbookmarksH   s    D''..///r   c                     | j         j        }|                    t          j                            | j        |          |           d S r   )r   vfswriter   r   r   r   )r   r*   jsonmetadatarF   s       r   saveoptionaljsonmetadataz%fileindexapi.saveoptionaljsonmetadataK   s8    jn		"',,t0$77FFFFFr   c           	   #     K   |                     d          rd|d d         z   dz   }t          j        |          \  }}}t          | j                  dz   }| j        j                            | j                  D ]\  }}}|D ]}	t          j	        
                    ||	          |d          }
t          j        |
          }
 ||
          sJ|
|                     t          j	        
                    ||	                    fV  d S )N   *s   re:^s   .*r   )endswithr   stringmatcherlenr   r   rF   walkr   r   r   r   pconvertr=   )r   r9   kindpatmatcher	prefixlendirpathr:   booksbookr.   s              r   r6   zfileindexapi._listbookmarksO   s!     D!! 	5,u4G'5g>>c7)**Q.	!%!4!4T5F!G!G 	H 	HGQ H H7<<66yzzB=22wx(( 

27<<+F+F G GGGGGGH	H 	Hr   c                     | j         j        }|                    |          }|                    |          s|                    |           |                    ||           d S r   )r   rF   dirnameexistsmakedirsrG   )r   r   valuerF   rZ   s        r   r'   zfileindexapi._write\   s\    jn++d##zz'"" 	"LL!!!		$r   c                 r    | j         j        }|                    |          sd S |                    |          S r   )r   rF   r[   readr   r   rF   s      r   r=   zfileindexapi._readd   s4    jnzz$ 	4xx~~r   c                 r    | j         j        }|                    |          sd S |                    |          S r   )r   rF   r[   unlinkr`   s      r   r7   zfileindexapi._deletej   s6    jnzz$ 	Fzz$r   )__name__
__module____qualname__r   r   r!   r,   r0   r4   r;   r>   r@   rD   rI   r6   r'   r=   r7   __classcell__)r   s   @r   r   r      s       
 
 
 
 
  ; ; ;, , ,
( ( (- - -+ + +$ $ $( ( (0 0 0G G GH H H                 r   r   )	__doc__r   	mercurialr   mercurial.utilsr    r   r    r   r   <module>rl      s     
			       & & & & & &      V  V  V  V  V 8$ V  V  V  V  V r   