rugged 1.3.2 → 1.6.2

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 (547) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -2
  3. data/ext/rugged/extconf.rb +7 -4
  4. data/ext/rugged/rugged.c +16 -0
  5. data/ext/rugged/rugged.h +4 -0
  6. data/ext/rugged/rugged_blame.c +2 -0
  7. data/ext/rugged/rugged_blob.c +3 -0
  8. data/ext/rugged/rugged_commit.c +1 -0
  9. data/ext/rugged/rugged_config.c +9 -2
  10. data/ext/rugged/rugged_diff.c +1 -0
  11. data/ext/rugged/rugged_index.c +2 -0
  12. data/ext/rugged/rugged_patch.c +1 -0
  13. data/ext/rugged/rugged_rebase.c +1 -0
  14. data/ext/rugged/rugged_reference.c +1 -0
  15. data/ext/rugged/rugged_remote.c +28 -10
  16. data/ext/rugged/rugged_repo.c +7 -9
  17. data/ext/rugged/rugged_revwalk.c +5 -1
  18. data/ext/rugged/rugged_settings.c +5 -0
  19. data/ext/rugged/rugged_submodule.c +1 -0
  20. data/ext/rugged/rugged_tag.c +1 -0
  21. data/ext/rugged/rugged_tree.c +4 -0
  22. data/lib/rugged/index.rb +1 -1
  23. data/lib/rugged/tree.rb +5 -1
  24. data/lib/rugged/version.rb +1 -1
  25. data/vendor/libgit2/CMakeLists.txt +132 -288
  26. data/vendor/libgit2/COPYING +106 -19
  27. data/vendor/libgit2/cmake/AddCFlagIfSupported.cmake +21 -21
  28. data/vendor/libgit2/cmake/AddClarTest.cmake +7 -0
  29. data/vendor/libgit2/cmake/DefaultCFlags.cmake +154 -0
  30. data/vendor/libgit2/cmake/EnableWarnings.cmake +13 -13
  31. data/vendor/libgit2/cmake/ExperimentalFeatures.cmake +23 -0
  32. data/vendor/libgit2/cmake/FindCoreFoundation.cmake +13 -13
  33. data/vendor/libgit2/cmake/FindGSSAPI.cmake +171 -287
  34. data/vendor/libgit2/cmake/FindGSSFramework.cmake +13 -13
  35. data/vendor/libgit2/cmake/{FindHTTP_Parser.cmake → FindHTTPParser.cmake} +17 -17
  36. data/vendor/libgit2/cmake/FindIconv.cmake +27 -27
  37. data/vendor/libgit2/cmake/FindLibSSH2.cmake +5 -5
  38. data/vendor/libgit2/cmake/FindPCRE.cmake +12 -13
  39. data/vendor/libgit2/cmake/FindPCRE2.cmake +12 -12
  40. data/vendor/libgit2/cmake/FindPkgLibraries.cmake +19 -19
  41. data/vendor/libgit2/cmake/FindSecurity.cmake +14 -14
  42. data/vendor/libgit2/cmake/FindStatNsec.cmake +12 -18
  43. data/vendor/libgit2/cmake/Findfutimens.cmake +8 -8
  44. data/vendor/libgit2/cmake/FindmbedTLS.cmake +63 -70
  45. data/vendor/libgit2/cmake/IdeSplitSources.cmake +18 -18
  46. data/vendor/libgit2/cmake/PkgBuildConfig.cmake +60 -60
  47. data/vendor/libgit2/cmake/SanitizeBool.cmake +20 -20
  48. data/vendor/libgit2/cmake/SelectGSSAPI.cmake +37 -37
  49. data/vendor/libgit2/cmake/SelectHTTPParser.cmake +19 -0
  50. data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +100 -100
  51. data/vendor/libgit2/cmake/SelectHashes.cmake +91 -53
  52. data/vendor/libgit2/cmake/SelectRegex.cmake +51 -0
  53. data/vendor/libgit2/cmake/SelectSSH.cmake +41 -0
  54. data/vendor/libgit2/cmake/SelectWinHTTP.cmake +17 -0
  55. data/vendor/libgit2/cmake/SelectZlib.cmake +34 -0
  56. data/vendor/libgit2/deps/chromium-zlib/CMakeLists.txt +6 -6
  57. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +33 -31
  58. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +3 -1
  59. data/vendor/libgit2/deps/ntlmclient/ntlm.c +4 -4
  60. data/vendor/libgit2/deps/ntlmclient/ntlm.h +4 -4
  61. data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +2 -2
  62. data/vendor/libgit2/deps/pcre/CMakeLists.txt +88 -88
  63. data/vendor/libgit2/deps/winhttp/CMakeLists.txt +14 -16
  64. data/vendor/libgit2/deps/zlib/adler32.c +7 -0
  65. data/vendor/libgit2/deps/zlib/crc32.c +975 -288
  66. data/vendor/libgit2/deps/zlib/crc32.h +9441 -436
  67. data/vendor/libgit2/deps/zlib/deflate.c +83 -31
  68. data/vendor/libgit2/deps/zlib/deflate.h +12 -15
  69. data/vendor/libgit2/deps/zlib/gzguts.h +3 -2
  70. data/vendor/libgit2/deps/zlib/infback.c +2 -1
  71. data/vendor/libgit2/deps/zlib/inffast.c +14 -14
  72. data/vendor/libgit2/deps/zlib/inflate.c +39 -8
  73. data/vendor/libgit2/deps/zlib/inflate.h +3 -2
  74. data/vendor/libgit2/deps/zlib/inftrees.c +3 -3
  75. data/vendor/libgit2/deps/zlib/trees.c +27 -48
  76. data/vendor/libgit2/deps/zlib/zlib.h +126 -100
  77. data/vendor/libgit2/deps/zlib/zutil.c +2 -2
  78. data/vendor/libgit2/deps/zlib/zutil.h +12 -9
  79. data/vendor/libgit2/include/git2/apply.h +16 -2
  80. data/vendor/libgit2/include/git2/attr.h +11 -2
  81. data/vendor/libgit2/include/git2/blame.h +4 -1
  82. data/vendor/libgit2/include/git2/blob.h +14 -1
  83. data/vendor/libgit2/include/git2/branch.h +4 -2
  84. data/vendor/libgit2/include/git2/buffer.h +18 -78
  85. data/vendor/libgit2/include/git2/cert.h +2 -2
  86. data/vendor/libgit2/include/git2/checkout.h +5 -2
  87. data/vendor/libgit2/include/git2/clone.h +3 -3
  88. data/vendor/libgit2/include/git2/commit.h +2 -0
  89. data/vendor/libgit2/include/git2/common.h +28 -7
  90. data/vendor/libgit2/include/git2/config.h +25 -9
  91. data/vendor/libgit2/include/git2/credential.h +2 -1
  92. data/vendor/libgit2/include/git2/credential_helpers.h +1 -0
  93. data/vendor/libgit2/include/git2/deprecated.h +9 -1
  94. data/vendor/libgit2/include/git2/describe.h +7 -2
  95. data/vendor/libgit2/include/git2/diff.h +18 -10
  96. data/vendor/libgit2/include/git2/email.h +1 -1
  97. data/vendor/libgit2/include/git2/errors.h +17 -3
  98. data/vendor/libgit2/include/git2/experimental.h +20 -0
  99. data/vendor/libgit2/include/git2/filter.h +7 -2
  100. data/vendor/libgit2/include/git2/graph.h +1 -0
  101. data/vendor/libgit2/include/git2/ignore.h +1 -1
  102. data/vendor/libgit2/include/git2/index.h +11 -5
  103. data/vendor/libgit2/include/git2/indexer.h +48 -0
  104. data/vendor/libgit2/include/git2/merge.h +24 -4
  105. data/vendor/libgit2/include/git2/message.h +2 -0
  106. data/vendor/libgit2/include/git2/object.h +49 -0
  107. data/vendor/libgit2/include/git2/odb.h +94 -13
  108. data/vendor/libgit2/include/git2/odb_backend.h +107 -19
  109. data/vendor/libgit2/include/git2/oid.h +115 -15
  110. data/vendor/libgit2/include/git2/pack.h +24 -8
  111. data/vendor/libgit2/include/git2/patch.h +8 -0
  112. data/vendor/libgit2/include/git2/pathspec.h +1 -1
  113. data/vendor/libgit2/include/git2/proxy.h +1 -1
  114. data/vendor/libgit2/include/git2/rebase.h +9 -1
  115. data/vendor/libgit2/include/git2/refdb.h +3 -0
  116. data/vendor/libgit2/include/git2/reflog.h +1 -1
  117. data/vendor/libgit2/include/git2/refs.h +2 -2
  118. data/vendor/libgit2/include/git2/remote.h +184 -37
  119. data/vendor/libgit2/include/git2/repository.h +34 -10
  120. data/vendor/libgit2/include/git2/reset.h +2 -2
  121. data/vendor/libgit2/include/git2/revparse.h +1 -1
  122. data/vendor/libgit2/include/git2/revwalk.h +4 -1
  123. data/vendor/libgit2/include/git2/signature.h +1 -1
  124. data/vendor/libgit2/include/git2/stash.h +61 -7
  125. data/vendor/libgit2/include/git2/status.h +14 -5
  126. data/vendor/libgit2/include/git2/strarray.h +0 -13
  127. data/vendor/libgit2/include/git2/submodule.h +7 -2
  128. data/vendor/libgit2/include/git2/sys/commit_graph.h +1 -1
  129. data/vendor/libgit2/include/git2/sys/odb_backend.h +3 -6
  130. data/vendor/libgit2/include/git2/sys/remote.h +46 -0
  131. data/vendor/libgit2/include/git2/sys/stream.h +1 -1
  132. data/vendor/libgit2/include/git2/sys/transport.h +46 -39
  133. data/vendor/libgit2/include/git2/tag.h +1 -0
  134. data/vendor/libgit2/include/git2/tree.h +4 -3
  135. data/vendor/libgit2/include/git2/types.h +7 -7
  136. data/vendor/libgit2/include/git2/version.h +27 -6
  137. data/vendor/libgit2/include/git2/worktree.h +12 -2
  138. data/vendor/libgit2/include/git2.h +1 -0
  139. data/vendor/libgit2/src/CMakeLists.txt +177 -419
  140. data/vendor/libgit2/src/README.md +12 -0
  141. data/vendor/libgit2/src/cli/CMakeLists.txt +57 -0
  142. data/vendor/libgit2/src/cli/README.md +26 -0
  143. data/vendor/libgit2/src/cli/cli.h +20 -0
  144. data/vendor/libgit2/src/cli/cmd.c +21 -0
  145. data/vendor/libgit2/src/cli/cmd.h +33 -0
  146. data/vendor/libgit2/src/cli/cmd_cat_file.c +204 -0
  147. data/vendor/libgit2/src/cli/cmd_clone.c +176 -0
  148. data/vendor/libgit2/src/cli/cmd_hash_object.c +154 -0
  149. data/vendor/libgit2/src/cli/cmd_help.c +86 -0
  150. data/vendor/libgit2/src/cli/error.h +51 -0
  151. data/vendor/libgit2/src/cli/main.c +106 -0
  152. data/vendor/libgit2/src/cli/opt.c +669 -0
  153. data/vendor/libgit2/src/cli/opt.h +349 -0
  154. data/vendor/libgit2/src/cli/opt_usage.c +194 -0
  155. data/vendor/libgit2/src/cli/opt_usage.h +35 -0
  156. data/vendor/libgit2/src/cli/progress.c +345 -0
  157. data/vendor/libgit2/src/cli/progress.h +117 -0
  158. data/vendor/libgit2/src/cli/sighandler.h +20 -0
  159. data/vendor/libgit2/src/cli/unix/sighandler.c +36 -0
  160. data/vendor/libgit2/src/cli/win32/precompiled.h +3 -0
  161. data/vendor/libgit2/src/cli/win32/sighandler.c +37 -0
  162. data/vendor/libgit2/src/libgit2/CMakeLists.txt +141 -0
  163. data/vendor/libgit2/src/{annotated_commit.c → libgit2/annotated_commit.c} +1 -1
  164. data/vendor/libgit2/src/{annotated_commit.h → libgit2/annotated_commit.h} +2 -2
  165. data/vendor/libgit2/src/{apply.c → libgit2/apply.c} +18 -18
  166. data/vendor/libgit2/src/{apply.h → libgit2/apply.h} +2 -2
  167. data/vendor/libgit2/src/{attr.c → libgit2/attr.c} +18 -18
  168. data/vendor/libgit2/src/{attr_file.c → libgit2/attr_file.c} +18 -18
  169. data/vendor/libgit2/src/{attr_file.h → libgit2/attr_file.h} +4 -4
  170. data/vendor/libgit2/src/{attrcache.c → libgit2/attrcache.c} +18 -13
  171. data/vendor/libgit2/src/{blame.c → libgit2/blame.c} +2 -0
  172. data/vendor/libgit2/src/{blame_git.c → libgit2/blame_git.c} +1 -1
  173. data/vendor/libgit2/src/{blob.c → libgit2/blob.c} +38 -29
  174. data/vendor/libgit2/src/{blob.h → libgit2/blob.h} +3 -3
  175. data/vendor/libgit2/src/{branch.c → libgit2/branch.c} +164 -118
  176. data/vendor/libgit2/src/{branch.h → libgit2/branch.h} +15 -3
  177. data/vendor/libgit2/src/libgit2/buf.c +126 -0
  178. data/vendor/libgit2/src/libgit2/buf.h +50 -0
  179. data/vendor/libgit2/src/{checkout.c → libgit2/checkout.c} +74 -68
  180. data/vendor/libgit2/src/{cherrypick.c → libgit2/cherrypick.c} +13 -13
  181. data/vendor/libgit2/src/{clone.c → libgit2/clone.c} +96 -67
  182. data/vendor/libgit2/src/{commit.c → libgit2/commit.c} +178 -73
  183. data/vendor/libgit2/src/libgit2/commit.h +87 -0
  184. data/vendor/libgit2/src/{commit_graph.c → libgit2/commit_graph.c} +122 -89
  185. data/vendor/libgit2/src/{commit_graph.h → libgit2/commit_graph.h} +14 -4
  186. data/vendor/libgit2/src/{commit_list.c → libgit2/commit_list.c} +7 -4
  187. data/vendor/libgit2/src/libgit2/common.h +55 -0
  188. data/vendor/libgit2/src/{config.c → libgit2/config.c} +101 -69
  189. data/vendor/libgit2/src/{config.h → libgit2/config.h} +15 -2
  190. data/vendor/libgit2/src/{config_file.c → libgit2/config_file.c} +105 -93
  191. data/vendor/libgit2/src/{config_mem.c → libgit2/config_mem.c} +9 -9
  192. data/vendor/libgit2/src/{config_parse.c → libgit2/config_parse.c} +27 -23
  193. data/vendor/libgit2/src/{crlf.c → libgit2/crlf.c} +24 -21
  194. data/vendor/libgit2/src/{describe.c → libgit2/describe.c} +35 -27
  195. data/vendor/libgit2/src/{diff.c → libgit2/diff.c} +30 -9
  196. data/vendor/libgit2/src/{diff.h → libgit2/diff.h} +2 -4
  197. data/vendor/libgit2/src/{diff_driver.c → libgit2/diff_driver.c} +34 -36
  198. data/vendor/libgit2/src/{diff_driver.h → libgit2/diff_driver.h} +3 -3
  199. data/vendor/libgit2/src/{diff_file.c → libgit2/diff_file.c} +44 -26
  200. data/vendor/libgit2/src/{diff_generate.c → libgit2/diff_generate.c} +47 -18
  201. data/vendor/libgit2/src/{diff_generate.h → libgit2/diff_generate.h} +5 -3
  202. data/vendor/libgit2/src/{diff_print.c → libgit2/diff_print.c} +112 -100
  203. data/vendor/libgit2/src/{diff_stats.c → libgit2/diff_stats.c} +40 -29
  204. data/vendor/libgit2/src/libgit2/diff_stats.h +18 -0
  205. data/vendor/libgit2/src/{diff_tform.c → libgit2/diff_tform.c} +13 -8
  206. data/vendor/libgit2/src/{diff_xdiff.c → libgit2/diff_xdiff.c} +4 -8
  207. data/vendor/libgit2/src/{email.c → libgit2/email.c} +55 -39
  208. data/vendor/libgit2/src/{email.h → libgit2/email.h} +1 -1
  209. data/vendor/libgit2/src/{errors.c → libgit2/errors.c} +18 -18
  210. data/vendor/libgit2/src/{errors.h → libgit2/errors.h} +1 -2
  211. data/vendor/libgit2/src/libgit2/experimental.h.in +13 -0
  212. data/vendor/libgit2/src/{fetch.c → libgit2/fetch.c} +72 -27
  213. data/vendor/libgit2/src/{fetch.h → libgit2/fetch.h} +1 -1
  214. data/vendor/libgit2/src/{fetchhead.c → libgit2/fetchhead.c} +23 -23
  215. data/vendor/libgit2/src/{filter.c → libgit2/filter.c} +127 -53
  216. data/vendor/libgit2/src/{filter.h → libgit2/filter.h} +26 -5
  217. data/vendor/libgit2/src/{ident.c → libgit2/ident.c} +20 -20
  218. data/vendor/libgit2/src/{ignore.c → libgit2/ignore.c} +35 -34
  219. data/vendor/libgit2/src/{ignore.h → libgit2/ignore.h} +2 -2
  220. data/vendor/libgit2/src/{index.c → libgit2/index.c} +91 -90
  221. data/vendor/libgit2/src/{index.h → libgit2/index.h} +6 -3
  222. data/vendor/libgit2/src/{indexer.c → libgit2/indexer.c} +173 -92
  223. data/vendor/libgit2/src/{iterator.c → libgit2/iterator.c} +71 -61
  224. data/vendor/libgit2/src/{iterator.h → libgit2/iterator.h} +5 -5
  225. data/vendor/libgit2/src/{libgit2.c → libgit2/libgit2.c} +46 -11
  226. data/vendor/libgit2/src/{mailmap.c → libgit2/mailmap.c} +38 -36
  227. data/vendor/libgit2/src/{merge.c → libgit2/merge.c} +30 -30
  228. data/vendor/libgit2/src/{merge.h → libgit2/merge.h} +1 -14
  229. data/vendor/libgit2/src/{merge_driver.c → libgit2/merge_driver.c} +2 -2
  230. data/vendor/libgit2/src/{merge_file.c → libgit2/merge_file.c} +13 -3
  231. data/vendor/libgit2/src/{message.c → libgit2/message.c} +21 -10
  232. data/vendor/libgit2/src/{midx.c → libgit2/midx.c} +112 -92
  233. data/vendor/libgit2/src/{midx.h → libgit2/midx.h} +5 -4
  234. data/vendor/libgit2/src/{mwindow.c → libgit2/mwindow.c} +15 -12
  235. data/vendor/libgit2/src/{mwindow.h → libgit2/mwindow.h} +5 -2
  236. data/vendor/libgit2/src/{netops.c → libgit2/netops.c} +1 -2
  237. data/vendor/libgit2/src/{netops.h → libgit2/netops.h} +1 -1
  238. data/vendor/libgit2/src/{notes.c → libgit2/notes.c} +25 -34
  239. data/vendor/libgit2/src/{object.c → libgit2/object.c} +135 -30
  240. data/vendor/libgit2/src/{object.h → libgit2/object.h} +12 -3
  241. data/vendor/libgit2/src/{odb.c → libgit2/odb.c} +228 -81
  242. data/vendor/libgit2/src/{odb.h → libgit2/odb.h} +44 -5
  243. data/vendor/libgit2/src/{odb_loose.c → libgit2/odb_loose.c} +192 -134
  244. data/vendor/libgit2/src/{odb_mempack.c → libgit2/odb_mempack.c} +18 -5
  245. data/vendor/libgit2/src/{odb_pack.c → libgit2/odb_pack.c} +137 -85
  246. data/vendor/libgit2/src/{oid.c → libgit2/oid.c} +136 -90
  247. data/vendor/libgit2/src/libgit2/oid.h +273 -0
  248. data/vendor/libgit2/src/{oidmap.c → libgit2/oidmap.c} +1 -1
  249. data/vendor/libgit2/src/{pack-objects.c → libgit2/pack-objects.c} +56 -30
  250. data/vendor/libgit2/src/{pack-objects.h → libgit2/pack-objects.h} +11 -6
  251. data/vendor/libgit2/src/{pack.c → libgit2/pack.c} +114 -84
  252. data/vendor/libgit2/src/{pack.h → libgit2/pack.h} +31 -16
  253. data/vendor/libgit2/src/{parse.c → libgit2/parse.c} +4 -3
  254. data/vendor/libgit2/src/{patch.c → libgit2/patch.c} +3 -3
  255. data/vendor/libgit2/src/{patch.h → libgit2/patch.h} +1 -0
  256. data/vendor/libgit2/src/{patch_generate.c → libgit2/patch_generate.c} +27 -11
  257. data/vendor/libgit2/src/{patch_generate.h → libgit2/patch_generate.h} +5 -5
  258. data/vendor/libgit2/src/{patch_parse.c → libgit2/patch_parse.c} +29 -29
  259. data/vendor/libgit2/src/libgit2/path.c +375 -0
  260. data/vendor/libgit2/src/libgit2/path.h +68 -0
  261. data/vendor/libgit2/src/{pathspec.c → libgit2/pathspec.c} +6 -6
  262. data/vendor/libgit2/src/{pathspec.h → libgit2/pathspec.h} +2 -2
  263. data/vendor/libgit2/src/{proxy.c → libgit2/proxy.c} +4 -1
  264. data/vendor/libgit2/src/{proxy.h → libgit2/proxy.h} +1 -1
  265. data/vendor/libgit2/src/{push.c → libgit2/push.c} +43 -38
  266. data/vendor/libgit2/src/{push.h → libgit2/push.h} +4 -16
  267. data/vendor/libgit2/src/{reader.c → libgit2/reader.c} +9 -9
  268. data/vendor/libgit2/src/{reader.h → libgit2/reader.h} +2 -2
  269. data/vendor/libgit2/src/{rebase.c → libgit2/rebase.c} +119 -107
  270. data/vendor/libgit2/src/{refdb_fs.c → libgit2/refdb_fs.c} +506 -197
  271. data/vendor/libgit2/src/{reflog.c → libgit2/reflog.c} +7 -5
  272. data/vendor/libgit2/src/{reflog.h → libgit2/reflog.h} +1 -2
  273. data/vendor/libgit2/src/{refs.c → libgit2/refs.c} +34 -32
  274. data/vendor/libgit2/src/{refs.h → libgit2/refs.h} +2 -2
  275. data/vendor/libgit2/src/{refspec.c → libgit2/refspec.c} +32 -37
  276. data/vendor/libgit2/src/{refspec.h → libgit2/refspec.h} +5 -2
  277. data/vendor/libgit2/src/{remote.c → libgit2/remote.c} +718 -420
  278. data/vendor/libgit2/src/libgit2/remote.h +100 -0
  279. data/vendor/libgit2/src/{repository.c → libgit2/repository.c} +629 -386
  280. data/vendor/libgit2/src/{repository.h → libgit2/repository.h} +20 -9
  281. data/vendor/libgit2/src/{reset.c → libgit2/reset.c} +8 -5
  282. data/vendor/libgit2/src/{revert.c → libgit2/revert.c} +14 -14
  283. data/vendor/libgit2/src/{revparse.c → libgit2/revparse.c} +71 -42
  284. data/vendor/libgit2/src/{revwalk.c → libgit2/revwalk.c} +12 -8
  285. data/vendor/libgit2/src/{signature.c → libgit2/signature.c} +12 -6
  286. data/vendor/libgit2/src/{signature.h → libgit2/signature.h} +1 -1
  287. data/vendor/libgit2/src/{stash.c → libgit2/stash.c} +235 -61
  288. data/vendor/libgit2/src/{status.c → libgit2/status.c} +4 -1
  289. data/vendor/libgit2/src/{strarray.c → libgit2/strarray.c} +1 -0
  290. data/vendor/libgit2/src/libgit2/strarray.h +25 -0
  291. data/vendor/libgit2/src/{streams → libgit2/streams}/mbedtls.c +8 -6
  292. data/vendor/libgit2/src/{streams → libgit2/streams}/openssl.c +1 -1
  293. data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_dynamic.c +7 -3
  294. data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_dynamic.h +3 -3
  295. data/vendor/libgit2/src/{streams → libgit2/streams}/socket.c +4 -1
  296. data/vendor/libgit2/src/{submodule.c → libgit2/submodule.c} +177 -161
  297. data/vendor/libgit2/src/{submodule.h → libgit2/submodule.h} +1 -1
  298. data/vendor/libgit2/src/libgit2/sysdir.c +650 -0
  299. data/vendor/libgit2/src/{sysdir.h → libgit2/sysdir.h} +53 -18
  300. data/vendor/libgit2/src/{tag.c → libgit2/tag.c} +73 -42
  301. data/vendor/libgit2/src/{tag.h → libgit2/tag.h} +2 -2
  302. data/vendor/libgit2/src/{threadstate.c → libgit2/threadstate.c} +3 -3
  303. data/vendor/libgit2/src/{threadstate.h → libgit2/threadstate.h} +2 -2
  304. data/vendor/libgit2/src/{trace.c → libgit2/trace.c} +1 -14
  305. data/vendor/libgit2/src/{trace.h → libgit2/trace.h} +5 -22
  306. data/vendor/libgit2/src/{trailer.c → libgit2/trailer.c} +1 -1
  307. data/vendor/libgit2/src/{transaction.c → libgit2/transaction.c} +1 -1
  308. data/vendor/libgit2/src/{transport.c → libgit2/transport.c} +10 -10
  309. data/vendor/libgit2/src/{transports → libgit2/transports}/auth.c +7 -9
  310. data/vendor/libgit2/src/{transports → libgit2/transports}/auth.h +2 -3
  311. data/vendor/libgit2/src/{transports → libgit2/transports}/auth_negotiate.c +12 -13
  312. data/vendor/libgit2/src/{transports → libgit2/transports}/auth_ntlm.c +10 -10
  313. data/vendor/libgit2/src/{transports → libgit2/transports}/auth_ntlm.h +0 -1
  314. data/vendor/libgit2/src/{transports → libgit2/transports}/git.c +9 -11
  315. data/vendor/libgit2/src/{transports → libgit2/transports}/http.c +41 -20
  316. data/vendor/libgit2/src/{transports → libgit2/transports}/http.h +2 -3
  317. data/vendor/libgit2/src/{transports → libgit2/transports}/httpclient.c +75 -66
  318. data/vendor/libgit2/src/{transports → libgit2/transports}/httpclient.h +10 -0
  319. data/vendor/libgit2/src/{transports → libgit2/transports}/local.c +138 -116
  320. data/vendor/libgit2/src/{transports → libgit2/transports}/smart.c +92 -133
  321. data/vendor/libgit2/src/{transports → libgit2/transports}/smart.h +35 -32
  322. data/vendor/libgit2/src/{transports → libgit2/transports}/smart_pkt.c +177 -65
  323. data/vendor/libgit2/src/{transports → libgit2/transports}/smart_protocol.c +97 -49
  324. data/vendor/libgit2/src/{transports → libgit2/transports}/ssh.c +365 -198
  325. data/vendor/libgit2/src/{transports → libgit2/transports}/winhttp.c +58 -59
  326. data/vendor/libgit2/src/{tree-cache.c → libgit2/tree-cache.c} +8 -8
  327. data/vendor/libgit2/src/{tree-cache.h → libgit2/tree-cache.h} +2 -2
  328. data/vendor/libgit2/src/{tree.c → libgit2/tree.c} +93 -83
  329. data/vendor/libgit2/src/{tree.h → libgit2/tree.h} +4 -4
  330. data/vendor/libgit2/src/{worktree.c → libgit2/worktree.c} +121 -94
  331. data/vendor/libgit2/src/{worktree.h → libgit2/worktree.h} +1 -1
  332. data/vendor/libgit2/src/libgit2/xdiff/git-xdiff.h +53 -0
  333. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xdiff.h +15 -15
  334. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xdiffi.c +134 -108
  335. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xemit.c +23 -7
  336. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xhistogram.c +87 -78
  337. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xinclude.h +1 -12
  338. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xmerge.c +104 -117
  339. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xpatience.c +6 -17
  340. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xprepare.c +15 -20
  341. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xutils.c +18 -7
  342. data/vendor/libgit2/src/util/CMakeLists.txt +80 -0
  343. data/vendor/libgit2/src/{allocators → util/allocators}/failalloc.h +1 -1
  344. data/vendor/libgit2/src/{allocators → util/allocators}/stdalloc.h +1 -1
  345. data/vendor/libgit2/src/{allocators → util/allocators}/win32_leakcheck.h +1 -1
  346. data/vendor/libgit2/src/{array.h → util/array.h} +1 -1
  347. data/vendor/libgit2/src/{assert_safe.h → util/assert_safe.h} +16 -0
  348. data/vendor/libgit2/src/{cc-compat.h → util/cc-compat.h} +1 -1
  349. data/vendor/libgit2/src/{date.c → util/date.c} +14 -20
  350. data/vendor/libgit2/src/util/date.h +33 -0
  351. data/vendor/libgit2/src/{filebuf.c → util/filebuf.c} +29 -29
  352. data/vendor/libgit2/src/{filebuf.h → util/filebuf.h} +2 -2
  353. data/vendor/libgit2/src/{path.c → util/fs_path.c} +453 -647
  354. data/vendor/libgit2/src/{path.h → util/fs_path.h} +221 -188
  355. data/vendor/libgit2/src/{futils.c → util/futils.c} +135 -90
  356. data/vendor/libgit2/src/{futils.h → util/futils.h} +28 -15
  357. data/vendor/libgit2/src/{features.h.in → util/git2_features.h.in} +15 -1
  358. data/vendor/libgit2/src/{common.h → util/git2_util.h} +20 -59
  359. data/vendor/libgit2/src/util/hash/builtin.c +53 -0
  360. data/vendor/libgit2/src/{hash/sha1/openssl.h → util/hash/builtin.h} +6 -6
  361. data/vendor/libgit2/src/{hash/sha1 → util/hash}/collisiondetect.c +3 -3
  362. data/vendor/libgit2/src/{hash/sha1 → util/hash}/collisiondetect.h +3 -3
  363. data/vendor/libgit2/src/util/hash/common_crypto.c +112 -0
  364. data/vendor/libgit2/src/{hash/sha1 → util/hash}/common_crypto.h +11 -3
  365. data/vendor/libgit2/src/util/hash/mbedtls.c +92 -0
  366. data/vendor/libgit2/src/{hash/sha1 → util/hash}/mbedtls.h +14 -4
  367. data/vendor/libgit2/src/util/hash/openssl.c +195 -0
  368. data/vendor/libgit2/src/util/hash/openssl.h +45 -0
  369. data/vendor/libgit2/src/util/hash/rfc6234/sha.h +243 -0
  370. data/vendor/libgit2/src/util/hash/rfc6234/sha224-256.c +601 -0
  371. data/vendor/libgit2/src/util/hash/sha.h +70 -0
  372. data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/sha1.c +1 -1
  373. data/vendor/libgit2/src/util/hash/win32.c +549 -0
  374. data/vendor/libgit2/src/util/hash/win32.h +60 -0
  375. data/vendor/libgit2/src/util/hash.c +158 -0
  376. data/vendor/libgit2/src/util/hash.h +61 -0
  377. data/vendor/libgit2/src/{khash.h → util/khash.h} +1 -1
  378. data/vendor/libgit2/src/{map.h → util/map.h} +1 -1
  379. data/vendor/libgit2/src/util/net.c +1003 -0
  380. data/vendor/libgit2/src/{net.h → util/net.h} +18 -4
  381. data/vendor/libgit2/src/{pool.h → util/pool.h} +1 -1
  382. data/vendor/libgit2/src/{posix.c → util/posix.c} +3 -3
  383. data/vendor/libgit2/src/{posix.h → util/posix.h} +4 -1
  384. data/vendor/libgit2/src/{pqueue.h → util/pqueue.h} +2 -2
  385. data/vendor/libgit2/src/util/rand.c +234 -0
  386. data/vendor/libgit2/src/util/rand.h +37 -0
  387. data/vendor/libgit2/src/{regexp.c → util/regexp.c} +4 -4
  388. data/vendor/libgit2/src/{regexp.h → util/regexp.h} +1 -1
  389. data/vendor/libgit2/src/{runtime.c → util/runtime.c} +1 -1
  390. data/vendor/libgit2/src/{runtime.h → util/runtime.h} +1 -1
  391. data/vendor/libgit2/src/{sortedcache.c → util/sortedcache.c} +1 -1
  392. data/vendor/libgit2/src/{sortedcache.h → util/sortedcache.h} +2 -2
  393. data/vendor/libgit2/src/{buffer.c → util/str.c} +157 -151
  394. data/vendor/libgit2/src/util/str.h +357 -0
  395. data/vendor/libgit2/src/{strmap.h → util/strmap.h} +1 -1
  396. data/vendor/libgit2/src/{thread.c → util/thread.c} +1 -1
  397. data/vendor/libgit2/src/{thread.h → util/thread.h} +23 -22
  398. data/vendor/libgit2/src/{tsort.c → util/tsort.c} +1 -1
  399. data/vendor/libgit2/src/{unix → util/unix}/map.c +1 -3
  400. data/vendor/libgit2/src/{unix → util/unix}/posix.h +1 -4
  401. data/vendor/libgit2/src/{unix → util/unix}/realpath.c +1 -3
  402. data/vendor/libgit2/src/{utf8.c → util/utf8.c} +1 -1
  403. data/vendor/libgit2/src/{utf8.h → util/utf8.h} +1 -1
  404. data/vendor/libgit2/src/{util.c → util/util.c} +15 -15
  405. data/vendor/libgit2/src/{util.h → util/util.h} +4 -29
  406. data/vendor/libgit2/src/{varint.h → util/varint.h} +1 -1
  407. data/vendor/libgit2/src/{vector.h → util/vector.h} +2 -2
  408. data/vendor/libgit2/src/{wildmatch.h → util/wildmatch.h} +1 -1
  409. data/vendor/libgit2/src/{win32 → util/win32}/dir.h +1 -1
  410. data/vendor/libgit2/src/{win32 → util/win32}/error.h +1 -1
  411. data/vendor/libgit2/src/{win32 → util/win32}/map.c +1 -1
  412. data/vendor/libgit2/src/{win32 → util/win32}/path_w32.c +140 -9
  413. data/vendor/libgit2/src/{win32 → util/win32}/path_w32.h +3 -1
  414. data/vendor/libgit2/src/{win32 → util/win32}/posix.h +1 -2
  415. data/vendor/libgit2/src/{win32 → util/win32}/posix_w32.c +12 -28
  416. data/vendor/libgit2/src/util/win32/precompiled.c +1 -0
  417. data/vendor/libgit2/src/{win32 → util/win32}/precompiled.h +1 -1
  418. data/vendor/libgit2/src/{win32 → util/win32}/thread.h +1 -1
  419. data/vendor/libgit2/src/{win32 → util/win32}/utf-conv.h +1 -1
  420. data/vendor/libgit2/src/{win32 → util/win32}/w32_buffer.c +2 -3
  421. data/vendor/libgit2/src/{win32 → util/win32}/w32_buffer.h +3 -4
  422. data/vendor/libgit2/src/{win32 → util/win32}/w32_leakcheck.c +1 -1
  423. data/vendor/libgit2/src/{win32 → util/win32}/w32_leakcheck.h +1 -1
  424. data/vendor/libgit2/src/{win32 → util/win32}/w32_util.h +1 -1
  425. data/vendor/libgit2/src/{zstream.c → util/zstream.c} +5 -5
  426. data/vendor/libgit2/src/{zstream.h → util/zstream.h} +5 -5
  427. metadata +402 -356
  428. data/vendor/libgit2/src/buffer.h +0 -374
  429. data/vendor/libgit2/src/commit.h +0 -46
  430. data/vendor/libgit2/src/hash/sha1/common_crypto.c +0 -57
  431. data/vendor/libgit2/src/hash/sha1/generic.c +0 -300
  432. data/vendor/libgit2/src/hash/sha1/generic.h +0 -19
  433. data/vendor/libgit2/src/hash/sha1/mbedtls.c +0 -46
  434. data/vendor/libgit2/src/hash/sha1/openssl.c +0 -59
  435. data/vendor/libgit2/src/hash/sha1/win32.c +0 -333
  436. data/vendor/libgit2/src/hash/sha1/win32.h +0 -128
  437. data/vendor/libgit2/src/hash/sha1.h +0 -38
  438. data/vendor/libgit2/src/hash.c +0 -110
  439. data/vendor/libgit2/src/hash.h +0 -46
  440. data/vendor/libgit2/src/message.h +0 -17
  441. data/vendor/libgit2/src/net.c +0 -540
  442. data/vendor/libgit2/src/oid.h +0 -51
  443. data/vendor/libgit2/src/remote.h +0 -55
  444. data/vendor/libgit2/src/sysdir.c +0 -347
  445. data/vendor/libgit2/src/win32/findfile.c +0 -230
  446. data/vendor/libgit2/src/win32/findfile.h +0 -19
  447. /data/vendor/libgit2/src/{win32 → cli/win32}/precompiled.c +0 -0
  448. /data/vendor/libgit2/src/{attr.h → libgit2/attr.h} +0 -0
  449. /data/vendor/libgit2/src/{attrcache.h → libgit2/attrcache.h} +0 -0
  450. /data/vendor/libgit2/src/{blame.h → libgit2/blame.h} +0 -0
  451. /data/vendor/libgit2/src/{blame_git.h → libgit2/blame_git.h} +0 -0
  452. /data/vendor/libgit2/src/{cache.c → libgit2/cache.c} +0 -0
  453. /data/vendor/libgit2/src/{cache.h → libgit2/cache.h} +0 -0
  454. /data/vendor/libgit2/src/{checkout.h → libgit2/checkout.h} +0 -0
  455. /data/vendor/libgit2/src/{clone.h → libgit2/clone.h} +0 -0
  456. /data/vendor/libgit2/src/{commit_list.h → libgit2/commit_list.h} +0 -0
  457. /data/vendor/libgit2/src/{config_backend.h → libgit2/config_backend.h} +0 -0
  458. /data/vendor/libgit2/src/{config_cache.c → libgit2/config_cache.c} +0 -0
  459. /data/vendor/libgit2/src/{config_entries.c → libgit2/config_entries.c} +0 -0
  460. /data/vendor/libgit2/src/{config_entries.h → libgit2/config_entries.h} +0 -0
  461. /data/vendor/libgit2/src/{config_parse.h → libgit2/config_parse.h} +0 -0
  462. /data/vendor/libgit2/src/{config_snapshot.c → libgit2/config_snapshot.c} +0 -0
  463. /data/vendor/libgit2/src/{delta.c → libgit2/delta.c} +0 -0
  464. /data/vendor/libgit2/src/{delta.h → libgit2/delta.h} +0 -0
  465. /data/vendor/libgit2/src/{diff_file.h → libgit2/diff_file.h} +0 -0
  466. /data/vendor/libgit2/src/{diff_parse.c → libgit2/diff_parse.c} +0 -0
  467. /data/vendor/libgit2/src/{diff_parse.h → libgit2/diff_parse.h} +0 -0
  468. /data/vendor/libgit2/src/{diff_tform.h → libgit2/diff_tform.h} +0 -0
  469. /data/vendor/libgit2/src/{diff_xdiff.h → libgit2/diff_xdiff.h} +0 -0
  470. /data/vendor/libgit2/src/{fetchhead.h → libgit2/fetchhead.h} +0 -0
  471. /data/vendor/libgit2/src/{win32 → libgit2}/git2.rc +0 -0
  472. /data/vendor/libgit2/src/{graph.c → libgit2/graph.c} +0 -0
  473. /data/vendor/libgit2/src/{hashsig.c → libgit2/hashsig.c} +0 -0
  474. /data/vendor/libgit2/src/{idxmap.c → libgit2/idxmap.c} +0 -0
  475. /data/vendor/libgit2/src/{idxmap.h → libgit2/idxmap.h} +0 -0
  476. /data/vendor/libgit2/src/{indexer.h → libgit2/indexer.h} +0 -0
  477. /data/vendor/libgit2/src/{libgit2.h → libgit2/libgit2.h} +0 -0
  478. /data/vendor/libgit2/src/{mailmap.h → libgit2/mailmap.h} +0 -0
  479. /data/vendor/libgit2/src/{merge_driver.h → libgit2/merge_driver.h} +0 -0
  480. /data/vendor/libgit2/src/{notes.h → libgit2/notes.h} +0 -0
  481. /data/vendor/libgit2/src/{object_api.c → libgit2/object_api.c} +0 -0
  482. /data/vendor/libgit2/src/{offmap.c → libgit2/offmap.c} +0 -0
  483. /data/vendor/libgit2/src/{offmap.h → libgit2/offmap.h} +0 -0
  484. /data/vendor/libgit2/src/{oidarray.c → libgit2/oidarray.c} +0 -0
  485. /data/vendor/libgit2/src/{oidarray.h → libgit2/oidarray.h} +0 -0
  486. /data/vendor/libgit2/src/{oidmap.h → libgit2/oidmap.h} +0 -0
  487. /data/vendor/libgit2/src/{parse.h → libgit2/parse.h} +0 -0
  488. /data/vendor/libgit2/src/{patch_parse.h → libgit2/patch_parse.h} +0 -0
  489. /data/vendor/libgit2/src/{refdb.c → libgit2/refdb.c} +0 -0
  490. /data/vendor/libgit2/src/{refdb.h → libgit2/refdb.h} +0 -0
  491. /data/vendor/libgit2/src/{repo_template.h → libgit2/repo_template.h} +0 -0
  492. /data/vendor/libgit2/src/{revwalk.h → libgit2/revwalk.h} +0 -0
  493. /data/vendor/libgit2/src/{settings.h → libgit2/settings.h} +0 -0
  494. /data/vendor/libgit2/src/{status.h → libgit2/status.h} +0 -0
  495. /data/vendor/libgit2/src/{stream.h → libgit2/stream.h} +0 -0
  496. /data/vendor/libgit2/src/{streams → libgit2/streams}/mbedtls.h +0 -0
  497. /data/vendor/libgit2/src/{streams → libgit2/streams}/openssl.h +0 -0
  498. /data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_legacy.c +0 -0
  499. /data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_legacy.h +0 -0
  500. /data/vendor/libgit2/src/{streams → libgit2/streams}/registry.c +0 -0
  501. /data/vendor/libgit2/src/{streams → libgit2/streams}/registry.h +0 -0
  502. /data/vendor/libgit2/src/{streams → libgit2/streams}/socket.h +0 -0
  503. /data/vendor/libgit2/src/{streams → libgit2/streams}/stransport.c +0 -0
  504. /data/vendor/libgit2/src/{streams → libgit2/streams}/stransport.h +0 -0
  505. /data/vendor/libgit2/src/{streams → libgit2/streams}/tls.c +0 -0
  506. /data/vendor/libgit2/src/{streams → libgit2/streams}/tls.h +0 -0
  507. /data/vendor/libgit2/src/{transaction.h → libgit2/transaction.h} +0 -0
  508. /data/vendor/libgit2/src/{transports → libgit2/transports}/auth_negotiate.h +0 -0
  509. /data/vendor/libgit2/src/{transports → libgit2/transports}/credential.c +0 -0
  510. /data/vendor/libgit2/src/{transports → libgit2/transports}/credential_helpers.c +0 -0
  511. /data/vendor/libgit2/src/{transports → libgit2/transports}/ssh.h +0 -0
  512. /data/vendor/libgit2/src/{userdiff.h → libgit2/userdiff.h} +0 -0
  513. /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xdiffi.h +0 -0
  514. /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xemit.h +0 -0
  515. /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xmacros.h +0 -0
  516. /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xprepare.h +0 -0
  517. /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xtypes.h +0 -0
  518. /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xutils.h +0 -0
  519. /data/vendor/libgit2/src/{alloc.c → util/alloc.c} +0 -0
  520. /data/vendor/libgit2/src/{alloc.h → util/alloc.h} +0 -0
  521. /data/vendor/libgit2/src/{allocators → util/allocators}/failalloc.c +0 -0
  522. /data/vendor/libgit2/src/{allocators → util/allocators}/stdalloc.c +0 -0
  523. /data/vendor/libgit2/src/{allocators → util/allocators}/win32_leakcheck.c +0 -0
  524. /data/vendor/libgit2/src/{bitvec.h → util/bitvec.h} +0 -0
  525. /data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/sha1.h +0 -0
  526. /data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/ubc_check.c +0 -0
  527. /data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/ubc_check.h +0 -0
  528. /data/vendor/libgit2/src/{integer.h → util/integer.h} +0 -0
  529. /data/vendor/libgit2/src/{pool.c → util/pool.c} +0 -0
  530. /data/vendor/libgit2/src/{pqueue.c → util/pqueue.c} +0 -0
  531. /data/vendor/libgit2/src/{strmap.c → util/strmap.c} +0 -0
  532. /data/vendor/libgit2/src/{strnlen.h → util/strnlen.h} +0 -0
  533. /data/vendor/libgit2/src/{unix → util/unix}/pthread.h +0 -0
  534. /data/vendor/libgit2/src/{varint.c → util/varint.c} +0 -0
  535. /data/vendor/libgit2/src/{vector.c → util/vector.c} +0 -0
  536. /data/vendor/libgit2/src/{wildmatch.c → util/wildmatch.c} +0 -0
  537. /data/vendor/libgit2/src/{win32 → util/win32}/dir.c +0 -0
  538. /data/vendor/libgit2/src/{win32 → util/win32}/error.c +0 -0
  539. /data/vendor/libgit2/src/{win32 → util/win32}/mingw-compat.h +0 -0
  540. /data/vendor/libgit2/src/{win32 → util/win32}/msvc-compat.h +0 -0
  541. /data/vendor/libgit2/src/{win32 → util/win32}/reparse.h +0 -0
  542. /data/vendor/libgit2/src/{win32 → util/win32}/thread.c +0 -0
  543. /data/vendor/libgit2/src/{win32 → util/win32}/utf-conv.c +0 -0
  544. /data/vendor/libgit2/src/{win32 → util/win32}/version.h +0 -0
  545. /data/vendor/libgit2/src/{win32 → util/win32}/w32_common.h +0 -0
  546. /data/vendor/libgit2/src/{win32 → util/win32}/w32_util.c +0 -0
  547. /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>
@@ -34,7 +35,7 @@ enum {
34
35
  PACKREF_HAS_PEEL = 1,
35
36
  PACKREF_WAS_LOOSE = 2,
36
37
  PACKREF_CANNOT_PEEL = 4,
37
- PACKREF_SHADOWED = 8,
38
+ PACKREF_SHADOWED = 8
38
39
  };
39
40
 
40
41
  enum {
@@ -59,29 +60,36 @@ typedef struct refdb_fs_backend {
59
60
  /* path to common objects' directory */
60
61
  char *commonpath;
61
62
 
62
- git_sortedcache *refcache;
63
+ git_oid_t oid_type;
64
+
65
+ int fsync : 1,
66
+ sorted : 1;
63
67
  int peeling_mode;
64
68
  git_iterator_flag_t iterator_flags;
65
69
  uint32_t direach_flags;
66
- int fsync;
70
+ git_sortedcache *refcache;
71
+ git_map packed_refs_map;
72
+ git_mutex prlock; /* protect packed_refs_map */
73
+ git_futils_filestamp packed_refs_stamp;
67
74
  } refdb_fs_backend;
68
75
 
69
76
  static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name);
77
+ static char *packed_set_peeling_mode(char *data, size_t data_sz, refdb_fs_backend *backend);
70
78
 
71
79
  GIT_INLINE(int) loose_path(
72
- git_buf *out,
80
+ git_str *out,
73
81
  const char *base,
74
82
  const char *refname)
75
83
  {
76
- if (git_buf_joinpath(out, base, refname) < 0)
84
+ if (git_str_joinpath(out, base, refname) < 0)
77
85
  return -1;
78
86
 
79
- return git_path_validate_filesystem_with_suffix(out->ptr, out->size,
87
+ return git_fs_path_validate_str_length_with_suffix(out,
80
88
  CONST_STRLEN(".lock"));
81
89
  }
82
90
 
83
91
  GIT_INLINE(int) reflog_path(
84
- git_buf *out,
92
+ git_str *out,
85
93
  git_repository *repo,
86
94
  const char *refname)
87
95
  {
@@ -91,7 +99,7 @@ GIT_INLINE(int) reflog_path(
91
99
  base = (strcmp(refname, GIT_HEAD_FILE) == 0) ? repo->gitdir :
92
100
  repo->commondir;
93
101
 
94
- if ((error = git_buf_joinpath(out, base, GIT_REFLOG_DIR)) < 0)
102
+ if ((error = git_str_joinpath(out, base, GIT_REFLOG_DIR)) < 0)
95
103
  return error;
96
104
 
97
105
  return loose_path(out, out->ptr, refname);
@@ -106,7 +114,8 @@ static int packref_cmp(const void *a_, const void *b_)
106
114
  static int packed_reload(refdb_fs_backend *backend)
107
115
  {
108
116
  int error;
109
- git_buf packedrefs = GIT_BUF_INIT;
117
+ git_str packedrefs = GIT_STR_INIT;
118
+ size_t oid_hexsize = git_oid_hexsize(backend->oid_type);
110
119
  char *scan, *eof, *eol;
111
120
 
112
121
  if (!backend->gitpath)
@@ -133,31 +142,12 @@ static int packed_reload(refdb_fs_backend *backend)
133
142
 
134
143
  GIT_UNUSED(git_sortedcache_clear(backend->refcache, false));
135
144
 
136
- scan = (char *)packedrefs.ptr;
145
+ scan = packedrefs.ptr;
137
146
  eof = scan + packedrefs.size;
138
147
 
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
- }
148
+ scan = packed_set_peeling_mode(scan, packedrefs.size, backend);
149
+ if (!scan)
150
+ goto parse_failed;
161
151
 
162
152
  while (scan < eof && *scan == '#') {
163
153
  if (!(eol = strchr(scan, '\n')))
@@ -171,9 +161,9 @@ static int packed_reload(refdb_fs_backend *backend)
171
161
 
172
162
  /* parse "<OID> <refname>\n" */
173
163
 
174
- if (git_oid_fromstr(&oid, scan) < 0)
164
+ if (git_oid__fromstr(&oid, scan, backend->oid_type) < 0)
175
165
  goto parse_failed;
176
- scan += GIT_OID_HEXSZ;
166
+ scan += oid_hexsize;
177
167
 
178
168
  if (*scan++ != ' ')
179
169
  goto parse_failed;
@@ -192,9 +182,9 @@ static int packed_reload(refdb_fs_backend *backend)
192
182
  /* look for optional "^<OID>\n" */
193
183
 
194
184
  if (*scan == '^') {
195
- if (git_oid_fromstr(&oid, scan + 1) < 0)
185
+ if (git_oid__fromstr(&oid, scan + 1, backend->oid_type) < 0)
196
186
  goto parse_failed;
197
- scan += GIT_OID_HEXSZ + 1;
187
+ scan += oid_hexsize + 1;
198
188
 
199
189
  if (scan < eof) {
200
190
  if (!(eol = strchr(scan, '\n')))
@@ -212,7 +202,7 @@ static int packed_reload(refdb_fs_backend *backend)
212
202
  }
213
203
 
214
204
  git_sortedcache_wunlock(backend->refcache);
215
- git_buf_dispose(&packedrefs);
205
+ git_str_dispose(&packedrefs);
216
206
 
217
207
  return 0;
218
208
 
@@ -221,25 +211,29 @@ parse_failed:
221
211
 
222
212
  GIT_UNUSED(git_sortedcache_clear(backend->refcache, false));
223
213
  git_sortedcache_wunlock(backend->refcache);
224
- git_buf_dispose(&packedrefs);
214
+ git_str_dispose(&packedrefs);
225
215
 
226
216
  return -1;
227
217
  }
228
218
 
229
219
  static int loose_parse_oid(
230
- git_oid *oid, const char *filename, git_buf *file_content)
220
+ git_oid *oid,
221
+ const char *filename,
222
+ git_str *file_content,
223
+ git_oid_t oid_type)
231
224
  {
232
- const char *str = git_buf_cstr(file_content);
225
+ const char *str = git_str_cstr(file_content);
226
+ size_t oid_hexsize = git_oid_hexsize(oid_type);
233
227
 
234
- if (git_buf_len(file_content) < GIT_OID_HEXSZ)
228
+ if (git_str_len(file_content) < oid_hexsize)
235
229
  goto corrupted;
236
230
 
237
231
  /* we need to get 40 OID characters from the file */
238
- if (git_oid_fromstr(oid, str) < 0)
232
+ if (git_oid__fromstr(oid, str, oid_type) < 0)
239
233
  goto corrupted;
240
234
 
241
235
  /* If the file is longer than 40 chars, the 41st must be a space */
242
- str += GIT_OID_HEXSZ;
236
+ str += oid_hexsize;
243
237
  if (*str == '\0' || git__isspace(*str))
244
238
  return 0;
245
239
 
@@ -248,13 +242,13 @@ corrupted:
248
242
  return -1;
249
243
  }
250
244
 
251
- static int loose_readbuffer(git_buf *buf, const char *base, const char *path)
245
+ static int loose_readbuffer(git_str *buf, const char *base, const char *path)
252
246
  {
253
247
  int error;
254
248
 
255
249
  if ((error = loose_path(buf, base, path)) < 0 ||
256
250
  (error = git_futils_readbuffer(buf, buf->ptr)) < 0)
257
- git_buf_dispose(buf);
251
+ git_str_dispose(buf);
258
252
 
259
253
  return error;
260
254
  }
@@ -262,7 +256,7 @@ static int loose_readbuffer(git_buf *buf, const char *base, const char *path)
262
256
  static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
263
257
  {
264
258
  int error = 0;
265
- git_buf ref_file = GIT_BUF_INIT;
259
+ git_str ref_file = GIT_STR_INIT;
266
260
  struct packref *ref = NULL;
267
261
  git_oid oid;
268
262
 
@@ -275,11 +269,11 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
275
269
  }
276
270
 
277
271
  /* skip symbolic refs */
278
- if (!git__prefixcmp(git_buf_cstr(&ref_file), GIT_SYMREF))
272
+ if (!git__prefixcmp(git_str_cstr(&ref_file), GIT_SYMREF))
279
273
  goto done;
280
274
 
281
275
  /* parse OID from file */
282
- if ((error = loose_parse_oid(&oid, name, &ref_file)) < 0)
276
+ if ((error = loose_parse_oid(&oid, name, &ref_file, backend->oid_type)) < 0)
283
277
  goto done;
284
278
 
285
279
  if ((error = git_sortedcache_wlock(backend->refcache)) < 0)
@@ -295,11 +289,11 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
295
289
  git_sortedcache_wunlock(backend->refcache);
296
290
 
297
291
  done:
298
- git_buf_dispose(&ref_file);
292
+ git_str_dispose(&ref_file);
299
293
  return error;
300
294
  }
301
295
 
302
- static int _dirent_loose_load(void *payload, git_buf *full_path)
296
+ static int _dirent_loose_load(void *payload, git_str *full_path)
303
297
  {
304
298
  refdb_fs_backend *backend = payload;
305
299
  const char *file_path;
@@ -307,8 +301,8 @@ static int _dirent_loose_load(void *payload, git_buf *full_path)
307
301
  if (git__suffixcmp(full_path->ptr, ".lock") == 0)
308
302
  return 0;
309
303
 
310
- if (git_path_isdir(full_path->ptr)) {
311
- int error = git_path_direach(
304
+ if (git_fs_path_isdir(full_path->ptr)) {
305
+ int error = git_fs_path_direach(
312
306
  full_path, backend->direach_flags, _dirent_loose_load, backend);
313
307
  /* Race with the filesystem, ignore it */
314
308
  if (error == GIT_ENOTFOUND) {
@@ -333,9 +327,9 @@ static int _dirent_loose_load(void *payload, git_buf *full_path)
333
327
  static int packed_loadloose(refdb_fs_backend *backend)
334
328
  {
335
329
  int error;
336
- git_buf refs_path = GIT_BUF_INIT;
330
+ git_str refs_path = GIT_STR_INIT;
337
331
 
338
- if (git_buf_joinpath(&refs_path, backend->gitpath, GIT_REFS_DIR) < 0)
332
+ if (git_str_joinpath(&refs_path, backend->gitpath, GIT_REFS_DIR) < 0)
339
333
  return -1;
340
334
 
341
335
  /*
@@ -343,10 +337,10 @@ static int packed_loadloose(refdb_fs_backend *backend)
343
337
  * This will overwrite any old packed entries with their
344
338
  * updated loose versions
345
339
  */
346
- error = git_path_direach(
340
+ error = git_fs_path_direach(
347
341
  &refs_path, backend->direach_flags, _dirent_loose_load, backend);
348
342
 
349
- git_buf_dispose(&refs_path);
343
+ git_str_dispose(&refs_path);
350
344
 
351
345
  return error;
352
346
  }
@@ -357,7 +351,7 @@ static int refdb_fs_backend__exists(
357
351
  const char *ref_name)
358
352
  {
359
353
  refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
360
- git_buf ref_path = GIT_BUF_INIT;
354
+ git_str ref_path = GIT_STR_INIT;
361
355
  int error;
362
356
 
363
357
  GIT_ASSERT_ARG(backend);
@@ -367,7 +361,7 @@ static int refdb_fs_backend__exists(
367
361
  if ((error = loose_path(&ref_path, backend->gitpath, ref_name)) < 0)
368
362
  goto out;
369
363
 
370
- if (git_path_isfile(ref_path.ptr)) {
364
+ if (git_fs_path_isfile(ref_path.ptr)) {
371
365
  *exists = 1;
372
366
  goto out;
373
367
  }
@@ -381,18 +375,18 @@ static int refdb_fs_backend__exists(
381
375
  }
382
376
 
383
377
  out:
384
- git_buf_dispose(&ref_path);
378
+ git_str_dispose(&ref_path);
385
379
  return error;
386
380
  }
387
381
 
388
- static const char *loose_parse_symbolic(git_buf *file_content)
382
+ static const char *loose_parse_symbolic(git_str *file_content)
389
383
  {
390
384
  const unsigned int header_len = (unsigned int)strlen(GIT_SYMREF);
391
385
  const char *refname_start;
392
386
 
393
387
  refname_start = (const char *)file_content->ptr;
394
388
 
395
- if (git_buf_len(file_content) < header_len + 1) {
389
+ if (git_str_len(file_content) < header_len + 1) {
396
390
  git_error_set(GIT_ERROR_REFERENCE, "corrupted loose reference file");
397
391
  return NULL;
398
392
  }
@@ -424,7 +418,7 @@ static int loose_lookup(
424
418
  refdb_fs_backend *backend,
425
419
  const char *ref_name)
426
420
  {
427
- git_buf ref_file = GIT_BUF_INIT;
421
+ git_str ref_file = GIT_STR_INIT;
428
422
  int error = 0;
429
423
  const char *ref_dir;
430
424
 
@@ -438,10 +432,10 @@ static int loose_lookup(
438
432
 
439
433
  if ((error = loose_readbuffer(&ref_file, ref_dir, ref_name)) < 0)
440
434
  /* cannot read loose ref file - gah */;
441
- else if (git__prefixcmp(git_buf_cstr(&ref_file), GIT_SYMREF) == 0) {
435
+ else if (git__prefixcmp(git_str_cstr(&ref_file), GIT_SYMREF) == 0) {
442
436
  const char *target;
443
437
 
444
- git_buf_rtrim(&ref_file);
438
+ git_str_rtrim(&ref_file);
445
439
 
446
440
  if (!(target = loose_parse_symbolic(&ref_file)))
447
441
  error = -1;
@@ -450,12 +444,12 @@ static int loose_lookup(
450
444
  } else {
451
445
  git_oid oid;
452
446
 
453
- if (!(error = loose_parse_oid(&oid, ref_name, &ref_file)) &&
447
+ if (!(error = loose_parse_oid(&oid, ref_name, &ref_file, backend->oid_type)) &&
454
448
  out != NULL)
455
449
  *out = git_reference__alloc(ref_name, &oid, NULL);
456
450
  }
457
451
 
458
- git_buf_dispose(&ref_file);
452
+ git_str_dispose(&ref_file);
459
453
  return error;
460
454
  }
461
455
 
@@ -465,10 +459,203 @@ static int ref_error_notfound(const char *name)
465
459
  return GIT_ENOTFOUND;
466
460
  }
467
461
 
468
- static int packed_lookup(
469
- git_reference **out,
470
- refdb_fs_backend *backend,
471
- const char *ref_name)
462
+ static char *packed_set_peeling_mode(
463
+ char *data,
464
+ size_t data_sz,
465
+ refdb_fs_backend *backend)
466
+ {
467
+ static const char *traits_header = "# pack-refs with:";
468
+ char *eol;
469
+ backend->peeling_mode = PEELING_NONE;
470
+
471
+ if (git__prefixncmp(data, data_sz, traits_header) == 0) {
472
+ size_t hdr_sz = strlen(traits_header);
473
+ const char *sorted = " sorted ";
474
+ const char *peeled = " peeled ";
475
+ const char *fully_peeled = " fully-peeled ";
476
+ data += hdr_sz;
477
+ data_sz -= hdr_sz;
478
+
479
+ eol = memchr(data, '\n', data_sz);
480
+
481
+ if (!eol)
482
+ return NULL;
483
+
484
+ if (git__memmem(data, eol - data, fully_peeled, strlen(fully_peeled)))
485
+ backend->peeling_mode = PEELING_FULL;
486
+ else if (git__memmem(data, eol - data, peeled, strlen(peeled)))
487
+ backend->peeling_mode = PEELING_STANDARD;
488
+
489
+ backend->sorted = NULL != git__memmem(data, eol - data, sorted, strlen(sorted));
490
+
491
+ return eol + 1;
492
+ }
493
+ return data;
494
+ }
495
+
496
+ static void packed_map_free(refdb_fs_backend *backend)
497
+ {
498
+ if (backend->packed_refs_map.data) {
499
+ #ifdef GIT_WIN32
500
+ git__free(backend->packed_refs_map.data);
501
+ #else
502
+ git_futils_mmap_free(&backend->packed_refs_map);
503
+ #endif
504
+ backend->packed_refs_map.data = NULL;
505
+ backend->packed_refs_map.len = 0;
506
+ git_futils_filestamp_set(&backend->packed_refs_stamp, NULL);
507
+ }
508
+ }
509
+
510
+ static int packed_map_check(refdb_fs_backend *backend)
511
+ {
512
+ int error = 0;
513
+ git_file fd = -1;
514
+ struct stat st;
515
+
516
+ if ((error = git_mutex_lock(&backend->prlock)) < 0)
517
+ return error;
518
+
519
+ if (backend->packed_refs_map.data &&
520
+ !git_futils_filestamp_check(
521
+ &backend->packed_refs_stamp, backend->refcache->path)) {
522
+ git_mutex_unlock(&backend->prlock);
523
+ return error;
524
+ }
525
+ packed_map_free(backend);
526
+
527
+ fd = git_futils_open_ro(backend->refcache->path);
528
+ if (fd < 0) {
529
+ git_mutex_unlock(&backend->prlock);
530
+ if (fd == GIT_ENOTFOUND) {
531
+ git_error_clear();
532
+ return 0;
533
+ }
534
+ return fd;
535
+ }
536
+
537
+ if (p_fstat(fd, &st) < 0) {
538
+ p_close(fd);
539
+ git_mutex_unlock(&backend->prlock);
540
+ git_error_set(GIT_ERROR_OS, "unable to stat packed-refs '%s'", backend->refcache->path);
541
+ return -1;
542
+ }
543
+
544
+ if (st.st_size == 0) {
545
+ p_close(fd);
546
+ git_mutex_unlock(&backend->prlock);
547
+ return 0;
548
+ }
549
+
550
+ git_futils_filestamp_set_from_stat(&backend->packed_refs_stamp, &st);
551
+
552
+ #ifdef GIT_WIN32
553
+ /* on windows, we copy the entire file into memory rather than using
554
+ * mmap() because using mmap() on windows also locks the file and this
555
+ * map is long-lived. */
556
+ backend->packed_refs_map.len = (size_t)st.st_size;
557
+ backend->packed_refs_map.data =
558
+ git__malloc(backend->packed_refs_map.len);
559
+ GIT_ERROR_CHECK_ALLOC(backend->packed_refs_map.data);
560
+ {
561
+ ssize_t bytesread =
562
+ p_read(fd, backend->packed_refs_map.data,
563
+ backend->packed_refs_map.len);
564
+ error = (bytesread == (ssize_t)backend->packed_refs_map.len) ? 0 : -1;
565
+ }
566
+ #else
567
+ error = git_futils_mmap_ro(&backend->packed_refs_map, fd, 0, (size_t)st.st_size);
568
+ #endif
569
+ p_close(fd);
570
+ if (error < 0) {
571
+ git_mutex_unlock(&backend->prlock);
572
+ return error;
573
+ }
574
+
575
+ packed_set_peeling_mode(
576
+ backend->packed_refs_map.data, backend->packed_refs_map.len,
577
+ backend);
578
+
579
+ git_mutex_unlock(&backend->prlock);
580
+ return error;
581
+ }
582
+
583
+ /*
584
+ * Find beginning of packed-ref record pointed to by p.
585
+ * buf - a lower-bound pointer to some memory buffer
586
+ * p - an upper-bound pointer to the same memory buffer
587
+ */
588
+ static const char *start_of_record(const char *buf, const char *p)
589
+ {
590
+ const char *nl = p;
591
+ while (true) {
592
+ nl = git__memrchr(buf, '\n', nl - buf);
593
+ if (!nl)
594
+ return buf;
595
+
596
+ if (nl[1] == '^' && nl > buf)
597
+ --nl;
598
+ else
599
+ break;
600
+ };
601
+ return nl + 1;
602
+ }
603
+
604
+ /*
605
+ * Find end of packed-ref record pointed to by p.
606
+ * end - an upper-bound pointer to some memory buffer
607
+ * p - a lower-bound pointer to the same memory buffer
608
+ */
609
+ static const char *end_of_record(const char *p, const char *end)
610
+ {
611
+ while (1) {
612
+ size_t sz = end - p;
613
+ p = memchr(p, '\n', sz);
614
+ if (!p)
615
+ return end;
616
+ ++p;
617
+ if (p < end && p[0] == '^')
618
+ ++p;
619
+ else
620
+ break;
621
+ }
622
+ return p;
623
+ }
624
+
625
+ static int cmp_record_to_refname(
626
+ const char *rec,
627
+ size_t data_end,
628
+ const char *ref_name,
629
+ git_oid_t oid_type)
630
+ {
631
+ const size_t ref_len = strlen(ref_name);
632
+ int cmp_val;
633
+ const char *end;
634
+ size_t oid_hexsize = git_oid_hexsize(oid_type);
635
+
636
+ rec += oid_hexsize + 1; /* <oid> + space */
637
+
638
+ /* an incomplete (corrupt) record is treated as less than ref_name */
639
+ if (data_end < oid_hexsize + 3)
640
+ return -1;
641
+
642
+ data_end -= oid_hexsize + 1;
643
+
644
+ end = memchr(rec, '\n', data_end);
645
+ if (end)
646
+ data_end = end - rec;
647
+
648
+ cmp_val = memcmp(rec, ref_name, min(ref_len, data_end));
649
+
650
+ if (cmp_val == 0 && data_end != ref_len)
651
+ return (data_end > ref_len) ? 1 : -1;
652
+ return cmp_val;
653
+ }
654
+
655
+ static int packed_unsorted_lookup(
656
+ git_reference **out,
657
+ refdb_fs_backend *backend,
658
+ const char *ref_name)
472
659
  {
473
660
  int error = 0;
474
661
  struct packref *entry;
@@ -493,6 +680,86 @@ static int packed_lookup(
493
680
  return error;
494
681
  }
495
682
 
683
+ static int packed_lookup(
684
+ git_reference **out,
685
+ refdb_fs_backend *backend,
686
+ const char *ref_name)
687
+ {
688
+ int error = 0;
689
+ const char *left, *right, *data_end;
690
+ size_t oid_hexsize = git_oid_hexsize(backend->oid_type);
691
+
692
+ if ((error = packed_map_check(backend)) < 0)
693
+ return error;
694
+
695
+ if (!backend->sorted)
696
+ return packed_unsorted_lookup(out, backend, ref_name);
697
+
698
+ left = backend->packed_refs_map.data;
699
+ right = data_end = (const char *) backend->packed_refs_map.data +
700
+ backend->packed_refs_map.len;
701
+
702
+ while (left < right && *left == '#') {
703
+ if (!(left = memchr(left, '\n', data_end - left)))
704
+ goto parse_failed;
705
+ left++;
706
+ }
707
+
708
+ while (left < right) {
709
+ const char *mid, *rec;
710
+ int compare;
711
+
712
+ mid = left + (right - left) / 2;
713
+ rec = start_of_record(left, mid);
714
+ compare = cmp_record_to_refname(rec, data_end - rec, ref_name, backend->oid_type);
715
+
716
+ if (compare < 0) {
717
+ left = end_of_record(mid, right);
718
+ } else if (compare > 0) {
719
+ right = rec;
720
+ } else {
721
+ const char *eol;
722
+ git_oid oid, peel, *peel_ptr = NULL;
723
+
724
+ if (data_end - rec < (long)oid_hexsize ||
725
+ git_oid__fromstr(&oid, rec, backend->oid_type) < 0) {
726
+ goto parse_failed;
727
+ }
728
+ rec += oid_hexsize + 1;
729
+ if (!(eol = memchr(rec, '\n', data_end - rec))) {
730
+ goto parse_failed;
731
+ }
732
+
733
+ /* look for optional "^<OID>\n" */
734
+
735
+ if (eol + 1 < data_end) {
736
+ rec = eol + 1;
737
+
738
+ if (*rec == '^') {
739
+ rec++;
740
+ if (data_end - rec < (long)oid_hexsize ||
741
+ git_oid__fromstr(&peel, rec, backend->oid_type) < 0) {
742
+ goto parse_failed;
743
+ }
744
+ peel_ptr = &peel;
745
+ }
746
+ }
747
+
748
+ *out = git_reference__alloc(ref_name, &oid, peel_ptr);
749
+ if (!*out) {
750
+ return -1;
751
+ }
752
+
753
+ return 0;
754
+ }
755
+ }
756
+ return ref_error_notfound(ref_name);
757
+
758
+ parse_failed:
759
+ git_error_set(GIT_ERROR_REFERENCE, "corrupted packed references file");
760
+ return -1;
761
+ }
762
+
496
763
  static int refdb_fs_backend__lookup(
497
764
  git_reference **out,
498
765
  git_refdb_backend *_backend,
@@ -512,7 +779,6 @@ static int refdb_fs_backend__lookup(
512
779
  git_error_clear();
513
780
  error = packed_lookup(out, backend, ref_name);
514
781
  }
515
-
516
782
  return error;
517
783
  }
518
784
 
@@ -542,7 +808,7 @@ static void refdb_fs_backend__iterator_free(git_reference_iterator *_iter)
542
808
  static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
543
809
  {
544
810
  int error = 0;
545
- git_buf path = GIT_BUF_INIT;
811
+ git_str path = GIT_STR_INIT;
546
812
  git_iterator *fsit = NULL;
547
813
  git_iterator_options fsit_opts = GIT_ITERATOR_OPTIONS_INIT;
548
814
  const git_index_entry *entry = NULL;
@@ -578,26 +844,26 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
578
844
  }
579
845
  }
580
846
 
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);
847
+ if ((error = git_str_puts(&path, backend->commonpath)) < 0 ||
848
+ (error = git_str_put(&path, ref_prefix, ref_prefix_len)) < 0) {
849
+ git_str_dispose(&path);
584
850
  return error;
585
851
  }
586
852
 
587
853
  if ((error = git_iterator_for_filesystem(&fsit, path.ptr, &fsit_opts)) < 0) {
588
- git_buf_dispose(&path);
854
+ git_str_dispose(&path);
589
855
  return (iter->glob && error == GIT_ENOTFOUND)? 0 : error;
590
856
  }
591
857
 
592
- error = git_buf_sets(&path, ref_prefix);
858
+ error = git_str_sets(&path, ref_prefix);
593
859
 
594
860
  while (!error && !git_iterator_advance(&entry, fsit)) {
595
861
  const char *ref_name;
596
862
  char *ref_dup;
597
863
 
598
- git_buf_truncate(&path, ref_prefix_len);
599
- git_buf_puts(&path, entry->path);
600
- ref_name = git_buf_cstr(&path);
864
+ git_str_truncate(&path, ref_prefix_len);
865
+ git_str_puts(&path, entry->path);
866
+ ref_name = git_str_cstr(&path);
601
867
 
602
868
  if (git__suffixcmp(ref_name, ".lock") == 0 ||
603
869
  (iter->glob && wildmatch(iter->glob, ref_name, 0) != 0))
@@ -611,7 +877,7 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
611
877
  }
612
878
 
613
879
  git_iterator_free(fsit);
614
- git_buf_dispose(&path);
880
+ git_str_dispose(&path);
615
881
 
616
882
  return error;
617
883
  }
@@ -810,14 +1076,14 @@ static int reference_path_available(
810
1076
  static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *name)
811
1077
  {
812
1078
  int error, filebuf_flags;
813
- git_buf ref_path = GIT_BUF_INIT;
1079
+ git_str ref_path = GIT_STR_INIT;
814
1080
  const char *basedir;
815
1081
 
816
1082
  GIT_ASSERT_ARG(file);
817
1083
  GIT_ASSERT_ARG(backend);
818
1084
  GIT_ASSERT_ARG(name);
819
1085
 
820
- if (!git_path_validate(backend->repo, name, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
1086
+ if (!git_path_is_valid(backend->repo, name, 0, GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
821
1087
  git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", name);
822
1088
  return GIT_EINVALIDSPEC;
823
1089
  }
@@ -845,7 +1111,7 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
845
1111
  if (error == GIT_EDIRECTORY)
846
1112
  git_error_set(GIT_ERROR_REFERENCE, "cannot lock ref '%s', there are refs beneath that folder", name);
847
1113
 
848
- git_buf_dispose(&ref_path);
1114
+ git_str_dispose(&ref_path);
849
1115
  return error;
850
1116
  }
851
1117
 
@@ -855,7 +1121,7 @@ static int loose_commit(git_filebuf *file, const git_reference *ref)
855
1121
  GIT_ASSERT_ARG(ref);
856
1122
 
857
1123
  if (ref->type == GIT_REFERENCE_DIRECT) {
858
- char oid[GIT_OID_HEXSZ + 1];
1124
+ char oid[GIT_OID_MAX_HEXSIZE + 1];
859
1125
  git_oid_nfmt(oid, sizeof(oid), &ref->target.oid);
860
1126
 
861
1127
  git_filebuf_printf(file, "%s\n", oid);
@@ -971,7 +1237,7 @@ static int packed_find_peel(refdb_fs_backend *backend, struct packref *ref)
971
1237
  */
972
1238
  static int packed_write_ref(struct packref *ref, git_filebuf *file)
973
1239
  {
974
- char oid[GIT_OID_HEXSZ + 1];
1240
+ char oid[GIT_OID_MAX_HEXSIZE + 1];
975
1241
  git_oid_nfmt(oid, sizeof(oid), &ref->oid);
976
1242
 
977
1243
  /*
@@ -985,7 +1251,7 @@ static int packed_write_ref(struct packref *ref, git_filebuf *file)
985
1251
  * The required peels have already been loaded into `ref->peel_target`.
986
1252
  */
987
1253
  if (ref->flags & PACKREF_HAS_PEEL) {
988
- char peel[GIT_OID_HEXSZ + 1];
1254
+ char peel[GIT_OID_MAX_HEXSIZE + 1];
989
1255
  git_oid_nfmt(peel, sizeof(peel), &ref->peel);
990
1256
 
991
1257
  if (git_filebuf_printf(file, "%s %s\n^%s\n", oid, ref->name, peel) < 0)
@@ -1013,7 +1279,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
1013
1279
  {
1014
1280
  size_t i;
1015
1281
  git_filebuf lock = GIT_FILEBUF_INIT;
1016
- git_buf ref_content = GIT_BUF_INIT;
1282
+ git_str ref_content = GIT_STR_INIT;
1017
1283
  int error = 0;
1018
1284
 
1019
1285
  /* backend->refcache is already locked when this is called */
@@ -1034,7 +1300,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
1034
1300
  continue;
1035
1301
 
1036
1302
  if (error < 0) {
1037
- git_buf_dispose(&ref_content);
1303
+ git_str_dispose(&ref_content);
1038
1304
  git_error_set(GIT_ERROR_REFERENCE, "failed to lock loose reference '%s'", ref->name);
1039
1305
  return error;
1040
1306
  }
@@ -1049,7 +1315,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
1049
1315
  continue;
1050
1316
 
1051
1317
  /* 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)
1318
+ if (loose_parse_oid(&current_id, lock.path_original, &ref_content, backend->oid_type) < 0)
1053
1319
  continue;
1054
1320
 
1055
1321
  /* If the ref moved since we packed it, we must not delete it */
@@ -1065,7 +1331,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
1065
1331
  p_unlink(lock.path_original);
1066
1332
  }
1067
1333
 
1068
- git_buf_dispose(&ref_content);
1334
+ git_str_dispose(&ref_content);
1069
1335
  git_filebuf_cleanup(&lock);
1070
1336
  return 0;
1071
1337
  }
@@ -1080,6 +1346,15 @@ static int packed_write(refdb_fs_backend *backend)
1080
1346
  int error, open_flags = 0;
1081
1347
  size_t i;
1082
1348
 
1349
+ /* take lock and close up packed-refs mmap if open */
1350
+ if ((error = git_mutex_lock(&backend->prlock)) < 0) {
1351
+ return error;
1352
+ }
1353
+
1354
+ packed_map_free(backend);
1355
+
1356
+ git_mutex_unlock(&backend->prlock);
1357
+
1083
1358
  /* lock the cache to updates while we do this */
1084
1359
  if ((error = git_sortedcache_wlock(refcache)) < 0)
1085
1360
  return error;
@@ -1099,7 +1374,11 @@ static int packed_write(refdb_fs_backend *backend)
1099
1374
 
1100
1375
  for (i = 0; i < git_sortedcache_entrycount(refcache); ++i) {
1101
1376
  struct packref *ref = git_sortedcache_entry(refcache, i);
1102
- GIT_ASSERT(ref);
1377
+
1378
+ GIT_ASSERT_WITH_CLEANUP(ref, {
1379
+ error = -1;
1380
+ goto fail;
1381
+ });
1103
1382
 
1104
1383
  if ((error = packed_find_peel(backend, ref)) < 0)
1105
1384
  goto fail;
@@ -1333,41 +1612,41 @@ static int refdb_fs_backend__prune_refs(
1333
1612
  const char *ref_name,
1334
1613
  const char *prefix)
1335
1614
  {
1336
- git_buf relative_path = GIT_BUF_INIT;
1337
- git_buf base_path = GIT_BUF_INIT;
1615
+ git_str relative_path = GIT_STR_INIT;
1616
+ git_str base_path = GIT_STR_INIT;
1338
1617
  size_t commonlen;
1339
1618
  int error;
1340
1619
 
1341
1620
  GIT_ASSERT_ARG(backend);
1342
1621
  GIT_ASSERT_ARG(ref_name);
1343
1622
 
1344
- if ((error = git_buf_sets(&relative_path, ref_name)) < 0)
1623
+ if ((error = git_str_sets(&relative_path, ref_name)) < 0)
1345
1624
  goto cleanup;
1346
1625
 
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/")) {
1626
+ git_fs_path_squash_slashes(&relative_path);
1627
+ if ((commonlen = git_fs_path_common_dirlen("refs/heads/", git_str_cstr(&relative_path))) == strlen("refs/heads/") ||
1628
+ (commonlen = git_fs_path_common_dirlen("refs/tags/", git_str_cstr(&relative_path))) == strlen("refs/tags/") ||
1629
+ (commonlen = git_fs_path_common_dirlen("refs/remotes/", git_str_cstr(&relative_path))) == strlen("refs/remotes/")) {
1351
1630
 
1352
- git_buf_truncate(&relative_path, commonlen);
1631
+ git_str_truncate(&relative_path, commonlen);
1353
1632
 
1354
1633
  if (prefix)
1355
- error = git_buf_join3(&base_path, '/',
1634
+ error = git_str_join3(&base_path, '/',
1356
1635
  backend->commonpath, prefix,
1357
- git_buf_cstr(&relative_path));
1636
+ git_str_cstr(&relative_path));
1358
1637
  else
1359
- error = git_buf_joinpath(&base_path,
1638
+ error = git_str_joinpath(&base_path,
1360
1639
  backend->commonpath,
1361
- git_buf_cstr(&relative_path));
1640
+ git_str_cstr(&relative_path));
1362
1641
 
1363
1642
  if (!error)
1364
- error = git_path_validate_filesystem(base_path.ptr, base_path.size);
1643
+ error = git_path_validate_str_length(NULL, &base_path);
1365
1644
 
1366
1645
  if (error < 0)
1367
1646
  goto cleanup;
1368
1647
 
1369
1648
  error = git_futils_rmdir_r(ref_name + commonlen,
1370
- git_buf_cstr(&base_path),
1649
+ git_str_cstr(&base_path),
1371
1650
  GIT_RMDIR_EMPTY_PARENTS | GIT_RMDIR_SKIP_ROOT);
1372
1651
 
1373
1652
  if (error == GIT_ENOTFOUND)
@@ -1375,8 +1654,8 @@ static int refdb_fs_backend__prune_refs(
1375
1654
  }
1376
1655
 
1377
1656
  cleanup:
1378
- git_buf_dispose(&relative_path);
1379
- git_buf_dispose(&base_path);
1657
+ git_str_dispose(&relative_path);
1658
+ git_str_dispose(&base_path);
1380
1659
  return error;
1381
1660
  }
1382
1661
 
@@ -1405,7 +1684,7 @@ static int refdb_fs_backend__delete(
1405
1684
 
1406
1685
  static int loose_delete(refdb_fs_backend *backend, const char *ref_name)
1407
1686
  {
1408
- git_buf path = GIT_BUF_INIT;
1687
+ git_str path = GIT_STR_INIT;
1409
1688
  int error = 0;
1410
1689
 
1411
1690
  if ((error = loose_path(&path, backend->commonpath, ref_name)) < 0)
@@ -1417,7 +1696,7 @@ static int loose_delete(refdb_fs_backend *backend, const char *ref_name)
1417
1696
  else if (error != 0)
1418
1697
  error = -1;
1419
1698
 
1420
- git_buf_dispose(&path);
1699
+ git_str_dispose(&path);
1421
1700
 
1422
1701
  return error;
1423
1702
  }
@@ -1567,6 +1846,12 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
1567
1846
  return;
1568
1847
 
1569
1848
  git_sortedcache_free(backend->refcache);
1849
+
1850
+ git_mutex_lock(&backend->prlock);
1851
+ packed_map_free(backend);
1852
+ git_mutex_unlock(&backend->prlock);
1853
+ git_mutex_free(&backend->prlock);
1854
+
1570
1855
  git__free(backend->gitpath);
1571
1856
  git__free(backend->commonpath);
1572
1857
  git__free(backend);
@@ -1574,17 +1859,17 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
1574
1859
 
1575
1860
  static char *setup_namespace(git_repository *repo, const char *in)
1576
1861
  {
1577
- git_buf path = GIT_BUF_INIT;
1862
+ git_str path = GIT_STR_INIT;
1578
1863
  char *parts, *start, *end, *out = NULL;
1579
1864
 
1580
1865
  if (!in)
1581
1866
  goto done;
1582
1867
 
1583
- git_buf_puts(&path, in);
1868
+ git_str_puts(&path, in);
1584
1869
 
1585
1870
  /* if the repo is not namespaced, nothing else to do */
1586
1871
  if (repo->namespace == NULL) {
1587
- out = git_buf_detach(&path);
1872
+ out = git_str_detach(&path);
1588
1873
  goto done;
1589
1874
  }
1590
1875
 
@@ -1599,27 +1884,30 @@ static char *setup_namespace(git_repository *repo, const char *in)
1599
1884
  * refs under refs/namespaces/foo/refs/namespaces/bar/
1600
1885
  */
1601
1886
  while ((start = git__strsep(&end, "/")) != NULL)
1602
- git_buf_printf(&path, "refs/namespaces/%s/", start);
1887
+ git_str_printf(&path, "refs/namespaces/%s/", start);
1603
1888
 
1604
- git_buf_printf(&path, "refs/namespaces/%s/refs", end);
1889
+ git_str_printf(&path, "refs/namespaces/%s/refs", end);
1605
1890
  git__free(parts);
1606
1891
 
1607
1892
  /* Make sure that the folder with the namespace exists */
1608
- if (git_futils_mkdir_relative(git_buf_cstr(&path), in, 0777,
1893
+ if (git_futils_mkdir_relative(git_str_cstr(&path), in, 0777,
1609
1894
  GIT_MKDIR_PATH, NULL) < 0)
1610
1895
  goto done;
1611
1896
 
1612
1897
  /* 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);
1898
+ git_str_rtruncate_at_char(&path, '/');
1899
+ git_str_putc(&path, '/');
1900
+ out = git_str_detach(&path);
1616
1901
 
1617
1902
  done:
1618
- git_buf_dispose(&path);
1903
+ git_str_dispose(&path);
1619
1904
  return out;
1620
1905
  }
1621
1906
 
1622
- static int reflog_alloc(git_reflog **reflog, const char *name)
1907
+ static int reflog_alloc(
1908
+ git_reflog **reflog,
1909
+ const char *name,
1910
+ git_oid_t oid_type)
1623
1911
  {
1624
1912
  git_reflog *log;
1625
1913
 
@@ -1631,6 +1919,8 @@ static int reflog_alloc(git_reflog **reflog, const char *name)
1631
1919
  log->ref_name = git__strdup(name);
1632
1920
  GIT_ERROR_CHECK_ALLOC(log->ref_name);
1633
1921
 
1922
+ log->oid_type = oid_type;
1923
+
1634
1924
  if (git_vector_init(&log->entries, 0, NULL) < 0) {
1635
1925
  git__free(log->ref_name);
1636
1926
  git__free(log);
@@ -1716,7 +2006,7 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
1716
2006
  {
1717
2007
  refdb_fs_backend *backend;
1718
2008
  git_repository *repo;
1719
- git_buf path = GIT_BUF_INIT;
2009
+ git_str path = GIT_STR_INIT;
1720
2010
  int error;
1721
2011
 
1722
2012
  GIT_ASSERT_ARG(_backend && name);
@@ -1727,8 +2017,8 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
1727
2017
  if ((error = reflog_path(&path, repo, name)) < 0)
1728
2018
  return error;
1729
2019
 
1730
- error = create_new_reflog_file(git_buf_cstr(&path));
1731
- git_buf_dispose(&path);
2020
+ error = create_new_reflog_file(git_str_cstr(&path));
2021
+ git_str_dispose(&path);
1732
2022
 
1733
2023
  return error;
1734
2024
  }
@@ -1736,15 +2026,15 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
1736
2026
  static int has_reflog(git_repository *repo, const char *name)
1737
2027
  {
1738
2028
  int ret = 0;
1739
- git_buf path = GIT_BUF_INIT;
2029
+ git_str path = GIT_STR_INIT;
1740
2030
 
1741
2031
  if (reflog_path(&path, repo, name) < 0)
1742
2032
  goto cleanup;
1743
2033
 
1744
- ret = git_path_isfile(git_buf_cstr(&path));
2034
+ ret = git_fs_path_isfile(git_str_cstr(&path));
1745
2035
 
1746
2036
  cleanup:
1747
- git_buf_dispose(&path);
2037
+ git_str_dispose(&path);
1748
2038
  return ret;
1749
2039
  }
1750
2040
 
@@ -1760,11 +2050,14 @@ static int refdb_reflog_fs__has_log(git_refdb_backend *_backend, const char *nam
1760
2050
  return has_reflog(backend->repo, name);
1761
2051
  }
1762
2052
 
1763
- static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend, const char *name)
2053
+ static int refdb_reflog_fs__read(
2054
+ git_reflog **out,
2055
+ git_refdb_backend *_backend,
2056
+ const char *name)
1764
2057
  {
1765
2058
  int error = -1;
1766
- git_buf log_path = GIT_BUF_INIT;
1767
- git_buf log_file = GIT_BUF_INIT;
2059
+ git_str log_path = GIT_STR_INIT;
2060
+ git_str log_file = GIT_STR_INIT;
1768
2061
  git_reflog *log = NULL;
1769
2062
  git_repository *repo;
1770
2063
  refdb_fs_backend *backend;
@@ -1776,22 +2069,22 @@ static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend,
1776
2069
  backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
1777
2070
  repo = backend->repo;
1778
2071
 
1779
- if (reflog_alloc(&log, name) < 0)
2072
+ if (reflog_alloc(&log, name, backend->oid_type) < 0)
1780
2073
  return -1;
1781
2074
 
1782
2075
  if (reflog_path(&log_path, repo, name) < 0)
1783
2076
  goto cleanup;
1784
2077
 
1785
- error = git_futils_readbuffer(&log_file, git_buf_cstr(&log_path));
2078
+ error = git_futils_readbuffer(&log_file, git_str_cstr(&log_path));
1786
2079
  if (error < 0 && error != GIT_ENOTFOUND)
1787
2080
  goto cleanup;
1788
2081
 
1789
2082
  if ((error == GIT_ENOTFOUND) &&
1790
- ((error = create_new_reflog_file(git_buf_cstr(&log_path))) < 0))
2083
+ ((error = create_new_reflog_file(git_str_cstr(&log_path))) < 0))
1791
2084
  goto cleanup;
1792
2085
 
1793
2086
  if ((error = reflog_parse(log,
1794
- git_buf_cstr(&log_file), git_buf_len(&log_file))) < 0)
2087
+ git_str_cstr(&log_file), git_str_len(&log_file))) < 0)
1795
2088
  goto cleanup;
1796
2089
 
1797
2090
  *out = log;
@@ -1801,62 +2094,62 @@ cleanup:
1801
2094
  git_reflog_free(log);
1802
2095
 
1803
2096
  success:
1804
- git_buf_dispose(&log_file);
1805
- git_buf_dispose(&log_path);
2097
+ git_str_dispose(&log_file);
2098
+ git_str_dispose(&log_path);
1806
2099
 
1807
2100
  return error;
1808
2101
  }
1809
2102
 
1810
2103
  static int serialize_reflog_entry(
1811
- git_buf *buf,
2104
+ git_str *buf,
1812
2105
  const git_oid *oid_old,
1813
2106
  const git_oid *oid_new,
1814
2107
  const git_signature *committer,
1815
2108
  const char *msg)
1816
2109
  {
1817
- char raw_old[GIT_OID_HEXSZ+1];
1818
- char raw_new[GIT_OID_HEXSZ+1];
2110
+ char raw_old[GIT_OID_MAX_HEXSIZE + 1];
2111
+ char raw_new[GIT_OID_MAX_HEXSIZE + 1];
1819
2112
 
1820
- git_oid_tostr(raw_old, GIT_OID_HEXSZ+1, oid_old);
1821
- git_oid_tostr(raw_new, GIT_OID_HEXSZ+1, oid_new);
2113
+ git_oid_tostr(raw_old, GIT_OID_MAX_HEXSIZE + 1, oid_old);
2114
+ git_oid_tostr(raw_new, GIT_OID_MAX_HEXSIZE + 1, oid_new);
1822
2115
 
1823
- git_buf_clear(buf);
2116
+ git_str_clear(buf);
1824
2117
 
1825
- git_buf_puts(buf, raw_old);
1826
- git_buf_putc(buf, ' ');
1827
- git_buf_puts(buf, raw_new);
2118
+ git_str_puts(buf, raw_old);
2119
+ git_str_putc(buf, ' ');
2120
+ git_str_puts(buf, raw_new);
1828
2121
 
1829
2122
  git_signature__writebuf(buf, " ", committer);
1830
2123
 
1831
2124
  /* drop trailing LF */
1832
- git_buf_rtrim(buf);
2125
+ git_str_rtrim(buf);
1833
2126
 
1834
2127
  if (msg) {
1835
2128
  size_t i;
1836
2129
 
1837
- git_buf_putc(buf, '\t');
1838
- git_buf_puts(buf, msg);
2130
+ git_str_putc(buf, '\t');
2131
+ git_str_puts(buf, msg);
1839
2132
 
1840
2133
  for (i = 0; i < buf->size - 2; i++)
1841
2134
  if (buf->ptr[i] == '\n')
1842
2135
  buf->ptr[i] = ' ';
1843
- git_buf_rtrim(buf);
2136
+ git_str_rtrim(buf);
1844
2137
  }
1845
2138
 
1846
- git_buf_putc(buf, '\n');
2139
+ git_str_putc(buf, '\n');
1847
2140
 
1848
- return git_buf_oom(buf);
2141
+ return git_str_oom(buf);
1849
2142
  }
1850
2143
 
1851
2144
  static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char *refname)
1852
2145
  {
1853
2146
  git_repository *repo;
1854
- git_buf log_path = GIT_BUF_INIT;
2147
+ git_str log_path = GIT_STR_INIT;
1855
2148
  int error;
1856
2149
 
1857
2150
  repo = backend->repo;
1858
2151
 
1859
- if (!git_path_validate(backend->repo, refname, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
2152
+ if (!git_path_is_valid(backend->repo, refname, 0, GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
1860
2153
  git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", refname);
1861
2154
  return GIT_EINVALIDSPEC;
1862
2155
  }
@@ -1864,17 +2157,17 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char
1864
2157
  if (reflog_path(&log_path, repo, refname) < 0)
1865
2158
  return -1;
1866
2159
 
1867
- if (!git_path_isfile(git_buf_cstr(&log_path))) {
2160
+ if (!git_fs_path_isfile(git_str_cstr(&log_path))) {
1868
2161
  git_error_set(GIT_ERROR_INVALID,
1869
2162
  "log file for reference '%s' doesn't exist", refname);
1870
2163
  error = -1;
1871
2164
  goto cleanup;
1872
2165
  }
1873
2166
 
1874
- error = git_filebuf_open(file, git_buf_cstr(&log_path), 0, GIT_REFLOG_FILE_MODE);
2167
+ error = git_filebuf_open(file, git_str_cstr(&log_path), 0, GIT_REFLOG_FILE_MODE);
1875
2168
 
1876
2169
  cleanup:
1877
- git_buf_dispose(&log_path);
2170
+ git_str_dispose(&log_path);
1878
2171
 
1879
2172
  return error;
1880
2173
  }
@@ -1885,7 +2178,7 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
1885
2178
  unsigned int i;
1886
2179
  git_reflog_entry *entry;
1887
2180
  refdb_fs_backend *backend;
1888
- git_buf log = GIT_BUF_INIT;
2181
+ git_str log = GIT_STR_INIT;
1889
2182
  git_filebuf fbuf = GIT_FILEBUF_INIT;
1890
2183
 
1891
2184
  GIT_ASSERT_ARG(_backend);
@@ -1911,17 +2204,23 @@ cleanup:
1911
2204
  git_filebuf_cleanup(&fbuf);
1912
2205
 
1913
2206
  success:
1914
- git_buf_dispose(&log);
2207
+ git_str_dispose(&log);
1915
2208
 
1916
2209
  return error;
1917
2210
  }
1918
2211
 
1919
2212
  /* 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)
2213
+ static int reflog_append(
2214
+ refdb_fs_backend *backend,
2215
+ const git_reference *ref,
2216
+ const git_oid *old,
2217
+ const git_oid *new,
2218
+ const git_signature *who,
2219
+ const char *message)
1921
2220
  {
1922
2221
  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;
2222
+ git_oid old_id, new_id;
2223
+ git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
1925
2224
  git_repository *repo = backend->repo;
1926
2225
 
1927
2226
  is_symbolic = ref->type == GIT_REFERENCE_SYMBOLIC;
@@ -1934,6 +2233,9 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
1934
2233
 
1935
2234
  /* From here on is_symbolic also means that it's HEAD */
1936
2235
 
2236
+ git_oid_clear(&old_id, backend->oid_type);
2237
+ git_oid_clear(&new_id, backend->oid_type);
2238
+
1937
2239
  if (old) {
1938
2240
  git_oid_cpy(&old_id, old);
1939
2241
  } else {
@@ -1965,7 +2267,7 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
1965
2267
  if ((error = reflog_path(&path, repo, ref->name)) < 0)
1966
2268
  goto cleanup;
1967
2269
 
1968
- if (((error = git_futils_mkpath2file(git_buf_cstr(&path), 0777)) < 0) &&
2270
+ if (((error = git_futils_mkpath2file(git_str_cstr(&path), 0777)) < 0) &&
1969
2271
  (error != GIT_EEXISTS)) {
1970
2272
  goto cleanup;
1971
2273
  }
@@ -1973,11 +2275,11 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
1973
2275
  /* If the new branch matches part of the namespace of a previously deleted branch,
1974
2276
  * there maybe an obsolete/unused directory (or directory hierarchy) in the way.
1975
2277
  */
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) {
2278
+ if (git_fs_path_isdir(git_str_cstr(&path))) {
2279
+ if ((error = git_futils_rmdir_r(git_str_cstr(&path), NULL, GIT_RMDIR_SKIP_NONEMPTY)) < 0) {
1978
2280
  if (error == GIT_ENOTFOUND)
1979
2281
  error = 0;
1980
- } else if (git_path_isdir(git_buf_cstr(&path))) {
2282
+ } else if (git_fs_path_isdir(git_str_cstr(&path))) {
1981
2283
  git_error_set(GIT_ERROR_REFERENCE, "cannot create reflog at '%s', there are reflogs beneath that folder",
1982
2284
  ref->name);
1983
2285
  error = GIT_EDIRECTORY;
@@ -1992,11 +2294,11 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
1992
2294
  if (backend->fsync)
1993
2295
  open_flags |= O_FSYNC;
1994
2296
 
1995
- error = git_futils_writebuffer(&buf, git_buf_cstr(&path), open_flags, GIT_REFLOG_FILE_MODE);
2297
+ error = git_futils_writebuffer(&buf, git_str_cstr(&path), open_flags, GIT_REFLOG_FILE_MODE);
1996
2298
 
1997
2299
  cleanup:
1998
- git_buf_dispose(&buf);
1999
- git_buf_dispose(&path);
2300
+ git_str_dispose(&buf);
2301
+ git_str_dispose(&path);
2000
2302
 
2001
2303
  return error;
2002
2304
  }
@@ -2004,10 +2306,10 @@ cleanup:
2004
2306
  static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_name, const char *new_name)
2005
2307
  {
2006
2308
  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;
2309
+ git_str old_path = GIT_STR_INIT;
2310
+ git_str new_path = GIT_STR_INIT;
2311
+ git_str temp_path = GIT_STR_INIT;
2312
+ git_str normalized = GIT_STR_INIT;
2011
2313
  git_repository *repo;
2012
2314
  refdb_fs_backend *backend;
2013
2315
 
@@ -2022,16 +2324,16 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
2022
2324
  &normalized, new_name, GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL)) < 0)
2023
2325
  return error;
2024
2326
 
2025
- if (git_buf_joinpath(&temp_path, repo->gitdir, GIT_REFLOG_DIR) < 0)
2327
+ if (git_str_joinpath(&temp_path, repo->gitdir, GIT_REFLOG_DIR) < 0)
2026
2328
  return -1;
2027
2329
 
2028
- if ((error = loose_path(&old_path, git_buf_cstr(&temp_path), old_name)) < 0)
2330
+ if ((error = loose_path(&old_path, git_str_cstr(&temp_path), old_name)) < 0)
2029
2331
  return error;
2030
2332
 
2031
- if ((error = loose_path(&new_path, git_buf_cstr(&temp_path), git_buf_cstr(&normalized))) < 0)
2333
+ if ((error = loose_path(&new_path, git_str_cstr(&temp_path), git_str_cstr(&normalized))) < 0)
2032
2334
  return error;
2033
2335
 
2034
- if (!git_path_exists(git_buf_cstr(&old_path))) {
2336
+ if (!git_fs_path_exists(git_str_cstr(&old_path))) {
2035
2337
  error = GIT_ENOTFOUND;
2036
2338
  goto cleanup;
2037
2339
  }
@@ -2043,43 +2345,43 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
2043
2345
  * - a/b -> a/b/c
2044
2346
  * - a/b/c/d -> a/b/c
2045
2347
  */
2046
- if ((error = loose_path(&temp_path, git_buf_cstr(&temp_path), "temp_reflog")) < 0)
2348
+ if ((error = loose_path(&temp_path, git_str_cstr(&temp_path), "temp_reflog")) < 0)
2047
2349
  return error;
2048
2350
 
2049
- if ((fd = git_futils_mktmp(&temp_path, git_buf_cstr(&temp_path), GIT_REFLOG_FILE_MODE)) < 0) {
2351
+ if ((fd = git_futils_mktmp(&temp_path, git_str_cstr(&temp_path), GIT_REFLOG_FILE_MODE)) < 0) {
2050
2352
  error = -1;
2051
2353
  goto cleanup;
2052
2354
  }
2053
2355
 
2054
2356
  p_close(fd);
2055
2357
 
2056
- if (p_rename(git_buf_cstr(&old_path), git_buf_cstr(&temp_path)) < 0) {
2358
+ if (p_rename(git_str_cstr(&old_path), git_str_cstr(&temp_path)) < 0) {
2057
2359
  git_error_set(GIT_ERROR_OS, "failed to rename reflog for %s", new_name);
2058
2360
  error = -1;
2059
2361
  goto cleanup;
2060
2362
  }
2061
2363
 
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)) {
2364
+ if (git_fs_path_isdir(git_str_cstr(&new_path)) &&
2365
+ (git_futils_rmdir_r(git_str_cstr(&new_path), NULL, GIT_RMDIR_SKIP_NONEMPTY) < 0)) {
2064
2366
  error = -1;
2065
2367
  goto cleanup;
2066
2368
  }
2067
2369
 
2068
- if (git_futils_mkpath2file(git_buf_cstr(&new_path), GIT_REFLOG_DIR_MODE) < 0) {
2370
+ if (git_futils_mkpath2file(git_str_cstr(&new_path), GIT_REFLOG_DIR_MODE) < 0) {
2069
2371
  error = -1;
2070
2372
  goto cleanup;
2071
2373
  }
2072
2374
 
2073
- if (p_rename(git_buf_cstr(&temp_path), git_buf_cstr(&new_path)) < 0) {
2375
+ if (p_rename(git_str_cstr(&temp_path), git_str_cstr(&new_path)) < 0) {
2074
2376
  git_error_set(GIT_ERROR_OS, "failed to rename reflog for %s", new_name);
2075
2377
  error = -1;
2076
2378
  }
2077
2379
 
2078
2380
  cleanup:
2079
- git_buf_dispose(&temp_path);
2080
- git_buf_dispose(&old_path);
2081
- git_buf_dispose(&new_path);
2082
- git_buf_dispose(&normalized);
2381
+ git_str_dispose(&temp_path);
2382
+ git_str_dispose(&old_path);
2383
+ git_str_dispose(&new_path);
2384
+ git_str_dispose(&normalized);
2083
2385
 
2084
2386
  return error;
2085
2387
  }
@@ -2087,7 +2389,7 @@ cleanup:
2087
2389
  static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name)
2088
2390
  {
2089
2391
  refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
2090
- git_buf path = GIT_BUF_INIT;
2392
+ git_str path = GIT_STR_INIT;
2091
2393
  int error;
2092
2394
 
2093
2395
  GIT_ASSERT_ARG(_backend);
@@ -2096,7 +2398,7 @@ static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name
2096
2398
  if ((error = reflog_path(&path, backend->repo, name)) < 0)
2097
2399
  goto out;
2098
2400
 
2099
- if (!git_path_exists(path.ptr))
2401
+ if (!git_fs_path_exists(path.ptr))
2100
2402
  goto out;
2101
2403
 
2102
2404
  if ((error = p_unlink(path.ptr)) < 0)
@@ -2105,7 +2407,7 @@ static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name
2105
2407
  error = refdb_fs_backend__prune_refs(backend, name, GIT_REFLOG_DIR);
2106
2408
 
2107
2409
  out:
2108
- git_buf_dispose(&path);
2410
+ git_str_dispose(&path);
2109
2411
 
2110
2412
  return error;
2111
2413
  }
@@ -2115,16 +2417,22 @@ int git_refdb_backend_fs(
2115
2417
  git_repository *repository)
2116
2418
  {
2117
2419
  int t = 0;
2118
- git_buf gitpath = GIT_BUF_INIT;
2420
+ git_str gitpath = GIT_STR_INIT;
2119
2421
  refdb_fs_backend *backend;
2120
2422
 
2121
2423
  backend = git__calloc(1, sizeof(refdb_fs_backend));
2122
2424
  GIT_ERROR_CHECK_ALLOC(backend);
2425
+ if (git_mutex_init(&backend->prlock) < 0) {
2426
+ git__free(backend);
2427
+ return -1;
2428
+ }
2429
+
2123
2430
 
2124
2431
  if (git_refdb_init_backend(&backend->parent, GIT_REFDB_BACKEND_VERSION) < 0)
2125
2432
  goto fail;
2126
2433
 
2127
2434
  backend->repo = repository;
2435
+ backend->oid_type = repository->oid_type;
2128
2436
 
2129
2437
  if (repository->gitdir) {
2130
2438
  backend->gitpath = setup_namespace(repository, repository->gitdir);
@@ -2140,21 +2448,21 @@ int git_refdb_backend_fs(
2140
2448
  goto fail;
2141
2449
  }
2142
2450
 
2143
- if (git_buf_joinpath(&gitpath, backend->commonpath, GIT_PACKEDREFS_FILE) < 0 ||
2451
+ if (git_str_joinpath(&gitpath, backend->commonpath, GIT_PACKEDREFS_FILE) < 0 ||
2144
2452
  git_sortedcache_new(
2145
2453
  &backend->refcache, offsetof(struct packref, name),
2146
- NULL, NULL, packref_cmp, git_buf_cstr(&gitpath)) < 0)
2454
+ NULL, NULL, packref_cmp, git_str_cstr(&gitpath)) < 0)
2147
2455
  goto fail;
2148
2456
 
2149
- git_buf_dispose(&gitpath);
2457
+ git_str_dispose(&gitpath);
2150
2458
 
2151
2459
  if (!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_IGNORECASE) && t) {
2152
2460
  backend->iterator_flags |= GIT_ITERATOR_IGNORE_CASE;
2153
- backend->direach_flags |= GIT_PATH_DIR_IGNORE_CASE;
2461
+ backend->direach_flags |= GIT_FS_PATH_DIR_IGNORE_CASE;
2154
2462
  }
2155
2463
  if (!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_PRECOMPOSE) && t) {
2156
2464
  backend->iterator_flags |= GIT_ITERATOR_PRECOMPOSE_UNICODE;
2157
- backend->direach_flags |= GIT_PATH_DIR_PRECOMPOSE_UNICODE;
2465
+ backend->direach_flags |= GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE;
2158
2466
  }
2159
2467
  if ((!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_FSYNCOBJECTFILES) && t) ||
2160
2468
  git_repository__fsync_gitdir)
@@ -2182,7 +2490,8 @@ int git_refdb_backend_fs(
2182
2490
  return 0;
2183
2491
 
2184
2492
  fail:
2185
- git_buf_dispose(&gitpath);
2493
+ git_mutex_free(&backend->prlock);
2494
+ git_str_dispose(&gitpath);
2186
2495
  git__free(backend->gitpath);
2187
2496
  git__free(backend->commonpath);
2188
2497
  git__free(backend);