1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 23:11:16 +02:00

Optimisation

This commit is contained in:
Eelco Dolstra 2024-12-04 15:31:19 +01:00
parent b9f60faab5
commit 33852ead6b
3 changed files with 16 additions and 25 deletions

View file

@ -438,11 +438,11 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
{ {
if (!(statusFlags & GIT_STATUS_INDEX_DELETED) && if (!(statusFlags & GIT_STATUS_INDEX_DELETED) &&
!(statusFlags & GIT_STATUS_WT_DELETED)) !(statusFlags & GIT_STATUS_WT_DELETED))
info.files.emplace(CanonPath(path), {
statusFlags == GIT_STATUS_CURRENT info.files.insert(CanonPath(path));
? WorkdirInfo::State::Clean if (statusFlags != GIT_STATUS_CURRENT)
: WorkdirInfo::State::Dirty); info.dirtyFiles.insert(CanonPath(path));
else } else
info.deletedFiles.insert(CanonPath(path)); info.deletedFiles.insert(CanonPath(path));
if (statusFlags != GIT_STATUS_CURRENT) if (statusFlags != GIT_STATUS_CURRENT)
info.isDirty = true; info.isDirty = true;
@ -1208,15 +1208,6 @@ ref<SourceAccessor> GitRepoImpl::getAccessor(const Hash & rev, bool exportIgnore
} }
} }
template<typename K, typename V>
std::set<K> getKeys(const std::map<K, V> & c)
{
std::set<K> res;
for (auto & i : c)
res.insert(i.first);
return res;
}
ref<SourceAccessor> GitRepoImpl::getAccessor(const WorkdirInfo & wd, bool exportIgnore, MakeNotAllowedError makeNotAllowedError) ref<SourceAccessor> GitRepoImpl::getAccessor(const WorkdirInfo & wd, bool exportIgnore, MakeNotAllowedError makeNotAllowedError)
{ {
auto self = ref<GitRepoImpl>(shared_from_this()); auto self = ref<GitRepoImpl>(shared_from_this());
@ -1229,7 +1220,7 @@ ref<SourceAccessor> GitRepoImpl::getAccessor(const WorkdirInfo & wd, bool export
? makeEmptySourceAccessor() ? makeEmptySourceAccessor()
: AllowListSourceAccessor::create( : AllowListSourceAccessor::create(
makeFSSourceAccessor(path), makeFSSourceAccessor(path),
std::set<CanonPath> { getKeys(wd.files) }, std::set<CanonPath> { wd.files },
std::move(makeNotAllowedError)).cast<SourceAccessor>(); std::move(makeNotAllowedError)).cast<SourceAccessor>();
if (exportIgnore) if (exportIgnore)
return make_ref<GitExportIgnoreSourceAccessor>(self, fileAccessor, std::nullopt); return make_ref<GitExportIgnoreSourceAccessor>(self, fileAccessor, std::nullopt);

View file

@ -55,11 +55,12 @@ struct GitRepo
in the repo yet. */ in the repo yet. */
std::optional<Hash> headRev; std::optional<Hash> headRev;
enum State { Clean, Dirty };
/* All files in the working directory that are unchanged, /* All files in the working directory that are unchanged,
modified or added, but excluding deleted files. */ modified or added, but excluding deleted files. */
std::map<CanonPath, State> files; std::set<CanonPath> files;
/* All modified or added files. */
std::set<CanonPath> dirtyFiles;
/* The deleted files. */ /* The deleted files. */
std::set<CanonPath> deletedFiles; std::set<CanonPath> deletedFiles;

View file

@ -686,7 +686,7 @@ struct GitInputScheme : InputScheme
if (getSubmodulesAttr(input)) if (getSubmodulesAttr(input))
/* Create mountpoints for the submodules. */ /* Create mountpoints for the submodules. */
for (auto & submodule : repoInfo.workdirInfo.submodules) for (auto & submodule : repoInfo.workdirInfo.submodules)
repoInfo.workdirInfo.files.emplace(submodule.path, GitRepo::WorkdirInfo::State::Clean); repoInfo.workdirInfo.files.insert(submodule.path);
auto repo = GitRepo::openRepo(repoInfo.url, false, false); auto repo = GitRepo::openRepo(repoInfo.url, false, false);
@ -807,12 +807,11 @@ struct GitInputScheme : InputScheme
/* Calculate a fingerprint that takes into account the /* Calculate a fingerprint that takes into account the
deleted and modified/added files. */ deleted and modified/added files. */
HashSink hashSink{HashAlgorithm::SHA512}; HashSink hashSink{HashAlgorithm::SHA512};
for (auto & file : repoInfo.workdirInfo.files) for (auto & file : repoInfo.workdirInfo.dirtyFiles) {
if (file.second == GitRepo::WorkdirInfo::State::Dirty) { writeString("modified:", hashSink);
writeString("modified:", hashSink); writeString(file.abs(), hashSink);
writeString(file.first.abs(), hashSink); dumpPath(repoInfo.url + "/" + file.abs(), hashSink);
dumpPath(repoInfo.url + "/" + file.first.abs(), hashSink); }
}
for (auto & file : repoInfo.workdirInfo.deletedFiles) { for (auto & file : repoInfo.workdirInfo.deletedFiles) {
writeString("deleted:", hashSink); writeString("deleted:", hashSink);
writeString(file.abs(), hashSink); writeString(file.abs(), hashSink);