Skip to content

Commit

Permalink
WIP POC - needs at least output struct or docs to be useful
Browse files Browse the repository at this point in the history
  • Loading branch information
roberth committed Nov 1, 2023
1 parent 542e1df commit 9c75cb8
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions src/libfetchers/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "pathlocks.hh"
#include "util.hh"
#include "git.hh"
#include "parser.hh"

#include "fetch-settings.hh"

Expand Down Expand Up @@ -254,6 +255,45 @@ std::pair<StorePath, Input> fetchFromWorkdir(ref<Store> store, Input & input, co
}
} // end namespace


static const auto gitParser = [](){
using namespace nix::fetchers::parsers;
return parsers::Attrs(
[](
// _type: FIXME: use @Ericson2341's work
std::optional<std::string> _type,
std::string url,
std::optional<std::string> ref,
std::optional<std::string> rev,
std::optional<bool> shallow,
std::optional<bool> submodules,
std::optional<int> lastModified,
std::optional<int> revCount,
std::optional<std::string> narHash,
std::optional<bool> allRefs,
std::optional<std::string> name,
std::optional<std::string> dirtyRev,
std::optional<std::string> dirtyShortRev
) {
// TODO: return representation of input, a new struct, or an Input subclass?
return true;
},
new OptionalAttr("type", String{}),
new RequiredAttr("url", String{}),
new OptionalAttr("ref", String{}),
new OptionalAttr("rev", String{}),
new OptionalAttr("shallow", Bool{}),
new OptionalAttr("submodules", Bool{}),
new OptionalAttr("lastModified", Int{}),
new OptionalAttr("revCount", Int{}),
new OptionalAttr("narHash", String{}),
new OptionalAttr("allRefs", Bool{}),
new OptionalAttr("name", String{}),
new OptionalAttr("dirtyRev", String{}),
new OptionalAttr("dirtyShortRev", String{})
);
}();

struct GitInputScheme : InputScheme
{
std::optional<Input> inputFromURL(const ParsedURL & url, bool requireTree) const override
Expand Down Expand Up @@ -289,9 +329,7 @@ struct GitInputScheme : InputScheme
{
if (maybeGetStrAttr(attrs, "type") != "git") return {};

for (auto & [name, value] : attrs)
if (name != "type" && name != "url" && name != "ref" && name != "rev" && name != "shallow" && name != "submodules" && name != "lastModified" && name != "revCount" && name != "narHash" && name != "allRefs" && name != "name" && name != "dirtyRev" && name != "dirtyShortRev")
throw Error("unsupported Git input attribute '%s'", name);
gitParser.parse(attrs);

maybeGetBoolAttr(attrs, "shallow");
maybeGetBoolAttr(attrs, "submodules");
Expand Down

0 comments on commit 9c75cb8

Please sign in to comment.