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,451 @@
1
+ // [**libgit2**][lg] is a portable, pure C implementation of the Git core methods
2
+ // provided as a re-entrant linkable library with a solid API, allowing you
3
+ // to write native speed custom Git applications in any language which
4
+ // supports C bindings.
5
+ //
6
+ // This file is an example of using that API in a real, compilable C file.
7
+ // As the API is updated, this file will be updated to demonstrate the
8
+ // new functionality.
9
+ //
10
+ // If you're trying to write something in C using [libgit2][lg], you will also want
11
+ // to check out the generated [API documentation][ap] and the [Usage Guide][ug]. We've
12
+ // tried to link to the relevant sections of the API docs in each section in this file.
13
+ //
14
+ // **libgit2** only implements the core plumbing functions, not really the higher
15
+ // level porcelain stuff. For a primer on Git Internals that you will need to know
16
+ // to work with Git at this level, check out [Chapter 9][pg] of the Pro Git book.
17
+ //
18
+ // [lg]: http://libgit2.github.com
19
+ // [ap]: http://libgit2.github.com/libgit2
20
+ // [ug]: http://libgit2.github.com/api.html
21
+ // [pg]: http://progit.org/book/ch9-0.html
22
+
23
+ // ### Includes
24
+
25
+ // Including the `git2.h` header will include all the other libgit2 headers that you need.
26
+ // It should be the only thing you need to include in order to compile properly and get
27
+ // all the libgit2 API.
28
+ #include <git2.h>
29
+ #include <stdio.h>
30
+
31
+ int main (int argc, char** argv)
32
+ {
33
+ // ### Opening the Repository
34
+
35
+ // There are a couple of methods for opening a repository, this being the simplest.
36
+ // There are also [methods][me] for specifying the index file and work tree locations, here
37
+ // we are assuming they are in the normal places.
38
+ //
39
+ // [me]: http://libgit2.github.com/libgit2/#HEAD/group/repository
40
+ git_repository *repo;
41
+ if (argc > 1) {
42
+ git_repository_open(&repo, argv[1]);
43
+ } else {
44
+ git_repository_open(&repo, "/opt/libgit2-test/.git");
45
+ }
46
+
47
+ // ### SHA-1 Value Conversions
48
+
49
+ // For our first example, we will convert a 40 character hex value to the 20 byte raw SHA1 value.
50
+ printf("*Hex to Raw*\n");
51
+ char hex[] = "fd6e612585290339ea8bf39c692a7ff6a29cb7c3";
52
+
53
+ // The `git_oid` is the structure that keeps the SHA value. We will use this throughout the example
54
+ // for storing the value of the current SHA key we're working with.
55
+ git_oid oid;
56
+ git_oid_fromstr(&oid, hex);
57
+
58
+ // Once we've converted the string into the oid value, we can get the raw value of the SHA.
59
+ printf("Raw 20 bytes: [%.20s]\n", (&oid)->id);
60
+
61
+ // Next we will convert the 20 byte raw SHA1 value to a human readable 40 char hex value.
62
+ printf("\n*Raw to Hex*\n");
63
+ char out[41];
64
+ out[40] = '\0';
65
+
66
+ // If you have a oid, you can easily get the hex value of the SHA as well.
67
+ git_oid_fmt(out, &oid);
68
+ printf("SHA hex string: %s\n", out);
69
+
70
+ // ### Working with the Object Database
71
+ // **libgit2** provides [direct access][odb] to the object database.
72
+ // The object database is where the actual objects are stored in Git. For
73
+ // working with raw objects, we'll need to get this structure from the
74
+ // repository.
75
+ // [odb]: http://libgit2.github.com/libgit2/#HEAD/group/odb
76
+ git_odb *odb;
77
+ odb = git_repository_database(repo);
78
+
79
+ // #### Raw Object Reading
80
+
81
+ printf("\n*Raw Object Read*\n");
82
+ git_odb_object *obj;
83
+ git_otype otype;
84
+ const unsigned char *data;
85
+ const char *str_type;
86
+ int error;
87
+
88
+ // We can read raw objects directly from the object database if we have the oid (SHA)
89
+ // of the object. This allows us to access objects without knowing thier type and inspect
90
+ // the raw bytes unparsed.
91
+ error = git_odb_read(&obj, odb, &oid);
92
+
93
+ // A raw object only has three properties - the type (commit, blob, tree or tag), the size
94
+ // of the raw data and the raw, unparsed data itself. For a commit or tag, that raw data
95
+ // is human readable plain ASCII text. For a blob it is just file contents, so it could be
96
+ // text or binary data. For a tree it is a special binary format, so it's unlikely to be
97
+ // hugely helpful as a raw object.
98
+ data = (const unsigned char *)git_odb_object_data(obj);
99
+ otype = git_odb_object_type(obj);
100
+
101
+ // We provide methods to convert from the object type which is an enum, to a string
102
+ // representation of that value (and vice-versa).
103
+ str_type = git_object_type2string(otype);
104
+ printf("object length and type: %d, %s\n",
105
+ (int)git_odb_object_size(obj),
106
+ str_type);
107
+
108
+ // For proper memory management, close the object when you are done with it or it will leak
109
+ // memory.
110
+ git_odb_object_free(obj);
111
+
112
+ // #### Raw Object Writing
113
+
114
+ printf("\n*Raw Object Write*\n");
115
+
116
+ // You can also write raw object data to Git. This is pretty cool because it gives you
117
+ // direct access to the key/value properties of Git. Here we'll write a new blob object
118
+ // that just contains a simple string. Notice that we have to specify the object type as
119
+ // the `git_otype` enum.
120
+ git_odb_write(&oid, odb, "test data", sizeof("test data") - 1, GIT_OBJ_BLOB);
121
+
122
+ // Now that we've written the object, we can check out what SHA1 was generated when the
123
+ // object was written to our database.
124
+ git_oid_fmt(out, &oid);
125
+ printf("Written Object: %s\n", out);
126
+
127
+ // ### Object Parsing
128
+ // libgit2 has methods to parse every object type in Git so you don't have to work directly
129
+ // with the raw data. This is much faster and simpler than trying to deal with the raw data
130
+ // yourself.
131
+
132
+ // #### Commit Parsing
133
+ // [Parsing commit objects][pco] is simple and gives you access to all the data in the commit
134
+ // - the // author (name, email, datetime), committer (same), tree, message, encoding and parent(s).
135
+ // [pco]: http://libgit2.github.com/libgit2/#HEAD/group/commit
136
+
137
+ printf("\n*Commit Parsing*\n");
138
+
139
+ git_commit *commit;
140
+ git_oid_fromstr(&oid, "f0877d0b841d75172ec404fc9370173dfffc20d1");
141
+
142
+ error = git_commit_lookup(&commit, repo, &oid);
143
+
144
+ const git_signature *author, *cmtter;
145
+ const char *message;
146
+ time_t ctime;
147
+ unsigned int parents, p;
148
+
149
+ // Each of the properties of the commit object are accessible via methods, including commonly
150
+ // needed variations, such as `git_commit_time` which returns the author time and `_message`
151
+ // which gives you the commit message.
152
+ message = git_commit_message(commit);
153
+ author = git_commit_author(commit);
154
+ cmtter = git_commit_committer(commit);
155
+ ctime = git_commit_time(commit);
156
+
157
+ // The author and committer methods return [git_signature] structures, which give you name, email
158
+ // and `when`, which is a `git_time` structure, giving you a timestamp and timezone offset.
159
+ printf("Author: %s (%s)\n", author->name, author->email);
160
+
161
+ // Commits can have zero or more parents. The first (root) commit will have no parents, most commits
162
+ // will have one, which is the commit it was based on, and merge commits will have two or more.
163
+ // Commits can technically have any number, though it's pretty rare to have more than two.
164
+ parents = git_commit_parentcount(commit);
165
+ for (p = 0;p < parents;p++) {
166
+ git_commit *parent;
167
+ git_commit_parent(&parent, commit, p);
168
+ git_oid_fmt(out, git_commit_id(parent));
169
+ printf("Parent: %s\n", out);
170
+ git_commit_free(parent);
171
+ }
172
+
173
+ // Don't forget to close the object to prevent memory leaks. You will have to do this for
174
+ // all the objects you open and parse.
175
+ git_commit_free(commit);
176
+
177
+ // #### Writing Commits
178
+ //
179
+ // libgit2 provides a couple of methods to create commit objects easily as well. There are four
180
+ // different create signatures, we'll just show one of them here. You can read about the other
181
+ // ones in the [commit API docs][cd].
182
+ // [cd]: http://libgit2.github.com/libgit2/#HEAD/group/commit
183
+
184
+ printf("\n*Commit Writing*\n");
185
+ git_oid tree_id, parent_id, commit_id;
186
+ git_tree *tree;
187
+ git_commit *parent;
188
+
189
+ // Creating signatures for an authoring identity and time is pretty simple - you will need to have
190
+ // this to create a commit in order to specify who created it and when. Default values for the name
191
+ // and email should be found in the `user.name` and `user.email` configuration options. See the `config`
192
+ // section of this example file to see how to access config values.
193
+ git_signature_new((git_signature **)&author, "Scott Chacon", "schacon@gmail.com",
194
+ 123456789, 60);
195
+ git_signature_new((git_signature **)&cmtter, "Scott A Chacon", "scott@github.com",
196
+ 987654321, 90);
197
+
198
+ // Commit objects need a tree to point to and optionally one or more parents. Here we're creating oid
199
+ // objects to create the commit with, but you can also use
200
+ git_oid_fromstr(&tree_id, "28873d96b4e8f4e33ea30f4c682fd325f7ba56ac");
201
+ git_tree_lookup(&tree, repo, &tree_id);
202
+ git_oid_fromstr(&parent_id, "f0877d0b841d75172ec404fc9370173dfffc20d1");
203
+ git_commit_lookup(&parent, repo, &parent_id);
204
+
205
+ // Here we actually create the commit object with a single call with all the values we need to create
206
+ // the commit. The SHA key is written to the `commit_id` variable here.
207
+ git_commit_create_v(
208
+ &commit_id, /* out id */
209
+ repo,
210
+ NULL, /* do not update the HEAD */
211
+ author,
212
+ cmtter,
213
+ NULL, /* use default message encoding */
214
+ "example commit",
215
+ tree,
216
+ 1, parent);
217
+
218
+ // Now we can take a look at the commit SHA we've generated.
219
+ git_oid_fmt(out, &commit_id);
220
+ printf("New Commit: %s\n", out);
221
+
222
+ // #### Tag Parsing
223
+ // You can parse and create tags with the [tag management API][tm], which functions very similarly
224
+ // to the commit lookup, parsing and creation methods, since the objects themselves are very similar.
225
+ // [tm]: http://libgit2.github.com/libgit2/#HEAD/group/tag
226
+ printf("\n*Tag Parsing*\n");
227
+ git_tag *tag;
228
+ const char *tmessage, *tname;
229
+ git_otype ttype;
230
+
231
+ // We create an oid for the tag object if we know the SHA and look it up in the repository the same
232
+ // way that we would a commit (or any other) object.
233
+ git_oid_fromstr(&oid, "bc422d45275aca289c51d79830b45cecebff7c3a");
234
+
235
+ error = git_tag_lookup(&tag, repo, &oid);
236
+
237
+ // Now that we have the tag object, we can extract the information it generally contains: the target
238
+ // (usually a commit object), the type of the target object (usually 'commit'), the name ('v1.0'),
239
+ // the tagger (a git_signature - name, email, timestamp), and the tag message.
240
+ git_tag_target((git_object **)&commit, tag);
241
+ tname = git_tag_name(tag); // "test"
242
+ ttype = git_tag_type(tag); // GIT_OBJ_COMMIT (otype enum)
243
+ tmessage = git_tag_message(tag); // "tag message\n"
244
+ printf("Tag Message: %s\n", tmessage);
245
+
246
+ git_commit_free(commit);
247
+
248
+ // #### Tree Parsing
249
+ // [Tree parsing][tp] is a bit different than the other objects, in that we have a subtype which is the
250
+ // tree entry. This is not an actual object type in Git, but a useful structure for parsing and
251
+ // traversing tree entries.
252
+ //
253
+ // [tp]: http://libgit2.github.com/libgit2/#HEAD/group/tree
254
+ printf("\n*Tree Parsing*\n");
255
+
256
+ const git_tree_entry *entry;
257
+ git_object *objt;
258
+
259
+ // Create the oid and lookup the tree object just like the other objects.
260
+ git_oid_fromstr(&oid, "2a741c18ac5ff082a7caaec6e74db3075a1906b5");
261
+ git_tree_lookup(&tree, repo, &oid);
262
+
263
+ // Getting the count of entries in the tree so you can iterate over them if you want to.
264
+ int cnt = git_tree_entrycount(tree); // 3
265
+ printf("tree entries: %d\n", cnt);
266
+
267
+ entry = git_tree_entry_byindex(tree, 0);
268
+ printf("Entry name: %s\n", git_tree_entry_name(entry)); // "hello.c"
269
+
270
+ // You can also access tree entries by name if you know the name of the entry you're looking for.
271
+ entry = git_tree_entry_byname(tree, "hello.c");
272
+ git_tree_entry_name(entry); // "hello.c"
273
+
274
+ // Once you have the entry object, you can access the content or subtree (or commit, in the case
275
+ // of submodules) that it points to. You can also get the mode if you want.
276
+ git_tree_entry_2object(&objt, repo, entry); // blob
277
+
278
+ // Remember to close the looked-up object once you are done using it
279
+ git_object_free(objt);
280
+
281
+ // #### Blob Parsing
282
+ //
283
+ // The last object type is the simplest and requires the least parsing help. Blobs are just file
284
+ // contents and can contain anything, there is no structure to it. The main advantage to using the
285
+ // [simple blob api][ba] is that when you're creating blobs you don't have to calculate the size
286
+ // of the content. There is also a helper for reading a file from disk and writing it to the db and
287
+ // getting the oid back so you don't have to do all those steps yourself.
288
+ //
289
+ // [ba]: http://libgit2.github.com/libgit2/#HEAD/group/blob
290
+
291
+ printf("\n*Blob Parsing*\n");
292
+ git_blob *blob;
293
+
294
+ git_oid_fromstr(&oid, "af7574ea73f7b166f869ef1a39be126d9a186ae0");
295
+ git_blob_lookup(&blob, repo, &oid);
296
+
297
+ // You can access a buffer with the raw contents of the blob directly.
298
+ // Note that this buffer may not be contain ASCII data for certain blobs (e.g. binary files):
299
+ // do not consider the buffer a NULL-terminated string, and use the `git_blob_rawsize` attribute to
300
+ // find out its exact size in bytes
301
+ printf("Blob Size: %ld\n", git_blob_rawsize(blob)); // 8
302
+ git_blob_rawcontent(blob); // "content"
303
+
304
+ // ### Revwalking
305
+ //
306
+ // The libgit2 [revision walking api][rw] provides methods to traverse the directed graph created
307
+ // by the parent pointers of the commit objects. Since all commits point back to the commit that
308
+ // came directly before them, you can walk this parentage as a graph and find all the commits that
309
+ // were ancestors of (reachable from) a given starting point. This can allow you to create `git log`
310
+ // type functionality.
311
+ //
312
+ // [rw]: http://libgit2.github.com/libgit2/#HEAD/group/revwalk
313
+
314
+ printf("\n*Revwalking*\n");
315
+ git_revwalk *walk;
316
+ git_commit *wcommit;
317
+
318
+ git_oid_fromstr(&oid, "f0877d0b841d75172ec404fc9370173dfffc20d1");
319
+
320
+ // To use the revwalker, create a new walker, tell it how you want to sort the output and then push
321
+ // one or more starting points onto the walker. If you want to emulate the output of `git log` you
322
+ // would push the SHA of the commit that HEAD points to into the walker and then start traversing them.
323
+ // You can also 'hide' commits that you want to stop at or not see any of their ancestors. So if you
324
+ // want to emulate `git log branch1..branch2`, you would push the oid of `branch2` and hide the oid
325
+ // of `branch1`.
326
+ git_revwalk_new(&walk, repo);
327
+ git_revwalk_sorting(walk, GIT_SORT_TOPOLOGICAL | GIT_SORT_REVERSE);
328
+ git_revwalk_push(walk, &oid);
329
+
330
+ const git_signature *cauth;
331
+ const char *cmsg;
332
+
333
+ // Now that we have the starting point pushed onto the walker, we can start asking for ancestors. It
334
+ // will return them in the sorting order we asked for as commit oids.
335
+ // We can then lookup and parse the commited pointed at by the returned OID;
336
+ // note that this operation is specially fast since the raw contents of the commit object will
337
+ // be cached in memory
338
+ while ((git_revwalk_next(&oid, walk)) == GIT_SUCCESS) {
339
+ error = git_commit_lookup(&wcommit, repo, &oid);
340
+ cmsg = git_commit_message(wcommit);
341
+ cauth = git_commit_author(wcommit);
342
+ printf("%s (%s)\n", cmsg, cauth->email);
343
+ git_commit_free(wcommit);
344
+ }
345
+
346
+ // Like the other objects, be sure to free the revwalker when you're done to prevent memory leaks.
347
+ // Also, make sure that the repository being walked it not deallocated while the walk is in
348
+ // progress, or it will result in undefined behavior
349
+ git_revwalk_free(walk);
350
+
351
+ // ### Index File Manipulation
352
+ //
353
+ // The [index file API][gi] allows you to read, traverse, update and write the Git index file
354
+ // (sometimes thought of as the staging area).
355
+ //
356
+ // [gi]: http://libgit2.github.com/libgit2/#HEAD/group/index
357
+
358
+ printf("\n*Index Walking*\n");
359
+
360
+ git_index *index;
361
+ unsigned int i, ecount;
362
+
363
+ // You can either open the index from the standard location in an open repository, as we're doing
364
+ // here, or you can open and manipulate any index file with `git_index_open_bare()`. The index
365
+ // for the repository will be located and loaded from disk.
366
+ git_repository_index(&index, repo);
367
+
368
+ // For each entry in the index, you can get a bunch of information including the SHA (oid), path
369
+ // and mode which map to the tree objects that are written out. It also has filesystem properties
370
+ // to help determine what to inspect for changes (ctime, mtime, dev, ino, uid, gid, file_size and flags)
371
+ // All these properties are exported publicly in the `git_index_entry` struct
372
+ ecount = git_index_entrycount(index);
373
+ for (i = 0; i < ecount; ++i) {
374
+ git_index_entry *e = git_index_get(index, i);
375
+
376
+ printf("path: %s\n", e->path);
377
+ printf("mtime: %d\n", (int)e->mtime.seconds);
378
+ printf("fs: %d\n", (int)e->file_size);
379
+ }
380
+
381
+ git_index_free(index);
382
+
383
+ // ### References
384
+ //
385
+ // The [reference API][ref] allows you to list, resolve, create and update references such as
386
+ // branches, tags and remote references (everything in the .git/refs directory).
387
+ //
388
+ // [ref]: http://libgit2.github.com/libgit2/#HEAD/group/reference
389
+
390
+ printf("\n*Reference Listing*\n");
391
+
392
+ // Here we will implement something like `git for-each-ref` simply listing out all available
393
+ // references and the object SHA they resolve to.
394
+ git_strarray ref_list;
395
+ git_reference_listall(&ref_list, repo, GIT_REF_LISTALL);
396
+
397
+ const char *refname;
398
+ git_reference *ref;
399
+
400
+ // Now that we have the list of reference names, we can lookup each ref one at a time and
401
+ // resolve them to the SHA, then print both values out.
402
+ for (i = 0; i < ref_list.count; ++i) {
403
+ refname = ref_list.strings[i];
404
+ git_reference_lookup(&ref, repo, refname);
405
+
406
+ switch (git_reference_type(ref)) {
407
+ case GIT_REF_OID:
408
+ git_oid_fmt(out, git_reference_oid(ref));
409
+ printf("%s [%s]\n", refname, out);
410
+ break;
411
+
412
+ case GIT_REF_SYMBOLIC:
413
+ printf("%s => %s\n", refname, git_reference_target(ref));
414
+ break;
415
+ default:
416
+ fprintf(stderr, "Unexpected reference type\n");
417
+ exit(1);
418
+ }
419
+ }
420
+
421
+ git_strarray_free(&ref_list);
422
+
423
+ // ### Config Files
424
+ //
425
+ // The [config API][config] allows you to list and updatee config values in
426
+ // any of the accessible config file locations (system, global, local).
427
+ //
428
+ // [config]: http://libgit2.github.com/libgit2/#HEAD/group/config
429
+
430
+ printf("\n*Config Listing*\n");
431
+
432
+ const char *email;
433
+ int32_t j;
434
+
435
+ git_config *cfg;
436
+
437
+ // Open a config object so we can read global values from it.
438
+ git_config_open_ondisk(&cfg, "~/.gitconfig");
439
+
440
+ git_config_get_int32(cfg, "help.autocorrect", &j);
441
+ printf("Autocorrect: %d\n", j);
442
+
443
+ git_config_get_string(cfg, "user.email", &email);
444
+ printf("Email: %s\n", email);
445
+
446
+ // Finally, when you're done with the repository, you can free it as well.
447
+ git_repository_free(repo);
448
+
449
+ return 0;
450
+ }
451
+
@@ -0,0 +1,14 @@
1
+ #ifndef __COMMON_H__
2
+ #define __COMMON_H__
3
+
4
+ #include <git2.h>
5
+
6
+ typedef int (*git_cb)(git_repository *, int , char **);
7
+
8
+ int ls_remote(git_repository *repo, int argc, char **argv);
9
+ int parse_pkt_line(git_repository *repo, int argc, char **argv);
10
+ int show_remote(git_repository *repo, int argc, char **argv);
11
+ int fetch(git_repository *repo, int argc, char **argv);
12
+ int index_pack(git_repository *repo, int argc, char **argv);
13
+
14
+ #endif /* __COMMON_H__ */