emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/debbugs 2c83d55 156/311: Touch up the automatic patch a


From: Stefan Monnier
Subject: [elpa] externals/debbugs 2c83d55 156/311: Touch up the automatic patch applying logic
Date: Sun, 29 Nov 2020 18:42:01 -0500 (EST)

branch: externals/debbugs
commit 2c83d55378f969fb5a734762e53bea00bd18ac64
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Touch up the automatic patch applying logic
---
 debbugs-gnu.el | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/debbugs-gnu.el b/debbugs-gnu.el
index 73c19d8..296538a 100644
--- a/debbugs-gnu.el
+++ b/debbugs-gnu.el
@@ -1378,7 +1378,9 @@ If given a prefix, patch in the branch directory instead."
       (article-decode-charset)
       (push gnus-article-buffer patch-buffers))
     (dolist (buffer patch-buffers)
-      (with-current-buffer buffer
+      (with-temp-buffer
+       (insert-buffer-substring buffer)
+       (debbugs-gnu-fix-patch dir)
        (call-process-region (point-min) (point-max)
                             "patch" nil output-buffer nil
                             "-r" rej "--no-backup-if-mismatch"
@@ -1414,6 +1416,28 @@ If given a prefix, patch in the branch directory 
instead."
     (switch-to-buffer "*vc-diff*")
     (goto-char (point-min))))
 
+(defun debbugs-gnu-fix-patch (dir)
+  (setq dir (directory-file-name (expand-file-name dir)))
+  (goto-char (point-min))
+  (re-search-forward diff-file-header-re nil t)
+  (goto-char (match-beginning 0))
+  (let ((file-names (diff-hunk-file-names)))
+    (when (and file-names
+              (not (string-match "/" (car file-names))))
+      ;; We have a simple patch that refers to a file somewhere in the
+      ;; tree.  Find it.
+      (when-let ((files (directory-files-recursively
+                        dir (concat "^" (regexp-quote (car file-names))
+                                    "$"))))
+       (when (re-search-forward (concat "^[+]+ "
+                                        (regexp-quote (car file-names))
+                                        "[ \t]")
+                                nil t)
+         (replace-match (concat "+++ a"
+                                (substring (car files) (length dir))
+                                "\t")
+                        nil t))))))
+
 (defun debbugs-gnu-find-contributor (string)
   "Search through ChangeLogs to find contributors."
   (interactive "sContributor match: ")
@@ -1503,7 +1527,11 @@ If given a prefix, patch in the branch directory 
instead."
   (save-some-buffers t)
    (when (get-buffer "*vc-dir*")
      (kill-buffer (get-buffer "*vc-dir*")))
-   (vc-dir debbugs-gnu-trunk-directory)
+   (let ((trunk (expand-file-name debbugs-gnu-trunk-directory)))
+     (if (equal (subseq default-directory 0 (length trunk))
+               trunk)
+        (vc-dir debbugs-gnu-trunk-directory)
+       (vc-dir debbugs-gnu-branch-directory)))
    (goto-char (point-min))
    (while (not (search-forward "edited" nil t))
      (sit-for 0.01))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]