o ]Lb@s4ddlmZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZmZmZmZmZmZmZm Z mZmZmZddlmZdd lmZmZe d Z!e"d Z#e#duZ$ej%Z%ej&Z&ej'Z(ej)Z)Gd d d e&Z*Gddde&Z+ddZ,ddZ-e.ej/Gdd d e0ZdS))absolute_importN)_)delattr)tracing) dirstatemapencodingerrormatchnodepathutilpolicypycompatscmutilsparseutil) timestamp)dirstaterparsersrc@eZdZdZddZdS) repocachezfilecache for files in .hg/cCs |j|SN)_openerjoinselfobjfnamer4/usr/lib/python3/dist-packages/mercurial/dirstate.pyr< zrepocache.joinN__name__ __module__ __qualname____doc__rrrrrr9 rc@r) rootcachez*filecache for files in the repository rootcCs ||Sr)_joinrrrrrC zrootcache.joinNr!rrrrr'@r&r'cfdd}|S)Ncs6|sd}|j;}t||g|Ri|S)Nz.calling `%s` outside of a parentchange contextpendingparentchanger"r ProgrammingErrorrargskwargsmsgfuncrrwrapH   z%requires_parents_change..wraprr3r4rr2rrequires_parents_changeG r7cr*)Ncs6|rd}|j;}t||g|Ri|S)Nz-calling `%s` inside of a parentchange contextr+r.r2rrr4Sr5z(requires_no_parents_change..wraprr6rr2rrequires_no_parents_changeRr8r9c@seZdZ dddZddZejddZdd Ze d d Z e d d Z e dddZe ddZddZedddZe ddZe ddZe ddZe ddZd d!Zd"d#Ze d$d%Zd&d'Zdd)d*Zd+d,Zd-d.Zd/d0Zd1d2ZeZ d3d4Z!d5d6Z"d7d8Z#e d9d:Z$d;d<Z%dd=d>Z&d?d@Z'dAdBZ(dCdDZ)dEdFZ*dGdHZ+e,ddIdJZ-e,dKdLZ.e,dMdNZ/e,dOdPZ0e1dQdRZ2e1   (ddSdTZ3dUdVZ4dWdXZ5ddYdZZ6dd[d\Z7dd]d^Z8d_d`Z9ddadbZ:dcddZ;dedfZdkdlZ?dmdnZ@dodpZAdqdrZBdsdtZCdudvZDddxdyZEdzd{ZFd|d}ZGd~dZHddZIddZJddZKddZLddZMd(S)rFc Cs||_||_||_||_||_||_||_t||_ d|_ d|_ ||_ i|_ d|_d|_d|_d|j|_i|_d|_tj|_|jdS)zCreate a new dirstate object. opener is an open()-like callable that can be used to open the dirstate file; root is the root of the directory tracked by the dirstate. Frsdirstatesdirstate-tracked-hints %s.pendingN)_use_dirstate_v2_use_tracked_hint_nodeconstantsr _validate_root_sparsematchfnr normasprefix_rootdir_dirty_dirty_tracked_set_ui _filecache_parentwriters _filename _filename_th_pendingfilename_plchangecallbacks_origplr_mapcls_cwd) ropeneruirootvalidate sparsematchfn nodeconstantsuse_dirstate_v2use_tracked_hintrrr__init___s(   zdirstate.__init__cCs |jdS)zRmake sure the parents are loaded Used to avoid a race condition. N_plrrrrprefetch_parentss zdirstate.prefetch_parentsccs(|jd7_dV|jd8_dS)zContext manager for handling dirstate parents. If an exception occurs in the scope of the context manager, the incoherent dirstate won't be written when wlock is released. rNrFrYrrr parentchangeszdirstate.parentchangecCs |jdkS)zsReturns true if the dirstate is in the middle of a set of changes that modify the dirstate parent. rr[rYrrrr,s zdirstate.pendingparentchangecCs$||j|j|j|j|j|_|jS)zAReturn the dirstate contents (see documentation for dirstatemap).)rLrDrr>r<r:_maprYrrrr]sz dirstate._mapcCs|S)zThe matcher for the sparse checkout. The working directory may not include every file from a manifest. The matcher obtained by this property will match a path if it is to be included in the working directory. )r?rYrrr_sparsematchers zdirstate._sparsematcherbranchc CsLz |jdp dWSty%}z|jtjkrWYd}~dSd}~ww)Nr_sdefault)rreadstripIOErrorerrnoENOENT)rinstrrr_branchs zdirstate._branchcCs |jSr)r]parentsrYrrrrXs z dirstate._plcCs |j|Sr)r] hastrackeddir)rdrrrhasdirr zdirstate.hasdir .hgignorecCs<|}|s tSdd|D}tj|jdg||jjdS)NcSsg|]}d|qS)s include:%sr.0frrr z$dirstate._ignore..warn) _ignorefilesmatchmodneverr r>rDrs)rfilespatsrrr_ignores zdirstate._ignorecCs|jddo tjdkS)Nuisslash/)rD configboolrosseprYrrr_slashszdirstate._slashcC t|jSr)r checklinkr>rYrrr _checklinks zdirstate._checklinkcCstt|jSr)boolr checkexecr>rYrrr _checkexeczdirstate._checkexeccCst|d S)N.hg)rfscasesensitiver(rYrrr _checkcaseszdirstate._checkcasecCs |j|Sr)rA)rrnrrrr(s zdirstate._joincsgfdd}|S)aSbuild a callable that returns flags associated with a filename The information is extracted from three possible layers: 1. the file system if it supports the information 2. the "fallback" information stored in the dirstate if any 3. a more expensive mechanism inferring the flags from the parents. csd}d}z t|}Wn tyYdSwjr$t|r#dSn"|}|jr2|j r1dSns: d|}d|vrFdSj rRt |rPdSdS|dur[|}|j re|jrcdSdS|durwsq d|}d|vr}dSdS)Nrqlrx)oslstatr(OSErrorrr statislink get_entryhas_fallback_symlinkfallback_symlinkappendr statisexechas_fallback_exec fallback_exec)xentryfallback_valuest buildfallback fallback_funcrrr get_flagssL         z$dirstate.flagfunc..get_flagsr)rrrrrrflagfuncs )zdirstate.flagfunccCs|jdd}|r |StS)Nrzsforcecwd)rDconfigrgetcwd)rforcecwdrrrrM(sz dirstate._cwdcCsL|j}||jkr dS|j}t|s|tj7}||r$|t|dS|S)aReturn the path from which a canonical path is calculated. This path should be used to resolve file patterns or to convert canonical paths back to file paths for display. It shouldn't be used to get real file paths. Use vfs functions instead. rqN)rMr>r endswithseprr} startswithlen)rcwdrootseprrrr0s    zdirstate.getcwdNcCs4|dur|}t|j||}|jrt|S|Sr)rrpathtor>r~pconvert)rrnrpathrrrrDs  zdirstate.pathtocCs|j|}|dur tS|S)z-return a DirstateItem for the associated pathN)r]get DirstateItem)rrrrrrrLs zdirstate.get_entrycCs ||jvSr)r])rkeyrrr __contains__Sr)zdirstate.__contains__cCstt|jSr)itersortedr]rYrrr__iter__Vszdirstate.__iter__cCrr)r iteritemsr]rYrrritemsYr zdirstate.itemscsfddjDS)Ncsg|]}|qSr)r=)rmprYrrro_sz$dirstate.parents..rWrYrrYrrg^szdirstate.parentscC||jdS)Nrr=rXrYrrrp1az dirstate.p1cCr)NrrrYrrrp2drz dirstate.p2cCs|jd|jjkS)zTrue if a merge is in progressr)rXr<nullidrYrrrin_mergegszdirstate.in_mergecCrr)rtolocalrfrYrrrbranchlr zdirstate.branchcCsn|dur|jj}|jdkrtdd|_|jd}|jdur"|j|_|jj}||ko-||k}|jj|||dS)zSet dirstate parents to p1 and p2. When moving from two parents to one, "merged" entries a adjusted to normal and previous copy records discarded and returned by the call. See localrepo.setparents() NrsKcannot set dirstate parent outside of dirstate.parentchange context managerTr)fold_p2) r<rrF ValueErrorrBrXrKr] setparents)rrroldp2rrrrrros    zdirstate.setparentscCst|jj|t||jddddd}z||jd||jd}|r/| WdSWdS| )Nr_wT atomictemp checkambig s_branch) __class__rfsetr fromlocalrwritecloserErefreshdiscard)rrrncerrr setbranchs zdirstate.setbranchcCs:dD] }||jvrt||qd|_d|_d|_d|_dS)aCauses the next access to reread the dirstate. This is different from localrepo.invalidatedirstate() because it always rereads the dirstate. Use localrepo.invalidatedirstate() if you want to check whether the dirstate has changed before rereading it.)r]rfryFrN)__dict__rrBrCrFrK)rarrr invalidates   zdirstate.invalidatecCs>||krdSd|_|dur||jj|<dS|jj|ddS)z=Mark dest as a copy of source. Unmark dest if source is None.NT)rBr]copymappop)rsourcedestrrrcopys z dirstate.copycCs|jj|dSr)r]rr)rfilerrrcopiedrzdirstate.copiedcC|jjSr)r]rrYrrrcopiesszdirstate.copiescCsXd|_|j|}|dus|js|||j|}|r%|jj|d|r*d|_|S)aUa "public" method for generic code to mark a file as tracked This function is to be called outside of "update/merge" case. For example by a command like `hg add X`. if reset_copy is set, any existing copy information will be dropped. return True the file was previously untracked, False otherwise. TN) rBr]rtracked_check_new_tracked_filename set_trackedrrrC)rfilename reset_copyr pre_trackedrrrrs   zdirstate.set_trackedcCs |j|}|rd|_d|_|S)a a "public" method for generic code to mark a file as untracked This function is to be called outside of "update/merge" case. For example by a command like `hg remove X`. return True the file was previously tracked, False otherwise. T)r] set_untrackedrBrC)rrretrrrrs zdirstate.set_untrackedcCs<d|_|j|js|||\}}}|j||||dS)zFrecord that the current state of the file on disk is known to be cleanTN)rBr]rr set_clean)rrparentfiledatamodesizemtimerrrrs    zdirstate.set_cleancCsd|_|j|dS)zrsplit _normalizerfspath) rrnormed ignoremissingexistsstoremaprirnfoldedrrrr _discoverpathPs$   zdirstate._discoverpathcCsHt|}|jj|d}|dur"|r|}|S||||||jj}|Sr)rnormcaser] filefoldmaprrrrisknownrrrrrrr_normalizefilejs zdirstate._normalizefilecCs`t|}|jj|d}|dur|jj|d}|dur.|r#|}|S||||||jj}|Sr)rrr]rr dirfoldmaprrrrrrvs zdirstate._normalizecCs|jr ||||S|S)aL normalize the case of a pathname when on a casefolding filesystem isknown specifies whether the filename came from walking the disk, to avoid extra filesystem access. If ignoremissing is True, missing path are returned unchanged. Otherwise, we try harder to normalize possibly existing path components. The normalized case is determined based on the following precedence: - version of name already stored in the dirstate - version of name stored on disk - version provided via command arguments )rr)rrrrrrr normalizeszdirstate.normalizecCs|jd|_dS)NT)r]clearrBrYrrrr s  zdirstate.clearcCs|dur |}g}|n-t|dkr,g}g}|D]}||vr%||q||qnt|}|t|@}||}|jdurC|j|_|j||jj |D]}|j rY| |qN|jj |dddqN|D]}|j |qed|_ dS)N T)rr)r rrrrKrXr]rr<rrrrrB)rparentallfiles changedfiles to_lookupto_droprnchangedfilessetrrrrebuilds:        zdirstate.rebuildcCr)zReturn identity of dirstate itself to detect changing in storage If identity of previous dirstate is equal to this, writing changes based on the former dirstate out can keep consistency. )r]identityrYrrrrszdirstate.identitycsjsdSjo j}r3jdjffddddd|r1jdjffddddddSfd d}|j}|Wdn1sOwY|rt|j}|WddS1smwYdSdS) Ndirstate-1-mainc |Sr_writedirstaternrtrrr z dirstate.write..plainTlocation post_finalizesdirstate-2-key-postcrr)_write_tracked_hintrrrrrrcsj|ddddS)NrTr)rrrYrrrs)rBr;rCaddfilegeneratorrGrHrr")rr write_keyrrnrrrrs:      "zdirstate.writecCs|j|jd|_dS)zOremove the tracked_hint file To be used by format downgrades operationFN)runlinkrHr;rYrrrdelete_tracked_hints zdirstate.delete_tracked_hintcCs||j|<dS)a%add a callback to be called when the wd parents are changed Callback will be called with the following arguments: dirstate, (oldp1, oldp2), (newp1, newp2) Category is a unique identifier to allow overwriting an old callback with a newer callback. N)rJ)rcategorycallbackrrraddparentchangecallbacks z dirstate.addparentchangecallbackcCsd|jdur#|j|jkr#tt|jD] \}}|||j|jqd|_|j||d|_d|_ dS)NF) rKrXrrrrJr]rrBrC)rrrcr(rrrrs   zdirstate._writedirstatecCs"ttj}|d|dS)Ns1 %s )r hexuuiduuid4bytesr)rrrnrrrrr"szdirstate._write_tracked_hintcCs2||rdSt|D] }||rdSq dS)NTF)ryr r)rrnrrrr _dirignores  zdirstate._dirignorec Csng}tj|dr||d|jdD]\}}|dks&|dr4|tj|j t |q|S)Nrkrzsignoresignore.) rrrr(rrD configitemsrrrAr expandpath)rrwnamerrrrrtszdirstate._ignorefilesc Cst|}t}|rX|}tj||jjdd}|D]4\}}}t |d\} } | dkr7| |vr6| | qtj |j dg|g|jjd} | |rP|||fSq| ||s dS)NT) sourceinfosglobs subincluderqrr)Nrq) collectionsdequertrpopleftrureadpatternfilerDrs _patsplitrr r>add) rrnrwvisitedipatternspatternlinenolinekindrmrrr_ignorefileandline&s,   zdirstate._ignorefileandlinec" CsXdd}|j}|j}tj}tj}tj}tj} tj} |j } g} | j } g}|j }| s1|j r1|j }nd}t|}|d\}}|t|kr|t|kr||d}|||kr^|d7}qA|t|kr{|||r{||=|t|kr{|||sk|d7}|t|kr|t|ksM|rd|vrdg}d}t|}d|d<|D]}|r||d d }n|}||vrqz<|| |}||j}||kr||vrd||<| ||fn|| ks|| kr|||<n||||||vrd||<Wqty!}z%||vrd||<n|j|r||n ||t|jWYd}~qd}~ww|rCt|D]}|dks7||vr9q+||sA||=q+| r|j ri}t|D]'\}}|dur^qSt |}|!|}|durtt"}|||<|#|qSt|D]&\}}t|dkr|D]} |$| |d d|jj%}!| |!krd|| <qq|| |fS) aGet stat data about the files explicitly specified by match. Return a triple (results, dirsfound, dirsnotfound). - results is a mapping from filename to stat result. It also contains listings mapping subrepos and .hg to None. - dirsfound is a list of files found to be directories. - dirsnotfound is a list of files that the dirstate thinks are directories and that were not found.cSsvtd}t|rtd}n't|rtd}nt|r"td}nt|r,td}n t|r5td}td|S)Nsunknownscharacter devices block devicesfifossockets directorys"unsupported file type (type is %s))rstatS_ISCHRS_ISBLKS_ISFIFOS_ISSOCKS_ISDIR)rrArrrbadtypeFs          z'dirstate._walkexplicit..badtypeN)rrr{rrqrFT)&badr]rrrDS_IFMTS_IFDIRS_IFREGS_IFLNKr(risexactrrrrwsortrrdictfromkeysst_moderrjr strtolocalstrerroranypatslistrrrrrrr:rr )"rr subreposrJbadfndmaprgetkinddirkindregkindlnkkindr dirsfoundfoundadd dirsnotfound notfoundaddr rwr<jsubpathresultsffnfrrArernrncpathsnormrrrrr _walkexplicit<s                    zdirstate._walkexplicitTcs|r tjtjn|rjjntjtjj j jtjt j }t j t j t jjd}}rEd}tjnrKd}|sYjrYj j d}nj d |\} } r}| D]} | dqk| D]} | qv|o| p| }fdd| D}  fdd} | D]\} } p| | k}| | g|q|D]}|=qd =|sB|sBs҈rd dD}n fd dD}||r(tjjdd }t|D]6} r |ddvrd|<q||r!z |||<Wqty d|<Yqwd|<qSt|}tfd d|DD] }|t|<q8S)a3 Walk recursively through the directory tree, finding all files matched by match. If full is False, maybe skip some known-clean files. Return a dict mapping filename to stat-like object (either mercurial.osutil.stat instance or return value of os.stat()). FTNrcsg|] }|ds|qS)rr)rmri) dirignorerrrosz!dirstate.walk..c s|j}|r tdt||}|}|sq|dks"|dkr$d}d}|dkr,d}z!td||d|d}Wdn1sGwYWn)tyv}z|jtj tj fvrq  |t |jWYd}~qd}~ww|D]\}} } |r||vrqy r |r|d |p|dd} n |r|d |p|} | vr| krƈ| s r | || | vrňs| rd | <qy| ks| kr| vr݈s؈| r| | <qys| r| s|s | d d} | | <qy| vrs| rd | <qy|sdSdS) Nzdirstate.walk worksthissallrqrz!dirstate.walk.traverse listdir %sT)rDskipr{F)rrcounterrrvisitchildrensetlogrrcEACCESrdrKrrrUrV) work alreadynormedwaddnd visitentriesrnentriesrernrArrh)r]r[ignorerlistdirr_r matchalwaysmatchfn matchtdirr  normalizefiler^rfrrrtraversesv       zdirstate.walk..traversercSsg|]}|qSrrrlrrrroTscs g|] }|vr|r|qSrrrl)r|rfrrroVs )cachedcsg|]}|qSrr)rmr<)rrrro{rp)rrvryr/alwaysr| traversedirr]rzrrrDrMrNrOr(rPprefixrrrrlrQr pathauditorr>rcheckr statfilesnext)rr rYunknownignoredfullrexact skipstep3rsrbrirrvrtsvisit audit_pathrhivrr)rmr]r[ryrrzr_r r{r|r}r r~r^rfrrwalks  ( A      z dirstate.walkc Csj|jdd}|durtjdd||jddd}|s#dtjd<t|jj||j | |j t |t |t |t |j  \ }}} } } } } }}}}}|j|O_|j r_|D]}| |qW|jjr|D]/}t|tr|\}}td||f}|j|qetd }|j|t|j |j |d fqe|D] \}}||t|qtj|| | | || | d }||fS) NsworkersnumcpussRAYON_NUM_THREADSs%dsenabledT1s!%s: ignoring invalid syntax '%s' s*skipping unreadable pattern file '%s': %s sNo such file or directory)modifiedrrdeletedrrclean)rD configintrenviron setdefaultr|rustmodstatusr]rArtrrrrBrs isinstancetuplerr canonpathrKrUr)rmatcher list_clean list_ignored list_unknownnumcpusworkers_enabledlookuprrrrrrrwarningsrK traverseddirtydiritem file_pathsyntaxr1fnmessagerrrr _rust_statuss       zdirstate._rust_statusc* Cs,|||}}}gggggf\} } } }}ggg} } }|j}|d}tjtjtjf}tdur4d}n|jr:d}n|r?d}n tj rEd}nt ||sLd}zt |j }Wn ty_d}Ynw|r{z|||||}||fWStjyzYnwdd}|j}|j}| j}| j}| j}|r|jn|}|r|jn|}| j}| j}|r|jn|}|j}|j}|j} |j}!|jj}"|p|jdu}#t|j|||||#dD]\}$}%||$s|s||$r||$r|r||$n||$q||$}&|&j}'|&j}(|%s|&jr||$q|&j r||$q|&j!r||$q|&j"r||$q|&jr|!s*|&j#r*||$q| s6|&j$r6||$q|(dkrT|(|%j%krI|(|%j%t&@ksY|'|%j'Ad@rT| sY|$|"vrpt()|%j'rk|(|%j%krk||$q||$q|&*t +|%s~||$q|r||$qt,-| | | | |||})| |)|fS) a|Determine the status of the working copy relative to the dirstate and return a pair of (unsure, status), where status is of type scmutil.status and: unsure: files that might have been modified since the dirstate was written, but need to be read to be sure (size is the same but mtime differs) status.modified: files that have definitely been modified since the dirstate was written (different size or mode) status.clean: files that have definitely not been modified since the dirstate was written TNFcSsdSrrrrrrnoop szdirstate.status..noop)rr@).r]preloadru alwaysmatcher exactmatcherincludematcherrrrenabledrr get_fs_nowrrr FallbackErrorr __getitem__rrr/rrrrrrrrrrrrrrrst_size _rangemaskrTrDS_ISLNKmtime_likely_equal_tomtime_ofrr)*rr rYrrr listignored listclean listunknownrrrrrr[use_rustallowed_matchersmtime_boundaryresr dcontainsdgetladdmaddaadduaddiaddradddaddcaddmexactrmrrrrrrtrrrrrrrs                  zdirstate.statuscs|jtdur |jjrS}r$fdd|DSr7tfdd|Dr7t|SfddDS)zT return files in the dirstate (in whatever state) filtered by match Ncsg|]}|vr|qSrrrlr[rrromz$dirstate.matches..c3s|]}|vVqdSrr)rmrrrr nsz#dirstate.matches..csg|]}|r|qSrrrl)r rrrorr) r]rrkeysrwrPrallrX)rr rwr)r[r rmatches_szdirstate.matchescCs|r|jS|jSr)rIrGrrrr_actualfilenametszdirstate._actualfilenamec s}||ks Jjsj|s!j|ddddr;jdjffdddddj|dd j|t j j |j |dd d S) z&Save current dirstate into backup filerTrrcrrrrrrrrrz%dirstate.savebackup..rr)r )hardlinkN) rrBrrrr#rG registertmp tryunlinkrcopyfiler)rr backupnamerrrr savebackupzs,       zdirstate.savebackupcCsR|||}|j}t||||r||dS|j||dddS)zRestore dirstate by backup fileT)rN)rrrrsamefilerr%rename)rrrrorrr restorebackups  zdirstate.restorebackupcCs|j|dS)zClear backup fileN)rr%)rrrrrr clearbackuprzdirstate.clearbackupc csd}d}d}d}|D]5\}}|j} | dvr"||vr"||| fV| dvr0||vr0||| fV| dvrB||vrB||vrB||| fVq |D]}||j} | dvrW||| fVqEd S) zEcheck the dirstate content again the parent manifest and yield errorss%%s in state %s, but not in manifest1 s&%s in state %s, but also in manifest1 s+%s in state %s, but not in either manifest s(%s in manifest1, but listed as state %s snramsnrmN)rstater) rm1m2missing_from_p1unexpected_in_p1missing_from_psmissing_from_dsrnrrrrrverifys(     zdirstate.verify)Fr)FFN)FN)FF)T)Nr"r#r$rVrZ contextlibcontextmanagerr\r, propertycacher]propertyr^rrfrXrjr'ryr~rrrr(rrMrrrrrrrrgrrrrrrrrrrr9rrrrr7rrrrrrr r rrrr&r)rr"r/rtrCrlrrrrrrrrrrrrrr]s -          7          ' +   (!    =N( )1 __future__rr5rrcrrDr,i18nrrrhgdemandimportrrrr r rur r r rrr dirstateutilsr interfacesr intdirstate interfaceutil importmodr importrustrHAS_FAST_DIRSTATE_V2r filecache rangemaskrrrr'r7r9 implementer idirstateobjectrrrrs4    4