Function: diff-merge-strings
diff-merge-strings is a byte-compiled function defined in
diff-mode.el.gz.
Signature
(diff-merge-strings ANCESTOR FROM TO)
Documentation
Merge the diff between ANCESTOR and FROM into TO.
Returns the merged string if successful or nil otherwise. The strings are assumed not to contain any "\\n" (i.e. end of line). If ANCESTOR = FROM, returns TO. If ANCESTOR = TO, returns FROM. The heuristic is simplistic and only really works for cases like (diff-merge-strings "b/foo" "b/bar" "/a/c/foo").
Source Code
;; Defined in /usr/src/emacs/lisp/vc/diff-mode.el.gz
(defun diff-merge-strings (ancestor from to)
"Merge the diff between ANCESTOR and FROM into TO.
Returns the merged string if successful or nil otherwise.
The strings are assumed not to contain any \"\\n\" (i.e. end of line).
If ANCESTOR = FROM, returns TO.
If ANCESTOR = TO, returns FROM.
The heuristic is simplistic and only really works for cases
like \(diff-merge-strings \"b/foo\" \"b/bar\" \"/a/c/foo\")."
;; Ideally, we want:
;; AMB ANB CMD -> CND
;; but that's ambiguous if `foo' or `bar' is empty:
;; a/foo a/foo1 b/foo.c -> b/foo1.c but not 1b/foo.c or b/foo.c1
(let ((str (concat ancestor "\n" from "\n" to)))
(when (and (string-match (concat
"\\`\\(.*?\\)\\(.*\\)\\(.*\\)\n"
"\\1\\(.*\\)\\3\n"
"\\(.*\\(\\2\\).*\\)\\'") str)
(equal to (match-string 5 str)))
(concat (substring str (match-beginning 5) (match-beginning 6))
(match-string 4 str)
(substring str (match-end 6) (match-end 5))))))