rugged 0.1.2 → 0.16.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (277) hide show
  1. data/README.md +25 -36
  2. data/Rakefile +20 -98
  3. data/ext/rugged/extconf.rb +44 -4
  4. data/ext/rugged/remote.c +215 -0
  5. data/ext/rugged/rugged.c +171 -0
  6. data/ext/rugged/rugged.h +126 -0
  7. data/ext/rugged/rugged_blob.c +99 -0
  8. data/ext/rugged/rugged_commit.c +224 -0
  9. data/ext/rugged/rugged_config.c +238 -0
  10. data/ext/rugged/rugged_index.c +440 -0
  11. data/ext/rugged/rugged_object.c +203 -0
  12. data/ext/rugged/rugged_reference.c +401 -0
  13. data/ext/rugged/rugged_repo.c +482 -0
  14. data/ext/rugged/rugged_revwalk.c +138 -0
  15. data/ext/rugged/rugged_signature.c +80 -0
  16. data/ext/rugged/rugged_tag.c +216 -0
  17. data/ext/rugged/rugged_tree.c +322 -0
  18. data/ext/rugged/vendor/libgit2-dist.tar.gz +0 -0
  19. data/ext/rugged/vendor/libgit2-dist/deps/http-parser/http_parser.c +1778 -0
  20. data/ext/rugged/vendor/libgit2-dist/deps/http-parser/http_parser.h +267 -0
  21. data/ext/rugged/vendor/libgit2-dist/deps/zlib/adler32.c +169 -0
  22. data/ext/rugged/vendor/libgit2-dist/deps/zlib/crc32.c +442 -0
  23. data/ext/rugged/vendor/libgit2-dist/deps/zlib/crc32.h +441 -0
  24. data/ext/rugged/vendor/libgit2-dist/deps/zlib/deflate.c +1834 -0
  25. data/ext/rugged/vendor/libgit2-dist/deps/zlib/deflate.h +342 -0
  26. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffast.c +340 -0
  27. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffast.h +11 -0
  28. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffixed.h +94 -0
  29. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inflate.c +1480 -0
  30. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inflate.h +122 -0
  31. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inftrees.c +330 -0
  32. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inftrees.h +62 -0
  33. data/ext/rugged/vendor/libgit2-dist/deps/zlib/trees.c +1244 -0
  34. data/ext/rugged/vendor/libgit2-dist/deps/zlib/trees.h +128 -0
  35. data/ext/rugged/vendor/libgit2-dist/deps/zlib/zconf.h +54 -0
  36. data/ext/rugged/vendor/libgit2-dist/deps/zlib/zlib.h +1613 -0
  37. data/ext/rugged/vendor/libgit2-dist/deps/zlib/zutil.c +318 -0
  38. data/ext/rugged/vendor/libgit2-dist/deps/zlib/zutil.h +274 -0
  39. data/ext/rugged/vendor/libgit2-dist/examples/general.c +451 -0
  40. data/ext/rugged/vendor/libgit2-dist/examples/network/common.h +14 -0
  41. data/ext/rugged/vendor/libgit2-dist/examples/network/fetch.c +97 -0
  42. data/ext/rugged/vendor/libgit2-dist/examples/network/git2.c +58 -0
  43. data/ext/rugged/vendor/libgit2-dist/examples/network/index-pack.c +47 -0
  44. data/ext/rugged/vendor/libgit2-dist/examples/network/ls-remote.c +76 -0
  45. data/ext/rugged/vendor/libgit2-dist/examples/showindex.c +43 -0
  46. data/ext/rugged/vendor/libgit2-dist/include/git2.h +44 -0
  47. data/ext/rugged/vendor/libgit2-dist/include/git2/blob.h +120 -0
  48. data/ext/rugged/vendor/libgit2-dist/include/git2/branch.h +15 -0
  49. data/ext/rugged/vendor/libgit2-dist/include/git2/commit.h +263 -0
  50. data/ext/rugged/vendor/libgit2-dist/include/git2/common.h +103 -0
  51. data/ext/rugged/vendor/libgit2-dist/include/git2/config.h +278 -0
  52. data/ext/rugged/vendor/libgit2-dist/include/git2/errors.h +144 -0
  53. data/ext/rugged/vendor/libgit2-dist/include/git2/index.h +306 -0
  54. data/ext/rugged/vendor/libgit2-dist/include/git2/indexer.h +76 -0
  55. data/ext/rugged/vendor/libgit2-dist/include/git2/inttypes.h +305 -0
  56. data/ext/rugged/vendor/libgit2-dist/include/git2/net.h +51 -0
  57. data/ext/rugged/vendor/libgit2-dist/include/git2/object.h +173 -0
  58. data/ext/rugged/vendor/libgit2-dist/include/git2/odb.h +331 -0
  59. data/ext/rugged/vendor/libgit2-dist/include/git2/odb_backend.h +100 -0
  60. data/ext/rugged/vendor/libgit2-dist/include/git2/oid.h +218 -0
  61. data/ext/rugged/vendor/libgit2-dist/include/git2/reflog.h +128 -0
  62. data/ext/rugged/vendor/libgit2-dist/include/git2/refs.h +309 -0
  63. data/ext/rugged/vendor/libgit2-dist/include/git2/refspec.h +60 -0
  64. data/ext/rugged/vendor/libgit2-dist/include/git2/remote.h +176 -0
  65. data/ext/rugged/vendor/libgit2-dist/include/git2/repository.h +290 -0
  66. data/ext/rugged/vendor/libgit2-dist/include/git2/revwalk.h +169 -0
  67. data/ext/rugged/vendor/libgit2-dist/include/git2/signature.h +65 -0
  68. data/ext/rugged/vendor/libgit2-dist/include/git2/status.h +63 -0
  69. data/ext/rugged/vendor/libgit2-dist/include/git2/stdint.h +247 -0
  70. data/ext/rugged/vendor/libgit2-dist/include/git2/tag.h +279 -0
  71. data/ext/rugged/vendor/libgit2-dist/include/git2/threads.h +48 -0
  72. data/ext/rugged/vendor/libgit2-dist/include/git2/tree.h +318 -0
  73. data/ext/rugged/vendor/libgit2-dist/include/git2/types.h +169 -0
  74. data/ext/rugged/vendor/libgit2-dist/include/git2/version.h +15 -0
  75. data/ext/rugged/vendor/libgit2-dist/include/git2/windows.h +59 -0
  76. data/ext/rugged/vendor/libgit2-dist/include/git2/zlib.h +40 -0
  77. data/ext/rugged/vendor/libgit2-dist/src/blob.c +135 -0
  78. data/ext/rugged/vendor/libgit2-dist/src/blob.h +23 -0
  79. data/ext/rugged/vendor/libgit2-dist/src/bswap.h +97 -0
  80. data/ext/rugged/vendor/libgit2-dist/src/buffer.c +113 -0
  81. data/ext/rugged/vendor/libgit2-dist/src/buffer.h +32 -0
  82. data/ext/rugged/vendor/libgit2-dist/src/cache.c +111 -0
  83. data/ext/rugged/vendor/libgit2-dist/src/cache.h +64 -0
  84. data/ext/rugged/vendor/libgit2-dist/src/cc-compat.h +67 -0
  85. data/ext/rugged/vendor/libgit2-dist/src/commit.c +299 -0
  86. data/ext/rugged/vendor/libgit2-dist/src/commit.h +34 -0
  87. data/ext/rugged/vendor/libgit2-dist/src/common.h +64 -0
  88. data/ext/rugged/vendor/libgit2-dist/src/config.c +418 -0
  89. data/ext/rugged/vendor/libgit2-dist/src/config.h +24 -0
  90. data/ext/rugged/vendor/libgit2-dist/src/config_file.c +1210 -0
  91. data/ext/rugged/vendor/libgit2-dist/src/delta-apply.c +115 -0
  92. data/ext/rugged/vendor/libgit2-dist/src/delta-apply.h +33 -0
  93. data/ext/rugged/vendor/libgit2-dist/src/dir.h +47 -0
  94. data/ext/rugged/vendor/libgit2-dist/src/errors.c +104 -0
  95. data/ext/rugged/vendor/libgit2-dist/src/fetch.c +172 -0
  96. data/ext/rugged/vendor/libgit2-dist/src/fetch.h +18 -0
  97. data/ext/rugged/vendor/libgit2-dist/src/filebuf.c +400 -0
  98. data/ext/rugged/vendor/libgit2-dist/src/filebuf.h +72 -0
  99. data/ext/rugged/vendor/libgit2-dist/src/fileops.c +358 -0
  100. data/ext/rugged/vendor/libgit2-dist/src/fileops.h +151 -0
  101. data/ext/rugged/vendor/libgit2-dist/src/global.c +134 -0
  102. data/ext/rugged/vendor/libgit2-dist/src/global.h +24 -0
  103. data/ext/rugged/vendor/libgit2-dist/src/hash.c +74 -0
  104. data/ext/rugged/vendor/libgit2-dist/src/hash.h +29 -0
  105. data/ext/rugged/vendor/libgit2-dist/src/hashtable.c +243 -0
  106. data/ext/rugged/vendor/libgit2-dist/src/hashtable.h +80 -0
  107. data/ext/rugged/vendor/libgit2-dist/src/index.c +918 -0
  108. data/ext/rugged/vendor/libgit2-dist/src/index.h +34 -0
  109. data/ext/rugged/vendor/libgit2-dist/src/indexer.c +401 -0
  110. data/ext/rugged/vendor/libgit2-dist/src/map.h +37 -0
  111. data/ext/rugged/vendor/libgit2-dist/src/mwindow.c +272 -0
  112. data/ext/rugged/vendor/libgit2-dist/src/mwindow.h +45 -0
  113. data/ext/rugged/vendor/libgit2-dist/src/netops.c +198 -0
  114. data/ext/rugged/vendor/libgit2-dist/src/netops.h +36 -0
  115. data/ext/rugged/vendor/libgit2-dist/src/object.c +295 -0
  116. data/ext/rugged/vendor/libgit2-dist/src/odb.c +672 -0
  117. data/ext/rugged/vendor/libgit2-dist/src/odb.h +43 -0
  118. data/ext/rugged/vendor/libgit2-dist/src/odb_loose.c +855 -0
  119. data/ext/rugged/vendor/libgit2-dist/src/odb_pack.c +485 -0
  120. data/ext/rugged/vendor/libgit2-dist/src/oid.c +388 -0
  121. data/ext/rugged/vendor/libgit2-dist/src/pack.c +788 -0
  122. data/ext/rugged/vendor/libgit2-dist/src/pack.h +99 -0
  123. data/ext/rugged/vendor/libgit2-dist/src/path.c +270 -0
  124. data/ext/rugged/vendor/libgit2-dist/src/path.h +84 -0
  125. data/ext/rugged/vendor/libgit2-dist/src/pkt.c +426 -0
  126. data/ext/rugged/vendor/libgit2-dist/src/pkt.h +77 -0
  127. data/ext/rugged/vendor/libgit2-dist/src/posix.c +94 -0
  128. data/ext/rugged/vendor/libgit2-dist/src/posix.h +69 -0
  129. data/ext/rugged/vendor/libgit2-dist/src/ppc/sha1.c +70 -0
  130. data/ext/rugged/vendor/libgit2-dist/src/ppc/sha1.h +26 -0
  131. data/ext/rugged/vendor/libgit2-dist/src/pqueue.c +141 -0
  132. data/ext/rugged/vendor/libgit2-dist/src/pqueue.h +81 -0
  133. data/ext/rugged/vendor/libgit2-dist/src/protocol.c +50 -0
  134. data/ext/rugged/vendor/libgit2-dist/src/protocol.h +23 -0
  135. data/ext/rugged/vendor/libgit2-dist/src/reflog.c +318 -0
  136. data/ext/rugged/vendor/libgit2-dist/src/reflog.h +34 -0
  137. data/ext/rugged/vendor/libgit2-dist/src/refs.c +1693 -0
  138. data/ext/rugged/vendor/libgit2-dist/src/refs.h +58 -0
  139. data/ext/rugged/vendor/libgit2-dist/src/refspec.c +95 -0
  140. data/ext/rugged/vendor/libgit2-dist/src/refspec.h +23 -0
  141. data/ext/rugged/vendor/libgit2-dist/src/remote.c +339 -0
  142. data/ext/rugged/vendor/libgit2-dist/src/remote.h +25 -0
  143. data/ext/rugged/vendor/libgit2-dist/src/repository.c +849 -0
  144. data/ext/rugged/vendor/libgit2-dist/src/repository.h +60 -0
  145. data/ext/rugged/vendor/libgit2-dist/src/revwalk.c +569 -0
  146. data/ext/rugged/vendor/libgit2-dist/src/sha1.c +280 -0
  147. data/ext/rugged/vendor/libgit2-dist/src/sha1.h +21 -0
  148. data/ext/rugged/vendor/libgit2-dist/src/sha1_lookup.c +177 -0
  149. data/ext/rugged/vendor/libgit2-dist/src/sha1_lookup.h +18 -0
  150. data/ext/rugged/vendor/libgit2-dist/src/signature.c +335 -0
  151. data/ext/rugged/vendor/libgit2-dist/src/signature.h +18 -0
  152. data/ext/rugged/vendor/libgit2-dist/src/status.c +696 -0
  153. data/ext/rugged/vendor/libgit2-dist/src/tag.c +446 -0
  154. data/ext/rugged/vendor/libgit2-dist/src/tag.h +28 -0
  155. data/ext/rugged/vendor/libgit2-dist/src/thread-utils.c +55 -0
  156. data/ext/rugged/vendor/libgit2-dist/src/thread-utils.h +108 -0
  157. data/ext/rugged/vendor/libgit2-dist/src/transport.c +85 -0
  158. data/ext/rugged/vendor/libgit2-dist/src/transport.h +110 -0
  159. data/ext/rugged/vendor/libgit2-dist/src/transports/git.c +502 -0
  160. data/ext/rugged/vendor/libgit2-dist/src/transports/http.c +756 -0
  161. data/ext/rugged/vendor/libgit2-dist/src/transports/local.c +235 -0
  162. data/ext/rugged/vendor/libgit2-dist/src/tree-cache.c +201 -0
  163. data/ext/rugged/vendor/libgit2-dist/src/tree-cache.h +31 -0
  164. data/ext/rugged/vendor/libgit2-dist/src/tree.c +758 -0
  165. data/ext/rugged/vendor/libgit2-dist/src/tree.h +37 -0
  166. data/ext/rugged/vendor/libgit2-dist/src/tsort.c +365 -0
  167. data/ext/rugged/vendor/libgit2-dist/src/unix/map.c +70 -0
  168. data/ext/rugged/vendor/libgit2-dist/src/unix/posix.h +25 -0
  169. data/ext/rugged/vendor/libgit2-dist/src/util.c +381 -0
  170. data/ext/rugged/vendor/libgit2-dist/src/util.h +137 -0
  171. data/ext/rugged/vendor/libgit2-dist/src/vector.c +174 -0
  172. data/ext/rugged/vendor/libgit2-dist/src/vector.h +45 -0
  173. data/ext/rugged/vendor/libgit2-dist/src/win32/dir.c +115 -0
  174. data/ext/rugged/vendor/libgit2-dist/src/win32/fnmatch.c +180 -0
  175. data/ext/rugged/vendor/libgit2-dist/src/win32/fnmatch.h +27 -0
  176. data/ext/rugged/vendor/libgit2-dist/src/win32/map.c +131 -0
  177. data/ext/rugged/vendor/libgit2-dist/src/win32/mingw-compat.h +24 -0
  178. data/ext/rugged/vendor/libgit2-dist/src/win32/msvc-compat.h +38 -0
  179. data/ext/rugged/vendor/libgit2-dist/src/win32/posix.h +53 -0
  180. data/ext/rugged/vendor/libgit2-dist/src/win32/posix_w32.c +404 -0
  181. data/ext/rugged/vendor/libgit2-dist/src/win32/pthread.c +65 -0
  182. data/ext/rugged/vendor/libgit2-dist/src/win32/pthread.h +40 -0
  183. data/ext/rugged/vendor/libgit2-dist/src/win32/utf-conv.c +88 -0
  184. data/ext/rugged/vendor/libgit2-dist/src/win32/utf-conv.h +17 -0
  185. data/ext/rugged/vendor/libgit2-dist/tests-clay/buf/basic.c +29 -0
  186. data/ext/rugged/vendor/libgit2-dist/tests-clay/clay.h +187 -0
  187. data/ext/rugged/vendor/libgit2-dist/tests-clay/clay_libgit2.h +28 -0
  188. data/ext/rugged/vendor/libgit2-dist/tests-clay/clay_main.c +1073 -0
  189. data/ext/rugged/vendor/libgit2-dist/tests-clay/config/add.c +37 -0
  190. data/ext/rugged/vendor/libgit2-dist/tests-clay/config/new.c +36 -0
  191. data/ext/rugged/vendor/libgit2-dist/tests-clay/config/read.c +209 -0
  192. data/ext/rugged/vendor/libgit2-dist/tests-clay/config/stress.c +39 -0
  193. data/ext/rugged/vendor/libgit2-dist/tests-clay/config/write.c +77 -0
  194. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/dirent.c +222 -0
  195. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/filebuf.c +106 -0
  196. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/oid.c +18 -0
  197. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/path.c +139 -0
  198. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/rmdir.c +50 -0
  199. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/string.c +28 -0
  200. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/strtol.c +37 -0
  201. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/vector.c +66 -0
  202. data/ext/rugged/vendor/libgit2-dist/tests-clay/index/rename.c +60 -0
  203. data/ext/rugged/vendor/libgit2-dist/tests-clay/network/remotes.c +50 -0
  204. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/chars.c +52 -0
  205. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/compare.c +124 -0
  206. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/convert.c +75 -0
  207. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/data.h +323 -0
  208. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/fromstr.c +30 -0
  209. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/hash.c +162 -0
  210. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/short.c +94 -0
  211. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/size.c +13 -0
  212. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/type2string.c +54 -0
  213. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/tree/frompath.c +75 -0
  214. data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/loose.c +84 -0
  215. data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/loose_data.h +522 -0
  216. data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/pack_data.h +151 -0
  217. data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/packed.c +78 -0
  218. data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/sorting.c +71 -0
  219. data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/getters.c +68 -0
  220. data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/init.c +104 -0
  221. data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/open.c +54 -0
  222. data/ext/rugged/vendor/libgit2-dist/tests-clay/status/single.c +38 -0
  223. data/ext/rugged/vendor/libgit2-dist/tests-clay/status/status_data.h +48 -0
  224. data/ext/rugged/vendor/libgit2-dist/tests-clay/status/worktree.c +124 -0
  225. data/ext/rugged/vendor/libgit2-dist/tests/t00-core.c +628 -0
  226. data/ext/rugged/vendor/libgit2-dist/tests/t01-data.h +322 -0
  227. data/ext/rugged/vendor/libgit2-dist/tests/t01-rawobj.c +638 -0
  228. data/ext/rugged/vendor/libgit2-dist/tests/t03-data.h +344 -0
  229. data/ext/rugged/vendor/libgit2-dist/tests/t03-objwrite.c +255 -0
  230. data/ext/rugged/vendor/libgit2-dist/tests/t04-commit.c +788 -0
  231. data/ext/rugged/vendor/libgit2-dist/tests/t05-revwalk.c +140 -0
  232. data/ext/rugged/vendor/libgit2-dist/tests/t06-index.c +219 -0
  233. data/ext/rugged/vendor/libgit2-dist/tests/t07-hashtable.c +192 -0
  234. data/ext/rugged/vendor/libgit2-dist/tests/t08-tag.c +357 -0
  235. data/ext/rugged/vendor/libgit2-dist/tests/t09-tree.c +221 -0
  236. data/ext/rugged/vendor/libgit2-dist/tests/t10-refs.c +1294 -0
  237. data/ext/rugged/vendor/libgit2-dist/tests/t12-repo.c +174 -0
  238. data/ext/rugged/vendor/libgit2-dist/tests/t13-threads.c +41 -0
  239. data/ext/rugged/vendor/libgit2-dist/tests/t17-bufs.c +61 -0
  240. data/ext/rugged/vendor/libgit2-dist/tests/t18-status.c +448 -0
  241. data/ext/rugged/vendor/libgit2-dist/tests/test_helpers.c +310 -0
  242. data/ext/rugged/vendor/libgit2-dist/tests/test_helpers.h +83 -0
  243. data/ext/rugged/vendor/libgit2-dist/tests/test_lib.c +198 -0
  244. data/ext/rugged/vendor/libgit2-dist/tests/test_lib.h +54 -0
  245. data/ext/rugged/vendor/libgit2-dist/tests/test_main.c +89 -0
  246. data/lib/rugged.rb +4 -3
  247. data/lib/rugged/index.rb +0 -8
  248. data/lib/rugged/objects.rb +45 -0
  249. data/lib/rugged/repository.rb +29 -0
  250. data/lib/rugged/tree.rb +16 -6
  251. data/lib/rugged/version.rb +1 -1
  252. data/lib/rugged/walker.rb +5 -0
  253. data/test/blob_test.rb +18 -14
  254. data/test/commit_test.rb +28 -26
  255. data/test/coverage/HEAD.json +1 -0
  256. data/test/coverage/cover.rb +106 -0
  257. data/test/fixtures/testrepo.git/refs/heads/new_name +1 -0
  258. data/test/index_test.rb +101 -78
  259. data/test/lib_test.rb +4 -4
  260. data/test/object_test.rb +3 -3
  261. data/test/reference_test.rb +75 -0
  262. data/test/remote_test.rb +19 -0
  263. data/test/repo_pack_test.rb +4 -4
  264. data/test/repo_test.rb +44 -15
  265. data/test/tag_test.rb +7 -17
  266. data/test/test_helper.rb +24 -5
  267. data/test/tree_test.rb +30 -12
  268. data/test/walker_test.rb +40 -31
  269. metadata +273 -50
  270. data/lib/rugged/person.rb +0 -20
  271. data/lib/rugged/tree_entry.rb +0 -9
  272. data/test/fixtures/testrepo.git/objects/1d/83f106355e4309a293e42ad2a2c4b8bdbe77ae +0 -0
  273. data/test/fixtures/testrepo.git/objects/2f/3321418db5b2a841375b8b70880a8ab5a4148f +0 -0
  274. data/test/fixtures/testrepo.git/objects/36/9b00a7700cca3a506d79e301d6ad8bf735d9ee +0 -3
  275. data/test/fixtures/testrepo.git/objects/3d/b1b5ceace59ff65279757003763046fd4cbbe6 +0 -0
  276. data/test/fixtures/testrepo.git/objects/4c/d1604907792e2c43e03dcec1216f99d63e68c4 +0 -3
  277. data/test/fixtures/testrepo.git/objects/e0/f46d77041c149296549b01ed4a18b02c4b7400 +0 -0
@@ -0,0 +1,138 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2011 GitHub, Inc
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+
25
+ #include "rugged.h"
26
+
27
+ extern VALUE rb_mRugged;
28
+ VALUE rb_cRuggedWalker;
29
+
30
+ static void rb_git_walk__free(git_revwalk *walk)
31
+ {
32
+ git_revwalk_free(walk);
33
+ }
34
+
35
+ VALUE rugged_walker_new(VALUE klass, VALUE owner, git_revwalk *walk)
36
+ {
37
+ VALUE rb_walk = Data_Wrap_Struct(klass, NULL, &rb_git_walk__free, walk);
38
+ rugged_set_owner(rb_walk, owner);
39
+ return rb_walk;
40
+ }
41
+
42
+ static VALUE rb_git_walker_new(VALUE klass, VALUE rb_repo)
43
+ {
44
+ git_repository *repo;
45
+ git_revwalk *walk;
46
+ int error;
47
+
48
+ Data_Get_Struct(rb_repo, git_repository, repo);
49
+
50
+ error = git_revwalk_new(&walk, repo);
51
+ rugged_exception_check(error);
52
+
53
+ return rugged_walker_new(klass, rb_repo, walk);;
54
+ }
55
+
56
+ static VALUE rb_git_walker_each(VALUE self)
57
+ {
58
+ git_revwalk *walk;
59
+ git_commit *commit;
60
+ git_repository *repo;
61
+ git_oid commit_oid;
62
+ int error;
63
+
64
+ Data_Get_Struct(self, git_revwalk, walk);
65
+ repo = git_revwalk_repository(walk);
66
+
67
+ if (!rb_block_given_p())
68
+ return rb_funcall(self, rb_intern("to_enum"), 0);
69
+
70
+ while ((error = git_revwalk_next(&commit_oid, walk)) == 0) {
71
+ error = git_commit_lookup(&commit, repo, &commit_oid);
72
+ rugged_exception_check(error);
73
+
74
+ rb_yield(rugged_object_new(rugged_owner(self), (git_object *)commit));
75
+ }
76
+
77
+ if (error != GIT_EREVWALKOVER)
78
+ rugged_exception_check(error);
79
+
80
+ return Qnil;
81
+ }
82
+
83
+ static VALUE rb_git_walker_push(VALUE self, VALUE rb_commit)
84
+ {
85
+ git_revwalk *walk;
86
+ git_commit *commit;
87
+
88
+ Data_Get_Struct(self, git_revwalk, walk);
89
+
90
+ commit = (git_commit *)rugged_object_load(
91
+ git_revwalk_repository(walk), rb_commit, GIT_OBJ_COMMIT);
92
+
93
+ git_revwalk_push(walk, git_object_id((git_object *)commit));
94
+ return Qnil;
95
+ }
96
+
97
+ static VALUE rb_git_walker_hide(VALUE self, VALUE rb_commit)
98
+ {
99
+ git_revwalk *walk;
100
+ git_commit *commit;
101
+
102
+ Data_Get_Struct(self, git_revwalk, walk);
103
+
104
+ commit = (git_commit *)rugged_object_load(
105
+ git_revwalk_repository(walk), rb_commit, GIT_OBJ_COMMIT);
106
+
107
+ git_revwalk_hide(walk, git_object_id((git_object *)commit));
108
+ return Qnil;
109
+ }
110
+
111
+ static VALUE rb_git_walker_sorting(VALUE self, VALUE ruby_sort_mode)
112
+ {
113
+ git_revwalk *walk;
114
+ Data_Get_Struct(self, git_revwalk, walk);
115
+ git_revwalk_sorting(walk, FIX2INT(ruby_sort_mode));
116
+ return Qnil;
117
+ }
118
+
119
+ static VALUE rb_git_walker_reset(VALUE self)
120
+ {
121
+ git_revwalk *walk;
122
+ Data_Get_Struct(self, git_revwalk, walk);
123
+ git_revwalk_reset(walk);
124
+ return Qnil;
125
+ }
126
+
127
+ void Init_rugged_revwalk()
128
+ {
129
+ rb_cRuggedWalker = rb_define_class_under(rb_mRugged, "Walker", rb_cObject);
130
+ rb_define_singleton_method(rb_cRuggedWalker, "new", rb_git_walker_new, 1);
131
+
132
+ rb_define_method(rb_cRuggedWalker, "push", rb_git_walker_push, 1);
133
+ rb_define_method(rb_cRuggedWalker, "each", rb_git_walker_each, 0);
134
+ rb_define_method(rb_cRuggedWalker, "walk", rb_git_walker_each, 0);
135
+ rb_define_method(rb_cRuggedWalker, "hide", rb_git_walker_hide, 1);
136
+ rb_define_method(rb_cRuggedWalker, "reset", rb_git_walker_reset, 0);
137
+ rb_define_method(rb_cRuggedWalker, "sorting", rb_git_walker_sorting, 1);
138
+ }
@@ -0,0 +1,80 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2011 GitHub, Inc
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+
25
+ #include "rugged.h"
26
+
27
+ VALUE rugged_signature_new(const git_signature *sig, const char *encoding_name)
28
+ {
29
+ VALUE rb_sig, rb_time;
30
+
31
+ #ifdef HAVE_RUBY_ENCODING_H
32
+ rb_encoding *encoding = NULL;
33
+
34
+ if (encoding_name != NULL)
35
+ encoding = rb_enc_find(encoding_name);
36
+ #endif
37
+
38
+ rb_sig = rb_hash_new();
39
+
40
+ rb_time = rb_time_new(sig->when.time, 0);
41
+ rb_funcall(rb_time, rb_intern("utc"), 0);
42
+
43
+ rb_hash_aset(rb_sig, CSTR2SYM("name"), rugged_str_new2(sig->name, encoding));
44
+ rb_hash_aset(rb_sig, CSTR2SYM("email"), rugged_str_new2(sig->email, encoding));
45
+ rb_hash_aset(rb_sig, CSTR2SYM("time"), rb_time);
46
+
47
+ return rb_sig;
48
+ }
49
+
50
+ git_signature *rugged_signature_get(VALUE rb_sig)
51
+ {
52
+ int error;
53
+ VALUE rb_time, rb_unix_t, rb_offset, rb_name, rb_email;
54
+ git_signature *sig;
55
+
56
+ Check_Type(rb_sig, T_HASH);
57
+
58
+ rb_name = rb_hash_aref(rb_sig, rb_intern("name"));
59
+ rb_email = rb_hash_aref(rb_sig, rb_intern("email"));
60
+ rb_time = rb_hash_aref(rb_sig, rb_intern("time"));
61
+
62
+ Check_Type(rb_name, T_STRING);
63
+ Check_Type(rb_email, T_STRING);
64
+ if (!rb_obj_is_kind_of(rb_time, rb_cTime))
65
+ rb_raise(rb_eTypeError, "expected Time object");
66
+
67
+ rb_unix_t = rb_funcall(rb_time, rb_intern("tv_sec"), 0);
68
+ rb_offset = rb_funcall(rb_time, rb_intern("utc_offset"), 0);
69
+
70
+ error = git_signature_new(&sig,
71
+ StringValueCStr(rb_name),
72
+ StringValueCStr(rb_email),
73
+ NUM2LONG(rb_unix_t),
74
+ FIX2INT(rb_offset) / 60);
75
+
76
+ rugged_exception_check(error);
77
+
78
+ return sig;
79
+ }
80
+
@@ -0,0 +1,216 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2011 GitHub, Inc
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+
25
+ #include "rugged.h"
26
+
27
+ extern VALUE rb_mRugged;
28
+ extern VALUE rb_cRuggedObject;
29
+ extern VALUE rb_cRuggedRepo;
30
+ VALUE rb_cRuggedTag;
31
+
32
+ static VALUE rb_git_tag_target_GET(VALUE self)
33
+ {
34
+ git_tag *tag;
35
+ git_object *target;
36
+ int error;
37
+ VALUE owner;
38
+
39
+ Data_Get_Struct(self, git_tag, tag);
40
+ owner = rugged_owner(self);
41
+
42
+ error = git_tag_target(&target, tag);
43
+ rugged_exception_check(error);
44
+
45
+ return rugged_object_new(owner, target);
46
+ }
47
+
48
+ static VALUE rb_git_tag_target_type_GET(VALUE self)
49
+ {
50
+ git_tag *tag;
51
+ Data_Get_Struct(self, git_tag, tag);
52
+
53
+ return rugged_str_new2(git_object_type2string(git_tag_type(tag)), NULL);
54
+ }
55
+
56
+ static VALUE rb_git_tag_name_GET(VALUE self)
57
+ {
58
+ git_tag *tag;
59
+ Data_Get_Struct(self, git_tag, tag);
60
+
61
+ return rugged_str_new2(git_tag_name(tag), NULL);
62
+ }
63
+
64
+ static VALUE rb_git_tag_tagger_GET(VALUE self)
65
+ {
66
+ git_tag *tag;
67
+ Data_Get_Struct(self, git_tag, tag);
68
+
69
+ return rugged_signature_new(git_tag_tagger(tag), NULL);
70
+ }
71
+
72
+ static VALUE rb_git_tag_message_GET(VALUE self)
73
+ {
74
+ git_tag *tag;
75
+ Data_Get_Struct(self, git_tag, tag);
76
+
77
+ return rugged_str_new2(git_tag_message(tag), NULL);
78
+ }
79
+
80
+ static VALUE rb_git_tag_create(VALUE self, VALUE rb_repo, VALUE rb_data)
81
+ {
82
+ git_oid tag_oid;
83
+ git_repository *repo = NULL;
84
+ int error, force = 0;
85
+
86
+ VALUE rb_name, rb_target, rb_tagger, rb_message, rb_force;
87
+
88
+ if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo))
89
+ rb_raise(rb_eTypeError, "Expeting a Rugged::Repository instance");
90
+
91
+ Data_Get_Struct(rb_repo, git_repository, repo);
92
+
93
+ if (TYPE(rb_data) == T_STRING) {
94
+ error = git_tag_create_frombuffer(
95
+ &tag_oid,
96
+ repo,
97
+ StringValueCStr(rb_data),
98
+ force
99
+ );
100
+ } else if (TYPE(rb_data) == T_HASH) {
101
+ git_object *target = NULL;
102
+
103
+ rb_name = rb_hash_aref(rb_data, CSTR2SYM("name"));
104
+ Check_Type(rb_name, T_STRING);
105
+
106
+ rb_target = rb_hash_aref(rb_data, CSTR2SYM("target"));
107
+ target = rugged_object_load(repo, rb_target, GIT_OBJ_ANY);
108
+
109
+ rb_force = rb_hash_aref(rb_data, CSTR2SYM("force"));
110
+ if (!NIL_P(rb_force))
111
+ force = rugged_parse_bool(rb_force);
112
+
113
+ /* only for heavy tags */
114
+ rb_message = rb_hash_aref(rb_data, CSTR2SYM("message"));
115
+ rb_tagger = rb_hash_aref(rb_data, CSTR2SYM("tagger"));
116
+
117
+ if (!NIL_P(rb_tagger) && !NIL_P(rb_message)) {
118
+ git_signature *tagger = NULL;
119
+
120
+ tagger = rugged_signature_get(rb_tagger);
121
+ Check_Type(rb_message, T_STRING);
122
+
123
+ error = git_tag_create(
124
+ &tag_oid,
125
+ repo,
126
+ StringValueCStr(rb_name),
127
+ target,
128
+ tagger,
129
+ StringValueCStr(rb_message),
130
+ force
131
+ );
132
+
133
+ git_signature_free(tagger);
134
+ } else {
135
+ error = git_tag_create_lightweight(
136
+ &tag_oid,
137
+ repo,
138
+ StringValueCStr(rb_name),
139
+ target,
140
+ force
141
+ );
142
+ }
143
+
144
+ git_object_free(target);
145
+ } else {
146
+ rb_raise(rb_eTypeError, "Invalid tag data: expected a String or a Hash");
147
+ }
148
+
149
+ rugged_exception_check(error);
150
+ return rugged_create_oid(&tag_oid);
151
+ }
152
+
153
+ static VALUE rb_git_tag_each(int argc, VALUE *argv, VALUE self)
154
+ {
155
+ git_repository *repo;
156
+ git_strarray tags;
157
+ size_t i;
158
+ int error;
159
+ VALUE rb_repo, rb_pattern;
160
+ const char *pattern = NULL;
161
+
162
+ rb_scan_args(argc, argv, "11", &rb_repo, &rb_pattern);
163
+
164
+ if (!rb_block_given_p())
165
+ return rb_funcall(self, rb_intern("to_enum"), 3, CSTR2SYM("each"), rb_repo, rb_pattern);
166
+
167
+ if (!NIL_P(rb_pattern)) {
168
+ Check_Type(rb_pattern, T_STRING);
169
+ pattern = StringValueCStr(rb_pattern);
170
+ }
171
+
172
+ if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo))
173
+ rb_raise(rb_eTypeError, "Expeting a Rugged::Repository instance");
174
+
175
+ Data_Get_Struct(rb_repo, git_repository, repo);
176
+
177
+ error = git_tag_list_match(&tags, pattern ? pattern : "", repo);
178
+ rugged_exception_check(error);
179
+
180
+ for (i = 0; i < tags.count; ++i)
181
+ rb_yield(rugged_str_new2(tags.strings[i], NULL));
182
+
183
+ git_strarray_free(&tags);
184
+ return Qnil;
185
+ }
186
+
187
+ static VALUE rb_git_tag_delete(VALUE self, VALUE rb_repo, VALUE rb_name)
188
+ {
189
+ git_repository *repo;
190
+ int error;
191
+
192
+ if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo))
193
+ rb_raise(rb_eTypeError, "Expeting a Rugged::Repository instance");
194
+ Data_Get_Struct(rb_repo, git_repository, repo);
195
+
196
+ Check_Type(rb_name, T_STRING);
197
+
198
+ error = git_tag_delete(repo, StringValueCStr(rb_name));
199
+ rugged_exception_check(error);
200
+ return Qnil;
201
+ }
202
+
203
+ void Init_rugged_tag()
204
+ {
205
+ rb_cRuggedTag = rb_define_class_under(rb_mRugged, "Tag", rb_cRuggedObject);
206
+
207
+ rb_define_singleton_method(rb_cRuggedTag, "create", rb_git_tag_create, 2);
208
+ rb_define_singleton_method(rb_cRuggedTag, "each", rb_git_tag_each, -1);
209
+ rb_define_singleton_method(rb_cRuggedTag, "delete", rb_git_tag_delete, 2);
210
+
211
+ rb_define_method(rb_cRuggedTag, "message", rb_git_tag_message_GET, 0);
212
+ rb_define_method(rb_cRuggedTag, "name", rb_git_tag_name_GET, 0);
213
+ rb_define_method(rb_cRuggedTag, "target", rb_git_tag_target_GET, 0);
214
+ rb_define_method(rb_cRuggedTag, "target_type", rb_git_tag_target_type_GET, 0);
215
+ rb_define_method(rb_cRuggedTag, "tagger", rb_git_tag_tagger_GET, 0);
216
+ }
@@ -0,0 +1,322 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2011 GitHub, Inc
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+
25
+ #include "rugged.h"
26
+
27
+ extern VALUE rb_mRugged;
28
+ extern VALUE rb_cRuggedObject;
29
+ extern VALUE rb_cRuggedRepo;
30
+
31
+ VALUE rb_cRuggedTree;
32
+ VALUE rb_cRuggedTreeBuilder;
33
+
34
+ static VALUE rb_git_treeentry_fromC(const git_tree_entry *entry)
35
+ {
36
+ VALUE rb_entry;
37
+ VALUE type;
38
+
39
+ if (!entry)
40
+ return Qnil;
41
+
42
+ rb_entry = rb_hash_new();
43
+
44
+ rb_hash_aset(rb_entry, CSTR2SYM("name"), rugged_str_new2(git_tree_entry_name(entry), NULL));
45
+ rb_hash_aset(rb_entry, CSTR2SYM("oid"), rugged_create_oid(git_tree_entry_id(entry)));
46
+
47
+ rb_hash_aset(rb_entry, CSTR2SYM("attributes"), INT2FIX(git_tree_entry_attributes(entry)));
48
+
49
+ switch(git_tree_entry_type(entry)) {
50
+ case GIT_OBJ_TREE:
51
+ type = CSTR2SYM("tree");
52
+ break;
53
+
54
+ case GIT_OBJ_BLOB:
55
+ type = CSTR2SYM("blob");
56
+ break;
57
+
58
+ default:
59
+ type = Qnil;
60
+ break;
61
+ }
62
+ rb_hash_aset(rb_entry, CSTR2SYM("type"), type);
63
+
64
+ return rb_entry;
65
+ }
66
+
67
+ /*
68
+ * Rugged Tree
69
+ */
70
+ static VALUE rb_git_tree_entrycount(VALUE self)
71
+ {
72
+ git_tree *tree;
73
+ Data_Get_Struct(self, git_tree, tree);
74
+
75
+ return INT2FIX(git_tree_entrycount(tree));
76
+ }
77
+
78
+ static VALUE rb_git_tree_get_entry(VALUE self, VALUE entry_id)
79
+ {
80
+ git_tree *tree;
81
+ Data_Get_Struct(self, git_tree, tree);
82
+
83
+ if (TYPE(entry_id) == T_FIXNUM)
84
+ return rb_git_treeentry_fromC(git_tree_entry_byindex(tree, FIX2INT(entry_id)));
85
+
86
+ else if (TYPE(entry_id) == T_STRING)
87
+ return rb_git_treeentry_fromC(git_tree_entry_byname(tree, StringValueCStr(entry_id)));
88
+
89
+ else
90
+ rb_raise(rb_eTypeError, "entry_id must be either an index or a filename");
91
+ }
92
+
93
+ static VALUE rb_git_tree_each(VALUE self)
94
+ {
95
+ git_tree *tree;
96
+ unsigned int i, count;
97
+ Data_Get_Struct(self, git_tree, tree);
98
+
99
+ if (!rb_block_given_p())
100
+ return rb_funcall(self, rb_intern("to_enum"), 0);
101
+
102
+ count = git_tree_entrycount(tree);
103
+
104
+ for (i = 0; i < count; ++i) {
105
+ const git_tree_entry *entry = git_tree_entry_byindex(tree, i);
106
+ rb_yield(rb_git_treeentry_fromC(entry));
107
+ }
108
+
109
+ return Qnil;
110
+ }
111
+
112
+ static int rugged__treewalk_cb(const char *root, git_tree_entry *entry, void *proc)
113
+ {
114
+ rb_funcall((VALUE)proc, rb_intern("call"), 2,
115
+ rugged_str_new2(root, NULL),
116
+ rb_git_treeentry_fromC(entry));
117
+
118
+ return GIT_SUCCESS;
119
+ }
120
+
121
+ static VALUE rb_git_tree_walk(VALUE self, VALUE rb_mode)
122
+ {
123
+ git_tree *tree;
124
+ int error, mode = 0;
125
+ ID id_mode;
126
+
127
+ Data_Get_Struct(self, git_tree, tree);
128
+
129
+ if (!rb_block_given_p())
130
+ return rb_funcall(self, rb_intern("to_enum"), 2, CSTR2SYM("walk"), rb_mode);
131
+
132
+ Check_Type(rb_mode, T_SYMBOL);
133
+ id_mode = SYM2ID(rb_mode);
134
+
135
+ if (id_mode == rb_intern("preorder"))
136
+ mode = GIT_TREEWALK_PRE;
137
+ else if (id_mode == rb_intern("postorder"))
138
+ mode = GIT_TREEWALK_POST;
139
+ else
140
+ rb_raise(rb_eTypeError,
141
+ "Invalid iteration mode. Expected `:preorder` or `:postorder`");
142
+
143
+ error = git_tree_walk(tree, &rugged__treewalk_cb, mode, (void *)rb_block_proc());
144
+ rugged_exception_check(error);
145
+
146
+ return Qnil;
147
+ }
148
+
149
+ static VALUE rb_git_tree_subtree(VALUE self, VALUE rb_path)
150
+ {
151
+ int error;
152
+ git_tree *tree, *subtree;
153
+ VALUE owner;
154
+
155
+ Data_Get_Struct(self, git_tree, tree);
156
+ owner = rugged_owner(self);
157
+
158
+ Check_Type(rb_path, T_STRING);
159
+
160
+ error = git_tree_get_subtree(&subtree, tree, StringValueCStr(rb_path));
161
+ rugged_exception_check(error);
162
+
163
+ return rugged_object_new(owner, (git_object *)subtree);
164
+ }
165
+
166
+ static void rb_git_treebuilder_free(git_treebuilder *bld)
167
+ {
168
+ git_treebuilder_free(bld);
169
+ }
170
+
171
+ static VALUE rb_git_treebuilder_allocate(VALUE klass)
172
+ {
173
+ return Data_Wrap_Struct(klass, NULL, &rb_git_treebuilder_free, NULL);
174
+ }
175
+
176
+ static VALUE rb_git_treebuilder_init(int argc, VALUE *argv, VALUE self)
177
+ {
178
+ git_treebuilder *builder;
179
+ git_tree *tree = NULL;
180
+ VALUE rb_object;
181
+ int error;
182
+
183
+ if (rb_scan_args(argc, argv, "01", &rb_object) == 1) {
184
+ if (!rb_obj_is_kind_of(rb_object, rb_cRuggedTree))
185
+ rb_raise(rb_eTypeError, "A Rugged::Tree instance is required");
186
+
187
+ Data_Get_Struct(rb_object, git_tree, tree);
188
+ }
189
+
190
+ error = git_treebuilder_create(&builder, tree);
191
+ rugged_exception_check(error);
192
+
193
+ DATA_PTR(self) = builder;
194
+ return Qnil;
195
+ }
196
+
197
+ static VALUE rb_git_treebuilder_clear(VALUE self)
198
+ {
199
+ git_treebuilder *builder;
200
+ Data_Get_Struct(self, git_treebuilder, builder);
201
+ git_treebuilder_clear(builder);
202
+ return Qnil;
203
+ }
204
+
205
+ static VALUE rb_git_treebuilder_get(VALUE self, VALUE path)
206
+ {
207
+ git_treebuilder *builder;
208
+ Data_Get_Struct(self, git_treebuilder, builder);
209
+
210
+ Check_Type(path, T_STRING);
211
+
212
+ return rb_git_treeentry_fromC(git_treebuilder_get(builder, StringValueCStr(path)));
213
+ }
214
+
215
+ static VALUE rb_git_treebuilder_insert(VALUE self, VALUE rb_entry)
216
+ {
217
+ git_treebuilder *builder;
218
+ VALUE rb_path, rb_oid, rb_attr;
219
+ git_oid oid;
220
+ int error;
221
+
222
+ Data_Get_Struct(self, git_treebuilder, builder);
223
+ Check_Type(rb_entry, T_HASH);
224
+
225
+ rb_path = rb_hash_aref(rb_entry, CSTR2SYM("path"));
226
+ Check_Type(rb_path, T_STRING);
227
+
228
+ rb_oid = rb_hash_aref(rb_entry, CSTR2SYM("oid"));
229
+ Check_Type(rb_oid, T_STRING);
230
+ rugged_exception_check(git_oid_fromstr(&oid, StringValueCStr(rb_oid)));
231
+
232
+ rb_attr = rb_hash_aref(rb_entry, CSTR2SYM("attributes"));
233
+ Check_Type(rb_attr, T_FIXNUM);
234
+
235
+ error = git_treebuilder_insert(NULL,
236
+ builder,
237
+ StringValueCStr(rb_path),
238
+ &oid,
239
+ FIX2INT(rb_attr));
240
+
241
+ rugged_exception_check(error);
242
+ return Qnil;
243
+ }
244
+
245
+ static VALUE rb_git_treebuilder_remove(VALUE self, VALUE path)
246
+ {
247
+ git_treebuilder *builder;
248
+ int error;
249
+
250
+ Data_Get_Struct(self, git_treebuilder, builder);
251
+ Check_Type(path, T_STRING);
252
+
253
+ error = git_treebuilder_remove(builder, StringValueCStr(path));
254
+ if (error == GIT_ENOTFOUND)
255
+ return Qfalse;
256
+
257
+ rugged_exception_check(error);
258
+ return Qtrue;
259
+ }
260
+
261
+ static VALUE rb_git_treebuilder_write(VALUE self, VALUE rb_repo)
262
+ {
263
+ git_treebuilder *builder;
264
+ git_repository *repo;
265
+ git_oid written_id;
266
+ int error;
267
+
268
+ if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo))
269
+ rb_raise(rb_eTypeError, "Expecting a Rugged::Repository instance");
270
+
271
+ Data_Get_Struct(self, git_treebuilder, builder);
272
+ Data_Get_Struct(rb_repo, git_repository, repo);
273
+
274
+ error = git_treebuilder_write(&written_id, repo, builder);
275
+ rugged_exception_check(error);
276
+
277
+ return rugged_create_oid(&written_id);
278
+ }
279
+
280
+ static int treebuilder_cb(const git_tree_entry *entry, void *opaque)
281
+ {
282
+ VALUE proc = (VALUE)opaque;
283
+ VALUE ret = rb_funcall(proc, rb_intern("call"), 1, rb_git_treeentry_fromC(entry));
284
+ return rugged_parse_bool(ret);
285
+ }
286
+
287
+ static VALUE rb_git_treebuilder_filter(VALUE self)
288
+ {
289
+ git_treebuilder *builder;
290
+
291
+ rb_need_block();
292
+ Data_Get_Struct(self, git_treebuilder, builder);
293
+
294
+ git_treebuilder_filter(builder, &treebuilder_cb, (void *)rb_block_proc());
295
+ return Qnil;
296
+ }
297
+
298
+ void Init_rugged_tree()
299
+ {
300
+ /*
301
+ * Tree
302
+ */
303
+ rb_cRuggedTree = rb_define_class_under(rb_mRugged, "Tree", rb_cRuggedObject);
304
+ rb_define_method(rb_cRuggedTree, "count", rb_git_tree_entrycount, 0);
305
+ rb_define_method(rb_cRuggedTree, "length", rb_git_tree_entrycount, 0);
306
+ rb_define_method(rb_cRuggedTree, "get_entry", rb_git_tree_get_entry, 1);
307
+ rb_define_method(rb_cRuggedTree, "get_subtree", rb_git_tree_subtree, 1);
308
+ rb_define_method(rb_cRuggedTree, "[]", rb_git_tree_get_entry, 1);
309
+ rb_define_method(rb_cRuggedTree, "each", rb_git_tree_each, 0);
310
+ rb_define_method(rb_cRuggedTree, "walk", rb_git_tree_walk, 1);
311
+
312
+ rb_cRuggedTreeBuilder = rb_define_class_under(rb_cRuggedTree, "Builder", rb_cObject);
313
+ rb_define_alloc_func(rb_cRuggedTreeBuilder, rb_git_treebuilder_allocate);
314
+ rb_define_method(rb_cRuggedTreeBuilder, "initialize", rb_git_treebuilder_init, -1);
315
+ rb_define_method(rb_cRuggedTreeBuilder, "clear", rb_git_treebuilder_clear, 0);
316
+ rb_define_method(rb_cRuggedTreeBuilder, "[]", rb_git_treebuilder_get, 1);
317
+ rb_define_method(rb_cRuggedTreeBuilder, "insert", rb_git_treebuilder_insert, 1);
318
+ rb_define_method(rb_cRuggedTreeBuilder, "<<", rb_git_treebuilder_insert, 1);
319
+ rb_define_method(rb_cRuggedTreeBuilder, "remove", rb_git_treebuilder_remove, 1);
320
+ rb_define_method(rb_cRuggedTreeBuilder, "write", rb_git_treebuilder_write, 1);
321
+ rb_define_method(rb_cRuggedTreeBuilder, "reject!", rb_git_treebuilder_filter, 0);
322
+ }