rugged 1.3.1 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (656) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -2
  3. data/ext/rugged/extconf.rb +6 -3
  4. data/ext/rugged/rugged.c +16 -0
  5. data/ext/rugged/rugged.h +4 -0
  6. data/ext/rugged/rugged_allocator.c +0 -54
  7. data/ext/rugged/rugged_blame.c +2 -0
  8. data/ext/rugged/rugged_blob.c +3 -0
  9. data/ext/rugged/rugged_commit.c +1 -0
  10. data/ext/rugged/rugged_config.c +9 -2
  11. data/ext/rugged/rugged_diff.c +1 -0
  12. data/ext/rugged/rugged_index.c +2 -0
  13. data/ext/rugged/rugged_patch.c +1 -0
  14. data/ext/rugged/rugged_rebase.c +1 -0
  15. data/ext/rugged/rugged_reference.c +1 -0
  16. data/ext/rugged/rugged_remote.c +28 -10
  17. data/ext/rugged/rugged_repo.c +7 -9
  18. data/ext/rugged/rugged_revwalk.c +5 -1
  19. data/ext/rugged/rugged_settings.c +5 -0
  20. data/ext/rugged/rugged_submodule.c +1 -0
  21. data/ext/rugged/rugged_tag.c +1 -0
  22. data/ext/rugged/rugged_tree.c +4 -0
  23. data/lib/rugged/index.rb +1 -1
  24. data/lib/rugged/tree.rb +5 -1
  25. data/lib/rugged/version.rb +1 -1
  26. data/vendor/libgit2/AUTHORS +1 -0
  27. data/vendor/libgit2/CMakeLists.txt +141 -289
  28. data/vendor/libgit2/COPYING +301 -20
  29. data/vendor/libgit2/cmake/AddCFlagIfSupported.cmake +21 -21
  30. data/vendor/libgit2/cmake/AddClarTest.cmake +7 -0
  31. data/vendor/libgit2/cmake/CheckPrototypeDefinitionSafe.cmake +16 -0
  32. data/vendor/libgit2/cmake/DefaultCFlags.cmake +154 -0
  33. data/vendor/libgit2/cmake/EnableWarnings.cmake +13 -13
  34. data/vendor/libgit2/cmake/ExperimentalFeatures.cmake +23 -0
  35. data/vendor/libgit2/cmake/FindCoreFoundation.cmake +13 -13
  36. data/vendor/libgit2/cmake/FindGSSAPI.cmake +171 -287
  37. data/vendor/libgit2/cmake/FindGSSFramework.cmake +13 -13
  38. data/vendor/libgit2/cmake/FindHTTP_Parser.cmake +17 -17
  39. data/vendor/libgit2/cmake/FindIntlIconv.cmake +51 -0
  40. data/vendor/libgit2/cmake/FindLLHTTP.cmake +39 -0
  41. data/vendor/libgit2/cmake/FindLibSSH2.cmake +5 -5
  42. data/vendor/libgit2/cmake/FindPCRE.cmake +12 -13
  43. data/vendor/libgit2/cmake/FindPCRE2.cmake +12 -12
  44. data/vendor/libgit2/cmake/FindPkgLibraries.cmake +19 -19
  45. data/vendor/libgit2/cmake/FindSecurity.cmake +14 -14
  46. data/vendor/libgit2/cmake/FindStatNsec.cmake +12 -18
  47. data/vendor/libgit2/cmake/Findfutimens.cmake +8 -8
  48. data/vendor/libgit2/cmake/FindmbedTLS.cmake +63 -70
  49. data/vendor/libgit2/cmake/IdeSplitSources.cmake +18 -18
  50. data/vendor/libgit2/cmake/PkgBuildConfig.cmake +60 -60
  51. data/vendor/libgit2/cmake/SanitizeBool.cmake +20 -20
  52. data/vendor/libgit2/cmake/SelectGSSAPI.cmake +37 -37
  53. data/vendor/libgit2/cmake/SelectHTTPParser.cmake +34 -0
  54. data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +129 -101
  55. data/vendor/libgit2/cmake/SelectHashes.cmake +113 -54
  56. data/vendor/libgit2/cmake/SelectRegex.cmake +56 -0
  57. data/vendor/libgit2/cmake/SelectSSH.cmake +46 -0
  58. data/vendor/libgit2/cmake/SelectXdiff.cmake +9 -0
  59. data/vendor/libgit2/cmake/SelectZlib.cmake +38 -0
  60. data/vendor/libgit2/deps/chromium-zlib/CMakeLists.txt +6 -6
  61. data/vendor/libgit2/deps/llhttp/CMakeLists.txt +8 -0
  62. data/vendor/libgit2/deps/llhttp/LICENSE-MIT +22 -0
  63. data/vendor/libgit2/deps/llhttp/api.c +510 -0
  64. data/vendor/libgit2/deps/llhttp/http.c +170 -0
  65. data/vendor/libgit2/deps/llhttp/llhttp.c +10168 -0
  66. data/vendor/libgit2/deps/llhttp/llhttp.h +897 -0
  67. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +33 -31
  68. data/vendor/libgit2/deps/ntlmclient/crypt_builtin_md4.c +311 -0
  69. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.c +2 -1
  70. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.c +0 -20
  71. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +7 -5
  72. data/vendor/libgit2/deps/ntlmclient/ntlm.c +25 -25
  73. data/vendor/libgit2/deps/ntlmclient/ntlm.h +4 -4
  74. data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +2 -2
  75. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.c +5 -4
  76. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.c +2 -1
  77. data/vendor/libgit2/deps/ntlmclient/utf8.h +1176 -721
  78. data/vendor/libgit2/deps/ntlmclient/util.h +11 -0
  79. data/vendor/libgit2/deps/pcre/CMakeLists.txt +89 -88
  80. data/vendor/libgit2/deps/pcre/LICENCE +5 -5
  81. data/vendor/libgit2/deps/pcre/pcre.h +2 -2
  82. data/vendor/libgit2/deps/pcre/pcre_compile.c +6 -3
  83. data/vendor/libgit2/deps/pcre/pcre_exec.c +2 -2
  84. data/vendor/libgit2/deps/winhttp/CMakeLists.txt +14 -16
  85. data/vendor/libgit2/deps/xdiff/CMakeLists.txt +28 -0
  86. data/vendor/libgit2/deps/xdiff/git-xdiff.h +56 -0
  87. data/vendor/libgit2/{src → deps}/xdiff/xdiff.h +15 -15
  88. data/vendor/libgit2/{src → deps}/xdiff/xdiffi.c +152 -125
  89. data/vendor/libgit2/{src → deps}/xdiff/xdiffi.h +2 -4
  90. data/vendor/libgit2/{src → deps}/xdiff/xemit.c +26 -10
  91. data/vendor/libgit2/{src → deps}/xdiff/xhistogram.c +92 -94
  92. data/vendor/libgit2/{src → deps}/xdiff/xinclude.h +1 -12
  93. data/vendor/libgit2/{src → deps}/xdiff/xmacros.h +18 -1
  94. data/vendor/libgit2/{src → deps}/xdiff/xmerge.c +126 -137
  95. data/vendor/libgit2/{src → deps}/xdiff/xpatience.c +26 -46
  96. data/vendor/libgit2/{src → deps}/xdiff/xprepare.c +24 -46
  97. data/vendor/libgit2/{src → deps}/xdiff/xutils.c +36 -8
  98. data/vendor/libgit2/{src → deps}/xdiff/xutils.h +2 -1
  99. data/vendor/libgit2/deps/zlib/CMakeLists.txt +6 -1
  100. data/vendor/libgit2/deps/zlib/LICENSE +22 -0
  101. data/vendor/libgit2/deps/zlib/adler32.c +7 -22
  102. data/vendor/libgit2/deps/zlib/crc32.c +931 -317
  103. data/vendor/libgit2/deps/zlib/crc32.h +9441 -436
  104. data/vendor/libgit2/deps/zlib/deflate.c +428 -453
  105. data/vendor/libgit2/deps/zlib/deflate.h +51 -23
  106. data/vendor/libgit2/deps/zlib/gzguts.h +15 -19
  107. data/vendor/libgit2/deps/zlib/infback.c +19 -31
  108. data/vendor/libgit2/deps/zlib/inffast.c +15 -18
  109. data/vendor/libgit2/deps/zlib/inffast.h +1 -1
  110. data/vendor/libgit2/deps/zlib/inflate.c +75 -110
  111. data/vendor/libgit2/deps/zlib/inflate.h +3 -2
  112. data/vendor/libgit2/deps/zlib/inftrees.c +6 -11
  113. data/vendor/libgit2/deps/zlib/inftrees.h +6 -6
  114. data/vendor/libgit2/deps/zlib/trees.c +294 -380
  115. data/vendor/libgit2/deps/zlib/zconf.h +23 -14
  116. data/vendor/libgit2/deps/zlib/zlib.h +310 -284
  117. data/vendor/libgit2/deps/zlib/zutil.c +20 -46
  118. data/vendor/libgit2/deps/zlib/zutil.h +24 -41
  119. data/vendor/libgit2/include/git2/annotated_commit.h +12 -5
  120. data/vendor/libgit2/include/git2/apply.h +43 -8
  121. data/vendor/libgit2/include/git2/attr.h +28 -6
  122. data/vendor/libgit2/include/git2/blame.h +137 -29
  123. data/vendor/libgit2/include/git2/blob.h +85 -29
  124. data/vendor/libgit2/include/git2/branch.h +25 -16
  125. data/vendor/libgit2/include/git2/buffer.h +24 -82
  126. data/vendor/libgit2/include/git2/cert.h +4 -3
  127. data/vendor/libgit2/include/git2/checkout.h +88 -34
  128. data/vendor/libgit2/include/git2/cherrypick.h +10 -3
  129. data/vendor/libgit2/include/git2/clone.h +28 -12
  130. data/vendor/libgit2/include/git2/commit.h +134 -3
  131. data/vendor/libgit2/include/git2/common.h +172 -59
  132. data/vendor/libgit2/include/git2/config.h +118 -32
  133. data/vendor/libgit2/include/git2/credential.h +32 -3
  134. data/vendor/libgit2/include/git2/credential_helpers.h +2 -0
  135. data/vendor/libgit2/include/git2/deprecated.h +141 -3
  136. data/vendor/libgit2/include/git2/describe.h +20 -3
  137. data/vendor/libgit2/include/git2/diff.h +95 -19
  138. data/vendor/libgit2/include/git2/email.h +10 -30
  139. data/vendor/libgit2/include/git2/errors.h +51 -61
  140. data/vendor/libgit2/include/git2/experimental.h +20 -0
  141. data/vendor/libgit2/include/git2/filter.h +21 -9
  142. data/vendor/libgit2/include/git2/global.h +8 -1
  143. data/vendor/libgit2/include/git2/graph.h +4 -2
  144. data/vendor/libgit2/include/git2/ignore.h +11 -1
  145. data/vendor/libgit2/include/git2/index.h +111 -11
  146. data/vendor/libgit2/include/git2/indexer.h +67 -2
  147. data/vendor/libgit2/include/git2/mailmap.h +7 -1
  148. data/vendor/libgit2/include/git2/merge.h +70 -5
  149. data/vendor/libgit2/include/git2/message.h +4 -2
  150. data/vendor/libgit2/include/git2/net.h +3 -1
  151. data/vendor/libgit2/include/git2/notes.h +9 -6
  152. data/vendor/libgit2/include/git2/object.h +57 -7
  153. data/vendor/libgit2/include/git2/odb.h +156 -33
  154. data/vendor/libgit2/include/git2/odb_backend.h +132 -16
  155. data/vendor/libgit2/include/git2/oid.h +116 -17
  156. data/vendor/libgit2/include/git2/oidarray.h +7 -1
  157. data/vendor/libgit2/include/git2/pack.h +37 -9
  158. data/vendor/libgit2/include/git2/patch.h +10 -3
  159. data/vendor/libgit2/include/git2/pathspec.h +10 -1
  160. data/vendor/libgit2/include/git2/proxy.h +11 -1
  161. data/vendor/libgit2/include/git2/rebase.h +18 -7
  162. data/vendor/libgit2/include/git2/refdb.h +5 -2
  163. data/vendor/libgit2/include/git2/reflog.h +4 -3
  164. data/vendor/libgit2/include/git2/refs.h +11 -8
  165. data/vendor/libgit2/include/git2/refspec.h +14 -4
  166. data/vendor/libgit2/include/git2/remote.h +295 -54
  167. data/vendor/libgit2/include/git2/repository.h +95 -25
  168. data/vendor/libgit2/include/git2/reset.h +18 -5
  169. data/vendor/libgit2/include/git2/revert.h +9 -4
  170. data/vendor/libgit2/include/git2/revparse.h +4 -4
  171. data/vendor/libgit2/include/git2/revwalk.h +7 -3
  172. data/vendor/libgit2/include/git2/signature.h +47 -2
  173. data/vendor/libgit2/include/git2/stash.h +78 -10
  174. data/vendor/libgit2/include/git2/status.h +24 -11
  175. data/vendor/libgit2/include/git2/stdint.h +87 -85
  176. data/vendor/libgit2/include/git2/strarray.h +2 -16
  177. data/vendor/libgit2/include/git2/submodule.h +27 -11
  178. data/vendor/libgit2/include/git2/sys/alloc.h +12 -34
  179. data/vendor/libgit2/include/git2/sys/commit.h +77 -3
  180. data/vendor/libgit2/include/git2/sys/commit_graph.h +110 -59
  181. data/vendor/libgit2/include/git2/sys/config.h +80 -4
  182. data/vendor/libgit2/include/git2/sys/credential.h +4 -3
  183. data/vendor/libgit2/include/git2/sys/diff.h +21 -1
  184. data/vendor/libgit2/include/git2/sys/email.h +7 -0
  185. data/vendor/libgit2/include/git2/sys/errors.h +76 -0
  186. data/vendor/libgit2/include/git2/sys/filter.h +66 -3
  187. data/vendor/libgit2/include/git2/sys/hashsig.h +11 -0
  188. data/vendor/libgit2/include/git2/sys/index.h +3 -2
  189. data/vendor/libgit2/include/git2/sys/mempack.h +32 -2
  190. data/vendor/libgit2/include/git2/sys/merge.h +55 -7
  191. data/vendor/libgit2/include/git2/sys/midx.h +47 -4
  192. data/vendor/libgit2/include/git2/sys/odb_backend.h +10 -9
  193. data/vendor/libgit2/include/git2/sys/openssl.h +8 -1
  194. data/vendor/libgit2/include/git2/sys/path.h +12 -1
  195. data/vendor/libgit2/include/git2/sys/refdb_backend.h +40 -36
  196. data/vendor/libgit2/include/git2/sys/refs.h +3 -2
  197. data/vendor/libgit2/include/git2/sys/remote.h +53 -0
  198. data/vendor/libgit2/include/git2/sys/repository.h +63 -3
  199. data/vendor/libgit2/include/git2/sys/stream.h +26 -3
  200. data/vendor/libgit2/include/git2/sys/transport.h +87 -41
  201. data/vendor/libgit2/include/git2/tag.h +4 -1
  202. data/vendor/libgit2/include/git2/trace.h +9 -3
  203. data/vendor/libgit2/include/git2/transaction.h +3 -2
  204. data/vendor/libgit2/include/git2/transport.h +11 -3
  205. data/vendor/libgit2/include/git2/tree.h +20 -8
  206. data/vendor/libgit2/include/git2/types.h +26 -10
  207. data/vendor/libgit2/include/git2/version.h +63 -6
  208. data/vendor/libgit2/include/git2/worktree.h +30 -8
  209. data/vendor/libgit2/include/git2.h +1 -0
  210. data/vendor/libgit2/src/CMakeLists.txt +203 -420
  211. data/vendor/libgit2/src/README.md +12 -0
  212. data/vendor/libgit2/src/cli/CMakeLists.txt +56 -0
  213. data/vendor/libgit2/src/cli/README.md +26 -0
  214. data/vendor/libgit2/src/{branch.h → cli/cmd.c} +10 -8
  215. data/vendor/libgit2/src/cli/cmd.h +37 -0
  216. data/vendor/libgit2/src/cli/cmd_blame.c +287 -0
  217. data/vendor/libgit2/src/cli/cmd_cat_file.c +202 -0
  218. data/vendor/libgit2/src/cli/cmd_clone.c +190 -0
  219. data/vendor/libgit2/src/cli/cmd_config.c +241 -0
  220. data/vendor/libgit2/src/cli/cmd_hash_object.c +152 -0
  221. data/vendor/libgit2/src/cli/cmd_help.c +85 -0
  222. data/vendor/libgit2/src/cli/cmd_index_pack.c +114 -0
  223. data/vendor/libgit2/src/cli/cmd_init.c +102 -0
  224. data/vendor/libgit2/src/cli/common.c +168 -0
  225. data/vendor/libgit2/src/cli/common.h +63 -0
  226. data/vendor/libgit2/src/cli/error.h +51 -0
  227. data/vendor/libgit2/src/cli/main.c +134 -0
  228. data/vendor/libgit2/src/cli/opt.c +695 -0
  229. data/vendor/libgit2/src/cli/opt.h +367 -0
  230. data/vendor/libgit2/src/cli/opt_usage.c +263 -0
  231. data/vendor/libgit2/src/cli/opt_usage.h +40 -0
  232. data/vendor/libgit2/src/cli/progress.c +395 -0
  233. data/vendor/libgit2/src/cli/progress.h +129 -0
  234. data/vendor/libgit2/src/cli/sighandler.h +20 -0
  235. data/vendor/libgit2/src/cli/unix/sighandler.c +37 -0
  236. data/vendor/libgit2/src/cli/win32/precompiled.h +3 -0
  237. data/vendor/libgit2/src/cli/win32/sighandler.c +37 -0
  238. data/vendor/libgit2/src/libgit2/CMakeLists.txt +140 -0
  239. data/vendor/libgit2/src/{annotated_commit.c → libgit2/annotated_commit.c} +2 -2
  240. data/vendor/libgit2/src/{annotated_commit.h → libgit2/annotated_commit.h} +2 -2
  241. data/vendor/libgit2/src/{apply.c → libgit2/apply.c} +32 -34
  242. data/vendor/libgit2/src/{apply.h → libgit2/apply.h} +2 -2
  243. data/vendor/libgit2/src/{attr.c → libgit2/attr.c} +48 -31
  244. data/vendor/libgit2/src/{attr_file.c → libgit2/attr_file.c} +25 -20
  245. data/vendor/libgit2/src/{attr_file.h → libgit2/attr_file.h} +6 -4
  246. data/vendor/libgit2/src/{attrcache.c → libgit2/attrcache.c} +87 -46
  247. data/vendor/libgit2/src/{attrcache.h → libgit2/attrcache.h} +5 -9
  248. data/vendor/libgit2/src/{blame.c → libgit2/blame.c} +152 -57
  249. data/vendor/libgit2/src/{blame.h → libgit2/blame.h} +1 -0
  250. data/vendor/libgit2/src/{blame_git.c → libgit2/blame_git.c} +1 -2
  251. data/vendor/libgit2/src/{blob.c → libgit2/blob.c} +38 -29
  252. data/vendor/libgit2/src/{blob.h → libgit2/blob.h} +3 -3
  253. data/vendor/libgit2/src/{branch.c → libgit2/branch.c} +164 -118
  254. data/vendor/libgit2/src/libgit2/branch.h +31 -0
  255. data/vendor/libgit2/src/libgit2/buf.c +126 -0
  256. data/vendor/libgit2/src/libgit2/buf.h +50 -0
  257. data/vendor/libgit2/src/{cache.c → libgit2/cache.c} +22 -17
  258. data/vendor/libgit2/src/{cache.h → libgit2/cache.h} +7 -9
  259. data/vendor/libgit2/src/{checkout.c → libgit2/checkout.c} +107 -91
  260. data/vendor/libgit2/src/{checkout.h → libgit2/checkout.h} +0 -2
  261. data/vendor/libgit2/src/{cherrypick.c → libgit2/cherrypick.c} +14 -15
  262. data/vendor/libgit2/src/{clone.c → libgit2/clone.c} +254 -203
  263. data/vendor/libgit2/src/{clone.h → libgit2/clone.h} +4 -1
  264. data/vendor/libgit2/src/{commit.c → libgit2/commit.c} +296 -77
  265. data/vendor/libgit2/src/libgit2/commit.h +87 -0
  266. data/vendor/libgit2/src/{commit_graph.c → libgit2/commit_graph.c} +246 -135
  267. data/vendor/libgit2/src/{commit_graph.h → libgit2/commit_graph.h} +33 -8
  268. data/vendor/libgit2/src/{commit_list.c → libgit2/commit_list.c} +17 -7
  269. data/vendor/libgit2/src/{commit_list.h → libgit2/commit_list.h} +1 -0
  270. data/vendor/libgit2/src/libgit2/common.h +55 -0
  271. data/vendor/libgit2/src/{config.c → libgit2/config.c} +490 -360
  272. data/vendor/libgit2/src/libgit2/config.cmake.in +3 -0
  273. data/vendor/libgit2/src/{config.h → libgit2/config.h} +24 -6
  274. data/vendor/libgit2/src/{config_backend.h → libgit2/config_backend.h} +8 -10
  275. data/vendor/libgit2/src/{config_cache.c → libgit2/config_cache.c} +4 -5
  276. data/vendor/libgit2/src/{config_file.c → libgit2/config_file.c} +212 -183
  277. data/vendor/libgit2/src/libgit2/config_list.c +285 -0
  278. data/vendor/libgit2/src/libgit2/config_list.h +32 -0
  279. data/vendor/libgit2/src/libgit2/config_mem.c +374 -0
  280. data/vendor/libgit2/src/{config_parse.c → libgit2/config_parse.c} +37 -32
  281. data/vendor/libgit2/src/{config_snapshot.c → libgit2/config_snapshot.c} +24 -31
  282. data/vendor/libgit2/src/{crlf.c → libgit2/crlf.c} +24 -21
  283. data/vendor/libgit2/src/{describe.c → libgit2/describe.c} +62 -51
  284. data/vendor/libgit2/src/{diff.c → libgit2/diff.c} +44 -14
  285. data/vendor/libgit2/src/{diff.h → libgit2/diff.h} +8 -10
  286. data/vendor/libgit2/src/{diff_driver.c → libgit2/diff_driver.c} +46 -55
  287. data/vendor/libgit2/src/{diff_driver.h → libgit2/diff_driver.h} +5 -5
  288. data/vendor/libgit2/src/{diff_file.c → libgit2/diff_file.c} +45 -27
  289. data/vendor/libgit2/src/{diff_generate.c → libgit2/diff_generate.c} +70 -20
  290. data/vendor/libgit2/src/{diff_generate.h → libgit2/diff_generate.h} +5 -3
  291. data/vendor/libgit2/src/{diff_parse.c → libgit2/diff_parse.c} +22 -6
  292. data/vendor/libgit2/src/{diff_print.c → libgit2/diff_print.c} +192 -105
  293. data/vendor/libgit2/src/{diff_stats.c → libgit2/diff_stats.c} +40 -29
  294. data/vendor/libgit2/src/libgit2/diff_stats.h +18 -0
  295. data/vendor/libgit2/src/{diff_tform.c → libgit2/diff_tform.c} +49 -16
  296. data/vendor/libgit2/src/{diff_xdiff.c → libgit2/diff_xdiff.c} +4 -8
  297. data/vendor/libgit2/src/{diff_xdiff.h → libgit2/diff_xdiff.h} +1 -1
  298. data/vendor/libgit2/src/{email.c → libgit2/email.c} +58 -40
  299. data/vendor/libgit2/src/{email.h → libgit2/email.h} +1 -1
  300. data/vendor/libgit2/src/{transports/ssh.h → libgit2/experimental.h.in} +3 -4
  301. data/vendor/libgit2/src/{fetch.c → libgit2/fetch.c} +105 -30
  302. data/vendor/libgit2/src/{fetch.h → libgit2/fetch.h} +1 -3
  303. data/vendor/libgit2/src/{fetchhead.c → libgit2/fetchhead.c} +30 -28
  304. data/vendor/libgit2/src/{filter.c → libgit2/filter.c} +132 -58
  305. data/vendor/libgit2/src/{filter.h → libgit2/filter.h} +26 -5
  306. data/vendor/libgit2/src/{win32 → libgit2}/git2.rc +3 -3
  307. data/vendor/libgit2/src/libgit2/grafts.c +270 -0
  308. data/vendor/libgit2/src/libgit2/grafts.h +35 -0
  309. data/vendor/libgit2/src/{graph.c → libgit2/graph.c} +1 -1
  310. data/vendor/libgit2/src/libgit2/hashmap_oid.h +30 -0
  311. data/vendor/libgit2/src/{ident.c → libgit2/ident.c} +20 -20
  312. data/vendor/libgit2/src/{ignore.c → libgit2/ignore.c} +44 -39
  313. data/vendor/libgit2/src/{ignore.h → libgit2/ignore.h} +2 -2
  314. data/vendor/libgit2/src/{index.c → libgit2/index.c} +460 -276
  315. data/vendor/libgit2/src/{index.h → libgit2/index.h} +21 -5
  316. data/vendor/libgit2/src/libgit2/index_map.c +95 -0
  317. data/vendor/libgit2/src/libgit2/index_map.h +28 -0
  318. data/vendor/libgit2/src/{indexer.c → libgit2/indexer.c} +208 -124
  319. data/vendor/libgit2/src/{iterator.c → libgit2/iterator.c} +102 -71
  320. data/vendor/libgit2/src/{iterator.h → libgit2/iterator.h} +8 -5
  321. data/vendor/libgit2/src/libgit2/libgit2.c +268 -0
  322. data/vendor/libgit2/src/{mailmap.c → libgit2/mailmap.c} +39 -37
  323. data/vendor/libgit2/src/{merge.c → libgit2/merge.c} +83 -73
  324. data/vendor/libgit2/src/{merge.h → libgit2/merge.h} +1 -14
  325. data/vendor/libgit2/src/{merge_driver.c → libgit2/merge_driver.c} +4 -4
  326. data/vendor/libgit2/src/{merge_file.c → libgit2/merge_file.c} +13 -5
  327. data/vendor/libgit2/src/{message.c → libgit2/message.c} +21 -10
  328. data/vendor/libgit2/src/{midx.c → libgit2/midx.c} +174 -112
  329. data/vendor/libgit2/src/{midx.h → libgit2/midx.h} +17 -6
  330. data/vendor/libgit2/src/{mwindow.c → libgit2/mwindow.c} +53 -57
  331. data/vendor/libgit2/src/{mwindow.h → libgit2/mwindow.h} +9 -2
  332. data/vendor/libgit2/src/{notes.c → libgit2/notes.c} +29 -37
  333. data/vendor/libgit2/src/{object.c → libgit2/object.c} +166 -35
  334. data/vendor/libgit2/src/{object.h → libgit2/object.h} +17 -2
  335. data/vendor/libgit2/src/{odb.c → libgit2/odb.c} +261 -88
  336. data/vendor/libgit2/src/{odb.h → libgit2/odb.h} +44 -5
  337. data/vendor/libgit2/src/{odb_loose.c → libgit2/odb_loose.c} +192 -134
  338. data/vendor/libgit2/src/{odb_mempack.c → libgit2/odb_mempack.c} +67 -22
  339. data/vendor/libgit2/src/{odb_pack.c → libgit2/odb_pack.c} +162 -89
  340. data/vendor/libgit2/src/{oid.c → libgit2/oid.c} +171 -92
  341. data/vendor/libgit2/src/libgit2/oid.h +284 -0
  342. data/vendor/libgit2/src/libgit2/oidarray.c +89 -0
  343. data/vendor/libgit2/src/{oidarray.h → libgit2/oidarray.h} +5 -1
  344. data/vendor/libgit2/src/{pack-objects.c → libgit2/pack-objects.c} +126 -66
  345. data/vendor/libgit2/src/{pack-objects.h → libgit2/pack-objects.h} +28 -12
  346. data/vendor/libgit2/src/{pack.c → libgit2/pack.c} +146 -111
  347. data/vendor/libgit2/src/{pack.h → libgit2/pack.h} +45 -25
  348. data/vendor/libgit2/src/{parse.c → libgit2/parse.c} +8 -4
  349. data/vendor/libgit2/src/{parse.h → libgit2/parse.h} +1 -1
  350. data/vendor/libgit2/src/{patch.c → libgit2/patch.c} +3 -3
  351. data/vendor/libgit2/src/{patch.h → libgit2/patch.h} +8 -1
  352. data/vendor/libgit2/src/{patch_generate.c → libgit2/patch_generate.c} +51 -16
  353. data/vendor/libgit2/src/{patch_generate.h → libgit2/patch_generate.h} +5 -5
  354. data/vendor/libgit2/src/{patch_parse.c → libgit2/patch_parse.c} +42 -34
  355. data/vendor/libgit2/src/libgit2/path.c +375 -0
  356. data/vendor/libgit2/src/libgit2/path.h +68 -0
  357. data/vendor/libgit2/src/{pathspec.c → libgit2/pathspec.c} +7 -7
  358. data/vendor/libgit2/src/{pathspec.h → libgit2/pathspec.h} +2 -2
  359. data/vendor/libgit2/src/{proxy.c → libgit2/proxy.c} +4 -1
  360. data/vendor/libgit2/src/{proxy.h → libgit2/proxy.h} +1 -1
  361. data/vendor/libgit2/src/{push.c → libgit2/push.c} +116 -60
  362. data/vendor/libgit2/src/{push.h → libgit2/push.h} +5 -16
  363. data/vendor/libgit2/src/{reader.c → libgit2/reader.c} +9 -9
  364. data/vendor/libgit2/src/{reader.h → libgit2/reader.h} +2 -2
  365. data/vendor/libgit2/src/{rebase.c → libgit2/rebase.c} +147 -147
  366. data/vendor/libgit2/src/{refdb_fs.c → libgit2/refdb_fs.c} +639 -254
  367. data/vendor/libgit2/src/{reflog.c → libgit2/reflog.c} +8 -7
  368. data/vendor/libgit2/src/{reflog.h → libgit2/reflog.h} +3 -2
  369. data/vendor/libgit2/src/{refs.c → libgit2/refs.c} +67 -39
  370. data/vendor/libgit2/src/{refs.h → libgit2/refs.h} +8 -3
  371. data/vendor/libgit2/src/{refspec.c → libgit2/refspec.c} +60 -38
  372. data/vendor/libgit2/src/{refspec.h → libgit2/refspec.h} +13 -2
  373. data/vendor/libgit2/src/{remote.c → libgit2/remote.c} +821 -454
  374. data/vendor/libgit2/src/libgit2/remote.h +101 -0
  375. data/vendor/libgit2/src/{repository.c → libgit2/repository.c} +1377 -594
  376. data/vendor/libgit2/src/{repository.h → libgit2/repository.h} +43 -12
  377. data/vendor/libgit2/src/{reset.c → libgit2/reset.c} +8 -5
  378. data/vendor/libgit2/src/{revert.c → libgit2/revert.c} +18 -22
  379. data/vendor/libgit2/src/{revparse.c → libgit2/revparse.c} +76 -44
  380. data/vendor/libgit2/src/{revwalk.c → libgit2/revwalk.c} +48 -19
  381. data/vendor/libgit2/src/{revwalk.h → libgit2/revwalk.h} +3 -3
  382. data/vendor/libgit2/src/{libgit2.c → libgit2/settings.c} +162 -95
  383. data/vendor/libgit2/src/{settings.h → libgit2/settings.h} +6 -2
  384. data/vendor/libgit2/src/{signature.c → libgit2/signature.c} +144 -21
  385. data/vendor/libgit2/src/{signature.h → libgit2/signature.h} +1 -2
  386. data/vendor/libgit2/src/{stash.c → libgit2/stash.c} +243 -68
  387. data/vendor/libgit2/src/{status.c → libgit2/status.c} +5 -2
  388. data/vendor/libgit2/src/{strarray.c → libgit2/strarray.c} +1 -0
  389. data/vendor/libgit2/src/libgit2/strarray.h +25 -0
  390. data/vendor/libgit2/src/{streams → libgit2/streams}/mbedtls.c +62 -67
  391. data/vendor/libgit2/src/{streams → libgit2/streams}/openssl.c +41 -24
  392. data/vendor/libgit2/src/{streams → libgit2/streams}/openssl.h +2 -0
  393. data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_dynamic.c +11 -3
  394. data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_dynamic.h +6 -3
  395. data/vendor/libgit2/src/libgit2/streams/schannel.c +715 -0
  396. data/vendor/libgit2/src/libgit2/streams/schannel.h +28 -0
  397. data/vendor/libgit2/src/libgit2/streams/socket.c +428 -0
  398. data/vendor/libgit2/src/{streams → libgit2/streams}/socket.h +3 -1
  399. data/vendor/libgit2/src/{streams → libgit2/streams}/stransport.c +79 -19
  400. data/vendor/libgit2/src/{streams → libgit2/streams}/tls.c +5 -0
  401. data/vendor/libgit2/src/{submodule.c → libgit2/submodule.c} +279 -220
  402. data/vendor/libgit2/src/{submodule.h → libgit2/submodule.h} +10 -11
  403. data/vendor/libgit2/src/libgit2/sysdir.c +650 -0
  404. data/vendor/libgit2/src/{sysdir.h → libgit2/sysdir.h} +55 -18
  405. data/vendor/libgit2/src/{tag.c → libgit2/tag.c} +74 -43
  406. data/vendor/libgit2/src/{tag.h → libgit2/tag.h} +2 -2
  407. data/vendor/libgit2/src/{trace.c → libgit2/trace.c} +1 -14
  408. data/vendor/libgit2/src/{trace.h → libgit2/trace.h} +5 -22
  409. data/vendor/libgit2/src/{trailer.c → libgit2/trailer.c} +7 -7
  410. data/vendor/libgit2/src/{transaction.c → libgit2/transaction.c} +27 -21
  411. data/vendor/libgit2/src/{transaction.h → libgit2/transaction.h} +4 -1
  412. data/vendor/libgit2/src/{transport.c → libgit2/transport.c} +14 -11
  413. data/vendor/libgit2/src/{transports → libgit2/transports}/auth.c +7 -9
  414. data/vendor/libgit2/src/{transports → libgit2/transports}/auth.h +3 -5
  415. data/vendor/libgit2/src/{transports/auth_negotiate.c → libgit2/transports/auth_gssapi.c} +44 -45
  416. data/vendor/libgit2/src/{transports → libgit2/transports}/auth_negotiate.h +1 -1
  417. data/vendor/libgit2/src/{transports → libgit2/transports}/auth_ntlm.h +1 -2
  418. data/vendor/libgit2/src/{transports/auth_ntlm.c → libgit2/transports/auth_ntlmclient.c} +22 -22
  419. data/vendor/libgit2/src/libgit2/transports/auth_sspi.c +341 -0
  420. data/vendor/libgit2/src/{transports → libgit2/transports}/credential.c +1 -1
  421. data/vendor/libgit2/src/{transports → libgit2/transports}/git.c +16 -19
  422. data/vendor/libgit2/src/{transports → libgit2/transports}/http.c +49 -24
  423. data/vendor/libgit2/src/{transports → libgit2/transports}/http.h +0 -11
  424. data/vendor/libgit2/src/{transports → libgit2/transports}/httpclient.c +188 -134
  425. data/vendor/libgit2/src/{transports → libgit2/transports}/httpclient.h +10 -0
  426. data/vendor/libgit2/src/libgit2/transports/httpparser.c +128 -0
  427. data/vendor/libgit2/src/libgit2/transports/httpparser.h +99 -0
  428. data/vendor/libgit2/src/{transports → libgit2/transports}/local.c +159 -127
  429. data/vendor/libgit2/src/{transports → libgit2/transports}/smart.c +142 -165
  430. data/vendor/libgit2/src/{transports → libgit2/transports}/smart.h +56 -36
  431. data/vendor/libgit2/src/{transports → libgit2/transports}/smart_pkt.c +307 -74
  432. data/vendor/libgit2/src/{transports → libgit2/transports}/smart_protocol.c +297 -97
  433. data/vendor/libgit2/src/libgit2/transports/ssh.c +85 -0
  434. data/vendor/libgit2/src/libgit2/transports/ssh_exec.c +347 -0
  435. data/vendor/libgit2/src/libgit2/transports/ssh_exec.h +26 -0
  436. data/vendor/libgit2/src/{transports/ssh.c → libgit2/transports/ssh_libssh2.c} +414 -268
  437. data/vendor/libgit2/src/libgit2/transports/ssh_libssh2.h +28 -0
  438. data/vendor/libgit2/src/{transports → libgit2/transports}/winhttp.c +101 -75
  439. data/vendor/libgit2/src/{tree-cache.c → libgit2/tree-cache.c} +30 -20
  440. data/vendor/libgit2/src/{tree-cache.h → libgit2/tree-cache.h} +7 -5
  441. data/vendor/libgit2/src/{tree.c → libgit2/tree.c} +128 -110
  442. data/vendor/libgit2/src/{tree.h → libgit2/tree.h} +7 -6
  443. data/vendor/libgit2/src/{worktree.c → libgit2/worktree.c} +160 -121
  444. data/vendor/libgit2/src/{worktree.h → libgit2/worktree.h} +1 -1
  445. data/vendor/libgit2/src/util/CMakeLists.txt +77 -0
  446. data/vendor/libgit2/src/{alloc.c → util/alloc.c} +69 -7
  447. data/vendor/libgit2/src/util/alloc.h +65 -0
  448. data/vendor/libgit2/src/util/allocators/debugalloc.c +73 -0
  449. data/vendor/libgit2/src/util/allocators/debugalloc.h +17 -0
  450. data/vendor/libgit2/src/util/allocators/failalloc.c +32 -0
  451. data/vendor/libgit2/src/util/allocators/failalloc.h +17 -0
  452. data/vendor/libgit2/src/util/allocators/stdalloc.c +37 -0
  453. data/vendor/libgit2/src/{allocators → util/allocators}/stdalloc.h +1 -1
  454. data/vendor/libgit2/src/util/allocators/win32_leakcheck.c +50 -0
  455. data/vendor/libgit2/src/{allocators → util/allocators}/win32_leakcheck.h +1 -1
  456. data/vendor/libgit2/src/{array.h → util/array.h} +25 -19
  457. data/vendor/libgit2/src/{assert_safe.h → util/assert_safe.h} +16 -0
  458. data/vendor/libgit2/src/{cc-compat.h → util/cc-compat.h} +5 -1
  459. data/vendor/libgit2/src/util/ctype_compat.h +70 -0
  460. data/vendor/libgit2/src/{date.c → util/date.c} +35 -33
  461. data/vendor/libgit2/src/util/date.h +45 -0
  462. data/vendor/libgit2/src/util/errors.c +401 -0
  463. data/vendor/libgit2/src/{errors.h → util/errors.h} +22 -19
  464. data/vendor/libgit2/src/{filebuf.c → util/filebuf.c} +35 -30
  465. data/vendor/libgit2/src/{filebuf.h → util/filebuf.h} +21 -8
  466. data/vendor/libgit2/src/{path.c → util/fs_path.c} +591 -615
  467. data/vendor/libgit2/src/{path.h → util/fs_path.h} +257 -181
  468. data/vendor/libgit2/src/{futils.c → util/futils.c} +144 -95
  469. data/vendor/libgit2/src/{futils.h → util/futils.h} +40 -18
  470. data/vendor/libgit2/src/{features.h.in → util/git2_features.h.in} +33 -2
  471. data/vendor/libgit2/src/{common.h → util/git2_util.h} +26 -59
  472. data/vendor/libgit2/src/util/hash/builtin.c +53 -0
  473. data/vendor/libgit2/src/{hash/sha1/openssl.h → util/hash/builtin.h} +6 -6
  474. data/vendor/libgit2/src/{hash/sha1 → util/hash}/collisiondetect.c +3 -3
  475. data/vendor/libgit2/src/{hash/sha1 → util/hash}/collisiondetect.h +3 -3
  476. data/vendor/libgit2/src/util/hash/common_crypto.c +112 -0
  477. data/vendor/libgit2/src/{hash/sha1 → util/hash}/common_crypto.h +11 -3
  478. data/vendor/libgit2/src/util/hash/mbedtls.c +92 -0
  479. data/vendor/libgit2/src/{hash/sha1 → util/hash}/mbedtls.h +14 -4
  480. data/vendor/libgit2/src/util/hash/openssl.c +347 -0
  481. data/vendor/libgit2/src/util/hash/openssl.h +61 -0
  482. data/vendor/libgit2/src/util/hash/rfc6234/sha.h +243 -0
  483. data/vendor/libgit2/src/util/hash/rfc6234/sha224-256.c +601 -0
  484. data/vendor/libgit2/src/util/hash/sha.h +73 -0
  485. data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/sha1.c +1 -1
  486. data/vendor/libgit2/src/util/hash/win32.c +549 -0
  487. data/vendor/libgit2/src/util/hash/win32.h +60 -0
  488. data/vendor/libgit2/src/util/hash.c +158 -0
  489. data/vendor/libgit2/src/util/hash.h +61 -0
  490. data/vendor/libgit2/src/util/hashmap.h +424 -0
  491. data/vendor/libgit2/src/util/hashmap_str.h +43 -0
  492. data/vendor/libgit2/src/{integer.h → util/integer.h} +3 -1
  493. data/vendor/libgit2/src/{map.h → util/map.h} +1 -1
  494. data/vendor/libgit2/src/util/net.c +1160 -0
  495. data/vendor/libgit2/src/{net.h → util/net.h} +45 -4
  496. data/vendor/libgit2/src/{pool.c → util/pool.c} +1 -1
  497. data/vendor/libgit2/src/{pool.h → util/pool.h} +6 -1
  498. data/vendor/libgit2/src/{posix.c → util/posix.c} +57 -3
  499. data/vendor/libgit2/src/{posix.h → util/posix.h} +26 -1
  500. data/vendor/libgit2/src/{pqueue.h → util/pqueue.h} +3 -3
  501. data/vendor/libgit2/src/util/process.h +222 -0
  502. data/vendor/libgit2/src/util/rand.c +230 -0
  503. data/vendor/libgit2/src/util/rand.h +37 -0
  504. data/vendor/libgit2/src/{regexp.c → util/regexp.c} +5 -5
  505. data/vendor/libgit2/src/{regexp.h → util/regexp.h} +1 -1
  506. data/vendor/libgit2/src/{runtime.c → util/runtime.c} +1 -1
  507. data/vendor/libgit2/src/{runtime.h → util/runtime.h} +1 -1
  508. data/vendor/libgit2/src/{sortedcache.c → util/sortedcache.c} +15 -14
  509. data/vendor/libgit2/src/{sortedcache.h → util/sortedcache.h} +5 -5
  510. data/vendor/libgit2/src/util/staticstr.h +66 -0
  511. data/vendor/libgit2/src/{buffer.c → util/str.c} +159 -153
  512. data/vendor/libgit2/src/util/str.h +357 -0
  513. data/vendor/libgit2/src/util/strlist.c +108 -0
  514. data/vendor/libgit2/src/util/strlist.h +36 -0
  515. data/vendor/libgit2/src/{thread.c → util/thread.c} +1 -1
  516. data/vendor/libgit2/src/{thread.h → util/thread.h} +23 -22
  517. data/vendor/libgit2/src/{tsort.c → util/tsort.c} +1 -1
  518. data/vendor/libgit2/src/{unix → util/unix}/map.c +1 -3
  519. data/vendor/libgit2/src/{unix → util/unix}/posix.h +1 -6
  520. data/vendor/libgit2/src/util/unix/process.c +629 -0
  521. data/vendor/libgit2/src/{unix → util/unix}/realpath.c +24 -8
  522. data/vendor/libgit2/src/{utf8.c → util/utf8.c} +1 -1
  523. data/vendor/libgit2/src/{utf8.h → util/utf8.h} +1 -1
  524. data/vendor/libgit2/src/{util.c → util/util.c} +24 -19
  525. data/vendor/libgit2/src/{util.h → util/util.h} +30 -81
  526. data/vendor/libgit2/src/{varint.h → util/varint.h} +1 -1
  527. data/vendor/libgit2/src/{vector.c → util/vector.c} +3 -3
  528. data/vendor/libgit2/src/{vector.h → util/vector.h} +4 -4
  529. data/vendor/libgit2/src/{wildmatch.h → util/wildmatch.h} +1 -1
  530. data/vendor/libgit2/src/{win32 → util/win32}/dir.h +1 -1
  531. data/vendor/libgit2/src/{win32 → util/win32}/error.c +1 -1
  532. data/vendor/libgit2/src/{win32 → util/win32}/error.h +1 -1
  533. data/vendor/libgit2/src/{win32 → util/win32}/map.c +1 -1
  534. data/vendor/libgit2/src/{win32 → util/win32}/path_w32.c +148 -17
  535. data/vendor/libgit2/src/{win32 → util/win32}/path_w32.h +3 -1
  536. data/vendor/libgit2/src/{win32 → util/win32}/posix.h +1 -2
  537. data/vendor/libgit2/src/{win32 → util/win32}/posix_w32.c +42 -35
  538. data/vendor/libgit2/src/util/win32/precompiled.c +1 -0
  539. data/vendor/libgit2/src/{win32 → util/win32}/precompiled.h +1 -1
  540. data/vendor/libgit2/src/util/win32/process.c +506 -0
  541. data/vendor/libgit2/src/{win32 → util/win32}/thread.h +1 -1
  542. data/vendor/libgit2/src/util/win32/utf-conv.c +144 -0
  543. data/vendor/libgit2/src/util/win32/utf-conv.h +127 -0
  544. data/vendor/libgit2/src/{win32 → util/win32}/w32_buffer.c +2 -3
  545. data/vendor/libgit2/src/{win32 → util/win32}/w32_buffer.h +3 -4
  546. data/vendor/libgit2/src/{win32 → util/win32}/w32_leakcheck.c +1 -1
  547. data/vendor/libgit2/src/{win32 → util/win32}/w32_leakcheck.h +1 -1
  548. data/vendor/libgit2/src/{win32 → util/win32}/w32_util.c +1 -1
  549. data/vendor/libgit2/src/{win32 → util/win32}/w32_util.h +1 -1
  550. data/vendor/libgit2/src/{zstream.c → util/zstream.c} +5 -5
  551. data/vendor/libgit2/src/{zstream.h → util/zstream.h} +5 -5
  552. metadata +431 -362
  553. data/vendor/libgit2/cmake/FindIconv.cmake +0 -45
  554. data/vendor/libgit2/deps/http-parser/CMakeLists.txt +0 -6
  555. data/vendor/libgit2/deps/http-parser/COPYING +0 -23
  556. data/vendor/libgit2/deps/http-parser/http_parser.c +0 -2182
  557. data/vendor/libgit2/deps/http-parser/http_parser.h +0 -305
  558. data/vendor/libgit2/deps/zlib/COPYING +0 -27
  559. data/vendor/libgit2/include/git2/sys/reflog.h +0 -21
  560. data/vendor/libgit2/src/alloc.h +0 -40
  561. data/vendor/libgit2/src/allocators/failalloc.c +0 -92
  562. data/vendor/libgit2/src/allocators/failalloc.h +0 -23
  563. data/vendor/libgit2/src/allocators/stdalloc.c +0 -150
  564. data/vendor/libgit2/src/allocators/win32_leakcheck.c +0 -118
  565. data/vendor/libgit2/src/buffer.h +0 -374
  566. data/vendor/libgit2/src/commit.h +0 -46
  567. data/vendor/libgit2/src/config_entries.c +0 -237
  568. data/vendor/libgit2/src/config_entries.h +0 -24
  569. data/vendor/libgit2/src/config_mem.c +0 -220
  570. data/vendor/libgit2/src/errors.c +0 -238
  571. data/vendor/libgit2/src/hash/sha1/common_crypto.c +0 -57
  572. data/vendor/libgit2/src/hash/sha1/generic.c +0 -300
  573. data/vendor/libgit2/src/hash/sha1/generic.h +0 -19
  574. data/vendor/libgit2/src/hash/sha1/mbedtls.c +0 -46
  575. data/vendor/libgit2/src/hash/sha1/openssl.c +0 -59
  576. data/vendor/libgit2/src/hash/sha1/win32.c +0 -333
  577. data/vendor/libgit2/src/hash/sha1/win32.h +0 -128
  578. data/vendor/libgit2/src/hash/sha1.h +0 -38
  579. data/vendor/libgit2/src/hash.c +0 -110
  580. data/vendor/libgit2/src/hash.h +0 -46
  581. data/vendor/libgit2/src/idxmap.c +0 -157
  582. data/vendor/libgit2/src/idxmap.h +0 -177
  583. data/vendor/libgit2/src/khash.h +0 -615
  584. data/vendor/libgit2/src/libgit2.h +0 -15
  585. data/vendor/libgit2/src/message.h +0 -17
  586. data/vendor/libgit2/src/net.c +0 -540
  587. data/vendor/libgit2/src/netops.c +0 -125
  588. data/vendor/libgit2/src/netops.h +0 -68
  589. data/vendor/libgit2/src/offmap.c +0 -101
  590. data/vendor/libgit2/src/offmap.h +0 -133
  591. data/vendor/libgit2/src/oid.h +0 -51
  592. data/vendor/libgit2/src/oidarray.c +0 -43
  593. data/vendor/libgit2/src/oidmap.c +0 -107
  594. data/vendor/libgit2/src/oidmap.h +0 -128
  595. data/vendor/libgit2/src/remote.h +0 -55
  596. data/vendor/libgit2/src/streams/socket.c +0 -239
  597. data/vendor/libgit2/src/strmap.c +0 -100
  598. data/vendor/libgit2/src/strmap.h +0 -131
  599. data/vendor/libgit2/src/sysdir.c +0 -347
  600. data/vendor/libgit2/src/threadstate.c +0 -84
  601. data/vendor/libgit2/src/threadstate.h +0 -24
  602. data/vendor/libgit2/src/win32/findfile.c +0 -230
  603. data/vendor/libgit2/src/win32/findfile.h +0 -19
  604. data/vendor/libgit2/src/win32/utf-conv.c +0 -146
  605. data/vendor/libgit2/src/win32/utf-conv.h +0 -60
  606. /data/vendor/libgit2/{src → deps}/xdiff/xemit.h +0 -0
  607. /data/vendor/libgit2/{src → deps}/xdiff/xprepare.h +0 -0
  608. /data/vendor/libgit2/{src → deps}/xdiff/xtypes.h +0 -0
  609. /data/vendor/libgit2/src/{win32 → cli/win32}/precompiled.c +0 -0
  610. /data/vendor/libgit2/src/{attr.h → libgit2/attr.h} +0 -0
  611. /data/vendor/libgit2/src/{blame_git.h → libgit2/blame_git.h} +0 -0
  612. /data/vendor/libgit2/src/{config_parse.h → libgit2/config_parse.h} +0 -0
  613. /data/vendor/libgit2/src/{delta.c → libgit2/delta.c} +0 -0
  614. /data/vendor/libgit2/src/{delta.h → libgit2/delta.h} +0 -0
  615. /data/vendor/libgit2/src/{diff_file.h → libgit2/diff_file.h} +0 -0
  616. /data/vendor/libgit2/src/{diff_parse.h → libgit2/diff_parse.h} +0 -0
  617. /data/vendor/libgit2/src/{diff_tform.h → libgit2/diff_tform.h} +0 -0
  618. /data/vendor/libgit2/src/{fetchhead.h → libgit2/fetchhead.h} +0 -0
  619. /data/vendor/libgit2/src/{hashsig.c → libgit2/hashsig.c} +0 -0
  620. /data/vendor/libgit2/src/{indexer.h → libgit2/indexer.h} +0 -0
  621. /data/vendor/libgit2/src/{mailmap.h → libgit2/mailmap.h} +0 -0
  622. /data/vendor/libgit2/src/{merge_driver.h → libgit2/merge_driver.h} +0 -0
  623. /data/vendor/libgit2/src/{notes.h → libgit2/notes.h} +0 -0
  624. /data/vendor/libgit2/src/{object_api.c → libgit2/object_api.c} +0 -0
  625. /data/vendor/libgit2/src/{patch_parse.h → libgit2/patch_parse.h} +0 -0
  626. /data/vendor/libgit2/src/{refdb.c → libgit2/refdb.c} +0 -0
  627. /data/vendor/libgit2/src/{refdb.h → libgit2/refdb.h} +0 -0
  628. /data/vendor/libgit2/src/{repo_template.h → libgit2/repo_template.h} +0 -0
  629. /data/vendor/libgit2/src/{status.h → libgit2/status.h} +0 -0
  630. /data/vendor/libgit2/src/{stream.h → libgit2/stream.h} +0 -0
  631. /data/vendor/libgit2/src/{streams → libgit2/streams}/mbedtls.h +0 -0
  632. /data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_legacy.c +0 -0
  633. /data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_legacy.h +0 -0
  634. /data/vendor/libgit2/src/{streams → libgit2/streams}/registry.c +0 -0
  635. /data/vendor/libgit2/src/{streams → libgit2/streams}/registry.h +0 -0
  636. /data/vendor/libgit2/src/{streams → libgit2/streams}/stransport.h +0 -0
  637. /data/vendor/libgit2/src/{streams → libgit2/streams}/tls.h +0 -0
  638. /data/vendor/libgit2/src/{transports → libgit2/transports}/credential_helpers.c +0 -0
  639. /data/vendor/libgit2/src/{userdiff.h → libgit2/userdiff.h} +0 -0
  640. /data/vendor/libgit2/src/{bitvec.h → util/bitvec.h} +0 -0
  641. /data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/sha1.h +0 -0
  642. /data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/ubc_check.c +0 -0
  643. /data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/ubc_check.h +0 -0
  644. /data/vendor/libgit2/src/{pqueue.c → util/pqueue.c} +0 -0
  645. /data/vendor/libgit2/src/{strnlen.h → util/strnlen.h} +0 -0
  646. /data/vendor/libgit2/src/{unix → util/unix}/pthread.h +0 -0
  647. /data/vendor/libgit2/src/{varint.c → util/varint.c} +0 -0
  648. /data/vendor/libgit2/src/{wildmatch.c → util/wildmatch.c} +0 -0
  649. /data/vendor/libgit2/src/{win32 → util/win32}/dir.c +0 -0
  650. /data/vendor/libgit2/src/{win32 → util/win32}/mingw-compat.h +0 -0
  651. /data/vendor/libgit2/src/{win32 → util/win32}/msvc-compat.h +0 -0
  652. /data/vendor/libgit2/src/{win32 → util/win32}/reparse.h +0 -0
  653. /data/vendor/libgit2/src/{win32 → util/win32}/thread.c +0 -0
  654. /data/vendor/libgit2/src/{win32 → util/win32}/version.h +0 -0
  655. /data/vendor/libgit2/src/{win32 → util/win32}/w32_common.h +0 -0
  656. /data/vendor/libgit2/src/{win32 → util/win32}/win32-compat.h +0 -0
@@ -18,6 +18,7 @@
18
18
  #include "sortedcache.h"
19
19
  #include "signature.h"
20
20
  #include "wildmatch.h"
21
+ #include "path.h"
21
22
 
22
23
  #include <git2/tag.h>
23
24
  #include <git2/object.h>
@@ -25,7 +26,6 @@
25
26
  #include <git2/branch.h>
26
27
  #include <git2/sys/refdb_backend.h>
27
28
  #include <git2/sys/refs.h>
28
- #include <git2/sys/reflog.h>
29
29
 
30
30
  #define DEFAULT_NESTING_LEVEL 5
31
31
  #define MAX_NESTING_LEVEL 10
@@ -34,7 +34,7 @@ enum {
34
34
  PACKREF_HAS_PEEL = 1,
35
35
  PACKREF_WAS_LOOSE = 2,
36
36
  PACKREF_CANNOT_PEEL = 4,
37
- PACKREF_SHADOWED = 8,
37
+ PACKREF_SHADOWED = 8
38
38
  };
39
39
 
40
40
  enum {
@@ -59,29 +59,36 @@ typedef struct refdb_fs_backend {
59
59
  /* path to common objects' directory */
60
60
  char *commonpath;
61
61
 
62
- git_sortedcache *refcache;
62
+ git_oid_t oid_type;
63
+
64
+ unsigned int fsync : 1,
65
+ sorted : 1;
63
66
  int peeling_mode;
64
67
  git_iterator_flag_t iterator_flags;
65
68
  uint32_t direach_flags;
66
- int fsync;
69
+ git_sortedcache *refcache;
70
+ git_map packed_refs_map;
71
+ git_mutex prlock; /* protect packed_refs_map */
72
+ git_futils_filestamp packed_refs_stamp;
67
73
  } refdb_fs_backend;
68
74
 
69
75
  static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name);
76
+ static char *packed_set_peeling_mode(char *data, size_t data_sz, refdb_fs_backend *backend);
70
77
 
71
78
  GIT_INLINE(int) loose_path(
72
- git_buf *out,
79
+ git_str *out,
73
80
  const char *base,
74
81
  const char *refname)
75
82
  {
76
- if (git_buf_joinpath(out, base, refname) < 0)
83
+ if (git_str_joinpath(out, base, refname) < 0)
77
84
  return -1;
78
85
 
79
- return git_path_validate_filesystem_with_suffix(out->ptr, out->size,
86
+ return git_fs_path_validate_str_length_with_suffix(out,
80
87
  CONST_STRLEN(".lock"));
81
88
  }
82
89
 
83
90
  GIT_INLINE(int) reflog_path(
84
- git_buf *out,
91
+ git_str *out,
85
92
  git_repository *repo,
86
93
  const char *refname)
87
94
  {
@@ -91,7 +98,7 @@ GIT_INLINE(int) reflog_path(
91
98
  base = (strcmp(refname, GIT_HEAD_FILE) == 0) ? repo->gitdir :
92
99
  repo->commondir;
93
100
 
94
- if ((error = git_buf_joinpath(out, base, GIT_REFLOG_DIR)) < 0)
101
+ if ((error = git_str_joinpath(out, base, GIT_REFLOG_DIR)) < 0)
95
102
  return error;
96
103
 
97
104
  return loose_path(out, out->ptr, refname);
@@ -106,7 +113,8 @@ static int packref_cmp(const void *a_, const void *b_)
106
113
  static int packed_reload(refdb_fs_backend *backend)
107
114
  {
108
115
  int error;
109
- git_buf packedrefs = GIT_BUF_INIT;
116
+ git_str packedrefs = GIT_STR_INIT;
117
+ size_t oid_hexsize = git_oid_hexsize(backend->oid_type);
110
118
  char *scan, *eof, *eol;
111
119
 
112
120
  if (!backend->gitpath)
@@ -133,31 +141,12 @@ static int packed_reload(refdb_fs_backend *backend)
133
141
 
134
142
  GIT_UNUSED(git_sortedcache_clear(backend->refcache, false));
135
143
 
136
- scan = (char *)packedrefs.ptr;
144
+ scan = packedrefs.ptr;
137
145
  eof = scan + packedrefs.size;
138
146
 
139
- backend->peeling_mode = PEELING_NONE;
140
-
141
- if (*scan == '#') {
142
- static const char *traits_header = "# pack-refs with: ";
143
-
144
- if (git__prefixcmp(scan, traits_header) == 0) {
145
- scan += strlen(traits_header);
146
- eol = strchr(scan, '\n');
147
-
148
- if (!eol)
149
- goto parse_failed;
150
- *eol = '\0';
151
-
152
- if (strstr(scan, " fully-peeled ") != NULL) {
153
- backend->peeling_mode = PEELING_FULL;
154
- } else if (strstr(scan, " peeled ") != NULL) {
155
- backend->peeling_mode = PEELING_STANDARD;
156
- }
157
-
158
- scan = eol + 1;
159
- }
160
- }
147
+ scan = packed_set_peeling_mode(scan, packedrefs.size, backend);
148
+ if (!scan)
149
+ goto parse_failed;
161
150
 
162
151
  while (scan < eof && *scan == '#') {
163
152
  if (!(eol = strchr(scan, '\n')))
@@ -171,9 +160,9 @@ static int packed_reload(refdb_fs_backend *backend)
171
160
 
172
161
  /* parse "<OID> <refname>\n" */
173
162
 
174
- if (git_oid_fromstr(&oid, scan) < 0)
163
+ if (git_oid__fromstr(&oid, scan, backend->oid_type) < 0)
175
164
  goto parse_failed;
176
- scan += GIT_OID_HEXSZ;
165
+ scan += oid_hexsize;
177
166
 
178
167
  if (*scan++ != ' ')
179
168
  goto parse_failed;
@@ -192,9 +181,9 @@ static int packed_reload(refdb_fs_backend *backend)
192
181
  /* look for optional "^<OID>\n" */
193
182
 
194
183
  if (*scan == '^') {
195
- if (git_oid_fromstr(&oid, scan + 1) < 0)
184
+ if (git_oid__fromstr(&oid, scan + 1, backend->oid_type) < 0)
196
185
  goto parse_failed;
197
- scan += GIT_OID_HEXSZ + 1;
186
+ scan += oid_hexsize + 1;
198
187
 
199
188
  if (scan < eof) {
200
189
  if (!(eol = strchr(scan, '\n')))
@@ -212,7 +201,7 @@ static int packed_reload(refdb_fs_backend *backend)
212
201
  }
213
202
 
214
203
  git_sortedcache_wunlock(backend->refcache);
215
- git_buf_dispose(&packedrefs);
204
+ git_str_dispose(&packedrefs);
216
205
 
217
206
  return 0;
218
207
 
@@ -221,25 +210,29 @@ parse_failed:
221
210
 
222
211
  GIT_UNUSED(git_sortedcache_clear(backend->refcache, false));
223
212
  git_sortedcache_wunlock(backend->refcache);
224
- git_buf_dispose(&packedrefs);
213
+ git_str_dispose(&packedrefs);
225
214
 
226
215
  return -1;
227
216
  }
228
217
 
229
218
  static int loose_parse_oid(
230
- git_oid *oid, const char *filename, git_buf *file_content)
219
+ git_oid *oid,
220
+ const char *filename,
221
+ git_str *file_content,
222
+ git_oid_t oid_type)
231
223
  {
232
- const char *str = git_buf_cstr(file_content);
224
+ const char *str = git_str_cstr(file_content);
225
+ size_t oid_hexsize = git_oid_hexsize(oid_type);
233
226
 
234
- if (git_buf_len(file_content) < GIT_OID_HEXSZ)
227
+ if (git_str_len(file_content) < oid_hexsize)
235
228
  goto corrupted;
236
229
 
237
230
  /* we need to get 40 OID characters from the file */
238
- if (git_oid_fromstr(oid, str) < 0)
231
+ if (git_oid__fromstr(oid, str, oid_type) < 0)
239
232
  goto corrupted;
240
233
 
241
234
  /* If the file is longer than 40 chars, the 41st must be a space */
242
- str += GIT_OID_HEXSZ;
235
+ str += oid_hexsize;
243
236
  if (*str == '\0' || git__isspace(*str))
244
237
  return 0;
245
238
 
@@ -248,13 +241,13 @@ corrupted:
248
241
  return -1;
249
242
  }
250
243
 
251
- static int loose_readbuffer(git_buf *buf, const char *base, const char *path)
244
+ static int loose_readbuffer(git_str *buf, const char *base, const char *path)
252
245
  {
253
246
  int error;
254
247
 
255
248
  if ((error = loose_path(buf, base, path)) < 0 ||
256
249
  (error = git_futils_readbuffer(buf, buf->ptr)) < 0)
257
- git_buf_dispose(buf);
250
+ git_str_dispose(buf);
258
251
 
259
252
  return error;
260
253
  }
@@ -262,7 +255,7 @@ static int loose_readbuffer(git_buf *buf, const char *base, const char *path)
262
255
  static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
263
256
  {
264
257
  int error = 0;
265
- git_buf ref_file = GIT_BUF_INIT;
258
+ git_str ref_file = GIT_STR_INIT;
266
259
  struct packref *ref = NULL;
267
260
  git_oid oid;
268
261
 
@@ -275,11 +268,11 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
275
268
  }
276
269
 
277
270
  /* skip symbolic refs */
278
- if (!git__prefixcmp(git_buf_cstr(&ref_file), GIT_SYMREF))
271
+ if (!git__prefixcmp(git_str_cstr(&ref_file), GIT_SYMREF))
279
272
  goto done;
280
273
 
281
274
  /* parse OID from file */
282
- if ((error = loose_parse_oid(&oid, name, &ref_file)) < 0)
275
+ if ((error = loose_parse_oid(&oid, name, &ref_file, backend->oid_type)) < 0)
283
276
  goto done;
284
277
 
285
278
  if ((error = git_sortedcache_wlock(backend->refcache)) < 0)
@@ -295,11 +288,11 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
295
288
  git_sortedcache_wunlock(backend->refcache);
296
289
 
297
290
  done:
298
- git_buf_dispose(&ref_file);
291
+ git_str_dispose(&ref_file);
299
292
  return error;
300
293
  }
301
294
 
302
- static int _dirent_loose_load(void *payload, git_buf *full_path)
295
+ static int _dirent_loose_load(void *payload, git_str *full_path)
303
296
  {
304
297
  refdb_fs_backend *backend = payload;
305
298
  const char *file_path;
@@ -307,8 +300,8 @@ static int _dirent_loose_load(void *payload, git_buf *full_path)
307
300
  if (git__suffixcmp(full_path->ptr, ".lock") == 0)
308
301
  return 0;
309
302
 
310
- if (git_path_isdir(full_path->ptr)) {
311
- int error = git_path_direach(
303
+ if (git_fs_path_isdir(full_path->ptr)) {
304
+ int error = git_fs_path_direach(
312
305
  full_path, backend->direach_flags, _dirent_loose_load, backend);
313
306
  /* Race with the filesystem, ignore it */
314
307
  if (error == GIT_ENOTFOUND) {
@@ -333,9 +326,9 @@ static int _dirent_loose_load(void *payload, git_buf *full_path)
333
326
  static int packed_loadloose(refdb_fs_backend *backend)
334
327
  {
335
328
  int error;
336
- git_buf refs_path = GIT_BUF_INIT;
329
+ git_str refs_path = GIT_STR_INIT;
337
330
 
338
- if (git_buf_joinpath(&refs_path, backend->gitpath, GIT_REFS_DIR) < 0)
331
+ if (git_str_joinpath(&refs_path, backend->gitpath, GIT_REFS_DIR) < 0)
339
332
  return -1;
340
333
 
341
334
  /*
@@ -343,10 +336,10 @@ static int packed_loadloose(refdb_fs_backend *backend)
343
336
  * This will overwrite any old packed entries with their
344
337
  * updated loose versions
345
338
  */
346
- error = git_path_direach(
339
+ error = git_fs_path_direach(
347
340
  &refs_path, backend->direach_flags, _dirent_loose_load, backend);
348
341
 
349
- git_buf_dispose(&refs_path);
342
+ git_str_dispose(&refs_path);
350
343
 
351
344
  return error;
352
345
  }
@@ -357,7 +350,7 @@ static int refdb_fs_backend__exists(
357
350
  const char *ref_name)
358
351
  {
359
352
  refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
360
- git_buf ref_path = GIT_BUF_INIT;
353
+ git_str ref_path = GIT_STR_INIT;
361
354
  int error;
362
355
 
363
356
  GIT_ASSERT_ARG(backend);
@@ -367,7 +360,7 @@ static int refdb_fs_backend__exists(
367
360
  if ((error = loose_path(&ref_path, backend->gitpath, ref_name)) < 0)
368
361
  goto out;
369
362
 
370
- if (git_path_isfile(ref_path.ptr)) {
363
+ if (git_fs_path_isfile(ref_path.ptr)) {
371
364
  *exists = 1;
372
365
  goto out;
373
366
  }
@@ -381,18 +374,18 @@ static int refdb_fs_backend__exists(
381
374
  }
382
375
 
383
376
  out:
384
- git_buf_dispose(&ref_path);
377
+ git_str_dispose(&ref_path);
385
378
  return error;
386
379
  }
387
380
 
388
- static const char *loose_parse_symbolic(git_buf *file_content)
381
+ static const char *loose_parse_symbolic(git_str *file_content)
389
382
  {
390
383
  const unsigned int header_len = (unsigned int)strlen(GIT_SYMREF);
391
384
  const char *refname_start;
392
385
 
393
386
  refname_start = (const char *)file_content->ptr;
394
387
 
395
- if (git_buf_len(file_content) < header_len + 1) {
388
+ if (git_str_len(file_content) < header_len + 1) {
396
389
  git_error_set(GIT_ERROR_REFERENCE, "corrupted loose reference file");
397
390
  return NULL;
398
391
  }
@@ -416,7 +409,9 @@ static const char *loose_parse_symbolic(git_buf *file_content)
416
409
  static bool is_per_worktree_ref(const char *ref_name)
417
410
  {
418
411
  return git__prefixcmp(ref_name, "refs/") != 0 ||
419
- git__prefixcmp(ref_name, "refs/bisect/") == 0;
412
+ git__prefixcmp(ref_name, "refs/bisect/") == 0 ||
413
+ git__prefixcmp(ref_name, "refs/worktree/") == 0 ||
414
+ git__prefixcmp(ref_name, "refs/rewritten/") == 0;
420
415
  }
421
416
 
422
417
  static int loose_lookup(
@@ -424,7 +419,7 @@ static int loose_lookup(
424
419
  refdb_fs_backend *backend,
425
420
  const char *ref_name)
426
421
  {
427
- git_buf ref_file = GIT_BUF_INIT;
422
+ git_str ref_file = GIT_STR_INIT;
428
423
  int error = 0;
429
424
  const char *ref_dir;
430
425
 
@@ -438,10 +433,10 @@ static int loose_lookup(
438
433
 
439
434
  if ((error = loose_readbuffer(&ref_file, ref_dir, ref_name)) < 0)
440
435
  /* cannot read loose ref file - gah */;
441
- else if (git__prefixcmp(git_buf_cstr(&ref_file), GIT_SYMREF) == 0) {
436
+ else if (git__prefixcmp(git_str_cstr(&ref_file), GIT_SYMREF) == 0) {
442
437
  const char *target;
443
438
 
444
- git_buf_rtrim(&ref_file);
439
+ git_str_rtrim(&ref_file);
445
440
 
446
441
  if (!(target = loose_parse_symbolic(&ref_file)))
447
442
  error = -1;
@@ -450,12 +445,12 @@ static int loose_lookup(
450
445
  } else {
451
446
  git_oid oid;
452
447
 
453
- if (!(error = loose_parse_oid(&oid, ref_name, &ref_file)) &&
448
+ if (!(error = loose_parse_oid(&oid, ref_name, &ref_file, backend->oid_type)) &&
454
449
  out != NULL)
455
450
  *out = git_reference__alloc(ref_name, &oid, NULL);
456
451
  }
457
452
 
458
- git_buf_dispose(&ref_file);
453
+ git_str_dispose(&ref_file);
459
454
  return error;
460
455
  }
461
456
 
@@ -465,10 +460,203 @@ static int ref_error_notfound(const char *name)
465
460
  return GIT_ENOTFOUND;
466
461
  }
467
462
 
468
- static int packed_lookup(
469
- git_reference **out,
470
- refdb_fs_backend *backend,
471
- const char *ref_name)
463
+ static char *packed_set_peeling_mode(
464
+ char *data,
465
+ size_t data_sz,
466
+ refdb_fs_backend *backend)
467
+ {
468
+ static const char *traits_header = "# pack-refs with:";
469
+ char *eol;
470
+ backend->peeling_mode = PEELING_NONE;
471
+
472
+ if (git__prefixncmp(data, data_sz, traits_header) == 0) {
473
+ size_t hdr_sz = strlen(traits_header);
474
+ const char *sorted = " sorted ";
475
+ const char *peeled = " peeled ";
476
+ const char *fully_peeled = " fully-peeled ";
477
+ data += hdr_sz;
478
+ data_sz -= hdr_sz;
479
+
480
+ eol = memchr(data, '\n', data_sz);
481
+
482
+ if (!eol)
483
+ return NULL;
484
+
485
+ if (git__memmem(data, eol - data, fully_peeled, strlen(fully_peeled)))
486
+ backend->peeling_mode = PEELING_FULL;
487
+ else if (git__memmem(data, eol - data, peeled, strlen(peeled)))
488
+ backend->peeling_mode = PEELING_STANDARD;
489
+
490
+ backend->sorted = NULL != git__memmem(data, eol - data, sorted, strlen(sorted));
491
+
492
+ return eol + 1;
493
+ }
494
+ return data;
495
+ }
496
+
497
+ static void packed_map_free(refdb_fs_backend *backend)
498
+ {
499
+ if (backend->packed_refs_map.data) {
500
+ #ifdef GIT_WIN32
501
+ git__free(backend->packed_refs_map.data);
502
+ #else
503
+ git_futils_mmap_free(&backend->packed_refs_map);
504
+ #endif
505
+ backend->packed_refs_map.data = NULL;
506
+ backend->packed_refs_map.len = 0;
507
+ git_futils_filestamp_set(&backend->packed_refs_stamp, NULL);
508
+ }
509
+ }
510
+
511
+ static int packed_map_check(refdb_fs_backend *backend)
512
+ {
513
+ int error = 0;
514
+ git_file fd = -1;
515
+ struct stat st;
516
+
517
+ if ((error = git_mutex_lock(&backend->prlock)) < 0)
518
+ return error;
519
+
520
+ if (backend->packed_refs_map.data &&
521
+ !git_futils_filestamp_check(
522
+ &backend->packed_refs_stamp, backend->refcache->path)) {
523
+ git_mutex_unlock(&backend->prlock);
524
+ return error;
525
+ }
526
+ packed_map_free(backend);
527
+
528
+ fd = git_futils_open_ro(backend->refcache->path);
529
+ if (fd < 0) {
530
+ git_mutex_unlock(&backend->prlock);
531
+ if (fd == GIT_ENOTFOUND) {
532
+ git_error_clear();
533
+ return 0;
534
+ }
535
+ return fd;
536
+ }
537
+
538
+ if (p_fstat(fd, &st) < 0) {
539
+ p_close(fd);
540
+ git_mutex_unlock(&backend->prlock);
541
+ git_error_set(GIT_ERROR_OS, "unable to stat packed-refs '%s'", backend->refcache->path);
542
+ return -1;
543
+ }
544
+
545
+ if (st.st_size == 0) {
546
+ p_close(fd);
547
+ git_mutex_unlock(&backend->prlock);
548
+ return 0;
549
+ }
550
+
551
+ git_futils_filestamp_set_from_stat(&backend->packed_refs_stamp, &st);
552
+
553
+ #ifdef GIT_WIN32
554
+ /* on windows, we copy the entire file into memory rather than using
555
+ * mmap() because using mmap() on windows also locks the file and this
556
+ * map is long-lived. */
557
+ backend->packed_refs_map.len = (size_t)st.st_size;
558
+ backend->packed_refs_map.data =
559
+ git__malloc(backend->packed_refs_map.len);
560
+ GIT_ERROR_CHECK_ALLOC(backend->packed_refs_map.data);
561
+ {
562
+ ssize_t bytesread =
563
+ p_read(fd, backend->packed_refs_map.data,
564
+ backend->packed_refs_map.len);
565
+ error = (bytesread == (ssize_t)backend->packed_refs_map.len) ? 0 : -1;
566
+ }
567
+ #else
568
+ error = git_futils_mmap_ro(&backend->packed_refs_map, fd, 0, (size_t)st.st_size);
569
+ #endif
570
+ p_close(fd);
571
+ if (error < 0) {
572
+ git_mutex_unlock(&backend->prlock);
573
+ return error;
574
+ }
575
+
576
+ packed_set_peeling_mode(
577
+ backend->packed_refs_map.data, backend->packed_refs_map.len,
578
+ backend);
579
+
580
+ git_mutex_unlock(&backend->prlock);
581
+ return error;
582
+ }
583
+
584
+ /*
585
+ * Find beginning of packed-ref record pointed to by p.
586
+ * buf - a lower-bound pointer to some memory buffer
587
+ * p - an upper-bound pointer to the same memory buffer
588
+ */
589
+ static const char *start_of_record(const char *buf, const char *p)
590
+ {
591
+ const char *nl = p;
592
+ while (true) {
593
+ nl = git__memrchr(buf, '\n', nl - buf);
594
+ if (!nl)
595
+ return buf;
596
+
597
+ if (nl[1] == '^' && nl > buf)
598
+ --nl;
599
+ else
600
+ break;
601
+ };
602
+ return nl + 1;
603
+ }
604
+
605
+ /*
606
+ * Find end of packed-ref record pointed to by p.
607
+ * end - an upper-bound pointer to some memory buffer
608
+ * p - a lower-bound pointer to the same memory buffer
609
+ */
610
+ static const char *end_of_record(const char *p, const char *end)
611
+ {
612
+ while (1) {
613
+ size_t sz = end - p;
614
+ p = memchr(p, '\n', sz);
615
+ if (!p)
616
+ return end;
617
+ ++p;
618
+ if (p < end && p[0] == '^')
619
+ ++p;
620
+ else
621
+ break;
622
+ }
623
+ return p;
624
+ }
625
+
626
+ static int cmp_record_to_refname(
627
+ const char *rec,
628
+ size_t data_end,
629
+ const char *ref_name,
630
+ git_oid_t oid_type)
631
+ {
632
+ const size_t ref_len = strlen(ref_name);
633
+ int cmp_val;
634
+ const char *end;
635
+ size_t oid_hexsize = git_oid_hexsize(oid_type);
636
+
637
+ rec += oid_hexsize + 1; /* <oid> + space */
638
+
639
+ /* an incomplete (corrupt) record is treated as less than ref_name */
640
+ if (data_end < oid_hexsize + 3)
641
+ return -1;
642
+
643
+ data_end -= oid_hexsize + 1;
644
+
645
+ end = memchr(rec, '\n', data_end);
646
+ if (end)
647
+ data_end = end - rec;
648
+
649
+ cmp_val = memcmp(rec, ref_name, min(ref_len, data_end));
650
+
651
+ if (cmp_val == 0 && data_end != ref_len)
652
+ return (data_end > ref_len) ? 1 : -1;
653
+ return cmp_val;
654
+ }
655
+
656
+ static int packed_unsorted_lookup(
657
+ git_reference **out,
658
+ refdb_fs_backend *backend,
659
+ const char *ref_name)
472
660
  {
473
661
  int error = 0;
474
662
  struct packref *entry;
@@ -493,6 +681,86 @@ static int packed_lookup(
493
681
  return error;
494
682
  }
495
683
 
684
+ static int packed_lookup(
685
+ git_reference **out,
686
+ refdb_fs_backend *backend,
687
+ const char *ref_name)
688
+ {
689
+ int error = 0;
690
+ const char *left, *right, *data_end;
691
+ size_t oid_hexsize = git_oid_hexsize(backend->oid_type);
692
+
693
+ if ((error = packed_map_check(backend)) < 0)
694
+ return error;
695
+
696
+ if (!backend->sorted)
697
+ return packed_unsorted_lookup(out, backend, ref_name);
698
+
699
+ left = backend->packed_refs_map.data;
700
+ right = data_end = (const char *) backend->packed_refs_map.data +
701
+ backend->packed_refs_map.len;
702
+
703
+ while (left < right && *left == '#') {
704
+ if (!(left = memchr(left, '\n', data_end - left)))
705
+ goto parse_failed;
706
+ left++;
707
+ }
708
+
709
+ while (left < right) {
710
+ const char *mid, *rec;
711
+ int compare;
712
+
713
+ mid = left + (right - left) / 2;
714
+ rec = start_of_record(left, mid);
715
+ compare = cmp_record_to_refname(rec, data_end - rec, ref_name, backend->oid_type);
716
+
717
+ if (compare < 0) {
718
+ left = end_of_record(mid, right);
719
+ } else if (compare > 0) {
720
+ right = rec;
721
+ } else {
722
+ const char *eol;
723
+ git_oid oid, peel, *peel_ptr = NULL;
724
+
725
+ if (data_end - rec < (long)oid_hexsize ||
726
+ git_oid__fromstr(&oid, rec, backend->oid_type) < 0) {
727
+ goto parse_failed;
728
+ }
729
+ rec += oid_hexsize + 1;
730
+ if (!(eol = memchr(rec, '\n', data_end - rec))) {
731
+ goto parse_failed;
732
+ }
733
+
734
+ /* look for optional "^<OID>\n" */
735
+
736
+ if (eol + 1 < data_end) {
737
+ rec = eol + 1;
738
+
739
+ if (*rec == '^') {
740
+ rec++;
741
+ if (data_end - rec < (long)oid_hexsize ||
742
+ git_oid__fromstr(&peel, rec, backend->oid_type) < 0) {
743
+ goto parse_failed;
744
+ }
745
+ peel_ptr = &peel;
746
+ }
747
+ }
748
+
749
+ *out = git_reference__alloc(ref_name, &oid, peel_ptr);
750
+ if (!*out) {
751
+ return -1;
752
+ }
753
+
754
+ return 0;
755
+ }
756
+ }
757
+ return ref_error_notfound(ref_name);
758
+
759
+ parse_failed:
760
+ git_error_set(GIT_ERROR_REFERENCE, "corrupted packed references file");
761
+ return -1;
762
+ }
763
+
496
764
  static int refdb_fs_backend__lookup(
497
765
  git_reference **out,
498
766
  git_refdb_backend *_backend,
@@ -512,7 +780,6 @@ static int refdb_fs_backend__lookup(
512
780
  git_error_clear();
513
781
  error = packed_lookup(out, backend, ref_name);
514
782
  }
515
-
516
783
  return error;
517
784
  }
518
785
 
@@ -533,86 +800,155 @@ static void refdb_fs_backend__iterator_free(git_reference_iterator *_iter)
533
800
  {
534
801
  refdb_fs_iter *iter = GIT_CONTAINER_OF(_iter, refdb_fs_iter, parent);
535
802
 
536
- git_vector_free(&iter->loose);
803
+ git_vector_dispose(&iter->loose);
537
804
  git_pool_clear(&iter->pool);
538
805
  git_sortedcache_free(iter->cache);
539
806
  git__free(iter);
540
807
  }
541
808
 
542
- static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
809
+ struct iter_load_context {
810
+ refdb_fs_backend *backend;
811
+ refdb_fs_iter *iter;
812
+
813
+ /*
814
+ * If we have a glob with a prefix (eg `refs/heads/ *`) then we can
815
+ * optimize our prefix to avoid walking refs that we know won't
816
+ * match. This is that prefix.
817
+ */
818
+ const char *ref_prefix;
819
+ size_t ref_prefix_len;
820
+
821
+ /* Temporary variables to avoid unnecessary allocations */
822
+ git_str ref_name;
823
+ git_str path;
824
+ };
825
+
826
+ static void iter_load_optimize_prefix(struct iter_load_context *ctx)
543
827
  {
544
- int error = 0;
545
- git_buf path = GIT_BUF_INIT;
546
- git_iterator *fsit = NULL;
547
- git_iterator_options fsit_opts = GIT_ITERATOR_OPTIONS_INIT;
548
- const git_index_entry *entry = NULL;
549
- const char *ref_prefix = GIT_REFS_DIR;
550
- size_t ref_prefix_len = strlen(ref_prefix);
828
+ const char *pos, *last_sep = NULL;
551
829
 
552
- if (!backend->commonpath) /* do nothing if no commonpath for loose refs */
553
- return 0;
830
+ if (!ctx->iter->glob)
831
+ return;
554
832
 
555
- fsit_opts.flags = backend->iterator_flags;
556
-
557
- if (iter->glob) {
558
- const char *last_sep = NULL;
559
- const char *pos;
560
- for (pos = iter->glob; *pos; ++pos) {
561
- switch (*pos) {
562
- case '?':
563
- case '*':
564
- case '[':
565
- case '\\':
566
- break;
567
- case '/':
568
- last_sep = pos;
569
- /* FALLTHROUGH */
570
- default:
571
- continue;
572
- }
833
+ for (pos = ctx->iter->glob; *pos; pos++) {
834
+ switch (*pos) {
835
+ case '?':
836
+ case '*':
837
+ case '[':
838
+ case '\\':
573
839
  break;
840
+ case '/':
841
+ last_sep = pos;
842
+ /* FALLTHROUGH */
843
+ default:
844
+ continue;
574
845
  }
575
- if (last_sep) {
576
- ref_prefix = iter->glob;
577
- ref_prefix_len = (last_sep - ref_prefix) + 1;
578
- }
846
+ break;
579
847
  }
580
848
 
581
- if ((error = git_buf_puts(&path, backend->commonpath)) < 0 ||
582
- (error = git_buf_put(&path, ref_prefix, ref_prefix_len)) < 0) {
583
- git_buf_dispose(&path);
584
- return error;
849
+ if (last_sep) {
850
+ ctx->ref_prefix = ctx->iter->glob;
851
+ ctx->ref_prefix_len = (last_sep - ctx->ref_prefix) + 1;
585
852
  }
853
+ }
854
+
855
+ static int iter_load_paths(
856
+ struct iter_load_context *ctx,
857
+ const char *root_path,
858
+ bool worktree)
859
+ {
860
+ git_iterator *fsit = NULL;
861
+ git_iterator_options fsit_opts = GIT_ITERATOR_OPTIONS_INIT;
862
+ const git_index_entry *entry;
863
+ int error = 0;
864
+
865
+ fsit_opts.flags = ctx->backend->iterator_flags;
866
+
867
+ git_str_clear(&ctx->path);
868
+ git_str_puts(&ctx->path, root_path);
869
+ git_str_put(&ctx->path, ctx->ref_prefix, ctx->ref_prefix_len);
870
+
871
+ fsit_opts.flags = ctx->backend->iterator_flags;
872
+ fsit_opts.oid_type = ctx->backend->oid_type;
586
873
 
587
- if ((error = git_iterator_for_filesystem(&fsit, path.ptr, &fsit_opts)) < 0) {
588
- git_buf_dispose(&path);
589
- return (iter->glob && error == GIT_ENOTFOUND)? 0 : error;
874
+ if ((error = git_iterator_for_filesystem(&fsit, ctx->path.ptr, &fsit_opts)) < 0) {
875
+ /*
876
+ * Subdirectories - either glob provided or per-worktree refs - need
877
+ * not exist.
878
+ */
879
+ if ((worktree || ctx->iter->glob) && error == GIT_ENOTFOUND)
880
+ error = 0;
881
+
882
+ goto done;
590
883
  }
591
884
 
592
- error = git_buf_sets(&path, ref_prefix);
885
+ git_str_clear(&ctx->ref_name);
886
+ git_str_put(&ctx->ref_name, ctx->ref_prefix, ctx->ref_prefix_len);
593
887
 
594
- while (!error && !git_iterator_advance(&entry, fsit)) {
595
- const char *ref_name;
888
+ while (git_iterator_advance(&entry, fsit) == 0) {
596
889
  char *ref_dup;
597
890
 
598
- git_buf_truncate(&path, ref_prefix_len);
599
- git_buf_puts(&path, entry->path);
600
- ref_name = git_buf_cstr(&path);
891
+ git_str_truncate(&ctx->ref_name, ctx->ref_prefix_len);
892
+ git_str_puts(&ctx->ref_name, entry->path);
601
893
 
602
- if (git__suffixcmp(ref_name, ".lock") == 0 ||
603
- (iter->glob && wildmatch(iter->glob, ref_name, 0) != 0))
894
+ if (worktree) {
895
+ if (!is_per_worktree_ref(ctx->ref_name.ptr))
896
+ continue;
897
+ } else {
898
+ if (git_repository_is_worktree(ctx->backend->repo) &&
899
+ is_per_worktree_ref(ctx->ref_name.ptr))
900
+ continue;
901
+ }
902
+
903
+ if (git__suffixcmp(ctx->ref_name.ptr, ".lock") == 0)
604
904
  continue;
605
905
 
606
- ref_dup = git_pool_strdup(&iter->pool, ref_name);
607
- if (!ref_dup)
608
- error = -1;
609
- else
610
- error = git_vector_insert(&iter->loose, ref_dup);
906
+ if (ctx->iter->glob && wildmatch(ctx->iter->glob, ctx->ref_name.ptr, 0))
907
+ continue;
908
+
909
+ ref_dup = git_pool_strdup(&ctx->iter->pool, ctx->ref_name.ptr);
910
+ GIT_ERROR_CHECK_ALLOC(ref_dup);
911
+
912
+ if ((error = git_vector_insert(&ctx->iter->loose, ref_dup)) < 0)
913
+ goto done;
611
914
  }
612
915
 
916
+ done:
613
917
  git_iterator_free(fsit);
614
- git_buf_dispose(&path);
918
+ return error;
919
+ }
920
+
921
+ #define iter_load_context_init(b, i) { b, i, GIT_REFS_DIR, CONST_STRLEN(GIT_REFS_DIR) }
922
+ #define iter_load_context_dispose(ctx) do { \
923
+ git_str_dispose(&((ctx)->path)); \
924
+ git_str_dispose(&((ctx)->ref_name)); \
925
+ } while(0)
926
+
927
+ static int iter_load_loose_paths(
928
+ refdb_fs_backend *backend,
929
+ refdb_fs_iter *iter)
930
+ {
931
+ struct iter_load_context ctx = iter_load_context_init(backend, iter);
932
+
933
+ int error = 0;
934
+
935
+ if (!backend->commonpath)
936
+ return 0;
937
+
938
+ iter_load_optimize_prefix(&ctx);
615
939
 
940
+ if ((error = iter_load_paths(&ctx,
941
+ backend->commonpath, false)) < 0)
942
+ goto done;
943
+
944
+ if (git_repository_is_worktree(backend->repo)) {
945
+ if ((error = iter_load_paths(&ctx,
946
+ backend->gitpath, true)) < 0)
947
+ goto done;
948
+ }
949
+
950
+ done:
951
+ iter_load_context_dispose(&ctx);
616
952
  return error;
617
953
  }
618
954
 
@@ -810,14 +1146,14 @@ static int reference_path_available(
810
1146
  static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *name)
811
1147
  {
812
1148
  int error, filebuf_flags;
813
- git_buf ref_path = GIT_BUF_INIT;
1149
+ git_str ref_path = GIT_STR_INIT;
814
1150
  const char *basedir;
815
1151
 
816
1152
  GIT_ASSERT_ARG(file);
817
1153
  GIT_ASSERT_ARG(backend);
818
1154
  GIT_ASSERT_ARG(name);
819
1155
 
820
- if (!git_path_validate(backend->repo, name, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
1156
+ if (!git_path_is_valid(backend->repo, name, 0, GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
821
1157
  git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", name);
822
1158
  return GIT_EINVALIDSPEC;
823
1159
  }
@@ -845,7 +1181,7 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
845
1181
  if (error == GIT_EDIRECTORY)
846
1182
  git_error_set(GIT_ERROR_REFERENCE, "cannot lock ref '%s', there are refs beneath that folder", name);
847
1183
 
848
- git_buf_dispose(&ref_path);
1184
+ git_str_dispose(&ref_path);
849
1185
  return error;
850
1186
  }
851
1187
 
@@ -855,7 +1191,7 @@ static int loose_commit(git_filebuf *file, const git_reference *ref)
855
1191
  GIT_ASSERT_ARG(ref);
856
1192
 
857
1193
  if (ref->type == GIT_REFERENCE_DIRECT) {
858
- char oid[GIT_OID_HEXSZ + 1];
1194
+ char oid[GIT_OID_MAX_HEXSIZE + 1];
859
1195
  git_oid_nfmt(oid, sizeof(oid), &ref->target.oid);
860
1196
 
861
1197
  git_filebuf_printf(file, "%s\n", oid);
@@ -971,7 +1307,7 @@ static int packed_find_peel(refdb_fs_backend *backend, struct packref *ref)
971
1307
  */
972
1308
  static int packed_write_ref(struct packref *ref, git_filebuf *file)
973
1309
  {
974
- char oid[GIT_OID_HEXSZ + 1];
1310
+ char oid[GIT_OID_MAX_HEXSIZE + 1];
975
1311
  git_oid_nfmt(oid, sizeof(oid), &ref->oid);
976
1312
 
977
1313
  /*
@@ -985,7 +1321,7 @@ static int packed_write_ref(struct packref *ref, git_filebuf *file)
985
1321
  * The required peels have already been loaded into `ref->peel_target`.
986
1322
  */
987
1323
  if (ref->flags & PACKREF_HAS_PEEL) {
988
- char peel[GIT_OID_HEXSZ + 1];
1324
+ char peel[GIT_OID_MAX_HEXSIZE + 1];
989
1325
  git_oid_nfmt(peel, sizeof(peel), &ref->peel);
990
1326
 
991
1327
  if (git_filebuf_printf(file, "%s %s\n^%s\n", oid, ref->name, peel) < 0)
@@ -1013,7 +1349,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
1013
1349
  {
1014
1350
  size_t i;
1015
1351
  git_filebuf lock = GIT_FILEBUF_INIT;
1016
- git_buf ref_content = GIT_BUF_INIT;
1352
+ git_str ref_content = GIT_STR_INIT;
1017
1353
  int error = 0;
1018
1354
 
1019
1355
  /* backend->refcache is already locked when this is called */
@@ -1034,7 +1370,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
1034
1370
  continue;
1035
1371
 
1036
1372
  if (error < 0) {
1037
- git_buf_dispose(&ref_content);
1373
+ git_str_dispose(&ref_content);
1038
1374
  git_error_set(GIT_ERROR_REFERENCE, "failed to lock loose reference '%s'", ref->name);
1039
1375
  return error;
1040
1376
  }
@@ -1049,7 +1385,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
1049
1385
  continue;
1050
1386
 
1051
1387
  /* Figure out the current id; if we find a bad ref file, skip it so we can do the rest */
1052
- if (loose_parse_oid(&current_id, lock.path_original, &ref_content) < 0)
1388
+ if (loose_parse_oid(&current_id, lock.path_original, &ref_content, backend->oid_type) < 0)
1053
1389
  continue;
1054
1390
 
1055
1391
  /* If the ref moved since we packed it, we must not delete it */
@@ -1065,7 +1401,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
1065
1401
  p_unlink(lock.path_original);
1066
1402
  }
1067
1403
 
1068
- git_buf_dispose(&ref_content);
1404
+ git_str_dispose(&ref_content);
1069
1405
  git_filebuf_cleanup(&lock);
1070
1406
  return 0;
1071
1407
  }
@@ -1080,6 +1416,15 @@ static int packed_write(refdb_fs_backend *backend)
1080
1416
  int error, open_flags = 0;
1081
1417
  size_t i;
1082
1418
 
1419
+ /* take lock and close up packed-refs mmap if open */
1420
+ if ((error = git_mutex_lock(&backend->prlock)) < 0) {
1421
+ return error;
1422
+ }
1423
+
1424
+ packed_map_free(backend);
1425
+
1426
+ git_mutex_unlock(&backend->prlock);
1427
+
1083
1428
  /* lock the cache to updates while we do this */
1084
1429
  if ((error = git_sortedcache_wlock(refcache)) < 0)
1085
1430
  return error;
@@ -1099,7 +1444,11 @@ static int packed_write(refdb_fs_backend *backend)
1099
1444
 
1100
1445
  for (i = 0; i < git_sortedcache_entrycount(refcache); ++i) {
1101
1446
  struct packref *ref = git_sortedcache_entry(refcache, i);
1102
- GIT_ASSERT(ref);
1447
+
1448
+ GIT_ASSERT_WITH_CLEANUP(ref, {
1449
+ error = -1;
1450
+ goto fail;
1451
+ });
1103
1452
 
1104
1453
  if ((error = packed_find_peel(backend, ref)) < 0)
1105
1454
  goto fail;
@@ -1333,41 +1682,41 @@ static int refdb_fs_backend__prune_refs(
1333
1682
  const char *ref_name,
1334
1683
  const char *prefix)
1335
1684
  {
1336
- git_buf relative_path = GIT_BUF_INIT;
1337
- git_buf base_path = GIT_BUF_INIT;
1685
+ git_str relative_path = GIT_STR_INIT;
1686
+ git_str base_path = GIT_STR_INIT;
1338
1687
  size_t commonlen;
1339
1688
  int error;
1340
1689
 
1341
1690
  GIT_ASSERT_ARG(backend);
1342
1691
  GIT_ASSERT_ARG(ref_name);
1343
1692
 
1344
- if ((error = git_buf_sets(&relative_path, ref_name)) < 0)
1693
+ if ((error = git_str_sets(&relative_path, ref_name)) < 0)
1345
1694
  goto cleanup;
1346
1695
 
1347
- git_path_squash_slashes(&relative_path);
1348
- if ((commonlen = git_path_common_dirlen("refs/heads/", git_buf_cstr(&relative_path))) == strlen("refs/heads/") ||
1349
- (commonlen = git_path_common_dirlen("refs/tags/", git_buf_cstr(&relative_path))) == strlen("refs/tags/") ||
1350
- (commonlen = git_path_common_dirlen("refs/remotes/", git_buf_cstr(&relative_path))) == strlen("refs/remotes/")) {
1696
+ git_fs_path_squash_slashes(&relative_path);
1697
+ if ((commonlen = git_fs_path_common_dirlen("refs/heads/", git_str_cstr(&relative_path))) == strlen("refs/heads/") ||
1698
+ (commonlen = git_fs_path_common_dirlen("refs/tags/", git_str_cstr(&relative_path))) == strlen("refs/tags/") ||
1699
+ (commonlen = git_fs_path_common_dirlen("refs/remotes/", git_str_cstr(&relative_path))) == strlen("refs/remotes/")) {
1351
1700
 
1352
- git_buf_truncate(&relative_path, commonlen);
1701
+ git_str_truncate(&relative_path, commonlen);
1353
1702
 
1354
1703
  if (prefix)
1355
- error = git_buf_join3(&base_path, '/',
1704
+ error = git_str_join3(&base_path, '/',
1356
1705
  backend->commonpath, prefix,
1357
- git_buf_cstr(&relative_path));
1706
+ git_str_cstr(&relative_path));
1358
1707
  else
1359
- error = git_buf_joinpath(&base_path,
1708
+ error = git_str_joinpath(&base_path,
1360
1709
  backend->commonpath,
1361
- git_buf_cstr(&relative_path));
1710
+ git_str_cstr(&relative_path));
1362
1711
 
1363
1712
  if (!error)
1364
- error = git_path_validate_filesystem(base_path.ptr, base_path.size);
1713
+ error = git_path_validate_str_length(NULL, &base_path);
1365
1714
 
1366
1715
  if (error < 0)
1367
1716
  goto cleanup;
1368
1717
 
1369
1718
  error = git_futils_rmdir_r(ref_name + commonlen,
1370
- git_buf_cstr(&base_path),
1719
+ git_str_cstr(&base_path),
1371
1720
  GIT_RMDIR_EMPTY_PARENTS | GIT_RMDIR_SKIP_ROOT);
1372
1721
 
1373
1722
  if (error == GIT_ENOTFOUND)
@@ -1375,8 +1724,8 @@ static int refdb_fs_backend__prune_refs(
1375
1724
  }
1376
1725
 
1377
1726
  cleanup:
1378
- git_buf_dispose(&relative_path);
1379
- git_buf_dispose(&base_path);
1727
+ git_str_dispose(&relative_path);
1728
+ git_str_dispose(&base_path);
1380
1729
  return error;
1381
1730
  }
1382
1731
 
@@ -1405,7 +1754,7 @@ static int refdb_fs_backend__delete(
1405
1754
 
1406
1755
  static int loose_delete(refdb_fs_backend *backend, const char *ref_name)
1407
1756
  {
1408
- git_buf path = GIT_BUF_INIT;
1757
+ git_str path = GIT_STR_INIT;
1409
1758
  int error = 0;
1410
1759
 
1411
1760
  if ((error = loose_path(&path, backend->commonpath, ref_name)) < 0)
@@ -1417,7 +1766,7 @@ static int loose_delete(refdb_fs_backend *backend, const char *ref_name)
1417
1766
  else if (error != 0)
1418
1767
  error = -1;
1419
1768
 
1420
- git_buf_dispose(&path);
1769
+ git_str_dispose(&path);
1421
1770
 
1422
1771
  return error;
1423
1772
  }
@@ -1503,7 +1852,7 @@ static int refdb_fs_backend__rename(
1503
1852
  (error = refdb_fs_backend__lookup(&old, _backend, old_name)) < 0)
1504
1853
  return error;
1505
1854
 
1506
- if ((error = refdb_fs_backend__delete(_backend, old_name, NULL, NULL)) < 0) {
1855
+ if ((error = loose_lock(&file, backend, old->name)) < 0) {
1507
1856
  git_reference_free(old);
1508
1857
  return error;
1509
1858
  }
@@ -1511,32 +1860,33 @@ static int refdb_fs_backend__rename(
1511
1860
  new = git_reference__realloc(&old, new_name);
1512
1861
  if (!new) {
1513
1862
  git_reference_free(old);
1863
+ git_filebuf_cleanup(&file);
1514
1864
  return -1;
1515
1865
  }
1516
1866
 
1517
- if ((error = loose_lock(&file, backend, new->name)) < 0) {
1867
+ if ((error = refdb_fs_backend__delete_tail(_backend, &file, old_name, NULL, NULL)) < 0) {
1518
1868
  git_reference_free(new);
1869
+ git_filebuf_cleanup(&file);
1519
1870
  return error;
1520
1871
  }
1521
1872
 
1522
- /* Try to rename the refog; it's ok if the old doesn't exist */
1523
- error = refdb_reflog_fs__rename(_backend, old_name, new_name);
1524
- if (((error == 0) || (error == GIT_ENOTFOUND)) &&
1525
- ((error = reflog_append(backend, new, git_reference_target(new), NULL, who, message)) < 0)) {
1873
+ if ((error = loose_lock(&file, backend, new_name)) < 0) {
1526
1874
  git_reference_free(new);
1527
- git_filebuf_cleanup(&file);
1528
1875
  return error;
1529
1876
  }
1530
1877
 
1531
- if (error < 0) {
1878
+ /* Try to rename the refog; it's ok if the old doesn't exist */
1879
+ error = refdb_reflog_fs__rename(_backend, old_name, new_name);
1880
+ if (((error == 0) || (error == GIT_ENOTFOUND)) &&
1881
+ ((error = reflog_append(backend, new, git_reference_target(new), NULL, who, message)) < 0)) {
1532
1882
  git_reference_free(new);
1533
1883
  git_filebuf_cleanup(&file);
1534
1884
  return error;
1535
1885
  }
1536
1886
 
1537
-
1538
1887
  if ((error = loose_commit(&file, new)) < 0 || out == NULL) {
1539
1888
  git_reference_free(new);
1889
+ git_filebuf_cleanup(&file);
1540
1890
  return error;
1541
1891
  }
1542
1892
 
@@ -1567,6 +1917,12 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
1567
1917
  return;
1568
1918
 
1569
1919
  git_sortedcache_free(backend->refcache);
1920
+
1921
+ git_mutex_lock(&backend->prlock);
1922
+ packed_map_free(backend);
1923
+ git_mutex_unlock(&backend->prlock);
1924
+ git_mutex_free(&backend->prlock);
1925
+
1570
1926
  git__free(backend->gitpath);
1571
1927
  git__free(backend->commonpath);
1572
1928
  git__free(backend);
@@ -1574,17 +1930,17 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
1574
1930
 
1575
1931
  static char *setup_namespace(git_repository *repo, const char *in)
1576
1932
  {
1577
- git_buf path = GIT_BUF_INIT;
1933
+ git_str path = GIT_STR_INIT;
1578
1934
  char *parts, *start, *end, *out = NULL;
1579
1935
 
1580
1936
  if (!in)
1581
1937
  goto done;
1582
1938
 
1583
- git_buf_puts(&path, in);
1939
+ git_str_puts(&path, in);
1584
1940
 
1585
1941
  /* if the repo is not namespaced, nothing else to do */
1586
1942
  if (repo->namespace == NULL) {
1587
- out = git_buf_detach(&path);
1943
+ out = git_str_detach(&path);
1588
1944
  goto done;
1589
1945
  }
1590
1946
 
@@ -1599,27 +1955,30 @@ static char *setup_namespace(git_repository *repo, const char *in)
1599
1955
  * refs under refs/namespaces/foo/refs/namespaces/bar/
1600
1956
  */
1601
1957
  while ((start = git__strsep(&end, "/")) != NULL)
1602
- git_buf_printf(&path, "refs/namespaces/%s/", start);
1958
+ git_str_printf(&path, "refs/namespaces/%s/", start);
1603
1959
 
1604
- git_buf_printf(&path, "refs/namespaces/%s/refs", end);
1960
+ git_str_printf(&path, "refs/namespaces/%s/refs", end);
1605
1961
  git__free(parts);
1606
1962
 
1607
1963
  /* Make sure that the folder with the namespace exists */
1608
- if (git_futils_mkdir_relative(git_buf_cstr(&path), in, 0777,
1964
+ if (git_futils_mkdir_relative(git_str_cstr(&path), in, 0777,
1609
1965
  GIT_MKDIR_PATH, NULL) < 0)
1610
1966
  goto done;
1611
1967
 
1612
1968
  /* Return root of the namespaced gitpath, i.e. without the trailing 'refs' */
1613
- git_buf_rtruncate_at_char(&path, '/');
1614
- git_buf_putc(&path, '/');
1615
- out = git_buf_detach(&path);
1969
+ git_str_rtruncate_at_char(&path, '/');
1970
+ git_str_putc(&path, '/');
1971
+ out = git_str_detach(&path);
1616
1972
 
1617
1973
  done:
1618
- git_buf_dispose(&path);
1974
+ git_str_dispose(&path);
1619
1975
  return out;
1620
1976
  }
1621
1977
 
1622
- static int reflog_alloc(git_reflog **reflog, const char *name)
1978
+ static int reflog_alloc(
1979
+ git_reflog **reflog,
1980
+ const char *name,
1981
+ git_oid_t oid_type)
1623
1982
  {
1624
1983
  git_reflog *log;
1625
1984
 
@@ -1631,6 +1990,8 @@ static int reflog_alloc(git_reflog **reflog, const char *name)
1631
1990
  log->ref_name = git__strdup(name);
1632
1991
  GIT_ERROR_CHECK_ALLOC(log->ref_name);
1633
1992
 
1993
+ log->oid_type = oid_type;
1994
+
1634
1995
  if (git_vector_init(&log->entries, 0, NULL) < 0) {
1635
1996
  git__free(log->ref_name);
1636
1997
  git__free(log);
@@ -1659,9 +2020,9 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
1659
2020
  entry->committer = git__calloc(1, sizeof(*entry->committer));
1660
2021
  GIT_ERROR_CHECK_ALLOC(entry->committer);
1661
2022
 
1662
- if (git_parse_advance_oid(&entry->oid_old, &parser) < 0 ||
2023
+ if (git_parse_advance_oid(&entry->oid_old, &parser, log->oid_type) < 0 ||
1663
2024
  git_parse_advance_expected(&parser, " ", 1) < 0 ||
1664
- git_parse_advance_oid(&entry->oid_cur, &parser) < 0)
2025
+ git_parse_advance_oid(&entry->oid_cur, &parser, log->oid_type) < 0)
1665
2026
  goto next;
1666
2027
 
1667
2028
  sig = parser.line;
@@ -1716,7 +2077,7 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
1716
2077
  {
1717
2078
  refdb_fs_backend *backend;
1718
2079
  git_repository *repo;
1719
- git_buf path = GIT_BUF_INIT;
2080
+ git_str path = GIT_STR_INIT;
1720
2081
  int error;
1721
2082
 
1722
2083
  GIT_ASSERT_ARG(_backend && name);
@@ -1727,8 +2088,8 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
1727
2088
  if ((error = reflog_path(&path, repo, name)) < 0)
1728
2089
  return error;
1729
2090
 
1730
- error = create_new_reflog_file(git_buf_cstr(&path));
1731
- git_buf_dispose(&path);
2091
+ error = create_new_reflog_file(git_str_cstr(&path));
2092
+ git_str_dispose(&path);
1732
2093
 
1733
2094
  return error;
1734
2095
  }
@@ -1736,15 +2097,15 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
1736
2097
  static int has_reflog(git_repository *repo, const char *name)
1737
2098
  {
1738
2099
  int ret = 0;
1739
- git_buf path = GIT_BUF_INIT;
2100
+ git_str path = GIT_STR_INIT;
1740
2101
 
1741
2102
  if (reflog_path(&path, repo, name) < 0)
1742
2103
  goto cleanup;
1743
2104
 
1744
- ret = git_path_isfile(git_buf_cstr(&path));
2105
+ ret = git_fs_path_isfile(git_str_cstr(&path));
1745
2106
 
1746
2107
  cleanup:
1747
- git_buf_dispose(&path);
2108
+ git_str_dispose(&path);
1748
2109
  return ret;
1749
2110
  }
1750
2111
 
@@ -1760,11 +2121,14 @@ static int refdb_reflog_fs__has_log(git_refdb_backend *_backend, const char *nam
1760
2121
  return has_reflog(backend->repo, name);
1761
2122
  }
1762
2123
 
1763
- static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend, const char *name)
2124
+ static int refdb_reflog_fs__read(
2125
+ git_reflog **out,
2126
+ git_refdb_backend *_backend,
2127
+ const char *name)
1764
2128
  {
1765
2129
  int error = -1;
1766
- git_buf log_path = GIT_BUF_INIT;
1767
- git_buf log_file = GIT_BUF_INIT;
2130
+ git_str log_path = GIT_STR_INIT;
2131
+ git_str log_file = GIT_STR_INIT;
1768
2132
  git_reflog *log = NULL;
1769
2133
  git_repository *repo;
1770
2134
  refdb_fs_backend *backend;
@@ -1776,22 +2140,22 @@ static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend,
1776
2140
  backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
1777
2141
  repo = backend->repo;
1778
2142
 
1779
- if (reflog_alloc(&log, name) < 0)
2143
+ if (reflog_alloc(&log, name, backend->oid_type) < 0)
1780
2144
  return -1;
1781
2145
 
1782
2146
  if (reflog_path(&log_path, repo, name) < 0)
1783
2147
  goto cleanup;
1784
2148
 
1785
- error = git_futils_readbuffer(&log_file, git_buf_cstr(&log_path));
2149
+ error = git_futils_readbuffer(&log_file, git_str_cstr(&log_path));
1786
2150
  if (error < 0 && error != GIT_ENOTFOUND)
1787
2151
  goto cleanup;
1788
2152
 
1789
2153
  if ((error == GIT_ENOTFOUND) &&
1790
- ((error = create_new_reflog_file(git_buf_cstr(&log_path))) < 0))
2154
+ ((error = create_new_reflog_file(git_str_cstr(&log_path))) < 0))
1791
2155
  goto cleanup;
1792
2156
 
1793
2157
  if ((error = reflog_parse(log,
1794
- git_buf_cstr(&log_file), git_buf_len(&log_file))) < 0)
2158
+ git_str_cstr(&log_file), git_str_len(&log_file))) < 0)
1795
2159
  goto cleanup;
1796
2160
 
1797
2161
  *out = log;
@@ -1801,62 +2165,62 @@ cleanup:
1801
2165
  git_reflog_free(log);
1802
2166
 
1803
2167
  success:
1804
- git_buf_dispose(&log_file);
1805
- git_buf_dispose(&log_path);
2168
+ git_str_dispose(&log_file);
2169
+ git_str_dispose(&log_path);
1806
2170
 
1807
2171
  return error;
1808
2172
  }
1809
2173
 
1810
2174
  static int serialize_reflog_entry(
1811
- git_buf *buf,
2175
+ git_str *buf,
1812
2176
  const git_oid *oid_old,
1813
2177
  const git_oid *oid_new,
1814
2178
  const git_signature *committer,
1815
2179
  const char *msg)
1816
2180
  {
1817
- char raw_old[GIT_OID_HEXSZ+1];
1818
- char raw_new[GIT_OID_HEXSZ+1];
2181
+ char raw_old[GIT_OID_MAX_HEXSIZE + 1];
2182
+ char raw_new[GIT_OID_MAX_HEXSIZE + 1];
1819
2183
 
1820
- git_oid_tostr(raw_old, GIT_OID_HEXSZ+1, oid_old);
1821
- git_oid_tostr(raw_new, GIT_OID_HEXSZ+1, oid_new);
2184
+ git_oid_tostr(raw_old, GIT_OID_MAX_HEXSIZE + 1, oid_old);
2185
+ git_oid_tostr(raw_new, GIT_OID_MAX_HEXSIZE + 1, oid_new);
1822
2186
 
1823
- git_buf_clear(buf);
2187
+ git_str_clear(buf);
1824
2188
 
1825
- git_buf_puts(buf, raw_old);
1826
- git_buf_putc(buf, ' ');
1827
- git_buf_puts(buf, raw_new);
2189
+ git_str_puts(buf, raw_old);
2190
+ git_str_putc(buf, ' ');
2191
+ git_str_puts(buf, raw_new);
1828
2192
 
1829
2193
  git_signature__writebuf(buf, " ", committer);
1830
2194
 
1831
2195
  /* drop trailing LF */
1832
- git_buf_rtrim(buf);
2196
+ git_str_rtrim(buf);
1833
2197
 
1834
2198
  if (msg) {
1835
2199
  size_t i;
1836
2200
 
1837
- git_buf_putc(buf, '\t');
1838
- git_buf_puts(buf, msg);
2201
+ git_str_putc(buf, '\t');
2202
+ git_str_puts(buf, msg);
1839
2203
 
1840
2204
  for (i = 0; i < buf->size - 2; i++)
1841
2205
  if (buf->ptr[i] == '\n')
1842
2206
  buf->ptr[i] = ' ';
1843
- git_buf_rtrim(buf);
2207
+ git_str_rtrim(buf);
1844
2208
  }
1845
2209
 
1846
- git_buf_putc(buf, '\n');
2210
+ git_str_putc(buf, '\n');
1847
2211
 
1848
- return git_buf_oom(buf);
2212
+ return git_str_oom(buf);
1849
2213
  }
1850
2214
 
1851
2215
  static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char *refname)
1852
2216
  {
1853
2217
  git_repository *repo;
1854
- git_buf log_path = GIT_BUF_INIT;
2218
+ git_str log_path = GIT_STR_INIT;
1855
2219
  int error;
1856
2220
 
1857
2221
  repo = backend->repo;
1858
2222
 
1859
- if (!git_path_validate(backend->repo, refname, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
2223
+ if (!git_path_is_valid(backend->repo, refname, 0, GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
1860
2224
  git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", refname);
1861
2225
  return GIT_EINVALIDSPEC;
1862
2226
  }
@@ -1864,17 +2228,17 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char
1864
2228
  if (reflog_path(&log_path, repo, refname) < 0)
1865
2229
  return -1;
1866
2230
 
1867
- if (!git_path_isfile(git_buf_cstr(&log_path))) {
2231
+ if (!git_fs_path_isfile(git_str_cstr(&log_path))) {
1868
2232
  git_error_set(GIT_ERROR_INVALID,
1869
2233
  "log file for reference '%s' doesn't exist", refname);
1870
2234
  error = -1;
1871
2235
  goto cleanup;
1872
2236
  }
1873
2237
 
1874
- error = git_filebuf_open(file, git_buf_cstr(&log_path), 0, GIT_REFLOG_FILE_MODE);
2238
+ error = git_filebuf_open(file, git_str_cstr(&log_path), 0, GIT_REFLOG_FILE_MODE);
1875
2239
 
1876
2240
  cleanup:
1877
- git_buf_dispose(&log_path);
2241
+ git_str_dispose(&log_path);
1878
2242
 
1879
2243
  return error;
1880
2244
  }
@@ -1885,7 +2249,7 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
1885
2249
  unsigned int i;
1886
2250
  git_reflog_entry *entry;
1887
2251
  refdb_fs_backend *backend;
1888
- git_buf log = GIT_BUF_INIT;
2252
+ git_str log = GIT_STR_INIT;
1889
2253
  git_filebuf fbuf = GIT_FILEBUF_INIT;
1890
2254
 
1891
2255
  GIT_ASSERT_ARG(_backend);
@@ -1911,17 +2275,23 @@ cleanup:
1911
2275
  git_filebuf_cleanup(&fbuf);
1912
2276
 
1913
2277
  success:
1914
- git_buf_dispose(&log);
2278
+ git_str_dispose(&log);
1915
2279
 
1916
2280
  return error;
1917
2281
  }
1918
2282
 
1919
2283
  /* Append to the reflog, must be called under reference lock */
1920
- static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, const git_oid *old, const git_oid *new, const git_signature *who, const char *message)
2284
+ static int reflog_append(
2285
+ refdb_fs_backend *backend,
2286
+ const git_reference *ref,
2287
+ const git_oid *old,
2288
+ const git_oid *new,
2289
+ const git_signature *who,
2290
+ const char *message)
1921
2291
  {
1922
2292
  int error, is_symbolic, open_flags;
1923
- git_oid old_id = {{0}}, new_id = {{0}};
1924
- git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
2293
+ git_oid old_id, new_id;
2294
+ git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
1925
2295
  git_repository *repo = backend->repo;
1926
2296
 
1927
2297
  is_symbolic = ref->type == GIT_REFERENCE_SYMBOLIC;
@@ -1934,6 +2304,9 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
1934
2304
 
1935
2305
  /* From here on is_symbolic also means that it's HEAD */
1936
2306
 
2307
+ git_oid_clear(&old_id, backend->oid_type);
2308
+ git_oid_clear(&new_id, backend->oid_type);
2309
+
1937
2310
  if (old) {
1938
2311
  git_oid_cpy(&old_id, old);
1939
2312
  } else {
@@ -1965,7 +2338,7 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
1965
2338
  if ((error = reflog_path(&path, repo, ref->name)) < 0)
1966
2339
  goto cleanup;
1967
2340
 
1968
- if (((error = git_futils_mkpath2file(git_buf_cstr(&path), 0777)) < 0) &&
2341
+ if (((error = git_futils_mkpath2file(git_str_cstr(&path), 0777)) < 0) &&
1969
2342
  (error != GIT_EEXISTS)) {
1970
2343
  goto cleanup;
1971
2344
  }
@@ -1973,11 +2346,11 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
1973
2346
  /* If the new branch matches part of the namespace of a previously deleted branch,
1974
2347
  * there maybe an obsolete/unused directory (or directory hierarchy) in the way.
1975
2348
  */
1976
- if (git_path_isdir(git_buf_cstr(&path))) {
1977
- if ((error = git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_SKIP_NONEMPTY)) < 0) {
2349
+ if (git_fs_path_isdir(git_str_cstr(&path))) {
2350
+ if ((error = git_futils_rmdir_r(git_str_cstr(&path), NULL, GIT_RMDIR_SKIP_NONEMPTY)) < 0) {
1978
2351
  if (error == GIT_ENOTFOUND)
1979
2352
  error = 0;
1980
- } else if (git_path_isdir(git_buf_cstr(&path))) {
2353
+ } else if (git_fs_path_isdir(git_str_cstr(&path))) {
1981
2354
  git_error_set(GIT_ERROR_REFERENCE, "cannot create reflog at '%s', there are reflogs beneath that folder",
1982
2355
  ref->name);
1983
2356
  error = GIT_EDIRECTORY;
@@ -1992,11 +2365,11 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
1992
2365
  if (backend->fsync)
1993
2366
  open_flags |= O_FSYNC;
1994
2367
 
1995
- error = git_futils_writebuffer(&buf, git_buf_cstr(&path), open_flags, GIT_REFLOG_FILE_MODE);
2368
+ error = git_futils_writebuffer(&buf, git_str_cstr(&path), open_flags, GIT_REFLOG_FILE_MODE);
1996
2369
 
1997
2370
  cleanup:
1998
- git_buf_dispose(&buf);
1999
- git_buf_dispose(&path);
2371
+ git_str_dispose(&buf);
2372
+ git_str_dispose(&path);
2000
2373
 
2001
2374
  return error;
2002
2375
  }
@@ -2004,10 +2377,10 @@ cleanup:
2004
2377
  static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_name, const char *new_name)
2005
2378
  {
2006
2379
  int error = 0, fd;
2007
- git_buf old_path = GIT_BUF_INIT;
2008
- git_buf new_path = GIT_BUF_INIT;
2009
- git_buf temp_path = GIT_BUF_INIT;
2010
- git_buf normalized = GIT_BUF_INIT;
2380
+ git_str old_path = GIT_STR_INIT;
2381
+ git_str new_path = GIT_STR_INIT;
2382
+ git_str temp_path = GIT_STR_INIT;
2383
+ git_str normalized = GIT_STR_INIT;
2011
2384
  git_repository *repo;
2012
2385
  refdb_fs_backend *backend;
2013
2386
 
@@ -2022,16 +2395,16 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
2022
2395
  &normalized, new_name, GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL)) < 0)
2023
2396
  return error;
2024
2397
 
2025
- if (git_buf_joinpath(&temp_path, repo->gitdir, GIT_REFLOG_DIR) < 0)
2398
+ if (git_str_joinpath(&temp_path, repo->gitdir, GIT_REFLOG_DIR) < 0)
2026
2399
  return -1;
2027
2400
 
2028
- if ((error = loose_path(&old_path, git_buf_cstr(&temp_path), old_name)) < 0)
2401
+ if ((error = loose_path(&old_path, git_str_cstr(&temp_path), old_name)) < 0)
2029
2402
  return error;
2030
2403
 
2031
- if ((error = loose_path(&new_path, git_buf_cstr(&temp_path), git_buf_cstr(&normalized))) < 0)
2404
+ if ((error = loose_path(&new_path, git_str_cstr(&temp_path), git_str_cstr(&normalized))) < 0)
2032
2405
  return error;
2033
2406
 
2034
- if (!git_path_exists(git_buf_cstr(&old_path))) {
2407
+ if (!git_fs_path_exists(git_str_cstr(&old_path))) {
2035
2408
  error = GIT_ENOTFOUND;
2036
2409
  goto cleanup;
2037
2410
  }
@@ -2043,43 +2416,43 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
2043
2416
  * - a/b -> a/b/c
2044
2417
  * - a/b/c/d -> a/b/c
2045
2418
  */
2046
- if ((error = loose_path(&temp_path, git_buf_cstr(&temp_path), "temp_reflog")) < 0)
2419
+ if ((error = loose_path(&temp_path, git_str_cstr(&temp_path), "temp_reflog")) < 0)
2047
2420
  return error;
2048
2421
 
2049
- if ((fd = git_futils_mktmp(&temp_path, git_buf_cstr(&temp_path), GIT_REFLOG_FILE_MODE)) < 0) {
2422
+ if ((fd = git_futils_mktmp(&temp_path, git_str_cstr(&temp_path), GIT_REFLOG_FILE_MODE)) < 0) {
2050
2423
  error = -1;
2051
2424
  goto cleanup;
2052
2425
  }
2053
2426
 
2054
2427
  p_close(fd);
2055
2428
 
2056
- if (p_rename(git_buf_cstr(&old_path), git_buf_cstr(&temp_path)) < 0) {
2429
+ if (p_rename(git_str_cstr(&old_path), git_str_cstr(&temp_path)) < 0) {
2057
2430
  git_error_set(GIT_ERROR_OS, "failed to rename reflog for %s", new_name);
2058
2431
  error = -1;
2059
2432
  goto cleanup;
2060
2433
  }
2061
2434
 
2062
- if (git_path_isdir(git_buf_cstr(&new_path)) &&
2063
- (git_futils_rmdir_r(git_buf_cstr(&new_path), NULL, GIT_RMDIR_SKIP_NONEMPTY) < 0)) {
2435
+ if (git_fs_path_isdir(git_str_cstr(&new_path)) &&
2436
+ (git_futils_rmdir_r(git_str_cstr(&new_path), NULL, GIT_RMDIR_SKIP_NONEMPTY) < 0)) {
2064
2437
  error = -1;
2065
2438
  goto cleanup;
2066
2439
  }
2067
2440
 
2068
- if (git_futils_mkpath2file(git_buf_cstr(&new_path), GIT_REFLOG_DIR_MODE) < 0) {
2441
+ if (git_futils_mkpath2file(git_str_cstr(&new_path), GIT_REFLOG_DIR_MODE) < 0) {
2069
2442
  error = -1;
2070
2443
  goto cleanup;
2071
2444
  }
2072
2445
 
2073
- if (p_rename(git_buf_cstr(&temp_path), git_buf_cstr(&new_path)) < 0) {
2446
+ if (p_rename(git_str_cstr(&temp_path), git_str_cstr(&new_path)) < 0) {
2074
2447
  git_error_set(GIT_ERROR_OS, "failed to rename reflog for %s", new_name);
2075
2448
  error = -1;
2076
2449
  }
2077
2450
 
2078
2451
  cleanup:
2079
- git_buf_dispose(&temp_path);
2080
- git_buf_dispose(&old_path);
2081
- git_buf_dispose(&new_path);
2082
- git_buf_dispose(&normalized);
2452
+ git_str_dispose(&temp_path);
2453
+ git_str_dispose(&old_path);
2454
+ git_str_dispose(&new_path);
2455
+ git_str_dispose(&normalized);
2083
2456
 
2084
2457
  return error;
2085
2458
  }
@@ -2087,7 +2460,7 @@ cleanup:
2087
2460
  static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name)
2088
2461
  {
2089
2462
  refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
2090
- git_buf path = GIT_BUF_INIT;
2463
+ git_str path = GIT_STR_INIT;
2091
2464
  int error;
2092
2465
 
2093
2466
  GIT_ASSERT_ARG(_backend);
@@ -2096,7 +2469,12 @@ static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name
2096
2469
  if ((error = reflog_path(&path, backend->repo, name)) < 0)
2097
2470
  goto out;
2098
2471
 
2099
- if (!git_path_exists(path.ptr))
2472
+ /*
2473
+ * If a reference was moved downwards, eg refs/heads/br2 -> refs/heads/br2/new-name,
2474
+ * refs/heads/br2 does exist but it's a directory. That's a valid situation.
2475
+ * Proceed only if it's a file.
2476
+ */
2477
+ if (!git_fs_path_isfile(path.ptr))
2100
2478
  goto out;
2101
2479
 
2102
2480
  if ((error = p_unlink(path.ptr)) < 0)
@@ -2105,7 +2483,7 @@ static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name
2105
2483
  error = refdb_fs_backend__prune_refs(backend, name, GIT_REFLOG_DIR);
2106
2484
 
2107
2485
  out:
2108
- git_buf_dispose(&path);
2486
+ git_str_dispose(&path);
2109
2487
 
2110
2488
  return error;
2111
2489
  }
@@ -2115,16 +2493,22 @@ int git_refdb_backend_fs(
2115
2493
  git_repository *repository)
2116
2494
  {
2117
2495
  int t = 0;
2118
- git_buf gitpath = GIT_BUF_INIT;
2496
+ git_str gitpath = GIT_STR_INIT;
2119
2497
  refdb_fs_backend *backend;
2120
2498
 
2121
2499
  backend = git__calloc(1, sizeof(refdb_fs_backend));
2122
2500
  GIT_ERROR_CHECK_ALLOC(backend);
2501
+ if (git_mutex_init(&backend->prlock) < 0) {
2502
+ git__free(backend);
2503
+ return -1;
2504
+ }
2505
+
2123
2506
 
2124
2507
  if (git_refdb_init_backend(&backend->parent, GIT_REFDB_BACKEND_VERSION) < 0)
2125
2508
  goto fail;
2126
2509
 
2127
2510
  backend->repo = repository;
2511
+ backend->oid_type = repository->oid_type;
2128
2512
 
2129
2513
  if (repository->gitdir) {
2130
2514
  backend->gitpath = setup_namespace(repository, repository->gitdir);
@@ -2140,21 +2524,21 @@ int git_refdb_backend_fs(
2140
2524
  goto fail;
2141
2525
  }
2142
2526
 
2143
- if (git_buf_joinpath(&gitpath, backend->commonpath, GIT_PACKEDREFS_FILE) < 0 ||
2527
+ if (git_str_joinpath(&gitpath, backend->commonpath, GIT_PACKEDREFS_FILE) < 0 ||
2144
2528
  git_sortedcache_new(
2145
2529
  &backend->refcache, offsetof(struct packref, name),
2146
- NULL, NULL, packref_cmp, git_buf_cstr(&gitpath)) < 0)
2530
+ NULL, NULL, packref_cmp, git_str_cstr(&gitpath)) < 0)
2147
2531
  goto fail;
2148
2532
 
2149
- git_buf_dispose(&gitpath);
2533
+ git_str_dispose(&gitpath);
2150
2534
 
2151
2535
  if (!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_IGNORECASE) && t) {
2152
2536
  backend->iterator_flags |= GIT_ITERATOR_IGNORE_CASE;
2153
- backend->direach_flags |= GIT_PATH_DIR_IGNORE_CASE;
2537
+ backend->direach_flags |= GIT_FS_PATH_DIR_IGNORE_CASE;
2154
2538
  }
2155
2539
  if (!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_PRECOMPOSE) && t) {
2156
2540
  backend->iterator_flags |= GIT_ITERATOR_PRECOMPOSE_UNICODE;
2157
- backend->direach_flags |= GIT_PATH_DIR_PRECOMPOSE_UNICODE;
2541
+ backend->direach_flags |= GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE;
2158
2542
  }
2159
2543
  if ((!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_FSYNCOBJECTFILES) && t) ||
2160
2544
  git_repository__fsync_gitdir)
@@ -2182,7 +2566,8 @@ int git_refdb_backend_fs(
2182
2566
  return 0;
2183
2567
 
2184
2568
  fail:
2185
- git_buf_dispose(&gitpath);
2569
+ git_mutex_free(&backend->prlock);
2570
+ git_str_dispose(&gitpath);
2186
2571
  git__free(backend->gitpath);
2187
2572
  git__free(backend->commonpath);
2188
2573
  git__free(backend);