From 2ccfaae0ea4ce8ab691f1b1a0e8481e9b43dbe1c Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 3 May 2019 21:10:08 -0700 Subject: new scripts: maildir-import-patch(1), notmuch-import-patch(1) Signed-off-by: Sean Whitton --- Makefile | 4 ++- debian/changelog | 2 ++ debian/control | 5 ++++ debian/mailscripts.install | 2 ++ debian/mailscripts.manpages | 2 ++ maildir-import-patch | 56 ++++++++++++++++++++++++++++++++++++++++++ maildir-import-patch.1.pod | 44 +++++++++++++++++++++++++++++++++ notmuch-import-patch | 60 +++++++++++++++++++++++++++++++++++++++++++++ notmuch-import-patch.1.pod | 50 +++++++++++++++++++++++++++++++++++++ 9 files changed, 224 insertions(+), 1 deletion(-) create mode 100755 maildir-import-patch create mode 100644 maildir-import-patch.1.pod create mode 100755 notmuch-import-patch create mode 100644 notmuch-import-patch.1.pod diff --git a/Makefile b/Makefile index a8d0233..220aa6f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ -MANPAGES=mdmv.1 mbox2maildir.1 notmuch-slurp-debbug.1 notmuch-extract-patch.1 +MANPAGES=mdmv.1 mbox2maildir.1 \ + notmuch-slurp-debbug.1 notmuch-extract-patch.1 maildir-import-patch.1 \ + notmuch-import-patch.1 all: $(MANPAGES) diff --git a/debian/changelog b/debian/changelog index 067f965..ec1c74f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,7 @@ mailscripts (0.8-1) UNRELEASED; urgency=medium + * New scripts: maildir-import-patch(1), notmuch-import-patch(1) + - Add git to Recommends. * mbox2maildir: acquire a lock before touching the Maildir, and be sure to flush after copying messages. Per the docs for Python's mailbox module. diff --git a/debian/control b/debian/control index 8bfe006..8667a6c 100644 --- a/debian/control +++ b/debian/control @@ -37,6 +37,7 @@ Depends: ${perl:Depends}, Recommends: devscripts, + git, notmuch, Architecture: all Description: collection of scripts for manipulating e-mail on Debian @@ -50,3 +51,7 @@ Description: collection of scripts for manipulating e-mail on Debian notmuch-slurp-debbug -- add messages from a Debian bug to notmuch . notmuch-extract-patch -- extract a git patch series from notmuch + . + maildir-import-patch -- import a git patch series into a maildir + . + notmuch-import-patch -- import a git patch series into notmuch diff --git a/debian/mailscripts.install b/debian/mailscripts.install index 5836e1a..36b87ea 100644 --- a/debian/mailscripts.install +++ b/debian/mailscripts.install @@ -1,4 +1,6 @@ mbox2maildir /usr/bin mdmv /usr/bin notmuch-slurp-debbug /usr/bin +maildir-import-patch /usr/bin +notmuch-import-patch /usr/bin notmuch-extract-patch/notmuch-extract-patch /usr/bin diff --git a/debian/mailscripts.manpages b/debian/mailscripts.manpages index 1d5eacd..fa878ca 100644 --- a/debian/mailscripts.manpages +++ b/debian/mailscripts.manpages @@ -1,4 +1,6 @@ mbox2maildir.1 mdmv.1 notmuch-slurp-debbug.1 +maildir-import-patch.1 +notmuch-import-patch.1 notmuch-extract-patch.1 diff --git a/maildir-import-patch b/maildir-import-patch new file mode 100755 index 0000000..a17c6cb --- /dev/null +++ b/maildir-import-patch @@ -0,0 +1,56 @@ +#!/usr/bin/python3 + +# maildir-import-patch -- import a git patch series into a maildir + +# Copyright (C) 2019 Sean Whitton +# +# This program 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. +# +# This program 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 this program. If not, see . + +import os +import sys +import mailbox +import shutil +import subprocess +import tempfile + +def eprint(*args, **kwargs): + print(*args, file=sys.stderr, **kwargs) + +us = os.path.basename(sys.argv[0]) + +if len(sys.argv) < 2: + eprint(us + ": usage: " + us + " MAILDIR [git-format-patch(1) args]") + sys.exit(1) + +if not shutil.which("git"): + eprint(us + ": this script requires git to be installed") + sys.exit(1) + +dest_path = sys.argv[1] +dest = mailbox.Maildir(dest_path) + +cmd = [ + "git", "format-patch", + "--thread=shallow", "--no-cc", "--no-to", + "--stdout", +] +user_args = sys.argv[2:] + +with tempfile.NamedTemporaryFile() as fp: + subprocess.run(cmd + user_args, stdout=fp) + source = mailbox.mbox(fp.name) + dest.lock() + for message in source: + dest.add(message) + dest.close() diff --git a/maildir-import-patch.1.pod b/maildir-import-patch.1.pod new file mode 100644 index 0000000..a3ef110 --- /dev/null +++ b/maildir-import-patch.1.pod @@ -0,0 +1,44 @@ +=head1 NAME + +maildir-import-patch - import a git patch series into a maildir + +=head1 SYNOPSIS + +B I [I] + +=head1 DESCRIPTION + +B generates a patch series using +git-format-patch(1), and then imports the series into a maildir as an +e-mail thread, one message per patch. + +This is useful for providing inline feedback on a branch by e-mail, +when the submitter did not use git-send-email(1). + +=head1 EXAMPLE + +Suppose that Bob uses git-request-pull(1) to ask you to review and +merge his branch 'feature'. You add Bob's repository as a remote +called 'bob', check out the bob/feature branch locally, look at the +commits and run some tests. Now you'd like to provide inline feedback +on Bob's changes, indicating which parts you think are ready to merge +and which parts need more work. So you type + +=over 4 + + % maildir-import-patch ~/Maildir/patches master..bob/feature + +=back + +Over in your MUA, you can then reply to each e-mail in the new thread +generated by B, providing line-by-line feedback +on Bob's work. + +=head1 SEE ALSO + +notmuch-import-patch(1), git-format-patch(1), git-send-email(1) + +=head1 AUTHOR + +B was written by Sean Whitton +. diff --git a/notmuch-import-patch b/notmuch-import-patch new file mode 100755 index 0000000..ea61634 --- /dev/null +++ b/notmuch-import-patch @@ -0,0 +1,60 @@ +#!/usr/bin/perl + +# notmuch-import-patch -- import a git patch series into notmuch + +# Copyright (C) 2019 Sean Whitton +# +# This program 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. +# +# This program 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 this program. If not, see . + +use strict; +use warnings; + +use Config::Tiny; +use File::Spec::Functions qw(catfile); +use File::Which; +use IPC::System::Simple qw(systemx); + +my $Config = Config::Tiny->new; + +die "notmuch-import-patch: this script requires git to be installed" + unless defined which "git"; +die "notmuch-import-patch: this script requires notmuch to be installed" + unless defined which "notmuch"; + +my $maildir; + +my $mailscripts_conf_dir = defined $ENV{'XDG_CONFIG_HOME'} + ? catfile $ENV{'XDG_CONFIG_HOME'}, "/mailscripts" + : catfile $ENV{'HOME'}, "/.config/mailscripts"; + +my $notmuch_import_patch_conf = "$mailscripts_conf_dir/notmuch-import-patch"; +if (-f $notmuch_import_patch_conf) { + $Config = Config::Tiny->read($notmuch_import_patch_conf); + $maildir = $Config->{_}->{maildir}; +} else { + # user probably doesn't want our generated patches, which are not + # real e-mails, to go into their inbox + my $database_path = `notmuch config get database.path`; + chomp $database_path; + $maildir = catfile $database_path, "patches"; +} + +die "notmuch-import-patch: $maildir does not look to be a maildir" + unless (-d catfile($maildir, "cur") + && -d catfile($maildir, "new") + && -d catfile($maildir, "tmp")); + +systemx("maildir-import-patch", $maildir, @ARGV); + +systemx(qw(notmuch new)); diff --git a/notmuch-import-patch.1.pod b/notmuch-import-patch.1.pod new file mode 100644 index 0000000..19ce1bc --- /dev/null +++ b/notmuch-import-patch.1.pod @@ -0,0 +1,50 @@ +=head1 NAME + +notmuch-import-patch - import a git patch series into notmuch + +=head1 SYNOPSIS + +B [I] + +=head1 DESCRIPTION + +B is a wrapper around maildir-import-patch(1) +for users of notmuch. It generates a patch series using +git-format-patch(1), and then imports the series into your notmuch +database as an e-mail thread, one message per patch. + +=head1 EXAMPLE + +See "EXAMPLE" in maildir-import-patch(1), replacing the call to +B with a call to B. + +=head1 CONFIGURATION + +B tries to read configuration from the file +B<$XDG_CONFIG_HOME/mailscripts/notmuch-import-patch>, or if +XDG_CONFIG_HOME is not set, it falls back to trying to read +B<~/.config/mailscripts/notmuch-import-patch>. + +The format is I, one per line. The following +configuration key is supported: + +=over 4 + +=item B + +The full path to a maildir indexed by notmuch into which +B will insert patches. Defaults to the +"patches" subdirectory of the B key in your notmuch +configuration. + +=back + +=head1 SEE ALSO + +notmuch(1), maildir-import-patch(1), git-format-patch(1), +git-send-email(1) + +=head1 AUTHOR + +B was written by Sean Whitton +. -- cgit v1.2.3