rugged 1.3.2 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (547) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -2
  3. data/ext/rugged/extconf.rb +7 -4
  4. data/ext/rugged/rugged.c +16 -0
  5. data/ext/rugged/rugged.h +4 -0
  6. data/ext/rugged/rugged_blame.c +2 -0
  7. data/ext/rugged/rugged_blob.c +3 -0
  8. data/ext/rugged/rugged_commit.c +1 -0
  9. data/ext/rugged/rugged_config.c +9 -2
  10. data/ext/rugged/rugged_diff.c +1 -0
  11. data/ext/rugged/rugged_index.c +2 -0
  12. data/ext/rugged/rugged_patch.c +1 -0
  13. data/ext/rugged/rugged_rebase.c +1 -0
  14. data/ext/rugged/rugged_reference.c +1 -0
  15. data/ext/rugged/rugged_remote.c +28 -10
  16. data/ext/rugged/rugged_repo.c +7 -9
  17. data/ext/rugged/rugged_revwalk.c +5 -1
  18. data/ext/rugged/rugged_settings.c +5 -0
  19. data/ext/rugged/rugged_submodule.c +1 -0
  20. data/ext/rugged/rugged_tag.c +1 -0
  21. data/ext/rugged/rugged_tree.c +4 -0
  22. data/lib/rugged/index.rb +1 -1
  23. data/lib/rugged/tree.rb +5 -1
  24. data/lib/rugged/version.rb +1 -1
  25. data/vendor/libgit2/CMakeLists.txt +132 -288
  26. data/vendor/libgit2/COPYING +106 -19
  27. data/vendor/libgit2/cmake/AddCFlagIfSupported.cmake +21 -21
  28. data/vendor/libgit2/cmake/AddClarTest.cmake +7 -0
  29. data/vendor/libgit2/cmake/DefaultCFlags.cmake +154 -0
  30. data/vendor/libgit2/cmake/EnableWarnings.cmake +13 -13
  31. data/vendor/libgit2/cmake/ExperimentalFeatures.cmake +23 -0
  32. data/vendor/libgit2/cmake/FindCoreFoundation.cmake +13 -13
  33. data/vendor/libgit2/cmake/FindGSSAPI.cmake +171 -287
  34. data/vendor/libgit2/cmake/FindGSSFramework.cmake +13 -13
  35. data/vendor/libgit2/cmake/{FindHTTP_Parser.cmake → FindHTTPParser.cmake} +17 -17
  36. data/vendor/libgit2/cmake/FindIconv.cmake +27 -27
  37. data/vendor/libgit2/cmake/FindLibSSH2.cmake +5 -5
  38. data/vendor/libgit2/cmake/FindPCRE.cmake +12 -13
  39. data/vendor/libgit2/cmake/FindPCRE2.cmake +12 -12
  40. data/vendor/libgit2/cmake/FindPkgLibraries.cmake +19 -19
  41. data/vendor/libgit2/cmake/FindSecurity.cmake +14 -14
  42. data/vendor/libgit2/cmake/FindStatNsec.cmake +12 -18
  43. data/vendor/libgit2/cmake/Findfutimens.cmake +8 -8
  44. data/vendor/libgit2/cmake/FindmbedTLS.cmake +63 -70
  45. data/vendor/libgit2/cmake/IdeSplitSources.cmake +18 -18
  46. data/vendor/libgit2/cmake/PkgBuildConfig.cmake +60 -60
  47. data/vendor/libgit2/cmake/SanitizeBool.cmake +20 -20
  48. data/vendor/libgit2/cmake/SelectGSSAPI.cmake +37 -37
  49. data/vendor/libgit2/cmake/SelectHTTPParser.cmake +19 -0
  50. data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +100 -100
  51. data/vendor/libgit2/cmake/SelectHashes.cmake +91 -53
  52. data/vendor/libgit2/cmake/SelectRegex.cmake +51 -0
  53. data/vendor/libgit2/cmake/SelectSSH.cmake +41 -0
  54. data/vendor/libgit2/cmake/SelectWinHTTP.cmake +17 -0
  55. data/vendor/libgit2/cmake/SelectZlib.cmake +34 -0
  56. data/vendor/libgit2/deps/chromium-zlib/CMakeLists.txt +6 -6
  57. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +33 -31
  58. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +3 -1
  59. data/vendor/libgit2/deps/ntlmclient/ntlm.c +4 -4
  60. data/vendor/libgit2/deps/ntlmclient/ntlm.h +4 -4
  61. data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +2 -2
  62. data/vendor/libgit2/deps/pcre/CMakeLists.txt +88 -88
  63. data/vendor/libgit2/deps/winhttp/CMakeLists.txt +14 -16
  64. data/vendor/libgit2/deps/zlib/adler32.c +7 -0
  65. data/vendor/libgit2/deps/zlib/crc32.c +975 -288
  66. data/vendor/libgit2/deps/zlib/crc32.h +9441 -436
  67. data/vendor/libgit2/deps/zlib/deflate.c +83 -31
  68. data/vendor/libgit2/deps/zlib/deflate.h +12 -15
  69. data/vendor/libgit2/deps/zlib/gzguts.h +3 -2
  70. data/vendor/libgit2/deps/zlib/infback.c +2 -1
  71. data/vendor/libgit2/deps/zlib/inffast.c +14 -14
  72. data/vendor/libgit2/deps/zlib/inflate.c +39 -8
  73. data/vendor/libgit2/deps/zlib/inflate.h +3 -2
  74. data/vendor/libgit2/deps/zlib/inftrees.c +3 -3
  75. data/vendor/libgit2/deps/zlib/trees.c +27 -48
  76. data/vendor/libgit2/deps/zlib/zlib.h +126 -100
  77. data/vendor/libgit2/deps/zlib/zutil.c +2 -2
  78. data/vendor/libgit2/deps/zlib/zutil.h +12 -9
  79. data/vendor/libgit2/include/git2/apply.h +16 -2
  80. data/vendor/libgit2/include/git2/attr.h +11 -2
  81. data/vendor/libgit2/include/git2/blame.h +4 -1
  82. data/vendor/libgit2/include/git2/blob.h +14 -1
  83. data/vendor/libgit2/include/git2/branch.h +4 -2
  84. data/vendor/libgit2/include/git2/buffer.h +18 -78
  85. data/vendor/libgit2/include/git2/cert.h +2 -2
  86. data/vendor/libgit2/include/git2/checkout.h +5 -2
  87. data/vendor/libgit2/include/git2/clone.h +3 -3
  88. data/vendor/libgit2/include/git2/commit.h +2 -0
  89. data/vendor/libgit2/include/git2/common.h +28 -7
  90. data/vendor/libgit2/include/git2/config.h +25 -9
  91. data/vendor/libgit2/include/git2/credential.h +2 -1
  92. data/vendor/libgit2/include/git2/credential_helpers.h +1 -0
  93. data/vendor/libgit2/include/git2/deprecated.h +9 -1
  94. data/vendor/libgit2/include/git2/describe.h +7 -2
  95. data/vendor/libgit2/include/git2/diff.h +18 -10
  96. data/vendor/libgit2/include/git2/email.h +1 -1
  97. data/vendor/libgit2/include/git2/errors.h +17 -3
  98. data/vendor/libgit2/include/git2/experimental.h +20 -0
  99. data/vendor/libgit2/include/git2/filter.h +7 -2
  100. data/vendor/libgit2/include/git2/graph.h +1 -0
  101. data/vendor/libgit2/include/git2/ignore.h +1 -1
  102. data/vendor/libgit2/include/git2/index.h +11 -5
  103. data/vendor/libgit2/include/git2/indexer.h +48 -0
  104. data/vendor/libgit2/include/git2/merge.h +24 -4
  105. data/vendor/libgit2/include/git2/message.h +2 -0
  106. data/vendor/libgit2/include/git2/object.h +49 -0
  107. data/vendor/libgit2/include/git2/odb.h +94 -13
  108. data/vendor/libgit2/include/git2/odb_backend.h +107 -19
  109. data/vendor/libgit2/include/git2/oid.h +115 -15
  110. data/vendor/libgit2/include/git2/pack.h +24 -8
  111. data/vendor/libgit2/include/git2/patch.h +8 -0
  112. data/vendor/libgit2/include/git2/pathspec.h +1 -1
  113. data/vendor/libgit2/include/git2/proxy.h +1 -1
  114. data/vendor/libgit2/include/git2/rebase.h +9 -1
  115. data/vendor/libgit2/include/git2/refdb.h +3 -0
  116. data/vendor/libgit2/include/git2/reflog.h +1 -1
  117. data/vendor/libgit2/include/git2/refs.h +2 -2
  118. data/vendor/libgit2/include/git2/remote.h +184 -37
  119. data/vendor/libgit2/include/git2/repository.h +34 -10
  120. data/vendor/libgit2/include/git2/reset.h +2 -2
  121. data/vendor/libgit2/include/git2/revparse.h +1 -1
  122. data/vendor/libgit2/include/git2/revwalk.h +4 -1
  123. data/vendor/libgit2/include/git2/signature.h +1 -1
  124. data/vendor/libgit2/include/git2/stash.h +61 -7
  125. data/vendor/libgit2/include/git2/status.h +14 -5
  126. data/vendor/libgit2/include/git2/strarray.h +0 -13
  127. data/vendor/libgit2/include/git2/submodule.h +7 -2
  128. data/vendor/libgit2/include/git2/sys/commit_graph.h +1 -1
  129. data/vendor/libgit2/include/git2/sys/odb_backend.h +3 -6
  130. data/vendor/libgit2/include/git2/sys/remote.h +46 -0
  131. data/vendor/libgit2/include/git2/sys/stream.h +1 -1
  132. data/vendor/libgit2/include/git2/sys/transport.h +46 -39
  133. data/vendor/libgit2/include/git2/tag.h +1 -0
  134. data/vendor/libgit2/include/git2/tree.h +4 -3
  135. data/vendor/libgit2/include/git2/types.h +7 -7
  136. data/vendor/libgit2/include/git2/version.h +27 -6
  137. data/vendor/libgit2/include/git2/worktree.h +12 -2
  138. data/vendor/libgit2/include/git2.h +1 -0
  139. data/vendor/libgit2/src/CMakeLists.txt +177 -419
  140. data/vendor/libgit2/src/README.md +12 -0
  141. data/vendor/libgit2/src/cli/CMakeLists.txt +57 -0
  142. data/vendor/libgit2/src/cli/README.md +26 -0
  143. data/vendor/libgit2/src/cli/cli.h +20 -0
  144. data/vendor/libgit2/src/cli/cmd.c +21 -0
  145. data/vendor/libgit2/src/cli/cmd.h +33 -0
  146. data/vendor/libgit2/src/cli/cmd_cat_file.c +204 -0
  147. data/vendor/libgit2/src/cli/cmd_clone.c +176 -0
  148. data/vendor/libgit2/src/cli/cmd_hash_object.c +154 -0
  149. data/vendor/libgit2/src/cli/cmd_help.c +86 -0
  150. data/vendor/libgit2/src/cli/error.h +51 -0
  151. data/vendor/libgit2/src/cli/main.c +106 -0
  152. data/vendor/libgit2/src/cli/opt.c +669 -0
  153. data/vendor/libgit2/src/cli/opt.h +349 -0
  154. data/vendor/libgit2/src/cli/opt_usage.c +194 -0
  155. data/vendor/libgit2/src/cli/opt_usage.h +35 -0
  156. data/vendor/libgit2/src/cli/progress.c +345 -0
  157. data/vendor/libgit2/src/cli/progress.h +117 -0
  158. data/vendor/libgit2/src/cli/sighandler.h +20 -0
  159. data/vendor/libgit2/src/cli/unix/sighandler.c +36 -0
  160. data/vendor/libgit2/src/cli/win32/precompiled.h +3 -0
  161. data/vendor/libgit2/src/cli/win32/sighandler.c +37 -0
  162. data/vendor/libgit2/src/libgit2/CMakeLists.txt +141 -0
  163. data/vendor/libgit2/src/{annotated_commit.c → libgit2/annotated_commit.c} +1 -1
  164. data/vendor/libgit2/src/{annotated_commit.h → libgit2/annotated_commit.h} +2 -2
  165. data/vendor/libgit2/src/{apply.c → libgit2/apply.c} +18 -18
  166. data/vendor/libgit2/src/{apply.h → libgit2/apply.h} +2 -2
  167. data/vendor/libgit2/src/{attr.c → libgit2/attr.c} +18 -18
  168. data/vendor/libgit2/src/{attr_file.c → libgit2/attr_file.c} +18 -18
  169. data/vendor/libgit2/src/{attr_file.h → libgit2/attr_file.h} +4 -4
  170. data/vendor/libgit2/src/{attrcache.c → libgit2/attrcache.c} +18 -13
  171. data/vendor/libgit2/src/{blame.c → libgit2/blame.c} +2 -0
  172. data/vendor/libgit2/src/{blame_git.c → libgit2/blame_git.c} +1 -1
  173. data/vendor/libgit2/src/{blob.c → libgit2/blob.c} +38 -29
  174. data/vendor/libgit2/src/{blob.h → libgit2/blob.h} +3 -3
  175. data/vendor/libgit2/src/{branch.c → libgit2/branch.c} +164 -118
  176. data/vendor/libgit2/src/{branch.h → libgit2/branch.h} +15 -3
  177. data/vendor/libgit2/src/libgit2/buf.c +126 -0
  178. data/vendor/libgit2/src/libgit2/buf.h +50 -0
  179. data/vendor/libgit2/src/{checkout.c → libgit2/checkout.c} +74 -68
  180. data/vendor/libgit2/src/{cherrypick.c → libgit2/cherrypick.c} +13 -13
  181. data/vendor/libgit2/src/{clone.c → libgit2/clone.c} +96 -67
  182. data/vendor/libgit2/src/{commit.c → libgit2/commit.c} +178 -73
  183. data/vendor/libgit2/src/libgit2/commit.h +87 -0
  184. data/vendor/libgit2/src/{commit_graph.c → libgit2/commit_graph.c} +122 -89
  185. data/vendor/libgit2/src/{commit_graph.h → libgit2/commit_graph.h} +14 -4
  186. data/vendor/libgit2/src/{commit_list.c → libgit2/commit_list.c} +7 -4
  187. data/vendor/libgit2/src/libgit2/common.h +55 -0
  188. data/vendor/libgit2/src/{config.c → libgit2/config.c} +101 -69
  189. data/vendor/libgit2/src/{config.h → libgit2/config.h} +15 -2
  190. data/vendor/libgit2/src/{config_file.c → libgit2/config_file.c} +105 -93
  191. data/vendor/libgit2/src/{config_mem.c → libgit2/config_mem.c} +9 -9
  192. data/vendor/libgit2/src/{config_parse.c → libgit2/config_parse.c} +27 -23
  193. data/vendor/libgit2/src/{crlf.c → libgit2/crlf.c} +24 -21
  194. data/vendor/libgit2/src/{describe.c → libgit2/describe.c} +35 -27
  195. data/vendor/libgit2/src/{diff.c → libgit2/diff.c} +30 -9
  196. data/vendor/libgit2/src/{diff.h → libgit2/diff.h} +2 -4
  197. data/vendor/libgit2/src/{diff_driver.c → libgit2/diff_driver.c} +34 -36
  198. data/vendor/libgit2/src/{diff_driver.h → libgit2/diff_driver.h} +3 -3
  199. data/vendor/libgit2/src/{diff_file.c → libgit2/diff_file.c} +44 -26
  200. data/vendor/libgit2/src/{diff_generate.c → libgit2/diff_generate.c} +47 -18
  201. data/vendor/libgit2/src/{diff_generate.h → libgit2/diff_generate.h} +5 -3
  202. data/vendor/libgit2/src/{diff_print.c → libgit2/diff_print.c} +112 -100
  203. data/vendor/libgit2/src/{diff_stats.c → libgit2/diff_stats.c} +40 -29
  204. data/vendor/libgit2/src/libgit2/diff_stats.h +18 -0
  205. data/vendor/libgit2/src/{diff_tform.c → libgit2/diff_tform.c} +13 -8
  206. data/vendor/libgit2/src/{diff_xdiff.c → libgit2/diff_xdiff.c} +4 -8
  207. data/vendor/libgit2/src/{email.c → libgit2/email.c} +55 -39
  208. data/vendor/libgit2/src/{email.h → libgit2/email.h} +1 -1
  209. data/vendor/libgit2/src/{errors.c → libgit2/errors.c} +18 -18
  210. data/vendor/libgit2/src/{errors.h → libgit2/errors.h} +1 -2
  211. data/vendor/libgit2/src/libgit2/experimental.h.in +13 -0
  212. data/vendor/libgit2/src/{fetch.c → libgit2/fetch.c} +72 -27
  213. data/vendor/libgit2/src/{fetch.h → libgit2/fetch.h} +1 -1
  214. data/vendor/libgit2/src/{fetchhead.c → libgit2/fetchhead.c} +23 -23
  215. data/vendor/libgit2/src/{filter.c → libgit2/filter.c} +127 -53
  216. data/vendor/libgit2/src/{filter.h → libgit2/filter.h} +26 -5
  217. data/vendor/libgit2/src/{ident.c → libgit2/ident.c} +20 -20
  218. data/vendor/libgit2/src/{ignore.c → libgit2/ignore.c} +35 -34
  219. data/vendor/libgit2/src/{ignore.h → libgit2/ignore.h} +2 -2
  220. data/vendor/libgit2/src/{index.c → libgit2/index.c} +91 -90
  221. data/vendor/libgit2/src/{index.h → libgit2/index.h} +6 -3
  222. data/vendor/libgit2/src/{indexer.c → libgit2/indexer.c} +173 -92
  223. data/vendor/libgit2/src/{iterator.c → libgit2/iterator.c} +71 -61
  224. data/vendor/libgit2/src/{iterator.h → libgit2/iterator.h} +5 -5
  225. data/vendor/libgit2/src/{libgit2.c → libgit2/libgit2.c} +46 -11
  226. data/vendor/libgit2/src/{mailmap.c → libgit2/mailmap.c} +38 -36
  227. data/vendor/libgit2/src/{merge.c → libgit2/merge.c} +30 -30
  228. data/vendor/libgit2/src/{merge.h → libgit2/merge.h} +1 -14
  229. data/vendor/libgit2/src/{merge_driver.c → libgit2/merge_driver.c} +2 -2
  230. data/vendor/libgit2/src/{merge_file.c → libgit2/merge_file.c} +13 -3
  231. data/vendor/libgit2/src/{message.c → libgit2/message.c} +21 -10
  232. data/vendor/libgit2/src/{midx.c → libgit2/midx.c} +112 -92
  233. data/vendor/libgit2/src/{midx.h → libgit2/midx.h} +5 -4
  234. data/vendor/libgit2/src/{mwindow.c → libgit2/mwindow.c} +15 -12
  235. data/vendor/libgit2/src/{mwindow.h → libgit2/mwindow.h} +5 -2
  236. data/vendor/libgit2/src/{netops.c → libgit2/netops.c} +1 -2
  237. data/vendor/libgit2/src/{netops.h → libgit2/netops.h} +1 -1
  238. data/vendor/libgit2/src/{notes.c → libgit2/notes.c} +25 -34
  239. data/vendor/libgit2/src/{object.c → libgit2/object.c} +135 -30
  240. data/vendor/libgit2/src/{object.h → libgit2/object.h} +12 -3
  241. data/vendor/libgit2/src/{odb.c → libgit2/odb.c} +228 -81
  242. data/vendor/libgit2/src/{odb.h → libgit2/odb.h} +44 -5
  243. data/vendor/libgit2/src/{odb_loose.c → libgit2/odb_loose.c} +192 -134
  244. data/vendor/libgit2/src/{odb_mempack.c → libgit2/odb_mempack.c} +18 -5
  245. data/vendor/libgit2/src/{odb_pack.c → libgit2/odb_pack.c} +137 -85
  246. data/vendor/libgit2/src/{oid.c → libgit2/oid.c} +136 -90
  247. data/vendor/libgit2/src/libgit2/oid.h +273 -0
  248. data/vendor/libgit2/src/{oidmap.c → libgit2/oidmap.c} +1 -1
  249. data/vendor/libgit2/src/{pack-objects.c → libgit2/pack-objects.c} +56 -30
  250. data/vendor/libgit2/src/{pack-objects.h → libgit2/pack-objects.h} +11 -6
  251. data/vendor/libgit2/src/{pack.c → libgit2/pack.c} +114 -84
  252. data/vendor/libgit2/src/{pack.h → libgit2/pack.h} +31 -16
  253. data/vendor/libgit2/src/{parse.c → libgit2/parse.c} +4 -3
  254. data/vendor/libgit2/src/{patch.c → libgit2/patch.c} +3 -3
  255. data/vendor/libgit2/src/{patch.h → libgit2/patch.h} +1 -0
  256. data/vendor/libgit2/src/{patch_generate.c → libgit2/patch_generate.c} +27 -11
  257. data/vendor/libgit2/src/{patch_generate.h → libgit2/patch_generate.h} +5 -5
  258. data/vendor/libgit2/src/{patch_parse.c → libgit2/patch_parse.c} +29 -29
  259. data/vendor/libgit2/src/libgit2/path.c +375 -0
  260. data/vendor/libgit2/src/libgit2/path.h +68 -0
  261. data/vendor/libgit2/src/{pathspec.c → libgit2/pathspec.c} +6 -6
  262. data/vendor/libgit2/src/{pathspec.h → libgit2/pathspec.h} +2 -2
  263. data/vendor/libgit2/src/{proxy.c → libgit2/proxy.c} +4 -1
  264. data/vendor/libgit2/src/{proxy.h → libgit2/proxy.h} +1 -1
  265. data/vendor/libgit2/src/{push.c → libgit2/push.c} +43 -38
  266. data/vendor/libgit2/src/{push.h → libgit2/push.h} +4 -16
  267. data/vendor/libgit2/src/{reader.c → libgit2/reader.c} +9 -9
  268. data/vendor/libgit2/src/{reader.h → libgit2/reader.h} +2 -2
  269. data/vendor/libgit2/src/{rebase.c → libgit2/rebase.c} +119 -107
  270. data/vendor/libgit2/src/{refdb_fs.c → libgit2/refdb_fs.c} +506 -197
  271. data/vendor/libgit2/src/{reflog.c → libgit2/reflog.c} +7 -5
  272. data/vendor/libgit2/src/{reflog.h → libgit2/reflog.h} +1 -2
  273. data/vendor/libgit2/src/{refs.c → libgit2/refs.c} +34 -32
  274. data/vendor/libgit2/src/{refs.h → libgit2/refs.h} +2 -2
  275. data/vendor/libgit2/src/{refspec.c → libgit2/refspec.c} +32 -37
  276. data/vendor/libgit2/src/{refspec.h → libgit2/refspec.h} +5 -2
  277. data/vendor/libgit2/src/{remote.c → libgit2/remote.c} +718 -420
  278. data/vendor/libgit2/src/libgit2/remote.h +100 -0
  279. data/vendor/libgit2/src/{repository.c → libgit2/repository.c} +629 -386
  280. data/vendor/libgit2/src/{repository.h → libgit2/repository.h} +20 -9
  281. data/vendor/libgit2/src/{reset.c → libgit2/reset.c} +8 -5
  282. data/vendor/libgit2/src/{revert.c → libgit2/revert.c} +14 -14
  283. data/vendor/libgit2/src/{revparse.c → libgit2/revparse.c} +71 -42
  284. data/vendor/libgit2/src/{revwalk.c → libgit2/revwalk.c} +12 -8
  285. data/vendor/libgit2/src/{signature.c → libgit2/signature.c} +12 -6
  286. data/vendor/libgit2/src/{signature.h → libgit2/signature.h} +1 -1
  287. data/vendor/libgit2/src/{stash.c → libgit2/stash.c} +235 -61
  288. data/vendor/libgit2/src/{status.c → libgit2/status.c} +4 -1
  289. data/vendor/libgit2/src/{strarray.c → libgit2/strarray.c} +1 -0
  290. data/vendor/libgit2/src/libgit2/strarray.h +25 -0
  291. data/vendor/libgit2/src/{streams → libgit2/streams}/mbedtls.c +8 -6
  292. data/vendor/libgit2/src/{streams → libgit2/streams}/openssl.c +1 -1
  293. data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_dynamic.c +7 -3
  294. data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_dynamic.h +3 -3
  295. data/vendor/libgit2/src/{streams → libgit2/streams}/socket.c +4 -1
  296. data/vendor/libgit2/src/{submodule.c → libgit2/submodule.c} +177 -161
  297. data/vendor/libgit2/src/{submodule.h → libgit2/submodule.h} +1 -1
  298. data/vendor/libgit2/src/libgit2/sysdir.c +650 -0
  299. data/vendor/libgit2/src/{sysdir.h → libgit2/sysdir.h} +53 -18
  300. data/vendor/libgit2/src/{tag.c → libgit2/tag.c} +73 -42
  301. data/vendor/libgit2/src/{tag.h → libgit2/tag.h} +2 -2
  302. data/vendor/libgit2/src/{threadstate.c → libgit2/threadstate.c} +3 -3
  303. data/vendor/libgit2/src/{threadstate.h → libgit2/threadstate.h} +2 -2
  304. data/vendor/libgit2/src/{trace.c → libgit2/trace.c} +1 -14
  305. data/vendor/libgit2/src/{trace.h → libgit2/trace.h} +5 -22
  306. data/vendor/libgit2/src/{trailer.c → libgit2/trailer.c} +1 -1
  307. data/vendor/libgit2/src/{transaction.c → libgit2/transaction.c} +1 -1
  308. data/vendor/libgit2/src/{transport.c → libgit2/transport.c} +10 -10
  309. data/vendor/libgit2/src/{transports → libgit2/transports}/auth.c +7 -9
  310. data/vendor/libgit2/src/{transports → libgit2/transports}/auth.h +2 -3
  311. data/vendor/libgit2/src/{transports → libgit2/transports}/auth_negotiate.c +12 -13
  312. data/vendor/libgit2/src/{transports → libgit2/transports}/auth_ntlm.c +10 -10
  313. data/vendor/libgit2/src/{transports → libgit2/transports}/auth_ntlm.h +0 -1
  314. data/vendor/libgit2/src/{transports → libgit2/transports}/git.c +9 -11
  315. data/vendor/libgit2/src/{transports → libgit2/transports}/http.c +41 -20
  316. data/vendor/libgit2/src/{transports → libgit2/transports}/http.h +2 -3
  317. data/vendor/libgit2/src/{transports → libgit2/transports}/httpclient.c +75 -66
  318. data/vendor/libgit2/src/{transports → libgit2/transports}/httpclient.h +10 -0
  319. data/vendor/libgit2/src/{transports → libgit2/transports}/local.c +138 -116
  320. data/vendor/libgit2/src/{transports → libgit2/transports}/smart.c +92 -133
  321. data/vendor/libgit2/src/{transports → libgit2/transports}/smart.h +35 -32
  322. data/vendor/libgit2/src/{transports → libgit2/transports}/smart_pkt.c +177 -65
  323. data/vendor/libgit2/src/{transports → libgit2/transports}/smart_protocol.c +97 -49
  324. data/vendor/libgit2/src/{transports → libgit2/transports}/ssh.c +365 -198
  325. data/vendor/libgit2/src/{transports → libgit2/transports}/winhttp.c +58 -59
  326. data/vendor/libgit2/src/{tree-cache.c → libgit2/tree-cache.c} +8 -8
  327. data/vendor/libgit2/src/{tree-cache.h → libgit2/tree-cache.h} +2 -2
  328. data/vendor/libgit2/src/{tree.c → libgit2/tree.c} +93 -83
  329. data/vendor/libgit2/src/{tree.h → libgit2/tree.h} +4 -4
  330. data/vendor/libgit2/src/{worktree.c → libgit2/worktree.c} +121 -94
  331. data/vendor/libgit2/src/{worktree.h → libgit2/worktree.h} +1 -1
  332. data/vendor/libgit2/src/libgit2/xdiff/git-xdiff.h +53 -0
  333. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xdiff.h +15 -15
  334. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xdiffi.c +134 -108
  335. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xemit.c +23 -7
  336. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xhistogram.c +87 -78
  337. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xinclude.h +1 -12
  338. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xmerge.c +104 -117
  339. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xpatience.c +6 -17
  340. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xprepare.c +15 -20
  341. data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xutils.c +18 -7
  342. data/vendor/libgit2/src/util/CMakeLists.txt +80 -0
  343. data/vendor/libgit2/src/{allocators → util/allocators}/failalloc.h +1 -1
  344. data/vendor/libgit2/src/{allocators → util/allocators}/stdalloc.h +1 -1
  345. data/vendor/libgit2/src/{allocators → util/allocators}/win32_leakcheck.h +1 -1
  346. data/vendor/libgit2/src/{array.h → util/array.h} +1 -1
  347. data/vendor/libgit2/src/{assert_safe.h → util/assert_safe.h} +16 -0
  348. data/vendor/libgit2/src/{cc-compat.h → util/cc-compat.h} +1 -1
  349. data/vendor/libgit2/src/{date.c → util/date.c} +14 -20
  350. data/vendor/libgit2/src/util/date.h +33 -0
  351. data/vendor/libgit2/src/{filebuf.c → util/filebuf.c} +29 -29
  352. data/vendor/libgit2/src/{filebuf.h → util/filebuf.h} +2 -2
  353. data/vendor/libgit2/src/{path.c → util/fs_path.c} +453 -647
  354. data/vendor/libgit2/src/{path.h → util/fs_path.h} +221 -188
  355. data/vendor/libgit2/src/{futils.c → util/futils.c} +135 -90
  356. data/vendor/libgit2/src/{futils.h → util/futils.h} +28 -15
  357. data/vendor/libgit2/src/{features.h.in → util/git2_features.h.in} +15 -1
  358. data/vendor/libgit2/src/{common.h → util/git2_util.h} +20 -59
  359. data/vendor/libgit2/src/util/hash/builtin.c +53 -0
  360. data/vendor/libgit2/src/{hash/sha1/openssl.h → util/hash/builtin.h} +6 -6
  361. data/vendor/libgit2/src/{hash/sha1 → util/hash}/collisiondetect.c +3 -3
  362. data/vendor/libgit2/src/{hash/sha1 → util/hash}/collisiondetect.h +3 -3
  363. data/vendor/libgit2/src/util/hash/common_crypto.c +112 -0
  364. data/vendor/libgit2/src/{hash/sha1 → util/hash}/common_crypto.h +11 -3
  365. data/vendor/libgit2/src/util/hash/mbedtls.c +92 -0
  366. data/vendor/libgit2/src/{hash/sha1 → util/hash}/mbedtls.h +14 -4
  367. data/vendor/libgit2/src/util/hash/openssl.c +195 -0
  368. data/vendor/libgit2/src/util/hash/openssl.h +45 -0
  369. data/vendor/libgit2/src/util/hash/rfc6234/sha.h +243 -0
  370. data/vendor/libgit2/src/util/hash/rfc6234/sha224-256.c +601 -0
  371. data/vendor/libgit2/src/util/hash/sha.h +70 -0
  372. data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/sha1.c +1 -1
  373. data/vendor/libgit2/src/util/hash/win32.c +549 -0
  374. data/vendor/libgit2/src/util/hash/win32.h +60 -0
  375. data/vendor/libgit2/src/util/hash.c +158 -0
  376. data/vendor/libgit2/src/util/hash.h +61 -0
  377. data/vendor/libgit2/src/{khash.h → util/khash.h} +1 -1
  378. data/vendor/libgit2/src/{map.h → util/map.h} +1 -1
  379. data/vendor/libgit2/src/util/net.c +1003 -0
  380. data/vendor/libgit2/src/{net.h → util/net.h} +18 -4
  381. data/vendor/libgit2/src/{pool.h → util/pool.h} +1 -1
  382. data/vendor/libgit2/src/{posix.c → util/posix.c} +3 -3
  383. data/vendor/libgit2/src/{posix.h → util/posix.h} +4 -1
  384. data/vendor/libgit2/src/{pqueue.h → util/pqueue.h} +2 -2
  385. data/vendor/libgit2/src/util/rand.c +234 -0
  386. data/vendor/libgit2/src/util/rand.h +37 -0
  387. data/vendor/libgit2/src/{regexp.c → util/regexp.c} +4 -4
  388. data/vendor/libgit2/src/{regexp.h → util/regexp.h} +1 -1
  389. data/vendor/libgit2/src/{runtime.c → util/runtime.c} +1 -1
  390. data/vendor/libgit2/src/{runtime.h → util/runtime.h} +1 -1
  391. data/vendor/libgit2/src/{sortedcache.c → util/sortedcache.c} +1 -1
  392. data/vendor/libgit2/src/{sortedcache.h → util/sortedcache.h} +2 -2
  393. data/vendor/libgit2/src/{buffer.c → util/str.c} +157 -151
  394. data/vendor/libgit2/src/util/str.h +357 -0
  395. data/vendor/libgit2/src/{strmap.h → util/strmap.h} +1 -1
  396. data/vendor/libgit2/src/{thread.c → util/thread.c} +1 -1
  397. data/vendor/libgit2/src/{thread.h → util/thread.h} +23 -22
  398. data/vendor/libgit2/src/{tsort.c → util/tsort.c} +1 -1
  399. data/vendor/libgit2/src/{unix → util/unix}/map.c +1 -3
  400. data/vendor/libgit2/src/{unix → util/unix}/posix.h +1 -4
  401. data/vendor/libgit2/src/{unix → util/unix}/realpath.c +1 -3
  402. data/vendor/libgit2/src/{utf8.c → util/utf8.c} +1 -1
  403. data/vendor/libgit2/src/{utf8.h → util/utf8.h} +1 -1
  404. data/vendor/libgit2/src/{util.c → util/util.c} +15 -15
  405. data/vendor/libgit2/src/{util.h → util/util.h} +4 -29
  406. data/vendor/libgit2/src/{varint.h → util/varint.h} +1 -1
  407. data/vendor/libgit2/src/{vector.h → util/vector.h} +2 -2
  408. data/vendor/libgit2/src/{wildmatch.h → util/wildmatch.h} +1 -1
  409. data/vendor/libgit2/src/{win32 → util/win32}/dir.h +1 -1
  410. data/vendor/libgit2/src/{win32 → util/win32}/error.h +1 -1
  411. data/vendor/libgit2/src/{win32 → util/win32}/map.c +1 -1
  412. data/vendor/libgit2/src/{win32 → util/win32}/path_w32.c +140 -9
  413. data/vendor/libgit2/src/{win32 → util/win32}/path_w32.h +3 -1
  414. data/vendor/libgit2/src/{win32 → util/win32}/posix.h +1 -2
  415. data/vendor/libgit2/src/{win32 → util/win32}/posix_w32.c +12 -28
  416. data/vendor/libgit2/src/util/win32/precompiled.c +1 -0
  417. data/vendor/libgit2/src/{win32 → util/win32}/precompiled.h +1 -1
  418. data/vendor/libgit2/src/{win32 → util/win32}/thread.h +1 -1
  419. data/vendor/libgit2/src/{win32 → util/win32}/utf-conv.h +1 -1
  420. data/vendor/libgit2/src/{win32 → util/win32}/w32_buffer.c +2 -3
  421. data/vendor/libgit2/src/{win32 → util/win32}/w32_buffer.h +3 -4
  422. data/vendor/libgit2/src/{win32 → util/win32}/w32_leakcheck.c +1 -1
  423. data/vendor/libgit2/src/{win32 → util/win32}/w32_leakcheck.h +1 -1
  424. data/vendor/libgit2/src/{win32 → util/win32}/w32_util.h +1 -1
  425. data/vendor/libgit2/src/{zstream.c → util/zstream.c} +5 -5
  426. data/vendor/libgit2/src/{zstream.h → util/zstream.h} +5 -5
  427. metadata +402 -356
  428. data/vendor/libgit2/src/buffer.h +0 -374
  429. data/vendor/libgit2/src/commit.h +0 -46
  430. data/vendor/libgit2/src/hash/sha1/common_crypto.c +0 -57
  431. data/vendor/libgit2/src/hash/sha1/generic.c +0 -300
  432. data/vendor/libgit2/src/hash/sha1/generic.h +0 -19
  433. data/vendor/libgit2/src/hash/sha1/mbedtls.c +0 -46
  434. data/vendor/libgit2/src/hash/sha1/openssl.c +0 -59
  435. data/vendor/libgit2/src/hash/sha1/win32.c +0 -333
  436. data/vendor/libgit2/src/hash/sha1/win32.h +0 -128
  437. data/vendor/libgit2/src/hash/sha1.h +0 -38
  438. data/vendor/libgit2/src/hash.c +0 -110
  439. data/vendor/libgit2/src/hash.h +0 -46
  440. data/vendor/libgit2/src/message.h +0 -17
  441. data/vendor/libgit2/src/net.c +0 -540
  442. data/vendor/libgit2/src/oid.h +0 -51
  443. data/vendor/libgit2/src/remote.h +0 -55
  444. data/vendor/libgit2/src/sysdir.c +0 -347
  445. data/vendor/libgit2/src/win32/findfile.c +0 -230
  446. data/vendor/libgit2/src/win32/findfile.h +0 -19
  447. /data/vendor/libgit2/src/{win32 → cli/win32}/precompiled.c +0 -0
  448. /data/vendor/libgit2/src/{attr.h → libgit2/attr.h} +0 -0
  449. /data/vendor/libgit2/src/{attrcache.h → libgit2/attrcache.h} +0 -0
  450. /data/vendor/libgit2/src/{blame.h → libgit2/blame.h} +0 -0
  451. /data/vendor/libgit2/src/{blame_git.h → libgit2/blame_git.h} +0 -0
  452. /data/vendor/libgit2/src/{cache.c → libgit2/cache.c} +0 -0
  453. /data/vendor/libgit2/src/{cache.h → libgit2/cache.h} +0 -0
  454. /data/vendor/libgit2/src/{checkout.h → libgit2/checkout.h} +0 -0
  455. /data/vendor/libgit2/src/{clone.h → libgit2/clone.h} +0 -0
  456. /data/vendor/libgit2/src/{commit_list.h → libgit2/commit_list.h} +0 -0
  457. /data/vendor/libgit2/src/{config_backend.h → libgit2/config_backend.h} +0 -0
  458. /data/vendor/libgit2/src/{config_cache.c → libgit2/config_cache.c} +0 -0
  459. /data/vendor/libgit2/src/{config_entries.c → libgit2/config_entries.c} +0 -0
  460. /data/vendor/libgit2/src/{config_entries.h → libgit2/config_entries.h} +0 -0
  461. /data/vendor/libgit2/src/{config_parse.h → libgit2/config_parse.h} +0 -0
  462. /data/vendor/libgit2/src/{config_snapshot.c → libgit2/config_snapshot.c} +0 -0
  463. /data/vendor/libgit2/src/{delta.c → libgit2/delta.c} +0 -0
  464. /data/vendor/libgit2/src/{delta.h → libgit2/delta.h} +0 -0
  465. /data/vendor/libgit2/src/{diff_file.h → libgit2/diff_file.h} +0 -0
  466. /data/vendor/libgit2/src/{diff_parse.c → libgit2/diff_parse.c} +0 -0
  467. /data/vendor/libgit2/src/{diff_parse.h → libgit2/diff_parse.h} +0 -0
  468. /data/vendor/libgit2/src/{diff_tform.h → libgit2/diff_tform.h} +0 -0
  469. /data/vendor/libgit2/src/{diff_xdiff.h → libgit2/diff_xdiff.h} +0 -0
  470. /data/vendor/libgit2/src/{fetchhead.h → libgit2/fetchhead.h} +0 -0
  471. /data/vendor/libgit2/src/{win32 → libgit2}/git2.rc +0 -0
  472. /data/vendor/libgit2/src/{graph.c → libgit2/graph.c} +0 -0
  473. /data/vendor/libgit2/src/{hashsig.c → libgit2/hashsig.c} +0 -0
  474. /data/vendor/libgit2/src/{idxmap.c → libgit2/idxmap.c} +0 -0
  475. /data/vendor/libgit2/src/{idxmap.h → libgit2/idxmap.h} +0 -0
  476. /data/vendor/libgit2/src/{indexer.h → libgit2/indexer.h} +0 -0
  477. /data/vendor/libgit2/src/{libgit2.h → libgit2/libgit2.h} +0 -0
  478. /data/vendor/libgit2/src/{mailmap.h → libgit2/mailmap.h} +0 -0
  479. /data/vendor/libgit2/src/{merge_driver.h → libgit2/merge_driver.h} +0 -0
  480. /data/vendor/libgit2/src/{notes.h → libgit2/notes.h} +0 -0
  481. /data/vendor/libgit2/src/{object_api.c → libgit2/object_api.c} +0 -0
  482. /data/vendor/libgit2/src/{offmap.c → libgit2/offmap.c} +0 -0
  483. /data/vendor/libgit2/src/{offmap.h → libgit2/offmap.h} +0 -0
  484. /data/vendor/libgit2/src/{oidarray.c → libgit2/oidarray.c} +0 -0
  485. /data/vendor/libgit2/src/{oidarray.h → libgit2/oidarray.h} +0 -0
  486. /data/vendor/libgit2/src/{oidmap.h → libgit2/oidmap.h} +0 -0
  487. /data/vendor/libgit2/src/{parse.h → libgit2/parse.h} +0 -0
  488. /data/vendor/libgit2/src/{patch_parse.h → libgit2/patch_parse.h} +0 -0
  489. /data/vendor/libgit2/src/{refdb.c → libgit2/refdb.c} +0 -0
  490. /data/vendor/libgit2/src/{refdb.h → libgit2/refdb.h} +0 -0
  491. /data/vendor/libgit2/src/{repo_template.h → libgit2/repo_template.h} +0 -0
  492. /data/vendor/libgit2/src/{revwalk.h → libgit2/revwalk.h} +0 -0
  493. /data/vendor/libgit2/src/{settings.h → libgit2/settings.h} +0 -0
  494. /data/vendor/libgit2/src/{status.h → libgit2/status.h} +0 -0
  495. /data/vendor/libgit2/src/{stream.h → libgit2/stream.h} +0 -0
  496. /data/vendor/libgit2/src/{streams → libgit2/streams}/mbedtls.h +0 -0
  497. /data/vendor/libgit2/src/{streams → libgit2/streams}/openssl.h +0 -0
  498. /data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_legacy.c +0 -0
  499. /data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_legacy.h +0 -0
  500. /data/vendor/libgit2/src/{streams → libgit2/streams}/registry.c +0 -0
  501. /data/vendor/libgit2/src/{streams → libgit2/streams}/registry.h +0 -0
  502. /data/vendor/libgit2/src/{streams → libgit2/streams}/socket.h +0 -0
  503. /data/vendor/libgit2/src/{streams → libgit2/streams}/stransport.c +0 -0
  504. /data/vendor/libgit2/src/{streams → libgit2/streams}/stransport.h +0 -0
  505. /data/vendor/libgit2/src/{streams → libgit2/streams}/tls.c +0 -0
  506. /data/vendor/libgit2/src/{streams → libgit2/streams}/tls.h +0 -0
  507. /data/vendor/libgit2/src/{transaction.h → libgit2/transaction.h} +0 -0
  508. /data/vendor/libgit2/src/{transports → libgit2/transports}/auth_negotiate.h +0 -0
  509. /data/vendor/libgit2/src/{transports → libgit2/transports}/credential.c +0 -0
  510. /data/vendor/libgit2/src/{transports → libgit2/transports}/credential_helpers.c +0 -0
  511. /data/vendor/libgit2/src/{transports → libgit2/transports}/ssh.h +0 -0
  512. /data/vendor/libgit2/src/{userdiff.h → libgit2/userdiff.h} +0 -0
  513. /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xdiffi.h +0 -0
  514. /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xemit.h +0 -0
  515. /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xmacros.h +0 -0
  516. /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xprepare.h +0 -0
  517. /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xtypes.h +0 -0
  518. /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xutils.h +0 -0
  519. /data/vendor/libgit2/src/{alloc.c → util/alloc.c} +0 -0
  520. /data/vendor/libgit2/src/{alloc.h → util/alloc.h} +0 -0
  521. /data/vendor/libgit2/src/{allocators → util/allocators}/failalloc.c +0 -0
  522. /data/vendor/libgit2/src/{allocators → util/allocators}/stdalloc.c +0 -0
  523. /data/vendor/libgit2/src/{allocators → util/allocators}/win32_leakcheck.c +0 -0
  524. /data/vendor/libgit2/src/{bitvec.h → util/bitvec.h} +0 -0
  525. /data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/sha1.h +0 -0
  526. /data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/ubc_check.c +0 -0
  527. /data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/ubc_check.h +0 -0
  528. /data/vendor/libgit2/src/{integer.h → util/integer.h} +0 -0
  529. /data/vendor/libgit2/src/{pool.c → util/pool.c} +0 -0
  530. /data/vendor/libgit2/src/{pqueue.c → util/pqueue.c} +0 -0
  531. /data/vendor/libgit2/src/{strmap.c → util/strmap.c} +0 -0
  532. /data/vendor/libgit2/src/{strnlen.h → util/strnlen.h} +0 -0
  533. /data/vendor/libgit2/src/{unix → util/unix}/pthread.h +0 -0
  534. /data/vendor/libgit2/src/{varint.c → util/varint.c} +0 -0
  535. /data/vendor/libgit2/src/{vector.c → util/vector.c} +0 -0
  536. /data/vendor/libgit2/src/{wildmatch.c → util/wildmatch.c} +0 -0
  537. /data/vendor/libgit2/src/{win32 → util/win32}/dir.c +0 -0
  538. /data/vendor/libgit2/src/{win32 → util/win32}/error.c +0 -0
  539. /data/vendor/libgit2/src/{win32 → util/win32}/mingw-compat.h +0 -0
  540. /data/vendor/libgit2/src/{win32 → util/win32}/msvc-compat.h +0 -0
  541. /data/vendor/libgit2/src/{win32 → util/win32}/reparse.h +0 -0
  542. /data/vendor/libgit2/src/{win32 → util/win32}/thread.c +0 -0
  543. /data/vendor/libgit2/src/{win32 → util/win32}/utf-conv.c +0 -0
  544. /data/vendor/libgit2/src/{win32 → util/win32}/version.h +0 -0
  545. /data/vendor/libgit2/src/{win32 → util/win32}/w32_common.h +0 -0
  546. /data/vendor/libgit2/src/{win32 → util/win32}/w32_util.c +0 -0
  547. /data/vendor/libgit2/src/{win32 → util/win32}/win32-compat.h +0 -0
@@ -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,7 +32,7 @@
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
@@ -66,6 +67,7 @@ static const struct {
66
67
  static int check_repositoryformatversion(int *version, git_config *config);
67
68
  static int check_extensions(git_config *config, int version);
68
69
  static int load_global_config(git_config **config);
70
+ static int load_objectformat(git_repository *repo, git_config *config);
69
71
 
70
72
  #define GIT_COMMONDIR_FILE "commondir"
71
73
  #define GIT_GITDIR_FILE "gitdir"
@@ -74,16 +76,16 @@ static int load_global_config(git_config **config);
74
76
 
75
77
  #define GIT_BRANCH_DEFAULT "master"
76
78
 
77
- #define GIT_REPO_VERSION 0
78
- #define GIT_REPO_MAX_VERSION 1
79
+ #define GIT_REPO_VERSION_DEFAULT 0
80
+ #define GIT_REPO_VERSION_MAX 1
79
81
 
80
- git_buf git_repository__reserved_names_win32[] = {
82
+ git_str git_repository__reserved_names_win32[] = {
81
83
  { DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
82
84
  { GIT_DIR_SHORTNAME, 0, CONST_STRLEN(GIT_DIR_SHORTNAME) }
83
85
  };
84
86
  size_t git_repository__reserved_names_win32_len = 2;
85
87
 
86
- git_buf git_repository__reserved_names_posix[] = {
88
+ git_str git_repository__reserved_names_posix[] = {
87
89
  { DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
88
90
  };
89
91
  size_t git_repository__reserved_names_posix_len = 1;
@@ -173,7 +175,7 @@ void git_repository_free(git_repository *repo)
173
175
  repo->diff_drivers = NULL;
174
176
 
175
177
  for (i = 0; i < repo->reserved_names.size; i++)
176
- git_buf_dispose(git_array_get(repo->reserved_names, i));
178
+ git_str_dispose(git_array_get(repo->reserved_names, i));
177
179
  git_array_clear(repo->reserved_names);
178
180
 
179
181
  git__free(repo->gitlink);
@@ -189,18 +191,18 @@ void git_repository_free(git_repository *repo)
189
191
  }
190
192
 
191
193
  /* Check if we have a separate commondir (e.g. we have a worktree) */
192
- 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)
193
195
  {
194
- git_buf common_link = GIT_BUF_INIT;
196
+ git_str common_link = GIT_STR_INIT;
195
197
  int error;
196
198
 
197
199
  /*
198
200
  * If there's no commondir file, the repository path is the
199
201
  * common path, but it needs a trailing slash.
200
202
  */
201
- if (!git_path_contains_file(repository_path, GIT_COMMONDIR_FILE)) {
202
- if ((error = git_buf_set(commondir, repository_path->ptr, repository_path->size)) == 0)
203
- 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);
204
206
 
205
207
  *separate = false;
206
208
  goto done;
@@ -208,28 +210,28 @@ static int lookup_commondir(bool *separate, git_buf *commondir, git_buf *reposit
208
210
 
209
211
  *separate = true;
210
212
 
211
- 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 ||
212
214
  (error = git_futils_readbuffer(&common_link, common_link.ptr)) < 0)
213
215
  goto done;
214
216
 
215
- git_buf_rtrim(&common_link);
216
- if (git_path_is_relative(common_link.ptr)) {
217
- 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)
218
220
  goto done;
219
221
  } else {
220
- git_buf_swap(commondir, &common_link);
222
+ git_str_swap(commondir, &common_link);
221
223
  }
222
224
 
223
- git_buf_dispose(&common_link);
225
+ git_str_dispose(&common_link);
224
226
 
225
227
  /* Make sure the commondir path always has a trailing slash */
226
- error = git_path_prettify_dir(commondir, commondir->ptr, NULL);
228
+ error = git_fs_path_prettify_dir(commondir, commondir->ptr, NULL);
227
229
 
228
230
  done:
229
231
  return error;
230
232
  }
231
233
 
232
- GIT_INLINE(int) validate_repo_path(git_buf *path)
234
+ GIT_INLINE(int) validate_repo_path(git_str *path)
233
235
  {
234
236
  /*
235
237
  * The longest static path in a repository (or commondir) is the
@@ -239,10 +241,10 @@ GIT_INLINE(int) validate_repo_path(git_buf *path)
239
241
  */
240
242
  static size_t suffix_len =
241
243
  CONST_STRLEN("objects/pack/pack-.pack.lock") +
242
- GIT_OID_HEXSZ;
244
+ GIT_OID_MAX_HEXSIZE;
243
245
 
244
- return git_path_validate_filesystem_with_suffix(
245
- path->ptr, path->size, suffix_len);
246
+ return git_fs_path_validate_str_length_with_suffix(
247
+ path, suffix_len);
246
248
  }
247
249
 
248
250
  /*
@@ -250,7 +252,7 @@ GIT_INLINE(int) validate_repo_path(git_buf *path)
250
252
  *
251
253
  * Open a repository object from its path
252
254
  */
253
- 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)
254
256
  {
255
257
  bool separate_commondir = false;
256
258
  int error;
@@ -261,13 +263,13 @@ static int is_valid_repository_path(bool *out, git_buf *repository_path, git_buf
261
263
  return error;
262
264
 
263
265
  /* Ensure HEAD file exists */
264
- if (git_path_contains_file(repository_path, GIT_HEAD_FILE) == false)
266
+ if (git_fs_path_contains_file(repository_path, GIT_HEAD_FILE) == false)
265
267
  return 0;
266
268
 
267
269
  /* Check files in common dir */
268
- if (git_path_contains_dir(common_path, GIT_OBJECTS_DIR) == false)
270
+ if (git_fs_path_contains_dir(common_path, GIT_OBJECTS_DIR) == false)
269
271
  return 0;
270
- if (git_path_contains_dir(common_path, GIT_REFS_DIR) == false)
272
+ if (git_fs_path_contains_dir(common_path, GIT_REFS_DIR) == false)
271
273
  return 0;
272
274
 
273
275
  /* Ensure the repo (and commondir) are valid paths */
@@ -335,12 +337,12 @@ static int load_config_data(git_repository *repo, const git_config *config)
335
337
  return 0;
336
338
  }
337
339
 
338
- 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)
339
341
  {
340
342
  int error;
341
343
  git_config_entry *ce;
342
- git_buf worktree = GIT_BUF_INIT;
343
- git_buf path = GIT_BUF_INIT;
344
+ git_str worktree = GIT_STR_INIT;
345
+ git_str path = GIT_STR_INIT;
344
346
 
345
347
  if (repo->is_bare)
346
348
  return 0;
@@ -356,38 +358,38 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren
356
358
  goto cleanup;
357
359
  }
358
360
 
359
- git_buf_attach(&worktree, gitlink, 0);
361
+ git_str_attach(&worktree, gitlink, 0);
360
362
 
361
- if ((git_path_dirname_r(&worktree, worktree.ptr)) < 0 ||
362
- 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) {
363
365
  error = -1;
364
366
  goto cleanup;
365
367
  }
366
368
 
367
- repo->workdir = git_buf_detach(&worktree);
369
+ repo->workdir = git_str_detach(&worktree);
368
370
  }
369
371
  else if (ce && ce->value) {
370
- if ((error = git_path_prettify_dir(
372
+ if ((error = git_fs_path_prettify_dir(
371
373
  &worktree, ce->value, repo->gitdir)) < 0)
372
374
  goto cleanup;
373
375
 
374
- repo->workdir = git_buf_detach(&worktree);
376
+ repo->workdir = git_str_detach(&worktree);
375
377
  }
376
- else if (parent_path && git_path_isdir(parent_path->ptr))
377
- 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);
378
380
  else {
379
- if (git_path_dirname_r(&worktree, repo->gitdir) < 0 ||
380
- 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) {
381
383
  error = -1;
382
384
  goto cleanup;
383
385
  }
384
386
 
385
- repo->workdir = git_buf_detach(&worktree);
387
+ repo->workdir = git_str_detach(&worktree);
386
388
  }
387
389
 
388
390
  GIT_ERROR_CHECK_ALLOC(repo->workdir);
389
391
  cleanup:
390
- git_buf_dispose(&path);
392
+ git_str_dispose(&path);
391
393
  git_config_entry_free(ce);
392
394
  return error;
393
395
  }
@@ -396,7 +398,7 @@ cleanup:
396
398
  * This function returns furthest offset into path where a ceiling dir
397
399
  * is found, so we can stop processing the path at that point.
398
400
  *
399
- * 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
400
402
  * the stack could remove directories name limits, but at the cost of doing
401
403
  * repeated malloc/frees inside the loop below, so let's not do it now.
402
404
  */
@@ -411,7 +413,7 @@ static size_t find_ceiling_dir_offset(
411
413
 
412
414
  GIT_ASSERT_ARG(path);
413
415
 
414
- min_len = (size_t)(git_path_root(path) + 1);
416
+ min_len = (size_t)(git_fs_path_root(path) + 1);
415
417
 
416
418
  if (ceiling_directories == NULL || min_len == 0)
417
419
  return min_len;
@@ -420,7 +422,7 @@ static size_t find_ceiling_dir_offset(
420
422
  for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++);
421
423
  len = sep - ceil;
422
424
 
423
- if (len == 0 || len >= sizeof(buf) || git_path_root(ceil) == -1)
425
+ if (len == 0 || len >= sizeof(buf) || git_fs_path_root(ceil) == -1)
424
426
  continue;
425
427
 
426
428
  strncpy(buf, ceil, len);
@@ -449,10 +451,10 @@ static size_t find_ceiling_dir_offset(
449
451
  * it points to. Before calling, set `path_out` to the base directory that
450
452
  * should be used if the contents of `file_path` are a relative path.
451
453
  */
452
- 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)
453
455
  {
454
456
  int error = 0;
455
- git_buf file = GIT_BUF_INIT;
457
+ git_str file = GIT_STR_INIT;
456
458
  size_t prefix_len = strlen(GIT_FILE_CONTENT_PREFIX);
457
459
 
458
460
  GIT_ASSERT_ARG(path_out);
@@ -461,98 +463,192 @@ static int read_gitfile(git_buf *path_out, const char *file_path)
461
463
  if (git_futils_readbuffer(&file, file_path) < 0)
462
464
  return -1;
463
465
 
464
- git_buf_rtrim(&file);
466
+ git_str_rtrim(&file);
465
467
  /* apparently on Windows, some people use backslashes in paths */
466
- git_path_mkposix(file.ptr);
468
+ git_fs_path_mkposix(file.ptr);
467
469
 
468
- if (git_buf_len(&file) <= prefix_len ||
469
- 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)
470
472
  {
471
473
  git_error_set(GIT_ERROR_REPOSITORY,
472
474
  "the `.git` file at '%s' is malformed", file_path);
473
475
  error = -1;
474
476
  }
475
- else if ((error = git_path_dirname_r(path_out, file_path)) >= 0) {
476
- 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;
477
479
  while (*gitlink && git__isspace(*gitlink)) gitlink++;
478
480
 
479
- error = git_path_prettify_dir(
480
- path_out, gitlink, git_buf_cstr(path_out));
481
+ error = git_fs_path_prettify_dir(
482
+ path_out, gitlink, git_str_cstr(path_out));
481
483
  }
482
484
 
483
- git_buf_dispose(&file);
485
+ git_str_dispose(&file);
484
486
  return error;
485
487
  }
486
488
 
487
489
  typedef struct {
488
490
  const char *repo_path;
489
- git_buf tmp;
490
- bool is_safe;
491
+ git_str tmp;
492
+ bool *is_safe;
491
493
  } validate_ownership_data;
492
494
 
493
495
  static int validate_ownership_cb(const git_config_entry *entry, void *payload)
494
496
  {
495
497
  validate_ownership_data *data = payload;
496
498
 
497
- if (strcmp(entry->value, "") == 0)
498
- data->is_safe = false;
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;
499
505
 
500
- if (git_path_prettify_dir(&data->tmp, entry->value, NULL) == 0 &&
501
- strcmp(data->tmp.ptr, data->repo_path) == 0)
502
- data->is_safe = true;
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
+ }
503
540
 
504
541
  return 0;
505
542
  }
506
543
 
507
- static int validate_ownership(const char *repo_path)
544
+ static int validate_ownership_config(bool *is_safe, const char *path)
508
545
  {
509
- git_config *config = NULL;
510
- validate_ownership_data data = { repo_path, GIT_BUF_INIT, false };
511
- bool is_safe;
546
+ validate_ownership_data ownership_data = {
547
+ path, GIT_STR_INIT, is_safe
548
+ };
549
+ git_config *config;
512
550
  int error;
513
551
 
514
- if ((error = git_path_owner_is_current_user(&is_safe, repo_path)) < 0) {
515
- if (error == GIT_ENOTFOUND)
516
- error = 0;
552
+ if (load_global_config(&config) != 0)
553
+ return 0;
517
554
 
518
- goto done;
519
- }
555
+ error = git_config_get_multivar_foreach(config,
556
+ "safe.directory", NULL,
557
+ validate_ownership_cb,
558
+ &ownership_data);
520
559
 
521
- if (is_safe) {
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;
522
585
  error = 0;
523
- goto done;
524
586
  }
525
587
 
526
- if (load_global_config(&config) == 0) {
527
- error = git_config_get_multivar_foreach(config, "safe.directory", NULL, validate_ownership_cb, &data);
588
+ return error;
589
+ }
528
590
 
529
- if (!error && data.is_safe)
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)
530
619
  goto done;
620
+
621
+ if (!is_safe)
622
+ break;
531
623
  }
532
624
 
533
- git_error_set(GIT_ERROR_CONFIG,
534
- "repository path '%s' is not owned by current user",
535
- repo_path);
536
- error = GIT_EOWNER;
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;
634
+ }
537
635
 
538
636
  done:
539
- git_config_free(config);
540
- git_buf_dispose(&data.tmp);
541
637
  return error;
542
638
  }
543
639
 
544
640
  static int find_repo(
545
- git_buf *gitdir_path,
546
- git_buf *workdir_path,
547
- git_buf *gitlink_path,
548
- git_buf *commondir_path,
641
+ git_str *gitdir_path,
642
+ git_str *workdir_path,
643
+ git_str *gitlink_path,
644
+ git_str *commondir_path,
549
645
  const char *start_path,
550
646
  uint32_t flags,
551
647
  const char *ceiling_dirs)
552
648
  {
553
- git_buf path = GIT_BUF_INIT;
554
- git_buf repo_link = GIT_BUF_INIT;
555
- 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;
556
652
  struct stat st;
557
653
  dev_t initial_device = 0;
558
654
  int min_iterations;
@@ -560,9 +656,9 @@ static int find_repo(
560
656
  size_t ceiling_offset = 0;
561
657
  int error;
562
658
 
563
- git_buf_clear(gitdir_path);
659
+ git_str_clear(gitdir_path);
564
660
 
565
- error = git_path_prettify(&path, start_path, NULL);
661
+ error = git_fs_path_prettify(&path, start_path, NULL);
566
662
  if (error < 0)
567
663
  return error;
568
664
 
@@ -584,7 +680,7 @@ static int find_repo(
584
680
  for (;;) {
585
681
  if (!(flags & GIT_REPOSITORY_OPEN_NO_DOTGIT)) {
586
682
  if (!in_dot_git) {
587
- if ((error = git_buf_joinpath(&path, path.ptr, DOT_GIT)) < 0)
683
+ if ((error = git_str_joinpath(&path, path.ptr, DOT_GIT)) < 0)
588
684
  goto out;
589
685
  }
590
686
  in_dot_git = !in_dot_git;
@@ -603,15 +699,15 @@ static int find_repo(
603
699
  goto out;
604
700
 
605
701
  if (is_valid) {
606
- if ((error = git_path_to_dir(&path)) < 0 ||
607
- (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)
608
704
  goto out;
609
705
 
610
706
  if (gitlink_path)
611
- 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)
612
708
  goto out;
613
709
  if (commondir_path)
614
- git_buf_swap(&common_link, commondir_path);
710
+ git_str_swap(&common_link, commondir_path);
615
711
 
616
712
  break;
617
713
  }
@@ -621,13 +717,13 @@ static int find_repo(
621
717
  goto out;
622
718
 
623
719
  if (is_valid) {
624
- git_buf_swap(gitdir_path, &repo_link);
720
+ git_str_swap(gitdir_path, &repo_link);
625
721
 
626
722
  if (gitlink_path)
627
- 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)
628
724
  goto out;
629
725
  if (commondir_path)
630
- git_buf_swap(&common_link, commondir_path);
726
+ git_str_swap(&common_link, commondir_path);
631
727
  }
632
728
  break;
633
729
  }
@@ -636,7 +732,7 @@ static int find_repo(
636
732
  /* Move up one directory. If we're in_dot_git, we'll search the
637
733
  * parent itself next. If we're !in_dot_git, we'll search .git
638
734
  * in the parent directory next (added at the top of the loop). */
639
- if ((error = git_path_dirname_r(&path, path.ptr)) < 0)
735
+ if ((error = git_fs_path_dirname_r(&path, path.ptr)) < 0)
640
736
  goto out;
641
737
 
642
738
  /* Once we've checked the directory (and .git if applicable),
@@ -651,25 +747,62 @@ static int find_repo(
651
747
  }
652
748
 
653
749
  if (workdir_path && !(flags & GIT_REPOSITORY_OPEN_BARE)) {
654
- if (!git_buf_len(gitdir_path))
655
- git_buf_clear(workdir_path);
656
- else if ((error = git_path_dirname_r(workdir_path, path.ptr)) < 0 ||
657
- (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)
658
754
  goto out;
659
755
  }
660
756
 
661
757
  /* If we didn't find the repository, and we don't have any other error
662
758
  * to report, report that. */
663
- if (!git_buf_len(gitdir_path)) {
759
+ if (!git_str_len(gitdir_path)) {
664
760
  git_error_set(GIT_ERROR_REPOSITORY, "could not find repository from '%s'", start_path);
665
761
  error = GIT_ENOTFOUND;
666
762
  goto out;
667
763
  }
668
764
 
669
765
  out:
670
- git_buf_dispose(&path);
671
- git_buf_dispose(&repo_link);
672
- 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
+
673
806
  return error;
674
807
  }
675
808
 
@@ -677,18 +810,19 @@ int git_repository_open_bare(
677
810
  git_repository **repo_ptr,
678
811
  const char *bare_path)
679
812
  {
680
- git_buf path = GIT_BUF_INIT, common_path = GIT_BUF_INIT;
813
+ git_str path = GIT_STR_INIT, common_path = GIT_STR_INIT;
681
814
  git_repository *repo = NULL;
682
815
  bool is_valid;
683
816
  int error;
817
+ git_config *config;
684
818
 
685
- if ((error = git_path_prettify_dir(&path, bare_path, NULL)) < 0 ||
819
+ if ((error = git_fs_path_prettify_dir(&path, bare_path, NULL)) < 0 ||
686
820
  (error = is_valid_repository_path(&is_valid, &path, &common_path)) < 0)
687
821
  return error;
688
822
 
689
823
  if (!is_valid) {
690
- git_buf_dispose(&path);
691
- git_buf_dispose(&common_path);
824
+ git_str_dispose(&path);
825
+ git_str_dispose(&common_path);
692
826
  git_error_set(GIT_ERROR_REPOSITORY, "path is not a repository: %s", bare_path);
693
827
  return GIT_ENOTFOUND;
694
828
  }
@@ -696,9 +830,9 @@ int git_repository_open_bare(
696
830
  repo = repository_alloc();
697
831
  GIT_ERROR_CHECK_ALLOC(repo);
698
832
 
699
- repo->gitdir = git_buf_detach(&path);
833
+ repo->gitdir = git_str_detach(&path);
700
834
  GIT_ERROR_CHECK_ALLOC(repo->gitdir);
701
- repo->commondir = git_buf_detach(&common_path);
835
+ repo->commondir = git_str_detach(&common_path);
702
836
  GIT_ERROR_CHECK_ALLOC(repo->commondir);
703
837
 
704
838
  /* of course we're bare! */
@@ -706,8 +840,15 @@ int git_repository_open_bare(
706
840
  repo->is_worktree = 0;
707
841
  repo->workdir = NULL;
708
842
 
843
+ if ((error = obtain_config_and_set_oid_type(&config, repo)) < 0)
844
+ goto cleanup;
845
+
709
846
  *repo_ptr = repo;
710
- return 0;
847
+
848
+ cleanup:
849
+ git_config_free(config);
850
+
851
+ return error;
711
852
  }
712
853
 
713
854
  static int _git_repository_open_ext_from_env(
@@ -717,15 +858,15 @@ static int _git_repository_open_ext_from_env(
717
858
  git_repository *repo = NULL;
718
859
  git_index *index = NULL;
719
860
  git_odb *odb = NULL;
720
- git_buf dir_buf = GIT_BUF_INIT;
721
- git_buf ceiling_dirs_buf = GIT_BUF_INIT;
722
- git_buf across_fs_buf = GIT_BUF_INIT;
723
- git_buf index_file_buf = GIT_BUF_INIT;
724
- git_buf namespace_buf = GIT_BUF_INIT;
725
- git_buf object_dir_buf = GIT_BUF_INIT;
726
- git_buf alts_buf = GIT_BUF_INIT;
727
- git_buf work_tree_buf = GIT_BUF_INIT;
728
- 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;
729
870
  const char *ceiling_dirs = NULL;
730
871
  unsigned flags = 0;
731
872
  int error;
@@ -738,7 +879,7 @@ static int _git_repository_open_ext_from_env(
738
879
  } else if (error < 0)
739
880
  goto error;
740
881
  else {
741
- start_path = git_buf_cstr(&dir_buf);
882
+ start_path = git_str_cstr(&dir_buf);
742
883
  flags |= GIT_REPOSITORY_OPEN_NO_SEARCH;
743
884
  flags |= GIT_REPOSITORY_OPEN_NO_DOTGIT;
744
885
  }
@@ -750,7 +891,7 @@ static int _git_repository_open_ext_from_env(
750
891
  else if (error < 0)
751
892
  goto error;
752
893
  else
753
- ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf);
894
+ ceiling_dirs = git_str_cstr(&ceiling_dirs_buf);
754
895
 
755
896
  error = git__getenv(&across_fs_buf, "GIT_DISCOVERY_ACROSS_FILESYSTEM");
756
897
  if (error == GIT_ENOTFOUND)
@@ -759,7 +900,7 @@ static int _git_repository_open_ext_from_env(
759
900
  goto error;
760
901
  else {
761
902
  int across_fs = 0;
762
- 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));
763
904
  if (error < 0)
764
905
  goto error;
765
906
  if (across_fs)
@@ -772,7 +913,7 @@ static int _git_repository_open_ext_from_env(
772
913
  else if (error < 0)
773
914
  goto error;
774
915
  else {
775
- error = git_index_open(&index, git_buf_cstr(&index_file_buf));
916
+ error = git_index_open(&index, git_str_cstr(&index_file_buf));
776
917
  if (error < 0)
777
918
  goto error;
778
919
  }
@@ -789,7 +930,7 @@ static int _git_repository_open_ext_from_env(
789
930
  else if (error < 0)
790
931
  goto error;
791
932
  else {
792
- error = git_odb_open(&odb, git_buf_cstr(&object_dir_buf));
933
+ error = git_odb__open(&odb, git_str_cstr(&object_dir_buf), NULL);
793
934
  if (error < 0)
794
935
  goto error;
795
936
  }
@@ -838,7 +979,7 @@ static int _git_repository_open_ext_from_env(
838
979
  goto error;
839
980
  }
840
981
 
841
- end = git_buf_cstr(&alts_buf) + git_buf_len(&alts_buf);
982
+ end = git_str_cstr(&alts_buf) + git_str_len(&alts_buf);
842
983
  for (sep = alt = alts_buf.ptr; sep != end; alt = sep+1) {
843
984
  for (sep = alt; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++)
844
985
  ;
@@ -850,8 +991,8 @@ static int _git_repository_open_ext_from_env(
850
991
  }
851
992
  }
852
993
 
853
- if (git_buf_len(&namespace_buf)) {
854
- 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));
855
996
  if (error < 0)
856
997
  goto error;
857
998
  }
@@ -867,21 +1008,21 @@ error:
867
1008
  success:
868
1009
  git_odb_free(odb);
869
1010
  git_index_free(index);
870
- git_buf_dispose(&common_dir_buf);
871
- git_buf_dispose(&work_tree_buf);
872
- git_buf_dispose(&alts_buf);
873
- git_buf_dispose(&object_dir_buf);
874
- git_buf_dispose(&namespace_buf);
875
- git_buf_dispose(&index_file_buf);
876
- git_buf_dispose(&across_fs_buf);
877
- git_buf_dispose(&ceiling_dirs_buf);
878
- 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);
879
1020
  return error;
880
1021
  }
881
1022
 
882
1023
  static int repo_is_worktree(unsigned *out, const git_repository *repo)
883
1024
  {
884
- git_buf gitdir_link = GIT_BUF_INIT;
1025
+ git_str gitdir_link = GIT_STR_INIT;
885
1026
  int error;
886
1027
 
887
1028
  /* Worktrees cannot have the same commondir and gitdir */
@@ -891,14 +1032,14 @@ static int repo_is_worktree(unsigned *out, const git_repository *repo)
891
1032
  return 0;
892
1033
  }
893
1034
 
894
- if ((error = git_buf_joinpath(&gitdir_link, repo->gitdir, "gitdir")) < 0)
1035
+ if ((error = git_str_joinpath(&gitdir_link, repo->gitdir, "gitdir")) < 0)
895
1036
  return -1;
896
1037
 
897
1038
  /* A 'gitdir' file inside a git directory is currently
898
1039
  * only used when the repository is a working tree. */
899
- *out = !!git_path_exists(gitdir_link.ptr);
1040
+ *out = !!git_fs_path_exists(gitdir_link.ptr);
900
1041
 
901
- git_buf_dispose(&gitdir_link);
1042
+ git_str_dispose(&gitdir_link);
902
1043
  return error;
903
1044
  }
904
1045
 
@@ -910,12 +1051,10 @@ int git_repository_open_ext(
910
1051
  {
911
1052
  int error;
912
1053
  unsigned is_worktree;
913
- git_buf gitdir = GIT_BUF_INIT, workdir = GIT_BUF_INIT,
914
- 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;
915
1056
  git_repository *repo = NULL;
916
1057
  git_config *config = NULL;
917
- const char *validation_path;
918
- int version = 0;
919
1058
 
920
1059
  if (flags & GIT_REPOSITORY_OPEN_FROM_ENV)
921
1060
  return _git_repository_open_ext_from_env(repo_ptr, start_path);
@@ -932,15 +1071,15 @@ int git_repository_open_ext(
932
1071
  repo = repository_alloc();
933
1072
  GIT_ERROR_CHECK_ALLOC(repo);
934
1073
 
935
- repo->gitdir = git_buf_detach(&gitdir);
1074
+ repo->gitdir = git_str_detach(&gitdir);
936
1075
  GIT_ERROR_CHECK_ALLOC(repo->gitdir);
937
1076
 
938
1077
  if (gitlink.size) {
939
- repo->gitlink = git_buf_detach(&gitlink);
1078
+ repo->gitlink = git_str_detach(&gitlink);
940
1079
  GIT_ERROR_CHECK_ALLOC(repo->gitlink);
941
1080
  }
942
1081
  if (commondir.size) {
943
- repo->commondir = git_buf_detach(&commondir);
1082
+ repo->commondir = git_str_detach(&commondir);
944
1083
  GIT_ERROR_CHECK_ALLOC(repo->commondir);
945
1084
  }
946
1085
 
@@ -948,19 +1087,8 @@ int git_repository_open_ext(
948
1087
  goto cleanup;
949
1088
  repo->is_worktree = is_worktree;
950
1089
 
951
- /*
952
- * We'd like to have the config, but git doesn't particularly
953
- * care if it's not there, so we need to deal with that.
954
- */
955
-
956
- error = git_repository_config_snapshot(&config, repo);
957
- if (error < 0 && error != GIT_ENOTFOUND)
958
- goto cleanup;
959
-
960
- if (config && (error = check_repositoryformatversion(&version, config)) < 0)
961
- goto cleanup;
962
-
963
- if ((error = check_extensions(config, version)) < 0)
1090
+ error = obtain_config_and_set_oid_type(&config, repo);
1091
+ if (error < 0)
964
1092
  goto cleanup;
965
1093
 
966
1094
  if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0) {
@@ -973,19 +1101,18 @@ int git_repository_open_ext(
973
1101
  }
974
1102
 
975
1103
  /*
976
- * Ensure that the git directory is owned by the current user.
1104
+ * Ensure that the git directory and worktree are
1105
+ * owned by the current user.
977
1106
  */
978
- validation_path = repo->is_bare ? repo->gitdir : repo->workdir;
979
-
980
1107
  if (git_repository__validate_ownership &&
981
- (error = validate_ownership(validation_path)) < 0)
1108
+ (error = validate_ownership(repo)) < 0)
982
1109
  goto cleanup;
983
1110
 
984
1111
  cleanup:
985
- git_buf_dispose(&gitdir);
986
- git_buf_dispose(&workdir);
987
- git_buf_dispose(&gitlink);
988
- git_buf_dispose(&commondir);
1112
+ git_str_dispose(&gitdir);
1113
+ git_str_dispose(&workdir);
1114
+ git_str_dispose(&gitlink);
1115
+ git_str_dispose(&commondir);
989
1116
  git_config_free(config);
990
1117
 
991
1118
  if (error < 0)
@@ -1004,7 +1131,7 @@ int git_repository_open(git_repository **repo_out, const char *path)
1004
1131
 
1005
1132
  int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *wt)
1006
1133
  {
1007
- git_buf path = GIT_BUF_INIT;
1134
+ git_str path = GIT_STR_INIT;
1008
1135
  git_repository *repo = NULL;
1009
1136
  size_t len;
1010
1137
  int err;
@@ -1020,7 +1147,7 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
1020
1147
  goto out;
1021
1148
  }
1022
1149
 
1023
- 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)
1024
1151
  goto out;
1025
1152
 
1026
1153
  if ((err = git_repository_open(&repo, path.ptr)) < 0)
@@ -1029,7 +1156,7 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
1029
1156
  *repo_out = repo;
1030
1157
 
1031
1158
  out:
1032
- git_buf_dispose(&path);
1159
+ git_str_dispose(&path);
1033
1160
 
1034
1161
  return err;
1035
1162
  }
@@ -1054,14 +1181,10 @@ int git_repository_discover(
1054
1181
  const char *ceiling_dirs)
1055
1182
  {
1056
1183
  uint32_t flags = across_fs ? GIT_REPOSITORY_OPEN_CROSS_FS : 0;
1057
- int error;
1058
1184
 
1059
1185
  GIT_ASSERT_ARG(start_path);
1060
1186
 
1061
- if ((error = git_buf_sanitize(out)) < 0)
1062
- return error;
1063
-
1064
- 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);
1065
1188
  }
1066
1189
 
1067
1190
  static int load_config(
@@ -1073,7 +1196,7 @@ static int load_config(
1073
1196
  const char *programdata_path)
1074
1197
  {
1075
1198
  int error;
1076
- git_buf config_path = GIT_BUF_INIT;
1199
+ git_str config_path = GIT_STR_INIT;
1077
1200
  git_config *cfg = NULL;
1078
1201
 
1079
1202
  GIT_ASSERT_ARG(out);
@@ -1082,13 +1205,13 @@ static int load_config(
1082
1205
  return error;
1083
1206
 
1084
1207
  if (repo) {
1085
- 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)
1086
1209
  error = git_config_add_file_ondisk(cfg, config_path.ptr, GIT_CONFIG_LEVEL_LOCAL, repo, 0);
1087
1210
 
1088
1211
  if (error && error != GIT_ENOTFOUND)
1089
1212
  goto on_error;
1090
1213
 
1091
- git_buf_dispose(&config_path);
1214
+ git_str_dispose(&config_path);
1092
1215
  }
1093
1216
 
1094
1217
  if (global_config_path != NULL &&
@@ -1121,15 +1244,15 @@ static int load_config(
1121
1244
  return 0;
1122
1245
 
1123
1246
  on_error:
1124
- git_buf_dispose(&config_path);
1247
+ git_str_dispose(&config_path);
1125
1248
  git_config_free(cfg);
1126
1249
  *out = NULL;
1127
1250
  return error;
1128
1251
  }
1129
1252
 
1130
- static const char *path_unless_empty(git_buf *buf)
1253
+ static const char *path_unless_empty(git_str *buf)
1131
1254
  {
1132
- return git_buf_len(buf) > 0 ? git_buf_cstr(buf) : NULL;
1255
+ return git_str_len(buf) > 0 ? git_str_cstr(buf) : NULL;
1133
1256
  }
1134
1257
 
1135
1258
  int git_repository_config__weakptr(git_config **out, git_repository *repo)
@@ -1137,19 +1260,19 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
1137
1260
  int error = 0;
1138
1261
 
1139
1262
  if (repo->_config == NULL) {
1140
- git_buf global_buf = GIT_BUF_INIT;
1141
- git_buf xdg_buf = GIT_BUF_INIT;
1142
- git_buf system_buf = GIT_BUF_INIT;
1143
- 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;
1144
1267
  git_config *config;
1145
1268
 
1146
- git_config_find_global(&global_buf);
1147
- git_config_find_xdg(&xdg_buf);
1148
- git_config_find_system(&system_buf);
1149
- 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);
1150
1273
 
1151
1274
  /* If there is no global file, open a backend for it anyway */
1152
- if (git_buf_len(&global_buf) == 0)
1275
+ if (git_str_len(&global_buf) == 0)
1153
1276
  git_config__global_location(&global_buf);
1154
1277
 
1155
1278
  error = load_config(
@@ -1167,10 +1290,10 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
1167
1290
  }
1168
1291
  }
1169
1292
 
1170
- git_buf_dispose(&global_buf);
1171
- git_buf_dispose(&xdg_buf);
1172
- git_buf_dispose(&system_buf);
1173
- 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);
1174
1297
  }
1175
1298
 
1176
1299
  *out = repo->_config;
@@ -1215,12 +1338,15 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
1215
1338
 
1216
1339
  *out = git_atomic_load(repo->_odb);
1217
1340
  if (*out == NULL) {
1218
- 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;
1219
1343
  git_odb *odb;
1220
1344
 
1221
- 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,
1222
1348
  GIT_REPOSITORY_ITEM_OBJECTS)) < 0 ||
1223
- (error = git_odb_new(&odb)) < 0)
1349
+ (error = git_odb__new(&odb, &odb_opts)) < 0)
1224
1350
  return error;
1225
1351
 
1226
1352
  GIT_REFCOUNT_OWN(odb, repo);
@@ -1236,7 +1362,7 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
1236
1362
  git_odb_free(odb);
1237
1363
  }
1238
1364
 
1239
- git_buf_dispose(&odb_path);
1365
+ git_str_dispose(&odb_path);
1240
1366
  *out = git_atomic_load(repo->_odb);
1241
1367
  }
1242
1368
 
@@ -1312,10 +1438,10 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
1312
1438
  GIT_ASSERT_ARG(repo);
1313
1439
 
1314
1440
  if (repo->_index == NULL) {
1315
- git_buf index_path = GIT_BUF_INIT;
1441
+ git_str index_path = GIT_STR_INIT;
1316
1442
  git_index *index;
1317
1443
 
1318
- 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)
1319
1445
  return error;
1320
1446
 
1321
1447
  error = git_index_open(&index, index_path.ptr);
@@ -1331,7 +1457,7 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
1331
1457
  GIT_INDEX_CAPABILITY_FROM_OWNER);
1332
1458
  }
1333
1459
 
1334
- git_buf_dispose(&index_path);
1460
+ git_str_dispose(&index_path);
1335
1461
  }
1336
1462
 
1337
1463
  *out = repo->_index;
@@ -1379,7 +1505,7 @@ static int reserved_names_add8dot3(git_repository *repo, const char *path)
1379
1505
  const char *def_dot_git = DOT_GIT;
1380
1506
  size_t name_len, def_len = CONST_STRLEN(GIT_DIR_SHORTNAME);
1381
1507
  size_t def_dot_git_len = CONST_STRLEN(DOT_GIT);
1382
- git_buf *buf;
1508
+ git_str *buf;
1383
1509
 
1384
1510
  if (!name)
1385
1511
  return 0;
@@ -1395,17 +1521,17 @@ static int reserved_names_add8dot3(git_repository *repo, const char *path)
1395
1521
  if ((buf = git_array_alloc(repo->reserved_names)) == NULL)
1396
1522
  return -1;
1397
1523
 
1398
- git_buf_attach(buf, name, name_len);
1524
+ git_str_attach(buf, name, name_len);
1399
1525
  return true;
1400
1526
  }
1401
1527
 
1402
1528
  bool git_repository__reserved_names(
1403
- 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)
1404
1530
  {
1405
1531
  GIT_UNUSED(include_ntfs);
1406
1532
 
1407
1533
  if (repo->reserved_names.size == 0) {
1408
- git_buf *buf;
1534
+ git_str *buf;
1409
1535
  size_t i;
1410
1536
 
1411
1537
  /* Add the static defaults */
@@ -1457,7 +1583,7 @@ on_error:
1457
1583
  }
1458
1584
  #else
1459
1585
  bool git_repository__reserved_names(
1460
- 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)
1461
1587
  {
1462
1588
  GIT_UNUSED(repo);
1463
1589
 
@@ -1478,6 +1604,7 @@ static int check_repositoryformatversion(int *version, git_config *config)
1478
1604
  int error;
1479
1605
 
1480
1606
  error = git_config_get_int32(version, config, "core.repositoryformatversion");
1607
+
1481
1608
  /* git ignores this if the config variable isn't there */
1482
1609
  if (error == GIT_ENOTFOUND)
1483
1610
  return 0;
@@ -1485,10 +1612,15 @@ static int check_repositoryformatversion(int *version, git_config *config)
1485
1612
  if (error < 0)
1486
1613
  return -1;
1487
1614
 
1488
- 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) {
1489
1621
  git_error_set(GIT_ERROR_REPOSITORY,
1490
1622
  "unsupported repository version %d; only versions up to %d are supported",
1491
- *version, GIT_REPO_MAX_VERSION);
1623
+ *version, GIT_REPO_VERSION_MAX);
1492
1624
  return -1;
1493
1625
  }
1494
1626
 
@@ -1496,14 +1628,15 @@ static int check_repositoryformatversion(int *version, git_config *config)
1496
1628
  }
1497
1629
 
1498
1630
  static const char *builtin_extensions[] = {
1499
- "noop"
1631
+ "noop",
1632
+ "objectformat"
1500
1633
  };
1501
1634
 
1502
1635
  static git_vector user_extensions = GIT_VECTOR_INIT;
1503
1636
 
1504
1637
  static int check_valid_extension(const git_config_entry *entry, void *payload)
1505
1638
  {
1506
- git_buf cfg = GIT_BUF_INIT;
1639
+ git_str cfg = GIT_STR_INIT;
1507
1640
  bool reject;
1508
1641
  const char *extension;
1509
1642
  size_t i;
@@ -1512,7 +1645,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
1512
1645
  GIT_UNUSED(payload);
1513
1646
 
1514
1647
  git_vector_foreach (&user_extensions, i, extension) {
1515
- git_buf_clear(&cfg);
1648
+ git_str_clear(&cfg);
1516
1649
 
1517
1650
  /*
1518
1651
  * Users can specify that they don't want to support an
@@ -1521,7 +1654,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
1521
1654
  if ((reject = (extension[0] == '!')) == true)
1522
1655
  extension = &extension[1];
1523
1656
 
1524
- if ((error = git_buf_printf(&cfg, "extensions.%s", extension)) < 0)
1657
+ if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0)
1525
1658
  goto done;
1526
1659
 
1527
1660
  if (strcmp(entry->name, cfg.ptr) == 0) {
@@ -1533,9 +1666,10 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
1533
1666
  }
1534
1667
 
1535
1668
  for (i = 0; i < ARRAY_SIZE(builtin_extensions); i++) {
1669
+ git_str_clear(&cfg);
1536
1670
  extension = builtin_extensions[i];
1537
1671
 
1538
- if ((error = git_buf_printf(&cfg, "extensions.%s", extension)) < 0)
1672
+ if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0)
1539
1673
  goto done;
1540
1674
 
1541
1675
  if (strcmp(entry->name, cfg.ptr) == 0)
@@ -1547,7 +1681,7 @@ fail:
1547
1681
  error = -1;
1548
1682
 
1549
1683
  done:
1550
- git_buf_dispose(&cfg);
1684
+ git_str_dispose(&cfg);
1551
1685
  return error;
1552
1686
  }
1553
1687
 
@@ -1559,6 +1693,79 @@ static int check_extensions(git_config *config, int version)
1559
1693
  return git_config_foreach_match(config, "^extensions\\.", check_valid_extension, NULL);
1560
1694
  }
1561
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
+
1562
1769
  int git_repository__extensions(char ***out, size_t *out_len)
1563
1770
  {
1564
1771
  git_vector extensions;
@@ -1625,12 +1832,12 @@ void git_repository__free_extensions(void)
1625
1832
 
1626
1833
  int git_repository_create_head(const char *git_dir, const char *ref_name)
1627
1834
  {
1628
- git_buf ref_path = GIT_BUF_INIT;
1835
+ git_str ref_path = GIT_STR_INIT;
1629
1836
  git_filebuf ref = GIT_FILEBUF_INIT;
1630
1837
  const char *fmt;
1631
1838
  int error;
1632
1839
 
1633
- 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 ||
1634
1841
  (error = git_filebuf_open(&ref, ref_path.ptr, 0, GIT_REFS_FILE_MODE)) < 0)
1635
1842
  goto out;
1636
1843
 
@@ -1644,7 +1851,7 @@ int git_repository_create_head(const char *git_dir, const char *ref_name)
1644
1851
  goto out;
1645
1852
 
1646
1853
  out:
1647
- git_buf_dispose(&ref_path);
1854
+ git_str_dispose(&ref_path);
1648
1855
  git_filebuf_cleanup(&ref);
1649
1856
  return error;
1650
1857
  }
@@ -1667,13 +1874,13 @@ static bool is_chmod_supported(const char *file_path)
1667
1874
 
1668
1875
  static bool is_filesystem_case_insensitive(const char *gitdir_path)
1669
1876
  {
1670
- git_buf path = GIT_BUF_INIT;
1877
+ git_str path = GIT_STR_INIT;
1671
1878
  int is_insensitive = -1;
1672
1879
 
1673
- if (!git_buf_joinpath(&path, gitdir_path, "CoNfIg"))
1674
- 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));
1675
1882
 
1676
- git_buf_dispose(&path);
1883
+ git_str_dispose(&path);
1677
1884
  return is_insensitive;
1678
1885
  }
1679
1886
 
@@ -1683,16 +1890,16 @@ static bool is_filesystem_case_insensitive(const char *gitdir_path)
1683
1890
  */
1684
1891
  static int load_global_config(git_config **config)
1685
1892
  {
1686
- git_buf global_buf = GIT_BUF_INIT;
1687
- git_buf xdg_buf = GIT_BUF_INIT;
1688
- git_buf system_buf = GIT_BUF_INIT;
1689
- git_buf programdata_buf = GIT_BUF_INIT;
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;
1690
1897
  int error;
1691
1898
 
1692
- git_config_find_global(&global_buf);
1693
- git_config_find_xdg(&xdg_buf);
1694
- git_config_find_system(&system_buf);
1695
- git_config_find_programdata(&programdata_buf);
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);
1696
1903
 
1697
1904
  error = load_config(config, NULL,
1698
1905
  path_unless_empty(&global_buf),
@@ -1700,10 +1907,10 @@ static int load_global_config(git_config **config)
1700
1907
  path_unless_empty(&system_buf),
1701
1908
  path_unless_empty(&programdata_buf));
1702
1909
 
1703
- git_buf_dispose(&global_buf);
1704
- git_buf_dispose(&xdg_buf);
1705
- git_buf_dispose(&system_buf);
1706
- git_buf_dispose(&programdata_buf);
1910
+ git_str_dispose(&global_buf);
1911
+ git_str_dispose(&xdg_buf);
1912
+ git_str_dispose(&system_buf);
1913
+ git_str_dispose(&programdata_buf);
1707
1914
 
1708
1915
  return error;
1709
1916
  }
@@ -1727,7 +1934,7 @@ static bool are_symlinks_supported(const char *wd_path)
1727
1934
  goto done;
1728
1935
  #endif
1729
1936
 
1730
- if (!(symlinks = git_path_supports_symlinks(wd_path)))
1937
+ if (!(symlinks = git_fs_path_supports_symlinks(wd_path)))
1731
1938
  goto done;
1732
1939
 
1733
1940
  done:
@@ -1754,7 +1961,7 @@ static int create_empty_file(const char *path, mode_t mode)
1754
1961
 
1755
1962
  static int repo_local_config(
1756
1963
  git_config **out,
1757
- git_buf *config_dir,
1964
+ git_str *config_dir,
1758
1965
  git_repository *repo,
1759
1966
  const char *repo_dir)
1760
1967
  {
@@ -1762,12 +1969,12 @@ static int repo_local_config(
1762
1969
  git_config *parent;
1763
1970
  const char *cfg_path;
1764
1971
 
1765
- 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)
1766
1973
  return -1;
1767
- cfg_path = git_buf_cstr(config_dir);
1974
+ cfg_path = git_str_cstr(config_dir);
1768
1975
 
1769
1976
  /* make LOCAL config if missing */
1770
- if (!git_path_isfile(cfg_path) &&
1977
+ if (!git_fs_path_isfile(cfg_path) &&
1771
1978
  (error = create_empty_file(cfg_path, GIT_CONFIG_FILE_MODE)) < 0)
1772
1979
  return error;
1773
1980
 
@@ -1825,7 +2032,7 @@ static int repo_init_fs_configs(
1825
2032
  #ifdef GIT_USE_ICONV
1826
2033
  if ((error = git_config_set_bool(
1827
2034
  cfg, "core.precomposeunicode",
1828
- git_path_does_fs_decompose_unicode(work_dir))) < 0)
2035
+ git_fs_path_does_decompose_unicode(work_dir))) < 0)
1829
2036
  return error;
1830
2037
  /* on non-iconv platforms, don't even set core.precomposeunicode */
1831
2038
  #endif
@@ -1837,19 +2044,21 @@ static int repo_init_config(
1837
2044
  const char *repo_dir,
1838
2045
  const char *work_dir,
1839
2046
  uint32_t flags,
1840
- uint32_t mode)
2047
+ uint32_t mode,
2048
+ git_oid_t oid_type)
1841
2049
  {
1842
2050
  int error = 0;
1843
- 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;
1844
2052
  git_config *config = NULL;
1845
2053
  bool is_bare = ((flags & GIT_REPOSITORY_INIT_BARE) != 0);
1846
2054
  bool is_reinit = ((flags & GIT_REPOSITORY_INIT__IS_REINIT) != 0);
1847
- int version = 0;
2055
+ int version = GIT_REPO_VERSION_DEFAULT;
1848
2056
 
1849
2057
  if ((error = repo_local_config(&config, &cfg_path, NULL, repo_dir)) < 0)
1850
2058
  goto cleanup;
1851
2059
 
1852
- if (is_reinit && (error = check_repositoryformatversion(&version, config)) < 0)
2060
+ if (is_reinit &&
2061
+ (error = check_repositoryformatversion(&version, config)) < 0)
1853
2062
  goto cleanup;
1854
2063
 
1855
2064
  if ((error = check_extensions(config, version)) < 0)
@@ -1860,7 +2069,7 @@ static int repo_init_config(
1860
2069
  goto cleanup; } while (0)
1861
2070
 
1862
2071
  SET_REPO_CONFIG(bool, "core.bare", is_bare);
1863
- SET_REPO_CONFIG(int32, "core.repositoryformatversion", GIT_REPO_VERSION);
2072
+ SET_REPO_CONFIG(int32, "core.repositoryformatversion", version);
1864
2073
 
1865
2074
  if ((error = repo_init_fs_configs(
1866
2075
  config, cfg_path.ptr, repo_dir, work_dir, !is_reinit)) < 0)
@@ -1870,11 +2079,11 @@ static int repo_init_config(
1870
2079
  SET_REPO_CONFIG(bool, "core.logallrefupdates", true);
1871
2080
 
1872
2081
  if (!(flags & GIT_REPOSITORY_INIT__NATURAL_WD)) {
1873
- if ((error = git_buf_sets(&worktree_path, work_dir)) < 0)
2082
+ if ((error = git_str_sets(&worktree_path, work_dir)) < 0)
1874
2083
  goto cleanup;
1875
2084
 
1876
2085
  if ((flags & GIT_REPOSITORY_INIT_RELATIVE_GITLINK))
1877
- if ((error = git_path_make_relative(&worktree_path, repo_dir)) < 0)
2086
+ if ((error = git_fs_path_make_relative(&worktree_path, repo_dir)) < 0)
1878
2087
  goto cleanup;
1879
2088
 
1880
2089
  SET_REPO_CONFIG(string, "core.worktree", worktree_path.ptr);
@@ -1893,9 +2102,14 @@ static int repo_init_config(
1893
2102
  SET_REPO_CONFIG(bool, "receive.denyNonFastforwards", true);
1894
2103
  }
1895
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
+
1896
2110
  cleanup:
1897
- git_buf_dispose(&cfg_path);
1898
- git_buf_dispose(&worktree_path);
2111
+ git_str_dispose(&cfg_path);
2112
+ git_str_dispose(&worktree_path);
1899
2113
  git_config_free(config);
1900
2114
 
1901
2115
  return error;
@@ -1917,7 +2131,7 @@ static int repo_reinit_submodule_fs(git_submodule *sm, const char *n, void *p)
1917
2131
  int git_repository_reinit_filesystem(git_repository *repo, int recurse)
1918
2132
  {
1919
2133
  int error = 0;
1920
- git_buf path = GIT_BUF_INIT;
2134
+ git_str path = GIT_STR_INIT;
1921
2135
  git_config *config = NULL;
1922
2136
  const char *repo_dir = git_repository_path(repo);
1923
2137
 
@@ -1926,7 +2140,7 @@ int git_repository_reinit_filesystem(git_repository *repo, int recurse)
1926
2140
  config, path.ptr, repo_dir, git_repository_workdir(repo), true);
1927
2141
 
1928
2142
  git_config_free(config);
1929
- git_buf_dispose(&path);
2143
+ git_str_dispose(&path);
1930
2144
 
1931
2145
  git_repository__configmap_lookup_cache_clear(repo);
1932
2146
 
@@ -1944,10 +2158,10 @@ static int repo_write_template(
1944
2158
  bool hidden,
1945
2159
  const char *content)
1946
2160
  {
1947
- git_buf path = GIT_BUF_INIT;
2161
+ git_str path = GIT_STR_INIT;
1948
2162
  int fd, error = 0, flags;
1949
2163
 
1950
- if (git_buf_joinpath(&path, git_dir, file) < 0)
2164
+ if (git_str_joinpath(&path, git_dir, file) < 0)
1951
2165
  return -1;
1952
2166
 
1953
2167
  if (allow_overwrite)
@@ -1955,7 +2169,7 @@ static int repo_write_template(
1955
2169
  else
1956
2170
  flags = O_WRONLY | O_CREAT | O_EXCL;
1957
2171
 
1958
- fd = p_open(git_buf_cstr(&path), flags, mode);
2172
+ fd = p_open(git_str_cstr(&path), flags, mode);
1959
2173
 
1960
2174
  if (fd >= 0) {
1961
2175
  error = p_write(fd, content, strlen(content));
@@ -1974,7 +2188,7 @@ static int repo_write_template(
1974
2188
  GIT_UNUSED(hidden);
1975
2189
  #endif
1976
2190
 
1977
- git_buf_dispose(&path);
2191
+ git_str_dispose(&path);
1978
2192
 
1979
2193
  if (error)
1980
2194
  git_error_set(GIT_ERROR_OS,
@@ -1987,13 +2201,13 @@ static int repo_write_gitlink(
1987
2201
  const char *in_dir, const char *to_repo, bool use_relative_path)
1988
2202
  {
1989
2203
  int error;
1990
- git_buf buf = GIT_BUF_INIT;
1991
- git_buf path_to_repo = GIT_BUF_INIT;
2204
+ git_str buf = GIT_STR_INIT;
2205
+ git_str path_to_repo = GIT_STR_INIT;
1992
2206
  struct stat st;
1993
2207
 
1994
- git_path_dirname_r(&buf, to_repo);
1995
- git_path_to_dir(&buf);
1996
- 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))
1997
2211
  return -1;
1998
2212
 
1999
2213
  /* don't write gitlink to natural workdir */
@@ -2004,7 +2218,7 @@ static int repo_write_gitlink(
2004
2218
  goto cleanup;
2005
2219
  }
2006
2220
 
2007
- if ((error = git_buf_joinpath(&buf, in_dir, DOT_GIT)) < 0)
2221
+ if ((error = git_str_joinpath(&buf, in_dir, DOT_GIT)) < 0)
2008
2222
  goto cleanup;
2009
2223
 
2010
2224
  if (!p_stat(buf.ptr, &st) && !S_ISREG(st.st_mode)) {
@@ -2014,22 +2228,22 @@ static int repo_write_gitlink(
2014
2228
  goto cleanup;
2015
2229
  }
2016
2230
 
2017
- git_buf_clear(&buf);
2231
+ git_str_clear(&buf);
2018
2232
 
2019
- error = git_buf_sets(&path_to_repo, to_repo);
2233
+ error = git_str_sets(&path_to_repo, to_repo);
2020
2234
 
2021
2235
  if (!error && use_relative_path)
2022
- error = git_path_make_relative(&path_to_repo, in_dir);
2236
+ error = git_fs_path_make_relative(&path_to_repo, in_dir);
2023
2237
 
2024
2238
  if (!error)
2025
- 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);
2026
2240
 
2027
2241
  if (!error)
2028
2242
  error = repo_write_template(in_dir, true, DOT_GIT, 0666, true, buf.ptr);
2029
2243
 
2030
2244
  cleanup:
2031
- git_buf_dispose(&buf);
2032
- git_buf_dispose(&path_to_repo);
2245
+ git_str_dispose(&buf);
2246
+ git_str_dispose(&path_to_repo);
2033
2247
  return error;
2034
2248
  }
2035
2249
 
@@ -2082,12 +2296,12 @@ static int repo_init_structure(
2082
2296
  git_config *cfg = NULL;
2083
2297
  const char *tdir = NULL;
2084
2298
  bool default_template = false;
2085
- git_buf template_buf = GIT_BUF_INIT;
2299
+ git_str template_buf = GIT_STR_INIT;
2086
2300
 
2087
2301
  if (opts->template_path)
2088
2302
  tdir = opts->template_path;
2089
2303
  else if ((error = git_config_open_default(&cfg)) >= 0) {
2090
- if (!git_config_get_path(&template_buf, cfg, "init.templatedir"))
2304
+ if (!git_config__get_path(&template_buf, cfg, "init.templatedir"))
2091
2305
  tdir = template_buf.ptr;
2092
2306
  git_error_clear();
2093
2307
  }
@@ -2113,11 +2327,16 @@ static int repo_init_structure(
2113
2327
  error = git_futils_cp_r(tdir, repo_dir, cpflags, dmode);
2114
2328
  }
2115
2329
 
2116
- git_buf_dispose(&template_buf);
2330
+ git_str_dispose(&template_buf);
2117
2331
  git_config_free(cfg);
2118
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
+ */
2119
2338
  if (error < 0) {
2120
- if (!default_template)
2339
+ if (!default_template && error != GIT_ENOTFOUND)
2121
2340
  return error;
2122
2341
 
2123
2342
  /* if template was default, ignore error and use internal */
@@ -2154,7 +2373,7 @@ static int repo_init_structure(
2154
2373
  return error;
2155
2374
  }
2156
2375
 
2157
- 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)
2158
2377
  {
2159
2378
  /* When making parent directories during repository initialization
2160
2379
  * don't try to set gid or grant world write access
@@ -2166,8 +2385,8 @@ static int mkdir_parent(git_buf *buf, uint32_t mode, bool skip2)
2166
2385
  }
2167
2386
 
2168
2387
  static int repo_init_directories(
2169
- git_buf *repo_path,
2170
- git_buf *wd_path,
2388
+ git_str *repo_path,
2389
+ git_str *wd_path,
2171
2390
  const char *given_repo,
2172
2391
  git_repository_init_options *opts)
2173
2392
  {
@@ -2205,7 +2424,7 @@ static int repo_init_directories(
2205
2424
  git__suffixcmp(given_repo, "/" DOT_GIT) != 0 &&
2206
2425
  git__suffixcmp(given_repo, "/" GIT_DIR) != 0;
2207
2426
 
2208
- 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)
2209
2428
  return -1;
2210
2429
 
2211
2430
  has_dotgit = (git__suffixcmp(repo_path->ptr, "/" GIT_DIR) == 0);
@@ -2216,11 +2435,11 @@ static int repo_init_directories(
2216
2435
 
2217
2436
  if (!is_bare) {
2218
2437
  if (opts->workdir_path) {
2219
- if (git_path_join_unrooted(
2438
+ if (git_fs_path_join_unrooted(
2220
2439
  wd_path, opts->workdir_path, repo_path->ptr, NULL) < 0)
2221
2440
  return -1;
2222
2441
  } else if (has_dotgit) {
2223
- if (git_path_dirname_r(wd_path, repo_path->ptr) < 0)
2442
+ if (git_fs_path_dirname_r(wd_path, repo_path->ptr) < 0)
2224
2443
  return -1;
2225
2444
  } else {
2226
2445
  git_error_set(GIT_ERROR_REPOSITORY, "cannot pick working directory"
@@ -2228,10 +2447,10 @@ static int repo_init_directories(
2228
2447
  return -1;
2229
2448
  }
2230
2449
 
2231
- if (git_path_to_dir(wd_path) < 0)
2450
+ if (git_fs_path_to_dir(wd_path) < 0)
2232
2451
  return -1;
2233
2452
  } else {
2234
- git_buf_clear(wd_path);
2453
+ git_str_clear(wd_path);
2235
2454
  }
2236
2455
 
2237
2456
  natural_wd =
@@ -2288,10 +2507,10 @@ static int repo_init_directories(
2288
2507
  /* prettify both directories now that they are created */
2289
2508
 
2290
2509
  if (!error) {
2291
- error = git_path_prettify_dir(repo_path, repo_path->ptr, NULL);
2510
+ error = git_fs_path_prettify_dir(repo_path, repo_path->ptr, NULL);
2292
2511
 
2293
2512
  if (!error && wd_path->size > 0)
2294
- error = git_path_prettify_dir(wd_path, wd_path->ptr, NULL);
2513
+ error = git_fs_path_prettify_dir(wd_path, wd_path->ptr, NULL);
2295
2514
  }
2296
2515
 
2297
2516
  return error;
@@ -2300,24 +2519,24 @@ static int repo_init_directories(
2300
2519
  static int repo_init_head(const char *repo_dir, const char *given)
2301
2520
  {
2302
2521
  git_config *cfg = NULL;
2303
- 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;
2304
2523
  const char *initial_head = NULL;
2305
2524
  int error;
2306
2525
 
2307
- 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)
2308
2527
  goto out;
2309
2528
 
2310
2529
  /*
2311
2530
  * A template may have set a HEAD; use that unless it's been
2312
2531
  * overridden by the caller's given initial head setting.
2313
2532
  */
2314
- if (git_path_exists(head_path.ptr) && !given)
2533
+ if (git_fs_path_exists(head_path.ptr) && !given)
2315
2534
  goto out;
2316
2535
 
2317
2536
  if (given) {
2318
2537
  initial_head = given;
2319
2538
  } else if ((error = git_config_open_default(&cfg)) >= 0 &&
2320
- (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 &&
2321
2540
  *cfg_branch.ptr) {
2322
2541
  initial_head = cfg_branch.ptr;
2323
2542
  }
@@ -2329,8 +2548,8 @@ static int repo_init_head(const char *repo_dir, const char *given)
2329
2548
 
2330
2549
  out:
2331
2550
  git_config_free(cfg);
2332
- git_buf_dispose(&head_path);
2333
- git_buf_dispose(&cfg_branch);
2551
+ git_str_dispose(&head_path);
2552
+ git_str_dispose(&cfg_branch);
2334
2553
 
2335
2554
  return error;
2336
2555
  }
@@ -2364,10 +2583,11 @@ int git_repository_init_ext(
2364
2583
  const char *given_repo,
2365
2584
  git_repository_init_options *opts)
2366
2585
  {
2367
- git_buf repo_path = GIT_BUF_INIT, wd_path = GIT_BUF_INIT,
2368
- common_path = GIT_BUF_INIT;
2586
+ git_str repo_path = GIT_STR_INIT, wd_path = GIT_STR_INIT,
2587
+ common_path = GIT_STR_INIT;
2369
2588
  const char *wd;
2370
2589
  bool is_valid;
2590
+ git_oid_t oid_type = GIT_OID_DEFAULT;
2371
2591
  int error;
2372
2592
 
2373
2593
  GIT_ASSERT_ARG(out);
@@ -2376,10 +2596,15 @@ int git_repository_init_ext(
2376
2596
 
2377
2597
  GIT_ERROR_CHECK_VERSION(opts, GIT_REPOSITORY_INIT_OPTIONS_VERSION, "git_repository_init_options");
2378
2598
 
2599
+ #ifdef GIT_EXPERIMENTAL_SHA256
2600
+ if (opts->oid_type)
2601
+ oid_type = opts->oid_type;
2602
+ #endif
2603
+
2379
2604
  if ((error = repo_init_directories(&repo_path, &wd_path, given_repo, opts)) < 0)
2380
2605
  goto out;
2381
2606
 
2382
- 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);
2383
2608
 
2384
2609
  if ((error = is_valid_repository_path(&is_valid, &repo_path, &common_path)) < 0)
2385
2610
  goto out;
@@ -2394,13 +2619,13 @@ int git_repository_init_ext(
2394
2619
 
2395
2620
  opts->flags |= GIT_REPOSITORY_INIT__IS_REINIT;
2396
2621
 
2397
- 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)
2398
2623
  goto out;
2399
2624
 
2400
2625
  /* TODO: reinitialize the templates */
2401
2626
  } else {
2402
2627
  if ((error = repo_init_structure(repo_path.ptr, wd, opts)) < 0 ||
2403
- (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 ||
2404
2629
  (error = repo_init_head(repo_path.ptr, opts->initial_head)) < 0)
2405
2630
  goto out;
2406
2631
  }
@@ -2413,9 +2638,9 @@ int git_repository_init_ext(
2413
2638
  goto out;
2414
2639
 
2415
2640
  out:
2416
- git_buf_dispose(&common_path);
2417
- git_buf_dispose(&repo_path);
2418
- git_buf_dispose(&wd_path);
2641
+ git_str_dispose(&common_path);
2642
+ git_str_dispose(&repo_path);
2643
+ git_str_dispose(&wd_path);
2419
2644
 
2420
2645
  return error;
2421
2646
  }
@@ -2603,7 +2828,7 @@ static int repo_contains_no_reference(git_repository *repo)
2603
2828
  return error;
2604
2829
  }
2605
2830
 
2606
- int git_repository_initialbranch(git_buf *out, git_repository *repo)
2831
+ int git_repository_initialbranch(git_str *out, git_repository *repo)
2607
2832
  {
2608
2833
  git_config *config;
2609
2834
  git_config_entry *entry = NULL;
@@ -2624,8 +2849,8 @@ int git_repository_initialbranch(git_buf *out, git_repository *repo)
2624
2849
  goto done;
2625
2850
  }
2626
2851
 
2627
- if ((error = git_buf_puts(out, GIT_REFS_HEADS_DIR)) < 0 ||
2628
- (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 ||
2629
2854
  (error = git_reference_name_is_valid(&valid, out->ptr)) < 0)
2630
2855
  goto done;
2631
2856
 
@@ -2642,7 +2867,7 @@ done:
2642
2867
  int git_repository_is_empty(git_repository *repo)
2643
2868
  {
2644
2869
  git_reference *head = NULL;
2645
- git_buf initialbranch = GIT_BUF_INIT;
2870
+ git_str initialbranch = GIT_STR_INIT;
2646
2871
  int result = 0;
2647
2872
 
2648
2873
  if ((result = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0 ||
@@ -2655,7 +2880,7 @@ int git_repository_is_empty(git_repository *repo)
2655
2880
 
2656
2881
  done:
2657
2882
  git_reference_free(head);
2658
- git_buf_dispose(&initialbranch);
2883
+ git_str_dispose(&initialbranch);
2659
2884
 
2660
2885
  return result;
2661
2886
  }
@@ -2684,7 +2909,18 @@ static const char *resolved_parent_path(const git_repository *repo, git_reposito
2684
2909
  return parent;
2685
2910
  }
2686
2911
 
2687
- 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)
2688
2924
  {
2689
2925
  const char *parent = resolved_parent_path(repo, items[item].parent, items[item].fallback);
2690
2926
  if (parent == NULL) {
@@ -2692,16 +2928,16 @@ int git_repository_item_path(git_buf *out, const git_repository *repo, git_repos
2692
2928
  return GIT_ENOTFOUND;
2693
2929
  }
2694
2930
 
2695
- if (git_buf_sets(out, parent) < 0)
2931
+ if (git_str_sets(out, parent) < 0)
2696
2932
  return -1;
2697
2933
 
2698
2934
  if (items[item].name) {
2699
- if (git_buf_joinpath(out, parent, items[item].name) < 0)
2935
+ if (git_str_joinpath(out, parent, items[item].name) < 0)
2700
2936
  return -1;
2701
2937
  }
2702
2938
 
2703
2939
  if (items[item].directory) {
2704
- if (git_path_to_dir(out) < 0)
2940
+ if (git_fs_path_to_dir(out) < 0)
2705
2941
  return -1;
2706
2942
  }
2707
2943
 
@@ -2725,7 +2961,7 @@ const char *git_repository_workdir(const git_repository *repo)
2725
2961
  }
2726
2962
 
2727
2963
  int git_repository_workdir_path(
2728
- git_buf *out, git_repository *repo, const char *path)
2964
+ git_str *out, git_repository *repo, const char *path)
2729
2965
  {
2730
2966
  int error;
2731
2967
 
@@ -2734,8 +2970,8 @@ int git_repository_workdir_path(
2734
2970
  return GIT_EBAREREPO;
2735
2971
  }
2736
2972
 
2737
- if (!(error = git_buf_joinpath(out, repo->workdir, path)))
2738
- 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);
2739
2975
 
2740
2976
  return error;
2741
2977
  }
@@ -2750,12 +2986,12 @@ int git_repository_set_workdir(
2750
2986
  git_repository *repo, const char *workdir, int update_gitlink)
2751
2987
  {
2752
2988
  int error = 0;
2753
- git_buf path = GIT_BUF_INIT;
2989
+ git_str path = GIT_STR_INIT;
2754
2990
 
2755
2991
  GIT_ASSERT_ARG(repo);
2756
2992
  GIT_ASSERT_ARG(workdir);
2757
2993
 
2758
- if (git_path_prettify_dir(&path, workdir, NULL) < 0)
2994
+ if (git_fs_path_prettify_dir(&path, workdir, NULL) < 0)
2759
2995
  return -1;
2760
2996
 
2761
2997
  if (repo->workdir && strcmp(repo->workdir, path.ptr) == 0)
@@ -2782,7 +3018,7 @@ int git_repository_set_workdir(
2782
3018
  if (!error) {
2783
3019
  char *old_workdir = repo->workdir;
2784
3020
 
2785
- repo->workdir = git_buf_detach(&path);
3021
+ repo->workdir = git_str_detach(&path);
2786
3022
  repo->is_bare = 0;
2787
3023
 
2788
3024
  git__free(old_workdir);
@@ -2851,60 +3087,62 @@ cleanup:
2851
3087
  int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head)
2852
3088
  {
2853
3089
  git_filebuf file = GIT_FILEBUF_INIT;
2854
- git_buf file_path = GIT_BUF_INIT;
2855
- char orig_head_str[GIT_OID_HEXSZ];
3090
+ git_str file_path = GIT_STR_INIT;
3091
+ char orig_head_str[GIT_OID_MAX_HEXSIZE];
2856
3092
  int error = 0;
2857
3093
 
2858
3094
  git_oid_fmt(orig_head_str, orig_head);
2859
3095
 
2860
- 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 &&
2861
3097
  (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) == 0 &&
2862
- (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)
2863
3099
  error = git_filebuf_commit(&file);
2864
3100
 
2865
3101
  if (error < 0)
2866
3102
  git_filebuf_cleanup(&file);
2867
3103
 
2868
- git_buf_dispose(&file_path);
3104
+ git_str_dispose(&file_path);
2869
3105
 
2870
3106
  return error;
2871
3107
  }
2872
3108
 
2873
- int git_repository_message(git_buf *out, git_repository *repo)
3109
+ static int git_repository__message(git_str *out, git_repository *repo)
2874
3110
  {
2875
- git_buf path = GIT_BUF_INIT;
3111
+ git_str path = GIT_STR_INIT;
2876
3112
  struct stat st;
2877
3113
  int error;
2878
3114
 
2879
- if ((error = git_buf_sanitize(out)) < 0)
2880
- return error;
2881
-
2882
- 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)
2883
3116
  return -1;
2884
3117
 
2885
- if ((error = p_stat(git_buf_cstr(&path), &st)) < 0) {
3118
+ if ((error = p_stat(git_str_cstr(&path), &st)) < 0) {
2886
3119
  if (errno == ENOENT)
2887
3120
  error = GIT_ENOTFOUND;
2888
3121
  git_error_set(GIT_ERROR_OS, "could not access message file");
2889
3122
  } else {
2890
- error = git_futils_readbuffer(out, git_buf_cstr(&path));
3123
+ error = git_futils_readbuffer(out, git_str_cstr(&path));
2891
3124
  }
2892
3125
 
2893
- git_buf_dispose(&path);
3126
+ git_str_dispose(&path);
2894
3127
 
2895
3128
  return error;
2896
3129
  }
2897
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
+
2898
3136
  int git_repository_message_remove(git_repository *repo)
2899
3137
  {
2900
- git_buf path = GIT_BUF_INIT;
3138
+ git_str path = GIT_STR_INIT;
2901
3139
  int error;
2902
3140
 
2903
- 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)
2904
3142
  return -1;
2905
3143
 
2906
- error = p_unlink(git_buf_cstr(&path));
2907
- git_buf_dispose(&path);
3144
+ error = p_unlink(git_str_cstr(&path));
3145
+ git_str_dispose(&path);
2908
3146
 
2909
3147
  return error;
2910
3148
  }
@@ -2920,7 +3158,7 @@ int git_repository_hashfile(
2920
3158
  git_filter_list *fl = NULL;
2921
3159
  git_file fd = -1;
2922
3160
  uint64_t len;
2923
- git_buf full_path = GIT_BUF_INIT;
3161
+ git_str full_path = GIT_STR_INIT;
2924
3162
  const char *workdir = git_repository_workdir(repo);
2925
3163
 
2926
3164
  /* as_path can be NULL */
@@ -2928,8 +3166,8 @@ int git_repository_hashfile(
2928
3166
  GIT_ASSERT_ARG(path);
2929
3167
  GIT_ASSERT_ARG(repo);
2930
3168
 
2931
- if ((error = git_path_join_unrooted(&full_path, path, workdir, NULL)) < 0 ||
2932
- (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)
2933
3171
  return error;
2934
3172
 
2935
3173
  /*
@@ -2970,36 +3208,36 @@ int git_repository_hashfile(
2970
3208
  goto cleanup;
2971
3209
  }
2972
3210
 
2973
- 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);
2974
3212
 
2975
3213
  cleanup:
2976
3214
  if (fd >= 0)
2977
3215
  p_close(fd);
2978
3216
  git_filter_list_free(fl);
2979
- git_buf_dispose(&full_path);
3217
+ git_str_dispose(&full_path);
2980
3218
 
2981
3219
  return error;
2982
3220
  }
2983
3221
 
2984
- 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)
2985
3223
  {
2986
- git_buf_puts(out, "checkout: moving from ");
3224
+ git_str_puts(out, "checkout: moving from ");
2987
3225
 
2988
3226
  if (git_reference_type(old) == GIT_REFERENCE_SYMBOLIC)
2989
- 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)));
2990
3228
  else
2991
- 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)));
2992
3230
 
2993
- git_buf_puts(out, " to ");
3231
+ git_str_puts(out, " to ");
2994
3232
 
2995
3233
  if (git_reference__is_branch(new) ||
2996
3234
  git_reference__is_tag(new) ||
2997
3235
  git_reference__is_remote(new))
2998
- git_buf_puts(out, git_reference__shorthand(new));
3236
+ git_str_puts(out, git_reference__shorthand(new));
2999
3237
  else
3000
- git_buf_puts(out, new);
3238
+ git_str_puts(out, new);
3001
3239
 
3002
- if (git_buf_oom(out))
3240
+ if (git_str_oom(out))
3003
3241
  return -1;
3004
3242
 
3005
3243
  return 0;
@@ -3008,7 +3246,7 @@ static int checkout_message(git_buf *out, git_reference *old, const char *new)
3008
3246
  static int detach(git_repository *repo, const git_oid *id, const char *new)
3009
3247
  {
3010
3248
  int error;
3011
- git_buf log_message = GIT_BUF_INIT;
3249
+ git_str log_message = GIT_STR_INIT;
3012
3250
  git_object *object = NULL, *peeled = NULL;
3013
3251
  git_reference *new_head = NULL, *current = NULL;
3014
3252
 
@@ -3030,10 +3268,10 @@ static int detach(git_repository *repo, const git_oid *id, const char *new)
3030
3268
  if ((error = checkout_message(&log_message, current, new)) < 0)
3031
3269
  goto cleanup;
3032
3270
 
3033
- 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));
3034
3272
 
3035
3273
  cleanup:
3036
- git_buf_dispose(&log_message);
3274
+ git_str_dispose(&log_message);
3037
3275
  git_object_free(object);
3038
3276
  git_object_free(peeled);
3039
3277
  git_reference_free(current);
@@ -3046,7 +3284,7 @@ int git_repository_set_head(
3046
3284
  const char *refname)
3047
3285
  {
3048
3286
  git_reference *ref = NULL, *current = NULL, *new_head = NULL;
3049
- git_buf log_message = GIT_BUF_INIT;
3287
+ git_str log_message = GIT_STR_INIT;
3050
3288
  int error;
3051
3289
 
3052
3290
  GIT_ASSERT_ARG(repo);
@@ -3073,18 +3311,18 @@ int git_repository_set_head(
3073
3311
  if (!error) {
3074
3312
  if (git_reference_is_branch(ref)) {
3075
3313
  error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE,
3076
- git_reference_name(ref), true, git_buf_cstr(&log_message));
3314
+ git_reference_name(ref), true, git_str_cstr(&log_message));
3077
3315
  } else {
3078
3316
  error = detach(repo, git_reference_target(ref),
3079
3317
  git_reference_is_tag(ref) || git_reference_is_remote(ref) ? refname : NULL);
3080
3318
  }
3081
3319
  } else if (git_reference__is_branch(refname)) {
3082
3320
  error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname,
3083
- true, git_buf_cstr(&log_message));
3321
+ true, git_str_cstr(&log_message));
3084
3322
  }
3085
3323
 
3086
3324
  cleanup:
3087
- git_buf_dispose(&log_message);
3325
+ git_str_dispose(&log_message);
3088
3326
  git_reference_free(current);
3089
3327
  git_reference_free(ref);
3090
3328
  git_reference_free(new_head);
@@ -3093,26 +3331,26 @@ cleanup:
3093
3331
 
3094
3332
  int git_repository_set_head_detached(
3095
3333
  git_repository *repo,
3096
- const git_oid *commitish)
3334
+ const git_oid *committish)
3097
3335
  {
3098
- return detach(repo, commitish, NULL);
3336
+ return detach(repo, committish, NULL);
3099
3337
  }
3100
3338
 
3101
3339
  int git_repository_set_head_detached_from_annotated(
3102
3340
  git_repository *repo,
3103
- const git_annotated_commit *commitish)
3341
+ const git_annotated_commit *committish)
3104
3342
  {
3105
3343
  GIT_ASSERT_ARG(repo);
3106
- GIT_ASSERT_ARG(commitish);
3344
+ GIT_ASSERT_ARG(committish);
3107
3345
 
3108
- return detach(repo, git_annotated_commit_id(commitish), commitish->description);
3346
+ return detach(repo, git_annotated_commit_id(committish), committish->description);
3109
3347
  }
3110
3348
 
3111
3349
  int git_repository_detach_head(git_repository *repo)
3112
3350
  {
3113
3351
  git_reference *old_head = NULL, *new_head = NULL, *current = NULL;
3114
3352
  git_object *object = NULL;
3115
- git_buf log_message = GIT_BUF_INIT;
3353
+ git_str log_message = GIT_STR_INIT;
3116
3354
  int error;
3117
3355
 
3118
3356
  GIT_ASSERT_ARG(repo);
@@ -3130,10 +3368,10 @@ int git_repository_detach_head(git_repository *repo)
3130
3368
  goto cleanup;
3131
3369
 
3132
3370
  error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head),
3133
- 1, git_buf_cstr(&log_message));
3371
+ 1, git_str_cstr(&log_message));
3134
3372
 
3135
3373
  cleanup:
3136
- git_buf_dispose(&log_message);
3374
+ git_str_dispose(&log_message);
3137
3375
  git_object_free(object);
3138
3376
  git_reference_free(old_head);
3139
3377
  git_reference_free(new_head);
@@ -3147,69 +3385,69 @@ cleanup:
3147
3385
  */
3148
3386
  int git_repository_state(git_repository *repo)
3149
3387
  {
3150
- git_buf repo_path = GIT_BUF_INIT;
3388
+ git_str repo_path = GIT_STR_INIT;
3151
3389
  int state = GIT_REPOSITORY_STATE_NONE;
3152
3390
 
3153
3391
  GIT_ASSERT_ARG(repo);
3154
3392
 
3155
- if (git_buf_puts(&repo_path, repo->gitdir) < 0)
3393
+ if (git_str_puts(&repo_path, repo->gitdir) < 0)
3156
3394
  return -1;
3157
3395
 
3158
- 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))
3159
3397
  state = GIT_REPOSITORY_STATE_REBASE_INTERACTIVE;
3160
- 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))
3161
3399
  state = GIT_REPOSITORY_STATE_REBASE_MERGE;
3162
- 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))
3163
3401
  state = GIT_REPOSITORY_STATE_REBASE;
3164
- 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))
3165
3403
  state = GIT_REPOSITORY_STATE_APPLY_MAILBOX;
3166
- 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))
3167
3405
  state = GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE;
3168
- 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))
3169
3407
  state = GIT_REPOSITORY_STATE_MERGE;
3170
- 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)) {
3171
3409
  state = GIT_REPOSITORY_STATE_REVERT;
3172
- if (git_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
3410
+ if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
3173
3411
  state = GIT_REPOSITORY_STATE_REVERT_SEQUENCE;
3174
3412
  }
3175
- } 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)) {
3176
3414
  state = GIT_REPOSITORY_STATE_CHERRYPICK;
3177
- if (git_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
3415
+ if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
3178
3416
  state = GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE;
3179
3417
  }
3180
- } 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))
3181
3419
  state = GIT_REPOSITORY_STATE_BISECT;
3182
3420
 
3183
- git_buf_dispose(&repo_path);
3421
+ git_str_dispose(&repo_path);
3184
3422
  return state;
3185
3423
  }
3186
3424
 
3187
3425
  int git_repository__cleanup_files(
3188
3426
  git_repository *repo, const char *files[], size_t files_len)
3189
3427
  {
3190
- git_buf buf = GIT_BUF_INIT;
3428
+ git_str buf = GIT_STR_INIT;
3191
3429
  size_t i;
3192
3430
  int error;
3193
3431
 
3194
3432
  for (error = 0, i = 0; !error && i < files_len; ++i) {
3195
3433
  const char *path;
3196
3434
 
3197
- if (git_buf_joinpath(&buf, repo->gitdir, files[i]) < 0)
3435
+ if (git_str_joinpath(&buf, repo->gitdir, files[i]) < 0)
3198
3436
  return -1;
3199
3437
 
3200
- path = git_buf_cstr(&buf);
3438
+ path = git_str_cstr(&buf);
3201
3439
 
3202
- if (git_path_isfile(path)) {
3440
+ if (git_fs_path_isfile(path)) {
3203
3441
  error = p_unlink(path);
3204
- } else if (git_path_isdir(path)) {
3442
+ } else if (git_fs_path_isdir(path)) {
3205
3443
  error = git_futils_rmdir_r(path, NULL,
3206
3444
  GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS);
3207
3445
  }
3208
3446
 
3209
- git_buf_clear(&buf);
3447
+ git_str_clear(&buf);
3210
3448
  }
3211
3449
 
3212
- git_buf_dispose(&buf);
3450
+ git_str_dispose(&buf);
3213
3451
  return error;
3214
3452
  }
3215
3453
 
@@ -3234,15 +3472,15 @@ int git_repository_state_cleanup(git_repository *repo)
3234
3472
 
3235
3473
  int git_repository_is_shallow(git_repository *repo)
3236
3474
  {
3237
- git_buf path = GIT_BUF_INIT;
3475
+ git_str path = GIT_STR_INIT;
3238
3476
  struct stat st;
3239
3477
  int error;
3240
3478
 
3241
- if ((error = git_buf_joinpath(&path, repo->gitdir, "shallow")) < 0)
3479
+ if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0)
3242
3480
  return error;
3243
3481
 
3244
- error = git_path_lstat(path.ptr, &st);
3245
- git_buf_dispose(&path);
3482
+ error = git_fs_path_lstat(path.ptr, &st);
3483
+ git_str_dispose(&path);
3246
3484
 
3247
3485
  if (error == GIT_ENOTFOUND) {
3248
3486
  git_error_clear();
@@ -3317,3 +3555,8 @@ int git_repository_submodule_cache_clear(git_repository *repo)
3317
3555
  repo->submodule_cache = NULL;
3318
3556
  return error;
3319
3557
  }
3558
+
3559
+ git_oid_t git_repository_oid_type(git_repository *repo)
3560
+ {
3561
+ return repo ? repo->oid_type : 0;
3562
+ }