Function: ediff-map-patch-buffer
ediff-map-patch-buffer is a byte-compiled function defined in
ediff-ptch.el.gz.
Signature
(ediff-map-patch-buffer BUF)
Source Code
;; Defined in /usr/src/emacs/lisp/vc/ediff-ptch.el.gz
;; Scan BUF (which is supposed to contain a patch) and make a list of the form
;; ((nil nil filename-spec1 marker1 marker2)
;; (nil nil filename-spec2 marker1 marker2) ...)
;; where filename-spec[12] are files to which the `patch' program would
;; have applied the patch.
;; nin, nil are placeholders. See ediff-make-new-meta-list-element in
;; ediff-meta.el for the explanations.
;; In the beginning we don't know exactly which files need to be patched.
;; We usually come up with two candidates and ediff-file-name-sans-prefix
;; resolves this later.
;;
;; The marker `mark1' delimits the beginning of the corresponding patch and
;; `mark2' does it for the end.
;; The result of ediff-map-patch-buffer is a list, which is then assigned
;; to ediff-patch-map.
;; The function returns the number of elements in the list ediff-patch-map
(defun ediff-map-patch-buffer (buf)
(ediff-with-current-buffer buf
(let ((count 0)
(mark1 (point-min-marker))
(mark1-end (point-min))
(possible-file-names `(,null-device . ,null-device))
mark2-end mark2 filenames
beg1 beg2 end1 end2
patch-map opoint)
(save-excursion
(goto-char (point-min))
(setq opoint (point))
(while (and (not (eobp))
(re-search-forward ediff-context-diff-label-regexp nil t))
(if (= opoint (point))
(forward-char 1) ; ensure progress towards the end
(setq mark2 (move-marker (make-marker) (match-beginning 0))
mark2-end (match-end 0)
beg1 (or (match-beginning 2) (match-beginning 4))
end1 (or (match-end 2) (match-end 4))
beg2 (or (match-beginning 3) (match-beginning 5))
end2 (or (match-end 3) (match-end 5)))
;; possible-file-names is holding the new file names until we
;; insert the old file name in the patch map
;; It is a pair
;; (filename-from-1st-header-line . filename-from-2nd-line)
(setq possible-file-names
(cons (if (and beg1 end1)
(buffer-substring beg1 end1)
null-device)
(if (and beg2 end2)
(buffer-substring beg2 end2)
null-device)))
;; Remove file junk (Bug#26084).
(while (re-search-backward
(concat "^\\(?:" diff-file-junk-re "\\)") mark1-end t)
(move-marker mark2 (match-beginning 0)))
(goto-char mark2-end)
(if filenames
(setq patch-map
(cons (ediff-make-new-meta-list-element
filenames mark1 mark2)
patch-map)))
(setq mark1 mark2
mark1-end mark2-end
filenames possible-file-names))
(setq opoint (point)
count (1+ count))))
(setq mark2 (point-max-marker)
patch-map (cons (ediff-make-new-meta-list-element
possible-file-names mark1 mark2)
patch-map))
(setq ediff-patch-map (nreverse patch-map))
count)))