-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Git fetcher: Improve submodule handling
Instead of making a complete copy of the repo, fetching the submodules, and writing the result to the store (which is all superexpensive), we now fetch the submodules recursively using the Git fetcher, and return a union accessor that "mounts" the accessors for the submodules on top of the root accessor.
- Loading branch information
Showing
6 changed files
with
210 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include "union-input-accessor.hh" | ||
|
||
namespace nix { | ||
|
||
struct UnionInputAccessor : InputAccessor | ||
{ | ||
std::map<CanonPath, ref<InputAccessor>> mounts; | ||
|
||
UnionInputAccessor(std::map<CanonPath, ref<InputAccessor>> _mounts) | ||
: mounts(std::move(_mounts)) | ||
{ | ||
// Currently we require a root filesystem. This could be relaxed. | ||
assert(mounts.contains(CanonPath::root)); | ||
|
||
// FIXME: should check that every mount point exists. Or we | ||
// could return dummy parent directories automatically. | ||
} | ||
|
||
std::string readFile(const CanonPath & path) override | ||
{ | ||
auto [accessor, subpath] = resolve(path); | ||
return accessor->readFile(subpath); | ||
} | ||
|
||
bool pathExists(const CanonPath & path) override | ||
{ | ||
auto [accessor, subpath] = resolve(path); | ||
return accessor->pathExists(subpath); | ||
} | ||
|
||
Stat lstat(const CanonPath & path) override | ||
{ | ||
auto [accessor, subpath] = resolve(path); | ||
return accessor->lstat(subpath); | ||
} | ||
|
||
DirEntries readDirectory(const CanonPath & path) override | ||
{ | ||
auto [accessor, subpath] = resolve(path); | ||
return accessor->readDirectory(subpath); | ||
} | ||
|
||
std::string readLink(const CanonPath & path) override | ||
{ | ||
auto [accessor, subpath] = resolve(path); | ||
return accessor->readLink(subpath); | ||
} | ||
|
||
std::string showPath(const CanonPath & path) override | ||
{ | ||
auto [accessor, subpath] = resolve(path); | ||
return accessor->showPath(subpath); | ||
} | ||
|
||
std::pair<ref<InputAccessor>, CanonPath> resolve(CanonPath path) | ||
{ | ||
// Find the nearest parent of `path` that is a mount point. | ||
std::vector<std::string> ss; | ||
while (true) { | ||
auto i = mounts.find(path); | ||
if (i != mounts.end()) { | ||
auto subpath = CanonPath::root; | ||
for (auto j = ss.rbegin(); j != ss.rend(); ++j) | ||
subpath.push(*j); | ||
return {i->second, std::move(subpath)}; | ||
} | ||
|
||
assert(!path.isRoot()); | ||
ss.push_back(std::string(*path.baseName())); | ||
path.pop(); | ||
} | ||
} | ||
}; | ||
|
||
ref<InputAccessor> makeUnionInputAccessor(std::map<CanonPath, ref<InputAccessor>> mounts) | ||
{ | ||
return make_ref<UnionInputAccessor>(std::move(mounts)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include "input-accessor.hh" | ||
|
||
namespace nix { | ||
|
||
ref<InputAccessor> makeUnionInputAccessor(std::map<CanonPath, ref<InputAccessor>> mounts); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters