@@ -668,6 +668,7 @@ struct GitSourceAccessor : SourceAccessor
668
668
struct State
669
669
{
670
670
ref<GitRepoImpl> repo;
671
+ std::string gitRev;
671
672
Object root;
672
673
std::optional<lfs::Fetch> lfsFetch = std::nullopt;
673
674
};
@@ -678,6 +679,7 @@ struct GitSourceAccessor : SourceAccessor
678
679
: state_{
679
680
State {
680
681
.repo = repo_,
682
+ .gitRev = rev.gitRev (),
681
683
.root = peelToTreeOrBlob (lookupObject (*repo_, hashToOID (rev)).get ()),
682
684
.lfsFetch = smudgeLfs ? std::make_optional (lfs::Fetch (*repo_, hashToOID (rev))) : std::nullopt,
683
685
}
@@ -707,7 +709,28 @@ struct GitSourceAccessor : SourceAccessor
707
709
}
708
710
}
709
711
710
- return std::string ((const char *) git_blob_rawcontent (blob.get ()), git_blob_rawsize (blob.get ()));
712
+ // Apply git filters including CRLF conversion
713
+ git_buf filtered = GIT_BUF_INIT;
714
+ git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT;
715
+
716
+ git_oid oid;
717
+ if (git_oid_fromstr (&oid, state->gitRev .c_str ()))
718
+ throw Error (" cannot convert '%s' to a Git OID" , state->gitRev .c_str ());
719
+
720
+ opts.attr_commit_id = oid;
721
+ opts.flags = GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT;
722
+
723
+ int error = git_blob_filter (&filtered, blob.get (), path.rel_c_str (), &opts);
724
+ if (error != 0 ) {
725
+ const git_error *e = git_error_last ();
726
+ std::string errorMsg = e ? e->message : " Unknown error" ;
727
+ git_buf_dispose (&filtered);
728
+ throw std::runtime_error (" Failed to filter blob: " + errorMsg);
729
+ }
730
+ std::string result (filtered.ptr , filtered.size );
731
+ git_buf_dispose (&filtered);
732
+
733
+ return result;
711
734
}
712
735
713
736
std::string readFile (const CanonPath & path) override
0 commit comments