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
@@ -4,17 +4,20 @@
4
4
  * This file is part of libgit2, distributed under the GNU GPL v2 with
5
5
  * a Linking Exception. For full terms see the included COPYING file.
6
6
  */
7
- #include "common.h"
7
+
8
+ #include "diff_tform.h"
8
9
 
9
10
  #include "git2/config.h"
10
11
  #include "git2/blob.h"
12
+ #include "git2/sys/hashsig.h"
11
13
 
12
14
  #include "diff.h"
13
- #include "hashsig.h"
15
+ #include "diff_generate.h"
14
16
  #include "path.h"
15
17
  #include "fileops.h"
18
+ #include "config.h"
16
19
 
17
- static git_diff_delta *diff_delta__dup(
20
+ git_diff_delta *git_diff__delta_dup(
18
21
  const git_diff_delta *d, git_pool *pool)
19
22
  {
20
23
  git_diff_delta *delta = git__malloc(sizeof(git_diff_delta));
@@ -45,8 +48,10 @@ fail:
45
48
  return NULL;
46
49
  }
47
50
 
48
- static git_diff_delta *diff_delta__merge_like_cgit(
49
- const git_diff_delta *a, const git_diff_delta *b, git_pool *pool)
51
+ git_diff_delta *git_diff__merge_like_cgit(
52
+ const git_diff_delta *a,
53
+ const git_diff_delta *b,
54
+ git_pool *pool)
50
55
  {
51
56
  git_diff_delta *dup;
52
57
 
@@ -62,33 +67,43 @@ static git_diff_delta *diff_delta__merge_like_cgit(
62
67
  * f3 = b->new_file
63
68
  */
64
69
 
70
+ /* If one of the diffs is a conflict, just dup it */
71
+ if (b->status == GIT_DELTA_CONFLICTED)
72
+ return git_diff__delta_dup(b, pool);
73
+ if (a->status == GIT_DELTA_CONFLICTED)
74
+ return git_diff__delta_dup(a, pool);
75
+
65
76
  /* if f2 == f3 or f2 is deleted, then just dup the 'a' diff */
66
77
  if (b->status == GIT_DELTA_UNMODIFIED || a->status == GIT_DELTA_DELETED)
67
- return diff_delta__dup(a, pool);
78
+ return git_diff__delta_dup(a, pool);
68
79
 
69
80
  /* otherwise, base this diff on the 'b' diff */
70
- if ((dup = diff_delta__dup(b, pool)) == NULL)
81
+ if ((dup = git_diff__delta_dup(b, pool)) == NULL)
71
82
  return NULL;
72
83
 
73
84
  /* If 'a' status is uninteresting, then we're done */
74
- if (a->status == GIT_DELTA_UNMODIFIED)
85
+ if (a->status == GIT_DELTA_UNMODIFIED ||
86
+ a->status == GIT_DELTA_UNTRACKED ||
87
+ a->status == GIT_DELTA_UNREADABLE)
75
88
  return dup;
76
89
 
77
- assert(a->status != GIT_DELTA_UNMODIFIED);
78
90
  assert(b->status != GIT_DELTA_UNMODIFIED);
79
91
 
80
92
  /* A cgit exception is that the diff of a file that is only in the
81
93
  * index (i.e. not in HEAD nor workdir) is given as empty.
82
94
  */
83
95
  if (dup->status == GIT_DELTA_DELETED) {
84
- if (a->status == GIT_DELTA_ADDED)
96
+ if (a->status == GIT_DELTA_ADDED) {
85
97
  dup->status = GIT_DELTA_UNMODIFIED;
98
+ dup->nfiles = 2;
99
+ }
86
100
  /* else don't overwrite DELETE status */
87
101
  } else {
88
102
  dup->status = a->status;
103
+ dup->nfiles = a->nfiles;
89
104
  }
90
105
 
91
- git_oid_cpy(&dup->old_file.oid, &a->old_file.oid);
106
+ git_oid_cpy(&dup->old_file.id, &a->old_file.id);
92
107
  dup->old_file.mode = a->old_file.mode;
93
108
  dup->old_file.size = a->old_file.size;
94
109
  dup->old_file.flags = a->old_file.flags;
@@ -96,15 +111,14 @@ static git_diff_delta *diff_delta__merge_like_cgit(
96
111
  return dup;
97
112
  }
98
113
 
99
- int git_diff_merge(
100
- git_diff_list *onto,
101
- const git_diff_list *from)
114
+ int git_diff__merge(
115
+ git_diff *onto, const git_diff *from, git_diff__merge_cb cb)
102
116
  {
103
117
  int error = 0;
104
118
  git_pool onto_pool;
105
119
  git_vector onto_new;
106
120
  git_diff_delta *delta;
107
- bool ignore_case = false;
121
+ bool ignore_case, reversed;
108
122
  unsigned int i, j;
109
123
 
110
124
  assert(onto && from);
@@ -112,35 +126,38 @@ int git_diff_merge(
112
126
  if (!from->deltas.length)
113
127
  return 0;
114
128
 
115
- if (git_vector_init(
116
- &onto_new, onto->deltas.length, git_diff_delta__cmp) < 0 ||
117
- git_pool_init(&onto_pool, 1, 0) < 0)
129
+ ignore_case = ((onto->opts.flags & GIT_DIFF_IGNORE_CASE) != 0);
130
+ reversed = ((onto->opts.flags & GIT_DIFF_REVERSE) != 0);
131
+
132
+ if (ignore_case != ((from->opts.flags & GIT_DIFF_IGNORE_CASE) != 0) ||
133
+ reversed != ((from->opts.flags & GIT_DIFF_REVERSE) != 0)) {
134
+ git_error_set(GIT_ERROR_INVALID,
135
+ "attempt to merge diffs created with conflicting options");
118
136
  return -1;
137
+ }
119
138
 
120
- if ((onto->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0 ||
121
- (from->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0)
122
- {
123
- ignore_case = true;
139
+ if (git_vector_init(&onto_new, onto->deltas.length, git_diff_delta__cmp) < 0)
140
+ return -1;
124
141
 
125
- /* This function currently only supports merging diff lists that
126
- * are sorted identically. */
127
- assert((onto->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0 &&
128
- (from->opts.flags & GIT_DIFF_DELTAS_ARE_ICASE) != 0);
129
- }
142
+ git_pool_init(&onto_pool, 1);
130
143
 
131
144
  for (i = 0, j = 0; i < onto->deltas.length || j < from->deltas.length; ) {
132
145
  git_diff_delta *o = GIT_VECTOR_GET(&onto->deltas, i);
133
146
  const git_diff_delta *f = GIT_VECTOR_GET(&from->deltas, j);
134
- int cmp = !f ? -1 : !o ? 1 : STRCMP_CASESELECT(ignore_case, o->old_file.path, f->old_file.path);
147
+ int cmp = !f ? -1 : !o ? 1 :
148
+ STRCMP_CASESELECT(ignore_case, o->old_file.path, f->old_file.path);
135
149
 
136
150
  if (cmp < 0) {
137
- delta = diff_delta__dup(o, &onto_pool);
151
+ delta = git_diff__delta_dup(o, &onto_pool);
138
152
  i++;
139
153
  } else if (cmp > 0) {
140
- delta = diff_delta__dup(f, &onto_pool);
154
+ delta = git_diff__delta_dup(f, &onto_pool);
141
155
  j++;
142
156
  } else {
143
- delta = diff_delta__merge_like_cgit(o, f, &onto_pool);
157
+ const git_diff_delta *left = reversed ? f : o;
158
+ const git_diff_delta *right = reversed ? o : f;
159
+
160
+ delta = cb(left, right, &onto_pool);
144
161
  i++;
145
162
  j++;
146
163
  }
@@ -148,7 +165,7 @@ int git_diff_merge(
148
165
  /* the ignore rules for the target may not match the source
149
166
  * or the result of a merged delta could be skippable...
150
167
  */
151
- if (git_diff_delta__should_skip(&onto->opts, delta)) {
168
+ if (delta && git_diff_delta__should_skip(&onto->opts, delta)) {
152
169
  git__free(delta);
153
170
  continue;
154
171
  }
@@ -160,7 +177,11 @@ int git_diff_merge(
160
177
  if (!error) {
161
178
  git_vector_swap(&onto->deltas, &onto_new);
162
179
  git_pool_swap(&onto->pool, &onto_pool);
163
- onto->new_src = from->new_src;
180
+
181
+ if ((onto->opts.flags & GIT_DIFF_REVERSE) != 0)
182
+ onto->old_src = from->old_src;
183
+ else
184
+ onto->new_src = from->new_src;
164
185
 
165
186
  /* prefix strings also come from old pool, so recreate those.*/
166
187
  onto->opts.old_prefix =
@@ -169,46 +190,33 @@ int git_diff_merge(
169
190
  git_pool_strdup_safe(&onto->pool, onto->opts.new_prefix);
170
191
  }
171
192
 
172
- git_vector_foreach(&onto_new, i, delta)
173
- git__free(delta);
174
- git_vector_free(&onto_new);
193
+ git_vector_free_deep(&onto_new);
175
194
  git_pool_clear(&onto_pool);
176
195
 
177
196
  return error;
178
197
  }
179
198
 
199
+ int git_diff_merge(git_diff *onto, const git_diff *from)
200
+ {
201
+ return git_diff__merge(onto, from, git_diff__merge_like_cgit);
202
+ }
203
+
180
204
  int git_diff_find_similar__hashsig_for_file(
181
205
  void **out, const git_diff_file *f, const char *path, void *p)
182
206
  {
183
- git_hashsig_option_t opt = (git_hashsig_option_t)p;
184
- int error = 0;
207
+ git_hashsig_option_t opt = (git_hashsig_option_t)(intptr_t)p;
185
208
 
186
209
  GIT_UNUSED(f);
187
- error = git_hashsig_create_fromfile((git_hashsig **)out, path, opt);
188
-
189
- if (error == GIT_EBUFS) {
190
- error = 0;
191
- giterr_clear();
192
- }
193
-
194
- return error;
210
+ return git_hashsig_create_fromfile((git_hashsig **)out, path, opt);
195
211
  }
196
212
 
197
213
  int git_diff_find_similar__hashsig_for_buf(
198
214
  void **out, const git_diff_file *f, const char *buf, size_t len, void *p)
199
215
  {
200
- git_hashsig_option_t opt = (git_hashsig_option_t)p;
201
- int error = 0;
216
+ git_hashsig_option_t opt = (git_hashsig_option_t)(intptr_t)p;
202
217
 
203
218
  GIT_UNUSED(f);
204
- error = git_hashsig_create((git_hashsig **)out, buf, len, opt);
205
-
206
- if (error == GIT_EBUFS) {
207
- error = 0;
208
- giterr_clear();
209
- }
210
-
211
- return error;
219
+ return git_hashsig_create((git_hashsig **)out, buf, len, opt);
212
220
  }
213
221
 
214
222
  void git_diff_find_similar__hashsig_free(void *sig, void *payload)
@@ -220,8 +228,14 @@ void git_diff_find_similar__hashsig_free(void *sig, void *payload)
220
228
  int git_diff_find_similar__calc_similarity(
221
229
  int *score, void *siga, void *sigb, void *payload)
222
230
  {
231
+ int error;
232
+
223
233
  GIT_UNUSED(payload);
224
- *score = git_hashsig_compare(siga, sigb);
234
+ error = git_hashsig_compare(siga, sigb);
235
+ if (error < 0)
236
+ return error;
237
+
238
+ *score = error;
225
239
  return 0;
226
240
  }
227
241
 
@@ -230,34 +244,44 @@ int git_diff_find_similar__calc_similarity(
230
244
  #define DEFAULT_RENAME_LIMIT 200
231
245
 
232
246
  static int normalize_find_opts(
233
- git_diff_list *diff,
247
+ git_diff *diff,
234
248
  git_diff_find_options *opts,
235
- git_diff_find_options *given)
249
+ const git_diff_find_options *given)
236
250
  {
237
251
  git_config *cfg = NULL;
252
+ git_hashsig_option_t hashsig_opts;
253
+
254
+ GIT_ERROR_CHECK_VERSION(given, GIT_DIFF_FIND_OPTIONS_VERSION, "git_diff_find_options");
238
255
 
239
256
  if (diff->repo != NULL &&
240
257
  git_repository_config__weakptr(&cfg, diff->repo) < 0)
241
258
  return -1;
242
259
 
243
- if (given != NULL)
260
+ if (given)
244
261
  memcpy(opts, given, sizeof(*opts));
245
- else {
246
- const char *val = NULL;
247
-
248
- GIT_INIT_STRUCTURE(opts, GIT_DIFF_FIND_OPTIONS_VERSION);
249
262
 
250
- opts->flags = GIT_DIFF_FIND_RENAMES;
263
+ if (!given ||
264
+ (given->flags & GIT_DIFF_FIND_ALL) == GIT_DIFF_FIND_BY_CONFIG)
265
+ {
266
+ if (cfg) {
267
+ char *rule =
268
+ git_config__get_string_force(cfg, "diff.renames", "true");
269
+ int boolval;
270
+
271
+ if (!git__parse_bool(&boolval, rule) && !boolval)
272
+ /* don't set FIND_RENAMES if bool value is false */;
273
+ else if (!strcasecmp(rule, "copies") || !strcasecmp(rule, "copy"))
274
+ opts->flags |= GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES;
275
+ else
276
+ opts->flags |= GIT_DIFF_FIND_RENAMES;
251
277
 
252
- if (git_config_get_string(&val, cfg, "diff.renames") < 0)
253
- giterr_clear();
254
- else if (val &&
255
- (!strcasecmp(val, "copies") || !strcasecmp(val, "copy")))
256
- opts->flags = GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES;
278
+ git__free(rule);
279
+ } else {
280
+ /* set default flag */
281
+ opts->flags |= GIT_DIFF_FIND_RENAMES;
282
+ }
257
283
  }
258
284
 
259
- GITERR_CHECK_VERSION(opts, GIT_DIFF_FIND_OPTIONS_VERSION, "git_diff_find_options");
260
-
261
285
  /* some flags imply others */
262
286
 
263
287
  if (opts->flags & GIT_DIFF_FIND_EXACT_MATCH_ONLY) {
@@ -296,20 +320,19 @@ static int normalize_find_opts(
296
320
  #undef USE_DEFAULT
297
321
 
298
322
  if (!opts->rename_limit) {
299
- int32_t limit = 0;
300
-
301
- opts->rename_limit = DEFAULT_RENAME_LIMIT;
323
+ if (cfg) {
324
+ opts->rename_limit = git_config__get_int_force(
325
+ cfg, "diff.renamelimit", DEFAULT_RENAME_LIMIT);
326
+ }
302
327
 
303
- if (git_config_get_int32(&limit, cfg, "diff.renameLimit") < 0)
304
- giterr_clear();
305
- else if (limit > 0)
306
- opts->rename_limit = limit;
328
+ if (opts->rename_limit <= 0)
329
+ opts->rename_limit = DEFAULT_RENAME_LIMIT;
307
330
  }
308
331
 
309
332
  /* assign the internal metric with whitespace flag as payload */
310
333
  if (!opts->metric) {
311
334
  opts->metric = git__malloc(sizeof(git_diff_similarity_metric));
312
- GITERR_CHECK_ALLOC(opts->metric);
335
+ GIT_ERROR_CHECK_ALLOC(opts->metric);
313
336
 
314
337
  opts->metric->file_signature = git_diff_find_similar__hashsig_for_file;
315
338
  opts->metric->buffer_signature = git_diff_find_similar__hashsig_for_buf;
@@ -317,22 +340,40 @@ static int normalize_find_opts(
317
340
  opts->metric->similarity = git_diff_find_similar__calc_similarity;
318
341
 
319
342
  if (opts->flags & GIT_DIFF_FIND_IGNORE_WHITESPACE)
320
- opts->metric->payload = (void *)GIT_HASHSIG_IGNORE_WHITESPACE;
343
+ hashsig_opts = GIT_HASHSIG_IGNORE_WHITESPACE;
321
344
  else if (opts->flags & GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE)
322
- opts->metric->payload = (void *)GIT_HASHSIG_NORMAL;
345
+ hashsig_opts = GIT_HASHSIG_NORMAL;
323
346
  else
324
- opts->metric->payload = (void *)GIT_HASHSIG_SMART_WHITESPACE;
347
+ hashsig_opts = GIT_HASHSIG_SMART_WHITESPACE;
348
+ hashsig_opts |= GIT_HASHSIG_ALLOW_SMALL_FILES;
349
+ opts->metric->payload = (void *)hashsig_opts;
325
350
  }
326
351
 
327
352
  return 0;
328
353
  }
329
354
 
355
+ static int insert_delete_side_of_split(
356
+ git_diff *diff, git_vector *onto, const git_diff_delta *delta)
357
+ {
358
+ /* make new record for DELETED side of split */
359
+ git_diff_delta *deleted = git_diff__delta_dup(delta, &diff->pool);
360
+ GIT_ERROR_CHECK_ALLOC(deleted);
361
+
362
+ deleted->status = GIT_DELTA_DELETED;
363
+ deleted->nfiles = 1;
364
+ memset(&deleted->new_file, 0, sizeof(deleted->new_file));
365
+ deleted->new_file.path = deleted->old_file.path;
366
+ deleted->new_file.flags |= GIT_DIFF_FLAG_VALID_ID;
367
+
368
+ return git_vector_insert(onto, deleted);
369
+ }
370
+
330
371
  static int apply_splits_and_deletes(
331
- git_diff_list *diff, size_t expected_size, bool actually_split)
372
+ git_diff *diff, size_t expected_size, bool actually_split)
332
373
  {
333
374
  git_vector onto = GIT_VECTOR_INIT;
334
375
  size_t i;
335
- git_diff_delta *delta, *deleted;
376
+ git_diff_delta *delta;
336
377
 
337
378
  if (git_vector_init(&onto, expected_size, git_diff_delta__cmp) < 0)
338
379
  return -1;
@@ -345,25 +386,17 @@ static int apply_splits_and_deletes(
345
386
  if ((delta->flags & GIT_DIFF_FLAG__TO_SPLIT) != 0 && actually_split) {
346
387
  delta->similarity = 0;
347
388
 
348
- /* make new record for DELETED side of split */
349
- if (!(deleted = diff_delta__dup(delta, &diff->pool)))
350
- goto on_error;
351
-
352
- deleted->status = GIT_DELTA_DELETED;
353
- memset(&deleted->new_file, 0, sizeof(deleted->new_file));
354
- deleted->new_file.path = deleted->old_file.path;
355
- deleted->new_file.flags |= GIT_DIFF_FLAG_VALID_OID;
356
-
357
- if (git_vector_insert(&onto, deleted) < 0)
389
+ if (insert_delete_side_of_split(diff, &onto, delta) < 0)
358
390
  goto on_error;
359
391
 
360
392
  if (diff->new_src == GIT_ITERATOR_TYPE_WORKDIR)
361
393
  delta->status = GIT_DELTA_UNTRACKED;
362
394
  else
363
395
  delta->status = GIT_DELTA_ADDED;
396
+ delta->nfiles = 1;
364
397
  memset(&delta->old_file, 0, sizeof(delta->old_file));
365
398
  delta->old_file.path = delta->new_file.path;
366
- delta->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
399
+ delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID;
367
400
  }
368
401
 
369
402
  /* clean up delta before inserting into new list */
@@ -395,70 +428,110 @@ static int apply_splits_and_deletes(
395
428
  return 0;
396
429
 
397
430
  on_error:
398
- git_vector_foreach(&onto, i, delta)
399
- git__free(delta);
400
- git_vector_free(&onto);
431
+ git_vector_free_deep(&onto);
401
432
 
402
433
  return -1;
403
434
  }
404
435
 
405
- GIT_INLINE(git_diff_file *) similarity_get_file(git_diff_list *diff, size_t idx)
436
+ GIT_INLINE(git_diff_file *) similarity_get_file(git_diff *diff, size_t idx)
406
437
  {
407
438
  git_diff_delta *delta = git_vector_get(&diff->deltas, idx / 2);
408
439
  return (idx & 1) ? &delta->new_file : &delta->old_file;
409
440
  }
410
441
 
411
- static int similarity_calc(
412
- git_diff_list *diff,
442
+ typedef struct {
443
+ size_t idx;
444
+ git_iterator_type_t src;
445
+ git_repository *repo;
446
+ git_diff_file *file;
447
+ git_buf data;
448
+ git_odb_object *odb_obj;
449
+ git_blob *blob;
450
+ } similarity_info;
451
+
452
+ static int similarity_init(
453
+ similarity_info *info, git_diff *diff, size_t file_idx)
454
+ {
455
+ info->idx = file_idx;
456
+ info->src = (file_idx & 1) ? diff->new_src : diff->old_src;
457
+ info->repo = diff->repo;
458
+ info->file = similarity_get_file(diff, file_idx);
459
+ info->odb_obj = NULL;
460
+ info->blob = NULL;
461
+ git_buf_init(&info->data, 0);
462
+
463
+ if (info->file->size > 0 || info->src == GIT_ITERATOR_TYPE_WORKDIR)
464
+ return 0;
465
+
466
+ return git_diff_file__resolve_zero_size(
467
+ info->file, &info->odb_obj, info->repo);
468
+ }
469
+
470
+ static int similarity_sig(
471
+ similarity_info *info,
413
472
  const git_diff_find_options *opts,
414
- size_t file_idx,
415
473
  void **cache)
416
474
  {
417
475
  int error = 0;
418
- git_diff_file *file = similarity_get_file(diff, file_idx);
419
- git_iterator_type_t src = (file_idx & 1) ? diff->new_src : diff->old_src;
420
-
421
- if (src == GIT_ITERATOR_TYPE_WORKDIR) { /* compute hashsig from file */
422
- git_buf path = GIT_BUF_INIT;
423
-
424
- /* TODO: apply wd-to-odb filters to file data if necessary */
476
+ git_diff_file *file = info->file;
425
477
 
478
+ if (info->src == GIT_ITERATOR_TYPE_WORKDIR) {
426
479
  if ((error = git_buf_joinpath(
427
- &path, git_repository_workdir(diff->repo), file->path)) < 0)
480
+ &info->data, git_repository_workdir(info->repo), file->path)) < 0)
428
481
  return error;
429
482
 
430
483
  /* if path is not a regular file, just skip this item */
431
- if (git_path_isfile(path.ptr))
432
- error = opts->metric->file_signature(
433
- &cache[file_idx], file, path.ptr, opts->metric->payload);
484
+ if (!git_path_isfile(info->data.ptr))
485
+ return 0;
434
486
 
435
- git_buf_free(&path);
436
- } else { /* compute hashsig from blob buffer */
437
- git_blob *blob = NULL;
438
- git_off_t blobsize;
487
+ /* TODO: apply wd-to-odb filters to file data if necessary */
439
488
 
440
- /* TODO: add max size threshold a la diff? */
489
+ error = opts->metric->file_signature(
490
+ &cache[info->idx], info->file,
491
+ info->data.ptr, opts->metric->payload);
492
+ } else {
493
+ /* if we didn't initially know the size, we might have an odb_obj
494
+ * around from earlier, so convert that, otherwise load the blob now
495
+ */
496
+ if (info->odb_obj != NULL)
497
+ error = git_object__from_odb_object(
498
+ (git_object **)&info->blob, info->repo,
499
+ info->odb_obj, GIT_OBJECT_BLOB);
500
+ else
501
+ error = git_blob_lookup(&info->blob, info->repo, &file->id);
441
502
 
442
- if (git_blob_lookup(&blob, diff->repo, &file->oid) < 0) {
503
+ if (error < 0) {
443
504
  /* if lookup fails, just skip this item in similarity calc */
444
- giterr_clear();
445
- return 0;
446
- }
505
+ git_error_clear();
506
+ } else {
507
+ size_t sz;
447
508
 
448
- blobsize = git_blob_rawsize(blob);
449
- if (!git__is_sizet(blobsize)) /* ? what to do ? */
450
- blobsize = (size_t)-1;
509
+ /* index size may not be actual blob size if filtered */
510
+ if (file->size != git_blob_rawsize(info->blob))
511
+ file->size = git_blob_rawsize(info->blob);
451
512
 
452
- error = opts->metric->buffer_signature(
453
- &cache[file_idx], file, git_blob_rawcontent(blob),
454
- (size_t)blobsize, opts->metric->payload);
513
+ sz = (size_t)(git__is_sizet(file->size) ? file->size : -1);
455
514
 
456
- git_blob_free(blob);
515
+ error = opts->metric->buffer_signature(
516
+ &cache[info->idx], info->file,
517
+ git_blob_rawcontent(info->blob), sz, opts->metric->payload);
518
+ }
457
519
  }
458
520
 
459
521
  return error;
460
522
  }
461
523
 
524
+ static void similarity_unload(similarity_info *info)
525
+ {
526
+ if (info->odb_obj)
527
+ git_odb_object_free(info->odb_obj);
528
+
529
+ if (info->blob)
530
+ git_blob_free(info->blob);
531
+ else
532
+ git_buf_dispose(&info->data);
533
+ }
534
+
462
535
  #define FLAG_SET(opts,flag_name) (((opts)->flags & flag_name) != 0)
463
536
 
464
537
  /* - score < 0 means files cannot be compared
@@ -467,7 +540,7 @@ static int similarity_calc(
467
540
  */
468
541
  static int similarity_measure(
469
542
  int *score,
470
- git_diff_list *diff,
543
+ git_diff *diff,
471
544
  const git_diff_find_options *opts,
472
545
  void **cache,
473
546
  size_t a_idx,
@@ -476,30 +549,32 @@ static int similarity_measure(
476
549
  git_diff_file *a_file = similarity_get_file(diff, a_idx);
477
550
  git_diff_file *b_file = similarity_get_file(diff, b_idx);
478
551
  bool exact_match = FLAG_SET(opts, GIT_DIFF_FIND_EXACT_MATCH_ONLY);
552
+ int error = 0;
553
+ similarity_info a_info, b_info;
479
554
 
480
555
  *score = -1;
481
556
 
482
- /* don't try to compare files of different types */
483
- if (GIT_MODE_TYPE(a_file->mode) != GIT_MODE_TYPE(b_file->mode))
557
+ /* don't try to compare things that aren't files */
558
+ if (!GIT_MODE_ISBLOB(a_file->mode) || !GIT_MODE_ISBLOB(b_file->mode))
484
559
  return 0;
485
560
 
486
561
  /* if exact match is requested, force calculation of missing OIDs now */
487
562
  if (exact_match) {
488
- if (git_oid_iszero(&a_file->oid) &&
563
+ if (git_oid_iszero(&a_file->id) &&
489
564
  diff->old_src == GIT_ITERATOR_TYPE_WORKDIR &&
490
- !git_diff__oid_for_file(diff->repo, a_file->path,
491
- a_file->mode, a_file->size, &a_file->oid))
492
- a_file->flags |= GIT_DIFF_FLAG_VALID_OID;
565
+ !git_diff__oid_for_file(&a_file->id,
566
+ diff, a_file->path, a_file->mode, a_file->size))
567
+ a_file->flags |= GIT_DIFF_FLAG_VALID_ID;
493
568
 
494
- if (git_oid_iszero(&b_file->oid) &&
569
+ if (git_oid_iszero(&b_file->id) &&
495
570
  diff->new_src == GIT_ITERATOR_TYPE_WORKDIR &&
496
- !git_diff__oid_for_file(diff->repo, b_file->path,
497
- b_file->mode, b_file->size, &b_file->oid))
498
- b_file->flags |= GIT_DIFF_FLAG_VALID_OID;
571
+ !git_diff__oid_for_file(&b_file->id,
572
+ diff, b_file->path, b_file->mode, b_file->size))
573
+ b_file->flags |= GIT_DIFF_FLAG_VALID_ID;
499
574
  }
500
575
 
501
576
  /* check OID match as a quick test */
502
- if (git_oid__cmp(&a_file->oid, &b_file->oid) == 0) {
577
+ if (git_oid__cmp(&a_file->id, &b_file->id) == 0) {
503
578
  *score = 100;
504
579
  return 0;
505
580
  }
@@ -510,23 +585,48 @@ static int similarity_measure(
510
585
  return 0;
511
586
  }
512
587
 
588
+ memset(&a_info, 0, sizeof(a_info));
589
+ memset(&b_info, 0, sizeof(b_info));
590
+
591
+ /* set up similarity data (will try to update missing file sizes) */
592
+ if (!cache[a_idx] && (error = similarity_init(&a_info, diff, a_idx)) < 0)
593
+ return error;
594
+ if (!cache[b_idx] && (error = similarity_init(&b_info, diff, b_idx)) < 0)
595
+ goto cleanup;
596
+
597
+ /* check if file sizes are nowhere near each other */
598
+ if (a_file->size > 127 &&
599
+ b_file->size > 127 &&
600
+ (a_file->size > (b_file->size << 3) ||
601
+ b_file->size > (a_file->size << 3)))
602
+ goto cleanup;
603
+
513
604
  /* update signature cache if needed */
514
- if (!cache[a_idx] && similarity_calc(diff, opts, a_idx, cache) < 0)
515
- return -1;
516
- if (!cache[b_idx] && similarity_calc(diff, opts, b_idx, cache) < 0)
517
- return -1;
605
+ if (!cache[a_idx]) {
606
+ if ((error = similarity_sig(&a_info, opts, cache)) < 0)
607
+ goto cleanup;
608
+ }
609
+ if (!cache[b_idx]) {
610
+ if ((error = similarity_sig(&b_info, opts, cache)) < 0)
611
+ goto cleanup;
612
+ }
518
613
 
519
- /* some metrics may not wish to process this file (too big / too small) */
520
- if (!cache[a_idx] || !cache[b_idx])
521
- return 0;
614
+ /* calculate similarity provided that the metric choose to process
615
+ * both the a and b files (some may not if file is too big, etc).
616
+ */
617
+ if (cache[a_idx] && cache[b_idx])
618
+ error = opts->metric->similarity(
619
+ score, cache[a_idx], cache[b_idx], opts->metric->payload);
620
+
621
+ cleanup:
622
+ similarity_unload(&a_info);
623
+ similarity_unload(&b_info);
522
624
 
523
- /* compare signatures */
524
- return opts->metric->similarity(
525
- score, cache[a_idx], cache[b_idx], opts->metric->payload);
625
+ return error;
526
626
  }
527
627
 
528
628
  static int calc_self_similarity(
529
- git_diff_list *diff,
629
+ git_diff *diff,
530
630
  const git_diff_find_options *opts,
531
631
  size_t delta_idx,
532
632
  void **cache)
@@ -543,7 +643,7 @@ static int calc_self_similarity(
543
643
  return error;
544
644
 
545
645
  if (similarity >= 0) {
546
- delta->similarity = (uint32_t)similarity;
646
+ delta->similarity = (uint16_t)similarity;
547
647
  delta->flags |= GIT_DIFF_FLAG__HAS_SELF_SIMILARITY;
548
648
  }
549
649
 
@@ -551,7 +651,7 @@ static int calc_self_similarity(
551
651
  }
552
652
 
553
653
  static bool is_rename_target(
554
- git_diff_list *diff,
654
+ git_diff *diff,
555
655
  const git_diff_find_options *opts,
556
656
  size_t delta_idx,
557
657
  void **cache)
@@ -563,11 +663,13 @@ static bool is_rename_target(
563
663
  return false;
564
664
 
565
665
  /* only consider ADDED, RENAMED, COPIED, and split MODIFIED as
566
- * targets; maybe include UNTRACKED and IGNORED if requested.
666
+ * targets; maybe include UNTRACKED if requested.
567
667
  */
568
668
  switch (delta->status) {
569
669
  case GIT_DELTA_UNMODIFIED:
570
670
  case GIT_DELTA_DELETED:
671
+ case GIT_DELTA_IGNORED:
672
+ case GIT_DELTA_CONFLICTED:
571
673
  return false;
572
674
 
573
675
  case GIT_DELTA_MODIFIED:
@@ -584,13 +686,14 @@ static bool is_rename_target(
584
686
  break;
585
687
  }
586
688
  if (FLAG_SET(opts, GIT_DIFF_FIND_RENAMES_FROM_REWRITES) &&
587
- delta->similarity < opts->rename_from_rewrite_threshold)
689
+ delta->similarity < opts->rename_from_rewrite_threshold) {
690
+ delta->flags |= GIT_DIFF_FLAG__TO_SPLIT;
588
691
  break;
692
+ }
589
693
 
590
694
  return false;
591
695
 
592
696
  case GIT_DELTA_UNTRACKED:
593
- case GIT_DELTA_IGNORED:
594
697
  if (!FLAG_SET(opts, GIT_DIFF_FIND_FOR_UNTRACKED))
595
698
  return false;
596
699
  break;
@@ -604,7 +707,7 @@ static bool is_rename_target(
604
707
  }
605
708
 
606
709
  static bool is_rename_source(
607
- git_diff_list *diff,
710
+ git_diff *diff,
608
711
  const git_diff_find_options *opts,
609
712
  size_t delta_idx,
610
713
  void **cache)
@@ -618,7 +721,9 @@ static bool is_rename_source(
618
721
  switch (delta->status) {
619
722
  case GIT_DELTA_ADDED:
620
723
  case GIT_DELTA_UNTRACKED:
724
+ case GIT_DELTA_UNREADABLE:
621
725
  case GIT_DELTA_IGNORED:
726
+ case GIT_DELTA_CONFLICTED:
622
727
  return false;
623
728
 
624
729
  case GIT_DELTA_DELETED:
@@ -628,6 +733,8 @@ static bool is_rename_source(
628
733
  case GIT_DELTA_UNMODIFIED:
629
734
  if (!FLAG_SET(opts, GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED))
630
735
  return false;
736
+ if (FLAG_SET(opts, GIT_DIFF_FIND_REMOVE_UNMODIFIED))
737
+ delta->flags |= GIT_DIFF_FLAG__TO_DELETE;
631
738
  break;
632
739
 
633
740
  default: /* MODIFIED, RENAMED, COPIED */
@@ -670,69 +777,93 @@ GIT_INLINE(bool) delta_is_new_only(git_diff_delta *delta)
670
777
  {
671
778
  return (delta->status == GIT_DELTA_ADDED ||
672
779
  delta->status == GIT_DELTA_UNTRACKED ||
780
+ delta->status == GIT_DELTA_UNREADABLE ||
673
781
  delta->status == GIT_DELTA_IGNORED);
674
782
  }
675
783
 
676
784
  GIT_INLINE(void) delta_make_rename(
677
- git_diff_delta *to, const git_diff_delta *from, uint32_t similarity)
785
+ git_diff_delta *to, const git_diff_delta *from, uint16_t similarity)
678
786
  {
679
787
  to->status = GIT_DELTA_RENAMED;
680
788
  to->similarity = similarity;
789
+ to->nfiles = 2;
681
790
  memcpy(&to->old_file, &from->old_file, sizeof(to->old_file));
682
791
  to->flags &= ~GIT_DIFF_FLAG__TO_SPLIT;
683
792
  }
684
793
 
685
794
  typedef struct {
686
- uint32_t idx;
687
- uint32_t similarity;
795
+ size_t idx;
796
+ uint16_t similarity;
688
797
  } diff_find_match;
689
798
 
690
799
  int git_diff_find_similar(
691
- git_diff_list *diff,
692
- git_diff_find_options *given_opts)
800
+ git_diff *diff,
801
+ const git_diff_find_options *given_opts)
693
802
  {
694
- size_t i, j, sigcache_size;
695
- int error = 0, similarity;
696
- git_diff_delta *from, *to;
697
- git_diff_find_options opts;
698
- size_t num_srcs = 0, num_tgts = 0, tried_srcs = 0, tried_tgts = 0;
803
+ size_t s, t;
804
+ int error = 0, result;
805
+ uint16_t similarity;
806
+ git_diff_delta *src, *tgt;
807
+ git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT;
808
+ size_t num_deltas, num_srcs = 0, num_tgts = 0;
809
+ size_t tried_srcs = 0, tried_tgts = 0;
699
810
  size_t num_rewrites = 0, num_updates = 0, num_bumped = 0;
700
- void **sigcache; /* cache of similarity metric file signatures */
701
- diff_find_match *match_srcs = NULL, *match_tgts = NULL, *best_match;
811
+ size_t sigcache_size;
812
+ void **sigcache = NULL; /* cache of similarity metric file signatures */
813
+ diff_find_match *tgt2src = NULL;
814
+ diff_find_match *src2tgt = NULL;
815
+ diff_find_match *tgt2src_copy = NULL;
816
+ diff_find_match *best_match;
702
817
  git_diff_file swap;
703
818
 
819
+ assert(diff);
820
+
704
821
  if ((error = normalize_find_opts(diff, &opts, given_opts)) < 0)
705
822
  return error;
706
823
 
824
+ num_deltas = diff->deltas.length;
825
+
707
826
  /* TODO: maybe abort if deltas.length > rename_limit ??? */
708
- if (!git__is_uint32(diff->deltas.length))
709
- return 0;
827
+ if (!num_deltas || !git__is_uint32(num_deltas))
828
+ goto cleanup;
829
+
830
+ /* No flags set; nothing to do */
831
+ if ((opts.flags & GIT_DIFF_FIND_ALL) == 0)
832
+ goto cleanup;
710
833
 
711
- sigcache_size = diff->deltas.length * 2; /* keep size b/c diff may change */
834
+ GIT_ERROR_CHECK_ALLOC_MULTIPLY(&sigcache_size, num_deltas, 2);
712
835
  sigcache = git__calloc(sigcache_size, sizeof(void *));
713
- GITERR_CHECK_ALLOC(sigcache);
836
+ GIT_ERROR_CHECK_ALLOC(sigcache);
714
837
 
715
838
  /* Label rename sources and targets
716
839
  *
717
840
  * This will also set self-similarity scores for MODIFIED files and
718
841
  * mark them for splitting if break-rewrites is enabled
719
842
  */
720
- git_vector_foreach(&diff->deltas, i, to) {
721
- if (is_rename_source(diff, &opts, i, sigcache))
843
+ git_vector_foreach(&diff->deltas, t, tgt) {
844
+ if (is_rename_source(diff, &opts, t, sigcache))
722
845
  ++num_srcs;
723
846
 
724
- if (is_rename_target(diff, &opts, i, sigcache))
847
+ if (is_rename_target(diff, &opts, t, sigcache))
725
848
  ++num_tgts;
849
+
850
+ if ((tgt->flags & GIT_DIFF_FLAG__TO_SPLIT) != 0)
851
+ num_rewrites++;
726
852
  }
727
853
 
728
854
  /* if there are no candidate srcs or tgts, we're done */
729
855
  if (!num_srcs || !num_tgts)
730
856
  goto cleanup;
731
857
 
732
- match_tgts = git__calloc(diff->deltas.length, sizeof(diff_find_match));
733
- GITERR_CHECK_ALLOC(match_tgts);
734
- match_srcs = git__calloc(diff->deltas.length, sizeof(diff_find_match));
735
- GITERR_CHECK_ALLOC(match_srcs);
858
+ src2tgt = git__calloc(num_deltas, sizeof(diff_find_match));
859
+ GIT_ERROR_CHECK_ALLOC(src2tgt);
860
+ tgt2src = git__calloc(num_deltas, sizeof(diff_find_match));
861
+ GIT_ERROR_CHECK_ALLOC(tgt2src);
862
+
863
+ if (FLAG_SET(&opts, GIT_DIFF_FIND_COPIES)) {
864
+ tgt2src_copy = git__calloc(num_deltas, sizeof(diff_find_match));
865
+ GIT_ERROR_CHECK_ALLOC(tgt2src_copy);
866
+ }
736
867
 
737
868
  /*
738
869
  * Find best-fit matches for rename / copy candidates
@@ -741,47 +872,62 @@ int git_diff_find_similar(
741
872
  find_best_matches:
742
873
  tried_tgts = num_bumped = 0;
743
874
 
744
- git_vector_foreach(&diff->deltas, i, to) {
875
+ git_vector_foreach(&diff->deltas, t, tgt) {
745
876
  /* skip things that are not rename targets */
746
- if ((to->flags & GIT_DIFF_FLAG__IS_RENAME_TARGET) == 0)
877
+ if ((tgt->flags & GIT_DIFF_FLAG__IS_RENAME_TARGET) == 0)
747
878
  continue;
748
879
 
749
880
  tried_srcs = 0;
750
881
 
751
- git_vector_foreach(&diff->deltas, j, from) {
882
+ git_vector_foreach(&diff->deltas, s, src) {
752
883
  /* skip things that are not rename sources */
753
- if ((from->flags & GIT_DIFF_FLAG__IS_RENAME_SOURCE) == 0)
884
+ if ((src->flags & GIT_DIFF_FLAG__IS_RENAME_SOURCE) == 0)
754
885
  continue;
755
886
 
756
887
  /* calculate similarity for this pair and find best match */
757
- if (i == j)
758
- similarity = -1; /* don't measure self-similarity here */
888
+ if (s == t)
889
+ result = -1; /* don't measure self-similarity here */
759
890
  else if ((error = similarity_measure(
760
- &similarity, diff, &opts, sigcache, 2 * j, 2 * i + 1)) < 0)
891
+ &result, diff, &opts, sigcache, 2 * s, 2 * t + 1)) < 0)
761
892
  goto cleanup;
762
893
 
763
- /* if this pairing is better for the src and the tgt, keep it */
764
- if (similarity > 0 &&
765
- match_tgts[i].similarity < (uint32_t)similarity &&
766
- match_srcs[j].similarity < (uint32_t)similarity)
894
+ if (result < 0)
895
+ continue;
896
+ similarity = (uint16_t)result;
897
+
898
+ /* is this a better rename? */
899
+ if (tgt2src[t].similarity < similarity &&
900
+ src2tgt[s].similarity < similarity)
767
901
  {
768
- if (match_tgts[i].similarity > 0) {
769
- match_tgts[match_srcs[j].idx].similarity = 0;
770
- match_srcs[match_tgts[i].idx].similarity = 0;
771
- ++num_bumped;
902
+ /* eject old mapping */
903
+ if (src2tgt[s].similarity > 0) {
904
+ tgt2src[src2tgt[s].idx].similarity = 0;
905
+ num_bumped++;
906
+ }
907
+ if (tgt2src[t].similarity > 0) {
908
+ src2tgt[tgt2src[t].idx].similarity = 0;
909
+ num_bumped++;
772
910
  }
773
911
 
774
- match_tgts[i].similarity = (uint32_t)similarity;
775
- match_tgts[i].idx = (uint32_t)j;
912
+ /* write new mapping */
913
+ tgt2src[t].idx = s;
914
+ tgt2src[t].similarity = similarity;
915
+ src2tgt[s].idx = t;
916
+ src2tgt[s].similarity = similarity;
917
+ }
776
918
 
777
- match_srcs[j].similarity = (uint32_t)similarity;
778
- match_srcs[j].idx = (uint32_t)i;
919
+ /* keep best absolute match for copies */
920
+ if (tgt2src_copy != NULL &&
921
+ tgt2src_copy[t].similarity < similarity)
922
+ {
923
+ tgt2src_copy[t].idx = s;
924
+ tgt2src_copy[t].similarity = similarity;
779
925
  }
780
926
 
781
927
  if (++tried_srcs >= num_srcs)
782
928
  break;
783
929
 
784
- /* cap on maximum targets we'll examine (per "to" file) */
930
+ /* cap on maximum targets we'll examine (per "tgt" file) */
785
931
  if (tried_srcs > opts.rename_limit)
786
932
  break;
787
933
  }
@@ -797,20 +943,21 @@ find_best_matches:
797
943
  * Rewrite the diffs with renames / copies
798
944
  */
799
945
 
800
- tried_tgts = 0;
801
-
802
- git_vector_foreach(&diff->deltas, i, to) {
946
+ git_vector_foreach(&diff->deltas, t, tgt) {
803
947
  /* skip things that are not rename targets */
804
- if ((to->flags & GIT_DIFF_FLAG__IS_RENAME_TARGET) == 0)
948
+ if ((tgt->flags & GIT_DIFF_FLAG__IS_RENAME_TARGET) == 0)
805
949
  continue;
806
950
 
807
951
  /* check if this delta was the target of a similarity */
808
- best_match = &match_tgts[i];
809
- if (!best_match->similarity)
952
+ if (tgt2src[t].similarity)
953
+ best_match = &tgt2src[t];
954
+ else if (tgt2src_copy && tgt2src_copy[t].similarity)
955
+ best_match = &tgt2src_copy[t];
956
+ else
810
957
  continue;
811
958
 
812
- j = best_match->idx;
813
- from = GIT_VECTOR_GET(&diff->deltas, j);
959
+ s = best_match->idx;
960
+ src = GIT_VECTOR_GET(&diff->deltas, s);
814
961
 
815
962
  /* possible scenarios:
816
963
  * 1. from DELETE to ADD/UNTRACK/IGNORE = RENAME
@@ -820,101 +967,122 @@ find_best_matches:
820
967
  * 5. from OTHER to ADD/UNTRACK/IGNORE = OTHER + COPY
821
968
  */
822
969
 
823
- if (from->status == GIT_DELTA_DELETED) {
970
+ if (src->status == GIT_DELTA_DELETED) {
824
971
 
825
- if (delta_is_new_only(to)) {
972
+ if (delta_is_new_only(tgt)) {
826
973
 
827
974
  if (best_match->similarity < opts.rename_threshold)
828
975
  continue;
829
976
 
830
- delta_make_rename(to, from, best_match->similarity);
977
+ delta_make_rename(tgt, src, best_match->similarity);
831
978
 
832
- from->flags |= GIT_DIFF_FLAG__TO_DELETE;
979
+ src->flags |= GIT_DIFF_FLAG__TO_DELETE;
833
980
  num_rewrites++;
834
981
  } else {
835
- assert(delta_is_split(to));
982
+ assert(delta_is_split(tgt));
836
983
 
837
984
  if (best_match->similarity < opts.rename_from_rewrite_threshold)
838
985
  continue;
839
986
 
840
- memcpy(&swap, &to->old_file, sizeof(swap));
987
+ memcpy(&swap, &tgt->old_file, sizeof(swap));
841
988
 
842
- delta_make_rename(to, from, best_match->similarity);
989
+ delta_make_rename(tgt, src, best_match->similarity);
843
990
  num_rewrites--;
844
991
 
845
- from->status = GIT_DELTA_DELETED;
846
- memcpy(&from->old_file, &swap, sizeof(from->old_file));
847
- memset(&from->new_file, 0, sizeof(from->new_file));
848
- from->new_file.path = from->old_file.path;
849
- from->new_file.flags |= GIT_DIFF_FLAG_VALID_OID;
992
+ assert(src->status == GIT_DELTA_DELETED);
993
+ memcpy(&src->old_file, &swap, sizeof(src->old_file));
994
+ memset(&src->new_file, 0, sizeof(src->new_file));
995
+ src->new_file.path = src->old_file.path;
996
+ src->new_file.flags |= GIT_DIFF_FLAG_VALID_ID;
850
997
 
851
998
  num_updates++;
999
+
1000
+ if (src2tgt[t].similarity > 0 && src2tgt[t].idx > t) {
1001
+ /* what used to be at src t is now at src s */
1002
+ tgt2src[src2tgt[t].idx].idx = s;
1003
+ }
852
1004
  }
853
1005
  }
854
1006
 
855
- else if (delta_is_split(from)) {
1007
+ else if (delta_is_split(src)) {
856
1008
 
857
- if (delta_is_new_only(to)) {
1009
+ if (delta_is_new_only(tgt)) {
858
1010
 
859
1011
  if (best_match->similarity < opts.rename_threshold)
860
1012
  continue;
861
1013
 
862
- delta_make_rename(to, from, best_match->similarity);
1014
+ delta_make_rename(tgt, src, best_match->similarity);
863
1015
 
864
- from->status = (diff->new_src == GIT_ITERATOR_TYPE_WORKDIR) ?
1016
+ src->status = (diff->new_src == GIT_ITERATOR_TYPE_WORKDIR) ?
865
1017
  GIT_DELTA_UNTRACKED : GIT_DELTA_ADDED;
866
- memset(&from->old_file, 0, sizeof(from->old_file));
867
- from->old_file.path = from->new_file.path;
868
- from->old_file.flags |= GIT_DIFF_FLAG_VALID_OID;
1018
+ src->nfiles = 1;
1019
+ memset(&src->old_file, 0, sizeof(src->old_file));
1020
+ src->old_file.path = src->new_file.path;
1021
+ src->old_file.flags |= GIT_DIFF_FLAG_VALID_ID;
869
1022
 
870
- from->flags &= ~GIT_DIFF_FLAG__TO_SPLIT;
1023
+ src->flags &= ~GIT_DIFF_FLAG__TO_SPLIT;
871
1024
  num_rewrites--;
872
1025
 
873
1026
  num_updates++;
874
1027
  } else {
875
- assert(delta_is_split(from));
1028
+ assert(delta_is_split(src));
876
1029
 
877
1030
  if (best_match->similarity < opts.rename_from_rewrite_threshold)
878
1031
  continue;
879
1032
 
880
- memcpy(&swap, &to->old_file, sizeof(swap));
1033
+ memcpy(&swap, &tgt->old_file, sizeof(swap));
881
1034
 
882
- delta_make_rename(to, from, best_match->similarity);
1035
+ delta_make_rename(tgt, src, best_match->similarity);
883
1036
  num_rewrites--;
884
1037
  num_updates++;
885
1038
 
886
- memcpy(&from->old_file, &swap, sizeof(from->old_file));
1039
+ memcpy(&src->old_file, &swap, sizeof(src->old_file));
887
1040
 
888
1041
  /* if we've just swapped the new element into the correct
889
1042
  * place, clear the SPLIT flag
890
1043
  */
891
- if (match_tgts[j].idx == i &&
892
- match_tgts[j].similarity >
1044
+ if (tgt2src[s].idx == t &&
1045
+ tgt2src[s].similarity >
893
1046
  opts.rename_from_rewrite_threshold) {
894
-
895
- from->status = GIT_DELTA_RENAMED;
896
- from->similarity = match_tgts[j].similarity;
897
- match_tgts[j].similarity = 0;
898
- from->flags &= ~GIT_DIFF_FLAG__TO_SPLIT;
1047
+ src->status = GIT_DELTA_RENAMED;
1048
+ src->similarity = tgt2src[s].similarity;
1049
+ tgt2src[s].similarity = 0;
1050
+ src->flags &= ~GIT_DIFF_FLAG__TO_SPLIT;
899
1051
  num_rewrites--;
900
1052
  }
901
1053
  /* otherwise, if we just overwrote a source, update mapping */
902
- else if (j > i && match_srcs[i].similarity > 0) {
903
- match_tgts[match_srcs[i].idx].idx = (uint32_t)j;
1054
+ else if (src2tgt[t].similarity > 0 && src2tgt[t].idx > t) {
1055
+ /* what used to be at src t is now at src s */
1056
+ tgt2src[src2tgt[t].idx].idx = s;
904
1057
  }
905
1058
 
906
1059
  num_updates++;
907
1060
  }
908
1061
  }
909
1062
 
910
- else if (delta_is_new_only(to)) {
911
- if (!FLAG_SET(&opts, GIT_DIFF_FIND_COPIES) ||
912
- best_match->similarity < opts.copy_threshold)
1063
+ else if (FLAG_SET(&opts, GIT_DIFF_FIND_COPIES)) {
1064
+ if (tgt2src_copy[t].similarity < opts.copy_threshold)
1065
+ continue;
1066
+
1067
+ /* always use best possible source for copy */
1068
+ best_match = &tgt2src_copy[t];
1069
+ src = GIT_VECTOR_GET(&diff->deltas, best_match->idx);
1070
+
1071
+ if (delta_is_split(tgt)) {
1072
+ error = insert_delete_side_of_split(diff, &diff->deltas, tgt);
1073
+ if (error < 0)
1074
+ goto cleanup;
1075
+ num_rewrites--;
1076
+ }
1077
+
1078
+ if (!delta_is_split(tgt) && !delta_is_new_only(tgt))
913
1079
  continue;
914
1080
 
915
- to->status = GIT_DELTA_COPIED;
916
- to->similarity = best_match->similarity;
917
- memcpy(&to->old_file, &from->old_file, sizeof(to->old_file));
1081
+ tgt->status = GIT_DELTA_COPIED;
1082
+ tgt->similarity = best_match->similarity;
1083
+ tgt->nfiles = 2;
1084
+ memcpy(&tgt->old_file, &src->old_file, sizeof(tgt->old_file));
1085
+ tgt->flags &= ~GIT_DIFF_FLAG__TO_SPLIT;
918
1086
 
919
1087
  num_updates++;
920
1088
  }
@@ -927,17 +1095,21 @@ find_best_matches:
927
1095
  if (num_rewrites > 0 || num_updates > 0)
928
1096
  error = apply_splits_and_deletes(
929
1097
  diff, diff->deltas.length - num_rewrites,
930
- FLAG_SET(&opts, GIT_DIFF_BREAK_REWRITES));
1098
+ FLAG_SET(&opts, GIT_DIFF_BREAK_REWRITES) &&
1099
+ !FLAG_SET(&opts, GIT_DIFF_BREAK_REWRITES_FOR_RENAMES_ONLY));
931
1100
 
932
1101
  cleanup:
933
- git__free(match_srcs);
934
- git__free(match_tgts);
935
-
936
- for (i = 0; i < sigcache_size; ++i) {
937
- if (sigcache[i] != NULL)
938
- opts.metric->free_signature(sigcache[i], opts.metric->payload);
1102
+ git__free(tgt2src);
1103
+ git__free(src2tgt);
1104
+ git__free(tgt2src_copy);
1105
+
1106
+ if (sigcache) {
1107
+ for (t = 0; t < num_deltas * 2; ++t) {
1108
+ if (sigcache[t] != NULL)
1109
+ opts.metric->free_signature(sigcache[t], opts.metric->payload);
1110
+ }
1111
+ git__free(sigcache);
939
1112
  }
940
- git__free(sigcache);
941
1113
 
942
1114
  if (!given_opts || !given_opts->metric)
943
1115
  git__free(opts.metric);