patch utilities?

Martin Geisler mg at
Tue Jun 22 03:56:16 CDT 2010

Jason Harris <jason at> writes:

(I guess this is a sort of relevant for the whole Mercurial developer
community, so I'm putting mercurial-devel in Cc. At least there may be
someone on our list who knows of a relevant tool or who want to help
write one.)

> On Jun 22, 2010, at 10:14 AM, Jim Meyering wrote:
>> Jason Harris wrote:
>>> First sorry if this is the wrong place to ask this. (It didn't seem
>>> so appropriate to send this to bug-diffutils since its not a bug at
>>> all.) Since you guys are the maintainers of the GNU diff utilities I
>>> thought I would ask you.
>>> I am the author of MacHg ( a nice open
>>> source (BSD License) OSX GUI for Mercurial (The distributed revision
>>> control system.)
>>> I was wanting to include hunk level control of committing, and patch
>>> manipulation.
>>> Thus, I want to do tasks like:
>>> 1. Find the number of hunks in a patch file
>>> 2. Then say get hunks 3, 6, and 8 of a given patch.
>>> 3. I then want to be able to apply only hunks 4, 5, and 7 of a patch
>>>    to the files the hunks apply to.
>>> 4. Split a patch file of 6 hunks into two patch files. First file
>>>    having hunks 1,2, 5, second file having hunks 3,4,6
>>> 5. Given two patch files, combine them into a single patch file.
>>> 6. Given two patch files, if I switch the order of application of
>>>    the patches, will there be conflicts when applying to a given set
>>>    of files?
>>> Thus I would like to do these sorts of things. It strikes me this is
>>> under the general prevue of "diff utilities" but I didn't see how to
>>> do this when scanning the documentation. Likely I could write my own
>>> but it strikes me that this would likely be reinventing some wheels.
>>> Thus, if I can trouble you what is currently the best way to do
>>> this? Are there other free utilities out there I should look at?
>> diffutils has little infrastructure that would be useful here.
> Ahh... Well at least I didn't miss something...
>> You might want to look at git.
>> It's "git add --patch" functionality seems to do exactly what you
>> want.
> Thanks. Actually mercurial also has this in the form of crecord
> extension, etc. But they coded this up in python. Also their
> implementation is somewhat specific to Mercurial. I had wondered if
> there were general tools for this. I know now of lots of places where
> this sort of functionality is replicated. Eg that the crecord
> extension, tortiseHg, GitX, etc. I am guessing they do the same in
> darcs and lots of other projects as well. Thus it just made sense to
> me that there should be some universal utilities which do this...

This wiki page lists an earlier attempt at unifying our patch handling
code, albeit this is of course talking about the Python code:

We also discussed this at the Paris sprint, but nothing came out of it
as far as I recall.

> Thanks,
>   Jason

Martin Geisler

aragost Trifork
Professional Mercurial support

More information about the Mercurial-devel mailing list