libfetchers: Use source accessor if the mercurial fetcher, use makeFSSourceAccessor

This significantly simplifies path filtering and gets rid of raw file system accesses.
This commit is contained in:
Sergei Zimmerman
2026-01-10 01:11:38 +03:00
parent f672f1a740
commit 803f864424

View File

@@ -213,26 +213,24 @@ struct MercurialInputScheme : InputScheme
runHg({"status", "-R", actualUrl, "--clean", "--modified", "--added", "--no-status", "--print0"}),
"\0"s);
std::filesystem::path actualPath(absPath(actualUrl));
auto accessor = makeFSSourceAccessor(absPath(actualUrl));
PathFilter filter = [&](const Path & p) -> bool {
assert(hasPrefix(p, actualPath.string()));
std::string file(p, actualPath.string().size() + 1);
auto cp = CanonPath(p);
auto st = accessor->lstat(cp);
auto st = lstat(p);
if (S_ISDIR(st.st_mode)) {
auto prefix = file + "/";
if (st.type == SourceAccessor::tDirectory) {
auto prefix = cp.rel() + "/";
auto i = files.lower_bound(prefix);
return i != files.end() && hasPrefix(*i, prefix);
}
return files.count(file);
return files.count(cp.rel());
};
auto storePath = store.addToStore(
input.getName(),
{getFSSourceAccessor(), CanonPath(actualPath.string())},
{accessor, CanonPath::root},
ContentAddressMethod::Raw::NixArchive,
HashAlgorithm::SHA256,
{},
@@ -334,7 +332,7 @@ struct MercurialInputScheme : InputScheme
deletePath(tmpDir / ".hg_archival.txt");
auto storePath = store.addToStore(name, {getFSSourceAccessor(), CanonPath(tmpDir.string())});
auto storePath = store.addToStore(name, {makeFSSourceAccessor(tmpDir), CanonPath::root});
Attrs infoAttrs({
{"revCount", (uint64_t) revCount},