• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/emacs-93/emacs/lisp/

Lines Matching defs:patch

1 ;;; ediff-ptch.el --- Ediff's  patch support
31 "Ediff patch support."
56 (defcustom ediff-patch-program "patch"
61 (defcustom ediff-patch-options "-f"
62 "*Options to pass to ediff-patch-program.
66 It is recommended to pass the `-f' option to the patch program, so it won't ask
72 (defvar ediff-last-dir-patch nil
73 "Last directory used by an Ediff command for file to patch.")
82 "Backup extension used by the patch program.
87 (defun ediff-test-patch-utility ()
89 (cond ((eq 0 (call-process ediff-patch-program nil nil nil "-z." "-b"))
90 ;; GNU `patch' v. >= 2.2
92 ((eq 0 (call-process ediff-patch-program nil nil nil "-b"))
98 (let ((type (ediff-test-patch-utility)))
100 ;; GNU `patch' v. >= 2.2
103 ;; POSIX `patch' -- ediff-backup-extension must be ".orig"
107 ;; traditional `patch'
109 "*Backup directives to pass to the patch program.
110 Ediff requires that the old version of the file \(before applying the patch\)
111 be saved in a file named `the-patch-file.extension'. Usually `extension' is
113 Therefore, Ediff needs to know the backup extension used by the patch program.
115 Some versions of the patch program let you specify `-b backup-extension'.
118 versions of GNU patch require `-b -z backup-extension'.
121 must be set properly. If your patch program takes the option `-b',
126 to be working for `traditional' patch, all versions of GNU patch, and for POSIX
127 patch. So, don't change these variables, unless the default doesn't work."
132 (defcustom ediff-patch-default-directory nil
144 You probably don't want to change that, unless you are using an obscure patch
149 ;; The buffer of the patch file. Local to control buffer.
152 ;; The buffer where patch displays its diagnostics.
153 (ediff-defvar-local ediff-patch-diagnostics nil "")
155 ;; Map of patch buffer. Has the form:
157 ;; where filenames are files to which patch would have applied the patch;
158 ;; marker1 delimits the beginning of the corresponding patch and marker2 does
160 (ediff-defvar-local ediff-patch-map nil "")
193 ;; Scan BUF (which is supposed to contain a patch) and make a list of the form
196 ;; where filename-spec[12] are files to which the `patch' program would
197 ;; have applied the patch.
204 ;; The marker `marker1' delimits the beginning of the corresponding patch and
206 ;; The result of ediff-map-patch-buffer is a list, which is then assigned
207 ;; to ediff-patch-map.
208 ;; The function returns the number of elements in the list ediff-patch-map
209 (defun ediff-map-patch-buffer (buf)
217 patch-map opoint)
232 ;; insert the old file name in the patch map
251 (setq patch-map
254 patch-map)))
261 patch-map (cons (ediff-make-new-meta-list-element
263 patch-map))
264 (setq ediff-patch-map (nreverse patch-map))
268 ;; Algorithm: find the files' directories in the patch and, if a directory is
269 ;; absolute, cut it out from the corresponding file name in the patch.
272 ;; originally from the patch).
273 ;; In addition, the first file in the patch document is replaced by FILENAME.
275 ;; In the end, for each pair, we ask the user which file to patch.
277 ;; with the `Index:' line. It treats them as a single-file patch.
279 ;; Executes inside the patch buffer
280 (defun ediff-fixup-patch-map (filename)
286 ;; In case 2 files are possible patch targets, the user will be offered
287 ;; to choose file1 or file2. In a multifile patch, if the user chooses
298 ;; base-dir1 is the dir part of the 1st file in the patch
302 ;; directory part of the 2nd file in the patch
328 ediff-patch-map)
333 (setcar (ediff-get-session-objA (car ediff-patch-map))
343 ;; couldn't intuit the file name to patch, so
351 The patch file contains a context diff for
385 ediff-patch-map)
397 ;; The patch program prefers the shortest file as the patch
427 are two possible targets for applying the patch.
453 is assumed to be the target for this patch. However, this file does not exist."
458 are two possible targets for this patch. However, these files do not exist."
461 \nPlease enter an alternative patch target ...\n"))
466 "Please enter a patch target: "
474 ediff-patch-map)
477 (defun ediff-show-patch-diagnostics ()
480 (set-window-buffer ediff-window-A ediff-patch-diagnostics))
482 (set-window-buffer ediff-window-B ediff-patch-diagnostics))
483 (t (display-buffer ediff-patch-diagnostics 'not-this-window))))
486 (defun ediff-prompt-for-patch-file ()
487 (let ((dir (cond (ediff-use-last-dir ediff-last-dir-patch)
488 (ediff-patch-default-directory) ; try patch default dir
491 patch-file-name)
492 (setq patch-file-name
504 (if (file-directory-p patch-file-name)
505 (error "Patch file cannot be a directory: %s" patch-file-name)
506 (find-file-noselect patch-file-name))
511 (defun ediff-prompt-for-patch-buffer ()
514 "Buffer that holds the patch: "
535 (defun ediff-get-patch-buffer (&optional arg patch-buf)
536 "Obtain patch buffer. If patch is already in a buffer---use it.
537 Else, read patch file into a new buffer. If patch buffer is passed as an
542 (cond ((ediff-buffer-live-p patch-buf))
543 ;; even prefix arg: patch in buffer
545 (setq patch-buf (ediff-prompt-for-patch-buffer)))
546 ;; odd prefix arg: get patch from a file
548 (setq patch-buf (ediff-prompt-for-patch-file)))
549 (t (setq patch-buf
550 (if (y-or-n-p "Is the patch already in a buffer? ")
551 (ediff-prompt-for-patch-buffer)
552 (ediff-prompt-for-patch-file)))))
554 (ediff-with-current-buffer patch-buf
556 (or (ediff-get-visible-buffer-window patch-buf)
558 (pop-to-buffer patch-buf 'other-window)
560 (ediff-map-patch-buffer patch-buf)
561 patch-buf))
563 ;; Dispatch the right patch file function: regular or meta-level,
564 ;; depending on how many patches are in the patch file.
567 (defun ediff-dispatch-file-patching-job (patch-buf filename
569 (ediff-with-current-buffer patch-buf
570 ;; relativize names in the patch with respect to source-file
571 (ediff-fixup-patch-map filename)
572 (if (< (length ediff-patch-map) 2)
573 (ediff-patch-file-internal
574 patch-buf
575 (if (and ediff-patch-map
578 ;; this is the file to patch
579 (ediff-get-session-objA-name (car ediff-patch-map))))
581 (ediff-get-session-objA-name (car ediff-patch-map)))
583 (ediff-get-session-objA-name (car ediff-patch-map))
586 (ediff-multi-patch-internal patch-buf startup-hooks))
592 ;; Users who want to actually patch the buffer should use
593 ;; ediff-patch-file, not ediff-patch-buffer.
594 (defun ediff-patch-buffer-internal (patch-buf
595 buf-to-patch-name
597 (let* ((buf-to-patch (get-buffer buf-to-patch-name))
598 (visited-file (if buf-to-patch (buffer-file-name buf-to-patch)))
599 (buf-mod-status (buffer-modified-p buf-to-patch))
600 (multifile-patch-p (> (length (ediff-with-current-buffer patch-buf
601 ediff-patch-map)) 1))
603 (if multifile-patch-p
605 "To apply multi-file patches, please use `ediff-patch-file'"))
607 ;; create a temp file to patch
608 (ediff-with-current-buffer buf-to-patch
610 (setq file-name (ediff-make-temp-file buf-to-patch))
617 (rename-buffer buf-to-patch-name)
623 ;; dispatch a patch function
625 patch-buf file-name startup-hooks))
633 (rename-buffer buf-to-patch-name)
640 (concat buf-to-patch-name "_patched") ""))
645 ;; Traditional patch has weird return codes.
649 (defun ediff-patch-return-code-ok (code)
651 ;;; (if (eq (ediff-test-patch-utility) 'traditional)
655 (defun ediff-patch-file-internal (patch-buf source-filename
660 (patch-diagnostics (get-buffer-create "*ediff patch diagnostics*"))
661 ;; ediff-find-file may use a temp file to do the patch
667 ;; this ensures that the patch process gets patch buffer in the
671 target-buf buf-to-patch file-name-magic-p
672 patch-return-code ctl-buf backup-style aux-wind)
674 (if (string-match "V" ediff-patch-options)
676 "Ediff doesn't take the -V option in `ediff-patch-options'--sorry"))
682 (ediff-find-file 'true-source-filename 'buf-to-patch
683 'ediff-last-dir-patch 'startup-hooks)
694 (ediff-maybe-checkout buf-to-patch)
696 (ediff-with-current-buffer patch-diagnostics
697 (insert-buffer-substring patch-buf)
698 (message "Applying patch ... ")
699 ;; fix environment for gnu patch, so it won't make numbered extensions
702 (setq patch-return-code
706 t ; delete region (which contains the patch
707 t ; insert output (patch diagnostics) in current buffer
711 ediff-patch-program
712 ediff-patch-options
717 ;; restore environment for gnu patch
720 (message "Applying patch ... done")
723 (switch-to-buffer patch-diagnostics)
726 (or (and (ediff-patch-return-code-ok patch-return-code)
734 "Patch program has failed due to a bad patch file,
738 The former could be caused by a corrupt patch file or because the %S
739 program doesn't understand the format of the patch file in use.
742 ediff-patch-program = %S ediff-patch-options = %S
749 However, if the patch was applied partially and the backup file was created,
751 ediff-patch-program
752 ediff-patch-program
753 ediff-patch-options
762 (switch-to-buffer-other-window patch-diagnostics)
765 ;; If black magic is involved, apply patch to a temp copy of the
766 ;; file. Otherwise, apply patch to the orig copy. If patch is applied
774 (ediff-with-current-buffer buf-to-patch
805 buf-to-patch target-buf nil
808 (setq ediff-patchbufer patch-buf
809 ediff-patch-diagnostics patch-diagnostics))
811 (bury-buffer patch-diagnostics)
812 (message "Type `P', if you need to see patch diagnostics")
815 (defun ediff-multi-patch-internal (patch-buf &optional startup-hooks)
823 'ediff-patch-file-form-meta
824 ediff-meta-patchbufer patch-buf) )
828 (ediff-with-current-buffer patch-buf
831 (format "%S" patch-buf) ; obj A
836 ediff-patch-map))
839 'ediff-multifile-patch