]> git.eshelyaron.com Git - emacs.git/commitdiff
Filter out -L foo labels in diff-hunk-file-names
authorLars Ingebrigtsen <larsi@gnus.org>
Sat, 14 Aug 2021 13:50:55 +0000 (15:50 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sat, 14 Aug 2021 13:50:55 +0000 (15:50 +0200)
* lisp/vc/diff-mode.el (diff-hunk-file-names): Filter out "-L foo"
labels (bug#10160).

lisp/vc/diff-mode.el
test/lisp/vc/diff-mode-tests.el

index bb1c46c070a02f10421aeca3af616c2141ea154e..eeb32f8fe50ac327401157da345834c6dedba916 100644 (file)
@@ -969,11 +969,11 @@ If the OLD prefix arg is passed, tell the file NAME of the old file."
               (list (match-string 1)))
             header-files
              ;; this assumes that there are no spaces in filenames
-            (when (re-search-backward
-                   "^diff \\(-\\S-+ +\\)*\\(\\S-+\\)\\( +\\(\\S-+\\)\\)?"
-                   nil t)
-              (list (if old (match-string 2) (match-string 4))
-                    (if old (match-string 4) (match-string 2)))))))))
+             (and (re-search-backward "^diff " nil t)
+                  (looking-at
+                  "^diff \\(-[^ \t\nL]+ +\\)*\\(-L +\\S-+ +\\)*\\(\\S-+\\)\\( +\\(\\S-+\\)\\)?")
+                 (list (if old (match-string 3) (match-string 5))
+                       (if old (match-string 4) (match-string 3)))))))))
 
 (defun diff-find-file-name (&optional old noprompt prefix)
   "Return the file corresponding to the current patch.
index 5bc4ad6daceaaf657c921523ae7a70ca92de63a2..521865906e784ad9f1a561fa79113f3d70105994 100644 (file)
@@ -468,4 +468,16 @@ baz"))))
                        (114 131 (diff-mode syntax face font-lock-string-face))
                        (134 140 (diff-mode syntax face font-lock-keyword-face))))))))
 
+(ert-deftest test-hunk-file-names ()
+  (with-temp-buffer
+    (insert "diff -c /tmp/ange-ftp13518wvE.el /tmp/ange-ftp1351895K.el\n")
+    (goto-char (point-min))
+    (should (equal (diff-hunk-file-names)
+                   '("/tmp/ange-ftp1351895K.el" "/tmp/ange-ftp13518wvE.el"))))
+  (with-temp-buffer
+    (insert "diff -c -L /ftp\:slbhao\:/home/albinus/src/tramp/lisp/tramp.el -L /ftp\:slbhao\:/home/albinus/src/emacs/lisp/net/tramp.el /tmp/ange-ftp13518wvE.el /tmp/ange-ftp1351895K.el\n")
+    (goto-char (point-min))
+    (should (equal (diff-hunk-file-names)
+                   '("/tmp/ange-ftp1351895K.el" "/tmp/ange-ftp13518wvE.el")))))
+
 (provide 'diff-mode-tests)