Advertisement
Guest User

Untitled

a guest
Sep 18th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.93 KB | None | 0 0
  1. require "git";
  2.  
  3. # open repo
  4. repo = Git::Repo.open "./"
  5. # get tree
  6. tree = repo.head.to_commit.to_tree
  7.  
  8. entries = [] of Git::C::X_TreeEntry
  9.  
  10. cb = ->(x : Pointer(UInt8) , entry : Git::C::X_TreeEntry, entries: Pointer(Void)) do
  11.   entries.as(Pointer(Array(Git::C::X_TreeEntry))).value << entry
  12.   0
  13. end
  14.  
  15. # walk tree and collect entries
  16. Git::C.tree_walk(tree.safe, Git::C::TreewalkMode::TreewalkPre, cb, pointerof(entries))
  17.  
  18. objects = [] of {String, Git::Object}
  19.  
  20. # create Objects for entries in repo
  21. entries.map do |entry|
  22.  
  23.   Git::C.tree_entry_to_object out ref, repo.safe, entry
  24.   object = Git::Object.new repo, Git::Safe::Object.free(ref)
  25.   name = String.new(Git::C.tree_entry_name entry)
  26.   objects.push({ name, object })
  27. end
  28.  
  29. #
  30. # this fails with an invalid memory access
  31. #
  32. pp(
  33.   objects.map do |(name, object)|
  34.   s = object.safe.to_unsafe.as(Git::C::X_Blob)
  35.   Git::C.blob_filtered_content out ref, s, "test.txt", 1
  36.   end
  37. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement