rugged 0.16.0 → 0.17.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (392) hide show
  1. data/README.md +373 -243
  2. data/Rakefile +22 -0
  3. data/ext/rugged/extconf.rb +9 -6
  4. data/ext/rugged/rugged.c +123 -31
  5. data/ext/rugged/rugged.h +11 -10
  6. data/ext/rugged/rugged_blob.c +181 -18
  7. data/ext/rugged/rugged_commit.c +196 -18
  8. data/ext/rugged/rugged_config.c +94 -5
  9. data/ext/rugged/rugged_object.c +54 -1
  10. data/ext/rugged/rugged_reference.c +203 -15
  11. data/ext/rugged/{remote.c → rugged_remote.c} +35 -10
  12. data/ext/rugged/rugged_repo.c +323 -81
  13. data/ext/rugged/rugged_revwalk.c +57 -4
  14. data/ext/rugged/rugged_signature.c +3 -3
  15. data/ext/rugged/rugged_tag.c +72 -1
  16. data/ext/rugged/rugged_tree.c +70 -2
  17. data/ext/rugged/vendor/libgit2-dist/deps/regex/config.h +7 -0
  18. data/ext/rugged/vendor/libgit2-dist/deps/regex/regcomp.c +3856 -0
  19. data/ext/rugged/vendor/libgit2-dist/deps/regex/regex.c +85 -0
  20. data/ext/rugged/vendor/libgit2-dist/deps/regex/regex.h +582 -0
  21. data/ext/rugged/vendor/libgit2-dist/deps/regex/regex_internal.c +1744 -0
  22. data/ext/rugged/vendor/libgit2-dist/deps/regex/regex_internal.h +810 -0
  23. data/ext/rugged/vendor/libgit2-dist/deps/regex/regexec.c +4369 -0
  24. data/ext/rugged/vendor/libgit2-dist/examples/diff.c +238 -0
  25. data/ext/rugged/vendor/libgit2-dist/examples/general.c +4 -4
  26. data/ext/rugged/vendor/libgit2-dist/examples/network/fetch.c +101 -85
  27. data/ext/rugged/vendor/libgit2-dist/examples/network/git2.c +7 -3
  28. data/ext/rugged/vendor/libgit2-dist/examples/network/index-pack.c +80 -25
  29. data/ext/rugged/vendor/libgit2-dist/examples/network/ls-remote.c +6 -6
  30. data/ext/rugged/vendor/libgit2-dist/include/git2/attr.h +224 -0
  31. data/ext/rugged/vendor/libgit2-dist/include/git2/blob.h +59 -5
  32. data/ext/rugged/vendor/libgit2-dist/include/git2/branch.h +114 -7
  33. data/ext/rugged/vendor/libgit2-dist/include/git2/commit.h +14 -7
  34. data/ext/rugged/vendor/libgit2-dist/include/git2/common.h +4 -3
  35. data/ext/rugged/vendor/libgit2-dist/include/git2/config.h +105 -27
  36. data/ext/rugged/vendor/libgit2-dist/include/git2/diff.h +409 -0
  37. data/ext/rugged/vendor/libgit2-dist/include/git2/errors.h +47 -82
  38. data/ext/rugged/vendor/libgit2-dist/include/git2/index.h +25 -10
  39. data/ext/rugged/vendor/libgit2-dist/include/git2/indexer.h +46 -1
  40. data/ext/rugged/vendor/libgit2-dist/include/git2/merge.h +35 -0
  41. data/ext/rugged/vendor/libgit2-dist/include/git2/net.h +1 -1
  42. data/ext/rugged/vendor/libgit2-dist/include/git2/notes.h +139 -0
  43. data/ext/rugged/vendor/libgit2-dist/include/git2/object.h +5 -5
  44. data/ext/rugged/vendor/libgit2-dist/include/git2/odb.h +13 -13
  45. data/ext/rugged/vendor/libgit2-dist/include/git2/odb_backend.h +8 -8
  46. data/ext/rugged/vendor/libgit2-dist/include/git2/oid.h +14 -9
  47. data/ext/rugged/vendor/libgit2-dist/include/git2/reflog.h +5 -5
  48. data/ext/rugged/vendor/libgit2-dist/include/git2/refs.h +37 -17
  49. data/ext/rugged/vendor/libgit2-dist/include/git2/refspec.h +17 -9
  50. data/ext/rugged/vendor/libgit2-dist/include/git2/remote.h +83 -16
  51. data/ext/rugged/vendor/libgit2-dist/include/git2/repository.h +24 -10
  52. data/ext/rugged/vendor/libgit2-dist/include/git2/reset.h +44 -0
  53. data/ext/rugged/vendor/libgit2-dist/include/git2/revparse.h +36 -0
  54. data/ext/rugged/vendor/libgit2-dist/include/git2/revwalk.h +74 -6
  55. data/ext/rugged/vendor/libgit2-dist/include/git2/signature.h +3 -3
  56. data/ext/rugged/vendor/libgit2-dist/include/git2/status.h +120 -19
  57. data/ext/rugged/vendor/libgit2-dist/include/git2/submodule.h +103 -0
  58. data/ext/rugged/vendor/libgit2-dist/include/git2/tag.h +28 -10
  59. data/ext/rugged/vendor/libgit2-dist/include/git2/threads.h +1 -1
  60. data/ext/rugged/vendor/libgit2-dist/include/git2/tree.h +13 -13
  61. data/ext/rugged/vendor/libgit2-dist/include/git2/types.h +16 -2
  62. data/ext/rugged/vendor/libgit2-dist/include/git2/version.h +3 -3
  63. data/ext/rugged/vendor/libgit2-dist/include/git2/windows.h +1 -1
  64. data/ext/rugged/vendor/libgit2-dist/include/git2.h +7 -2
  65. data/ext/rugged/vendor/libgit2-dist/src/attr.c +677 -0
  66. data/ext/rugged/vendor/libgit2-dist/src/attr.h +56 -0
  67. data/ext/rugged/vendor/libgit2-dist/src/attr_file.c +609 -0
  68. data/ext/rugged/vendor/libgit2-dist/src/attr_file.h +145 -0
  69. data/ext/rugged/vendor/libgit2-dist/src/blob.c +213 -60
  70. data/ext/rugged/vendor/libgit2-dist/src/blob.h +2 -1
  71. data/ext/rugged/vendor/libgit2-dist/src/branch.c +208 -0
  72. data/ext/rugged/vendor/libgit2-dist/src/branch.h +17 -0
  73. data/ext/rugged/vendor/libgit2-dist/src/bswap.h +1 -1
  74. data/ext/rugged/vendor/libgit2-dist/src/buffer.c +395 -46
  75. data/ext/rugged/vendor/libgit2-dist/src/buffer.h +112 -9
  76. data/ext/rugged/vendor/libgit2-dist/src/cache.c +37 -49
  77. data/ext/rugged/vendor/libgit2-dist/src/cache.h +7 -17
  78. data/ext/rugged/vendor/libgit2-dist/src/cc-compat.h +18 -16
  79. data/ext/rugged/vendor/libgit2-dist/src/commit.c +56 -90
  80. data/ext/rugged/vendor/libgit2-dist/src/commit.h +1 -1
  81. data/ext/rugged/vendor/libgit2-dist/src/common.h +12 -5
  82. data/ext/rugged/vendor/libgit2-dist/src/{win32 → compat}/fnmatch.c +1 -1
  83. data/ext/rugged/vendor/libgit2-dist/src/{win32 → compat}/fnmatch.h +3 -3
  84. data/ext/rugged/vendor/libgit2-dist/src/config.c +247 -158
  85. data/ext/rugged/vendor/libgit2-dist/src/config.h +10 -1
  86. data/ext/rugged/vendor/libgit2-dist/src/config_cache.c +94 -0
  87. data/ext/rugged/vendor/libgit2-dist/src/config_file.c +606 -496
  88. data/ext/rugged/vendor/libgit2-dist/src/config_file.h +31 -0
  89. data/ext/rugged/vendor/libgit2-dist/src/crlf.c +228 -0
  90. data/ext/rugged/vendor/libgit2-dist/src/date.c +876 -0
  91. data/ext/rugged/vendor/libgit2-dist/src/delta-apply.c +15 -9
  92. data/ext/rugged/vendor/libgit2-dist/src/delta-apply.h +2 -2
  93. data/ext/rugged/vendor/libgit2-dist/src/diff.c +814 -0
  94. data/ext/rugged/vendor/libgit2-dist/src/diff.h +43 -0
  95. data/ext/rugged/vendor/libgit2-dist/src/diff_output.c +794 -0
  96. data/ext/rugged/vendor/libgit2-dist/src/errors.c +89 -74
  97. data/ext/rugged/vendor/libgit2-dist/src/fetch.c +94 -66
  98. data/ext/rugged/vendor/libgit2-dist/src/fetch.h +5 -4
  99. data/ext/rugged/vendor/libgit2-dist/src/filebuf.c +157 -100
  100. data/ext/rugged/vendor/libgit2-dist/src/filebuf.h +22 -8
  101. data/ext/rugged/vendor/libgit2-dist/src/fileops.c +330 -206
  102. data/ext/rugged/vendor/libgit2-dist/src/fileops.h +82 -51
  103. data/ext/rugged/vendor/libgit2-dist/src/filter.c +165 -0
  104. data/ext/rugged/vendor/libgit2-dist/src/filter.h +119 -0
  105. data/ext/rugged/vendor/libgit2-dist/src/global.c +4 -4
  106. data/ext/rugged/vendor/libgit2-dist/src/global.h +4 -1
  107. data/ext/rugged/vendor/libgit2-dist/src/hash.c +1 -1
  108. data/ext/rugged/vendor/libgit2-dist/src/hash.h +1 -1
  109. data/ext/rugged/vendor/libgit2-dist/src/ignore.c +203 -0
  110. data/ext/rugged/vendor/libgit2-dist/src/ignore.h +38 -0
  111. data/ext/rugged/vendor/libgit2-dist/src/index.c +220 -169
  112. data/ext/rugged/vendor/libgit2-dist/src/index.h +5 -1
  113. data/ext/rugged/vendor/libgit2-dist/src/indexer.c +601 -102
  114. data/ext/rugged/vendor/libgit2-dist/src/iterator.c +748 -0
  115. data/ext/rugged/vendor/libgit2-dist/src/iterator.h +151 -0
  116. data/ext/rugged/vendor/libgit2-dist/src/khash.h +608 -0
  117. data/ext/rugged/vendor/libgit2-dist/src/map.h +6 -1
  118. data/ext/rugged/vendor/libgit2-dist/src/message.c +61 -0
  119. data/ext/rugged/vendor/libgit2-dist/src/message.h +14 -0
  120. data/ext/rugged/vendor/libgit2-dist/src/mwindow.c +27 -29
  121. data/ext/rugged/vendor/libgit2-dist/src/mwindow.h +4 -4
  122. data/ext/rugged/vendor/libgit2-dist/src/netops.c +375 -56
  123. data/ext/rugged/vendor/libgit2-dist/src/netops.h +12 -9
  124. data/ext/rugged/vendor/libgit2-dist/src/notes.c +548 -0
  125. data/ext/rugged/vendor/libgit2-dist/src/notes.h +28 -0
  126. data/ext/rugged/vendor/libgit2-dist/src/object.c +59 -21
  127. data/ext/rugged/vendor/libgit2-dist/src/odb.c +212 -175
  128. data/ext/rugged/vendor/libgit2-dist/src/odb.h +39 -2
  129. data/ext/rugged/vendor/libgit2-dist/src/odb_loose.c +238 -241
  130. data/ext/rugged/vendor/libgit2-dist/src/odb_pack.c +94 -106
  131. data/ext/rugged/vendor/libgit2-dist/src/oid.c +59 -60
  132. data/ext/rugged/vendor/libgit2-dist/src/oidmap.h +42 -0
  133. data/ext/rugged/vendor/libgit2-dist/src/pack.c +198 -170
  134. data/ext/rugged/vendor/libgit2-dist/src/pack.h +16 -9
  135. data/ext/rugged/vendor/libgit2-dist/src/path.c +496 -106
  136. data/ext/rugged/vendor/libgit2-dist/src/path.h +214 -20
  137. data/ext/rugged/vendor/libgit2-dist/src/pkt.c +88 -159
  138. data/ext/rugged/vendor/libgit2-dist/src/pkt.h +9 -5
  139. data/ext/rugged/vendor/libgit2-dist/src/pool.c +294 -0
  140. data/ext/rugged/vendor/libgit2-dist/src/pool.h +125 -0
  141. data/ext/rugged/vendor/libgit2-dist/src/posix.c +38 -16
  142. data/ext/rugged/vendor/libgit2-dist/src/posix.h +20 -2
  143. data/ext/rugged/vendor/libgit2-dist/src/ppc/sha1.c +1 -1
  144. data/ext/rugged/vendor/libgit2-dist/src/ppc/sha1.h +1 -1
  145. data/ext/rugged/vendor/libgit2-dist/src/pqueue.c +7 -7
  146. data/ext/rugged/vendor/libgit2-dist/src/pqueue.h +1 -1
  147. data/ext/rugged/vendor/libgit2-dist/src/protocol.c +21 -13
  148. data/ext/rugged/vendor/libgit2-dist/src/protocol.h +1 -1
  149. data/ext/rugged/vendor/libgit2-dist/src/reflog.c +125 -103
  150. data/ext/rugged/vendor/libgit2-dist/src/reflog.h +1 -1
  151. data/ext/rugged/vendor/libgit2-dist/src/refs.c +713 -640
  152. data/ext/rugged/vendor/libgit2-dist/src/refs.h +27 -3
  153. data/ext/rugged/vendor/libgit2-dist/src/refspec.c +51 -17
  154. data/ext/rugged/vendor/libgit2-dist/src/refspec.h +13 -1
  155. data/ext/rugged/vendor/libgit2-dist/src/remote.c +307 -119
  156. data/ext/rugged/vendor/libgit2-dist/src/remote.h +3 -2
  157. data/ext/rugged/vendor/libgit2-dist/src/repository.c +593 -442
  158. data/ext/rugged/vendor/libgit2-dist/src/repository.h +80 -2
  159. data/ext/rugged/vendor/libgit2-dist/src/reset.c +103 -0
  160. data/ext/rugged/vendor/libgit2-dist/src/revparse.c +753 -0
  161. data/ext/rugged/vendor/libgit2-dist/src/revwalk.c +434 -158
  162. data/ext/rugged/vendor/libgit2-dist/src/sha1.c +3 -3
  163. data/ext/rugged/vendor/libgit2-dist/src/sha1.h +2 -2
  164. data/ext/rugged/vendor/libgit2-dist/src/sha1_lookup.c +3 -2
  165. data/ext/rugged/vendor/libgit2-dist/src/sha1_lookup.h +1 -1
  166. data/ext/rugged/vendor/libgit2-dist/src/signature.c +69 -80
  167. data/ext/rugged/vendor/libgit2-dist/src/signature.h +1 -1
  168. data/ext/rugged/vendor/libgit2-dist/src/status.c +184 -638
  169. data/ext/rugged/vendor/libgit2-dist/src/strmap.h +64 -0
  170. data/ext/rugged/vendor/libgit2-dist/src/submodule.c +387 -0
  171. data/ext/rugged/vendor/libgit2-dist/src/tag.c +162 -137
  172. data/ext/rugged/vendor/libgit2-dist/src/tag.h +2 -1
  173. data/ext/rugged/vendor/libgit2-dist/src/thread-utils.c +1 -1
  174. data/ext/rugged/vendor/libgit2-dist/src/thread-utils.h +8 -8
  175. data/ext/rugged/vendor/libgit2-dist/src/transport.c +31 -19
  176. data/ext/rugged/vendor/libgit2-dist/src/transport.h +31 -11
  177. data/ext/rugged/vendor/libgit2-dist/src/transports/git.c +168 -193
  178. data/ext/rugged/vendor/libgit2-dist/src/transports/http.c +192 -241
  179. data/ext/rugged/vendor/libgit2-dist/src/transports/local.c +92 -86
  180. data/ext/rugged/vendor/libgit2-dist/src/tree-cache.c +32 -49
  181. data/ext/rugged/vendor/libgit2-dist/src/tree-cache.h +1 -1
  182. data/ext/rugged/vendor/libgit2-dist/src/tree.c +172 -145
  183. data/ext/rugged/vendor/libgit2-dist/src/tree.h +16 -2
  184. data/ext/rugged/vendor/libgit2-dist/src/tsort.c +16 -14
  185. data/ext/rugged/vendor/libgit2-dist/src/unix/map.c +8 -24
  186. data/ext/rugged/vendor/libgit2-dist/src/unix/posix.h +9 -3
  187. data/ext/rugged/vendor/libgit2-dist/src/util.c +94 -38
  188. data/ext/rugged/vendor/libgit2-dist/src/util.h +119 -13
  189. data/ext/rugged/vendor/libgit2-dist/src/vector.c +84 -31
  190. data/ext/rugged/vendor/libgit2-dist/src/vector.h +37 -4
  191. data/ext/rugged/vendor/libgit2-dist/src/win32/dir.c +81 -41
  192. data/ext/rugged/vendor/libgit2-dist/src/{dir.h → win32/dir.h} +4 -9
  193. data/ext/rugged/vendor/libgit2-dist/src/win32/map.c +19 -35
  194. data/ext/rugged/vendor/libgit2-dist/src/win32/mingw-compat.h +1 -1
  195. data/ext/rugged/vendor/libgit2-dist/src/win32/msvc-compat.h +5 -1
  196. data/ext/rugged/vendor/libgit2-dist/src/win32/posix.h +10 -8
  197. data/ext/rugged/vendor/libgit2-dist/src/win32/posix_w32.c +262 -118
  198. data/ext/rugged/vendor/libgit2-dist/src/win32/pthread.c +12 -9
  199. data/ext/rugged/vendor/libgit2-dist/src/win32/pthread.h +1 -1
  200. data/ext/rugged/vendor/libgit2-dist/src/win32/utf-conv.c +30 -26
  201. data/ext/rugged/vendor/libgit2-dist/src/win32/utf-conv.h +2 -1
  202. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xdiff.h +135 -0
  203. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xdiffi.c +572 -0
  204. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xdiffi.h +63 -0
  205. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xemit.c +253 -0
  206. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xemit.h +36 -0
  207. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xhistogram.c +371 -0
  208. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xinclude.h +46 -0
  209. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xmacros.h +54 -0
  210. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xmerge.c +619 -0
  211. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xpatience.c +358 -0
  212. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xprepare.c +483 -0
  213. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xprepare.h +34 -0
  214. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xtypes.h +67 -0
  215. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xutils.c +419 -0
  216. data/ext/rugged/vendor/libgit2-dist/src/xdiff/xutils.h +49 -0
  217. data/ext/rugged/vendor/libgit2-dist/tests-clar/attr/attr_expect.h +43 -0
  218. data/ext/rugged/vendor/libgit2-dist/tests-clar/attr/file.c +226 -0
  219. data/ext/rugged/vendor/libgit2-dist/tests-clar/attr/flags.c +108 -0
  220. data/ext/rugged/vendor/libgit2-dist/tests-clar/attr/lookup.c +262 -0
  221. data/ext/rugged/vendor/libgit2-dist/tests-clar/attr/repo.c +273 -0
  222. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/buf/basic.c +5 -5
  223. data/ext/rugged/vendor/libgit2-dist/tests-clar/clar_helpers.c +181 -0
  224. data/ext/rugged/vendor/libgit2-dist/tests-clar/clar_libgit2.h +55 -0
  225. data/ext/rugged/vendor/libgit2-dist/tests-clar/commit/commit.c +44 -0
  226. data/ext/rugged/vendor/libgit2-dist/tests-clar/commit/parse.c +350 -0
  227. data/ext/rugged/vendor/libgit2-dist/tests-clar/commit/signature.c +65 -0
  228. data/ext/rugged/vendor/libgit2-dist/tests-clar/commit/write.c +140 -0
  229. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/config/add.c +3 -3
  230. data/ext/rugged/vendor/libgit2-dist/tests-clar/config/multivar.c +151 -0
  231. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/config/new.c +5 -5
  232. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/config/read.c +44 -32
  233. data/ext/rugged/vendor/libgit2-dist/tests-clar/config/stress.c +61 -0
  234. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/config/write.c +20 -5
  235. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/buffer.c +613 -0
  236. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/core/dirent.c +39 -26
  237. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/env.c +115 -0
  238. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/errors.c +60 -0
  239. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/core/filebuf.c +4 -18
  240. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/hex.c +22 -0
  241. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/core/oid.c +6 -6
  242. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/path.c +420 -0
  243. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/pool.c +85 -0
  244. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/rmdir.c +68 -0
  245. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/core/string.c +1 -1
  246. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/strmap.c +102 -0
  247. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/core/strtol.c +1 -1
  248. data/ext/rugged/vendor/libgit2-dist/tests-clar/core/vector.c +191 -0
  249. data/ext/rugged/vendor/libgit2-dist/tests-clar/date/date.c +15 -0
  250. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/blob.c +254 -0
  251. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/diff_helpers.c +104 -0
  252. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/diff_helpers.h +47 -0
  253. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/index.c +92 -0
  254. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/iterator.c +572 -0
  255. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/patch.c +99 -0
  256. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/tree.c +210 -0
  257. data/ext/rugged/vendor/libgit2-dist/tests-clar/diff/workdir.c +543 -0
  258. data/ext/rugged/vendor/libgit2-dist/tests-clar/index/read_tree.c +46 -0
  259. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/index/rename.c +2 -12
  260. data/ext/rugged/vendor/libgit2-dist/tests-clar/index/tests.c +246 -0
  261. data/ext/rugged/vendor/libgit2-dist/tests-clar/network/createremotethenload.c +33 -0
  262. data/ext/rugged/vendor/libgit2-dist/tests-clar/network/remotelocal.c +137 -0
  263. data/ext/rugged/vendor/libgit2-dist/tests-clar/network/remotes.c +183 -0
  264. data/ext/rugged/vendor/libgit2-dist/tests-clar/notes/notes.c +133 -0
  265. data/ext/rugged/vendor/libgit2-dist/tests-clar/notes/notesref.c +57 -0
  266. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/blob/filter.c +125 -0
  267. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/blob/fromchunks.c +87 -0
  268. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/blob/write.c +69 -0
  269. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/commit/commitstagedfile.c +126 -0
  270. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/lookup.c +63 -0
  271. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/message.c +171 -0
  272. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/chars.c +3 -14
  273. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/compare.c +4 -4
  274. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/convert.c +10 -10
  275. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/data.h +0 -0
  276. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/fromstr.c +1 -1
  277. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/hash.c +21 -17
  278. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/short.c +1 -1
  279. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/size.c +1 -1
  280. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/raw/type2string.c +14 -14
  281. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/raw/write.c +455 -0
  282. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/tag/peel.c +56 -0
  283. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/tag/read.c +130 -0
  284. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/tag/write.c +192 -0
  285. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/object/tree/frompath.c +22 -16
  286. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/tree/read.c +75 -0
  287. data/ext/rugged/vendor/libgit2-dist/tests-clar/object/tree/write.c +84 -0
  288. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/odb/loose.c +1 -1
  289. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/odb/loose_data.h +0 -0
  290. data/ext/rugged/vendor/libgit2-dist/tests-clar/odb/mixed.c +24 -0
  291. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/odb/pack_data.h +0 -0
  292. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/odb/packed.c +1 -1
  293. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/odb/sorting.c +1 -1
  294. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/branches/create.c +113 -0
  295. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/branches/delete.c +91 -0
  296. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/branches/listall.c +78 -0
  297. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/branches/move.c +72 -0
  298. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/crashes.c +17 -0
  299. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/create.c +149 -0
  300. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/delete.c +85 -0
  301. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/list.c +53 -0
  302. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/listall.c +36 -0
  303. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/lookup.c +42 -0
  304. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/normalize.c +200 -0
  305. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/overwrite.c +136 -0
  306. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/pack.c +67 -0
  307. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/read.c +194 -0
  308. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/reflog.c +123 -0
  309. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/rename.c +339 -0
  310. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/revparse.c +174 -0
  311. data/ext/rugged/vendor/libgit2-dist/tests-clar/refs/unicode.c +42 -0
  312. data/ext/rugged/vendor/libgit2-dist/tests-clar/repo/discover.c +142 -0
  313. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/repo/getters.c +19 -1
  314. data/ext/rugged/vendor/libgit2-dist/tests-clar/repo/init.c +235 -0
  315. data/ext/rugged/vendor/libgit2-dist/tests-clar/repo/open.c +282 -0
  316. data/ext/rugged/vendor/libgit2-dist/tests-clar/repo/setters.c +80 -0
  317. data/ext/rugged/vendor/libgit2-dist/tests-clar/reset/mixed.c +47 -0
  318. data/ext/rugged/vendor/libgit2-dist/tests-clar/reset/reset_helpers.c +10 -0
  319. data/ext/rugged/vendor/libgit2-dist/tests-clar/reset/reset_helpers.h +6 -0
  320. data/ext/rugged/vendor/libgit2-dist/tests-clar/reset/soft.c +102 -0
  321. data/ext/rugged/vendor/libgit2-dist/{tests/t05-revwalk.c → tests-clar/revwalk/basic.c} +85 -44
  322. data/ext/rugged/vendor/libgit2-dist/tests-clar/revwalk/mergebase.c +148 -0
  323. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/ignore.c +133 -0
  324. data/ext/rugged/vendor/libgit2-dist/{tests-clay → tests-clar}/status/single.c +2 -11
  325. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/status_data.h +202 -0
  326. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/status_helpers.c +49 -0
  327. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/status_helpers.h +33 -0
  328. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/submodules.c +112 -0
  329. data/ext/rugged/vendor/libgit2-dist/tests-clar/status/worktree.c +649 -0
  330. data/ext/rugged/vendor/libgit2-dist/tests-clar/threads/basic.c +20 -0
  331. data/ext/rugged/vendor/libgit2-dist.tar.gz +0 -0
  332. data/lib/rugged/commit.rb +35 -0
  333. data/lib/rugged/object.rb +7 -0
  334. data/lib/rugged/reference.rb +9 -0
  335. data/lib/rugged/repository.rb +99 -3
  336. data/lib/rugged/tag.rb +22 -0
  337. data/lib/rugged/tree.rb +8 -0
  338. data/lib/rugged/version.rb +1 -1
  339. data/lib/rugged.rb +4 -1
  340. data/test/blob_test.rb +2 -2
  341. data/test/commit_test.rb +27 -13
  342. data/test/config_test.rb +44 -0
  343. data/test/coverage/HEAD.json +1 -1
  344. data/test/fixtures/testrepo.git/config +2 -0
  345. data/test/fixtures/testrepo.git/objects/7f/043268ea43ce18e3540acaabf9e090c91965b0 +0 -0
  346. data/test/lib_test.rb +7 -0
  347. data/test/object_test.rb +3 -3
  348. data/test/reference_test.rb +46 -8
  349. data/test/remote_test.rb +8 -2
  350. data/test/repo_pack_test.rb +3 -3
  351. data/test/repo_test.rb +79 -11
  352. data/test/tag_test.rb +9 -2
  353. data/test/test_helper.rb +21 -0
  354. data/test/tree_test.rb +18 -6
  355. metadata +205 -81
  356. data/ext/rugged/vendor/libgit2-dist/include/git2/zlib.h +0 -40
  357. data/ext/rugged/vendor/libgit2-dist/src/hashtable.c +0 -243
  358. data/ext/rugged/vendor/libgit2-dist/src/hashtable.h +0 -80
  359. data/ext/rugged/vendor/libgit2-dist/tests/t00-core.c +0 -628
  360. data/ext/rugged/vendor/libgit2-dist/tests/t01-data.h +0 -322
  361. data/ext/rugged/vendor/libgit2-dist/tests/t01-rawobj.c +0 -638
  362. data/ext/rugged/vendor/libgit2-dist/tests/t03-data.h +0 -344
  363. data/ext/rugged/vendor/libgit2-dist/tests/t03-objwrite.c +0 -255
  364. data/ext/rugged/vendor/libgit2-dist/tests/t04-commit.c +0 -788
  365. data/ext/rugged/vendor/libgit2-dist/tests/t06-index.c +0 -219
  366. data/ext/rugged/vendor/libgit2-dist/tests/t07-hashtable.c +0 -192
  367. data/ext/rugged/vendor/libgit2-dist/tests/t08-tag.c +0 -357
  368. data/ext/rugged/vendor/libgit2-dist/tests/t09-tree.c +0 -221
  369. data/ext/rugged/vendor/libgit2-dist/tests/t10-refs.c +0 -1294
  370. data/ext/rugged/vendor/libgit2-dist/tests/t12-repo.c +0 -174
  371. data/ext/rugged/vendor/libgit2-dist/tests/t13-threads.c +0 -41
  372. data/ext/rugged/vendor/libgit2-dist/tests/t17-bufs.c +0 -61
  373. data/ext/rugged/vendor/libgit2-dist/tests/t18-status.c +0 -448
  374. data/ext/rugged/vendor/libgit2-dist/tests/test_helpers.c +0 -310
  375. data/ext/rugged/vendor/libgit2-dist/tests/test_helpers.h +0 -83
  376. data/ext/rugged/vendor/libgit2-dist/tests/test_lib.c +0 -198
  377. data/ext/rugged/vendor/libgit2-dist/tests/test_lib.h +0 -54
  378. data/ext/rugged/vendor/libgit2-dist/tests/test_main.c +0 -89
  379. data/ext/rugged/vendor/libgit2-dist/tests-clay/clay.h +0 -187
  380. data/ext/rugged/vendor/libgit2-dist/tests-clay/clay_libgit2.h +0 -28
  381. data/ext/rugged/vendor/libgit2-dist/tests-clay/clay_main.c +0 -1073
  382. data/ext/rugged/vendor/libgit2-dist/tests-clay/config/stress.c +0 -39
  383. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/path.c +0 -139
  384. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/rmdir.c +0 -50
  385. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/vector.c +0 -66
  386. data/ext/rugged/vendor/libgit2-dist/tests-clay/network/remotes.c +0 -50
  387. data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/init.c +0 -104
  388. data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/open.c +0 -54
  389. data/ext/rugged/vendor/libgit2-dist/tests-clay/status/status_data.h +0 -48
  390. data/ext/rugged/vendor/libgit2-dist/tests-clay/status/worktree.c +0 -124
  391. data/lib/rugged/objects.rb +0 -45
  392. data/test/fixtures/testrepo.git/refs/heads/new_name +0 -1
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (C) 2009-2011 the libgit2 contributors
2
+ * Copyright (C) 2009-2012 the libgit2 contributors
3
3
  *
4
4
  * This file is part of libgit2, distributed under the GNU GPL v2 with
5
5
  * a Linking Exception. For full terms see the included COPYING file.
@@ -14,15 +14,15 @@
14
14
  #include "fileops.h"
15
15
 
16
16
  #include "git2/oid.h"
17
- #include "git2/zlib.h"
17
+ #include <zlib.h>
18
18
 
19
19
  static int packfile_open(struct git_pack_file *p);
20
- static off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n);
20
+ static git_off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n);
21
21
  int packfile_unpack_compressed(
22
22
  git_rawobj *obj,
23
23
  struct git_pack_file *p,
24
24
  git_mwindow **w_curs,
25
- off_t *curpos,
25
+ git_off_t *curpos,
26
26
  size_t size,
27
27
  git_otype type);
28
28
 
@@ -34,12 +34,18 @@ int packfile_unpack_compressed(
34
34
  * GIT_OID_MINPREFIXLEN and GIT_OID_HEXSZ.
35
35
  */
36
36
  static int pack_entry_find_offset(
37
- off_t *offset_out,
37
+ git_off_t *offset_out,
38
38
  git_oid *found_oid,
39
39
  struct git_pack_file *p,
40
40
  const git_oid *short_oid,
41
41
  unsigned int len);
42
42
 
43
+ static int packfile_error(const char *message)
44
+ {
45
+ giterr_set(GITERR_ODB, "Invalid pack file - %s", message);
46
+ return -1;
47
+ }
48
+
43
49
  /***********************************************************
44
50
  *
45
51
  * PACK INDEX METHODS
@@ -58,40 +64,31 @@ static int pack_index_check(const char *path, struct git_pack_file *p)
58
64
  {
59
65
  struct git_pack_idx_header *hdr;
60
66
  uint32_t version, nr, i, *index;
61
-
62
67
  void *idx_map;
63
68
  size_t idx_size;
64
-
65
69
  struct stat st;
66
-
67
- /* TODO: properly open the file without access time */
68
- git_file fd = p_open(path, O_RDONLY /*| O_NOATIME */);
69
-
70
70
  int error;
71
-
71
+ /* TODO: properly open the file without access time using O_NOATIME */
72
+ git_file fd = git_futils_open_ro(path);
72
73
  if (fd < 0)
73
- return git__throw(GIT_EOSERR, "Failed to check index. File missing or corrupted");
74
+ return fd;
74
75
 
75
- if (p_fstat(fd, &st) < GIT_SUCCESS) {
76
+ if (p_fstat(fd, &st) < 0 ||
77
+ !S_ISREG(st.st_mode) ||
78
+ !git__is_sizet(st.st_size) ||
79
+ (idx_size = (size_t)st.st_size) < 4 * 256 + 20 + 20)
80
+ {
76
81
  p_close(fd);
77
- return git__throw(GIT_EOSERR, "Failed to check index. File appears to be corrupted");
78
- }
79
-
80
- if (!git__is_sizet(st.st_size))
81
- return GIT_ENOMEM;
82
-
83
- idx_size = (size_t)st.st_size;
84
-
85
- if (idx_size < 4 * 256 + 20 + 20) {
86
- p_close(fd);
87
- return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Object is corrupted");
82
+ giterr_set(GITERR_OS, "Failed to check pack index.");
83
+ return -1;
88
84
  }
89
85
 
90
86
  error = git_futils_mmap_ro(&p->index_map, fd, 0, idx_size);
87
+
91
88
  p_close(fd);
92
89
 
93
- if (error < GIT_SUCCESS)
94
- return git__rethrow(error, "Failed to check index");
90
+ if (error < 0)
91
+ return error;
95
92
 
96
93
  hdr = idx_map = p->index_map.data;
97
94
 
@@ -100,7 +97,7 @@ static int pack_index_check(const char *path, struct git_pack_file *p)
100
97
 
101
98
  if (version < 2 || version > 2) {
102
99
  git_futils_mmap_free(&p->index_map);
103
- return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Unsupported index version");
100
+ return packfile_error("unsupported index version");
104
101
  }
105
102
 
106
103
  } else
@@ -116,7 +113,7 @@ static int pack_index_check(const char *path, struct git_pack_file *p)
116
113
  uint32_t n = ntohl(index[i]);
117
114
  if (n < nr) {
118
115
  git_futils_mmap_free(&p->index_map);
119
- return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Index is non-monotonic");
116
+ return packfile_error("index is non-monotonic");
120
117
  }
121
118
  nr = n;
122
119
  }
@@ -131,7 +128,7 @@ static int pack_index_check(const char *path, struct git_pack_file *p)
131
128
  */
132
129
  if (idx_size != 4*256 + nr * 24 + 20 + 20) {
133
130
  git_futils_mmap_free(&p->index_map);
134
- return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Object is corrupted");
131
+ return packfile_error("index is corrupted");
135
132
  }
136
133
  } else if (version == 2) {
137
134
  /*
@@ -155,46 +152,46 @@ static int pack_index_check(const char *path, struct git_pack_file *p)
155
152
 
156
153
  if (idx_size < min_size || idx_size > max_size) {
157
154
  git_futils_mmap_free(&p->index_map);
158
- return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Wrong index size");
159
- }
160
-
161
- /* Make sure that off_t is big enough to access the whole pack...
162
- * Is this an issue in libgit2? It shouldn't. */
163
- if (idx_size != min_size && (sizeof(off_t) <= 4)) {
164
- git_futils_mmap_free(&p->index_map);
165
- return git__throw(GIT_EOSERR, "Failed to check index. off_t not big enough to access the whole pack");
155
+ return packfile_error("wrong index size");
166
156
  }
167
157
  }
168
158
 
169
159
  p->index_version = version;
170
160
  p->num_objects = nr;
171
- return GIT_SUCCESS;
161
+ return 0;
172
162
  }
173
163
 
174
164
  static int pack_index_open(struct git_pack_file *p)
175
165
  {
176
166
  char *idx_name;
177
167
  int error;
168
+ size_t name_len, offset;
178
169
 
179
170
  if (p->index_map.data)
180
- return GIT_SUCCESS;
171
+ return 0;
181
172
 
182
173
  idx_name = git__strdup(p->pack_name);
183
- strcpy(idx_name + strlen(idx_name) - strlen(".pack"), ".idx");
174
+ GITERR_CHECK_ALLOC(idx_name);
175
+
176
+ name_len = strlen(idx_name);
177
+ offset = name_len - strlen(".pack");
178
+ assert(offset < name_len); /* make sure no underflow */
179
+
180
+ strncpy(idx_name + offset, ".idx", name_len - offset);
184
181
 
185
182
  error = pack_index_check(idx_name, p);
186
183
  git__free(idx_name);
187
184
 
188
- return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to open index");
185
+ return error;
189
186
  }
190
187
 
191
188
  static unsigned char *pack_window_open(
192
189
  struct git_pack_file *p,
193
190
  git_mwindow **w_cursor,
194
- off_t offset,
191
+ git_off_t offset,
195
192
  unsigned int *left)
196
193
  {
197
- if (p->mwf.fd == -1 && packfile_open(p) < GIT_SUCCESS)
194
+ if (p->mwf.fd == -1 && packfile_open(p) < 0)
198
195
  return NULL;
199
196
 
200
197
  /* Since packfiles end in a hash of their content and it's
@@ -208,7 +205,8 @@ static unsigned char *pack_window_open(
208
205
  return git_mwindow_open(&p->mwf, w_cursor, offset, 20, left);
209
206
  }
210
207
 
211
- static unsigned long packfile_unpack_header1(
208
+ static int packfile_unpack_header1(
209
+ unsigned long *usedp,
212
210
  size_t *sizep,
213
211
  git_otype *type,
214
212
  const unsigned char *buf,
@@ -223,8 +221,13 @@ static unsigned long packfile_unpack_header1(
223
221
  size = c & 15;
224
222
  shift = 4;
225
223
  while (c & 0x80) {
226
- if (len <= used || bitsizeof(long) <= shift)
227
- return 0;
224
+ if (len <= used)
225
+ return GIT_EBUFS;
226
+
227
+ if (bitsizeof(long) <= shift) {
228
+ *usedp = 0;
229
+ return -1;
230
+ }
228
231
 
229
232
  c = buf[used++];
230
233
  size += (c & 0x7f) << shift;
@@ -232,7 +235,8 @@ static unsigned long packfile_unpack_header1(
232
235
  }
233
236
 
234
237
  *sizep = (size_t)size;
235
- return used;
238
+ *usedp = used;
239
+ return 0;
236
240
  }
237
241
 
238
242
  int git_packfile_unpack_header(
@@ -240,11 +244,12 @@ int git_packfile_unpack_header(
240
244
  git_otype *type_p,
241
245
  git_mwindow_file *mwf,
242
246
  git_mwindow **w_curs,
243
- off_t *curpos)
247
+ git_off_t *curpos)
244
248
  {
245
249
  unsigned char *base;
246
250
  unsigned int left;
247
251
  unsigned long used;
252
+ int ret;
248
253
 
249
254
  /* pack_window_open() assures us we have [base, base + 20) available
250
255
  * as a range that we can look at at. (Its actually the hash
@@ -255,37 +260,39 @@ int git_packfile_unpack_header(
255
260
  // base = pack_window_open(p, w_curs, *curpos, &left);
256
261
  base = git_mwindow_open(mwf, w_curs, *curpos, 20, &left);
257
262
  if (base == NULL)
258
- return GIT_ENOMEM;
263
+ return GIT_EBUFS;
259
264
 
260
- used = packfile_unpack_header1(size_p, type_p, base, left);
261
-
262
- if (used == 0)
263
- return git__throw(GIT_EOBJCORRUPTED, "Header length is zero");
265
+ ret = packfile_unpack_header1(&used, size_p, type_p, base, left);
266
+ git_mwindow_close(w_curs);
267
+ if (ret == GIT_EBUFS)
268
+ return ret;
269
+ else if (ret < 0)
270
+ return packfile_error("header length is zero");
264
271
 
265
272
  *curpos += used;
266
- return GIT_SUCCESS;
273
+ return 0;
267
274
  }
268
275
 
269
276
  static int packfile_unpack_delta(
270
277
  git_rawobj *obj,
271
278
  struct git_pack_file *p,
272
279
  git_mwindow **w_curs,
273
- off_t *curpos,
280
+ git_off_t *curpos,
274
281
  size_t delta_size,
275
282
  git_otype delta_type,
276
- off_t obj_offset)
283
+ git_off_t obj_offset)
277
284
  {
278
- off_t base_offset;
285
+ git_off_t base_offset;
279
286
  git_rawobj base, delta;
280
287
  int error;
281
288
 
282
289
  base_offset = get_delta_base(p, w_curs, curpos, delta_type, obj_offset);
290
+ git_mwindow_close(w_curs);
283
291
  if (base_offset == 0)
284
- return git__throw(GIT_EOBJCORRUPTED, "Delta offset is zero");
285
- if (base_offset < 0)
286
- return git__rethrow(base_offset, "Failed to get delta base");
292
+ return packfile_error("delta offset is zero");
293
+ if (base_offset < 0) /* must actually be an error code */
294
+ return (int)base_offset;
287
295
 
288
- git_mwindow_close(w_curs);
289
296
  error = git_packfile_unpack(&base, p, &base_offset);
290
297
 
291
298
  /*
@@ -294,35 +301,35 @@ static int packfile_unpack_delta(
294
301
  *
295
302
  * We'll need to do this in order to support thin packs.
296
303
  */
297
- if (error < GIT_SUCCESS)
298
- return git__rethrow(error, "Corrupted delta");
304
+ if (error < 0)
305
+ return error;
299
306
 
300
307
  error = packfile_unpack_compressed(&delta, p, w_curs, curpos, delta_size, delta_type);
301
- if (error < GIT_SUCCESS) {
308
+ git_mwindow_close(w_curs);
309
+ if (error < 0) {
302
310
  git__free(base.data);
303
- return git__rethrow(error, "Corrupted delta");
311
+ return error;
304
312
  }
305
313
 
306
314
  obj->type = base.type;
307
- error = git__delta_apply(obj,
308
- base.data, base.len,
309
- delta.data, delta.len);
315
+ error = git__delta_apply(obj, base.data, base.len, delta.data, delta.len);
310
316
 
311
317
  git__free(base.data);
312
318
  git__free(delta.data);
313
319
 
314
320
  /* TODO: we might want to cache this shit. eventually */
315
321
  //add_delta_base_cache(p, base_offset, base, base_size, *type);
322
+
316
323
  return error; /* error set by git__delta_apply */
317
324
  }
318
325
 
319
326
  int git_packfile_unpack(
320
- git_rawobj *obj,
321
- struct git_pack_file *p,
322
- off_t *obj_offset)
327
+ git_rawobj *obj,
328
+ struct git_pack_file *p,
329
+ git_off_t *obj_offset)
323
330
  {
324
331
  git_mwindow *w_curs = NULL;
325
- off_t curpos = *obj_offset;
332
+ git_off_t curpos = *obj_offset;
326
333
  int error;
327
334
 
328
335
  size_t size = 0;
@@ -337,8 +344,10 @@ int git_packfile_unpack(
337
344
  obj->type = GIT_OBJ_BAD;
338
345
 
339
346
  error = git_packfile_unpack_header(&size, &type, &p->mwf, &w_curs, &curpos);
340
- if (error < GIT_SUCCESS)
341
- return git__rethrow(error, "Failed to unpack packfile");
347
+ git_mwindow_close(&w_curs);
348
+
349
+ if (error < 0)
350
+ return error;
342
351
 
343
352
  switch (type) {
344
353
  case GIT_OBJ_OFS_DELTA:
@@ -358,52 +367,70 @@ int git_packfile_unpack(
358
367
  break;
359
368
 
360
369
  default:
361
- error = GIT_EOBJCORRUPTED;
370
+ error = packfile_error("invalid packfile type in header");;
362
371
  break;
363
372
  }
364
373
 
365
- git_mwindow_close(&w_curs);
374
+ *obj_offset = curpos;
375
+ return error;
376
+ }
366
377
 
367
- if (error < GIT_SUCCESS)
368
- return git__rethrow(error, "Failed to unpack object");
378
+ static void *use_git_alloc(void *opaq, unsigned int count, unsigned int size)
379
+ {
380
+ GIT_UNUSED(opaq);
381
+ return git__calloc(count, size);
382
+ }
369
383
 
370
- *obj_offset = curpos;
371
- return GIT_SUCCESS;
384
+ static void use_git_free(void *opaq, void *ptr)
385
+ {
386
+ GIT_UNUSED(opaq);
387
+ git__free(ptr);
372
388
  }
373
389
 
374
390
  int packfile_unpack_compressed(
375
- git_rawobj *obj,
376
- struct git_pack_file *p,
377
- git_mwindow **w_curs,
378
- off_t *curpos,
379
- size_t size,
380
- git_otype type)
391
+ git_rawobj *obj,
392
+ struct git_pack_file *p,
393
+ git_mwindow **w_curs,
394
+ git_off_t *curpos,
395
+ size_t size,
396
+ git_otype type)
381
397
  {
382
398
  int st;
383
399
  z_stream stream;
384
400
  unsigned char *buffer, *in;
385
401
 
386
- buffer = git__malloc(size + 1);
387
- memset(buffer, 0x0, size + 1);
402
+ buffer = git__calloc(1, size + 1);
403
+ GITERR_CHECK_ALLOC(buffer);
388
404
 
389
405
  memset(&stream, 0, sizeof(stream));
390
406
  stream.next_out = buffer;
391
407
  stream.avail_out = (uInt)size + 1;
408
+ stream.zalloc = use_git_alloc;
409
+ stream.zfree = use_git_free;
392
410
 
393
411
  st = inflateInit(&stream);
394
412
  if (st != Z_OK) {
395
413
  git__free(buffer);
396
- return git__throw(GIT_EZLIB, "Error in zlib");
414
+ giterr_set(GITERR_ZLIB, "Failed to inflate packfile");
415
+
416
+ return -1;
397
417
  }
398
418
 
399
419
  do {
400
420
  in = pack_window_open(p, w_curs, *curpos, &stream.avail_in);
401
421
  stream.next_in = in;
402
422
  st = inflate(&stream, Z_FINISH);
423
+ git_mwindow_close(w_curs);
403
424
 
404
425
  if (!stream.avail_out)
405
426
  break; /* the payload is larger than it should be */
406
427
 
428
+ if (st == Z_BUF_ERROR && in == NULL) {
429
+ inflateEnd(&stream);
430
+ git__free(buffer);
431
+ return GIT_EBUFS;
432
+ }
433
+
407
434
  *curpos += stream.next_in - in;
408
435
  } while (st == Z_OK || st == Z_BUF_ERROR);
409
436
 
@@ -411,30 +438,36 @@ int packfile_unpack_compressed(
411
438
 
412
439
  if ((st != Z_STREAM_END) || stream.total_out != size) {
413
440
  git__free(buffer);
414
- return git__throw(GIT_EZLIB, "Error in zlib");
441
+ giterr_set(GITERR_ZLIB, "Failed to inflate packfile");
442
+ return -1;
415
443
  }
416
444
 
417
445
  obj->type = type;
418
446
  obj->len = size;
419
447
  obj->data = buffer;
420
- return GIT_SUCCESS;
448
+ return 0;
421
449
  }
422
450
 
423
451
  /*
424
452
  * curpos is where the data starts, delta_obj_offset is the where the
425
453
  * header starts
426
454
  */
427
- off_t get_delta_base(
428
- struct git_pack_file *p,
429
- git_mwindow **w_curs,
430
- off_t *curpos,
431
- git_otype type,
432
- off_t delta_obj_offset)
455
+ git_off_t get_delta_base(
456
+ struct git_pack_file *p,
457
+ git_mwindow **w_curs,
458
+ git_off_t *curpos,
459
+ git_otype type,
460
+ git_off_t delta_obj_offset)
433
461
  {
434
- unsigned char *base_info = pack_window_open(p, w_curs, *curpos, NULL);
435
- off_t base_offset;
462
+ unsigned int left = 0;
463
+ unsigned char *base_info;
464
+ git_off_t base_offset;
436
465
  git_oid unused;
437
466
 
467
+ base_info = pack_window_open(p, w_curs, *curpos, &left);
468
+ /* Assumption: the only reason this would fail is because the file is too small */
469
+ if (base_info == NULL)
470
+ return GIT_EBUFS;
438
471
  /* pack_window_open() assured us we have [base_info, base_info + 20)
439
472
  * as a range that we can look at without walking off the
440
473
  * end of the mapped window. Its actually the hash size
@@ -446,6 +479,8 @@ off_t get_delta_base(
446
479
  unsigned char c = base_info[used++];
447
480
  base_offset = c & 127;
448
481
  while (c & 128) {
482
+ if (left <= used)
483
+ return GIT_EBUFS;
449
484
  base_offset += 1;
450
485
  if (!base_offset || MSB(base_offset, 7))
451
486
  return 0; /* overflow */
@@ -470,8 +505,8 @@ off_t get_delta_base(
470
505
  }
471
506
  }
472
507
  /* The base entry _must_ be in the same pack */
473
- if (pack_entry_find_offset(&base_offset, &unused, p, (git_oid *)base_info, GIT_OID_HEXSZ) < GIT_SUCCESS)
474
- return git__rethrow(GIT_EPACKCORRUPTED, "Base entry delta is not in the same pack");
508
+ if (pack_entry_find_offset(&base_offset, &unused, p, (git_oid *)base_info, GIT_OID_HEXSZ) < 0)
509
+ return packfile_error("base entry delta is not in the same pack");
475
510
  *curpos += 20;
476
511
  } else
477
512
  return 0;
@@ -485,11 +520,11 @@ off_t get_delta_base(
485
520
  *
486
521
  ***********************************************************/
487
522
 
488
- static struct git_pack_file *packfile_alloc(int extra)
523
+ static struct git_pack_file *packfile_alloc(size_t extra)
489
524
  {
490
- struct git_pack_file *p = git__malloc(sizeof(*p) + extra);
491
- memset(p, 0, sizeof(*p));
492
- p->mwf.fd = -1;
525
+ struct git_pack_file *p = git__calloc(1, sizeof(*p) + extra);
526
+ if (p != NULL)
527
+ p->mwf.fd = -1;
493
528
  return p;
494
529
  }
495
530
 
@@ -517,24 +552,25 @@ static int packfile_open(struct git_pack_file *p)
517
552
  git_oid sha1;
518
553
  unsigned char *idx_sha1;
519
554
 
520
- if (!p->index_map.data && pack_index_open(p) < GIT_SUCCESS)
521
- return git__throw(GIT_ENOTFOUND, "Failed to open packfile. File not found");
555
+ assert(p->index_map.data);
556
+
557
+ if (!p->index_map.data && pack_index_open(p) < 0)
558
+ return git_odb__error_notfound("failed to open packfile", NULL);
522
559
 
523
560
  /* TODO: open with noatime */
524
- p->mwf.fd = p_open(p->pack_name, O_RDONLY);
525
- if (p->mwf.fd < 0 || p_fstat(p->mwf.fd, &st) < GIT_SUCCESS)
526
- return git__throw(GIT_EOSERR, "Failed to open packfile. File appears to be corrupted");
561
+ p->mwf.fd = git_futils_open_ro(p->pack_name);
562
+ if (p->mwf.fd < 0)
563
+ return p->mwf.fd;
527
564
 
528
- if (git_mwindow_file_register(&p->mwf) < GIT_SUCCESS) {
529
- p_close(p->mwf.fd);
530
- return git__throw(GIT_ERROR, "Failed to register packfile windows");
531
- }
565
+ if (p_fstat(p->mwf.fd, &st) < 0 ||
566
+ git_mwindow_file_register(&p->mwf) < 0)
567
+ goto cleanup;
532
568
 
533
569
  /* If we created the struct before we had the pack we lack size. */
534
570
  if (!p->mwf.size) {
535
571
  if (!S_ISREG(st.st_mode))
536
572
  goto cleanup;
537
- p->mwf.size = (off_t)st.st_size;
573
+ p->mwf.size = (git_off_t)st.st_size;
538
574
  } else if (p->mwf.size != st.st_size)
539
575
  goto cleanup;
540
576
 
@@ -544,44 +580,35 @@ static int packfile_open(struct git_pack_file *p)
544
580
  */
545
581
  fd_flag = fcntl(p->mwf.fd, F_GETFD, 0);
546
582
  if (fd_flag < 0)
547
- return error("cannot determine file descriptor flags");
583
+ goto cleanup;
548
584
 
549
585
  fd_flag |= FD_CLOEXEC;
550
586
  if (fcntl(p->pack_fd, F_SETFD, fd_flag) == -1)
551
- return GIT_EOSERR;
587
+ goto cleanup;
552
588
  #endif
553
589
 
554
590
  /* Verify we recognize this pack file format. */
555
- if (p_read(p->mwf.fd, &hdr, sizeof(hdr)) < GIT_SUCCESS)
556
- goto cleanup;
557
-
558
- if (hdr.hdr_signature != htonl(PACK_SIGNATURE))
559
- goto cleanup;
560
-
561
- if (!pack_version_ok(hdr.hdr_version))
591
+ if (p_read(p->mwf.fd, &hdr, sizeof(hdr)) < 0 ||
592
+ hdr.hdr_signature != htonl(PACK_SIGNATURE) ||
593
+ !pack_version_ok(hdr.hdr_version))
562
594
  goto cleanup;
563
595
 
564
596
  /* Verify the pack matches its index. */
565
- if (p->num_objects != ntohl(hdr.hdr_entries))
566
- goto cleanup;
567
-
568
- if (p_lseek(p->mwf.fd, p->mwf.size - GIT_OID_RAWSZ, SEEK_SET) == -1)
569
- goto cleanup;
570
-
571
- if (p_read(p->mwf.fd, sha1.id, GIT_OID_RAWSZ) < GIT_SUCCESS)
597
+ if (p->num_objects != ntohl(hdr.hdr_entries) ||
598
+ p_lseek(p->mwf.fd, p->mwf.size - GIT_OID_RAWSZ, SEEK_SET) == -1 ||
599
+ p_read(p->mwf.fd, sha1.id, GIT_OID_RAWSZ) < 0)
572
600
  goto cleanup;
573
601
 
574
602
  idx_sha1 = ((unsigned char *)p->index_map.data) + p->index_map.len - 40;
575
603
 
576
- if (git_oid_cmp(&sha1, (git_oid *)idx_sha1) != 0)
577
- goto cleanup;
578
-
579
- return GIT_SUCCESS;
604
+ if (git_oid_cmp(&sha1, (git_oid *)idx_sha1) == 0)
605
+ return 0;
580
606
 
581
607
  cleanup:
608
+ giterr_set(GITERR_OS, "Invalid packfile '%s'", p->pack_name);
582
609
  p_close(p->mwf.fd);
583
610
  p->mwf.fd = -1;
584
- return git__throw(GIT_EPACKCORRUPTED, "Failed to open packfile. Pack is corrupted");
611
+ return -1;
585
612
  }
586
613
 
587
614
  int git_packfile_check(struct git_pack_file **pack_out, const char *path)
@@ -593,6 +620,7 @@ int git_packfile_check(struct git_pack_file **pack_out, const char *path)
593
620
  *pack_out = NULL;
594
621
  path_len = strlen(path);
595
622
  p = packfile_alloc(path_len + 2);
623
+ GITERR_CHECK_ALLOC(p);
596
624
 
597
625
  /*
598
626
  * Make sure a corresponding .pack file exists and that
@@ -601,35 +629,36 @@ int git_packfile_check(struct git_pack_file **pack_out, const char *path)
601
629
  path_len -= strlen(".idx");
602
630
  if (path_len < 1) {
603
631
  git__free(p);
604
- return git__throw(GIT_ENOTFOUND, "Failed to check packfile. Wrong path name");
632
+ return git_odb__error_notfound("invalid packfile path", NULL);
605
633
  }
606
634
 
607
635
  memcpy(p->pack_name, path, path_len);
608
636
 
609
637
  strcpy(p->pack_name + path_len, ".keep");
610
- if (git_futils_exists(p->pack_name) == GIT_SUCCESS)
638
+ if (git_path_exists(p->pack_name) == true)
611
639
  p->pack_keep = 1;
612
640
 
613
641
  strcpy(p->pack_name + path_len, ".pack");
614
- if (p_stat(p->pack_name, &st) < GIT_SUCCESS || !S_ISREG(st.st_mode)) {
642
+ if (p_stat(p->pack_name, &st) < 0 || !S_ISREG(st.st_mode)) {
615
643
  git__free(p);
616
- return git__throw(GIT_ENOTFOUND, "Failed to check packfile. File not found");
644
+ return git_odb__error_notfound("packfile not found", NULL);
617
645
  }
618
646
 
619
647
  /* ok, it looks sane as far as we can check without
620
648
  * actually mapping the pack file.
621
649
  */
622
- p->mwf.size = (off_t)st.st_size;
650
+ p->mwf.size = st.st_size;
623
651
  p->pack_local = 1;
624
652
  p->mtime = (git_time_t)st.st_mtime;
625
653
 
626
654
  /* see if we can parse the sha1 oid in the packfile name */
627
655
  if (path_len < 40 ||
628
- git_oid_fromstr(&p->sha1, path + path_len - GIT_OID_HEXSZ) < GIT_SUCCESS)
656
+ git_oid_fromstr(&p->sha1, path + path_len - GIT_OID_HEXSZ) < 0)
629
657
  memset(&p->sha1, 0x0, GIT_OID_RAWSZ);
630
658
 
631
659
  *pack_out = p;
632
- return GIT_SUCCESS;
660
+
661
+ return 0;
633
662
  }
634
663
 
635
664
  /***********************************************************
@@ -638,7 +667,7 @@ int git_packfile_check(struct git_pack_file **pack_out, const char *path)
638
667
  *
639
668
  ***********************************************************/
640
669
 
641
- static off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n)
670
+ static git_off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n)
642
671
  {
643
672
  const unsigned char *index = p->index_map.data;
644
673
  index += 4 * 256;
@@ -657,11 +686,11 @@ static off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n)
657
686
  }
658
687
 
659
688
  static int pack_entry_find_offset(
660
- off_t *offset_out,
661
- git_oid *found_oid,
662
- struct git_pack_file *p,
663
- const git_oid *short_oid,
664
- unsigned int len)
689
+ git_off_t *offset_out,
690
+ git_oid *found_oid,
691
+ struct git_pack_file *p,
692
+ const git_oid *short_oid,
693
+ unsigned int len)
665
694
  {
666
695
  const uint32_t *level1_ofs = p->index_map.data;
667
696
  const unsigned char *index = p->index_map.data;
@@ -674,8 +703,8 @@ static int pack_entry_find_offset(
674
703
  if (index == NULL) {
675
704
  int error;
676
705
 
677
- if ((error = pack_index_open(p)) < GIT_SUCCESS)
678
- return git__rethrow(error, "Failed to find offset for pack entry");
706
+ if ((error = pack_index_open(p)) < 0)
707
+ return error;
679
708
 
680
709
  assert(p->index_map.data);
681
710
 
@@ -718,9 +747,8 @@ static int pack_entry_find_offset(
718
747
  if (pos < (int)p->num_objects) {
719
748
  current = index + pos * stride;
720
749
 
721
- if (!git_oid_ncmp(short_oid, (const git_oid *)current, len)) {
750
+ if (!git_oid_ncmp(short_oid, (const git_oid *)current, len))
722
751
  found = 1;
723
- }
724
752
  }
725
753
  }
726
754
 
@@ -733,22 +761,22 @@ static int pack_entry_find_offset(
733
761
  }
734
762
  }
735
763
 
736
- if (!found) {
737
- return git__throw(GIT_ENOTFOUND, "Failed to find offset for pack entry. Entry not found");
738
- } else if (found > 1) {
739
- return git__throw(GIT_EAMBIGUOUSOIDPREFIX, "Failed to find offset for pack entry. Ambiguous sha1 prefix within pack");
740
- } else {
741
- *offset_out = nth_packed_object_offset(p, pos);
742
- git_oid_fromraw(found_oid, current);
764
+ if (!found)
765
+ return git_odb__error_notfound("failed to find offset for pack entry", short_oid);
766
+ if (found > 1)
767
+ return git_odb__error_ambiguous("found multiple offsets for pack entry");
768
+ *offset_out = nth_packed_object_offset(p, pos);
769
+ git_oid_fromraw(found_oid, current);
743
770
 
744
771
  #ifdef INDEX_DEBUG_LOOKUP
772
+ {
745
773
  unsigned char hex_sha1[GIT_OID_HEXSZ + 1];
746
774
  git_oid_fmt(hex_sha1, found_oid);
747
775
  hex_sha1[GIT_OID_HEXSZ] = '\0';
748
776
  printf("found lo=%d %s\n", lo, hex_sha1);
749
- #endif
750
- return GIT_SUCCESS;
751
777
  }
778
+ #endif
779
+ return 0;
752
780
  }
753
781
 
754
782
  int git_pack_entry_find(
@@ -757,7 +785,7 @@ int git_pack_entry_find(
757
785
  const git_oid *short_oid,
758
786
  unsigned int len)
759
787
  {
760
- off_t offset;
788
+ git_off_t offset;
761
789
  git_oid found_oid;
762
790
  int error;
763
791
 
@@ -767,22 +795,22 @@ int git_pack_entry_find(
767
795
  unsigned i;
768
796
  for (i = 0; i < p->num_bad_objects; i++)
769
797
  if (git_oid_cmp(short_oid, &p->bad_object_sha1[i]) == 0)
770
- return git__throw(GIT_ERROR, "Failed to find pack entry. Bad object found");
798
+ return packfile_error("bad object found in packfile");
771
799
  }
772
800
 
773
801
  error = pack_entry_find_offset(&offset, &found_oid, p, short_oid, len);
774
- if (error < GIT_SUCCESS)
775
- return git__rethrow(error, "Failed to find pack entry. Couldn't find offset");
802
+ if (error < 0)
803
+ return error;
776
804
 
777
805
  /* we found a unique entry in the index;
778
806
  * make sure the packfile backing the index
779
807
  * still exists on disk */
780
- if (p->mwf.fd == -1 && packfile_open(p) < GIT_SUCCESS)
781
- return git__throw(GIT_EOSERR, "Failed to find pack entry. Packfile doesn't exist on disk");
808
+ if (p->mwf.fd == -1 && (error = packfile_open(p)) < 0)
809
+ return error;
782
810
 
783
811
  e->offset = offset;
784
812
  e->p = p;
785
813
 
786
814
  git_oid_cpy(&e->sha1, &found_oid);
787
- return GIT_SUCCESS;
815
+ return 0;
788
816
  }