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,171 @@
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 rb_mRugged;
28
+ static VALUE rb_mShutdownHook;
29
+
30
+ static VALUE rb_git_hex_to_raw(VALUE self, VALUE hex)
31
+ {
32
+ git_oid oid;
33
+
34
+ Check_Type(hex, T_STRING);
35
+ rugged_exception_check(git_oid_fromstr(&oid, StringValueCStr(hex)));
36
+
37
+ return rugged_str_ascii(oid.id, 20);
38
+ }
39
+
40
+ static VALUE rb_git_raw_to_hex(VALUE self, VALUE raw)
41
+ {
42
+ git_oid oid;
43
+ char out[40];
44
+
45
+ Check_Type(raw, T_STRING);
46
+ git_oid_fromraw(&oid, StringValueCStr(raw));
47
+ git_oid_fmt(out, &oid);
48
+
49
+ return rugged_str_new(out, 40, NULL);
50
+ }
51
+
52
+ static VALUE rb_git_type_to_string(VALUE self, VALUE type)
53
+ {
54
+ const char *str;
55
+
56
+ Check_Type(type, T_FIXNUM);
57
+ str = git_object_type2string(FIX2INT(type));
58
+ return str ? rugged_str_new2(str, NULL) : Qfalse;
59
+ }
60
+
61
+ static VALUE rb_git_string_to_type(VALUE self, VALUE string_type)
62
+ {
63
+ Check_Type(string_type, T_STRING);
64
+ return INT2FIX(git_object_string2type(StringValueCStr(string_type)));
65
+ }
66
+
67
+ static VALUE minimize_cb(VALUE rb_oid, git_oid_shorten *shortener)
68
+ {
69
+ Check_Type(rb_oid, T_STRING);
70
+ git_oid_shorten_add(shortener, RSTRING_PTR(rb_oid));
71
+ return Qnil;
72
+ }
73
+
74
+ static VALUE minimize_yield(VALUE rb_oid, VALUE *data)
75
+ {
76
+ rb_funcall(data[0], rb_intern("call"), 1,
77
+ rb_str_substr(rb_oid, 0, FIX2INT(data[1])));
78
+ return Qnil;
79
+ }
80
+
81
+ static VALUE rb_git_minimize_oid(int argc, VALUE *argv, VALUE self)
82
+ {
83
+ git_oid_shorten *shrt;
84
+ int length, minlen = 7;
85
+ VALUE rb_enum, rb_minlen, rb_block;
86
+
87
+ rb_scan_args(argc, argv, "11&", &rb_enum, &rb_minlen, &rb_block);
88
+
89
+ if (!NIL_P(rb_minlen)) {
90
+ Check_Type(rb_minlen, T_FIXNUM);
91
+ minlen = FIX2INT(rb_minlen);
92
+ }
93
+
94
+ if (!rb_respond_to(rb_enum, rb_intern("each")))
95
+ rb_raise(rb_eTypeError, "Expecting an Enumerable instance");
96
+
97
+ shrt = git_oid_shorten_new(minlen);
98
+
99
+ rb_iterate(rb_each, rb_enum, &minimize_cb, (VALUE)shrt);
100
+ length = git_oid_shorten_add(shrt, NULL);
101
+ rugged_exception_check(length);
102
+
103
+ if (RTEST(rb_block)) {
104
+ VALUE yield_data[2];
105
+
106
+ yield_data[0] = rb_block;
107
+ yield_data[1] = INT2FIX(length);
108
+
109
+ rb_iterate(rb_each, rb_enum, &minimize_yield, (VALUE)yield_data);
110
+ git_oid_shorten_free(shrt);
111
+ return Qnil;
112
+ }
113
+
114
+ git_oid_shorten_free(shrt);
115
+ return INT2FIX(length);
116
+ }
117
+
118
+ static void cleanup_cb(void *unused)
119
+ {
120
+ (void)unused;
121
+ git_threads_shutdown();
122
+ }
123
+
124
+ void Init_rugged()
125
+ {
126
+ rb_mRugged = rb_define_module("Rugged");
127
+
128
+ rb_define_module_function(rb_mRugged, "hex_to_raw", rb_git_hex_to_raw, 1);
129
+ rb_define_module_function(rb_mRugged, "raw_to_hex", rb_git_raw_to_hex, 1);
130
+ rb_define_module_function(rb_mRugged, "type_to_string", rb_git_type_to_string, 1);
131
+ rb_define_module_function(rb_mRugged, "string_to_type", rb_git_string_to_type, 1);
132
+ rb_define_module_function(rb_mRugged, "minimize_oid", rb_git_minimize_oid, -1);
133
+
134
+ Init_rugged_object();
135
+ Init_rugged_commit();
136
+ Init_rugged_tree();
137
+ Init_rugged_tag();
138
+ Init_rugged_blob();
139
+
140
+ Init_rugged_index();
141
+ Init_rugged_repo();
142
+ Init_rugged_revwalk();
143
+ Init_rugged_reference();
144
+ Init_rugged_config();
145
+ Init_rugged_remote();
146
+
147
+ /* Constants */
148
+ rb_define_const(rb_mRugged, "SORT_NONE", INT2FIX(0));
149
+ rb_define_const(rb_mRugged, "SORT_TOPO", INT2FIX(1));
150
+ rb_define_const(rb_mRugged, "SORT_DATE", INT2FIX(2));
151
+ rb_define_const(rb_mRugged, "SORT_REVERSE", INT2FIX(4));
152
+
153
+ rb_define_const(rb_mRugged, "OBJ_ANY", INT2FIX(GIT_OBJ_ANY));
154
+ rb_define_const(rb_mRugged, "OBJ_BAD", INT2FIX(GIT_OBJ_BAD));
155
+ rb_define_const(rb_mRugged, "OBJ_COMMIT", INT2FIX(GIT_OBJ_COMMIT));
156
+ rb_define_const(rb_mRugged, "OBJ_TREE", INT2FIX(GIT_OBJ_TREE));
157
+ rb_define_const(rb_mRugged, "OBJ_BLOB", INT2FIX(GIT_OBJ_BLOB));
158
+ rb_define_const(rb_mRugged, "OBJ_TAG", INT2FIX(GIT_OBJ_TAG));
159
+
160
+ rb_define_const(rb_mRugged, "REF_OID", INT2FIX(GIT_REF_OID));
161
+ rb_define_const(rb_mRugged, "REF_SYMBOLIC", INT2FIX(GIT_REF_SYMBOLIC));
162
+
163
+ /* Initialize libgit2 */
164
+ git_threads_init();
165
+
166
+ /* Hook a global object to cleanup the library
167
+ * on shutdown */
168
+ rb_mShutdownHook = Data_Wrap_Struct(rb_cObject, NULL, &cleanup_cb, NULL);
169
+ rb_global_variable(&rb_mShutdownHook);
170
+ }
171
+
@@ -0,0 +1,126 @@
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
+ #ifndef __H_RUGGED_BINDINGS__
26
+ #define __H_RUGGED_BINDINGS__
27
+
28
+ // tell rbx not to use it's caching compat layer
29
+ // by doing this we're making a promize to RBX that
30
+ // we'll never modify the pointers we get back from RSTRING_PTR
31
+ #define RSTRING_NOT_MODIFIED
32
+
33
+ #include <ruby.h>
34
+
35
+ #ifdef HAVE_RUBY_ENCODING_H
36
+ # include <ruby/encoding.h>
37
+ #endif
38
+
39
+ #include <assert.h>
40
+ #include <git2.h>
41
+ #include <git2/odb_backend.h>
42
+
43
+ /*
44
+ * Initialization functions
45
+ */
46
+ void Init_rugged_object();
47
+ void Init_rugged_commit();
48
+ void Init_rugged_tree();
49
+ void Init_rugged_tag();
50
+ void Init_rugged_blob();
51
+ void Init_rugged_index();
52
+ void Init_rugged_repo();
53
+ void Init_rugged_revwalk();
54
+ void Init_rugged_reference();
55
+ void Init_rugged_config();
56
+ void Init_rugged_remote();
57
+
58
+ VALUE rb_git_object_init(git_otype type, int argc, VALUE *argv, VALUE self);
59
+
60
+ VALUE rugged_raw_read(git_repository *repo, const git_oid *oid);
61
+
62
+ VALUE rugged_signature_new(const git_signature *sig, const char *encoding_name);
63
+
64
+ VALUE rugged_index_new(VALUE klass, VALUE owner, git_index *index);
65
+ VALUE rugged_object_new(VALUE owner, git_object *object);
66
+ VALUE rugged_config_new(VALUE klass, VALUE owner, git_config *cfg);
67
+
68
+ git_otype rugged_get_otype(VALUE rb_type);
69
+
70
+ git_signature *rugged_signature_get(VALUE rb_person);
71
+ git_object *rugged_object_load(git_repository *repo, VALUE object_value, git_otype type);
72
+
73
+ #define CSTR2SYM(s) (ID2SYM(rb_intern((s))))
74
+
75
+ static inline void rugged_set_owner(VALUE object, VALUE owner)
76
+ {
77
+ rb_iv_set(object, "@owner", owner);
78
+ }
79
+
80
+ static inline VALUE rugged_owner(VALUE object)
81
+ {
82
+ rb_iv_get(object, "@owner");
83
+ }
84
+
85
+ static inline void rugged_exception_check(int errorcode)
86
+ {
87
+ if (errorcode < 0)
88
+ rb_raise(rb_eRuntimeError, "%s\n(error code %d)", git_lasterror(), errorcode);
89
+
90
+ git_clearerror();
91
+ }
92
+
93
+ static inline int rugged_parse_bool(VALUE boolean)
94
+ {
95
+ if (TYPE(boolean) != T_TRUE && TYPE(boolean) != T_FALSE)
96
+ rb_raise(rb_eTypeError, "Expected boolean value");
97
+
98
+ return boolean ? 1 : 0;
99
+ }
100
+
101
+ /* support for string encodings in 1.9 */
102
+ #ifdef HAVE_RUBY_ENCODING_H
103
+ # define rugged_str_new(str, len, enc) rb_enc_str_new(str, len, enc)
104
+ # define rugged_str_new2(str, enc) rb_enc_str_new(str, strlen(str), enc)
105
+ # define rugged_str_ascii(str, len) rb_enc_str_new(str, len, rb_ascii8bit_encoding());
106
+
107
+ static VALUE rugged_str_repoenc(const char *str, long len, VALUE rb_repo)
108
+ {
109
+ VALUE rb_enc = rb_iv_get(rb_repo, "@encoding");
110
+ return rb_enc_str_new(str, len, NIL_P(rb_enc) ? NULL : rb_to_encoding(rb_enc));
111
+ }
112
+ #else
113
+ # define rugged_str_new(str, len, rb_enc) rb_str_new(str, len)
114
+ # define rugged_str_new2(str, rb_enc) rb_str_new2(str)
115
+ # define rugged_str_repoenc(str, len, repo) rb_str_new(str, len)
116
+ # define rugged_str_ascii(str, len) rb_str_new(str, len)
117
+ #endif
118
+
119
+ static inline VALUE rugged_create_oid(const git_oid *oid)
120
+ {
121
+ char out[40];
122
+ git_oid_fmt(out, oid);
123
+ return rugged_str_new(out, 40, NULL);
124
+ }
125
+
126
+ #endif
@@ -0,0 +1,99 @@
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_cRuggedBlob;
32
+
33
+ static VALUE rb_git_blob_content_GET(VALUE self)
34
+ {
35
+ git_blob *blob;
36
+ size_t size;
37
+
38
+ Data_Get_Struct(self, git_blob, blob);
39
+
40
+ size = git_blob_rawsize(blob);
41
+ if (size == 0)
42
+ return rugged_str_ascii("", 0);
43
+
44
+ /*
45
+ * since we don't really ever know the encoding of a blob
46
+ * lets default to the binary encoding (ascii-8bit)
47
+ * If there is a way to tell, we should just pass 0/null here instead
48
+ *
49
+ * we're skipping the use of STR_NEW because we don't want our string to
50
+ * eventually end up converted to Encoding.default_internal because this
51
+ * string could very well be binary data
52
+ */
53
+ return rugged_str_ascii(git_blob_rawcontent(blob), size);
54
+ }
55
+
56
+ static VALUE rb_git_blob_rawsize(VALUE self)
57
+ {
58
+ git_blob *blob;
59
+ Data_Get_Struct(self, git_blob, blob);
60
+
61
+ return INT2FIX(git_blob_rawsize(blob));
62
+ }
63
+
64
+ static VALUE rb_git_blob_create(int argc, VALUE *argv, VALUE self)
65
+ {
66
+ int error;
67
+ git_oid oid;
68
+ git_repository *repo;
69
+
70
+ VALUE rb_buffer, rb_repo, rb_is_buffer = Qfalse;
71
+
72
+ rb_scan_args(argc, argv, "21", &rb_repo, &rb_buffer, &rb_is_buffer);
73
+
74
+ Check_Type(rb_buffer, T_STRING);
75
+ if (!rb_obj_is_instance_of(rb_repo, rb_cRuggedRepo))
76
+ rb_raise(rb_eTypeError, "Expecting a Rugged Repository");
77
+
78
+ Data_Get_Struct(rb_repo, git_repository, repo);
79
+
80
+ if (rugged_parse_bool(rb_is_buffer)) {
81
+ error = git_blob_create_frombuffer(&oid, repo, RSTRING_PTR(rb_buffer), RSTRING_LEN(rb_buffer));
82
+ } else {
83
+ error = git_blob_create_fromfile(&oid, repo, StringValueCStr(rb_buffer));
84
+ }
85
+
86
+ rugged_exception_check(error);
87
+
88
+ return rugged_create_oid(&oid);
89
+ }
90
+
91
+ void Init_rugged_blob()
92
+ {
93
+ rb_cRuggedBlob = rb_define_class_under(rb_mRugged, "Blob", rb_cRuggedObject);
94
+
95
+ rb_define_method(rb_cRuggedBlob, "size", rb_git_blob_rawsize, 0);
96
+ rb_define_method(rb_cRuggedBlob, "content", rb_git_blob_content_GET, 0);
97
+
98
+ rb_define_singleton_method(rb_cRuggedBlob, "create", rb_git_blob_create, -1);
99
+ }
@@ -0,0 +1,224 @@
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
+ extern VALUE rb_cRuggedSignature;
31
+ VALUE rb_cRuggedCommit;
32
+
33
+ /*
34
+ * Commit code
35
+ */
36
+ static VALUE rb_git_commit_message_GET(VALUE self)
37
+ {
38
+ git_commit *commit;
39
+
40
+ #ifdef HAVE_RUBY_ENCODING_H
41
+ rb_encoding *encoding = NULL;
42
+ const char *encoding_name;
43
+ #endif
44
+
45
+ Data_Get_Struct(self, git_commit, commit);
46
+
47
+ #ifdef HAVE_RUBY_ENCODING_H
48
+ encoding_name = git_commit_message_encoding(commit);
49
+ if (encoding_name != NULL)
50
+ encoding = rb_enc_find(encoding_name);
51
+ #endif
52
+
53
+ return rugged_str_new2(git_commit_message(commit), encoding);
54
+ }
55
+
56
+ static VALUE rb_git_commit_committer_GET(VALUE self)
57
+ {
58
+ git_commit *commit;
59
+ Data_Get_Struct(self, git_commit, commit);
60
+
61
+ return rugged_signature_new(
62
+ git_commit_committer(commit),
63
+ git_commit_message_encoding(commit));
64
+ }
65
+
66
+ static VALUE rb_git_commit_author_GET(VALUE self)
67
+ {
68
+ git_commit *commit;
69
+ Data_Get_Struct(self, git_commit, commit);
70
+
71
+ return rugged_signature_new(
72
+ git_commit_author(commit),
73
+ git_commit_message_encoding(commit));
74
+ }
75
+
76
+ static VALUE rb_git_commit_time_GET(VALUE self)
77
+ {
78
+ git_commit *commit;
79
+ Data_Get_Struct(self, git_commit, commit);
80
+
81
+ return ULONG2NUM(git_commit_time(commit));
82
+ }
83
+
84
+ static VALUE rb_git_commit_tree_GET(VALUE self)
85
+ {
86
+ git_commit *commit;
87
+ git_tree *tree;
88
+ VALUE owner;
89
+ int error;
90
+
91
+ Data_Get_Struct(self, git_commit, commit);
92
+ owner = rugged_owner(self);
93
+
94
+ error = git_commit_tree(&tree, commit);
95
+ rugged_exception_check(error);
96
+
97
+ return rugged_object_new(owner, (git_object *)tree);
98
+ }
99
+
100
+ static VALUE rb_git_commit_parents_GET(VALUE self)
101
+ {
102
+ git_commit *commit;
103
+ git_commit *parent;
104
+ unsigned int n, parent_count;
105
+ VALUE ret_arr, owner;
106
+ int error;
107
+
108
+ Data_Get_Struct(self, git_commit, commit);
109
+ owner = rugged_owner(self);
110
+
111
+ parent_count = git_commit_parentcount(commit);
112
+ ret_arr = rb_ary_new2((long)parent_count);
113
+
114
+ for (n = 0; n < parent_count; n++) {
115
+ error = git_commit_parent(&parent, commit, n);
116
+ rugged_exception_check(error);
117
+ rb_ary_push(ret_arr, rugged_object_new(owner, (git_object *)parent));
118
+ }
119
+
120
+ return ret_arr;
121
+ }
122
+
123
+ static VALUE rb_git_commit_create(VALUE self, VALUE rb_repo, VALUE rb_data)
124
+ {
125
+ VALUE rb_message, rb_tree, rb_parents;
126
+ int parent_count, i, error;
127
+ const git_commit **parents;
128
+ git_tree *tree;
129
+ git_signature *author, *committer;
130
+ git_oid commit_oid;
131
+ git_repository *repo;
132
+
133
+ Check_Type(rb_data, T_HASH);
134
+
135
+ if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo))
136
+ rb_raise(rb_eTypeError, "Expeting a Rugged::Repository instance");
137
+ Data_Get_Struct(rb_repo, git_repository, repo);
138
+
139
+ rb_message = rb_hash_aref(rb_data, CSTR2SYM("message"));
140
+ Check_Type(rb_message, T_STRING);
141
+
142
+ committer = rugged_signature_get(
143
+ rb_hash_aref(rb_data, CSTR2SYM("committer"))
144
+ );
145
+
146
+ author = rugged_signature_get(
147
+ rb_hash_aref(rb_data, CSTR2SYM("author"))
148
+ );
149
+
150
+ rb_parents = rb_hash_aref(rb_data, CSTR2SYM("parents"));
151
+ Check_Type(rb_parents, T_ARRAY);
152
+
153
+ rb_tree = rb_hash_aref(rb_data, CSTR2SYM("tree"));
154
+ tree = (git_tree *)rugged_object_load(repo, rb_tree, GIT_OBJ_TREE);
155
+
156
+ parent_count = (int)RARRAY_LEN(rb_parents);
157
+ parents = malloc(parent_count * sizeof(void*));
158
+
159
+ for (i = 0; i < parent_count; ++i) {
160
+ VALUE p = rb_ary_entry(rb_parents, i);
161
+ git_commit *parent = NULL;
162
+
163
+ if (TYPE(p) == T_STRING) {
164
+ git_oid oid;
165
+
166
+ error = git_oid_fromstr(&oid, StringValueCStr(p));
167
+ if (error < GIT_SUCCESS)
168
+ goto cleanup;
169
+
170
+ error = git_commit_lookup(&parent, repo, &oid);
171
+ if (error < GIT_SUCCESS)
172
+ goto cleanup;
173
+
174
+ } else if (rb_obj_is_kind_of(p, rb_cRuggedCommit)) {
175
+ Data_Get_Struct(p, git_commit, parent);
176
+ } else {
177
+ error = GIT_EINVALIDTYPE;
178
+ goto cleanup;
179
+ }
180
+
181
+ parents[i] = parent;
182
+ }
183
+
184
+ error = git_commit_create(
185
+ &commit_oid,
186
+ repo,
187
+ NULL,
188
+ author,
189
+ committer,
190
+ NULL,
191
+ StringValueCStr(rb_message),
192
+ tree,
193
+ parent_count,
194
+ parents);
195
+
196
+ cleanup:
197
+ git_signature_free(author);
198
+ git_signature_free(committer);
199
+
200
+ git_object_free((git_object *)tree);
201
+
202
+ for (i = 0; i < parent_count; ++i)
203
+ git_object_free((git_object *)parents[i]);
204
+
205
+ free(parents);
206
+ rugged_exception_check(error);
207
+
208
+ return rugged_create_oid(&commit_oid);
209
+ }
210
+
211
+ void Init_rugged_commit()
212
+ {
213
+ rb_cRuggedCommit = rb_define_class_under(rb_mRugged, "Commit", rb_cRuggedObject);
214
+
215
+ rb_define_singleton_method(rb_cRuggedCommit, "create", rb_git_commit_create, 2);
216
+
217
+ rb_define_method(rb_cRuggedCommit, "message", rb_git_commit_message_GET, 0);
218
+ rb_define_method(rb_cRuggedCommit, "time", rb_git_commit_time_GET, 0);
219
+ rb_define_method(rb_cRuggedCommit, "committer", rb_git_commit_committer_GET, 0);
220
+ rb_define_method(rb_cRuggedCommit, "author", rb_git_commit_author_GET, 0);
221
+ rb_define_method(rb_cRuggedCommit, "tree", rb_git_commit_tree_GET, 0);
222
+ rb_define_method(rb_cRuggedCommit, "parents", rb_git_commit_parents_GET, 0);
223
+ }
224
+