unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH 2/3] Ssoma::Git: hoist out ensure_sha1 function
@ 2015-01-11 10:43 Eric Wong
  2015-01-11 10:43 ` [PATCH 3/3] ssoma-mda: Use the email subject as the commit message Eric Wong
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2015-01-11 10:43 UTC (permalink / raw)
  To: meta; +Cc: W. Trevor King

We repeat the same pattern in multiple places, and will
again for the next commit to ensure Subject shows up
in the commit message.
---
 lib/Ssoma/Git.pm | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/lib/Ssoma/Git.pm b/lib/Ssoma/Git.pm
index 244d6b3..839d07a 100644
--- a/lib/Ssoma/Git.pm
+++ b/lib/Ssoma/Git.pm
@@ -117,8 +117,13 @@ sub bidi_sha1 {
 	close $out_0 or die "close out_0 failed: $!\n";
 	waitpid($pid, 0) or die "waitpid $pid failed: $!\n";
 	$? == 0 or die "$cmd failed: $?\n";
+	ensure_sha1($sha1, $cmd);
+}
+
+sub ensure_sha1 {
+	my ($sha1, $msg) = @_;
 	chomp $sha1;
-	$sha1 =~ /\A[a-f0-9]{40}\z/i or die "not a SHA-1: $sha1\n";
+	$sha1 =~ /\A[a-f0-9]{40}\z/i or die "not a SHA-1 hex from: $msg\n";
 	$sha1;
 }
 
@@ -128,10 +133,7 @@ sub qx_sha1 {
 	my $sha1 = `$str`;
 
 	die "$str failed: $?\n" if $?;
-	chomp $sha1;
-	$sha1 =~ /\A[a-f0-9]{40}\z/i or
-		die "not a SHA-1 hexdigest from: $str\n";
-	$sha1;
+	ensure_sha1($sha1, $str);
 }
 
 # returns a blob identifier the new message
@@ -250,8 +252,8 @@ sub commit_index {
 		$parent = $self->qx_sha1($cmd);
 	} else {
 		$parent = eval { $self->qx_sha1("$cmd 2>/dev/null") };
-		if (defined $parent && $parent !~ /\A[a-f0-9]{40}\z/) {
-			die "$cmd returned bad SHA-1: $parent\n";
+		if (defined $parent) {
+			ensure_sha1($parent, $cmd);
 		}
 	}
 
-- 
EW


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 3/3] ssoma-mda: Use the email subject as the commit message
  2015-01-11 10:43 [PATCH 2/3] Ssoma::Git: hoist out ensure_sha1 function Eric Wong
@ 2015-01-11 10:43 ` Eric Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2015-01-11 10:43 UTC (permalink / raw)
  To: meta; +Cc: W. Trevor King

This is more interesting than just using 'mda' all the time.
Based on original patch by: W. Trevor King

Cc: W. Trevor King <wking@tremily.us>
---
 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 <me\@example\.com>/, "author set");
+
+		is('zzz', $x[-1], "subject set");
 	}
 }
 
-- 
EW


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-01-11 10:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-11 10:43 [PATCH 2/3] Ssoma::Git: hoist out ensure_sha1 function Eric Wong
2015-01-11 10:43 ` [PATCH 3/3] ssoma-mda: Use the email subject as the commit message Eric Wong

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