Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 678A0429E33 for ; Fri, 6 Jan 2012 02:03:26 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yKnckYkHDRGO for ; Fri, 6 Jan 2012 02:03:25 -0800 (PST) Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id CFADC429E32 for ; Fri, 6 Jan 2012 02:03:24 -0800 (PST) Received: by wgbds13 with SMTP id ds13so1308182wgb.2 for ; Fri, 06 Jan 2012 02:03:23 -0800 (PST) Received: by 10.180.83.104 with SMTP id p8mr6133905wiy.4.1325844203443; Fri, 06 Jan 2012 02:03:23 -0800 (PST) Received: from hotblack-desiato.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25]) by mx.google.com with ESMTPS id n3sm22869186wiz.9.2012.01.06.02.03.21 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 06 Jan 2012 02:03:22 -0800 (PST) Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000) id 8056DA01DB; Fri, 6 Jan 2012 10:03:20 +0000 (GMT) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH v2] emacs: Helpers for notmuch developers. Date: Fri, 6 Jan 2012 10:03:19 +0000 Message-Id: <1325844199-1812-1-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1325685678-12710-1-git-send-email-dme@dme.org> References: <1325685678-12710-1-git-send-email-dme@dme.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Jan 2012 10:03:26 -0000 --- - Prefix the branch name with 'review/' - Avoid `shell-command', which also results in better error reporting when 'git-am' fails. emacs/notmuch-dev.el | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 129 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..ac427ec --- /dev/null +++ b/emacs/notmuch-dev.el @@ -0,0 +1,129 @@ +;; 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 . +;; +;; Authors: David Edmondson + +(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")) + +(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-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) -- 1.7.7.3