~ruther/guix-local

4b9d14378fcc3d8dd4eea36b541fe87e198fd7b8 — Congcong Kuo 1 year, 1 month ago 8a6cf4f
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 <ludo@gnu.org>
M nix/libstore/build.cc => nix/libstore/build.cc +5 -6
@@ 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);


M nix/libstore/local-store.cc => nix/libstore/local-store.cc +3 -3
@@ 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)) {


M nix/libutil/types.hh => nix/libutil/types.hh +7 -7
@@ 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;
};


}

M nix/libutil/util.hh => nix/libutil/util.hh +0 -9
@@ 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. */



M nix/nix-daemon/nix-daemon.cc => nix/nix-daemon/nix-daemon.cc +2 -2
@@ 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())