refactor(tvix/nix-compat): introduce CaHash::algo_str
This is the `{fixed,fixed:r,text}:{sha*,md5}` prefix used in various
string representations.
Factor that code out, and use it in the two places it can be used in.
Change-Id: Ic9555fa9e1884198d435e55c7f630b8d3ba2a032
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12041
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: Brian Olsen <me@griff.name>
This commit is contained in:
parent
5114504b67
commit
c8f92c6e9f
2 changed files with 27 additions and 28 deletions
|
|
@ -12,7 +12,6 @@ use jemallocator::Jemalloc;
|
|||
use nix_compat::{
|
||||
narinfo::{self, NarInfo},
|
||||
nixbase32,
|
||||
nixhash::{CAHash, NixHash},
|
||||
};
|
||||
use polars::{io::parquet::ParquetWriter, prelude::*};
|
||||
use std::{
|
||||
|
|
@ -177,26 +176,8 @@ impl FrameBuilder {
|
|||
}));
|
||||
|
||||
if let Some(ca) = &entry.ca {
|
||||
// decompose the CAHash into algo and hash parts
|
||||
// TODO(edef): move this into CAHash
|
||||
let (algo, hash) = match ca {
|
||||
CAHash::Flat(h) => match h {
|
||||
NixHash::Md5(h) => ("fixed:md5", &h[..]),
|
||||
NixHash::Sha1(h) => ("fixed:sha1", &h[..]),
|
||||
NixHash::Sha256(h) => ("fixed:sha256", &h[..]),
|
||||
NixHash::Sha512(h) => ("fixed:sha512", &h[..]),
|
||||
},
|
||||
CAHash::Nar(h) => match h {
|
||||
NixHash::Md5(h) => ("fixed:r:md5", &h[..]),
|
||||
NixHash::Sha1(h) => ("fixed:r:sha1", &h[..]),
|
||||
NixHash::Sha256(h) => ("fixed:r:sha256", &h[..]),
|
||||
NixHash::Sha512(h) => ("fixed:r:sha512", &h[..]),
|
||||
},
|
||||
CAHash::Text(h) => ("text:sha256", &h[..]),
|
||||
};
|
||||
|
||||
self.ca_algo.append_value(algo);
|
||||
self.ca_hash.append_value(hash);
|
||||
self.ca_algo.append_value(ca.algo_str());
|
||||
self.ca_hash.append_value(ca.hash().digest_as_bytes());
|
||||
} else {
|
||||
self.ca_algo.append_null();
|
||||
self.ca_hash.append_null();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue