o ö]Lb_ã@sÄddlmZddlZddlmZddlmZmZmZm Z m Z m Z ddl m ZmZe d¡Ze d¡Ze jZedur=ejZnejZd ZGd d „d eƒZGd d „d eƒZedur`Gdd „d eƒZdSdS)é)Úabsolute_importNé)Ú_)ÚerrorÚpathutilÚpolicyÚpycompatÚtxnutilÚutil)ÚdocketÚv2ÚparsersÚdirstateiÿÿÿc@sâeZdZdZdZdZdd„Zdd„Zd2dd„Zd d „Z d d „Z d d„Z dd„Z d2dd„Z d3dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Z    $ $ d4d%d&„Zd'd(„Zd5d*d+„Zed,d-„ƒZd.d/„Zd0d1„ZdS)6Ú_dirstatemapcommonz… Methods that are identical for both implementations of the dirstatemap class, with and without Rust extensions enabled. NcCsF||_||_||_||_||_d|_d|_d|_d|_d|_ d|_ dS)NsdirstateéF) Ú_use_dirstate_v2Ú_nodeconstantsÚ_uiÚ_openerÚ_rootÚ _filenameÚ_nodelenÚ_parentsÚ _dirtyparentsÚ_docketÚ _pendingmode)ÚselfÚuiÚopenerÚrootÚ nodeconstantsÚuse_dirstate_v2©r"ú7/usr/lib/python3/dist-packages/mercurial/dirstatemap.pyÚ__init__2s z_dirstatemapcommon.__init__cCs |jdS)z5Loads the underlying data, if it's not already loadedN©Ú_map©rr"r"r#ÚpreloadAó z_dirstatemapcommon.preloadcCs|j ||¡S©N)r&Úget)rÚkeyÚdefaultr"r"r#r+Eóz_dirstatemapcommon.getcCó t|jƒSr*)Úlenr&r'r"r"r#Ú__len__Hó z_dirstatemapcommon.__len__cCr/r*©Úiterr&r'r"r"r#Ú__iter__Kr2z_dirstatemapcommon.__iter__cCó ||jvSr*r%)rr,r"r"r#Ú __contains__Nr2z_dirstatemapcommon.__contains__cCs |j|Sr*r%)rÚitemr"r"r#Ú __getitem__Qr2z_dirstatemapcommon.__getitem__cCódS)z¤incremente the dirstate counter if applicable This might be a no-op for some subclass who deal with directory tracking in a different way. Nr"©rÚfilenameÚ old_entryr"r"r#Ú _dirs_incrYóz_dirstatemapcommon._dirs_incrFcCr:)z¤decremente the dirstate counter if applicable This might be a no-op for some subclass who deal with directory tracking in a different way. Nr")rr<r=Úremove_variantr"r"r#Ú _dirs_decr`r?z_dirstatemapcommon._dirs_decrcCr:)z record updated state of an entryNr"©rÚfÚentryr"r"r#Ú_refresh_entrygr?z!_dirstatemapcommon._refresh_entrycCr:)zˆadd a new dirstate entry (or replace an unrelated one) The fact it is actually new is the responsability of the caller Nr"rBr"r"r#Ú _insert_entryjr?z _dirstatemapcommon._insert_entrycCr:)z¨remove any entry for file f This should also drop associated copy information The fact we actually need to drop it is the responsability of the callerNr"©rrCr"r"r#Ú _drop_entrypr?z_dirstatemapcommon._drop_entrycCs ||}| ¡| ||¡dS)zÚ DirstateItemrFÚtrackedÚ set_trackedrErI)rr<ÚnewrDr"r"r#rT‡s&  ÿ  õ  þ z_dirstatemapcommon.set_trackedcCsV| |¡}|dur dS|j|||j d|js|j |d¡| ¡| ||¡dS)z4Mark a file as no longer tracked in the dirstate mapNF)r=r@T)r+rAÚaddedÚp2_inforLrMÚ set_untrackedrErBr"r"r#rXŸs  z _dirstatemapcommon.set_untrackedTc Cs||j |d¡|s!|s!|s!|j |¡}| |¡|j||ddS|j |¡}| ||¡t|||||d} | || ¡dS)ahSet a entry to a given state, diregarding all previous state This is to be used by the part of the dirstate API dedicated to adjusting the dirstate after a update/merge. note: calling this might result to no entry existing at all if the dirstate map does not see any point at having one for this file anymore. N)r=)rQÚ p1_trackedrWÚhas_meaningful_mtimeÚparentfiledata) rLrMr&r+rHrAr>rRrF) rr<rQrYrWrZÚhas_meaningful_datar[r=rDr"r"r#Ú reset_state¬s      ûz_dirstatemapcommon.reset_statecCsLt |j|j|j¡\}}|jdur!|j|kr!| ¡t t dƒ¡‚||_|S)Ns1working directory state may be changed parallelly) r Ú trypendingrrrrÚcloserÚAbortr)rÚfprNr"r"r#Ú_opendirstatefileÖsÿz$_dirstatemapcommon._opendirstatefileéÿÿÿÿc Cspz| ¡}| |¡WdƒWS1swYWdSty7}z|jtjkr,‚WYd}~dSd}~ww)Nó)rbÚreadÚIOErrorÚerrnoÚENOENT)rrOraÚerrr"r"r#Ú_readdirstatefileàs (ÿ €üz$_dirstatemapcommon._readdirstatefilecCs2|js|js t d¡‚tj | ¡|j¡|_|jS)Ns'dirstate only has a docket in v2 format) rrrÚProgrammingErrorÚ docketmodÚDirstateDocketÚparserjrr'r"r"r#r êsÿ ÿz_dirstatemapcommon.docketc s¤ˆj}tj ˆ ¡t|ƒ|¡}| ¡‰|r| ˆd¡ˆj  ˆ|¡|  |  ¡¡|  ¡|j rM| ¡‰d‡‡fdd„ }|rJd|j }|  ||¡n|ƒ|ˆ_dS)Nrcs ˆj ˆ¡Sr*)rÚunlink)Ú_tr©Ú data_filenamerr"r#Ús z7_dirstatemapcommon.write_v2_no_append..sdirstate-v2-clean-r*)r rlrmÚ with_new_uuidÚparentsr0rrÚaddrÚwriteÚ serializer_ÚuuidÚ addpostcloser) rÚtrÚstÚmetaÚpackedÚ old_docketÚ new_docketroÚcategoryr"rqr#Úwrite_v2_no_appendös$ÿ   z%_dirstatemapcommon.write_v2_no_appendcCsž|jsL|jr|jj|_|jS|jd}| |¡}t|ƒ}||kr5|d|j…||jd|j…f|_|jS|dkrE|jj|jjf|_|jSt   t dƒ¡‚|jS)Nérs(working directory state appears damaged!) rrr rurrjr0rÚnullidrr`r)rÚread_lenr|Úlr"r"r#rus*  î  þöþ üÿz_dirstatemapcommon.parentsr*©NF)FFFTTN)rc)Ú__name__Ú __module__Ú __qualname__Ú__doc__r&rLr$r(r+r1r5r7r9r>rArErFrHrIrKrTrXr]rbrjÚpropertyr r‚rur"r"r"r#r'sB     ø*   rc@sÞeZdZdZedd„ƒZedd„ƒZdd„Zdd „ZeZ d d „Z d d „Z d.dd„Z dd„Z dd„Zedd„ƒZd/dd„Zd0dd„Zedd„ƒZedd„ƒZd d!„Zd"d#„Zed$d%„ƒZed&d'„ƒZd(d)„Zd*d+„Zd,d-„ZdS)1Ú dirstatemapa´Map encapsulating the dirstate's contents. The dirstate contains the following state: - `identity` is the identity of the dirstate file, which can be used to detect when changes have occurred to the dirstate file. - `parents` is a pair containing the parents of the working copy. The parents are updated by calling `setparents`. - the state map maps filenames to tuples of (state, mode, size, mtime), where state is a single character representing 'normal', 'added', 'removed', or 'merged'. It is read by treating the dirstate as a dict. File state is updated by calling various methods (see each documentation for details): - `reset_state`, - `set_tracked` - `set_untracked` - `set_clean` - `set_possibly_dirty` - `copymap` maps destination filenames to their source filename. The dirstate also provides the following views onto the state: - `filefoldmap` is a dict mapping normalized filenames to the denormalized form that they appear as in the dirstate. - `dirfoldmap` is a dict mapping normalized directory names to the denormalized form that they appear as in the dirstate. cCsi|_| ¡|jSr*)r&rer'r"r"r#r&Psúdirstatemap._mapcCsi|_|j|jSr*)rLr&r'r"r"r#rLVsúdirstatemap.copymapcCs\|j ¡|j ¡| |jj|jj¡t |d¡t |d¡t |d¡t |d¡dS)Nó_dirsó_alldirss filefoldmapó dirfoldmap)r&ÚclearrLÚ setparentsrr„r Úclearcachedpropertyr'r"r"r#r“\s     údirstatemap.clearcCó t |j¡Sr*)rÚ iteritemsr&r'r"r"r#Úitemseó údirstatemap.itemsccs0| ¡D]\}}||j|j|j|jfVqdS)z… Return an iterator of (filename, state, mode, size, mtime) tuples `all` is unused when Rust is not enabled N)r™ÚstaterNrOrP)rÚallr<r8r"r"r#Ú debug_iterks€ÿúdirstatemap.debug_itercCó |j ¡Sr*)r&Úkeysr'r"r"r#r¡tr2údirstatemap.keysFcCsZ||f|_d|_i}|r+t |j¡D]\}}|jr*|j |d¡}|r&|||<| ¡q|S)NT) rrrr˜r&rWrLrMÚdrop_merge_data)rÚp1Úp2Úfold_p2ÚcopiesrCÚsÚsourcer"r"r#r”ys €údirstatemap.setparentscCsòtj |j |j¡¡|_|jr|jj sdS|j  |j  ¡¡}n|  ¡}|s'dSt  td¡r7t t|ƒd¡|_|jrR|jj}|jj}t tj¡}||j|j||ƒnt tj¡}||j|j|ƒ}|jsh|j|Ž|jj|_|jj|_|jj|_dS)Nsdict_new_presizedéG)r ÚfilestatÚfrompathrÚjoinrÚidentityrr ryrerrrjÚ safehasattrr Údict_new_presizedr0r&ruÚ tree_metadataÚnogcr Úparse_dirstaterLrr”r7r9r+)rr|Úpr}r´r"r"r#re‰s0 ÿ      zdirstatemap.readcCs^|jrt |j|j¡\}}| ||||¡nt |j|j| ¡¡}| |¡|  ¡d|_ dSr‡) rr Ú pack_dirstater&rLr‚r rurwr_r)rr{r|r~r}r"r"r#rw¿sÿ  údirstatemap.writecCó |j|jSr*©r&r¯r'r"r"r#r¯Ëóúdirstatemap.identityNcCsN|dus|jrd|jvr|j |¡|dur#d|jvr%|j |¡dSdSdS)z-incremente the dirstate counter if applicableNÚ_dirsÚ_alldirs)ÚremovedÚ__dict__r¼Úaddpathr½r;r"r"r#r>Ós   ÿzdirstatemap._dirs_incrcCs„|dur d|jvr|js|j |¡d|jvr|s|j |¡n |r-d|jvr-|j |¡d|jvr@t |¡}|j  |d¡dSdS)z-decremente the dirstate counter if applicableNr¼r½Ú filefoldmap) r¿r¾r¼Údelpathr½rÀr ÚnormcaserÁrM)rr<r=r@Únormedr"r"r#rAÜs  €   þzdirstatemap._dirs_decrcCsnztj}Wn tyYn w||jtjtjƒSi}tj}t  |j¡D] \}}|j s0||||ƒ<q#d|d<|S)zeReturns a dictionary mapping normalized case paths to their non-normalized versions. ó.) r Úmake_file_foldmapÚAttributeErrorr&r Ú normcasespecÚnormcasefallbackrÃrr˜r¾)rÚmakefilefoldmaprCrÃÚnamer¨r"r"r#rÁés   ÿ ÿ €údirstatemap.filefoldmapcCs&i}tj}|jD]}||||ƒ<q|Sr*)r rÃr¼©rrCrÃrËr"r"r#Ú dirfoldmapÿs  údirstatemap.dirfoldmapcCr6)zo Returns True if the dirstate contains a tracked (not removed) file in this directory. )r¼©rÚdr"r"r#Ú hastrackeddiró údirstatemap.hastrackeddircCr6)zn Returns True if the dirstate contains a file (tracked or removed) in this directory. )r½rÐr"r"r#ÚhasdirrÓúdirstatemap.hasdircCstj|jddS)NT)Ú only_tracked©rÚdirsr&r'r"r"r#r¼szdirstatemap._dirscCr—r*rØr'r"r"r#r½s zdirstatemap._alldirscCs|js |j |d¡dSdSr*)Ú any_trackedr&rMrBr"r"r#rEsÿúdirstatemap._refresh_entrycCs||j|<dSr*r%rBr"r"r#rF#r.údirstatemap._insert_entrycCs |j |d¡|j |d¡dSr*)r&rMrLrGr"r"r#rH&óúdirstatemap._drop_entry©Fr*r‡)rˆr‰rŠr‹Ú propertycacher&rLr“r™r˜ržr¡r”rerwr¯r>rArÁrÎrÒrÕr¼r½rErFrHr"r"r"r#r,s>#    6        rc@s®eZdZedd„ƒZedd„ƒZdd„Zdd„Zd d „Z e Z d d „Z d%dd„Z edd„ƒZ dd„Zedd„ƒZdd„Zdd„Zedd„ƒZdd„Zdd„Zd d!„Zd"d#„Zd$S)&rcCs°tj |j |j¡¡|_|jr1|jj r|j  |j  ¡¡}nd}t j  ||jj|jj¡|_|jj}n t j  | ¡¡\|_}|rF|jsF|j|Ž|jj|_|jj|_|jj|_|jS)z< Fills the Dirstatemap when called. rd)r r¬r­rr®rr¯rr ryrerrÚrustmodÚ DirstateMapÚnew_v2Ú data_sizer²r&ruÚnew_v1rjrr”r7r9r+)rÚdatarur"r"r#r&1s( ÿÿ  ÿ     rŽcCr r*)r&rLr'r"r"r#rLRr)rcCó |j |¡S)zà Return an iterator of (filename, state, mode, size, mtime) tuples `all`: also include with `state == b' '` dirstate tree nodes that don't have an associated `DirstateItem`. )r&rž)rrr"r"r#ržVs rŸcCsF|j ¡| |jj|jj¡t |d¡t |d¡t |d¡dS)Nrr‘r’)r&r“r”rr„r r•r'r"r"r#r“`s  ÿ  r–cCr r*)r&r™r'r"r"r#r™ir2r›cCr/r*r3r'r"r"r#r¡or2r¢Fc Csx||f|_d|_i}|r:dd„|j ¡Dƒ}|j}|D]}| |¡}|j |d¡} | r/| ||<| ¡| ||¡q|S)NTcSsg|] \}}|jr|‘qSr")rW)Ú.0rCr¨r"r"r#Ú ~s  ÿÿz*dirstatemap.setparents..) rrr&r™r+rLrMr£Úset_dirstate_item) rr¤r¥r¦r§Úfiles_with_p2_infoÚrust_maprCÚer©r"r"r#r”ts ÿ rªcCr¸r*r¹r'r"r"r#r¯rºr»c CsV|js| ¡\}}|j ||¡}| |¡| ¡d|_dS|jjdu}|j  |¡\}}}|r˜|j} |   ¡} |r?|  | | j ¡|  | d¡.} |  | j ¡|  ¡| j ksUJ‚|  |¡} | durl| t|ƒkslJ| t|ƒfƒ‚Wdƒn1svwY| j t|ƒ7_ | ¡| _|| _| |  ¡¡| ¡n| ||||¡t |d¡d|_dS)NFsr+bs_map)rrur&Úwrite_v1rwr_rr ryÚwrite_v2rrrvrärÚseekÚtellr0r²rxr‚r r•) rr{r|r¤r¥r~Ú can_appendr}Úappendr rrraÚwrittenr"r"r#rw’s<     €û    r·cCr )zmReturns a dictionary mapping normalized case paths to their non-normalized versions. )r&Úfilefoldmapasdictr'r"r"r#rÁ·rÓrÌcCrçr*)r&rÒrÐr"r"r#rÒ¾ršrÔcCrçr*)r&rÕrÐr"r"r#rÕÁršrÖcCs*i}tj}|j ¡D]}||||ƒ<q |Sr*)r rÃr&Ú tracked_dirsrÍr"r"r#rÎÄs rÏcCs(|js |j |¡dS|j ||¡dSr*)rÚr&Údrop_item_and_copy_sourceÚaddfilerBr"r"r#rEÎsrÛcCs|j ||¡dSr*)r&rørBr"r"r#rFÔsrÜcCs|j |¡dSr*)r&r÷rGr"r"r#rH×srÞcCs t|tƒsJ‚|j ||¡dSr*)Ú isinstancerRr&rê)rr,Úvaluer"r"r#Ú __setitem__ÚrÝzdirstatemap.__setitem__Nrß)rˆr‰rŠràr&rŒrLržr“r™r˜r¡r”r¯rwrÁrÒrÕrÎrErFrHrûr"r"r"r#r-s0      %    )Ú __future__rrgÚi18nrÚrrrrr r Ú dirstateutilsr rlr Ú importmodr Ú importrustráràrRrJÚobjectrrr"r"r"r#Ús*     þ