rugged 0.1.2 → 0.16.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (277) hide show
  1. data/README.md +25 -36
  2. data/Rakefile +20 -98
  3. data/ext/rugged/extconf.rb +44 -4
  4. data/ext/rugged/remote.c +215 -0
  5. data/ext/rugged/rugged.c +171 -0
  6. data/ext/rugged/rugged.h +126 -0
  7. data/ext/rugged/rugged_blob.c +99 -0
  8. data/ext/rugged/rugged_commit.c +224 -0
  9. data/ext/rugged/rugged_config.c +238 -0
  10. data/ext/rugged/rugged_index.c +440 -0
  11. data/ext/rugged/rugged_object.c +203 -0
  12. data/ext/rugged/rugged_reference.c +401 -0
  13. data/ext/rugged/rugged_repo.c +482 -0
  14. data/ext/rugged/rugged_revwalk.c +138 -0
  15. data/ext/rugged/rugged_signature.c +80 -0
  16. data/ext/rugged/rugged_tag.c +216 -0
  17. data/ext/rugged/rugged_tree.c +322 -0
  18. data/ext/rugged/vendor/libgit2-dist.tar.gz +0 -0
  19. data/ext/rugged/vendor/libgit2-dist/deps/http-parser/http_parser.c +1778 -0
  20. data/ext/rugged/vendor/libgit2-dist/deps/http-parser/http_parser.h +267 -0
  21. data/ext/rugged/vendor/libgit2-dist/deps/zlib/adler32.c +169 -0
  22. data/ext/rugged/vendor/libgit2-dist/deps/zlib/crc32.c +442 -0
  23. data/ext/rugged/vendor/libgit2-dist/deps/zlib/crc32.h +441 -0
  24. data/ext/rugged/vendor/libgit2-dist/deps/zlib/deflate.c +1834 -0
  25. data/ext/rugged/vendor/libgit2-dist/deps/zlib/deflate.h +342 -0
  26. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffast.c +340 -0
  27. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffast.h +11 -0
  28. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffixed.h +94 -0
  29. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inflate.c +1480 -0
  30. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inflate.h +122 -0
  31. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inftrees.c +330 -0
  32. data/ext/rugged/vendor/libgit2-dist/deps/zlib/inftrees.h +62 -0
  33. data/ext/rugged/vendor/libgit2-dist/deps/zlib/trees.c +1244 -0
  34. data/ext/rugged/vendor/libgit2-dist/deps/zlib/trees.h +128 -0
  35. data/ext/rugged/vendor/libgit2-dist/deps/zlib/zconf.h +54 -0
  36. data/ext/rugged/vendor/libgit2-dist/deps/zlib/zlib.h +1613 -0
  37. data/ext/rugged/vendor/libgit2-dist/deps/zlib/zutil.c +318 -0
  38. data/ext/rugged/vendor/libgit2-dist/deps/zlib/zutil.h +274 -0
  39. data/ext/rugged/vendor/libgit2-dist/examples/general.c +451 -0
  40. data/ext/rugged/vendor/libgit2-dist/examples/network/common.h +14 -0
  41. data/ext/rugged/vendor/libgit2-dist/examples/network/fetch.c +97 -0
  42. data/ext/rugged/vendor/libgit2-dist/examples/network/git2.c +58 -0
  43. data/ext/rugged/vendor/libgit2-dist/examples/network/index-pack.c +47 -0
  44. data/ext/rugged/vendor/libgit2-dist/examples/network/ls-remote.c +76 -0
  45. data/ext/rugged/vendor/libgit2-dist/examples/showindex.c +43 -0
  46. data/ext/rugged/vendor/libgit2-dist/include/git2.h +44 -0
  47. data/ext/rugged/vendor/libgit2-dist/include/git2/blob.h +120 -0
  48. data/ext/rugged/vendor/libgit2-dist/include/git2/branch.h +15 -0
  49. data/ext/rugged/vendor/libgit2-dist/include/git2/commit.h +263 -0
  50. data/ext/rugged/vendor/libgit2-dist/include/git2/common.h +103 -0
  51. data/ext/rugged/vendor/libgit2-dist/include/git2/config.h +278 -0
  52. data/ext/rugged/vendor/libgit2-dist/include/git2/errors.h +144 -0
  53. data/ext/rugged/vendor/libgit2-dist/include/git2/index.h +306 -0
  54. data/ext/rugged/vendor/libgit2-dist/include/git2/indexer.h +76 -0
  55. data/ext/rugged/vendor/libgit2-dist/include/git2/inttypes.h +305 -0
  56. data/ext/rugged/vendor/libgit2-dist/include/git2/net.h +51 -0
  57. data/ext/rugged/vendor/libgit2-dist/include/git2/object.h +173 -0
  58. data/ext/rugged/vendor/libgit2-dist/include/git2/odb.h +331 -0
  59. data/ext/rugged/vendor/libgit2-dist/include/git2/odb_backend.h +100 -0
  60. data/ext/rugged/vendor/libgit2-dist/include/git2/oid.h +218 -0
  61. data/ext/rugged/vendor/libgit2-dist/include/git2/reflog.h +128 -0
  62. data/ext/rugged/vendor/libgit2-dist/include/git2/refs.h +309 -0
  63. data/ext/rugged/vendor/libgit2-dist/include/git2/refspec.h +60 -0
  64. data/ext/rugged/vendor/libgit2-dist/include/git2/remote.h +176 -0
  65. data/ext/rugged/vendor/libgit2-dist/include/git2/repository.h +290 -0
  66. data/ext/rugged/vendor/libgit2-dist/include/git2/revwalk.h +169 -0
  67. data/ext/rugged/vendor/libgit2-dist/include/git2/signature.h +65 -0
  68. data/ext/rugged/vendor/libgit2-dist/include/git2/status.h +63 -0
  69. data/ext/rugged/vendor/libgit2-dist/include/git2/stdint.h +247 -0
  70. data/ext/rugged/vendor/libgit2-dist/include/git2/tag.h +279 -0
  71. data/ext/rugged/vendor/libgit2-dist/include/git2/threads.h +48 -0
  72. data/ext/rugged/vendor/libgit2-dist/include/git2/tree.h +318 -0
  73. data/ext/rugged/vendor/libgit2-dist/include/git2/types.h +169 -0
  74. data/ext/rugged/vendor/libgit2-dist/include/git2/version.h +15 -0
  75. data/ext/rugged/vendor/libgit2-dist/include/git2/windows.h +59 -0
  76. data/ext/rugged/vendor/libgit2-dist/include/git2/zlib.h +40 -0
  77. data/ext/rugged/vendor/libgit2-dist/src/blob.c +135 -0
  78. data/ext/rugged/vendor/libgit2-dist/src/blob.h +23 -0
  79. data/ext/rugged/vendor/libgit2-dist/src/bswap.h +97 -0
  80. data/ext/rugged/vendor/libgit2-dist/src/buffer.c +113 -0
  81. data/ext/rugged/vendor/libgit2-dist/src/buffer.h +32 -0
  82. data/ext/rugged/vendor/libgit2-dist/src/cache.c +111 -0
  83. data/ext/rugged/vendor/libgit2-dist/src/cache.h +64 -0
  84. data/ext/rugged/vendor/libgit2-dist/src/cc-compat.h +67 -0
  85. data/ext/rugged/vendor/libgit2-dist/src/commit.c +299 -0
  86. data/ext/rugged/vendor/libgit2-dist/src/commit.h +34 -0
  87. data/ext/rugged/vendor/libgit2-dist/src/common.h +64 -0
  88. data/ext/rugged/vendor/libgit2-dist/src/config.c +418 -0
  89. data/ext/rugged/vendor/libgit2-dist/src/config.h +24 -0
  90. data/ext/rugged/vendor/libgit2-dist/src/config_file.c +1210 -0
  91. data/ext/rugged/vendor/libgit2-dist/src/delta-apply.c +115 -0
  92. data/ext/rugged/vendor/libgit2-dist/src/delta-apply.h +33 -0
  93. data/ext/rugged/vendor/libgit2-dist/src/dir.h +47 -0
  94. data/ext/rugged/vendor/libgit2-dist/src/errors.c +104 -0
  95. data/ext/rugged/vendor/libgit2-dist/src/fetch.c +172 -0
  96. data/ext/rugged/vendor/libgit2-dist/src/fetch.h +18 -0
  97. data/ext/rugged/vendor/libgit2-dist/src/filebuf.c +400 -0
  98. data/ext/rugged/vendor/libgit2-dist/src/filebuf.h +72 -0
  99. data/ext/rugged/vendor/libgit2-dist/src/fileops.c +358 -0
  100. data/ext/rugged/vendor/libgit2-dist/src/fileops.h +151 -0
  101. data/ext/rugged/vendor/libgit2-dist/src/global.c +134 -0
  102. data/ext/rugged/vendor/libgit2-dist/src/global.h +24 -0
  103. data/ext/rugged/vendor/libgit2-dist/src/hash.c +74 -0
  104. data/ext/rugged/vendor/libgit2-dist/src/hash.h +29 -0
  105. data/ext/rugged/vendor/libgit2-dist/src/hashtable.c +243 -0
  106. data/ext/rugged/vendor/libgit2-dist/src/hashtable.h +80 -0
  107. data/ext/rugged/vendor/libgit2-dist/src/index.c +918 -0
  108. data/ext/rugged/vendor/libgit2-dist/src/index.h +34 -0
  109. data/ext/rugged/vendor/libgit2-dist/src/indexer.c +401 -0
  110. data/ext/rugged/vendor/libgit2-dist/src/map.h +37 -0
  111. data/ext/rugged/vendor/libgit2-dist/src/mwindow.c +272 -0
  112. data/ext/rugged/vendor/libgit2-dist/src/mwindow.h +45 -0
  113. data/ext/rugged/vendor/libgit2-dist/src/netops.c +198 -0
  114. data/ext/rugged/vendor/libgit2-dist/src/netops.h +36 -0
  115. data/ext/rugged/vendor/libgit2-dist/src/object.c +295 -0
  116. data/ext/rugged/vendor/libgit2-dist/src/odb.c +672 -0
  117. data/ext/rugged/vendor/libgit2-dist/src/odb.h +43 -0
  118. data/ext/rugged/vendor/libgit2-dist/src/odb_loose.c +855 -0
  119. data/ext/rugged/vendor/libgit2-dist/src/odb_pack.c +485 -0
  120. data/ext/rugged/vendor/libgit2-dist/src/oid.c +388 -0
  121. data/ext/rugged/vendor/libgit2-dist/src/pack.c +788 -0
  122. data/ext/rugged/vendor/libgit2-dist/src/pack.h +99 -0
  123. data/ext/rugged/vendor/libgit2-dist/src/path.c +270 -0
  124. data/ext/rugged/vendor/libgit2-dist/src/path.h +84 -0
  125. data/ext/rugged/vendor/libgit2-dist/src/pkt.c +426 -0
  126. data/ext/rugged/vendor/libgit2-dist/src/pkt.h +77 -0
  127. data/ext/rugged/vendor/libgit2-dist/src/posix.c +94 -0
  128. data/ext/rugged/vendor/libgit2-dist/src/posix.h +69 -0
  129. data/ext/rugged/vendor/libgit2-dist/src/ppc/sha1.c +70 -0
  130. data/ext/rugged/vendor/libgit2-dist/src/ppc/sha1.h +26 -0
  131. data/ext/rugged/vendor/libgit2-dist/src/pqueue.c +141 -0
  132. data/ext/rugged/vendor/libgit2-dist/src/pqueue.h +81 -0
  133. data/ext/rugged/vendor/libgit2-dist/src/protocol.c +50 -0
  134. data/ext/rugged/vendor/libgit2-dist/src/protocol.h +23 -0
  135. data/ext/rugged/vendor/libgit2-dist/src/reflog.c +318 -0
  136. data/ext/rugged/vendor/libgit2-dist/src/reflog.h +34 -0
  137. data/ext/rugged/vendor/libgit2-dist/src/refs.c +1693 -0
  138. data/ext/rugged/vendor/libgit2-dist/src/refs.h +58 -0
  139. data/ext/rugged/vendor/libgit2-dist/src/refspec.c +95 -0
  140. data/ext/rugged/vendor/libgit2-dist/src/refspec.h +23 -0
  141. data/ext/rugged/vendor/libgit2-dist/src/remote.c +339 -0
  142. data/ext/rugged/vendor/libgit2-dist/src/remote.h +25 -0
  143. data/ext/rugged/vendor/libgit2-dist/src/repository.c +849 -0
  144. data/ext/rugged/vendor/libgit2-dist/src/repository.h +60 -0
  145. data/ext/rugged/vendor/libgit2-dist/src/revwalk.c +569 -0
  146. data/ext/rugged/vendor/libgit2-dist/src/sha1.c +280 -0
  147. data/ext/rugged/vendor/libgit2-dist/src/sha1.h +21 -0
  148. data/ext/rugged/vendor/libgit2-dist/src/sha1_lookup.c +177 -0
  149. data/ext/rugged/vendor/libgit2-dist/src/sha1_lookup.h +18 -0
  150. data/ext/rugged/vendor/libgit2-dist/src/signature.c +335 -0
  151. data/ext/rugged/vendor/libgit2-dist/src/signature.h +18 -0
  152. data/ext/rugged/vendor/libgit2-dist/src/status.c +696 -0
  153. data/ext/rugged/vendor/libgit2-dist/src/tag.c +446 -0
  154. data/ext/rugged/vendor/libgit2-dist/src/tag.h +28 -0
  155. data/ext/rugged/vendor/libgit2-dist/src/thread-utils.c +55 -0
  156. data/ext/rugged/vendor/libgit2-dist/src/thread-utils.h +108 -0
  157. data/ext/rugged/vendor/libgit2-dist/src/transport.c +85 -0
  158. data/ext/rugged/vendor/libgit2-dist/src/transport.h +110 -0
  159. data/ext/rugged/vendor/libgit2-dist/src/transports/git.c +502 -0
  160. data/ext/rugged/vendor/libgit2-dist/src/transports/http.c +756 -0
  161. data/ext/rugged/vendor/libgit2-dist/src/transports/local.c +235 -0
  162. data/ext/rugged/vendor/libgit2-dist/src/tree-cache.c +201 -0
  163. data/ext/rugged/vendor/libgit2-dist/src/tree-cache.h +31 -0
  164. data/ext/rugged/vendor/libgit2-dist/src/tree.c +758 -0
  165. data/ext/rugged/vendor/libgit2-dist/src/tree.h +37 -0
  166. data/ext/rugged/vendor/libgit2-dist/src/tsort.c +365 -0
  167. data/ext/rugged/vendor/libgit2-dist/src/unix/map.c +70 -0
  168. data/ext/rugged/vendor/libgit2-dist/src/unix/posix.h +25 -0
  169. data/ext/rugged/vendor/libgit2-dist/src/util.c +381 -0
  170. data/ext/rugged/vendor/libgit2-dist/src/util.h +137 -0
  171. data/ext/rugged/vendor/libgit2-dist/src/vector.c +174 -0
  172. data/ext/rugged/vendor/libgit2-dist/src/vector.h +45 -0
  173. data/ext/rugged/vendor/libgit2-dist/src/win32/dir.c +115 -0
  174. data/ext/rugged/vendor/libgit2-dist/src/win32/fnmatch.c +180 -0
  175. data/ext/rugged/vendor/libgit2-dist/src/win32/fnmatch.h +27 -0
  176. data/ext/rugged/vendor/libgit2-dist/src/win32/map.c +131 -0
  177. data/ext/rugged/vendor/libgit2-dist/src/win32/mingw-compat.h +24 -0
  178. data/ext/rugged/vendor/libgit2-dist/src/win32/msvc-compat.h +38 -0
  179. data/ext/rugged/vendor/libgit2-dist/src/win32/posix.h +53 -0
  180. data/ext/rugged/vendor/libgit2-dist/src/win32/posix_w32.c +404 -0
  181. data/ext/rugged/vendor/libgit2-dist/src/win32/pthread.c +65 -0
  182. data/ext/rugged/vendor/libgit2-dist/src/win32/pthread.h +40 -0
  183. data/ext/rugged/vendor/libgit2-dist/src/win32/utf-conv.c +88 -0
  184. data/ext/rugged/vendor/libgit2-dist/src/win32/utf-conv.h +17 -0
  185. data/ext/rugged/vendor/libgit2-dist/tests-clay/buf/basic.c +29 -0
  186. data/ext/rugged/vendor/libgit2-dist/tests-clay/clay.h +187 -0
  187. data/ext/rugged/vendor/libgit2-dist/tests-clay/clay_libgit2.h +28 -0
  188. data/ext/rugged/vendor/libgit2-dist/tests-clay/clay_main.c +1073 -0
  189. data/ext/rugged/vendor/libgit2-dist/tests-clay/config/add.c +37 -0
  190. data/ext/rugged/vendor/libgit2-dist/tests-clay/config/new.c +36 -0
  191. data/ext/rugged/vendor/libgit2-dist/tests-clay/config/read.c +209 -0
  192. data/ext/rugged/vendor/libgit2-dist/tests-clay/config/stress.c +39 -0
  193. data/ext/rugged/vendor/libgit2-dist/tests-clay/config/write.c +77 -0
  194. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/dirent.c +222 -0
  195. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/filebuf.c +106 -0
  196. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/oid.c +18 -0
  197. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/path.c +139 -0
  198. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/rmdir.c +50 -0
  199. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/string.c +28 -0
  200. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/strtol.c +37 -0
  201. data/ext/rugged/vendor/libgit2-dist/tests-clay/core/vector.c +66 -0
  202. data/ext/rugged/vendor/libgit2-dist/tests-clay/index/rename.c +60 -0
  203. data/ext/rugged/vendor/libgit2-dist/tests-clay/network/remotes.c +50 -0
  204. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/chars.c +52 -0
  205. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/compare.c +124 -0
  206. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/convert.c +75 -0
  207. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/data.h +323 -0
  208. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/fromstr.c +30 -0
  209. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/hash.c +162 -0
  210. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/short.c +94 -0
  211. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/size.c +13 -0
  212. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/type2string.c +54 -0
  213. data/ext/rugged/vendor/libgit2-dist/tests-clay/object/tree/frompath.c +75 -0
  214. data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/loose.c +84 -0
  215. data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/loose_data.h +522 -0
  216. data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/pack_data.h +151 -0
  217. data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/packed.c +78 -0
  218. data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/sorting.c +71 -0
  219. data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/getters.c +68 -0
  220. data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/init.c +104 -0
  221. data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/open.c +54 -0
  222. data/ext/rugged/vendor/libgit2-dist/tests-clay/status/single.c +38 -0
  223. data/ext/rugged/vendor/libgit2-dist/tests-clay/status/status_data.h +48 -0
  224. data/ext/rugged/vendor/libgit2-dist/tests-clay/status/worktree.c +124 -0
  225. data/ext/rugged/vendor/libgit2-dist/tests/t00-core.c +628 -0
  226. data/ext/rugged/vendor/libgit2-dist/tests/t01-data.h +322 -0
  227. data/ext/rugged/vendor/libgit2-dist/tests/t01-rawobj.c +638 -0
  228. data/ext/rugged/vendor/libgit2-dist/tests/t03-data.h +344 -0
  229. data/ext/rugged/vendor/libgit2-dist/tests/t03-objwrite.c +255 -0
  230. data/ext/rugged/vendor/libgit2-dist/tests/t04-commit.c +788 -0
  231. data/ext/rugged/vendor/libgit2-dist/tests/t05-revwalk.c +140 -0
  232. data/ext/rugged/vendor/libgit2-dist/tests/t06-index.c +219 -0
  233. data/ext/rugged/vendor/libgit2-dist/tests/t07-hashtable.c +192 -0
  234. data/ext/rugged/vendor/libgit2-dist/tests/t08-tag.c +357 -0
  235. data/ext/rugged/vendor/libgit2-dist/tests/t09-tree.c +221 -0
  236. data/ext/rugged/vendor/libgit2-dist/tests/t10-refs.c +1294 -0
  237. data/ext/rugged/vendor/libgit2-dist/tests/t12-repo.c +174 -0
  238. data/ext/rugged/vendor/libgit2-dist/tests/t13-threads.c +41 -0
  239. data/ext/rugged/vendor/libgit2-dist/tests/t17-bufs.c +61 -0
  240. data/ext/rugged/vendor/libgit2-dist/tests/t18-status.c +448 -0
  241. data/ext/rugged/vendor/libgit2-dist/tests/test_helpers.c +310 -0
  242. data/ext/rugged/vendor/libgit2-dist/tests/test_helpers.h +83 -0
  243. data/ext/rugged/vendor/libgit2-dist/tests/test_lib.c +198 -0
  244. data/ext/rugged/vendor/libgit2-dist/tests/test_lib.h +54 -0
  245. data/ext/rugged/vendor/libgit2-dist/tests/test_main.c +89 -0
  246. data/lib/rugged.rb +4 -3
  247. data/lib/rugged/index.rb +0 -8
  248. data/lib/rugged/objects.rb +45 -0
  249. data/lib/rugged/repository.rb +29 -0
  250. data/lib/rugged/tree.rb +16 -6
  251. data/lib/rugged/version.rb +1 -1
  252. data/lib/rugged/walker.rb +5 -0
  253. data/test/blob_test.rb +18 -14
  254. data/test/commit_test.rb +28 -26
  255. data/test/coverage/HEAD.json +1 -0
  256. data/test/coverage/cover.rb +106 -0
  257. data/test/fixtures/testrepo.git/refs/heads/new_name +1 -0
  258. data/test/index_test.rb +101 -78
  259. data/test/lib_test.rb +4 -4
  260. data/test/object_test.rb +3 -3
  261. data/test/reference_test.rb +75 -0
  262. data/test/remote_test.rb +19 -0
  263. data/test/repo_pack_test.rb +4 -4
  264. data/test/repo_test.rb +44 -15
  265. data/test/tag_test.rb +7 -17
  266. data/test/test_helper.rb +24 -5
  267. data/test/tree_test.rb +30 -12
  268. data/test/walker_test.rb +40 -31
  269. metadata +273 -50
  270. data/lib/rugged/person.rb +0 -20
  271. data/lib/rugged/tree_entry.rb +0 -9
  272. data/test/fixtures/testrepo.git/objects/1d/83f106355e4309a293e42ad2a2c4b8bdbe77ae +0 -0
  273. data/test/fixtures/testrepo.git/objects/2f/3321418db5b2a841375b8b70880a8ab5a4148f +0 -0
  274. data/test/fixtures/testrepo.git/objects/36/9b00a7700cca3a506d79e301d6ad8bf735d9ee +0 -3
  275. data/test/fixtures/testrepo.git/objects/3d/b1b5ceace59ff65279757003763046fd4cbbe6 +0 -0
  276. data/test/fixtures/testrepo.git/objects/4c/d1604907792e2c43e03dcec1216f99d63e68c4 +0 -3
  277. data/test/fixtures/testrepo.git/objects/e0/f46d77041c149296549b01ed4a18b02c4b7400 +0 -0
@@ -0,0 +1,758 @@
1
+ /*
2
+ * Copyright (C) 2009-2011 the libgit2 contributors
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #include "common.h"
9
+ #include "commit.h"
10
+ #include "tree.h"
11
+ #include "git2/repository.h"
12
+ #include "git2/object.h"
13
+
14
+ #define DEFAULT_TREE_SIZE 16
15
+ #define MAX_FILEMODE 0777777
16
+ #define MAX_FILEMODE_BYTES 6
17
+
18
+ #define ENTRY_IS_TREE(e) ((e)->attr & 040000)
19
+
20
+ static int valid_attributes(const int attributes)
21
+ {
22
+ return attributes >= 0 && attributes <= MAX_FILEMODE;
23
+ }
24
+
25
+ static int valid_entry_name(const char *filename)
26
+ {
27
+ return strlen(filename) > 0 && strchr(filename, '/') == NULL;
28
+ }
29
+
30
+ static int entry_sort_cmp(const void *a, const void *b)
31
+ {
32
+ const git_tree_entry *entry_a = (const git_tree_entry *)(a);
33
+ const git_tree_entry *entry_b = (const git_tree_entry *)(b);
34
+
35
+ return git_futils_cmp_path(
36
+ entry_a->filename, entry_a->filename_len, ENTRY_IS_TREE(entry_a),
37
+ entry_b->filename, entry_b->filename_len, ENTRY_IS_TREE(entry_b));
38
+ }
39
+
40
+
41
+ struct tree_key_search {
42
+ const char *filename;
43
+ size_t filename_len;
44
+ };
45
+
46
+ static int homing_search_cmp(const void *key, const void *array_member)
47
+ {
48
+ const struct tree_key_search *ksearch = key;
49
+ const git_tree_entry *entry = array_member;
50
+
51
+ const size_t len1 = ksearch->filename_len;
52
+ const size_t len2 = entry->filename_len;
53
+
54
+ return memcmp(
55
+ ksearch->filename,
56
+ entry->filename,
57
+ len1 < len2 ? len1 : len2
58
+ );
59
+ }
60
+
61
+ /*
62
+ * Search for an entry in a given tree.
63
+ *
64
+ * Note that this search is performed in two steps because
65
+ * of the way tree entries are sorted internally in git:
66
+ *
67
+ * Entries in a tree are not sorted alphabetically; two entries
68
+ * with the same root prefix will have different positions
69
+ * depending on whether they are folders (subtrees) or normal files.
70
+ *
71
+ * Consequently, it is not possible to find an entry on the tree
72
+ * with a binary search if you don't know whether the filename
73
+ * you're looking for is a folder or a normal file.
74
+ *
75
+ * To work around this, we first perform a homing binary search
76
+ * on the tree, using the minimal length root prefix of our filename.
77
+ * Once the comparisons for this homing search start becoming
78
+ * ambiguous because of folder vs file sorting, we look linearly
79
+ * around the area for our target file.
80
+ */
81
+ static int tree_key_search(git_vector *entries, const char *filename)
82
+ {
83
+ struct tree_key_search ksearch;
84
+ const git_tree_entry *entry;
85
+
86
+ int homing, i;
87
+
88
+ ksearch.filename = filename;
89
+ ksearch.filename_len = strlen(filename);
90
+
91
+ /* Initial homing search; find an entry on the tree with
92
+ * the same prefix as the filename we're looking for */
93
+ homing = git_vector_bsearch2(entries, &homing_search_cmp, &ksearch);
94
+ if (homing < 0)
95
+ return homing;
96
+
97
+ /* We found a common prefix. Look forward as long as
98
+ * there are entries that share the common prefix */
99
+ for (i = homing; i < (int)entries->length; ++i) {
100
+ entry = entries->contents[i];
101
+
102
+ if (homing_search_cmp(&ksearch, entry) != 0)
103
+ break;
104
+
105
+ if (strcmp(filename, entry->filename) == 0)
106
+ return i;
107
+ }
108
+
109
+ /* If we haven't found our filename yet, look backwards
110
+ * too as long as we have entries with the same prefix */
111
+ for (i = homing - 1; i >= 0; --i) {
112
+ entry = entries->contents[i];
113
+
114
+ if (homing_search_cmp(&ksearch, entry) != 0)
115
+ break;
116
+
117
+ if (strcmp(filename, entry->filename) == 0)
118
+ return i;
119
+ }
120
+
121
+ /* The filename doesn't exist at all */
122
+ return GIT_ENOTFOUND;
123
+ }
124
+
125
+ void git_tree__free(git_tree *tree)
126
+ {
127
+ unsigned int i;
128
+
129
+ for (i = 0; i < tree->entries.length; ++i) {
130
+ git_tree_entry *e;
131
+ e = git_vector_get(&tree->entries, i);
132
+
133
+ git__free(e->filename);
134
+ git__free(e);
135
+ }
136
+
137
+ git_vector_free(&tree->entries);
138
+ git__free(tree);
139
+ }
140
+
141
+ const git_oid *git_tree_id(git_tree *c)
142
+ {
143
+ return git_object_id((git_object *)c);
144
+ }
145
+
146
+ unsigned int git_tree_entry_attributes(const git_tree_entry *entry)
147
+ {
148
+ return entry->attr;
149
+ }
150
+
151
+ const char *git_tree_entry_name(const git_tree_entry *entry)
152
+ {
153
+ assert(entry);
154
+ return entry->filename;
155
+ }
156
+
157
+ const git_oid *git_tree_entry_id(const git_tree_entry *entry)
158
+ {
159
+ assert(entry);
160
+ return &entry->oid;
161
+ }
162
+
163
+ git_otype git_tree_entry_type(const git_tree_entry *entry)
164
+ {
165
+ assert(entry);
166
+
167
+ if (S_ISGITLINK(entry->attr))
168
+ return GIT_OBJ_COMMIT;
169
+ else if (S_ISDIR(entry->attr))
170
+ return GIT_OBJ_TREE;
171
+ else
172
+ return GIT_OBJ_BLOB;
173
+ }
174
+
175
+ int git_tree_entry_2object(git_object **object_out, git_repository *repo, const git_tree_entry *entry)
176
+ {
177
+ assert(entry && object_out);
178
+ return git_object_lookup(object_out, repo, &entry->oid, GIT_OBJ_ANY);
179
+ }
180
+
181
+ const git_tree_entry *git_tree_entry_byname(git_tree *tree, const char *filename)
182
+ {
183
+ int idx;
184
+
185
+ assert(tree && filename);
186
+
187
+ idx = tree_key_search(&tree->entries, filename);
188
+ if (idx == GIT_ENOTFOUND)
189
+ return NULL;
190
+
191
+ return git_vector_get(&tree->entries, idx);
192
+ }
193
+
194
+ const git_tree_entry *git_tree_entry_byindex(git_tree *tree, unsigned int idx)
195
+ {
196
+ assert(tree);
197
+ return git_vector_get(&tree->entries, idx);
198
+ }
199
+
200
+ unsigned int git_tree_entrycount(git_tree *tree)
201
+ {
202
+ assert(tree);
203
+ return tree->entries.length;
204
+ }
205
+
206
+ static int tree_parse_buffer(git_tree *tree, const char *buffer, const char *buffer_end)
207
+ {
208
+ int error = GIT_SUCCESS;
209
+
210
+ if (git_vector_init(&tree->entries, DEFAULT_TREE_SIZE, entry_sort_cmp) < GIT_SUCCESS)
211
+ return GIT_ENOMEM;
212
+
213
+ while (buffer < buffer_end) {
214
+ git_tree_entry *entry;
215
+ int tmp;
216
+
217
+ entry = git__calloc(1, sizeof(git_tree_entry));
218
+ if (entry == NULL) {
219
+ error = GIT_ENOMEM;
220
+ break;
221
+ }
222
+
223
+ if (git_vector_insert(&tree->entries, entry) < GIT_SUCCESS)
224
+ return GIT_ENOMEM;
225
+
226
+ if (git__strtol32(&tmp, buffer, &buffer, 8) < GIT_SUCCESS ||
227
+ !buffer || !valid_attributes(tmp))
228
+ return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tree. Can't parse attributes");
229
+
230
+ entry->attr = tmp;
231
+
232
+ if (*buffer++ != ' ') {
233
+ error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse tree. Object it corrupted");
234
+ break;
235
+ }
236
+
237
+ if (memchr(buffer, 0, buffer_end - buffer) == NULL) {
238
+ error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse tree. Object it corrupted");
239
+ break;
240
+ }
241
+
242
+ entry->filename = git__strdup(buffer);
243
+ entry->filename_len = strlen(buffer);
244
+
245
+ while (buffer < buffer_end && *buffer != 0)
246
+ buffer++;
247
+
248
+ buffer++;
249
+
250
+ git_oid_fromraw(&entry->oid, (const unsigned char *)buffer);
251
+ buffer += GIT_OID_RAWSZ;
252
+ }
253
+
254
+ return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to parse buffer");
255
+ }
256
+
257
+ int git_tree__parse(git_tree *tree, git_odb_object *obj)
258
+ {
259
+ assert(tree);
260
+ return tree_parse_buffer(tree, (char *)obj->raw.data, (char *)obj->raw.data + obj->raw.len);
261
+ }
262
+
263
+ static unsigned int find_next_dir(const char *dirname, git_index *index, unsigned int start)
264
+ {
265
+ unsigned int i, entries = git_index_entrycount(index);
266
+ size_t dirlen;
267
+
268
+ dirlen = strlen(dirname);
269
+ for (i = start; i < entries; ++i) {
270
+ git_index_entry *entry = git_index_get(index, i);
271
+ if (strlen(entry->path) < dirlen ||
272
+ memcmp(entry->path, dirname, dirlen) ||
273
+ (dirlen > 0 && entry->path[dirlen] != '/')) {
274
+ break;
275
+ }
276
+ }
277
+
278
+ return i;
279
+ }
280
+
281
+ static int append_entry(git_treebuilder *bld, const char *filename, const git_oid *id, unsigned int attributes)
282
+ {
283
+ git_tree_entry *entry;
284
+
285
+ if ((entry = git__malloc(sizeof(git_tree_entry))) == NULL)
286
+ return GIT_ENOMEM;
287
+
288
+ memset(entry, 0x0, sizeof(git_tree_entry));
289
+ entry->filename = git__strdup(filename);
290
+ entry->filename_len = strlen(entry->filename);
291
+
292
+ bld->entry_count++;
293
+
294
+ git_oid_cpy(&entry->oid, id);
295
+ entry->attr = attributes;
296
+
297
+ if (git_vector_insert(&bld->entries, entry) < 0)
298
+ return GIT_ENOMEM;
299
+
300
+ return GIT_SUCCESS;
301
+ }
302
+
303
+ static int write_tree(
304
+ git_oid *oid,
305
+ git_repository *repo,
306
+ git_index *index,
307
+ const char *dirname,
308
+ unsigned int start)
309
+ {
310
+ git_treebuilder *bld = NULL;
311
+
312
+ unsigned int i, entries = git_index_entrycount(index);
313
+ int error;
314
+ size_t dirname_len = strlen(dirname);
315
+ const git_tree_cache *cache;
316
+
317
+ cache = git_tree_cache_get(index->tree, dirname);
318
+ if (cache != NULL && cache->entries >= 0){
319
+ git_oid_cpy(oid, &cache->oid);
320
+ return find_next_dir(dirname, index, start);
321
+ }
322
+
323
+ error = git_treebuilder_create(&bld, NULL);
324
+ if (bld == NULL) {
325
+ return GIT_ENOMEM;
326
+ }
327
+
328
+ /*
329
+ * This loop is unfortunate, but necessary. The index doesn't have
330
+ * any directores, so we need to handle that manually, and we
331
+ * need to keep track of the current position.
332
+ */
333
+ for (i = start; i < entries; ++i) {
334
+ git_index_entry *entry = git_index_get(index, i);
335
+ char *filename, *next_slash;
336
+
337
+ /*
338
+ * If we've left our (sub)tree, exit the loop and return. The
339
+ * first check is an early out (and security for the
340
+ * third). The second check is a simple prefix comparison. The
341
+ * third check catches situations where there is a directory
342
+ * win32/sys and a file win32mmap.c. Without it, the following
343
+ * code believes there is a file win32/mmap.c
344
+ */
345
+ if (strlen(entry->path) < dirname_len ||
346
+ memcmp(entry->path, dirname, dirname_len) ||
347
+ (dirname_len > 0 && entry->path[dirname_len] != '/')) {
348
+ break;
349
+ }
350
+
351
+ filename = entry->path + dirname_len;
352
+ if (*filename == '/')
353
+ filename++;
354
+ next_slash = strchr(filename, '/');
355
+ if (next_slash) {
356
+ git_oid sub_oid;
357
+ int written;
358
+ char *subdir, *last_comp;
359
+
360
+ subdir = git__strndup(entry->path, next_slash - entry->path);
361
+ if (subdir == NULL) {
362
+ error = GIT_ENOMEM;
363
+ goto cleanup;
364
+ }
365
+
366
+ /* Write out the subtree */
367
+ written = write_tree(&sub_oid, repo, index, subdir, i);
368
+ if (written < 0) {
369
+ error = git__rethrow(written, "Failed to write subtree %s", subdir);
370
+ } else {
371
+ i = written - 1; /* -1 because of the loop increment */
372
+ }
373
+
374
+ /*
375
+ * We need to figure out what we want toinsert
376
+ * into this tree. If we're traversing
377
+ * deps/zlib/, then we only want to write
378
+ * 'zlib' into the tree.
379
+ */
380
+ last_comp = strrchr(subdir, '/');
381
+ if (last_comp) {
382
+ last_comp++; /* Get rid of the '/' */
383
+ } else {
384
+ last_comp = subdir;
385
+ }
386
+ error = append_entry(bld, last_comp, &sub_oid, S_IFDIR);
387
+ git__free(subdir);
388
+ if (error < GIT_SUCCESS) {
389
+ error = git__rethrow(error, "Failed to insert dir");
390
+ goto cleanup;
391
+ }
392
+ } else {
393
+ error = append_entry(bld, filename, &entry->oid, entry->mode);
394
+ if (error < GIT_SUCCESS) {
395
+ error = git__rethrow(error, "Failed to insert file");
396
+ }
397
+ }
398
+ }
399
+
400
+ error = git_treebuilder_write(oid, repo, bld);
401
+ if (error < GIT_SUCCESS)
402
+ error = git__rethrow(error, "Failed to write tree to db");
403
+
404
+ cleanup:
405
+ git_treebuilder_free(bld);
406
+
407
+ if (error < GIT_SUCCESS)
408
+ return error;
409
+ else
410
+ return i;
411
+ }
412
+
413
+ int git_tree_create_fromindex(git_oid *oid, git_index *index)
414
+ {
415
+ git_repository *repo;
416
+ int error;
417
+
418
+ repo = (git_repository *)GIT_REFCOUNT_OWNER(index);
419
+
420
+ if (repo == NULL)
421
+ return git__throw(GIT_EBAREINDEX,
422
+ "Failed to create tree. "
423
+ "The index file is not backed up by an existing repository");
424
+
425
+ if (index->tree != NULL && index->tree->entries >= 0) {
426
+ git_oid_cpy(oid, &index->tree->oid);
427
+ return GIT_SUCCESS;
428
+ }
429
+
430
+ /* The tree cache didn't help us */
431
+ error = write_tree(oid, repo, index, "", 0);
432
+ return (error < GIT_SUCCESS) ? git__rethrow(error, "Failed to create tree") : GIT_SUCCESS;
433
+ }
434
+
435
+ static void sort_entries(git_treebuilder *bld)
436
+ {
437
+ git_vector_sort(&bld->entries);
438
+ }
439
+
440
+ int git_treebuilder_create(git_treebuilder **builder_p, const git_tree *source)
441
+ {
442
+ git_treebuilder *bld;
443
+ unsigned int i, source_entries = DEFAULT_TREE_SIZE;
444
+
445
+ assert(builder_p);
446
+
447
+ bld = git__calloc(1, sizeof(git_treebuilder));
448
+ if (bld == NULL)
449
+ return GIT_ENOMEM;
450
+
451
+ if (source != NULL)
452
+ source_entries = source->entries.length;
453
+
454
+ if (git_vector_init(&bld->entries, source_entries, entry_sort_cmp) < GIT_SUCCESS) {
455
+ git__free(bld);
456
+ return GIT_ENOMEM;
457
+ }
458
+
459
+ if (source != NULL) {
460
+ for (i = 0; i < source->entries.length; ++i) {
461
+ git_tree_entry *entry_src = source->entries.contents[i];
462
+
463
+ if (append_entry(bld, entry_src->filename, &entry_src->oid, entry_src->attr) < 0) {
464
+ git_treebuilder_free(bld);
465
+ return GIT_ENOMEM;
466
+ }
467
+ }
468
+ }
469
+
470
+ *builder_p = bld;
471
+ return GIT_SUCCESS;
472
+ }
473
+
474
+ int git_treebuilder_insert(git_tree_entry **entry_out, git_treebuilder *bld, const char *filename, const git_oid *id, unsigned int attributes)
475
+ {
476
+ git_tree_entry *entry;
477
+ int pos;
478
+
479
+ assert(bld && id && filename);
480
+
481
+ if (!valid_attributes(attributes))
482
+ return git__throw(GIT_ERROR, "Failed to insert entry. Invalid attributes");
483
+
484
+ if (!valid_entry_name(filename))
485
+ return git__throw(GIT_ERROR, "Failed to insert entry. Invalid name for a tree entry");
486
+
487
+ pos = tree_key_search(&bld->entries, filename);
488
+
489
+ if (pos >= 0) {
490
+ entry = git_vector_get(&bld->entries, pos);
491
+ if (entry->removed) {
492
+ entry->removed = 0;
493
+ bld->entry_count++;
494
+ }
495
+ } else {
496
+ if ((entry = git__malloc(sizeof(git_tree_entry))) == NULL)
497
+ return GIT_ENOMEM;
498
+
499
+ memset(entry, 0x0, sizeof(git_tree_entry));
500
+ entry->filename = git__strdup(filename);
501
+ entry->filename_len = strlen(entry->filename);
502
+
503
+ bld->entry_count++;
504
+ }
505
+
506
+ git_oid_cpy(&entry->oid, id);
507
+ entry->attr = attributes;
508
+
509
+ if (pos == GIT_ENOTFOUND) {
510
+ if (git_vector_insert(&bld->entries, entry) < 0)
511
+ return GIT_ENOMEM;
512
+ }
513
+
514
+ if (entry_out != NULL)
515
+ *entry_out = entry;
516
+
517
+ return GIT_SUCCESS;
518
+ }
519
+
520
+ static git_tree_entry *treebuilder_get(git_treebuilder *bld, const char *filename)
521
+ {
522
+ int idx;
523
+ git_tree_entry *entry;
524
+
525
+ assert(bld && filename);
526
+
527
+ idx = tree_key_search(&bld->entries, filename);
528
+ if (idx < 0)
529
+ return NULL;
530
+
531
+ entry = git_vector_get(&bld->entries, idx);
532
+ if (entry->removed)
533
+ return NULL;
534
+
535
+ return entry;
536
+ }
537
+
538
+ const git_tree_entry *git_treebuilder_get(git_treebuilder *bld, const char *filename)
539
+ {
540
+ return treebuilder_get(bld, filename);
541
+ }
542
+
543
+ int git_treebuilder_remove(git_treebuilder *bld, const char *filename)
544
+ {
545
+ git_tree_entry *remove_ptr = treebuilder_get(bld, filename);
546
+
547
+ if (remove_ptr == NULL || remove_ptr->removed)
548
+ return git__throw(GIT_ENOTFOUND, "Failed to remove entry. File isn't in the tree");
549
+
550
+ remove_ptr->removed = 1;
551
+ bld->entry_count--;
552
+ return GIT_SUCCESS;
553
+ }
554
+
555
+ int git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *bld)
556
+ {
557
+ unsigned int i;
558
+ int error;
559
+ git_buf tree = GIT_BUF_INIT;
560
+ git_odb *odb;
561
+
562
+ assert(bld);
563
+
564
+ sort_entries(bld);
565
+
566
+ /* Grow the buffer beforehand to an estimated size */
567
+ git_buf_grow(&tree, bld->entries.length * 72);
568
+
569
+ for (i = 0; i < bld->entries.length; ++i) {
570
+ git_tree_entry *entry = bld->entries.contents[i];
571
+
572
+ if (entry->removed)
573
+ continue;
574
+
575
+ git_buf_printf(&tree, "%o ", entry->attr);
576
+ git_buf_put(&tree, entry->filename, entry->filename_len + 1);
577
+ git_buf_put(&tree, (char *)entry->oid.id, GIT_OID_RAWSZ);
578
+ }
579
+
580
+ if (git_buf_oom(&tree)) {
581
+ git_buf_free(&tree);
582
+ return git__throw(GIT_ENOMEM, "Not enough memory to build the tree data");
583
+ }
584
+
585
+ error = git_repository_odb__weakptr(&odb, repo);
586
+ if (error < GIT_SUCCESS) {
587
+ git_buf_free(&tree);
588
+ return error;
589
+ }
590
+
591
+ error = git_odb_write(oid, odb, tree.ptr, tree.size, GIT_OBJ_TREE);
592
+ git_buf_free(&tree);
593
+
594
+ return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to write tree");
595
+ }
596
+
597
+ void git_treebuilder_filter(git_treebuilder *bld, int (*filter)(const git_tree_entry *, void *), void *payload)
598
+ {
599
+ unsigned int i;
600
+
601
+ assert(bld && filter);
602
+
603
+ for (i = 0; i < bld->entries.length; ++i) {
604
+ git_tree_entry *entry = bld->entries.contents[i];
605
+ if (!entry->removed && filter(entry, payload))
606
+ entry->removed = 1;
607
+ }
608
+ }
609
+
610
+ void git_treebuilder_clear(git_treebuilder *bld)
611
+ {
612
+ unsigned int i;
613
+ assert(bld);
614
+
615
+ for (i = 0; i < bld->entries.length; ++i) {
616
+ git_tree_entry *e = bld->entries.contents[i];
617
+ git__free(e->filename);
618
+ git__free(e);
619
+ }
620
+
621
+ git_vector_clear(&bld->entries);
622
+ }
623
+
624
+ void git_treebuilder_free(git_treebuilder *bld)
625
+ {
626
+ git_treebuilder_clear(bld);
627
+ git_vector_free(&bld->entries);
628
+ git__free(bld);
629
+ }
630
+
631
+ static int tree_frompath(
632
+ git_tree **parent_out,
633
+ git_tree *root,
634
+ const char *treeentry_path,
635
+ int offset)
636
+ {
637
+ char *slash_pos = NULL;
638
+ const git_tree_entry* entry;
639
+ int error = GIT_SUCCESS;
640
+ git_tree *subtree;
641
+
642
+ if (!*(treeentry_path + offset))
643
+ return git__rethrow(GIT_EINVALIDPATH,
644
+ "Invalid relative path to a tree entry '%s'.", treeentry_path);
645
+
646
+ slash_pos = (char *)strchr(treeentry_path + offset, '/');
647
+
648
+ if (slash_pos == NULL)
649
+ return git_tree_lookup(
650
+ parent_out,
651
+ root->object.repo,
652
+ git_object_id((const git_object *)root)
653
+ );
654
+
655
+ if (slash_pos == treeentry_path + offset)
656
+ return git__rethrow(GIT_EINVALIDPATH,
657
+ "Invalid relative path to a tree entry '%s'.", treeentry_path);
658
+
659
+ *slash_pos = '\0';
660
+
661
+ entry = git_tree_entry_byname(root, treeentry_path + offset);
662
+
663
+ if (slash_pos != NULL)
664
+ *slash_pos = '/';
665
+
666
+ if (entry == NULL)
667
+ return git__rethrow(GIT_ENOTFOUND,
668
+ "No tree entry can be found from "
669
+ "the given tree and relative path '%s'.", treeentry_path);
670
+
671
+
672
+ error = git_tree_lookup(&subtree, root->object.repo, &entry->oid);
673
+ if (error < GIT_SUCCESS)
674
+ return error;
675
+
676
+ error = tree_frompath(
677
+ parent_out,
678
+ subtree,
679
+ treeentry_path,
680
+ slash_pos - treeentry_path + 1
681
+ );
682
+
683
+ git_tree_free(subtree);
684
+ return error;
685
+ }
686
+
687
+ int git_tree_get_subtree(
688
+ git_tree **subtree,
689
+ git_tree *root,
690
+ const char *subtree_path)
691
+ {
692
+ char buffer[GIT_PATH_MAX];
693
+
694
+ assert(subtree && root && subtree_path);
695
+
696
+ strncpy(buffer, subtree_path, GIT_PATH_MAX);
697
+ return tree_frompath(subtree, root, buffer, 0);
698
+ }
699
+
700
+ static int tree_walk_post(
701
+ git_tree *tree,
702
+ git_treewalk_cb callback,
703
+ char *root,
704
+ size_t root_len,
705
+ void *payload)
706
+ {
707
+ int error;
708
+ unsigned int i;
709
+
710
+ for (i = 0; i < tree->entries.length; ++i) {
711
+ git_tree_entry *entry = tree->entries.contents[i];
712
+
713
+ root[root_len] = '\0';
714
+
715
+ if (callback(root, entry, payload) < 0)
716
+ continue;
717
+
718
+ if (ENTRY_IS_TREE(entry)) {
719
+ git_tree *subtree;
720
+
721
+ if ((error = git_tree_lookup(
722
+ &subtree, tree->object.repo, &entry->oid)) < 0)
723
+ return error;
724
+
725
+ strcpy(root + root_len, entry->filename);
726
+ root[root_len + entry->filename_len] = '/';
727
+
728
+ tree_walk_post(subtree,
729
+ callback, root,
730
+ root_len + entry->filename_len + 1,
731
+ payload
732
+ );
733
+
734
+ git_tree_free(subtree);
735
+ }
736
+ }
737
+
738
+ return GIT_SUCCESS;
739
+ }
740
+
741
+ int git_tree_walk(git_tree *tree, git_treewalk_cb callback, int mode, void *payload)
742
+ {
743
+ char root_path[GIT_PATH_MAX];
744
+
745
+ root_path[0] = '\0';
746
+ switch (mode) {
747
+ case GIT_TREEWALK_POST:
748
+ return tree_walk_post(tree, callback, root_path, 0, payload);
749
+
750
+ case GIT_TREEWALK_PRE:
751
+ return git__throw(GIT_ENOTIMPLEMENTED,
752
+ "Preorder tree walking is still not implemented");
753
+
754
+ default:
755
+ return git__throw(GIT_EINVALIDARGS,
756
+ "Invalid walking mode for tree walk");
757
+ }
758
+ }