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,426 @@
1
+ /*
2
+ * Copyright (C) 2009-2011 the libgit2 contributors
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #include "common.h"
9
+
10
+ #include "git2/types.h"
11
+ #include "git2/errors.h"
12
+ #include "git2/refs.h"
13
+ #include "git2/revwalk.h"
14
+
15
+ #include "pkt.h"
16
+ #include "util.h"
17
+ #include "netops.h"
18
+ #include "posix.h"
19
+ #include "buffer.h"
20
+
21
+ #include <ctype.h>
22
+
23
+ #define PKT_LEN_SIZE 4
24
+ static const char pkt_done_str[] = "0009done\n";
25
+ static const char pkt_flush_str[] = "0000";
26
+ static const char pkt_have_prefix[] = "0032have ";
27
+ static const char pkt_want_prefix[] = "0032want ";
28
+
29
+ static int flush_pkt(git_pkt **out)
30
+ {
31
+ git_pkt *pkt;
32
+
33
+ pkt = git__malloc(sizeof(git_pkt));
34
+ if (pkt == NULL)
35
+ return GIT_ENOMEM;
36
+
37
+ pkt->type = GIT_PKT_FLUSH;
38
+ *out = pkt;
39
+
40
+ return GIT_SUCCESS;
41
+ }
42
+
43
+ /* the rest of the line will be useful for multi_ack */
44
+ static int ack_pkt(git_pkt **out, const char *GIT_UNUSED(line), size_t GIT_UNUSED(len))
45
+ {
46
+ git_pkt *pkt;
47
+ GIT_UNUSED_ARG(line);
48
+ GIT_UNUSED_ARG(len);
49
+
50
+ pkt = git__malloc(sizeof(git_pkt));
51
+ if (pkt == NULL)
52
+ return GIT_ENOMEM;
53
+
54
+ pkt->type = GIT_PKT_ACK;
55
+ *out = pkt;
56
+
57
+ return GIT_SUCCESS;
58
+ }
59
+
60
+ static int nak_pkt(git_pkt **out)
61
+ {
62
+ git_pkt *pkt;
63
+
64
+ pkt = git__malloc(sizeof(git_pkt));
65
+ if (pkt == NULL)
66
+ return GIT_ENOMEM;
67
+
68
+ pkt->type = GIT_PKT_NAK;
69
+ *out = pkt;
70
+
71
+ return GIT_SUCCESS;
72
+ }
73
+
74
+ static int pack_pkt(git_pkt **out)
75
+ {
76
+ git_pkt *pkt;
77
+
78
+ pkt = git__malloc(sizeof(git_pkt));
79
+ if (pkt == NULL)
80
+ return GIT_ENOMEM;
81
+
82
+ pkt->type = GIT_PKT_PACK;
83
+ *out = pkt;
84
+
85
+ return GIT_SUCCESS;
86
+ }
87
+
88
+ static int comment_pkt(git_pkt **out, const char *line, size_t len)
89
+ {
90
+ git_pkt_comment *pkt;
91
+
92
+ pkt = git__malloc(sizeof(git_pkt_comment) + len + 1);
93
+ if (pkt == NULL)
94
+ return GIT_ENOMEM;
95
+
96
+ pkt->type = GIT_PKT_COMMENT;
97
+ memcpy(pkt->comment, line, len);
98
+ pkt->comment[len] = '\0';
99
+
100
+ *out = (git_pkt *) pkt;
101
+
102
+ return GIT_SUCCESS;
103
+ }
104
+
105
+ /*
106
+ * Parse an other-ref line.
107
+ */
108
+ static int ref_pkt(git_pkt **out, const char *line, size_t len)
109
+ {
110
+ git_pkt_ref *pkt;
111
+ int error;
112
+
113
+ pkt = git__malloc(sizeof(git_pkt_ref));
114
+ if (pkt == NULL)
115
+ return GIT_ENOMEM;
116
+
117
+ memset(pkt, 0x0, sizeof(git_pkt_ref));
118
+ pkt->type = GIT_PKT_REF;
119
+ error = git_oid_fromstr(&pkt->head.oid, line);
120
+ if (error < GIT_SUCCESS) {
121
+ error = git__throw(error, "Failed to parse reference ID");
122
+ goto out;
123
+ }
124
+
125
+ /* Check for a bit of consistency */
126
+ if (line[GIT_OID_HEXSZ] != ' ') {
127
+ error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse ref. No SP");
128
+ goto out;
129
+ }
130
+
131
+ /* Jump from the name */
132
+ line += GIT_OID_HEXSZ + 1;
133
+ len -= (GIT_OID_HEXSZ + 1);
134
+
135
+ if (line[len - 1] == '\n')
136
+ --len;
137
+
138
+ pkt->head.name = git__malloc(len + 1);
139
+ if (pkt->head.name == NULL) {
140
+ error = GIT_ENOMEM;
141
+ goto out;
142
+ }
143
+ memcpy(pkt->head.name, line, len);
144
+ pkt->head.name[len] = '\0';
145
+
146
+ if (strlen(pkt->head.name) < len) {
147
+ pkt->capabilities = strchr(pkt->head.name, '\0') + 1;
148
+ }
149
+
150
+ out:
151
+ if (error < GIT_SUCCESS)
152
+ git__free(pkt);
153
+ else
154
+ *out = (git_pkt *)pkt;
155
+
156
+ return error;
157
+ }
158
+
159
+ static ssize_t parse_len(const char *line)
160
+ {
161
+ char num[PKT_LEN_SIZE + 1];
162
+ int i, error;
163
+ int len;
164
+ const char *num_end;
165
+
166
+ memcpy(num, line, PKT_LEN_SIZE);
167
+ num[PKT_LEN_SIZE] = '\0';
168
+
169
+ for (i = 0; i < PKT_LEN_SIZE; ++i) {
170
+ if (!isxdigit(num[i]))
171
+ return GIT_ENOTNUM;
172
+ }
173
+
174
+ error = git__strtol32(&len, num, &num_end, 16);
175
+ if (error < GIT_SUCCESS) {
176
+ return error;
177
+ }
178
+
179
+ return (unsigned int) len;
180
+ }
181
+
182
+ /*
183
+ * As per the documentation, the syntax is:
184
+ *
185
+ * pkt-line = data-pkt / flush-pkt
186
+ * data-pkt = pkt-len pkt-payload
187
+ * pkt-len = 4*(HEXDIG)
188
+ * pkt-payload = (pkt-len -4)*(OCTET)
189
+ * flush-pkt = "0000"
190
+ *
191
+ * Which means that the first four bytes are the length of the line,
192
+ * in ASCII hexadecimal (including itself)
193
+ */
194
+
195
+ int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t bufflen)
196
+ {
197
+ int error = GIT_SUCCESS;
198
+ size_t len;
199
+
200
+ /* Not even enough for the length */
201
+ if (bufflen > 0 && bufflen < PKT_LEN_SIZE)
202
+ return GIT_ESHORTBUFFER;
203
+
204
+ error = parse_len(line);
205
+ if (error < GIT_SUCCESS) {
206
+ /*
207
+ * If we fail to parse the length, it might be because the
208
+ * server is trying to send us the packfile already.
209
+ */
210
+ if (bufflen >= 4 && !git__prefixcmp(line, "PACK")) {
211
+ *out = line;
212
+ return pack_pkt(head);
213
+ }
214
+
215
+ return git__throw(error, "Failed to parse pkt length");
216
+ }
217
+
218
+ len = error;
219
+
220
+ /*
221
+ * If we were given a buffer length, then make sure there is
222
+ * enough in the buffer to satisfy this line
223
+ */
224
+ if (bufflen > 0 && bufflen < len)
225
+ return GIT_ESHORTBUFFER;
226
+
227
+ line += PKT_LEN_SIZE;
228
+ /*
229
+ * TODO: How do we deal with empty lines? Try again? with the next
230
+ * line?
231
+ */
232
+ if (len == PKT_LEN_SIZE) {
233
+ *out = line;
234
+ return GIT_SUCCESS;
235
+ }
236
+
237
+ if (len == 0) { /* Flush pkt */
238
+ *out = line;
239
+ return flush_pkt(head);
240
+ }
241
+
242
+ len -= PKT_LEN_SIZE; /* the encoded length includes its own size */
243
+
244
+ /* Assming the minimal size is actually 4 */
245
+ if (!git__prefixcmp(line, "ACK"))
246
+ error = ack_pkt(head, line, len);
247
+ else if (!git__prefixcmp(line, "NAK"))
248
+ error = nak_pkt(head);
249
+ else if (*line == '#')
250
+ error = comment_pkt(head, line, len);
251
+ else
252
+ error = ref_pkt(head, line, len);
253
+
254
+ *out = line + len;
255
+
256
+ return error;
257
+ }
258
+
259
+ void git_pkt_free(git_pkt *pkt)
260
+ {
261
+ if(pkt->type == GIT_PKT_REF) {
262
+ git_pkt_ref *p = (git_pkt_ref *) pkt;
263
+ git__free(p->head.name);
264
+ }
265
+
266
+ git__free(pkt);
267
+ }
268
+
269
+ int git_pkt_buffer_flush(git_buf *buf)
270
+ {
271
+ git_buf_put(buf, pkt_flush_str, strlen(pkt_flush_str));
272
+ return git_buf_oom(buf) ? GIT_ENOMEM : GIT_SUCCESS;
273
+ }
274
+
275
+ int git_pkt_send_flush(int s)
276
+ {
277
+
278
+ return gitno_send(s, pkt_flush_str, strlen(pkt_flush_str), 0);
279
+ }
280
+
281
+ static int buffer_want_with_caps(git_remote_head *head, git_transport_caps *caps, git_buf *buf)
282
+ {
283
+ char capstr[20];
284
+ char oid[GIT_OID_HEXSZ +1] = {0};
285
+ int len;
286
+
287
+ if (caps->ofs_delta)
288
+ strcpy(capstr, GIT_CAP_OFS_DELTA);
289
+
290
+ len = strlen("XXXXwant ") + GIT_OID_HEXSZ + 1 /* NUL */ + strlen(capstr) + 1 /* LF */;
291
+ git_buf_grow(buf, buf->size + len);
292
+
293
+ git_oid_fmt(oid, &head->oid);
294
+ git_buf_printf(buf, "%04xwant %s%c%s\n", len, oid, 0, capstr);
295
+
296
+ return git_buf_oom(buf) ? GIT_ENOMEM : GIT_SUCCESS;
297
+ }
298
+
299
+ static int send_want_with_caps(git_remote_head *head, git_transport_caps *caps, GIT_SOCKET fd)
300
+ {
301
+ git_buf buf = GIT_BUF_INIT;
302
+ int error;
303
+
304
+ error = buffer_want_with_caps(head, caps, &buf);
305
+ if (error < GIT_SUCCESS)
306
+ return git__rethrow(error, "Failed to buffer want with caps");
307
+
308
+ error = gitno_send(fd, buf.ptr, buf.size, 0);
309
+ git_buf_free(&buf);
310
+
311
+ return error;
312
+ }
313
+
314
+ /*
315
+ * All "want" packets have the same length and format, so what we do
316
+ * is overwrite the OID each time.
317
+ */
318
+
319
+ int git_pkt_buffer_wants(const git_vector *refs, git_transport_caps *caps, git_buf *buf)
320
+ {
321
+ unsigned int i = 0;
322
+ int error;
323
+ git_remote_head *head;
324
+
325
+ if (caps->common) {
326
+ for (; i < refs->length; ++i) {
327
+ head = refs->contents[i];
328
+ if (!head->local)
329
+ break;
330
+ }
331
+
332
+ error = buffer_want_with_caps(refs->contents[i], caps, buf);
333
+ if (error < GIT_SUCCESS)
334
+ return git__rethrow(error, "Failed to buffer want with caps");
335
+
336
+ i++;
337
+ }
338
+
339
+ for (; i < refs->length; ++i) {
340
+ char oid[GIT_OID_HEXSZ];
341
+
342
+ head = refs->contents[i];
343
+ if (head->local)
344
+ continue;
345
+
346
+ git_oid_fmt(oid, &head->oid);
347
+ git_buf_put(buf, pkt_want_prefix, strlen(pkt_want_prefix));
348
+ git_buf_put(buf, oid, GIT_OID_HEXSZ);
349
+ git_buf_putc(buf, '\n');
350
+ }
351
+
352
+ return git_pkt_buffer_flush(buf);
353
+ }
354
+
355
+ int git_pkt_send_wants(const git_vector *refs, git_transport_caps *caps, int fd)
356
+ {
357
+ unsigned int i = 0;
358
+ int error = GIT_SUCCESS;
359
+ char buf[sizeof(pkt_want_prefix) + GIT_OID_HEXSZ + 1];
360
+ git_remote_head *head;
361
+
362
+ memcpy(buf, pkt_want_prefix, strlen(pkt_want_prefix));
363
+ buf[sizeof(buf) - 2] = '\n';
364
+ buf[sizeof(buf) - 1] = '\0';
365
+
366
+ /* If there are common caps, find the first one */
367
+ if (caps->common) {
368
+ for (; i < refs->length; ++i) {
369
+ head = refs->contents[i];
370
+ if (head->local)
371
+ continue;
372
+ else
373
+ break;
374
+ }
375
+
376
+ error = send_want_with_caps(refs->contents[i], caps, fd);
377
+ if (error < GIT_SUCCESS)
378
+ return git__rethrow(error, "Failed to send want pkt with caps");
379
+ /* Increase it here so it's correct whether we run this or not */
380
+ i++;
381
+ }
382
+
383
+ /* Continue from where we left off */
384
+ for (; i < refs->length; ++i) {
385
+ head = refs->contents[i];
386
+ if (head->local)
387
+ continue;
388
+
389
+ git_oid_fmt(buf + strlen(pkt_want_prefix), &head->oid);
390
+ error = gitno_send(fd, buf, strlen(buf), 0);
391
+ if (error < GIT_SUCCESS)
392
+ return git__rethrow(error, "Failed to send want pkt");
393
+ }
394
+
395
+ return git_pkt_send_flush(fd);
396
+ }
397
+
398
+ int git_pkt_buffer_have(git_oid *oid, git_buf *buf)
399
+ {
400
+ char oidhex[GIT_OID_HEXSZ + 1];
401
+
402
+ memset(oidhex, 0x0, sizeof(oidhex));
403
+ git_oid_fmt(oidhex, oid);
404
+ git_buf_printf(buf, "%s%s\n", pkt_have_prefix, oidhex);
405
+ return git_buf_oom(buf) ? GIT_ENOMEM : GIT_SUCCESS;
406
+ }
407
+
408
+ int git_pkt_send_have(git_oid *oid, int fd)
409
+ {
410
+ char buf[] = "0032have 0000000000000000000000000000000000000000\n";
411
+
412
+ git_oid_fmt(buf + strlen(pkt_have_prefix), oid);
413
+ return gitno_send(fd, buf, strlen(buf), 0);
414
+ }
415
+
416
+
417
+ int git_pkt_buffer_done(git_buf *buf)
418
+ {
419
+ git_buf_puts(buf, pkt_done_str);
420
+ return git_buf_oom(buf) ? GIT_ENOMEM : GIT_SUCCESS;
421
+ }
422
+
423
+ int git_pkt_send_done(int fd)
424
+ {
425
+ return gitno_send(fd, pkt_done_str, strlen(pkt_done_str), 0);
426
+ }
@@ -0,0 +1,77 @@
1
+ /*
2
+ * Copyright (C) 2009-2011 the libgit2 contributors
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #ifndef INCLUDE_pkt_h__
9
+ #define INCLUDE_pkt_h__
10
+
11
+ #include "common.h"
12
+ #include "transport.h"
13
+ #include "buffer.h"
14
+ #include "git2/net.h"
15
+
16
+ enum git_pkt_type {
17
+ GIT_PKT_CMD,
18
+ GIT_PKT_FLUSH,
19
+ GIT_PKT_REF,
20
+ GIT_PKT_HAVE,
21
+ GIT_PKT_ACK,
22
+ GIT_PKT_NAK,
23
+ GIT_PKT_PACK,
24
+ GIT_PKT_COMMENT,
25
+ };
26
+
27
+ /* Used for multi-ack */
28
+ enum git_ack_status {
29
+ GIT_ACK_NONE,
30
+ GIT_ACK_CONTINUE,
31
+ GIT_ACK_COMMON,
32
+ GIT_ACK_READY
33
+ };
34
+
35
+ /* This would be a flush pkt */
36
+ typedef struct {
37
+ enum git_pkt_type type;
38
+ } git_pkt;
39
+
40
+ struct git_pkt_cmd {
41
+ enum git_pkt_type type;
42
+ char *cmd;
43
+ char *path;
44
+ char *host;
45
+ };
46
+
47
+ /* This is a pkt-line with some info in it */
48
+ typedef struct {
49
+ enum git_pkt_type type;
50
+ git_remote_head head;
51
+ char *capabilities;
52
+ } git_pkt_ref;
53
+
54
+ /* Useful later */
55
+ typedef struct {
56
+ enum git_pkt_type type;
57
+ git_oid oid;
58
+ enum git_ack_status status;
59
+ } git_pkt_ack;
60
+
61
+ typedef struct {
62
+ enum git_pkt_type type;
63
+ char comment[GIT_FLEX_ARRAY];
64
+ } git_pkt_comment;
65
+
66
+ int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t len);
67
+ int git_pkt_buffer_flush(git_buf *buf);
68
+ int git_pkt_send_flush(int s);
69
+ int git_pkt_buffer_done(git_buf *buf);
70
+ int git_pkt_send_done(int s);
71
+ int git_pkt_buffer_wants(const git_vector *refs, git_transport_caps *caps, git_buf *buf);
72
+ int git_pkt_send_wants(const git_vector *refs, git_transport_caps *caps, int fd);
73
+ int git_pkt_buffer_have(git_oid *oid, git_buf *buf);
74
+ int git_pkt_send_have(git_oid *oid, int fd);
75
+ void git_pkt_free(git_pkt *pkt);
76
+
77
+ #endif