Differences between revisions 2 and 3
Revision 2 as of 2011-10-24 00:05:59
Size: 3536
Comment: 2.0 or later
Revision 3 as of 2011-10-24 07:44:07
Size: 5666
Comment: Add hgext/largefiles/design.txt
Deletions are marked like this. Additions are marked like this.
Line 61: Line 61:
== Design ==

The extension is based off of Greg Ward's BfilesExtension.

=== The largefile store ===

largefile stores are, in the typical use case, centralized servers that have every past revision of a given binary file. Each largefile is identified by its SHA-1 hash, and all interactions with the store take one of the following forms.

 * Download a bfile with this hash
 * Upload a bfile with this hash
 * Check if the store has a bfile with this hash

largefiles stores can take one of two forms:

 * Directories on a network file share
 * Mercurial wireproto servers, either via ssh or http (hgweb)

=== The Local Repository ===

The local repository has a largefile store in '`.hg/largefiles`' which holds a subset of the largefiles needed. On a clone only the largefiles at tip are downloaded. When largefiles are downloaded from the central store, a copy is saved in this store.

=== The User Cache ===

largefiles in a local repository store are hardlinked to files in the user cache. Before a file is downloaded we check if it is in the global cache, hard-linking to the local store if we find it.

=== Implementation Details ===

Each largefile has a standin which is in '`.hglf.`' The standin is tracked by Mercurial. The standin contains the SHA-1 hash of the largefile. When a largefile is added/removed/copied/renamed/etc the same operation is applied to the standin. Thus the history of the standin is the history of the largefile.

For performance reasons, the contents of a standin are only updated before a commit. Standins are added/removed/copied/renamed from add/remove/copy/rename Mercurial commands but their contents will not be updated. The contents of a standin will always be the hash of the largefile as of the last commit. To support some commands (revert) some standins are temporarily updated but will be changed back after the command is finished.

A Mercurial dirstate object tracks the state of the largefiles. The dirstate uses the last modified time and current size to detect if a file has changed (without reading the entire contents of the file).

Largefiles extension

Large binary files tend to be not very compressible, not very "diffable", and not at all mergeable. Such files are not handled well by Mercurial's storage format (Revlog), which is based on compressed binary deltas. largefiles solves this problem by adding a centralized client-server layer on top of Mercurial: largefiles live in a central store out on the network somewhere, and you only fetch the ones that you need when you need them.

1. Status

This extension is distributed with Mercurial 2.0 and later.

Author: Various

2. Overview

The largefiles extension allows for tracking large, incompressible binary files in Mercurial without requiring excessive bandwidth for clones and pulls. Files added as largefiles are not tracked directly by Mercurial; rather, their revisions are identified by a checksum, and Mercurial tracks these checksums. This way, when you clone a repository or pull in changesets, the large files in older revisions of the repository are not needed, and only the ones needed to update to the current version are downloaded. This saves both disk space and bandwidth.

If you are starting a new repository or adding new large binary files, using largefiles for them is as easy as adding '--large' to your hg add command. For example:

$ dd if=/dev/urandom of=thisfileislarge count=2000
$ hg add --large thisfileislarge
$ hg commit -m 'add thisfileislarge, which is large, as a largefile'

When you push a changeset that affects largefiles to a remote repository, its largefile revisions will be uploaded along with it. Note that the remote Mercurial must also have the largefiles extension enabled for this to work.

When you pull a changeset that affects largefiles from a remote repository, nothing different from Mercurial's normal behavior happens. However, when you update to such a revision, any largefiles needed by that revision are downloaded and cached if they have never been downloaded before. This means that network access is required to update to revision you have not yet updated to.

If you already have large files tracked by Mercurial without the largefiles extension, you will need to convert your repository in order to benefit from largefiles. This is done with the 'hg lfconvert' command:

$ hg lfconvert --size 10 oldrepo newrepo

By default, in repositories that already have largefiles in them, any new file over 10MB will automatically be added as largefiles. To change this threshhold, set largefiles.size in your Mercurial config file to the minimum size in megabytes to track as a largefile:

[largefiles]
size = 2

or use the --lfsize option to the add command (also in megabytes):

$ hg add --lfsize 2

The largefiles.patterns config option allows you to specify specific space-separated filename patterns (in shell glob syntax) that should always be tracked as largefiles:

[largefiles]
patterns = *.jpg *.{png,bmp} library.zip content/audio/*

3. Configuration

Configure your config file to enable the extension by adding following lines:

[extensions]
largefiles =

4. Design

The extension is based off of Greg Ward's BfilesExtension.

4.1. The largefile store

largefile stores are, in the typical use case, centralized servers that have every past revision of a given binary file. Each largefile is identified by its SHA-1 hash, and all interactions with the store take one of the following forms.

  • Download a bfile with this hash
  • Upload a bfile with this hash
  • Check if the store has a bfile with this hash

largefiles stores can take one of two forms:

  • Directories on a network file share
  • Mercurial wireproto servers, either via ssh or http (hgweb)

4.2. The Local Repository

The local repository has a largefile store in '.hg/largefiles' which holds a subset of the largefiles needed. On a clone only the largefiles at tip are downloaded. When largefiles are downloaded from the central store, a copy is saved in this store.

4.3. The User Cache

largefiles in a local repository store are hardlinked to files in the user cache. Before a file is downloaded we check if it is in the global cache, hard-linking to the local store if we find it.

4.4. Implementation Details

Each largefile has a standin which is in '.hglf.' The standin is tracked by Mercurial. The standin contains the SHA-1 hash of the largefile. When a largefile is added/removed/copied/renamed/etc the same operation is applied to the standin. Thus the history of the standin is the history of the largefile.

For performance reasons, the contents of a standin are only updated before a commit. Standins are added/removed/copied/renamed from add/remove/copy/rename Mercurial commands but their contents will not be updated. The contents of a standin will always be the hash of the largefile as of the last commit. To support some commands (revert) some standins are temporarily updated but will be changed back after the command is finished.

A Mercurial dirstate object tracks the state of the largefiles. The dirstate uses the last modified time and current size to detect if a file has changed (without reading the entire contents of the file).

5. See also

There are a number of older extensions for managing large files. This extension is a descendant of the BfilesExtension and is now the recommended way to handle such files. Alternatives are BigfilesExtension and SnapExtension.


CategoryBundledExtension

LargefilesExtension (last edited 2017-01-10 15:03:55 by CharlesB)