rugged 0.19.0 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (668) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -1
  3. data/README.md +184 -33
  4. data/ext/rugged/extconf.rb +111 -28
  5. data/ext/rugged/rugged.c +327 -89
  6. data/ext/rugged/rugged.h +64 -28
  7. data/ext/rugged/rugged_allocator.c +89 -0
  8. data/ext/rugged/rugged_backend.c +17 -0
  9. data/ext/rugged/rugged_blame.c +278 -0
  10. data/ext/rugged/rugged_blob.c +301 -75
  11. data/ext/rugged/rugged_branch.c +92 -242
  12. data/ext/rugged/rugged_branch_collection.c +388 -0
  13. data/ext/rugged/rugged_commit.c +575 -79
  14. data/ext/rugged/rugged_config.c +129 -36
  15. data/ext/rugged/rugged_cred.c +131 -0
  16. data/ext/rugged/rugged_diff.c +291 -122
  17. data/ext/rugged/rugged_diff_delta.c +16 -22
  18. data/ext/rugged/rugged_diff_hunk.c +35 -51
  19. data/ext/rugged/rugged_diff_line.c +23 -36
  20. data/ext/rugged/rugged_index.c +289 -152
  21. data/ext/rugged/rugged_note.c +50 -60
  22. data/ext/rugged/rugged_object.c +13 -30
  23. data/ext/rugged/rugged_patch.c +400 -0
  24. data/ext/rugged/rugged_rebase.c +397 -0
  25. data/ext/rugged/rugged_reference.c +76 -346
  26. data/ext/rugged/rugged_reference_collection.c +423 -0
  27. data/ext/rugged/rugged_remote.c +438 -461
  28. data/ext/rugged/rugged_remote_collection.c +435 -0
  29. data/ext/rugged/rugged_repo.c +1548 -365
  30. data/ext/rugged/rugged_revwalk.c +378 -99
  31. data/ext/rugged/rugged_settings.c +86 -23
  32. data/ext/rugged/rugged_signature.c +47 -37
  33. data/ext/rugged/rugged_submodule.c +835 -0
  34. data/ext/rugged/rugged_submodule_collection.c +366 -0
  35. data/ext/rugged/rugged_tag.c +88 -210
  36. data/ext/rugged/rugged_tag_collection.c +326 -0
  37. data/ext/rugged/rugged_tree.c +460 -217
  38. data/lib/rugged/attributes.rb +46 -0
  39. data/lib/rugged/blob.rb +33 -0
  40. data/lib/rugged/branch.rb +12 -16
  41. data/lib/rugged/commit.rb +9 -0
  42. data/lib/rugged/console.rb +5 -0
  43. data/lib/rugged/credentials.rb +48 -0
  44. data/lib/rugged/diff/delta.rb +6 -2
  45. data/lib/rugged/diff/hunk.rb +9 -9
  46. data/lib/rugged/diff/line.rb +28 -5
  47. data/lib/rugged/diff.rb +7 -1
  48. data/lib/rugged/index.rb +120 -0
  49. data/lib/rugged/object.rb +5 -0
  50. data/lib/rugged/patch.rb +41 -0
  51. data/lib/rugged/reference.rb +6 -3
  52. data/lib/rugged/remote.rb +5 -9
  53. data/lib/rugged/repository.rb +126 -14
  54. data/lib/rugged/submodule_collection.rb +53 -0
  55. data/lib/rugged/tag.rb +45 -16
  56. data/lib/rugged/tree.rb +163 -1
  57. data/lib/rugged/version.rb +6 -1
  58. data/lib/rugged/walker.rb +5 -0
  59. data/lib/rugged.rb +16 -1
  60. data/vendor/libgit2/AUTHORS +77 -0
  61. data/vendor/libgit2/CMakeLists.txt +317 -0
  62. data/vendor/libgit2/COPYING +993 -0
  63. data/vendor/libgit2/cmake/Modules/AddCFlagIfSupported.cmake +30 -0
  64. data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.c.in +29 -0
  65. data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.cmake +96 -0
  66. data/vendor/libgit2/cmake/Modules/EnableWarnings.cmake +11 -0
  67. data/vendor/libgit2/cmake/Modules/FindCoreFoundation.cmake +26 -0
  68. data/vendor/libgit2/cmake/Modules/FindGSSAPI.cmake +324 -0
  69. data/vendor/libgit2/cmake/Modules/FindHTTP_Parser.cmake +39 -0
  70. data/vendor/libgit2/cmake/Modules/FindIconv.cmake +45 -0
  71. data/vendor/libgit2/cmake/Modules/FindPkgLibraries.cmake +28 -0
  72. data/vendor/libgit2/cmake/Modules/FindSecurity.cmake +28 -0
  73. data/vendor/libgit2/cmake/Modules/FindStatNsec.cmake +20 -0
  74. data/vendor/libgit2/cmake/Modules/FindmbedTLS.cmake +93 -0
  75. data/vendor/libgit2/cmake/Modules/IdeSplitSources.cmake +22 -0
  76. data/vendor/libgit2/deps/http-parser/CMakeLists.txt +5 -0
  77. data/vendor/libgit2/deps/http-parser/COPYING +23 -0
  78. data/vendor/libgit2/deps/http-parser/http_parser.c +5 -2
  79. data/vendor/libgit2/deps/http-parser/http_parser.h +2 -0
  80. data/vendor/libgit2/deps/regex/CMakeLists.txt +2 -0
  81. data/vendor/libgit2/deps/regex/COPYING +502 -0
  82. data/vendor/libgit2/deps/regex/regex.c +10 -3
  83. data/vendor/libgit2/deps/winhttp/CMakeLists.txt +26 -0
  84. data/vendor/libgit2/deps/winhttp/COPYING.GPL +993 -0
  85. data/vendor/libgit2/deps/winhttp/COPYING.LGPL +502 -0
  86. data/vendor/libgit2/deps/winhttp/urlmon.h +45 -0
  87. data/vendor/libgit2/deps/winhttp/winhttp.def +29 -0
  88. data/vendor/libgit2/deps/winhttp/winhttp.h +594 -0
  89. data/vendor/libgit2/deps/winhttp/winhttp64.def +29 -0
  90. data/vendor/libgit2/deps/zlib/CMakeLists.txt +5 -0
  91. data/vendor/libgit2/deps/zlib/COPYING +27 -0
  92. data/vendor/libgit2/deps/zlib/adler32.c +51 -34
  93. data/vendor/libgit2/deps/zlib/crc32.c +61 -61
  94. data/vendor/libgit2/deps/zlib/crc32.h +1 -1
  95. data/vendor/libgit2/deps/zlib/deflate.c +681 -352
  96. data/vendor/libgit2/deps/zlib/deflate.h +25 -18
  97. data/vendor/libgit2/deps/zlib/gzguts.h +218 -0
  98. data/vendor/libgit2/deps/zlib/infback.c +640 -0
  99. data/vendor/libgit2/deps/zlib/inffast.c +36 -53
  100. data/vendor/libgit2/deps/zlib/inffixed.h +3 -3
  101. data/vendor/libgit2/deps/zlib/inflate.c +167 -86
  102. data/vendor/libgit2/deps/zlib/inflate.h +7 -4
  103. data/vendor/libgit2/deps/zlib/inftrees.c +24 -50
  104. data/vendor/libgit2/deps/zlib/trees.c +55 -96
  105. data/vendor/libgit2/deps/zlib/zconf.h +499 -19
  106. data/vendor/libgit2/deps/zlib/zlib.h +526 -227
  107. data/vendor/libgit2/deps/zlib/zutil.c +39 -32
  108. data/vendor/libgit2/deps/zlib/zutil.h +75 -78
  109. data/vendor/libgit2/include/git2/annotated_commit.h +125 -0
  110. data/vendor/libgit2/include/git2/apply.h +129 -0
  111. data/vendor/libgit2/include/git2/attr.h +36 -21
  112. data/vendor/libgit2/include/git2/blame.h +229 -0
  113. data/vendor/libgit2/include/git2/blob.h +81 -44
  114. data/vendor/libgit2/include/git2/branch.h +81 -42
  115. data/vendor/libgit2/include/git2/buffer.h +128 -0
  116. data/vendor/libgit2/include/git2/checkout.h +141 -67
  117. data/vendor/libgit2/include/git2/cherrypick.h +92 -0
  118. data/vendor/libgit2/include/git2/clone.h +157 -58
  119. data/vendor/libgit2/include/git2/commit.h +231 -12
  120. data/vendor/libgit2/include/git2/common.h +216 -30
  121. data/vendor/libgit2/include/git2/config.h +274 -48
  122. data/vendor/libgit2/include/git2/cred_helpers.h +4 -4
  123. data/vendor/libgit2/include/git2/deprecated.h +253 -0
  124. data/vendor/libgit2/include/git2/describe.h +189 -0
  125. data/vendor/libgit2/include/git2/diff.h +985 -575
  126. data/vendor/libgit2/include/git2/errors.h +93 -52
  127. data/vendor/libgit2/include/git2/filter.h +217 -0
  128. data/vendor/libgit2/include/git2/global.h +44 -0
  129. data/vendor/libgit2/include/git2/graph.h +17 -0
  130. data/vendor/libgit2/include/git2/ignore.h +2 -2
  131. data/vendor/libgit2/include/git2/index.h +269 -94
  132. data/vendor/libgit2/include/git2/indexer.h +44 -12
  133. data/vendor/libgit2/include/git2/mailmap.h +115 -0
  134. data/vendor/libgit2/include/git2/merge.h +501 -64
  135. data/vendor/libgit2/include/git2/message.h +52 -17
  136. data/vendor/libgit2/include/git2/net.h +11 -5
  137. data/vendor/libgit2/include/git2/notes.h +120 -16
  138. data/vendor/libgit2/include/git2/object.h +62 -23
  139. data/vendor/libgit2/include/git2/odb.h +140 -24
  140. data/vendor/libgit2/include/git2/odb_backend.h +56 -12
  141. data/vendor/libgit2/include/git2/oid.h +17 -18
  142. data/vendor/libgit2/include/git2/oidarray.h +40 -0
  143. data/vendor/libgit2/include/git2/pack.h +86 -7
  144. data/vendor/libgit2/include/git2/patch.h +274 -0
  145. data/vendor/libgit2/include/git2/pathspec.h +280 -0
  146. data/vendor/libgit2/include/git2/proxy.h +96 -0
  147. data/vendor/libgit2/include/git2/rebase.h +323 -0
  148. data/vendor/libgit2/include/git2/reflog.h +12 -9
  149. data/vendor/libgit2/include/git2/refs.h +241 -46
  150. data/vendor/libgit2/include/git2/refspec.h +20 -4
  151. data/vendor/libgit2/include/git2/remote.h +636 -209
  152. data/vendor/libgit2/include/git2/repository.h +267 -57
  153. data/vendor/libgit2/include/git2/reset.h +36 -6
  154. data/vendor/libgit2/include/git2/revert.h +91 -0
  155. data/vendor/libgit2/include/git2/revparse.h +27 -16
  156. data/vendor/libgit2/include/git2/revwalk.h +78 -35
  157. data/vendor/libgit2/include/git2/signature.h +32 -5
  158. data/vendor/libgit2/include/git2/stash.h +160 -21
  159. data/vendor/libgit2/include/git2/status.h +92 -30
  160. data/vendor/libgit2/include/git2/submodule.h +226 -133
  161. data/vendor/libgit2/include/git2/sys/alloc.h +101 -0
  162. data/vendor/libgit2/include/git2/sys/commit.h +38 -4
  163. data/vendor/libgit2/include/git2/sys/config.h +68 -9
  164. data/vendor/libgit2/include/git2/sys/diff.h +94 -0
  165. data/vendor/libgit2/include/git2/sys/filter.h +332 -0
  166. data/vendor/libgit2/include/git2/sys/hashsig.h +106 -0
  167. data/vendor/libgit2/include/git2/sys/index.h +6 -5
  168. data/vendor/libgit2/include/git2/sys/mempack.h +86 -0
  169. data/vendor/libgit2/include/git2/sys/merge.h +182 -0
  170. data/vendor/libgit2/include/git2/sys/odb_backend.h +66 -28
  171. data/vendor/libgit2/include/git2/sys/openssl.h +38 -0
  172. data/vendor/libgit2/include/git2/sys/path.h +64 -0
  173. data/vendor/libgit2/include/git2/sys/refdb_backend.h +79 -19
  174. data/vendor/libgit2/include/git2/sys/reflog.h +21 -0
  175. data/vendor/libgit2/include/git2/sys/refs.h +13 -2
  176. data/vendor/libgit2/include/git2/sys/repository.h +64 -1
  177. data/vendor/libgit2/include/git2/sys/stream.h +138 -0
  178. data/vendor/libgit2/include/git2/sys/time.h +31 -0
  179. data/vendor/libgit2/include/git2/sys/transport.h +439 -0
  180. data/vendor/libgit2/include/git2/tag.h +11 -2
  181. data/vendor/libgit2/include/git2/trace.h +1 -1
  182. data/vendor/libgit2/include/git2/transaction.h +121 -0
  183. data/vendor/libgit2/include/git2/transport.h +261 -292
  184. data/vendor/libgit2/include/git2/tree.h +111 -21
  185. data/vendor/libgit2/include/git2/types.h +244 -32
  186. data/vendor/libgit2/include/git2/version.h +5 -2
  187. data/vendor/libgit2/include/git2/worktree.h +255 -0
  188. data/vendor/libgit2/include/git2.h +50 -40
  189. data/vendor/libgit2/libgit2.pc.in +13 -0
  190. data/vendor/libgit2/src/CMakeLists.txt +525 -0
  191. data/vendor/libgit2/src/alloc.c +55 -0
  192. data/vendor/libgit2/src/alloc.h +40 -0
  193. data/vendor/libgit2/src/annotated_commit.c +228 -0
  194. data/vendor/libgit2/src/annotated_commit.h +52 -0
  195. data/vendor/libgit2/src/apply.c +855 -0
  196. data/vendor/libgit2/src/apply.h +25 -0
  197. data/vendor/libgit2/src/array.h +74 -16
  198. data/vendor/libgit2/src/attr.c +239 -408
  199. data/vendor/libgit2/src/attr.h +3 -33
  200. data/vendor/libgit2/src/attr_file.c +424 -156
  201. data/vendor/libgit2/src/attr_file.h +95 -23
  202. data/vendor/libgit2/src/attrcache.c +469 -0
  203. data/vendor/libgit2/src/attrcache.h +37 -5
  204. data/vendor/libgit2/src/bitvec.h +75 -0
  205. data/vendor/libgit2/src/blame.c +532 -0
  206. data/vendor/libgit2/src/blame.h +95 -0
  207. data/vendor/libgit2/src/blame_git.c +668 -0
  208. data/vendor/libgit2/src/blame_git.h +22 -0
  209. data/vendor/libgit2/src/blob.c +233 -129
  210. data/vendor/libgit2/src/blob.h +29 -1
  211. data/vendor/libgit2/src/branch.c +295 -197
  212. data/vendor/libgit2/src/branch.h +2 -0
  213. data/vendor/libgit2/src/buf_text.c +52 -27
  214. data/vendor/libgit2/src/buf_text.h +7 -7
  215. data/vendor/libgit2/src/buffer.c +609 -52
  216. data/vendor/libgit2/src/buffer.h +68 -23
  217. data/vendor/libgit2/src/cache.c +48 -51
  218. data/vendor/libgit2/src/cache.h +6 -4
  219. data/vendor/libgit2/src/cc-compat.h +35 -7
  220. data/vendor/libgit2/src/checkout.c +1827 -483
  221. data/vendor/libgit2/src/checkout.h +4 -1
  222. data/vendor/libgit2/src/cherrypick.c +230 -0
  223. data/vendor/libgit2/src/clone.c +338 -258
  224. data/vendor/libgit2/src/{compress.h → clone.h} +5 -5
  225. data/vendor/libgit2/src/commit.c +711 -124
  226. data/vendor/libgit2/src/commit.h +10 -3
  227. data/vendor/libgit2/src/commit_list.c +21 -14
  228. data/vendor/libgit2/src/commit_list.h +9 -3
  229. data/vendor/libgit2/src/common.h +153 -13
  230. data/vendor/libgit2/src/config.c +871 -242
  231. data/vendor/libgit2/src/config.h +58 -14
  232. data/vendor/libgit2/src/config_backend.h +84 -0
  233. data/vendor/libgit2/src/config_cache.c +44 -18
  234. data/vendor/libgit2/src/config_entries.c +259 -0
  235. data/vendor/libgit2/src/config_entries.h +23 -0
  236. data/vendor/libgit2/src/config_file.c +837 -1113
  237. data/vendor/libgit2/src/config_mem.c +224 -0
  238. data/vendor/libgit2/src/config_parse.c +558 -0
  239. data/vendor/libgit2/src/config_parse.h +64 -0
  240. data/vendor/libgit2/src/crlf.c +290 -195
  241. data/vendor/libgit2/src/date.c +35 -7
  242. data/vendor/libgit2/src/delta.c +275 -71
  243. data/vendor/libgit2/src/delta.h +80 -58
  244. data/vendor/libgit2/src/describe.c +893 -0
  245. data/vendor/libgit2/src/diff.c +330 -1128
  246. data/vendor/libgit2/src/diff.h +25 -67
  247. data/vendor/libgit2/src/diff_driver.c +225 -109
  248. data/vendor/libgit2/src/diff_driver.h +5 -2
  249. data/vendor/libgit2/src/diff_file.c +128 -103
  250. data/vendor/libgit2/src/diff_file.h +17 -12
  251. data/vendor/libgit2/src/diff_generate.c +1622 -0
  252. data/vendor/libgit2/src/diff_generate.h +128 -0
  253. data/vendor/libgit2/src/diff_parse.c +108 -0
  254. data/vendor/libgit2/src/diff_parse.h +20 -0
  255. data/vendor/libgit2/src/diff_print.c +578 -218
  256. data/vendor/libgit2/src/diff_stats.c +362 -0
  257. data/vendor/libgit2/src/diff_tform.c +429 -257
  258. data/vendor/libgit2/src/diff_tform.h +25 -0
  259. data/vendor/libgit2/src/diff_xdiff.c +143 -46
  260. data/vendor/libgit2/src/diff_xdiff.h +12 -5
  261. data/vendor/libgit2/src/errors.c +150 -34
  262. data/vendor/libgit2/src/features.h.in +37 -0
  263. data/vendor/libgit2/src/fetch.c +69 -46
  264. data/vendor/libgit2/src/fetch.h +6 -12
  265. data/vendor/libgit2/src/fetchhead.c +40 -33
  266. data/vendor/libgit2/src/fetchhead.h +5 -4
  267. data/vendor/libgit2/src/filebuf.c +163 -61
  268. data/vendor/libgit2/src/filebuf.h +13 -7
  269. data/vendor/libgit2/src/fileops.c +549 -407
  270. data/vendor/libgit2/src/fileops.h +97 -106
  271. data/vendor/libgit2/src/filter.c +989 -46
  272. data/vendor/libgit2/src/filter.h +21 -70
  273. data/vendor/libgit2/src/fnmatch.c +67 -11
  274. data/vendor/libgit2/src/fnmatch.h +27 -7
  275. data/vendor/libgit2/src/global.c +257 -63
  276. data/vendor/libgit2/src/global.h +19 -0
  277. data/vendor/libgit2/src/graph.c +39 -23
  278. data/vendor/libgit2/src/hash/hash_collisiondetect.h +51 -0
  279. data/vendor/libgit2/src/hash/hash_common_crypto.h +61 -0
  280. data/vendor/libgit2/src/hash/hash_generic.c +3 -3
  281. data/vendor/libgit2/src/hash/hash_generic.h +10 -5
  282. data/vendor/libgit2/src/hash/hash_mbedtls.c +38 -0
  283. data/vendor/libgit2/src/hash/hash_mbedtls.h +24 -0
  284. data/vendor/libgit2/src/hash/hash_openssl.h +26 -8
  285. data/vendor/libgit2/src/hash/hash_win32.c +71 -43
  286. data/vendor/libgit2/src/hash/hash_win32.h +4 -3
  287. data/vendor/libgit2/src/hash/sha1dc/sha1.c +1900 -0
  288. data/vendor/libgit2/src/hash/sha1dc/sha1.h +110 -0
  289. data/vendor/libgit2/src/hash/sha1dc/ubc_check.c +372 -0
  290. data/vendor/libgit2/src/hash/sha1dc/ubc_check.h +52 -0
  291. data/vendor/libgit2/src/hash.c +0 -1
  292. data/vendor/libgit2/src/hash.h +13 -6
  293. data/vendor/libgit2/src/hashsig.c +121 -126
  294. data/vendor/libgit2/src/ident.c +129 -0
  295. data/vendor/libgit2/src/idxmap.c +153 -0
  296. data/vendor/libgit2/src/idxmap.h +41 -0
  297. data/vendor/libgit2/src/ignore.c +362 -123
  298. data/vendor/libgit2/src/ignore.h +16 -4
  299. data/vendor/libgit2/src/index.c +2131 -692
  300. data/vendor/libgit2/src/index.h +138 -6
  301. data/vendor/libgit2/src/indexer.c +866 -266
  302. data/vendor/libgit2/src/indexer.h +16 -0
  303. data/vendor/libgit2/src/integer.h +106 -0
  304. data/vendor/libgit2/src/iterator.c +1888 -967
  305. data/vendor/libgit2/src/iterator.h +130 -67
  306. data/vendor/libgit2/src/khash.h +43 -29
  307. data/vendor/libgit2/src/mailmap.c +485 -0
  308. data/vendor/libgit2/src/mailmap.h +35 -0
  309. data/vendor/libgit2/src/map.h +1 -1
  310. data/vendor/libgit2/src/merge.c +1679 -479
  311. data/vendor/libgit2/src/merge.h +89 -22
  312. data/vendor/libgit2/src/merge_driver.c +426 -0
  313. data/vendor/libgit2/src/merge_driver.h +62 -0
  314. data/vendor/libgit2/src/merge_file.c +238 -101
  315. data/vendor/libgit2/src/message.c +4 -28
  316. data/vendor/libgit2/src/message.h +3 -1
  317. data/vendor/libgit2/src/mwindow.c +123 -15
  318. data/vendor/libgit2/src/mwindow.h +10 -1
  319. data/vendor/libgit2/src/netops.c +178 -499
  320. data/vendor/libgit2/src/netops.h +51 -27
  321. data/vendor/libgit2/src/notes.c +251 -94
  322. data/vendor/libgit2/src/notes.h +5 -2
  323. data/vendor/libgit2/src/object.c +253 -67
  324. data/vendor/libgit2/src/object.h +40 -2
  325. data/vendor/libgit2/src/object_api.c +30 -11
  326. data/vendor/libgit2/src/odb.c +765 -201
  327. data/vendor/libgit2/src/odb.h +40 -8
  328. data/vendor/libgit2/src/odb_loose.c +560 -346
  329. data/vendor/libgit2/src/odb_mempack.c +185 -0
  330. data/vendor/libgit2/src/odb_pack.c +117 -73
  331. data/vendor/libgit2/src/offmap.c +113 -0
  332. data/vendor/libgit2/src/offmap.h +32 -42
  333. data/vendor/libgit2/src/oid.c +45 -25
  334. data/vendor/libgit2/src/oid.h +26 -8
  335. data/vendor/libgit2/src/oidarray.c +34 -0
  336. data/vendor/libgit2/src/oidarray.h +20 -0
  337. data/vendor/libgit2/src/oidmap.c +125 -0
  338. data/vendor/libgit2/src/oidmap.h +30 -17
  339. data/vendor/libgit2/src/pack-objects.c +688 -265
  340. data/vendor/libgit2/src/pack-objects.h +27 -13
  341. data/vendor/libgit2/src/pack.c +418 -202
  342. data/vendor/libgit2/src/pack.h +25 -16
  343. data/vendor/libgit2/src/parse.c +124 -0
  344. data/vendor/libgit2/src/parse.h +61 -0
  345. data/vendor/libgit2/src/patch.c +223 -0
  346. data/vendor/libgit2/src/patch.h +68 -0
  347. data/vendor/libgit2/src/patch_generate.c +901 -0
  348. data/vendor/libgit2/src/patch_generate.h +69 -0
  349. data/vendor/libgit2/src/patch_parse.c +1136 -0
  350. data/vendor/libgit2/src/patch_parse.h +51 -0
  351. data/vendor/libgit2/src/path.c +1247 -241
  352. data/vendor/libgit2/src/path.h +353 -57
  353. data/vendor/libgit2/src/pathspec.c +586 -58
  354. data/vendor/libgit2/src/pathspec.h +37 -15
  355. data/vendor/libgit2/src/pool.c +134 -221
  356. data/vendor/libgit2/src/pool.h +38 -50
  357. data/vendor/libgit2/src/posix.c +76 -10
  358. data/vendor/libgit2/src/posix.h +74 -32
  359. data/vendor/libgit2/src/pqueue.c +79 -117
  360. data/vendor/libgit2/src/pqueue.h +38 -82
  361. data/vendor/libgit2/src/proxy.c +39 -0
  362. data/vendor/libgit2/src/proxy.h +17 -0
  363. data/vendor/libgit2/src/push.c +178 -279
  364. data/vendor/libgit2/src/push.h +93 -4
  365. data/vendor/libgit2/src/reader.c +265 -0
  366. data/vendor/libgit2/src/reader.h +107 -0
  367. data/vendor/libgit2/src/rebase.c +1364 -0
  368. data/vendor/libgit2/src/refdb.c +74 -19
  369. data/vendor/libgit2/src/refdb.h +16 -3
  370. data/vendor/libgit2/src/refdb_fs.c +1472 -603
  371. data/vendor/libgit2/src/refdb_fs.h +4 -0
  372. data/vendor/libgit2/src/reflog.c +40 -330
  373. data/vendor/libgit2/src/reflog.h +8 -2
  374. data/vendor/libgit2/src/refs.c +641 -225
  375. data/vendor/libgit2/src/refs.h +53 -6
  376. data/vendor/libgit2/src/refspec.c +175 -62
  377. data/vendor/libgit2/src/refspec.h +10 -25
  378. data/vendor/libgit2/src/remote.c +1741 -723
  379. data/vendor/libgit2/src/remote.h +17 -5
  380. data/vendor/libgit2/src/repository.c +1505 -421
  381. data/vendor/libgit2/src/repository.h +95 -15
  382. data/vendor/libgit2/src/reset.c +63 -26
  383. data/vendor/libgit2/src/revert.c +232 -0
  384. data/vendor/libgit2/src/revparse.c +94 -80
  385. data/vendor/libgit2/src/revwalk.c +427 -194
  386. data/vendor/libgit2/src/revwalk.h +14 -5
  387. data/vendor/libgit2/src/settings.c +290 -0
  388. data/vendor/libgit2/src/sha1_lookup.c +16 -159
  389. data/vendor/libgit2/src/sha1_lookup.h +5 -4
  390. data/vendor/libgit2/src/signature.c +138 -26
  391. data/vendor/libgit2/src/signature.h +5 -0
  392. data/vendor/libgit2/src/sortedcache.c +395 -0
  393. data/vendor/libgit2/src/sortedcache.h +180 -0
  394. data/vendor/libgit2/src/stash.c +629 -168
  395. data/vendor/libgit2/src/status.c +125 -75
  396. data/vendor/libgit2/src/status.h +4 -2
  397. data/vendor/libgit2/src/stdalloc.c +120 -0
  398. data/vendor/libgit2/src/stdalloc.h +17 -0
  399. data/vendor/libgit2/src/stream.h +86 -0
  400. data/vendor/libgit2/src/streams/mbedtls.c +483 -0
  401. data/vendor/libgit2/src/streams/mbedtls.h +23 -0
  402. data/vendor/libgit2/src/streams/openssl.c +789 -0
  403. data/vendor/libgit2/src/streams/openssl.h +23 -0
  404. data/vendor/libgit2/src/streams/registry.c +118 -0
  405. data/vendor/libgit2/src/streams/registry.h +19 -0
  406. data/vendor/libgit2/src/streams/socket.c +235 -0
  407. data/vendor/libgit2/src/streams/socket.h +23 -0
  408. data/vendor/libgit2/src/streams/stransport.c +323 -0
  409. data/vendor/libgit2/src/streams/stransport.h +21 -0
  410. data/vendor/libgit2/src/streams/tls.c +73 -0
  411. data/vendor/libgit2/src/streams/tls.h +31 -0
  412. data/vendor/libgit2/src/strmap.c +147 -0
  413. data/vendor/libgit2/src/strmap.h +46 -51
  414. data/vendor/libgit2/src/strnlen.h +24 -0
  415. data/vendor/libgit2/src/submodule.c +1633 -877
  416. data/vendor/libgit2/src/submodule.h +83 -21
  417. data/vendor/libgit2/src/sysdir.c +355 -0
  418. data/vendor/libgit2/src/sysdir.h +119 -0
  419. data/vendor/libgit2/src/tag.c +87 -62
  420. data/vendor/libgit2/src/tag.h +4 -1
  421. data/vendor/libgit2/src/thread-utils.c +3 -0
  422. data/vendor/libgit2/src/thread-utils.h +71 -35
  423. data/vendor/libgit2/src/trace.c +4 -4
  424. data/vendor/libgit2/src/trace.h +11 -3
  425. data/vendor/libgit2/src/trailer.c +416 -0
  426. data/vendor/libgit2/src/transaction.c +382 -0
  427. data/vendor/libgit2/src/transaction.h +14 -0
  428. data/vendor/libgit2/src/transport.c +133 -67
  429. data/vendor/libgit2/src/transports/auth.c +75 -0
  430. data/vendor/libgit2/src/transports/auth.h +64 -0
  431. data/vendor/libgit2/src/transports/auth_negotiate.c +277 -0
  432. data/vendor/libgit2/src/transports/auth_negotiate.h +27 -0
  433. data/vendor/libgit2/src/transports/cred.c +296 -68
  434. data/vendor/libgit2/src/transports/cred.h +16 -0
  435. data/vendor/libgit2/src/transports/cred_helpers.c +4 -0
  436. data/vendor/libgit2/src/transports/git.c +108 -90
  437. data/vendor/libgit2/src/transports/http.c +803 -258
  438. data/vendor/libgit2/src/transports/http.h +25 -0
  439. data/vendor/libgit2/src/transports/local.c +265 -169
  440. data/vendor/libgit2/src/transports/smart.c +255 -45
  441. data/vendor/libgit2/src/transports/smart.h +42 -22
  442. data/vendor/libgit2/src/transports/smart_pkt.c +250 -159
  443. data/vendor/libgit2/src/transports/smart_protocol.c +414 -196
  444. data/vendor/libgit2/src/transports/ssh.c +645 -236
  445. data/vendor/libgit2/src/transports/ssh.h +14 -0
  446. data/vendor/libgit2/src/transports/winhttp.c +809 -353
  447. data/vendor/libgit2/src/tree-cache.c +138 -52
  448. data/vendor/libgit2/src/tree-cache.h +14 -7
  449. data/vendor/libgit2/src/tree.c +620 -259
  450. data/vendor/libgit2/src/tree.h +12 -19
  451. data/vendor/libgit2/src/tsort.c +3 -2
  452. data/vendor/libgit2/src/unix/map.c +25 -7
  453. data/vendor/libgit2/src/unix/posix.h +77 -12
  454. data/vendor/libgit2/src/unix/pthread.h +56 -0
  455. data/vendor/libgit2/src/unix/realpath.c +12 -8
  456. data/vendor/libgit2/src/userdiff.h +208 -0
  457. data/vendor/libgit2/src/util.c +349 -165
  458. data/vendor/libgit2/src/util.h +167 -85
  459. data/vendor/libgit2/src/varint.c +43 -0
  460. data/vendor/libgit2/src/varint.h +17 -0
  461. data/vendor/libgit2/src/vector.c +156 -33
  462. data/vendor/libgit2/src/vector.h +41 -5
  463. data/vendor/libgit2/src/win32/dir.c +22 -42
  464. data/vendor/libgit2/src/win32/dir.h +7 -5
  465. data/vendor/libgit2/src/win32/error.c +6 -32
  466. data/vendor/libgit2/src/win32/error.h +4 -2
  467. data/vendor/libgit2/src/win32/findfile.c +62 -69
  468. data/vendor/libgit2/src/win32/findfile.h +5 -13
  469. data/vendor/libgit2/src/win32/git2.rc +44 -0
  470. data/vendor/libgit2/src/win32/map.c +39 -11
  471. data/vendor/libgit2/src/win32/mingw-compat.h +10 -11
  472. data/vendor/libgit2/src/win32/msvc-compat.h +10 -33
  473. data/vendor/libgit2/src/win32/path_w32.c +476 -0
  474. data/vendor/libgit2/src/win32/path_w32.h +104 -0
  475. data/vendor/libgit2/src/win32/posix.h +35 -30
  476. data/vendor/libgit2/src/win32/posix_w32.c +659 -327
  477. data/vendor/libgit2/src/win32/precompiled.h +7 -2
  478. data/vendor/libgit2/src/win32/reparse.h +57 -0
  479. data/vendor/libgit2/src/win32/thread.c +258 -0
  480. data/vendor/libgit2/src/win32/thread.h +64 -0
  481. data/vendor/libgit2/src/win32/utf-conv.c +127 -62
  482. data/vendor/libgit2/src/win32/utf-conv.h +47 -6
  483. data/vendor/libgit2/src/win32/version.h +21 -4
  484. data/vendor/libgit2/src/win32/w32_buffer.c +54 -0
  485. data/vendor/libgit2/src/win32/w32_buffer.h +20 -0
  486. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +438 -0
  487. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +129 -0
  488. data/vendor/libgit2/src/win32/w32_stack.c +193 -0
  489. data/vendor/libgit2/src/win32/w32_stack.h +140 -0
  490. data/vendor/libgit2/src/win32/w32_util.c +95 -0
  491. data/vendor/libgit2/src/win32/w32_util.h +170 -0
  492. data/vendor/libgit2/src/win32/win32-compat.h +52 -0
  493. data/vendor/libgit2/src/worktree.c +578 -0
  494. data/vendor/libgit2/src/worktree.h +39 -0
  495. data/vendor/libgit2/src/xdiff/xdiff.h +33 -18
  496. data/vendor/libgit2/src/xdiff/xdiffi.c +578 -88
  497. data/vendor/libgit2/src/xdiff/xdiffi.h +3 -2
  498. data/vendor/libgit2/src/xdiff/xemit.c +106 -45
  499. data/vendor/libgit2/src/xdiff/xemit.h +3 -3
  500. data/vendor/libgit2/src/xdiff/xhistogram.c +5 -4
  501. data/vendor/libgit2/src/xdiff/xinclude.h +3 -2
  502. data/vendor/libgit2/src/xdiff/xmacros.h +2 -2
  503. data/vendor/libgit2/src/xdiff/xmerge.c +167 -48
  504. data/vendor/libgit2/src/xdiff/xpatience.c +42 -10
  505. data/vendor/libgit2/src/xdiff/xprepare.c +14 -14
  506. data/vendor/libgit2/src/xdiff/xprepare.h +2 -2
  507. data/vendor/libgit2/src/xdiff/xtypes.h +2 -2
  508. data/vendor/libgit2/src/xdiff/xutils.c +60 -56
  509. data/vendor/libgit2/src/xdiff/xutils.h +3 -5
  510. data/vendor/libgit2/src/zstream.c +205 -0
  511. data/vendor/libgit2/src/zstream.h +53 -0
  512. metadata +281 -233
  513. data/Rakefile +0 -61
  514. data/ext/rugged/rugged_diff_patch.c +0 -169
  515. data/lib/rugged/diff/patch.rb +0 -28
  516. data/test/blob_test.rb +0 -341
  517. data/test/branch_test.rb +0 -199
  518. data/test/commit_test.rb +0 -104
  519. data/test/config_test.rb +0 -45
  520. data/test/coverage/cover.rb +0 -133
  521. data/test/diff_test.rb +0 -777
  522. data/test/errors_test.rb +0 -34
  523. data/test/fixtures/alternate/objects/14/6ae76773c91e3b1d00cf7a338ec55ae58297e2 +0 -0
  524. data/test/fixtures/alternate/objects/14/9c32d47e99d0a3572ff1e70a2e0051bbf347a9 +0 -0
  525. data/test/fixtures/alternate/objects/14/fb3108588f9421bf764041e5e3ac305eb6277f +0 -0
  526. data/test/fixtures/archive.tar.gz +0 -0
  527. data/test/fixtures/attr/attr0 +0 -1
  528. data/test/fixtures/attr/attr1 +0 -29
  529. data/test/fixtures/attr/attr2 +0 -21
  530. data/test/fixtures/attr/attr3 +0 -4
  531. data/test/fixtures/attr/binfile +0 -1
  532. data/test/fixtures/attr/dir/file +0 -0
  533. data/test/fixtures/attr/file +0 -1
  534. data/test/fixtures/attr/gitattributes +0 -29
  535. data/test/fixtures/attr/gitignore +0 -2
  536. data/test/fixtures/attr/ign +0 -1
  537. data/test/fixtures/attr/macro_bad +0 -1
  538. data/test/fixtures/attr/macro_test +0 -1
  539. data/test/fixtures/attr/root_test1 +0 -1
  540. data/test/fixtures/attr/root_test2 +0 -6
  541. data/test/fixtures/attr/root_test3 +0 -19
  542. data/test/fixtures/attr/root_test4.txt +0 -14
  543. data/test/fixtures/attr/sub/abc +0 -37
  544. data/test/fixtures/attr/sub/dir/file +0 -0
  545. data/test/fixtures/attr/sub/file +0 -1
  546. data/test/fixtures/attr/sub/ign/file +0 -1
  547. data/test/fixtures/attr/sub/ign/sub/file +0 -1
  548. data/test/fixtures/attr/sub/sub/dir +0 -0
  549. data/test/fixtures/attr/sub/sub/file +0 -1
  550. data/test/fixtures/attr/sub/sub/subsub.txt +0 -1
  551. data/test/fixtures/attr/sub/subdir_test1 +0 -2
  552. data/test/fixtures/attr/sub/subdir_test2.txt +0 -1
  553. data/test/fixtures/diff/another.txt +0 -38
  554. data/test/fixtures/diff/readme.txt +0 -36
  555. data/test/fixtures/mergedrepo/conflicts-one.txt +0 -5
  556. data/test/fixtures/mergedrepo/conflicts-two.txt +0 -5
  557. data/test/fixtures/mergedrepo/one.txt +0 -10
  558. data/test/fixtures/mergedrepo/two.txt +0 -12
  559. data/test/fixtures/status/current_file +0 -1
  560. data/test/fixtures/status/ignored_file +0 -1
  561. data/test/fixtures/status/modified_file +0 -2
  562. data/test/fixtures/status/new_file +0 -1
  563. data/test/fixtures/status/staged_changes +0 -2
  564. data/test/fixtures/status/staged_changes_modified_file +0 -3
  565. data/test/fixtures/status/staged_delete_modified_file +0 -1
  566. data/test/fixtures/status/staged_new_file +0 -1
  567. data/test/fixtures/status/staged_new_file_modified_file +0 -2
  568. data/test/fixtures/status/subdir/current_file +0 -1
  569. data/test/fixtures/status/subdir/modified_file +0 -2
  570. data/test/fixtures/status/subdir/new_file +0 -1
  571. data/test/fixtures/status/subdir.txt +0 -2
  572. data/test/fixtures/status//350/277/231 +0 -1
  573. data/test/fixtures/testrepo.git/HEAD +0 -1
  574. data/test/fixtures/testrepo.git/config +0 -13
  575. data/test/fixtures/testrepo.git/description +0 -1
  576. data/test/fixtures/testrepo.git/index +0 -0
  577. data/test/fixtures/testrepo.git/info/exclude +0 -6
  578. data/test/fixtures/testrepo.git/logs/HEAD +0 -3
  579. data/test/fixtures/testrepo.git/logs/refs/heads/master +0 -3
  580. data/test/fixtures/testrepo.git/logs/refs/notes/commits +0 -1
  581. data/test/fixtures/testrepo.git/objects/0c/37a5391bbff43c37f0d0371823a5509eed5b1d +0 -0
  582. data/test/fixtures/testrepo.git/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08 +0 -0
  583. data/test/fixtures/testrepo.git/objects/18/1037049a54a1eb5fab404658a3a250b44335d7 +0 -0
  584. data/test/fixtures/testrepo.git/objects/18/10dff58d8a660512d4832e740f692884338ccd +0 -0
  585. data/test/fixtures/testrepo.git/objects/2d/2eff63372b08adf0a9eb84109ccf7d19e2f3a2 +0 -0
  586. data/test/fixtures/testrepo.git/objects/36/060c58702ed4c2a40832c51758d5344201d89a +0 -2
  587. data/test/fixtures/testrepo.git/objects/44/1034f860c1d5d90e4188d11ae0d325176869a8 +0 -1
  588. data/test/fixtures/testrepo.git/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 +0 -0
  589. data/test/fixtures/testrepo.git/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 +0 -2
  590. data/test/fixtures/testrepo.git/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644 +0 -2
  591. data/test/fixtures/testrepo.git/objects/60/d415052a33de2150bf68757f6461df4f563ae4 +0 -0
  592. data/test/fixtures/testrepo.git/objects/61/9f9935957e010c419cb9d15621916ddfcc0b96 +0 -0
  593. data/test/fixtures/testrepo.git/objects/68/8a8f4ef7496901d15322972f96e212a9e466cc +0 -1
  594. data/test/fixtures/testrepo.git/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a +0 -0
  595. data/test/fixtures/testrepo.git/objects/77/71329dfa3002caf8c61a0ceb62a31d09023f37 +0 -0
  596. data/test/fixtures/testrepo.git/objects/81/4889a078c031f61ed08ab5fa863aea9314344d +0 -0
  597. data/test/fixtures/testrepo.git/objects/84/96071c1b46c854b31185ea97743be6a8774479 +0 -0
  598. data/test/fixtures/testrepo.git/objects/94/eca2de348d5f672faf56b0decafa5937e3235e +0 -0
  599. data/test/fixtures/testrepo.git/objects/9b/7384fe1676186192842f5d3e129457b62db9e3 +0 -0
  600. data/test/fixtures/testrepo.git/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a +0 -3
  601. data/test/fixtures/testrepo.git/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f +0 -2
  602. data/test/fixtures/testrepo.git/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd +0 -0
  603. data/test/fixtures/testrepo.git/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 +0 -0
  604. data/test/fixtures/testrepo.git/objects/b7/4713326bc972cc15751ed504dca6f6f3b91f7a +0 -3
  605. data/test/fixtures/testrepo.git/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644 +0 -3
  606. data/test/fixtures/testrepo.git/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd +0 -3
  607. data/test/fixtures/testrepo.git/objects/c4/dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b +0 -0
  608. data/test/fixtures/testrepo.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
  609. data/test/fixtures/testrepo.git/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1 +0 -0
  610. data/test/fixtures/testrepo.git/objects/fa/49b077972391ad58037050f2a75f74e3671e92 +0 -0
  611. data/test/fixtures/testrepo.git/objects/fd/093bff70906175335656e6ce6ae05783708765 +0 -0
  612. data/test/fixtures/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx +0 -0
  613. data/test/fixtures/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack +0 -0
  614. data/test/fixtures/testrepo.git/packed-refs +0 -2
  615. data/test/fixtures/testrepo.git/refs/heads/master +0 -1
  616. data/test/fixtures/testrepo.git/refs/notes/commits +0 -1
  617. data/test/fixtures/testrepo.git/refs/tags/v0.9 +0 -1
  618. data/test/fixtures/testrepo.git/refs/tags/v1.0 +0 -1
  619. data/test/fixtures/text_file.md +0 -464
  620. data/test/fixtures/unsymlinked.git/HEAD +0 -1
  621. data/test/fixtures/unsymlinked.git/config +0 -6
  622. data/test/fixtures/unsymlinked.git/description +0 -1
  623. data/test/fixtures/unsymlinked.git/info/exclude +0 -2
  624. data/test/fixtures/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf +0 -0
  625. data/test/fixtures/unsymlinked.git/objects/13/a5e939bca25940c069fd2169d993dba328e30b +0 -0
  626. data/test/fixtures/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c +0 -0
  627. data/test/fixtures/unsymlinked.git/objects/58/1fadd35b4cf320d102a152f918729011604773 +0 -0
  628. data/test/fixtures/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c +0 -0
  629. data/test/fixtures/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27 +0 -0
  630. data/test/fixtures/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d +0 -0
  631. data/test/fixtures/unsymlinked.git/objects/80/6999882bf91d24241e4077906b9017605eb1f3 +0 -0
  632. data/test/fixtures/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230 +0 -0
  633. data/test/fixtures/unsymlinked.git/objects/a8/595ccca04f40818ae0155c8f9c77a230e597b6 +0 -2
  634. data/test/fixtures/unsymlinked.git/objects/cf/8f1cf5cce859c438d6cc067284cb5e161206e7 +0 -0
  635. data/test/fixtures/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a +0 -0
  636. data/test/fixtures/unsymlinked.git/objects/f4/e16fb76536591a41454194058d048d8e4dd2e9 +0 -0
  637. data/test/fixtures/unsymlinked.git/objects/f9/e65619d93fdf2673882e0a261c5e93b1a84006 +0 -0
  638. data/test/fixtures/unsymlinked.git/refs/heads/exe-file +0 -1
  639. data/test/fixtures/unsymlinked.git/refs/heads/master +0 -1
  640. data/test/fixtures/unsymlinked.git/refs/heads/reg-file +0 -1
  641. data/test/index_test.rb +0 -333
  642. data/test/lib_test.rb +0 -127
  643. data/test/note_test.rb +0 -158
  644. data/test/object_test.rb +0 -43
  645. data/test/reference_test.rb +0 -207
  646. data/test/remote_test.rb +0 -324
  647. data/test/repo_pack_test.rb +0 -24
  648. data/test/repo_reset_test.rb +0 -82
  649. data/test/repo_test.rb +0 -402
  650. data/test/tag_test.rb +0 -68
  651. data/test/test_helper.rb +0 -92
  652. data/test/tree_test.rb +0 -91
  653. data/test/walker_test.rb +0 -88
  654. data/vendor/libgit2/Makefile.embed +0 -42
  655. data/vendor/libgit2/include/git2/push.h +0 -131
  656. data/vendor/libgit2/include/git2/threads.h +0 -50
  657. data/vendor/libgit2/src/amiga/map.c +0 -48
  658. data/vendor/libgit2/src/bswap.h +0 -97
  659. data/vendor/libgit2/src/compress.c +0 -53
  660. data/vendor/libgit2/src/config_file.h +0 -60
  661. data/vendor/libgit2/src/delta-apply.c +0 -134
  662. data/vendor/libgit2/src/delta-apply.h +0 -50
  663. data/vendor/libgit2/src/diff_patch.c +0 -995
  664. data/vendor/libgit2/src/diff_patch.h +0 -46
  665. data/vendor/libgit2/src/hashsig.h +0 -72
  666. data/vendor/libgit2/src/merge_file.h +0 -71
  667. data/vendor/libgit2/src/win32/pthread.c +0 -144
  668. data/vendor/libgit2/src/win32/pthread.h +0 -50
@@ -16,46 +16,6 @@
16
16
  /**
17
17
  * @file git2/diff.h
18
18
  * @brief Git tree and file differencing routines.
19
- *
20
- * Overview
21
- * --------
22
- *
23
- * Calculating diffs is generally done in two phases: building a diff list
24
- * then traversing the diff list. This makes is easier to share logic
25
- * across the various types of diffs (tree vs tree, workdir vs index, etc.),
26
- * and also allows you to insert optional diff list post-processing phases,
27
- * such as rename detected, in between the steps. When you are done with a
28
- * diff list object, it must be freed.
29
- *
30
- * Terminology
31
- * -----------
32
- *
33
- * To understand the diff APIs, you should know the following terms:
34
- *
35
- * - A `diff` or `diff list` represents the cumulative list of differences
36
- * between two snapshots of a repository (possibly filtered by a set of
37
- * file name patterns). This is the `git_diff_list` object.
38
- * - A `delta` is a file pair with an old and new revision. The old version
39
- * may be absent if the file was just created and the new version may be
40
- * absent if the file was deleted. A diff is mostly just a list of deltas.
41
- * - A `binary` file / delta is a file (or pair) for which no text diffs
42
- * should be generated. A diff list can contain delta entries that are
43
- * binary, but no diff content will be output for those files. There is
44
- * a base heuristic for binary detection and you can further tune the
45
- * behavior with git attributes or diff flags and option settings.
46
- * - A `hunk` is a span of modified lines in a delta along with some stable
47
- * surrounding context. You can configure the amount of context and other
48
- * properties of how hunks are generated. Each hunk also comes with a
49
- * header that described where it starts and ends in both the old and new
50
- * versions in the delta.
51
- * - A `line` is a range of characters inside a hunk. It could be a context
52
- * line (i.e. in both old and new versions), an added line (i.e. only in
53
- * the new version), or a removed line (i.e. only in the old version).
54
- * Unfortunately, we don't know anything about the encoding of data in the
55
- * file being diffed, so we cannot tell you much about the line content.
56
- * Line data will not be NUL-byte terminated, however, because it will be
57
- * just a span of bytes inside the larger file.
58
- *
59
19
  * @ingroup Git
60
20
  * @{
61
21
  */
@@ -68,100 +28,169 @@ GIT_BEGIN_DECL
68
28
  typedef enum {
69
29
  /** Normal diff, the default */
70
30
  GIT_DIFF_NORMAL = 0,
71
- /** Reverse the sides of the diff */
72
- GIT_DIFF_REVERSE = (1 << 0),
73
- /** Treat all files as text, disabling binary attributes & detection */
74
- GIT_DIFF_FORCE_TEXT = (1 << 1),
75
- /** Ignore all whitespace */
76
- GIT_DIFF_IGNORE_WHITESPACE = (1 << 2),
77
- /** Ignore changes in amount of whitespace */
78
- GIT_DIFF_IGNORE_WHITESPACE_CHANGE = (1 << 3),
79
- /** Ignore whitespace at end of line */
80
- GIT_DIFF_IGNORE_WHITESPACE_EOL = (1 << 4),
81
- /** Exclude submodules from the diff completely */
82
- GIT_DIFF_IGNORE_SUBMODULES = (1 << 5),
83
- /** Use the "patience diff" algorithm (currently unimplemented) */
84
- GIT_DIFF_PATIENCE = (1 << 6),
85
- /** Include ignored files in the diff list */
86
- GIT_DIFF_INCLUDE_IGNORED = (1 << 7),
87
- /** Include untracked files in the diff list */
88
- GIT_DIFF_INCLUDE_UNTRACKED = (1 << 8),
89
- /** Include unmodified files in the diff list */
90
- GIT_DIFF_INCLUDE_UNMODIFIED = (1 << 9),
91
31
 
92
- /** Even with GIT_DIFF_INCLUDE_UNTRACKED, an entire untracked
93
- * directory will be marked with only a single entry in the diff list
94
- * (a la what core Git does in `git status`); this flag adds *all*
95
- * files under untracked directories as UNTRACKED entries, too.
32
+ /*
33
+ * Options controlling which files will be in the diff
96
34
  */
97
- GIT_DIFF_RECURSE_UNTRACKED_DIRS = (1 << 10),
98
35
 
99
- /** If the pathspec is set in the diff options, this flags means to
100
- * apply it as an exact match instead of as an fnmatch pattern.
101
- */
102
- GIT_DIFF_DISABLE_PATHSPEC_MATCH = (1 << 11),
36
+ /** Reverse the sides of the diff */
37
+ GIT_DIFF_REVERSE = (1u << 0),
103
38
 
104
- /** Use case insensitive filename comparisons */
105
- GIT_DIFF_DELTAS_ARE_ICASE = (1 << 12),
39
+ /** Include ignored files in the diff */
40
+ GIT_DIFF_INCLUDE_IGNORED = (1u << 1),
106
41
 
107
- /** When generating patch text, include the content of untracked
108
- * files. This automatically turns on GIT_DIFF_INCLUDE_UNTRACKED but
109
- * it does not turn on GIT_DIFF_RECURSE_UNTRACKED_DIRS. Add that
110
- * flag if you want the content of every single UNTRACKED file.
42
+ /** Even with GIT_DIFF_INCLUDE_IGNORED, an entire ignored directory
43
+ * will be marked with only a single entry in the diff; this flag
44
+ * adds all files under the directory as IGNORED entries, too.
111
45
  */
112
- GIT_DIFF_INCLUDE_UNTRACKED_CONTENT = (1 << 13),
46
+ GIT_DIFF_RECURSE_IGNORED_DIRS = (1u << 2),
113
47
 
114
- /** Disable updating of the `binary` flag in delta records. This is
115
- * useful when iterating over a diff if you don't need hunk and data
116
- * callbacks and want to avoid having to load file completely.
48
+ /** Include untracked files in the diff */
49
+ GIT_DIFF_INCLUDE_UNTRACKED = (1u << 3),
50
+
51
+ /** Even with GIT_DIFF_INCLUDE_UNTRACKED, an entire untracked
52
+ * directory will be marked with only a single entry in the diff
53
+ * (a la what core Git does in `git status`); this flag adds *all*
54
+ * files under untracked directories as UNTRACKED entries, too.
117
55
  */
118
- GIT_DIFF_SKIP_BINARY_CHECK = (1 << 14),
56
+ GIT_DIFF_RECURSE_UNTRACKED_DIRS = (1u << 4),
57
+
58
+ /** Include unmodified files in the diff */
59
+ GIT_DIFF_INCLUDE_UNMODIFIED = (1u << 5),
119
60
 
120
61
  /** Normally, a type change between files will be converted into a
121
62
  * DELETED record for the old and an ADDED record for the new; this
122
63
  * options enabled the generation of TYPECHANGE delta records.
123
64
  */
124
- GIT_DIFF_INCLUDE_TYPECHANGE = (1 << 15),
65
+ GIT_DIFF_INCLUDE_TYPECHANGE = (1u << 6),
125
66
 
126
67
  /** Even with GIT_DIFF_INCLUDE_TYPECHANGE, blob->tree changes still
127
68
  * generally show as a DELETED blob. This flag tries to correctly
128
69
  * label blob->tree transitions as TYPECHANGE records with new_file's
129
70
  * mode set to tree. Note: the tree SHA will not be available.
130
71
  */
131
- GIT_DIFF_INCLUDE_TYPECHANGE_TREES = (1 << 16),
72
+ GIT_DIFF_INCLUDE_TYPECHANGE_TREES = (1u << 7),
132
73
 
133
74
  /** Ignore file mode changes */
134
- GIT_DIFF_IGNORE_FILEMODE = (1 << 17),
75
+ GIT_DIFF_IGNORE_FILEMODE = (1u << 8),
135
76
 
136
- /** Even with GIT_DIFF_INCLUDE_IGNORED, an entire ignored directory
137
- * will be marked with only a single entry in the diff list; this flag
138
- * adds all files under the directory as IGNORED entries, too.
77
+ /** Treat all submodules as unmodified */
78
+ GIT_DIFF_IGNORE_SUBMODULES = (1u << 9),
79
+
80
+ /** Use case insensitive filename comparisons */
81
+ GIT_DIFF_IGNORE_CASE = (1u << 10),
82
+
83
+ /** May be combined with `GIT_DIFF_IGNORE_CASE` to specify that a file
84
+ * that has changed case will be returned as an add/delete pair.
139
85
  */
140
- GIT_DIFF_RECURSE_IGNORED_DIRS = (1 << 18),
141
-
142
- /** Core Git scans inside untracked directories, labeling them IGNORED
143
- * if they are empty or only contain ignored files; a directory is
144
- * consider UNTRACKED only if it has an actual untracked file in it.
145
- * This scan is extra work for a case you often don't care about. This
146
- * flag makes libgit2 immediately label an untracked directory as
147
- * UNTRACKED without looking inside it (which differs from core Git).
148
- * Of course, ignore rules are still checked for the directory itself.
86
+ GIT_DIFF_INCLUDE_CASECHANGE = (1u << 11),
87
+
88
+ /** If the pathspec is set in the diff options, this flags indicates
89
+ * that the paths will be treated as literal paths instead of
90
+ * fnmatch patterns. Each path in the list must either be a full
91
+ * path to a file or a directory. (A trailing slash indicates that
92
+ * the path will _only_ match a directory). If a directory is
93
+ * specified, all children will be included.
149
94
  */
150
- GIT_DIFF_FAST_UNTRACKED_DIRS = (1 << 19),
95
+ GIT_DIFF_DISABLE_PATHSPEC_MATCH = (1u << 12),
151
96
 
97
+ /** Disable updating of the `binary` flag in delta records. This is
98
+ * useful when iterating over a diff if you don't need hunk and data
99
+ * callbacks and want to avoid having to load file completely.
100
+ */
101
+ GIT_DIFF_SKIP_BINARY_CHECK = (1u << 13),
102
+
103
+ /** When diff finds an untracked directory, to match the behavior of
104
+ * core Git, it scans the contents for IGNORED and UNTRACKED files.
105
+ * If *all* contents are IGNORED, then the directory is IGNORED; if
106
+ * any contents are not IGNORED, then the directory is UNTRACKED.
107
+ * This is extra work that may not matter in many cases. This flag
108
+ * turns off that scan and immediately labels an untracked directory
109
+ * as UNTRACKED (changing the behavior to not match core Git).
110
+ */
111
+ GIT_DIFF_ENABLE_FAST_UNTRACKED_DIRS = (1u << 14),
112
+
113
+ /** When diff finds a file in the working directory with stat
114
+ * information different from the index, but the OID ends up being the
115
+ * same, write the correct stat information into the index. Note:
116
+ * without this flag, diff will always leave the index untouched.
117
+ */
118
+ GIT_DIFF_UPDATE_INDEX = (1u << 15),
119
+
120
+ /** Include unreadable files in the diff */
121
+ GIT_DIFF_INCLUDE_UNREADABLE = (1u << 16),
122
+
123
+ /** Include unreadable files in the diff */
124
+ GIT_DIFF_INCLUDE_UNREADABLE_AS_UNTRACKED = (1u << 17),
125
+
126
+ /*
127
+ * Options controlling how output will be generated
128
+ */
129
+
130
+ /** Use a heuristic that takes indentation and whitespace into account
131
+ * which generally can produce better diffs when dealing with ambiguous
132
+ * diff hunks.
133
+ */
134
+ GIT_DIFF_INDENT_HEURISTIC = (1u << 18),
135
+
136
+ /** Treat all files as text, disabling binary attributes & detection */
137
+ GIT_DIFF_FORCE_TEXT = (1u << 20),
152
138
  /** Treat all files as binary, disabling text diffs */
153
- GIT_DIFF_FORCE_BINARY = (1 << 20),
139
+ GIT_DIFF_FORCE_BINARY = (1u << 21),
140
+
141
+ /** Ignore all whitespace */
142
+ GIT_DIFF_IGNORE_WHITESPACE = (1u << 22),
143
+ /** Ignore changes in amount of whitespace */
144
+ GIT_DIFF_IGNORE_WHITESPACE_CHANGE = (1u << 23),
145
+ /** Ignore whitespace at end of line */
146
+ GIT_DIFF_IGNORE_WHITESPACE_EOL = (1u << 24),
147
+
148
+ /** When generating patch text, include the content of untracked
149
+ * files. This automatically turns on GIT_DIFF_INCLUDE_UNTRACKED but
150
+ * it does not turn on GIT_DIFF_RECURSE_UNTRACKED_DIRS. Add that
151
+ * flag if you want the content of every single UNTRACKED file.
152
+ */
153
+ GIT_DIFF_SHOW_UNTRACKED_CONTENT = (1u << 25),
154
+
155
+ /** When generating output, include the names of unmodified files if
156
+ * they are included in the git_diff. Normally these are skipped in
157
+ * the formats that list files (e.g. name-only, name-status, raw).
158
+ * Even with this, these will not be included in patch format.
159
+ */
160
+ GIT_DIFF_SHOW_UNMODIFIED = (1u << 26),
161
+
162
+ /** Use the "patience diff" algorithm */
163
+ GIT_DIFF_PATIENCE = (1u << 28),
164
+ /** Take extra time to find minimal diff */
165
+ GIT_DIFF_MINIMAL = (1u << 29),
166
+
167
+ /** Include the necessary deflate / delta information so that `git-apply`
168
+ * can apply given diff information to binary files.
169
+ */
170
+ GIT_DIFF_SHOW_BINARY = (1u << 30),
154
171
  } git_diff_option_t;
155
172
 
156
173
  /**
157
- * The diff list object that contains all individual file deltas.
174
+ * The diff object that contains all individual file deltas.
175
+ *
176
+ * A `diff` represents the cumulative list of differences between two
177
+ * snapshots of a repository (possibly filtered by a set of file name
178
+ * patterns).
179
+ *
180
+ * Calculating diffs is generally done in two phases: building a list of
181
+ * diffs then traversing it. This makes is easier to share logic across
182
+ * the various types of diffs (tree vs tree, workdir vs index, etc.), and
183
+ * also allows you to insert optional diff post-processing phases,
184
+ * such as rename detection, in between the steps. When you are done with
185
+ * a diff object, it must be freed.
158
186
  *
159
187
  * This is an opaque structure which will be allocated by one of the diff
160
- * generator functions below (such as `git_diff_tree_to_tree`). You are
188
+ * generator functions below (such as `git_diff_tree_to_tree`). You are
161
189
  * responsible for releasing the object memory when done, using the
162
- * `git_diff_list_free()` function.
190
+ * `git_diff_free()` function.
191
+ *
163
192
  */
164
- typedef struct git_diff_list git_diff_list;
193
+ typedef struct git_diff git_diff;
165
194
 
166
195
  /**
167
196
  * Flags for the delta object and the file objects on each side.
@@ -172,41 +201,44 @@ typedef struct git_diff_list git_diff_list;
172
201
  * considered reserved for internal or future use.
173
202
  */
174
203
  typedef enum {
175
- GIT_DIFF_FLAG_BINARY = (1 << 0), /** file(s) treated as binary data */
176
- GIT_DIFF_FLAG_NOT_BINARY = (1 << 1), /** file(s) treated as text data */
177
- GIT_DIFF_FLAG_VALID_OID = (1 << 2), /** `oid` value is known correct */
204
+ GIT_DIFF_FLAG_BINARY = (1u << 0), /**< file(s) treated as binary data */
205
+ GIT_DIFF_FLAG_NOT_BINARY = (1u << 1), /**< file(s) treated as text data */
206
+ GIT_DIFF_FLAG_VALID_ID = (1u << 2), /**< `id` value is known correct */
207
+ GIT_DIFF_FLAG_EXISTS = (1u << 3), /**< file exists at this side of the delta */
178
208
  } git_diff_flag_t;
179
209
 
180
210
  /**
181
211
  * What type of change is described by a git_diff_delta?
182
212
  *
183
213
  * `GIT_DELTA_RENAMED` and `GIT_DELTA_COPIED` will only show up if you run
184
- * `git_diff_find_similar()` on the diff list object.
214
+ * `git_diff_find_similar()` on the diff object.
185
215
  *
186
216
  * `GIT_DELTA_TYPECHANGE` only shows up given `GIT_DIFF_INCLUDE_TYPECHANGE`
187
217
  * in the option flags (otherwise type changes will be split into ADDED /
188
218
  * DELETED pairs).
189
219
  */
190
220
  typedef enum {
191
- GIT_DELTA_UNMODIFIED = 0, /** no changes */
192
- GIT_DELTA_ADDED = 1, /** entry does not exist in old version */
193
- GIT_DELTA_DELETED = 2, /** entry does not exist in new version */
194
- GIT_DELTA_MODIFIED = 3, /** entry content changed between old and new */
195
- GIT_DELTA_RENAMED = 4, /** entry was renamed between old and new */
196
- GIT_DELTA_COPIED = 5, /** entry was copied from another old entry */
197
- GIT_DELTA_IGNORED = 6, /** entry is ignored item in workdir */
198
- GIT_DELTA_UNTRACKED = 7, /** entry is untracked item in workdir */
199
- GIT_DELTA_TYPECHANGE = 8, /** type of entry changed between old and new */
221
+ GIT_DELTA_UNMODIFIED = 0, /**< no changes */
222
+ GIT_DELTA_ADDED = 1, /**< entry does not exist in old version */
223
+ GIT_DELTA_DELETED = 2, /**< entry does not exist in new version */
224
+ GIT_DELTA_MODIFIED = 3, /**< entry content changed between old and new */
225
+ GIT_DELTA_RENAMED = 4, /**< entry was renamed between old and new */
226
+ GIT_DELTA_COPIED = 5, /**< entry was copied from another old entry */
227
+ GIT_DELTA_IGNORED = 6, /**< entry is ignored item in workdir */
228
+ GIT_DELTA_UNTRACKED = 7, /**< entry is untracked item in workdir */
229
+ GIT_DELTA_TYPECHANGE = 8, /**< type of entry changed between old and new */
230
+ GIT_DELTA_UNREADABLE = 9, /**< entry is unreadable */
231
+ GIT_DELTA_CONFLICTED = 10, /**< entry in the index is conflicted */
200
232
  } git_delta_t;
201
233
 
202
234
  /**
203
- * Description of one side of a diff entry.
235
+ * Description of one side of a delta.
204
236
  *
205
- * Although this is called a "file", it may actually represent a file, a
206
- * symbolic link, a submodule commit id, or even a tree (although that only
207
- * if you are tracking type changes or ignored/untracked directories).
237
+ * Although this is called a "file", it could represent a file, a symbolic
238
+ * link, a submodule commit id, or even a tree (although that only if you
239
+ * are tracking type changes or ignored/untracked directories).
208
240
  *
209
- * The `oid` is the `git_oid` of the item. If the entry represents an
241
+ * The `id` is the `git_oid` of the item. If the entry represents an
210
242
  * absent side of a diff (e.g. the `old_file` of a `GIT_DELTA_ADDED` delta),
211
243
  * then the oid will be zeroes.
212
244
  *
@@ -219,21 +251,30 @@ typedef enum {
219
251
  *
220
252
  * `mode` is, roughly, the stat() `st_mode` value for the item. This will
221
253
  * be restricted to one of the `git_filemode_t` values.
254
+ *
255
+ * The `id_abbrev` represents the known length of the `id` field, when
256
+ * converted to a hex string. It is generally `GIT_OID_HEXSZ`, unless this
257
+ * delta was created from reading a patch file, in which case it may be
258
+ * abbreviated to something reasonable, like 7 characters.
222
259
  */
223
260
  typedef struct {
224
- git_oid oid;
261
+ git_oid id;
225
262
  const char *path;
226
263
  git_off_t size;
227
264
  uint32_t flags;
228
265
  uint16_t mode;
266
+ uint16_t id_abbrev;
229
267
  } git_diff_file;
230
268
 
231
269
  /**
232
270
  * Description of changes to one entry.
233
271
  *
234
- * When iterating over a diff list object, this will be passed to most
235
- * callback functions and you can use the contents to understand exactly
236
- * what has changed.
272
+ * A `delta` is a file pair with an old and new revision. The old version
273
+ * may be absent if the file was just created and the new version may be
274
+ * absent if the file was deleted. A diff is mostly just a list of deltas.
275
+ *
276
+ * When iterating over a diff, this will be passed to most callbacks and
277
+ * you can use the contents to understand exactly what has changed.
237
278
  *
238
279
  * The `old_file` represents the "from" side of the diff and the `new_file`
239
280
  * represents to "to" side of the diff. What those means depend on the
@@ -266,32 +307,49 @@ typedef struct {
266
307
  * the score (a la `printf("M%03d", 100 - delta->similarity)`).
267
308
  */
268
309
  typedef struct {
310
+ git_delta_t status;
311
+ uint32_t flags; /**< git_diff_flag_t values */
312
+ uint16_t similarity; /**< for RENAMED and COPIED, value 0-100 */
313
+ uint16_t nfiles; /**< number of files in this delta */
269
314
  git_diff_file old_file;
270
315
  git_diff_file new_file;
271
- git_delta_t status;
272
- uint32_t similarity; /**< for RENAMED and COPIED, value 0-100 */
273
- uint32_t flags;
274
316
  } git_diff_delta;
275
317
 
276
318
  /**
277
319
  * Diff notification callback function.
278
320
  *
279
- * The callback will be called for each file, just before the `git_delta_t`
280
- * gets inserted into the diff list.
321
+ * The callback will be called for each file, just before the `git_diff_delta`
322
+ * gets inserted into the diff.
281
323
  *
282
324
  * When the callback:
283
325
  * - returns < 0, the diff process will be aborted.
284
- * - returns > 0, the delta will not be inserted into the diff list, but the
326
+ * - returns > 0, the delta will not be inserted into the diff, but the
285
327
  * diff process continues.
286
- * - returns 0, the delta is inserted into the diff list, and the diff process
328
+ * - returns 0, the delta is inserted into the diff, and the diff process
287
329
  * continues.
288
330
  */
289
- typedef int (*git_diff_notify_cb)(
290
- const git_diff_list *diff_so_far,
331
+ typedef int GIT_CALLBACK(git_diff_notify_cb)(
332
+ const git_diff *diff_so_far,
291
333
  const git_diff_delta *delta_to_add,
292
334
  const char *matched_pathspec,
293
335
  void *payload);
294
336
 
337
+ /**
338
+ * Diff progress callback.
339
+ *
340
+ * Called before each file comparison.
341
+ *
342
+ * @param diff_so_far The diff being generated.
343
+ * @param old_path The path to the old file or NULL.
344
+ * @param new_path The path to the new file or NULL.
345
+ * @return Non-zero to abort the diff.
346
+ */
347
+ typedef int GIT_CALLBACK(git_diff_progress_cb)(
348
+ const git_diff *diff_so_far,
349
+ const char *old_path,
350
+ const char *new_path,
351
+ void *payload);
352
+
295
353
  /**
296
354
  * Structure describing options about how the diff should be executed.
297
355
  *
@@ -299,81 +357,219 @@ typedef int (*git_diff_notify_cb)(
299
357
  * values. Similarly, passing NULL for the options structure will
300
358
  * give the defaults. The default values are marked below.
301
359
  *
302
- * - `flags` is a combination of the `git_diff_option_t` values above
303
- * - `context_lines` is the number of unchanged lines that define the
304
- * boundary of a hunk (and to display before and after)
305
- * - `interhunk_lines` is the maximum number of unchanged lines between
306
- * hunk boundaries before the hunks will be merged into a one.
307
- * - `old_prefix` is the virtual "directory" to prefix to old file names
308
- * in hunk headers (default "a")
309
- * - `new_prefix` is the virtual "directory" to prefix to new file names
310
- * in hunk headers (default "b")
311
- * - `pathspec` is an array of paths / fnmatch patterns to constrain diff
312
- * - `max_size` is a file size (in bytes) above which a blob will be marked
313
- * as binary automatically; pass a negative value to disable.
314
- * - `notify_cb` is an optional callback function, notifying the consumer of
315
- * which files are being examined as the diff is generated
316
- * - `notify_payload` is the payload data to pass to the `notify_cb` function
317
360
  */
318
361
  typedef struct {
319
362
  unsigned int version; /**< version for the struct */
320
- uint32_t flags; /**< defaults to GIT_DIFF_NORMAL */
321
- uint16_t context_lines; /**< defaults to 3 */
322
- uint16_t interhunk_lines; /**< defaults to 0 */
323
- const char *old_prefix; /**< defaults to "a" */
324
- const char *new_prefix; /**< defaults to "b" */
325
- git_strarray pathspec; /**< defaults to include all paths */
326
- git_off_t max_size; /**< defaults to 512MB */
327
- git_diff_notify_cb notify_cb;
328
- void *notify_payload;
363
+
364
+ /**
365
+ * A combination of `git_diff_option_t` values above.
366
+ * Defaults to GIT_DIFF_NORMAL
367
+ */
368
+ uint32_t flags;
369
+
370
+ /* options controlling which files are in the diff */
371
+
372
+ /** Overrides the submodule ignore setting for all submodules in the diff. */
373
+ git_submodule_ignore_t ignore_submodules;
374
+
375
+ /**
376
+ * An array of paths / fnmatch patterns to constrain diff.
377
+ * All paths are included by default.
378
+ */
379
+ git_strarray pathspec;
380
+
381
+ /**
382
+ * An optional callback function, notifying the consumer of changes to
383
+ * the diff as new deltas are added.
384
+ */
385
+ git_diff_notify_cb notify_cb;
386
+
387
+ /**
388
+ * An optional callback function, notifying the consumer of which files
389
+ * are being examined as the diff is generated.
390
+ */
391
+ git_diff_progress_cb progress_cb;
392
+
393
+ /** The payload to pass to the callback functions. */
394
+ void *payload;
395
+
396
+ /* options controlling how to diff text is generated */
397
+
398
+ /**
399
+ * The number of unchanged lines that define the boundary of a hunk
400
+ * (and to display before and after). Defaults to 3.
401
+ */
402
+ uint32_t context_lines;
403
+ /**
404
+ * The maximum number of unchanged lines between hunk boundaries before
405
+ * the hunks will be merged into one. Defaults to 0.
406
+ */
407
+ uint32_t interhunk_lines;
408
+
409
+ /**
410
+ * The abbreviation length to use when formatting object ids.
411
+ * Defaults to the value of 'core.abbrev' from the config, or 7 if unset.
412
+ */
413
+ uint16_t id_abbrev;
414
+
415
+ /**
416
+ * A size (in bytes) above which a blob will be marked as binary
417
+ * automatically; pass a negative value to disable.
418
+ * Defaults to 512MB.
419
+ */
420
+ git_off_t max_size;
421
+
422
+ /**
423
+ * The virtual "directory" prefix for old file names in hunk headers.
424
+ * Default is "a".
425
+ */
426
+ const char *old_prefix;
427
+
428
+ /**
429
+ * The virtual "directory" prefix for new file names in hunk headers.
430
+ * Defaults to "b".
431
+ */
432
+ const char *new_prefix;
329
433
  } git_diff_options;
330
434
 
435
+ /* The current version of the diff options structure */
331
436
  #define GIT_DIFF_OPTIONS_VERSION 1
332
- #define GIT_DIFF_OPTIONS_INIT {GIT_DIFF_OPTIONS_VERSION, GIT_DIFF_NORMAL, 3}
437
+
438
+ /* Stack initializer for diff options. Alternatively use
439
+ * `git_diff_options_init` programmatic initialization.
440
+ */
441
+ #define GIT_DIFF_OPTIONS_INIT \
442
+ {GIT_DIFF_OPTIONS_VERSION, 0, GIT_SUBMODULE_IGNORE_UNSPECIFIED, {NULL,0}, NULL, NULL, NULL, 3}
443
+
444
+ /**
445
+ * Initialize git_diff_options structure
446
+ *
447
+ * Initializes a `git_diff_options` with default values. Equivalent to creating
448
+ * an instance with GIT_DIFF_OPTIONS_INIT.
449
+ *
450
+ * @param opts The `git_diff_options` struct to initialize.
451
+ * @param version The struct version; pass `GIT_DIFF_OPTIONS_VERSION`.
452
+ * @return Zero on success; -1 on failure.
453
+ */
454
+ GIT_EXTERN(int) git_diff_init_options(
455
+ git_diff_options *opts,
456
+ unsigned int version);
333
457
 
334
458
  /**
335
459
  * When iterating over a diff, callback that will be made per file.
336
460
  *
337
461
  * @param delta A pointer to the delta data for the file
338
- * @param progress Goes from 0 to 1 over the diff list
462
+ * @param progress Goes from 0 to 1 over the diff
339
463
  * @param payload User-specified pointer from foreach function
340
464
  */
341
- typedef int (*git_diff_file_cb)(
465
+ typedef int GIT_CALLBACK(git_diff_file_cb)(
342
466
  const git_diff_delta *delta,
343
467
  float progress,
344
468
  void *payload);
345
469
 
470
+ #define GIT_DIFF_HUNK_HEADER_SIZE 128
471
+
472
+ /**
473
+ * When producing a binary diff, the binary data returned will be
474
+ * either the deflated full ("literal") contents of the file, or
475
+ * the deflated binary delta between the two sides (whichever is
476
+ * smaller).
477
+ */
478
+ typedef enum {
479
+ /** There is no binary delta. */
480
+ GIT_DIFF_BINARY_NONE,
481
+
482
+ /** The binary data is the literal contents of the file. */
483
+ GIT_DIFF_BINARY_LITERAL,
484
+
485
+ /** The binary data is the delta from one side to the other. */
486
+ GIT_DIFF_BINARY_DELTA,
487
+ } git_diff_binary_t;
488
+
489
+ /** The contents of one of the files in a binary diff. */
490
+ typedef struct {
491
+ /** The type of binary data for this file. */
492
+ git_diff_binary_t type;
493
+
494
+ /** The binary data, deflated. */
495
+ const char *data;
496
+
497
+ /** The length of the binary data. */
498
+ size_t datalen;
499
+
500
+ /** The length of the binary data after inflation. */
501
+ size_t inflatedlen;
502
+ } git_diff_binary_file;
503
+
504
+ /**
505
+ * Structure describing the binary contents of a diff.
506
+ *
507
+ * A `binary` file / delta is a file (or pair) for which no text diffs
508
+ * should be generated. A diff can contain delta entries that are
509
+ * binary, but no diff content will be output for those files. There is
510
+ * a base heuristic for binary detection and you can further tune the
511
+ * behavior with git attributes or diff flags and option settings.
512
+ */
513
+ typedef struct {
514
+ /**
515
+ * Whether there is data in this binary structure or not.
516
+ *
517
+ * If this is `1`, then this was produced and included binary content.
518
+ * If this is `0` then this was generated knowing only that a binary
519
+ * file changed but without providing the data, probably from a patch
520
+ * that said `Binary files a/file.txt and b/file.txt differ`.
521
+ */
522
+ unsigned int contains_data;
523
+ git_diff_binary_file old_file; /**< The contents of the old file. */
524
+ git_diff_binary_file new_file; /**< The contents of the new file. */
525
+ } git_diff_binary;
526
+
527
+ /**
528
+ * When iterating over a diff, callback that will be made for
529
+ * binary content within the diff.
530
+ */
531
+ typedef int GIT_CALLBACK(git_diff_binary_cb)(
532
+ const git_diff_delta *delta,
533
+ const git_diff_binary *binary,
534
+ void *payload);
535
+
346
536
  /**
347
537
  * Structure describing a hunk of a diff.
538
+ *
539
+ * A `hunk` is a span of modified lines in a delta along with some stable
540
+ * surrounding context. You can configure the amount of context and other
541
+ * properties of how hunks are generated. Each hunk also comes with a
542
+ * header that described where it starts and ends in both the old and new
543
+ * versions in the delta.
348
544
  */
349
545
  typedef struct {
350
- int old_start; /** Starting line number in old_file */
351
- int old_lines; /** Number of lines in old_file */
352
- int new_start; /** Starting line number in new_file */
353
- int new_lines; /** Number of lines in new_file */
354
- } git_diff_range;
546
+ int old_start; /**< Starting line number in old_file */
547
+ int old_lines; /**< Number of lines in old_file */
548
+ int new_start; /**< Starting line number in new_file */
549
+ int new_lines; /**< Number of lines in new_file */
550
+ size_t header_len; /**< Number of bytes in header text */
551
+ char header[GIT_DIFF_HUNK_HEADER_SIZE]; /**< Header text, NUL-byte terminated */
552
+ } git_diff_hunk;
355
553
 
356
554
  /**
357
555
  * When iterating over a diff, callback that will be made per hunk.
358
556
  */
359
- typedef int (*git_diff_hunk_cb)(
557
+ typedef int GIT_CALLBACK(git_diff_hunk_cb)(
360
558
  const git_diff_delta *delta,
361
- const git_diff_range *range,
362
- const char *header,
363
- size_t header_len,
559
+ const git_diff_hunk *hunk,
364
560
  void *payload);
365
561
 
366
562
  /**
367
563
  * Line origin constants.
368
564
  *
369
565
  * These values describe where a line came from and will be passed to
370
- * the git_diff_data_cb when iterating over a diff. There are some
566
+ * the git_diff_line_cb when iterating over a diff. There are some
371
567
  * special origin constants at the end that are used for the text
372
568
  * output callbacks to demarcate lines that are actually part of
373
569
  * the file or hunk headers.
374
570
  */
375
571
  typedef enum {
376
- /* These values will be sent to `git_diff_data_cb` along with the line */
572
+ /* These values will be sent to `git_diff_line_cb` along with the line */
377
573
  GIT_DIFF_LINE_CONTEXT = ' ',
378
574
  GIT_DIFF_LINE_ADDITION = '+',
379
575
  GIT_DIFF_LINE_DELETION = '-',
@@ -382,15 +578,35 @@ typedef enum {
382
578
  GIT_DIFF_LINE_ADD_EOFNL = '>', /**< Old has no LF at end, new does */
383
579
  GIT_DIFF_LINE_DEL_EOFNL = '<', /**< Old has LF at end, new does not */
384
580
 
385
- /* The following values will only be sent to a `git_diff_data_cb` when
386
- * the content of a diff is being formatted (eg. through
387
- * git_diff_print_patch() or git_diff_print_compact(), for instance).
581
+ /* The following values will only be sent to a `git_diff_line_cb` when
582
+ * the content of a diff is being formatted through `git_diff_print`.
388
583
  */
389
584
  GIT_DIFF_LINE_FILE_HDR = 'F',
390
585
  GIT_DIFF_LINE_HUNK_HDR = 'H',
391
- GIT_DIFF_LINE_BINARY = 'B'
586
+ GIT_DIFF_LINE_BINARY = 'B' /**< For "Binary files x and y differ" */
392
587
  } git_diff_line_t;
393
588
 
589
+ /**
590
+ * Structure describing a line (or data span) of a diff.
591
+ *
592
+ * A `line` is a range of characters inside a hunk. It could be a context
593
+ * line (i.e. in both old and new versions), an added line (i.e. only in
594
+ * the new version), or a removed line (i.e. only in the old version).
595
+ * Unfortunately, we don't know anything about the encoding of data in the
596
+ * file being diffed, so we cannot tell you much about the line content.
597
+ * Line data will not be NUL-byte terminated, however, because it will be
598
+ * just a span of bytes inside the larger file.
599
+ */
600
+ typedef struct {
601
+ char origin; /**< A git_diff_line_t value */
602
+ int old_lineno; /**< Line number in old file or -1 for added line */
603
+ int new_lineno; /**< Line number in new file or -1 for deleted line */
604
+ int num_lines; /**< Number of newline characters in content */
605
+ size_t content_len; /**< Number of bytes of data */
606
+ git_off_t content_offset; /**< Offset in the original file to the content */
607
+ const char *content; /**< Pointer to diff text, not NUL-byte terminated */
608
+ } git_diff_line;
609
+
394
610
  /**
395
611
  * When iterating over a diff, callback that will be made per text diff
396
612
  * line. In this context, the provided range will be NULL.
@@ -399,72 +615,98 @@ typedef enum {
399
615
  * of text. This uses some extra GIT_DIFF_LINE_... constants for output
400
616
  * of lines of file and hunk headers.
401
617
  */
402
- typedef int (*git_diff_data_cb)(
403
- const git_diff_delta *delta, /** delta that contains this data */
404
- const git_diff_range *range, /** range of lines containing this data */
405
- char line_origin, /** git_diff_list_t value from above */
406
- const char *content, /** diff data - not NUL terminated */
407
- size_t content_len, /** number of bytes of diff data */
408
- void *payload); /** user reference data */
409
-
410
- /**
411
- * The diff patch is used to store all the text diffs for a delta.
412
- *
413
- * You can easily loop over the content of patches and get information about
414
- * them.
415
- */
416
- typedef struct git_diff_patch git_diff_patch;
618
+ typedef int GIT_CALLBACK(git_diff_line_cb)(
619
+ const git_diff_delta *delta, /**< delta that contains this data */
620
+ const git_diff_hunk *hunk, /**< hunk containing this data */
621
+ const git_diff_line *line, /**< line data */
622
+ void *payload); /**< user reference data */
417
623
 
418
624
  /**
419
625
  * Flags to control the behavior of diff rename/copy detection.
420
626
  */
421
627
  typedef enum {
422
- /** look for renames? (`--find-renames`) */
423
- GIT_DIFF_FIND_RENAMES = (1 << 0),
424
- /** consider old side of modified for renames? (`--break-rewrites=N`) */
425
- GIT_DIFF_FIND_RENAMES_FROM_REWRITES = (1 << 1),
426
-
427
- /** look for copies? (a la `--find-copies`) */
428
- GIT_DIFF_FIND_COPIES = (1 << 2),
429
- /** consider unmodified as copy sources? (`--find-copies-harder`) */
430
- GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED = (1 << 3),
431
-
432
- /** mark large rewrites for split (`--break-rewrites=/M`) */
433
- GIT_DIFF_FIND_REWRITES = (1 << 4),
434
- /** actually split large rewrites into delete/add pairs */
435
- GIT_DIFF_BREAK_REWRITES = (1 << 5),
436
- /** mark rewrites for split and break into delete/add pairs */
628
+ /** Obey `diff.renames`. Overridden by any other GIT_DIFF_FIND_... flag. */
629
+ GIT_DIFF_FIND_BY_CONFIG = 0,
630
+
631
+ /** Look for renames? (`--find-renames`) */
632
+ GIT_DIFF_FIND_RENAMES = (1u << 0),
633
+
634
+ /** Consider old side of MODIFIED for renames? (`--break-rewrites=N`) */
635
+ GIT_DIFF_FIND_RENAMES_FROM_REWRITES = (1u << 1),
636
+
637
+ /** Look for copies? (a la `--find-copies`). */
638
+ GIT_DIFF_FIND_COPIES = (1u << 2),
639
+
640
+ /** Consider UNMODIFIED as copy sources? (`--find-copies-harder`).
641
+ *
642
+ * For this to work correctly, use GIT_DIFF_INCLUDE_UNMODIFIED when
643
+ * the initial `git_diff` is being generated.
644
+ */
645
+ GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED = (1u << 3),
646
+
647
+ /** Mark significant rewrites for split (`--break-rewrites=/M`) */
648
+ GIT_DIFF_FIND_REWRITES = (1u << 4),
649
+ /** Actually split large rewrites into delete/add pairs */
650
+ GIT_DIFF_BREAK_REWRITES = (1u << 5),
651
+ /** Mark rewrites for split and break into delete/add pairs */
437
652
  GIT_DIFF_FIND_AND_BREAK_REWRITES =
438
653
  (GIT_DIFF_FIND_REWRITES | GIT_DIFF_BREAK_REWRITES),
439
654
 
440
- /** find renames/copies for untracked items in working directory */
441
- GIT_DIFF_FIND_FOR_UNTRACKED = (1 << 6),
655
+ /** Find renames/copies for UNTRACKED items in working directory.
656
+ *
657
+ * For this to work correctly, use GIT_DIFF_INCLUDE_UNTRACKED when the
658
+ * initial `git_diff` is being generated (and obviously the diff must
659
+ * be against the working directory for this to make sense).
660
+ */
661
+ GIT_DIFF_FIND_FOR_UNTRACKED = (1u << 6),
442
662
 
443
- /** turn on all finding features */
663
+ /** Turn on all finding features. */
444
664
  GIT_DIFF_FIND_ALL = (0x0ff),
445
665
 
446
- /** measure similarity ignoring leading whitespace (default) */
666
+ /** Measure similarity ignoring leading whitespace (default) */
447
667
  GIT_DIFF_FIND_IGNORE_LEADING_WHITESPACE = 0,
448
- /** measure similarity ignoring all whitespace */
449
- GIT_DIFF_FIND_IGNORE_WHITESPACE = (1 << 12),
450
- /** measure similarity including all data */
451
- GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE = (1 << 13),
452
- /** measure similarity only by comparing SHAs (fast and cheap) */
453
- GIT_DIFF_FIND_EXACT_MATCH_ONLY = (1 << 14),
668
+ /** Measure similarity ignoring all whitespace */
669
+ GIT_DIFF_FIND_IGNORE_WHITESPACE = (1u << 12),
670
+ /** Measure similarity including all data */
671
+ GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE = (1u << 13),
672
+ /** Measure similarity only by comparing SHAs (fast and cheap) */
673
+ GIT_DIFF_FIND_EXACT_MATCH_ONLY = (1u << 14),
674
+
675
+ /** Do not break rewrites unless they contribute to a rename.
676
+ *
677
+ * Normally, GIT_DIFF_FIND_AND_BREAK_REWRITES will measure the self-
678
+ * similarity of modified files and split the ones that have changed a
679
+ * lot into a DELETE / ADD pair. Then the sides of that pair will be
680
+ * considered candidates for rename and copy detection.
681
+ *
682
+ * If you add this flag in and the split pair is *not* used for an
683
+ * actual rename or copy, then the modified record will be restored to
684
+ * a regular MODIFIED record instead of being split.
685
+ */
686
+ GIT_DIFF_BREAK_REWRITES_FOR_RENAMES_ONLY = (1u << 15),
687
+
688
+ /** Remove any UNMODIFIED deltas after find_similar is done.
689
+ *
690
+ * Using GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED to emulate the
691
+ * --find-copies-harder behavior requires building a diff with the
692
+ * GIT_DIFF_INCLUDE_UNMODIFIED flag. If you do not want UNMODIFIED
693
+ * records in the final result, pass this flag to have them removed.
694
+ */
695
+ GIT_DIFF_FIND_REMOVE_UNMODIFIED = (1u << 16),
454
696
  } git_diff_find_t;
455
697
 
456
698
  /**
457
699
  * Pluggable similarity metric
458
700
  */
459
701
  typedef struct {
460
- int (*file_signature)(
702
+ int GIT_CALLBACK(file_signature)(
461
703
  void **out, const git_diff_file *file,
462
704
  const char *fullpath, void *payload);
463
- int (*buffer_signature)(
705
+ int GIT_CALLBACK(buffer_signature)(
464
706
  void **out, const git_diff_file *file,
465
707
  const char *buf, size_t buflen, void *payload);
466
- void (*free_signature)(void *sig, void *payload);
467
- int (*similarity)(int *score, void *siga, void *sigb, void *payload);
708
+ void GIT_CALLBACK(free_signature)(void *sig, void *payload);
709
+ int GIT_CALLBACK(similarity)(int *score, void *siga, void *sigb, void *payload);
468
710
  void *payload;
469
711
  } git_diff_similarity_metric;
470
712
 
@@ -472,65 +714,96 @@ typedef struct {
472
714
  * Control behavior of rename and copy detection
473
715
  *
474
716
  * These options mostly mimic parameters that can be passed to git-diff.
475
- *
476
- * - `rename_threshold` is the same as the -M option with a value
477
- * - `copy_threshold` is the same as the -C option with a value
478
- * - `rename_from_rewrite_threshold` matches the top of the -B option
479
- * - `break_rewrite_threshold` matches the bottom of the -B option
480
- * - `rename_limit` is the maximum number of matches to consider for
481
- * a particular file. This is a little different from the `-l` option
482
- * to regular Git because we will still process up to this many matches
483
- * before abandoning the search.
484
- *
485
- * The `metric` option allows you to plug in a custom similarity metric.
486
- * Set it to NULL for the default internal metric which is based on sampling
487
- * hashes of ranges of data in the file. The default metric is a pretty
488
- * good similarity approximation that should work fairly well for both text
489
- * and binary data, and is pretty fast with fixed memory overhead.
490
717
  */
491
718
  typedef struct {
492
719
  unsigned int version;
493
720
 
494
- /** Combination of git_diff_find_t values (default FIND_RENAMES) */
721
+ /**
722
+ * Combination of git_diff_find_t values (default GIT_DIFF_FIND_BY_CONFIG).
723
+ * NOTE: if you don't explicitly set this, `diff.renames` could be set
724
+ * to false, resulting in `git_diff_find_similar` doing nothing.
725
+ */
495
726
  uint32_t flags;
496
727
 
497
- /** Similarity to consider a file renamed (default 50) */
728
+ /**
729
+ * Threshold above which similar files will be considered renames.
730
+ * This is equivalent to the -M option. Defaults to 50.
731
+ */
498
732
  uint16_t rename_threshold;
499
- /** Similarity of modified to be eligible rename source (default 50) */
733
+
734
+ /**
735
+ * Threshold below which similar files will be eligible to be a rename source.
736
+ * This is equivalent to the first part of the -B option. Defaults to 50.
737
+ */
500
738
  uint16_t rename_from_rewrite_threshold;
501
- /** Similarity to consider a file a copy (default 50) */
739
+
740
+ /**
741
+ * Threshold above which similar files will be considered copies.
742
+ * This is equivalent to the -C option. Defaults to 50.
743
+ */
502
744
  uint16_t copy_threshold;
503
- /** Similarity to split modify into delete/add pair (default 60) */
745
+
746
+ /**
747
+ * Treshold below which similar files will be split into a delete/add pair.
748
+ * This is equivalent to the last part of the -B option. Defaults to 60.
749
+ */
504
750
  uint16_t break_rewrite_threshold;
505
751
 
506
- /** Maximum similarity sources to examine for a file (somewhat like
507
- * git-diff's `-l` option or `diff.renameLimit` config) (default 200)
752
+ /**
753
+ * Maximum number of matches to consider for a particular file.
754
+ *
755
+ * This is a little different from the `-l` option from Git because we
756
+ * will still process up to this many matches before abandoning the search.
757
+ * Defaults to 200.
508
758
  */
509
759
  size_t rename_limit;
510
760
 
511
- /** Pluggable similarity metric; pass NULL to use internal metric */
761
+ /**
762
+ * The `metric` option allows you to plug in a custom similarity metric.
763
+ *
764
+ * Set it to NULL to use the default internal metric.
765
+ *
766
+ * The default metric is based on sampling hashes of ranges of data in
767
+ * the file, which is a pretty good similarity approximation that should
768
+ * work fairly well for both text and binary data while still being
769
+ * pretty fast with a fixed memory overhead.
770
+ */
512
771
  git_diff_similarity_metric *metric;
513
772
  } git_diff_find_options;
514
773
 
515
774
  #define GIT_DIFF_FIND_OPTIONS_VERSION 1
516
775
  #define GIT_DIFF_FIND_OPTIONS_INIT {GIT_DIFF_FIND_OPTIONS_VERSION}
517
776
 
518
- /** @name Diff List Generator Functions
777
+ /**
778
+ * Initialize git_diff_find_options structure
779
+ *
780
+ * Initializes a `git_diff_find_options` with default values. Equivalent to creating
781
+ * an instance with GIT_DIFF_FIND_OPTIONS_INIT.
782
+ *
783
+ * @param opts The `git_diff_find_options` struct to initialize.
784
+ * @param version The struct version; pass `GIT_DIFF_FIND_OPTIONS_VERSION`.
785
+ * @return Zero on success; -1 on failure.
786
+ */
787
+ GIT_EXTERN(int) git_diff_find_init_options(
788
+ git_diff_find_options *opts,
789
+ unsigned int version);
790
+
791
+ /** @name Diff Generator Functions
519
792
  *
520
793
  * These are the functions you would use to create (or destroy) a
521
- * git_diff_list from various objects in a repository.
794
+ * git_diff from various objects in a repository.
522
795
  */
523
796
  /**@{*/
524
797
 
525
798
  /**
526
- * Deallocate a diff list.
799
+ * Deallocate a diff.
527
800
  *
528
- * @param diff The previously created diff list; cannot be used after free.
801
+ * @param diff The previously created diff; cannot be used after free.
529
802
  */
530
- GIT_EXTERN(void) git_diff_list_free(git_diff_list *diff);
803
+ GIT_EXTERN(void) git_diff_free(git_diff *diff);
531
804
 
532
805
  /**
533
- * Create a diff list with the difference between two tree objects.
806
+ * Create a diff with the difference between two tree objects.
534
807
  *
535
808
  * This is equivalent to `git diff <old-tree> <new-tree>`
536
809
  *
@@ -539,21 +812,21 @@ GIT_EXTERN(void) git_diff_list_free(git_diff_list *diff);
539
812
  * pass NULL to indicate an empty tree, although it is an error to pass
540
813
  * NULL for both the `old_tree` and `new_tree`.
541
814
  *
542
- * @param diff Output pointer to a git_diff_list pointer to be allocated.
815
+ * @param diff Output pointer to a git_diff pointer to be allocated.
543
816
  * @param repo The repository containing the trees.
544
817
  * @param old_tree A git_tree object to diff from, or NULL for empty tree.
545
818
  * @param new_tree A git_tree object to diff to, or NULL for empty tree.
546
819
  * @param opts Structure with options to influence diff or NULL for defaults.
547
820
  */
548
821
  GIT_EXTERN(int) git_diff_tree_to_tree(
549
- git_diff_list **diff,
822
+ git_diff **diff,
550
823
  git_repository *repo,
551
824
  git_tree *old_tree,
552
825
  git_tree *new_tree,
553
- const git_diff_options *opts); /**< can be NULL for defaults */
826
+ const git_diff_options *opts);
554
827
 
555
828
  /**
556
- * Create a diff list between a tree and repository index.
829
+ * Create a diff between a tree and repository index.
557
830
  *
558
831
  * This is equivalent to `git diff --cached <treeish>` or if you pass
559
832
  * the HEAD tree, then like `git diff --cached`.
@@ -561,21 +834,25 @@ GIT_EXTERN(int) git_diff_tree_to_tree(
561
834
  * The tree you pass will be used for the "old_file" side of the delta, and
562
835
  * the index will be used for the "new_file" side of the delta.
563
836
  *
564
- * @param diff Output pointer to a git_diff_list pointer to be allocated.
837
+ * If you pass NULL for the index, then the existing index of the `repo`
838
+ * will be used. In this case, the index will be refreshed from disk
839
+ * (if it has changed) before the diff is generated.
840
+ *
841
+ * @param diff Output pointer to a git_diff pointer to be allocated.
565
842
  * @param repo The repository containing the tree and index.
566
843
  * @param old_tree A git_tree object to diff from, or NULL for empty tree.
567
844
  * @param index The index to diff with; repo index used if NULL.
568
845
  * @param opts Structure with options to influence diff or NULL for defaults.
569
846
  */
570
847
  GIT_EXTERN(int) git_diff_tree_to_index(
571
- git_diff_list **diff,
848
+ git_diff **diff,
572
849
  git_repository *repo,
573
850
  git_tree *old_tree,
574
851
  git_index *index,
575
- const git_diff_options *opts); /**< can be NULL for defaults */
852
+ const git_diff_options *opts);
576
853
 
577
854
  /**
578
- * Create a diff list between the repository index and the workdir directory.
855
+ * Create a diff between the repository index and the workdir directory.
579
856
  *
580
857
  * This matches the `git diff` command. See the note below on
581
858
  * `git_diff_tree_to_workdir` for a discussion of the difference between
@@ -585,57 +862,93 @@ GIT_EXTERN(int) git_diff_tree_to_index(
585
862
  * The index will be used for the "old_file" side of the delta, and the
586
863
  * working directory will be used for the "new_file" side of the delta.
587
864
  *
588
- * @param diff Output pointer to a git_diff_list pointer to be allocated.
865
+ * If you pass NULL for the index, then the existing index of the `repo`
866
+ * will be used. In this case, the index will be refreshed from disk
867
+ * (if it has changed) before the diff is generated.
868
+ *
869
+ * @param diff Output pointer to a git_diff pointer to be allocated.
589
870
  * @param repo The repository.
590
871
  * @param index The index to diff from; repo index used if NULL.
591
872
  * @param opts Structure with options to influence diff or NULL for defaults.
592
873
  */
593
874
  GIT_EXTERN(int) git_diff_index_to_workdir(
594
- git_diff_list **diff,
875
+ git_diff **diff,
595
876
  git_repository *repo,
596
877
  git_index *index,
597
- const git_diff_options *opts); /**< can be NULL for defaults */
878
+ const git_diff_options *opts);
598
879
 
599
880
  /**
600
- * Create a diff list between a tree and the working directory.
881
+ * Create a diff between a tree and the working directory.
601
882
  *
602
883
  * The tree you provide will be used for the "old_file" side of the delta,
603
884
  * and the working directory will be used for the "new_file" side.
604
885
  *
605
- * Please note: this is *NOT* the same as `git diff <treeish>`. Running
606
- * `git diff HEAD` or the like actually uses information from the index,
607
- * along with the tree and working directory info.
886
+ * This is not the same as `git diff <treeish>` or `git diff-index
887
+ * <treeish>`. Those commands use information from the index, whereas this
888
+ * function strictly returns the differences between the tree and the files
889
+ * in the working directory, regardless of the state of the index. Use
890
+ * `git_diff_tree_to_workdir_with_index` to emulate those commands.
608
891
  *
609
- * This function returns strictly the differences between the tree and the
610
- * files contained in the working directory, regardless of the state of
611
- * files in the index. It may come as a surprise, but there is no direct
612
- * equivalent in core git.
892
+ * To see difference between this and `git_diff_tree_to_workdir_with_index`,
893
+ * consider the example of a staged file deletion where the file has then
894
+ * been put back into the working dir and further modified. The
895
+ * tree-to-workdir diff for that file is 'modified', but `git diff` would
896
+ * show status 'deleted' since there is a staged delete.
613
897
  *
614
- * To emulate `git diff <treeish>`, call both `git_diff_tree_to_index` and
615
- * `git_diff_index_to_workdir`, then call `git_diff_merge` on the results.
616
- * That will yield a `git_diff_list` that matches the git output.
898
+ * @param diff A pointer to a git_diff pointer that will be allocated.
899
+ * @param repo The repository containing the tree.
900
+ * @param old_tree A git_tree object to diff from, or NULL for empty tree.
901
+ * @param opts Structure with options to influence diff or NULL for defaults.
902
+ */
903
+ GIT_EXTERN(int) git_diff_tree_to_workdir(
904
+ git_diff **diff,
905
+ git_repository *repo,
906
+ git_tree *old_tree,
907
+ const git_diff_options *opts);
908
+
909
+ /**
910
+ * Create a diff between a tree and the working directory using index data
911
+ * to account for staged deletes, tracked files, etc.
617
912
  *
618
- * If this seems confusing, take the case of a file with a staged deletion
619
- * where the file has then been put back into the working dir and modified.
620
- * The tree-to-workdir diff for that file is 'modified', but core git would
621
- * show status 'deleted' since there is a pending deletion in the index.
913
+ * This emulates `git diff <tree>` by diffing the tree to the index and
914
+ * the index to the working directory and blending the results into a
915
+ * single diff that includes staged deleted, etc.
622
916
  *
623
- * @param diff A pointer to a git_diff_list pointer that will be allocated.
917
+ * @param diff A pointer to a git_diff pointer that will be allocated.
624
918
  * @param repo The repository containing the tree.
625
919
  * @param old_tree A git_tree object to diff from, or NULL for empty tree.
626
920
  * @param opts Structure with options to influence diff or NULL for defaults.
627
921
  */
628
- GIT_EXTERN(int) git_diff_tree_to_workdir(
629
- git_diff_list **diff,
922
+ GIT_EXTERN(int) git_diff_tree_to_workdir_with_index(
923
+ git_diff **diff,
630
924
  git_repository *repo,
631
925
  git_tree *old_tree,
632
- const git_diff_options *opts); /**< can be NULL for defaults */
926
+ const git_diff_options *opts);
633
927
 
634
928
  /**
635
- * Merge one diff list into another.
929
+ * Create a diff with the difference between two index objects.
930
+ *
931
+ * The first index will be used for the "old_file" side of the delta and the
932
+ * second index will be used for the "new_file" side of the delta.
933
+ *
934
+ * @param diff Output pointer to a git_diff pointer to be allocated.
935
+ * @param repo The repository containing the indexes.
936
+ * @param old_index A git_index object to diff from.
937
+ * @param new_index A git_index object to diff to.
938
+ * @param opts Structure with options to influence diff or NULL for defaults.
939
+ */
940
+ GIT_EXTERN(int) git_diff_index_to_index(
941
+ git_diff **diff,
942
+ git_repository *repo,
943
+ git_index *old_index,
944
+ git_index *new_index,
945
+ const git_diff_options *opts);
946
+
947
+ /**
948
+ * Merge one diff into another.
636
949
  *
637
950
  * This merges items from the "from" list into the "onto" list. The
638
- * resulting diff list will have all items that appear in either list.
951
+ * resulting diff will have all items that appear in either list.
639
952
  * If an item appears in both lists, then it will be "merged" to appear
640
953
  * as if the old version was from the "onto" list and the new version
641
954
  * is from the "from" list (with the exception that if the item has a
@@ -645,319 +958,175 @@ GIT_EXTERN(int) git_diff_tree_to_workdir(
645
958
  * @param from Diff to merge.
646
959
  */
647
960
  GIT_EXTERN(int) git_diff_merge(
648
- git_diff_list *onto,
649
- const git_diff_list *from);
961
+ git_diff *onto,
962
+ const git_diff *from);
650
963
 
651
964
  /**
652
- * Transform a diff list marking file renames, copies, etc.
965
+ * Transform a diff marking file renames, copies, etc.
653
966
  *
654
- * This modifies a diff list in place, replacing old entries that look
967
+ * This modifies a diff in place, replacing old entries that look
655
968
  * like renames or copies with new entries reflecting those changes.
656
969
  * This also will, if requested, break modified files into add/remove
657
970
  * pairs if the amount of change is above a threshold.
658
971
  *
659
- * @param diff Diff list to run detection algorithms on
972
+ * @param diff diff to run detection algorithms on
660
973
  * @param options Control how detection should be run, NULL for defaults
661
974
  * @return 0 on success, -1 on failure
662
975
  */
663
976
  GIT_EXTERN(int) git_diff_find_similar(
664
- git_diff_list *diff,
665
- git_diff_find_options *options);
977
+ git_diff *diff,
978
+ const git_diff_find_options *options);
666
979
 
667
980
  /**@}*/
668
981
 
669
982
 
670
- /** @name Diff List Processor Functions
983
+ /** @name Diff Processor Functions
671
984
  *
672
- * These are the functions you apply to a diff list to process it
985
+ * These are the functions you apply to a diff to process it
673
986
  * or read it in some way.
674
987
  */
675
988
  /**@{*/
676
989
 
677
990
  /**
678
- * Loop over all deltas in a diff list issuing callbacks.
991
+ * Query how many diff records are there in a diff.
679
992
  *
680
- * This will iterate through all of the files described in a diff. You
681
- * should provide a file callback to learn about each file.
682
- *
683
- * The "hunk" and "line" callbacks are optional, and the text diff of the
684
- * files will only be calculated if they are not NULL. Of course, these
685
- * callbacks will not be invoked for binary files on the diff list or for
686
- * files whose only changed is a file mode change.
687
- *
688
- * Returning a non-zero value from any of the callbacks will terminate
689
- * the iteration and cause this return `GIT_EUSER`.
690
- *
691
- * @param diff A git_diff_list generated by one of the above functions.
692
- * @param file_cb Callback function to make per file in the diff.
693
- * @param hunk_cb Optional callback to make per hunk of text diff. This
694
- * callback is called to describe a range of lines in the
695
- * diff. It will not be issued for binary files.
696
- * @param line_cb Optional callback to make per line of diff text. This
697
- * same callback will be made for context lines, added, and
698
- * removed lines, and even for a deleted trailing newline.
699
- * @param payload Reference pointer that will be passed to your callbacks.
700
- * @return 0 on success, GIT_EUSER on non-zero callback, or error code
701
- */
702
- GIT_EXTERN(int) git_diff_foreach(
703
- git_diff_list *diff,
704
- git_diff_file_cb file_cb,
705
- git_diff_hunk_cb hunk_cb,
706
- git_diff_data_cb line_cb,
707
- void *payload);
708
-
709
- /**
710
- * Iterate over a diff generating text output like "git diff --name-status".
711
- *
712
- * Returning a non-zero value from the callbacks will terminate the
713
- * iteration and cause this return `GIT_EUSER`.
714
- *
715
- * @param diff A git_diff_list generated by one of the above functions.
716
- * @param print_cb Callback to make per line of diff text.
717
- * @param payload Reference pointer that will be passed to your callback.
718
- * @return 0 on success, GIT_EUSER on non-zero callback, or error code
719
- */
720
- GIT_EXTERN(int) git_diff_print_compact(
721
- git_diff_list *diff,
722
- git_diff_data_cb print_cb,
723
- void *payload);
724
-
725
- /**
726
- * Iterate over a diff generating text output like "git diff --raw".
727
- *
728
- * Returning a non-zero value from the callbacks will terminate the
729
- * iteration and cause this return `GIT_EUSER`.
730
- *
731
- * @param diff A git_diff_list generated by one of the above functions.
732
- * @param print_cb Callback to make per line of diff text.
733
- * @param payload Reference pointer that will be passed to your callback.
734
- * @return 0 on success, GIT_EUSER on non-zero callback, or error code
735
- */
736
- GIT_EXTERN(int) git_diff_print_raw(
737
- git_diff_list *diff,
738
- git_diff_data_cb print_cb,
739
- void *payload);
740
-
741
- /**
742
- * Look up the single character abbreviation for a delta status code.
743
- *
744
- * When you call `git_diff_print_compact` it prints single letter codes into
745
- * the output such as 'A' for added, 'D' for deleted, 'M' for modified, etc.
746
- * It is sometimes convenient to convert a git_delta_t value into these
747
- * letters for your own purposes. This function does just that. By the
748
- * way, unmodified will return a space (i.e. ' ').
749
- *
750
- * @param status The git_delta_t value to look up
751
- * @return The single character label for that code
752
- */
753
- GIT_EXTERN(char) git_diff_status_char(git_delta_t status);
754
-
755
- /**
756
- * Iterate over a diff generating text output like "git diff".
757
- *
758
- * This is a super easy way to generate a patch from a diff.
759
- *
760
- * Returning a non-zero value from the callbacks will terminate the
761
- * iteration and cause this return `GIT_EUSER`.
762
- *
763
- * @param diff A git_diff_list generated by one of the above functions.
764
- * @param payload Reference pointer that will be passed to your callbacks.
765
- * @param print_cb Callback function to output lines of the diff. This
766
- * same function will be called for file headers, hunk
767
- * headers, and diff lines. Fortunately, you can probably
768
- * use various GIT_DIFF_LINE constants to determine what
769
- * text you are given.
770
- * @return 0 on success, GIT_EUSER on non-zero callback, or error code
771
- */
772
- GIT_EXTERN(int) git_diff_print_patch(
773
- git_diff_list *diff,
774
- git_diff_data_cb print_cb,
775
- void *payload);
776
-
777
- /**
778
- * Query how many diff records are there in a diff list.
779
- *
780
- * @param diff A git_diff_list generated by one of the above functions
993
+ * @param diff A git_diff generated by one of the above functions
781
994
  * @return Count of number of deltas in the list
782
995
  */
783
- GIT_EXTERN(size_t) git_diff_num_deltas(git_diff_list *diff);
996
+ GIT_EXTERN(size_t) git_diff_num_deltas(const git_diff *diff);
784
997
 
785
998
  /**
786
- * Query how many diff deltas are there in a diff list filtered by type.
999
+ * Query how many diff deltas are there in a diff filtered by type.
787
1000
  *
788
1001
  * This works just like `git_diff_entrycount()` with an extra parameter
789
1002
  * that is a `git_delta_t` and returns just the count of how many deltas
790
1003
  * match that particular type.
791
1004
  *
792
- * @param diff A git_diff_list generated by one of the above functions
1005
+ * @param diff A git_diff generated by one of the above functions
793
1006
  * @param type A git_delta_t value to filter the count
794
1007
  * @return Count of number of deltas matching delta_t type
795
1008
  */
796
1009
  GIT_EXTERN(size_t) git_diff_num_deltas_of_type(
797
- git_diff_list *diff,
798
- git_delta_t type);
1010
+ const git_diff *diff, git_delta_t type);
799
1011
 
800
1012
  /**
801
- * Return the diff delta and patch for an entry in the diff list.
1013
+ * Return the diff delta for an entry in the diff list.
802
1014
  *
803
- * The `git_diff_patch` is a newly created object contains the text diffs
804
- * for the delta. You have to call `git_diff_patch_free()` when you are
805
- * done with it. You can use the patch object to loop over all the hunks
806
- * and lines in the diff of the one delta.
1015
+ * The `git_diff_delta` pointer points to internal data and you do not
1016
+ * have to release it when you are done with it. It will go away when
1017
+ * the * `git_diff` (or any associated `git_patch`) goes away.
807
1018
  *
808
- * For an unchanged file or a binary file, no `git_diff_patch` will be
809
- * created, the output will be set to NULL, and the `binary` flag will be
810
- * set true in the `git_diff_delta` structure.
1019
+ * Note that the flags on the delta related to whether it has binary
1020
+ * content or not may not be set if there are no attributes set for the
1021
+ * file and there has been no reason to load the file data at this point.
1022
+ * For now, if you need those flags to be up to date, your only option is
1023
+ * to either use `git_diff_foreach` or create a `git_patch`.
811
1024
  *
812
- * The `git_diff_delta` pointer points to internal data and you do not have
813
- * to release it when you are done with it. It will go away when the
814
- * `git_diff_list` and `git_diff_patch` go away.
815
- *
816
- * It is okay to pass NULL for either of the output parameters; if you pass
817
- * NULL for the `git_diff_patch`, then the text diff will not be calculated.
818
- *
819
- * @param patch_out Output parameter for the delta patch object
820
- * @param delta_out Output parameter for the delta object
821
1025
  * @param diff Diff list object
822
1026
  * @param idx Index into diff list
823
- * @return 0 on success, other value < 0 on error
824
- */
825
- GIT_EXTERN(int) git_diff_get_patch(
826
- git_diff_patch **patch_out,
827
- const git_diff_delta **delta_out,
828
- git_diff_list *diff,
829
- size_t idx);
830
-
831
- /**
832
- * Free a git_diff_patch object.
833
- */
834
- GIT_EXTERN(void) git_diff_patch_free(
835
- git_diff_patch *patch);
836
-
837
- /**
838
- * Get the delta associated with a patch
1027
+ * @return Pointer to git_diff_delta (or NULL if `idx` out of range)
839
1028
  */
840
- GIT_EXTERN(const git_diff_delta *) git_diff_patch_delta(
841
- git_diff_patch *patch);
1029
+ GIT_EXTERN(const git_diff_delta *) git_diff_get_delta(
1030
+ const git_diff *diff, size_t idx);
842
1031
 
843
1032
  /**
844
- * Get the number of hunks in a patch
1033
+ * Check if deltas are sorted case sensitively or insensitively.
1034
+ *
1035
+ * @param diff diff to check
1036
+ * @return 0 if case sensitive, 1 if case is ignored
845
1037
  */
846
- GIT_EXTERN(size_t) git_diff_patch_num_hunks(
847
- git_diff_patch *patch);
1038
+ GIT_EXTERN(int) git_diff_is_sorted_icase(const git_diff *diff);
848
1039
 
849
1040
  /**
850
- * Get line counts of each type in a patch.
1041
+ * Loop over all deltas in a diff issuing callbacks.
851
1042
  *
852
- * This helps imitate a diff --numstat type of output. For that purpose,
853
- * you only need the `total_additions` and `total_deletions` values, but we
854
- * include the `total_context` line count in case you want the total number
855
- * of lines of diff output that will be generated.
1043
+ * This will iterate through all of the files described in a diff. You
1044
+ * should provide a file callback to learn about each file.
856
1045
  *
857
- * All outputs are optional. Pass NULL if you don't need a particular count.
1046
+ * The "hunk" and "line" callbacks are optional, and the text diff of the
1047
+ * files will only be calculated if they are not NULL. Of course, these
1048
+ * callbacks will not be invoked for binary files on the diff or for
1049
+ * files whose only changed is a file mode change.
1050
+ *
1051
+ * Returning a non-zero value from any of the callbacks will terminate
1052
+ * the iteration and return the value to the user.
858
1053
  *
859
- * @param total_context Count of context lines in output, can be NULL.
860
- * @param total_additions Count of addition lines in output, can be NULL.
861
- * @param total_deletions Count of deletion lines in output, can be NULL.
862
- * @param patch The git_diff_patch object
863
- * @return 0 on success, <0 on error
1054
+ * @param diff A git_diff generated by one of the above functions.
1055
+ * @param file_cb Callback function to make per file in the diff.
1056
+ * @param binary_cb Optional callback to make for binary files.
1057
+ * @param hunk_cb Optional callback to make per hunk of text diff. This
1058
+ * callback is called to describe a range of lines in the
1059
+ * diff. It will not be issued for binary files.
1060
+ * @param line_cb Optional callback to make per line of diff text. This
1061
+ * same callback will be made for context lines, added, and
1062
+ * removed lines, and even for a deleted trailing newline.
1063
+ * @param payload Reference pointer that will be passed to your callbacks.
1064
+ * @return 0 on success, non-zero callback return value, or error code
864
1065
  */
865
- GIT_EXTERN(int) git_diff_patch_line_stats(
866
- size_t *total_context,
867
- size_t *total_additions,
868
- size_t *total_deletions,
869
- const git_diff_patch *patch);
870
-
871
- /**
872
- * Get the information about a hunk in a patch
873
- *
874
- * Given a patch and a hunk index into the patch, this returns detailed
875
- * information about that hunk. Any of the output pointers can be passed
876
- * as NULL if you don't care about that particular piece of information.
877
- *
878
- * @param range Output pointer to git_diff_range of hunk
879
- * @param header Output pointer to header string for hunk. Unlike the
880
- * content pointer for each line, this will be NUL-terminated
881
- * @param header_len Output value of characters in header string
882
- * @param lines_in_hunk Output count of total lines in this hunk
883
- * @param patch Input pointer to patch object
884
- * @param hunk_idx Input index of hunk to get information about
885
- * @return 0 on success, GIT_ENOTFOUND if hunk_idx out of range, <0 on error
886
- */
887
- GIT_EXTERN(int) git_diff_patch_get_hunk(
888
- const git_diff_range **range,
889
- const char **header,
890
- size_t *header_len,
891
- size_t *lines_in_hunk,
892
- git_diff_patch *patch,
893
- size_t hunk_idx);
1066
+ GIT_EXTERN(int) git_diff_foreach(
1067
+ git_diff *diff,
1068
+ git_diff_file_cb file_cb,
1069
+ git_diff_binary_cb binary_cb,
1070
+ git_diff_hunk_cb hunk_cb,
1071
+ git_diff_line_cb line_cb,
1072
+ void *payload);
894
1073
 
895
1074
  /**
896
- * Get the number of lines in a hunk.
1075
+ * Look up the single character abbreviation for a delta status code.
1076
+ *
1077
+ * When you run `git diff --name-status` it uses single letter codes in
1078
+ * the output such as 'A' for added, 'D' for deleted, 'M' for modified,
1079
+ * etc. This function converts a git_delta_t value into these letters for
1080
+ * your own purposes. GIT_DELTA_UNTRACKED will return a space (i.e. ' ').
897
1081
  *
898
- * @param patch The git_diff_patch object
899
- * @param hunk_idx Index of the hunk
900
- * @return Number of lines in hunk or -1 if invalid hunk index
1082
+ * @param status The git_delta_t value to look up
1083
+ * @return The single character label for that code
901
1084
  */
902
- GIT_EXTERN(int) git_diff_patch_num_lines_in_hunk(
903
- git_diff_patch *patch,
904
- size_t hunk_idx);
1085
+ GIT_EXTERN(char) git_diff_status_char(git_delta_t status);
905
1086
 
906
1087
  /**
907
- * Get data about a line in a hunk of a patch.
908
- *
909
- * Given a patch, a hunk index, and a line index in the hunk, this
910
- * will return a lot of details about that line. If you pass a hunk
911
- * index larger than the number of hunks or a line index larger than
912
- * the number of lines in the hunk, this will return -1.
913
- *
914
- * @param line_origin A GIT_DIFF_LINE constant from above
915
- * @param content Pointer to content of diff line, not NUL-terminated
916
- * @param content_len Number of characters in content
917
- * @param old_lineno Line number in old file or -1 if line is added
918
- * @param new_lineno Line number in new file or -1 if line is deleted
919
- * @param patch The patch to look in
920
- * @param hunk_idx The index of the hunk
921
- * @param line_of_hunk The index of the line in the hunk
922
- * @return 0 on success, <0 on failure
923
- */
924
- GIT_EXTERN(int) git_diff_patch_get_line_in_hunk(
925
- char *line_origin,
926
- const char **content,
927
- size_t *content_len,
928
- int *old_lineno,
929
- int *new_lineno,
930
- git_diff_patch *patch,
931
- size_t hunk_idx,
932
- size_t line_of_hunk);
1088
+ * Possible output formats for diff data
1089
+ */
1090
+ typedef enum {
1091
+ GIT_DIFF_FORMAT_PATCH = 1u, /**< full git diff */
1092
+ GIT_DIFF_FORMAT_PATCH_HEADER = 2u, /**< just the file headers of patch */
1093
+ GIT_DIFF_FORMAT_RAW = 3u, /**< like git diff --raw */
1094
+ GIT_DIFF_FORMAT_NAME_ONLY = 4u, /**< like git diff --name-only */
1095
+ GIT_DIFF_FORMAT_NAME_STATUS = 5u, /**< like git diff --name-status */
1096
+ } git_diff_format_t;
933
1097
 
934
1098
  /**
935
- * Serialize the patch to text via callback.
1099
+ * Iterate over a diff generating formatted text output.
936
1100
  *
937
- * Returning a non-zero value from the callback will terminate the iteration
938
- * and cause this return `GIT_EUSER`.
1101
+ * Returning a non-zero value from the callbacks will terminate the
1102
+ * iteration and return the non-zero value to the caller.
939
1103
  *
940
- * @param patch A git_diff_patch representing changes to one file
941
- * @param print_cb Callback function to output lines of the patch. Will be
942
- * called for file headers, hunk headers, and diff lines.
943
- * @param payload Reference pointer that will be passed to your callbacks.
944
- * @return 0 on success, GIT_EUSER on non-zero callback, or error code
1104
+ * @param diff A git_diff generated by one of the above functions.
1105
+ * @param format A git_diff_format_t value to pick the text format.
1106
+ * @param print_cb Callback to make per line of diff text.
1107
+ * @param payload Reference pointer that will be passed to your callback.
1108
+ * @return 0 on success, non-zero callback return value, or error code
945
1109
  */
946
- GIT_EXTERN(int) git_diff_patch_print(
947
- git_diff_patch *patch,
948
- git_diff_data_cb print_cb,
1110
+ GIT_EXTERN(int) git_diff_print(
1111
+ git_diff *diff,
1112
+ git_diff_format_t format,
1113
+ git_diff_line_cb print_cb,
949
1114
  void *payload);
950
1115
 
951
1116
  /**
952
- * Get the content of a patch as a single diff text.
953
- *
954
- * @param string Allocated string; caller must free.
955
- * @param patch A git_diff_patch representing changes to one file
956
- * @return 0 on success, <0 on failure.
1117
+ * Produce the complete formatted text output from a diff into a
1118
+ * buffer.
1119
+ *
1120
+ * @param out A pointer to a user-allocated git_buf that will
1121
+ * contain the diff text
1122
+ * @param diff A git_diff generated by one of the above functions.
1123
+ * @param format A git_diff_format_t value to pick the text format.
1124
+ * @return 0 on success or error code
957
1125
  */
958
- GIT_EXTERN(int) git_diff_patch_to_str(
959
- char **string,
960
- git_diff_patch *patch);
1126
+ GIT_EXTERN(int) git_diff_to_buf(
1127
+ git_buf *out,
1128
+ git_diff *diff,
1129
+ git_diff_format_t format);
961
1130
 
962
1131
  /**@}*/
963
1132
 
@@ -988,10 +1157,11 @@ GIT_EXTERN(int) git_diff_patch_to_str(
988
1157
  * @param new_as_path Treat new blob as if it had this filename; can be NULL
989
1158
  * @param options Options for diff, or NULL for default options
990
1159
  * @param file_cb Callback for "file"; made once if there is a diff; can be NULL
1160
+ * @param binary_cb Callback for binary files; can be NULL
991
1161
  * @param hunk_cb Callback for each hunk in diff; can be NULL
992
1162
  * @param line_cb Callback for each line in diff; can be NULL
993
1163
  * @param payload Payload passed to each callback function
994
- * @return 0 on success, GIT_EUSER on non-zero callback return, or error code
1164
+ * @return 0 on success, non-zero callback return value, or error code
995
1165
  */
996
1166
  GIT_EXTERN(int) git_diff_blobs(
997
1167
  const git_blob *old_blob,
@@ -1000,34 +1170,11 @@ GIT_EXTERN(int) git_diff_blobs(
1000
1170
  const char *new_as_path,
1001
1171
  const git_diff_options *options,
1002
1172
  git_diff_file_cb file_cb,
1173
+ git_diff_binary_cb binary_cb,
1003
1174
  git_diff_hunk_cb hunk_cb,
1004
- git_diff_data_cb line_cb,
1175
+ git_diff_line_cb line_cb,
1005
1176
  void *payload);
1006
1177
 
1007
- /**
1008
- * Directly generate a patch from the difference between two blobs.
1009
- *
1010
- * This is just like `git_diff_blobs()` except it generates a patch object
1011
- * for the difference instead of directly making callbacks. You can use the
1012
- * standard `git_diff_patch` accessor functions to read the patch data, and
1013
- * you must call `git_diff_patch_free()` on the patch when done.
1014
- *
1015
- * @param out The generated patch; NULL on error
1016
- * @param old_blob Blob for old side of diff, or NULL for empty blob
1017
- * @param old_as_path Treat old blob as if it had this filename; can be NULL
1018
- * @param new_blob Blob for new side of diff, or NULL for empty blob
1019
- * @param new_as_path Treat new blob as if it had this filename; can be NULL
1020
- * @param opts Options for diff, or NULL for default options
1021
- * @return 0 on success or error code < 0
1022
- */
1023
- GIT_EXTERN(int) git_diff_patch_from_blobs(
1024
- git_diff_patch **out,
1025
- const git_blob *old_blob,
1026
- const char *old_as_path,
1027
- const git_blob *new_blob,
1028
- const char *new_as_path,
1029
- const git_diff_options *opts);
1030
-
1031
1178
  /**
1032
1179
  * Directly run a diff between a blob and a buffer.
1033
1180
  *
@@ -1047,10 +1194,11 @@ GIT_EXTERN(int) git_diff_patch_from_blobs(
1047
1194
  * @param buffer_as_path Treat buffer as if it had this filename; can be NULL
1048
1195
  * @param options Options for diff, or NULL for default options
1049
1196
  * @param file_cb Callback for "file"; made once if there is a diff; can be NULL
1197
+ * @param binary_cb Callback for binary files; can be NULL
1050
1198
  * @param hunk_cb Callback for each hunk in diff; can be NULL
1051
- * @param data_cb Callback for each line in diff; can be NULL
1199
+ * @param line_cb Callback for each line in diff; can be NULL
1052
1200
  * @param payload Payload passed to each callback function
1053
- * @return 0 on success, GIT_EUSER on non-zero callback return, or error code
1201
+ * @return 0 on success, non-zero callback return value, or error code
1054
1202
  */
1055
1203
  GIT_EXTERN(int) git_diff_blob_to_buffer(
1056
1204
  const git_blob *old_blob,
@@ -1060,36 +1208,298 @@ GIT_EXTERN(int) git_diff_blob_to_buffer(
1060
1208
  const char *buffer_as_path,
1061
1209
  const git_diff_options *options,
1062
1210
  git_diff_file_cb file_cb,
1211
+ git_diff_binary_cb binary_cb,
1063
1212
  git_diff_hunk_cb hunk_cb,
1064
- git_diff_data_cb data_cb,
1213
+ git_diff_line_cb line_cb,
1065
1214
  void *payload);
1066
1215
 
1067
1216
  /**
1068
- * Directly generate a patch from the difference between a blob and a buffer.
1217
+ * Directly run a diff between two buffers.
1218
+ *
1219
+ * Even more than with `git_diff_blobs`, comparing two buffer lacks
1220
+ * context, so the `git_diff_file` parameters to the callbacks will be
1221
+ * faked a la the rules for `git_diff_blobs()`.
1222
+ *
1223
+ * @param old_buffer Raw data for old side of diff, or NULL for empty
1224
+ * @param old_len Length of the raw data for old side of the diff
1225
+ * @param old_as_path Treat old buffer as if it had this filename; can be NULL
1226
+ * @param new_buffer Raw data for new side of diff, or NULL for empty
1227
+ * @param new_len Length of raw data for new side of diff
1228
+ * @param new_as_path Treat buffer as if it had this filename; can be NULL
1229
+ * @param options Options for diff, or NULL for default options
1230
+ * @param file_cb Callback for "file"; made once if there is a diff; can be NULL
1231
+ * @param binary_cb Callback for binary files; can be NULL
1232
+ * @param hunk_cb Callback for each hunk in diff; can be NULL
1233
+ * @param line_cb Callback for each line in diff; can be NULL
1234
+ * @param payload Payload passed to each callback function
1235
+ * @return 0 on success, non-zero callback return value, or error code
1236
+ */
1237
+ GIT_EXTERN(int) git_diff_buffers(
1238
+ const void *old_buffer,
1239
+ size_t old_len,
1240
+ const char *old_as_path,
1241
+ const void *new_buffer,
1242
+ size_t new_len,
1243
+ const char *new_as_path,
1244
+ const git_diff_options *options,
1245
+ git_diff_file_cb file_cb,
1246
+ git_diff_binary_cb binary_cb,
1247
+ git_diff_hunk_cb hunk_cb,
1248
+ git_diff_line_cb line_cb,
1249
+ void *payload);
1250
+
1251
+ /**
1252
+ * Read the contents of a git patch file into a `git_diff` object.
1253
+ *
1254
+ * The diff object produced is similar to the one that would be
1255
+ * produced if you actually produced it computationally by comparing
1256
+ * two trees, however there may be subtle differences. For example,
1257
+ * a patch file likely contains abbreviated object IDs, so the
1258
+ * object IDs in a `git_diff_delta` produced by this function will
1259
+ * also be abbreviated.
1260
+ *
1261
+ * This function will only read patch files created by a git
1262
+ * implementation, it will not read unified diffs produced by
1263
+ * the `diff` program, nor any other types of patch files.
1264
+ *
1265
+ * @param out A pointer to a git_diff pointer that will be allocated.
1266
+ * @param content The contents of a patch file
1267
+ * @param content_len The length of the patch file contents
1268
+ * @return 0 or an error code
1269
+ */
1270
+ GIT_EXTERN(int) git_diff_from_buffer(
1271
+ git_diff **out,
1272
+ const char *content,
1273
+ size_t content_len);
1274
+
1275
+ /**
1276
+ * This is an opaque structure which is allocated by `git_diff_get_stats`.
1277
+ * You are responsible for releasing the object memory when done, using the
1278
+ * `git_diff_stats_free()` function.
1279
+ */
1280
+ typedef struct git_diff_stats git_diff_stats;
1281
+
1282
+ /**
1283
+ * Formatting options for diff stats
1284
+ */
1285
+ typedef enum {
1286
+ /** No stats*/
1287
+ GIT_DIFF_STATS_NONE = 0,
1288
+
1289
+ /** Full statistics, equivalent of `--stat` */
1290
+ GIT_DIFF_STATS_FULL = (1u << 0),
1291
+
1292
+ /** Short statistics, equivalent of `--shortstat` */
1293
+ GIT_DIFF_STATS_SHORT = (1u << 1),
1294
+
1295
+ /** Number statistics, equivalent of `--numstat` */
1296
+ GIT_DIFF_STATS_NUMBER = (1u << 2),
1297
+
1298
+ /** Extended header information such as creations, renames and mode changes, equivalent of `--summary` */
1299
+ GIT_DIFF_STATS_INCLUDE_SUMMARY = (1u << 3),
1300
+ } git_diff_stats_format_t;
1301
+
1302
+ /**
1303
+ * Accumulate diff statistics for all patches.
1069
1304
  *
1070
- * This is just like `git_diff_blob_to_buffer()` except it generates a patch
1071
- * object for the difference instead of directly making callbacks. You can
1072
- * use the standard `git_diff_patch` accessor functions to read the patch
1073
- * data, and you must call `git_diff_patch_free()` on the patch when done.
1305
+ * @param out Structure containg the diff statistics.
1306
+ * @param diff A git_diff generated by one of the above functions.
1307
+ * @return 0 on success; non-zero on error
1308
+ */
1309
+ GIT_EXTERN(int) git_diff_get_stats(
1310
+ git_diff_stats **out,
1311
+ git_diff *diff);
1312
+
1313
+ /**
1314
+ * Get the total number of files changed in a diff
1074
1315
  *
1075
- * @param out The generated patch; NULL on error
1076
- * @param old_blob Blob for old side of diff, or NULL for empty blob
1077
- * @param old_as_path Treat old blob as if it had this filename; can be NULL
1078
- * @param buffer Raw data for new side of diff, or NULL for empty
1079
- * @param buffer_len Length of raw data for new side of diff
1080
- * @param buffer_as_path Treat buffer as if it had this filename; can be NULL
1081
- * @param opts Options for diff, or NULL for default options
1082
- * @return 0 on success or error code < 0
1316
+ * @param stats A `git_diff_stats` generated by one of the above functions.
1317
+ * @return total number of files changed in the diff
1083
1318
  */
1084
- GIT_EXTERN(int) git_diff_patch_from_blob_and_buffer(
1085
- git_diff_patch **out,
1086
- const git_blob *old_blob,
1087
- const char *old_as_path,
1088
- const char *buffer,
1089
- size_t buffer_len,
1090
- const char *buffer_as_path,
1091
- const git_diff_options *opts);
1319
+ GIT_EXTERN(size_t) git_diff_stats_files_changed(
1320
+ const git_diff_stats *stats);
1321
+
1322
+ /**
1323
+ * Get the total number of insertions in a diff
1324
+ *
1325
+ * @param stats A `git_diff_stats` generated by one of the above functions.
1326
+ * @return total number of insertions in the diff
1327
+ */
1328
+ GIT_EXTERN(size_t) git_diff_stats_insertions(
1329
+ const git_diff_stats *stats);
1330
+
1331
+ /**
1332
+ * Get the total number of deletions in a diff
1333
+ *
1334
+ * @param stats A `git_diff_stats` generated by one of the above functions.
1335
+ * @return total number of deletions in the diff
1336
+ */
1337
+ GIT_EXTERN(size_t) git_diff_stats_deletions(
1338
+ const git_diff_stats *stats);
1339
+
1340
+ /**
1341
+ * Print diff statistics to a `git_buf`.
1342
+ *
1343
+ * @param out buffer to store the formatted diff statistics in.
1344
+ * @param stats A `git_diff_stats` generated by one of the above functions.
1345
+ * @param format Formatting option.
1346
+ * @param width Target width for output (only affects GIT_DIFF_STATS_FULL)
1347
+ * @return 0 on success; non-zero on error
1348
+ */
1349
+ GIT_EXTERN(int) git_diff_stats_to_buf(
1350
+ git_buf *out,
1351
+ const git_diff_stats *stats,
1352
+ git_diff_stats_format_t format,
1353
+ size_t width);
1092
1354
 
1355
+ /**
1356
+ * Deallocate a `git_diff_stats`.
1357
+ *
1358
+ * @param stats The previously created statistics object;
1359
+ * cannot be used after free.
1360
+ */
1361
+ GIT_EXTERN(void) git_diff_stats_free(git_diff_stats *stats);
1362
+
1363
+ /**
1364
+ * Formatting options for diff e-mail generation
1365
+ */
1366
+ typedef enum {
1367
+ /** Normal patch, the default */
1368
+ GIT_DIFF_FORMAT_EMAIL_NONE = 0,
1369
+
1370
+ /** Don't insert "[PATCH]" in the subject header*/
1371
+ GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER = (1 << 0),
1372
+
1373
+ } git_diff_format_email_flags_t;
1374
+
1375
+ /**
1376
+ * Options for controlling the formatting of the generated e-mail.
1377
+ */
1378
+ typedef struct {
1379
+ unsigned int version;
1380
+
1381
+ git_diff_format_email_flags_t flags;
1382
+
1383
+ /** This patch number */
1384
+ size_t patch_no;
1385
+
1386
+ /** Total number of patches in this series */
1387
+ size_t total_patches;
1388
+
1389
+ /** id to use for the commit */
1390
+ const git_oid *id;
1391
+
1392
+ /** Summary of the change */
1393
+ const char *summary;
1394
+
1395
+ /** Commit message's body */
1396
+ const char *body;
1397
+
1398
+ /** Author of the change */
1399
+ const git_signature *author;
1400
+ } git_diff_format_email_options;
1401
+
1402
+ #define GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION 1
1403
+ #define GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT {GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION, 0, 1, 1, NULL, NULL, NULL, NULL}
1404
+
1405
+ /**
1406
+ * Create an e-mail ready patch from a diff.
1407
+ *
1408
+ * @param out buffer to store the e-mail patch in
1409
+ * @param diff containing the commit
1410
+ * @param opts structure with options to influence content and formatting.
1411
+ * @return 0 or an error code
1412
+ */
1413
+ GIT_EXTERN(int) git_diff_format_email(
1414
+ git_buf *out,
1415
+ git_diff *diff,
1416
+ const git_diff_format_email_options *opts);
1417
+
1418
+ /**
1419
+ * Create an e-mail ready patch for a commit.
1420
+ *
1421
+ * Does not support creating patches for merge commits (yet).
1422
+ *
1423
+ * @param out buffer to store the e-mail patch in
1424
+ * @param repo containing the commit
1425
+ * @param commit pointer to up commit
1426
+ * @param patch_no patch number of the commit
1427
+ * @param total_patches total number of patches in the patch set
1428
+ * @param flags determines the formatting of the e-mail
1429
+ * @param diff_opts structure with options to influence diff or NULL for defaults.
1430
+ * @return 0 or an error code
1431
+ */
1432
+ GIT_EXTERN(int) git_diff_commit_as_email(
1433
+ git_buf *out,
1434
+ git_repository *repo,
1435
+ git_commit *commit,
1436
+ size_t patch_no,
1437
+ size_t total_patches,
1438
+ git_diff_format_email_flags_t flags,
1439
+ const git_diff_options *diff_opts);
1440
+
1441
+ /**
1442
+ * Initialize git_diff_format_email_options structure
1443
+ *
1444
+ * Initializes a `git_diff_format_email_options` with default values. Equivalent
1445
+ * to creating an instance with GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT.
1446
+ *
1447
+ * @param opts The `git_blame_options` struct to initialize.
1448
+ * @param version The struct version; pass `GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION`.
1449
+ * @return Zero on success; -1 on failure.
1450
+ */
1451
+ GIT_EXTERN(int) git_diff_format_email_init_options(
1452
+ git_diff_format_email_options *opts,
1453
+ unsigned int version);
1454
+
1455
+ /**
1456
+ * Patch ID options structure
1457
+ *
1458
+ * Initialize with `GIT_PATCHID_OPTIONS_INIT`. Alternatively, you can
1459
+ * use `git_patchid_init_options`.
1460
+ *
1461
+ */
1462
+ typedef struct git_diff_patchid_options {
1463
+ unsigned int version;
1464
+ } git_diff_patchid_options;
1465
+
1466
+ #define GIT_DIFF_PATCHID_OPTIONS_VERSION 1
1467
+ #define GIT_DIFF_PATCHID_OPTIONS_INIT { GIT_DIFF_PATCHID_OPTIONS_VERSION }
1468
+
1469
+ /**
1470
+ * Initialize git_diff_patchid_options structure
1471
+ *
1472
+ * Initializes a `git_diff_patchid_options` with default values. Equivalent to
1473
+ * creating an instance with `GIT_DIFF_PATCHID_OPTIONS_INIT`.
1474
+ *
1475
+ * @param opts The `git_diff_patchid_options` struct to initialize.
1476
+ * @param version The struct version; pass `GIT_DIFF_PATCHID_OPTIONS_VERSION`.
1477
+ * @return Zero on success; -1 on failure.
1478
+ */
1479
+ GIT_EXTERN(int) git_diff_patchid_init_options(
1480
+ git_diff_patchid_options *opts,
1481
+ unsigned int version);
1482
+
1483
+ /**
1484
+ * Calculate the patch ID for the given patch.
1485
+ *
1486
+ * Calculate a stable patch ID for the given patch by summing the
1487
+ * hash of the file diffs, ignoring whitespace and line numbers.
1488
+ * This can be used to derive whether two diffs are the same with
1489
+ * a high probability.
1490
+ *
1491
+ * Currently, this function only calculates stable patch IDs, as
1492
+ * defined in git-patch-id(1), and should in fact generate the
1493
+ * same IDs as the upstream git project does.
1494
+ *
1495
+ * @param out Pointer where the calculated patch ID should be stored
1496
+ * @param diff The diff to calculate the ID for
1497
+ * @param opts Options for how to calculate the patch ID. This is
1498
+ * intended for future changes, as currently no options are
1499
+ * available.
1500
+ * @return 0 on success, an error code otherwise.
1501
+ */
1502
+ GIT_EXTERN(int) git_diff_patchid(git_oid *out, git_diff *diff, git_diff_patchid_options *opts);
1093
1503
 
1094
1504
  GIT_END_DECL
1095
1505