rugged 1.3.2.3 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (329) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/extconf.rb +1 -1
  3. data/ext/rugged/rugged_config.c +7 -2
  4. data/ext/rugged/rugged_remote.c +17 -0
  5. data/lib/rugged/version.rb +1 -1
  6. data/vendor/libgit2/CMakeLists.txt +103 -276
  7. data/vendor/libgit2/COPYING +36 -19
  8. data/vendor/libgit2/cmake/AddCFlagIfSupported.cmake +21 -21
  9. data/vendor/libgit2/cmake/DefaultCFlags.cmake +154 -0
  10. data/vendor/libgit2/cmake/EnableWarnings.cmake +13 -13
  11. data/vendor/libgit2/cmake/FindCoreFoundation.cmake +13 -13
  12. data/vendor/libgit2/cmake/FindGSSAPI.cmake +171 -287
  13. data/vendor/libgit2/cmake/FindGSSFramework.cmake +13 -13
  14. data/vendor/libgit2/cmake/{FindHTTP_Parser.cmake → FindHTTPParser.cmake} +17 -17
  15. data/vendor/libgit2/cmake/FindIconv.cmake +27 -27
  16. data/vendor/libgit2/cmake/FindLibSSH2.cmake +5 -5
  17. data/vendor/libgit2/cmake/FindPCRE.cmake +13 -13
  18. data/vendor/libgit2/cmake/FindPCRE2.cmake +12 -12
  19. data/vendor/libgit2/cmake/FindPkgLibraries.cmake +19 -19
  20. data/vendor/libgit2/cmake/FindSecurity.cmake +14 -14
  21. data/vendor/libgit2/cmake/FindStatNsec.cmake +12 -18
  22. data/vendor/libgit2/cmake/Findfutimens.cmake +8 -8
  23. data/vendor/libgit2/cmake/FindmbedTLS.cmake +63 -70
  24. data/vendor/libgit2/cmake/IdeSplitSources.cmake +18 -18
  25. data/vendor/libgit2/cmake/PkgBuildConfig.cmake +60 -60
  26. data/vendor/libgit2/cmake/SanitizeBool.cmake +20 -20
  27. data/vendor/libgit2/cmake/SelectGSSAPI.cmake +37 -37
  28. data/vendor/libgit2/cmake/SelectHTTPParser.cmake +19 -0
  29. data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +100 -100
  30. data/vendor/libgit2/cmake/SelectHashes.cmake +39 -49
  31. data/vendor/libgit2/cmake/SelectRegex.cmake +51 -0
  32. data/vendor/libgit2/cmake/SelectSSH.cmake +41 -0
  33. data/vendor/libgit2/cmake/SelectWinHTTP.cmake +17 -0
  34. data/vendor/libgit2/cmake/SelectZlib.cmake +34 -0
  35. data/vendor/libgit2/deps/chromium-zlib/CMakeLists.txt +6 -6
  36. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +31 -31
  37. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +1 -1
  38. data/vendor/libgit2/deps/ntlmclient/ntlm.c +4 -4
  39. data/vendor/libgit2/deps/ntlmclient/ntlm.h +4 -4
  40. data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +2 -2
  41. data/vendor/libgit2/deps/pcre/CMakeLists.txt +88 -88
  42. data/vendor/libgit2/deps/winhttp/CMakeLists.txt +14 -16
  43. data/vendor/libgit2/deps/zlib/adler32.c +0 -7
  44. data/vendor/libgit2/deps/zlib/crc32.c +288 -975
  45. data/vendor/libgit2/deps/zlib/crc32.h +436 -9441
  46. data/vendor/libgit2/deps/zlib/deflate.c +31 -83
  47. data/vendor/libgit2/deps/zlib/deflate.h +15 -12
  48. data/vendor/libgit2/deps/zlib/gzguts.h +2 -3
  49. data/vendor/libgit2/deps/zlib/infback.c +1 -2
  50. data/vendor/libgit2/deps/zlib/inffast.c +14 -14
  51. data/vendor/libgit2/deps/zlib/inflate.c +8 -39
  52. data/vendor/libgit2/deps/zlib/inflate.h +2 -3
  53. data/vendor/libgit2/deps/zlib/inftrees.c +3 -3
  54. data/vendor/libgit2/deps/zlib/trees.c +48 -27
  55. data/vendor/libgit2/deps/zlib/zlib.h +100 -126
  56. data/vendor/libgit2/deps/zlib/zutil.c +2 -2
  57. data/vendor/libgit2/deps/zlib/zutil.h +9 -12
  58. data/vendor/libgit2/include/git2/apply.h +16 -2
  59. data/vendor/libgit2/include/git2/attr.h +11 -2
  60. data/vendor/libgit2/include/git2/blame.h +4 -1
  61. data/vendor/libgit2/include/git2/blob.h +14 -1
  62. data/vendor/libgit2/include/git2/branch.h +2 -0
  63. data/vendor/libgit2/include/git2/buffer.h +18 -78
  64. data/vendor/libgit2/include/git2/cert.h +2 -2
  65. data/vendor/libgit2/include/git2/checkout.h +5 -2
  66. data/vendor/libgit2/include/git2/clone.h +3 -3
  67. data/vendor/libgit2/include/git2/commit.h +2 -0
  68. data/vendor/libgit2/include/git2/common.h +5 -12
  69. data/vendor/libgit2/include/git2/config.h +19 -3
  70. data/vendor/libgit2/include/git2/credential.h +2 -1
  71. data/vendor/libgit2/include/git2/credential_helpers.h +1 -0
  72. data/vendor/libgit2/include/git2/deprecated.h +1 -1
  73. data/vendor/libgit2/include/git2/describe.h +7 -2
  74. data/vendor/libgit2/include/git2/diff.h +17 -9
  75. data/vendor/libgit2/include/git2/email.h +1 -1
  76. data/vendor/libgit2/include/git2/errors.h +1 -2
  77. data/vendor/libgit2/include/git2/filter.h +7 -2
  78. data/vendor/libgit2/include/git2/graph.h +1 -0
  79. data/vendor/libgit2/include/git2/ignore.h +1 -1
  80. data/vendor/libgit2/include/git2/index.h +11 -5
  81. data/vendor/libgit2/include/git2/indexer.h +19 -0
  82. data/vendor/libgit2/include/git2/merge.h +23 -3
  83. data/vendor/libgit2/include/git2/message.h +2 -0
  84. data/vendor/libgit2/include/git2/object.h +23 -0
  85. data/vendor/libgit2/include/git2/odb.h +37 -7
  86. data/vendor/libgit2/include/git2/odb_backend.h +1 -1
  87. data/vendor/libgit2/include/git2/pack.h +24 -8
  88. data/vendor/libgit2/include/git2/patch.h +8 -0
  89. data/vendor/libgit2/include/git2/pathspec.h +1 -1
  90. data/vendor/libgit2/include/git2/proxy.h +1 -1
  91. data/vendor/libgit2/include/git2/rebase.h +9 -1
  92. data/vendor/libgit2/include/git2/refdb.h +3 -0
  93. data/vendor/libgit2/include/git2/reflog.h +1 -1
  94. data/vendor/libgit2/include/git2/refs.h +2 -2
  95. data/vendor/libgit2/include/git2/remote.h +184 -37
  96. data/vendor/libgit2/include/git2/repository.h +14 -9
  97. data/vendor/libgit2/include/git2/reset.h +2 -2
  98. data/vendor/libgit2/include/git2/revparse.h +1 -1
  99. data/vendor/libgit2/include/git2/revwalk.h +4 -1
  100. data/vendor/libgit2/include/git2/signature.h +1 -1
  101. data/vendor/libgit2/include/git2/stash.h +3 -3
  102. data/vendor/libgit2/include/git2/status.h +9 -3
  103. data/vendor/libgit2/include/git2/submodule.h +7 -2
  104. data/vendor/libgit2/include/git2/sys/commit_graph.h +1 -1
  105. data/vendor/libgit2/include/git2/sys/odb_backend.h +2 -5
  106. data/vendor/libgit2/include/git2/sys/remote.h +31 -0
  107. data/vendor/libgit2/include/git2/sys/stream.h +1 -1
  108. data/vendor/libgit2/include/git2/sys/transport.h +25 -34
  109. data/vendor/libgit2/include/git2/tag.h +1 -0
  110. data/vendor/libgit2/include/git2/tree.h +4 -3
  111. data/vendor/libgit2/include/git2/types.h +7 -7
  112. data/vendor/libgit2/include/git2/version.h +3 -3
  113. data/vendor/libgit2/include/git2/worktree.h +12 -2
  114. data/vendor/libgit2/src/CMakeLists.txt +189 -315
  115. data/vendor/libgit2/src/annotated_commit.h +1 -1
  116. data/vendor/libgit2/src/apply.c +18 -18
  117. data/vendor/libgit2/src/apply.h +2 -2
  118. data/vendor/libgit2/src/attr.c +18 -18
  119. data/vendor/libgit2/src/attr_file.c +17 -17
  120. data/vendor/libgit2/src/attr_file.h +4 -4
  121. data/vendor/libgit2/src/attrcache.c +17 -12
  122. data/vendor/libgit2/src/blame_git.c +1 -1
  123. data/vendor/libgit2/src/blob.c +33 -26
  124. data/vendor/libgit2/src/blob.h +1 -1
  125. data/vendor/libgit2/src/branch.c +150 -109
  126. data/vendor/libgit2/src/branch.h +15 -3
  127. data/vendor/libgit2/src/buf.c +126 -0
  128. data/vendor/libgit2/src/buf.h +50 -0
  129. data/vendor/libgit2/src/cc-compat.h +1 -1
  130. data/vendor/libgit2/src/checkout.c +74 -68
  131. data/vendor/libgit2/src/cherrypick.c +10 -10
  132. data/vendor/libgit2/src/clone.c +66 -66
  133. data/vendor/libgit2/src/commit.c +128 -58
  134. data/vendor/libgit2/src/commit.h +24 -1
  135. data/vendor/libgit2/src/commit_graph.c +68 -53
  136. data/vendor/libgit2/src/commit_graph.h +10 -3
  137. data/vendor/libgit2/src/commit_list.c +2 -3
  138. data/vendor/libgit2/src/common.h +10 -3
  139. data/vendor/libgit2/src/config.c +99 -77
  140. data/vendor/libgit2/src/config.h +15 -2
  141. data/vendor/libgit2/src/config_file.c +103 -91
  142. data/vendor/libgit2/src/config_mem.c +9 -9
  143. data/vendor/libgit2/src/config_parse.c +27 -23
  144. data/vendor/libgit2/src/crlf.c +24 -21
  145. data/vendor/libgit2/src/date.c +10 -17
  146. data/vendor/libgit2/src/date.h +33 -0
  147. data/vendor/libgit2/src/describe.c +27 -19
  148. data/vendor/libgit2/src/diff.c +25 -8
  149. data/vendor/libgit2/src/diff.h +2 -4
  150. data/vendor/libgit2/src/diff_driver.c +34 -36
  151. data/vendor/libgit2/src/diff_driver.h +3 -3
  152. data/vendor/libgit2/src/diff_file.c +29 -20
  153. data/vendor/libgit2/src/diff_generate.c +30 -6
  154. data/vendor/libgit2/src/diff_generate.h +5 -3
  155. data/vendor/libgit2/src/diff_print.c +102 -95
  156. data/vendor/libgit2/src/diff_stats.c +40 -29
  157. data/vendor/libgit2/src/{message.h → diff_stats.h} +7 -6
  158. data/vendor/libgit2/src/diff_tform.c +9 -8
  159. data/vendor/libgit2/src/diff_xdiff.c +3 -8
  160. data/vendor/libgit2/src/email.c +54 -38
  161. data/vendor/libgit2/src/email.h +1 -1
  162. data/vendor/libgit2/src/errors.c +18 -18
  163. data/vendor/libgit2/src/features.h.in +6 -1
  164. data/vendor/libgit2/src/fetch.c +69 -24
  165. data/vendor/libgit2/src/fetch.h +1 -1
  166. data/vendor/libgit2/src/fetchhead.c +19 -19
  167. data/vendor/libgit2/src/filebuf.c +28 -28
  168. data/vendor/libgit2/src/filebuf.h +1 -1
  169. data/vendor/libgit2/src/filter.c +96 -52
  170. data/vendor/libgit2/src/filter.h +26 -5
  171. data/vendor/libgit2/src/fs_path.c +1912 -0
  172. data/vendor/libgit2/src/fs_path.h +752 -0
  173. data/vendor/libgit2/src/futils.c +91 -85
  174. data/vendor/libgit2/src/futils.h +26 -14
  175. data/vendor/libgit2/src/hash/sha1/collisiondetect.c +2 -2
  176. data/vendor/libgit2/src/hash/sha1/common_crypto.c +2 -2
  177. data/vendor/libgit2/src/hash/sha1/generic.c +2 -2
  178. data/vendor/libgit2/src/hash/sha1/mbedtls.c +2 -2
  179. data/vendor/libgit2/src/hash/sha1/openssl.c +2 -2
  180. data/vendor/libgit2/src/hash/sha1/sha1dc/sha1.c +1 -1
  181. data/vendor/libgit2/src/hash/sha1/win32.c +6 -6
  182. data/vendor/libgit2/src/hash/sha1.h +3 -1
  183. data/vendor/libgit2/src/hash.c +67 -35
  184. data/vendor/libgit2/src/hash.h +12 -12
  185. data/vendor/libgit2/src/ident.c +18 -18
  186. data/vendor/libgit2/src/ignore.c +35 -34
  187. data/vendor/libgit2/src/ignore.h +2 -2
  188. data/vendor/libgit2/src/index.c +79 -80
  189. data/vendor/libgit2/src/index.h +6 -3
  190. data/vendor/libgit2/src/indexer.c +75 -57
  191. data/vendor/libgit2/src/iterator.c +64 -56
  192. data/vendor/libgit2/src/iterator.h +5 -5
  193. data/vendor/libgit2/src/khash.h +1 -1
  194. data/vendor/libgit2/src/libgit2.c +22 -19
  195. data/vendor/libgit2/src/mailmap.c +38 -36
  196. data/vendor/libgit2/src/merge.c +27 -27
  197. data/vendor/libgit2/src/merge.h +1 -14
  198. data/vendor/libgit2/src/merge_driver.c +2 -2
  199. data/vendor/libgit2/src/merge_file.c +13 -3
  200. data/vendor/libgit2/src/message.c +21 -10
  201. data/vendor/libgit2/src/midx.c +83 -66
  202. data/vendor/libgit2/src/midx.h +3 -3
  203. data/vendor/libgit2/src/mwindow.c +1 -1
  204. data/vendor/libgit2/src/net.c +278 -68
  205. data/vendor/libgit2/src/net.h +10 -3
  206. data/vendor/libgit2/src/netops.c +1 -1
  207. data/vendor/libgit2/src/netops.h +1 -1
  208. data/vendor/libgit2/src/notes.c +20 -29
  209. data/vendor/libgit2/src/object.c +49 -9
  210. data/vendor/libgit2/src/object.h +1 -1
  211. data/vendor/libgit2/src/odb.c +35 -32
  212. data/vendor/libgit2/src/odb.h +1 -1
  213. data/vendor/libgit2/src/odb_loose.c +68 -68
  214. data/vendor/libgit2/src/odb_mempack.c +18 -5
  215. data/vendor/libgit2/src/odb_pack.c +43 -43
  216. data/vendor/libgit2/src/oid.c +11 -4
  217. data/vendor/libgit2/src/oid.h +15 -0
  218. data/vendor/libgit2/src/pack-objects.c +41 -26
  219. data/vendor/libgit2/src/pack-objects.h +11 -6
  220. data/vendor/libgit2/src/pack.c +10 -10
  221. data/vendor/libgit2/src/patch.c +3 -3
  222. data/vendor/libgit2/src/patch.h +1 -0
  223. data/vendor/libgit2/src/patch_generate.c +27 -11
  224. data/vendor/libgit2/src/patch_generate.h +5 -5
  225. data/vendor/libgit2/src/patch_parse.c +24 -24
  226. data/vendor/libgit2/src/path.c +76 -1951
  227. data/vendor/libgit2/src/path.h +34 -741
  228. data/vendor/libgit2/src/pathspec.c +6 -6
  229. data/vendor/libgit2/src/pathspec.h +2 -2
  230. data/vendor/libgit2/src/posix.c +3 -3
  231. data/vendor/libgit2/src/posix.h +1 -0
  232. data/vendor/libgit2/src/pqueue.h +1 -1
  233. data/vendor/libgit2/src/proxy.c +4 -1
  234. data/vendor/libgit2/src/proxy.h +1 -1
  235. data/vendor/libgit2/src/push.c +30 -35
  236. data/vendor/libgit2/src/push.h +4 -16
  237. data/vendor/libgit2/src/rand.c +226 -0
  238. data/vendor/libgit2/src/rand.h +37 -0
  239. data/vendor/libgit2/src/reader.c +8 -8
  240. data/vendor/libgit2/src/reader.h +2 -2
  241. data/vendor/libgit2/src/rebase.c +89 -88
  242. data/vendor/libgit2/src/refdb_fs.c +447 -173
  243. data/vendor/libgit2/src/refs.c +32 -32
  244. data/vendor/libgit2/src/refs.h +2 -2
  245. data/vendor/libgit2/src/refspec.c +32 -37
  246. data/vendor/libgit2/src/refspec.h +5 -2
  247. data/vendor/libgit2/src/regexp.c +1 -1
  248. data/vendor/libgit2/src/remote.c +713 -419
  249. data/vendor/libgit2/src/remote.h +15 -10
  250. data/vendor/libgit2/src/repository.c +350 -467
  251. data/vendor/libgit2/src/repository.h +11 -10
  252. data/vendor/libgit2/src/reset.c +8 -5
  253. data/vendor/libgit2/src/revert.c +10 -10
  254. data/vendor/libgit2/src/revparse.c +48 -35
  255. data/vendor/libgit2/src/revwalk.c +7 -7
  256. data/vendor/libgit2/src/signature.c +12 -6
  257. data/vendor/libgit2/src/signature.h +1 -1
  258. data/vendor/libgit2/src/sortedcache.c +1 -1
  259. data/vendor/libgit2/src/sortedcache.h +1 -1
  260. data/vendor/libgit2/src/stash.c +36 -37
  261. data/vendor/libgit2/src/status.c +4 -1
  262. data/vendor/libgit2/src/{buffer.c → str.c} +157 -151
  263. data/vendor/libgit2/src/str.h +357 -0
  264. data/vendor/libgit2/src/streams/mbedtls.c +8 -6
  265. data/vendor/libgit2/src/streams/openssl_dynamic.h +3 -3
  266. data/vendor/libgit2/src/submodule.c +171 -159
  267. data/vendor/libgit2/src/submodule.h +1 -1
  268. data/vendor/libgit2/src/sysdir.c +68 -52
  269. data/vendor/libgit2/src/sysdir.h +15 -10
  270. data/vendor/libgit2/src/tag.c +29 -27
  271. data/vendor/libgit2/src/thread.h +3 -3
  272. data/vendor/libgit2/src/threadstate.c +3 -3
  273. data/vendor/libgit2/src/threadstate.h +1 -1
  274. data/vendor/libgit2/src/trace.c +1 -14
  275. data/vendor/libgit2/src/trace.h +5 -22
  276. data/vendor/libgit2/src/trailer.c +1 -1
  277. data/vendor/libgit2/src/transaction.c +1 -1
  278. data/vendor/libgit2/src/transport.c +10 -10
  279. data/vendor/libgit2/src/transports/auth.c +7 -9
  280. data/vendor/libgit2/src/transports/auth.h +2 -3
  281. data/vendor/libgit2/src/transports/auth_negotiate.c +12 -13
  282. data/vendor/libgit2/src/transports/auth_ntlm.c +10 -10
  283. data/vendor/libgit2/src/transports/auth_ntlm.h +0 -1
  284. data/vendor/libgit2/src/transports/git.c +9 -11
  285. data/vendor/libgit2/src/transports/http.c +37 -17
  286. data/vendor/libgit2/src/transports/http.h +2 -3
  287. data/vendor/libgit2/src/transports/httpclient.c +65 -65
  288. data/vendor/libgit2/src/transports/local.c +124 -116
  289. data/vendor/libgit2/src/transports/smart.c +51 -139
  290. data/vendor/libgit2/src/transports/smart.h +25 -31
  291. data/vendor/libgit2/src/transports/smart_pkt.c +33 -33
  292. data/vendor/libgit2/src/transports/smart_protocol.c +57 -39
  293. data/vendor/libgit2/src/transports/ssh.c +47 -112
  294. data/vendor/libgit2/src/transports/winhttp.c +50 -56
  295. data/vendor/libgit2/src/tree-cache.c +5 -5
  296. data/vendor/libgit2/src/tree-cache.h +2 -2
  297. data/vendor/libgit2/src/tree.c +59 -48
  298. data/vendor/libgit2/src/tree.h +1 -1
  299. data/vendor/libgit2/src/unix/map.c +0 -2
  300. data/vendor/libgit2/src/unix/posix.h +1 -4
  301. data/vendor/libgit2/src/unix/realpath.c +0 -2
  302. data/vendor/libgit2/src/util.c +14 -14
  303. data/vendor/libgit2/src/util.h +2 -28
  304. data/vendor/libgit2/src/vector.h +1 -1
  305. data/vendor/libgit2/src/win32/findfile.c +172 -116
  306. data/vendor/libgit2/src/win32/findfile.h +7 -4
  307. data/vendor/libgit2/src/win32/path_w32.c +140 -9
  308. data/vendor/libgit2/src/win32/path_w32.h +2 -0
  309. data/vendor/libgit2/src/win32/posix.h +0 -1
  310. data/vendor/libgit2/src/win32/posix_w32.c +11 -27
  311. data/vendor/libgit2/src/win32/w32_buffer.c +2 -3
  312. data/vendor/libgit2/src/win32/w32_buffer.h +2 -3
  313. data/vendor/libgit2/src/win32/w32_leakcheck.c +1 -1
  314. data/vendor/libgit2/src/worktree.c +116 -94
  315. data/vendor/libgit2/src/worktree.h +1 -1
  316. data/vendor/libgit2/src/xdiff/git-xdiff.h +53 -0
  317. data/vendor/libgit2/src/xdiff/xdiff.h +15 -15
  318. data/vendor/libgit2/src/xdiff/xdiffi.c +134 -108
  319. data/vendor/libgit2/src/xdiff/xemit.c +23 -7
  320. data/vendor/libgit2/src/xdiff/xhistogram.c +87 -78
  321. data/vendor/libgit2/src/xdiff/xinclude.h +1 -12
  322. data/vendor/libgit2/src/xdiff/xmerge.c +104 -117
  323. data/vendor/libgit2/src/xdiff/xpatience.c +6 -17
  324. data/vendor/libgit2/src/xdiff/xprepare.c +15 -20
  325. data/vendor/libgit2/src/xdiff/xutils.c +18 -7
  326. data/vendor/libgit2/src/zstream.c +5 -5
  327. data/vendor/libgit2/src/zstream.h +4 -4
  328. metadata +25 -10
  329. data/vendor/libgit2/src/buffer.h +0 -374
@@ -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,14 +32,13 @@
31
32
  #include "annotated_commit.h"
32
33
  #include "submodule.h"
33
34
  #include "worktree.h"
34
-
35
+ #include "path.h"
35
36
  #include "strmap.h"
36
37
 
37
38
  #ifdef GIT_WIN32
38
39
  # include "win32/w32_util.h"
39
40
  #endif
40
41
 
41
- bool git_repository__validate_ownership = true;
42
42
  bool git_repository__fsync_gitdir = false;
43
43
 
44
44
  static const struct {
@@ -65,7 +65,6 @@ static const struct {
65
65
 
66
66
  static int check_repositoryformatversion(int *version, git_config *config);
67
67
  static int check_extensions(git_config *config, int version);
68
- static int load_global_config(git_config **config);
69
68
 
70
69
  #define GIT_COMMONDIR_FILE "commondir"
71
70
  #define GIT_GITDIR_FILE "gitdir"
@@ -77,13 +76,13 @@ static int load_global_config(git_config **config);
77
76
  #define GIT_REPO_VERSION 0
78
77
  #define GIT_REPO_MAX_VERSION 1
79
78
 
80
- git_buf git_repository__reserved_names_win32[] = {
79
+ git_str git_repository__reserved_names_win32[] = {
81
80
  { DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
82
81
  { GIT_DIR_SHORTNAME, 0, CONST_STRLEN(GIT_DIR_SHORTNAME) }
83
82
  };
84
83
  size_t git_repository__reserved_names_win32_len = 2;
85
84
 
86
- git_buf git_repository__reserved_names_posix[] = {
85
+ git_str git_repository__reserved_names_posix[] = {
87
86
  { DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
88
87
  };
89
88
  size_t git_repository__reserved_names_posix_len = 1;
@@ -173,7 +172,7 @@ void git_repository_free(git_repository *repo)
173
172
  repo->diff_drivers = NULL;
174
173
 
175
174
  for (i = 0; i < repo->reserved_names.size; i++)
176
- git_buf_dispose(git_array_get(repo->reserved_names, i));
175
+ git_str_dispose(git_array_get(repo->reserved_names, i));
177
176
  git_array_clear(repo->reserved_names);
178
177
 
179
178
  git__free(repo->gitlink);
@@ -189,18 +188,18 @@ void git_repository_free(git_repository *repo)
189
188
  }
190
189
 
191
190
  /* 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)
191
+ static int lookup_commondir(bool *separate, git_str *commondir, git_str *repository_path)
193
192
  {
194
- git_buf common_link = GIT_BUF_INIT;
193
+ git_str common_link = GIT_STR_INIT;
195
194
  int error;
196
195
 
197
196
  /*
198
197
  * If there's no commondir file, the repository path is the
199
198
  * common path, but it needs a trailing slash.
200
199
  */
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);
200
+ if (!git_fs_path_contains_file(repository_path, GIT_COMMONDIR_FILE)) {
201
+ if ((error = git_str_set(commondir, repository_path->ptr, repository_path->size)) == 0)
202
+ error = git_fs_path_to_dir(commondir);
204
203
 
205
204
  *separate = false;
206
205
  goto done;
@@ -208,28 +207,28 @@ static int lookup_commondir(bool *separate, git_buf *commondir, git_buf *reposit
208
207
 
209
208
  *separate = true;
210
209
 
211
- if ((error = git_buf_joinpath(&common_link, repository_path->ptr, GIT_COMMONDIR_FILE)) < 0 ||
210
+ if ((error = git_str_joinpath(&common_link, repository_path->ptr, GIT_COMMONDIR_FILE)) < 0 ||
212
211
  (error = git_futils_readbuffer(&common_link, common_link.ptr)) < 0)
213
212
  goto done;
214
213
 
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)
214
+ git_str_rtrim(&common_link);
215
+ if (git_fs_path_is_relative(common_link.ptr)) {
216
+ if ((error = git_str_joinpath(commondir, repository_path->ptr, common_link.ptr)) < 0)
218
217
  goto done;
219
218
  } else {
220
- git_buf_swap(commondir, &common_link);
219
+ git_str_swap(commondir, &common_link);
221
220
  }
222
221
 
223
- git_buf_dispose(&common_link);
222
+ git_str_dispose(&common_link);
224
223
 
225
224
  /* Make sure the commondir path always has a trailing slash */
226
- error = git_path_prettify_dir(commondir, commondir->ptr, NULL);
225
+ error = git_fs_path_prettify_dir(commondir, commondir->ptr, NULL);
227
226
 
228
227
  done:
229
228
  return error;
230
229
  }
231
230
 
232
- GIT_INLINE(int) validate_repo_path(git_buf *path)
231
+ GIT_INLINE(int) validate_repo_path(git_str *path)
233
232
  {
234
233
  /*
235
234
  * The longest static path in a repository (or commondir) is the
@@ -241,8 +240,8 @@ GIT_INLINE(int) validate_repo_path(git_buf *path)
241
240
  CONST_STRLEN("objects/pack/pack-.pack.lock") +
242
241
  GIT_OID_HEXSZ;
243
242
 
244
- return git_path_validate_filesystem_with_suffix(
245
- path->ptr, path->size, suffix_len);
243
+ return git_fs_path_validate_str_length_with_suffix(
244
+ path, suffix_len);
246
245
  }
247
246
 
248
247
  /*
@@ -250,7 +249,7 @@ GIT_INLINE(int) validate_repo_path(git_buf *path)
250
249
  *
251
250
  * Open a repository object from its path
252
251
  */
253
- static int is_valid_repository_path(bool *out, git_buf *repository_path, git_buf *common_path)
252
+ static int is_valid_repository_path(bool *out, git_str *repository_path, git_str *common_path)
254
253
  {
255
254
  bool separate_commondir = false;
256
255
  int error;
@@ -261,13 +260,13 @@ static int is_valid_repository_path(bool *out, git_buf *repository_path, git_buf
261
260
  return error;
262
261
 
263
262
  /* Ensure HEAD file exists */
264
- if (git_path_contains_file(repository_path, GIT_HEAD_FILE) == false)
263
+ if (git_fs_path_contains_file(repository_path, GIT_HEAD_FILE) == false)
265
264
  return 0;
266
265
 
267
266
  /* Check files in common dir */
268
- if (git_path_contains_dir(common_path, GIT_OBJECTS_DIR) == false)
267
+ if (git_fs_path_contains_dir(common_path, GIT_OBJECTS_DIR) == false)
269
268
  return 0;
270
- if (git_path_contains_dir(common_path, GIT_REFS_DIR) == false)
269
+ if (git_fs_path_contains_dir(common_path, GIT_REFS_DIR) == false)
271
270
  return 0;
272
271
 
273
272
  /* Ensure the repo (and commondir) are valid paths */
@@ -335,12 +334,12 @@ static int load_config_data(git_repository *repo, const git_config *config)
335
334
  return 0;
336
335
  }
337
336
 
338
- static int load_workdir(git_repository *repo, git_config *config, git_buf *parent_path)
337
+ static int load_workdir(git_repository *repo, git_config *config, git_str *parent_path)
339
338
  {
340
339
  int error;
341
340
  git_config_entry *ce;
342
- git_buf worktree = GIT_BUF_INIT;
343
- git_buf path = GIT_BUF_INIT;
341
+ git_str worktree = GIT_STR_INIT;
342
+ git_str path = GIT_STR_INIT;
344
343
 
345
344
  if (repo->is_bare)
346
345
  return 0;
@@ -356,38 +355,38 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren
356
355
  goto cleanup;
357
356
  }
358
357
 
359
- git_buf_attach(&worktree, gitlink, 0);
358
+ git_str_attach(&worktree, gitlink, 0);
360
359
 
361
- if ((git_path_dirname_r(&worktree, worktree.ptr)) < 0 ||
362
- git_path_to_dir(&worktree) < 0) {
360
+ if ((git_fs_path_dirname_r(&worktree, worktree.ptr)) < 0 ||
361
+ git_fs_path_to_dir(&worktree) < 0) {
363
362
  error = -1;
364
363
  goto cleanup;
365
364
  }
366
365
 
367
- repo->workdir = git_buf_detach(&worktree);
366
+ repo->workdir = git_str_detach(&worktree);
368
367
  }
369
368
  else if (ce && ce->value) {
370
- if ((error = git_path_prettify_dir(
369
+ if ((error = git_fs_path_prettify_dir(
371
370
  &worktree, ce->value, repo->gitdir)) < 0)
372
371
  goto cleanup;
373
372
 
374
- repo->workdir = git_buf_detach(&worktree);
373
+ repo->workdir = git_str_detach(&worktree);
375
374
  }
376
- else if (parent_path && git_path_isdir(parent_path->ptr))
377
- repo->workdir = git_buf_detach(parent_path);
375
+ else if (parent_path && git_fs_path_isdir(parent_path->ptr))
376
+ repo->workdir = git_str_detach(parent_path);
378
377
  else {
379
- if (git_path_dirname_r(&worktree, repo->gitdir) < 0 ||
380
- git_path_to_dir(&worktree) < 0) {
378
+ if (git_fs_path_dirname_r(&worktree, repo->gitdir) < 0 ||
379
+ git_fs_path_to_dir(&worktree) < 0) {
381
380
  error = -1;
382
381
  goto cleanup;
383
382
  }
384
383
 
385
- repo->workdir = git_buf_detach(&worktree);
384
+ repo->workdir = git_str_detach(&worktree);
386
385
  }
387
386
 
388
387
  GIT_ERROR_CHECK_ALLOC(repo->workdir);
389
388
  cleanup:
390
- git_buf_dispose(&path);
389
+ git_str_dispose(&path);
391
390
  git_config_entry_free(ce);
392
391
  return error;
393
392
  }
@@ -396,7 +395,7 @@ cleanup:
396
395
  * This function returns furthest offset into path where a ceiling dir
397
396
  * is found, so we can stop processing the path at that point.
398
397
  *
399
- * Note: converting this to use git_bufs instead of GIT_PATH_MAX buffers on
398
+ * Note: converting this to use git_strs instead of GIT_PATH_MAX buffers on
400
399
  * the stack could remove directories name limits, but at the cost of doing
401
400
  * repeated malloc/frees inside the loop below, so let's not do it now.
402
401
  */
@@ -411,7 +410,7 @@ static size_t find_ceiling_dir_offset(
411
410
 
412
411
  GIT_ASSERT_ARG(path);
413
412
 
414
- min_len = (size_t)(git_path_root(path) + 1);
413
+ min_len = (size_t)(git_fs_path_root(path) + 1);
415
414
 
416
415
  if (ceiling_directories == NULL || min_len == 0)
417
416
  return min_len;
@@ -420,7 +419,7 @@ static size_t find_ceiling_dir_offset(
420
419
  for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++);
421
420
  len = sep - ceil;
422
421
 
423
- if (len == 0 || len >= sizeof(buf) || git_path_root(ceil) == -1)
422
+ if (len == 0 || len >= sizeof(buf) || git_fs_path_root(ceil) == -1)
424
423
  continue;
425
424
 
426
425
  strncpy(buf, ceil, len);
@@ -449,10 +448,10 @@ static size_t find_ceiling_dir_offset(
449
448
  * it points to. Before calling, set `path_out` to the base directory that
450
449
  * should be used if the contents of `file_path` are a relative path.
451
450
  */
452
- static int read_gitfile(git_buf *path_out, const char *file_path)
451
+ static int read_gitfile(git_str *path_out, const char *file_path)
453
452
  {
454
453
  int error = 0;
455
- git_buf file = GIT_BUF_INIT;
454
+ git_str file = GIT_STR_INIT;
456
455
  size_t prefix_len = strlen(GIT_FILE_CONTENT_PREFIX);
457
456
 
458
457
  GIT_ASSERT_ARG(path_out);
@@ -461,151 +460,41 @@ static int read_gitfile(git_buf *path_out, const char *file_path)
461
460
  if (git_futils_readbuffer(&file, file_path) < 0)
462
461
  return -1;
463
462
 
464
- git_buf_rtrim(&file);
463
+ git_str_rtrim(&file);
465
464
  /* apparently on Windows, some people use backslashes in paths */
466
- git_path_mkposix(file.ptr);
465
+ git_fs_path_mkposix(file.ptr);
467
466
 
468
- if (git_buf_len(&file) <= prefix_len ||
469
- memcmp(git_buf_cstr(&file), GIT_FILE_CONTENT_PREFIX, prefix_len) != 0)
467
+ if (git_str_len(&file) <= prefix_len ||
468
+ memcmp(git_str_cstr(&file), GIT_FILE_CONTENT_PREFIX, prefix_len) != 0)
470
469
  {
471
470
  git_error_set(GIT_ERROR_REPOSITORY,
472
471
  "the `.git` file at '%s' is malformed", file_path);
473
472
  error = -1;
474
473
  }
475
- else if ((error = git_path_dirname_r(path_out, file_path)) >= 0) {
476
- const char *gitlink = git_buf_cstr(&file) + prefix_len;
474
+ else if ((error = git_fs_path_dirname_r(path_out, file_path)) >= 0) {
475
+ const char *gitlink = git_str_cstr(&file) + prefix_len;
477
476
  while (*gitlink && git__isspace(*gitlink)) gitlink++;
478
477
 
479
- error = git_path_prettify_dir(
480
- path_out, gitlink, git_buf_cstr(path_out));
481
- }
482
-
483
- git_buf_dispose(&file);
484
- return error;
485
- }
486
-
487
- typedef struct {
488
- const char *repo_path;
489
- git_buf tmp;
490
- bool *is_safe;
491
- } validate_ownership_data;
492
-
493
- static int validate_ownership_cb(const git_config_entry *entry, void *payload)
494
- {
495
- validate_ownership_data *data = payload;
496
-
497
- if (strcmp(entry->value, "") == 0)
498
- *data->is_safe = false;
499
-
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;
503
-
504
- return 0;
505
- }
506
-
507
- static int validate_ownership_config(bool *is_safe, const char *path)
508
- {
509
- validate_ownership_data ownership_data = {
510
- path, GIT_BUF_INIT, is_safe
511
- };
512
- git_config *config;
513
- int error;
514
-
515
- if (load_global_config(&config) != 0)
516
- return 0;
517
-
518
- error = git_config_get_multivar_foreach(config,
519
- "safe.directory", NULL,
520
- validate_ownership_cb,
521
- &ownership_data);
522
-
523
- git_config_free(config);
524
- git_buf_dispose(&ownership_data.tmp);
525
-
526
- return error;
527
- }
528
-
529
- static int validate_ownership_path(bool *is_safe, const char *path)
530
- {
531
- git_path_owner_t owner_level =
532
- GIT_PATH_OWNER_CURRENT_USER |
533
- GIT_PATH_USER_IS_ADMINISTRATOR |
534
- GIT_PATH_OWNER_RUNNING_SUDO;
535
- int error = 0;
536
-
537
- if (path)
538
- error = git_path_owner_is(is_safe, path, owner_level);
539
-
540
- if (error == GIT_ENOTFOUND) {
541
- *is_safe = true;
542
- error = 0;
543
- }
544
-
545
- return error;
546
- }
547
-
548
- static int validate_ownership(git_repository *repo)
549
- {
550
- const char *validation_paths[3] = { NULL }, *path;
551
- size_t validation_len = 0, i;
552
- bool is_safe = false;
553
- int error = 0;
554
-
555
- /*
556
- * If there's a worktree, validate the permissions to it *and*
557
- * the git directory, and use the worktree as the configuration
558
- * key for allowlisting the directory. In a bare setup, only
559
- * look at the gitdir and use that as the allowlist. So we
560
- * examine all `validation_paths` but use only the first as
561
- * the configuration lookup.
562
- */
563
-
564
- if (repo->workdir)
565
- validation_paths[validation_len++] = repo->workdir;
566
-
567
- if (repo->gitlink)
568
- validation_paths[validation_len++] = repo->gitlink;
569
-
570
- validation_paths[validation_len++] = repo->gitdir;
571
-
572
- for (i = 0; i < validation_len; i++) {
573
- path = validation_paths[i];
574
-
575
- if ((error = validate_ownership_path(&is_safe, path)) < 0)
576
- goto done;
577
-
578
- if (!is_safe)
579
- break;
580
- }
581
-
582
- if (is_safe ||
583
- (error = validate_ownership_config(&is_safe, validation_paths[0])) < 0)
584
- goto done;
585
-
586
- if (!is_safe) {
587
- git_error_set(GIT_ERROR_CONFIG,
588
- "repository path '%s' is not owned by current user",
589
- path);
590
- error = GIT_EOWNER;
478
+ error = git_fs_path_prettify_dir(
479
+ path_out, gitlink, git_str_cstr(path_out));
591
480
  }
592
481
 
593
- done:
482
+ git_str_dispose(&file);
594
483
  return error;
595
484
  }
596
485
 
597
486
  static int find_repo(
598
- git_buf *gitdir_path,
599
- git_buf *workdir_path,
600
- git_buf *gitlink_path,
601
- git_buf *commondir_path,
487
+ git_str *gitdir_path,
488
+ git_str *workdir_path,
489
+ git_str *gitlink_path,
490
+ git_str *commondir_path,
602
491
  const char *start_path,
603
492
  uint32_t flags,
604
493
  const char *ceiling_dirs)
605
494
  {
606
- git_buf path = GIT_BUF_INIT;
607
- git_buf repo_link = GIT_BUF_INIT;
608
- git_buf common_link = GIT_BUF_INIT;
495
+ git_str path = GIT_STR_INIT;
496
+ git_str repo_link = GIT_STR_INIT;
497
+ git_str common_link = GIT_STR_INIT;
609
498
  struct stat st;
610
499
  dev_t initial_device = 0;
611
500
  int min_iterations;
@@ -613,9 +502,9 @@ static int find_repo(
613
502
  size_t ceiling_offset = 0;
614
503
  int error;
615
504
 
616
- git_buf_clear(gitdir_path);
505
+ git_str_clear(gitdir_path);
617
506
 
618
- error = git_path_prettify(&path, start_path, NULL);
507
+ error = git_fs_path_prettify(&path, start_path, NULL);
619
508
  if (error < 0)
620
509
  return error;
621
510
 
@@ -637,7 +526,7 @@ static int find_repo(
637
526
  for (;;) {
638
527
  if (!(flags & GIT_REPOSITORY_OPEN_NO_DOTGIT)) {
639
528
  if (!in_dot_git) {
640
- if ((error = git_buf_joinpath(&path, path.ptr, DOT_GIT)) < 0)
529
+ if ((error = git_str_joinpath(&path, path.ptr, DOT_GIT)) < 0)
641
530
  goto out;
642
531
  }
643
532
  in_dot_git = !in_dot_git;
@@ -656,15 +545,15 @@ static int find_repo(
656
545
  goto out;
657
546
 
658
547
  if (is_valid) {
659
- if ((error = git_path_to_dir(&path)) < 0 ||
660
- (error = git_buf_set(gitdir_path, path.ptr, path.size)) < 0)
548
+ if ((error = git_fs_path_to_dir(&path)) < 0 ||
549
+ (error = git_str_set(gitdir_path, path.ptr, path.size)) < 0)
661
550
  goto out;
662
551
 
663
552
  if (gitlink_path)
664
- if ((error = git_buf_attach(gitlink_path, git_worktree__read_link(path.ptr, GIT_GITDIR_FILE), 0)) < 0)
553
+ if ((error = git_str_attach(gitlink_path, git_worktree__read_link(path.ptr, GIT_GITDIR_FILE), 0)) < 0)
665
554
  goto out;
666
555
  if (commondir_path)
667
- git_buf_swap(&common_link, commondir_path);
556
+ git_str_swap(&common_link, commondir_path);
668
557
 
669
558
  break;
670
559
  }
@@ -674,13 +563,13 @@ static int find_repo(
674
563
  goto out;
675
564
 
676
565
  if (is_valid) {
677
- git_buf_swap(gitdir_path, &repo_link);
566
+ git_str_swap(gitdir_path, &repo_link);
678
567
 
679
568
  if (gitlink_path)
680
- if ((error = git_buf_put(gitlink_path, path.ptr, path.size)) < 0)
569
+ if ((error = git_str_put(gitlink_path, path.ptr, path.size)) < 0)
681
570
  goto out;
682
571
  if (commondir_path)
683
- git_buf_swap(&common_link, commondir_path);
572
+ git_str_swap(&common_link, commondir_path);
684
573
  }
685
574
  break;
686
575
  }
@@ -689,7 +578,7 @@ static int find_repo(
689
578
  /* Move up one directory. If we're in_dot_git, we'll search the
690
579
  * parent itself next. If we're !in_dot_git, we'll search .git
691
580
  * in the parent directory next (added at the top of the loop). */
692
- if ((error = git_path_dirname_r(&path, path.ptr)) < 0)
581
+ if ((error = git_fs_path_dirname_r(&path, path.ptr)) < 0)
693
582
  goto out;
694
583
 
695
584
  /* Once we've checked the directory (and .git if applicable),
@@ -704,25 +593,25 @@ static int find_repo(
704
593
  }
705
594
 
706
595
  if (workdir_path && !(flags & GIT_REPOSITORY_OPEN_BARE)) {
707
- if (!git_buf_len(gitdir_path))
708
- git_buf_clear(workdir_path);
709
- else if ((error = git_path_dirname_r(workdir_path, path.ptr)) < 0 ||
710
- (error = git_path_to_dir(workdir_path)) < 0)
596
+ if (!git_str_len(gitdir_path))
597
+ git_str_clear(workdir_path);
598
+ else if ((error = git_fs_path_dirname_r(workdir_path, path.ptr)) < 0 ||
599
+ (error = git_fs_path_to_dir(workdir_path)) < 0)
711
600
  goto out;
712
601
  }
713
602
 
714
603
  /* If we didn't find the repository, and we don't have any other error
715
604
  * to report, report that. */
716
- if (!git_buf_len(gitdir_path)) {
605
+ if (!git_str_len(gitdir_path)) {
717
606
  git_error_set(GIT_ERROR_REPOSITORY, "could not find repository from '%s'", start_path);
718
607
  error = GIT_ENOTFOUND;
719
608
  goto out;
720
609
  }
721
610
 
722
611
  out:
723
- git_buf_dispose(&path);
724
- git_buf_dispose(&repo_link);
725
- git_buf_dispose(&common_link);
612
+ git_str_dispose(&path);
613
+ git_str_dispose(&repo_link);
614
+ git_str_dispose(&common_link);
726
615
  return error;
727
616
  }
728
617
 
@@ -730,18 +619,18 @@ int git_repository_open_bare(
730
619
  git_repository **repo_ptr,
731
620
  const char *bare_path)
732
621
  {
733
- git_buf path = GIT_BUF_INIT, common_path = GIT_BUF_INIT;
622
+ git_str path = GIT_STR_INIT, common_path = GIT_STR_INIT;
734
623
  git_repository *repo = NULL;
735
624
  bool is_valid;
736
625
  int error;
737
626
 
738
- if ((error = git_path_prettify_dir(&path, bare_path, NULL)) < 0 ||
627
+ if ((error = git_fs_path_prettify_dir(&path, bare_path, NULL)) < 0 ||
739
628
  (error = is_valid_repository_path(&is_valid, &path, &common_path)) < 0)
740
629
  return error;
741
630
 
742
631
  if (!is_valid) {
743
- git_buf_dispose(&path);
744
- git_buf_dispose(&common_path);
632
+ git_str_dispose(&path);
633
+ git_str_dispose(&common_path);
745
634
  git_error_set(GIT_ERROR_REPOSITORY, "path is not a repository: %s", bare_path);
746
635
  return GIT_ENOTFOUND;
747
636
  }
@@ -749,9 +638,9 @@ int git_repository_open_bare(
749
638
  repo = repository_alloc();
750
639
  GIT_ERROR_CHECK_ALLOC(repo);
751
640
 
752
- repo->gitdir = git_buf_detach(&path);
641
+ repo->gitdir = git_str_detach(&path);
753
642
  GIT_ERROR_CHECK_ALLOC(repo->gitdir);
754
- repo->commondir = git_buf_detach(&common_path);
643
+ repo->commondir = git_str_detach(&common_path);
755
644
  GIT_ERROR_CHECK_ALLOC(repo->commondir);
756
645
 
757
646
  /* of course we're bare! */
@@ -770,15 +659,15 @@ static int _git_repository_open_ext_from_env(
770
659
  git_repository *repo = NULL;
771
660
  git_index *index = NULL;
772
661
  git_odb *odb = NULL;
773
- git_buf dir_buf = GIT_BUF_INIT;
774
- git_buf ceiling_dirs_buf = GIT_BUF_INIT;
775
- git_buf across_fs_buf = GIT_BUF_INIT;
776
- git_buf index_file_buf = GIT_BUF_INIT;
777
- git_buf namespace_buf = GIT_BUF_INIT;
778
- git_buf object_dir_buf = GIT_BUF_INIT;
779
- git_buf alts_buf = GIT_BUF_INIT;
780
- git_buf work_tree_buf = GIT_BUF_INIT;
781
- git_buf common_dir_buf = GIT_BUF_INIT;
662
+ git_str dir_buf = GIT_STR_INIT;
663
+ git_str ceiling_dirs_buf = GIT_STR_INIT;
664
+ git_str across_fs_buf = GIT_STR_INIT;
665
+ git_str index_file_buf = GIT_STR_INIT;
666
+ git_str namespace_buf = GIT_STR_INIT;
667
+ git_str object_dir_buf = GIT_STR_INIT;
668
+ git_str alts_buf = GIT_STR_INIT;
669
+ git_str work_tree_buf = GIT_STR_INIT;
670
+ git_str common_dir_buf = GIT_STR_INIT;
782
671
  const char *ceiling_dirs = NULL;
783
672
  unsigned flags = 0;
784
673
  int error;
@@ -791,7 +680,7 @@ static int _git_repository_open_ext_from_env(
791
680
  } else if (error < 0)
792
681
  goto error;
793
682
  else {
794
- start_path = git_buf_cstr(&dir_buf);
683
+ start_path = git_str_cstr(&dir_buf);
795
684
  flags |= GIT_REPOSITORY_OPEN_NO_SEARCH;
796
685
  flags |= GIT_REPOSITORY_OPEN_NO_DOTGIT;
797
686
  }
@@ -803,7 +692,7 @@ static int _git_repository_open_ext_from_env(
803
692
  else if (error < 0)
804
693
  goto error;
805
694
  else
806
- ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf);
695
+ ceiling_dirs = git_str_cstr(&ceiling_dirs_buf);
807
696
 
808
697
  error = git__getenv(&across_fs_buf, "GIT_DISCOVERY_ACROSS_FILESYSTEM");
809
698
  if (error == GIT_ENOTFOUND)
@@ -812,7 +701,7 @@ static int _git_repository_open_ext_from_env(
812
701
  goto error;
813
702
  else {
814
703
  int across_fs = 0;
815
- error = git_config_parse_bool(&across_fs, git_buf_cstr(&across_fs_buf));
704
+ error = git_config_parse_bool(&across_fs, git_str_cstr(&across_fs_buf));
816
705
  if (error < 0)
817
706
  goto error;
818
707
  if (across_fs)
@@ -825,7 +714,7 @@ static int _git_repository_open_ext_from_env(
825
714
  else if (error < 0)
826
715
  goto error;
827
716
  else {
828
- error = git_index_open(&index, git_buf_cstr(&index_file_buf));
717
+ error = git_index_open(&index, git_str_cstr(&index_file_buf));
829
718
  if (error < 0)
830
719
  goto error;
831
720
  }
@@ -842,7 +731,7 @@ static int _git_repository_open_ext_from_env(
842
731
  else if (error < 0)
843
732
  goto error;
844
733
  else {
845
- error = git_odb_open(&odb, git_buf_cstr(&object_dir_buf));
734
+ error = git_odb_open(&odb, git_str_cstr(&object_dir_buf));
846
735
  if (error < 0)
847
736
  goto error;
848
737
  }
@@ -891,7 +780,7 @@ static int _git_repository_open_ext_from_env(
891
780
  goto error;
892
781
  }
893
782
 
894
- end = git_buf_cstr(&alts_buf) + git_buf_len(&alts_buf);
783
+ end = git_str_cstr(&alts_buf) + git_str_len(&alts_buf);
895
784
  for (sep = alt = alts_buf.ptr; sep != end; alt = sep+1) {
896
785
  for (sep = alt; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++)
897
786
  ;
@@ -903,8 +792,8 @@ static int _git_repository_open_ext_from_env(
903
792
  }
904
793
  }
905
794
 
906
- if (git_buf_len(&namespace_buf)) {
907
- error = git_repository_set_namespace(repo, git_buf_cstr(&namespace_buf));
795
+ if (git_str_len(&namespace_buf)) {
796
+ error = git_repository_set_namespace(repo, git_str_cstr(&namespace_buf));
908
797
  if (error < 0)
909
798
  goto error;
910
799
  }
@@ -920,21 +809,21 @@ error:
920
809
  success:
921
810
  git_odb_free(odb);
922
811
  git_index_free(index);
923
- git_buf_dispose(&common_dir_buf);
924
- git_buf_dispose(&work_tree_buf);
925
- git_buf_dispose(&alts_buf);
926
- git_buf_dispose(&object_dir_buf);
927
- git_buf_dispose(&namespace_buf);
928
- git_buf_dispose(&index_file_buf);
929
- git_buf_dispose(&across_fs_buf);
930
- git_buf_dispose(&ceiling_dirs_buf);
931
- git_buf_dispose(&dir_buf);
812
+ git_str_dispose(&common_dir_buf);
813
+ git_str_dispose(&work_tree_buf);
814
+ git_str_dispose(&alts_buf);
815
+ git_str_dispose(&object_dir_buf);
816
+ git_str_dispose(&namespace_buf);
817
+ git_str_dispose(&index_file_buf);
818
+ git_str_dispose(&across_fs_buf);
819
+ git_str_dispose(&ceiling_dirs_buf);
820
+ git_str_dispose(&dir_buf);
932
821
  return error;
933
822
  }
934
823
 
935
824
  static int repo_is_worktree(unsigned *out, const git_repository *repo)
936
825
  {
937
- git_buf gitdir_link = GIT_BUF_INIT;
826
+ git_str gitdir_link = GIT_STR_INIT;
938
827
  int error;
939
828
 
940
829
  /* Worktrees cannot have the same commondir and gitdir */
@@ -944,14 +833,14 @@ static int repo_is_worktree(unsigned *out, const git_repository *repo)
944
833
  return 0;
945
834
  }
946
835
 
947
- if ((error = git_buf_joinpath(&gitdir_link, repo->gitdir, "gitdir")) < 0)
836
+ if ((error = git_str_joinpath(&gitdir_link, repo->gitdir, "gitdir")) < 0)
948
837
  return -1;
949
838
 
950
839
  /* A 'gitdir' file inside a git directory is currently
951
840
  * only used when the repository is a working tree. */
952
- *out = !!git_path_exists(gitdir_link.ptr);
841
+ *out = !!git_fs_path_exists(gitdir_link.ptr);
953
842
 
954
- git_buf_dispose(&gitdir_link);
843
+ git_str_dispose(&gitdir_link);
955
844
  return error;
956
845
  }
957
846
 
@@ -963,8 +852,8 @@ int git_repository_open_ext(
963
852
  {
964
853
  int error;
965
854
  unsigned is_worktree;
966
- git_buf gitdir = GIT_BUF_INIT, workdir = GIT_BUF_INIT,
967
- gitlink = GIT_BUF_INIT, commondir = GIT_BUF_INIT;
855
+ git_str gitdir = GIT_STR_INIT, workdir = GIT_STR_INIT,
856
+ gitlink = GIT_STR_INIT, commondir = GIT_STR_INIT;
968
857
  git_repository *repo = NULL;
969
858
  git_config *config = NULL;
970
859
  int version = 0;
@@ -984,15 +873,15 @@ int git_repository_open_ext(
984
873
  repo = repository_alloc();
985
874
  GIT_ERROR_CHECK_ALLOC(repo);
986
875
 
987
- repo->gitdir = git_buf_detach(&gitdir);
876
+ repo->gitdir = git_str_detach(&gitdir);
988
877
  GIT_ERROR_CHECK_ALLOC(repo->gitdir);
989
878
 
990
879
  if (gitlink.size) {
991
- repo->gitlink = git_buf_detach(&gitlink);
880
+ repo->gitlink = git_str_detach(&gitlink);
992
881
  GIT_ERROR_CHECK_ALLOC(repo->gitlink);
993
882
  }
994
883
  if (commondir.size) {
995
- repo->commondir = git_buf_detach(&commondir);
884
+ repo->commondir = git_str_detach(&commondir);
996
885
  GIT_ERROR_CHECK_ALLOC(repo->commondir);
997
886
  }
998
887
 
@@ -1015,28 +904,21 @@ int git_repository_open_ext(
1015
904
  if ((error = check_extensions(config, version)) < 0)
1016
905
  goto cleanup;
1017
906
 
1018
- if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0) {
907
+ if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0)
1019
908
  repo->is_bare = 1;
1020
- } else {
909
+ else {
910
+
1021
911
  if (config &&
1022
912
  ((error = load_config_data(repo, config)) < 0 ||
1023
913
  (error = load_workdir(repo, config, &workdir)) < 0))
1024
914
  goto cleanup;
1025
915
  }
1026
916
 
1027
- /*
1028
- * Ensure that the git directory and worktree are
1029
- * owned by the current user.
1030
- */
1031
- if (git_repository__validate_ownership &&
1032
- (error = validate_ownership(repo)) < 0)
1033
- goto cleanup;
1034
-
1035
917
  cleanup:
1036
- git_buf_dispose(&gitdir);
1037
- git_buf_dispose(&workdir);
1038
- git_buf_dispose(&gitlink);
1039
- git_buf_dispose(&commondir);
918
+ git_str_dispose(&gitdir);
919
+ git_str_dispose(&workdir);
920
+ git_str_dispose(&gitlink);
921
+ git_str_dispose(&commondir);
1040
922
  git_config_free(config);
1041
923
 
1042
924
  if (error < 0)
@@ -1055,7 +937,7 @@ int git_repository_open(git_repository **repo_out, const char *path)
1055
937
 
1056
938
  int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *wt)
1057
939
  {
1058
- git_buf path = GIT_BUF_INIT;
940
+ git_str path = GIT_STR_INIT;
1059
941
  git_repository *repo = NULL;
1060
942
  size_t len;
1061
943
  int err;
@@ -1071,7 +953,7 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
1071
953
  goto out;
1072
954
  }
1073
955
 
1074
- if ((err = git_buf_set(&path, wt->gitlink_path, len - 4)) < 0)
956
+ if ((err = git_str_set(&path, wt->gitlink_path, len - 4)) < 0)
1075
957
  goto out;
1076
958
 
1077
959
  if ((err = git_repository_open(&repo, path.ptr)) < 0)
@@ -1080,7 +962,7 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
1080
962
  *repo_out = repo;
1081
963
 
1082
964
  out:
1083
- git_buf_dispose(&path);
965
+ git_str_dispose(&path);
1084
966
 
1085
967
  return err;
1086
968
  }
@@ -1105,14 +987,10 @@ int git_repository_discover(
1105
987
  const char *ceiling_dirs)
1106
988
  {
1107
989
  uint32_t flags = across_fs ? GIT_REPOSITORY_OPEN_CROSS_FS : 0;
1108
- int error;
1109
990
 
1110
991
  GIT_ASSERT_ARG(start_path);
1111
992
 
1112
- if ((error = git_buf_sanitize(out)) < 0)
1113
- return error;
1114
-
1115
- return find_repo(out, NULL, NULL, NULL, start_path, flags, ceiling_dirs);
993
+ GIT_BUF_WRAP_PRIVATE(out, find_repo, NULL, NULL, NULL, start_path, flags, ceiling_dirs);
1116
994
  }
1117
995
 
1118
996
  static int load_config(
@@ -1124,7 +1002,7 @@ static int load_config(
1124
1002
  const char *programdata_path)
1125
1003
  {
1126
1004
  int error;
1127
- git_buf config_path = GIT_BUF_INIT;
1005
+ git_str config_path = GIT_STR_INIT;
1128
1006
  git_config *cfg = NULL;
1129
1007
 
1130
1008
  GIT_ASSERT_ARG(out);
@@ -1133,13 +1011,13 @@ static int load_config(
1133
1011
  return error;
1134
1012
 
1135
1013
  if (repo) {
1136
- if ((error = git_repository_item_path(&config_path, repo, GIT_REPOSITORY_ITEM_CONFIG)) == 0)
1014
+ if ((error = git_repository__item_path(&config_path, repo, GIT_REPOSITORY_ITEM_CONFIG)) == 0)
1137
1015
  error = git_config_add_file_ondisk(cfg, config_path.ptr, GIT_CONFIG_LEVEL_LOCAL, repo, 0);
1138
1016
 
1139
1017
  if (error && error != GIT_ENOTFOUND)
1140
1018
  goto on_error;
1141
1019
 
1142
- git_buf_dispose(&config_path);
1020
+ git_str_dispose(&config_path);
1143
1021
  }
1144
1022
 
1145
1023
  if (global_config_path != NULL &&
@@ -1172,15 +1050,15 @@ static int load_config(
1172
1050
  return 0;
1173
1051
 
1174
1052
  on_error:
1175
- git_buf_dispose(&config_path);
1053
+ git_str_dispose(&config_path);
1176
1054
  git_config_free(cfg);
1177
1055
  *out = NULL;
1178
1056
  return error;
1179
1057
  }
1180
1058
 
1181
- static const char *path_unless_empty(git_buf *buf)
1059
+ static const char *path_unless_empty(git_str *buf)
1182
1060
  {
1183
- return git_buf_len(buf) > 0 ? git_buf_cstr(buf) : NULL;
1061
+ return git_str_len(buf) > 0 ? git_str_cstr(buf) : NULL;
1184
1062
  }
1185
1063
 
1186
1064
  int git_repository_config__weakptr(git_config **out, git_repository *repo)
@@ -1188,19 +1066,19 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
1188
1066
  int error = 0;
1189
1067
 
1190
1068
  if (repo->_config == NULL) {
1191
- git_buf global_buf = GIT_BUF_INIT;
1192
- git_buf xdg_buf = GIT_BUF_INIT;
1193
- git_buf system_buf = GIT_BUF_INIT;
1194
- git_buf programdata_buf = GIT_BUF_INIT;
1069
+ git_str global_buf = GIT_STR_INIT;
1070
+ git_str xdg_buf = GIT_STR_INIT;
1071
+ git_str system_buf = GIT_STR_INIT;
1072
+ git_str programdata_buf = GIT_STR_INIT;
1195
1073
  git_config *config;
1196
1074
 
1197
- git_config_find_global(&global_buf);
1198
- git_config_find_xdg(&xdg_buf);
1199
- git_config_find_system(&system_buf);
1200
- git_config_find_programdata(&programdata_buf);
1075
+ git_config__find_global(&global_buf);
1076
+ git_config__find_xdg(&xdg_buf);
1077
+ git_config__find_system(&system_buf);
1078
+ git_config__find_programdata(&programdata_buf);
1201
1079
 
1202
1080
  /* If there is no global file, open a backend for it anyway */
1203
- if (git_buf_len(&global_buf) == 0)
1081
+ if (git_str_len(&global_buf) == 0)
1204
1082
  git_config__global_location(&global_buf);
1205
1083
 
1206
1084
  error = load_config(
@@ -1218,10 +1096,10 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
1218
1096
  }
1219
1097
  }
1220
1098
 
1221
- git_buf_dispose(&global_buf);
1222
- git_buf_dispose(&xdg_buf);
1223
- git_buf_dispose(&system_buf);
1224
- git_buf_dispose(&programdata_buf);
1099
+ git_str_dispose(&global_buf);
1100
+ git_str_dispose(&xdg_buf);
1101
+ git_str_dispose(&system_buf);
1102
+ git_str_dispose(&programdata_buf);
1225
1103
  }
1226
1104
 
1227
1105
  *out = repo->_config;
@@ -1266,10 +1144,10 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
1266
1144
 
1267
1145
  *out = git_atomic_load(repo->_odb);
1268
1146
  if (*out == NULL) {
1269
- git_buf odb_path = GIT_BUF_INIT;
1147
+ git_str odb_path = GIT_STR_INIT;
1270
1148
  git_odb *odb;
1271
1149
 
1272
- if ((error = git_repository_item_path(&odb_path, repo,
1150
+ if ((error = git_repository__item_path(&odb_path, repo,
1273
1151
  GIT_REPOSITORY_ITEM_OBJECTS)) < 0 ||
1274
1152
  (error = git_odb_new(&odb)) < 0)
1275
1153
  return error;
@@ -1287,7 +1165,7 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
1287
1165
  git_odb_free(odb);
1288
1166
  }
1289
1167
 
1290
- git_buf_dispose(&odb_path);
1168
+ git_str_dispose(&odb_path);
1291
1169
  *out = git_atomic_load(repo->_odb);
1292
1170
  }
1293
1171
 
@@ -1363,10 +1241,10 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
1363
1241
  GIT_ASSERT_ARG(repo);
1364
1242
 
1365
1243
  if (repo->_index == NULL) {
1366
- git_buf index_path = GIT_BUF_INIT;
1244
+ git_str index_path = GIT_STR_INIT;
1367
1245
  git_index *index;
1368
1246
 
1369
- if ((error = git_buf_joinpath(&index_path, repo->gitdir, GIT_INDEX_FILE)) < 0)
1247
+ if ((error = git_str_joinpath(&index_path, repo->gitdir, GIT_INDEX_FILE)) < 0)
1370
1248
  return error;
1371
1249
 
1372
1250
  error = git_index_open(&index, index_path.ptr);
@@ -1382,7 +1260,7 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
1382
1260
  GIT_INDEX_CAPABILITY_FROM_OWNER);
1383
1261
  }
1384
1262
 
1385
- git_buf_dispose(&index_path);
1263
+ git_str_dispose(&index_path);
1386
1264
  }
1387
1265
 
1388
1266
  *out = repo->_index;
@@ -1430,7 +1308,7 @@ static int reserved_names_add8dot3(git_repository *repo, const char *path)
1430
1308
  const char *def_dot_git = DOT_GIT;
1431
1309
  size_t name_len, def_len = CONST_STRLEN(GIT_DIR_SHORTNAME);
1432
1310
  size_t def_dot_git_len = CONST_STRLEN(DOT_GIT);
1433
- git_buf *buf;
1311
+ git_str *buf;
1434
1312
 
1435
1313
  if (!name)
1436
1314
  return 0;
@@ -1446,17 +1324,17 @@ static int reserved_names_add8dot3(git_repository *repo, const char *path)
1446
1324
  if ((buf = git_array_alloc(repo->reserved_names)) == NULL)
1447
1325
  return -1;
1448
1326
 
1449
- git_buf_attach(buf, name, name_len);
1327
+ git_str_attach(buf, name, name_len);
1450
1328
  return true;
1451
1329
  }
1452
1330
 
1453
1331
  bool git_repository__reserved_names(
1454
- git_buf **out, size_t *outlen, git_repository *repo, bool include_ntfs)
1332
+ git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs)
1455
1333
  {
1456
1334
  GIT_UNUSED(include_ntfs);
1457
1335
 
1458
1336
  if (repo->reserved_names.size == 0) {
1459
- git_buf *buf;
1337
+ git_str *buf;
1460
1338
  size_t i;
1461
1339
 
1462
1340
  /* Add the static defaults */
@@ -1508,7 +1386,7 @@ on_error:
1508
1386
  }
1509
1387
  #else
1510
1388
  bool git_repository__reserved_names(
1511
- git_buf **out, size_t *outlen, git_repository *repo, bool include_ntfs)
1389
+ git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs)
1512
1390
  {
1513
1391
  GIT_UNUSED(repo);
1514
1392
 
@@ -1554,7 +1432,7 @@ static git_vector user_extensions = GIT_VECTOR_INIT;
1554
1432
 
1555
1433
  static int check_valid_extension(const git_config_entry *entry, void *payload)
1556
1434
  {
1557
- git_buf cfg = GIT_BUF_INIT;
1435
+ git_str cfg = GIT_STR_INIT;
1558
1436
  bool reject;
1559
1437
  const char *extension;
1560
1438
  size_t i;
@@ -1563,7 +1441,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
1563
1441
  GIT_UNUSED(payload);
1564
1442
 
1565
1443
  git_vector_foreach (&user_extensions, i, extension) {
1566
- git_buf_clear(&cfg);
1444
+ git_str_clear(&cfg);
1567
1445
 
1568
1446
  /*
1569
1447
  * Users can specify that they don't want to support an
@@ -1572,7 +1450,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
1572
1450
  if ((reject = (extension[0] == '!')) == true)
1573
1451
  extension = &extension[1];
1574
1452
 
1575
- if ((error = git_buf_printf(&cfg, "extensions.%s", extension)) < 0)
1453
+ if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0)
1576
1454
  goto done;
1577
1455
 
1578
1456
  if (strcmp(entry->name, cfg.ptr) == 0) {
@@ -1586,7 +1464,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
1586
1464
  for (i = 0; i < ARRAY_SIZE(builtin_extensions); i++) {
1587
1465
  extension = builtin_extensions[i];
1588
1466
 
1589
- if ((error = git_buf_printf(&cfg, "extensions.%s", extension)) < 0)
1467
+ if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0)
1590
1468
  goto done;
1591
1469
 
1592
1470
  if (strcmp(entry->name, cfg.ptr) == 0)
@@ -1598,7 +1476,7 @@ fail:
1598
1476
  error = -1;
1599
1477
 
1600
1478
  done:
1601
- git_buf_dispose(&cfg);
1479
+ git_str_dispose(&cfg);
1602
1480
  return error;
1603
1481
  }
1604
1482
 
@@ -1676,12 +1554,12 @@ void git_repository__free_extensions(void)
1676
1554
 
1677
1555
  int git_repository_create_head(const char *git_dir, const char *ref_name)
1678
1556
  {
1679
- git_buf ref_path = GIT_BUF_INIT;
1557
+ git_str ref_path = GIT_STR_INIT;
1680
1558
  git_filebuf ref = GIT_FILEBUF_INIT;
1681
1559
  const char *fmt;
1682
1560
  int error;
1683
1561
 
1684
- if ((error = git_buf_joinpath(&ref_path, git_dir, GIT_HEAD_FILE)) < 0 ||
1562
+ if ((error = git_str_joinpath(&ref_path, git_dir, GIT_HEAD_FILE)) < 0 ||
1685
1563
  (error = git_filebuf_open(&ref, ref_path.ptr, 0, GIT_REFS_FILE_MODE)) < 0)
1686
1564
  goto out;
1687
1565
 
@@ -1695,7 +1573,7 @@ int git_repository_create_head(const char *git_dir, const char *ref_name)
1695
1573
  goto out;
1696
1574
 
1697
1575
  out:
1698
- git_buf_dispose(&ref_path);
1576
+ git_str_dispose(&ref_path);
1699
1577
  git_filebuf_cleanup(&ref);
1700
1578
  return error;
1701
1579
  }
@@ -1718,50 +1596,23 @@ static bool is_chmod_supported(const char *file_path)
1718
1596
 
1719
1597
  static bool is_filesystem_case_insensitive(const char *gitdir_path)
1720
1598
  {
1721
- git_buf path = GIT_BUF_INIT;
1599
+ git_str path = GIT_STR_INIT;
1722
1600
  int is_insensitive = -1;
1723
1601
 
1724
- if (!git_buf_joinpath(&path, gitdir_path, "CoNfIg"))
1725
- is_insensitive = git_path_exists(git_buf_cstr(&path));
1602
+ if (!git_str_joinpath(&path, gitdir_path, "CoNfIg"))
1603
+ is_insensitive = git_fs_path_exists(git_str_cstr(&path));
1726
1604
 
1727
- git_buf_dispose(&path);
1605
+ git_str_dispose(&path);
1728
1606
  return is_insensitive;
1729
1607
  }
1730
1608
 
1731
- /*
1732
- * Return a configuration object with only the global and system
1733
- * configurations; no repository-level configuration.
1734
- */
1735
- static int load_global_config(git_config **config)
1736
- {
1737
- git_buf global_buf = GIT_BUF_INIT;
1738
- git_buf xdg_buf = GIT_BUF_INIT;
1739
- git_buf system_buf = GIT_BUF_INIT;
1740
- git_buf programdata_buf = GIT_BUF_INIT;
1741
- int error;
1742
-
1743
- git_config_find_global(&global_buf);
1744
- git_config_find_xdg(&xdg_buf);
1745
- git_config_find_system(&system_buf);
1746
- git_config_find_programdata(&programdata_buf);
1747
-
1748
- error = load_config(config, NULL,
1749
- path_unless_empty(&global_buf),
1750
- path_unless_empty(&xdg_buf),
1751
- path_unless_empty(&system_buf),
1752
- path_unless_empty(&programdata_buf));
1753
-
1754
- git_buf_dispose(&global_buf);
1755
- git_buf_dispose(&xdg_buf);
1756
- git_buf_dispose(&system_buf);
1757
- git_buf_dispose(&programdata_buf);
1758
-
1759
- return error;
1760
- }
1761
-
1762
1609
  static bool are_symlinks_supported(const char *wd_path)
1763
1610
  {
1764
1611
  git_config *config = NULL;
1612
+ git_str global_buf = GIT_STR_INIT;
1613
+ git_str xdg_buf = GIT_STR_INIT;
1614
+ git_str system_buf = GIT_STR_INIT;
1615
+ git_str programdata_buf = GIT_STR_INIT;
1765
1616
  int symlinks = 0;
1766
1617
 
1767
1618
  /*
@@ -1772,16 +1623,30 @@ static bool are_symlinks_supported(const char *wd_path)
1772
1623
  * _not_ set, then we do not test or enable symlink support.
1773
1624
  */
1774
1625
  #ifdef GIT_WIN32
1775
- if (load_global_config(&config) < 0 ||
1776
- git_config_get_bool(&symlinks, config, "core.symlinks") < 0 ||
1777
- !symlinks)
1626
+ git_config__find_global(&global_buf);
1627
+ git_config__find_xdg(&xdg_buf);
1628
+ git_config__find_system(&system_buf);
1629
+ git_config__find_programdata(&programdata_buf);
1630
+
1631
+ if (load_config(&config, NULL,
1632
+ path_unless_empty(&global_buf),
1633
+ path_unless_empty(&xdg_buf),
1634
+ path_unless_empty(&system_buf),
1635
+ path_unless_empty(&programdata_buf)) < 0)
1636
+ goto done;
1637
+
1638
+ if (git_config_get_bool(&symlinks, config, "core.symlinks") < 0 || !symlinks)
1778
1639
  goto done;
1779
1640
  #endif
1780
1641
 
1781
- if (!(symlinks = git_path_supports_symlinks(wd_path)))
1642
+ if (!(symlinks = git_fs_path_supports_symlinks(wd_path)))
1782
1643
  goto done;
1783
1644
 
1784
1645
  done:
1646
+ git_str_dispose(&global_buf);
1647
+ git_str_dispose(&xdg_buf);
1648
+ git_str_dispose(&system_buf);
1649
+ git_str_dispose(&programdata_buf);
1785
1650
  git_config_free(config);
1786
1651
  return symlinks != 0;
1787
1652
  }
@@ -1805,7 +1670,7 @@ static int create_empty_file(const char *path, mode_t mode)
1805
1670
 
1806
1671
  static int repo_local_config(
1807
1672
  git_config **out,
1808
- git_buf *config_dir,
1673
+ git_str *config_dir,
1809
1674
  git_repository *repo,
1810
1675
  const char *repo_dir)
1811
1676
  {
@@ -1813,12 +1678,12 @@ static int repo_local_config(
1813
1678
  git_config *parent;
1814
1679
  const char *cfg_path;
1815
1680
 
1816
- if (git_buf_joinpath(config_dir, repo_dir, GIT_CONFIG_FILENAME_INREPO) < 0)
1681
+ if (git_str_joinpath(config_dir, repo_dir, GIT_CONFIG_FILENAME_INREPO) < 0)
1817
1682
  return -1;
1818
- cfg_path = git_buf_cstr(config_dir);
1683
+ cfg_path = git_str_cstr(config_dir);
1819
1684
 
1820
1685
  /* make LOCAL config if missing */
1821
- if (!git_path_isfile(cfg_path) &&
1686
+ if (!git_fs_path_isfile(cfg_path) &&
1822
1687
  (error = create_empty_file(cfg_path, GIT_CONFIG_FILE_MODE)) < 0)
1823
1688
  return error;
1824
1689
 
@@ -1876,7 +1741,7 @@ static int repo_init_fs_configs(
1876
1741
  #ifdef GIT_USE_ICONV
1877
1742
  if ((error = git_config_set_bool(
1878
1743
  cfg, "core.precomposeunicode",
1879
- git_path_does_fs_decompose_unicode(work_dir))) < 0)
1744
+ git_fs_path_does_decompose_unicode(work_dir))) < 0)
1880
1745
  return error;
1881
1746
  /* on non-iconv platforms, don't even set core.precomposeunicode */
1882
1747
  #endif
@@ -1891,7 +1756,7 @@ static int repo_init_config(
1891
1756
  uint32_t mode)
1892
1757
  {
1893
1758
  int error = 0;
1894
- git_buf cfg_path = GIT_BUF_INIT, worktree_path = GIT_BUF_INIT;
1759
+ git_str cfg_path = GIT_STR_INIT, worktree_path = GIT_STR_INIT;
1895
1760
  git_config *config = NULL;
1896
1761
  bool is_bare = ((flags & GIT_REPOSITORY_INIT_BARE) != 0);
1897
1762
  bool is_reinit = ((flags & GIT_REPOSITORY_INIT__IS_REINIT) != 0);
@@ -1921,11 +1786,11 @@ static int repo_init_config(
1921
1786
  SET_REPO_CONFIG(bool, "core.logallrefupdates", true);
1922
1787
 
1923
1788
  if (!(flags & GIT_REPOSITORY_INIT__NATURAL_WD)) {
1924
- if ((error = git_buf_sets(&worktree_path, work_dir)) < 0)
1789
+ if ((error = git_str_sets(&worktree_path, work_dir)) < 0)
1925
1790
  goto cleanup;
1926
1791
 
1927
1792
  if ((flags & GIT_REPOSITORY_INIT_RELATIVE_GITLINK))
1928
- if ((error = git_path_make_relative(&worktree_path, repo_dir)) < 0)
1793
+ if ((error = git_fs_path_make_relative(&worktree_path, repo_dir)) < 0)
1929
1794
  goto cleanup;
1930
1795
 
1931
1796
  SET_REPO_CONFIG(string, "core.worktree", worktree_path.ptr);
@@ -1945,8 +1810,8 @@ static int repo_init_config(
1945
1810
  }
1946
1811
 
1947
1812
  cleanup:
1948
- git_buf_dispose(&cfg_path);
1949
- git_buf_dispose(&worktree_path);
1813
+ git_str_dispose(&cfg_path);
1814
+ git_str_dispose(&worktree_path);
1950
1815
  git_config_free(config);
1951
1816
 
1952
1817
  return error;
@@ -1968,7 +1833,7 @@ static int repo_reinit_submodule_fs(git_submodule *sm, const char *n, void *p)
1968
1833
  int git_repository_reinit_filesystem(git_repository *repo, int recurse)
1969
1834
  {
1970
1835
  int error = 0;
1971
- git_buf path = GIT_BUF_INIT;
1836
+ git_str path = GIT_STR_INIT;
1972
1837
  git_config *config = NULL;
1973
1838
  const char *repo_dir = git_repository_path(repo);
1974
1839
 
@@ -1977,7 +1842,7 @@ int git_repository_reinit_filesystem(git_repository *repo, int recurse)
1977
1842
  config, path.ptr, repo_dir, git_repository_workdir(repo), true);
1978
1843
 
1979
1844
  git_config_free(config);
1980
- git_buf_dispose(&path);
1845
+ git_str_dispose(&path);
1981
1846
 
1982
1847
  git_repository__configmap_lookup_cache_clear(repo);
1983
1848
 
@@ -1995,10 +1860,10 @@ static int repo_write_template(
1995
1860
  bool hidden,
1996
1861
  const char *content)
1997
1862
  {
1998
- git_buf path = GIT_BUF_INIT;
1863
+ git_str path = GIT_STR_INIT;
1999
1864
  int fd, error = 0, flags;
2000
1865
 
2001
- if (git_buf_joinpath(&path, git_dir, file) < 0)
1866
+ if (git_str_joinpath(&path, git_dir, file) < 0)
2002
1867
  return -1;
2003
1868
 
2004
1869
  if (allow_overwrite)
@@ -2006,7 +1871,7 @@ static int repo_write_template(
2006
1871
  else
2007
1872
  flags = O_WRONLY | O_CREAT | O_EXCL;
2008
1873
 
2009
- fd = p_open(git_buf_cstr(&path), flags, mode);
1874
+ fd = p_open(git_str_cstr(&path), flags, mode);
2010
1875
 
2011
1876
  if (fd >= 0) {
2012
1877
  error = p_write(fd, content, strlen(content));
@@ -2025,7 +1890,7 @@ static int repo_write_template(
2025
1890
  GIT_UNUSED(hidden);
2026
1891
  #endif
2027
1892
 
2028
- git_buf_dispose(&path);
1893
+ git_str_dispose(&path);
2029
1894
 
2030
1895
  if (error)
2031
1896
  git_error_set(GIT_ERROR_OS,
@@ -2038,13 +1903,13 @@ static int repo_write_gitlink(
2038
1903
  const char *in_dir, const char *to_repo, bool use_relative_path)
2039
1904
  {
2040
1905
  int error;
2041
- git_buf buf = GIT_BUF_INIT;
2042
- git_buf path_to_repo = GIT_BUF_INIT;
1906
+ git_str buf = GIT_STR_INIT;
1907
+ git_str path_to_repo = GIT_STR_INIT;
2043
1908
  struct stat st;
2044
1909
 
2045
- git_path_dirname_r(&buf, to_repo);
2046
- git_path_to_dir(&buf);
2047
- if (git_buf_oom(&buf))
1910
+ git_fs_path_dirname_r(&buf, to_repo);
1911
+ git_fs_path_to_dir(&buf);
1912
+ if (git_str_oom(&buf))
2048
1913
  return -1;
2049
1914
 
2050
1915
  /* don't write gitlink to natural workdir */
@@ -2055,7 +1920,7 @@ static int repo_write_gitlink(
2055
1920
  goto cleanup;
2056
1921
  }
2057
1922
 
2058
- if ((error = git_buf_joinpath(&buf, in_dir, DOT_GIT)) < 0)
1923
+ if ((error = git_str_joinpath(&buf, in_dir, DOT_GIT)) < 0)
2059
1924
  goto cleanup;
2060
1925
 
2061
1926
  if (!p_stat(buf.ptr, &st) && !S_ISREG(st.st_mode)) {
@@ -2065,22 +1930,22 @@ static int repo_write_gitlink(
2065
1930
  goto cleanup;
2066
1931
  }
2067
1932
 
2068
- git_buf_clear(&buf);
1933
+ git_str_clear(&buf);
2069
1934
 
2070
- error = git_buf_sets(&path_to_repo, to_repo);
1935
+ error = git_str_sets(&path_to_repo, to_repo);
2071
1936
 
2072
1937
  if (!error && use_relative_path)
2073
- error = git_path_make_relative(&path_to_repo, in_dir);
1938
+ error = git_fs_path_make_relative(&path_to_repo, in_dir);
2074
1939
 
2075
1940
  if (!error)
2076
- error = git_buf_join(&buf, ' ', GIT_FILE_CONTENT_PREFIX, path_to_repo.ptr);
1941
+ error = git_str_join(&buf, ' ', GIT_FILE_CONTENT_PREFIX, path_to_repo.ptr);
2077
1942
 
2078
1943
  if (!error)
2079
1944
  error = repo_write_template(in_dir, true, DOT_GIT, 0666, true, buf.ptr);
2080
1945
 
2081
1946
  cleanup:
2082
- git_buf_dispose(&buf);
2083
- git_buf_dispose(&path_to_repo);
1947
+ git_str_dispose(&buf);
1948
+ git_str_dispose(&path_to_repo);
2084
1949
  return error;
2085
1950
  }
2086
1951
 
@@ -2133,12 +1998,12 @@ static int repo_init_structure(
2133
1998
  git_config *cfg = NULL;
2134
1999
  const char *tdir = NULL;
2135
2000
  bool default_template = false;
2136
- git_buf template_buf = GIT_BUF_INIT;
2001
+ git_str template_buf = GIT_STR_INIT;
2137
2002
 
2138
2003
  if (opts->template_path)
2139
2004
  tdir = opts->template_path;
2140
2005
  else if ((error = git_config_open_default(&cfg)) >= 0) {
2141
- if (!git_config_get_path(&template_buf, cfg, "init.templatedir"))
2006
+ if (!git_config__get_path(&template_buf, cfg, "init.templatedir"))
2142
2007
  tdir = template_buf.ptr;
2143
2008
  git_error_clear();
2144
2009
  }
@@ -2164,11 +2029,16 @@ static int repo_init_structure(
2164
2029
  error = git_futils_cp_r(tdir, repo_dir, cpflags, dmode);
2165
2030
  }
2166
2031
 
2167
- git_buf_dispose(&template_buf);
2032
+ git_str_dispose(&template_buf);
2168
2033
  git_config_free(cfg);
2169
2034
 
2035
+ /* If tdir does not exist, then do not error out. This matches the
2036
+ * behaviour of git(1), which just prints a warning and continues.
2037
+ * TODO: issue warning when warning API is available.
2038
+ * `git` prints to stderr: 'warning: templates not found in /path/to/tdir'
2039
+ */
2170
2040
  if (error < 0) {
2171
- if (!default_template)
2041
+ if (!default_template && error != GIT_ENOTFOUND)
2172
2042
  return error;
2173
2043
 
2174
2044
  /* if template was default, ignore error and use internal */
@@ -2205,7 +2075,7 @@ static int repo_init_structure(
2205
2075
  return error;
2206
2076
  }
2207
2077
 
2208
- static int mkdir_parent(git_buf *buf, uint32_t mode, bool skip2)
2078
+ static int mkdir_parent(git_str *buf, uint32_t mode, bool skip2)
2209
2079
  {
2210
2080
  /* When making parent directories during repository initialization
2211
2081
  * don't try to set gid or grant world write access
@@ -2217,8 +2087,8 @@ static int mkdir_parent(git_buf *buf, uint32_t mode, bool skip2)
2217
2087
  }
2218
2088
 
2219
2089
  static int repo_init_directories(
2220
- git_buf *repo_path,
2221
- git_buf *wd_path,
2090
+ git_str *repo_path,
2091
+ git_str *wd_path,
2222
2092
  const char *given_repo,
2223
2093
  git_repository_init_options *opts)
2224
2094
  {
@@ -2256,7 +2126,7 @@ static int repo_init_directories(
2256
2126
  git__suffixcmp(given_repo, "/" DOT_GIT) != 0 &&
2257
2127
  git__suffixcmp(given_repo, "/" GIT_DIR) != 0;
2258
2128
 
2259
- if (git_buf_joinpath(repo_path, given_repo, add_dotgit ? GIT_DIR : "") < 0)
2129
+ if (git_str_joinpath(repo_path, given_repo, add_dotgit ? GIT_DIR : "") < 0)
2260
2130
  return -1;
2261
2131
 
2262
2132
  has_dotgit = (git__suffixcmp(repo_path->ptr, "/" GIT_DIR) == 0);
@@ -2267,11 +2137,11 @@ static int repo_init_directories(
2267
2137
 
2268
2138
  if (!is_bare) {
2269
2139
  if (opts->workdir_path) {
2270
- if (git_path_join_unrooted(
2140
+ if (git_fs_path_join_unrooted(
2271
2141
  wd_path, opts->workdir_path, repo_path->ptr, NULL) < 0)
2272
2142
  return -1;
2273
2143
  } else if (has_dotgit) {
2274
- if (git_path_dirname_r(wd_path, repo_path->ptr) < 0)
2144
+ if (git_fs_path_dirname_r(wd_path, repo_path->ptr) < 0)
2275
2145
  return -1;
2276
2146
  } else {
2277
2147
  git_error_set(GIT_ERROR_REPOSITORY, "cannot pick working directory"
@@ -2279,10 +2149,10 @@ static int repo_init_directories(
2279
2149
  return -1;
2280
2150
  }
2281
2151
 
2282
- if (git_path_to_dir(wd_path) < 0)
2152
+ if (git_fs_path_to_dir(wd_path) < 0)
2283
2153
  return -1;
2284
2154
  } else {
2285
- git_buf_clear(wd_path);
2155
+ git_str_clear(wd_path);
2286
2156
  }
2287
2157
 
2288
2158
  natural_wd =
@@ -2339,10 +2209,10 @@ static int repo_init_directories(
2339
2209
  /* prettify both directories now that they are created */
2340
2210
 
2341
2211
  if (!error) {
2342
- error = git_path_prettify_dir(repo_path, repo_path->ptr, NULL);
2212
+ error = git_fs_path_prettify_dir(repo_path, repo_path->ptr, NULL);
2343
2213
 
2344
2214
  if (!error && wd_path->size > 0)
2345
- error = git_path_prettify_dir(wd_path, wd_path->ptr, NULL);
2215
+ error = git_fs_path_prettify_dir(wd_path, wd_path->ptr, NULL);
2346
2216
  }
2347
2217
 
2348
2218
  return error;
@@ -2351,24 +2221,24 @@ static int repo_init_directories(
2351
2221
  static int repo_init_head(const char *repo_dir, const char *given)
2352
2222
  {
2353
2223
  git_config *cfg = NULL;
2354
- git_buf head_path = GIT_BUF_INIT, cfg_branch = GIT_BUF_INIT;
2224
+ git_str head_path = GIT_STR_INIT, cfg_branch = GIT_STR_INIT;
2355
2225
  const char *initial_head = NULL;
2356
2226
  int error;
2357
2227
 
2358
- if ((error = git_buf_joinpath(&head_path, repo_dir, GIT_HEAD_FILE)) < 0)
2228
+ if ((error = git_str_joinpath(&head_path, repo_dir, GIT_HEAD_FILE)) < 0)
2359
2229
  goto out;
2360
2230
 
2361
2231
  /*
2362
2232
  * A template may have set a HEAD; use that unless it's been
2363
2233
  * overridden by the caller's given initial head setting.
2364
2234
  */
2365
- if (git_path_exists(head_path.ptr) && !given)
2235
+ if (git_fs_path_exists(head_path.ptr) && !given)
2366
2236
  goto out;
2367
2237
 
2368
2238
  if (given) {
2369
2239
  initial_head = given;
2370
2240
  } else if ((error = git_config_open_default(&cfg)) >= 0 &&
2371
- (error = git_config_get_string_buf(&cfg_branch, cfg, "init.defaultbranch")) >= 0 &&
2241
+ (error = git_config__get_string_buf(&cfg_branch, cfg, "init.defaultbranch")) >= 0 &&
2372
2242
  *cfg_branch.ptr) {
2373
2243
  initial_head = cfg_branch.ptr;
2374
2244
  }
@@ -2380,8 +2250,8 @@ static int repo_init_head(const char *repo_dir, const char *given)
2380
2250
 
2381
2251
  out:
2382
2252
  git_config_free(cfg);
2383
- git_buf_dispose(&head_path);
2384
- git_buf_dispose(&cfg_branch);
2253
+ git_str_dispose(&head_path);
2254
+ git_str_dispose(&cfg_branch);
2385
2255
 
2386
2256
  return error;
2387
2257
  }
@@ -2415,8 +2285,8 @@ int git_repository_init_ext(
2415
2285
  const char *given_repo,
2416
2286
  git_repository_init_options *opts)
2417
2287
  {
2418
- git_buf repo_path = GIT_BUF_INIT, wd_path = GIT_BUF_INIT,
2419
- common_path = GIT_BUF_INIT;
2288
+ git_str repo_path = GIT_STR_INIT, wd_path = GIT_STR_INIT,
2289
+ common_path = GIT_STR_INIT;
2420
2290
  const char *wd;
2421
2291
  bool is_valid;
2422
2292
  int error;
@@ -2430,7 +2300,7 @@ int git_repository_init_ext(
2430
2300
  if ((error = repo_init_directories(&repo_path, &wd_path, given_repo, opts)) < 0)
2431
2301
  goto out;
2432
2302
 
2433
- wd = (opts->flags & GIT_REPOSITORY_INIT_BARE) ? NULL : git_buf_cstr(&wd_path);
2303
+ wd = (opts->flags & GIT_REPOSITORY_INIT_BARE) ? NULL : git_str_cstr(&wd_path);
2434
2304
 
2435
2305
  if ((error = is_valid_repository_path(&is_valid, &repo_path, &common_path)) < 0)
2436
2306
  goto out;
@@ -2464,9 +2334,9 @@ int git_repository_init_ext(
2464
2334
  goto out;
2465
2335
 
2466
2336
  out:
2467
- git_buf_dispose(&common_path);
2468
- git_buf_dispose(&repo_path);
2469
- git_buf_dispose(&wd_path);
2337
+ git_str_dispose(&common_path);
2338
+ git_str_dispose(&repo_path);
2339
+ git_str_dispose(&wd_path);
2470
2340
 
2471
2341
  return error;
2472
2342
  }
@@ -2654,7 +2524,7 @@ static int repo_contains_no_reference(git_repository *repo)
2654
2524
  return error;
2655
2525
  }
2656
2526
 
2657
- int git_repository_initialbranch(git_buf *out, git_repository *repo)
2527
+ int git_repository_initialbranch(git_str *out, git_repository *repo)
2658
2528
  {
2659
2529
  git_config *config;
2660
2530
  git_config_entry *entry = NULL;
@@ -2675,8 +2545,8 @@ int git_repository_initialbranch(git_buf *out, git_repository *repo)
2675
2545
  goto done;
2676
2546
  }
2677
2547
 
2678
- if ((error = git_buf_puts(out, GIT_REFS_HEADS_DIR)) < 0 ||
2679
- (error = git_buf_puts(out, branch)) < 0 ||
2548
+ if ((error = git_str_puts(out, GIT_REFS_HEADS_DIR)) < 0 ||
2549
+ (error = git_str_puts(out, branch)) < 0 ||
2680
2550
  (error = git_reference_name_is_valid(&valid, out->ptr)) < 0)
2681
2551
  goto done;
2682
2552
 
@@ -2693,7 +2563,7 @@ done:
2693
2563
  int git_repository_is_empty(git_repository *repo)
2694
2564
  {
2695
2565
  git_reference *head = NULL;
2696
- git_buf initialbranch = GIT_BUF_INIT;
2566
+ git_str initialbranch = GIT_STR_INIT;
2697
2567
  int result = 0;
2698
2568
 
2699
2569
  if ((result = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0 ||
@@ -2706,7 +2576,7 @@ int git_repository_is_empty(git_repository *repo)
2706
2576
 
2707
2577
  done:
2708
2578
  git_reference_free(head);
2709
- git_buf_dispose(&initialbranch);
2579
+ git_str_dispose(&initialbranch);
2710
2580
 
2711
2581
  return result;
2712
2582
  }
@@ -2735,7 +2605,18 @@ static const char *resolved_parent_path(const git_repository *repo, git_reposito
2735
2605
  return parent;
2736
2606
  }
2737
2607
 
2738
- int git_repository_item_path(git_buf *out, const git_repository *repo, git_repository_item_t item)
2608
+ int git_repository_item_path(
2609
+ git_buf *out,
2610
+ const git_repository *repo,
2611
+ git_repository_item_t item)
2612
+ {
2613
+ GIT_BUF_WRAP_PRIVATE(out, git_repository__item_path, repo, item);
2614
+ }
2615
+
2616
+ int git_repository__item_path(
2617
+ git_str *out,
2618
+ const git_repository *repo,
2619
+ git_repository_item_t item)
2739
2620
  {
2740
2621
  const char *parent = resolved_parent_path(repo, items[item].parent, items[item].fallback);
2741
2622
  if (parent == NULL) {
@@ -2743,16 +2624,16 @@ int git_repository_item_path(git_buf *out, const git_repository *repo, git_repos
2743
2624
  return GIT_ENOTFOUND;
2744
2625
  }
2745
2626
 
2746
- if (git_buf_sets(out, parent) < 0)
2627
+ if (git_str_sets(out, parent) < 0)
2747
2628
  return -1;
2748
2629
 
2749
2630
  if (items[item].name) {
2750
- if (git_buf_joinpath(out, parent, items[item].name) < 0)
2631
+ if (git_str_joinpath(out, parent, items[item].name) < 0)
2751
2632
  return -1;
2752
2633
  }
2753
2634
 
2754
2635
  if (items[item].directory) {
2755
- if (git_path_to_dir(out) < 0)
2636
+ if (git_fs_path_to_dir(out) < 0)
2756
2637
  return -1;
2757
2638
  }
2758
2639
 
@@ -2776,7 +2657,7 @@ const char *git_repository_workdir(const git_repository *repo)
2776
2657
  }
2777
2658
 
2778
2659
  int git_repository_workdir_path(
2779
- git_buf *out, git_repository *repo, const char *path)
2660
+ git_str *out, git_repository *repo, const char *path)
2780
2661
  {
2781
2662
  int error;
2782
2663
 
@@ -2785,8 +2666,8 @@ int git_repository_workdir_path(
2785
2666
  return GIT_EBAREREPO;
2786
2667
  }
2787
2668
 
2788
- if (!(error = git_buf_joinpath(out, repo->workdir, path)))
2789
- error = git_path_validate_workdir_buf(repo, out);
2669
+ if (!(error = git_str_joinpath(out, repo->workdir, path)))
2670
+ error = git_path_validate_str_length(repo, out);
2790
2671
 
2791
2672
  return error;
2792
2673
  }
@@ -2801,12 +2682,12 @@ int git_repository_set_workdir(
2801
2682
  git_repository *repo, const char *workdir, int update_gitlink)
2802
2683
  {
2803
2684
  int error = 0;
2804
- git_buf path = GIT_BUF_INIT;
2685
+ git_str path = GIT_STR_INIT;
2805
2686
 
2806
2687
  GIT_ASSERT_ARG(repo);
2807
2688
  GIT_ASSERT_ARG(workdir);
2808
2689
 
2809
- if (git_path_prettify_dir(&path, workdir, NULL) < 0)
2690
+ if (git_fs_path_prettify_dir(&path, workdir, NULL) < 0)
2810
2691
  return -1;
2811
2692
 
2812
2693
  if (repo->workdir && strcmp(repo->workdir, path.ptr) == 0)
@@ -2833,7 +2714,7 @@ int git_repository_set_workdir(
2833
2714
  if (!error) {
2834
2715
  char *old_workdir = repo->workdir;
2835
2716
 
2836
- repo->workdir = git_buf_detach(&path);
2717
+ repo->workdir = git_str_detach(&path);
2837
2718
  repo->is_bare = 0;
2838
2719
 
2839
2720
  git__free(old_workdir);
@@ -2902,13 +2783,13 @@ cleanup:
2902
2783
  int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head)
2903
2784
  {
2904
2785
  git_filebuf file = GIT_FILEBUF_INIT;
2905
- git_buf file_path = GIT_BUF_INIT;
2786
+ git_str file_path = GIT_STR_INIT;
2906
2787
  char orig_head_str[GIT_OID_HEXSZ];
2907
2788
  int error = 0;
2908
2789
 
2909
2790
  git_oid_fmt(orig_head_str, orig_head);
2910
2791
 
2911
- if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_ORIG_HEAD_FILE)) == 0 &&
2792
+ if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_ORIG_HEAD_FILE)) == 0 &&
2912
2793
  (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) == 0 &&
2913
2794
  (error = git_filebuf_printf(&file, "%.*s\n", GIT_OID_HEXSZ, orig_head_str)) == 0)
2914
2795
  error = git_filebuf_commit(&file);
@@ -2916,46 +2797,48 @@ int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head
2916
2797
  if (error < 0)
2917
2798
  git_filebuf_cleanup(&file);
2918
2799
 
2919
- git_buf_dispose(&file_path);
2800
+ git_str_dispose(&file_path);
2920
2801
 
2921
2802
  return error;
2922
2803
  }
2923
2804
 
2924
- int git_repository_message(git_buf *out, git_repository *repo)
2805
+ static int git_repository__message(git_str *out, git_repository *repo)
2925
2806
  {
2926
- git_buf path = GIT_BUF_INIT;
2807
+ git_str path = GIT_STR_INIT;
2927
2808
  struct stat st;
2928
2809
  int error;
2929
2810
 
2930
- if ((error = git_buf_sanitize(out)) < 0)
2931
- return error;
2932
-
2933
- if (git_buf_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
2811
+ if (git_str_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
2934
2812
  return -1;
2935
2813
 
2936
- if ((error = p_stat(git_buf_cstr(&path), &st)) < 0) {
2814
+ if ((error = p_stat(git_str_cstr(&path), &st)) < 0) {
2937
2815
  if (errno == ENOENT)
2938
2816
  error = GIT_ENOTFOUND;
2939
2817
  git_error_set(GIT_ERROR_OS, "could not access message file");
2940
2818
  } else {
2941
- error = git_futils_readbuffer(out, git_buf_cstr(&path));
2819
+ error = git_futils_readbuffer(out, git_str_cstr(&path));
2942
2820
  }
2943
2821
 
2944
- git_buf_dispose(&path);
2822
+ git_str_dispose(&path);
2945
2823
 
2946
2824
  return error;
2947
2825
  }
2948
2826
 
2827
+ int git_repository_message(git_buf *out, git_repository *repo)
2828
+ {
2829
+ GIT_BUF_WRAP_PRIVATE(out, git_repository__message, repo);
2830
+ }
2831
+
2949
2832
  int git_repository_message_remove(git_repository *repo)
2950
2833
  {
2951
- git_buf path = GIT_BUF_INIT;
2834
+ git_str path = GIT_STR_INIT;
2952
2835
  int error;
2953
2836
 
2954
- if (git_buf_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
2837
+ if (git_str_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
2955
2838
  return -1;
2956
2839
 
2957
- error = p_unlink(git_buf_cstr(&path));
2958
- git_buf_dispose(&path);
2840
+ error = p_unlink(git_str_cstr(&path));
2841
+ git_str_dispose(&path);
2959
2842
 
2960
2843
  return error;
2961
2844
  }
@@ -2971,7 +2854,7 @@ int git_repository_hashfile(
2971
2854
  git_filter_list *fl = NULL;
2972
2855
  git_file fd = -1;
2973
2856
  uint64_t len;
2974
- git_buf full_path = GIT_BUF_INIT;
2857
+ git_str full_path = GIT_STR_INIT;
2975
2858
  const char *workdir = git_repository_workdir(repo);
2976
2859
 
2977
2860
  /* as_path can be NULL */
@@ -2979,8 +2862,8 @@ int git_repository_hashfile(
2979
2862
  GIT_ASSERT_ARG(path);
2980
2863
  GIT_ASSERT_ARG(repo);
2981
2864
 
2982
- if ((error = git_path_join_unrooted(&full_path, path, workdir, NULL)) < 0 ||
2983
- (error = git_path_validate_workdir_buf(repo, &full_path)) < 0)
2865
+ if ((error = git_fs_path_join_unrooted(&full_path, path, workdir, NULL)) < 0 ||
2866
+ (error = git_path_validate_str_length(repo, &full_path)) < 0)
2984
2867
  return error;
2985
2868
 
2986
2869
  /*
@@ -3027,30 +2910,30 @@ cleanup:
3027
2910
  if (fd >= 0)
3028
2911
  p_close(fd);
3029
2912
  git_filter_list_free(fl);
3030
- git_buf_dispose(&full_path);
2913
+ git_str_dispose(&full_path);
3031
2914
 
3032
2915
  return error;
3033
2916
  }
3034
2917
 
3035
- static int checkout_message(git_buf *out, git_reference *old, const char *new)
2918
+ static int checkout_message(git_str *out, git_reference *old, const char *new)
3036
2919
  {
3037
- git_buf_puts(out, "checkout: moving from ");
2920
+ git_str_puts(out, "checkout: moving from ");
3038
2921
 
3039
2922
  if (git_reference_type(old) == GIT_REFERENCE_SYMBOLIC)
3040
- git_buf_puts(out, git_reference__shorthand(git_reference_symbolic_target(old)));
2923
+ git_str_puts(out, git_reference__shorthand(git_reference_symbolic_target(old)));
3041
2924
  else
3042
- git_buf_puts(out, git_oid_tostr_s(git_reference_target(old)));
2925
+ git_str_puts(out, git_oid_tostr_s(git_reference_target(old)));
3043
2926
 
3044
- git_buf_puts(out, " to ");
2927
+ git_str_puts(out, " to ");
3045
2928
 
3046
2929
  if (git_reference__is_branch(new) ||
3047
2930
  git_reference__is_tag(new) ||
3048
2931
  git_reference__is_remote(new))
3049
- git_buf_puts(out, git_reference__shorthand(new));
2932
+ git_str_puts(out, git_reference__shorthand(new));
3050
2933
  else
3051
- git_buf_puts(out, new);
2934
+ git_str_puts(out, new);
3052
2935
 
3053
- if (git_buf_oom(out))
2936
+ if (git_str_oom(out))
3054
2937
  return -1;
3055
2938
 
3056
2939
  return 0;
@@ -3059,7 +2942,7 @@ static int checkout_message(git_buf *out, git_reference *old, const char *new)
3059
2942
  static int detach(git_repository *repo, const git_oid *id, const char *new)
3060
2943
  {
3061
2944
  int error;
3062
- git_buf log_message = GIT_BUF_INIT;
2945
+ git_str log_message = GIT_STR_INIT;
3063
2946
  git_object *object = NULL, *peeled = NULL;
3064
2947
  git_reference *new_head = NULL, *current = NULL;
3065
2948
 
@@ -3081,10 +2964,10 @@ static int detach(git_repository *repo, const git_oid *id, const char *new)
3081
2964
  if ((error = checkout_message(&log_message, current, new)) < 0)
3082
2965
  goto cleanup;
3083
2966
 
3084
- error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, git_buf_cstr(&log_message));
2967
+ error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, git_str_cstr(&log_message));
3085
2968
 
3086
2969
  cleanup:
3087
- git_buf_dispose(&log_message);
2970
+ git_str_dispose(&log_message);
3088
2971
  git_object_free(object);
3089
2972
  git_object_free(peeled);
3090
2973
  git_reference_free(current);
@@ -3097,7 +2980,7 @@ int git_repository_set_head(
3097
2980
  const char *refname)
3098
2981
  {
3099
2982
  git_reference *ref = NULL, *current = NULL, *new_head = NULL;
3100
- git_buf log_message = GIT_BUF_INIT;
2983
+ git_str log_message = GIT_STR_INIT;
3101
2984
  int error;
3102
2985
 
3103
2986
  GIT_ASSERT_ARG(repo);
@@ -3124,18 +3007,18 @@ int git_repository_set_head(
3124
3007
  if (!error) {
3125
3008
  if (git_reference_is_branch(ref)) {
3126
3009
  error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE,
3127
- git_reference_name(ref), true, git_buf_cstr(&log_message));
3010
+ git_reference_name(ref), true, git_str_cstr(&log_message));
3128
3011
  } else {
3129
3012
  error = detach(repo, git_reference_target(ref),
3130
3013
  git_reference_is_tag(ref) || git_reference_is_remote(ref) ? refname : NULL);
3131
3014
  }
3132
3015
  } else if (git_reference__is_branch(refname)) {
3133
3016
  error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname,
3134
- true, git_buf_cstr(&log_message));
3017
+ true, git_str_cstr(&log_message));
3135
3018
  }
3136
3019
 
3137
3020
  cleanup:
3138
- git_buf_dispose(&log_message);
3021
+ git_str_dispose(&log_message);
3139
3022
  git_reference_free(current);
3140
3023
  git_reference_free(ref);
3141
3024
  git_reference_free(new_head);
@@ -3144,26 +3027,26 @@ cleanup:
3144
3027
 
3145
3028
  int git_repository_set_head_detached(
3146
3029
  git_repository *repo,
3147
- const git_oid *commitish)
3030
+ const git_oid *committish)
3148
3031
  {
3149
- return detach(repo, commitish, NULL);
3032
+ return detach(repo, committish, NULL);
3150
3033
  }
3151
3034
 
3152
3035
  int git_repository_set_head_detached_from_annotated(
3153
3036
  git_repository *repo,
3154
- const git_annotated_commit *commitish)
3037
+ const git_annotated_commit *committish)
3155
3038
  {
3156
3039
  GIT_ASSERT_ARG(repo);
3157
- GIT_ASSERT_ARG(commitish);
3040
+ GIT_ASSERT_ARG(committish);
3158
3041
 
3159
- return detach(repo, git_annotated_commit_id(commitish), commitish->description);
3042
+ return detach(repo, git_annotated_commit_id(committish), committish->description);
3160
3043
  }
3161
3044
 
3162
3045
  int git_repository_detach_head(git_repository *repo)
3163
3046
  {
3164
3047
  git_reference *old_head = NULL, *new_head = NULL, *current = NULL;
3165
3048
  git_object *object = NULL;
3166
- git_buf log_message = GIT_BUF_INIT;
3049
+ git_str log_message = GIT_STR_INIT;
3167
3050
  int error;
3168
3051
 
3169
3052
  GIT_ASSERT_ARG(repo);
@@ -3181,10 +3064,10 @@ int git_repository_detach_head(git_repository *repo)
3181
3064
  goto cleanup;
3182
3065
 
3183
3066
  error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head),
3184
- 1, git_buf_cstr(&log_message));
3067
+ 1, git_str_cstr(&log_message));
3185
3068
 
3186
3069
  cleanup:
3187
- git_buf_dispose(&log_message);
3070
+ git_str_dispose(&log_message);
3188
3071
  git_object_free(object);
3189
3072
  git_reference_free(old_head);
3190
3073
  git_reference_free(new_head);
@@ -3198,69 +3081,69 @@ cleanup:
3198
3081
  */
3199
3082
  int git_repository_state(git_repository *repo)
3200
3083
  {
3201
- git_buf repo_path = GIT_BUF_INIT;
3084
+ git_str repo_path = GIT_STR_INIT;
3202
3085
  int state = GIT_REPOSITORY_STATE_NONE;
3203
3086
 
3204
3087
  GIT_ASSERT_ARG(repo);
3205
3088
 
3206
- if (git_buf_puts(&repo_path, repo->gitdir) < 0)
3089
+ if (git_str_puts(&repo_path, repo->gitdir) < 0)
3207
3090
  return -1;
3208
3091
 
3209
- if (git_path_contains_file(&repo_path, GIT_REBASE_MERGE_INTERACTIVE_FILE))
3092
+ if (git_fs_path_contains_file(&repo_path, GIT_REBASE_MERGE_INTERACTIVE_FILE))
3210
3093
  state = GIT_REPOSITORY_STATE_REBASE_INTERACTIVE;
3211
- else if (git_path_contains_dir(&repo_path, GIT_REBASE_MERGE_DIR))
3094
+ else if (git_fs_path_contains_dir(&repo_path, GIT_REBASE_MERGE_DIR))
3212
3095
  state = GIT_REPOSITORY_STATE_REBASE_MERGE;
3213
- else if (git_path_contains_file(&repo_path, GIT_REBASE_APPLY_REBASING_FILE))
3096
+ else if (git_fs_path_contains_file(&repo_path, GIT_REBASE_APPLY_REBASING_FILE))
3214
3097
  state = GIT_REPOSITORY_STATE_REBASE;
3215
- else if (git_path_contains_file(&repo_path, GIT_REBASE_APPLY_APPLYING_FILE))
3098
+ else if (git_fs_path_contains_file(&repo_path, GIT_REBASE_APPLY_APPLYING_FILE))
3216
3099
  state = GIT_REPOSITORY_STATE_APPLY_MAILBOX;
3217
- else if (git_path_contains_dir(&repo_path, GIT_REBASE_APPLY_DIR))
3100
+ else if (git_fs_path_contains_dir(&repo_path, GIT_REBASE_APPLY_DIR))
3218
3101
  state = GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE;
3219
- else if (git_path_contains_file(&repo_path, GIT_MERGE_HEAD_FILE))
3102
+ else if (git_fs_path_contains_file(&repo_path, GIT_MERGE_HEAD_FILE))
3220
3103
  state = GIT_REPOSITORY_STATE_MERGE;
3221
- else if (git_path_contains_file(&repo_path, GIT_REVERT_HEAD_FILE)) {
3104
+ else if (git_fs_path_contains_file(&repo_path, GIT_REVERT_HEAD_FILE)) {
3222
3105
  state = GIT_REPOSITORY_STATE_REVERT;
3223
- if (git_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
3106
+ if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
3224
3107
  state = GIT_REPOSITORY_STATE_REVERT_SEQUENCE;
3225
3108
  }
3226
- } else if (git_path_contains_file(&repo_path, GIT_CHERRYPICK_HEAD_FILE)) {
3109
+ } else if (git_fs_path_contains_file(&repo_path, GIT_CHERRYPICK_HEAD_FILE)) {
3227
3110
  state = GIT_REPOSITORY_STATE_CHERRYPICK;
3228
- if (git_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
3111
+ if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
3229
3112
  state = GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE;
3230
3113
  }
3231
- } else if (git_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE))
3114
+ } else if (git_fs_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE))
3232
3115
  state = GIT_REPOSITORY_STATE_BISECT;
3233
3116
 
3234
- git_buf_dispose(&repo_path);
3117
+ git_str_dispose(&repo_path);
3235
3118
  return state;
3236
3119
  }
3237
3120
 
3238
3121
  int git_repository__cleanup_files(
3239
3122
  git_repository *repo, const char *files[], size_t files_len)
3240
3123
  {
3241
- git_buf buf = GIT_BUF_INIT;
3124
+ git_str buf = GIT_STR_INIT;
3242
3125
  size_t i;
3243
3126
  int error;
3244
3127
 
3245
3128
  for (error = 0, i = 0; !error && i < files_len; ++i) {
3246
3129
  const char *path;
3247
3130
 
3248
- if (git_buf_joinpath(&buf, repo->gitdir, files[i]) < 0)
3131
+ if (git_str_joinpath(&buf, repo->gitdir, files[i]) < 0)
3249
3132
  return -1;
3250
3133
 
3251
- path = git_buf_cstr(&buf);
3134
+ path = git_str_cstr(&buf);
3252
3135
 
3253
- if (git_path_isfile(path)) {
3136
+ if (git_fs_path_isfile(path)) {
3254
3137
  error = p_unlink(path);
3255
- } else if (git_path_isdir(path)) {
3138
+ } else if (git_fs_path_isdir(path)) {
3256
3139
  error = git_futils_rmdir_r(path, NULL,
3257
3140
  GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS);
3258
3141
  }
3259
3142
 
3260
- git_buf_clear(&buf);
3143
+ git_str_clear(&buf);
3261
3144
  }
3262
3145
 
3263
- git_buf_dispose(&buf);
3146
+ git_str_dispose(&buf);
3264
3147
  return error;
3265
3148
  }
3266
3149
 
@@ -3285,15 +3168,15 @@ int git_repository_state_cleanup(git_repository *repo)
3285
3168
 
3286
3169
  int git_repository_is_shallow(git_repository *repo)
3287
3170
  {
3288
- git_buf path = GIT_BUF_INIT;
3171
+ git_str path = GIT_STR_INIT;
3289
3172
  struct stat st;
3290
3173
  int error;
3291
3174
 
3292
- if ((error = git_buf_joinpath(&path, repo->gitdir, "shallow")) < 0)
3175
+ if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0)
3293
3176
  return error;
3294
3177
 
3295
- error = git_path_lstat(path.ptr, &st);
3296
- git_buf_dispose(&path);
3178
+ error = git_fs_path_lstat(path.ptr, &st);
3179
+ git_str_dispose(&path);
3297
3180
 
3298
3181
  if (error == GIT_ENOTFOUND) {
3299
3182
  git_error_clear();