Function: ediff-dir-diff-copy-file

ediff-dir-diff-copy-file is an interactive and byte-compiled function defined in ediff-mult.el.gz.

Signature

(ediff-dir-diff-copy-file)

Documentation

Copy file described at point to directories where this file is missing.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/vc/ediff-mult.el.gz
;; Format of meta info in dir-diff-buffer:
;;               (filename-tail filename-full otherdir1 otherdir2)
(defun ediff-dir-diff-copy-file ()
  "Copy file described at point to directories where this file is missing."
  (interactive)
  (let* ((pos (ediff-event-point last-command-event))
	 (info (ediff-get-meta-info (current-buffer) pos 'noerror))
	 (meta-buf (car info))
	 (file-tail (nth 1 info))
	 (file-abs  (nth 2 info))
	 (otherdir1 (nth 3 info))
	 (otherfile1 (if otherdir1 (concat otherdir1 file-tail)))
	 (otherdir2 (nth 4 info))
	 (otherfile2 (if otherdir2 (concat otherdir2 file-tail)))
	 (otherdir3 (nth 5 info))
	 (otherfile3 (if otherdir3 (concat otherdir3 file-tail)))
	 meta-list dir-diff-list
	 )
    (if (null info)
	(error "No file suitable for copying described at this location"))
    (ediff-with-current-buffer meta-buf
      (setq meta-list ediff-meta-list
	    dir-diff-list ediff-dir-difference-list))

    ;; copy file to directories where it doesn't exist, update
    ;; ediff-dir-difference-list and redisplay
    (mapc
     (lambda (otherfile-struct)
       (let ((otherfile (car otherfile-struct))
	     (file-mem-code (cdr otherfile-struct)))
	 (if otherfile
	     (or (file-exists-p otherfile)
		 (if (y-or-n-p
		      (format "Copy %s to %s? " file-abs otherfile))
		     (let* ((file-diff-record (assoc file-tail dir-diff-list))
			    (new-mem-code
			     (* (cdr file-diff-record) file-mem-code)))
		       (copy-file file-abs otherfile)
		       (setcdr file-diff-record new-mem-code)
		       (ediff-draw-dir-diffs dir-diff-list (buffer-name))
		       (sit-for 0)
		       ;; if file is in all three dirs or in two dirs and only
		       ;; two dirs are involved, delete this file's record
		       (if (or (= new-mem-code ediff-product-of-memcodes)
			       (and (> new-mem-code ediff-membership-code3)
				    (null otherfile3)))
			   (delq file-diff-record dir-diff-list))
		       ))))
	 ))
     ;; 2,3,5 are numbers used to encode membership of a file in
     ;;       dir1/2/3. See ediff-intersect-directories.
     (list (cons otherfile1 2) (cons otherfile2 3) (cons otherfile3 5)))

    (if (and (file-exists-p otherfile1)
	     (file-exists-p otherfile2)
	     (or (not otherfile3) (file-exists-p otherfile3)))
	;; update ediff-meta-list by direct modification
	(nconc meta-list
	       (list (ediff-make-new-meta-list-element
		      (expand-file-name otherfile1)
		      (expand-file-name otherfile2)
		      (if otherfile3
			  (expand-file-name otherfile3)))))
      )
    (ediff-update-meta-buffer meta-buf 'must-redraw)
  ))