August 17th, 2008

  • evan

smarter merges

I often use meld to handle file merges, but I'm not too happy with it. Aside from the obvious bug of it seeming to get confused at the end of files (I've gotta believe this is some local misconfiguration, because it breaks all the time for me), there's also many cases where it could have provided a more informative diff had it only had "tried harder". I write "harder" in scare quotes because it's fuzzy concept in my head, but you could imagine that (especially since I am willing to give it a second to grind away on the file if necessary) you could examine blocks where lines differ and, for example, infer variable renames. Or it could detect when code has both moved and changed slightly and indicate as something more than a delete and an add.

Here's an odd parallel: Patch files effectively leave you with the state of the file before and the state of the file afterwards. This is just what git does at the tree level, and though it's often rightfully blamed for its weak handling of renames, guessing at renames is certainly better than not trying to handle them at all. Yet in the world of patches, we don't expect anyone to annotate their patches with which variables have been renamed (what you typically do with files in most VCSes) while simultaneously accepting that tools can't handle them at all.

This makes me think I'm just ignorant of what cleverer people use. Am I just using the wrong tool? What should I be using instead?
  • evan


Dear lazyweb,

I want a command -- "patch-interactively". It takes a diff as input and lets you interactively walk through it as it tries to apply to your tree -- sorta like how darcs (or git add -p) does interactive cherry-picking of diff chunks, or sorta like how merge tools work but without applying any of the diff without your explicit action.

Here's my common scenario: I'm working on a patch and I discover I've unintentionally changed the whitespace on a part I don't care about. I don't want to throw away all my work but I want a minimal diff. I find myself manually reconstructing the whitespace -- lame. (I believe but it's been too long for me to say definitively that darcs provides an interactive revert command just for this kind of scenario.) In my imagined world I could run "git diff | patch-interactively" to pick and revert just what I wanted.

Another common scenario: you have a patch where half of it is good, but the other half isn't. I find myself manually editing the patch and deleting the chunks I don't like -- also lame, and sometimes I end up corrupting the patch. Instead, I could "patch-interactively < patch".

In all cases I want something fancier than the darcs interface; good merge tools (side-by-side, coloring) are way too useful.

As before, I have the suspicion this has already been built -- where? (Feels like the kind of thing that Emacs would do...)