1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 16:51:15 +02:00

todo: fix git_attr_foreach

This commit is contained in:
Brian Camacho 2024-03-12 11:59:47 -07:00
parent f8bc96abf8
commit 8c6641ecfa
3 changed files with 31 additions and 11 deletions

View file

@ -318,7 +318,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
std::vector<std::tuple<Submodule, Hash>> getSubmodules(const Hash & rev, bool exportIgnore) override; std::vector<std::tuple<Submodule, Hash>> getSubmodules(const Hash & rev, bool exportIgnore) override;
void smudgeLfs() override; //void smudgeLfs() override;
std::string resolveSubmoduleUrl( std::string resolveSubmoduleUrl(
const std::string & url, const std::string & url,
@ -495,6 +495,17 @@ ref<GitRepo> GitRepo::openRepo(const std::filesystem::path & path, bool create,
/** /**
* Raw git tree input accessor. * Raw git tree input accessor.
*/ */
static int attr_callback(const char *name, const char *value, void *payload) {
warn("got an attribute! it's %s = %s", name, value);
return 0;
//// Check if the attribute is a filter attribute
//if (strncmp(name, "filter.", 7) == 0) {
// printf("Filter attribute: %s\n", name);
//}
//return 0; // Continue iterating
}
struct GitInputAccessor : InputAccessor struct GitInputAccessor : InputAccessor
{ {
ref<GitRepoImpl> repo; ref<GitRepoImpl> repo;
@ -510,7 +521,15 @@ struct GitInputAccessor : InputAccessor
{ {
auto blob = getBlob(path, symlink); auto blob = getBlob(path, symlink);
int error;
// read filters here, perform smudge // read filters here, perform smudge
// TODO: fix git_attr_foreach here, it can't seem to parse `.gitattributes` here even though it should
warn("on path %s", path.abs().c_str());
if ((error = git_attr_foreach(&(*(*repo).repo), GIT_ATTR_CHECK_INCLUDE_HEAD, path.rel_c_str(), attr_callback, NULL)) < 0) {
warn("git_attr_foreach: %s", git_error_last()->message);
}
auto data = std::string_view((const char *) git_blob_rawcontent(blob.get()), git_blob_rawsize(blob.get())); auto data = std::string_view((const char *) git_blob_rawcontent(blob.get()), git_blob_rawsize(blob.get()));
return std::string(data); return std::string(data);
@ -1010,14 +1029,14 @@ std::vector<std::tuple<GitRepoImpl::Submodule, Hash>> GitRepoImpl::getSubmodules
return result; return result;
} }
void GitRepoImpl::smudgeLfs() { //void GitRepoImpl::smudgeLfs() {
runProgram(RunOptions{ // runProgram(RunOptions{
.program = "git", // .program = "git",
.searchPath = true, // .searchPath = true,
.args = { "lfs", "pull" }, // .args = { "lfs", "pull" },
.chdir = std::make_optional(this->path) // .chdir = std::make_optional(this->path)
}); // });
} //}
ref<GitRepo> getTarballCache() ref<GitRepo> getTarballCache()
{ {

View file

@ -69,7 +69,7 @@ struct GitRepo
*/ */
virtual std::vector<std::tuple<Submodule, Hash>> getSubmodules(const Hash & rev, bool exportIgnore) = 0; virtual std::vector<std::tuple<Submodule, Hash>> getSubmodules(const Hash & rev, bool exportIgnore) = 0;
virtual void smudgeLfs() = 0; //virtual void smudgeLfs() = 0;
virtual std::string resolveSubmoduleUrl( virtual std::string resolveSubmoduleUrl(
const std::string & url, const std::string & url,

View file

@ -655,8 +655,9 @@ struct GitInputScheme : InputScheme
} }
if (getLfsAttr(input)) { if (getLfsAttr(input)) {
warn("lfs attr set on %s", input.to_string());
// urlencoded `?lfs=1` param is set, // urlencoded `?lfs=1` param is set,
repo->smudgeLfs(); //repo->smudgeLfs();
} }
assert(!origRev || origRev == rev); assert(!origRev || origRev == rev);