Skip to content

Commit

Permalink
Use enum strut and drop prefixes
Browse files Browse the repository at this point in the history
This does a few enums; the rest will be gotten in subsequent commits.
  • Loading branch information
Ericson2314 committed Mar 29, 2020
1 parent eb1911e commit 6385c95
Show file tree
Hide file tree
Showing 56 changed files with 379 additions and 351 deletions.
8 changes: 4 additions & 4 deletions src/build-remote/build-remote.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static int _main(int argc, char * * argv)

try {

Activity act(*logger, lvlTalkative, actUnknown, fmt("connecting to '%s'", bestMachine->storeUri));
Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("connecting to '%s'", bestMachine->storeUri));

Store::Params storeParams;
if (hasPrefix(bestMachine->storeUri, "ssh://")) {
Expand Down Expand Up @@ -222,7 +222,7 @@ static int _main(int argc, char * * argv)
AutoCloseFD uploadLock = openLockFile(currentLoad + "/" + escapeUri(storeUri) + ".upload-lock", true);

{
Activity act(*logger, lvlTalkative, actUnknown, fmt("waiting for the upload lock to '%s'", storeUri));
Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("waiting for the upload lock to '%s'", storeUri));

auto old = signal(SIGALRM, handleAlarm);
alarm(15 * 60);
Expand All @@ -235,7 +235,7 @@ static int _main(int argc, char * * argv)
auto substitute = settings.buildersUseSubstitutes ? Substitute : NoSubstitute;

{
Activity act(*logger, lvlTalkative, actUnknown, fmt("copying dependencies to '%s'", storeUri));
Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("copying dependencies to '%s'", storeUri));
copyPaths(store, ref<Store>(sshStore), store->parseStorePathSet(inputs), NoRepair, NoCheckSigs, substitute);
}

Expand All @@ -254,7 +254,7 @@ static int _main(int argc, char * * argv)
if (!store->isValidPath(store->parseStorePath(path))) missing.insert(store->parseStorePath(path));

if (!missing.empty()) {
Activity act(*logger, lvlTalkative, actUnknown, fmt("copying outputs from '%s'", storeUri));
Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("copying outputs from '%s'", storeUri));
for (auto & i : missing)
store->locksHeld.insert(store->printStorePath(i)); /* FIXME: ugly */
copyPaths(ref<Store>(sshStore), store, missing, NoRepair, NoCheckSigs, NoSubstitute);
Expand Down
6 changes: 3 additions & 3 deletions src/cpptoml/cpptoml.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ using string_to_base_map
= std::unordered_map<std::string, std::shared_ptr<base>>;
#endif

// if defined, `base` will retain type information in form of an enum class
// if defined, `base` will retain type information in form of an enum struct
// such that static_cast can be used instead of dynamic_cast
// #define CPPTOML_NO_RTTI

Expand Down Expand Up @@ -405,7 +405,7 @@ inline std::shared_ptr<table_array> make_table_array(bool is_inline = false);

#if defined(CPPTOML_NO_RTTI)
/// Base type used to store underlying data type explicitly if RTTI is disabled
enum class base_type
enum struct base_type
{
NONE,
STRING,
Expand Down Expand Up @@ -2268,7 +2268,7 @@ class parser
return key;
}

enum class parse_type
enum struct parse_type
{
STRING = 1,
LOCAL_TIME,
Expand Down
4 changes: 2 additions & 2 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1661,10 +1661,10 @@ string EvalState::copyPathToStore(PathSet & context, const Path & path)
else {
auto p = settings.readOnlyMode
? store->computeStorePathForPath(std::string(baseNameOf(path)), checkSourcePath(path)).first
: store->addToStore(std::string(baseNameOf(path)), checkSourcePath(path), true, htSHA256, defaultPathFilter, repair);
: store->addToStore(std::string(baseNameOf(path)), checkSourcePath(path), true, HashType::SHA256, defaultPathFilter, repair);
dstPath = store->printStorePath(p);
srcToStore.insert_or_assign(path, std::move(p));
printMsg(lvlChatty, "copied source '%1%' -> '%2%'", path, dstPath);
printMsg(Verbosity::Chatty, "copied source '%1%' -> '%2%'", path, dstPath);
}

context.insert(dstPath);
Expand Down
4 changes: 2 additions & 2 deletions src/libexpr/function-trace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace nix {
FunctionCallTrace::FunctionCallTrace(const Pos & pos) : pos(pos) {
auto duration = std::chrono::high_resolution_clock::now().time_since_epoch();
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
printMsg(lvlInfo, "function-trace entered %1% at %2%", pos, ns.count());
printMsg(Verbosity::Info, "function-trace entered %1% at %2%", pos, ns.count());
}

FunctionCallTrace::~FunctionCallTrace() {
auto duration = std::chrono::high_resolution_clock::now().time_since_epoch();
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
printMsg(lvlInfo, "function-trace exited %1% at %2%", pos, ns.count());
printMsg(Verbosity::Info, "function-trace exited %1% at %2%", pos, ns.count());
}

}
2 changes: 1 addition & 1 deletion src/libexpr/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ Expr * EvalState::parseExprFromString(std::string_view s, const Path & basePath)

Expr * EvalState::parseStdin()
{
//Activity act(*logger, lvlTalkative, format("parsing standard input"));
//Activity act(*logger, Verbosity::Talkative, format("parsing standard input"));
return parseExprFromString(drainFD(0), absPath("."));
}

Expand Down
22 changes: 11 additions & 11 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -719,14 +719,14 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
if (outputs.size() != 1 || *(outputs.begin()) != "out")
throw Error(format("multiple outputs are not supported in fixed-output derivations, at %1%") % posDrvName);

HashType ht = outputHashAlgo.empty() ? htUnknown : parseHashType(outputHashAlgo);
HashType ht = outputHashAlgo.empty() ? HashType::Unknown : parseHashType(outputHashAlgo);
Hash h(*outputHash, ht);

auto outPath = state.store->makeFixedOutputPath(outputHashRecursive, h, drvName);
if (!jsonObject) drv.env["out"] = state.store->printStorePath(outPath);
drv.outputs.insert_or_assign("out", DerivationOutput(std::move(outPath),
(outputHashRecursive ? "r:" : "") + printHashType(h.type),
h.to_string(Base16, false)));
h.to_string(Base::Base16, false)));
}

else {
Expand Down Expand Up @@ -756,7 +756,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
auto drvPath = writeDerivation(state.store, drv, drvName, state.repair);
auto drvPathS = state.store->printStorePath(drvPath);

printMsg(lvlChatty, "instantiated '%1%' -> '%2%'", drvName, drvPathS);
printMsg(Verbosity::Chatty, "instantiated '%1%' -> '%2%'", drvName, drvPathS);

/* Optimisation, but required in read-only mode! because in that
case we don't actually write store derivations, so we can't
Expand Down Expand Up @@ -933,13 +933,13 @@ static void prim_hashFile(EvalState & state, const Pos & pos, Value * * args, Va
{
string type = state.forceStringNoCtx(*args[0], pos);
HashType ht = parseHashType(type);
if (ht == htUnknown)
if (ht == HashType::Unknown)
throw Error(format("unknown hash type '%1%', at %2%") % type % pos);

PathSet context; // discarded
Path p = state.coerceToPath(pos, *args[1], context);

mkString(v, hashFile(ht, state.checkSourcePath(p)).to_string(Base16, false), context);
mkString(v, hashFile(ht, state.checkSourcePath(p)).to_string(Base::Base16, false), context);
}

/* Read a directory (without . or ..) */
Expand Down Expand Up @@ -1073,8 +1073,8 @@ static void addPath(EvalState & state, const Pos & pos, const string & name, con
Path dstPath;
if (!expectedHash || !state.store->isValidPath(*expectedStorePath)) {
dstPath = state.store->printStorePath(settings.readOnlyMode
? state.store->computeStorePathForPath(name, path, recursive, htSHA256, filter).first
: state.store->addToStore(name, path, recursive, htSHA256, filter, state.repair));
? state.store->computeStorePathForPath(name, path, recursive, HashType::SHA256, filter).first
: state.store->addToStore(name, path, recursive, HashType::SHA256, filter, state.repair));
if (expectedHash && expectedStorePath != state.store->parseStorePath(dstPath))
throw Error("store path mismatch in (possibly filtered) path added from '%s'", path);
} else
Expand Down Expand Up @@ -1122,7 +1122,7 @@ static void prim_path(EvalState & state, const Pos & pos, Value * * args, Value
} else if (n == "recursive")
recursive = state.forceBool(*attr.value, *attr.pos);
else if (n == "sha256")
expectedHash = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256);
expectedHash = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), HashType::SHA256);
else
throw EvalError(format("unsupported argument '%1%' to 'addPath', at %2%") % attr.name % *attr.pos);
}
Expand Down Expand Up @@ -1806,13 +1806,13 @@ static void prim_hashString(EvalState & state, const Pos & pos, Value * * args,
{
string type = state.forceStringNoCtx(*args[0], pos);
HashType ht = parseHashType(type);
if (ht == htUnknown)
if (ht == HashType::Unknown)
throw Error(format("unknown hash type '%1%', at %2%") % type % pos);

PathSet context; // discarded
string s = state.forceString(*args[1], context, pos);

mkString(v, hashString(ht, s).to_string(Base16, false), context);
mkString(v, hashString(ht, s).to_string(Base::Base16, false), context);
}


Expand Down Expand Up @@ -2068,7 +2068,7 @@ void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
if (n == "url")
request.uri = state.forceStringNoCtx(*attr.value, *attr.pos);
else if (n == "sha256")
request.expectedHash = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256);
request.expectedHash = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), HashType::SHA256);
else if (n == "name")
request.name = state.forceStringNoCtx(*attr.value, *attr.pos);
else
Expand Down
8 changes: 4 additions & 4 deletions src/libexpr/primops/fetchGit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
return files.count(file);
};

gitInfo.storePath = store->printStorePath(store->addToStore("source", uri, true, htSHA256, filter));
gitInfo.storePath = store->printStorePath(store->addToStore("source", uri, true, HashType::SHA256, filter));

return gitInfo;
}
Expand All @@ -86,7 +86,7 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,

deletePath(getCacheDir() + "/nix/git");

Path cacheDir = getCacheDir() + "/nix/gitv2/" + hashString(htSHA256, uri).to_string(Base32, false);
Path cacheDir = getCacheDir() + "/nix/gitv2/" + hashString(HashType::SHA256, uri).to_string(Base::Base32, false);

if (!pathExists(cacheDir)) {
createDirs(dirOf(cacheDir));
Expand Down Expand Up @@ -123,7 +123,7 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
}
if (doFetch)
{
Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Git repository '%s'", uri));
Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("fetching Git repository '%s'", uri));

// FIXME: git stderr messes up our progress indicator, so
// we're using --quiet for now. Should process its stderr.
Expand All @@ -145,7 +145,7 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,

printTalkative("using revision %s of repo '%s'", gitInfo.rev, uri);

std::string storeLinkName = hashString(htSHA512, name + std::string("\0"s) + gitInfo.rev).to_string(Base32, false);
std::string storeLinkName = hashString(HashType::SHA512, name + std::string("\0"s) + gitInfo.rev).to_string(Base::Base32, false);
Path storeLink = cacheDir + "/" + storeLinkName + ".link";
PathLocks storeLinkLock({storeLink}, fmt("waiting for lock on '%1%'...", storeLink)); // FIXME: broken

Expand Down
10 changes: 5 additions & 5 deletions src/libexpr/primops/fetchMercurial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ HgInfo exportMercurial(ref<Store> store, const std::string & uri,
return files.count(file);
};

hgInfo.storePath = store->printStorePath(store->addToStore("source", uri, true, htSHA256, filter));
hgInfo.storePath = store->printStorePath(store->addToStore("source", uri, true, HashType::SHA256, filter));

return hgInfo;
}
}

if (rev == "") rev = "default";

Path cacheDir = fmt("%s/nix/hg/%s", getCacheDir(), hashString(htSHA256, uri).to_string(Base32, false));
Path cacheDir = fmt("%s/nix/hg/%s", getCacheDir(), hashString(HashType::SHA256, uri).to_string(Base::Base32, false));

Path stampFile = fmt("%s/.hg/%s.stamp", cacheDir, hashString(htSHA512, rev).to_string(Base32, false));
Path stampFile = fmt("%s/.hg/%s.stamp", cacheDir, hashString(HashType::SHA512, rev).to_string(Base::Base32, false));

/* If we haven't pulled this repo less than ‘tarball-ttl’ seconds,
do so now. */
Expand All @@ -90,7 +90,7 @@ HgInfo exportMercurial(ref<Store> store, const std::string & uri,
RunOptions("hg", { "log", "-R", cacheDir, "-r", rev, "--template", "1" })
.killStderr(true)).second == "1"))
{
Activity act(*logger, lvlTalkative, actUnknown, fmt("fetching Mercurial repository '%s'", uri));
Activity act(*logger, Verbosity::Talkative, ActivityType::Unknown, fmt("fetching Mercurial repository '%s'", uri));

if (pathExists(cacheDir)) {
try {
Expand Down Expand Up @@ -124,7 +124,7 @@ HgInfo exportMercurial(ref<Store> store, const std::string & uri,
hgInfo.revCount = std::stoull(tokens[1]);
hgInfo.branch = tokens[2];

std::string storeLinkName = hashString(htSHA512, name + std::string("\0"s) + hgInfo.rev).to_string(Base32, false);
std::string storeLinkName = hashString(HashType::SHA512, name + std::string("\0"s) + hgInfo.rev).to_string(Base::Base32, false);
Path storeLink = fmt("%s/.hg/%s.link", cacheDir, storeLinkName);

try {
Expand Down
8 changes: 5 additions & 3 deletions src/libmain/common-args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ MixCommonArgs::MixCommonArgs(const string & programName)
.longName("verbose")
.shortName('v')
.description("increase verbosity level")
.handler([]() { verbosity = (Verbosity) (verbosity + 1); });
.handler([]() { verbosity = (Verbosity) ((uint64_t) verbosity + 1); });

mkFlag()
.longName("quiet")
.description("decrease verbosity level")
.handler([]() { verbosity = verbosity > lvlError ? (Verbosity) (verbosity - 1) : lvlError; });
.handler([]() { verbosity = verbosity > Verbosity::Error
? (Verbosity) ((uint64_t) verbosity - 1)
: Verbosity::Error; });

mkFlag()
.longName("debug")
.description("enable debug output")
.handler([]() { verbosity = lvlDebug; });
.handler([]() { verbosity = Verbosity::Debug; });

mkFlag()
.longName("option")
Expand Down
2 changes: 1 addition & 1 deletion src/libmain/shared.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void parseCmdLine(const string & programName, const Strings & args,
void printVersion(const string & programName)
{
std::cout << format("%1% (Nix) %2%") % programName % nixVersion << std::endl;
if (verbosity > lvlInfo) {
if (verbosity > Verbosity::Info) {
Strings cfg;
#if HAVE_BOEHMGC
cfg.push_back("gc");
Expand Down
4 changes: 2 additions & 2 deletions src/libmain/shared.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ struct StorePathWithOutputs;
void printMissing(
ref<Store> store,
const std::vector<StorePathWithOutputs> & paths,
Verbosity lvl = lvlInfo);
Verbosity lvl = Verbosity::Info);

void printMissing(ref<Store> store, const StorePathSet & willBuild,
const StorePathSet & willSubstitute, const StorePathSet & unknown,
unsigned long long downloadSize, unsigned long long narSize, Verbosity lvl = lvlInfo);
unsigned long long downloadSize, unsigned long long narSize, Verbosity lvl = Verbosity::Info);

string getArg(const string & opt,
Strings::iterator & i, const Strings::iterator & end);
Expand Down
12 changes: 6 additions & 6 deletions src/libstore/binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, const ref<std::str
auto narInfo = make_ref<NarInfo>(info);

narInfo->narSize = nar->size();
narInfo->narHash = hashString(htSHA256, *nar);
narInfo->narHash = hashString(HashType::SHA256, *nar);

if (info.narHash && info.narHash != narInfo->narHash)
throw Error("refusing to copy corrupted path '%1%' to binary cache", printStorePath(info.path));
Expand Down Expand Up @@ -169,16 +169,16 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, const ref<std::str
auto now1 = std::chrono::steady_clock::now();
auto narCompressed = compress(compression, *nar, parallelCompression);
auto now2 = std::chrono::steady_clock::now();
narInfo->fileHash = hashString(htSHA256, *narCompressed);
narInfo->fileHash = hashString(HashType::SHA256, *narCompressed);
narInfo->fileSize = narCompressed->size();

auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(now2 - now1).count();
printMsg(lvlTalkative, "copying path '%1%' (%2% bytes, compressed %3$.1f%% in %4% ms) to binary cache",
printMsg(Verbosity::Talkative, "copying path '%1%' (%2% bytes, compressed %3$.1f%% in %4% ms) to binary cache",
printStorePath(narInfo->path), narInfo->narSize,
((1.0 - (double) narCompressed->size() / nar->size()) * 100.0),
duration);

narInfo->url = "nar/" + narInfo->fileHash.to_string(Base32, false) + ".nar"
narInfo->url = "nar/" + narInfo->fileHash.to_string(Base::Base32, false) + ".nar"
+ (compression == "xz" ? ".xz" :
compression == "bzip2" ? ".bz2" :
compression == "br" ? ".br" :
Expand Down Expand Up @@ -206,7 +206,7 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, const ref<std::str
// to a GC'ed file, so overwriting might be useful...
if (fileExists(key)) return;

printMsg(lvlTalkative, "creating debuginfo link from '%s' to '%s'", key, target);
printMsg(Verbosity::Talkative, "creating debuginfo link from '%s' to '%s'", key, target);

upsertFile(key, json.dump(), "application/json");
};
Expand Down Expand Up @@ -299,7 +299,7 @@ void BinaryCacheStore::queryPathInfoUncached(const StorePath & storePath,
{
auto uri = getUri();
auto storePathS = printStorePath(storePath);
auto act = std::make_shared<Activity>(*logger, lvlTalkative, actQueryPathInfo,
auto act = std::make_shared<Activity>(*logger, Verbosity::Talkative, ActivityType::QueryPathInfo,
fmt("querying info about '%s' on '%s'", storePathS, uri), Logger::Fields{storePathS, uri});
PushActivity pact(act->id);

Expand Down
Loading

0 comments on commit 6385c95

Please sign in to comment.