Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "git";
- # open repo
- repo = Git::Repo.open "./"
- # get tree
- tree = repo.head.to_commit.to_tree
- entries = [] of Git::C::X_TreeEntry
- cb = ->(x : Pointer(UInt8) , entry : Git::C::X_TreeEntry, entries: Pointer(Void)) do
- entries.as(Pointer(Array(Git::C::X_TreeEntry))).value << entry
- 0
- end
- # walk tree and collect entries
- Git::C.tree_walk(tree.safe, Git::C::TreewalkMode::TreewalkPre, cb, pointerof(entries))
- objects = [] of {String, Git::Object}
- # create Objects for entries in repo
- entries.map do |entry|
- Git::C.tree_entry_to_object out ref, repo.safe, entry
- object = Git::Object.new repo, Git::Safe::Object.free(ref)
- name = String.new(Git::C.tree_entry_name entry)
- objects.push({ name, object })
- end
- #
- # this fails with an invalid memory access
- #
- pp(
- objects.map do |(name, object)|
- s = object.safe.to_unsafe.as(Git::C::X_Blob)
- Git::C.blob_filtered_content out ref, s, "test.txt", 1
- end
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement