mirror of
https://github.com/NixOS/nix.git
synced 2025-11-29 13:41:00 +01:00
Use git_blob_filter instead of git_blob_rawcontent
This commit is contained in:
parent
cf0df2607d
commit
14a7b651c1
1 changed files with 24 additions and 1 deletions
|
|
@ -668,6 +668,7 @@ struct GitSourceAccessor : SourceAccessor
|
||||||
struct State
|
struct State
|
||||||
{
|
{
|
||||||
ref<GitRepoImpl> repo;
|
ref<GitRepoImpl> repo;
|
||||||
|
std::string gitRev;
|
||||||
Object root;
|
Object root;
|
||||||
std::optional<lfs::Fetch> lfsFetch = std::nullopt;
|
std::optional<lfs::Fetch> lfsFetch = std::nullopt;
|
||||||
};
|
};
|
||||||
|
|
@ -678,6 +679,7 @@ struct GitSourceAccessor : SourceAccessor
|
||||||
: state_{
|
: state_{
|
||||||
State {
|
State {
|
||||||
.repo = repo_,
|
.repo = repo_,
|
||||||
|
.gitRev = rev.gitRev(),
|
||||||
.root = peelToTreeOrBlob(lookupObject(*repo_, hashToOID(rev)).get()),
|
.root = peelToTreeOrBlob(lookupObject(*repo_, hashToOID(rev)).get()),
|
||||||
.lfsFetch = smudgeLfs ? std::make_optional(lfs::Fetch(*repo_, hashToOID(rev))) : std::nullopt,
|
.lfsFetch = smudgeLfs ? std::make_optional(lfs::Fetch(*repo_, hashToOID(rev))) : std::nullopt,
|
||||||
}
|
}
|
||||||
|
|
@ -707,7 +709,28 @@ struct GitSourceAccessor : SourceAccessor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::string((const char *) git_blob_rawcontent(blob.get()), git_blob_rawsize(blob.get()));
|
// Apply git filters including CRLF conversion
|
||||||
|
git_buf filtered = GIT_BUF_INIT;
|
||||||
|
git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT;
|
||||||
|
|
||||||
|
git_oid oid;
|
||||||
|
if (git_oid_fromstr(&oid, state->gitRev.c_str()))
|
||||||
|
throw Error("cannot convert '%s' to a Git OID", state->gitRev.c_str());
|
||||||
|
|
||||||
|
opts.attr_commit_id = oid;
|
||||||
|
opts.flags = GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT;
|
||||||
|
|
||||||
|
int error = git_blob_filter(&filtered, blob.get(), path.rel_c_str(), &opts);
|
||||||
|
if (error != 0) {
|
||||||
|
const git_error *e = git_error_last();
|
||||||
|
std::string errorMsg = e ? e->message : "Unknown error";
|
||||||
|
git_buf_dispose(&filtered);
|
||||||
|
throw std::runtime_error("Failed to filter blob: " + errorMsg);
|
||||||
|
}
|
||||||
|
std::string result(filtered.ptr, filtered.size);
|
||||||
|
git_buf_dispose(&filtered);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string readFile(const CanonPath & path) override
|
std::string readFile(const CanonPath & path) override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue