Maintaining a Mercurial Repository
You should do regular maintenance of your Mercurial repository to reduce its size. If you imported code from another version control system, you may need to clean up unnecessary files after the import. This explains how to reduce repository size by removing large files from a Mercurial repo and contains the following topics:
Another technique to reduce repository size is to split the repository into multiple smaller ones. This could be run for each directory in the repository, which will create sub-repositories for each one. To learn more about splitting repositories, see Split a repository in two.
How to Find Large Files
Large files are typically things like third-party libraries (jars, dlls), compiled versions of your applications, and binary media assets (such as image files). Keep in mind that Mercurial usually saves differences between files. A small change to a binary file's content can cause many or most of the file's bytes to change. Committing a change to binary files potentially causes Mercurial to store the entire or most of a large file multiple times.
In a Linux Environment
To find large files in a Linux environment, use the following piped command:
This command ignores hidden files and directories. For example, the command ignores everything in the the
.hg directory. It sorts the output of the
ls by size and uses the
head command to return the ten largest files. For example, right now the Bitbucket tutorial repo has these large files:
In a Windows Environment
In a Windows environment, we recommend using PowerShell. To open PowerShell in Windows 7, do the following:
- Click the Start button.
- Begin typing
Powershellin the Search programs and files field.
- Select the Windows PowerShell option.
The Powershell command window opens.
- Change to the root of your repository.
Enter the following at the command prompt:
This command lists all the repo's files excluding those in the
.hg(metadata) directory. The system lists output similar to the following:
Removing Large Files
To remove large files, you use the
convert extension and
--filemap option. The
convert extension filters a repository and creates a new repository with a parallel history. The
--filemap option takes a
filemap file that specifies filters for file processing. During the conversion process the convert extension uses the
filemap to modify the changesets it processes. You can use the filemap to include, rename, or exclude individual files or whole directories.
For example, the following shows the a simple set of
For the detailed information about the
convert extension and the
--filemap option, see the
ConvertExtension --filemap documentation.
Example of using convert to reduce repository files
Consider the following directory structure in a repository:
To remove all libraries except
commons-lang and retain all Javadoc except the one for
commons-io you create the following
filemap.txt file in the repository root:
Then, to convert the structure, you would issue the following command at the command line:
initialHgRepo is the repository to convert and the
hgRepoAfterConversion is the new repository. After the conversion,
hgRepoAfterConversion repository structure is:
You can then check in the
Was this helpful?
Thanks for your feedback!