o ]Lb99@sPdZddlmZddlZddlmZddlmZddlm Z m Z m Z m Z m Z mZmZmZmZmZmZmZmZmZmZmZddlmZdd lmZmZmZd ZeZ e !ej e !ej e j"Z"e j#Z#e j$Z%e j&Z'e j(Z(e j)Z*e j+Z+e j,d d d de j,d ddde j,d ddde j,d dd de j,dddde j,dddde j,dddde j,dddde j,ddddej-ej.ej/fZ0ddZ1e j'ddZ2e j*dd Z3d!d"Z4d#d$Z5e 6ed%d&d'Z7e j%d(d)Z8e (d*d+d,Z9e j+d-d.hd/d0d1Z:e ;d2d3d4ged5fgd6d7ZZ>dS)?alfs - large file support (EXPERIMENTAL) This extension allows large files to be tracked outside of the normal repository storage and stored on a centralized server, similar to the ``largefiles`` extension. The ``git-lfs`` protocol is used when communicating with the server, so existing git infrastructure can be harnessed. Even though the files are stored outside of the repository, they are still integrity checked in the same manner as normal files. The files stored outside of the repository are downloaded on demand, which reduces the time to clone, and possibly the local disk usage. This changes fundamental workflows in a DVCS, so careful thought should be given before deploying it. :hg:`convert` can be used to convert LFS repositories to normal repositories that no longer require this extension, and do so without changing the commit hashes. This allows the extension to be disabled if the centralized workflow becomes burdensome. However, the pre and post convert clones will not be able to communicate with each other unless the extension is enabled on both. To start a new repository, or to add LFS files to an existing one, just create an ``.hglfs`` file as described below in the root directory of the repository. Typically, this file should be put under version control, so that the settings will propagate to other repositories with push and pull. During any commit, Mercurial will consult this file to determine if an added or modified file should be stored externally. The type of storage depends on the characteristics of the file at each commit. A file that is near a size threshold may switch back and forth between LFS and normal storage, as needed. Alternately, both normal repositories and largefile controlled repositories can be converted to LFS by using :hg:`convert` and the ``lfs.track`` config option described below. The ``.hglfs`` file should then be created and added, to control subsequent LFS selection. The hashes are also unchanged in this case. The LFS and non-LFS repositories can be distinguished because the LFS repository will abort any command if this extension is disabled. Committed LFS files are held locally, until the repository is pushed. Prior to pushing the normal repository data, the LFS files that are tracked by the outgoing commits are automatically uploaded to the configured central server. No LFS files are transferred on :hg:`pull` or :hg:`clone`. Instead, the files are downloaded on demand as they need to be read, if a cached copy cannot be found locally. Both committing and downloading an LFS file will link the file to a usercache, to speed up future access. See the `usercache` config setting described below. The extension reads its configuration from a versioned ``.hglfs`` configuration file found in the root of the working directory. The ``.hglfs`` file uses the same syntax as all other Mercurial configuration files. It uses a single section, ``[track]``. The ``[track]`` section specifies which files are stored as LFS (or not). Each line is keyed by a file pattern, with a predicate value. The first file pattern match is used, so put more specific patterns first. The available predicates are ``all()``, ``none()``, and ``size()``. See "hg help filesets.size" for the latter. Example versioned ``.hglfs`` file:: [track] # No Makefile or python file, anywhere, will be LFS **Makefile = none() **.py = none() **.zip = all() **.exe = size(">1MB") # Catchall for everything not matched above ** = size(">10MB") Configs:: [lfs] # Remote endpoint. Multiple protocols are supported: # - http(s)://user:pass@example.com/path # git-lfs endpoint # - file:///tmp/path # local filesystem, usually for testing # if unset, lfs will assume the remote repository also handles blob storage # for http(s) URLs. Otherwise, lfs will prompt to set this when it must # use this value. # (default: unset) url = https://example.com/repo.git/info/lfs # Which files to track in LFS. Path tests are "**.extname" for file # extensions, and "path:under/some/directory" for path prefix. Both # are relative to the repository root. # File size can be tested with the "size()" fileset, and tests can be # joined with fileset operators. (See "hg help filesets.operators".) # # Some examples: # - all() # everything # - none() # nothing # - size(">20MB") # larger than 20MB # - !**.txt # anything not a *.txt file # - **.zip | **.tar.gz | **.7z # some types of compressed files # - path:bin # files under "bin" in the project root # - (**.php & size(">2MB")) | (**.js & size(">5MB")) | **.tar.gz # | (path:bin & !path:/bin/README) | size(">1GB") # (default: none()) # # This is ignored if there is a tracked '.hglfs' file, and this setting # will eventually be deprecated and removed. track = size(">10M") # how many times to retry before giving up on transferring an object retry = 5 # the local directory to store lfs files for sharing across local clones. # If not set, the cache is located in an OS specific cache location. usercache = /path/to/global/cache )absolute_importN)_)bin) bundlecachesconfigcontexterror extensions exthelperfilelog filesetlang localrepo logcmdutil minifilesetpycompatrevlogscmutil templateutilutil) repository) blobstorewireprotolfsserverwrappersships-with-hg-cores experimentals lfs.serveT)defaultslfs.user-agentslfs.disableusercacheFslfs.worker-enablelfssurls usercache thresholdtracksnone()sretrycCs|dhO}dS)Nr)ui supportedrr4/usr/lib/python3/dist-packages/hgext/lfs/__init__.py featuresetupsr#cCstjtdSN)r featuresetupfuncsaddr#r rrr"_uisetupsr(cssdStj_tj_Gfdddj_djvr>dd}|dd|d|dd|ddSj dt j dS) Ncs(eZdZejdfdd ZZS)z_reposetup..lfsrepoFNcs&t|jjd<t|j|||dS)Nslfstrack)origctx)_trackedmatchersvfsoptionssuper commitctx)selfctxrr)) __class__lfsreporeporr"r.sz%_reposetup..lfsrepo.commitctx)FN)__name__ __module__ __qualname__r unfilteredmethodr. __classcell__rr2r3)r1r"r2sr2rcs|pd|jvr WddS|d}|r(|dt|dt|}n |dt|d}|j|D],tfddDrc|jd|j t j t ||jdtjn q7WddSWddS1swwYdS) Nrr node_lasts%n:%nnodes%nc3s,|]}|vr|r|VqdSr$)islfs).0fr0matchrr" s z7_reposetup..checkrequireslfs..)lock requirementsgetsetr_storenarrowmatchanyfilesr&featuresrREPO_FEATURE_LFSrwritereporequirementsprepushoutgoinghooksrprepush)r r3kwargslastsrr?r"checkrequireslfss.     "z$_reposetup..checkrequireslfsshookss commit.lfsspretxnchangegroup.lfs) localrr+lfslocalblobstoreremotelfsremoteblobstorer1rC setconfigrLr&rrM)r r3rQrr9r" _reposetups rWc s|jds&|jdd}|jdd}|r!t|d||f}t|S|j d}|s2ddSt}|d|z dd | dDWnt j y^}z t td |d }~wwfd d }|S)zdReturn a function (path, size) -> bool indicating whether or not to track a given file with lfs.s.hglfsrrrs(%s) | size('>%d')cSsdSNFr)prPrrr"4sz!_trackedmatcher..cSs$g|]\}}t|t|fqSr)rcompile)r=patternrulerrr" <sz#_trackedmatcher..sparse error in .hglfs: %sNcs*D]\}}|||r|||SqdSrXr)pathsizepatr]rulesrr"_matchGs  z_trackedmatcher.._match)wvfsexistsr r configbytesr parserr[tryreaditemsr ParseErrorAbortr)r3 trackspec thresholddatacfgerdrrbr"r*#s,        r*cCs4tj}||dtj||dtj||dtjdS)N addrevisionrenamedr`)r wrapfunctionrfilelogaddrevisionfilelogrenamed filelogsize)r rtrrr" wrapfilelogRsrxsresolverevlogstorevfsoptionscCsl||||}t|D](\}}|tjtur3tj|dvr)tdtj}t|t |dtj<|Sq |S)Nsflagprocessorss2cannot register multiple processors on flag '%#x'.) r sysmodulesr4rREVIDX_EXTSTOREDrrrl lfsprocessor)origr rCrIoptsnamemodulemsgrrr"_resolverevlogstorevfsoptionsZs   rcCs6ttjtjtj_tj dtj dt j dd<dS)Nrs03sv2s cg.version) rxr r filectxislfsr basefilectxr<rfileprefetchhooksr&_prefetchfilesr_bundlespeccontentoptsr'rrr" _extsetupls  rslfs()cs4t|ddtd|jfdd}|j|ddS)zFile that uses LFS storage.rslfs takes no argumentscstj|ddduS)NTremoved)rpointerfromctx)r>r0rr"lfsfilepszlfsfileset..lfsfileps)predrepr)r getargsrr0 predicate)mctxxrrrr" lfsfilesetzs rs lfs_filesctx)requirescsb||d}tj|ddt}fddfdd}t||d|}t|||tj S) zMList of strings. All files modified, added, or removed by this changeset.rTrcs(dd}tt||d}t|S)NcSs|ddk|fS)Nrsversionr)rrrr"rZsz+lfsfiles..pointer..)key)sortedr iteritemsrsortdict)v sortkeyfuncrj)pointersrr"pointers zlfsfiles..pointercs*||r |ndt|dS)N)sfileslfsoids lfspointer)oidr hybriddict)rrrrr"rZs zlfsfiles..slfs_file) resourcerpointersfromctxrkeysr_showcompatlisthybridridentity)rmappingr0rHmakemapr>rrr"lfsfiless   rsdebuglfsuploadrsrevs$upload large files introduced by REVcKs0|dg}t|t||}t||dS)zDupload lfs blobs added by the working copy parent or given revisionsrevN)rDrextractpointersrrevrange uploadblobs)r r3r~revsrrrr"debuglfsuploads rverifysno-lfssskip missing lfs blob content)r~cKs|jdd}|d}|r|dur|tjM}nd}|dur$|tjO}|d|i|||fi|WdS1s?wYdS)Nr skipflagsno_lfsFrT)rr)r configintpoprREVISION_FLAG_EXTSTOREDconfigoverride)r}r r3r~ skipflagsrrrr"verifys   $r)?__doc__ __future__rrymercurial.i18nrmercurial.noder mercurialrrrrr r r r r rrrrrrrmercurial.interfacesrrrr testedwithehmergecmdtable configtable finalextsetupextsetup finaluisetupuisetupfilesetpredicatefinalreposetup reposetuptemplatekeyword configitem readfromstore writetostorebypasscheckhashr|r#r(rWr*rxrtrrrrcommandr wrapcommandrrrrr"s s  H      2/