o ]Lb_@sddlmZddlZddlmZddlmZmZmZm Z m Z m Z ddl m ZmZedZedZe jZedur=ejZnejZd ZGd d d eZGd d d eZedur`Gdd d eZdSdS))absolute_importN)_)errorpathutilpolicypycompattxnutilutil)docketv2parsersdirstateic@seZdZdZdZdZddZddZd2ddZd d Z d d Z d dZ ddZ d2ddZ d3ddZddZddZddZddZddZd d!Zd"d#Z    $ $ d4d%d&Zd'd(Zd5d*d+Zed,d-Zd.d/Zd0d1ZdS)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)NsdirstateF) _use_dirstate_v2_nodeconstants_ui_opener_root _filename_nodelen_parents _dirtyparents_docket _pendingmode)selfuiopenerroot nodeconstantsuse_dirstate_v2r"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_maprr"r"r#preloadA z_dirstatemapcommon.preloadcCs|j||SN)r&get)rkeydefaultr"r"r#r+Ez_dirstatemapcommon.getcC t|jSr*)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%)ritemr"r"r# __getitem__Qr2z_dirstatemapcommon.__getitem__cCdS)zincremente the dirstate counter if applicable This might be a no-op for some subclass who deal with directory tracking in a different way. Nr"rfilename old_entryr"r"r# _dirs_incrYz_dirstatemapcommon._dirs_incrFcCr:)zdecremente 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"rfentryr"r"r#_refresh_entrygr?z!_dirstatemapcommon._refresh_entrycCr:)zadd 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:)zremove 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 DirstateItemrFtracked set_trackedrErI)rr<newrDr"r"r#rTs&       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+rAaddedp2_inforLrM set_untrackedrErBr"r"r#rXs  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_trackedrWhas_meaningful_mtimeparentfiledata) rLrMr&r+rHrAr>rRrF) rr<rQrYrWrZhas_meaningful_datar[r=rDr"r"r# reset_states      z_dirstatemapcommon.reset_statecCsLt|j|j|j\}}|jdur!|j|kr!|tt d||_|S)Ns1working directory state may be changed parallelly) r trypendingrrrrcloserAbortr)rfprNr"r"r#_opendirstatefilesz$_dirstatemapcommon._opendirstatefilec Cspz|}||WdWS1swYWdSty7}z|jtjkr,WYd}~dSd}~ww)N)rbreadIOErrorerrnoENOENT)rrOraerrr"r"r#_readdirstatefiles ( z$_dirstatemapcommon._readdirstatefilecCs2|js|js tdtj||j|_|jS)Ns'dirstate only has a docket in v2 format) rrrProgrammingError docketmodDirstateDocketparserjrr'r"r"r#r s z_dirstatemapcommon.docketc sj}tjt||}||r|dj || | | |j rM|dfdd }|rJd|j }| ||n||_dS)Nrcs jSr*)runlink)_tr data_filenamerr"r#s z7_dirstatemapcommon.write_v2_no_append..sdirstate-v2-clean-r*)r rlrm with_new_uuidparentsr0rraddrwrite serializer_uuid addpostcloser) rtrstmetapacked old_docket new_docketrocategoryr"rqr#write_v2_no_appends$   z%_dirstatemapcommon.write_v2_no_appendcCs|jsL|jr|jj|_|jS|jd}||}t|}||kr5|d|j||jd|jf|_|jS|dkrE|jj|jjf|_|jSt t d|jS)Nrs(working directory state appears damaged!) rrr rurrjr0rnullidrr`r)rread_lenr|lr"r"r#rus*    z_dirstatemapcommon.parentsr*NF)FFFTTN)rc)__name__ __module__ __qualname____doc__r&rLr$r(r+r1r5r7r9r>rArErFrHrIrKrTrXr]rbrjpropertyr rrur"r"r"r#r'sB     *   rc@seZdZdZeddZeddZddZdd ZeZ d d Z d d Z d.ddZ ddZ ddZeddZd/ddZd0ddZeddZeddZd d!Zd"d#Zed$d%Zed&d'Zd(d)Zd*d+Zd,d-ZdS)1 dirstatemapaMap 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&Psdirstatemap._mapcCsi|_|j|jSr*)rLr&r'r"r"r#rLVsdirstatemap.copymapcCs\|j|j||jj|jjt|dt|dt|dt|ddS)N_dirs_alldirss filefoldmap dirfoldmap)r&clearrL setparentsrrr clearcachedpropertyr'r"r"r#r\s     dirstatemap.clearcC t|jSr*)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)rstaterNrOrP)rallr<r8r"r"r# debug_iterksdirstatemap.debug_itercC |jSr*)r&keysr'r"r"r#rtr2dirstatemap.keysFcCsZ||f|_d|_i}|r+t|jD]\}}|jr*|j|d}|r&|||<|q|S)NT) rrrrr&rWrLrMdrop_merge_data)rp1p2fold_p2copiesrCssourcer"r"r#rys dirstatemap.setparentscCstj|j|j|_|jr|jj sdS|j |j }n| }|s'dSt tdr7tt|d|_|jrR|jj}|jj}ttj}||j|j||nttj}||j|j|}|jsh|j||jj|_|jj|_|jj|_dS)Nsdict_new_presizedG)r filestatfrompathrjoinridentityrr ryrerrrj safehasattrr dict_new_presizedr0r&ru tree_metadatanogcr parse_dirstaterLrrr7r9r+)rr|pr}rr"r"r#res0       zdirstatemap.readcCs^|jrt|j|j\}}|||||nt|j|j|}||| d|_ dSr) rr pack_dirstater&rLrr rurwr_r)rr{r|r~r}r"r"r#rws  dirstatemap.writecC |j|jSr*r&rr'r"r"r#rdirstatemap.identityNcCsN|dus|jrd|jvr|j||dur#d|jvr%|j|dSdSdS)z-incremente the dirstate counter if applicableN_dirs_alldirs)removed__dict__raddpathrr;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 |ddSdS)z-decremente the dirstate counter if applicableNrr filefoldmap) rrrdelpathrrr normcaserrM)rr<r=r@normedr"r"r#rAs     zdirstatemap._dirs_decrcCsnztj}Wn tyYn w||jtjtjSi}tj}t |jD] \}}|j s0||||<q#d|d<|S)zeReturns a dictionary mapping normalized case paths to their non-normalized versions. .) r make_file_foldmapAttributeErrorr&r normcasespecnormcasefallbackrrrr)rmakefilefoldmaprCrnamerr"r"r#rs     dirstatemap.filefoldmapcCs&i}tj}|jD]}||||<q|Sr*)r rrrrCrrr"r"r# dirfoldmaps  dirstatemap.dirfoldmapcCr6)zo Returns True if the dirstate contains a tracked (not removed) file in this directory. )rrdr"r"r# hastrackeddir dirstatemap.hastrackeddircCr6)zn Returns True if the dirstate contains a file (tracked or removed) in this directory. )rrr"r"r#hasdirrdirstatemap.hasdircCstj|jddS)NT) only_trackedrdirsr&r'r"r"r#rszdirstatemap._dirscCrr*rr'r"r"r#rs zdirstatemap._alldirscCs|js |j|ddSdSr*) any_trackedr&rMrBr"r"r#rEsdirstatemap._refresh_entrycCs||j|<dSr*r%rBr"r"r#rF#r.dirstatemap._insert_entrycCs |j|d|j|ddSr*)r&rMrLrGr"r"r#rH&dirstatemap._drop_entryFr*r)rrrr propertycacher&rLrrrrrrrerwrr>rArrrrrrrErFrHr"r"r"r#r,s>#    6        rc@seZdZeddZeddZddZddZd d Z e Z d d Z d%ddZ eddZ ddZeddZddZddZeddZddZddZd d!Zd"d#Zd$S)&rcCstj|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 rrrrrrrr ryrerrrustmod DirstateMapnew_v2 data_sizerr&runew_v1rjrrr7r9r+)rdatarur"r"r#r&1s(       rcCrr*)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#rVs rcCsF|j||jj|jjt|dt|dt|ddS)Nrrr)r&rrrrr rr'r"r"r#r`s    rcCrr*)r&rr'r"r"r#rir2rcCr/r*r3r'r"r"r#ror2rFc Csx||f|_d|_i}|r:dd|jD}|j}|D]}||}|j|d} | r/| ||<||||q|S)NTcSsg|] \}}|jr|qSr")rW).0rCrr"r"r# ~s  z*dirstatemap.setparents..) rrr&rr+rLrMrset_dirstate_item) rrrrrfiles_with_p2_inforust_maprCerr"r"r#rts  rcCrr*rr'r"r"r#rrrc CsV|js|\}}|j||}|||d|_dS|jjdu}|j |\}}}|r|j} | } |r?| | | j | | d.} | | j | | j ksUJ| |} | durl| t|kslJ| t|fWdn1svwY| j t|7_ || _|| _|| |n|||||t|dd|_dS)NFsr+bs_map)rrur&write_v1rwr_rr rywrite_v2rrrvrrseektellr0rrxrr r) rr{r|rrr~ can_appendr}appendr rrrawrittenr"r"r#rws<         rcCr)zmReturns a dictionary mapping normalized case paths to their non-normalized versions. )r&filefoldmapasdictr'r"r"r#rrrcCrr*)r&rrr"r"r#rrrcCrr*)r&rrr"r"r#rrrcCs*i}tj}|jD]}||||<q |Sr*)r rr& tracked_dirsrr"r"r#rs rcCs(|js |j|dS|j||dSr*)rr&drop_item_and_copy_sourceaddfilerBr"r"r#rEsrcCs|j||dSr*)r&rrBr"r"r#rFsrcCs|j|dSr*)r&rrGr"r"r#rHsrcCs t|tsJ|j||dSr*) isinstancerRr&r)rr,valuer"r"r# __setitem__rzdirstatemap.__setitem__Nr)rrrrr&rrLrrrrrrrrwrrrrrErFrHrr"r"r"r#r-s0      %    ) __future__rrgi18nrrrrrr r dirstateutilsr rlr importmodr importrustrrrRrJobjectrrr"r"r"r#s*