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,12 +1,12 @@
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.
6
6
  */
7
7
 
8
8
  #include "common.h"
9
- #include "git2/zlib.h"
9
+ #include <zlib.h>
10
10
  #include "git2/object.h"
11
11
  #include "git2/oid.h"
12
12
  #include "fileops.h"
@@ -26,7 +26,6 @@ typedef struct { /* object header data */
26
26
  typedef struct {
27
27
  git_odb_stream stream;
28
28
  git_filebuf fbuf;
29
- int finished;
30
29
  } loose_writestream;
31
30
 
32
31
  typedef struct loose_backend {
@@ -51,41 +50,38 @@ typedef struct {
51
50
  } loose_locate_object_state;
52
51
 
53
52
 
54
-
55
53
  /***********************************************************
56
54
  *
57
55
  * MISCELANEOUS HELPER FUNCTIONS
58
56
  *
59
57
  ***********************************************************/
60
58
 
61
- static size_t object_file_name(char *name, size_t n, char *dir, const git_oid *id)
59
+ static int object_file_name(git_buf *name, const char *dir, const git_oid *id)
62
60
  {
63
- size_t len = strlen(dir);
61
+ git_buf_sets(name, dir);
64
62
 
65
- /* check length: 43 = 40 hex sha1 chars + 2 * '/' + '\0' */
66
- if (len+43 > n)
67
- return len+43;
63
+ /* expand length for 40 hex sha1 chars + 2 * '/' + '\0' */
64
+ if (git_buf_grow(name, git_buf_len(name) + GIT_OID_HEXSZ + 3) < 0)
65
+ return -1;
68
66
 
69
- /* the object dir: eg $GIT_DIR/objects */
70
- strcpy(name, dir);
71
- if (name[len-1] != '/')
72
- name[len++] = '/';
67
+ git_path_to_dir(name);
73
68
 
74
69
  /* loose object filename: aa/aaa... (41 bytes) */
75
- git_oid_pathfmt(&name[len], id);
76
- name[len+41] = '\0';
70
+ git_oid_pathfmt(name->ptr + git_buf_len(name), id);
71
+ name->size += GIT_OID_HEXSZ + 1;
72
+ name->ptr[name->size] = '\0';
77
73
 
78
74
  return 0;
79
75
  }
80
76
 
81
77
 
82
- static size_t get_binary_object_header(obj_hdr *hdr, git_fbuffer *obj)
78
+ static size_t get_binary_object_header(obj_hdr *hdr, git_buf *obj)
83
79
  {
84
80
  unsigned char c;
85
- unsigned char *data = obj->data;
81
+ unsigned char *data = (unsigned char *)obj->ptr;
86
82
  size_t shift, size, used = 0;
87
83
 
88
- if (obj->len == 0)
84
+ if (git_buf_len(obj) == 0)
89
85
  return 0;
90
86
 
91
87
  c = data[used++];
@@ -94,7 +90,7 @@ static size_t get_binary_object_header(obj_hdr *hdr, git_fbuffer *obj)
94
90
  size = c & 15;
95
91
  shift = 4;
96
92
  while (c & 0x80) {
97
- if (obj->len <= used)
93
+ if (git_buf_len(obj) <= used)
98
94
  return 0;
99
95
  if (sizeof(size_t) * 8 <= shift)
100
96
  return 0;
@@ -181,12 +177,12 @@ static void set_stream_output(z_stream *s, void *out, size_t len)
181
177
  }
182
178
 
183
179
 
184
- static int start_inflate(z_stream *s, git_fbuffer *obj, void *out, size_t len)
180
+ static int start_inflate(z_stream *s, git_buf *obj, void *out, size_t len)
185
181
  {
186
182
  int status;
187
183
 
188
184
  init_stream(s, out, len);
189
- set_stream_input(s, obj->data, obj->len);
185
+ set_stream_input(s, obj->ptr, git_buf_len(obj));
190
186
 
191
187
  if ((status = inflateInit(s)) < Z_OK)
192
188
  return status;
@@ -203,10 +199,12 @@ static int finish_inflate(z_stream *s)
203
199
 
204
200
  inflateEnd(s);
205
201
 
206
- if ((status != Z_STREAM_END) || (s->avail_in != 0))
207
- return git__throw(GIT_ERROR, "Failed to finish inflation. Stream aborted prematurely");
202
+ if ((status != Z_STREAM_END) || (s->avail_in != 0)) {
203
+ giterr_set(GITERR_ZLIB, "Failed to finish ZLib inflation. Stream aborted prematurely");
204
+ return -1;
205
+ }
208
206
 
209
- return GIT_SUCCESS;
207
+ return 0;
210
208
  }
211
209
 
212
210
  static int is_zlib_compressed_data(unsigned char *data)
@@ -230,21 +228,24 @@ static int inflate_buffer(void *in, size_t inlen, void *out, size_t outlen)
230
228
  zs.next_in = in;
231
229
  zs.avail_in = (uInt)inlen;
232
230
 
233
- if (inflateInit(&zs) < Z_OK)
234
- return git__throw(GIT_ERROR, "Failed to inflate buffer");
231
+ if (inflateInit(&zs) < Z_OK) {
232
+ giterr_set(GITERR_ZLIB, "Failed to inflate buffer");
233
+ return -1;
234
+ }
235
235
 
236
236
  while (status == Z_OK)
237
237
  status = inflate(&zs, Z_FINISH);
238
238
 
239
239
  inflateEnd(&zs);
240
240
 
241
- if ((status != Z_STREAM_END) /*|| (zs.avail_in != 0) */)
242
- return git__throw(GIT_ERROR, "Failed to inflate buffer. Stream aborted prematurely");
243
-
244
- if (zs.total_out != outlen)
245
- return git__throw(GIT_ERROR, "Failed to inflate buffer. Stream aborted prematurely");
241
+ if (status != Z_STREAM_END /* || zs.avail_in != 0 */ ||
242
+ zs.total_out != outlen)
243
+ {
244
+ giterr_set(GITERR_ZLIB, "Failed to inflate buffer. Stream aborted prematurely");
245
+ return -1;
246
+ }
246
247
 
247
- return GIT_SUCCESS;
248
+ return 0;
248
249
  }
249
250
 
250
251
  static void *inflate_tail(z_stream *s, void *hb, size_t used, obj_hdr *hdr)
@@ -291,7 +292,7 @@ static void *inflate_tail(z_stream *s, void *hb, size_t used, obj_hdr *hdr)
291
292
  * of loose object data into packs. This format is no longer used, but
292
293
  * we must still read it.
293
294
  */
294
- static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj)
295
+ static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_buf *obj)
295
296
  {
296
297
  unsigned char *in, *buf;
297
298
  obj_hdr hdr;
@@ -301,24 +302,23 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj)
301
302
  * read the object header, which is an (uncompressed)
302
303
  * binary encoding of the object type and size.
303
304
  */
304
- if ((used = get_binary_object_header(&hdr, obj)) == 0)
305
- return git__throw(GIT_ERROR, "Failed to inflate loose object. Object has no header");
306
-
307
- if (!git_object_typeisloose(hdr.type))
308
- return git__throw(GIT_ERROR, "Failed to inflate loose object. Wrong object type");
305
+ if ((used = get_binary_object_header(&hdr, obj)) == 0 ||
306
+ !git_object_typeisloose(hdr.type)) {
307
+ giterr_set(GITERR_ODB, "Failed to inflate loose object.");
308
+ return -1;
309
+ }
309
310
 
310
311
  /*
311
312
  * allocate a buffer and inflate the data into it
312
313
  */
313
314
  buf = git__malloc(hdr.size + 1);
314
- if (!buf)
315
- return GIT_ENOMEM;
315
+ GITERR_CHECK_ALLOC(buf);
316
316
 
317
- in = ((unsigned char *)obj->data) + used;
318
- len = obj->len - used;
319
- if (inflate_buffer(in, len, buf, hdr.size)) {
317
+ in = ((unsigned char *)obj->ptr) + used;
318
+ len = obj->size - used;
319
+ if (inflate_buffer(in, len, buf, hdr.size) < 0) {
320
320
  git__free(buf);
321
- return git__throw(GIT_ERROR, "Failed to inflate loose object. Could not inflate buffer");
321
+ return -1;
322
322
  }
323
323
  buf[hdr.size] = '\0';
324
324
 
@@ -326,10 +326,10 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj)
326
326
  out->len = hdr.size;
327
327
  out->type = hdr.type;
328
328
 
329
- return GIT_SUCCESS;
329
+ return 0;
330
330
  }
331
331
 
332
- static int inflate_disk_obj(git_rawobj *out, git_fbuffer *obj)
332
+ static int inflate_disk_obj(git_rawobj *out, git_buf *obj)
333
333
  {
334
334
  unsigned char head[64], *buf;
335
335
  z_stream zs;
@@ -339,35 +339,34 @@ static int inflate_disk_obj(git_rawobj *out, git_fbuffer *obj)
339
339
  /*
340
340
  * check for a pack-like loose object
341
341
  */
342
- if (!is_zlib_compressed_data(obj->data))
342
+ if (!is_zlib_compressed_data((unsigned char *)obj->ptr))
343
343
  return inflate_packlike_loose_disk_obj(out, obj);
344
344
 
345
345
  /*
346
346
  * inflate the initial part of the io buffer in order
347
347
  * to parse the object header (type and size).
348
348
  */
349
- if (start_inflate(&zs, obj, head, sizeof(head)) < Z_OK)
350
- return git__throw(GIT_ERROR, "Failed to inflate disk object. Could not inflate buffer");
351
-
352
- if ((used = get_object_header(&hdr, head)) == 0)
353
- return git__throw(GIT_ERROR, "Failed to inflate disk object. Object has no header");
354
-
355
- if (!git_object_typeisloose(hdr.type))
356
- return git__throw(GIT_ERROR, "Failed to inflate disk object. Wrong object type");
349
+ if (start_inflate(&zs, obj, head, sizeof(head)) < Z_OK ||
350
+ (used = get_object_header(&hdr, head)) == 0 ||
351
+ !git_object_typeisloose(hdr.type))
352
+ {
353
+ giterr_set(GITERR_ODB, "Failed to inflate disk object.");
354
+ return -1;
355
+ }
357
356
 
358
357
  /*
359
358
  * allocate a buffer and inflate the object data into it
360
359
  * (including the initial sequence in the head buffer).
361
360
  */
362
361
  if ((buf = inflate_tail(&zs, head, used, &hdr)) == NULL)
363
- return GIT_ENOMEM;
362
+ return -1;
364
363
  buf[hdr.size] = '\0';
365
364
 
366
365
  out->data = buf;
367
366
  out->len = hdr.size;
368
367
  out->type = hdr.type;
369
368
 
370
- return GIT_SUCCESS;
369
+ return 0;
371
370
  }
372
371
 
373
372
 
@@ -384,29 +383,31 @@ static int inflate_disk_obj(git_rawobj *out, git_fbuffer *obj)
384
383
  *
385
384
  ***********************************************************/
386
385
 
387
- static int read_loose(git_rawobj *out, const char *loc)
386
+ static int read_loose(git_rawobj *out, git_buf *loc)
388
387
  {
389
388
  int error;
390
- git_fbuffer obj = GIT_FBUFFER_INIT;
389
+ git_buf obj = GIT_BUF_INIT;
391
390
 
392
391
  assert(out && loc);
393
392
 
393
+ if (git_buf_oom(loc))
394
+ return -1;
395
+
394
396
  out->data = NULL;
395
397
  out->len = 0;
396
398
  out->type = GIT_OBJ_BAD;
397
399
 
398
- if (git_futils_readbuffer(&obj, loc) < 0)
399
- return git__throw(GIT_ENOTFOUND, "Failed to read loose object. File not found");
400
+ if (!(error = git_futils_readbuffer(&obj, loc->ptr)))
401
+ error = inflate_disk_obj(out, &obj);
400
402
 
401
- error = inflate_disk_obj(out, &obj);
402
- git_futils_freebuffer(&obj);
403
+ git_buf_free(&obj);
403
404
 
404
- return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to read loose object");
405
+ return error;
405
406
  }
406
407
 
407
- static int read_header_loose(git_rawobj *out, const char *loc)
408
+ static int read_header_loose(git_rawobj *out, git_buf *loc)
408
409
  {
409
- int error = GIT_SUCCESS, z_return = Z_ERRNO, read_bytes;
410
+ int error = 0, z_return = Z_ERRNO, read_bytes;
410
411
  git_file fd;
411
412
  z_stream zs;
412
413
  obj_hdr header_obj;
@@ -414,133 +415,151 @@ static int read_header_loose(git_rawobj *out, const char *loc)
414
415
 
415
416
  assert(out && loc);
416
417
 
418
+ if (git_buf_oom(loc))
419
+ return -1;
420
+
417
421
  out->data = NULL;
418
422
 
419
- if ((fd = p_open(loc, O_RDONLY)) < 0)
420
- return git__throw(GIT_ENOTFOUND, "Failed to read loose object header. File not found");
423
+ if ((fd = git_futils_open_ro(loc->ptr)) < 0)
424
+ return fd;
421
425
 
422
426
  init_stream(&zs, inflated_buffer, sizeof(inflated_buffer));
423
427
 
424
- if (inflateInit(&zs) < Z_OK) {
425
- error = GIT_EZLIB;
426
- goto cleanup;
427
- }
428
+ z_return = inflateInit(&zs);
428
429
 
429
- do {
430
- if ((read_bytes = read(fd, raw_buffer, sizeof(raw_buffer))) > 0) {
430
+ while (z_return == Z_OK) {
431
+ if ((read_bytes = p_read(fd, raw_buffer, sizeof(raw_buffer))) > 0) {
431
432
  set_stream_input(&zs, raw_buffer, read_bytes);
432
433
  z_return = inflate(&zs, 0);
433
- } else {
434
+ } else
434
435
  z_return = Z_STREAM_END;
435
- break;
436
- }
437
- } while (z_return == Z_OK);
436
+ }
438
437
 
439
438
  if ((z_return != Z_STREAM_END && z_return != Z_BUF_ERROR)
440
439
  || get_object_header(&header_obj, inflated_buffer) == 0
441
- || git_object_typeisloose(header_obj.type) == 0) {
442
- error = GIT_EOBJCORRUPTED;
443
- goto cleanup;
440
+ || git_object_typeisloose(header_obj.type) == 0)
441
+ {
442
+ giterr_set(GITERR_ZLIB, "Failed to read loose object header");
443
+ error = -1;
444
+ } else {
445
+ out->len = header_obj.size;
446
+ out->type = header_obj.type;
444
447
  }
445
448
 
446
- out->len = header_obj.size;
447
- out->type = header_obj.type;
448
-
449
- cleanup:
450
449
  finish_inflate(&zs);
451
450
  p_close(fd);
452
451
 
453
- if (error < GIT_SUCCESS)
454
- return git__throw(error, "Failed to read loose object header. Header is corrupted");
455
-
456
- return GIT_SUCCESS;
452
+ return error;
457
453
  }
458
454
 
459
- static int locate_object(char *object_location, loose_backend *backend, const git_oid *oid)
455
+ static int locate_object(
456
+ git_buf *object_location,
457
+ loose_backend *backend,
458
+ const git_oid *oid)
460
459
  {
461
- object_file_name(object_location, GIT_PATH_MAX, backend->objects_dir, oid);
462
- return git_futils_exists(object_location);
460
+ int error = object_file_name(object_location, backend->objects_dir, oid);
461
+
462
+ if (!error && !git_path_exists(object_location->ptr))
463
+ return GIT_ENOTFOUND;
464
+
465
+ return error;
463
466
  }
464
467
 
465
468
  /* Explore an entry of a directory and see if it matches a short oid */
466
- static int fn_locate_object_short_oid(void *state, char *pathbuf) {
469
+ static int fn_locate_object_short_oid(void *state, git_buf *pathbuf) {
467
470
  loose_locate_object_state *sstate = (loose_locate_object_state *)state;
468
471
 
469
- size_t pathbuf_len = strlen(pathbuf);
470
- if (pathbuf_len - sstate->dir_len != GIT_OID_HEXSZ - 2) {
472
+ if (git_buf_len(pathbuf) - sstate->dir_len != GIT_OID_HEXSZ - 2) {
471
473
  /* Entry cannot be an object. Continue to next entry */
472
- return GIT_SUCCESS;
474
+ return 0;
473
475
  }
474
476
 
475
- if (!git_futils_exists(pathbuf) && git_futils_isdir(pathbuf)) {
477
+ if (git_path_isdir(pathbuf->ptr) == false) {
476
478
  /* We are already in the directory matching the 2 first hex characters,
477
479
  * compare the first ncmp characters of the oids */
478
480
  if (!memcmp(sstate->short_oid + 2,
479
- (unsigned char *)pathbuf + sstate->dir_len,
481
+ (unsigned char *)pathbuf->ptr + sstate->dir_len,
480
482
  sstate->short_oid_len - 2)) {
481
483
 
482
484
  if (!sstate->found) {
483
485
  sstate->res_oid[0] = sstate->short_oid[0];
484
486
  sstate->res_oid[1] = sstate->short_oid[1];
485
- memcpy(sstate->res_oid+2, pathbuf+sstate->dir_len, GIT_OID_HEXSZ-2);
487
+ memcpy(sstate->res_oid+2, pathbuf->ptr+sstate->dir_len, GIT_OID_HEXSZ-2);
486
488
  }
487
489
  sstate->found++;
488
490
  }
489
491
  }
492
+
490
493
  if (sstate->found > 1)
491
- return git__throw(GIT_EAMBIGUOUSOIDPREFIX, "Ambiguous sha1 prefix within loose objects");
494
+ return git_odb__error_ambiguous("multiple matches in loose objects");
492
495
 
493
- return GIT_SUCCESS;
496
+ return 0;
494
497
  }
495
498
 
496
499
  /* Locate an object matching a given short oid */
497
- static int locate_object_short_oid(char *object_location, git_oid *res_oid, loose_backend *backend, const git_oid *short_oid, unsigned int len)
500
+ static int locate_object_short_oid(
501
+ git_buf *object_location,
502
+ git_oid *res_oid,
503
+ loose_backend *backend,
504
+ const git_oid *short_oid,
505
+ unsigned int len)
498
506
  {
499
507
  char *objects_dir = backend->objects_dir;
500
508
  size_t dir_len = strlen(objects_dir);
501
509
  loose_locate_object_state state;
502
510
  int error;
503
511
 
504
- if (dir_len+43 > GIT_PATH_MAX)
505
- return git__throw(GIT_ERROR, "Failed to locate object from short oid. Object path too long");
512
+ /* prealloc memory for OBJ_DIR/xx/ */
513
+ if (git_buf_grow(object_location, dir_len + 5) < 0)
514
+ return -1;
506
515
 
507
- strcpy(object_location, objects_dir);
516
+ git_buf_sets(object_location, objects_dir);
517
+ git_path_to_dir(object_location);
508
518
 
509
- /* Add a separator if not already there */
510
- if (object_location[dir_len-1] != '/')
511
- object_location[dir_len++] = '/';
519
+ /* save adjusted position at end of dir so it can be restored later */
520
+ dir_len = git_buf_len(object_location);
512
521
 
513
522
  /* Convert raw oid to hex formatted oid */
514
523
  git_oid_fmt((char *)state.short_oid, short_oid);
524
+
515
525
  /* Explore OBJ_DIR/xx/ where xx is the beginning of hex formatted short oid */
516
- sprintf(object_location+dir_len, "%.2s/", state.short_oid);
526
+ if (git_buf_printf(object_location, "%.2s/", state.short_oid) < 0)
527
+ return -1;
517
528
 
518
529
  /* Check that directory exists */
519
- if (git_futils_exists(object_location) || git_futils_isdir(object_location))
520
- return git__throw(GIT_ENOTFOUND, "Failed to locate object from short oid. Object not found");
530
+ if (git_path_isdir(object_location->ptr) == false)
531
+ return git_odb__error_notfound("no matching loose object for prefix", short_oid);
521
532
 
522
- state.dir_len = dir_len+3;
533
+ state.dir_len = git_buf_len(object_location);
523
534
  state.short_oid_len = len;
524
535
  state.found = 0;
536
+
525
537
  /* Explore directory to find a unique object matching short_oid */
526
- error = git_futils_direach(object_location, GIT_PATH_MAX, fn_locate_object_short_oid, &state);
527
- if (error) {
528
- return git__rethrow(error, "Failed to locate object from short oid");
529
- }
530
- if (!state.found) {
531
- return git__throw(GIT_ENOTFOUND, "Failed to locate object from short oid. Object not found");
532
- }
538
+ error = git_path_direach(
539
+ object_location, fn_locate_object_short_oid, &state);
540
+ if (error)
541
+ return error;
542
+
543
+ if (!state.found)
544
+ return git_odb__error_notfound("no matching loose object for prefix", short_oid);
533
545
 
534
546
  /* Convert obtained hex formatted oid to raw */
535
547
  error = git_oid_fromstr(res_oid, (char *)state.res_oid);
536
- if (error) {
537
- return git__rethrow(error, "Failed to locate object from short oid");
538
- }
548
+ if (error)
549
+ return error;
539
550
 
540
551
  /* Update the location according to the oid obtained */
541
- git_oid_pathfmt(object_location+dir_len, res_oid);
542
552
 
543
- return GIT_SUCCESS;
553
+ git_buf_truncate(object_location, dir_len);
554
+ if (git_buf_grow(object_location, dir_len + GIT_OID_HEXSZ + 2) < 0)
555
+ return -1;
556
+
557
+ git_oid_pathfmt(object_location->ptr + dir_len, res_oid);
558
+
559
+ object_location->size += GIT_OID_HEXSZ + 1;
560
+ object_location->ptr[object_location->size] = '\0';
561
+
562
+ return 0;
544
563
  }
545
564
 
546
565
 
@@ -561,7 +580,7 @@ static int locate_object_short_oid(char *object_location, git_oid *res_oid, loos
561
580
 
562
581
  static int loose_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid)
563
582
  {
564
- char object_path[GIT_PATH_MAX];
583
+ git_buf object_path = GIT_BUF_INIT;
565
584
  git_rawobj raw;
566
585
  int error;
567
586
 
@@ -570,36 +589,37 @@ static int loose_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_
570
589
  raw.len = 0;
571
590
  raw.type = GIT_OBJ_BAD;
572
591
 
573
- if (locate_object(object_path, (loose_backend *)backend, oid) < 0)
574
- return git__throw(GIT_ENOTFOUND, "Failed to read loose backend header. Object not found");
592
+ if (locate_object(&object_path, (loose_backend *)backend, oid) < 0)
593
+ error = git_odb__error_notfound("no matching loose object", oid);
594
+ else if ((error = read_header_loose(&raw, &object_path)) == 0) {
595
+ *len_p = raw.len;
596
+ *type_p = raw.type;
597
+ }
575
598
 
576
- if ((error = read_header_loose(&raw, object_path)) < GIT_SUCCESS)
577
- return error;
599
+ git_buf_free(&object_path);
578
600
 
579
- *len_p = raw.len;
580
- *type_p = raw.type;
581
- return GIT_SUCCESS;
601
+ return error;
582
602
  }
583
603
 
584
604
  static int loose_backend__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid)
585
605
  {
586
- char object_path[GIT_PATH_MAX];
606
+ git_buf object_path = GIT_BUF_INIT;
587
607
  git_rawobj raw;
588
- int error;
608
+ int error = 0;
589
609
 
590
610
  assert(backend && oid);
591
611
 
592
- if (locate_object(object_path, (loose_backend *)backend, oid) < 0)
593
- return git__throw(GIT_ENOTFOUND, "Failed to read loose backend. Object not found");
594
-
595
- if ((error = read_loose(&raw, object_path)) < GIT_SUCCESS)
596
- return git__rethrow(error, "Failed to read loose backend");
612
+ if (locate_object(&object_path, (loose_backend *)backend, oid) < 0)
613
+ error = git_odb__error_notfound("no matching loose object", oid);
614
+ else if ((error = read_loose(&raw, &object_path)) == 0) {
615
+ *buffer_p = raw.data;
616
+ *len_p = raw.len;
617
+ *type_p = raw.type;
618
+ }
597
619
 
598
- *buffer_p = raw.data;
599
- *len_p = raw.len;
600
- *type_p = raw.type;
620
+ git_buf_free(&object_path);
601
621
 
602
- return GIT_SUCCESS;
622
+ return error;
603
623
  }
604
624
 
605
625
  static int loose_backend__read_prefix(
@@ -611,77 +631,76 @@ static int loose_backend__read_prefix(
611
631
  const git_oid *short_oid,
612
632
  unsigned int len)
613
633
  {
634
+ int error = 0;
635
+
614
636
  if (len < GIT_OID_MINPREFIXLEN)
615
- return git__throw(GIT_EAMBIGUOUSOIDPREFIX, "Failed to read loose backend. Prefix length is lower than %d.", GIT_OID_MINPREFIXLEN);
637
+ error = git_odb__error_ambiguous("prefix length too short");
616
638
 
617
- if (len >= GIT_OID_HEXSZ) {
639
+ else if (len >= GIT_OID_HEXSZ) {
618
640
  /* We can fall back to regular read method */
619
- int error = loose_backend__read(buffer_p, len_p, type_p, backend, short_oid);
620
- if (error == GIT_SUCCESS)
641
+ error = loose_backend__read(buffer_p, len_p, type_p, backend, short_oid);
642
+ if (!error)
621
643
  git_oid_cpy(out_oid, short_oid);
622
-
623
- return error;
624
644
  } else {
625
- char object_path[GIT_PATH_MAX];
645
+ git_buf object_path = GIT_BUF_INIT;
626
646
  git_rawobj raw;
627
- int error;
628
647
 
629
648
  assert(backend && short_oid);
630
649
 
631
- if ((error = locate_object_short_oid(object_path, out_oid, (loose_backend *)backend, short_oid, len)) < 0) {
632
- return git__rethrow(error, "Failed to read loose backend");
650
+ if ((error = locate_object_short_oid(&object_path, out_oid,
651
+ (loose_backend *)backend, short_oid, len)) == 0 &&
652
+ (error = read_loose(&raw, &object_path)) == 0)
653
+ {
654
+ *buffer_p = raw.data;
655
+ *len_p = raw.len;
656
+ *type_p = raw.type;
633
657
  }
634
658
 
635
- if ((error = read_loose(&raw, object_path)) < GIT_SUCCESS)
636
- return git__rethrow(error, "Failed to read loose backend");
637
-
638
- *buffer_p = raw.data;
639
- *len_p = raw.len;
640
- *type_p = raw.type;
659
+ git_buf_free(&object_path);
641
660
  }
642
661
 
643
- return GIT_SUCCESS;
662
+ return error;
644
663
  }
645
664
 
646
665
  static int loose_backend__exists(git_odb_backend *backend, const git_oid *oid)
647
666
  {
648
- char object_path[GIT_PATH_MAX];
667
+ git_buf object_path = GIT_BUF_INIT;
668
+ int error;
649
669
 
650
670
  assert(backend && oid);
651
671
 
652
- return locate_object(object_path, (loose_backend *)backend, oid) == GIT_SUCCESS;
672
+ error = locate_object(&object_path, (loose_backend *)backend, oid);
673
+
674
+ git_buf_free(&object_path);
675
+
676
+ return !error;
653
677
  }
654
678
 
655
679
  static int loose_backend__stream_fwrite(git_oid *oid, git_odb_stream *_stream)
656
680
  {
657
681
  loose_writestream *stream = (loose_writestream *)_stream;
658
682
  loose_backend *backend = (loose_backend *)_stream->backend;
683
+ git_buf final_path = GIT_BUF_INIT;
684
+ int error = 0;
659
685
 
660
- int error;
661
- char final_path[GIT_PATH_MAX];
662
-
663
- if ((error = git_filebuf_hash(oid, &stream->fbuf)) < GIT_SUCCESS)
664
- return git__rethrow(error, "Failed to write loose backend");
665
-
666
- if (object_file_name(final_path, sizeof(final_path), backend->objects_dir, oid))
667
- return GIT_ENOMEM;
668
-
669
- if ((error = git_futils_mkpath2file(final_path, GIT_OBJECT_DIR_MODE)) < GIT_SUCCESS)
670
- return git__rethrow(error, "Failed to write loose backend");
671
-
672
- stream->finished = 1;
673
-
686
+ if (git_filebuf_hash(oid, &stream->fbuf) < 0 ||
687
+ object_file_name(&final_path, backend->objects_dir, oid) < 0 ||
688
+ git_futils_mkpath2file(final_path.ptr, GIT_OBJECT_DIR_MODE) < 0)
689
+ error = -1;
674
690
  /*
675
691
  * Don't try to add an existing object to the repository. This
676
692
  * is what git does and allows us to sidestep the fact that
677
693
  * we're not allowed to overwrite a read-only file on Windows.
678
694
  */
679
- if (git_futils_exists(final_path) == GIT_SUCCESS) {
695
+ else if (git_path_exists(final_path.ptr) == true)
680
696
  git_filebuf_cleanup(&stream->fbuf);
681
- return GIT_SUCCESS;
682
- }
697
+ else
698
+ error = git_filebuf_commit_at(
699
+ &stream->fbuf, final_path.ptr, GIT_OBJECT_FILE_MODE);
700
+
701
+ git_buf_free(&final_path);
683
702
 
684
- return git_filebuf_commit_at(&stream->fbuf, final_path, GIT_OBJECT_FILE_MODE);
703
+ return error;
685
704
  }
686
705
 
687
706
  static int loose_backend__stream_write(git_odb_stream *_stream, const char *data, size_t len)
@@ -694,9 +713,7 @@ static void loose_backend__stream_free(git_odb_stream *_stream)
694
713
  {
695
714
  loose_writestream *stream = (loose_writestream *)_stream;
696
715
 
697
- if (!stream->finished)
698
- git_filebuf_cleanup(&stream->fbuf);
699
-
716
+ git_filebuf_cleanup(&stream->fbuf);
700
717
  git__free(stream);
701
718
  }
702
719
 
@@ -706,21 +723,18 @@ static int format_object_header(char *hdr, size_t n, size_t obj_len, git_otype o
706
723
  int len = snprintf(hdr, n, "%s %"PRIuZ, type_str, obj_len);
707
724
 
708
725
  assert(len > 0); /* otherwise snprintf() is broken */
709
- assert(((size_t) len) < n); /* otherwise the caller is broken! */
726
+ assert(((size_t)len) < n); /* otherwise the caller is broken! */
710
727
 
711
- if (len < 0 || ((size_t) len) >= n)
712
- return git__throw(GIT_ERROR, "Failed to format object header. Length is out of bounds");
713
728
  return len+1;
714
729
  }
715
730
 
716
731
  static int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_backend, size_t length, git_otype type)
717
732
  {
718
733
  loose_backend *backend;
719
- loose_writestream *stream;
720
-
721
- char hdr[64], tmp_path[GIT_PATH_MAX];
734
+ loose_writestream *stream = NULL;
735
+ char hdr[64];
736
+ git_buf tmp_path = GIT_BUF_INIT;
722
737
  int hdrlen;
723
- int error;
724
738
 
725
739
  assert(_backend);
726
740
 
@@ -728,12 +742,9 @@ static int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_
728
742
  *stream_out = NULL;
729
743
 
730
744
  hdrlen = format_object_header(hdr, sizeof(hdr), length, type);
731
- if (hdrlen < GIT_SUCCESS)
732
- return git__throw(GIT_EOBJCORRUPTED, "Failed to create loose backend stream. Object is corrupted");
733
745
 
734
746
  stream = git__calloc(1, sizeof(loose_writestream));
735
- if (stream == NULL)
736
- return GIT_ENOMEM;
747
+ GITERR_CHECK_ALLOC(stream);
737
748
 
738
749
  stream->stream.backend = _backend;
739
750
  stream->stream.read = NULL; /* read only */
@@ -742,69 +753,59 @@ static int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_
742
753
  stream->stream.free = &loose_backend__stream_free;
743
754
  stream->stream.mode = GIT_STREAM_WRONLY;
744
755
 
745
- git_path_join(tmp_path, backend->objects_dir, "tmp_object");
746
-
747
- error = git_filebuf_open(&stream->fbuf, tmp_path,
748
- GIT_FILEBUF_HASH_CONTENTS |
749
- GIT_FILEBUF_TEMPORARY |
750
- (backend->object_zlib_level << GIT_FILEBUF_DEFLATE_SHIFT));
751
-
752
- if (error < GIT_SUCCESS) {
753
- git__free(stream);
754
- return git__rethrow(error, "Failed to create loose backend stream");
755
- }
756
-
757
- error = stream->stream.write((git_odb_stream *)stream, hdr, hdrlen);
758
- if (error < GIT_SUCCESS) {
756
+ if (git_buf_joinpath(&tmp_path, backend->objects_dir, "tmp_object") < 0 ||
757
+ git_filebuf_open(&stream->fbuf, tmp_path.ptr,
758
+ GIT_FILEBUF_HASH_CONTENTS |
759
+ GIT_FILEBUF_TEMPORARY |
760
+ (backend->object_zlib_level << GIT_FILEBUF_DEFLATE_SHIFT)) < 0 ||
761
+ stream->stream.write((git_odb_stream *)stream, hdr, hdrlen) < 0)
762
+ {
759
763
  git_filebuf_cleanup(&stream->fbuf);
760
764
  git__free(stream);
761
- return git__rethrow(error, "Failed to create loose backend stream");
765
+ stream = NULL;
762
766
  }
763
-
767
+ git_buf_free(&tmp_path);
764
768
  *stream_out = (git_odb_stream *)stream;
765
- return GIT_SUCCESS;
769
+
770
+ return !stream ? -1 : 0;
766
771
  }
767
772
 
768
773
  static int loose_backend__write(git_oid *oid, git_odb_backend *_backend, const void *data, size_t len, git_otype type)
769
774
  {
770
- int error, header_len;
771
- char final_path[GIT_PATH_MAX], header[64];
775
+ int error = 0, header_len;
776
+ git_buf final_path = GIT_BUF_INIT;
777
+ char header[64];
772
778
  git_filebuf fbuf = GIT_FILEBUF_INIT;
773
779
  loose_backend *backend;
774
780
 
775
781
  backend = (loose_backend *)_backend;
776
782
 
777
783
  /* prepare the header for the file */
784
+ header_len = format_object_header(header, sizeof(header), len, type);
785
+
786
+ if (git_buf_joinpath(&final_path, backend->objects_dir, "tmp_object") < 0 ||
787
+ git_filebuf_open(&fbuf, final_path.ptr,
788
+ GIT_FILEBUF_HASH_CONTENTS |
789
+ GIT_FILEBUF_TEMPORARY |
790
+ (backend->object_zlib_level << GIT_FILEBUF_DEFLATE_SHIFT)) < 0)
778
791
  {
779
- header_len = format_object_header(header, sizeof(header), len, type);
780
- if (header_len < GIT_SUCCESS)
781
- return GIT_EOBJCORRUPTED;
792
+ error = -1;
793
+ goto cleanup;
782
794
  }
783
795
 
784
- git_path_join(final_path, backend->objects_dir, "tmp_object");
785
-
786
- error = git_filebuf_open(&fbuf, final_path,
787
- GIT_FILEBUF_HASH_CONTENTS |
788
- GIT_FILEBUF_TEMPORARY |
789
- (backend->object_zlib_level << GIT_FILEBUF_DEFLATE_SHIFT));
790
-
791
- if (error < GIT_SUCCESS)
792
- return error;
793
-
794
796
  git_filebuf_write(&fbuf, header, header_len);
795
797
  git_filebuf_write(&fbuf, data, len);
796
798
  git_filebuf_hash(oid, &fbuf);
797
799
 
798
- if ((error = object_file_name(final_path, sizeof(final_path), backend->objects_dir, oid)) < GIT_SUCCESS)
799
- goto cleanup;
800
-
801
- if ((error = git_futils_mkpath2file(final_path, GIT_OBJECT_DIR_MODE)) < GIT_SUCCESS)
802
- goto cleanup;
803
-
804
- return git_filebuf_commit_at(&fbuf, final_path, GIT_OBJECT_FILE_MODE);
800
+ if (object_file_name(&final_path, backend->objects_dir, oid) < 0 ||
801
+ git_futils_mkpath2file(final_path.ptr, GIT_OBJECT_DIR_MODE) < 0 ||
802
+ git_filebuf_commit_at(&fbuf, final_path.ptr, GIT_OBJECT_FILE_MODE) < 0)
803
+ error = -1;
805
804
 
806
805
  cleanup:
807
- git_filebuf_cleanup(&fbuf);
806
+ if (error < 0)
807
+ git_filebuf_cleanup(&fbuf);
808
+ git_buf_free(&final_path);
808
809
  return error;
809
810
  }
810
811
 
@@ -827,14 +828,10 @@ int git_odb_backend_loose(
827
828
  loose_backend *backend;
828
829
 
829
830
  backend = git__calloc(1, sizeof(loose_backend));
830
- if (backend == NULL)
831
- return GIT_ENOMEM;
831
+ GITERR_CHECK_ALLOC(backend);
832
832
 
833
833
  backend->objects_dir = git__strdup(objects_dir);
834
- if (backend->objects_dir == NULL) {
835
- git__free(backend);
836
- return GIT_ENOMEM;
837
- }
834
+ GITERR_CHECK_ALLOC(backend->objects_dir);
838
835
 
839
836
  if (compression_level < 0)
840
837
  compression_level = Z_BEST_SPEED;
@@ -851,5 +848,5 @@ int git_odb_backend_loose(
851
848
  backend->parent.free = &loose_backend__free;
852
849
 
853
850
  *backend_out = (git_odb_backend *)backend;
854
- return GIT_SUCCESS;
851
+ return 0;
855
852
  }