Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ Myers is vendored from by Thomas Gazagnaire (released under `ISC`)
[ocaml-merge3](https://tangled.org/gazagnaire.org/ocaml-merge3). Only the pure
diff computation is vendored; the parts unused by this project are not included.
The exact provenance and list of changes are documented at the top of
`src/myers/merge3.ml` and in `src/myers/vendor.json`.
`src/merge3/merge3.ml` and in `src/merge3/vendor.json`.

A copy of the license file for ocaml-merge3 is located under
`third-party-license/gazagnaire/ocaml-merge3/LICENSE`.
`third-party-license/gazagnaire/ocaml-merge3/LICENSE.md`.

## Windtrap (unified-diff renderer)

Expand Down
3 changes: 3 additions & 0 deletions src/merge3/COPYING.HEADER
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
crs-merge3 - Myers shortest-edit-script computation
SPDX-FileCopyrightText: 2026 Mathieu Barbin <mathieu.barbin@gmail.com>
SPDX-License-Identifier: ISC
9 changes: 9 additions & 0 deletions src/merge3/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(library
(name crs_merge3)
(package crs-tests)
(flags :standard -w +a-4-40-41-42-44-45-48-66 -warn-error +a)
(instrumentation
(backend bisect_ppx))
(lint
(pps ppx_js_style -allow-let-operators -check-doc-comments))
(preprocess no_preprocessing))
27 changes: 19 additions & 8 deletions src/myers/merge3.ml → src/merge3/merge3.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
(**************************************************************************)
(* crs-myers - Myers diff computation and unified-diff printing *)
(* Copyright (C) 2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(* SPDX-License-Identifier: ISC *)
(**************************************************************************)

(* Copyright (c) 2024-2026 Thomas Gazagnaire <thomas@gazagnaire.org> *)
(* SPDX-License-Identifier: ISC *)
(****************************************************************************)
(* crs-merge3 - Myers shortest-edit-script computation *)
(* SPDX-FileCopyrightText: 2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(* SPDX-License-Identifier: ISC *)
(****************************************************************************)

(* Copyright (c) 2024-2026 Thomas Gazagnaire <thomas@gazagnaire.org>

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *)

(* Notice: This file was vendored from gazagnaire/ocaml-merge3 (the [Merge3]
module, [lib/merge3.ml]) as documented in [vendor.json] and the project's
Expand Down
55 changes: 55 additions & 0 deletions src/merge3/merge3.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
(*_***************************************************************************)
(*_ crs-merge3 - Myers shortest-edit-script computation *)
(*_ SPDX-FileCopyrightText: 2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(*_ SPDX-License-Identifier: ISC *)
(*_***************************************************************************)

(*_ Copyright (c) 2024-2026 Thomas Gazagnaire <thomas@gazagnaire.org>

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *)

(*_ Notice: This file was vendored from gazagnaire/ocaml-merge3 (the [Merge3]
module, [lib/merge3.mli]) as documented in [vendor.json] and the project's
root [NOTICE.md].

List of changes:

- Applied local project ocamlformat (janestreet profile).
- Removed the parts unused by this project.

- Replace use of globally-visible [Stdlib.Exit] exception by a custom one.
An [eq] that itself raised [Exit] would be silently swallowed and yield
a wrong diff. *)

(** Myers' O(ND) shortest-edit-script, vendored from gazagnaire/ocaml-merge3.

Only the pure diff computation is vendored; see [merge3.ml] and the root
[NOTICE.md] for the list of (non-algorithmic) parts removed. *)

(** An edit operation in the shortest edit script. *)
type 'a edit =
| Keep of 'a (** Line present in both sequences. *)
| Delete of 'a (** Line present in old, absent in new. *)
| Insert of 'a (** Line absent in old, present in new. *)

(** [diff ~eq a b] computes the shortest edit script from [a] to [b] using
Myers' O(ND) algorithm. [eq] is the equality predicate.

The result is a list of edits that transforms [a] into [b]:
- [Keep x]: line [x] is present in both
- [Delete x]: line [x] from [a] is removed
- [Insert x]: line [x] from [b] is added

Time: O(ND) where N = |a| + |b| and D = edit distance. Space: O(D²) for the
trace. *)
val diff : eq:('a -> 'a -> bool) -> 'a array -> 'a array -> 'a edit list
13 changes: 13 additions & 0 deletions src/merge3/vendor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"note": "This directory vendors the Myers shortest-edit-script computation from gazagnaire/ocaml-merge3. See the in-file Notice block for the list of changes.",
"sources": [
{
"file": "merge3.ml",
"description": "Myers shortest-edit-script computation",
"url": "https://tangled.sh/@gazagnaire.org/monopampam",
"gitRev": "f09e84825149d6b76365bd7af347577182fe9c79",
"path": "ocaml-merge3/lib/merge3.ml",
"license": "ISC"
}
]
}
2 changes: 1 addition & 1 deletion src/myers/COPYING.HEADER
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
crs-myers - Myers diff computation and unified-diff printing
Copyright (C) 2026 Mathieu Barbin <mathieu.barbin@gmail.com>
SPDX-FileCopyrightText: 2026 Mathieu Barbin <mathieu.barbin@gmail.com>
SPDX-License-Identifier: ISC
11 changes: 9 additions & 2 deletions src/myers/dune
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
(library
(name crs_myers)
(package crs-tests)
(private_modules merge3)
(flags :standard -w +a-4-40-41-42-44-45-48-66 -warn-error +a)
(libraries crs_merge3)
(flags
:standard
-w
+a-4-40-41-42-44-45-48-66
-warn-error
+a
-open
Crs_merge3)
(instrumentation
(backend bisect_ppx))
(lint
Expand Down
31 changes: 0 additions & 31 deletions src/myers/merge3.mli

This file was deleted.

25 changes: 18 additions & 7 deletions src/myers/myers.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
(**************************************************************************)
(* crs-myers - Myers diff computation and unified-diff printing *)
(* Copyright (C) 2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(* SPDX-License-Identifier: ISC *)
(**************************************************************************)
(****************************************************************************)
(* crs-myers - Myers diff computation and unified-diff printing *)
(* SPDX-FileCopyrightText: 2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(* SPDX-License-Identifier: ISC *)
(****************************************************************************)

(* Copyright (c) 2026 Invariant Systems. All rights reserved. *)
(* SPDX-License-Identifier: ISC *)
(* Copyright (c) 2026 Invariant Systems. All rights reserved.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *)

(* Notice: The unified-diff renderer and the [Equal] / [Line] / [compute] API
shape in this file were vendored from windtrap (the [Myers] module,
Expand Down
47 changes: 39 additions & 8 deletions src/myers/myers.mli
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
(*_*************************************************************************)
(*_ crs-myers - Myers diff computation and unified-diff printing *)
(*_ Copyright (C) 2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(*_ SPDX-License-Identifier: ISC *)
(*_*************************************************************************)

(*_ Copyright (c) 2026 Invariant Systems. All rights reserved. *)
(*_ SPDX-License-Identifier: ISC *)
(*_***************************************************************************)
(*_ crs-myers - Myers diff computation and unified-diff printing *)
(*_ SPDX-FileCopyrightText: 2026 Mathieu Barbin <mathieu.barbin@gmail.com> *)
(*_ SPDX-License-Identifier: ISC *)
(*_***************************************************************************)

(*_ Copyright (c) 2026 Invariant Systems. All rights reserved.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *)

(*_ Notice: The unified-diff renderer and the [Equal] / [Line] / [compute] API
shape in this file were vendored from windtrap (the [Myers] module,
[lib/myers/myers.mli]) as documented in [vendor.json] and the project's root
[NOTICE.md]. Only the shortest-edit-script computation was replaced (it now
lives in [merge3.mli], vendored from gazagnaire/ocaml-merge3); the rendering
logic — [type hunk], [lines_of_string], [hunks_of_lines], [diff],
[print_diff] — derives from windtrap.

List of changes relative to windtrap:

- Applied local project ocamlformat (janestreet profile).
- [compute] delegates to the vendored {!Merge3.diff}.
- Hunk lines use the [Line] variant instead of windtrap's [(char * string)]
encoding ([type hunk.lines : string Line.t list]).
- [lines_of_string] returns a [string list] and the intermediate [Array]
representation in [hunks_of_lines] was removed.
- Diff rendering tweaks: line prefixes are ["-|"] / ["+|"] / [" "], and the
[--- / +++] header is emitted only when a label is explicitly provided
(windtrap always emitted it with the defaults "expected" / "actual"). *)

(** Unified-diff renderer built on a vendored Myers shortest-edit-script.

Expand Down
10 changes: 1 addition & 9 deletions src/myers/vendor.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
{
"note": "This directory vendors code from two upstreams. The Myers shortest-edit-script computation is in [merge3.ml] (from gazagnaire/ocaml-merge3). The unified-diff renderer and the Equal/Line/compute API shape are in [myers.ml] (from windtrap). See the in-file Notice blocks and the root [NOTICE.md] for the list of changes.",
"note": "This directory vendors the unified-diff renderer and the Equal/Line/compute API shape from windtrap. The Myers shortest-edit-script computation it calls into lives in ../merge3, vendored separately from gazagnaire/ocaml-merge3. See the in-file Notice block for the list of changes.",
"sources": [
{
"file": "merge3.ml",
"description": "Myers shortest-edit-script computation",
"url": "https://tangled.sh/@gazagnaire.org/monopampam",
"gitRev": "f09e84825149d6b76365bd7af347577182fe9c79",
"path": "ocaml-merge3/lib/merge3.ml",
"license": "ISC"
},
{
"file": "myers.ml",
"description": "Unified-diff renderer and Equal/Line/compute API shape",
Expand Down
Loading