Online Book Reader

Home Category

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

By Root 982 0
’s not difficult to accumulate a large number of patches. For example, I have one patch repository that contains over 250 patches.

If you can group these patches into separate logical categories, you can store them in different directories if you like; MQ has no problems with patch names that contain path separators.

Viewing the History of a Patch

If you’re developing a set of patches over a long time, it’s a good idea to maintain them in a repository, as discussed in Managing Patches in a Repository. If you do so, you’ll quickly discover that using the hg diff command to look at the history of changes to a patch is unworkable. This is in part because you’re looking at the second derivative of the real code (a diff of a diff), but also because MQ adds noise to the process by modifying timestamps and directory names when it updates a patch.

However, you can use the extdiff extension, which is bundled with Mercurial, to turn a diff of two versions of a patch into something readable. To do this, you will need a third-party package called patchutils. This provides a command named interdiff, which shows the differences between two diffs as a diff. Used on two versions of the same diff, it generates a diff that represents the diff from the first to the second version.

You can enable the extdiff extension in the usual way, by adding a line to the extensions section of your ~/.hgrc.

[extensions]

extdiff =

The interdiff command expects to be passed the names of two files, but the extdiff extension passes the program it runs a pair of directories, each of which can contain an arbitrary number of files. We thus need a small program that will run interdiff on each pair of files in these two directories. This program is available as hg-interdiff in the examples directory of the source code repository that accompanies this book.

With the hg-interdiff program in your shell’s search path, you can run it as follows, from inside an MQ patch directory:

hg extdiff -p hg-interdiff -r A:B my-change.patch

Since you’ll probably want to use this long-winded command a lot, you can get hgext to make it available as a normal Mercurial command, again by editing your ~/.hgrc.

[extdiff]

cmd.interdiff = hg-interdiff

This directs hgext to make an interdiff command available, so you can now shorten the previous invocation of extdiff to something a little more wieldy.

hg interdiff -r A:B my-change.patch

* * *

Note


The interdiff command works well only if the underlying files against which versions of a patch are generated remain the same. If you create a patch, modify the underlying files, and then regenerate the patch, interdiff may not produce useful output.

* * *

The extdiff extension is useful for more than merely improving the presentation of MQ patches. To read more about it, go to Flexible Diff Support with the extdiff Extension.

Chapter 14. Adding Functionality with Extensions

While the core of Mercurial is quite complete from a functionality standpoint, it’s deliberately shorn of fancy features. This approach of preserving simplicity keeps the software easy to deal with for both maintainers and users.

However, Mercurial doesn’t box you in with an inflexible command set: you can add features to it as extensions (sometimes known as plug-ins). We’ve already discussed a few of these extensions in earlier chapters.

Simplifying the Pull-Merge-Commit Sequence covers the fetch extension; this combines pulling new changes and merging them with local changes into a single command, fetch.

In Chapter 10, we covered several extensions that are useful for hook-related functionality: acl adds access control lists; bugzilla adds integration with the Bugzilla bug tracking system; and notify sends notification emails on new changes.

The Mercurial Queues patch management extension is so invaluable that it merits two chapters and an appendix all to itself. Chapter 12 covers the basics; Chapter 13 discusses advanced topics; and Appendix B goes into detail on each command.

In this chapter, we’ll cover

Return Main Page Previous Page Next Page

®Online Book Reader