Skip to content

Commit

Permalink
Optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Dec 4, 2024
1 parent 83c83d7 commit a7a616e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
21 changes: 6 additions & 15 deletions src/libfetchers/git-utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,11 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
{
if (!(statusFlags & GIT_STATUS_INDEX_DELETED) &&
!(statusFlags & GIT_STATUS_WT_DELETED))
info.files.emplace(CanonPath(path),
statusFlags == GIT_STATUS_CURRENT
? WorkdirInfo::State::Clean
: WorkdirInfo::State::Dirty);
else
{
info.files.insert(CanonPath(path));
if (statusFlags != GIT_STATUS_CURRENT)
info.dirtyFiles.insert(CanonPath(path));
} else
info.deletedFiles.insert(CanonPath(path));
if (statusFlags != GIT_STATUS_CURRENT)
info.isDirty = true;
Expand Down Expand Up @@ -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)
{
auto self = ref<GitRepoImpl>(shared_from_this());
Expand All @@ -1229,7 +1220,7 @@ ref<SourceAccessor> GitRepoImpl::getAccessor(const WorkdirInfo & wd, bool export
? makeEmptySourceAccessor()
: AllowListSourceAccessor::create(
makeFSSourceAccessor(path),
std::set<CanonPath> { getKeys(wd.files) },
std::set<CanonPath> { wd.files },
std::move(makeNotAllowedError)).cast<SourceAccessor>();
if (exportIgnore)
return make_ref<GitExportIgnoreSourceAccessor>(self, fileAccessor, std::nullopt);
Expand Down
7 changes: 4 additions & 3 deletions src/libfetchers/git-utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ struct GitRepo
in the repo yet. */
std::optional<Hash> headRev;

enum State { Clean, Dirty };

/* All files in the working directory that are unchanged,
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. */
std::set<CanonPath> deletedFiles;
Expand Down
13 changes: 6 additions & 7 deletions src/libfetchers/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ struct GitInputScheme : InputScheme
if (getSubmodulesAttr(input))
/* Create mountpoints for the 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);

Expand Down Expand Up @@ -807,12 +807,11 @@ struct GitInputScheme : InputScheme
/* Calculate a fingerprint that takes into account the
deleted and modified/added files. */
HashSink hashSink{HashAlgorithm::SHA512};
for (auto & file : repoInfo.workdirInfo.files)
if (file.second == GitRepo::WorkdirInfo::State::Dirty) {
writeString("modified:", hashSink);
writeString(file.first.abs(), hashSink);
dumpPath(repoInfo.url + "/" + file.first.abs(), hashSink);
}
for (auto & file : repoInfo.workdirInfo.dirtyFiles) {
writeString("modified:", hashSink);
writeString(file.abs(), hashSink);
dumpPath(repoInfo.url + "/" + file.abs(), hashSink);
}
for (auto & file : repoInfo.workdirInfo.deletedFiles) {
writeString("deleted:", hashSink);
writeString(file.abs(), hashSink);
Expand Down

0 comments on commit a7a616e

Please sign in to comment.