hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 25d3f6ac79a2ee07214f02af4f31540089274d12
parent fc8562c4f5a93afaff824988d7cc191e75e450c9
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri, 26 Feb 2021 15:13:50 -0500

hare::module: store hashes unencoded

Diffstat:
Mhare/module/scan.ha | 19++++++-------------
Mhare/module/types.ha | 4++--
2 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/hare/module/scan.ha b/hare/module/scan.ha @@ -1,5 +1,4 @@ use crypto::sha256; -use encoding::hex; use fs; use hare::ast; use hash; @@ -8,14 +7,12 @@ use path; use slice; use strings; -fn hash_file(ctx: *context, path: path::path) (str | error) = { +fn hash_file(ctx: *context, path: path::path) ([]u8 | error) = { let sha = sha256::sha256(); //defer! hash::close(sha); let f = fs::open(ctx.fs, path, io::mode::READ)?; io::copy(hash::writer(sha), f)?; - let sum = hash::finish(sha); - defer free(sum); - return hex::encode(sum); + return hash::finish(sha); }; // Scans the files in a directory for eligible build inputs and returns a @@ -34,11 +31,9 @@ export fn scan(ctx: *context, path: path::path) (version | error) = { ... }; append(inputs, in); - hash::write(sha, strings::to_utf8(in.hash)); - let sum = hash::finish(sha); - defer free(sum); + hash::write(sha, in.hash); return version { - hash = hex::encode(sum), + hash = hash::finish(sha), inputs = inputs, }; }, @@ -60,15 +55,13 @@ export fn scan(ctx: *context, path: path::path) (version | error) = { ... }; append(inputs, in); - hash::write(sha, strings::to_utf8(in.hash)); + hash::write(sha, in.hash); }, * => void, }, }; - let sum = hash::finish(sha); - defer free(sum); return version { - hash = hex::encode(sum), + hash = hash::finish(sha), inputs = inputs, }; }; diff --git a/hare/module/types.ha b/hare/module/types.ha @@ -23,13 +23,13 @@ export type manifest = struct { // A module version: a set of possible input files for that module. export type version = struct { - hash: str, + hash: []u8, inputs: []input, }; // An input to a module, generally a source file. export type input = struct { - hash: str, + hash: []u8, path: path::path, stat: fs::filestat, };