o ]LbK.@sddlmZddlmZddlmZddlmZmZ m Z m Z m Z mZmZmZdZdZdZd d Zd d Zd dZd8ddZddZddZddZd9ddZddZddZdd Zd!d"Zd#d$Zd%d&Z d'd(Z!d)d*Z"d+d,Z#d-d.Z$d/d0Z%d1d2Z&d3d4Z'd:d6d7Z(dS);)absolute_import)_)getattr)errormatchmerge mergestate requirementsscmutilsparseutils narrowspecsnarrowspec.dirstate)spath:s rootfilesin:cCs|d}t|||fS)zReturns the normalized version of a pattern and kind. Returns a tuple with the normalized kind and normalized pattern. /)rstrip_validatepattern)kindpatr6/usr/lib/python3/dist-packages/mercurial/narrowspec.pynormalizesplitpattern(s rcCst|dS)z?Returns the number of lines in s, including ending empty lines.x)len splitlines)srrr _numlines2srcCsFt|dkr ttd|d}d|vsd|vr!ttddS)zValidates the pattern and aborts if it is invalid. Patterns are stored in the narrowspec as newline-separated POSIX-style bytestring paths. There's no escaping. rs,newlines are not allowed in narrowspec pathsr.s..s0"." and ".." are not allowed in narrowspec pathsN)rrAbortrsplit)r componentsrrrr:s  rpathcCst||\}}dt||S)zyReturns the normalized version of a text-format pattern. If the pattern has no kind, the default will be added. s%s:%s)matchmod _patsplitr)pattern defaultkindrrrrrnormalizepatternMsr$cCsdd|D}t||S)aParses an iterable of patterns into a typed pattern set. Patterns are assumed to be ``path:`` if no prefix is present. For safety and performance reasons, only some prefixes are allowed. See ``validatepatterns()``. This function should be used on patterns that come from the user to normalize and validate them to the internal data structure used for representing patterns. cSsh|]}t|qSr)r$).0origrrr asz parsepatterns..)validatepatterns)patsresrrr parsepatternsVs r+cCstdt|1t|tstd||D]}|ts0tj t d|t dd tdqWddS1st||d\}}}|rttdt|t|||fS)NsnarrowsJincluding other spec files using '%include' is not supported in narrowspec)r parseconfigrrrr()uispec includepats excludepatsprofilesrrrrCsrCcCs|jt}t|j|SN)svfstryreadFILENAMErCrDreporErrrloads  rOcCs,t|t|t||}|jt|dSrI)r(r<rJwriterL)rNrFrGrErrrsaves rQcCs|jt}|jt|dSrI)rJreadrLvfsrPDIRSTATE_FILENAMErMrrrcopytoworkingcopys rUcCs@tj|jvrdS|j}||tj|t||dddSNT)hardlink)r NARROW_REQUIREMENTrJ tryunlinkr copyfiler4rL)rN backupnamerJrrr savebackups   r\cCs0tj|jvrdSt|j||jtdSrI)r rXr renamerJr4rLrNr[rrr restorebackups  r_cCsNtj|jvrdS|j}|||tr%tj|t||dddSdSrV) r rXrSrYexistsrTr rZr4)rNr[rSrrr savewcbackups    racCs@tj|jvrdS|j|rt|j||jtdSdSrI)r rXrSr`r r]r4rTr^rrrrestorewcbackups   rbcCs tj|jvrdS|j|dSrI)r rXrSrYr^rrr clearwcbackups rcc Cst|}||g}|st|}nNd|vr\g}|D]2}tt|}||vr.||qd}|D]} || drDd}||nq2|sL||qt|dkrWdh}n t|}nt|}|||fS)aVRestricts the patterns according to repo settings, results in a logical AND operation :param req_includes: requested includes :param req_excludes: requested excludes :param repo_includes: repo includes :param repo_excludes: repo excludes :return: include patterns, exclude patterns, and invalid include patterns. spath:.FrTr)r0updater expandpathnormpathappendr2r) req_includes req_excludes repo_includes repo_excludes res_excludesinvalid_includes res_includes req_includevalid repo_includerrrrestrictpatternss6        rrcCs|D]}|j|qdSrI)wvfs unlinkpath)rNfilesfrrr_deletecleanfilessrwcCsht}|d}|D]}|j|s"||tj||dfdq tj |||d|dddddS)NrFsnarrowspec updated)wctxmctx overwrite wantfiledata) r mergeresultmanifestrsr`addfile mergestatemod ACTION_GETflags applyupdates)rNpctxrumresultmfrvrrr_writeaddedfiless&    rcCsJt|ddrdS|jt}|jt}||kr#tjtdtdddS)N_updatingnarrowspecFs"working copy's narrowspec is stales&run 'hg tracked --update-working-copy'r,) rrJrKrLrSrTr StateErrorr)rN storespecwcspecrrrcheckworkingcopynarrowspec(s   rFcs|jt}|jt}d|_t|j|\}}t|j|\}}t|j ||d}t|j ||d} t | |} t || } |j j | gdddd\} } }| j| j}| j}|r\|| n|| t||t|}t|D]}|j td||qot| jD]}|j td||qt| jD]}|j td||q||D] }j|dddq|d }t | t|} fd d || D}|D] }j|dddd qt|||d|_d S)zupdates the working copy and dirstate from the store narrowspec When assumeclean=True, files that are not known to be clean will also be deleted. It is then up to the caller to make sure they are clean. Tr>)subreposignoredcleanunknowns$not deleting possibly dirty file %s snot deleting unknown file %s snot deleting ignored file %s F) p1_tracked wc_trackedrcsg|]}|vr|qSrr)r%rvdsrr asz%updateworkingcopy..)rrpossibly_dirtyN) rSrKrTrJrLrrCrDrrBr differencematcherdirstatestatusmodifiedaddedrextendrwr getuipathfnr6rrr update_fileintersectmatchersr matcherr}walkr)rN assumecleanoldspecnewspec oldincludes oldexcludes newincludes newexcludesoldmatchnewmatch addedmatch removedmatchlookupr_mtime_boundary trackeddirtyruipathfnrvrnewfilesrrrupdateworkingcopy5sJ              r)r)NN)F)) __future__ri18nrpycompatrrrr rr rr r r r rLrTr3rrrr$r+r(r<rCrOrQrUr\r_rarbrcrrrwrrrrrrrs:   (       )