guix_mirror_bot pushed a commit to branch master
in repository guix.

commit 4b9d14378fcc3d8dd4eea36b541fe87e198fd7b8
Author: Congcong Kuo <[email protected]>
AuthorDate: Mon May 26 00:49:26 2025 +0800

    daemon: Remove ‘singleton’ and replace ‘typedef’ with ‘using’ in ‘types.hh’
    
    * nix/libutil/util.hh (singleton): Remove.
    * nix/libstore/build.cc (DerivationGoal::startBuilder)
    (SubstitutionGoal::tryNext, SubstitutionGoal::tryToRun)
    (LocalStore::ensurePath, LocalStore::repairPath): Use normal
    construction function instead of ‘singleton’.
    * nix/libstore/local-store.cc (LocalStore::addToStoreFromDump)
    (LocalStore::addTextToStore, LocalStore::importPath): Likewise.
    * nix/nix-daemon/nix-daemon.cc (performOp): Likewise.
    
    Change-Id: If0d929407c09482f3b506a1c51dfda70e29696dd
    Signed-off-by: Ludovic Courtès <[email protected]>
---
 nix/libstore/build.cc        | 11 +++++------
 nix/libstore/local-store.cc  |  6 +++---
 nix/libutil/types.hh         | 14 +++++++-------
 nix/libutil/util.hh          |  9 ---------
 nix/nix-daemon/nix-daemon.cc |  4 ++--
 5 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index 993876c6d1..47e93d1a21 100644
--- a/nix/libstore/build.cc
+++ b/nix/libstore/build.cc
@@ -2041,8 +2041,7 @@ void DerivationGoal::startBuilder()
     /* parent */
     pid.setSeparatePG(true);
     builderOut.writeSide.close();
-    worker.childStarted(shared_from_this(), pid,
-        singleton<set<int> >(builderOut.readSide), true, true);
+    worker.childStarted(shared_from_this(), pid, 
std::set<int>{builderOut.readSide}, true, true);
 
     /* Check if setting up the build environment failed. */
     string msg = readLine(builderOut.readSide);
@@ -3168,7 +3167,7 @@ void SubstitutionGoal::tryNext()
     trace("trying substituter");
 
     SubstitutablePathInfos infos;
-    PathSet dummy(singleton<PathSet>(storePath));
+    PathSet dummy{storePath};
     worker.store.querySubstitutablePathInfos(dummy, infos);
     SubstitutablePathInfos::iterator k = infos.find(storePath);
     if (k == infos.end()) {
@@ -3243,7 +3242,7 @@ void SubstitutionGoal::tryToRun()
 
     /* Acquire a lock on the output path. */
     outputLock = std::shared_ptr<PathLocks>(new PathLocks);
-    if (!outputLock->lockPaths(singleton<PathSet>(storePath), "", false)) {
+    if (!outputLock->lockPaths(PathSet{storePath}, "", false)) {
         worker.waitForAWhile(shared_from_this());
         return;
     }
@@ -3842,7 +3841,7 @@ void LocalStore::ensurePath(const Path & path)
 
     Worker worker(*this);
     GoalPtr goal = worker.makeSubstitutionGoal(path);
-    Goals goals = singleton<Goals>(goal);
+    Goals goals{goal};
 
     worker.run(goals);
 
@@ -3855,7 +3854,7 @@ void LocalStore::repairPath(const Path & path)
 {
     Worker worker(*this);
     GoalPtr goal = worker.makeSubstitutionGoal(path, true);
-    Goals goals = singleton<Goals>(goal);
+    Goals goals{goal};
 
     worker.run(goals);
 
diff --git a/nix/libstore/local-store.cc b/nix/libstore/local-store.cc
index f6540c2117..d544253add 100644
--- a/nix/libstore/local-store.cc
+++ b/nix/libstore/local-store.cc
@@ -1015,7 +1015,7 @@ Path LocalStore::addToStoreFromDump(const string & dump, 
const string & name,
         /* The first check above is an optimisation to prevent
            unnecessary lock acquisition. */
 
-        PathLocks outputLock(singleton<PathSet, Path>(dstPath));
+        PathLocks outputLock{ PathSet{dstPath} };
 
         if (repair || !isValidPath(dstPath)) {
 
@@ -1084,7 +1084,7 @@ Path LocalStore::addTextToStore(const string & name, 
const string & s,
 
     if (repair || !isValidPath(dstPath)) {
 
-        PathLocks outputLock(singleton<PathSet, Path>(dstPath));
+        PathLocks outputLock{ PathSet{dstPath} };
 
         if (repair || !isValidPath(dstPath)) {
 
@@ -1380,7 +1380,7 @@ Path LocalStore::importPath(bool requireSignature, Source 
& source)
            lock on this path). */
         Strings locksHeld = tokenizeString<Strings>(getEnv("NIX_HELD_LOCKS"));
         if (find(locksHeld.begin(), locksHeld.end(), dstPath) == 
locksHeld.end())
-            outputLock.lockPaths(singleton<PathSet, Path>(dstPath));
+            outputLock.lockPaths(PathSet{dstPath});
 
         if (!isValidPath(dstPath)) {
 
diff --git a/nix/libutil/types.hh b/nix/libutil/types.hh
index 160884ee1a..62889e6fa9 100644
--- a/nix/libutil/types.hh
+++ b/nix/libutil/types.hh
@@ -76,24 +76,24 @@ public:
 };
 
 
-typedef list<string> Strings;
-typedef set<string> StringSet;
+using Strings = std::list<std::string>;
+using StringSet = std::set<std::string>;
 
 
 /* Paths are just strings. */
-typedef string Path;
-typedef list<Path> Paths;
-typedef set<Path> PathSet;
+using Path = std::string;
+using Paths = std::list<Path>;
+using PathSet = std::set<Path>;
 
 
-typedef enum {
+enum Verbosity {
     lvlError = 0,
     lvlInfo,
     lvlTalkative,
     lvlChatty,
     lvlDebug,
     lvlVomit
-} Verbosity;
+};
 
 
 }
diff --git a/nix/libutil/util.hh b/nix/libutil/util.hh
index 03234e3a5d..176247e699 100644
--- a/nix/libutil/util.hh
+++ b/nix/libutil/util.hh
@@ -121,15 +121,6 @@ Paths createDirs(const Path & path);
 void createSymlink(const Path & target, const Path & link);
 
 
-template<class T, class A>
-T singleton(const A & a)
-{
-    T t;
-    t.insert(a);
-    return t;
-}
-
-
 /* Messages. */
 
 
diff --git a/nix/nix-daemon/nix-daemon.cc b/nix/nix-daemon/nix-daemon.cc
index e29237e65d..b43bcf7fc6 100644
--- a/nix/nix-daemon/nix-daemon.cc
+++ b/nix/nix-daemon/nix-daemon.cc
@@ -336,7 +336,7 @@ static void performOp(bool trusted, unsigned int 
clientVersion,
     case wopHasSubstitutes: {
         Path path = readStorePath(from);
         startWork();
-        PathSet res = store->querySubstitutablePaths(singleton<PathSet>(path));
+        PathSet res = store->querySubstitutablePaths(PathSet{path});
         stopWork();
         writeInt(res.find(path) != res.end(), to);
         break;
@@ -656,7 +656,7 @@ static void performOp(bool trusted, unsigned int 
clientVersion,
         Path path = absPath(readString(from));
         startWork();
         SubstitutablePathInfos infos;
-        store->querySubstitutablePathInfos(singleton<PathSet>(path), infos);
+        store->querySubstitutablePathInfos(PathSet{path}, infos);
         stopWork();
         SubstitutablePathInfos::iterator i = infos.find(path);
         if (i == infos.end())

Reply via email to