[darcs-users] Internals question: How to apply a merger patch?

Kevin Smith yarcs at qualitycode.com
Sun Nov 30 21:12:20 UTC 2003

David Roundy wrote:
> First, I'd like to point out that merger 0.9 patches are no longer created,

Ah. It would be nice if I could refuse to support them, or perhaps only 
support whatever subset of them is needed to handle the darcs tree. Do 
you have any rough idea how many 0.9 mergers are out in the wild?

> glump "0.9" p1 p2 = case unravel $ Merger True "0.9" p1 p2 of
>                     [ps] -> join_patches ps
>                     pss -> if only_hunks pss
>                            then mangle_unravelled_hunks pss
>                            else join_patches $ head pss
> ps and pss are just local variables bound to the result of the unravel.  In
> this case I'm using the (common?) convention that a 's' suffix indicates a
> list (think of ps as the plural of p and pss as the plural of ps).

Oh. I'm not used to haskell's 'case..of' details. You're saying that [x] 
will only match a list containing exactly one item. Anything else 
(including lists of zero or multiple items) will fall through to the 
next case. Interesting.

> If they were all hunk patches, we can join them
> together into one big conflict-marker hunk patch.  

Which they are in this case, so I can initially only worry about this 
one situation, and throw an error for any other case.

> You will get something like the following:
> hunk ./Makefile 37
> -       install -d $(DESTDIR)/etc/darcs
> -       install -m 0644 cgi.conf /etc/darcs/cgi.conf
> +v v v v v
> +       install -d $(DESTDIR)/etc/darcs
> +       test -e $(DESTDIR)/etc/darcs/cgi.conf || \
> +           install -m 0644 cgi.conf $(DESTDIR)/etc/darcs/cgi.conf
> +*********
> +       install -d $(DESTDIR)/$(PREFIX)/etc/darcs
> +       install -m 0644 cgi.conf $(DESTDIR)/$(PREFIX)/etc/darcs/cgi.conf
> +^ ^ ^ ^ ^

Ok. So the merger patch isn't used to _resolve_ a conflict--at least not 
from a human standpoint. It merely merges two conflicting patches into a 
conflict notification. Very interesting. So if I look ahead a patch or 
two in the darcs history, I should find another hunk patch where you 
manually cleaned up this conflict, right?

> Each patch sequence output by unravel corresponds to a different version
> that got merged together.  So if three people make three different changes
> to the same line, unravel of the final merger created would give three
> possibilities.

Would a three-way merger be stored as a merger that contains a patch and 
another merger? What sequence of darcs commands would result in a 
three-way merger? I guess you would have to apply a merger that 
conflicts with the tree it is being applied to?

> 4) Output a (canonized) hunk that 
> a) removes the original version of the lines modified.
> b) adds a line containing v v v v v
> c) adds each of the N versions with a ****** separating them
> d) adds a final ^ ^ ^ ^ ^ line to indicate the end of the conflict. 

Yes, that's straightforward enough. And in the case of a simple two-hunk 
merger, looks easy to implement. But unfortunately I'll have to match 
the legacy sorting for it to work properly :-(

Thanks very much for all your answers. They're very helpful!


More information about the darcs-users mailing list