lfs

Contents

lfs - large file support (EXPERIMENTAL)

Description

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

Commands