From 83821f496144e59633860e288189f943ba958b74 Mon Sep 17 00:00:00 2001 From: Lars Magne Ingebrigtsen Date: Mon, 25 Apr 2016 18:03:38 +0200 Subject: [PATCH] Get more info from patches in debbugs-gnu * packages/debbugs/debbugs-gnu.el (debbugs-gnu-insert-changelog): When handling git-formatted patches, get all the info from the patches automatically. --- packages/debbugs/debbugs-gnu.el | 86 ++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 24 deletions(-) diff --git a/packages/debbugs/debbugs-gnu.el b/packages/debbugs/debbugs-gnu.el index 378937b5c..316a654d1 100644 --- a/packages/debbugs/debbugs-gnu.el +++ b/packages/debbugs/debbugs-gnu.el @@ -1574,18 +1574,48 @@ If given a prefix, patch in the branch directory instead." (message "%s is a contributor %d times" string found) found)) +(defvar debbugs-gnu-patch-subject nil) + (defun debbugs-gnu-insert-changelog () "Add a ChangeLog from a recently applied patch from a third party." (interactive) - (let (from subject) + (let (from subject patch-subject changelog) (gnus-with-article-buffer (widen) (goto-char (point-min)) (setq from (mail-extract-address-components (gnus-fetch-field "from")) - subject (gnus-fetch-field "subject"))) + subject (gnus-fetch-field "subject")) + ;; If it's a patch formatted the right way, extract that data. + (dolist (handle (mapcar 'cdr (gnus-article-mime-handles))) + (when (string-match "diff\\|patch\\|plain" + (mm-handle-media-type handle)) + (with-temp-buffer + (insert-buffer-substring (mm-handle-buffer handle)) + (cond ((eq (mm-handle-encoding handle) 'base64) + (base64-decode-region (point-min) (point-max))) + ((eq (mm-handle-encoding handle) 'quoted-printable) + (quoted-printable-decode-region (point-min) (point-max)))) + (setq patch-subject + (or (gnus-fetch-field "subject") patch-subject)) + (goto-char (point-min)) + (when (re-search-forward "^[*] " nil t) + (let ((start (match-beginning 0))) + (while (and (not (eobp)) + (not (looking-at "---"))) + (forward-line 1)) + (setq changelog (buffer-substring + start (line-end-position 0))))))))) (let ((add-log-full-name (car from)) (add-log-mailing-address (cadr from))) (add-change-log-entry-other-window) + (when patch-subject + (setq-local debbugs-gnu-patch-subject patch-subject)) + (when changelog + (delete-region (line-beginning-position) (point-max)) + (save-restriction + (narrow-to-region (point) (point)) + (insert changelog) + (indent-region (point-min) (point-max)))) (let ((point (point))) (when (string-match "\\(bug#[0-9]+\\)" subject) (insert " (" (match-string 1 subject) ").")) @@ -1601,6 +1631,8 @@ If given a prefix, patch in the branch directory instead." (cadr from)))))) (goto-char (point-max)) (end-of-line) + (when changelog + (insert "\n\n")) (insert " Copyright-paperwork-exempt: yes")) (goto-char point))))) @@ -1644,28 +1676,34 @@ If given a prefix, patch in the branch directory instead." "Prepare checking in the current changes." (interactive) (save-some-buffers t) - (when (get-buffer "*vc-dir*") - (kill-buffer (get-buffer "*vc-dir*"))) - (let ((trunk (expand-file-name debbugs-gnu-trunk-directory))) - (if (equal (cl-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)) - (beginning-of-line) - (while (search-forward "edited" nil t) - (vc-dir-mark) - (beginning-of-line)) - (vc-diff nil) - (vc-next-action nil) - (log-edit-insert-changelog t) - (delete-other-windows) - (split-window) - (other-window 1) - (switch-to-buffer "*vc-diff*") - (other-window 1)) + (when (get-buffer "*vc-dir*") + (kill-buffer (get-buffer "*vc-dir*"))) + (let ((patch-subject debbugs-gnu-patch-subject)) + (let ((trunk (expand-file-name debbugs-gnu-trunk-directory))) + (if (equal (cl-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)) + (beginning-of-line) + (while (search-forward "edited" nil t) + (vc-dir-mark) + (beginning-of-line)) + (vc-diff nil) + (vc-next-action nil) + (delete-region (point-min) (point-max)) + (log-edit-insert-changelog t) + (delete-other-windows) + (split-window) + (other-window 1) + (switch-to-buffer "*vc-diff*") + (other-window 1) + (when patch-subject + (insert "Summary: " + (replace-regexp-in-string "^ *\\[PATCH\\] *" "" patch-subject) + "\n")))) (defun debbugs-gnu-save-cache () "Save the bugs cache to a file." -- 2.39.2