diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 69d3997778e..fe083b8e878 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1005,10 +1005,7 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source, return n; }); - if (hasPrefix(info.ca, "fixed:git:")) - restoreGit(realPath, wrapperSource, realStoreDir, storeDir); - else - restorePath(realPath, wrapperSource); + restorePath(realPath, wrapperSource); auto hashResult = hashSink->finish(); diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc index b70eeccd8db..9541e5d1ac9 100644 --- a/src/nix/add-to-store.cc +++ b/src/nix/add-to-store.cc @@ -10,7 +10,7 @@ struct CmdAddToStore : MixDryRun, StoreCommand { Path path; std::optional namePart; - bool git = false; + FileIngestionMethod ingestionMethod = FileIngestionMethod::Recursive; CmdAddToStore() { @@ -26,8 +26,9 @@ struct CmdAddToStore : MixDryRun, StoreCommand addFlag({ .longName = "git", + .shortName = 0, .description = "treat path as a git object", - .handler = {&this->git, true}, + .handler = {&ingestionMethod, FileIngestionMethod::Git}, }); } @@ -48,13 +49,25 @@ struct CmdAddToStore : MixDryRun, StoreCommand { if (!namePart) namePart = baseNameOf(path); - auto ingestionMethod = git ? FileIngestionMethod::Git : FileIngestionMethod::Recursive; - StringSink sink; dumpPath(path, sink); auto narHash = hashString(htSHA256, *sink.s); - auto hash = git ? dumpGitHash(htSHA1, path) : narHash; + + Hash hash; + switch (ingestionMethod) { + case FileIngestionMethod::Recursive: { + hash = narHash; + break; + } + case FileIngestionMethod::Flat: { + abort(); // not yet supported above + } + case FileIngestionMethod::Git: { + hash = dumpGitHash(htSHA1, path); + break; + } + } ValidPathInfo info(store->makeFixedOutputPath(ingestionMethod, hash, *namePart)); info.narHash = narHash; @@ -62,10 +75,8 @@ struct CmdAddToStore : MixDryRun, StoreCommand info.ca = makeFixedOutputCA(ingestionMethod, hash); if (!dryRun) { - auto addedPath = store->addToStore(*namePart, path, ingestionMethod, git ? htSHA1 : htSHA256); - if (addedPath != info.path) - throw Error("Added path %s does not match calculated path %s; something has changed", - addedPath.to_string(), info.path.to_string()); + auto source = StringSource { *sink.s }; + store->addToStore(info, source); } logger->stdout("%s", store->printStorePath(info.path));