unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
blob 3a15bf43f62f973c8d28f3fcff3ea7388c2d6397 4453 bytes (raw)
name: emacs/notmuch-dev.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
 
;; 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))
    (message "Cloning %s into %s...done." 
	     notmuch-dev-master-repository notmuch-dev-temporary-repository-path)

    (unless (file-directory-p notmuch-dev-temporary-repository-path)
      (error "git clone failed."))))

(defun notmuch-dev-checkout-master ()
  (magit-checkout "master")
  (when current-prefix-arg
    (message "Updating master...")
    ;; Don't use `magit-pull' because it runs asynchronously.
    (magit-run-git "pull" "-v")
    (message "Updating master...done.")))

(defun notmuch-dev-delete-branch (name)
  ;; `magit-delete-branch' uses "-d", which is not sufficiently
  ;; aggressive for us.
  (magit-run-git "branch" "-D" name))

(defun notmuch-dev-create-branch (name)
  ;; Switches to the new branch automatically.
  (magit-create-branch name "master"))

(defun notmuch-dev-flatten-title (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-title-to-branch (title)
  (concat "review/" (notmuch-dev-flatten-title title)))

(defun notmuch-dev-title-to-mbox (title)
  (concat notmuch-dev-temporary-directory "/"
	  (notmuch-dev-flatten-title title) ".mbox"))

;;

(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)
				       " OR ")))

(defun notmuch-dev-review-patch (title search-terms)
  (let ((patch-name (notmuch-dev-title-to-branch title))
	(mbox-path (notmuch-dev-title-to-mbox 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...
      (with-temp-file mbox-path
	(erase-buffer)
	(call-process notmuch-command nil t nil
		      "show" "--format=mbox" search-terms))

      ;; ...and feed that to git-am.
      (magit-run* (list magit-git-executable "am" mbox-path))

      (magit-status notmuch-dev-temporary-repository-path))))

;;

(provide 'notmuch-dev)

debug log:

solving 3a15bf4 ...
found 3a15bf4 in https://yhetil.org/notmuch/1326461294-25546-2-git-send-email-dme@dme.org/
found 465846f in https://yhetil.org/notmuch/1326461294-25546-1-git-send-email-dme@dme.org/
found 871ce3b in https://yhetil.org/notmuch/1326450329-10108-1-git-send-email-dme@dme.org/
found ac427ec in https://yhetil.org/notmuch/1325844199-1812-1-git-send-email-dme@dme.org/

applying [1/4] https://yhetil.org/notmuch/1325844199-1812-1-git-send-email-dme@dme.org/
diff --git a/emacs/notmuch-dev.el b/emacs/notmuch-dev.el
new file mode 100644
index 0000000..ac427ec


applying [2/4] https://yhetil.org/notmuch/1326450329-10108-1-git-send-email-dme@dme.org/
diff --git a/emacs/notmuch-dev.el b/emacs/notmuch-dev.el
index ac427ec..871ce3b 100644


applying [3/4] https://yhetil.org/notmuch/1326461294-25546-1-git-send-email-dme@dme.org/
diff --git a/emacs/notmuch-dev.el b/emacs/notmuch-dev.el
index 871ce3b..465846f 100644


applying [4/4] https://yhetil.org/notmuch/1326461294-25546-2-git-send-email-dme@dme.org/
diff --git a/emacs/notmuch-dev.el b/emacs/notmuch-dev.el
index 465846f..3a15bf4 100644

4:58: trailing whitespace.
    (message "Cloning %s into %s..." 
4:63: trailing whitespace.
    (message "Cloning %s into %s...done." 
Checking patch emacs/notmuch-dev.el...
Applied patch emacs/notmuch-dev.el cleanly.
Checking patch emacs/notmuch-dev.el...
Applied patch emacs/notmuch-dev.el cleanly.
Checking patch emacs/notmuch-dev.el...
Applied patch emacs/notmuch-dev.el cleanly.
Checking patch emacs/notmuch-dev.el...
Applied patch emacs/notmuch-dev.el cleanly.
warning: 2 lines add whitespace errors.

index at:
100644 3a15bf43f62f973c8d28f3fcff3ea7388c2d6397	emacs/notmuch-dev.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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).