unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: Helpers for notmuch developers.
@ 2012-01-04 14:01 David Edmondson
  2012-01-06  3:39 ` David Bremner
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: David Edmondson @ 2012-01-04 14:01 UTC (permalink / raw)
  To: notmuch

---

I've been using this for a few days and decided to share it to get
feedback. Reviewing patches can be tedious, so I tried to make things
a little simpler.

To use this, load the file and then from `notmuch-show-mode' invoke
`notmuch-dev-show-review-patch'. It assumes that any open messages
contain patches and attempts to build a repository with the patches
applied.

General management (i.e. keeping up to date) of the repository it uses
is your responsibility, as is cleaning out old branches. You can, of
course, just delete the temporary repository after using it - the code
will re-create it next time.

If you have a slow network connection then a local copy of the main
repository can be specified by changing
`notmuch-dev-master-repository'.

Comments?

 emacs/notmuch-dev.el |  121 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 121 insertions(+), 0 deletions(-)
 create mode 100644 emacs/notmuch-dev.el

diff --git a/emacs/notmuch-dev.el b/emacs/notmuch-dev.el
new file mode 100644
index 0000000..63ee490
--- /dev/null
+++ b/emacs/notmuch-dev.el
@@ -0,0 +1,121 @@
+;; notmuch-dev.el --- help for notmuch developers
+;;
+;; Copyright © David Edmondson
+;;
+;; This file is part of Notmuch.
+;;
+;; Notmuch is free software: you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+;;
+;; Notmuch is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with Notmuch.  If not, see <http://www.gnu.org/licenses/>.
+;;
+;; Authors: David Edmondson <dme@dme.org>
+
+(require 'notmuch-lib)
+(require 'notmuch-show)
+(require 'magit)
+
+(defgroup notmuch-dev nil
+  "Helpers for notmuch developers."
+  :group 'notmuch)
+
+(defcustom notmuch-dev-master-repository "git://notmuchmail.org/git/notmuch"
+  "The URI of the master notmuch repository."
+  :group 'notmuch-dev
+  :type 'string)
+
+(defcustom notmuch-dev-temporary-directory temporary-file-directory
+  "A directory in which to place temporary repositories."
+  :group 'notmuch-dev
+  :type 'string)
+
+;;
+
+(defvar notmuch-dev-temporary-repository-name (concat "notmuch-dev-" (user-login-name))
+  "The name of the temporary repository.")
+
+(defvar notmuch-dev-temporary-repository-path
+  (file-name-as-directory (file-truename (concat notmuch-dev-temporary-directory "/"
+						 notmuch-dev-temporary-repository-name)))
+  "The path of the temporary repository.")
+
+(defun notmuch-dev-make-temporary-repository ()
+  (unless (file-directory-p notmuch-dev-temporary-repository-path)
+    (message "Cloning %s into %s..." 
+	     notmuch-dev-master-repository notmuch-dev-temporary-repository-path)
+    (magit-run* (list magit-git-executable "clone"
+		      notmuch-dev-master-repository
+		      notmuch-dev-temporary-repository-path))
+
+    (unless (file-directory-p notmuch-dev-temporary-repository-path)
+      (error "git clone failed.")))
+
+  ;; Causes us to switch to the magit buffer - is that unfortunate in
+  ;; some situations?
+  (magit-status notmuch-dev-temporary-repository-path))
+
+(defun notmuch-dev-checkout-master ()
+  (magit-checkout "master"))
+
+(defun notmuch-dev-delete-branch (name)
+  (magit-delete-branch name))
+
+(defun notmuch-dev-create-branch (name)
+  ;; Switches to the new branch automatically.
+  (magit-create-branch name "master"))
+
+(defun notmuch-dev-title-to-branch (title)
+  (let* ((s (downcase title))
+	 (s (replace-regexp-in-string "[ \t]+" "-" s))
+	 (s (replace-regexp-in-string "[\]\[\":]" "" s))
+	 (s (replace-regexp-in-string ".$" "" s))
+	 )
+    s))
+
+;;
+
+(defun notmuch-dev-show-review-patch ()
+  "Call this from `notmuch-show-mode'."
+  (interactive)
+
+  (notmuch-dev-review-patch (notmuch-show-get-subject)
+			    (mapconcat 'identity
+				       (notmuch-show-get-message-ids-for-open-messages)
+				       " | ")))
+
+(defun notmuch-dev-review-patch (title search-terms)
+  (let ((patch-name (notmuch-dev-title-to-branch title)))
+
+    (notmuch-dev-make-temporary-repository)
+
+    ;; Switch to the repository directory.
+    (let ((default-directory notmuch-dev-temporary-repository-path))
+
+      (notmuch-dev-checkout-master)
+      ;; Delete the branch if it exists.
+      (condition-case nil
+	  (notmuch-dev-delete-branch patch-name)
+	(error nil))
+      (notmuch-dev-create-branch patch-name)
+
+      ;; Have notmuch generate mailbox format output for the search
+      ;; terms and feed that to git-am.
+      (shell-command
+       (concat
+	notmuch-command " show --format=mbox " (shell-quote-argument search-terms)
+	" | "
+	"git am --quiet"))
+
+      (magit-status notmuch-dev-temporary-repository-path))))
+
+;;
+
+(provide 'notmuch-dev)
-- 
1.7.7.3

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2012-01-16 21:01 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-04 14:01 [PATCH] emacs: Helpers for notmuch developers David Edmondson
2012-01-06  3:39 ` David Bremner
2012-01-06  8:27   ` David Edmondson
2012-01-06 10:03 ` [PATCH v2] " David Edmondson
2012-01-07 11:53   ` David Bremner
2012-01-09  8:23     ` David Edmondson
2012-01-09 10:38       ` David Bremner
2012-01-09 11:16         ` David Edmondson
2012-01-13  3:04           ` David Bremner
2012-01-13 10:25             ` [PATCH] notmuch-dev: Forcibly delete branches David Edmondson
2012-01-13 12:25               ` David Bremner
2012-01-13 13:28                 ` [PATCH 1/2] notmuch-dev: Remove more characters from branch names David Edmondson
2012-01-13 13:28                   ` [PATCH 2/2] notmuch-dev: Update the master branch when requested David Edmondson
2012-01-13 21:03                     ` Xavier Maillard
2012-01-16  9:07                       ` David Edmondson
2012-01-16 21:19                         ` Xavier Maillard
2012-01-06 22:56 ` [PATCH] emacs: Helpers for notmuch developers Tomi Ollila
2012-01-09  8:27   ` David Edmondson

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).