views:

236

answers:

3

If I've been churning away at the code for a while, and forgotten to create a patch series as I go, how do I create the patch series retrospectively? So far the only thing that comes to mind is:

# Prepare and test the first batch of changes.
$ hg qrecord -m 'first batch' 1.patch
$ hg qnew -m 'stash downstream changes' stash-1.patch
$ hg qdelete -k temp-1.patch
$ make hello
cc     hello.c   -o hello
hello.c: In function ‘main’:
hello.c:4: error: syntax error at end of input
make: *** [hello] Error 1
$ echo '}' >> hello.c
$ make hello
cc     hello.c   -o hello
$ hg qrefresh

# Recover the stashed changes.
$ patch -p1 < .hg/patches/last.patch

# And around we go again!
$ hg qrecord -m 'second batch' 2.patch
$ hg qnew -m 'stash downstream changes' stash-2.patch
$ hg qdelete -k stash-2.patch
$ make hello
...

This very cumbersome approach is also hazardous. I might forget the -k on qdelete, at which point I'll go bash my forehead against a brick wall for several minutes, or I might include too much or too little during the qrecord operation.

Is there a better way?

(What I'd really like is to be able to hg qpop to just before a patch I want to split, and use a currently non-existent command, hg qunrecord, to interactively suck changes out of the patch into my working directory. Once I'm happy with the changes, hg qnew -f could squeeze a new patch in front of the old one.)

A: 

I think the crecord extension will let you do this. It gives you an interactive curses based interface where you can choose exactly what's in a commit.

RyanWilcox
Based on a cursory reading, crecord seems to be a curses-based equivalent to the record extension. Thank you for pointing this extension out, as it looks quite handy. However, it doesn't appear to reduce the number of steps I have to perform; it just makes the first step more pleasant.
Marcelo Cantos
A: 

TortoiseHg has very useful feature "Hunk Selection" in Commit dialog for kind of this work:
http://tortoisehg.bitbucket.org/manual/0.9/commit.html#change-selection

kuy
Most of my work isn't in Windows, but I use it occasionally, so thank you for the tip. Unfortunately, as with @RyanWilcox's suggestion, this seems to help with the first step in my process, rather than simplifying the process overall.
Marcelo Cantos
FYI: If need, you can run TortoiseHg on Linux and Mac OS :) http://bitbucket.org/tortoisehg/stable/wiki/install
kuy
I had no idea! That's great to know.
Marcelo Cantos
+3  A: 

The MQTutorial explains how to split patches. So you could create a patch from you current work and split it into several patches.

wierob
Thanks. That's not an ideal solution, but it's much better than what I've been doing so far.
Marcelo Cantos
What I usually do is to use two repositories and a nice visual diff tool like Beyond Compare. Using the names in the tutorial, I start with repo A with OP applied, and I clone A to B. Then in A I `qpop -a`, diff A and B, cherry-pick the changes for P1 to copy from B to A, `qnew -f P1`, then copy the rest, `qnew -f P2`.
Geoffrey Zheng