SVN-like merging

Matt Mackall mpm at selenic.com
Fri May 5 08:22:56 CDT 2006


On Fri, May 05, 2006 at 09:38:50AM +0200, Christian Boos wrote:
> Matt Mackall wrote:
> >On Thu, May 04, 2006 at 03:31:15PM -0400, S?bastien Pierre wrote:
> >  
> >>...
> >>
> >>- The user can then manually resolve each conflict. Conflict resolution
> >>is explicitely notified by running the "resolve" command with the name
> >>of the resolved conflict.
> >>
> >>Is this possible in Mercurial ?
> >>    
> >
> >All merging is handled by the external merge script. Simply replace
> >that script with one that does the appropriate thing, it should be
> >about 3 lines.
> 
> I think that what is really useful in the SVN approach is a way
> to *prevent* the accidental commit of conflicted files.
> Arguably you should always review your diffs before committing,
> but a little extra help wouldn't hurt here.
> 
> I'd propose scanning for the presence of the usual conflict markers
> in modified files, and if found, refuse to commit unless --force
> is used.
> 
> Alternatively, if we think we can't rely on the conflict markers
> to be always there (as the merge script could do something unusual),
> simply leave a file.conflict behind when the merge failed, and refuse
> to commit if there's such a file.
> "hg resolve" could be used to cleanup those files.

Before we can begin to discuss this I have to remind everyone of an
important fact:

 Mercurial intentionally knows nothing about how files are merged. 

All the merge logic is in hgmerge, which is just an _example_, and for
most people could be replaced with a single line like:

 kdiff3 --auto "$2" "$1" "$3"

Why is this important? It means that Mercurial's merge handling is
extremely flexible and easily taught about handling project-specific
special cases. It also means that Mercurial doesn't have to care about
the details.

With that in mind, teaching Mercurial proper about merge(1) markers
doesn't make sense. It's never heard of merge(1) and it doesn't want
to.

So what's the right way to do this? The obvious place is in the
user-defined commit editor. At commit time, simply grep all the
changed files for whatever you want and exit with an error to abort
the commit.

-- 
Mathematics is the supreme nostalgia of our time.


More information about the Mercurial mailing list