o ]Lb9@sdZddlmZddlmZddlmZddlmZm Z m Z m Z m Z m Z mZmZmZmZmZmZdZiZeeZddZd d Zd d Zd dZddZddZddZedddgededfddgededfddgededfd d!d"ed#fd$d%ged&edfd$d'ged(edfd$d)ged*edfd$d+d"ed,fd$d-d"ed.fd$d/d"ed0fg e j ed1d2d3d4d5Z!d6S)7aG allow sparse checkouts of the working directory (EXPERIMENTAL) (This extension is not yet protected by backwards compatibility guarantees. Any aspect may break in future releases until this notice is removed.) This extension allows the working directory to only consist of a subset of files for the revision. This allows specific files or directories to be explicitly included or excluded. Many repository operations have performance proportional to the number of files in the working directory. So only realizing a subset of files in the working directory can improve performance. Sparse Config Files ------------------- The set of files that are part of a sparse checkout are defined by a sparse config file. The file defines 3 things: includes (files to include in the sparse checkout), excludes (files to exclude from the sparse checkout), and profiles (links to other config files). The file format is newline delimited. Empty lines and lines beginning with ``#`` are ignored. Lines beginning with ``%include `` denote another sparse config file to include. e.g. ``%include tests.sparse``. The filename is relative to the repository root. The special lines ``[include]`` and ``[exclude]`` denote the section for includes and excludes that follow, respectively. It is illegal to have ``[include]`` after ``[exclude]``. Non-special lines resemble file patterns to be added to either includes or excludes. The syntax of these lines is documented by :hg:`help patterns`. Patterns are interpreted as ``glob:`` by default and match against the root of the repository. Exclusion patterns take precedence over inclusion patterns. So even if a file is explicitly included, an ``[exclude]`` entry can remove it. For example, say you have a repository with 3 directories, ``frontend/``, ``backend/``, and ``tools/``. ``frontend/`` and ``backend/`` correspond to different projects and it is uncommon for someone working on one to need the files for the other. But ``tools/`` contains files shared between both projects. Your sparse config files may resemble:: # frontend.sparse frontend/** tools/** # backend.sparse backend/** tools/** Say the backend grows in size. Or there's a directory with thousands of files you wish to exclude. You can modify the profile to exclude certain files:: [include] backend/** tools/** [exclude] tools/tests/** )absolute_import)_)setattr) cmdutilcommandsdirstateerror extensions logcmdutilmatchmergepycompat registrarsparseutilsships-with-hg-corecCs*dt_t|t|t|t|dS)NT)renabled _setupclone _setuplog _setupadd_setupdirstate)uir./usr/lib/python3/dist-packages/hgext/sparse.pyextsetupgs  rcCsp|}t|sJ|tur(||jvr|j|}t||||n |jd}|tus |tur6ttd||fdS)ziReplace a filecache property with a new class. This allows changing the cache invalidation condition.rstype '%s' has no property '%s'N)callableobject__dict__r __bases__AttributeErrorr)clspropname replacementorigclsorigrrrreplacefilecacheps    r$cCs2tjd}|dddd}ttd|dS)Ns log|history)sparseNs1limit to changesets affecting the sparse checkoutcs<||}|jdrtfdd}||}|S)Nr'cs"|}tfdd|DS)Nc3s|] }|r|VqdSNr.0f) sparsematchrr szD_setuplog.._initialrevs..ctxmatch..)anyfiles)revctxrepor,rrctxmatchsz1_setuplog.._initialrevs..ctxmatch)optsgetrmatcherfilter)r#r3woptsrevsr4rr2r _initialrevss    z_setuplog.._initialrevss _initialrevs)rtableappendr wrapfunctionr )rentryr;rrrrs   rcsn|d|d|d|d}|s+ssr+fdd}ttd||||g|Ri|S)Nincludeexcludeenable_profilenarrowcs4tj|idd||g|Ri|S)NT)r@rA enableprofileusereporootpaths)r updateconfigr3 unfiltered)r#r1argskwargsrDrAr@rr clonesparses z$_clonesparsecmd..clonesparsesupdate)r6r r>mergemod)r#rr3rHr5 narrow_patrKrrJr_clonesparsecmds     rNcCs`tjd}|dddgdf|dddgdf|dddgd fttjdtdS) Nscloner%r&enable-profilesenable a sparse profileincludesinclude sparse patternexcludesexclude sparse pattern)rr<r=r wrapcommandrN)rr?rrrrs rcCs4tjd}|dddd}ttjd|dS)Nsaddr%)sr'Ns8also include directories of added files in sparse configc _s^|dr#t}|D]}t|\}}||q tj||t|d|||g|Ri|S)Nr)r@)r6setrsplitaddrrFlist) r#rr3patsr5dirspatdirnamebasenamerrr_adds  z_setupadd.._add)rr<r=r rR)rr?r]rrrrs   rcsnd dd}ttjd|ddd}ttjd|gd }td |D]}fd d }ttj||q$dS)z|Modify the dirstate to prevent stat'ing excluded files, and to prevent modifications to files outside the checkout. Tc Ss<t|}t|j|g}t||}|||||||Sr()matchmodexactr/ unionmatcher_sparsematcherintersectmatchers) r#selfr subreposunknownignoredfullemsmrrrwalks z_setupdirstate..walkswalkNcsh|js-fdd|D}|rfdd|D}|dur-fdd|D}||}|||||S)Ncg|]}|r|qSrrr)r7rr z4_setupdirstate.._rebuild..crkrrr)rlrrrmrncsh|]}|s|qSrrr)rlrr rnz3_setupdirstate.._rebuild..)raalwaysunion)r#rcparentallfiles changedfilesdirstatefilestoremoverrlr_rebuilds z _setupdirstate.._rebuildsrebuild)s set_trackeds set_untrackedscopyswinclude file with `hg debugsparse --include ` or use `hg add -s ` to include file directory while addingcs\|j}|s#|D]}|dur"||s"||vr"tjtd|dq ||g|Ri|S)Ns3cannot add '%s' - it is outside the sparse checkouthint)rarprAbortr)r#rcrHrIr,r+rwrr_wrappersz _setupdirstate.._wrapper)Tr()r r>rr)rrjrv editfuncsfuncrzrrwrrs   rs debugsparseIrPs$include files in the sparse checkoutsPATTERNXrQs$exclude files in the sparse checkoutddeletesdelete an include/exclude rulefforceFs.allow changing rules even with pending changesr&rOsenables the specified profilesdisable-profilesdisables the specified profiles import-rulessimports rules from a files clear-ruless"clears local include/exclude rulesrefreshs,updates the working after sparseness changesresetsmakes the repo full agains [--OPTION]T) helpbasicc Kst|}|d}|d}|d}|d}|d}|d}|d} |d} |d } |d } t|ddd } t|pK|pK| pK| pK|pK|}t|t| g}|d kr`tt d |d kr|j dr| |j ddt|}|r| t d| d|ddStt d|rtj||||| | |||d |rtj||||d| rtj||d| rz,|}tttj|| t||d}tj|||d |d |ddW|dS|wdS)amake the current checkout sparse, or edit the existing checkout The sparse command is used to make the current checkout sparse. This means files that don't meet the sparse condition will not be written to disk, or show up in any working copy operations. It does not affect files in history in any way. Passing no arguments prints the currently applied sparse rules. --include and --exclude are used to add and remove files from the sparse checkout. The effects of adding an include or exclude rule are applied immediately. If applying the new rule would cause a file with pending changes to be added or removed, the command will fail. Pass --force to force a rule change even with pending changes (the changes on disk will be preserved). --delete removes an existing include/exclude rule. The effects are immediate. --refresh refreshes the files on disk based on the sparse rules. This is only necessary if .hg/sparse was changed by hand. --enable-profile and --disable-profile accept a path to a .hgsparse file. This allows defining sparse checkouts and tracking them inside the repository. This is useful for defining commonly used sparse checkouts for many people to use. As the profile definition changes over time, the sparse checkout will automatically be updated appropriately, depending on which changeset is checked out. Changes to .hgsparse are not applied until they have been committed. --import-rules accepts a path to a file containing rules in the .hgsparse format, allowing you to add --include, --exclude and --enable-profile rules in bulk. Like the --include, --exclude and --enable-profile switches, the changes are applied immediately. --clear-rules removes all local include and exclude rules, while leaving any enabled profiles in place. Returns 0 if editing the sparse checkout succeeds. rPrQrsenable_profilesdisable_profiles import_ruless clear_rulesrrrr%stoo many flags specifiedrr' s/Temporarily Included Files (for merge/rebase): Ns@the debugsparse command is only supported on sparse repositories)r@rAresetdeleterDdisableprofileforce)r)addeddropped conflicting)r byteskwargsr6rcheck_at_most_one_argboolsumrryrvfsexistsstatusreadrreadtemporaryincludesjoinrFimportfromfiles clearruleswlockmaplen refreshwdirr7 printchangesrelease)rr3r5r@rArrDr importrulesrrrefreshractionrFcounttemporaryincludesrfcountsrrr debugsparses i             rN)"__doc__ __future__rmercurial.i18nrmercurial.pycompatr mercurialrrrrr r r r^r rLr rrr testedwithcmdtablecommandrr$rrNrrr templateoptsrrrrrs B  8  ?:;@