Restore previous fetchGit behaviour

For compatibility, it returns a store path again, rather than a
SourcePath.
This commit is contained in:
Eelco Dolstra 2022-05-19 12:29:17 +02:00
parent 3cc9dc38f3
commit 066ed1c830
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -11,28 +11,22 @@
namespace nix { namespace nix {
void emitTreeAttrs( static void emitTreeAttrs(
EvalState & state, EvalState & state,
const SourcePath & path,
const fetchers::Input & input, const fetchers::Input & input,
Value & v, Value & v,
std::function<void(Value &)> setOutPath,
bool emptyRevFallback, bool emptyRevFallback,
bool forceDirty) bool forceDirty)
{ {
// FIXME?
//assert(input.isLocked());
auto attrs = state.buildBindings(8); auto attrs = state.buildBindings(8);
attrs.alloc(state.sOutPath).mkPath(path); setOutPath(attrs.alloc(state.sOutPath));
// FIXME: support arbitrary input attributes. // FIXME: support arbitrary input attributes.
#if 0 if (auto narHash = input.getNarHash())
auto narHash = input.getNarHash(); attrs.alloc("narHash").mkString(narHash->to_string(SRI, true));
assert(narHash);
attrs.alloc("narHash").mkString(narHash->to_string(SRI, true));
#endif
if (input.getType() == "git") if (input.getType() == "git")
attrs.alloc("submodules").mkBool( attrs.alloc("submodules").mkBool(
@ -66,6 +60,22 @@ void emitTreeAttrs(
v.mkAttrs(attrs); v.mkAttrs(attrs);
} }
void emitTreeAttrs(
EvalState & state,
const SourcePath & path,
const fetchers::Input & input,
Value & v,
bool emptyRevFallback,
bool forceDirty)
{
emitTreeAttrs(state, input, v,
[&](Value & vOutPath) {
vOutPath.mkPath(path);
},
emptyRevFallback,
forceDirty);
}
std::string fixURI(std::string uri, EvalState & state, const std::string & defaultScheme = "file") std::string fixURI(std::string uri, EvalState & state, const std::string & defaultScheme = "file")
{ {
state.checkURI(uri); state.checkURI(uri);
@ -87,6 +97,7 @@ std::string fixURIForGit(std::string uri, EvalState & state)
struct FetchTreeParams { struct FetchTreeParams {
bool emptyRevFallback = false; bool emptyRevFallback = false;
bool allowNameArgument = false; bool allowNameArgument = false;
bool returnPath = true; // whether to return a lazily fetched SourcePath or a StorePath
}; };
static void fetchTree( static void fetchTree(
@ -186,20 +197,36 @@ static void fetchTree(
if (evalSettings.pureEval && !input.isLocked()) if (evalSettings.pureEval && !input.isLocked())
throw Error("in pure evaluation mode, 'fetchTree' requires a locked input, at %s", state.positions[pos]); throw Error("in pure evaluation mode, 'fetchTree' requires a locked input, at %s", state.positions[pos]);
auto [accessor, input2] = input.lazyFetch(state.store); if (params.returnPath) {
auto [accessor, input2] = input.lazyFetch(state.store);
if (!patches.empty()) if (!patches.empty())
accessor = makePatchingInputAccessor(accessor, patches); accessor = makePatchingInputAccessor(accessor, patches);
//state.allowPath(tree.storePath); emitTreeAttrs(
state,
{ state.registerAccessor(accessor), CanonPath::root },
input2,
v,
params.emptyRevFallback,
false);
} else {
assert(patches.empty());
emitTreeAttrs( auto [tree, input2] = input.fetch(state.store);
state,
{state.registerAccessor(accessor), CanonPath::root}, auto storePath = state.store->printStorePath(tree.storePath);
input2,
v, emitTreeAttrs(
params.emptyRevFallback, state, input2, v,
false); [&](Value & vOutPath) {
vOutPath.mkString(storePath, {storePath});
},
params.emptyRevFallback,
false);
//state.allowPath(tree.storePath);
}
} }
static void prim_fetchTree(EvalState & state, const PosIdx pos, Value * * args, Value & v) static void prim_fetchTree(EvalState & state, const PosIdx pos, Value * * args, Value & v)
@ -357,7 +384,13 @@ static RegisterPrimOp primop_fetchTarball({
static void prim_fetchGit(EvalState & state, const PosIdx pos, Value * * args, Value & v) static void prim_fetchGit(EvalState & state, const PosIdx pos, Value * * args, Value & v)
{ {
fetchTree(state, pos, args, v, "git", FetchTreeParams { .emptyRevFallback = true, .allowNameArgument = true }); fetchTree(
state, pos, args, v, "git",
FetchTreeParams {
.emptyRevFallback = true,
.allowNameArgument = true,
.returnPath = false,
});
} }
static RegisterPrimOp primop_fetchGit({ static RegisterPrimOp primop_fetchGit({