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
@@ -0,0 +1,748 @@
1
+ /*
2
+ * Copyright (C) 2009-2012 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 "iterator.h"
9
+ #include "tree.h"
10
+ #include "ignore.h"
11
+ #include "buffer.h"
12
+ #include "git2/submodule.h"
13
+
14
+ #define ITERATOR_BASE_INIT(P,NAME_LC,NAME_UC) do { \
15
+ (P) = git__calloc(1, sizeof(NAME_LC ## _iterator)); \
16
+ GITERR_CHECK_ALLOC(P); \
17
+ (P)->base.type = GIT_ITERATOR_ ## NAME_UC; \
18
+ (P)->base.start = start ? git__strdup(start) : NULL; \
19
+ (P)->base.end = end ? git__strdup(end) : NULL; \
20
+ (P)->base.current = NAME_LC ## _iterator__current; \
21
+ (P)->base.at_end = NAME_LC ## _iterator__at_end; \
22
+ (P)->base.advance = NAME_LC ## _iterator__advance; \
23
+ (P)->base.seek = NAME_LC ## _iterator__seek; \
24
+ (P)->base.reset = NAME_LC ## _iterator__reset; \
25
+ (P)->base.free = NAME_LC ## _iterator__free; \
26
+ if ((start && !(P)->base.start) || (end && !(P)->base.end)) \
27
+ return -1; \
28
+ } while (0)
29
+
30
+
31
+ static int empty_iterator__no_item(
32
+ git_iterator *iter, const git_index_entry **entry)
33
+ {
34
+ GIT_UNUSED(iter);
35
+ *entry = NULL;
36
+ return 0;
37
+ }
38
+
39
+ static int empty_iterator__at_end(git_iterator *iter)
40
+ {
41
+ GIT_UNUSED(iter);
42
+ return 1;
43
+ }
44
+
45
+ static int empty_iterator__noop(git_iterator *iter)
46
+ {
47
+ GIT_UNUSED(iter);
48
+ return 0;
49
+ }
50
+
51
+ static int empty_iterator__seek(git_iterator *iter, const char *prefix)
52
+ {
53
+ GIT_UNUSED(iter);
54
+ GIT_UNUSED(prefix);
55
+ return -1;
56
+ }
57
+
58
+ static void empty_iterator__free(git_iterator *iter)
59
+ {
60
+ GIT_UNUSED(iter);
61
+ }
62
+
63
+ int git_iterator_for_nothing(git_iterator **iter)
64
+ {
65
+ git_iterator *i = git__calloc(1, sizeof(git_iterator));
66
+ GITERR_CHECK_ALLOC(i);
67
+
68
+ i->type = GIT_ITERATOR_EMPTY;
69
+ i->current = empty_iterator__no_item;
70
+ i->at_end = empty_iterator__at_end;
71
+ i->advance = empty_iterator__no_item;
72
+ i->seek = empty_iterator__seek;
73
+ i->reset = empty_iterator__noop;
74
+ i->free = empty_iterator__free;
75
+
76
+ *iter = i;
77
+
78
+ return 0;
79
+ }
80
+
81
+
82
+ typedef struct tree_iterator_frame tree_iterator_frame;
83
+ struct tree_iterator_frame {
84
+ tree_iterator_frame *next;
85
+ git_tree *tree;
86
+ char *start;
87
+ unsigned int index;
88
+ };
89
+
90
+ typedef struct {
91
+ git_iterator base;
92
+ git_repository *repo;
93
+ tree_iterator_frame *stack;
94
+ git_index_entry entry;
95
+ git_buf path;
96
+ bool path_has_filename;
97
+ } tree_iterator;
98
+
99
+ static const git_tree_entry *tree_iterator__tree_entry(tree_iterator *ti)
100
+ {
101
+ return (ti->stack == NULL) ? NULL :
102
+ git_tree_entry_byindex(ti->stack->tree, ti->stack->index);
103
+ }
104
+
105
+ static char *tree_iterator__current_filename(
106
+ tree_iterator *ti, const git_tree_entry *te)
107
+ {
108
+ if (!ti->path_has_filename) {
109
+ if (git_buf_joinpath(&ti->path, ti->path.ptr, te->filename) < 0)
110
+ return NULL;
111
+ ti->path_has_filename = true;
112
+ }
113
+
114
+ return ti->path.ptr;
115
+ }
116
+
117
+ static void tree_iterator__pop_frame(tree_iterator *ti)
118
+ {
119
+ tree_iterator_frame *tf = ti->stack;
120
+ ti->stack = tf->next;
121
+ if (ti->stack != NULL) /* don't free the initial tree */
122
+ git_tree_free(tf->tree);
123
+ git__free(tf);
124
+ }
125
+
126
+ static int tree_iterator__to_end(tree_iterator *ti)
127
+ {
128
+ while (ti->stack && ti->stack->next)
129
+ tree_iterator__pop_frame(ti);
130
+
131
+ if (ti->stack)
132
+ ti->stack->index = git_tree_entrycount(ti->stack->tree);
133
+
134
+ return 0;
135
+ }
136
+
137
+ static int tree_iterator__current(
138
+ git_iterator *self, const git_index_entry **entry)
139
+ {
140
+ tree_iterator *ti = (tree_iterator *)self;
141
+ const git_tree_entry *te = tree_iterator__tree_entry(ti);
142
+
143
+ if (entry)
144
+ *entry = NULL;
145
+
146
+ if (te == NULL)
147
+ return 0;
148
+
149
+ ti->entry.mode = te->attr;
150
+ git_oid_cpy(&ti->entry.oid, &te->oid);
151
+
152
+ ti->entry.path = tree_iterator__current_filename(ti, te);
153
+ if (ti->entry.path == NULL)
154
+ return -1;
155
+
156
+ if (ti->base.end && git__prefixcmp(ti->entry.path, ti->base.end) > 0)
157
+ return tree_iterator__to_end(ti);
158
+
159
+ if (entry)
160
+ *entry = &ti->entry;
161
+
162
+ return 0;
163
+ }
164
+
165
+ static int tree_iterator__at_end(git_iterator *self)
166
+ {
167
+ return (tree_iterator__tree_entry((tree_iterator *)self) == NULL);
168
+ }
169
+
170
+ static tree_iterator_frame *tree_iterator__alloc_frame(
171
+ git_tree *tree, char *start)
172
+ {
173
+ tree_iterator_frame *tf = git__calloc(1, sizeof(tree_iterator_frame));
174
+ if (!tf)
175
+ return NULL;
176
+
177
+ tf->tree = tree;
178
+
179
+ if (start && *start) {
180
+ tf->start = start;
181
+ tf->index = git_tree__prefix_position(tree, start);
182
+ }
183
+
184
+ return tf;
185
+ }
186
+
187
+ static int tree_iterator__expand_tree(tree_iterator *ti)
188
+ {
189
+ int error;
190
+ git_tree *subtree;
191
+ const git_tree_entry *te = tree_iterator__tree_entry(ti);
192
+ tree_iterator_frame *tf;
193
+ char *relpath;
194
+
195
+ while (te != NULL && git_tree_entry__is_tree(te)) {
196
+ if (git_buf_joinpath(&ti->path, ti->path.ptr, te->filename) < 0)
197
+ return -1;
198
+
199
+ /* check that we have not passed the range end */
200
+ if (ti->base.end != NULL &&
201
+ git__prefixcmp(ti->path.ptr, ti->base.end) > 0)
202
+ return tree_iterator__to_end(ti);
203
+
204
+ if ((error = git_tree_lookup(&subtree, ti->repo, &te->oid)) < 0)
205
+ return error;
206
+
207
+ relpath = NULL;
208
+
209
+ /* apply range start to new frame if relevant */
210
+ if (ti->stack->start &&
211
+ git__prefixcmp(ti->stack->start, te->filename) == 0)
212
+ {
213
+ size_t namelen = strlen(te->filename);
214
+ if (ti->stack->start[namelen] == '/')
215
+ relpath = ti->stack->start + namelen + 1;
216
+ }
217
+
218
+ if ((tf = tree_iterator__alloc_frame(subtree, relpath)) == NULL)
219
+ return -1;
220
+
221
+ tf->next = ti->stack;
222
+ ti->stack = tf;
223
+
224
+ te = tree_iterator__tree_entry(ti);
225
+ }
226
+
227
+ return 0;
228
+ }
229
+
230
+ static int tree_iterator__advance(
231
+ git_iterator *self, const git_index_entry **entry)
232
+ {
233
+ int error = 0;
234
+ tree_iterator *ti = (tree_iterator *)self;
235
+ const git_tree_entry *te = NULL;
236
+
237
+ if (entry != NULL)
238
+ *entry = NULL;
239
+
240
+ if (ti->path_has_filename) {
241
+ git_buf_rtruncate_at_char(&ti->path, '/');
242
+ ti->path_has_filename = false;
243
+ }
244
+
245
+ while (ti->stack != NULL) {
246
+ te = git_tree_entry_byindex(ti->stack->tree, ++ti->stack->index);
247
+ if (te != NULL)
248
+ break;
249
+
250
+ tree_iterator__pop_frame(ti);
251
+
252
+ git_buf_rtruncate_at_char(&ti->path, '/');
253
+ }
254
+
255
+ if (te && git_tree_entry__is_tree(te))
256
+ error = tree_iterator__expand_tree(ti);
257
+
258
+ if (!error)
259
+ error = tree_iterator__current(self, entry);
260
+
261
+ return error;
262
+ }
263
+
264
+ static int tree_iterator__seek(git_iterator *self, const char *prefix)
265
+ {
266
+ GIT_UNUSED(self);
267
+ GIT_UNUSED(prefix);
268
+ /* pop stack until matches prefix */
269
+ /* seek item in current frame matching prefix */
270
+ /* push stack which matches prefix */
271
+ return -1;
272
+ }
273
+
274
+ static void tree_iterator__free(git_iterator *self)
275
+ {
276
+ tree_iterator *ti = (tree_iterator *)self;
277
+ while (ti->stack != NULL)
278
+ tree_iterator__pop_frame(ti);
279
+ git_buf_free(&ti->path);
280
+ }
281
+
282
+ static int tree_iterator__reset(git_iterator *self)
283
+ {
284
+ tree_iterator *ti = (tree_iterator *)self;
285
+
286
+ while (ti->stack && ti->stack->next)
287
+ tree_iterator__pop_frame(ti);
288
+
289
+ if (ti->stack)
290
+ ti->stack->index =
291
+ git_tree__prefix_position(ti->stack->tree, ti->base.start);
292
+
293
+ git_buf_clear(&ti->path);
294
+
295
+ return tree_iterator__expand_tree(ti);
296
+ }
297
+
298
+ int git_iterator_for_tree_range(
299
+ git_iterator **iter,
300
+ git_repository *repo,
301
+ git_tree *tree,
302
+ const char *start,
303
+ const char *end)
304
+ {
305
+ int error;
306
+ tree_iterator *ti;
307
+
308
+ if (tree == NULL)
309
+ return git_iterator_for_nothing(iter);
310
+
311
+ ITERATOR_BASE_INIT(ti, tree, TREE);
312
+
313
+ ti->repo = repo;
314
+ ti->stack = tree_iterator__alloc_frame(tree, ti->base.start);
315
+
316
+ if ((error = tree_iterator__expand_tree(ti)) < 0)
317
+ git_iterator_free((git_iterator *)ti);
318
+ else
319
+ *iter = (git_iterator *)ti;
320
+
321
+ return error;
322
+ }
323
+
324
+
325
+ typedef struct {
326
+ git_iterator base;
327
+ git_index *index;
328
+ unsigned int current;
329
+ } index_iterator;
330
+
331
+ static int index_iterator__current(
332
+ git_iterator *self, const git_index_entry **entry)
333
+ {
334
+ index_iterator *ii = (index_iterator *)self;
335
+ git_index_entry *ie = git_index_get(ii->index, ii->current);
336
+
337
+ if (ie != NULL &&
338
+ ii->base.end != NULL &&
339
+ git__prefixcmp(ie->path, ii->base.end) > 0)
340
+ {
341
+ ii->current = git_index_entrycount(ii->index);
342
+ ie = NULL;
343
+ }
344
+
345
+ if (entry)
346
+ *entry = ie;
347
+
348
+ return 0;
349
+ }
350
+
351
+ static int index_iterator__at_end(git_iterator *self)
352
+ {
353
+ index_iterator *ii = (index_iterator *)self;
354
+ return (ii->current >= git_index_entrycount(ii->index));
355
+ }
356
+
357
+ static int index_iterator__advance(
358
+ git_iterator *self, const git_index_entry **entry)
359
+ {
360
+ index_iterator *ii = (index_iterator *)self;
361
+
362
+ if (ii->current < git_index_entrycount(ii->index))
363
+ ii->current++;
364
+
365
+ return index_iterator__current(self, entry);
366
+ }
367
+
368
+ static int index_iterator__seek(git_iterator *self, const char *prefix)
369
+ {
370
+ GIT_UNUSED(self);
371
+ GIT_UNUSED(prefix);
372
+ /* find last item before prefix */
373
+ return -1;
374
+ }
375
+
376
+ static int index_iterator__reset(git_iterator *self)
377
+ {
378
+ index_iterator *ii = (index_iterator *)self;
379
+ ii->current = 0;
380
+ return 0;
381
+ }
382
+
383
+ static void index_iterator__free(git_iterator *self)
384
+ {
385
+ index_iterator *ii = (index_iterator *)self;
386
+ git_index_free(ii->index);
387
+ ii->index = NULL;
388
+ }
389
+
390
+ int git_iterator_for_index_range(
391
+ git_iterator **iter,
392
+ git_repository *repo,
393
+ const char *start,
394
+ const char *end)
395
+ {
396
+ int error;
397
+ index_iterator *ii;
398
+
399
+ ITERATOR_BASE_INIT(ii, index, INDEX);
400
+
401
+ if ((error = git_repository_index(&ii->index, repo)) < 0)
402
+ git__free(ii);
403
+ else {
404
+ ii->current = start ? git_index__prefix_position(ii->index, start) : 0;
405
+ *iter = (git_iterator *)ii;
406
+ }
407
+
408
+ return error;
409
+ }
410
+
411
+
412
+ typedef struct workdir_iterator_frame workdir_iterator_frame;
413
+ struct workdir_iterator_frame {
414
+ workdir_iterator_frame *next;
415
+ git_vector entries;
416
+ unsigned int index;
417
+ char *start;
418
+ };
419
+
420
+ typedef struct {
421
+ git_iterator base;
422
+ git_repository *repo;
423
+ size_t root_len;
424
+ workdir_iterator_frame *stack;
425
+ git_ignores ignores;
426
+ git_index_entry entry;
427
+ git_buf path;
428
+ int is_ignored;
429
+ } workdir_iterator;
430
+
431
+ static workdir_iterator_frame *workdir_iterator__alloc_frame(void)
432
+ {
433
+ workdir_iterator_frame *wf = git__calloc(1, sizeof(workdir_iterator_frame));
434
+ if (wf == NULL)
435
+ return NULL;
436
+ if (git_vector_init(&wf->entries, 0, git_path_with_stat_cmp) != 0) {
437
+ git__free(wf);
438
+ return NULL;
439
+ }
440
+ return wf;
441
+ }
442
+
443
+ static void workdir_iterator__free_frame(workdir_iterator_frame *wf)
444
+ {
445
+ unsigned int i;
446
+ git_path_with_stat *path;
447
+
448
+ git_vector_foreach(&wf->entries, i, path)
449
+ git__free(path);
450
+ git_vector_free(&wf->entries);
451
+ git__free(wf);
452
+ }
453
+
454
+ static int workdir_iterator__update_entry(workdir_iterator *wi);
455
+
456
+ static int workdir_iterator__entry_cmp(const void *prefix, const void *item)
457
+ {
458
+ const git_path_with_stat *ps = item;
459
+ return git__prefixcmp((const char *)prefix, ps->path);
460
+ }
461
+
462
+ static int workdir_iterator__expand_dir(workdir_iterator *wi)
463
+ {
464
+ int error;
465
+ workdir_iterator_frame *wf = workdir_iterator__alloc_frame();
466
+ GITERR_CHECK_ALLOC(wf);
467
+
468
+ error = git_path_dirload_with_stat(wi->path.ptr, wi->root_len, &wf->entries);
469
+ if (error < 0 || wf->entries.length == 0) {
470
+ workdir_iterator__free_frame(wf);
471
+ return GIT_ENOTFOUND;
472
+ }
473
+
474
+ git_vector_sort(&wf->entries);
475
+
476
+ if (!wi->stack)
477
+ wf->start = wi->base.start;
478
+ else if (wi->stack->start &&
479
+ git__prefixcmp(wi->stack->start, wi->path.ptr + wi->root_len) == 0)
480
+ wf->start = wi->stack->start;
481
+
482
+ if (wf->start)
483
+ git_vector_bsearch3(
484
+ &wf->index, &wf->entries, workdir_iterator__entry_cmp, wf->start);
485
+
486
+ wf->next = wi->stack;
487
+ wi->stack = wf;
488
+
489
+ /* only push new ignores if this is not top level directory */
490
+ if (wi->stack->next != NULL) {
491
+ ssize_t slash_pos = git_buf_rfind_next(&wi->path, '/');
492
+ (void)git_ignore__push_dir(&wi->ignores, &wi->path.ptr[slash_pos + 1]);
493
+ }
494
+
495
+ return workdir_iterator__update_entry(wi);
496
+ }
497
+
498
+ static int workdir_iterator__current(
499
+ git_iterator *self, const git_index_entry **entry)
500
+ {
501
+ workdir_iterator *wi = (workdir_iterator *)self;
502
+ *entry = (wi->entry.path == NULL) ? NULL : &wi->entry;
503
+ return 0;
504
+ }
505
+
506
+ static int workdir_iterator__at_end(git_iterator *self)
507
+ {
508
+ return (((workdir_iterator *)self)->entry.path == NULL);
509
+ }
510
+
511
+ static int workdir_iterator__advance(
512
+ git_iterator *self, const git_index_entry **entry)
513
+ {
514
+ int error;
515
+ workdir_iterator *wi = (workdir_iterator *)self;
516
+ workdir_iterator_frame *wf;
517
+ git_path_with_stat *next;
518
+
519
+ if (entry != NULL)
520
+ *entry = NULL;
521
+
522
+ if (wi->entry.path == NULL)
523
+ return 0;
524
+
525
+ while ((wf = wi->stack) != NULL) {
526
+ next = git_vector_get(&wf->entries, ++wf->index);
527
+ if (next != NULL) {
528
+ if (strcmp(next->path, DOT_GIT "/") == 0)
529
+ continue;
530
+ /* else found a good entry */
531
+ break;
532
+ }
533
+
534
+ /* pop workdir directory stack */
535
+ wi->stack = wf->next;
536
+ workdir_iterator__free_frame(wf);
537
+ git_ignore__pop_dir(&wi->ignores);
538
+
539
+ if (wi->stack == NULL) {
540
+ memset(&wi->entry, 0, sizeof(wi->entry));
541
+ return 0;
542
+ }
543
+ }
544
+
545
+ error = workdir_iterator__update_entry(wi);
546
+
547
+ if (!error && entry != NULL)
548
+ error = workdir_iterator__current(self, entry);
549
+
550
+ return error;
551
+ }
552
+
553
+ static int workdir_iterator__seek(git_iterator *self, const char *prefix)
554
+ {
555
+ GIT_UNUSED(self);
556
+ GIT_UNUSED(prefix);
557
+ /* pop stack until matching prefix */
558
+ /* find prefix item in current frame */
559
+ /* push subdirectories as deep as possible while matching */
560
+ return 0;
561
+ }
562
+
563
+ static int workdir_iterator__reset(git_iterator *self)
564
+ {
565
+ workdir_iterator *wi = (workdir_iterator *)self;
566
+ while (wi->stack != NULL && wi->stack->next != NULL) {
567
+ workdir_iterator_frame *wf = wi->stack;
568
+ wi->stack = wf->next;
569
+ workdir_iterator__free_frame(wf);
570
+ git_ignore__pop_dir(&wi->ignores);
571
+ }
572
+ if (wi->stack)
573
+ wi->stack->index = 0;
574
+ return 0;
575
+ }
576
+
577
+ static void workdir_iterator__free(git_iterator *self)
578
+ {
579
+ workdir_iterator *wi = (workdir_iterator *)self;
580
+
581
+ while (wi->stack != NULL) {
582
+ workdir_iterator_frame *wf = wi->stack;
583
+ wi->stack = wf->next;
584
+ workdir_iterator__free_frame(wf);
585
+ }
586
+
587
+ git_ignore__free(&wi->ignores);
588
+ git_buf_free(&wi->path);
589
+ }
590
+
591
+ static int workdir_iterator__update_entry(workdir_iterator *wi)
592
+ {
593
+ git_path_with_stat *ps = git_vector_get(&wi->stack->entries, wi->stack->index);
594
+
595
+ git_buf_truncate(&wi->path, wi->root_len);
596
+ memset(&wi->entry, 0, sizeof(wi->entry));
597
+
598
+ if (!ps)
599
+ return 0;
600
+
601
+ if (git_buf_put(&wi->path, ps->path, ps->path_len) < 0)
602
+ return -1;
603
+
604
+ if (wi->base.end &&
605
+ git__prefixcmp(wi->path.ptr + wi->root_len, wi->base.end) > 0)
606
+ return 0;
607
+
608
+ wi->entry.path = ps->path;
609
+
610
+ /* skip over .git directory */
611
+ if (strcmp(ps->path, DOT_GIT "/") == 0)
612
+ return workdir_iterator__advance((git_iterator *)wi, NULL);
613
+
614
+ /* if there is an error processing the entry, treat as ignored */
615
+ wi->is_ignored = 1;
616
+
617
+ git_index__init_entry_from_stat(&ps->st, &wi->entry);
618
+
619
+ /* need different mode here to keep directories during iteration */
620
+ wi->entry.mode = git_futils_canonical_mode(ps->st.st_mode);
621
+
622
+ /* if this is a file type we don't handle, treat as ignored */
623
+ if (wi->entry.mode == 0)
624
+ return 0;
625
+
626
+ /* okay, we are far enough along to look up real ignore rule */
627
+ if (git_ignore__lookup(&wi->ignores, wi->entry.path, &wi->is_ignored) < 0)
628
+ return 0; /* if error, ignore it and ignore file */
629
+
630
+ /* detect submodules */
631
+ if (S_ISDIR(wi->entry.mode)) {
632
+ bool is_submodule = git_path_contains(&wi->path, DOT_GIT);
633
+
634
+ /* if there is no .git, still check submodules data */
635
+ if (!is_submodule) {
636
+ int res = git_submodule_lookup(NULL, wi->repo, wi->entry.path);
637
+ is_submodule = (res == 0);
638
+ if (res == GIT_ENOTFOUND)
639
+ giterr_clear();
640
+ }
641
+
642
+ /* if submodule, mark as GITLINK and remove trailing slash */
643
+ if (is_submodule) {
644
+ size_t len = strlen(wi->entry.path);
645
+ assert(wi->entry.path[len - 1] == '/');
646
+ wi->entry.path[len - 1] = '\0';
647
+ wi->entry.mode = S_IFGITLINK;
648
+ }
649
+ }
650
+
651
+ return 0;
652
+ }
653
+
654
+ int git_iterator_for_workdir_range(
655
+ git_iterator **iter,
656
+ git_repository *repo,
657
+ const char *start,
658
+ const char *end)
659
+ {
660
+ int error;
661
+ workdir_iterator *wi;
662
+
663
+ assert(iter && repo);
664
+
665
+ if (git_repository_is_bare(repo)) {
666
+ giterr_set(GITERR_INVALID,
667
+ "Cannot scan working directory for bare repo");
668
+ return -1;
669
+ }
670
+
671
+ ITERATOR_BASE_INIT(wi, workdir, WORKDIR);
672
+
673
+ wi->repo = repo;
674
+
675
+ if (git_buf_sets(&wi->path, git_repository_workdir(repo)) < 0 ||
676
+ git_path_to_dir(&wi->path) < 0 ||
677
+ git_ignore__for_path(repo, "", &wi->ignores) < 0)
678
+ {
679
+ git__free(wi);
680
+ return -1;
681
+ }
682
+
683
+ wi->root_len = wi->path.size;
684
+
685
+ if ((error = workdir_iterator__expand_dir(wi)) < 0) {
686
+ if (error == GIT_ENOTFOUND)
687
+ error = 0;
688
+ else {
689
+ git_iterator_free((git_iterator *)wi);
690
+ wi = NULL;
691
+ }
692
+ }
693
+
694
+ *iter = (git_iterator *)wi;
695
+
696
+ return error;
697
+ }
698
+
699
+
700
+ int git_iterator_current_tree_entry(
701
+ git_iterator *iter, const git_tree_entry **tree_entry)
702
+ {
703
+ *tree_entry = (iter->type != GIT_ITERATOR_TREE) ? NULL :
704
+ tree_iterator__tree_entry((tree_iterator *)iter);
705
+ return 0;
706
+ }
707
+
708
+ int git_iterator_current_is_ignored(git_iterator *iter)
709
+ {
710
+ return (iter->type != GIT_ITERATOR_WORKDIR) ? 0 :
711
+ ((workdir_iterator *)iter)->is_ignored;
712
+ }
713
+
714
+ int git_iterator_advance_into_directory(
715
+ git_iterator *iter, const git_index_entry **entry)
716
+ {
717
+ workdir_iterator *wi = (workdir_iterator *)iter;
718
+
719
+ if (iter->type == GIT_ITERATOR_WORKDIR &&
720
+ wi->entry.path &&
721
+ S_ISDIR(wi->entry.mode) &&
722
+ !S_ISGITLINK(wi->entry.mode))
723
+ {
724
+ if (workdir_iterator__expand_dir(wi) < 0)
725
+ /* if error loading or if empty, skip the directory. */
726
+ return workdir_iterator__advance(iter, entry);
727
+ }
728
+
729
+ return entry ? git_iterator_current(iter, entry) : 0;
730
+ }
731
+
732
+ int git_iterator_cmp(
733
+ git_iterator *iter, const char *path_prefix)
734
+ {
735
+ const git_index_entry *entry;
736
+
737
+ /* a "done" iterator is after every prefix */
738
+ if (git_iterator_current(iter, &entry) < 0 ||
739
+ entry == NULL)
740
+ return 1;
741
+
742
+ /* a NULL prefix is after any valid iterator */
743
+ if (!path_prefix)
744
+ return -1;
745
+
746
+ return git__prefixcmp(entry->path, path_prefix);
747
+ }
748
+