1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-26 07:31:15 +02:00

Git fetcher: Calculate a fingerprint for dirty workdirs

This restores evaluation caching for dirty Git workdirs.
This commit is contained in:
Eelco Dolstra 2024-11-29 16:55:27 +01:00
parent da7e3be8fc
commit 331bf3e261
3 changed files with 49 additions and 6 deletions

View file

@ -437,7 +437,12 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
{
if (!(statusFlags & GIT_STATUS_INDEX_DELETED) &&
!(statusFlags & GIT_STATUS_WT_DELETED))
info.files.insert(CanonPath(path));
info.files.emplace(CanonPath(path),
statusFlags == GIT_STATUS_CURRENT
? WorkdirInfo::State::Clean
: WorkdirInfo::State::Dirty);
else
info.deletedFiles.insert(CanonPath(path));
if (statusFlags != GIT_STATUS_CURRENT)
info.isDirty = true;
return 0;
@ -1202,6 +1207,15 @@ 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)
{
auto self = ref<GitRepoImpl>(shared_from_this());
@ -1214,7 +1228,7 @@ ref<SourceAccessor> GitRepoImpl::getAccessor(const WorkdirInfo & wd, bool export
? makeEmptySourceAccessor()
: AllowListSourceAccessor::create(
makeFSSourceAccessor(path),
std::set<CanonPath> { wd.files },
std::set<CanonPath> { getKeys(wd.files) },
std::move(makeNotAllowedError)).cast<SourceAccessor>();
if (exportIgnore)
return make_ref<GitExportIgnoreSourceAccessor>(self, fileAccessor, std::nullopt);