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 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 B48FE1F7B4; Sun, 11 Jan 2015 10:43:25 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Cc: "W. Trevor King" Subject: [PATCH 2/3] Ssoma::Git: hoist out ensure_sha1 function Date: Sun, 11 Jan 2015 10:43:22 +0000 Message-Id: <1420973003-5173-2-git-send-email-e@80x24.org> X-Mailer: git-send-email 2.2.1.269.g12c6725 List-Id: 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