comparison lisp/smerge-mode.el @ 93983:955774916817

(smerge-apply-resolution-patch): Fix typo. (smerge-resolve): Merge the "2-way refinement" case with one half of the "mere whitespace" resolution.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 11 Apr 2008 01:10:43 +0000
parents 87b6e6f4a207
children 5eb3ee73ed4e
comparison
equal deleted inserted replaced
93982:ec7aefc66165 93983:955774916817
455 (dotimes (i otherlines) (delete-char 2) (forward-line 1)) 455 (dotimes (i otherlines) (delete-char 2) (forward-line 1))
456 (buffer-substring pos (point))))) 456 (buffer-substring pos (point)))))
457 (with-current-buffer textbuf 457 (with-current-buffer textbuf
458 (forward-line (- startline line)) 458 (forward-line (- startline line))
459 (insert "<<<<<<< " name1 "\n" othertext 459 (insert "<<<<<<< " name1 "\n" othertext
460 (if name2 (concat "||||||| " name2)) 460 (if name2 (concat "||||||| " name2 "\n"))
461 "=======\n") 461 "=======\n")
462 (forward-line lines) 462 (forward-line lines)
463 (insert ">>>>>>> " name3 "\n") 463 (insert ">>>>>>> " name3 "\n")
464 (setq line endline)))))))) 464 (setq line endline))))))))
465 465
496 (funcall smerge-resolve-function)) 496 (funcall smerge-resolve-function))
497 t) 497 t)
498 (error nil)) 498 (error nil))
499 ;; Nothing to do: the resolution function has done it already. 499 ;; Nothing to do: the resolution function has done it already.
500 nil) 500 nil)
501 ;; "Mere whitespace" conflicts. 501 ;; Non-conflict.
502 ((or (and (eq m1e m3e) (eq m1b m3b)) ;Non-conflict. 502 ((and (eq m1e m3e) (eq m1b m3b))
503 (progn 503 (set-match-data md) (smerge-keep-n 3))
504 (setq m (make-temp-file "smm"))
505 (write-region m1b m1e m nil 'silent)
506 (setq o (make-temp-file "smo"))
507 (write-region m3b m3e o nil 'silent)
508 ;; Same patch applied on both sides, with whitespace changes.
509 (zerop (call-process diff-command nil nil nil "-b" m o)))
510 (when m2e
511 (setq b (make-temp-file "smb"))
512 (write-region m2b m2e b nil 'silent)
513 ;; Only minor whitespace changes made locally.
514 (zerop (call-process diff-command nil buf nil "-bc" b m))))
515 (set-match-data md)
516 (smerge-keep-n 3))
517 ;; Refine a 2-way conflict using "diff -b". 504 ;; Refine a 2-way conflict using "diff -b".
518 ;; In case of a 3-way conflict with an empty base 505 ;; In case of a 3-way conflict with an empty base
519 ;; (i.e. 2 conflicting additions), we do the same, presuming 506 ;; (i.e. 2 conflicting additions), we do the same, presuming
520 ;; that the 2 additions should be somehow merged rather 507 ;; that the 2 additions should be somehow merged rather
521 ;; than concatenated. 508 ;; than concatenated.
522 ((not (or (and m2b (not (eq m2b m2e))) 509 ((let ((lines (count-lines m3b m3e)))
523 (eq m1b m1e) (eq m3b m3e) 510 (setq m (make-temp-file "smm"))
524 (let ((lines (count-lines m3b m3e))) 511 (write-region m1b m1e m nil 'silent)
525 (call-process diff-command nil buf nil "-b" o m) 512 (setq o (make-temp-file "smo"))
513 (write-region m3b m3e o nil 'silent)
514 (not (or (eq m1b m1e) (eq m3b m3e)
515 (and (not (zerop (call-process diff-command
516 nil buf nil "-b" o m)))
517 ;; TODO: We don't know how to do the refinement
518 ;; if there's a non-empty ancestor and m1 and m3
519 ;; aren't just plain equal.
520 m2b (not (eq m2b m2e)))
526 (with-current-buffer buf 521 (with-current-buffer buf
527 (goto-char (point-min)) 522 (goto-char (point-min))
528 ;; Make sure there's some refinement. 523 ;; Make sure there's some refinement.
529 (looking-at 524 (looking-at
530 (concat "1," (number-to-string lines) "c")))))) 525 (concat "1," (number-to-string lines) "c"))))))
531 (smerge-apply-resolution-patch buf m0b m0e m3b m3e m2b)) 526 (smerge-apply-resolution-patch buf m0b m0e m3b m3e m2b))
527 ;; "Mere whitespace changes" conflicts.
528 ((when m2e
529 (setq b (make-temp-file "smb"))
530 (write-region m2b m2e b nil 'silent)
531 (with-current-buffer buf (erase-buffer))
532 ;; Only minor whitespace changes made locally.
533 ;; BEWARE: pass "-c" 'cause the output is reused in the next test.
534 (zerop (call-process diff-command nil buf nil "-bc" b m)))
535 (set-match-data md)
536 (smerge-keep-n 3))
532 ;; Try "diff -b BASE MINE | patch OTHER". 537 ;; Try "diff -b BASE MINE | patch OTHER".
533 ((when (and (not safe) m2e b 538 ((when (and (not safe) m2e b
534 ;; If the BASE is empty, this would just concatenate 539 ;; If the BASE is empty, this would just concatenate
535 ;; the two, which is rarely right. 540 ;; the two, which is rarely right.
536 (not (eq m2b m2e))) 541 (not (eq m2b m2e)))
542 ;; BEWARE: we're using here the patch of the previous test.
537 (with-current-buffer buf 543 (with-current-buffer buf
538 (zerop (call-process-region 544 (zerop (call-process-region
539 (point-min) (point-max) "patch" t nil nil 545 (point-min) (point-max) "patch" t nil nil
540 "-r" "/dev/null" "--no-backup-if-mismatch" 546 "-r" "/dev/null" "--no-backup-if-mismatch"
541 "-fl" o)))) 547 "-fl" o))))