rugged 1.3.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (547) 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_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 +38 -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 +18 -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} +107 -71
  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} +54 -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} +690 -366
  280. data/vendor/libgit2/src/{repository.h → libgit2/repository.h} +21 -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} +580 -615
  354. data/vendor/libgit2/src/{path.h → util/fs_path.h} +234 -181
  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
@@ -12,6 +12,7 @@
12
12
  #include "git2/object.h"
13
13
  #include "git2/sys/repository.h"
14
14
 
15
+ #include "buf.h"
15
16
  #include "common.h"
16
17
  #include "commit.h"
17
18
  #include "tag.h"
@@ -31,13 +32,14 @@
31
32
  #include "annotated_commit.h"
32
33
  #include "submodule.h"
33
34
  #include "worktree.h"
34
-
35
+ #include "path.h"
35
36
  #include "strmap.h"
36
37
 
37
38
  #ifdef GIT_WIN32
38
39
  # include "win32/w32_util.h"
39
40
  #endif
40
41
 
42
+ bool git_repository__validate_ownership = true;
41
43
  bool git_repository__fsync_gitdir = false;
42
44
 
43
45
  static const struct {
@@ -64,6 +66,8 @@ static const struct {
64
66
 
65
67
  static int check_repositoryformatversion(int *version, git_config *config);
66
68
  static int check_extensions(git_config *config, int version);
69
+ static int load_global_config(git_config **config);
70
+ static int load_objectformat(git_repository *repo, git_config *config);
67
71
 
68
72
  #define GIT_COMMONDIR_FILE "commondir"
69
73
  #define GIT_GITDIR_FILE "gitdir"
@@ -72,16 +76,16 @@ static int check_extensions(git_config *config, int version);
72
76
 
73
77
  #define GIT_BRANCH_DEFAULT "master"
74
78
 
75
- #define GIT_REPO_VERSION 0
76
- #define GIT_REPO_MAX_VERSION 1
79
+ #define GIT_REPO_VERSION_DEFAULT 0
80
+ #define GIT_REPO_VERSION_MAX 1
77
81
 
78
- git_buf git_repository__reserved_names_win32[] = {
82
+ git_str git_repository__reserved_names_win32[] = {
79
83
  { DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
80
84
  { GIT_DIR_SHORTNAME, 0, CONST_STRLEN(GIT_DIR_SHORTNAME) }
81
85
  };
82
86
  size_t git_repository__reserved_names_win32_len = 2;
83
87
 
84
- git_buf git_repository__reserved_names_posix[] = {
88
+ git_str git_repository__reserved_names_posix[] = {
85
89
  { DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
86
90
  };
87
91
  size_t git_repository__reserved_names_posix_len = 1;
@@ -171,7 +175,7 @@ void git_repository_free(git_repository *repo)
171
175
  repo->diff_drivers = NULL;
172
176
 
173
177
  for (i = 0; i < repo->reserved_names.size; i++)
174
- git_buf_dispose(git_array_get(repo->reserved_names, i));
178
+ git_str_dispose(git_array_get(repo->reserved_names, i));
175
179
  git_array_clear(repo->reserved_names);
176
180
 
177
181
  git__free(repo->gitlink);
@@ -187,18 +191,18 @@ void git_repository_free(git_repository *repo)
187
191
  }
188
192
 
189
193
  /* Check if we have a separate commondir (e.g. we have a worktree) */
190
- static int lookup_commondir(bool *separate, git_buf *commondir, git_buf *repository_path)
194
+ static int lookup_commondir(bool *separate, git_str *commondir, git_str *repository_path)
191
195
  {
192
- git_buf common_link = GIT_BUF_INIT;
196
+ git_str common_link = GIT_STR_INIT;
193
197
  int error;
194
198
 
195
199
  /*
196
200
  * If there's no commondir file, the repository path is the
197
201
  * common path, but it needs a trailing slash.
198
202
  */
199
- if (!git_path_contains_file(repository_path, GIT_COMMONDIR_FILE)) {
200
- if ((error = git_buf_set(commondir, repository_path->ptr, repository_path->size)) == 0)
201
- error = git_path_to_dir(commondir);
203
+ if (!git_fs_path_contains_file(repository_path, GIT_COMMONDIR_FILE)) {
204
+ if ((error = git_str_set(commondir, repository_path->ptr, repository_path->size)) == 0)
205
+ error = git_fs_path_to_dir(commondir);
202
206
 
203
207
  *separate = false;
204
208
  goto done;
@@ -206,28 +210,28 @@ static int lookup_commondir(bool *separate, git_buf *commondir, git_buf *reposit
206
210
 
207
211
  *separate = true;
208
212
 
209
- if ((error = git_buf_joinpath(&common_link, repository_path->ptr, GIT_COMMONDIR_FILE)) < 0 ||
213
+ if ((error = git_str_joinpath(&common_link, repository_path->ptr, GIT_COMMONDIR_FILE)) < 0 ||
210
214
  (error = git_futils_readbuffer(&common_link, common_link.ptr)) < 0)
211
215
  goto done;
212
216
 
213
- git_buf_rtrim(&common_link);
214
- if (git_path_is_relative(common_link.ptr)) {
215
- if ((error = git_buf_joinpath(commondir, repository_path->ptr, common_link.ptr)) < 0)
217
+ git_str_rtrim(&common_link);
218
+ if (git_fs_path_is_relative(common_link.ptr)) {
219
+ if ((error = git_str_joinpath(commondir, repository_path->ptr, common_link.ptr)) < 0)
216
220
  goto done;
217
221
  } else {
218
- git_buf_swap(commondir, &common_link);
222
+ git_str_swap(commondir, &common_link);
219
223
  }
220
224
 
221
- git_buf_dispose(&common_link);
225
+ git_str_dispose(&common_link);
222
226
 
223
227
  /* Make sure the commondir path always has a trailing slash */
224
- error = git_path_prettify_dir(commondir, commondir->ptr, NULL);
228
+ error = git_fs_path_prettify_dir(commondir, commondir->ptr, NULL);
225
229
 
226
230
  done:
227
231
  return error;
228
232
  }
229
233
 
230
- GIT_INLINE(int) validate_repo_path(git_buf *path)
234
+ GIT_INLINE(int) validate_repo_path(git_str *path)
231
235
  {
232
236
  /*
233
237
  * The longest static path in a repository (or commondir) is the
@@ -237,10 +241,10 @@ GIT_INLINE(int) validate_repo_path(git_buf *path)
237
241
  */
238
242
  static size_t suffix_len =
239
243
  CONST_STRLEN("objects/pack/pack-.pack.lock") +
240
- GIT_OID_HEXSZ;
244
+ GIT_OID_MAX_HEXSIZE;
241
245
 
242
- return git_path_validate_filesystem_with_suffix(
243
- path->ptr, path->size, suffix_len);
246
+ return git_fs_path_validate_str_length_with_suffix(
247
+ path, suffix_len);
244
248
  }
245
249
 
246
250
  /*
@@ -248,7 +252,7 @@ GIT_INLINE(int) validate_repo_path(git_buf *path)
248
252
  *
249
253
  * Open a repository object from its path
250
254
  */
251
- static int is_valid_repository_path(bool *out, git_buf *repository_path, git_buf *common_path)
255
+ static int is_valid_repository_path(bool *out, git_str *repository_path, git_str *common_path)
252
256
  {
253
257
  bool separate_commondir = false;
254
258
  int error;
@@ -259,13 +263,13 @@ static int is_valid_repository_path(bool *out, git_buf *repository_path, git_buf
259
263
  return error;
260
264
 
261
265
  /* Ensure HEAD file exists */
262
- if (git_path_contains_file(repository_path, GIT_HEAD_FILE) == false)
266
+ if (git_fs_path_contains_file(repository_path, GIT_HEAD_FILE) == false)
263
267
  return 0;
264
268
 
265
269
  /* Check files in common dir */
266
- if (git_path_contains_dir(common_path, GIT_OBJECTS_DIR) == false)
270
+ if (git_fs_path_contains_dir(common_path, GIT_OBJECTS_DIR) == false)
267
271
  return 0;
268
- if (git_path_contains_dir(common_path, GIT_REFS_DIR) == false)
272
+ if (git_fs_path_contains_dir(common_path, GIT_REFS_DIR) == false)
269
273
  return 0;
270
274
 
271
275
  /* Ensure the repo (and commondir) are valid paths */
@@ -333,12 +337,12 @@ static int load_config_data(git_repository *repo, const git_config *config)
333
337
  return 0;
334
338
  }
335
339
 
336
- static int load_workdir(git_repository *repo, git_config *config, git_buf *parent_path)
340
+ static int load_workdir(git_repository *repo, git_config *config, git_str *parent_path)
337
341
  {
338
342
  int error;
339
343
  git_config_entry *ce;
340
- git_buf worktree = GIT_BUF_INIT;
341
- git_buf path = GIT_BUF_INIT;
344
+ git_str worktree = GIT_STR_INIT;
345
+ git_str path = GIT_STR_INIT;
342
346
 
343
347
  if (repo->is_bare)
344
348
  return 0;
@@ -354,38 +358,38 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren
354
358
  goto cleanup;
355
359
  }
356
360
 
357
- git_buf_attach(&worktree, gitlink, 0);
361
+ git_str_attach(&worktree, gitlink, 0);
358
362
 
359
- if ((git_path_dirname_r(&worktree, worktree.ptr)) < 0 ||
360
- git_path_to_dir(&worktree) < 0) {
363
+ if ((git_fs_path_dirname_r(&worktree, worktree.ptr)) < 0 ||
364
+ git_fs_path_to_dir(&worktree) < 0) {
361
365
  error = -1;
362
366
  goto cleanup;
363
367
  }
364
368
 
365
- repo->workdir = git_buf_detach(&worktree);
369
+ repo->workdir = git_str_detach(&worktree);
366
370
  }
367
371
  else if (ce && ce->value) {
368
- if ((error = git_path_prettify_dir(
372
+ if ((error = git_fs_path_prettify_dir(
369
373
  &worktree, ce->value, repo->gitdir)) < 0)
370
374
  goto cleanup;
371
375
 
372
- repo->workdir = git_buf_detach(&worktree);
376
+ repo->workdir = git_str_detach(&worktree);
373
377
  }
374
- else if (parent_path && git_path_isdir(parent_path->ptr))
375
- repo->workdir = git_buf_detach(parent_path);
378
+ else if (parent_path && git_fs_path_isdir(parent_path->ptr))
379
+ repo->workdir = git_str_detach(parent_path);
376
380
  else {
377
- if (git_path_dirname_r(&worktree, repo->gitdir) < 0 ||
378
- git_path_to_dir(&worktree) < 0) {
381
+ if (git_fs_path_dirname_r(&worktree, repo->gitdir) < 0 ||
382
+ git_fs_path_to_dir(&worktree) < 0) {
379
383
  error = -1;
380
384
  goto cleanup;
381
385
  }
382
386
 
383
- repo->workdir = git_buf_detach(&worktree);
387
+ repo->workdir = git_str_detach(&worktree);
384
388
  }
385
389
 
386
390
  GIT_ERROR_CHECK_ALLOC(repo->workdir);
387
391
  cleanup:
388
- git_buf_dispose(&path);
392
+ git_str_dispose(&path);
389
393
  git_config_entry_free(ce);
390
394
  return error;
391
395
  }
@@ -394,7 +398,7 @@ cleanup:
394
398
  * This function returns furthest offset into path where a ceiling dir
395
399
  * is found, so we can stop processing the path at that point.
396
400
  *
397
- * Note: converting this to use git_bufs instead of GIT_PATH_MAX buffers on
401
+ * Note: converting this to use git_strs instead of GIT_PATH_MAX buffers on
398
402
  * the stack could remove directories name limits, but at the cost of doing
399
403
  * repeated malloc/frees inside the loop below, so let's not do it now.
400
404
  */
@@ -409,7 +413,7 @@ static size_t find_ceiling_dir_offset(
409
413
 
410
414
  GIT_ASSERT_ARG(path);
411
415
 
412
- min_len = (size_t)(git_path_root(path) + 1);
416
+ min_len = (size_t)(git_fs_path_root(path) + 1);
413
417
 
414
418
  if (ceiling_directories == NULL || min_len == 0)
415
419
  return min_len;
@@ -418,7 +422,7 @@ static size_t find_ceiling_dir_offset(
418
422
  for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++);
419
423
  len = sep - ceil;
420
424
 
421
- if (len == 0 || len >= sizeof(buf) || git_path_root(ceil) == -1)
425
+ if (len == 0 || len >= sizeof(buf) || git_fs_path_root(ceil) == -1)
422
426
  continue;
423
427
 
424
428
  strncpy(buf, ceil, len);
@@ -447,10 +451,10 @@ static size_t find_ceiling_dir_offset(
447
451
  * it points to. Before calling, set `path_out` to the base directory that
448
452
  * should be used if the contents of `file_path` are a relative path.
449
453
  */
450
- static int read_gitfile(git_buf *path_out, const char *file_path)
454
+ static int read_gitfile(git_str *path_out, const char *file_path)
451
455
  {
452
456
  int error = 0;
453
- git_buf file = GIT_BUF_INIT;
457
+ git_str file = GIT_STR_INIT;
454
458
  size_t prefix_len = strlen(GIT_FILE_CONTENT_PREFIX);
455
459
 
456
460
  GIT_ASSERT_ARG(path_out);
@@ -459,41 +463,192 @@ static int read_gitfile(git_buf *path_out, const char *file_path)
459
463
  if (git_futils_readbuffer(&file, file_path) < 0)
460
464
  return -1;
461
465
 
462
- git_buf_rtrim(&file);
466
+ git_str_rtrim(&file);
463
467
  /* apparently on Windows, some people use backslashes in paths */
464
- git_path_mkposix(file.ptr);
468
+ git_fs_path_mkposix(file.ptr);
465
469
 
466
- if (git_buf_len(&file) <= prefix_len ||
467
- memcmp(git_buf_cstr(&file), GIT_FILE_CONTENT_PREFIX, prefix_len) != 0)
470
+ if (git_str_len(&file) <= prefix_len ||
471
+ memcmp(git_str_cstr(&file), GIT_FILE_CONTENT_PREFIX, prefix_len) != 0)
468
472
  {
469
473
  git_error_set(GIT_ERROR_REPOSITORY,
470
474
  "the `.git` file at '%s' is malformed", file_path);
471
475
  error = -1;
472
476
  }
473
- else if ((error = git_path_dirname_r(path_out, file_path)) >= 0) {
474
- const char *gitlink = git_buf_cstr(&file) + prefix_len;
477
+ else if ((error = git_fs_path_dirname_r(path_out, file_path)) >= 0) {
478
+ const char *gitlink = git_str_cstr(&file) + prefix_len;
475
479
  while (*gitlink && git__isspace(*gitlink)) gitlink++;
476
480
 
477
- error = git_path_prettify_dir(
478
- path_out, gitlink, git_buf_cstr(path_out));
481
+ error = git_fs_path_prettify_dir(
482
+ path_out, gitlink, git_str_cstr(path_out));
483
+ }
484
+
485
+ git_str_dispose(&file);
486
+ return error;
487
+ }
488
+
489
+ typedef struct {
490
+ const char *repo_path;
491
+ git_str tmp;
492
+ bool *is_safe;
493
+ } validate_ownership_data;
494
+
495
+ static int validate_ownership_cb(const git_config_entry *entry, void *payload)
496
+ {
497
+ validate_ownership_data *data = payload;
498
+
499
+ if (strcmp(entry->value, "") == 0) {
500
+ *data->is_safe = false;
501
+ } else if (strcmp(entry->value, "*") == 0) {
502
+ *data->is_safe = true;
503
+ } else {
504
+ const char *test_path = entry->value;
505
+
506
+ #ifdef GIT_WIN32
507
+ /*
508
+ * Git for Windows does some truly bizarre things with
509
+ * paths that start with a forward slash; and expects you
510
+ * to escape that with `%(prefix)`. This syntax generally
511
+ * means to add the prefix that Git was installed to -- eg
512
+ * `/usr/local` -- unless it's an absolute path, in which
513
+ * case the leading `%(prefix)/` is just removed. And Git
514
+ * for Windows expects you to use this syntax for absolute
515
+ * Unix-style paths (in "Git Bash" or Windows Subsystem for
516
+ * Linux).
517
+ *
518
+ * Worse, the behavior used to be that a leading `/` was
519
+ * not absolute. It would indicate that Git for Windows
520
+ * should add the prefix. So `//` is required for absolute
521
+ * Unix-style paths. Yes, this is truly horrifying.
522
+ *
523
+ * Emulate that behavior, I guess, but only for absolute
524
+ * paths. We won't deal with the Git install prefix. Also,
525
+ * give WSL users an escape hatch where they don't have to
526
+ * think about this and can use the literal path that the
527
+ * filesystem APIs provide (`//wsl.localhost/...`).
528
+ */
529
+ if (strncmp(test_path, "%(prefix)//", strlen("%(prefix)//")) == 0)
530
+ test_path += strlen("%(prefix)/");
531
+ else if (strncmp(test_path, "//", 2) == 0 &&
532
+ strncmp(test_path, "//wsl.localhost/", strlen("//wsl.localhost/")) != 0)
533
+ test_path++;
534
+ #endif
535
+
536
+ if (git_fs_path_prettify_dir(&data->tmp, test_path, NULL) == 0 &&
537
+ strcmp(data->tmp.ptr, data->repo_path) == 0)
538
+ *data->is_safe = true;
539
+ }
540
+
541
+ return 0;
542
+ }
543
+
544
+ static int validate_ownership_config(bool *is_safe, const char *path)
545
+ {
546
+ validate_ownership_data ownership_data = {
547
+ path, GIT_STR_INIT, is_safe
548
+ };
549
+ git_config *config;
550
+ int error;
551
+
552
+ if (load_global_config(&config) != 0)
553
+ return 0;
554
+
555
+ error = git_config_get_multivar_foreach(config,
556
+ "safe.directory", NULL,
557
+ validate_ownership_cb,
558
+ &ownership_data);
559
+
560
+ if (error == GIT_ENOTFOUND)
561
+ error = 0;
562
+
563
+ git_config_free(config);
564
+ git_str_dispose(&ownership_data.tmp);
565
+
566
+ return error;
567
+ }
568
+
569
+ static int validate_ownership_path(bool *is_safe, const char *path)
570
+ {
571
+ git_fs_path_owner_t owner_level =
572
+ GIT_FS_PATH_OWNER_CURRENT_USER |
573
+ GIT_FS_PATH_USER_IS_ADMINISTRATOR |
574
+ GIT_FS_PATH_OWNER_RUNNING_SUDO;
575
+ int error = 0;
576
+
577
+ if (path)
578
+ error = git_fs_path_owner_is(is_safe, path, owner_level);
579
+
580
+ if (error == GIT_ENOTFOUND) {
581
+ *is_safe = true;
582
+ error = 0;
583
+ } else if (error == GIT_EINVALID) {
584
+ *is_safe = false;
585
+ error = 0;
586
+ }
587
+
588
+ return error;
589
+ }
590
+
591
+ static int validate_ownership(git_repository *repo)
592
+ {
593
+ const char *validation_paths[3] = { NULL }, *path;
594
+ size_t validation_len = 0, i;
595
+ bool is_safe = false;
596
+ int error = 0;
597
+
598
+ /*
599
+ * If there's a worktree, validate the permissions to it *and*
600
+ * the git directory, and use the worktree as the configuration
601
+ * key for allowlisting the directory. In a bare setup, only
602
+ * look at the gitdir and use that as the allowlist. So we
603
+ * examine all `validation_paths` but use only the first as
604
+ * the configuration lookup.
605
+ */
606
+
607
+ if (repo->workdir)
608
+ validation_paths[validation_len++] = repo->workdir;
609
+
610
+ if (repo->gitlink)
611
+ validation_paths[validation_len++] = repo->gitlink;
612
+
613
+ validation_paths[validation_len++] = repo->gitdir;
614
+
615
+ for (i = 0; i < validation_len; i++) {
616
+ path = validation_paths[i];
617
+
618
+ if ((error = validate_ownership_path(&is_safe, path)) < 0)
619
+ goto done;
620
+
621
+ if (!is_safe)
622
+ break;
623
+ }
624
+
625
+ if (is_safe ||
626
+ (error = validate_ownership_config(&is_safe, validation_paths[0])) < 0)
627
+ goto done;
628
+
629
+ if (!is_safe) {
630
+ git_error_set(GIT_ERROR_CONFIG,
631
+ "repository path '%s' is not owned by current user",
632
+ path);
633
+ error = GIT_EOWNER;
479
634
  }
480
635
 
481
- git_buf_dispose(&file);
636
+ done:
482
637
  return error;
483
638
  }
484
639
 
485
640
  static int find_repo(
486
- git_buf *gitdir_path,
487
- git_buf *workdir_path,
488
- git_buf *gitlink_path,
489
- git_buf *commondir_path,
641
+ git_str *gitdir_path,
642
+ git_str *workdir_path,
643
+ git_str *gitlink_path,
644
+ git_str *commondir_path,
490
645
  const char *start_path,
491
646
  uint32_t flags,
492
647
  const char *ceiling_dirs)
493
648
  {
494
- git_buf path = GIT_BUF_INIT;
495
- git_buf repo_link = GIT_BUF_INIT;
496
- git_buf common_link = GIT_BUF_INIT;
649
+ git_str path = GIT_STR_INIT;
650
+ git_str repo_link = GIT_STR_INIT;
651
+ git_str common_link = GIT_STR_INIT;
497
652
  struct stat st;
498
653
  dev_t initial_device = 0;
499
654
  int min_iterations;
@@ -501,9 +656,9 @@ static int find_repo(
501
656
  size_t ceiling_offset = 0;
502
657
  int error;
503
658
 
504
- git_buf_clear(gitdir_path);
659
+ git_str_clear(gitdir_path);
505
660
 
506
- error = git_path_prettify(&path, start_path, NULL);
661
+ error = git_fs_path_prettify(&path, start_path, NULL);
507
662
  if (error < 0)
508
663
  return error;
509
664
 
@@ -525,7 +680,7 @@ static int find_repo(
525
680
  for (;;) {
526
681
  if (!(flags & GIT_REPOSITORY_OPEN_NO_DOTGIT)) {
527
682
  if (!in_dot_git) {
528
- if ((error = git_buf_joinpath(&path, path.ptr, DOT_GIT)) < 0)
683
+ if ((error = git_str_joinpath(&path, path.ptr, DOT_GIT)) < 0)
529
684
  goto out;
530
685
  }
531
686
  in_dot_git = !in_dot_git;
@@ -544,15 +699,15 @@ static int find_repo(
544
699
  goto out;
545
700
 
546
701
  if (is_valid) {
547
- if ((error = git_path_to_dir(&path)) < 0 ||
548
- (error = git_buf_set(gitdir_path, path.ptr, path.size)) < 0)
702
+ if ((error = git_fs_path_to_dir(&path)) < 0 ||
703
+ (error = git_str_set(gitdir_path, path.ptr, path.size)) < 0)
549
704
  goto out;
550
705
 
551
706
  if (gitlink_path)
552
- if ((error = git_buf_attach(gitlink_path, git_worktree__read_link(path.ptr, GIT_GITDIR_FILE), 0)) < 0)
707
+ if ((error = git_str_attach(gitlink_path, git_worktree__read_link(path.ptr, GIT_GITDIR_FILE), 0)) < 0)
553
708
  goto out;
554
709
  if (commondir_path)
555
- git_buf_swap(&common_link, commondir_path);
710
+ git_str_swap(&common_link, commondir_path);
556
711
 
557
712
  break;
558
713
  }
@@ -562,13 +717,13 @@ static int find_repo(
562
717
  goto out;
563
718
 
564
719
  if (is_valid) {
565
- git_buf_swap(gitdir_path, &repo_link);
720
+ git_str_swap(gitdir_path, &repo_link);
566
721
 
567
722
  if (gitlink_path)
568
- if ((error = git_buf_put(gitlink_path, path.ptr, path.size)) < 0)
723
+ if ((error = git_str_put(gitlink_path, path.ptr, path.size)) < 0)
569
724
  goto out;
570
725
  if (commondir_path)
571
- git_buf_swap(&common_link, commondir_path);
726
+ git_str_swap(&common_link, commondir_path);
572
727
  }
573
728
  break;
574
729
  }
@@ -577,7 +732,7 @@ static int find_repo(
577
732
  /* Move up one directory. If we're in_dot_git, we'll search the
578
733
  * parent itself next. If we're !in_dot_git, we'll search .git
579
734
  * in the parent directory next (added at the top of the loop). */
580
- if ((error = git_path_dirname_r(&path, path.ptr)) < 0)
735
+ if ((error = git_fs_path_dirname_r(&path, path.ptr)) < 0)
581
736
  goto out;
582
737
 
583
738
  /* Once we've checked the directory (and .git if applicable),
@@ -592,25 +747,62 @@ static int find_repo(
592
747
  }
593
748
 
594
749
  if (workdir_path && !(flags & GIT_REPOSITORY_OPEN_BARE)) {
595
- if (!git_buf_len(gitdir_path))
596
- git_buf_clear(workdir_path);
597
- else if ((error = git_path_dirname_r(workdir_path, path.ptr)) < 0 ||
598
- (error = git_path_to_dir(workdir_path)) < 0)
750
+ if (!git_str_len(gitdir_path))
751
+ git_str_clear(workdir_path);
752
+ else if ((error = git_fs_path_dirname_r(workdir_path, path.ptr)) < 0 ||
753
+ (error = git_fs_path_to_dir(workdir_path)) < 0)
599
754
  goto out;
600
755
  }
601
756
 
602
757
  /* If we didn't find the repository, and we don't have any other error
603
758
  * to report, report that. */
604
- if (!git_buf_len(gitdir_path)) {
759
+ if (!git_str_len(gitdir_path)) {
605
760
  git_error_set(GIT_ERROR_REPOSITORY, "could not find repository from '%s'", start_path);
606
761
  error = GIT_ENOTFOUND;
607
762
  goto out;
608
763
  }
609
764
 
610
765
  out:
611
- git_buf_dispose(&path);
612
- git_buf_dispose(&repo_link);
613
- git_buf_dispose(&common_link);
766
+ git_str_dispose(&path);
767
+ git_str_dispose(&repo_link);
768
+ git_str_dispose(&common_link);
769
+ return error;
770
+ }
771
+
772
+ static int obtain_config_and_set_oid_type(
773
+ git_config **config_ptr,
774
+ git_repository *repo)
775
+ {
776
+ int error;
777
+ git_config *config = NULL;
778
+ int version = 0;
779
+
780
+ /*
781
+ * We'd like to have the config, but git doesn't particularly
782
+ * care if it's not there, so we need to deal with that.
783
+ */
784
+
785
+ error = git_repository_config_snapshot(&config, repo);
786
+ if (error < 0 && error != GIT_ENOTFOUND)
787
+ goto out;
788
+
789
+ if (config &&
790
+ (error = check_repositoryformatversion(&version, config)) < 0)
791
+ goto out;
792
+
793
+ if ((error = check_extensions(config, version)) < 0)
794
+ goto out;
795
+
796
+ if (version > 0) {
797
+ if ((error = load_objectformat(repo, config)) < 0)
798
+ goto out;
799
+ } else {
800
+ repo->oid_type = GIT_OID_SHA1;
801
+ }
802
+
803
+ out:
804
+ *config_ptr = config;
805
+
614
806
  return error;
615
807
  }
616
808
 
@@ -618,18 +810,19 @@ int git_repository_open_bare(
618
810
  git_repository **repo_ptr,
619
811
  const char *bare_path)
620
812
  {
621
- git_buf path = GIT_BUF_INIT, common_path = GIT_BUF_INIT;
813
+ git_str path = GIT_STR_INIT, common_path = GIT_STR_INIT;
622
814
  git_repository *repo = NULL;
623
815
  bool is_valid;
624
816
  int error;
817
+ git_config *config;
625
818
 
626
- if ((error = git_path_prettify_dir(&path, bare_path, NULL)) < 0 ||
819
+ if ((error = git_fs_path_prettify_dir(&path, bare_path, NULL)) < 0 ||
627
820
  (error = is_valid_repository_path(&is_valid, &path, &common_path)) < 0)
628
821
  return error;
629
822
 
630
823
  if (!is_valid) {
631
- git_buf_dispose(&path);
632
- git_buf_dispose(&common_path);
824
+ git_str_dispose(&path);
825
+ git_str_dispose(&common_path);
633
826
  git_error_set(GIT_ERROR_REPOSITORY, "path is not a repository: %s", bare_path);
634
827
  return GIT_ENOTFOUND;
635
828
  }
@@ -637,9 +830,9 @@ int git_repository_open_bare(
637
830
  repo = repository_alloc();
638
831
  GIT_ERROR_CHECK_ALLOC(repo);
639
832
 
640
- repo->gitdir = git_buf_detach(&path);
833
+ repo->gitdir = git_str_detach(&path);
641
834
  GIT_ERROR_CHECK_ALLOC(repo->gitdir);
642
- repo->commondir = git_buf_detach(&common_path);
835
+ repo->commondir = git_str_detach(&common_path);
643
836
  GIT_ERROR_CHECK_ALLOC(repo->commondir);
644
837
 
645
838
  /* of course we're bare! */
@@ -647,8 +840,15 @@ int git_repository_open_bare(
647
840
  repo->is_worktree = 0;
648
841
  repo->workdir = NULL;
649
842
 
843
+ if ((error = obtain_config_and_set_oid_type(&config, repo)) < 0)
844
+ goto cleanup;
845
+
650
846
  *repo_ptr = repo;
651
- return 0;
847
+
848
+ cleanup:
849
+ git_config_free(config);
850
+
851
+ return error;
652
852
  }
653
853
 
654
854
  static int _git_repository_open_ext_from_env(
@@ -658,15 +858,15 @@ static int _git_repository_open_ext_from_env(
658
858
  git_repository *repo = NULL;
659
859
  git_index *index = NULL;
660
860
  git_odb *odb = NULL;
661
- git_buf dir_buf = GIT_BUF_INIT;
662
- git_buf ceiling_dirs_buf = GIT_BUF_INIT;
663
- git_buf across_fs_buf = GIT_BUF_INIT;
664
- git_buf index_file_buf = GIT_BUF_INIT;
665
- git_buf namespace_buf = GIT_BUF_INIT;
666
- git_buf object_dir_buf = GIT_BUF_INIT;
667
- git_buf alts_buf = GIT_BUF_INIT;
668
- git_buf work_tree_buf = GIT_BUF_INIT;
669
- git_buf common_dir_buf = GIT_BUF_INIT;
861
+ git_str dir_buf = GIT_STR_INIT;
862
+ git_str ceiling_dirs_buf = GIT_STR_INIT;
863
+ git_str across_fs_buf = GIT_STR_INIT;
864
+ git_str index_file_buf = GIT_STR_INIT;
865
+ git_str namespace_buf = GIT_STR_INIT;
866
+ git_str object_dir_buf = GIT_STR_INIT;
867
+ git_str alts_buf = GIT_STR_INIT;
868
+ git_str work_tree_buf = GIT_STR_INIT;
869
+ git_str common_dir_buf = GIT_STR_INIT;
670
870
  const char *ceiling_dirs = NULL;
671
871
  unsigned flags = 0;
672
872
  int error;
@@ -679,7 +879,7 @@ static int _git_repository_open_ext_from_env(
679
879
  } else if (error < 0)
680
880
  goto error;
681
881
  else {
682
- start_path = git_buf_cstr(&dir_buf);
882
+ start_path = git_str_cstr(&dir_buf);
683
883
  flags |= GIT_REPOSITORY_OPEN_NO_SEARCH;
684
884
  flags |= GIT_REPOSITORY_OPEN_NO_DOTGIT;
685
885
  }
@@ -691,7 +891,7 @@ static int _git_repository_open_ext_from_env(
691
891
  else if (error < 0)
692
892
  goto error;
693
893
  else
694
- ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf);
894
+ ceiling_dirs = git_str_cstr(&ceiling_dirs_buf);
695
895
 
696
896
  error = git__getenv(&across_fs_buf, "GIT_DISCOVERY_ACROSS_FILESYSTEM");
697
897
  if (error == GIT_ENOTFOUND)
@@ -700,7 +900,7 @@ static int _git_repository_open_ext_from_env(
700
900
  goto error;
701
901
  else {
702
902
  int across_fs = 0;
703
- error = git_config_parse_bool(&across_fs, git_buf_cstr(&across_fs_buf));
903
+ error = git_config_parse_bool(&across_fs, git_str_cstr(&across_fs_buf));
704
904
  if (error < 0)
705
905
  goto error;
706
906
  if (across_fs)
@@ -713,7 +913,7 @@ static int _git_repository_open_ext_from_env(
713
913
  else if (error < 0)
714
914
  goto error;
715
915
  else {
716
- error = git_index_open(&index, git_buf_cstr(&index_file_buf));
916
+ error = git_index_open(&index, git_str_cstr(&index_file_buf));
717
917
  if (error < 0)
718
918
  goto error;
719
919
  }
@@ -730,7 +930,7 @@ static int _git_repository_open_ext_from_env(
730
930
  else if (error < 0)
731
931
  goto error;
732
932
  else {
733
- error = git_odb_open(&odb, git_buf_cstr(&object_dir_buf));
933
+ error = git_odb__open(&odb, git_str_cstr(&object_dir_buf), NULL);
734
934
  if (error < 0)
735
935
  goto error;
736
936
  }
@@ -779,7 +979,7 @@ static int _git_repository_open_ext_from_env(
779
979
  goto error;
780
980
  }
781
981
 
782
- end = git_buf_cstr(&alts_buf) + git_buf_len(&alts_buf);
982
+ end = git_str_cstr(&alts_buf) + git_str_len(&alts_buf);
783
983
  for (sep = alt = alts_buf.ptr; sep != end; alt = sep+1) {
784
984
  for (sep = alt; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++)
785
985
  ;
@@ -791,8 +991,8 @@ static int _git_repository_open_ext_from_env(
791
991
  }
792
992
  }
793
993
 
794
- if (git_buf_len(&namespace_buf)) {
795
- error = git_repository_set_namespace(repo, git_buf_cstr(&namespace_buf));
994
+ if (git_str_len(&namespace_buf)) {
995
+ error = git_repository_set_namespace(repo, git_str_cstr(&namespace_buf));
796
996
  if (error < 0)
797
997
  goto error;
798
998
  }
@@ -808,21 +1008,21 @@ error:
808
1008
  success:
809
1009
  git_odb_free(odb);
810
1010
  git_index_free(index);
811
- git_buf_dispose(&common_dir_buf);
812
- git_buf_dispose(&work_tree_buf);
813
- git_buf_dispose(&alts_buf);
814
- git_buf_dispose(&object_dir_buf);
815
- git_buf_dispose(&namespace_buf);
816
- git_buf_dispose(&index_file_buf);
817
- git_buf_dispose(&across_fs_buf);
818
- git_buf_dispose(&ceiling_dirs_buf);
819
- git_buf_dispose(&dir_buf);
1011
+ git_str_dispose(&common_dir_buf);
1012
+ git_str_dispose(&work_tree_buf);
1013
+ git_str_dispose(&alts_buf);
1014
+ git_str_dispose(&object_dir_buf);
1015
+ git_str_dispose(&namespace_buf);
1016
+ git_str_dispose(&index_file_buf);
1017
+ git_str_dispose(&across_fs_buf);
1018
+ git_str_dispose(&ceiling_dirs_buf);
1019
+ git_str_dispose(&dir_buf);
820
1020
  return error;
821
1021
  }
822
1022
 
823
1023
  static int repo_is_worktree(unsigned *out, const git_repository *repo)
824
1024
  {
825
- git_buf gitdir_link = GIT_BUF_INIT;
1025
+ git_str gitdir_link = GIT_STR_INIT;
826
1026
  int error;
827
1027
 
828
1028
  /* Worktrees cannot have the same commondir and gitdir */
@@ -832,14 +1032,14 @@ static int repo_is_worktree(unsigned *out, const git_repository *repo)
832
1032
  return 0;
833
1033
  }
834
1034
 
835
- if ((error = git_buf_joinpath(&gitdir_link, repo->gitdir, "gitdir")) < 0)
1035
+ if ((error = git_str_joinpath(&gitdir_link, repo->gitdir, "gitdir")) < 0)
836
1036
  return -1;
837
1037
 
838
1038
  /* A 'gitdir' file inside a git directory is currently
839
1039
  * only used when the repository is a working tree. */
840
- *out = !!git_path_exists(gitdir_link.ptr);
1040
+ *out = !!git_fs_path_exists(gitdir_link.ptr);
841
1041
 
842
- git_buf_dispose(&gitdir_link);
1042
+ git_str_dispose(&gitdir_link);
843
1043
  return error;
844
1044
  }
845
1045
 
@@ -851,11 +1051,10 @@ int git_repository_open_ext(
851
1051
  {
852
1052
  int error;
853
1053
  unsigned is_worktree;
854
- git_buf gitdir = GIT_BUF_INIT, workdir = GIT_BUF_INIT,
855
- gitlink = GIT_BUF_INIT, commondir = GIT_BUF_INIT;
1054
+ git_str gitdir = GIT_STR_INIT, workdir = GIT_STR_INIT,
1055
+ gitlink = GIT_STR_INIT, commondir = GIT_STR_INIT;
856
1056
  git_repository *repo = NULL;
857
1057
  git_config *config = NULL;
858
- int version = 0;
859
1058
 
860
1059
  if (flags & GIT_REPOSITORY_OPEN_FROM_ENV)
861
1060
  return _git_repository_open_ext_from_env(repo_ptr, start_path);
@@ -872,15 +1071,15 @@ int git_repository_open_ext(
872
1071
  repo = repository_alloc();
873
1072
  GIT_ERROR_CHECK_ALLOC(repo);
874
1073
 
875
- repo->gitdir = git_buf_detach(&gitdir);
1074
+ repo->gitdir = git_str_detach(&gitdir);
876
1075
  GIT_ERROR_CHECK_ALLOC(repo->gitdir);
877
1076
 
878
1077
  if (gitlink.size) {
879
- repo->gitlink = git_buf_detach(&gitlink);
1078
+ repo->gitlink = git_str_detach(&gitlink);
880
1079
  GIT_ERROR_CHECK_ALLOC(repo->gitlink);
881
1080
  }
882
1081
  if (commondir.size) {
883
- repo->commondir = git_buf_detach(&commondir);
1082
+ repo->commondir = git_str_detach(&commondir);
884
1083
  GIT_ERROR_CHECK_ALLOC(repo->commondir);
885
1084
  }
886
1085
 
@@ -888,36 +1087,32 @@ int git_repository_open_ext(
888
1087
  goto cleanup;
889
1088
  repo->is_worktree = is_worktree;
890
1089
 
891
- /*
892
- * We'd like to have the config, but git doesn't particularly
893
- * care if it's not there, so we need to deal with that.
894
- */
895
-
896
- error = git_repository_config_snapshot(&config, repo);
897
- if (error < 0 && error != GIT_ENOTFOUND)
898
- goto cleanup;
899
-
900
- if (config && (error = check_repositoryformatversion(&version, config)) < 0)
901
- goto cleanup;
902
-
903
- if ((error = check_extensions(config, version)) < 0)
1090
+ error = obtain_config_and_set_oid_type(&config, repo);
1091
+ if (error < 0)
904
1092
  goto cleanup;
905
1093
 
906
- if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0)
1094
+ if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0) {
907
1095
  repo->is_bare = 1;
908
- else {
909
-
1096
+ } else {
910
1097
  if (config &&
911
1098
  ((error = load_config_data(repo, config)) < 0 ||
912
1099
  (error = load_workdir(repo, config, &workdir)) < 0))
913
1100
  goto cleanup;
914
1101
  }
915
1102
 
1103
+ /*
1104
+ * Ensure that the git directory and worktree are
1105
+ * owned by the current user.
1106
+ */
1107
+ if (git_repository__validate_ownership &&
1108
+ (error = validate_ownership(repo)) < 0)
1109
+ goto cleanup;
1110
+
916
1111
  cleanup:
917
- git_buf_dispose(&gitdir);
918
- git_buf_dispose(&workdir);
919
- git_buf_dispose(&gitlink);
920
- git_buf_dispose(&commondir);
1112
+ git_str_dispose(&gitdir);
1113
+ git_str_dispose(&workdir);
1114
+ git_str_dispose(&gitlink);
1115
+ git_str_dispose(&commondir);
921
1116
  git_config_free(config);
922
1117
 
923
1118
  if (error < 0)
@@ -936,7 +1131,7 @@ int git_repository_open(git_repository **repo_out, const char *path)
936
1131
 
937
1132
  int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *wt)
938
1133
  {
939
- git_buf path = GIT_BUF_INIT;
1134
+ git_str path = GIT_STR_INIT;
940
1135
  git_repository *repo = NULL;
941
1136
  size_t len;
942
1137
  int err;
@@ -952,7 +1147,7 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
952
1147
  goto out;
953
1148
  }
954
1149
 
955
- if ((err = git_buf_set(&path, wt->gitlink_path, len - 4)) < 0)
1150
+ if ((err = git_str_set(&path, wt->gitlink_path, len - 4)) < 0)
956
1151
  goto out;
957
1152
 
958
1153
  if ((err = git_repository_open(&repo, path.ptr)) < 0)
@@ -961,7 +1156,7 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
961
1156
  *repo_out = repo;
962
1157
 
963
1158
  out:
964
- git_buf_dispose(&path);
1159
+ git_str_dispose(&path);
965
1160
 
966
1161
  return err;
967
1162
  }
@@ -986,14 +1181,10 @@ int git_repository_discover(
986
1181
  const char *ceiling_dirs)
987
1182
  {
988
1183
  uint32_t flags = across_fs ? GIT_REPOSITORY_OPEN_CROSS_FS : 0;
989
- int error;
990
1184
 
991
1185
  GIT_ASSERT_ARG(start_path);
992
1186
 
993
- if ((error = git_buf_sanitize(out)) < 0)
994
- return error;
995
-
996
- return find_repo(out, NULL, NULL, NULL, start_path, flags, ceiling_dirs);
1187
+ GIT_BUF_WRAP_PRIVATE(out, find_repo, NULL, NULL, NULL, start_path, flags, ceiling_dirs);
997
1188
  }
998
1189
 
999
1190
  static int load_config(
@@ -1005,7 +1196,7 @@ static int load_config(
1005
1196
  const char *programdata_path)
1006
1197
  {
1007
1198
  int error;
1008
- git_buf config_path = GIT_BUF_INIT;
1199
+ git_str config_path = GIT_STR_INIT;
1009
1200
  git_config *cfg = NULL;
1010
1201
 
1011
1202
  GIT_ASSERT_ARG(out);
@@ -1014,13 +1205,13 @@ static int load_config(
1014
1205
  return error;
1015
1206
 
1016
1207
  if (repo) {
1017
- if ((error = git_repository_item_path(&config_path, repo, GIT_REPOSITORY_ITEM_CONFIG)) == 0)
1208
+ if ((error = git_repository__item_path(&config_path, repo, GIT_REPOSITORY_ITEM_CONFIG)) == 0)
1018
1209
  error = git_config_add_file_ondisk(cfg, config_path.ptr, GIT_CONFIG_LEVEL_LOCAL, repo, 0);
1019
1210
 
1020
1211
  if (error && error != GIT_ENOTFOUND)
1021
1212
  goto on_error;
1022
1213
 
1023
- git_buf_dispose(&config_path);
1214
+ git_str_dispose(&config_path);
1024
1215
  }
1025
1216
 
1026
1217
  if (global_config_path != NULL &&
@@ -1053,15 +1244,15 @@ static int load_config(
1053
1244
  return 0;
1054
1245
 
1055
1246
  on_error:
1056
- git_buf_dispose(&config_path);
1247
+ git_str_dispose(&config_path);
1057
1248
  git_config_free(cfg);
1058
1249
  *out = NULL;
1059
1250
  return error;
1060
1251
  }
1061
1252
 
1062
- static const char *path_unless_empty(git_buf *buf)
1253
+ static const char *path_unless_empty(git_str *buf)
1063
1254
  {
1064
- return git_buf_len(buf) > 0 ? git_buf_cstr(buf) : NULL;
1255
+ return git_str_len(buf) > 0 ? git_str_cstr(buf) : NULL;
1065
1256
  }
1066
1257
 
1067
1258
  int git_repository_config__weakptr(git_config **out, git_repository *repo)
@@ -1069,19 +1260,19 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
1069
1260
  int error = 0;
1070
1261
 
1071
1262
  if (repo->_config == NULL) {
1072
- git_buf global_buf = GIT_BUF_INIT;
1073
- git_buf xdg_buf = GIT_BUF_INIT;
1074
- git_buf system_buf = GIT_BUF_INIT;
1075
- git_buf programdata_buf = GIT_BUF_INIT;
1263
+ git_str global_buf = GIT_STR_INIT;
1264
+ git_str xdg_buf = GIT_STR_INIT;
1265
+ git_str system_buf = GIT_STR_INIT;
1266
+ git_str programdata_buf = GIT_STR_INIT;
1076
1267
  git_config *config;
1077
1268
 
1078
- git_config_find_global(&global_buf);
1079
- git_config_find_xdg(&xdg_buf);
1080
- git_config_find_system(&system_buf);
1081
- git_config_find_programdata(&programdata_buf);
1269
+ git_config__find_global(&global_buf);
1270
+ git_config__find_xdg(&xdg_buf);
1271
+ git_config__find_system(&system_buf);
1272
+ git_config__find_programdata(&programdata_buf);
1082
1273
 
1083
1274
  /* If there is no global file, open a backend for it anyway */
1084
- if (git_buf_len(&global_buf) == 0)
1275
+ if (git_str_len(&global_buf) == 0)
1085
1276
  git_config__global_location(&global_buf);
1086
1277
 
1087
1278
  error = load_config(
@@ -1099,10 +1290,10 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
1099
1290
  }
1100
1291
  }
1101
1292
 
1102
- git_buf_dispose(&global_buf);
1103
- git_buf_dispose(&xdg_buf);
1104
- git_buf_dispose(&system_buf);
1105
- git_buf_dispose(&programdata_buf);
1293
+ git_str_dispose(&global_buf);
1294
+ git_str_dispose(&xdg_buf);
1295
+ git_str_dispose(&system_buf);
1296
+ git_str_dispose(&programdata_buf);
1106
1297
  }
1107
1298
 
1108
1299
  *out = repo->_config;
@@ -1147,12 +1338,15 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
1147
1338
 
1148
1339
  *out = git_atomic_load(repo->_odb);
1149
1340
  if (*out == NULL) {
1150
- git_buf odb_path = GIT_BUF_INIT;
1341
+ git_str odb_path = GIT_STR_INIT;
1342
+ git_odb_options odb_opts = GIT_ODB_OPTIONS_INIT;
1151
1343
  git_odb *odb;
1152
1344
 
1153
- if ((error = git_repository_item_path(&odb_path, repo,
1345
+ odb_opts.oid_type = repo->oid_type;
1346
+
1347
+ if ((error = git_repository__item_path(&odb_path, repo,
1154
1348
  GIT_REPOSITORY_ITEM_OBJECTS)) < 0 ||
1155
- (error = git_odb_new(&odb)) < 0)
1349
+ (error = git_odb__new(&odb, &odb_opts)) < 0)
1156
1350
  return error;
1157
1351
 
1158
1352
  GIT_REFCOUNT_OWN(odb, repo);
@@ -1168,7 +1362,7 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
1168
1362
  git_odb_free(odb);
1169
1363
  }
1170
1364
 
1171
- git_buf_dispose(&odb_path);
1365
+ git_str_dispose(&odb_path);
1172
1366
  *out = git_atomic_load(repo->_odb);
1173
1367
  }
1174
1368
 
@@ -1244,10 +1438,10 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
1244
1438
  GIT_ASSERT_ARG(repo);
1245
1439
 
1246
1440
  if (repo->_index == NULL) {
1247
- git_buf index_path = GIT_BUF_INIT;
1441
+ git_str index_path = GIT_STR_INIT;
1248
1442
  git_index *index;
1249
1443
 
1250
- if ((error = git_buf_joinpath(&index_path, repo->gitdir, GIT_INDEX_FILE)) < 0)
1444
+ if ((error = git_str_joinpath(&index_path, repo->gitdir, GIT_INDEX_FILE)) < 0)
1251
1445
  return error;
1252
1446
 
1253
1447
  error = git_index_open(&index, index_path.ptr);
@@ -1263,7 +1457,7 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
1263
1457
  GIT_INDEX_CAPABILITY_FROM_OWNER);
1264
1458
  }
1265
1459
 
1266
- git_buf_dispose(&index_path);
1460
+ git_str_dispose(&index_path);
1267
1461
  }
1268
1462
 
1269
1463
  *out = repo->_index;
@@ -1311,7 +1505,7 @@ static int reserved_names_add8dot3(git_repository *repo, const char *path)
1311
1505
  const char *def_dot_git = DOT_GIT;
1312
1506
  size_t name_len, def_len = CONST_STRLEN(GIT_DIR_SHORTNAME);
1313
1507
  size_t def_dot_git_len = CONST_STRLEN(DOT_GIT);
1314
- git_buf *buf;
1508
+ git_str *buf;
1315
1509
 
1316
1510
  if (!name)
1317
1511
  return 0;
@@ -1327,17 +1521,17 @@ static int reserved_names_add8dot3(git_repository *repo, const char *path)
1327
1521
  if ((buf = git_array_alloc(repo->reserved_names)) == NULL)
1328
1522
  return -1;
1329
1523
 
1330
- git_buf_attach(buf, name, name_len);
1524
+ git_str_attach(buf, name, name_len);
1331
1525
  return true;
1332
1526
  }
1333
1527
 
1334
1528
  bool git_repository__reserved_names(
1335
- git_buf **out, size_t *outlen, git_repository *repo, bool include_ntfs)
1529
+ git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs)
1336
1530
  {
1337
1531
  GIT_UNUSED(include_ntfs);
1338
1532
 
1339
1533
  if (repo->reserved_names.size == 0) {
1340
- git_buf *buf;
1534
+ git_str *buf;
1341
1535
  size_t i;
1342
1536
 
1343
1537
  /* Add the static defaults */
@@ -1389,7 +1583,7 @@ on_error:
1389
1583
  }
1390
1584
  #else
1391
1585
  bool git_repository__reserved_names(
1392
- git_buf **out, size_t *outlen, git_repository *repo, bool include_ntfs)
1586
+ git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs)
1393
1587
  {
1394
1588
  GIT_UNUSED(repo);
1395
1589
 
@@ -1410,6 +1604,7 @@ static int check_repositoryformatversion(int *version, git_config *config)
1410
1604
  int error;
1411
1605
 
1412
1606
  error = git_config_get_int32(version, config, "core.repositoryformatversion");
1607
+
1413
1608
  /* git ignores this if the config variable isn't there */
1414
1609
  if (error == GIT_ENOTFOUND)
1415
1610
  return 0;
@@ -1417,10 +1612,15 @@ static int check_repositoryformatversion(int *version, git_config *config)
1417
1612
  if (error < 0)
1418
1613
  return -1;
1419
1614
 
1420
- if (GIT_REPO_MAX_VERSION < *version) {
1615
+ if (*version < 0) {
1616
+ git_error_set(GIT_ERROR_REPOSITORY,
1617
+ "invalid repository version %d", *version);
1618
+ }
1619
+
1620
+ if (GIT_REPO_VERSION_MAX < *version) {
1421
1621
  git_error_set(GIT_ERROR_REPOSITORY,
1422
1622
  "unsupported repository version %d; only versions up to %d are supported",
1423
- *version, GIT_REPO_MAX_VERSION);
1623
+ *version, GIT_REPO_VERSION_MAX);
1424
1624
  return -1;
1425
1625
  }
1426
1626
 
@@ -1428,14 +1628,15 @@ static int check_repositoryformatversion(int *version, git_config *config)
1428
1628
  }
1429
1629
 
1430
1630
  static const char *builtin_extensions[] = {
1431
- "noop"
1631
+ "noop",
1632
+ "objectformat"
1432
1633
  };
1433
1634
 
1434
1635
  static git_vector user_extensions = GIT_VECTOR_INIT;
1435
1636
 
1436
1637
  static int check_valid_extension(const git_config_entry *entry, void *payload)
1437
1638
  {
1438
- git_buf cfg = GIT_BUF_INIT;
1639
+ git_str cfg = GIT_STR_INIT;
1439
1640
  bool reject;
1440
1641
  const char *extension;
1441
1642
  size_t i;
@@ -1444,7 +1645,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
1444
1645
  GIT_UNUSED(payload);
1445
1646
 
1446
1647
  git_vector_foreach (&user_extensions, i, extension) {
1447
- git_buf_clear(&cfg);
1648
+ git_str_clear(&cfg);
1448
1649
 
1449
1650
  /*
1450
1651
  * Users can specify that they don't want to support an
@@ -1453,7 +1654,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
1453
1654
  if ((reject = (extension[0] == '!')) == true)
1454
1655
  extension = &extension[1];
1455
1656
 
1456
- if ((error = git_buf_printf(&cfg, "extensions.%s", extension)) < 0)
1657
+ if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0)
1457
1658
  goto done;
1458
1659
 
1459
1660
  if (strcmp(entry->name, cfg.ptr) == 0) {
@@ -1465,9 +1666,10 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
1465
1666
  }
1466
1667
 
1467
1668
  for (i = 0; i < ARRAY_SIZE(builtin_extensions); i++) {
1669
+ git_str_clear(&cfg);
1468
1670
  extension = builtin_extensions[i];
1469
1671
 
1470
- if ((error = git_buf_printf(&cfg, "extensions.%s", extension)) < 0)
1672
+ if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0)
1471
1673
  goto done;
1472
1674
 
1473
1675
  if (strcmp(entry->name, cfg.ptr) == 0)
@@ -1479,7 +1681,7 @@ fail:
1479
1681
  error = -1;
1480
1682
 
1481
1683
  done:
1482
- git_buf_dispose(&cfg);
1684
+ git_str_dispose(&cfg);
1483
1685
  return error;
1484
1686
  }
1485
1687
 
@@ -1491,6 +1693,79 @@ static int check_extensions(git_config *config, int version)
1491
1693
  return git_config_foreach_match(config, "^extensions\\.", check_valid_extension, NULL);
1492
1694
  }
1493
1695
 
1696
+ static int load_objectformat(git_repository *repo, git_config *config)
1697
+ {
1698
+ git_config_entry *entry = NULL;
1699
+ int error;
1700
+
1701
+ if ((error = git_config_get_entry(&entry, config, "extensions.objectformat")) < 0) {
1702
+ if (error == GIT_ENOTFOUND) {
1703
+ repo->oid_type = GIT_OID_SHA1;
1704
+ git_error_clear();
1705
+ error = 0;
1706
+ }
1707
+
1708
+ goto done;
1709
+ }
1710
+
1711
+ if ((repo->oid_type = git_oid_type_fromstr(entry->value)) == 0) {
1712
+ git_error_set(GIT_ERROR_REPOSITORY,
1713
+ "unknown object format '%s'", entry->value);
1714
+ error = GIT_EINVALID;
1715
+ }
1716
+
1717
+ done:
1718
+ git_config_entry_free(entry);
1719
+ return error;
1720
+ }
1721
+
1722
+ int git_repository__set_objectformat(
1723
+ git_repository *repo,
1724
+ git_oid_t oid_type)
1725
+ {
1726
+ git_config *cfg;
1727
+
1728
+ /*
1729
+ * Older clients do not necessarily understand the
1730
+ * `objectformat` extension, even when it's set to an
1731
+ * object format that they understand (SHA1). Do not set
1732
+ * the objectformat extension unless we're not using the
1733
+ * default object format.
1734
+ */
1735
+ if (oid_type == GIT_OID_DEFAULT)
1736
+ return 0;
1737
+
1738
+ if (!git_repository_is_empty(repo) && repo->oid_type != oid_type) {
1739
+ git_error_set(GIT_ERROR_REPOSITORY,
1740
+ "cannot change object id type of existing repository");
1741
+ return -1;
1742
+ }
1743
+
1744
+ if (git_repository_config__weakptr(&cfg, repo) < 0)
1745
+ return -1;
1746
+
1747
+ if (git_config_set_int32(cfg,
1748
+ "core.repositoryformatversion", 1) < 0 ||
1749
+ git_config_set_string(cfg, "extensions.objectformat",
1750
+ git_oid_type_name(oid_type)) < 0)
1751
+ return -1;
1752
+
1753
+ /*
1754
+ * During repo init, we may create some backends with the
1755
+ * default oid type. Clear them so that we create them with
1756
+ * the proper oid type.
1757
+ */
1758
+ if (repo->oid_type != oid_type) {
1759
+ set_index(repo, NULL);
1760
+ set_odb(repo, NULL);
1761
+ set_refdb(repo, NULL);
1762
+
1763
+ repo->oid_type = oid_type;
1764
+ }
1765
+
1766
+ return 0;
1767
+ }
1768
+
1494
1769
  int git_repository__extensions(char ***out, size_t *out_len)
1495
1770
  {
1496
1771
  git_vector extensions;
@@ -1557,12 +1832,12 @@ void git_repository__free_extensions(void)
1557
1832
 
1558
1833
  int git_repository_create_head(const char *git_dir, const char *ref_name)
1559
1834
  {
1560
- git_buf ref_path = GIT_BUF_INIT;
1835
+ git_str ref_path = GIT_STR_INIT;
1561
1836
  git_filebuf ref = GIT_FILEBUF_INIT;
1562
1837
  const char *fmt;
1563
1838
  int error;
1564
1839
 
1565
- if ((error = git_buf_joinpath(&ref_path, git_dir, GIT_HEAD_FILE)) < 0 ||
1840
+ if ((error = git_str_joinpath(&ref_path, git_dir, GIT_HEAD_FILE)) < 0 ||
1566
1841
  (error = git_filebuf_open(&ref, ref_path.ptr, 0, GIT_REFS_FILE_MODE)) < 0)
1567
1842
  goto out;
1568
1843
 
@@ -1576,7 +1851,7 @@ int git_repository_create_head(const char *git_dir, const char *ref_name)
1576
1851
  goto out;
1577
1852
 
1578
1853
  out:
1579
- git_buf_dispose(&ref_path);
1854
+ git_str_dispose(&ref_path);
1580
1855
  git_filebuf_cleanup(&ref);
1581
1856
  return error;
1582
1857
  }
@@ -1599,23 +1874,50 @@ static bool is_chmod_supported(const char *file_path)
1599
1874
 
1600
1875
  static bool is_filesystem_case_insensitive(const char *gitdir_path)
1601
1876
  {
1602
- git_buf path = GIT_BUF_INIT;
1877
+ git_str path = GIT_STR_INIT;
1603
1878
  int is_insensitive = -1;
1604
1879
 
1605
- if (!git_buf_joinpath(&path, gitdir_path, "CoNfIg"))
1606
- is_insensitive = git_path_exists(git_buf_cstr(&path));
1880
+ if (!git_str_joinpath(&path, gitdir_path, "CoNfIg"))
1881
+ is_insensitive = git_fs_path_exists(git_str_cstr(&path));
1607
1882
 
1608
- git_buf_dispose(&path);
1883
+ git_str_dispose(&path);
1609
1884
  return is_insensitive;
1610
1885
  }
1611
1886
 
1887
+ /*
1888
+ * Return a configuration object with only the global and system
1889
+ * configurations; no repository-level configuration.
1890
+ */
1891
+ static int load_global_config(git_config **config)
1892
+ {
1893
+ git_str global_buf = GIT_STR_INIT;
1894
+ git_str xdg_buf = GIT_STR_INIT;
1895
+ git_str system_buf = GIT_STR_INIT;
1896
+ git_str programdata_buf = GIT_STR_INIT;
1897
+ int error;
1898
+
1899
+ git_config__find_global(&global_buf);
1900
+ git_config__find_xdg(&xdg_buf);
1901
+ git_config__find_system(&system_buf);
1902
+ git_config__find_programdata(&programdata_buf);
1903
+
1904
+ error = load_config(config, NULL,
1905
+ path_unless_empty(&global_buf),
1906
+ path_unless_empty(&xdg_buf),
1907
+ path_unless_empty(&system_buf),
1908
+ path_unless_empty(&programdata_buf));
1909
+
1910
+ git_str_dispose(&global_buf);
1911
+ git_str_dispose(&xdg_buf);
1912
+ git_str_dispose(&system_buf);
1913
+ git_str_dispose(&programdata_buf);
1914
+
1915
+ return error;
1916
+ }
1917
+
1612
1918
  static bool are_symlinks_supported(const char *wd_path)
1613
1919
  {
1614
1920
  git_config *config = NULL;
1615
- git_buf global_buf = GIT_BUF_INIT;
1616
- git_buf xdg_buf = GIT_BUF_INIT;
1617
- git_buf system_buf = GIT_BUF_INIT;
1618
- git_buf programdata_buf = GIT_BUF_INIT;
1619
1921
  int symlinks = 0;
1620
1922
 
1621
1923
  /*
@@ -1626,30 +1928,16 @@ static bool are_symlinks_supported(const char *wd_path)
1626
1928
  * _not_ set, then we do not test or enable symlink support.
1627
1929
  */
1628
1930
  #ifdef GIT_WIN32
1629
- git_config_find_global(&global_buf);
1630
- git_config_find_xdg(&xdg_buf);
1631
- git_config_find_system(&system_buf);
1632
- git_config_find_programdata(&programdata_buf);
1633
-
1634
- if (load_config(&config, NULL,
1635
- path_unless_empty(&global_buf),
1636
- path_unless_empty(&xdg_buf),
1637
- path_unless_empty(&system_buf),
1638
- path_unless_empty(&programdata_buf)) < 0)
1639
- goto done;
1640
-
1641
- if (git_config_get_bool(&symlinks, config, "core.symlinks") < 0 || !symlinks)
1931
+ if (load_global_config(&config) < 0 ||
1932
+ git_config_get_bool(&symlinks, config, "core.symlinks") < 0 ||
1933
+ !symlinks)
1642
1934
  goto done;
1643
1935
  #endif
1644
1936
 
1645
- if (!(symlinks = git_path_supports_symlinks(wd_path)))
1937
+ if (!(symlinks = git_fs_path_supports_symlinks(wd_path)))
1646
1938
  goto done;
1647
1939
 
1648
1940
  done:
1649
- git_buf_dispose(&global_buf);
1650
- git_buf_dispose(&xdg_buf);
1651
- git_buf_dispose(&system_buf);
1652
- git_buf_dispose(&programdata_buf);
1653
1941
  git_config_free(config);
1654
1942
  return symlinks != 0;
1655
1943
  }
@@ -1673,7 +1961,7 @@ static int create_empty_file(const char *path, mode_t mode)
1673
1961
 
1674
1962
  static int repo_local_config(
1675
1963
  git_config **out,
1676
- git_buf *config_dir,
1964
+ git_str *config_dir,
1677
1965
  git_repository *repo,
1678
1966
  const char *repo_dir)
1679
1967
  {
@@ -1681,12 +1969,12 @@ static int repo_local_config(
1681
1969
  git_config *parent;
1682
1970
  const char *cfg_path;
1683
1971
 
1684
- if (git_buf_joinpath(config_dir, repo_dir, GIT_CONFIG_FILENAME_INREPO) < 0)
1972
+ if (git_str_joinpath(config_dir, repo_dir, GIT_CONFIG_FILENAME_INREPO) < 0)
1685
1973
  return -1;
1686
- cfg_path = git_buf_cstr(config_dir);
1974
+ cfg_path = git_str_cstr(config_dir);
1687
1975
 
1688
1976
  /* make LOCAL config if missing */
1689
- if (!git_path_isfile(cfg_path) &&
1977
+ if (!git_fs_path_isfile(cfg_path) &&
1690
1978
  (error = create_empty_file(cfg_path, GIT_CONFIG_FILE_MODE)) < 0)
1691
1979
  return error;
1692
1980
 
@@ -1744,7 +2032,7 @@ static int repo_init_fs_configs(
1744
2032
  #ifdef GIT_USE_ICONV
1745
2033
  if ((error = git_config_set_bool(
1746
2034
  cfg, "core.precomposeunicode",
1747
- git_path_does_fs_decompose_unicode(work_dir))) < 0)
2035
+ git_fs_path_does_decompose_unicode(work_dir))) < 0)
1748
2036
  return error;
1749
2037
  /* on non-iconv platforms, don't even set core.precomposeunicode */
1750
2038
  #endif
@@ -1756,19 +2044,21 @@ static int repo_init_config(
1756
2044
  const char *repo_dir,
1757
2045
  const char *work_dir,
1758
2046
  uint32_t flags,
1759
- uint32_t mode)
2047
+ uint32_t mode,
2048
+ git_oid_t oid_type)
1760
2049
  {
1761
2050
  int error = 0;
1762
- git_buf cfg_path = GIT_BUF_INIT, worktree_path = GIT_BUF_INIT;
2051
+ git_str cfg_path = GIT_STR_INIT, worktree_path = GIT_STR_INIT;
1763
2052
  git_config *config = NULL;
1764
2053
  bool is_bare = ((flags & GIT_REPOSITORY_INIT_BARE) != 0);
1765
2054
  bool is_reinit = ((flags & GIT_REPOSITORY_INIT__IS_REINIT) != 0);
1766
- int version = 0;
2055
+ int version = GIT_REPO_VERSION_DEFAULT;
1767
2056
 
1768
2057
  if ((error = repo_local_config(&config, &cfg_path, NULL, repo_dir)) < 0)
1769
2058
  goto cleanup;
1770
2059
 
1771
- if (is_reinit && (error = check_repositoryformatversion(&version, config)) < 0)
2060
+ if (is_reinit &&
2061
+ (error = check_repositoryformatversion(&version, config)) < 0)
1772
2062
  goto cleanup;
1773
2063
 
1774
2064
  if ((error = check_extensions(config, version)) < 0)
@@ -1779,7 +2069,7 @@ static int repo_init_config(
1779
2069
  goto cleanup; } while (0)
1780
2070
 
1781
2071
  SET_REPO_CONFIG(bool, "core.bare", is_bare);
1782
- SET_REPO_CONFIG(int32, "core.repositoryformatversion", GIT_REPO_VERSION);
2072
+ SET_REPO_CONFIG(int32, "core.repositoryformatversion", version);
1783
2073
 
1784
2074
  if ((error = repo_init_fs_configs(
1785
2075
  config, cfg_path.ptr, repo_dir, work_dir, !is_reinit)) < 0)
@@ -1789,11 +2079,11 @@ static int repo_init_config(
1789
2079
  SET_REPO_CONFIG(bool, "core.logallrefupdates", true);
1790
2080
 
1791
2081
  if (!(flags & GIT_REPOSITORY_INIT__NATURAL_WD)) {
1792
- if ((error = git_buf_sets(&worktree_path, work_dir)) < 0)
2082
+ if ((error = git_str_sets(&worktree_path, work_dir)) < 0)
1793
2083
  goto cleanup;
1794
2084
 
1795
2085
  if ((flags & GIT_REPOSITORY_INIT_RELATIVE_GITLINK))
1796
- if ((error = git_path_make_relative(&worktree_path, repo_dir)) < 0)
2086
+ if ((error = git_fs_path_make_relative(&worktree_path, repo_dir)) < 0)
1797
2087
  goto cleanup;
1798
2088
 
1799
2089
  SET_REPO_CONFIG(string, "core.worktree", worktree_path.ptr);
@@ -1812,9 +2102,14 @@ static int repo_init_config(
1812
2102
  SET_REPO_CONFIG(bool, "receive.denyNonFastforwards", true);
1813
2103
  }
1814
2104
 
2105
+ if (oid_type != GIT_OID_SHA1) {
2106
+ SET_REPO_CONFIG(int32, "core.repositoryformatversion", 1);
2107
+ SET_REPO_CONFIG(string, "extensions.objectformat", git_oid_type_name(oid_type));
2108
+ }
2109
+
1815
2110
  cleanup:
1816
- git_buf_dispose(&cfg_path);
1817
- git_buf_dispose(&worktree_path);
2111
+ git_str_dispose(&cfg_path);
2112
+ git_str_dispose(&worktree_path);
1818
2113
  git_config_free(config);
1819
2114
 
1820
2115
  return error;
@@ -1836,7 +2131,7 @@ static int repo_reinit_submodule_fs(git_submodule *sm, const char *n, void *p)
1836
2131
  int git_repository_reinit_filesystem(git_repository *repo, int recurse)
1837
2132
  {
1838
2133
  int error = 0;
1839
- git_buf path = GIT_BUF_INIT;
2134
+ git_str path = GIT_STR_INIT;
1840
2135
  git_config *config = NULL;
1841
2136
  const char *repo_dir = git_repository_path(repo);
1842
2137
 
@@ -1845,7 +2140,7 @@ int git_repository_reinit_filesystem(git_repository *repo, int recurse)
1845
2140
  config, path.ptr, repo_dir, git_repository_workdir(repo), true);
1846
2141
 
1847
2142
  git_config_free(config);
1848
- git_buf_dispose(&path);
2143
+ git_str_dispose(&path);
1849
2144
 
1850
2145
  git_repository__configmap_lookup_cache_clear(repo);
1851
2146
 
@@ -1863,10 +2158,10 @@ static int repo_write_template(
1863
2158
  bool hidden,
1864
2159
  const char *content)
1865
2160
  {
1866
- git_buf path = GIT_BUF_INIT;
2161
+ git_str path = GIT_STR_INIT;
1867
2162
  int fd, error = 0, flags;
1868
2163
 
1869
- if (git_buf_joinpath(&path, git_dir, file) < 0)
2164
+ if (git_str_joinpath(&path, git_dir, file) < 0)
1870
2165
  return -1;
1871
2166
 
1872
2167
  if (allow_overwrite)
@@ -1874,7 +2169,7 @@ static int repo_write_template(
1874
2169
  else
1875
2170
  flags = O_WRONLY | O_CREAT | O_EXCL;
1876
2171
 
1877
- fd = p_open(git_buf_cstr(&path), flags, mode);
2172
+ fd = p_open(git_str_cstr(&path), flags, mode);
1878
2173
 
1879
2174
  if (fd >= 0) {
1880
2175
  error = p_write(fd, content, strlen(content));
@@ -1893,7 +2188,7 @@ static int repo_write_template(
1893
2188
  GIT_UNUSED(hidden);
1894
2189
  #endif
1895
2190
 
1896
- git_buf_dispose(&path);
2191
+ git_str_dispose(&path);
1897
2192
 
1898
2193
  if (error)
1899
2194
  git_error_set(GIT_ERROR_OS,
@@ -1906,13 +2201,13 @@ static int repo_write_gitlink(
1906
2201
  const char *in_dir, const char *to_repo, bool use_relative_path)
1907
2202
  {
1908
2203
  int error;
1909
- git_buf buf = GIT_BUF_INIT;
1910
- git_buf path_to_repo = GIT_BUF_INIT;
2204
+ git_str buf = GIT_STR_INIT;
2205
+ git_str path_to_repo = GIT_STR_INIT;
1911
2206
  struct stat st;
1912
2207
 
1913
- git_path_dirname_r(&buf, to_repo);
1914
- git_path_to_dir(&buf);
1915
- if (git_buf_oom(&buf))
2208
+ git_fs_path_dirname_r(&buf, to_repo);
2209
+ git_fs_path_to_dir(&buf);
2210
+ if (git_str_oom(&buf))
1916
2211
  return -1;
1917
2212
 
1918
2213
  /* don't write gitlink to natural workdir */
@@ -1923,7 +2218,7 @@ static int repo_write_gitlink(
1923
2218
  goto cleanup;
1924
2219
  }
1925
2220
 
1926
- if ((error = git_buf_joinpath(&buf, in_dir, DOT_GIT)) < 0)
2221
+ if ((error = git_str_joinpath(&buf, in_dir, DOT_GIT)) < 0)
1927
2222
  goto cleanup;
1928
2223
 
1929
2224
  if (!p_stat(buf.ptr, &st) && !S_ISREG(st.st_mode)) {
@@ -1933,22 +2228,22 @@ static int repo_write_gitlink(
1933
2228
  goto cleanup;
1934
2229
  }
1935
2230
 
1936
- git_buf_clear(&buf);
2231
+ git_str_clear(&buf);
1937
2232
 
1938
- error = git_buf_sets(&path_to_repo, to_repo);
2233
+ error = git_str_sets(&path_to_repo, to_repo);
1939
2234
 
1940
2235
  if (!error && use_relative_path)
1941
- error = git_path_make_relative(&path_to_repo, in_dir);
2236
+ error = git_fs_path_make_relative(&path_to_repo, in_dir);
1942
2237
 
1943
2238
  if (!error)
1944
- error = git_buf_join(&buf, ' ', GIT_FILE_CONTENT_PREFIX, path_to_repo.ptr);
2239
+ error = git_str_join(&buf, ' ', GIT_FILE_CONTENT_PREFIX, path_to_repo.ptr);
1945
2240
 
1946
2241
  if (!error)
1947
2242
  error = repo_write_template(in_dir, true, DOT_GIT, 0666, true, buf.ptr);
1948
2243
 
1949
2244
  cleanup:
1950
- git_buf_dispose(&buf);
1951
- git_buf_dispose(&path_to_repo);
2245
+ git_str_dispose(&buf);
2246
+ git_str_dispose(&path_to_repo);
1952
2247
  return error;
1953
2248
  }
1954
2249
 
@@ -2001,12 +2296,12 @@ static int repo_init_structure(
2001
2296
  git_config *cfg = NULL;
2002
2297
  const char *tdir = NULL;
2003
2298
  bool default_template = false;
2004
- git_buf template_buf = GIT_BUF_INIT;
2299
+ git_str template_buf = GIT_STR_INIT;
2005
2300
 
2006
2301
  if (opts->template_path)
2007
2302
  tdir = opts->template_path;
2008
2303
  else if ((error = git_config_open_default(&cfg)) >= 0) {
2009
- if (!git_config_get_path(&template_buf, cfg, "init.templatedir"))
2304
+ if (!git_config__get_path(&template_buf, cfg, "init.templatedir"))
2010
2305
  tdir = template_buf.ptr;
2011
2306
  git_error_clear();
2012
2307
  }
@@ -2032,11 +2327,16 @@ static int repo_init_structure(
2032
2327
  error = git_futils_cp_r(tdir, repo_dir, cpflags, dmode);
2033
2328
  }
2034
2329
 
2035
- git_buf_dispose(&template_buf);
2330
+ git_str_dispose(&template_buf);
2036
2331
  git_config_free(cfg);
2037
2332
 
2333
+ /* If tdir does not exist, then do not error out. This matches the
2334
+ * behaviour of git(1), which just prints a warning and continues.
2335
+ * TODO: issue warning when warning API is available.
2336
+ * `git` prints to stderr: 'warning: templates not found in /path/to/tdir'
2337
+ */
2038
2338
  if (error < 0) {
2039
- if (!default_template)
2339
+ if (!default_template && error != GIT_ENOTFOUND)
2040
2340
  return error;
2041
2341
 
2042
2342
  /* if template was default, ignore error and use internal */
@@ -2073,7 +2373,7 @@ static int repo_init_structure(
2073
2373
  return error;
2074
2374
  }
2075
2375
 
2076
- static int mkdir_parent(git_buf *buf, uint32_t mode, bool skip2)
2376
+ static int mkdir_parent(git_str *buf, uint32_t mode, bool skip2)
2077
2377
  {
2078
2378
  /* When making parent directories during repository initialization
2079
2379
  * don't try to set gid or grant world write access
@@ -2085,8 +2385,8 @@ static int mkdir_parent(git_buf *buf, uint32_t mode, bool skip2)
2085
2385
  }
2086
2386
 
2087
2387
  static int repo_init_directories(
2088
- git_buf *repo_path,
2089
- git_buf *wd_path,
2388
+ git_str *repo_path,
2389
+ git_str *wd_path,
2090
2390
  const char *given_repo,
2091
2391
  git_repository_init_options *opts)
2092
2392
  {
@@ -2124,7 +2424,7 @@ static int repo_init_directories(
2124
2424
  git__suffixcmp(given_repo, "/" DOT_GIT) != 0 &&
2125
2425
  git__suffixcmp(given_repo, "/" GIT_DIR) != 0;
2126
2426
 
2127
- if (git_buf_joinpath(repo_path, given_repo, add_dotgit ? GIT_DIR : "") < 0)
2427
+ if (git_str_joinpath(repo_path, given_repo, add_dotgit ? GIT_DIR : "") < 0)
2128
2428
  return -1;
2129
2429
 
2130
2430
  has_dotgit = (git__suffixcmp(repo_path->ptr, "/" GIT_DIR) == 0);
@@ -2135,11 +2435,11 @@ static int repo_init_directories(
2135
2435
 
2136
2436
  if (!is_bare) {
2137
2437
  if (opts->workdir_path) {
2138
- if (git_path_join_unrooted(
2438
+ if (git_fs_path_join_unrooted(
2139
2439
  wd_path, opts->workdir_path, repo_path->ptr, NULL) < 0)
2140
2440
  return -1;
2141
2441
  } else if (has_dotgit) {
2142
- if (git_path_dirname_r(wd_path, repo_path->ptr) < 0)
2442
+ if (git_fs_path_dirname_r(wd_path, repo_path->ptr) < 0)
2143
2443
  return -1;
2144
2444
  } else {
2145
2445
  git_error_set(GIT_ERROR_REPOSITORY, "cannot pick working directory"
@@ -2147,10 +2447,10 @@ static int repo_init_directories(
2147
2447
  return -1;
2148
2448
  }
2149
2449
 
2150
- if (git_path_to_dir(wd_path) < 0)
2450
+ if (git_fs_path_to_dir(wd_path) < 0)
2151
2451
  return -1;
2152
2452
  } else {
2153
- git_buf_clear(wd_path);
2453
+ git_str_clear(wd_path);
2154
2454
  }
2155
2455
 
2156
2456
  natural_wd =
@@ -2207,10 +2507,10 @@ static int repo_init_directories(
2207
2507
  /* prettify both directories now that they are created */
2208
2508
 
2209
2509
  if (!error) {
2210
- error = git_path_prettify_dir(repo_path, repo_path->ptr, NULL);
2510
+ error = git_fs_path_prettify_dir(repo_path, repo_path->ptr, NULL);
2211
2511
 
2212
2512
  if (!error && wd_path->size > 0)
2213
- error = git_path_prettify_dir(wd_path, wd_path->ptr, NULL);
2513
+ error = git_fs_path_prettify_dir(wd_path, wd_path->ptr, NULL);
2214
2514
  }
2215
2515
 
2216
2516
  return error;
@@ -2219,24 +2519,24 @@ static int repo_init_directories(
2219
2519
  static int repo_init_head(const char *repo_dir, const char *given)
2220
2520
  {
2221
2521
  git_config *cfg = NULL;
2222
- git_buf head_path = GIT_BUF_INIT, cfg_branch = GIT_BUF_INIT;
2522
+ git_str head_path = GIT_STR_INIT, cfg_branch = GIT_STR_INIT;
2223
2523
  const char *initial_head = NULL;
2224
2524
  int error;
2225
2525
 
2226
- if ((error = git_buf_joinpath(&head_path, repo_dir, GIT_HEAD_FILE)) < 0)
2526
+ if ((error = git_str_joinpath(&head_path, repo_dir, GIT_HEAD_FILE)) < 0)
2227
2527
  goto out;
2228
2528
 
2229
2529
  /*
2230
2530
  * A template may have set a HEAD; use that unless it's been
2231
2531
  * overridden by the caller's given initial head setting.
2232
2532
  */
2233
- if (git_path_exists(head_path.ptr) && !given)
2533
+ if (git_fs_path_exists(head_path.ptr) && !given)
2234
2534
  goto out;
2235
2535
 
2236
2536
  if (given) {
2237
2537
  initial_head = given;
2238
2538
  } else if ((error = git_config_open_default(&cfg)) >= 0 &&
2239
- (error = git_config_get_string_buf(&cfg_branch, cfg, "init.defaultbranch")) >= 0 &&
2539
+ (error = git_config__get_string_buf(&cfg_branch, cfg, "init.defaultbranch")) >= 0 &&
2240
2540
  *cfg_branch.ptr) {
2241
2541
  initial_head = cfg_branch.ptr;
2242
2542
  }
@@ -2248,8 +2548,8 @@ static int repo_init_head(const char *repo_dir, const char *given)
2248
2548
 
2249
2549
  out:
2250
2550
  git_config_free(cfg);
2251
- git_buf_dispose(&head_path);
2252
- git_buf_dispose(&cfg_branch);
2551
+ git_str_dispose(&head_path);
2552
+ git_str_dispose(&cfg_branch);
2253
2553
 
2254
2554
  return error;
2255
2555
  }
@@ -2283,10 +2583,11 @@ int git_repository_init_ext(
2283
2583
  const char *given_repo,
2284
2584
  git_repository_init_options *opts)
2285
2585
  {
2286
- git_buf repo_path = GIT_BUF_INIT, wd_path = GIT_BUF_INIT,
2287
- common_path = GIT_BUF_INIT;
2586
+ git_str repo_path = GIT_STR_INIT, wd_path = GIT_STR_INIT,
2587
+ common_path = GIT_STR_INIT;
2288
2588
  const char *wd;
2289
2589
  bool is_valid;
2590
+ git_oid_t oid_type = GIT_OID_DEFAULT;
2290
2591
  int error;
2291
2592
 
2292
2593
  GIT_ASSERT_ARG(out);
@@ -2295,10 +2596,15 @@ int git_repository_init_ext(
2295
2596
 
2296
2597
  GIT_ERROR_CHECK_VERSION(opts, GIT_REPOSITORY_INIT_OPTIONS_VERSION, "git_repository_init_options");
2297
2598
 
2599
+ #ifdef GIT_EXPERIMENTAL_SHA256
2600
+ if (opts->oid_type)
2601
+ oid_type = opts->oid_type;
2602
+ #endif
2603
+
2298
2604
  if ((error = repo_init_directories(&repo_path, &wd_path, given_repo, opts)) < 0)
2299
2605
  goto out;
2300
2606
 
2301
- wd = (opts->flags & GIT_REPOSITORY_INIT_BARE) ? NULL : git_buf_cstr(&wd_path);
2607
+ wd = (opts->flags & GIT_REPOSITORY_INIT_BARE) ? NULL : git_str_cstr(&wd_path);
2302
2608
 
2303
2609
  if ((error = is_valid_repository_path(&is_valid, &repo_path, &common_path)) < 0)
2304
2610
  goto out;
@@ -2313,13 +2619,13 @@ int git_repository_init_ext(
2313
2619
 
2314
2620
  opts->flags |= GIT_REPOSITORY_INIT__IS_REINIT;
2315
2621
 
2316
- if ((error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode)) < 0)
2622
+ if ((error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode, oid_type)) < 0)
2317
2623
  goto out;
2318
2624
 
2319
2625
  /* TODO: reinitialize the templates */
2320
2626
  } else {
2321
2627
  if ((error = repo_init_structure(repo_path.ptr, wd, opts)) < 0 ||
2322
- (error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode)) < 0 ||
2628
+ (error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode, oid_type)) < 0 ||
2323
2629
  (error = repo_init_head(repo_path.ptr, opts->initial_head)) < 0)
2324
2630
  goto out;
2325
2631
  }
@@ -2332,9 +2638,9 @@ int git_repository_init_ext(
2332
2638
  goto out;
2333
2639
 
2334
2640
  out:
2335
- git_buf_dispose(&common_path);
2336
- git_buf_dispose(&repo_path);
2337
- git_buf_dispose(&wd_path);
2641
+ git_str_dispose(&common_path);
2642
+ git_str_dispose(&repo_path);
2643
+ git_str_dispose(&wd_path);
2338
2644
 
2339
2645
  return error;
2340
2646
  }
@@ -2522,7 +2828,7 @@ static int repo_contains_no_reference(git_repository *repo)
2522
2828
  return error;
2523
2829
  }
2524
2830
 
2525
- int git_repository_initialbranch(git_buf *out, git_repository *repo)
2831
+ int git_repository_initialbranch(git_str *out, git_repository *repo)
2526
2832
  {
2527
2833
  git_config *config;
2528
2834
  git_config_entry *entry = NULL;
@@ -2543,8 +2849,8 @@ int git_repository_initialbranch(git_buf *out, git_repository *repo)
2543
2849
  goto done;
2544
2850
  }
2545
2851
 
2546
- if ((error = git_buf_puts(out, GIT_REFS_HEADS_DIR)) < 0 ||
2547
- (error = git_buf_puts(out, branch)) < 0 ||
2852
+ if ((error = git_str_puts(out, GIT_REFS_HEADS_DIR)) < 0 ||
2853
+ (error = git_str_puts(out, branch)) < 0 ||
2548
2854
  (error = git_reference_name_is_valid(&valid, out->ptr)) < 0)
2549
2855
  goto done;
2550
2856
 
@@ -2561,7 +2867,7 @@ done:
2561
2867
  int git_repository_is_empty(git_repository *repo)
2562
2868
  {
2563
2869
  git_reference *head = NULL;
2564
- git_buf initialbranch = GIT_BUF_INIT;
2870
+ git_str initialbranch = GIT_STR_INIT;
2565
2871
  int result = 0;
2566
2872
 
2567
2873
  if ((result = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0 ||
@@ -2574,7 +2880,7 @@ int git_repository_is_empty(git_repository *repo)
2574
2880
 
2575
2881
  done:
2576
2882
  git_reference_free(head);
2577
- git_buf_dispose(&initialbranch);
2883
+ git_str_dispose(&initialbranch);
2578
2884
 
2579
2885
  return result;
2580
2886
  }
@@ -2603,7 +2909,18 @@ static const char *resolved_parent_path(const git_repository *repo, git_reposito
2603
2909
  return parent;
2604
2910
  }
2605
2911
 
2606
- int git_repository_item_path(git_buf *out, const git_repository *repo, git_repository_item_t item)
2912
+ int git_repository_item_path(
2913
+ git_buf *out,
2914
+ const git_repository *repo,
2915
+ git_repository_item_t item)
2916
+ {
2917
+ GIT_BUF_WRAP_PRIVATE(out, git_repository__item_path, repo, item);
2918
+ }
2919
+
2920
+ int git_repository__item_path(
2921
+ git_str *out,
2922
+ const git_repository *repo,
2923
+ git_repository_item_t item)
2607
2924
  {
2608
2925
  const char *parent = resolved_parent_path(repo, items[item].parent, items[item].fallback);
2609
2926
  if (parent == NULL) {
@@ -2611,16 +2928,16 @@ int git_repository_item_path(git_buf *out, const git_repository *repo, git_repos
2611
2928
  return GIT_ENOTFOUND;
2612
2929
  }
2613
2930
 
2614
- if (git_buf_sets(out, parent) < 0)
2931
+ if (git_str_sets(out, parent) < 0)
2615
2932
  return -1;
2616
2933
 
2617
2934
  if (items[item].name) {
2618
- if (git_buf_joinpath(out, parent, items[item].name) < 0)
2935
+ if (git_str_joinpath(out, parent, items[item].name) < 0)
2619
2936
  return -1;
2620
2937
  }
2621
2938
 
2622
2939
  if (items[item].directory) {
2623
- if (git_path_to_dir(out) < 0)
2940
+ if (git_fs_path_to_dir(out) < 0)
2624
2941
  return -1;
2625
2942
  }
2626
2943
 
@@ -2644,7 +2961,7 @@ const char *git_repository_workdir(const git_repository *repo)
2644
2961
  }
2645
2962
 
2646
2963
  int git_repository_workdir_path(
2647
- git_buf *out, git_repository *repo, const char *path)
2964
+ git_str *out, git_repository *repo, const char *path)
2648
2965
  {
2649
2966
  int error;
2650
2967
 
@@ -2653,8 +2970,8 @@ int git_repository_workdir_path(
2653
2970
  return GIT_EBAREREPO;
2654
2971
  }
2655
2972
 
2656
- if (!(error = git_buf_joinpath(out, repo->workdir, path)))
2657
- error = git_path_validate_workdir_buf(repo, out);
2973
+ if (!(error = git_str_joinpath(out, repo->workdir, path)))
2974
+ error = git_path_validate_str_length(repo, out);
2658
2975
 
2659
2976
  return error;
2660
2977
  }
@@ -2669,12 +2986,12 @@ int git_repository_set_workdir(
2669
2986
  git_repository *repo, const char *workdir, int update_gitlink)
2670
2987
  {
2671
2988
  int error = 0;
2672
- git_buf path = GIT_BUF_INIT;
2989
+ git_str path = GIT_STR_INIT;
2673
2990
 
2674
2991
  GIT_ASSERT_ARG(repo);
2675
2992
  GIT_ASSERT_ARG(workdir);
2676
2993
 
2677
- if (git_path_prettify_dir(&path, workdir, NULL) < 0)
2994
+ if (git_fs_path_prettify_dir(&path, workdir, NULL) < 0)
2678
2995
  return -1;
2679
2996
 
2680
2997
  if (repo->workdir && strcmp(repo->workdir, path.ptr) == 0)
@@ -2701,7 +3018,7 @@ int git_repository_set_workdir(
2701
3018
  if (!error) {
2702
3019
  char *old_workdir = repo->workdir;
2703
3020
 
2704
- repo->workdir = git_buf_detach(&path);
3021
+ repo->workdir = git_str_detach(&path);
2705
3022
  repo->is_bare = 0;
2706
3023
 
2707
3024
  git__free(old_workdir);
@@ -2770,60 +3087,62 @@ cleanup:
2770
3087
  int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head)
2771
3088
  {
2772
3089
  git_filebuf file = GIT_FILEBUF_INIT;
2773
- git_buf file_path = GIT_BUF_INIT;
2774
- char orig_head_str[GIT_OID_HEXSZ];
3090
+ git_str file_path = GIT_STR_INIT;
3091
+ char orig_head_str[GIT_OID_MAX_HEXSIZE];
2775
3092
  int error = 0;
2776
3093
 
2777
3094
  git_oid_fmt(orig_head_str, orig_head);
2778
3095
 
2779
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_ORIG_HEAD_FILE)) == 0 &&
3096
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_ORIG_HEAD_FILE)) == 0 &&
2780
3097
  (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) == 0 &&
2781
- (error = git_filebuf_printf(&file, "%.*s\n", GIT_OID_HEXSZ, orig_head_str)) == 0)
3098
+ (error = git_filebuf_printf(&file, "%.*s\n", (int)git_oid_hexsize(repo->oid_type), orig_head_str)) == 0)
2782
3099
  error = git_filebuf_commit(&file);
2783
3100
 
2784
3101
  if (error < 0)
2785
3102
  git_filebuf_cleanup(&file);
2786
3103
 
2787
- git_buf_dispose(&file_path);
3104
+ git_str_dispose(&file_path);
2788
3105
 
2789
3106
  return error;
2790
3107
  }
2791
3108
 
2792
- int git_repository_message(git_buf *out, git_repository *repo)
3109
+ static int git_repository__message(git_str *out, git_repository *repo)
2793
3110
  {
2794
- git_buf path = GIT_BUF_INIT;
3111
+ git_str path = GIT_STR_INIT;
2795
3112
  struct stat st;
2796
3113
  int error;
2797
3114
 
2798
- if ((error = git_buf_sanitize(out)) < 0)
2799
- return error;
2800
-
2801
- if (git_buf_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
3115
+ if (git_str_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
2802
3116
  return -1;
2803
3117
 
2804
- if ((error = p_stat(git_buf_cstr(&path), &st)) < 0) {
3118
+ if ((error = p_stat(git_str_cstr(&path), &st)) < 0) {
2805
3119
  if (errno == ENOENT)
2806
3120
  error = GIT_ENOTFOUND;
2807
3121
  git_error_set(GIT_ERROR_OS, "could not access message file");
2808
3122
  } else {
2809
- error = git_futils_readbuffer(out, git_buf_cstr(&path));
3123
+ error = git_futils_readbuffer(out, git_str_cstr(&path));
2810
3124
  }
2811
3125
 
2812
- git_buf_dispose(&path);
3126
+ git_str_dispose(&path);
2813
3127
 
2814
3128
  return error;
2815
3129
  }
2816
3130
 
3131
+ int git_repository_message(git_buf *out, git_repository *repo)
3132
+ {
3133
+ GIT_BUF_WRAP_PRIVATE(out, git_repository__message, repo);
3134
+ }
3135
+
2817
3136
  int git_repository_message_remove(git_repository *repo)
2818
3137
  {
2819
- git_buf path = GIT_BUF_INIT;
3138
+ git_str path = GIT_STR_INIT;
2820
3139
  int error;
2821
3140
 
2822
- if (git_buf_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
3141
+ if (git_str_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
2823
3142
  return -1;
2824
3143
 
2825
- error = p_unlink(git_buf_cstr(&path));
2826
- git_buf_dispose(&path);
3144
+ error = p_unlink(git_str_cstr(&path));
3145
+ git_str_dispose(&path);
2827
3146
 
2828
3147
  return error;
2829
3148
  }
@@ -2839,7 +3158,7 @@ int git_repository_hashfile(
2839
3158
  git_filter_list *fl = NULL;
2840
3159
  git_file fd = -1;
2841
3160
  uint64_t len;
2842
- git_buf full_path = GIT_BUF_INIT;
3161
+ git_str full_path = GIT_STR_INIT;
2843
3162
  const char *workdir = git_repository_workdir(repo);
2844
3163
 
2845
3164
  /* as_path can be NULL */
@@ -2847,8 +3166,8 @@ int git_repository_hashfile(
2847
3166
  GIT_ASSERT_ARG(path);
2848
3167
  GIT_ASSERT_ARG(repo);
2849
3168
 
2850
- if ((error = git_path_join_unrooted(&full_path, path, workdir, NULL)) < 0 ||
2851
- (error = git_path_validate_workdir_buf(repo, &full_path)) < 0)
3169
+ if ((error = git_fs_path_join_unrooted(&full_path, path, workdir, NULL)) < 0 ||
3170
+ (error = git_path_validate_str_length(repo, &full_path)) < 0)
2852
3171
  return error;
2853
3172
 
2854
3173
  /*
@@ -2889,36 +3208,36 @@ int git_repository_hashfile(
2889
3208
  goto cleanup;
2890
3209
  }
2891
3210
 
2892
- error = git_odb__hashfd_filtered(out, fd, (size_t)len, type, fl);
3211
+ error = git_odb__hashfd_filtered(out, fd, (size_t)len, type, repo->oid_type, fl);
2893
3212
 
2894
3213
  cleanup:
2895
3214
  if (fd >= 0)
2896
3215
  p_close(fd);
2897
3216
  git_filter_list_free(fl);
2898
- git_buf_dispose(&full_path);
3217
+ git_str_dispose(&full_path);
2899
3218
 
2900
3219
  return error;
2901
3220
  }
2902
3221
 
2903
- static int checkout_message(git_buf *out, git_reference *old, const char *new)
3222
+ static int checkout_message(git_str *out, git_reference *old, const char *new)
2904
3223
  {
2905
- git_buf_puts(out, "checkout: moving from ");
3224
+ git_str_puts(out, "checkout: moving from ");
2906
3225
 
2907
3226
  if (git_reference_type(old) == GIT_REFERENCE_SYMBOLIC)
2908
- git_buf_puts(out, git_reference__shorthand(git_reference_symbolic_target(old)));
3227
+ git_str_puts(out, git_reference__shorthand(git_reference_symbolic_target(old)));
2909
3228
  else
2910
- git_buf_puts(out, git_oid_tostr_s(git_reference_target(old)));
3229
+ git_str_puts(out, git_oid_tostr_s(git_reference_target(old)));
2911
3230
 
2912
- git_buf_puts(out, " to ");
3231
+ git_str_puts(out, " to ");
2913
3232
 
2914
3233
  if (git_reference__is_branch(new) ||
2915
3234
  git_reference__is_tag(new) ||
2916
3235
  git_reference__is_remote(new))
2917
- git_buf_puts(out, git_reference__shorthand(new));
3236
+ git_str_puts(out, git_reference__shorthand(new));
2918
3237
  else
2919
- git_buf_puts(out, new);
3238
+ git_str_puts(out, new);
2920
3239
 
2921
- if (git_buf_oom(out))
3240
+ if (git_str_oom(out))
2922
3241
  return -1;
2923
3242
 
2924
3243
  return 0;
@@ -2927,7 +3246,7 @@ static int checkout_message(git_buf *out, git_reference *old, const char *new)
2927
3246
  static int detach(git_repository *repo, const git_oid *id, const char *new)
2928
3247
  {
2929
3248
  int error;
2930
- git_buf log_message = GIT_BUF_INIT;
3249
+ git_str log_message = GIT_STR_INIT;
2931
3250
  git_object *object = NULL, *peeled = NULL;
2932
3251
  git_reference *new_head = NULL, *current = NULL;
2933
3252
 
@@ -2949,10 +3268,10 @@ static int detach(git_repository *repo, const git_oid *id, const char *new)
2949
3268
  if ((error = checkout_message(&log_message, current, new)) < 0)
2950
3269
  goto cleanup;
2951
3270
 
2952
- error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, git_buf_cstr(&log_message));
3271
+ error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, git_str_cstr(&log_message));
2953
3272
 
2954
3273
  cleanup:
2955
- git_buf_dispose(&log_message);
3274
+ git_str_dispose(&log_message);
2956
3275
  git_object_free(object);
2957
3276
  git_object_free(peeled);
2958
3277
  git_reference_free(current);
@@ -2965,7 +3284,7 @@ int git_repository_set_head(
2965
3284
  const char *refname)
2966
3285
  {
2967
3286
  git_reference *ref = NULL, *current = NULL, *new_head = NULL;
2968
- git_buf log_message = GIT_BUF_INIT;
3287
+ git_str log_message = GIT_STR_INIT;
2969
3288
  int error;
2970
3289
 
2971
3290
  GIT_ASSERT_ARG(repo);
@@ -2992,18 +3311,18 @@ int git_repository_set_head(
2992
3311
  if (!error) {
2993
3312
  if (git_reference_is_branch(ref)) {
2994
3313
  error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE,
2995
- git_reference_name(ref), true, git_buf_cstr(&log_message));
3314
+ git_reference_name(ref), true, git_str_cstr(&log_message));
2996
3315
  } else {
2997
3316
  error = detach(repo, git_reference_target(ref),
2998
3317
  git_reference_is_tag(ref) || git_reference_is_remote(ref) ? refname : NULL);
2999
3318
  }
3000
3319
  } else if (git_reference__is_branch(refname)) {
3001
3320
  error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname,
3002
- true, git_buf_cstr(&log_message));
3321
+ true, git_str_cstr(&log_message));
3003
3322
  }
3004
3323
 
3005
3324
  cleanup:
3006
- git_buf_dispose(&log_message);
3325
+ git_str_dispose(&log_message);
3007
3326
  git_reference_free(current);
3008
3327
  git_reference_free(ref);
3009
3328
  git_reference_free(new_head);
@@ -3012,26 +3331,26 @@ cleanup:
3012
3331
 
3013
3332
  int git_repository_set_head_detached(
3014
3333
  git_repository *repo,
3015
- const git_oid *commitish)
3334
+ const git_oid *committish)
3016
3335
  {
3017
- return detach(repo, commitish, NULL);
3336
+ return detach(repo, committish, NULL);
3018
3337
  }
3019
3338
 
3020
3339
  int git_repository_set_head_detached_from_annotated(
3021
3340
  git_repository *repo,
3022
- const git_annotated_commit *commitish)
3341
+ const git_annotated_commit *committish)
3023
3342
  {
3024
3343
  GIT_ASSERT_ARG(repo);
3025
- GIT_ASSERT_ARG(commitish);
3344
+ GIT_ASSERT_ARG(committish);
3026
3345
 
3027
- return detach(repo, git_annotated_commit_id(commitish), commitish->description);
3346
+ return detach(repo, git_annotated_commit_id(committish), committish->description);
3028
3347
  }
3029
3348
 
3030
3349
  int git_repository_detach_head(git_repository *repo)
3031
3350
  {
3032
3351
  git_reference *old_head = NULL, *new_head = NULL, *current = NULL;
3033
3352
  git_object *object = NULL;
3034
- git_buf log_message = GIT_BUF_INIT;
3353
+ git_str log_message = GIT_STR_INIT;
3035
3354
  int error;
3036
3355
 
3037
3356
  GIT_ASSERT_ARG(repo);
@@ -3049,10 +3368,10 @@ int git_repository_detach_head(git_repository *repo)
3049
3368
  goto cleanup;
3050
3369
 
3051
3370
  error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head),
3052
- 1, git_buf_cstr(&log_message));
3371
+ 1, git_str_cstr(&log_message));
3053
3372
 
3054
3373
  cleanup:
3055
- git_buf_dispose(&log_message);
3374
+ git_str_dispose(&log_message);
3056
3375
  git_object_free(object);
3057
3376
  git_reference_free(old_head);
3058
3377
  git_reference_free(new_head);
@@ -3066,69 +3385,69 @@ cleanup:
3066
3385
  */
3067
3386
  int git_repository_state(git_repository *repo)
3068
3387
  {
3069
- git_buf repo_path = GIT_BUF_INIT;
3388
+ git_str repo_path = GIT_STR_INIT;
3070
3389
  int state = GIT_REPOSITORY_STATE_NONE;
3071
3390
 
3072
3391
  GIT_ASSERT_ARG(repo);
3073
3392
 
3074
- if (git_buf_puts(&repo_path, repo->gitdir) < 0)
3393
+ if (git_str_puts(&repo_path, repo->gitdir) < 0)
3075
3394
  return -1;
3076
3395
 
3077
- if (git_path_contains_file(&repo_path, GIT_REBASE_MERGE_INTERACTIVE_FILE))
3396
+ if (git_fs_path_contains_file(&repo_path, GIT_REBASE_MERGE_INTERACTIVE_FILE))
3078
3397
  state = GIT_REPOSITORY_STATE_REBASE_INTERACTIVE;
3079
- else if (git_path_contains_dir(&repo_path, GIT_REBASE_MERGE_DIR))
3398
+ else if (git_fs_path_contains_dir(&repo_path, GIT_REBASE_MERGE_DIR))
3080
3399
  state = GIT_REPOSITORY_STATE_REBASE_MERGE;
3081
- else if (git_path_contains_file(&repo_path, GIT_REBASE_APPLY_REBASING_FILE))
3400
+ else if (git_fs_path_contains_file(&repo_path, GIT_REBASE_APPLY_REBASING_FILE))
3082
3401
  state = GIT_REPOSITORY_STATE_REBASE;
3083
- else if (git_path_contains_file(&repo_path, GIT_REBASE_APPLY_APPLYING_FILE))
3402
+ else if (git_fs_path_contains_file(&repo_path, GIT_REBASE_APPLY_APPLYING_FILE))
3084
3403
  state = GIT_REPOSITORY_STATE_APPLY_MAILBOX;
3085
- else if (git_path_contains_dir(&repo_path, GIT_REBASE_APPLY_DIR))
3404
+ else if (git_fs_path_contains_dir(&repo_path, GIT_REBASE_APPLY_DIR))
3086
3405
  state = GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE;
3087
- else if (git_path_contains_file(&repo_path, GIT_MERGE_HEAD_FILE))
3406
+ else if (git_fs_path_contains_file(&repo_path, GIT_MERGE_HEAD_FILE))
3088
3407
  state = GIT_REPOSITORY_STATE_MERGE;
3089
- else if (git_path_contains_file(&repo_path, GIT_REVERT_HEAD_FILE)) {
3408
+ else if (git_fs_path_contains_file(&repo_path, GIT_REVERT_HEAD_FILE)) {
3090
3409
  state = GIT_REPOSITORY_STATE_REVERT;
3091
- if (git_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
3410
+ if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
3092
3411
  state = GIT_REPOSITORY_STATE_REVERT_SEQUENCE;
3093
3412
  }
3094
- } else if (git_path_contains_file(&repo_path, GIT_CHERRYPICK_HEAD_FILE)) {
3413
+ } else if (git_fs_path_contains_file(&repo_path, GIT_CHERRYPICK_HEAD_FILE)) {
3095
3414
  state = GIT_REPOSITORY_STATE_CHERRYPICK;
3096
- if (git_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
3415
+ if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
3097
3416
  state = GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE;
3098
3417
  }
3099
- } else if (git_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE))
3418
+ } else if (git_fs_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE))
3100
3419
  state = GIT_REPOSITORY_STATE_BISECT;
3101
3420
 
3102
- git_buf_dispose(&repo_path);
3421
+ git_str_dispose(&repo_path);
3103
3422
  return state;
3104
3423
  }
3105
3424
 
3106
3425
  int git_repository__cleanup_files(
3107
3426
  git_repository *repo, const char *files[], size_t files_len)
3108
3427
  {
3109
- git_buf buf = GIT_BUF_INIT;
3428
+ git_str buf = GIT_STR_INIT;
3110
3429
  size_t i;
3111
3430
  int error;
3112
3431
 
3113
3432
  for (error = 0, i = 0; !error && i < files_len; ++i) {
3114
3433
  const char *path;
3115
3434
 
3116
- if (git_buf_joinpath(&buf, repo->gitdir, files[i]) < 0)
3435
+ if (git_str_joinpath(&buf, repo->gitdir, files[i]) < 0)
3117
3436
  return -1;
3118
3437
 
3119
- path = git_buf_cstr(&buf);
3438
+ path = git_str_cstr(&buf);
3120
3439
 
3121
- if (git_path_isfile(path)) {
3440
+ if (git_fs_path_isfile(path)) {
3122
3441
  error = p_unlink(path);
3123
- } else if (git_path_isdir(path)) {
3442
+ } else if (git_fs_path_isdir(path)) {
3124
3443
  error = git_futils_rmdir_r(path, NULL,
3125
3444
  GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS);
3126
3445
  }
3127
3446
 
3128
- git_buf_clear(&buf);
3447
+ git_str_clear(&buf);
3129
3448
  }
3130
3449
 
3131
- git_buf_dispose(&buf);
3450
+ git_str_dispose(&buf);
3132
3451
  return error;
3133
3452
  }
3134
3453
 
@@ -3153,15 +3472,15 @@ int git_repository_state_cleanup(git_repository *repo)
3153
3472
 
3154
3473
  int git_repository_is_shallow(git_repository *repo)
3155
3474
  {
3156
- git_buf path = GIT_BUF_INIT;
3475
+ git_str path = GIT_STR_INIT;
3157
3476
  struct stat st;
3158
3477
  int error;
3159
3478
 
3160
- if ((error = git_buf_joinpath(&path, repo->gitdir, "shallow")) < 0)
3479
+ if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0)
3161
3480
  return error;
3162
3481
 
3163
- error = git_path_lstat(path.ptr, &st);
3164
- git_buf_dispose(&path);
3482
+ error = git_fs_path_lstat(path.ptr, &st);
3483
+ git_str_dispose(&path);
3165
3484
 
3166
3485
  if (error == GIT_ENOTFOUND) {
3167
3486
  git_error_clear();
@@ -3236,3 +3555,8 @@ int git_repository_submodule_cache_clear(git_repository *repo)
3236
3555
  repo->submodule_cache = NULL;
3237
3556
  return error;
3238
3557
  }
3558
+
3559
+ git_oid_t git_repository_oid_type(git_repository *repo)
3560
+ {
3561
+ return repo ? repo->oid_type : 0;
3562
+ }