1
0
mirror of https://github.com/m00natic/vlfi.git synced 2025-01-31 02:00:47 +00:00

Use single ediff pass to adjust borders. Protect against user

interruption while searching for difference.
This commit is contained in:
Andrey Kotlarski 2014-01-21 01:29:37 +02:00
parent d5d9cd71ee
commit 5d30eb4826

View File

@ -157,6 +157,7 @@ logical chunks in case there is no difference at the current ones."
(set-buffer buffer-A) (set-buffer buffer-A)
(setq buffer-A (current-buffer)) ;names change, so reference by buffer object (setq buffer-A (current-buffer)) ;names change, so reference by buffer object
(let ((end-A (= vlf-start-pos vlf-end-pos)) (let ((end-A (= vlf-start-pos vlf-end-pos))
(chunk-A (cons vlf-start-pos vlf-end-pos))
(point-max-A (point-max)) (point-max-A (point-max))
(min-file-size vlf-file-size) (min-file-size vlf-file-size)
(forward-p (eq next-func 'vlf-next-chunk))) (forward-p (eq next-func 'vlf-next-chunk)))
@ -164,55 +165,79 @@ logical chunks in case there is no difference at the current ones."
(setq buffer-B (current-buffer) (setq buffer-B (current-buffer)
min-file-size (min min-file-size vlf-file-size)) min-file-size (min min-file-size vlf-file-size))
(let ((end-B (= vlf-start-pos vlf-end-pos)) (let ((end-B (= vlf-start-pos vlf-end-pos))
(chunk-B (cons vlf-start-pos vlf-end-pos))
(done nil)
(reporter (make-progress-reporter (reporter (make-progress-reporter
"Searching for difference..." "Searching for difference..."
(if forward-p vlf-start-pos (if forward-p vlf-start-pos
(- min-file-size vlf-end-pos)) (- min-file-size vlf-end-pos))
min-file-size))) min-file-size)))
(while (and (or (not end-A) (not end-B)) (unwind-protect
(or (zerop (compare-buffer-substrings (progn
buffer-A (point-min) point-max-A (while (and (or (not end-A) (not end-B))
buffer-B (point-min) (point-max))) (or (zerop (compare-buffer-substrings
(with-current-buffer ediff-buffer buffer-A (point-min) point-max-A
(ediff-update-diffs) buffer-B (point-min) (point-max)))
(when (and (not end-A) (not end-B)) (with-current-buffer ediff-buffer
(vlf-ediff-adjust buffer-A buffer-B) (ediff-update-diffs)
(or (zerop ediff-number-of-differences) (and (not end-A) (not end-B)
(vlf-ediff-adjust buffer-A buffer-B t))) (vlf-ediff-refine buffer-A
(zerop ediff-number-of-differences)))) buffer-B))
(funcall next-func) (zerop ediff-number-of-differences))))
(setq end-B (= vlf-start-pos vlf-end-pos)) (funcall next-func)
(with-current-buffer buffer-A (setq end-B (= vlf-start-pos vlf-end-pos))
(funcall next-func) (with-current-buffer buffer-A
(setq end-A (= vlf-start-pos vlf-end-pos) (funcall next-func)
point-max-A (point-max))) (setq end-A (= vlf-start-pos vlf-end-pos)
(progress-reporter-update reporter point-max-A (point-max)))
(if forward-p vlf-end-pos (progress-reporter-update reporter
(- vlf-file-size vlf-start-pos)))) (if forward-p vlf-end-pos
(progress-reporter-done reporter) (- vlf-file-size
(if (or (not end-A) (not end-B)) vlf-start-pos))))
(progn (vlf-update-buffer-name) (progress-reporter-done reporter)
(set-buffer buffer-A) (if (or (not end-A) (not end-B))
(vlf-update-buffer-name)) (progn (vlf-update-buffer-name)
(if forward-p (set-buffer buffer-A)
(let ((max-file-size vlf-file-size)) (vlf-update-buffer-name))
(vlf-move-to-chunk (- max-file-size vlf-batch-size) (if forward-p
max-file-size) (let ((max-file-size vlf-file-size))
(set-buffer buffer-A) (vlf-move-to-chunk (- max-file-size vlf-batch-size)
(setq max-file-size (max max-file-size vlf-file-size)) max-file-size)
(vlf-move-to-chunk (- max-file-size vlf-batch-size) (set-buffer buffer-A)
max-file-size)) (setq max-file-size (max max-file-size
(vlf-beginning-of-file) vlf-file-size))
(vlf-move-to-chunk (- max-file-size
vlf-batch-size)
max-file-size))
(vlf-beginning-of-file)
(set-buffer buffer-A)
(vlf-beginning-of-file))
(set-buffer ediff-buffer)
(ediff-update-diffs)
(if (or (not forward-p)
(and (not end-A) (not end-B)))
(vlf-ediff-refine buffer-A buffer-B)))
(setq done t))
(unless done
(set-buffer buffer-A) (set-buffer buffer-A)
(vlf-beginning-of-file)) (set-buffer-modified-p nil)
(set-buffer ediff-buffer) (vlf-move-to-chunk (car chunk-A) (cdr chunk-A) t)
(ediff-update-diffs) (set-buffer buffer-B)
(when (or (not forward-p) (set-buffer-modified-p nil)
(and (not end-A) (not end-B))) (vlf-move-to-chunk (car chunk-B) (cdr chunk-B) t)
(or (zerop ediff-number-of-differences) (set-buffer ediff-buffer)
(vlf-ediff-adjust buffer-A buffer-B)) (ediff-update-diffs)
(or (zerop ediff-number-of-differences) (vlf-ediff-refine buffer-A buffer-B))))))
(vlf-ediff-adjust buffer-A buffer-B t)))))))
(defun vlf-ediff-refine (buffer-A buffer-B)
"Try to minimize differences between BUFFER-A and BUFFER-B.
This can happen if first or last difference is at the start/end of
buffer."
(or (zerop ediff-number-of-differences)
(let ((adjust-p (vlf-ediff-adjust buffer-A buffer-B)))
(setq adjust-p (or (vlf-ediff-adjust buffer-A buffer-B t)
adjust-p))
(if adjust-p (ediff-update-diffs)))))
(defun vlf-ediff-adjust (buf-A buf-B &optional end) (defun vlf-ediff-adjust (buf-A buf-B &optional end)
"Additionally adjust buffer borders for BUF-A and BUF-B. "Additionally adjust buffer borders for BUF-A and BUF-B.
@ -221,8 +246,7 @@ Adjust beginning if END is nil."
(diff-A (ediff-get-diff-overlay diff-num 'A)) (diff-A (ediff-get-diff-overlay diff-num 'A))
(diff-B (ediff-get-diff-overlay diff-num 'B)) (diff-B (ediff-get-diff-overlay diff-num 'B))
diff-A-str diff-B-str adjust-p) diff-A-str diff-B-str adjust-p)
(save-excursion (with-current-buffer buf-A
(set-buffer buf-A)
(setq adjust-p (if end (= (overlay-end diff-A) (point-max)) (setq adjust-p (if end (= (overlay-end diff-A) (point-max))
(= (overlay-start diff-A) (point-min))) (= (overlay-start diff-A) (point-min)))
diff-A-str (and adjust-p (buffer-substring-no-properties diff-A-str (and adjust-p (buffer-substring-no-properties
@ -248,7 +272,7 @@ Adjust beginning if END is nil."
(or (funcall adjust-func diff-B-str diff-A-str buf-A) (or (funcall adjust-func diff-B-str diff-A-str buf-A)
(setq adjust-p nil))) (setq adjust-p nil)))
(t (setq adjust-p nil)))))) (t (setq adjust-p nil))))))
(if adjust-p (ediff-update-diffs)))) adjust-p))
(defun vlf-ediff-adjust-start (diff-short diff-long vlf-buffer) (defun vlf-ediff-adjust-start (diff-short diff-long vlf-buffer)
"Remove difference between DIFF-SHORT and DIFF-LONG from beginning\ "Remove difference between DIFF-SHORT and DIFF-LONG from beginning\