Re: folder and path completely broken in HEAD?
[notmuch-archives.git] / 85 / cacf558279f68b505baf55574cce7f9ef2f8e0
1 Return-Path: <dme@dme.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 678A0429E33\r
6         for <notmuch@notmuchmail.org>; Fri,  6 Jan 2012 02:03:26 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id yKnckYkHDRGO for <notmuch@notmuchmail.org>;\r
16         Fri,  6 Jan 2012 02:03:25 -0800 (PST)\r
17 Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com\r
18  [74.125.82.45])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
19  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
20  CFADC429E32    for <notmuch@notmuchmail.org>; Fri,  6 Jan 2012 02:03:24 -0800\r
21  (PST)\r
22 Received: by wgbds13 with SMTP id ds13so1308182wgb.2\r
23         for <notmuch@notmuchmail.org>; Fri, 06 Jan 2012 02:03:23 -0800 (PST)\r
24 Received: by 10.180.83.104 with SMTP id p8mr6133905wiy.4.1325844203443;\r
25         Fri, 06 Jan 2012 02:03:23 -0800 (PST)\r
26 Received: from hotblack-desiato.hh.sledj.net\r
27         (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25])\r
28         by mx.google.com with ESMTPS id n3sm22869186wiz.9.2012.01.06.02.03.21\r
29         (version=TLSv1/SSLv3 cipher=OTHER);\r
30         Fri, 06 Jan 2012 02:03:22 -0800 (PST)\r
31 Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
32         id 8056DA01DB; Fri,  6 Jan 2012 10:03:20 +0000 (GMT)\r
33 From: David Edmondson <dme@dme.org>\r
34 To: notmuch@notmuchmail.org\r
35 Subject: [PATCH v2] emacs: Helpers for notmuch developers.\r
36 Date: Fri,  6 Jan 2012 10:03:19 +0000\r
37 Message-Id: <1325844199-1812-1-git-send-email-dme@dme.org>\r
38 X-Mailer: git-send-email 1.7.7.3\r
39 In-Reply-To: <1325685678-12710-1-git-send-email-dme@dme.org>\r
40 References: <1325685678-12710-1-git-send-email-dme@dme.org>\r
41 MIME-Version: 1.0\r
42 Content-Type: text/plain; charset=UTF-8\r
43 Content-Transfer-Encoding: 8bit\r
44 X-BeenThere: notmuch@notmuchmail.org\r
45 X-Mailman-Version: 2.1.13\r
46 Precedence: list\r
47 List-Id: "Use and development of the notmuch mail system."\r
48         <notmuch.notmuchmail.org>\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
52 List-Post: <mailto:notmuch@notmuchmail.org>\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
56 X-List-Received-Date: Fri, 06 Jan 2012 10:03:26 -0000\r
57 \r
58 ---\r
59 \r
60 - Prefix the branch name with 'review/'\r
61 - Avoid `shell-command', which also results in better error reporting\r
62   when 'git-am' fails.\r
63 \r
64  emacs/notmuch-dev.el |  129 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
65  1 files changed, 129 insertions(+), 0 deletions(-)\r
66  create mode 100644 emacs/notmuch-dev.el\r
67 \r
68 diff --git a/emacs/notmuch-dev.el b/emacs/notmuch-dev.el\r
69 new file mode 100644\r
70 index 0000000..ac427ec\r
71 --- /dev/null\r
72 +++ b/emacs/notmuch-dev.el\r
73 @@ -0,0 +1,129 @@\r
74 +;; notmuch-dev.el --- help for notmuch developers\r
75 +;;\r
76 +;; Copyright © David Edmondson\r
77 +;;\r
78 +;; This file is part of Notmuch.\r
79 +;;\r
80 +;; Notmuch is free software: you can redistribute it and/or modify it\r
81 +;; under the terms of the GNU General Public License as published by\r
82 +;; the Free Software Foundation, either version 3 of the License, or\r
83 +;; (at your option) any later version.\r
84 +;;\r
85 +;; Notmuch is distributed in the hope that it will be useful, but\r
86 +;; WITHOUT ANY WARRANTY; without even the implied warranty of\r
87 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
88 +;; General Public License for more details.\r
89 +;;\r
90 +;; You should have received a copy of the GNU General Public License\r
91 +;; along with Notmuch.  If not, see <http://www.gnu.org/licenses/>.\r
92 +;;\r
93 +;; Authors: David Edmondson <dme@dme.org>\r
94 +\r
95 +(require 'notmuch-lib)\r
96 +(require 'notmuch-show)\r
97 +(require 'magit)\r
98 +\r
99 +(defgroup notmuch-dev nil\r
100 +  "Helpers for notmuch developers."\r
101 +  :group 'notmuch)\r
102 +\r
103 +(defcustom notmuch-dev-master-repository "git://notmuchmail.org/git/notmuch"\r
104 +  "The URI of the master notmuch repository."\r
105 +  :group 'notmuch-dev\r
106 +  :type 'string)\r
107 +\r
108 +(defcustom notmuch-dev-temporary-directory temporary-file-directory\r
109 +  "A directory in which to place temporary repositories."\r
110 +  :group 'notmuch-dev\r
111 +  :type 'string)\r
112 +\r
113 +;;\r
114 +\r
115 +(defvar notmuch-dev-temporary-repository-name (concat "notmuch-dev-" (user-login-name))\r
116 +  "The name of the temporary repository.")\r
117 +\r
118 +(defvar notmuch-dev-temporary-repository-path\r
119 +  (file-name-as-directory (file-truename (concat notmuch-dev-temporary-directory "/"\r
120 +                                                notmuch-dev-temporary-repository-name)))\r
121 +  "The path of the temporary repository.")\r
122 +\r
123 +(defun notmuch-dev-make-temporary-repository ()\r
124 +  (unless (file-directory-p notmuch-dev-temporary-repository-path)\r
125 +    (message "Cloning %s into %s..." \r
126 +            notmuch-dev-master-repository notmuch-dev-temporary-repository-path)\r
127 +    (magit-run* (list magit-git-executable "clone"\r
128 +                     notmuch-dev-master-repository\r
129 +                     notmuch-dev-temporary-repository-path))\r
130 +    (message "Cloning %s into %s...done." \r
131 +            notmuch-dev-master-repository notmuch-dev-temporary-repository-path)\r
132 +\r
133 +    (unless (file-directory-p notmuch-dev-temporary-repository-path)\r
134 +      (error "git clone failed."))))\r
135 +\r
136 +(defun notmuch-dev-checkout-master ()\r
137 +  (magit-checkout "master"))\r
138 +\r
139 +(defun notmuch-dev-delete-branch (name)\r
140 +  (magit-delete-branch name))\r
141 +\r
142 +(defun notmuch-dev-create-branch (name)\r
143 +  ;; Switches to the new branch automatically.\r
144 +  (magit-create-branch name "master"))\r
145 +\r
146 +(defun notmuch-dev-flatten-title (title)\r
147 +  (let* ((s (downcase title))\r
148 +        (s (replace-regexp-in-string "[ \t/]+" "-" s))\r
149 +        (s (replace-regexp-in-string "[\]\[\":]" "" s))\r
150 +        (s (replace-regexp-in-string "\\.$" "" s))\r
151 +        )\r
152 +    s))\r
153 +\r
154 +(defun notmuch-dev-title-to-branch (title)\r
155 +  (concat "review/" (notmuch-dev-flatten-title title)))\r
156 +\r
157 +(defun notmuch-dev-title-to-mbox (title)\r
158 +  (concat notmuch-dev-temporary-directory "/"\r
159 +         (notmuch-dev-flatten-title title) ".mbox"))\r
160 +\r
161 +;;\r
162 +\r
163 +(defun notmuch-dev-show-review-patch ()\r
164 +  "Call this from `notmuch-show-mode'."\r
165 +  (interactive)\r
166 +\r
167 +  (notmuch-dev-review-patch (notmuch-show-get-subject)\r
168 +                           (mapconcat 'identity\r
169 +                                      (notmuch-show-get-message-ids-for-open-messages)\r
170 +                                      " OR ")))\r
171 +\r
172 +(defun notmuch-dev-review-patch (title search-terms)\r
173 +  (let ((patch-name (notmuch-dev-title-to-branch title))\r
174 +       (mbox-path (notmuch-dev-title-to-mbox title)))\r
175 +\r
176 +    (notmuch-dev-make-temporary-repository)\r
177 +\r
178 +    ;; Switch to the repository directory.\r
179 +    (let ((default-directory notmuch-dev-temporary-repository-path))\r
180 +\r
181 +      (notmuch-dev-checkout-master)\r
182 +      ;; Delete the branch if it exists.\r
183 +      (condition-case nil\r
184 +         (notmuch-dev-delete-branch patch-name)\r
185 +       (error nil))\r
186 +      (notmuch-dev-create-branch patch-name)\r
187 +\r
188 +      ;; Have notmuch generate mailbox format output for the search\r
189 +      ;; terms...\r
190 +      (with-temp-file mbox-path\r
191 +       (erase-buffer)\r
192 +       (call-process notmuch-command nil t nil\r
193 +                     "show" "--format=mbox" search-terms))\r
194 +\r
195 +      ;; ...and feed that to git-am.\r
196 +      (magit-run* (list magit-git-executable "am" mbox-path))\r
197 +\r
198 +      (magit-status notmuch-dev-temporary-repository-path))))\r
199 +\r
200 +;;\r
201 +\r
202 +(provide 'notmuch-dev)\r
203 -- \r
204 1.7.7.3\r
205 \r