A beginner’s guide to Mercurial for Firefox development

I came across Mercurial when I first started contributing code to Firefox. Mercurial is a version control software like Git, CVS, etc. The Firefox code base is version controlled using Mercurial which means that if you’re interested in contributing code to Firefox, it’s a good idea to get acquainted with Mercurial first.

In this blog post, I talk about a few Mercurial commands with a focus on Firefox development. This should help you get started with Mercurial quickly and save you the time spent in figuring out what to learn on the web.

If you’ve built Firefox on your machine using the bootstrap.py file, you should already have Mercurial installed and configured for Firefox development.

So, here are a few commands to help you get started:

1. hg diff

This command is used to see all the changes you have made to different files in the code base after you’ve saved the changes. It displays the file names along with any uncommitted changes you have made to a file.

2. hg wip

What a ‘hg wip’ output looks like

This command gives you a tree view of your work in progress. It helps keep track of all the changesets you have created while working on different bugs. A changeset in Mercurial is a collection of changes to files in the code base. It is identified using a changeset ID. A changeset can be created by committing your local file changes.

3. hg commit

This command is used to consolidate all your different file changes into a changeset. I suggest using this command with the -m flag if you don’t want to enter into editor mode and get stuck trying to figure out how to exit vi or vim. Here’s how you can do that:

hg commit -m”commit_message_goes_here”

or

hg commit — amend -m”new_commit_message_goes_here”

The ‘amend’ option is used to update a changeset.

4. hg up <changesetID>

This command is used to navigate between changesets when you’re working on many bugs at once. It can be used with the ‘hg wip’ command to switch between different changesets.

5. hg push review

This command is used to submit a changeset for review. You can submit a changeset for review by first navigating to that changeset by using ‘hg up <changesetID>’ and then using ‘hg push review’. Before you can submit your patches for review using ‘hg push review’, you have to configure your machine to use MozReview.

6. hg export

This command is used to generate a patch file. You can save the generated patch file by doing:

hg export > file.txt

However, if you’re using MozReview, it’s not necessary to generate a patch file. In that case, ‘hg export’ can be used to simply view the patch file in your terminal.

7. hg pull central

This command is used to pull the latest changes that have landed on central onto your local machine, between when you last updated your local code base and now.

8. hg rebase

This command is used to take a changeset that has been committed on top of an older version of your local code base and put it on top of the latest version you have pulled. It is usually used after ‘hg pull central’ to place a changeset on top of the latest changes. Here’s how you can use it:

hg rebase -s <changesetID> -d central

-s flag notes the source changeset ID and -d flag notes the destination changeset ID. Mercurial tags like ‘central’, ‘tip’, etc. can be used in place of changeset IDs.

9. hg add <path>

This command is used to add new files or folders to the repository.

10. hg remove <path>

This command is used to remove files or folders from the repository and also erase it on disk.

11. hg forget <path>

This command is used to remove files or folders from the repository without actually erasing it on disk.

That is it for this blog post. I hope that this blog post has given you a good enough idea about Mercurial to get started with Firefox development. Happy coding!