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,794 @@
1
+ /*
2
+ * Copyright (C) 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
+ #include "common.h"
8
+ #include "git2/diff.h"
9
+ #include "git2/attr.h"
10
+ #include "git2/blob.h"
11
+ #include "xdiff/xdiff.h"
12
+ #include <ctype.h>
13
+ #include "diff.h"
14
+ #include "map.h"
15
+ #include "fileops.h"
16
+ #include "filter.h"
17
+
18
+ typedef struct {
19
+ git_diff_list *diff;
20
+ void *cb_data;
21
+ git_diff_hunk_fn hunk_cb;
22
+ git_diff_data_fn line_cb;
23
+ unsigned int index;
24
+ git_diff_delta *delta;
25
+ git_diff_range range;
26
+ } diff_output_info;
27
+
28
+ static int read_next_int(const char **str, int *value)
29
+ {
30
+ const char *scan = *str;
31
+ int v = 0, digits = 0;
32
+ /* find next digit */
33
+ for (scan = *str; *scan && !isdigit(*scan); scan++);
34
+ /* parse next number */
35
+ for (; isdigit(*scan); scan++, digits++)
36
+ v = (v * 10) + (*scan - '0');
37
+ *str = scan;
38
+ *value = v;
39
+ return (digits > 0) ? 0 : -1;
40
+ }
41
+
42
+ static int diff_output_cb(void *priv, mmbuffer_t *bufs, int len)
43
+ {
44
+ diff_output_info *info = priv;
45
+
46
+ if (len == 1 && info->hunk_cb) {
47
+ git_diff_range range = { -1, 0, -1, 0 };
48
+ const char *scan = bufs[0].ptr;
49
+
50
+ /* expect something of the form "@@ -%d[,%d] +%d[,%d] @@" */
51
+ if (*scan != '@')
52
+ return -1;
53
+
54
+ if (read_next_int(&scan, &range.old_start) < 0)
55
+ return -1;
56
+ if (*scan == ',' && read_next_int(&scan, &range.old_lines) < 0)
57
+ return -1;
58
+
59
+ if (read_next_int(&scan, &range.new_start) < 0)
60
+ return -1;
61
+ if (*scan == ',' && read_next_int(&scan, &range.new_lines) < 0)
62
+ return -1;
63
+
64
+ if (range.old_start < 0 || range.new_start < 0)
65
+ return -1;
66
+
67
+ memcpy(&info->range, &range, sizeof(git_diff_range));
68
+
69
+ return info->hunk_cb(
70
+ info->cb_data, info->delta, &range, bufs[0].ptr, bufs[0].size);
71
+ }
72
+
73
+ if ((len == 2 || len == 3) && info->line_cb) {
74
+ int origin;
75
+
76
+ /* expect " "/"-"/"+", then data, then maybe newline */
77
+ origin =
78
+ (*bufs[0].ptr == '+') ? GIT_DIFF_LINE_ADDITION :
79
+ (*bufs[0].ptr == '-') ? GIT_DIFF_LINE_DELETION :
80
+ GIT_DIFF_LINE_CONTEXT;
81
+
82
+ if (info->line_cb(
83
+ info->cb_data, info->delta, &info->range, origin, bufs[1].ptr, bufs[1].size) < 0)
84
+ return -1;
85
+
86
+ /* This should only happen if we are adding a line that does not
87
+ * have a newline at the end and the old code did. In that case,
88
+ * we have a ADD with a DEL_EOFNL as a pair.
89
+ */
90
+ if (len == 3) {
91
+ origin = (origin == GIT_DIFF_LINE_ADDITION) ?
92
+ GIT_DIFF_LINE_DEL_EOFNL : GIT_DIFF_LINE_ADD_EOFNL;
93
+
94
+ return info->line_cb(
95
+ info->cb_data, info->delta, &info->range, origin, bufs[2].ptr, bufs[2].size);
96
+ }
97
+ }
98
+
99
+ return 0;
100
+ }
101
+
102
+ #define BINARY_DIFF_FLAGS (GIT_DIFF_FILE_BINARY|GIT_DIFF_FILE_NOT_BINARY)
103
+
104
+ static int update_file_is_binary_by_attr(git_repository *repo, git_diff_file *file)
105
+ {
106
+ const char *value;
107
+ if (git_attr_get(&value, repo, 0, file->path, "diff") < 0)
108
+ return -1;
109
+
110
+ if (GIT_ATTR_FALSE(value))
111
+ file->flags |= GIT_DIFF_FILE_BINARY;
112
+ else if (GIT_ATTR_TRUE(value))
113
+ file->flags |= GIT_DIFF_FILE_NOT_BINARY;
114
+ /* otherwise leave file->flags alone */
115
+
116
+ return 0;
117
+ }
118
+
119
+ static void update_delta_is_binary(git_diff_delta *delta)
120
+ {
121
+ if ((delta->old_file.flags & GIT_DIFF_FILE_BINARY) != 0 ||
122
+ (delta->new_file.flags & GIT_DIFF_FILE_BINARY) != 0)
123
+ delta->binary = 1;
124
+ else if ((delta->old_file.flags & GIT_DIFF_FILE_NOT_BINARY) != 0 ||
125
+ (delta->new_file.flags & GIT_DIFF_FILE_NOT_BINARY) != 0)
126
+ delta->binary = 0;
127
+ /* otherwise leave delta->binary value untouched */
128
+ }
129
+
130
+ static int file_is_binary_by_attr(
131
+ git_diff_list *diff,
132
+ git_diff_delta *delta)
133
+ {
134
+ int error = 0, mirror_new;
135
+
136
+ delta->binary = -1;
137
+
138
+ /* make sure files are conceivably mmap-able */
139
+ if ((git_off_t)((size_t)delta->old_file.size) != delta->old_file.size ||
140
+ (git_off_t)((size_t)delta->new_file.size) != delta->new_file.size)
141
+ {
142
+ delta->old_file.flags |= GIT_DIFF_FILE_BINARY;
143
+ delta->new_file.flags |= GIT_DIFF_FILE_BINARY;
144
+ delta->binary = 1;
145
+ return 0;
146
+ }
147
+
148
+ /* check if user is forcing us to text diff these files */
149
+ if (diff->opts.flags & GIT_DIFF_FORCE_TEXT) {
150
+ delta->old_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
151
+ delta->new_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
152
+ delta->binary = 0;
153
+ return 0;
154
+ }
155
+
156
+ /* check diff attribute +, -, or 0 */
157
+ if (update_file_is_binary_by_attr(diff->repo, &delta->old_file) < 0)
158
+ return -1;
159
+
160
+ mirror_new = (delta->new_file.path == delta->old_file.path ||
161
+ strcmp(delta->new_file.path, delta->old_file.path) == 0);
162
+ if (mirror_new)
163
+ delta->new_file.flags &= (delta->old_file.flags & BINARY_DIFF_FLAGS);
164
+ else
165
+ error = update_file_is_binary_by_attr(diff->repo, &delta->new_file);
166
+
167
+ update_delta_is_binary(delta);
168
+
169
+ return error;
170
+ }
171
+
172
+ static int file_is_binary_by_content(
173
+ git_diff_delta *delta,
174
+ git_map *old_data,
175
+ git_map *new_data)
176
+ {
177
+ git_buf search;
178
+
179
+ if ((delta->old_file.flags & BINARY_DIFF_FLAGS) == 0) {
180
+ search.ptr = old_data->data;
181
+ search.size = min(old_data->len, 4000);
182
+
183
+ if (git_buf_is_binary(&search))
184
+ delta->old_file.flags |= GIT_DIFF_FILE_BINARY;
185
+ else
186
+ delta->old_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
187
+ }
188
+
189
+ if ((delta->new_file.flags & BINARY_DIFF_FLAGS) == 0) {
190
+ search.ptr = new_data->data;
191
+ search.size = min(new_data->len, 4000);
192
+
193
+ if (git_buf_is_binary(&search))
194
+ delta->new_file.flags |= GIT_DIFF_FILE_BINARY;
195
+ else
196
+ delta->new_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
197
+ }
198
+
199
+ update_delta_is_binary(delta);
200
+
201
+ /* TODO: if value != NULL, implement diff drivers */
202
+
203
+ return 0;
204
+ }
205
+
206
+ static void setup_xdiff_options(
207
+ git_diff_options *opts, xdemitconf_t *cfg, xpparam_t *param)
208
+ {
209
+ memset(cfg, 0, sizeof(xdemitconf_t));
210
+ memset(param, 0, sizeof(xpparam_t));
211
+
212
+ cfg->ctxlen =
213
+ (!opts || !opts->context_lines) ? 3 : opts->context_lines;
214
+ cfg->interhunkctxlen =
215
+ (!opts || !opts->interhunk_lines) ? 3 : opts->interhunk_lines;
216
+
217
+ if (!opts)
218
+ return;
219
+
220
+ if (opts->flags & GIT_DIFF_IGNORE_WHITESPACE)
221
+ param->flags |= XDF_WHITESPACE_FLAGS;
222
+ if (opts->flags & GIT_DIFF_IGNORE_WHITESPACE_CHANGE)
223
+ param->flags |= XDF_IGNORE_WHITESPACE_CHANGE;
224
+ if (opts->flags & GIT_DIFF_IGNORE_WHITESPACE_EOL)
225
+ param->flags |= XDF_IGNORE_WHITESPACE_AT_EOL;
226
+ }
227
+
228
+ static int get_blob_content(
229
+ git_repository *repo,
230
+ const git_oid *oid,
231
+ git_map *map,
232
+ git_blob **blob)
233
+ {
234
+ if (git_oid_iszero(oid))
235
+ return 0;
236
+
237
+ if (git_blob_lookup(blob, repo, oid) < 0)
238
+ return -1;
239
+
240
+ map->data = (void *)git_blob_rawcontent(*blob);
241
+ map->len = git_blob_rawsize(*blob);
242
+ return 0;
243
+ }
244
+
245
+ static int get_workdir_content(
246
+ git_repository *repo,
247
+ git_diff_file *file,
248
+ git_map *map)
249
+ {
250
+ int error = 0;
251
+ git_buf path = GIT_BUF_INIT;
252
+
253
+ if (git_buf_joinpath(&path, git_repository_workdir(repo), file->path) < 0)
254
+ return -1;
255
+
256
+ if (S_ISLNK(file->mode)) {
257
+ ssize_t read_len;
258
+
259
+ file->flags |= GIT_DIFF_FILE_FREE_DATA;
260
+ file->flags |= GIT_DIFF_FILE_BINARY;
261
+
262
+ map->data = git__malloc((size_t)file->size + 1);
263
+ GITERR_CHECK_ALLOC(map->data);
264
+
265
+ read_len = p_readlink(path.ptr, map->data, (size_t)file->size + 1);
266
+ if (read_len != (ssize_t)file->size) {
267
+ giterr_set(GITERR_OS, "Failed to read symlink '%s'", file->path);
268
+ error = -1;
269
+ } else
270
+ map->len = read_len;
271
+ }
272
+ else {
273
+ error = git_futils_mmap_ro_file(map, path.ptr);
274
+ file->flags |= GIT_DIFF_FILE_UNMAP_DATA;
275
+ }
276
+ git_buf_free(&path);
277
+ return error;
278
+ }
279
+
280
+ static void release_content(git_diff_file *file, git_map *map, git_blob *blob)
281
+ {
282
+ if (blob != NULL)
283
+ git_blob_free(blob);
284
+
285
+ if (file->flags & GIT_DIFF_FILE_FREE_DATA) {
286
+ git__free(map->data);
287
+ map->data = NULL;
288
+ file->flags &= ~GIT_DIFF_FILE_FREE_DATA;
289
+ }
290
+ else if (file->flags & GIT_DIFF_FILE_UNMAP_DATA) {
291
+ git_futils_mmap_free(map);
292
+ map->data = NULL;
293
+ file->flags &= ~GIT_DIFF_FILE_UNMAP_DATA;
294
+ }
295
+ }
296
+
297
+ static void fill_map_from_mmfile(git_map *dst, mmfile_t *src) {
298
+ assert(dst && src);
299
+
300
+ dst->data = src->ptr;
301
+ dst->len = src->size;
302
+ #ifdef GIT_WIN32
303
+ dst->fmh = NULL;
304
+ #endif
305
+ }
306
+
307
+ int git_diff_foreach(
308
+ git_diff_list *diff,
309
+ void *data,
310
+ git_diff_file_fn file_cb,
311
+ git_diff_hunk_fn hunk_cb,
312
+ git_diff_data_fn line_cb)
313
+ {
314
+ int error = 0;
315
+ diff_output_info info;
316
+ git_diff_delta *delta;
317
+ xpparam_t xdiff_params;
318
+ xdemitconf_t xdiff_config;
319
+ xdemitcb_t xdiff_callback;
320
+
321
+ info.diff = diff;
322
+ info.cb_data = data;
323
+ info.hunk_cb = hunk_cb;
324
+ info.line_cb = line_cb;
325
+
326
+ setup_xdiff_options(&diff->opts, &xdiff_config, &xdiff_params);
327
+ memset(&xdiff_callback, 0, sizeof(xdiff_callback));
328
+ xdiff_callback.outf = diff_output_cb;
329
+ xdiff_callback.priv = &info;
330
+
331
+ git_vector_foreach(&diff->deltas, info.index, delta) {
332
+ git_blob *old_blob = NULL, *new_blob = NULL;
333
+ git_map old_data, new_data;
334
+ mmfile_t old_xdiff_data, new_xdiff_data;
335
+
336
+ if (delta->status == GIT_DELTA_UNMODIFIED &&
337
+ (diff->opts.flags & GIT_DIFF_INCLUDE_UNMODIFIED) == 0)
338
+ continue;
339
+
340
+ if (delta->status == GIT_DELTA_IGNORED &&
341
+ (diff->opts.flags & GIT_DIFF_INCLUDE_IGNORED) == 0)
342
+ continue;
343
+
344
+ if (delta->status == GIT_DELTA_UNTRACKED &&
345
+ (diff->opts.flags & GIT_DIFF_INCLUDE_UNTRACKED) == 0)
346
+ continue;
347
+
348
+ if ((error = file_is_binary_by_attr(diff, delta)) < 0)
349
+ goto cleanup;
350
+
351
+ old_data.data = "";
352
+ old_data.len = 0;
353
+ new_data.data = "";
354
+ new_data.len = 0;
355
+
356
+ /* TODO: Partial blob reading to defer loading whole blob.
357
+ * I.e. I want a blob with just the first 4kb loaded, then
358
+ * later on I will read the rest of the blob if needed.
359
+ */
360
+
361
+ /* map files */
362
+ if (delta->binary != 1 &&
363
+ (hunk_cb || line_cb || git_oid_iszero(&delta->old_file.oid)) &&
364
+ (delta->status == GIT_DELTA_DELETED ||
365
+ delta->status == GIT_DELTA_MODIFIED))
366
+ {
367
+ if (diff->old_src == GIT_ITERATOR_WORKDIR)
368
+ error = get_workdir_content(diff->repo, &delta->old_file, &old_data);
369
+ else
370
+ error = get_blob_content(
371
+ diff->repo, &delta->old_file.oid, &old_data, &old_blob);
372
+
373
+ if (error < 0)
374
+ goto cleanup;
375
+ }
376
+
377
+ if (delta->binary != 1 &&
378
+ (hunk_cb || line_cb || git_oid_iszero(&delta->new_file.oid)) &&
379
+ (delta->status == GIT_DELTA_ADDED ||
380
+ delta->status == GIT_DELTA_MODIFIED))
381
+ {
382
+ if (diff->new_src == GIT_ITERATOR_WORKDIR)
383
+ error = get_workdir_content(diff->repo, &delta->new_file, &new_data);
384
+ else
385
+ error = get_blob_content(
386
+ diff->repo, &delta->new_file.oid, &new_data, &new_blob);
387
+
388
+ if (error < 0)
389
+ goto cleanup;
390
+
391
+ if ((delta->new_file.flags & GIT_DIFF_FILE_VALID_OID) == 0) {
392
+ error = git_odb_hash(
393
+ &delta->new_file.oid, new_data.data, new_data.len, GIT_OBJ_BLOB);
394
+
395
+ if (error < 0)
396
+ goto cleanup;
397
+
398
+ /* since we did not have the definitive oid, we may have
399
+ * incorrect status and need to skip this item.
400
+ */
401
+ if (delta->old_file.mode == delta->new_file.mode &&
402
+ !git_oid_cmp(&delta->old_file.oid, &delta->new_file.oid))
403
+ {
404
+ delta->status = GIT_DELTA_UNMODIFIED;
405
+ if ((diff->opts.flags & GIT_DIFF_INCLUDE_UNMODIFIED) == 0)
406
+ goto cleanup;
407
+ }
408
+ }
409
+ }
410
+
411
+ /* if we have not already decided whether file is binary,
412
+ * check the first 4K for nul bytes to decide...
413
+ */
414
+ if (delta->binary == -1) {
415
+ error = file_is_binary_by_content(
416
+ delta, &old_data, &new_data);
417
+ if (error < 0)
418
+ goto cleanup;
419
+ }
420
+
421
+ /* TODO: if ignore_whitespace is set, then we *must* do text
422
+ * diffs to tell if a file has really been changed.
423
+ */
424
+
425
+ if (file_cb != NULL) {
426
+ error = file_cb(
427
+ data, delta, (float)info.index / diff->deltas.length);
428
+ if (error < 0)
429
+ goto cleanup;
430
+ }
431
+
432
+ /* don't do hunk and line diffs if file is binary */
433
+ if (delta->binary == 1)
434
+ goto cleanup;
435
+
436
+ /* nothing to do if we did not get data */
437
+ if (!old_data.len && !new_data.len)
438
+ goto cleanup;
439
+
440
+ /* nothing to do if only diff was a mode change */
441
+ if (!git_oid_cmp(&delta->old_file.oid, &delta->new_file.oid))
442
+ goto cleanup;
443
+
444
+ assert(hunk_cb || line_cb);
445
+
446
+ info.delta = delta;
447
+ old_xdiff_data.ptr = old_data.data;
448
+ old_xdiff_data.size = old_data.len;
449
+ new_xdiff_data.ptr = new_data.data;
450
+ new_xdiff_data.size = new_data.len;
451
+
452
+ xdl_diff(&old_xdiff_data, &new_xdiff_data,
453
+ &xdiff_params, &xdiff_config, &xdiff_callback);
454
+
455
+ cleanup:
456
+ release_content(&delta->old_file, &old_data, old_blob);
457
+ release_content(&delta->new_file, &new_data, new_blob);
458
+
459
+ if (error < 0)
460
+ break;
461
+ }
462
+
463
+ return error;
464
+ }
465
+
466
+
467
+ typedef struct {
468
+ git_diff_list *diff;
469
+ git_diff_data_fn print_cb;
470
+ void *cb_data;
471
+ git_buf *buf;
472
+ } diff_print_info;
473
+
474
+ static char pick_suffix(int mode)
475
+ {
476
+ if (S_ISDIR(mode))
477
+ return '/';
478
+ else if (mode & 0100) //-V536
479
+ /* in git, modes are very regular, so we must have 0100755 mode */
480
+ return '*';
481
+ else
482
+ return ' ';
483
+ }
484
+
485
+ static int print_compact(void *data, git_diff_delta *delta, float progress)
486
+ {
487
+ diff_print_info *pi = data;
488
+ char code, old_suffix, new_suffix;
489
+
490
+ GIT_UNUSED(progress);
491
+
492
+ switch (delta->status) {
493
+ case GIT_DELTA_ADDED: code = 'A'; break;
494
+ case GIT_DELTA_DELETED: code = 'D'; break;
495
+ case GIT_DELTA_MODIFIED: code = 'M'; break;
496
+ case GIT_DELTA_RENAMED: code = 'R'; break;
497
+ case GIT_DELTA_COPIED: code = 'C'; break;
498
+ case GIT_DELTA_IGNORED: code = 'I'; break;
499
+ case GIT_DELTA_UNTRACKED: code = '?'; break;
500
+ default: code = 0;
501
+ }
502
+
503
+ if (!code)
504
+ return 0;
505
+
506
+ old_suffix = pick_suffix(delta->old_file.mode);
507
+ new_suffix = pick_suffix(delta->new_file.mode);
508
+
509
+ git_buf_clear(pi->buf);
510
+
511
+ if (delta->old_file.path != delta->new_file.path &&
512
+ strcmp(delta->old_file.path,delta->new_file.path) != 0)
513
+ git_buf_printf(pi->buf, "%c\t%s%c -> %s%c\n", code,
514
+ delta->old_file.path, old_suffix, delta->new_file.path, new_suffix);
515
+ else if (delta->old_file.mode != delta->new_file.mode &&
516
+ delta->old_file.mode != 0 && delta->new_file.mode != 0)
517
+ git_buf_printf(pi->buf, "%c\t%s%c (%o -> %o)\n", code,
518
+ delta->old_file.path, new_suffix, delta->old_file.mode, delta->new_file.mode);
519
+ else if (old_suffix != ' ')
520
+ git_buf_printf(pi->buf, "%c\t%s%c\n", code, delta->old_file.path, old_suffix);
521
+ else
522
+ git_buf_printf(pi->buf, "%c\t%s\n", code, delta->old_file.path);
523
+
524
+ if (git_buf_oom(pi->buf))
525
+ return -1;
526
+
527
+ return pi->print_cb(pi->cb_data, delta, NULL, GIT_DIFF_LINE_FILE_HDR, git_buf_cstr(pi->buf), git_buf_len(pi->buf));
528
+ }
529
+
530
+ int git_diff_print_compact(
531
+ git_diff_list *diff,
532
+ void *cb_data,
533
+ git_diff_data_fn print_cb)
534
+ {
535
+ int error;
536
+ git_buf buf = GIT_BUF_INIT;
537
+ diff_print_info pi;
538
+
539
+ pi.diff = diff;
540
+ pi.print_cb = print_cb;
541
+ pi.cb_data = cb_data;
542
+ pi.buf = &buf;
543
+
544
+ error = git_diff_foreach(diff, &pi, print_compact, NULL, NULL);
545
+
546
+ git_buf_free(&buf);
547
+
548
+ return error;
549
+ }
550
+
551
+
552
+ static int print_oid_range(diff_print_info *pi, git_diff_delta *delta)
553
+ {
554
+ char start_oid[8], end_oid[8];
555
+
556
+ /* TODO: Determine a good actual OID range to print */
557
+ git_oid_tostr(start_oid, sizeof(start_oid), &delta->old_file.oid);
558
+ git_oid_tostr(end_oid, sizeof(end_oid), &delta->new_file.oid);
559
+
560
+ /* TODO: Match git diff more closely */
561
+ if (delta->old_file.mode == delta->new_file.mode) {
562
+ git_buf_printf(pi->buf, "index %s..%s %o\n",
563
+ start_oid, end_oid, delta->old_file.mode);
564
+ } else {
565
+ if (delta->old_file.mode == 0) {
566
+ git_buf_printf(pi->buf, "new file mode %o\n", delta->new_file.mode);
567
+ } else if (delta->new_file.mode == 0) {
568
+ git_buf_printf(pi->buf, "deleted file mode %o\n", delta->old_file.mode);
569
+ } else {
570
+ git_buf_printf(pi->buf, "old mode %o\n", delta->old_file.mode);
571
+ git_buf_printf(pi->buf, "new mode %o\n", delta->new_file.mode);
572
+ }
573
+ git_buf_printf(pi->buf, "index %s..%s\n", start_oid, end_oid);
574
+ }
575
+
576
+ if (git_buf_oom(pi->buf))
577
+ return -1;
578
+
579
+ return 0;
580
+ }
581
+
582
+ static int print_patch_file(void *data, git_diff_delta *delta, float progress)
583
+ {
584
+ diff_print_info *pi = data;
585
+ const char *oldpfx = pi->diff->opts.old_prefix;
586
+ const char *oldpath = delta->old_file.path;
587
+ const char *newpfx = pi->diff->opts.new_prefix;
588
+ const char *newpath = delta->new_file.path;
589
+ int result;
590
+
591
+ GIT_UNUSED(progress);
592
+
593
+ if (!oldpfx)
594
+ oldpfx = DIFF_OLD_PREFIX_DEFAULT;
595
+
596
+ if (!newpfx)
597
+ newpfx = DIFF_NEW_PREFIX_DEFAULT;
598
+
599
+ git_buf_clear(pi->buf);
600
+ git_buf_printf(pi->buf, "diff --git %s%s %s%s\n", oldpfx, delta->old_file.path, newpfx, delta->new_file.path);
601
+
602
+ if (print_oid_range(pi, delta) < 0)
603
+ return -1;
604
+
605
+ if (git_oid_iszero(&delta->old_file.oid)) {
606
+ oldpfx = "";
607
+ oldpath = "/dev/null";
608
+ }
609
+ if (git_oid_iszero(&delta->new_file.oid)) {
610
+ newpfx = "";
611
+ newpath = "/dev/null";
612
+ }
613
+
614
+ if (delta->binary != 1) {
615
+ git_buf_printf(pi->buf, "--- %s%s\n", oldpfx, oldpath);
616
+ git_buf_printf(pi->buf, "+++ %s%s\n", newpfx, newpath);
617
+ }
618
+
619
+ if (git_buf_oom(pi->buf))
620
+ return -1;
621
+
622
+ result = pi->print_cb(pi->cb_data, delta, NULL, GIT_DIFF_LINE_FILE_HDR, git_buf_cstr(pi->buf), git_buf_len(pi->buf));
623
+ if (result < 0)
624
+ return result;
625
+
626
+ if (delta->binary != 1)
627
+ return 0;
628
+
629
+ git_buf_clear(pi->buf);
630
+ git_buf_printf(
631
+ pi->buf, "Binary files %s%s and %s%s differ\n",
632
+ oldpfx, oldpath, newpfx, newpath);
633
+ if (git_buf_oom(pi->buf))
634
+ return -1;
635
+
636
+ return pi->print_cb(pi->cb_data, delta, NULL, GIT_DIFF_LINE_BINARY, git_buf_cstr(pi->buf), git_buf_len(pi->buf));
637
+ }
638
+
639
+ static int print_patch_hunk(
640
+ void *data,
641
+ git_diff_delta *d,
642
+ git_diff_range *r,
643
+ const char *header,
644
+ size_t header_len)
645
+ {
646
+ diff_print_info *pi = data;
647
+
648
+ git_buf_clear(pi->buf);
649
+ if (git_buf_printf(pi->buf, "%.*s", (int)header_len, header) < 0)
650
+ return -1;
651
+
652
+ return pi->print_cb(pi->cb_data, d, r, GIT_DIFF_LINE_HUNK_HDR, git_buf_cstr(pi->buf), git_buf_len(pi->buf));
653
+ }
654
+
655
+ static int print_patch_line(
656
+ void *data,
657
+ git_diff_delta *delta,
658
+ git_diff_range *range,
659
+ char line_origin, /* GIT_DIFF_LINE value from above */
660
+ const char *content,
661
+ size_t content_len)
662
+ {
663
+ diff_print_info *pi = data;
664
+
665
+ git_buf_clear(pi->buf);
666
+
667
+ if (line_origin == GIT_DIFF_LINE_ADDITION ||
668
+ line_origin == GIT_DIFF_LINE_DELETION ||
669
+ line_origin == GIT_DIFF_LINE_CONTEXT)
670
+ git_buf_printf(pi->buf, "%c%.*s", line_origin, (int)content_len, content);
671
+ else if (content_len > 0)
672
+ git_buf_printf(pi->buf, "%.*s", (int)content_len, content);
673
+
674
+ if (git_buf_oom(pi->buf))
675
+ return -1;
676
+
677
+ return pi->print_cb(pi->cb_data, delta, range, line_origin, git_buf_cstr(pi->buf), git_buf_len(pi->buf));
678
+ }
679
+
680
+ int git_diff_print_patch(
681
+ git_diff_list *diff,
682
+ void *cb_data,
683
+ git_diff_data_fn print_cb)
684
+ {
685
+ int error;
686
+ git_buf buf = GIT_BUF_INIT;
687
+ diff_print_info pi;
688
+
689
+ pi.diff = diff;
690
+ pi.print_cb = print_cb;
691
+ pi.cb_data = cb_data;
692
+ pi.buf = &buf;
693
+
694
+ error = git_diff_foreach(
695
+ diff, &pi, print_patch_file, print_patch_hunk, print_patch_line);
696
+
697
+ git_buf_free(&buf);
698
+
699
+ return error;
700
+ }
701
+
702
+ int git_diff_blobs(
703
+ git_blob *old_blob,
704
+ git_blob *new_blob,
705
+ git_diff_options *options,
706
+ void *cb_data,
707
+ git_diff_file_fn file_cb,
708
+ git_diff_hunk_fn hunk_cb,
709
+ git_diff_data_fn line_cb)
710
+ {
711
+ diff_output_info info;
712
+ git_diff_delta delta;
713
+ mmfile_t old_data, new_data;
714
+ git_map old_map, new_map;
715
+ xpparam_t xdiff_params;
716
+ xdemitconf_t xdiff_config;
717
+ xdemitcb_t xdiff_callback;
718
+ git_blob *new, *old;
719
+
720
+ memset(&delta, 0, sizeof(delta));
721
+
722
+ new = new_blob;
723
+ old = old_blob;
724
+
725
+ if (options && (options->flags & GIT_DIFF_REVERSE)) {
726
+ git_blob *swap = old;
727
+ old = new;
728
+ new = swap;
729
+ }
730
+
731
+ if (old) {
732
+ old_data.ptr = (char *)git_blob_rawcontent(old);
733
+ old_data.size = git_blob_rawsize(old);
734
+ git_oid_cpy(&delta.old_file.oid, git_object_id((const git_object *)old));
735
+ } else {
736
+ old_data.ptr = "";
737
+ old_data.size = 0;
738
+ }
739
+
740
+ if (new) {
741
+ new_data.ptr = (char *)git_blob_rawcontent(new);
742
+ new_data.size = git_blob_rawsize(new);
743
+ git_oid_cpy(&delta.new_file.oid, git_object_id((const git_object *)new));
744
+ } else {
745
+ new_data.ptr = "";
746
+ new_data.size = 0;
747
+ }
748
+
749
+ /* populate a "fake" delta record */
750
+ delta.status = new ?
751
+ (old ? GIT_DELTA_MODIFIED : GIT_DELTA_ADDED) :
752
+ (old ? GIT_DELTA_DELETED : GIT_DELTA_UNTRACKED);
753
+
754
+ if (git_oid_cmp(&delta.new_file.oid, &delta.old_file.oid) == 0)
755
+ delta.status = GIT_DELTA_UNMODIFIED;
756
+
757
+ delta.old_file.size = old_data.size;
758
+ delta.new_file.size = new_data.size;
759
+
760
+ fill_map_from_mmfile(&old_map, &old_data);
761
+ fill_map_from_mmfile(&new_map, &new_data);
762
+
763
+ if (file_is_binary_by_content(&delta, &old_map, &new_map) < 0)
764
+ return -1;
765
+
766
+ if (file_cb != NULL) {
767
+ int error = file_cb(cb_data, &delta, 1);
768
+ if (error < 0)
769
+ return error;
770
+ }
771
+
772
+ /* don't do hunk and line diffs if the two blobs are identical */
773
+ if (delta.status == GIT_DELTA_UNMODIFIED)
774
+ return 0;
775
+
776
+ /* don't do hunk and line diffs if file is binary */
777
+ if (delta.binary == 1)
778
+ return 0;
779
+
780
+ info.diff = NULL;
781
+ info.delta = &delta;
782
+ info.cb_data = cb_data;
783
+ info.hunk_cb = hunk_cb;
784
+ info.line_cb = line_cb;
785
+
786
+ setup_xdiff_options(options, &xdiff_config, &xdiff_params);
787
+ memset(&xdiff_callback, 0, sizeof(xdiff_callback));
788
+ xdiff_callback.outf = diff_output_cb;
789
+ xdiff_callback.priv = &info;
790
+
791
+ xdl_diff(&old_data, &new_data, &xdiff_params, &xdiff_config, &xdiff_callback);
792
+
793
+ return 0;
794
+ }