chiark / gitweb /
Dgit.pm: Provide hashfile()
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 28 Nov 2015 15:56:10 +0000 (15:56 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 16 Jul 2016 15:47:46 +0000 (16:47 +0100)
Call site(s) will come later.

Debian/Dgit.pm

index fa85374..2555812 100644 (file)
@@ -8,6 +8,7 @@ use warnings;
 use POSIX;
 use IO::Handle;
 use Config;
+use Digest::SHA;
 
 BEGIN {
     use Exporter   ();
@@ -18,6 +19,7 @@ BEGIN {
     @EXPORT      = qw(setup_sigwarn
                       debiantag server_branch server_ref
                       stat_exists link_ltarget
+                     hashfile
                       fail ensuredir executable_on_path
                       waitstatusmsg failedcmd
                       cmdoutput cmdoutput_errok
@@ -229,6 +231,13 @@ sub link_ltarget ($$) {
     link $old, $new or die "link $old $new: $!";
 }
 
+sub hashfile ($) {
+    my ($fn) = @_;
+    my $h = Digest::SHA->new(256);
+    $h->addfile($fn);
+    return $h->hexdigest();
+}
+
 sub git_rev_parse ($) {
     return cmdoutput qw(git rev-parse), "$_[0]~0";
 }