{"id":1215,"date":"2011-01-26T19:59:55","date_gmt":"2011-01-27T00:59:55","guid":{"rendered":"http:\/\/unitstep.net\/?p=1215"},"modified":"2011-01-26T20:09:10","modified_gmt":"2011-01-27T01:09:10","slug":"folding-changesets-with-the-mercurial-queues-extension","status":"publish","type":"post","link":"https:\/\/unitstep.net\/blog\/2011\/01\/26\/folding-changesets-with-the-mercurial-queues-extension\/","title":{"rendered":"Folding changesets with the Mercurial Queues extension"},"content":{"rendered":"

\"\"<\/p>\n

Mercurial is my distributed revision control system of choice, a trait I picked up at my previous job. I haven’t had the opportunity to deal with Git for any period of time, so I can’t comment on the various “Why X is better than Y<\/a>” arguments<\/a> out there<\/a>. <\/p>\n

Most of you using Mercurial\/Hg (or revision control in general) will be familiar with the concept of merging<\/em>, where the changes in a source branch are merged into a target branch, creating a new revision or changeset on the target branch. But what about the times when you would like to combine two or more changesets\/revisions into a single one that has the combined\/overall changes of all of them? In that case, the Mercurial Queues extension provides for the concept of folding<\/em>, which accomplishes just that.<\/p>\n

<\/p>\n

Mercurial Queues<\/h2>\n

The Mercurial Queues extension<\/a> (mq<\/strong>) is one of the most useful Hg extensions available, as it allows for much more<\/a> than folding. Basically, mq allows you to import changesets to a patch queue<\/em>, where they can be manipulated. In this way, previously immutable changesets can be modified. One such modification is the concept of folding<\/em>, where one more more changesets are combined to produce a single changeset with the equivalent effect.<\/p>\n

Proceed with caution<\/h2>\n

Because mq can directly modify changesets (i.e. revision history), it can have adverse on your Hg repository; data can be permanently lost, since the changes that can be made cannot be “backed out” or “reverted”. I strongly recommend cloning your Hg repo before undertaking any actions with Mercurial Queues for the first time<\/strong>, if only for peace of mind and the fact that cloning is such an easy operation with Mercurial.<\/p>\n

The case for folding<\/h2>\n

Generally, it’s not a good idea to go and change revision history, which is what folding does. The purpose of revision control is to preserve<\/em> history and provide a timeline for how the codebase has evolved. In the case of Mercurial, it’s especially troublesome to go and modify revision history on a central server that others are pushing to\/pulling from, as this may cause inconsistencies. Having said that, there are times when combining multiple changesets into one may be beneficial.<\/p>\n

Some examples that come to mind are:<\/p>\n