sx-git Phase 6: merge — diff3 textual 3-way, tree merge, ff detection (TDD)

Textual diff3 built on the Myers scripts: non-eq regions clustered by strict
base-interval overlap (same-point insert pairs cluster too); one-sided
clusters apply, two-sided take shared result or emit <<<<<<</|||||||/=======/
>>>>>>> markers with base section. Per-path 3-way tree merge with blob-level
auto-merge and delete/modify flagging; merge-commits handles up-to-date /
fast-forward / merged / conflicts, unrelated histories merge over an empty
base. (Content CvRDT not reused deliberately: its state-based LWW block
semantics differ from base-anchored 3-way; the path-set merge here is the
same idea applied natively.) 28/28, total 187/187.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-03 12:22:35 +00:00
parent 4d5a60a754
commit 989dc278c1
6 changed files with 488 additions and 22 deletions

View File

@@ -145,30 +145,33 @@
(nth r 2)))))))))))
; ---- edit script over two strings ----
(define
git/diff-script-lines
(fn
(al bl)
(let
((rt (git/myers-run (git/dvec al) (git/dvec bl) (len al) (len bl) (assoc {} "1" 0) 0 (list))))
(git/myers-back
(git/dvec al)
(git/dvec bl)
(first rt)
(nth rt 1)
(len al)
(len bl)
(list)))))
(define
git/diff-script
(fn
(a-data b-data)
(let
((al (git/diff-lines a-data)) (bl (git/diff-lines b-data)))
(let
((rt (git/myers-run (git/dvec al) (git/dvec bl) (len al) (len bl) (assoc {} "1" 0) 0 (list))))
(git/myers-back
(git/dvec al)
(git/dvec bl)
(first rt)
(nth rt 1)
(len al)
(len bl)
(list))))))
(git/diff-script-lines (git/diff-lines a-data) (git/diff-lines b-data))))
; reconstruction invariants: old = eq+del lines, new = eq+add lines
(define
git/diff-changes
(fn
(script)
(len (filter (fn (o) (not (equal? (get o :op) "eq"))) script))))
; reconstruction invariants: old = eq+del lines, new = eq+add lines
(define
git/diff-old-lines
(fn
@@ -176,6 +179,8 @@
(map
(fn (o) (get o :line))
(filter (fn (o) (not (equal? (get o :op) "add"))) script))))
; ---- unified rendering ----
(define
git/diff-new-lines
(fn
@@ -184,7 +189,6 @@
(fn (o) (get o :line))
(filter (fn (o) (not (equal? (get o :op) "del"))) script))))
; ---- unified rendering ----
(define
git/diff-annotate
(fn
@@ -312,6 +316,7 @@
""
ops))))))
; ---- object-level diffs ----
(define
git/diff-unified
(fn
@@ -328,7 +333,6 @@
""
(git/diff-hunk-ranges ann 3)))))
; ---- object-level diffs ----
(define
git/blob-diff
(fn
@@ -343,6 +347,7 @@
(repo t1 t2)
(git/files-diff (git/tree-flatten repo t1) (git/tree-flatten repo t2))))
; ---- whole-commit unified render: added, deleted, then modified paths ----
(define
git/commit-diff
(fn
@@ -352,7 +357,6 @@
(git/commit-tree (git/read repo c1))
(git/commit-tree (git/read repo c2)))))
; ---- whole-commit unified render: added, deleted, then modified paths ----
(define
git/diff-path-data
(fn