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,677 @@
1
+ #include "repository.h"
2
+ #include "fileops.h"
3
+ #include "config.h"
4
+ #include <ctype.h>
5
+
6
+ GIT__USE_STRMAP;
7
+
8
+ static int collect_attr_files(
9
+ git_repository *repo,
10
+ uint32_t flags,
11
+ const char *path,
12
+ git_vector *files);
13
+
14
+
15
+ int git_attr_get(
16
+ const char **value,
17
+ git_repository *repo,
18
+ uint32_t flags,
19
+ const char *pathname,
20
+ const char *name)
21
+ {
22
+ int error;
23
+ git_attr_path path;
24
+ git_vector files = GIT_VECTOR_INIT;
25
+ unsigned int i, j;
26
+ git_attr_file *file;
27
+ git_attr_name attr;
28
+ git_attr_rule *rule;
29
+
30
+ *value = NULL;
31
+
32
+ if (git_attr_path__init(&path, pathname, git_repository_workdir(repo)) < 0)
33
+ return -1;
34
+
35
+ if ((error = collect_attr_files(repo, flags, pathname, &files)) < 0)
36
+ goto cleanup;
37
+
38
+ attr.name = name;
39
+ attr.name_hash = git_attr_file__name_hash(name);
40
+
41
+ git_vector_foreach(&files, i, file) {
42
+
43
+ git_attr_file__foreach_matching_rule(file, &path, j, rule) {
44
+ int pos = git_vector_bsearch(&rule->assigns, &attr);
45
+ if (pos >= 0) {
46
+ *value = ((git_attr_assignment *)git_vector_get(
47
+ &rule->assigns, pos))->value;
48
+ goto cleanup;
49
+ }
50
+ }
51
+ }
52
+
53
+ cleanup:
54
+ git_vector_free(&files);
55
+ git_attr_path__free(&path);
56
+
57
+ return error;
58
+ }
59
+
60
+
61
+ typedef struct {
62
+ git_attr_name name;
63
+ git_attr_assignment *found;
64
+ } attr_get_many_info;
65
+
66
+ int git_attr_get_many(
67
+ const char **values,
68
+ git_repository *repo,
69
+ uint32_t flags,
70
+ const char *pathname,
71
+ size_t num_attr,
72
+ const char **names)
73
+ {
74
+ int error;
75
+ git_attr_path path;
76
+ git_vector files = GIT_VECTOR_INIT;
77
+ unsigned int i, j, k;
78
+ git_attr_file *file;
79
+ git_attr_rule *rule;
80
+ attr_get_many_info *info = NULL;
81
+ size_t num_found = 0;
82
+
83
+ memset((void *)values, 0, sizeof(const char *) * num_attr);
84
+
85
+ if (git_attr_path__init(&path, pathname, git_repository_workdir(repo)) < 0)
86
+ return -1;
87
+
88
+ if ((error = collect_attr_files(repo, flags, pathname, &files)) < 0)
89
+ goto cleanup;
90
+
91
+ info = git__calloc(num_attr, sizeof(attr_get_many_info));
92
+ GITERR_CHECK_ALLOC(info);
93
+
94
+ git_vector_foreach(&files, i, file) {
95
+
96
+ git_attr_file__foreach_matching_rule(file, &path, j, rule) {
97
+
98
+ for (k = 0; k < num_attr; k++) {
99
+ int pos;
100
+
101
+ if (info[k].found != NULL) /* already found assignment */
102
+ continue;
103
+
104
+ if (!info[k].name.name) {
105
+ info[k].name.name = names[k];
106
+ info[k].name.name_hash = git_attr_file__name_hash(names[k]);
107
+ }
108
+
109
+ pos = git_vector_bsearch(&rule->assigns, &info[k].name);
110
+ if (pos >= 0) {
111
+ info[k].found = (git_attr_assignment *)
112
+ git_vector_get(&rule->assigns, pos);
113
+ values[k] = info[k].found->value;
114
+
115
+ if (++num_found == num_attr)
116
+ goto cleanup;
117
+ }
118
+ }
119
+ }
120
+ }
121
+
122
+ cleanup:
123
+ git_vector_free(&files);
124
+ git_attr_path__free(&path);
125
+ git__free(info);
126
+
127
+ return error;
128
+ }
129
+
130
+
131
+ int git_attr_foreach(
132
+ git_repository *repo,
133
+ uint32_t flags,
134
+ const char *pathname,
135
+ int (*callback)(const char *name, const char *value, void *payload),
136
+ void *payload)
137
+ {
138
+ int error;
139
+ git_attr_path path;
140
+ git_vector files = GIT_VECTOR_INIT;
141
+ unsigned int i, j, k;
142
+ git_attr_file *file;
143
+ git_attr_rule *rule;
144
+ git_attr_assignment *assign;
145
+ git_strmap *seen = NULL;
146
+
147
+ if (git_attr_path__init(&path, pathname, git_repository_workdir(repo)) < 0)
148
+ return -1;
149
+
150
+ if ((error = collect_attr_files(repo, flags, pathname, &files)) < 0)
151
+ goto cleanup;
152
+
153
+ seen = git_strmap_alloc();
154
+ GITERR_CHECK_ALLOC(seen);
155
+
156
+ git_vector_foreach(&files, i, file) {
157
+
158
+ git_attr_file__foreach_matching_rule(file, &path, j, rule) {
159
+
160
+ git_vector_foreach(&rule->assigns, k, assign) {
161
+ /* skip if higher priority assignment was already seen */
162
+ if (git_strmap_exists(seen, assign->name))
163
+ continue;
164
+
165
+ git_strmap_insert(seen, assign->name, assign, error);
166
+ if (error >= 0)
167
+ error = callback(assign->name, assign->value, payload);
168
+
169
+ if (error != 0)
170
+ goto cleanup;
171
+ }
172
+ }
173
+ }
174
+
175
+ cleanup:
176
+ git_strmap_free(seen);
177
+ git_vector_free(&files);
178
+ git_attr_path__free(&path);
179
+
180
+ return error;
181
+ }
182
+
183
+
184
+ int git_attr_add_macro(
185
+ git_repository *repo,
186
+ const char *name,
187
+ const char *values)
188
+ {
189
+ int error;
190
+ git_attr_rule *macro = NULL;
191
+ git_pool *pool;
192
+
193
+ if (git_attr_cache__init(repo) < 0)
194
+ return -1;
195
+
196
+ macro = git__calloc(1, sizeof(git_attr_rule));
197
+ GITERR_CHECK_ALLOC(macro);
198
+
199
+ pool = &git_repository_attr_cache(repo)->pool;
200
+
201
+ macro->match.pattern = git_pool_strdup(pool, name);
202
+ GITERR_CHECK_ALLOC(macro->match.pattern);
203
+
204
+ macro->match.length = strlen(macro->match.pattern);
205
+ macro->match.flags = GIT_ATTR_FNMATCH_MACRO;
206
+
207
+ error = git_attr_assignment__parse(repo, pool, &macro->assigns, &values);
208
+
209
+ if (!error)
210
+ error = git_attr_cache__insert_macro(repo, macro);
211
+
212
+ if (error < 0)
213
+ git_attr_rule__free(macro);
214
+
215
+ return error;
216
+ }
217
+
218
+ bool git_attr_cache__is_cached(
219
+ git_repository *repo, git_attr_file_source source, const char *path)
220
+ {
221
+ git_buf cache_key = GIT_BUF_INIT;
222
+ git_strmap *files = git_repository_attr_cache(repo)->files;
223
+ const char *workdir = git_repository_workdir(repo);
224
+ bool rval;
225
+
226
+ if (workdir && git__prefixcmp(path, workdir) == 0)
227
+ path += strlen(workdir);
228
+ if (git_buf_printf(&cache_key, "%d#%s", (int)source, path) < 0)
229
+ return false;
230
+
231
+ rval = git_strmap_exists(files, git_buf_cstr(&cache_key));
232
+
233
+ git_buf_free(&cache_key);
234
+
235
+ return rval;
236
+ }
237
+
238
+ static int load_attr_file(
239
+ const char **data,
240
+ git_attr_file_stat_sig *sig,
241
+ const char *filename)
242
+ {
243
+ int error;
244
+ git_buf content = GIT_BUF_INIT;
245
+ struct stat st;
246
+
247
+ if (p_stat(filename, &st) < 0)
248
+ return GIT_ENOTFOUND;
249
+
250
+ if (sig != NULL &&
251
+ (git_time_t)st.st_mtime == sig->seconds &&
252
+ (git_off_t)st.st_size == sig->size &&
253
+ (unsigned int)st.st_ino == sig->ino)
254
+ return GIT_ENOTFOUND;
255
+
256
+ error = git_futils_readbuffer_updated(&content, filename, NULL, NULL);
257
+ if (error < 0)
258
+ return error;
259
+
260
+ if (sig != NULL) {
261
+ sig->seconds = (git_time_t)st.st_mtime;
262
+ sig->size = (git_off_t)st.st_size;
263
+ sig->ino = (unsigned int)st.st_ino;
264
+ }
265
+
266
+ *data = git_buf_detach(&content);
267
+
268
+ return 0;
269
+ }
270
+
271
+ static int load_attr_blob_from_index(
272
+ const char **content,
273
+ git_blob **blob,
274
+ git_repository *repo,
275
+ const git_oid *old_oid,
276
+ const char *relfile)
277
+ {
278
+ int error;
279
+ git_index *index;
280
+ git_index_entry *entry;
281
+
282
+ if ((error = git_repository_index__weakptr(&index, repo)) < 0 ||
283
+ (error = git_index_find(index, relfile)) < 0)
284
+ return error;
285
+
286
+ entry = git_index_get(index, error);
287
+
288
+ if (old_oid && git_oid_cmp(old_oid, &entry->oid) == 0)
289
+ return GIT_ENOTFOUND;
290
+
291
+ if ((error = git_blob_lookup(blob, repo, &entry->oid)) < 0)
292
+ return error;
293
+
294
+ *content = git_blob_rawcontent(*blob);
295
+ return 0;
296
+ }
297
+
298
+ static int load_attr_from_cache(
299
+ git_attr_file **file,
300
+ git_attr_cache *cache,
301
+ git_attr_file_source source,
302
+ const char *relative_path)
303
+ {
304
+ git_buf cache_key = GIT_BUF_INIT;
305
+ khiter_t cache_pos;
306
+
307
+ *file = NULL;
308
+
309
+ if (!cache || !cache->files)
310
+ return 0;
311
+
312
+ if (git_buf_printf(&cache_key, "%d#%s", (int)source, relative_path) < 0)
313
+ return -1;
314
+
315
+ cache_pos = git_strmap_lookup_index(cache->files, cache_key.ptr);
316
+
317
+ git_buf_free(&cache_key);
318
+
319
+ if (git_strmap_valid_index(cache->files, cache_pos))
320
+ *file = git_strmap_value_at(cache->files, cache_pos);
321
+
322
+ return 0;
323
+ }
324
+
325
+ int git_attr_cache__internal_file(
326
+ git_repository *repo,
327
+ const char *filename,
328
+ git_attr_file **file)
329
+ {
330
+ int error = 0;
331
+ git_attr_cache *cache = git_repository_attr_cache(repo);
332
+ khiter_t cache_pos = git_strmap_lookup_index(cache->files, filename);
333
+
334
+ if (git_strmap_valid_index(cache->files, cache_pos)) {
335
+ *file = git_strmap_value_at(cache->files, cache_pos);
336
+ return 0;
337
+ }
338
+
339
+ if (git_attr_file__new(file, 0, filename, &cache->pool) < 0)
340
+ return -1;
341
+
342
+ git_strmap_insert(cache->files, (*file)->key + 2, *file, error);
343
+ if (error > 0)
344
+ error = 0;
345
+
346
+ return error;
347
+ }
348
+
349
+ int git_attr_cache__push_file(
350
+ git_repository *repo,
351
+ const char *base,
352
+ const char *filename,
353
+ git_attr_file_source source,
354
+ git_attr_file_parser parse,
355
+ git_vector *stack)
356
+ {
357
+ int error = 0;
358
+ git_buf path = GIT_BUF_INIT;
359
+ const char *workdir = git_repository_workdir(repo);
360
+ const char *relfile, *content = NULL;
361
+ git_attr_cache *cache = git_repository_attr_cache(repo);
362
+ git_attr_file *file = NULL;
363
+ git_blob *blob = NULL;
364
+ git_attr_file_stat_sig st;
365
+
366
+ assert(filename && stack);
367
+
368
+ /* join base and path as needed */
369
+ if (base != NULL && git_path_root(filename) < 0) {
370
+ if (git_buf_joinpath(&path, base, filename) < 0)
371
+ return -1;
372
+ filename = path.ptr;
373
+ }
374
+
375
+ relfile = filename;
376
+ if (workdir && git__prefixcmp(relfile, workdir) == 0)
377
+ relfile += strlen(workdir);
378
+
379
+ /* check cache */
380
+ if (load_attr_from_cache(&file, cache, source, relfile) < 0)
381
+ return -1;
382
+
383
+ /* if not in cache, load data, parse, and cache */
384
+
385
+ if (source == GIT_ATTR_FILE_FROM_FILE) {
386
+ if (file)
387
+ memcpy(&st, &file->cache_data.st, sizeof(st));
388
+ else
389
+ memset(&st, 0, sizeof(st));
390
+
391
+ error = load_attr_file(&content, &st, filename);
392
+ } else {
393
+ error = load_attr_blob_from_index(&content, &blob,
394
+ repo, file ? &file->cache_data.oid : NULL, relfile);
395
+ }
396
+
397
+ if (error) {
398
+ /* not finding a file is not an error for this function */
399
+ if (error == GIT_ENOTFOUND) {
400
+ giterr_clear();
401
+ error = 0;
402
+ }
403
+ goto finish;
404
+ }
405
+
406
+ /* if we got here, we have to parse and/or reparse the file */
407
+ if (file)
408
+ git_attr_file__clear_rules(file);
409
+ else {
410
+ error = git_attr_file__new(&file, source, relfile, &cache->pool);
411
+ if (error < 0)
412
+ goto finish;
413
+ }
414
+
415
+ if (parse && (error = parse(repo, content, file)) < 0)
416
+ goto finish;
417
+
418
+ git_strmap_insert(cache->files, file->key, file, error); //-V595
419
+ if (error > 0)
420
+ error = 0;
421
+
422
+ /* remember "cache buster" file signature */
423
+ if (blob)
424
+ git_oid_cpy(&file->cache_data.oid, git_object_id((git_object *)blob));
425
+ else
426
+ memcpy(&file->cache_data.st, &st, sizeof(st));
427
+
428
+ finish:
429
+ /* push file onto vector if we found one*/
430
+ if (!error && file != NULL)
431
+ error = git_vector_insert(stack, file);
432
+
433
+ if (error != 0)
434
+ git_attr_file__free(file);
435
+
436
+ if (blob)
437
+ git_blob_free(blob);
438
+ else
439
+ git__free((void *)content);
440
+
441
+ git_buf_free(&path);
442
+
443
+ return error;
444
+ }
445
+
446
+ #define push_attr_file(R,S,B,F) \
447
+ git_attr_cache__push_file((R),(B),(F),GIT_ATTR_FILE_FROM_FILE,git_attr_file__parse_buffer,(S))
448
+
449
+ typedef struct {
450
+ git_repository *repo;
451
+ uint32_t flags;
452
+ const char *workdir;
453
+ git_index *index;
454
+ git_vector *files;
455
+ } attr_walk_up_info;
456
+
457
+ int git_attr_cache__decide_sources(
458
+ uint32_t flags, bool has_wd, bool has_index, git_attr_file_source *srcs)
459
+ {
460
+ int count = 0;
461
+
462
+ switch (flags & 0x03) {
463
+ case GIT_ATTR_CHECK_FILE_THEN_INDEX:
464
+ if (has_wd)
465
+ srcs[count++] = GIT_ATTR_FILE_FROM_FILE;
466
+ if (has_index)
467
+ srcs[count++] = GIT_ATTR_FILE_FROM_INDEX;
468
+ break;
469
+ case GIT_ATTR_CHECK_INDEX_THEN_FILE:
470
+ if (has_index)
471
+ srcs[count++] = GIT_ATTR_FILE_FROM_INDEX;
472
+ if (has_wd)
473
+ srcs[count++] = GIT_ATTR_FILE_FROM_FILE;
474
+ break;
475
+ case GIT_ATTR_CHECK_INDEX_ONLY:
476
+ if (has_index)
477
+ srcs[count++] = GIT_ATTR_FILE_FROM_INDEX;
478
+ break;
479
+ }
480
+
481
+ return count;
482
+ }
483
+
484
+ static int push_one_attr(void *ref, git_buf *path)
485
+ {
486
+ int error = 0, n_src, i;
487
+ attr_walk_up_info *info = (attr_walk_up_info *)ref;
488
+ git_attr_file_source src[2];
489
+
490
+ n_src = git_attr_cache__decide_sources(
491
+ info->flags, info->workdir != NULL, info->index != NULL, src);
492
+
493
+ for (i = 0; !error && i < n_src; ++i)
494
+ error = git_attr_cache__push_file(
495
+ info->repo, path->ptr, GIT_ATTR_FILE, src[i],
496
+ git_attr_file__parse_buffer, info->files);
497
+
498
+ return error;
499
+ }
500
+
501
+ static int collect_attr_files(
502
+ git_repository *repo,
503
+ uint32_t flags,
504
+ const char *path,
505
+ git_vector *files)
506
+ {
507
+ int error;
508
+ git_buf dir = GIT_BUF_INIT;
509
+ const char *workdir = git_repository_workdir(repo);
510
+ attr_walk_up_info info;
511
+
512
+ if (git_attr_cache__init(repo) < 0 ||
513
+ git_vector_init(files, 4, NULL) < 0)
514
+ return -1;
515
+
516
+ /* Resolve path in a non-bare repo */
517
+ if (workdir != NULL)
518
+ error = git_path_find_dir(&dir, path, workdir);
519
+ else
520
+ error = git_path_dirname_r(&dir, path);
521
+ if (error < 0)
522
+ goto cleanup;
523
+
524
+ /* in precendence order highest to lowest:
525
+ * - $GIT_DIR/info/attributes
526
+ * - path components with .gitattributes
527
+ * - config core.attributesfile
528
+ * - $GIT_PREFIX/etc/gitattributes
529
+ */
530
+
531
+ error = push_attr_file(
532
+ repo, files, git_repository_path(repo), GIT_ATTR_FILE_INREPO);
533
+ if (error < 0)
534
+ goto cleanup;
535
+
536
+ info.repo = repo;
537
+ info.flags = flags;
538
+ info.workdir = workdir;
539
+ if (git_repository_index__weakptr(&info.index, repo) < 0)
540
+ giterr_clear(); /* no error even if there is no index */
541
+ info.files = files;
542
+
543
+ error = git_path_walk_up(&dir, workdir, push_one_attr, &info);
544
+ if (error < 0)
545
+ goto cleanup;
546
+
547
+ if (git_repository_attr_cache(repo)->cfg_attr_file != NULL) {
548
+ error = push_attr_file(
549
+ repo, files, NULL, git_repository_attr_cache(repo)->cfg_attr_file);
550
+ if (error < 0)
551
+ goto cleanup;
552
+ }
553
+
554
+ if ((flags & GIT_ATTR_CHECK_NO_SYSTEM) == 0) {
555
+ error = git_futils_find_system_file(&dir, GIT_ATTR_FILE_SYSTEM);
556
+ if (!error)
557
+ error = push_attr_file(repo, files, NULL, dir.ptr);
558
+ else if (error == GIT_ENOTFOUND)
559
+ error = 0;
560
+ }
561
+
562
+ cleanup:
563
+ if (error < 0)
564
+ git_vector_free(files);
565
+ git_buf_free(&dir);
566
+
567
+ return error;
568
+ }
569
+
570
+
571
+ int git_attr_cache__init(git_repository *repo)
572
+ {
573
+ int ret;
574
+ git_attr_cache *cache = git_repository_attr_cache(repo);
575
+ git_config *cfg;
576
+
577
+ if (cache->initialized)
578
+ return 0;
579
+
580
+ /* cache config settings for attributes and ignores */
581
+ if (git_repository_config__weakptr(&cfg, repo) < 0)
582
+ return -1;
583
+
584
+ ret = git_config_get_string(&cache->cfg_attr_file, cfg, GIT_ATTR_CONFIG);
585
+ if (ret < 0 && ret != GIT_ENOTFOUND)
586
+ return ret;
587
+
588
+ ret = git_config_get_string(&cache->cfg_excl_file, cfg, GIT_IGNORE_CONFIG);
589
+ if (ret < 0 && ret != GIT_ENOTFOUND)
590
+ return ret;
591
+
592
+ giterr_clear();
593
+
594
+ /* allocate hashtable for attribute and ignore file contents */
595
+ if (cache->files == NULL) {
596
+ cache->files = git_strmap_alloc();
597
+ GITERR_CHECK_ALLOC(cache->files);
598
+ }
599
+
600
+ /* allocate hashtable for attribute macros */
601
+ if (cache->macros == NULL) {
602
+ cache->macros = git_strmap_alloc();
603
+ GITERR_CHECK_ALLOC(cache->macros);
604
+ }
605
+
606
+ /* allocate string pool */
607
+ if (git_pool_init(&cache->pool, 1, 0) < 0)
608
+ return -1;
609
+
610
+ cache->initialized = 1;
611
+
612
+ /* insert default macros */
613
+ return git_attr_add_macro(repo, "binary", "-diff -crlf -text");
614
+ }
615
+
616
+ void git_attr_cache_flush(
617
+ git_repository *repo)
618
+ {
619
+ git_attr_cache *cache;
620
+
621
+ if (!repo)
622
+ return;
623
+
624
+ cache = git_repository_attr_cache(repo);
625
+
626
+ if (cache->files != NULL) {
627
+ git_attr_file *file;
628
+
629
+ git_strmap_foreach_value(cache->files, file, {
630
+ git_attr_file__free(file);
631
+ });
632
+
633
+ git_strmap_free(cache->files);
634
+ }
635
+
636
+ if (cache->macros != NULL) {
637
+ git_attr_rule *rule;
638
+
639
+ git_strmap_foreach_value(cache->macros, rule, {
640
+ git_attr_rule__free(rule);
641
+ });
642
+
643
+ git_strmap_free(cache->macros);
644
+ }
645
+
646
+ git_pool_clear(&cache->pool);
647
+
648
+ cache->initialized = 0;
649
+ }
650
+
651
+ int git_attr_cache__insert_macro(git_repository *repo, git_attr_rule *macro)
652
+ {
653
+ git_strmap *macros = git_repository_attr_cache(repo)->macros;
654
+ int error;
655
+
656
+ /* TODO: generate warning log if (macro->assigns.length == 0) */
657
+ if (macro->assigns.length == 0)
658
+ return 0;
659
+
660
+ git_strmap_insert(macros, macro->match.pattern, macro, error);
661
+ return (error < 0) ? -1 : 0;
662
+ }
663
+
664
+ git_attr_rule *git_attr_cache__lookup_macro(
665
+ git_repository *repo, const char *name)
666
+ {
667
+ git_strmap *macros = git_repository_attr_cache(repo)->macros;
668
+ khiter_t pos;
669
+
670
+ pos = git_strmap_lookup_index(macros, name);
671
+
672
+ if (!git_strmap_valid_index(macros, pos))
673
+ return NULL;
674
+
675
+ return (git_attr_rule *)git_strmap_value_at(macros, pos);
676
+ }
677
+
@@ -0,0 +1,56 @@
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
+ #ifndef INCLUDE_attr_h__
8
+ #define INCLUDE_attr_h__
9
+
10
+ #include "attr_file.h"
11
+ #include "strmap.h"
12
+
13
+ #define GIT_ATTR_CONFIG "core.attributesfile"
14
+ #define GIT_IGNORE_CONFIG "core.excludesfile"
15
+
16
+ typedef struct {
17
+ int initialized;
18
+ git_pool pool;
19
+ git_strmap *files; /* hash path to git_attr_file of rules */
20
+ git_strmap *macros; /* hash name to vector<git_attr_assignment> */
21
+ const char *cfg_attr_file; /* cached value of core.attributesfile */
22
+ const char *cfg_excl_file; /* cached value of core.excludesfile */
23
+ } git_attr_cache;
24
+
25
+ typedef int (*git_attr_file_parser)(
26
+ git_repository *, const char *, git_attr_file *);
27
+
28
+ extern int git_attr_cache__init(git_repository *repo);
29
+
30
+ extern int git_attr_cache__insert_macro(
31
+ git_repository *repo, git_attr_rule *macro);
32
+
33
+ extern git_attr_rule *git_attr_cache__lookup_macro(
34
+ git_repository *repo, const char *name);
35
+
36
+ extern int git_attr_cache__push_file(
37
+ git_repository *repo,
38
+ const char *base,
39
+ const char *filename,
40
+ git_attr_file_source source,
41
+ git_attr_file_parser parse,
42
+ git_vector *stack);
43
+
44
+ extern int git_attr_cache__internal_file(
45
+ git_repository *repo,
46
+ const char *key,
47
+ git_attr_file **file_ptr);
48
+
49
+ /* returns true if path is in cache */
50
+ extern bool git_attr_cache__is_cached(
51
+ git_repository *repo, git_attr_file_source source, const char *path);
52
+
53
+ extern int git_attr_cache__decide_sources(
54
+ uint32_t flags, bool has_wd, bool has_index, git_attr_file_source *srcs);
55
+
56
+ #endif