3-way merge with Myers diff
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

OCaml 74.6%
Python 17.9%
Dune 1.9%
Shell 0.8%
Other 4.8%
17 1 0

Clone this repository

https://tangled.org/gazagnaire.org/ocaml-merge3 https://tangled.org/did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-merge3
git@git.recoil.org:gazagnaire.org/ocaml-merge3 git@git.recoil.org:did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-merge3

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

merge3#

Myers diff and diff3 three-way merge for OCaml.

merge3 implements Myers' O(ND) line-level diff and the diff3 three-way merge with git-compatible conflict markers. It also exposes Irmin-style merge combinators (pair, option, alist) for composing merges on structured types.

Installation#

Install with opam:

$ opam install merge3

If opam cannot find the package, it may not yet be released in the public opam-repository. Add the overlay repository, then install it:

$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install merge3

Usage#

Line-level diff#

Merge3.diff returns a shortest edit script that transforms one array of lines into another:

# let a = [| "one"; "two"; "three" |]
  and b = [| "one"; "TWO"; "three" |] in
  Merge3.diff ~eq:String.equal a b
- : string Merge3.edit list =
[Merge3.Keep "one"; Merge3.Delete "two"; Merge3.Insert "TWO";
 Merge3.Keep "three"]

Three-way merge#

Merge3.merge performs diff3 against a common ancestor. Clean regions are returned as Resolved; overlapping edits as Conflict. When both sides change the same line region differently, rendering the merge produces git-style markers:

# let base = "a\nb\nc\n"
  and ours = "a\nB1\nc\n"
  and theirs = "a\nB2\nc\n" in
  print_string (Merge3.to_string (Merge3.merge ~base ~ours ~theirs ()))
a
<<<<<<< ours
B1
=======
B2
>>>>>>> theirs
c
- : unit = ()

Merge3.has_conflicts inspects a merge result without formatting it:

# let chunks =
    Merge3.merge ~base:"a\nb\nc\n"
                 ~ours:"a\nb\nc\n"
                 ~theirs:"a\nb\nC\n" () in
  Merge3.has_conflicts chunks
- : bool = false

Merge combinators#

Compose merge functions on structured types using Irmin-style combinators:

# let merge_int = Merge3.default ~eq:Int.equal in
  let merge_pair = Merge3.pair merge_int (Merge3.option merge_int) in
  merge_pair ~old:(Some (1, None)) (1, Some 2) (1, Some 2)
- : (int * int option) Merge3.result = Merge3.Ok (1, Some 2)

Licence#

ISC