From 2e8ce8e21f2b69c850ae022b36a6612a67fd2a59 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Thu, 20 Nov 2025 22:13:58 +0300 Subject: [PATCH] libutil: Remove really dead code for git hashing It's not being excersised by anything and already contains bugs (like the fact that copyRecursive only handles the first entry in a directory). Evidently, it can just be removed and was never used by anything. --- src/libutil/fs-sink.cc | 39 ----------------------------- src/libutil/git.cc | 23 ----------------- src/libutil/include/nix/util/git.hh | 7 ------ 3 files changed, 69 deletions(-) diff --git a/src/libutil/fs-sink.cc b/src/libutil/fs-sink.cc index 45c0262e620..b7ca4183eda 100644 --- a/src/libutil/fs-sink.cc +++ b/src/libutil/fs-sink.cc @@ -14,45 +14,6 @@ namespace nix { -void copyRecursive(SourceAccessor & accessor, const CanonPath & from, FileSystemObjectSink & sink, const CanonPath & to) -{ - auto stat = accessor.lstat(from); - - switch (stat.type) { - case SourceAccessor::tSymlink: { - sink.createSymlink(to, accessor.readLink(from)); - break; - } - - case SourceAccessor::tRegular: { - sink.createRegularFile(to, [&](CreateRegularFileSink & crf) { - if (stat.isExecutable) - crf.isExecutable(); - accessor.readFile(from, crf, [&](uint64_t size) { crf.preallocateContents(size); }); - }); - break; - } - - case SourceAccessor::tDirectory: { - sink.createDirectory(to, [&](FileSystemObjectSink & dirSink, const CanonPath & relDirPath) { - for (auto & [name, _] : accessor.readDirectory(from)) { - copyRecursive(accessor, from / name, dirSink, relDirPath / name); - break; - } - }); - break; - } - - case SourceAccessor::tChar: - case SourceAccessor::tBlock: - case SourceAccessor::tSocket: - case SourceAccessor::tFifo: - case SourceAccessor::tUnknown: - default: - throw Error("file '%1%' has an unsupported type of %2%", from, stat.typeString()); - } -} - struct RestoreSinkSettings : Config { Setting preallocateContents{ diff --git a/src/libutil/git.cc b/src/libutil/git.cc index b17fdf145cc..c759c0f4ac9 100644 --- a/src/libutil/git.cc +++ b/src/libutil/git.cc @@ -217,29 +217,6 @@ std::optional convertMode(SourceAccessor::Type type) } } -void restore(FileSystemObjectSink & sink, Source & source, HashAlgorithm hashAlgo, std::function hook) -{ - parse(sink, CanonPath::root, source, BlobMode::Regular, hashAlgo, [&](CanonPath name, TreeEntry entry) { - auto [accessor, from] = hook(entry.hash); - auto stat = accessor->lstat(from); - auto gotOpt = convertMode(stat.type); - if (!gotOpt) - throw Error( - "file '%s' (git hash %s) has an unsupported type", - from, - entry.hash.to_string(HashFormat::Base16, false)); - auto & got = *gotOpt; - if (got != entry.mode) - throw Error( - "git mode of file '%s' (git hash %s) is %o but expected %o", - from, - entry.hash.to_string(HashFormat::Base16, false), - (RawMode) got, - (RawMode) entry.mode); - copyRecursive(*accessor, from, sink, name); - }); -} - void dumpBlobPrefix(uint64_t size, Sink & sink, const ExperimentalFeatureSettings & xpSettings) { xpSettings.require(Xp::GitHashing); diff --git a/src/libutil/include/nix/util/git.hh b/src/libutil/include/nix/util/git.hh index 5140c76c493..d4795de95be 100644 --- a/src/libutil/include/nix/util/git.hh +++ b/src/libutil/include/nix/util/git.hh @@ -136,13 +136,6 @@ std::optional convertMode(SourceAccessor::Type type); */ using RestoreHook = SourcePath(Hash); -/** - * Wrapper around `parse` and `RestoreSink` - * - * @param hashAlgo must be `HashAlgo::SHA1` or `HashAlgo::SHA256` for now. - */ -void restore(FileSystemObjectSink & sink, Source & source, HashAlgorithm hashAlgo, std::function hook); - /** * Dumps a single file to a sink *