o ]Lb}i@s:ddlmZddlZddlmZddlmZddlmZm Z m Z m ZmZmZmZmZmZddlmZdZd d Zd d Zd dZddZd3ddZddZddZddZddZddZ ddZ!d4d d!Z"d"d#Z#d5d$d%Z$d&d'Z% d6d(d)Z&d5d*d+Z'd5d,d-Z( . .  . . .  d7d/d0Z) d8d1d2Z*dS)9)absolute_importN)_)hex) errormatchmerge mergestatepathutilpycompat requirementsscmutilutil)hashutilFc CsPtdt||t}t}t}d}d}|dD]u}|}|r)|dr*q|dr?|dd}|r>||q|dkrY|rT||krTt t d d |id }|}q|d krbd }|}q|r|durxtj t d ||dt dd|dr| t d||dq||q|||fWdS1swYdS)zParse sparse config file content. action is the command which is trigerring this read, can be narrow, sparse Returns a tuple of includes, excludes, and profiles. z+sparse.parseconfig(ui, %d bytes, action=%s)NF #s %include s [include]s5%(action)s config cannot have includes after excludesactionTs [exclude]s4%(action)s config entry outside of section: %(line)s)rslines<add an [include] or [exclude] line to declare the entry type)hint/sPwarning: %(action)s profile cannot use paths starting with /, ignoring %(line)s ) rtimedcmlensetsplitstrip startswithaddrAbortrwarn) uirawactionincludesexcludesprofilescurrent havesectionliner(2/usr/lib/python3/dist-packages/mercurial/sparse.py parseconfig"sr      $r*cCs|j||dS)z1Resolve the raw content of a sparse profile file.)changeid)filectxdata)repoprofiler+r(r(r) readprofilehsr0c Cs<ts tttfS|jd}|stttfS|dur%ttdt|j|d\}}}||}|rt}|r| }||vrCq8| |zt |||}Wn$tj ytd||f} |j ddrl|j| n|j| Yq8wt|j|d\} } } || || || |s:|}|r| d|||fS)zObtain sparse checkout patterns for the given rev. Returns a tuple of iterables representing includes, excludes, and patterns. sparseNs3cannot parse sparse patterns from working directorys?warning: sparse profile '%s' not found in rev %s - ignoring it smissingwarnings.hg*)enabledrvfstryreadrrrr*rpoprr0ManifestLookupError configboolrdebugupdate) r.revr r"r#r$ctxvisitedr/msg pincludes pexcludessubprofsr(r(r)patternsforrevosR         rAc sffddjD}t}t}t}|D]}t|\}}}||O}||O}||O}q|||fS)zDetermine the active sparse config rules. Rules are constructed by reading the current sparse config and bringing in referenced profiles from parents of the working directory. c"g|] }|jkrj|qSr(nullid changelogr:.0noder.r(r)   z activeconfig..)dirstateparentsrrA) r.revs allincludes allexcludes allprofilesr:r"r#r$r(rIr) activeconfigs   rRTcCs|j}|d}|r|d}nd}|dus|rB|durBtt|jd}||d<|rB|jd}tt|}||d<d||fS)zObtain the signature string for the current sparse configuration. This is used to construct a cache key for matchers. s signatures tempsignature0Nr1 tempsparse%s %s)_sparsesignaturecachegetrrsha1r3r4digest)r. includetempcache signature tempsignaturer r(r(r)configsignatures    r^cCs|ddF}t|D] }|d|q |r-|dt|D] }|||dq |rE|dt|D] }|||dq8Wdn1sOwY|jdS)z:Write the sparse config file given a sparse configuration.r1swbs %%include %s s [include] rs [exclude] N)r3sortedwriterVclear)r.r"r#r$fhpier(r(r) writeconfigs          rfcCs$|jd}|s tSt|dSNrTr)r3r4rr)r.r r(r(r)readtemporaryincludess rhcCs&|jddt||jdSrg)r3r`joinr_rVra)r.r"r(r(r)writetemporaryincludessrjcCs*t|}|D]}||qt||dSN)rhrrj)r. additionalr"rdr(r(r)addtemporaryincludess rmc Cs tr|jds dS|}|js|js|js|jrdSt|dd}|j }t }g}t |}|D]}||vrM||sMt d}||tjd|||q1t j|||d|dddd|D] }|j|dddq_|jd|jt d} |j| t|dS) NrTFrZs*dropping temporarily included sparse files. wantfiledata p1_tracked wc_trackedsAcleaned up %d temporarily added file(s) from the sparse checkout )r2r3existsstatusmodifiedaddedremoveddeletedmatcherrLmergemod mergeresultrhraddfile mergestatemod ACTION_REMOVEappend applyupdates update_fileunlinkrVrarr) r.s sparsematchrLmresultdropped tempincludesfilemessager=r(r(r)prunetemporaryincludess6    rcCs(dd|D}td|}t||gS)zqReturns a matcher that returns true for any of the forced includes before testing against the actual matcher.cSsg|]}d|dfqS)spathr()rGincluder(r(r)rJ/sz'forceincludematcher..r)matchmodincludematcher unionmatcher)r{r"kindpatsrr(r(r)forceincludematcher,s rc ststS|r |dgkrfddjD}t|d}d|dttj |f}j |}|r6|Sg}|D]*}zt |\}} } |sI| rZtj jdg|| dd } || Wq:tydYq:w|slt}nt|d krw|d }nt|}|rt} t|| }|j |<|S) zObtain a matcher for sparse working directories for the given revs. If multiple revisions are specified, the matcher is the union of all revs. ``includetemp`` indicates whether to use the temporary sparse profile. NcrBr(rCrFrIr(r)rJArKzmatcher..rnrU rsrelpath)rexcludedefaultrr)r2ralwaysrLrMr^rimapr bytestr_sparsematchercacherWrArrootrIOErrorrrrhr) r.rNrZr\keyresultmatchersr:r"r#r$r{rr(rIr)r{4sN            r{c CstsdSdd|D}t||}|rdSt}i}|r*t||g} nt||g} g} |D]b\} } | \} }}|| | | rO| || <n4| t j kr^| | | || <n%|rm| j sl| | | || <n| t j krw| || <n | |vrt j||f|| <|r| t j kr|\}}}}}| |s| |q8t| dkr|jtdt| t|| t}d}|d}| D]} | |vr|d| }|| t j|df|q|j/tj|||d|dddd |j}|t jgD] \} }}|j| d d d qWdn 1swYt|d }||@}|r_|s_|}|D]0} || }| | }|sO|rO|| }t j|dfd f|| <q.|r]|s]t jgd f|| <q.| |dS)zAFilter updates to only lay out files that match the sparse rules.NcSsg|]}|qSr()r:)rGpctxr(r(r)rJvsz(filterupdatesactions..rsCtemporarily included %d file(s) in the sparse checkout for merging s%temporarily adding to sparse checkoutFrorpTrrr)!r2rMr{rrp1r:filemaprr ACTION_MERGErno_op ACTION_FORGETrrrrvrrmr|r}manifestr~ ACTION_GETflagsrL parentchanger getactionsrrR setactions) r.wctxmctx branchmergeroldrevsoldsparsematchfiles prunedactionsrtemporaryfilesrr!typeargsr=f1f2famoveanctmresultr wctxmanifestfctxrLrr$changedprofilesmfoldnewr(r(r)filterupdatesactionsqs                      rcCsbt}||j||j||jt|}d}|D]}||s0|jtd|| }q|r:t td|j }|d} g} g} g} | } t| }t }|D]`}||}||}|rc|rk|r|r||vr| |}|j|r||tj|fd| |qU||tj|dfd| |qU|r|r|s|s||vr| |||vr||tjgdqUd}| D]}|jtd|| }q|rt tdt|D]\}}||vr||}||}|r|s| |qt j|||d|dddd| D] }|j|d d d q| D] }|j|ddd q| D] }|j|d d d d q| | | fS) a Refreshes working directory by taking sparse config into account. The old status and sparse matcher is compared against the current sparse matcher. Will abort if a file with pending changes is being excluded or included unless ``force`` is True. Fspending changes to '%s' s2could not update sparseness due to pending changesrorsjcannot change sparseness due to pending changes (delete the files or use --force to bring them back dirty)NrpTrr)rsrtpossibly_dirty)rr9rwrxryr{rrrrrrLrr|r}rwvfsrur~r ACTION_EXECrrrr iteritemsrr)r. origstatusorigsparsematchforcependingrabortfrLr;rxlookuprrrrrrrflstater(r(r) refreshwdirs           rcCsV||}t||d}|t|@r%|}t|}t|||ddt|dS)z1Perform actions after a working directory commit.rTrN)rAr:rrrvr{rr)r.rHr;r$rrr(r(r) aftercommitIs rc Cs||jd}t|j|d\}}} |} t|} t|j} tj | vr6|r6|j tj t |ntj | vrG|j tj t |zt||||t|| | |dWWdSty|j| kr{|j|j| O_t |t|||| w1swYdS)z5Update the sparse config and working directory state.r1rN)lockr3r4r*rrvr{rr SPARSE_REQUIREMENTdiscardr writereporequirementsrrfr Exceptionra) r.r"r#r$rremovingr oldincludes oldexcludes oldprofiles oldstatusoldmatch oldrequiresr(r(r)_updateconfigandrefreshwdirZs6            rc Cs|T|j6|jd}t|j|d\}}}|s.|s. WdWddSt|tt||dWdn1sCwYWddSWddS1s[wYdS)zClears include/exclude rules from the sparse config. The remaining sparse config only has profiles, if defined. The working directory is refreshed, as needed. r1Nr) wlockrLrr3r4r*rrr)r.rr r"r#r$r(r(r) clearruless Prc Cs||j|jd}t|j|d\}}}t|\}} } d} |D][} tj t | dd } | }Wdn1sAwYt|j|d\}}}t |t |t |}| ||| || | || t |t |t ||krd} q&d}}}d}| rt || }t ||}t || }tt t|||||d }t|j||||g|RWdn1swYWddSWddS1swYdS) zImport sparse config rules from files. The updated sparse config is written out and the working directory is refreshed, as needed. r1Fsrb)modeNTr)rrrr)rrLrr3r4r*rrRr posixfile expandpathreadrr9rr printchanges)r.optspathsrr r"r#r$ aincludes aexcludes aprofileschangedrcrb iincludes iexcludes iprofilesoldsize profilecount includecount excludecountfcountsr(r(r)importfromfilessJ          Prr(c  sjjd} tj| d\} } } |r,t}t}t}n t| }t| }t| }fdd}||}||}||}||}||}| || || || || || |t || t | |}t || t | |}t || t | |}t t t |||||d}tj||||g|RWdn1swYWdn1swYWddSWddS1swYdS)zuPerform a sparse config update. The new config is written out and a working directory refresh is performed. r1cstdd|Drttdr|Sj}}g}|D]-}t|d\}}|tjvs3|durH|r9|dndt |||}| |q | |q |S)Ncss|] }tj|VqdSrk)ospathisabs)rGpatr(r(r) sz7updateconfig..normalize_pats..spaths cannot be absolute:r) anyrrrrgetcwdr _patsplitcwdrelativepatternkindsr canonpathr)patsrcwdabspatskindpatkindrapr.usereporootpathsr(r)normalize_patss  z$updateconfig..normalize_pats)rrN)rrrLrr3r4r*rrdifference_updater9rrrr)r.rrrresetdelete enableprofiledisableprofilerr r oldinclude oldexcluder newinclude newexclude newprofilesr rrrrr(rr) updateconfigsh              Prc Cs|d|[}|||jdtd|||jdtd|||jdtd||sY||jdtd |||jd td |||jd td |WddSWddS1sdwYdS)z/Print output summarizing sparse config changes.r1sprofiles_addedsProfiles changed: %d sinclude_rules_addedsInclude rules changed: %d sexclude_rules_addedsExclude rules changed: %d s files_addedsFiles added: %d s files_droppedsFiles dropped: %d sfiles_conflictingsFiles conflicting: %d N) formatter startitem condwriteverboserisplain) rrrrrrxr conflictingfmr(r(r)r sH  "r)T)NT)F)FF)r(r(Fr(r(r(FF)rrrrrr)+ __future__rri18nrrHrrrrrr|r rr r r r rutilsrr2r*r0rArRr^rfrhrjrmrrr{rrrrrrrrr(r(r(r)sT   , F< % = se ) 4 _