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

Improve refining of differences and readjustment.

This commit is contained in:
Andrey Kotlarski 2014-01-20 02:40:26 +02:00
parent e747de4495
commit d5d9cd71ee

View File

@ -59,12 +59,11 @@ respectively of difference list, runs ediff over the adjacent chunks."
(setq buffer-B (current-buffer)) (setq buffer-B (current-buffer))
(setq vlf-batch-size vlf-size)) (setq vlf-batch-size vlf-size))
(vlf-beginning-of-file) (vlf-beginning-of-file)
(vlf-ediff-next buffer-A buffer-B 'vlf-next-chunk)
(ediff-buffers buffer-A buffer-B (ediff-buffers buffer-A buffer-B
'((lambda () (setq vlf-ediff-session t) '((lambda () (setq vlf-ediff-session t)
(when (< 0 ediff-number-of-differences) (vlf-ediff-next ediff-buffer-A ediff-buffer-B
(vlf-ediff-adjust buffer-A buffer-B t) ediff-control-buffer
(ediff-jump-to-difference 1)))))) 'vlf-next-chunk)))))
;;;###autoload ;;;###autoload
(defun vlf-ediff-files (file-A file-B batch-size) (defun vlf-ediff-files (file-A file-B batch-size)
@ -101,6 +100,47 @@ respectively of difference list, runs ediff over the adjacent chunks."
(let ((buffer-B (vlf file-B))) (let ((buffer-B (vlf file-B)))
(vlf-ediff-buffers buffer-A buffer-B)))) (vlf-ediff-buffers buffer-A buffer-B))))
(defadvice ediff-next-difference (around vlf-ediff-next-difference
compile activate)
"Move to the next VLF chunk and search for difference if at the end\
of difference list."
(if (and vlf-ediff-session
(<= (1- ediff-number-of-differences)
ediff-current-difference))
(let ((buffer-A ediff-buffer-A)
(buffer-B ediff-buffer-B)
(ediff-buffer (current-buffer)))
(save-excursion
(set-buffer buffer-A)
(vlf-next-chunk)
(set-buffer buffer-B)
(vlf-next-chunk)
(vlf-ediff-next buffer-A buffer-B ediff-buffer
'vlf-next-chunk))
(or (zerop ediff-number-of-differences)
(ediff-jump-to-difference 1)))
ad-do-it))
(defadvice ediff-previous-difference (around vlf-ediff-prev-difference
compile activate)
"Move to the previous VLF chunk and search for difference if at the\
beginning of difference list."
(if (and vlf-ediff-session
(<= ediff-current-difference 0))
(let ((buffer-A ediff-buffer-A)
(buffer-B ediff-buffer-B)
(ediff-buffer (current-buffer)))
(save-excursion
(set-buffer buffer-A)
(vlf-prev-chunk)
(set-buffer buffer-B)
(vlf-prev-chunk)
(vlf-ediff-next buffer-A buffer-B ediff-buffer
'vlf-prev-chunk))
(or (zerop ediff-number-of-differences)
(ediff-jump-to-difference -1)))
ad-do-it))
(defun vlf-next-chunk () (defun vlf-next-chunk ()
"Move to next chunk." "Move to next chunk."
(vlf-move-to-chunk vlf-end-pos (+ vlf-end-pos vlf-batch-size) t)) (vlf-move-to-chunk vlf-end-pos (+ vlf-end-pos vlf-batch-size) t))
@ -109,10 +149,11 @@ respectively of difference list, runs ediff over the adjacent chunks."
"Move to previous chunk." "Move to previous chunk."
(vlf-move-to-chunk (- vlf-start-pos vlf-batch-size) vlf-start-pos t)) (vlf-move-to-chunk (- vlf-start-pos vlf-batch-size) vlf-start-pos t))
(defun vlf-ediff-next (buffer-A buffer-B &optional next-func) (defun vlf-ediff-next (buffer-A buffer-B ediff-buffer
"Find next pair of chunks that differ in BUFFER-A and BUFFER-B. &optional next-func)
NEXT-FUNC is used to jump to the next logical chunks in case there is "Find next pair of chunks that differ in BUFFER-A and BUFFER-B\
no difference at the current ones." governed by EDIFF-BUFFER. NEXT-FUNC is used to jump to the next
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))
@ -129,9 +170,16 @@ no difference at the current ones."
(- 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)) (while (and (or (not end-A) (not end-B))
(zerop (compare-buffer-substrings (or (zerop (compare-buffer-substrings
buffer-A (point-min) point-max-A buffer-A (point-min) point-max-A
buffer-B (point-min) (point-max)))) buffer-B (point-min) (point-max)))
(with-current-buffer ediff-buffer
(ediff-update-diffs)
(when (and (not end-A) (not end-B))
(vlf-ediff-adjust buffer-A buffer-B)
(or (zerop ediff-number-of-differences)
(vlf-ediff-adjust buffer-A buffer-B t)))
(zerop ediff-number-of-differences))))
(funcall next-func) (funcall next-func)
(setq end-B (= vlf-start-pos vlf-end-pos)) (setq end-B (= vlf-start-pos vlf-end-pos))
(with-current-buffer buffer-A (with-current-buffer buffer-A
@ -142,70 +190,29 @@ no difference at the current ones."
(if forward-p vlf-end-pos (if forward-p vlf-end-pos
(- vlf-file-size vlf-start-pos)))) (- vlf-file-size vlf-start-pos))))
(progress-reporter-done reporter) (progress-reporter-done reporter)
(cond ((or (not end-A) (not end-B)) (if (or (not end-A) (not end-B))
(vlf-update-buffer-name) (progn (vlf-update-buffer-name)
(set-buffer buffer-A) (set-buffer buffer-A)
(vlf-update-buffer-name)) (vlf-update-buffer-name))
(forward-p ;end of both files (if forward-p
(let ((max-file-size vlf-file-size)) (let ((max-file-size vlf-file-size))
(with-current-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-file-size))
(vlf-move-to-chunk (- max-file-size vlf-batch-size) (vlf-move-to-chunk (- max-file-size vlf-batch-size)
max-file-size))) max-file-size))
(t (vlf-beginning-of-file) (vlf-beginning-of-file)
(set-buffer buffer-A)
(vlf-beginning-of-file))))))
(defadvice ediff-next-difference (around vlf-ediff-next-difference
compile activate)
"Move to the next VLF chunk and search for difference if at the end\
of difference list."
(if (and vlf-ediff-session
(<= (1- ediff-number-of-differences)
ediff-current-difference))
(let ((buffer-A ediff-buffer-A)
(buffer-B ediff-buffer-B))
(save-excursion
(set-buffer buffer-A) (set-buffer buffer-A)
(vlf-next-chunk) (vlf-beginning-of-file))
(set-buffer buffer-B) (set-buffer ediff-buffer)
(vlf-next-chunk)
(vlf-ediff-next buffer-A buffer-B 'vlf-next-chunk))
(ediff-update-diffs) (ediff-update-diffs)
(when (< 0 ediff-number-of-differences) (when (or (not forward-p)
(vlf-ediff-adjust buffer-A buffer-B t) (and (not end-A) (not end-B)))
(vlf-ediff-adjust buffer-A buffer-B) (or (zerop ediff-number-of-differences)
(if (< 0 ediff-number-of-differences) (vlf-ediff-adjust buffer-A buffer-B))
(save-excursion (or (zerop ediff-number-of-differences)
(vlf-ediff-next buffer-A buffer-B 'vlf-next-chunk))) (vlf-ediff-adjust buffer-A buffer-B t)))))))
(ediff-jump-to-difference 1)))
ad-do-it))
(defadvice ediff-previous-difference (around vlf-ediff-prev-difference
compile activate)
"Move to the previous VLF chunk and search for difference if at the\
beginning of difference list."
(if (and vlf-ediff-session
(<= ediff-current-difference 0))
(let ((buffer-A ediff-buffer-A)
(buffer-B ediff-buffer-B))
(save-excursion
(set-buffer buffer-A)
(vlf-prev-chunk)
(set-buffer buffer-B)
(vlf-prev-chunk)
(vlf-ediff-next buffer-A buffer-B 'vlf-prev-chunk))
(ediff-update-diffs)
(when (< 0 ediff-number-of-differences)
(vlf-ediff-adjust buffer-A buffer-B)
(vlf-ediff-adjust buffer-A buffer-B t)
(if (< 0 ediff-number-of-differences)
(save-excursion
(vlf-ediff-next buffer-A buffer-B 'vlf-prev-chunk)))
(ediff-jump-to-difference -1)))
ad-do-it))
(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.
@ -231,8 +238,8 @@ Adjust beginning if END is nil."
(if adjust-p (if adjust-p
(let ((len-A (length diff-A-str)) (let ((len-A (length diff-A-str))
(len-B (length diff-B-str)) (len-B (length diff-B-str))
(adjust-func (if end 'vlf-ediff-adjust-end-1 (adjust-func (if end 'vlf-ediff-adjust-end
'vlf-ediff-adjust-start-1))) 'vlf-ediff-adjust-start)))
(cond (cond
((< len-A len-B) ((< len-A len-B)
(or (funcall adjust-func diff-A-str diff-B-str buf-B) (or (funcall adjust-func diff-A-str diff-B-str buf-B)
@ -243,7 +250,7 @@ Adjust beginning if END is nil."
(t (setq adjust-p nil)))))) (t (setq adjust-p nil))))))
(if adjust-p (ediff-update-diffs)))) (if adjust-p (ediff-update-diffs))))
(defun vlf-ediff-adjust-start-1 (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\
of VLF-BUFFER." of VLF-BUFFER."
(when (string-suffix-p diff-short diff-long) (when (string-suffix-p diff-short diff-long)
@ -256,7 +263,7 @@ of VLF-BUFFER."
buffer-file-coding-system t))) buffer-file-coding-system t)))
vlf-end-pos))) vlf-end-pos)))
(defun vlf-ediff-adjust-end-1 (diff-short diff-long vlf-buffer) (defun vlf-ediff-adjust-end (diff-short diff-long vlf-buffer)
"Remove difference between DIFF-SHORT and DIFF-LONG from the end of\ "Remove difference between DIFF-SHORT and DIFF-LONG from the end of\
VLF-BUFFER." VLF-BUFFER."
(when (string-prefix-p diff-short diff-long) (when (string-prefix-p diff-short diff-long)