Mercurial-evolve

Assume you're preparing a small feature but it is bigger than reasonably fits a single commit. While there is mercurial queues (mq), it is nicer to work with actual commits. One way to deal with the situation is to use the mutable history extension, also known as evolve.

Evolve is not yet shipped with mercurial (you can get it from https://bitbucket.org/marmoute/mutable-history) and you need to activate it in your .hgrc by

[extensions]
evolve = /path/to/evolve.py

How can it help you with your daily work?

Assume you prepare a small feature:

hg commit -m "-Codechange: Simplify some stuff" 
(edit some other stuff)
hg commit -m "-Add: New cool feature, possible only due to previous commit" 
hg log -G
@  changeset:   2:ef728218c6c5
|  tag:         tip
|  user:        planetmaker <planetmaker@openttd.org>
|  date:        Thu Apr 17 14:22:31 2014 +0200
|  summary:     -Add: New cool feature
|
o  changeset:   1:227c690a1822
|  user:        planetmaker <planetmaker@openttd.org>
|  date:        Thu Apr 17 14:22:05 2014 +0200
|  summary:     -Codechange: Introduce foo in preparation for cool stuff
|
o  changeset:   0:4cd637edd9b5
   user:        planetmaker <planetmaker@openttd.org>
   date:        Thu Apr 17 14:20:58 2014 +0200
   summary:     -Add: Initial check-in

And now you notice "oh, bugger, I made a mistake in the codechange, I need to fix it. If you haven't yet pushed your changes, evolve can help you to fix changeset 1:

hg up 1
0 files updated, 0 files merged, 1 files removed, 0 files unresolved

(make your changes as necessary)
hg commit --amend
1 new unstable changesets
hg log -G
@  changeset:   4:0602f70b6892
|  tag:         tip
|  parent:      0:4cd637edd9b5
|  user:        planetmaker <planetmaker@openttd.org>
|  date:        Thu Apr 17 14:22:05 2014 +0200
|  summary:     -Codechange: Introduce foo in preparation for cool stuff
|
| o  changeset:   2:ef728218c6c5
| |  user:        planetmaker <planetmaker@openttd.org>
| |  date:        Thu Apr 17 14:22:31 2014 +0200
| |  summary:     -Add: New cool feature
| |
| x  changeset:   1:227c690a1822
|/   user:        planetmaker <planetmaker@openttd.org>
|    date:        Thu Apr 17 14:22:05 2014 +0200
|    summary:     -Codechange: Introduce foo in preparation for cool stuff
|
o  changeset:   0:4cd637edd9b5
   user:        planetmaker <planetmaker@openttd.org>
   date:        Thu Apr 17 14:20:58 2014 +0200
   summary:     -Add: Initial check-in

So now you have fixed your commit no.1 which is now present as commit no.4. But the actual feature commit (no.2) now is based on an outdated (obsolete) changeset (no.1, obsolescence indicated by the 'x' in the tree) and commit no.2 needs re-basing on no.4, your now updated codechange commit. Fortunately that's very easy:

hg evolve
move:[2] -Add: New cool feature
atop:[4] -Codechange: Introduce foo in preparation for cool stuff
hg log -G
@  changeset:   5:888a9a6be6b3
|  tag:         tip
|  user:        planetmaker <planetmaker@openttd.org>
|  date:        Thu Apr 17 14:22:31 2014 +0200
|  summary:     -Add: New cool feature
|
o  changeset:   4:0602f70b6892
|  parent:      0:4cd637edd9b5
|  user:        planetmaker <planetmaker@openttd.org>
|  date:        Thu Apr 17 14:22:05 2014 +0200
|  summary:     -Codechange: Introduce foo in preparation for cool stuff
|
o  changeset:   0:4cd637edd9b5
   user:        planetmaker <planetmaker@openttd.org>
   date:        Thu Apr 17 14:20:58 2014 +0200
   summary:     -Add: Initial check-in

Thus it shows you the repository in the bug-fixed state, hiding the obsolete commits. If you need to look back, you can still access them all:

hg log -G --hidden
@  changeset:   5:888a9a6be6b3
|  tag:         tip
|  user:        planetmaker <planetmaker@openttd.org>
|  date:        Thu Apr 17 14:22:31 2014 +0200
|  summary:     -Add: New cool feature
|
o  changeset:   4:0602f70b6892
|  parent:      0:4cd637edd9b5
|  user:        planetmaker <planetmaker@openttd.org>
|  date:        Thu Apr 17 14:22:05 2014 +0200
|  summary:     -Codechange: Introduce foo in preparation for cool stuff
|
| x  changeset:   3:86838fac74d7
| |  parent:      1:227c690a1822
| |  user:        planetmaker <planetmaker@openttd.org>
| |  date:        Thu Apr 17 14:22:05 2014 +0200
| |  summary:     temporary amend commit for 227c690a1822
| |
| | x  changeset:   2:ef728218c6c5
| |/   user:        planetmaker <planetmaker@openttd.org>
| |    date:        Thu Apr 17 14:22:31 2014 +0200
| |    summary:     -Add: New cool feature
| |
| x  changeset:   1:227c690a1822
|/   user:        planetmaker <planetmaker@openttd.org>
|    date:        Thu Apr 17 14:22:05 2014 +0200
|    summary:     -Codechange: Introduce foo in preparation for cool stuff
|
o  changeset:   0:4cd637edd9b5
   user:        planetmaker <planetmaker@openttd.org>
   date:        Thu Apr 17 14:20:58 2014 +0200
   summary:     -Add: Initial check-in

These instructions are released under the Creative Commons Attribution by the #openttdcoop DevZone