1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00

Use StringMap instead of std::map<std::string, std::string> throughout the codebase

This commit is contained in:
Sergei Zimmerman 2025-05-19 20:33:28 +00:00
parent 8c10104e9e
commit 8ee513379a
No known key found for this signature in database
GPG key ID: A9B0B557CA632325
26 changed files with 37 additions and 37 deletions

View file

@ -336,7 +336,7 @@ struct MixEnvironment : virtual Args
StringSet keepVars; StringSet keepVars;
StringSet unsetVars; StringSet unsetVars;
std::map<std::string, std::string> setVars; StringMap setVars;
bool ignoreEnvironment; bool ignoreEnvironment;
MixEnvironment(); MixEnvironment();

View file

@ -89,9 +89,9 @@ bool getBoolAttr(const Attrs & attrs, const std::string & name)
return *s; return *s;
} }
std::map<std::string, std::string> attrsToQuery(const Attrs & attrs) StringMap attrsToQuery(const Attrs & attrs)
{ {
std::map<std::string, std::string> query; StringMap query;
for (auto & attr : attrs) { for (auto & attr : attrs) {
if (auto v = std::get_if<uint64_t>(&attr.second)) { if (auto v = std::get_if<uint64_t>(&attr.second)) {
query.insert_or_assign(attr.first, fmt("%d", *v)); query.insert_or_assign(attr.first, fmt("%d", *v));

View file

@ -134,7 +134,7 @@ ParsedURL Input::toURL() const
return scheme->toURL(*this); return scheme->toURL(*this);
} }
std::string Input::toURLString(const std::map<std::string, std::string> & extraQuery) const std::string Input::toURLString(const StringMap & extraQuery) const
{ {
auto url = toURL(); auto url = toURL();
for (auto & attr : extraQuery) for (auto & attr : extraQuery)

View file

@ -368,7 +368,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
if (git_config_iterator_glob_new(Setter(it), config.get(), "^submodule\\..*\\.(path|url|branch)$")) if (git_config_iterator_glob_new(Setter(it), config.get(), "^submodule\\..*\\.(path|url|branch)$"))
throw Error("iterating over .gitmodules: %s", git_error_last()->message); throw Error("iterating over .gitmodules: %s", git_error_last()->message);
std::map<std::string, std::string> entries; StringMap entries;
while (true) { while (true) {
git_config_entry * entry = nullptr; git_config_entry * entry = nullptr;

View file

@ -37,7 +37,7 @@ std::optional<bool> maybeGetBoolAttr(const Attrs & attrs, const std::string & na
bool getBoolAttr(const Attrs & attrs, const std::string & name); bool getBoolAttr(const Attrs & attrs, const std::string & name);
std::map<std::string, std::string> attrsToQuery(const Attrs & attrs); StringMap attrsToQuery(const Attrs & attrs);
Hash getRevAttr(const Attrs & attrs, const std::string & name); Hash getRevAttr(const Attrs & attrs, const std::string & name);

View file

@ -71,7 +71,7 @@ public:
ParsedURL toURL() const; ParsedURL toURL() const;
std::string toURLString(const std::map<std::string, std::string> & extraQuery = {}) const; std::string toURLString(const StringMap & extraQuery = {}) const;
std::string to_string() const; std::string to_string() const;

View file

@ -15,7 +15,7 @@ const static std::string subDirRegex = subDirElemRegex + "(?:/" + subDirElemRege
std::string FlakeRef::to_string() const std::string FlakeRef::to_string() const
{ {
std::map<std::string, std::string> extraQuery; StringMap extraQuery;
if (subdir != "") if (subdir != "")
extraQuery.insert_or_assign("dir", subdir); extraQuery.insert_or_assign("dir", subdir);
return input.toURLString(extraQuery); return input.toURLString(extraQuery);

View file

@ -974,7 +974,7 @@ void runPostBuildHook(
fmt("running post-build-hook '%s'", settings.postBuildHook), fmt("running post-build-hook '%s'", settings.postBuildHook),
Logger::Fields{store.printStorePath(drvPath)}); Logger::Fields{store.printStorePath(drvPath)});
PushActivity pact(act.id); PushActivity pact(act.id);
std::map<std::string, std::string> hookEnvironment = getEnv(); StringMap hookEnvironment = getEnv();
hookEnvironment.emplace("DRV_PATH", store.printStorePath(drvPath)); hookEnvironment.emplace("DRV_PATH", store.printStorePath(drvPath));
hookEnvironment.emplace("OUT_PATHS", chomp(concatStringsSep(" ", store.printStorePathSet(outputPaths)))); hookEnvironment.emplace("OUT_PATHS", chomp(concatStringsSep(" ", store.printStorePathSet(outputPaths))));

View file

@ -125,7 +125,7 @@ struct StoreDirConfigBase : Config
*/ */
struct StoreDirConfig : StoreDirConfigBase, MixStoreDirMethods struct StoreDirConfig : StoreDirConfigBase, MixStoreDirMethods
{ {
using Params = std::map<std::string, std::string>; using Params = StringMap;
StoreDirConfig(const Params & params); StoreDirConfig(const Params & params);

View file

@ -41,7 +41,7 @@ namespace nix {
*/ */
struct StoreReference struct StoreReference
{ {
using Params = std::map<std::string, std::string>; using Params = StringMap;
/** /**
* Special store reference `""` or `"auto"` * Special store reference `""` or `"auto"`

View file

@ -96,7 +96,7 @@ Realisation Realisation::fromJSON(
std::map <DrvOutput, StorePath> dependentRealisations; std::map <DrvOutput, StorePath> dependentRealisations;
if (auto jsonDependencies = json.find("dependentRealisations"); jsonDependencies != json.end()) if (auto jsonDependencies = json.find("dependentRealisations"); jsonDependencies != json.end())
for (auto & [jsonDepId, jsonDepOutPath] : jsonDependencies->get<std::map<std::string, std::string>>()) for (auto & [jsonDepId, jsonDepOutPath] : jsonDependencies->get<StringMap>())
dependentRealisations.insert({DrvOutput::parse(jsonDepId), StorePath(jsonDepOutPath)}); dependentRealisations.insert({DrvOutput::parse(jsonDepId), StorePath(jsonDepOutPath)});
return Realisation{ return Realisation{

View file

@ -83,7 +83,7 @@ bool SSHMaster::isMasterRunning() {
Strings createSSHEnv() Strings createSSHEnv()
{ {
// Copy the environment and set SHELL=/bin/sh // Copy the environment and set SHELL=/bin/sh
std::map<std::string, std::string> env = getEnv(); StringMap env = getEnv();
// SSH will invoke the "user" shell for -oLocalCommand, but that means // SSH will invoke the "user" shell for -oLocalCommand, but that means
// $SHELL. To keep things simple and avoid potential issues with other // $SHELL. To keep things simple and avoid potential issues with other

View file

@ -187,7 +187,7 @@ private:
typedef std::map<Path, ChrootPath> PathsInChroot; // maps target path to source path typedef std::map<Path, ChrootPath> PathsInChroot; // maps target path to source path
PathsInChroot pathsInChroot; PathsInChroot pathsInChroot;
typedef std::map<std::string, std::string> Environment; typedef StringMap Environment;
Environment env; Environment env;
/** /**

View file

@ -106,7 +106,7 @@ TEST(concatMapStringsSep, two)
TEST(concatMapStringsSep, map) TEST(concatMapStringsSep, map)
{ {
std::map<std::string, std::string> strings; StringMap strings;
strings["this"] = "that"; strings["this"] = "that";
strings["1"] = "one"; strings["1"] = "one";

View file

@ -5,8 +5,8 @@ namespace nix {
/* ----------- tests for url.hh --------------------------------------------------*/ /* ----------- tests for url.hh --------------------------------------------------*/
std::string print_map(std::map<std::string, std::string> m) { std::string print_map(StringMap m) {
std::map<std::string, std::string>::iterator it; StringMap::iterator it;
std::string s = "{ "; std::string s = "{ ";
for (it = m.begin(); it != m.end(); ++it) { for (it = m.begin(); it != m.end(); ++it) {
s += "{ "; s += "{ ";

View file

@ -72,7 +72,7 @@ void SourceAccessor::dumpPath(
/* If we're on a case-insensitive system like macOS, undo /* If we're on a case-insensitive system like macOS, undo
the case hack applied by restorePath(). */ the case hack applied by restorePath(). */
std::map<std::string, std::string> unhacked; StringMap unhacked;
for (auto & i : readDirectory(path)) for (auto & i : readDirectory(path))
if (archiveSettings.useCaseHack) { if (archiveSettings.useCaseHack) {
std::string name(i.first); std::string name(i.first);

View file

@ -21,9 +21,9 @@ std::optional<std::string> getEnvNonEmpty(const std::string & key)
return value; return value;
} }
std::map<std::string, std::string> getEnv() StringMap getEnv()
{ {
std::map<std::string, std::string> env; StringMap env;
for (size_t i = 0; environ[i]; ++i) { for (size_t i = 0; environ[i]; ++i) {
auto s = environ[i]; auto s = environ[i];
auto eq = strchr(s, '='); auto eq = strchr(s, '=');
@ -41,7 +41,7 @@ void clearEnv()
unsetenv(name.first.c_str()); unsetenv(name.first.c_str());
} }
void replaceEnv(const std::map<std::string, std::string> & newEnv) void replaceEnv(const StringMap & newEnv)
{ {
clearEnv(); clearEnv();
for (auto & newEnvVar : newEnv) for (auto & newEnvVar : newEnv)

View file

@ -34,7 +34,7 @@ std::optional<std::string> getEnvNonEmpty(const std::string & key);
/** /**
* Get the entire environment. * Get the entire environment.
*/ */
std::map<std::string, std::string> getEnv(); StringMap getEnv();
#ifdef _WIN32 #ifdef _WIN32
/** /**
@ -64,6 +64,6 @@ void clearEnv();
/** /**
* Replace the entire environment with the given one. * Replace the entire environment with the given one.
*/ */
void replaceEnv(const std::map<std::string, std::string> & newEnv); void replaceEnv(const StringMap & newEnv);
} }

View file

@ -103,7 +103,7 @@ struct RunOptions
std::optional<uid_t> gid; std::optional<uid_t> gid;
#endif #endif
std::optional<Path> chdir; std::optional<Path> chdir;
std::optional<std::map<std::string, std::string>> environment; std::optional<StringMap> environment;
std::optional<std::string> input; std::optional<std::string> input;
Source * standardIn = nullptr; Source * standardIn = nullptr;
Sink * standardOut = nullptr; Sink * standardOut = nullptr;

View file

@ -10,7 +10,7 @@ struct ParsedURL
std::string scheme; std::string scheme;
std::optional<std::string> authority; std::optional<std::string> authority;
std::string path; std::string path;
std::map<std::string, std::string> query; StringMap query;
std::string fragment; std::string fragment;
std::string to_string() const; std::string to_string() const;
@ -30,9 +30,9 @@ MakeError(BadURL, Error);
std::string percentDecode(std::string_view in); std::string percentDecode(std::string_view in);
std::string percentEncode(std::string_view s, std::string_view keep=""); std::string percentEncode(std::string_view s, std::string_view keep="");
std::map<std::string, std::string> decodeQuery(const std::string & query); StringMap decodeQuery(const std::string & query);
std::string encodeQuery(const std::map<std::string, std::string> & query); std::string encodeQuery(const StringMap & query);
ParsedURL parseURL(const std::string & url); ParsedURL parseURL(const std::string & url);

View file

@ -10,7 +10,7 @@
namespace nix { namespace nix {
typedef std::map<std::string, std::string> XMLAttrs; typedef std::map<std::string, std::string, std::less<>> XMLAttrs;
class XMLWriter class XMLWriter

View file

@ -31,9 +31,9 @@ std::optional<Path> getCgroupFS()
} }
// FIXME: obsolete, check for cgroup2 // FIXME: obsolete, check for cgroup2
std::map<std::string, std::string> getCgroups(const Path & cgroupFile) StringMap getCgroups(const Path & cgroupFile)
{ {
std::map<std::string, std::string> cgroups; StringMap cgroups;
for (auto & line : tokenizeString<std::vector<std::string>>(readFile(cgroupFile), "\n")) { for (auto & line : tokenizeString<std::vector<std::string>>(readFile(cgroupFile), "\n")) {
static std::regex regex("([0-9]+):([^:]*):(.*)"); static std::regex regex("([0-9]+):([^:]*):(.*)");

View file

@ -10,7 +10,7 @@ namespace nix {
std::optional<Path> getCgroupFS(); std::optional<Path> getCgroupFS();
std::map<std::string, std::string> getCgroups(const Path & cgroupFile); StringMap getCgroups(const Path & cgroupFile);
struct CgroupStats struct CgroupStats
{ {

View file

@ -70,9 +70,9 @@ std::string percentDecode(std::string_view in)
return decoded; return decoded;
} }
std::map<std::string, std::string> decodeQuery(const std::string & query) StringMap decodeQuery(const std::string & query)
{ {
std::map<std::string, std::string> result; StringMap result;
for (const auto & s : tokenizeString<Strings>(query, "&")) { for (const auto & s : tokenizeString<Strings>(query, "&")) {
auto e = s.find('='); auto e = s.find('=');
@ -108,7 +108,7 @@ std::string percentEncode(std::string_view s, std::string_view keep)
return res; return res;
} }
std::string encodeQuery(const std::map<std::string, std::string> & ss) std::string encodeQuery(const StringMap & ss)
{ {
std::string res; std::string res;
bool first = true; bool first = true;

View file

@ -18,7 +18,7 @@
using namespace nix; using namespace nix;
typedef std::map<std::string, std::string> Channels; typedef StringMap Channels;
static Channels channels; static Channels channels;
static std::filesystem::path channelsList; static std::filesystem::path channelsList;

View file

@ -55,12 +55,12 @@ struct BuildEnvironment
using Array = std::vector<std::string>; using Array = std::vector<std::string>;
using Associative = std::map<std::string, std::string>; using Associative = StringMap;
using Value = std::variant<String, Array, Associative>; using Value = std::variant<String, Array, Associative>;
std::map<std::string, Value> vars; std::map<std::string, Value> vars;
std::map<std::string, std::string> bashFunctions; StringMap bashFunctions;
std::optional<std::pair<std::string, std::string>> structuredAttrs; std::optional<std::pair<std::string, std::string>> structuredAttrs;
static BuildEnvironment fromJSON(const nlohmann::json & json) static BuildEnvironment fromJSON(const nlohmann::json & json)