First off, I love using mercurial to manage source code. It provides a lot of power and flexibility. Some things that you want to do, however, are not always straight forward.
In an effort to make clean isolated commits and avoid filling the commit log with 10s of patches as I develop a new feature I’m making use of Mercurial Queues. Queues allow you to work on code changes that you wouldn’t want to keep a permanent history of. They do that by managing a separate stack of patches outside of the main repository and providing easy command line helpers to make it easy to use.
I’ve run in to this problem a few times over the last few weeks as I’m getting the hang of using mercurial to manage code more and more. I start to make changes to the code, then later as it progresses I realize two things.
- I want someone else to review my code
- it’s not in a state that I want to have committed to the repository.
It’s possible to commit the code review it and then rollback the transaction, but I have on a few occasions found that rollback won’t work (you can only rollback once). So that isn’t ideal.
The problem with Queues is that you need to have a clean repo to init a new queue. Here’s the workaround that I’ve found.
hg diff > temp.patch
hg revert --all
hg qnew experiment
hg import --no-commit temp.patch
With the Queue applied browsing the repo through hg serve will show the diff so someone else can review the code changes. Success!