Skip to content

Commit

Permalink
Organize content-address.hh a bit better
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Oct 13, 2020
1 parent a0f369a commit 39c11c5
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions src/libstore/content-address.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,42 @@
namespace nix {

/*
* Mini content address
* Content addressing method
*/

enum struct FileIngestionMethod : uint8_t {
Flat = false,
Recursive = true
};

/*
We only have one way to hash text with references, so this is single-value
type is only useful in std::variant.
*/
struct TextHashMethod { };

struct FixedOutputHashMethod {
FileIngestionMethod fileIngestionMethod;
HashType hashType;
};

/* Compute the prefix to the hash algorithm which indicates how the files were
ingested. */
std::string makeFileIngestionPrefix(const FileIngestionMethod m);


typedef std::variant<
TextHashMethod,
FixedOutputHashMethod
> ContentAddressMethod;

ContentAddressMethod parseContentAddressMethod(std::string_view rawCaMethod);

std::string renderContentAddressMethod(ContentAddressMethod caMethod);

/*
* Mini content address
*/

struct TextHash {
Hash hash;
Expand Down Expand Up @@ -43,10 +71,6 @@ typedef std::variant<
FixedOutputHash // for path computed by makeFixedOutputPath
> ContentAddress;

/* Compute the prefix to the hash algorithm which indicates how the files were
ingested. */
std::string makeFileIngestionPrefix(const FileIngestionMethod m);

std::string renderContentAddress(ContentAddress ca);

std::string renderContentAddress(std::optional<ContentAddress> ca);
Expand All @@ -57,25 +81,6 @@ std::optional<ContentAddress> parseContentAddressOpt(std::string_view rawCaOpt);

Hash getContentAddressHash(const ContentAddress & ca);

/*
We only have one way to hash text with references, so this is single-value
type is only useful in std::variant.
*/
struct TextHashMethod { };
struct FixedOutputHashMethod {
FileIngestionMethod fileIngestionMethod;
HashType hashType;
};

typedef std::variant<
TextHashMethod,
FixedOutputHashMethod
> ContentAddressMethod;

ContentAddressMethod parseContentAddressMethod(std::string_view rawCaMethod);

std::string renderContentAddressMethod(ContentAddressMethod caMethod);

/*
* References set
*/
Expand Down

0 comments on commit 39c11c5

Please sign in to comment.