diff options
| author | Tino Calancha | 2017-03-21 17:25:55 +0900 |
|---|---|---|
| committer | Tino Calancha | 2017-03-21 17:25:55 +0900 |
| commit | abe731eef0fcbc59ef4836e06f6099ea17042b90 (patch) | |
| tree | 6611bae15f92a0451acf7ce02128cab09d6dfb95 | |
| parent | 205223f4725864e1fb53df5cd12694d0bc89f7d0 (diff) | |
| download | emacs-abe731eef0fcbc59ef4836e06f6099ea17042b90.tar.gz emacs-abe731eef0fcbc59ef4836e06f6099ea17042b90.zip | |
epatch: Save right backups in Git multipatches
Multipatches on N Git files save wrong backups for
N-1 files; only the last one has a correct backup (Bug#26084).
* lisp/vc/diff-mode.el (diff-file-junk-re): Add 'Prereq: '
* lisp/vc/ediff-ptch.el (ediff-map-patch-buffer): Use 'diff-file-junk-re'.
* test/lisp/vc/ediff-ptch-tests.el (ediff-ptch-test-bug25010):
Rename from ibuffer-test-bug25010.
(ediff-ptch-test-bug26084): New test.
| -rw-r--r-- | lisp/vc/diff-mode.el | 2 | ||||
| -rw-r--r-- | lisp/vc/ediff-ptch.el | 13 | ||||
| -rw-r--r-- | test/lisp/vc/ediff-ptch-tests.el | 59 |
3 files changed, 65 insertions, 9 deletions
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 31c33e6a720..aa8d77882ec 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el | |||
| @@ -504,7 +504,7 @@ See http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01990.html") | |||
| 504 | ;; "index ", "old mode", "new mode", "new file mode" and | 504 | ;; "index ", "old mode", "new mode", "new file mode" and |
| 505 | ;; "deleted file mode" are output by git-diff. | 505 | ;; "deleted file mode" are output by git-diff. |
| 506 | (defconst diff-file-junk-re | 506 | (defconst diff-file-junk-re |
| 507 | (concat "Index: \\|=\\{20,\\}\\|" ; SVN | 507 | (concat "Index: \\|Prereq: \\|=\\{20,\\}\\|" ; SVN |
| 508 | "diff \\|index \\|\\(?:deleted file\\|new\\(?: file\\)?\\|old\\) mode\\|=== modified file")) | 508 | "diff \\|index \\|\\(?:deleted file\\|new\\(?: file\\)?\\|old\\) mode\\|=== modified file")) |
| 509 | 509 | ||
| 510 | ;; If point is in a diff header, then return beginning | 510 | ;; If point is in a diff header, then return beginning |
diff --git a/lisp/vc/ediff-ptch.el b/lisp/vc/ediff-ptch.el index 9d2ec51b596..36aebf4aed1 100644 --- a/lisp/vc/ediff-ptch.el +++ b/lisp/vc/ediff-ptch.el | |||
| @@ -25,6 +25,8 @@ | |||
| 25 | ;;; Code: | 25 | ;;; Code: |
| 26 | 26 | ||
| 27 | 27 | ||
| 28 | (require 'diff-mode) ; For `diff-file-junk-re'. | ||
| 29 | |||
| 28 | (provide 'ediff-ptch) | 30 | (provide 'ediff-ptch) |
| 29 | 31 | ||
| 30 | (defgroup ediff-ptch nil | 32 | (defgroup ediff-ptch nil |
| @@ -225,14 +227,11 @@ program." | |||
| 225 | (if (and beg2 end2) | 227 | (if (and beg2 end2) |
| 226 | (buffer-substring beg2 end2) | 228 | (buffer-substring beg2 end2) |
| 227 | "/dev/null"))) | 229 | "/dev/null"))) |
| 228 | ;; check for any `Index:' or `Prereq:' lines, but don't use them | 230 | ;; Remove file junk (Bug#26084). |
| 229 | (if (re-search-backward "^Index:" mark1-end 'noerror) | 231 | (while (re-search-backward |
| 230 | (move-marker mark2 (match-beginning 0))) | 232 | (concat "^" diff-file-junk-re) mark1-end t) |
| 231 | (if (re-search-backward "^Prereq:" mark1-end 'noerror) | 233 | (move-marker mark2 (match-beginning 0))) |
| 232 | (move-marker mark2 (match-beginning 0))) | ||
| 233 | |||
| 234 | (goto-char mark2-end) | 234 | (goto-char mark2-end) |
| 235 | |||
| 236 | (if filenames | 235 | (if filenames |
| 237 | (setq patch-map | 236 | (setq patch-map |
| 238 | (cons (ediff-make-new-meta-list-element | 237 | (cons (ediff-make-new-meta-list-element |
diff --git a/test/lisp/vc/ediff-ptch-tests.el b/test/lisp/vc/ediff-ptch-tests.el index 912c6b1e818..9aacb6bd20f 100644 --- a/test/lisp/vc/ediff-ptch-tests.el +++ b/test/lisp/vc/ediff-ptch-tests.el | |||
| @@ -22,7 +22,7 @@ | |||
| 22 | (require 'ert) | 22 | (require 'ert) |
| 23 | (require 'ediff-ptch) | 23 | (require 'ediff-ptch) |
| 24 | 24 | ||
| 25 | (ert-deftest ibuffer-test-bug25010 () | 25 | (ert-deftest ediff-ptch-test-bug25010 () |
| 26 | "Test for http://debbugs.gnu.org/25010 ." | 26 | "Test for http://debbugs.gnu.org/25010 ." |
| 27 | (with-temp-buffer | 27 | (with-temp-buffer |
| 28 | (insert "diff --git a/lisp/vc/ediff-ptch.el b/lisp/vc/ediff-ptch.el | 28 | (insert "diff --git a/lisp/vc/ediff-ptch.el b/lisp/vc/ediff-ptch.el |
| @@ -38,5 +38,62 @@ index 6a07f80..6e8e947 100644 | |||
| 38 | (match-string 1)))) | 38 | (match-string 1)))) |
| 39 | (should-not (string-suffix-p "@@" filename))))) | 39 | (should-not (string-suffix-p "@@" filename))))) |
| 40 | 40 | ||
| 41 | |||
| 42 | (ert-deftest ediff-ptch-test-bug26084 () | ||
| 43 | "Test for http://debbugs.gnu.org/26084 ." | ||
| 44 | (let* ((tmpdir temporary-file-directory) | ||
| 45 | (foo (expand-file-name "foo" tmpdir)) | ||
| 46 | (patch (expand-file-name "foo.diff" tmpdir)) | ||
| 47 | (qux (expand-file-name "qux.txt" foo)) | ||
| 48 | (bar (expand-file-name "bar.txt" foo)) | ||
| 49 | (cmd " | ||
| 50 | mkdir -p foo | ||
| 51 | cd foo | ||
| 52 | echo 'qux here' > qux.txt | ||
| 53 | echo 'bar here' > bar.txt | ||
| 54 | git init | ||
| 55 | git add . && git commit -m 'Test repository.' | ||
| 56 | echo 'foo here' > qux.txt | ||
| 57 | echo 'foo here' > bar.txt | ||
| 58 | git diff > ../foo.diff | ||
| 59 | git reset --hard HEAD | ||
| 60 | ")) | ||
| 61 | (setq default-directory tmpdir) | ||
| 62 | (call-process-shell-command cmd) | ||
| 63 | (find-file patch) | ||
| 64 | (unwind-protect | ||
| 65 | (let* ((info | ||
| 66 | (progn (ediff-map-patch-buffer (current-buffer)) ediff-patch-map)) | ||
| 67 | (patch1 | ||
| 68 | (buffer-substring-no-properties | ||
| 69 | (car (nth 3 (car info))) | ||
| 70 | (car (nth 4 (car info))))) | ||
| 71 | (patch2 | ||
| 72 | (buffer-substring-no-properties | ||
| 73 | (car (nth 3 (cadr info))) | ||
| 74 | (car (nth 4 (cadr info)))))) | ||
| 75 | ;; Apply both patches. | ||
| 76 | (dolist (x (list (cons patch1 bar) (cons patch2 qux))) | ||
| 77 | (with-temp-buffer | ||
| 78 | (insert (car x)) | ||
| 79 | (call-shell-region (point-min) | ||
| 80 | (point-max) | ||
| 81 | (format "%s %s %s %s" | ||
| 82 | ediff-patch-program | ||
| 83 | ediff-patch-options | ||
| 84 | ediff-backup-specs | ||
| 85 | (cdr x))))) | ||
| 86 | ;; Check backup files were saved correctly. | ||
| 87 | (dolist (x (list qux bar)) | ||
| 88 | (should-not (string= (with-temp-buffer | ||
| 89 | (insert-file-contents x) | ||
| 90 | (buffer-string)) | ||
| 91 | (with-temp-buffer | ||
| 92 | (insert-file-contents (concat x ediff-backup-extension)) | ||
| 93 | (buffer-string)))))) | ||
| 94 | (delete-directory foo 'recursive) | ||
| 95 | (delete-file patch)))) | ||
| 96 | |||
| 97 | |||
| 41 | (provide 'ediff-ptch-tests) | 98 | (provide 'ediff-ptch-tests) |
| 42 | ;;; ediff-ptch-tests.el ends here | 99 | ;;; ediff-ptch-tests.el ends here |