rugged 1.1.1 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (407) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -0
  3. data/README.md +1 -1
  4. data/ext/rugged/extconf.rb +2 -2
  5. data/ext/rugged/rugged.c +7 -4
  6. data/ext/rugged/rugged_config.c +7 -2
  7. data/ext/rugged/rugged_object.c +1 -1
  8. data/ext/rugged/rugged_remote.c +17 -0
  9. data/ext/rugged/rugged_repo.c +3 -3
  10. data/lib/rugged/repository.rb +2 -2
  11. data/lib/rugged/version.rb +1 -1
  12. data/vendor/libgit2/CMakeLists.txt +103 -271
  13. data/vendor/libgit2/COPYING +149 -24
  14. data/vendor/libgit2/cmake/AddCFlagIfSupported.cmake +21 -21
  15. data/vendor/libgit2/cmake/DefaultCFlags.cmake +154 -0
  16. data/vendor/libgit2/cmake/EnableWarnings.cmake +13 -13
  17. data/vendor/libgit2/cmake/FindCoreFoundation.cmake +13 -13
  18. data/vendor/libgit2/cmake/FindGSSAPI.cmake +171 -287
  19. data/vendor/libgit2/cmake/FindGSSFramework.cmake +13 -13
  20. data/vendor/libgit2/cmake/{FindHTTP_Parser.cmake → FindHTTPParser.cmake} +17 -17
  21. data/vendor/libgit2/cmake/FindIconv.cmake +27 -27
  22. data/vendor/libgit2/cmake/FindLibSSH2.cmake +13 -0
  23. data/vendor/libgit2/cmake/FindPCRE.cmake +13 -13
  24. data/vendor/libgit2/cmake/FindPCRE2.cmake +12 -12
  25. data/vendor/libgit2/cmake/FindPkgLibraries.cmake +19 -19
  26. data/vendor/libgit2/cmake/FindSecurity.cmake +14 -14
  27. data/vendor/libgit2/cmake/FindStatNsec.cmake +12 -18
  28. data/vendor/libgit2/cmake/Findfutimens.cmake +14 -0
  29. data/vendor/libgit2/cmake/FindmbedTLS.cmake +63 -70
  30. data/vendor/libgit2/cmake/IdeSplitSources.cmake +18 -18
  31. data/vendor/libgit2/cmake/PkgBuildConfig.cmake +60 -60
  32. data/vendor/libgit2/cmake/SanitizeBool.cmake +20 -20
  33. data/vendor/libgit2/cmake/SelectGSSAPI.cmake +37 -37
  34. data/vendor/libgit2/cmake/SelectHTTPParser.cmake +19 -0
  35. data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +100 -96
  36. data/vendor/libgit2/cmake/SelectHashes.cmake +39 -48
  37. data/vendor/libgit2/cmake/SelectRegex.cmake +51 -0
  38. data/vendor/libgit2/cmake/SelectSSH.cmake +41 -0
  39. data/vendor/libgit2/cmake/SelectWinHTTP.cmake +17 -0
  40. data/vendor/libgit2/cmake/SelectZlib.cmake +34 -0
  41. data/vendor/libgit2/deps/chromium-zlib/CMakeLists.txt +101 -0
  42. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +32 -20
  43. data/vendor/libgit2/deps/ntlmclient/crypt.h +14 -9
  44. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.c +20 -20
  45. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.h +3 -3
  46. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.c +37 -36
  47. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.h +4 -3
  48. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +178 -51
  49. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.h +74 -5
  50. data/vendor/libgit2/deps/ntlmclient/ntlm.c +154 -122
  51. data/vendor/libgit2/deps/ntlmclient/ntlm.h +17 -13
  52. data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +17 -4
  53. data/vendor/libgit2/deps/ntlmclient/unicode.h +10 -4
  54. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.c +16 -27
  55. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.h +20 -0
  56. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.c +28 -52
  57. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.h +22 -0
  58. data/vendor/libgit2/deps/pcre/CMakeLists.txt +88 -88
  59. data/vendor/libgit2/deps/winhttp/CMakeLists.txt +14 -16
  60. data/vendor/libgit2/include/git2/apply.h +16 -2
  61. data/vendor/libgit2/include/git2/attr.h +106 -2
  62. data/vendor/libgit2/include/git2/blame.h +97 -43
  63. data/vendor/libgit2/include/git2/blob.h +33 -2
  64. data/vendor/libgit2/include/git2/branch.h +27 -0
  65. data/vendor/libgit2/include/git2/buffer.h +18 -78
  66. data/vendor/libgit2/include/git2/cert.h +43 -6
  67. data/vendor/libgit2/include/git2/checkout.h +32 -13
  68. data/vendor/libgit2/include/git2/clone.h +4 -4
  69. data/vendor/libgit2/include/git2/commit.h +37 -19
  70. data/vendor/libgit2/include/git2/common.h +46 -5
  71. data/vendor/libgit2/include/git2/config.h +19 -3
  72. data/vendor/libgit2/include/git2/credential.h +2 -1
  73. data/vendor/libgit2/include/git2/credential_helpers.h +1 -0
  74. data/vendor/libgit2/include/git2/deprecated.h +326 -6
  75. data/vendor/libgit2/include/git2/describe.h +7 -2
  76. data/vendor/libgit2/include/git2/diff.h +50 -121
  77. data/vendor/libgit2/include/git2/email.h +127 -0
  78. data/vendor/libgit2/include/git2/errors.h +7 -6
  79. data/vendor/libgit2/include/git2/filter.h +69 -18
  80. data/vendor/libgit2/include/git2/graph.h +21 -2
  81. data/vendor/libgit2/include/git2/ignore.h +1 -1
  82. data/vendor/libgit2/include/git2/index.h +13 -7
  83. data/vendor/libgit2/include/git2/indexer.h +19 -0
  84. data/vendor/libgit2/include/git2/merge.h +23 -3
  85. data/vendor/libgit2/include/git2/message.h +2 -0
  86. data/vendor/libgit2/include/git2/notes.h +2 -2
  87. data/vendor/libgit2/include/git2/object.h +23 -0
  88. data/vendor/libgit2/include/git2/odb.h +65 -6
  89. data/vendor/libgit2/include/git2/odb_backend.h +1 -1
  90. data/vendor/libgit2/include/git2/oidarray.h +5 -8
  91. data/vendor/libgit2/include/git2/pack.h +24 -8
  92. data/vendor/libgit2/include/git2/patch.h +16 -0
  93. data/vendor/libgit2/include/git2/pathspec.h +1 -1
  94. data/vendor/libgit2/include/git2/proxy.h +1 -1
  95. data/vendor/libgit2/include/git2/rebase.h +34 -2
  96. data/vendor/libgit2/include/git2/refdb.h +3 -0
  97. data/vendor/libgit2/include/git2/reflog.h +1 -1
  98. data/vendor/libgit2/include/git2/refs.h +8 -4
  99. data/vendor/libgit2/include/git2/remote.h +246 -46
  100. data/vendor/libgit2/include/git2/repository.h +25 -18
  101. data/vendor/libgit2/include/git2/reset.h +2 -2
  102. data/vendor/libgit2/include/git2/revparse.h +5 -5
  103. data/vendor/libgit2/include/git2/revwalk.h +4 -1
  104. data/vendor/libgit2/include/git2/signature.h +1 -1
  105. data/vendor/libgit2/include/git2/stash.h +4 -4
  106. data/vendor/libgit2/include/git2/status.h +124 -62
  107. data/vendor/libgit2/include/git2/stdint.h +3 -3
  108. data/vendor/libgit2/include/git2/submodule.h +16 -2
  109. data/vendor/libgit2/include/git2/sys/commit_graph.h +174 -0
  110. data/vendor/libgit2/include/git2/sys/email.h +45 -0
  111. data/vendor/libgit2/include/git2/sys/filter.h +49 -28
  112. data/vendor/libgit2/include/git2/sys/midx.h +74 -0
  113. data/vendor/libgit2/include/git2/sys/odb_backend.h +9 -5
  114. data/vendor/libgit2/include/git2/sys/remote.h +31 -0
  115. data/vendor/libgit2/include/git2/sys/stream.h +1 -1
  116. data/vendor/libgit2/include/git2/sys/transport.h +26 -34
  117. data/vendor/libgit2/include/git2/tag.h +13 -0
  118. data/vendor/libgit2/include/git2/tree.h +4 -17
  119. data/vendor/libgit2/include/git2/types.h +16 -7
  120. data/vendor/libgit2/include/git2/version.h +4 -4
  121. data/vendor/libgit2/include/git2/worktree.h +13 -2
  122. data/vendor/libgit2/include/git2.h +1 -0
  123. data/vendor/libgit2/src/CMakeLists.txt +192 -290
  124. data/vendor/libgit2/src/alloc.c +21 -8
  125. data/vendor/libgit2/src/allocators/failalloc.c +92 -0
  126. data/vendor/libgit2/src/allocators/failalloc.h +23 -0
  127. data/vendor/libgit2/src/allocators/stdalloc.c +41 -10
  128. data/vendor/libgit2/src/allocators/win32_leakcheck.c +118 -0
  129. data/vendor/libgit2/src/allocators/{win32_crtdbg.h → win32_leakcheck.h} +3 -3
  130. data/vendor/libgit2/src/annotated_commit.c +21 -9
  131. data/vendor/libgit2/src/annotated_commit.h +1 -1
  132. data/vendor/libgit2/src/apply.c +34 -25
  133. data/vendor/libgit2/src/apply.h +2 -2
  134. data/vendor/libgit2/src/array.h +11 -11
  135. data/vendor/libgit2/src/attr.c +204 -82
  136. data/vendor/libgit2/src/attr_file.c +105 -52
  137. data/vendor/libgit2/src/attr_file.h +36 -15
  138. data/vendor/libgit2/src/attrcache.c +55 -45
  139. data/vendor/libgit2/src/attrcache.h +4 -5
  140. data/vendor/libgit2/src/blame.c +15 -9
  141. data/vendor/libgit2/src/blame_git.c +2 -2
  142. data/vendor/libgit2/src/blob.c +76 -52
  143. data/vendor/libgit2/src/blob.h +1 -1
  144. data/vendor/libgit2/src/branch.c +203 -110
  145. data/vendor/libgit2/src/branch.h +15 -3
  146. data/vendor/libgit2/src/buf.c +126 -0
  147. data/vendor/libgit2/src/buf.h +50 -0
  148. data/vendor/libgit2/src/cache.c +2 -2
  149. data/vendor/libgit2/src/cache.h +7 -7
  150. data/vendor/libgit2/src/cc-compat.h +11 -9
  151. data/vendor/libgit2/src/checkout.c +118 -91
  152. data/vendor/libgit2/src/cherrypick.c +16 -12
  153. data/vendor/libgit2/src/clone.c +97 -103
  154. data/vendor/libgit2/src/commit.c +167 -84
  155. data/vendor/libgit2/src/commit.h +24 -1
  156. data/vendor/libgit2/src/commit_graph.c +1224 -0
  157. data/vendor/libgit2/src/commit_graph.h +169 -0
  158. data/vendor/libgit2/src/commit_list.c +48 -3
  159. data/vendor/libgit2/src/commit_list.h +2 -0
  160. data/vendor/libgit2/src/common.h +35 -5
  161. data/vendor/libgit2/src/config.c +119 -64
  162. data/vendor/libgit2/src/config.h +15 -2
  163. data/vendor/libgit2/src/config_cache.c +5 -3
  164. data/vendor/libgit2/src/config_file.c +120 -100
  165. data/vendor/libgit2/src/config_mem.c +9 -9
  166. data/vendor/libgit2/src/config_parse.c +29 -27
  167. data/vendor/libgit2/src/crlf.c +36 -23
  168. data/vendor/libgit2/src/date.c +13 -19
  169. data/vendor/libgit2/src/date.h +33 -0
  170. data/vendor/libgit2/src/delta.c +1 -1
  171. data/vendor/libgit2/src/describe.c +32 -21
  172. data/vendor/libgit2/src/diff.c +71 -183
  173. data/vendor/libgit2/src/diff.h +2 -4
  174. data/vendor/libgit2/src/diff_driver.c +53 -51
  175. data/vendor/libgit2/src/diff_driver.h +3 -3
  176. data/vendor/libgit2/src/diff_file.c +31 -26
  177. data/vendor/libgit2/src/diff_generate.c +76 -23
  178. data/vendor/libgit2/src/diff_generate.h +5 -3
  179. data/vendor/libgit2/src/diff_print.c +120 -95
  180. data/vendor/libgit2/src/diff_stats.c +47 -34
  181. data/vendor/libgit2/src/{message.h → diff_stats.h} +7 -6
  182. data/vendor/libgit2/src/diff_tform.c +18 -16
  183. data/vendor/libgit2/src/diff_xdiff.c +7 -10
  184. data/vendor/libgit2/src/diff_xdiff.h +1 -1
  185. data/vendor/libgit2/src/email.c +315 -0
  186. data/vendor/libgit2/src/email.h +25 -0
  187. data/vendor/libgit2/src/errors.c +37 -32
  188. data/vendor/libgit2/src/features.h.in +11 -2
  189. data/vendor/libgit2/src/fetch.c +77 -26
  190. data/vendor/libgit2/src/fetch.h +1 -1
  191. data/vendor/libgit2/src/fetchhead.c +27 -23
  192. data/vendor/libgit2/src/filebuf.c +36 -34
  193. data/vendor/libgit2/src/filebuf.h +1 -1
  194. data/vendor/libgit2/src/filter.c +278 -132
  195. data/vendor/libgit2/src/filter.h +46 -6
  196. data/vendor/libgit2/src/fs_path.c +2071 -0
  197. data/vendor/libgit2/src/fs_path.h +772 -0
  198. data/vendor/libgit2/src/futils.c +96 -90
  199. data/vendor/libgit2/src/futils.h +27 -15
  200. data/vendor/libgit2/src/graph.c +64 -9
  201. data/vendor/libgit2/src/hash/sha1/collisiondetect.c +5 -5
  202. data/vendor/libgit2/src/hash/sha1/common_crypto.c +5 -5
  203. data/vendor/libgit2/src/hash/sha1/generic.c +2 -2
  204. data/vendor/libgit2/src/hash/sha1/generic.h +1 -1
  205. data/vendor/libgit2/src/hash/sha1/mbedtls.c +13 -13
  206. data/vendor/libgit2/src/hash/sha1/openssl.c +5 -5
  207. data/vendor/libgit2/src/hash/sha1/sha1dc/sha1.c +9 -11
  208. data/vendor/libgit2/src/hash/sha1/win32.c +21 -17
  209. data/vendor/libgit2/src/hash/sha1.h +3 -1
  210. data/vendor/libgit2/src/hash.c +71 -36
  211. data/vendor/libgit2/src/hash.h +13 -13
  212. data/vendor/libgit2/src/hashsig.c +23 -10
  213. data/vendor/libgit2/src/ident.c +30 -20
  214. data/vendor/libgit2/src/ignore.c +63 -46
  215. data/vendor/libgit2/src/ignore.h +2 -2
  216. data/vendor/libgit2/src/index.c +184 -149
  217. data/vendor/libgit2/src/index.h +7 -4
  218. data/vendor/libgit2/src/indexer.c +143 -89
  219. data/vendor/libgit2/src/integer.h +64 -2
  220. data/vendor/libgit2/src/iterator.c +93 -73
  221. data/vendor/libgit2/src/iterator.h +6 -6
  222. data/vendor/libgit2/src/khash.h +3 -12
  223. data/vendor/libgit2/src/{settings.c → libgit2.c} +165 -56
  224. data/vendor/libgit2/src/libgit2.h +15 -0
  225. data/vendor/libgit2/src/mailmap.c +60 -45
  226. data/vendor/libgit2/src/map.h +3 -3
  227. data/vendor/libgit2/src/merge.c +104 -61
  228. data/vendor/libgit2/src/merge.h +3 -15
  229. data/vendor/libgit2/src/merge_driver.c +21 -15
  230. data/vendor/libgit2/src/merge_file.c +24 -6
  231. data/vendor/libgit2/src/message.c +21 -8
  232. data/vendor/libgit2/src/midx.c +501 -18
  233. data/vendor/libgit2/src/midx.h +29 -2
  234. data/vendor/libgit2/src/mwindow.c +103 -59
  235. data/vendor/libgit2/src/mwindow.h +3 -3
  236. data/vendor/libgit2/src/net.c +405 -71
  237. data/vendor/libgit2/src/net.h +26 -5
  238. data/vendor/libgit2/src/netops.c +7 -5
  239. data/vendor/libgit2/src/netops.h +3 -3
  240. data/vendor/libgit2/src/notes.c +40 -49
  241. data/vendor/libgit2/src/object.c +68 -20
  242. data/vendor/libgit2/src/object.h +1 -1
  243. data/vendor/libgit2/src/odb.c +320 -80
  244. data/vendor/libgit2/src/odb.h +17 -3
  245. data/vendor/libgit2/src/odb_loose.c +96 -86
  246. data/vendor/libgit2/src/odb_mempack.c +19 -6
  247. data/vendor/libgit2/src/odb_pack.c +402 -125
  248. data/vendor/libgit2/src/oid.c +16 -8
  249. data/vendor/libgit2/src/oid.h +15 -0
  250. data/vendor/libgit2/src/oidarray.c +10 -1
  251. data/vendor/libgit2/src/pack-objects.c +90 -69
  252. data/vendor/libgit2/src/pack-objects.h +11 -6
  253. data/vendor/libgit2/src/pack.c +337 -127
  254. data/vendor/libgit2/src/pack.h +25 -7
  255. data/vendor/libgit2/src/patch.c +17 -10
  256. data/vendor/libgit2/src/patch.h +1 -0
  257. data/vendor/libgit2/src/patch_generate.c +29 -13
  258. data/vendor/libgit2/src/patch_generate.h +5 -5
  259. data/vendor/libgit2/src/patch_parse.c +26 -25
  260. data/vendor/libgit2/src/path.c +86 -1768
  261. data/vendor/libgit2/src/path.h +39 -635
  262. data/vendor/libgit2/src/pathspec.c +12 -12
  263. data/vendor/libgit2/src/pathspec.h +2 -2
  264. data/vendor/libgit2/src/pool.c +13 -7
  265. data/vendor/libgit2/src/posix.c +14 -6
  266. data/vendor/libgit2/src/posix.h +1 -0
  267. data/vendor/libgit2/src/pqueue.h +1 -1
  268. data/vendor/libgit2/src/proxy.c +4 -1
  269. data/vendor/libgit2/src/proxy.h +1 -1
  270. data/vendor/libgit2/src/push.c +30 -35
  271. data/vendor/libgit2/src/push.h +4 -16
  272. data/vendor/libgit2/src/rand.c +226 -0
  273. data/vendor/libgit2/src/rand.h +37 -0
  274. data/vendor/libgit2/src/reader.c +18 -14
  275. data/vendor/libgit2/src/reader.h +2 -2
  276. data/vendor/libgit2/src/rebase.c +177 -132
  277. data/vendor/libgit2/src/refdb.c +30 -13
  278. data/vendor/libgit2/src/refdb_fs.c +548 -222
  279. data/vendor/libgit2/src/reflog.c +19 -14
  280. data/vendor/libgit2/src/refs.c +107 -72
  281. data/vendor/libgit2/src/refs.h +2 -2
  282. data/vendor/libgit2/src/refspec.c +53 -38
  283. data/vendor/libgit2/src/refspec.h +5 -2
  284. data/vendor/libgit2/src/regexp.c +1 -1
  285. data/vendor/libgit2/src/remote.c +960 -486
  286. data/vendor/libgit2/src/remote.h +16 -10
  287. data/vendor/libgit2/src/repository.c +702 -422
  288. data/vendor/libgit2/src/repository.h +26 -8
  289. data/vendor/libgit2/src/reset.c +16 -12
  290. data/vendor/libgit2/src/revert.c +16 -12
  291. data/vendor/libgit2/src/revparse.c +66 -48
  292. data/vendor/libgit2/src/revwalk.c +39 -22
  293. data/vendor/libgit2/src/runtime.c +162 -0
  294. data/vendor/libgit2/src/runtime.h +62 -0
  295. data/vendor/libgit2/src/settings.h +11 -0
  296. data/vendor/libgit2/src/signature.c +18 -11
  297. data/vendor/libgit2/src/signature.h +1 -1
  298. data/vendor/libgit2/src/sortedcache.c +1 -1
  299. data/vendor/libgit2/src/sortedcache.h +10 -8
  300. data/vendor/libgit2/src/stash.c +39 -38
  301. data/vendor/libgit2/src/status.c +11 -5
  302. data/vendor/libgit2/src/{buffer.c → str.c} +459 -136
  303. data/vendor/libgit2/src/str.h +357 -0
  304. data/vendor/libgit2/src/strarray.c +2 -1
  305. data/vendor/libgit2/src/streams/mbedtls.c +22 -23
  306. data/vendor/libgit2/src/streams/mbedtls.h +1 -1
  307. data/vendor/libgit2/src/streams/openssl.c +101 -201
  308. data/vendor/libgit2/src/streams/openssl.h +9 -1
  309. data/vendor/libgit2/src/streams/openssl_dynamic.c +309 -0
  310. data/vendor/libgit2/src/streams/openssl_dynamic.h +348 -0
  311. data/vendor/libgit2/src/streams/openssl_legacy.c +203 -0
  312. data/vendor/libgit2/src/streams/openssl_legacy.h +63 -0
  313. data/vendor/libgit2/src/streams/registry.c +5 -6
  314. data/vendor/libgit2/src/streams/socket.c +6 -2
  315. data/vendor/libgit2/src/streams/stransport.c +6 -3
  316. data/vendor/libgit2/src/streams/tls.c +5 -3
  317. data/vendor/libgit2/src/submodule.c +290 -212
  318. data/vendor/libgit2/src/submodule.h +10 -10
  319. data/vendor/libgit2/src/sysdir.c +70 -56
  320. data/vendor/libgit2/src/sysdir.h +15 -10
  321. data/vendor/libgit2/src/tag.c +72 -34
  322. data/vendor/libgit2/src/thread.c +140 -0
  323. data/vendor/libgit2/src/thread.h +479 -0
  324. data/vendor/libgit2/src/threadstate.c +84 -0
  325. data/vendor/libgit2/src/threadstate.h +24 -0
  326. data/vendor/libgit2/src/trace.c +3 -16
  327. data/vendor/libgit2/src/trace.h +17 -30
  328. data/vendor/libgit2/src/trailer.c +2 -2
  329. data/vendor/libgit2/src/transaction.c +20 -9
  330. data/vendor/libgit2/src/transport.c +13 -13
  331. data/vendor/libgit2/src/transports/auth.c +8 -10
  332. data/vendor/libgit2/src/transports/auth.h +2 -3
  333. data/vendor/libgit2/src/transports/auth_negotiate.c +23 -17
  334. data/vendor/libgit2/src/transports/auth_ntlm.c +20 -16
  335. data/vendor/libgit2/src/transports/auth_ntlm.h +0 -1
  336. data/vendor/libgit2/src/transports/credential.c +15 -7
  337. data/vendor/libgit2/src/transports/git.c +10 -14
  338. data/vendor/libgit2/src/transports/http.c +56 -34
  339. data/vendor/libgit2/src/transports/http.h +3 -3
  340. data/vendor/libgit2/src/transports/httpclient.c +106 -79
  341. data/vendor/libgit2/src/transports/httpclient.h +1 -1
  342. data/vendor/libgit2/src/transports/local.c +127 -119
  343. data/vendor/libgit2/src/transports/smart.c +61 -144
  344. data/vendor/libgit2/src/transports/smart.h +26 -32
  345. data/vendor/libgit2/src/transports/smart_pkt.c +33 -33
  346. data/vendor/libgit2/src/transports/smart_protocol.c +68 -44
  347. data/vendor/libgit2/src/transports/ssh.c +100 -131
  348. data/vendor/libgit2/src/transports/winhttp.c +86 -82
  349. data/vendor/libgit2/src/tree-cache.c +5 -5
  350. data/vendor/libgit2/src/tree-cache.h +2 -2
  351. data/vendor/libgit2/src/tree.c +150 -116
  352. data/vendor/libgit2/src/tree.h +1 -0
  353. data/vendor/libgit2/src/tsort.c +0 -2
  354. data/vendor/libgit2/src/unix/map.c +3 -3
  355. data/vendor/libgit2/src/unix/posix.h +1 -4
  356. data/vendor/libgit2/src/unix/pthread.h +2 -1
  357. data/vendor/libgit2/src/unix/realpath.c +0 -2
  358. data/vendor/libgit2/src/utf8.c +150 -0
  359. data/vendor/libgit2/src/utf8.h +52 -0
  360. data/vendor/libgit2/src/util.c +68 -144
  361. data/vendor/libgit2/src/util.h +36 -68
  362. data/vendor/libgit2/src/vector.c +23 -19
  363. data/vendor/libgit2/src/vector.h +5 -3
  364. data/vendor/libgit2/src/win32/findfile.c +172 -114
  365. data/vendor/libgit2/src/win32/findfile.h +7 -4
  366. data/vendor/libgit2/src/win32/map.c +1 -1
  367. data/vendor/libgit2/src/win32/msvc-compat.h +9 -1
  368. data/vendor/libgit2/src/win32/path_w32.c +162 -33
  369. data/vendor/libgit2/src/win32/path_w32.h +2 -1
  370. data/vendor/libgit2/src/win32/posix.h +6 -7
  371. data/vendor/libgit2/src/win32/posix_w32.c +26 -33
  372. data/vendor/libgit2/src/win32/precompiled.h +0 -1
  373. data/vendor/libgit2/src/win32/reparse.h +4 -4
  374. data/vendor/libgit2/src/win32/thread.c +24 -15
  375. data/vendor/libgit2/src/win32/thread.h +1 -1
  376. data/vendor/libgit2/src/win32/w32_buffer.c +5 -6
  377. data/vendor/libgit2/src/win32/w32_buffer.h +2 -3
  378. data/vendor/libgit2/src/win32/w32_common.h +18 -9
  379. data/vendor/libgit2/src/win32/{w32_crtdbg_stacktrace.c → w32_leakcheck.c} +269 -33
  380. data/vendor/libgit2/src/win32/w32_leakcheck.h +222 -0
  381. data/vendor/libgit2/src/win32/w32_util.h +6 -6
  382. data/vendor/libgit2/src/worktree.c +138 -105
  383. data/vendor/libgit2/src/worktree.h +1 -1
  384. data/vendor/libgit2/src/xdiff/git-xdiff.h +53 -0
  385. data/vendor/libgit2/src/xdiff/xdiff.h +15 -15
  386. data/vendor/libgit2/src/xdiff/xdiffi.c +134 -108
  387. data/vendor/libgit2/src/xdiff/xemit.c +23 -7
  388. data/vendor/libgit2/src/xdiff/xhistogram.c +87 -78
  389. data/vendor/libgit2/src/xdiff/xinclude.h +1 -12
  390. data/vendor/libgit2/src/xdiff/xmerge.c +104 -117
  391. data/vendor/libgit2/src/xdiff/xpatience.c +6 -17
  392. data/vendor/libgit2/src/xdiff/xprepare.c +15 -20
  393. data/vendor/libgit2/src/xdiff/xutils.c +18 -7
  394. data/vendor/libgit2/src/zstream.c +6 -6
  395. data/vendor/libgit2/src/zstream.h +4 -4
  396. metadata +60 -24
  397. data/vendor/libgit2/src/allocators/win32_crtdbg.c +0 -118
  398. data/vendor/libgit2/src/buf_text.c +0 -316
  399. data/vendor/libgit2/src/buf_text.h +0 -122
  400. data/vendor/libgit2/src/buffer.h +0 -222
  401. data/vendor/libgit2/src/global.c +0 -363
  402. data/vendor/libgit2/src/global.h +0 -41
  403. data/vendor/libgit2/src/thread-utils.c +0 -58
  404. data/vendor/libgit2/src/thread-utils.h +0 -369
  405. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +0 -127
  406. data/vendor/libgit2/src/win32/w32_stack.c +0 -188
  407. data/vendor/libgit2/src/win32/w32_stack.h +0 -140
@@ -7,13 +7,16 @@
7
7
 
8
8
  #include "midx.h"
9
9
 
10
- #include "buffer.h"
10
+ #include "array.h"
11
+ #include "buf.h"
12
+ #include "filebuf.h"
11
13
  #include "futils.h"
12
14
  #include "hash.h"
13
15
  #include "odb.h"
14
16
  #include "pack.h"
15
-
16
- #define GIT_MIDX_FILE_MODE 0444
17
+ #include "fs_path.h"
18
+ #include "repository.h"
19
+ #include "str.h"
17
20
 
18
21
  #define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */
19
22
  #define MIDX_VERSION 1
@@ -38,6 +41,8 @@ struct git_midx_chunk {
38
41
  size_t length;
39
42
  };
40
43
 
44
+ typedef int (*midx_write_cb)(const char *buf, size_t size, void *cb_data);
45
+
41
46
  static int midx_error(const char *message)
42
47
  {
43
48
  git_error_set(GIT_ERROR_ODB, "invalid multi-pack-index file - %s", message);
@@ -116,7 +121,7 @@ static int midx_parse_oid_lookup(
116
121
  return midx_error("missing OID Lookup chunk");
117
122
  if (chunk_oid_lookup->length == 0)
118
123
  return midx_error("empty OID Lookup chunk");
119
- if (chunk_oid_lookup->length != idx->num_objects * 20)
124
+ if (chunk_oid_lookup->length != idx->num_objects * GIT_OID_RAWSZ)
120
125
  return midx_error("OID Lookup chunk has wrong length");
121
126
 
122
127
  idx->oid_lookup = oid = (git_oid *)(data + chunk_oid_lookup->offset);
@@ -173,7 +178,8 @@ int git_midx_parse(
173
178
  struct git_midx_chunk *last_chunk;
174
179
  uint32_t i;
175
180
  off64_t last_chunk_offset, chunk_offset, trailer_offset;
176
- git_oid idx_checksum = {{0}};
181
+ size_t checksum_size;
182
+ unsigned char checksum[GIT_HASH_SHA1_SIZE];
177
183
  int error;
178
184
  struct git_midx_chunk chunk_packfile_names = {0},
179
185
  chunk_oid_fanout = {0},
@@ -181,9 +187,9 @@ int git_midx_parse(
181
187
  chunk_object_offsets = {0},
182
188
  chunk_object_large_offsets = {0};
183
189
 
184
- assert(idx);
190
+ GIT_ASSERT_ARG(idx);
185
191
 
186
- if (size < sizeof(struct git_midx_header) + 20)
192
+ if (size < sizeof(struct git_midx_header) + GIT_OID_RAWSZ)
187
193
  return midx_error("multi-pack index is too short");
188
194
 
189
195
  hdr = ((struct git_midx_header *)data);
@@ -203,21 +209,29 @@ int git_midx_parse(
203
209
  last_chunk_offset =
204
210
  sizeof(struct git_midx_header) +
205
211
  (1 + hdr->chunks) * 12;
206
- trailer_offset = size - 20;
212
+
213
+ checksum_size = GIT_HASH_SHA1_SIZE;
214
+ trailer_offset = size - checksum_size;
215
+
207
216
  if (trailer_offset < last_chunk_offset)
208
217
  return midx_error("wrong index size");
209
- git_oid_cpy(&idx->checksum, (git_oid *)(data + trailer_offset));
218
+ memcpy(idx->checksum, data + trailer_offset, checksum_size);
210
219
 
211
- if (git_hash_buf(&idx_checksum, data, (size_t)trailer_offset) < 0)
220
+ if (git_hash_buf(checksum, data, (size_t)trailer_offset, GIT_HASH_ALGORITHM_SHA1) < 0)
212
221
  return midx_error("could not calculate signature");
213
- if (!git_oid_equal(&idx_checksum, &idx->checksum))
222
+ if (memcmp(checksum, idx->checksum, checksum_size) != 0)
214
223
  return midx_error("index signature mismatch");
215
224
 
216
225
  chunk_hdr = data + sizeof(struct git_midx_header);
217
226
  last_chunk = NULL;
218
227
  for (i = 0; i < hdr->chunks; ++i, chunk_hdr += 12) {
219
- chunk_offset = ((off64_t)ntohl(*((uint32_t *)(chunk_hdr + 4)))) << 32 |
220
- ((off64_t)ntohl(*((uint32_t *)(chunk_hdr + 8))));
228
+ uint32_t chunk_id = ntohl(*((uint32_t *)(chunk_hdr + 0)));
229
+ uint64_t high_offset = ((uint64_t)ntohl(*((uint32_t *)(chunk_hdr + 4)))) & 0xffffffffu;
230
+ uint64_t low_offset = ((uint64_t)ntohl(*((uint32_t *)(chunk_hdr + 8)))) & 0xffffffffu;
231
+
232
+ if (high_offset >= INT32_MAX)
233
+ return midx_error("chunk offset out of range");
234
+ chunk_offset = (off64_t)(high_offset << 32 | low_offset);
221
235
  if (chunk_offset < last_chunk_offset)
222
236
  return midx_error("chunks are non-monotonic");
223
237
  if (chunk_offset >= trailer_offset)
@@ -226,7 +240,7 @@ int git_midx_parse(
226
240
  last_chunk->length = (size_t)(chunk_offset - last_chunk_offset);
227
241
  last_chunk_offset = chunk_offset;
228
242
 
229
- switch (ntohl(*((uint32_t *)(chunk_hdr + 0)))) {
243
+ switch (chunk_id) {
230
244
  case MIDX_PACKFILE_NAMES_ID:
231
245
  chunk_packfile_names.offset = last_chunk_offset;
232
246
  last_chunk = &chunk_packfile_names;
@@ -309,6 +323,10 @@ int git_midx_open(
309
323
  idx = git__calloc(1, sizeof(git_midx_file));
310
324
  GIT_ERROR_CHECK_ALLOC(idx);
311
325
 
326
+ error = git_str_sets(&idx->filename, path);
327
+ if (error < 0)
328
+ return error;
329
+
312
330
  error = git_futils_mmap_ro(&idx->index_map, fd, 0, idx_size);
313
331
  p_close(fd);
314
332
  if (error < 0) {
@@ -325,6 +343,43 @@ int git_midx_open(
325
343
  return 0;
326
344
  }
327
345
 
346
+ bool git_midx_needs_refresh(
347
+ const git_midx_file *idx,
348
+ const char *path)
349
+ {
350
+ git_file fd = -1;
351
+ struct stat st;
352
+ ssize_t bytes_read;
353
+ unsigned char checksum[GIT_HASH_SHA1_SIZE];
354
+ size_t checksum_size;
355
+
356
+ /* TODO: properly open the file without access time using O_NOATIME */
357
+ fd = git_futils_open_ro(path);
358
+ if (fd < 0)
359
+ return true;
360
+
361
+ if (p_fstat(fd, &st) < 0) {
362
+ p_close(fd);
363
+ return true;
364
+ }
365
+
366
+ if (!S_ISREG(st.st_mode) ||
367
+ !git__is_sizet(st.st_size) ||
368
+ (size_t)st.st_size != idx->index_map.len) {
369
+ p_close(fd);
370
+ return true;
371
+ }
372
+
373
+ checksum_size = GIT_HASH_SHA1_SIZE;
374
+ bytes_read = p_pread(fd, checksum, checksum_size, st.st_size - GIT_OID_RAWSZ);
375
+ p_close(fd);
376
+
377
+ if (bytes_read != (ssize_t)checksum_size)
378
+ return true;
379
+
380
+ return (memcmp(checksum, idx->checksum, checksum_size) != 0);
381
+ }
382
+
328
383
  int git_midx_entry_find(
329
384
  git_midx_entry *e,
330
385
  git_midx_file *idx,
@@ -338,12 +393,12 @@ int git_midx_entry_find(
338
393
  const unsigned char *object_offset;
339
394
  off64_t offset;
340
395
 
341
- assert(idx);
396
+ GIT_ASSERT_ARG(idx);
342
397
 
343
398
  hi = ntohl(idx->oid_fanout[(int)short_oid->id[0]]);
344
399
  lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(idx->oid_fanout[(int)short_oid->id[0] - 1]));
345
400
 
346
- pos = git_pack__lookup_sha1(idx->oid_lookup, 20, lo, hi, short_oid->id);
401
+ pos = git_pack__lookup_sha1(idx->oid_lookup, GIT_OID_RAWSZ, lo, hi, short_oid->id);
347
402
 
348
403
  if (pos >= 0) {
349
404
  /* An object matching exactly the oid was found */
@@ -399,13 +454,34 @@ int git_midx_entry_find(
399
454
  return 0;
400
455
  }
401
456
 
402
- void git_midx_close(git_midx_file *idx)
457
+ int git_midx_foreach_entry(
458
+ git_midx_file *idx,
459
+ git_odb_foreach_cb cb,
460
+ void *data)
403
461
  {
404
- assert(idx);
462
+ size_t i;
463
+ int error;
464
+
465
+ GIT_ASSERT_ARG(idx);
466
+
467
+ for (i = 0; i < idx->num_objects; ++i) {
468
+ if ((error = cb(&idx->oid_lookup[i], data)) != 0)
469
+ return git_error_set_after_callback(error);
470
+ }
471
+
472
+ return error;
473
+ }
474
+
475
+ int git_midx_close(git_midx_file *idx)
476
+ {
477
+ GIT_ASSERT_ARG(idx);
405
478
 
406
479
  if (idx->index_map.data)
407
480
  git_futils_mmap_free(&idx->index_map);
481
+
408
482
  git_vector_free(&idx->packfile_names);
483
+
484
+ return 0;
409
485
  }
410
486
 
411
487
  void git_midx_free(git_midx_file *idx)
@@ -413,6 +489,413 @@ void git_midx_free(git_midx_file *idx)
413
489
  if (!idx)
414
490
  return;
415
491
 
492
+ git_str_dispose(&idx->filename);
416
493
  git_midx_close(idx);
417
494
  git__free(idx);
418
495
  }
496
+
497
+ static int packfile__cmp(const void *a_, const void *b_)
498
+ {
499
+ const struct git_pack_file *a = a_;
500
+ const struct git_pack_file *b = b_;
501
+
502
+ return strcmp(a->pack_name, b->pack_name);
503
+ }
504
+
505
+ int git_midx_writer_new(
506
+ git_midx_writer **out,
507
+ const char *pack_dir)
508
+ {
509
+ git_midx_writer *w = git__calloc(1, sizeof(git_midx_writer));
510
+ GIT_ERROR_CHECK_ALLOC(w);
511
+
512
+ if (git_str_sets(&w->pack_dir, pack_dir) < 0) {
513
+ git__free(w);
514
+ return -1;
515
+ }
516
+ git_fs_path_squash_slashes(&w->pack_dir);
517
+
518
+ if (git_vector_init(&w->packs, 0, packfile__cmp) < 0) {
519
+ git_str_dispose(&w->pack_dir);
520
+ git__free(w);
521
+ return -1;
522
+ }
523
+
524
+ *out = w;
525
+ return 0;
526
+ }
527
+
528
+ void git_midx_writer_free(git_midx_writer *w)
529
+ {
530
+ struct git_pack_file *p;
531
+ size_t i;
532
+
533
+ if (!w)
534
+ return;
535
+
536
+ git_vector_foreach (&w->packs, i, p)
537
+ git_mwindow_put_pack(p);
538
+ git_vector_free(&w->packs);
539
+ git_str_dispose(&w->pack_dir);
540
+ git__free(w);
541
+ }
542
+
543
+ int git_midx_writer_add(
544
+ git_midx_writer *w,
545
+ const char *idx_path)
546
+ {
547
+ git_str idx_path_buf = GIT_STR_INIT;
548
+ int error;
549
+ struct git_pack_file *p;
550
+
551
+ error = git_fs_path_prettify(&idx_path_buf, idx_path, git_str_cstr(&w->pack_dir));
552
+ if (error < 0)
553
+ return error;
554
+
555
+ error = git_mwindow_get_pack(&p, git_str_cstr(&idx_path_buf));
556
+ git_str_dispose(&idx_path_buf);
557
+ if (error < 0)
558
+ return error;
559
+
560
+ error = git_vector_insert(&w->packs, p);
561
+ if (error < 0) {
562
+ git_mwindow_put_pack(p);
563
+ return error;
564
+ }
565
+
566
+ return 0;
567
+ }
568
+
569
+ typedef git_array_t(git_midx_entry) object_entry_array_t;
570
+
571
+ struct object_entry_cb_state {
572
+ uint32_t pack_index;
573
+ object_entry_array_t *object_entries_array;
574
+ };
575
+
576
+ static int object_entry__cb(const git_oid *oid, off64_t offset, void *data)
577
+ {
578
+ struct object_entry_cb_state *state = (struct object_entry_cb_state *)data;
579
+
580
+ git_midx_entry *entry = git_array_alloc(*state->object_entries_array);
581
+ GIT_ERROR_CHECK_ALLOC(entry);
582
+
583
+ git_oid_cpy(&entry->sha1, oid);
584
+ entry->offset = offset;
585
+ entry->pack_index = state->pack_index;
586
+
587
+ return 0;
588
+ }
589
+
590
+ static int object_entry__cmp(const void *a_, const void *b_)
591
+ {
592
+ const git_midx_entry *a = (const git_midx_entry *)a_;
593
+ const git_midx_entry *b = (const git_midx_entry *)b_;
594
+
595
+ return git_oid_cmp(&a->sha1, &b->sha1);
596
+ }
597
+
598
+ static int write_offset(off64_t offset, midx_write_cb write_cb, void *cb_data)
599
+ {
600
+ int error;
601
+ uint32_t word;
602
+
603
+ word = htonl((uint32_t)((offset >> 32) & 0xffffffffu));
604
+ error = write_cb((const char *)&word, sizeof(word), cb_data);
605
+ if (error < 0)
606
+ return error;
607
+ word = htonl((uint32_t)((offset >> 0) & 0xffffffffu));
608
+ error = write_cb((const char *)&word, sizeof(word), cb_data);
609
+ if (error < 0)
610
+ return error;
611
+
612
+ return 0;
613
+ }
614
+
615
+ static int write_chunk_header(int chunk_id, off64_t offset, midx_write_cb write_cb, void *cb_data)
616
+ {
617
+ uint32_t word = htonl(chunk_id);
618
+ int error = write_cb((const char *)&word, sizeof(word), cb_data);
619
+ if (error < 0)
620
+ return error;
621
+ return write_offset(offset, write_cb, cb_data);
622
+
623
+ return 0;
624
+ }
625
+
626
+ static int midx_write_buf(const char *buf, size_t size, void *data)
627
+ {
628
+ git_str *b = (git_str *)data;
629
+ return git_str_put(b, buf, size);
630
+ }
631
+
632
+ struct midx_write_hash_context {
633
+ midx_write_cb write_cb;
634
+ void *cb_data;
635
+ git_hash_ctx *ctx;
636
+ };
637
+
638
+ static int midx_write_hash(const char *buf, size_t size, void *data)
639
+ {
640
+ struct midx_write_hash_context *ctx = (struct midx_write_hash_context *)data;
641
+ int error;
642
+
643
+ error = git_hash_update(ctx->ctx, buf, size);
644
+ if (error < 0)
645
+ return error;
646
+
647
+ return ctx->write_cb(buf, size, ctx->cb_data);
648
+ }
649
+
650
+ static int midx_write(
651
+ git_midx_writer *w,
652
+ midx_write_cb write_cb,
653
+ void *cb_data)
654
+ {
655
+ int error = 0;
656
+ size_t i;
657
+ struct git_pack_file *p;
658
+ struct git_midx_header hdr = {0};
659
+ uint32_t oid_fanout_count;
660
+ uint32_t object_large_offsets_count;
661
+ uint32_t oid_fanout[256];
662
+ off64_t offset;
663
+ git_str packfile_names = GIT_STR_INIT,
664
+ oid_lookup = GIT_STR_INIT,
665
+ object_offsets = GIT_STR_INIT,
666
+ object_large_offsets = GIT_STR_INIT;
667
+ unsigned char checksum[GIT_HASH_SHA1_SIZE];
668
+ size_t checksum_size;
669
+ git_midx_entry *entry;
670
+ object_entry_array_t object_entries_array = GIT_ARRAY_INIT;
671
+ git_vector object_entries = GIT_VECTOR_INIT;
672
+ git_hash_ctx ctx;
673
+ struct midx_write_hash_context hash_cb_data = {0};
674
+
675
+ hdr.signature = htonl(MIDX_SIGNATURE);
676
+ hdr.version = MIDX_VERSION;
677
+ hdr.object_id_version = MIDX_OBJECT_ID_VERSION;
678
+ hdr.base_midx_files = 0;
679
+
680
+ hash_cb_data.write_cb = write_cb;
681
+ hash_cb_data.cb_data = cb_data;
682
+ hash_cb_data.ctx = &ctx;
683
+
684
+ checksum_size = GIT_HASH_SHA1_SIZE;
685
+ error = git_hash_ctx_init(&ctx, GIT_HASH_ALGORITHM_SHA1);
686
+ if (error < 0)
687
+ return error;
688
+ cb_data = &hash_cb_data;
689
+ write_cb = midx_write_hash;
690
+
691
+ git_vector_sort(&w->packs);
692
+ git_vector_foreach (&w->packs, i, p) {
693
+ git_str relative_index = GIT_STR_INIT;
694
+ struct object_entry_cb_state state = {0};
695
+ size_t path_len;
696
+
697
+ state.pack_index = (uint32_t)i;
698
+ state.object_entries_array = &object_entries_array;
699
+
700
+ error = git_str_sets(&relative_index, p->pack_name);
701
+ if (error < 0)
702
+ goto cleanup;
703
+ error = git_fs_path_make_relative(&relative_index, git_str_cstr(&w->pack_dir));
704
+ if (error < 0) {
705
+ git_str_dispose(&relative_index);
706
+ goto cleanup;
707
+ }
708
+ path_len = git_str_len(&relative_index);
709
+ if (path_len <= strlen(".pack") || git__suffixcmp(git_str_cstr(&relative_index), ".pack") != 0) {
710
+ git_str_dispose(&relative_index);
711
+ git_error_set(GIT_ERROR_INVALID, "invalid packfile name: '%s'", p->pack_name);
712
+ error = -1;
713
+ goto cleanup;
714
+ }
715
+ path_len -= strlen(".pack");
716
+
717
+ git_str_put(&packfile_names, git_str_cstr(&relative_index), path_len);
718
+ git_str_puts(&packfile_names, ".idx");
719
+ git_str_putc(&packfile_names, '\0');
720
+ git_str_dispose(&relative_index);
721
+
722
+ error = git_pack_foreach_entry_offset(p, object_entry__cb, &state);
723
+ if (error < 0)
724
+ goto cleanup;
725
+ }
726
+
727
+ /* Sort the object entries. */
728
+ error = git_vector_init(&object_entries, git_array_size(object_entries_array), object_entry__cmp);
729
+ if (error < 0)
730
+ goto cleanup;
731
+ git_array_foreach (object_entries_array, i, entry) {
732
+ if ((error = git_vector_set(NULL, &object_entries, i, entry)) < 0)
733
+ goto cleanup;
734
+ }
735
+ git_vector_set_sorted(&object_entries, 0);
736
+ git_vector_sort(&object_entries);
737
+ git_vector_uniq(&object_entries, NULL);
738
+
739
+ /* Pad the packfile names so it is a multiple of four. */
740
+ while (git_str_len(&packfile_names) & 3)
741
+ git_str_putc(&packfile_names, '\0');
742
+
743
+ /* Fill the OID Fanout table. */
744
+ oid_fanout_count = 0;
745
+ for (i = 0; i < 256; i++) {
746
+ while (oid_fanout_count < git_vector_length(&object_entries) &&
747
+ ((const git_midx_entry *)git_vector_get(&object_entries, oid_fanout_count))->sha1.id[0] <= i)
748
+ ++oid_fanout_count;
749
+ oid_fanout[i] = htonl(oid_fanout_count);
750
+ }
751
+
752
+ /* Fill the OID Lookup table. */
753
+ git_vector_foreach (&object_entries, i, entry) {
754
+ error = git_str_put(&oid_lookup, (const char *)&entry->sha1, sizeof(entry->sha1));
755
+ if (error < 0)
756
+ goto cleanup;
757
+ }
758
+
759
+ /* Fill the Object Offsets and Object Large Offsets tables. */
760
+ object_large_offsets_count = 0;
761
+ git_vector_foreach (&object_entries, i, entry) {
762
+ uint32_t word;
763
+
764
+ word = htonl((uint32_t)entry->pack_index);
765
+ error = git_str_put(&object_offsets, (const char *)&word, sizeof(word));
766
+ if (error < 0)
767
+ goto cleanup;
768
+ if (entry->offset >= 0x80000000l) {
769
+ word = htonl(0x80000000u | object_large_offsets_count++);
770
+ if ((error = write_offset(entry->offset, midx_write_buf, &object_large_offsets)) < 0)
771
+ goto cleanup;
772
+ } else {
773
+ word = htonl((uint32_t)entry->offset & 0x7fffffffu);
774
+ }
775
+
776
+ error = git_str_put(&object_offsets, (const char *)&word, sizeof(word));
777
+ if (error < 0)
778
+ goto cleanup;
779
+ }
780
+
781
+ /* Write the header. */
782
+ hdr.packfiles = htonl((uint32_t)git_vector_length(&w->packs));
783
+ hdr.chunks = 4;
784
+ if (git_str_len(&object_large_offsets) > 0)
785
+ hdr.chunks++;
786
+ error = write_cb((const char *)&hdr, sizeof(hdr), cb_data);
787
+ if (error < 0)
788
+ goto cleanup;
789
+
790
+ /* Write the chunk headers. */
791
+ offset = sizeof(hdr) + (hdr.chunks + 1) * 12;
792
+ error = write_chunk_header(MIDX_PACKFILE_NAMES_ID, offset, write_cb, cb_data);
793
+ if (error < 0)
794
+ goto cleanup;
795
+ offset += git_str_len(&packfile_names);
796
+ error = write_chunk_header(MIDX_OID_FANOUT_ID, offset, write_cb, cb_data);
797
+ if (error < 0)
798
+ goto cleanup;
799
+ offset += sizeof(oid_fanout);
800
+ error = write_chunk_header(MIDX_OID_LOOKUP_ID, offset, write_cb, cb_data);
801
+ if (error < 0)
802
+ goto cleanup;
803
+ offset += git_str_len(&oid_lookup);
804
+ error = write_chunk_header(MIDX_OBJECT_OFFSETS_ID, offset, write_cb, cb_data);
805
+ if (error < 0)
806
+ goto cleanup;
807
+ offset += git_str_len(&object_offsets);
808
+ if (git_str_len(&object_large_offsets) > 0) {
809
+ error = write_chunk_header(MIDX_OBJECT_LARGE_OFFSETS_ID, offset, write_cb, cb_data);
810
+ if (error < 0)
811
+ goto cleanup;
812
+ offset += git_str_len(&object_large_offsets);
813
+ }
814
+ error = write_chunk_header(0, offset, write_cb, cb_data);
815
+ if (error < 0)
816
+ goto cleanup;
817
+
818
+ /* Write all the chunks. */
819
+ error = write_cb(git_str_cstr(&packfile_names), git_str_len(&packfile_names), cb_data);
820
+ if (error < 0)
821
+ goto cleanup;
822
+ error = write_cb((const char *)oid_fanout, sizeof(oid_fanout), cb_data);
823
+ if (error < 0)
824
+ goto cleanup;
825
+ error = write_cb(git_str_cstr(&oid_lookup), git_str_len(&oid_lookup), cb_data);
826
+ if (error < 0)
827
+ goto cleanup;
828
+ error = write_cb(git_str_cstr(&object_offsets), git_str_len(&object_offsets), cb_data);
829
+ if (error < 0)
830
+ goto cleanup;
831
+ error = write_cb(git_str_cstr(&object_large_offsets), git_str_len(&object_large_offsets), cb_data);
832
+ if (error < 0)
833
+ goto cleanup;
834
+
835
+ /* Finalize the checksum and write the trailer. */
836
+ error = git_hash_final(checksum, &ctx);
837
+ if (error < 0)
838
+ goto cleanup;
839
+ error = write_cb((char *)checksum, checksum_size, cb_data);
840
+ if (error < 0)
841
+ goto cleanup;
842
+
843
+ cleanup:
844
+ git_array_clear(object_entries_array);
845
+ git_vector_free(&object_entries);
846
+ git_str_dispose(&packfile_names);
847
+ git_str_dispose(&oid_lookup);
848
+ git_str_dispose(&object_offsets);
849
+ git_str_dispose(&object_large_offsets);
850
+ git_hash_ctx_cleanup(&ctx);
851
+ return error;
852
+ }
853
+
854
+ static int midx_write_filebuf(const char *buf, size_t size, void *data)
855
+ {
856
+ git_filebuf *f = (git_filebuf *)data;
857
+ return git_filebuf_write(f, buf, size);
858
+ }
859
+
860
+ int git_midx_writer_commit(
861
+ git_midx_writer *w)
862
+ {
863
+ int error;
864
+ int filebuf_flags = GIT_FILEBUF_DO_NOT_BUFFER;
865
+ git_str midx_path = GIT_STR_INIT;
866
+ git_filebuf output = GIT_FILEBUF_INIT;
867
+
868
+ error = git_str_joinpath(&midx_path, git_str_cstr(&w->pack_dir), "multi-pack-index");
869
+ if (error < 0)
870
+ return error;
871
+
872
+ if (git_repository__fsync_gitdir)
873
+ filebuf_flags |= GIT_FILEBUF_FSYNC;
874
+ error = git_filebuf_open(&output, git_str_cstr(&midx_path), filebuf_flags, 0644);
875
+ git_str_dispose(&midx_path);
876
+ if (error < 0)
877
+ return error;
878
+
879
+ error = midx_write(w, midx_write_filebuf, &output);
880
+ if (error < 0) {
881
+ git_filebuf_cleanup(&output);
882
+ return error;
883
+ }
884
+
885
+ return git_filebuf_commit(&output);
886
+ }
887
+
888
+ int git_midx_writer_dump(
889
+ git_buf *midx,
890
+ git_midx_writer *w)
891
+ {
892
+ git_str str = GIT_STR_INIT;
893
+ int error;
894
+
895
+ if ((error = git_buf_tostr(&str, midx)) < 0 ||
896
+ (error = midx_write(w, midx_write_buf, &str)) == 0)
897
+ error = git_buf_fromstr(midx, &str);
898
+
899
+ git_str_dispose(&str);
900
+ return error;
901
+ }
@@ -12,8 +12,11 @@
12
12
 
13
13
  #include <ctype.h>
14
14
 
15
+ #include "git2/sys/midx.h"
16
+
15
17
  #include "map.h"
16
18
  #include "mwindow.h"
19
+ #include "odb.h"
17
20
 
18
21
  /*
19
22
  * A multi-pack-index file.
@@ -48,7 +51,10 @@ typedef struct git_midx_file {
48
51
  size_t num_object_large_offsets;
49
52
 
50
53
  /* The trailer of the file. Contains the SHA1-checksum of the whole file. */
51
- git_oid checksum;
54
+ unsigned char checksum[GIT_HASH_SHA1_SIZE];
55
+
56
+ /* something like ".git/objects/pack/multi-pack-index". */
57
+ git_str filename;
52
58
  } git_midx_file;
53
59
 
54
60
  /*
@@ -63,15 +69,36 @@ typedef struct git_midx_entry {
63
69
  git_oid sha1;
64
70
  } git_midx_entry;
65
71
 
72
+ /*
73
+ * A writer for `multi-pack-index` files.
74
+ */
75
+ struct git_midx_writer {
76
+ /*
77
+ * The path of the directory where the .pack/.idx files are stored. The
78
+ * `multi-pack-index` file will be written to the same directory.
79
+ */
80
+ git_str pack_dir;
81
+
82
+ /* The list of `git_pack_file`s. */
83
+ git_vector packs;
84
+ };
85
+
66
86
  int git_midx_open(
67
87
  git_midx_file **idx_out,
68
88
  const char *path);
89
+ bool git_midx_needs_refresh(
90
+ const git_midx_file *idx,
91
+ const char *path);
69
92
  int git_midx_entry_find(
70
93
  git_midx_entry *e,
71
94
  git_midx_file *idx,
72
95
  const git_oid *short_oid,
73
96
  size_t len);
74
- void git_midx_close(git_midx_file *idx);
97
+ int git_midx_foreach_entry(
98
+ git_midx_file *idx,
99
+ git_odb_foreach_cb cb,
100
+ void *data);
101
+ int git_midx_close(git_midx_file *idx);
75
102
  void git_midx_free(git_midx_file *idx);
76
103
 
77
104
  /* This is exposed for use in the fuzzers. */