diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2020-05-11 15:25:35 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2020-05-11 15:25:35 -0700 |
commit | 75df035544868a65e2a3d5603e65fc6f578e1550 (patch) | |
tree | b8b0cfde404dcb0dd84e5b986f5107ae560b7b9c /maildir-import-patch | |
parent | c92a2b7d7aa9467e9ff69643ee46874dfb9eb829 (diff) | |
parent | ab4acbc313dc1a20e166045e61c603053c4f00dc (diff) | |
download | mailscripts-75df035544868a65e2a3d5603e65fc6f578e1550.tar.gz |
Merge tag 'debian/0.20-1' into buster-bpo
mailscripts release 0.20-1 for unstable (sid) [dgit]
[dgit distro=debian no-split --quilt=linear]
# gpg: Signature made Tue 05 May 2020 10:57:07 AM MST
# gpg: using RSA key 9B917007AE030E36E4FC248B695B7AE4BF066240
# gpg: Good signature from "Sean Whitton <spwhitton@spwhitton.name>" [ultimate]
# Primary key fingerprint: 8DC2 487E 51AB DD90 B5C4 753F 0F56 D055 3B6D 411B
# Subkey fingerprint: 9B91 7007 AE03 0E36 E4FC 248B 695B 7AE4 BF06 6240
Diffstat (limited to 'maildir-import-patch')
-rwxr-xr-x | maildir-import-patch | 98 |
1 files changed, 59 insertions, 39 deletions
diff --git a/maildir-import-patch b/maildir-import-patch index f69a5e6..605435b 100755 --- a/maildir-import-patch +++ b/maildir-import-patch @@ -1,8 +1,8 @@ -#!/usr/bin/python3 +#!/usr/bin/perl # maildir-import-patch -- import a git patch series into a maildir -# Copyright (C) 2019 Sean Whitton +# Copyright (C) 2019-2020 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 @@ -17,40 +17,60 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. -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() +use strict; +use warnings; + +use Cwd; +use File::Basename; +use File::Temp (); +use File::Which; +use List::MoreUtils "firstidx"; +use Mail::Box::Manager; + +my $us = basename $0; +my $maildir_dir = shift + or die "$us: usage: $us MAILDIR [git-format-patch(1) args]\n"; +which "git" or die "$us: this script requires git to be installed\n"; +eval { require Git::Wrapper } + or die "$us: this script requires Git::Wrapper (libgit-wrapper-perl)\n"; + +my $git = Git::Wrapper->new(getcwd); +my $toplevel; +{ + local $@; + eval { ($toplevel) = $git->rev_parse({ show_toplevel => 1 }) }; + $@ and die "$us: pwd doesn't look like a git repository ..\n"; +} +$toplevel =~ s/\.git$//; + +if (firstidx(sub { /^--subject-prefix/ }, @ARGV) == -1) { + my $subject_prefix; + my $rfc_idx = firstidx { /^--rfc$/ } @ARGV; + if ($rfc_idx == -1) { + $subject_prefix = "PATCH"; + } else { + $subject_prefix = "RFC PATCH"; + splice @ARGV, $rfc_idx, 1; + } + my ($project) = $git->config(qw|--local --get --default|, + basename($toplevel), "mailscripts.project-shortname"); + unshift @ARGV, "--subject-prefix=$subject_prefix $project imported"; +} + +my $mgr = Mail::Box::Manager->new; +my $maildir + = $mgr->open($maildir_dir, type => "maildir", access => "w", create => 1); + +my $mbox_file = File::Temp->new; +my $pid = fork; +die "fork() failed: $!" unless defined $pid; +unless ($pid) { + open STDOUT, ">&=", $mbox_file->fileno + or die "couldn't reopen child's STDOUT: $!"; + exec qw(git format-patch --no-cc --no-to --stdout --thread=shallow), @ARGV; +} +$mbox_file->close; +wait; + +my $mbox = $mgr->open($mbox_file->filename, type => "mbox", access => "r"); +$mgr->copyMessage($maildir, $_) for $mbox->messages; |