user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Cc: "W. Trevor King" <wking@tremily.us>
Subject: [PATCH 2/3] Ssoma::Git: hoist out ensure_sha1 function
Date: Sun, 11 Jan 2015 10:43:22 +0000	[thread overview]
Message-ID: <1420973003-5173-2-git-send-email-e@80x24.org> (raw)

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


             reply	other threads:[~2015-01-11 10:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-11 10:43 Eric Wong [this message]
2015-01-11 10:43 ` [PATCH 3/3] ssoma-mda: Use the email subject as the commit message Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1420973003-5173-2-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    --cc=wking@tremily.us \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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