Function: diff-hl-adjust-changes
diff-hl-adjust-changes is a natively compiled function defined in
diff-hl.el.
Signature
(diff-hl-adjust-changes OLD NEW)
Documentation
Adjust changesets in OLD using changes in NEW.
The result alters the values inside the OLD changeset so that the line numbers and insertion/deletion counts refer to the lines in the file contents as they are (or would be) after applying the changes in NEW.
Source Code
;; Defined in /nix/store/cfz56rl3lp066226i0bmmgiicls3gcq7-emacs-packages-deps/share/emacs/site-lisp/elpa/diff-hl-20261001.135/diff-hl.el
(defun diff-hl-adjust-changes (old new)
"Adjust changesets in OLD using changes in NEW.
The result alters the values inside the OLD changeset so that the line
numbers and insertion/deletion counts refer to the lines in the file
contents as they are (or would be) after applying the changes in NEW."
(let ((acc 0)
(ref old)
overlap)
(while (and new old)
(cond
((<= (+ (nth 0 (car new)) (nth 2 (car new)))
(+ acc (nth 0 (car old))))
;; (A) NEW-END <= OLD-BEG
(cl-incf acc (- (nth 1 (car new)) (nth 2 (car new))))
(setq new (cdr new)))
((<= (+ acc (nth 0 (car old)) (nth 1 (car old)))
(nth 0 (car new)))
;; (B) OLD-END <= NEW-BEG
(cl-incf (nth 0 (car old)) acc)
(setq old (cdr old)))
(t
;; There is overlap.
(setq overlap
(-
(min
(+ (nth 0 (car new)) (nth 2 (car new)))
(+ acc (nth 0 (car old)) (nth 1 (car old))))
(max
(nth 0 (car new))
(+ acc (nth 0 (car old))))))
(cl-decf (nth 1 (car old)) overlap)
;; Add INSERTION amount to either before or inside.
(cl-incf (nth
(if (> (nth 0 (car new))
(+ acc (nth 0 (car old))))
1 0)
(car old))
(-
(nth 1 (car new))
(- (nth 2 (car new))
overlap)))
;; See which of the heads to pop.
(if (> (+ (nth 0 (car new)) (nth 1 (car new)))
(+ acc (nth 0 (car old)) (nth 1 (car old))))
(progn
;; Repetition of B (how to avoid dup?)
(cl-incf (nth 0 (car old)) acc)
(setq old (cdr old)))
;; Repetition of A.
(cl-incf acc (- (nth 1 (car new)) (nth 2 (car new))))
;; But also decrease OLD-BEG by the same amount: it's added later.
(cl-decf (nth 0 (car old)) (- (nth 1 (car new)) (nth 2 (car new))))
(setq new (cdr new))))))
(while old
(cl-incf (nth 0 (car old)) acc)
(setq old (cdr old)))
ref))