Online Book Reader

Home Category

Mercurial_ The Definitive Guide - Bryan O'Sullivan [38]

By Root 890 0
between the previous and current versions of the file. For most text files, this is extremely efficient. However, some files (particularly binary files) are laid out in such a way that even a small change to a file’s logical content results in many or most of the bytes inside the file changing. For instance, compressed files are particularly susceptible to this. If the differences between each successive version of a file are always large, Mercurial will not be able to store the file’s revision history very efficiently. This can affect both local storage needs and the amount of time it takes to clone a repository.

To get an idea of how this could affect you in practice, suppose you want to use Mercurial to manage an OpenOffice document. OpenOffice stores documents on disk as compressed zip files. Edit even a single letter of your document in OpenOffice, and almost every byte in the entire file will change when you save it. Now suppose that file is 2MB in size. Because most of the file changes every time you save, Mercurial will have to store all 2MB of the file every time you commit, even though from your perspective, perhaps only a few words are changing each time. A single frequently edited file that is not friendly to Mercurial’s storage assumptions can easily have an outsized effect on the size of the repository.

Even worse, if both you and someone else edit the OpenOffice document you’re working on, there is no useful way to merge your work. In fact, there isn’t even a good way to tell what the differences are between your respective changes.

There are thus a few clear recommendations about specific kinds of files to be very careful with.

Files that are very large and incompressible, e.g., ISO CD-ROM images, will by virtue of sheer size make clones over a network very slow.

Files that change a lot from one revision to the next may be expensive to store if you edit them frequently, and conflicts due to concurrent edits may be difficult to resolve.

Backups and Mirroring

Since Mercurial maintains a complete copy of history in each clone, everyone who uses Mercurial to collaborate on a project can potentially act as a source of backups in the event of a catastrophe. If a central repository becomes unavailable, you can construct a replacement simply by cloning a copy of the repository from one contributor, and pulling any changes they may not have seen from others.

It is simple to use Mercurial to perform offsite backups and remote mirrors. Set up a periodic job (e.g., via the cron command) on a remote server to pull changes from your master repositories every hour. This will only be tricky in the unlikely case that the number of master repositories you maintain changes frequently, in which case you’ll need to do a little scripting to refresh the list of repositories to back up.

If you perform traditional backups of your master repositories to tape or disk, and you want to back up a repository named myrepo, use hg clone -U myrepo myrepo.bak to create a clone of myrepo before you start your backups. The -U option doesn’t check out a working directory after the clone completes, since that would be superfluous and make the backup take longer.

If you then back up myrepo.bak instead of myrepo, you will be guaranteed to have a consistent snapshot of your repository that won’t be pushed to by an insomniac developer in mid-backup.

Chapter 6. Collaborating with Other People

As a completely decentralized tool, Mercurial doesn’t impose any policy on how people ought to work with each other. However, if you’re new to distributed revision control, it helps to have some tools and examples in mind when you’re thinking about possible workflow models.

Mercurial’s Web Interface

Mercurial has a powerful web interface that provides several useful capabilities.

For interactive use, the web interface lets you browse a single repository or a collection of repositories. You can view the history of a repository, examine each change (comments and diffs), and view the contents of each directory and file. You

Return Main Page Previous Page Next Page

®Online Book Reader