Skip to content

Commit

Permalink
refactor: Don't reassemble SourcePath unnecessarily
Browse files Browse the repository at this point in the history
  • Loading branch information
roberth committed Dec 13, 2024
1 parent 2d54c8b commit 123a607
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/nix-store/nix-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ static void opAdd(Strings opFlags, Strings opArgs)
if (!opFlags.empty()) throw UsageError("unknown flag");

for (auto & i : opArgs) {
auto [accessor, canonPath] = PosixSourceAccessor::createAtRoot(i);
auto sourcePath = PosixSourceAccessor::createAtRoot(i);
cout << fmt("%s\n", store->printStorePath(store->addToStore(
std::string(baseNameOf(i)), {accessor, canonPath})));
std::string(baseNameOf(i)), sourcePath)));
}
}

Expand All @@ -207,10 +207,10 @@ static void opAddFixed(Strings opFlags, Strings opArgs)
opArgs.pop_front();

for (auto & i : opArgs) {
auto [accessor, canonPath] = PosixSourceAccessor::createAtRoot(i);
auto sourcePath = PosixSourceAccessor::createAtRoot(i);
std::cout << fmt("%s\n", store->printStorePath(store->addToStoreSlow(
baseNameOf(i),
{accessor, canonPath},
sourcePath,
method,
hashAlgo).path));
}
Expand Down
6 changes: 3 additions & 3 deletions src/nix/add-to-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ struct CmdAddToStore : MixDryRun, StoreCommand
{
if (!namePart) namePart = baseNameOf(path);

auto [accessor, path2] = PosixSourceAccessor::createAtRoot(path);
auto sourcePath = PosixSourceAccessor::createAtRoot(path);

auto storePath = dryRun
? store->computeStorePath(
*namePart, {accessor, path2}, caMethod, hashAlgo, {}).first
*namePart, sourcePath, caMethod, hashAlgo, {}).first
: store->addToStoreSlow(
*namePart, {accessor, path2}, caMethod, hashAlgo, {}).path;
*namePart, sourcePath, caMethod, hashAlgo, {}).path;

logger->cout("%s", store->printStorePath(storePath));
}
Expand Down

0 comments on commit 123a607

Please sign in to comment.