]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/ContentHash.pm
www: avoid incorrect instructions for extindex
[public-inbox.git] / lib / PublicInbox / ContentHash.pm
index 4dbe7b5049d57290f56d20e6f5a52d50612ed73b..cc4a54c922d09c9788cfb63b03097631ecc7bcb0 100644 (file)
@@ -8,9 +8,9 @@
 # See L<public-inbox-v2-format(5)> manpage for more details.
 package PublicInbox::ContentHash;
 use strict;
-use warnings;
-use base qw/Exporter/;
-our @EXPORT_OK = qw/content_hash content_digest/;
+use v5.10.1;
+use parent qw(Exporter);
+our @EXPORT_OK = qw(content_hash content_digest git_sha);
 use PublicInbox::MID qw(mids references);
 use PublicInbox::MsgIter;
 
@@ -94,4 +94,13 @@ sub content_hash ($) {
        content_digest($_[0])->digest;
 }
 
+sub git_sha ($$) {
+       my ($n, $eml) = @_;
+       my $dig = Digest::SHA->new($n);
+       my $bref = ref($eml) eq 'SCALAR' ? $eml : \($eml->as_string);
+       $dig->add('blob '.length($$bref)."\0");
+       $dig->add($$bref);
+       $dig;
+}
+
 1;