1 ;;; patch.el --- mail/apply a patch
3 ;; Copyright (C) 2001, 2006 Free Software Foundation, Inc.
5 ;; GNU Emacs is free software; you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation; either version 2, or (at your option)
10 ;; GNU Emacs is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with GNU Emacs; see the file COPYING. If not, write to the
17 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 ;; Boston, MA 02110-1301, USA.
20 ;;; Author: Thien-Thi Nguyen <ttn@gnu.org>
22 ;;; Favorite-Favorite: Favorite-Favorite
26 ;; This file has two symmetrical usage modes, for patch creation and
27 ;; application, respectively. The details are somewhat tuned for Guile
28 ;; maintenance; probably we should generalize it a bit and add it to
29 ;; Emacs proper at some point in the future. Long live free software!
31 ;; On the patch creation side of things, there are various version
32 ;; control systems that are happy to write a diff to stdout (and
33 ;; numerous Emacs interfaces to them all). Thus, we provide only a
34 ;; simple `patch-send' that composes mail from the current buffer;
35 ;; the contents of that buffer are left as an exercise for the patch
36 ;; creator. When preparing the mail, `patch-send' scans the patch
37 ;; for standard filename headers and sets up a skeleton change log --
38 ;; filling this in is a good way to earn respect from maintainers (hint
39 ;; hint). Type `C-c C-c' to send the mail when you are done. (See
40 ;; `compose-mail' for more info.)
42 ;; TODO: Write/document patch-apply side of things.
43 ;; TODO: Integrate w/ `ediff-patch-buffer' et al.
48 (require 'update-changelog) ; for stitching
52 (defvar patch-greeting "hello guile maintainers,\n\n"
53 "*String to insert at beginning of patch mail.")
55 (defun patch-scan-files ()
58 (while (re-search-forward "^[+][+][+] \\(\\S-+\\)" (point-max) t)
59 (setq files (cons (cons (match-string 1)
64 (defun patch-common-prefix (filenames)
65 (let* ((first-file (car filenames))
66 (prefix (and first-file (file-name-directory first-file))))
68 (not (string= "" prefix))
69 (not (every (lambda (filename)
70 (string-match (concat "^" prefix) filename))
72 (setq prefix (file-name-directory (substring prefix 0 -1))))
75 (defun patch-changelog-skeleton ()
76 (let* ((file-info (patch-scan-files))
77 (fullpath-files (mapcar 'car file-info))
78 (cut (length (patch-common-prefix fullpath-files)))
79 (files (mapcar (lambda (fullpath-file)
80 (substring fullpath-file cut))
84 (concat (make-string (length file) ?_) "\n" file "\n[writeme]"))
88 (defun patch-send (buffer subject)
89 (interactive "bBuffer: \nsSubject: ")
90 (when (string= "" subject)
91 (error "(empty subject)"))
92 (compose-mail "bug-guile@gnu.org" subject)
93 (insert (with-current-buffer buffer (buffer-string)))
95 (insert patch-greeting)
97 (insert "here is a patch ... [overview/observations/etc]\n\n"
98 (patch-changelog-skeleton) "\n\n\n"
99 (make-string 72 ?_) "\n")))
106 ;;; patch.el ends here