5

The purpose of the hg mq plugin is to be able to make perfect commits to your repository, not confusing the changes that you made in your absent-minded ADHD induced rambling through your code;

For instance....

I'm working on bug x when I notice bug y and start working on it instead. At this point you are supposed to create a new patch in the patch queue so as not to confuse the changes when it is hg qfinish committed to your repository.

Now suppose for a minute that you forget make the new patch and in the process hg qrefresh. Then later realizing your mistake you wish to separate the changes from that one patch into two patches.

I realize that it has to do with editing your patch file (and a new patch file) in the queue to separate the changes into separate patches and later commits. However, I'm not yet skilled at editing the diff patch files.

Where can I learn about this? And how might one go about this?

leeand00
  • 25,510
  • 39
  • 140
  • 297

4 Answers4

3

Another option (assuming it runs on your platform) is version 2.0 of TortoiseHG. The 'inappropriately' named Shelve utility allows for moving of chunks and files between patches, or into the working directory. It's available for Windows, Linux and possibly OSX.

http://tortoisehg.bitbucket.io/

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Mikezx6r
  • 16,829
  • 7
  • 33
  • 31
2

As noted in this related SO question, check out the "Split a patch into multiple patches" section of the MQ tutorial.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Tim Henigan
  • 60,452
  • 11
  • 85
  • 78
2

You can activate the record extension, adding to .hgrc the following lines:

[extensions]
hgext.record =

You can clear your current patch with

hg qrefresh nothing

(note that the "nothing" is just a random string: the arguments to qrefresh is the list of files which must be included in the current patch, so anything that is not the name of a modified file will do - I usually use "0")

Now with hg qrecord <patchName> you can choose interactively which changes must go in the new patch. The remaining changes can then be added to another patch with qnew or another qrecord. You can finally use qpop, qfold or edit .hg/patches/series to merge and reorder the patches.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Aldo
  • 536
  • 5
  • 23
0

I have a shell alias, viq="vim $(hg root)/.hg/patches/", that I use for just these situations!

I'll just run viq to pull up the patches, then hand-edit the diff and move the hunks into other patches as appropriate.

I prefer this over interactive methods (eg, git add -i) because I don't feel as safe working from the interactive prompt as I do working from my editor (I know that my editor makes backups, has trivial undo, etc…).

David Wolever
  • 148,955
  • 89
  • 346
  • 502
  • I didn't make it clear in my post but, I know where the patch files are, it's just that I'm not real good on the particulars of editing the patch file. – leeand00 Mar 24 '11 at 17:03
  • Ah, sorry — I didn't mean to suggest that you didn't know where they are. I'm just saying that, given all the options I'm aware of, this is how I prefer to do it. – David Wolever Mar 24 '11 at 17:10
  • Also, so long as you're editing at the [hunk level](http://en.wikipedia.org/wiki/Diff#Unified_format), it's really easy — you can move hunks around however you want, just so long as the correct header (ie, `--- a/foo\n+++ b/foo`) is somewhere above the moved hunks. – David Wolever Mar 24 '11 at 17:12