Skip to content

Commit

Permalink
Fill in missing comparison operators for content addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Mar 25, 2022
1 parent 0dc2974 commit 2c21cb6
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/libstore/content-address.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <variant>
#include "hash.hh"
#include "path.hh"
#include "comparator.hh"

namespace nix {

Expand Down Expand Up @@ -46,13 +47,17 @@ std::string renderContentAddressMethod(ContentAddressMethod caMethod);

struct TextHash {
Hash hash;

GENERATE_CMP(TextHash, me->hash);
};

/// Pair of a hash, and how the file system was ingested
struct FixedOutputHash {
FileIngestionMethod method;
Hash hash;
std::string printMethodAlgo() const;

GENERATE_CMP(FixedOutputHash, me->method, me->hash);
};

/*
Expand Down Expand Up @@ -91,17 +96,13 @@ struct PathReferences
std::set<Ref> references;
bool hasSelfReference = false;

bool operator == (const PathReferences<Ref> & other) const
{
return references == other.references
&& hasSelfReference == other.hasSelfReference;
}

/* Functions to view references + hasSelfReference as one set, mainly for
compatibility's sake. */
StorePathSet referencesPossiblyToSelf(const Ref & self) const;
void insertReferencePossiblyToSelf(const Ref & self, Ref && ref);
void setReferencesPossiblyToSelf(const Ref & self, std::set<Ref> && refs);

GENERATE_CMP(PathReferences<Ref>, me->references, me->hasSelfReference);
};

template<typename Ref>
Expand Down Expand Up @@ -142,11 +143,15 @@ void PathReferences<Ref>::setReferencesPossiblyToSelf(const Ref & self, std::set
struct TextInfo : TextHash {
// References for the paths, self references disallowed
StorePathSet references;

GENERATE_CMP(TextInfo, *(const TextHash *)me, me->references);
};

struct FixedOutputInfo : FixedOutputHash {
// References for the paths
PathReferences<StorePath> references;

GENERATE_CMP(FixedOutputInfo, *(const FixedOutputHash *)me, me->references);
};

typedef std::variant<
Expand All @@ -160,17 +165,7 @@ struct StorePathDescriptor {
std::string name;
ContentAddressWithReferences info;

bool operator == (const StorePathDescriptor & other) const
{
return name == other.name;
// FIXME second field
}

bool operator < (const StorePathDescriptor & other) const
{
return name < other.name;
// FIXME second field
}
GENERATE_CMP(StorePathDescriptor, me->name, me->info);
};

}

0 comments on commit 2c21cb6

Please sign in to comment.