From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, URIBL_BLOCKED shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: meta@public-inbox.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id EB9EB1F8C2; Sun, 11 Jan 2015 10:43:25 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Cc: "W. Trevor King" Subject: [PATCH 3/3] ssoma-mda: Use the email subject as the commit message Date: Sun, 11 Jan 2015 10:43:23 +0000 Message-Id: <1420973003-5173-3-git-send-email-e@80x24.org> X-Mailer: git-send-email 2.2.1.269.g12c6725 In-Reply-To: <1420973003-5173-2-git-send-email-e@80x24.org> References: <1420973003-5173-2-git-send-email-e@80x24.org> List-Id: This is more interesting than just using 'mda' all the time. Based on original patch by: W. Trevor King Cc: W. Trevor King --- Makefile.PL | 1 + lib/Ssoma/Git.pm | 13 +++++++------ lib/Ssoma/MDA.pm | 4 +++- t/all.t | 2 ++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 3b961ff..a28be51 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -19,6 +19,7 @@ WriteMakefile( 'Email::LocalDelivery' => 0, 'Email::Simple' => 0, 'Email::MIME' => 0, + 'IPC::Run' => 0, 'File::Path::Expand' => 0, 'Net::IMAP::Simple' => 0, }, diff --git a/lib/Ssoma/Git.pm b/lib/Ssoma/Git.pm index 839d07a..60058df 100644 --- a/lib/Ssoma/Git.pm +++ b/lib/Ssoma/Git.pm @@ -14,6 +14,7 @@ use Fcntl qw/:DEFAULT :flock SEEK_END/; use IO::Handle; use Email::Simple; use Digest::SHA qw/sha1_hex/; +use IPC::Run qw/run/; # Future versions of Ssoma will always be able to handle this version, at least our $REPO_VERSION = 1; @@ -261,19 +262,19 @@ sub commit_index { my @cmd = qw/git commit-tree/; push @cmd, $tree; push @cmd, '-p', $parent if $parent; - - # git commit-tree -m didn't work in older git versions - $message =~ /\A\w+\z/ or die "message must be \\w+ only\n"; - my $commit = $self->qx_sha1("echo $message |". join(' ', @cmd)); + my $commit = ''; + $cmd = join(' ', @cmd); + run(\@cmd, \$message, \$commit) or die "command: $cmd failed: $?\n"; + $commit = ensure_sha1($commit, $cmd); # update the ref @cmd = (qw/git update-ref/, $ref, $commit); push @cmd, $parent if $parent; # verification - system(@cmd) == 0 or die "command: ". join(' ', @cmd) . ": $?\n"; + system(@cmd) == 0 or die "command: $cmd failed: $?\n"; # gc if needed @cmd = qw/git gc --auto/; - system(@cmd) == 0 or die "command: ". join(' ', @cmd) . ": $?\n"; + system(@cmd) == 0 or die "command: $cmd failed: $?\n"; } # keep Git.pm optional, not all installations of git have it diff --git a/lib/Ssoma/MDA.pm b/lib/Ssoma/MDA.pm index 387b1a2..46dd79e 100644 --- a/lib/Ssoma/MDA.pm +++ b/lib/Ssoma/MDA.pm @@ -110,10 +110,12 @@ sub append { my $name = $from[0]->name; my $email = $from[0]->address; my $date = $mime->header('Date'); + my $subject = $mime->header("Subject"); + $subject = '(no subject)' unless defined $subject; local $ENV{GIT_AUTHOR_NAME} ||= $name if defined $name; local $ENV{GIT_AUTHOR_EMAIL} ||= $email if defined $email; local $ENV{GIT_AUTHOR_DATE} ||= $date if defined $date; - $git->commit_index($gii, 0, $ref, "mda"); + $git->commit_index($gii, 0, $ref, $subject); } } diff --git a/t/all.t b/t/all.t index 6f6a203..2d86989 100644 --- a/t/all.t +++ b/t/all.t @@ -52,6 +52,8 @@ EOF chomp @x; my @au = grep(/^author /, @x); like($au[0], qr/\Aauthor me /, "author set"); + + is('zzz', $x[-1], "subject set"); } } -- EW